]> git.sesse.net Git - nageru/commitdiff
Support other streams than the default file.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Oct 2018 14:16:45 +0000 (16:16 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Oct 2018 14:51:15 +0000 (16:51 +0200)
Makefile
flags.cpp [new file with mode: 0644]
flags.h [new file with mode: 0644]
main.cpp

index 07752113caed275fd6e3761174e53d9b669f0ae3..a080c6c966f5e66e8ef86b594afb60fc9b9f1cd4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ OBJS += $(OBJS_WITH_MOC:.o=.moc.o)
 OBJS += flow.o gpu_timers.o
 
 OBJS += ffmpeg_raii.o main.o player.o httpd.o mux.o metacube2.o video_stream.o context.o chroma_subsampler.o
-OBJS += vaapi_jpeg_decoder.o memcpy_interleaved.o db.o disk_space_estimator.o ycbcr_converter.o
+OBJS += vaapi_jpeg_decoder.o memcpy_interleaved.o db.o disk_space_estimator.o ycbcr_converter.o flags.o
 OBJS += state.pb.o
 
 %.o: %.cpp
diff --git a/flags.cpp b/flags.cpp
new file mode 100644 (file)
index 0000000..af1cfb9
--- /dev/null
+++ b/flags.cpp
@@ -0,0 +1,57 @@
+#include "flags.h"
+
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <utility>
+
+using namespace std;
+
+Flags global_flags;
+
+// Long options that have no corresponding short option.
+enum LongOption {
+       OPTION_HELP = 1000,
+       OPTION_SLOW_DOWN_INPUT = 1001
+};
+
+void usage()
+{
+       fprintf(stderr, "Usage: futatabi [OPTION]... SOURCE_URL\n");
+       fprintf(stderr, "\n");
+       fprintf(stderr, "      --help                      print usage information\n");
+       fprintf(stderr, "      --slow-down-input           slow down input to realtime (default on if no\n");
+       fprintf(stderr, "                                    source URL given)");
+}
+
+void parse_flags(int argc, char * const argv[])
+{
+       static const option long_options[] = {
+               { "help", no_argument, 0, OPTION_HELP },
+               { "slow-down-input", no_argument, 0, OPTION_SLOW_DOWN_INPUT },
+               { 0, 0, 0, 0 }
+       };
+       for ( ;; ) {
+               int option_index = 0;
+               int c = getopt_long(argc, argv, "q:", long_options, &option_index);
+
+               if (c == -1) {
+                       break;
+               }
+               switch (c) {
+               case OPTION_SLOW_DOWN_INPUT:
+                       global_flags.slow_down_input = true;
+                       break;
+               case OPTION_HELP:
+                       usage();
+                       exit(0);
+               default:
+                       fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
+                       fprintf(stderr, "\n");
+                       usage();
+                       exit(1);
+               }
+       }
+}
diff --git a/flags.h b/flags.h
new file mode 100644 (file)
index 0000000..794e90d
--- /dev/null
+++ b/flags.h
@@ -0,0 +1,15 @@
+#ifndef _FLAGS_H
+#define _FLAGS_H
+
+#include <string>
+
+struct Flags {
+       std::string stream_source;
+       bool slow_down_input = false;
+};
+extern Flags global_flags;
+
+void usage();
+void parse_flags(int argc, char * const argv[]);
+
+#endif  // !defined(_FLAGS_H)
index da2340bdfd81c34862bd075648395adaf1e8554b..b81471d64ce38aee758d1bacd0ba028f6643fb6c 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -3,6 +3,7 @@
 #include <chrono>
 #include <condition_variable>
 #include <dirent.h>
+#include <getopt.h>
 #include <memory>
 #include <mutex>
 #include <stdint.h>
@@ -21,6 +22,7 @@ extern "C" {
 #include "defs.h"
 #include "disk_space_estimator.h"
 #include "ffmpeg_raii.h"
+#include "flags.h"
 #include "httpd.h"
 #include "mainwindow.h"
 #include "player.h"
@@ -61,6 +63,17 @@ int record_thread_func();
 
 int main(int argc, char **argv)
 {
+       parse_flags(argc, argv);
+       if (optind == argc) {
+               global_flags.stream_source = "multiangle.mp4";
+               global_flags.slow_down_input = true;
+       } else if (optind + 1 == argc) {
+               global_flags.stream_source = argv[optind];
+       } else {
+               usage();
+               exit(1);
+       }
+
        avformat_network_init();
        global_httpd = new HTTPD;
        global_httpd->start(DEFAULT_HTTPD_PORT);
@@ -161,9 +174,9 @@ void load_existing_frames()
 
 int record_thread_func()
 {
-       auto format_ctx = avformat_open_input_unique("multiangle.mp4", nullptr, nullptr);
+       auto format_ctx = avformat_open_input_unique(global_flags.stream_source.c_str(), nullptr, nullptr);
        if (format_ctx == nullptr) {
-               fprintf(stderr, "%s: Error opening file\n", "example.mp4");
+               fprintf(stderr, "%s: Error opening file\n", global_flags.stream_source.c_str());
                return 1;
        }
 
@@ -222,8 +235,7 @@ int record_thread_func()
                assert(pkt.stream_index < MAX_STREAMS);
                frames[pkt.stream_index].push_back(pts);
 
-               // Hack. Remove when we're dealing with live streams.
-               if (last_pts != -1) {
+               if (last_pts != -1 && global_flags.slow_down_input) {
                        this_thread::sleep_for(microseconds((pts - last_pts) * 1000000 / TIMEBASE));
                }
                last_pts = pts;