]> git.sesse.net Git - nageru/blobdiff - flags.cpp
Add a flag to output Y'CbCr using Rec. 709 coefficients.
[nageru] / flags.cpp
index f3d9b658d286c125d057a1384cec6c1aff5538ad..02ea81b6fd8ed4174916a344151f33eb2b238889 100644 (file)
--- a/flags.cpp
+++ b/flags.cpp
@@ -13,7 +13,8 @@ Flags global_flags;
 
 // Long options that have no corresponding short option.
 enum LongOption {
-       OPTION_MULTICHANNEL = 1000,
+       OPTION_HELP = 1000,
+       OPTION_MULTICHANNEL,
        OPTION_MIDI_MAPPING,
        OPTION_FAKE_CARDS_AUDIO,
        OPTION_HTTP_UNCOMPRESSED_VIDEO,
@@ -43,14 +44,19 @@ enum LongOption {
        OPTION_DISABLE_MAKEUP_GAIN_AUTO,
        OPTION_ENABLE_MAKEUP_GAIN_AUTO,
        OPTION_DISABLE_ALSA_OUTPUT,
-       OPTION_NO_FLUSH_PBOS
+       OPTION_NO_FLUSH_PBOS,
+       OPTION_PRINT_VIDEO_LATENCY,
+       OPTION_AUDIO_QUEUE_LENGTH_MS,
+       OPTION_OUTPUT_YCBCR_COEFFICIENTS
 };
 
 void usage()
 {
        fprintf(stderr, "Usage: nageru [OPTION]...\n");
        fprintf(stderr, "\n");
-       fprintf(stderr, "  -h, --help                      print usage information\n");
+       fprintf(stderr, "      --help                      print usage information\n");
+       fprintf(stderr, "  -w, --width                     output width in pixels (default 1280)\n");
+       fprintf(stderr, "  -h, --height                    output height in pixels (default 720)\n");
        fprintf(stderr, "  -c, --num-cards                 set number of input cards (default 2)\n");
        fprintf(stderr, "  -t, --theme=FILE                choose theme (default theme.lua)\n");
        fprintf(stderr, "  -I, --theme-dir=DIR             search for theme in this directory (can be given multiple times)\n");
@@ -95,12 +101,18 @@ void usage()
        fprintf(stderr, "      --no-flush-pbos             do not explicitly signal texture data uploads\n");
        fprintf(stderr, "                                    (will give display corruption, but makes it\n");
        fprintf(stderr, "                                    possible to run with apitrace in real time)\n");
+       fprintf(stderr, "      --print-video-latency       print out measurements of video latency on stdout\n");
+       fprintf(stderr, "      --audio-queue-length-ms     length of audio resampling queue (default 100.0)\n");
+       fprintf(stderr, "      --output-ycbcr-coefficients={rec601,rec709}\n");
+       fprintf(stderr, "                                  Y'CbCr coefficient standard of output (default rec601)\n");
 }
 
 void parse_flags(int argc, char * const argv[])
 {
        static const option long_options[] = {
-               { "help", no_argument, 0, 'h' },
+               { "help", no_argument, 0, OPTION_HELP },
+               { "width", required_argument, 0, 'w' },
+               { "height", required_argument, 0, 'h' },
                { "num-cards", required_argument, 0, 'c' },
                { "theme", required_argument, 0, 't' },
                { "theme-dir", required_argument, 0, 'I' },
@@ -138,17 +150,27 @@ void parse_flags(int argc, char * const argv[])
                { "enable-makeup-gain-auto", no_argument, 0, OPTION_ENABLE_MAKEUP_GAIN_AUTO },
                { "disable-alsa-output", no_argument, 0, OPTION_DISABLE_ALSA_OUTPUT },
                { "no-flush-pbos", no_argument, 0, OPTION_NO_FLUSH_PBOS },
+               { "print-video-latency", no_argument, 0, OPTION_PRINT_VIDEO_LATENCY },
+               { "audio-queue-length-ms", required_argument, 0, OPTION_AUDIO_QUEUE_LENGTH_MS },
+               { "output-ycbcr-coefficients", required_argument, 0, OPTION_OUTPUT_YCBCR_COEFFICIENTS },
                { 0, 0, 0, 0 }
        };
        vector<string> theme_dirs;
+       string output_ycbcr_coefficients = "rec601";
        for ( ;; ) {
                int option_index = 0;
-               int c = getopt_long(argc, argv, "c:t:I:v:m:M:", long_options, &option_index);
+               int c = getopt_long(argc, argv, "c:t:I:v:m:M:w:h:", long_options, &option_index);
 
                if (c == -1) {
                        break;
                }
                switch (c) {
+               case 'w':
+                       global_flags.width = atoi(optarg);
+                       break;
+               case 'h':
+                       global_flags.height = atoi(optarg);
+                       break;
                case 'c':
                        global_flags.num_cards = atoi(optarg);
                        break;
@@ -281,7 +303,16 @@ void parse_flags(int argc, char * const argv[])
                case OPTION_NO_FLUSH_PBOS:
                        global_flags.flush_pbos = false;
                        break;
-               case 'h':
+               case OPTION_PRINT_VIDEO_LATENCY:
+                       global_flags.print_video_latency = true;
+                       break;
+               case OPTION_AUDIO_QUEUE_LENGTH_MS:
+                       global_flags.audio_queue_length_ms = atof(optarg);
+                       break;
+               case OPTION_OUTPUT_YCBCR_COEFFICIENTS:
+                       output_ycbcr_coefficients = optarg;
+                       break;
+               case OPTION_HELP:
                        usage();
                        exit(0);
                default:
@@ -313,6 +344,16 @@ void parse_flags(int argc, char * const argv[])
                global_flags.theme_dirs = theme_dirs;
        }
 
+       // In reality, we could probably do with any even value (we subsample
+       // by two in some places), but it's better to be on the safe side
+       // wrt. video codecs and such. (I'd set 16 if I could, but 1080 isn't
+       // divisible by 16.)
+       if (global_flags.width <= 0 || (global_flags.width % 8) != 0 ||
+           global_flags.height <= 0 || (global_flags.height % 8) != 0) {
+               fprintf(stderr, "ERROR: --width and --height must be positive integers divisible by 8\n");
+               exit(1);
+       }
+
        for (pair<int, int> mapping : global_flags.default_stream_mapping) {
                if (mapping.second >= global_flags.num_cards) {
                        fprintf(stderr, "ERROR: Signal %d mapped to card %d, which doesn't exist (try adjusting --num-cards)\n",
@@ -320,4 +361,13 @@ void parse_flags(int argc, char * const argv[])
                        exit(1);
                }
        }
+
+       if (output_ycbcr_coefficients == "rec709") {
+               global_flags.ycbcr_rec709_coefficients = true;
+       } else if (output_ycbcr_coefficients == "rec601") {
+               global_flags.ycbcr_rec709_coefficients = false;
+       } else {
+               fprintf(stderr, "ERROR: --output-ycbcr-coefficients must be “rec601” or “rec709”\n");
+               exit(1);
+       }
 }