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
--- /dev/null
+#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);
+ }
+ }
+}
--- /dev/null
+#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)
#include <chrono>
#include <condition_variable>
#include <dirent.h>
+#include <getopt.h>
#include <memory>
#include <mutex>
#include <stdint.h>
#include "defs.h"
#include "disk_space_estimator.h"
#include "ffmpeg_raii.h"
+#include "flags.h"
#include "httpd.h"
#include "mainwindow.h"
#include "player.h"
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);
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;
}
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;