]> git.sesse.net Git - nageru/blobdiff - nageru/flags.cpp
Make number of cards flexible at runtime.
[nageru] / nageru / flags.cpp
index 9c58ad9c0d7bf4aa0d0bfebe46e81a3b8b29b191..402e33d7eca7a0be7d05d6ae87a4025f78ad9d0f 100644 (file)
@@ -15,6 +15,7 @@ Flags global_flags;
 enum LongOption {
        OPTION_HELP = 1000,
        OPTION_FULLSCREEN,
+       OPTION_MAX_NUM_CARDS,
        OPTION_MULTICHANNEL,
        OPTION_MIDI_MAPPING,
        OPTION_DEFAULT_HDMI_INPUT,
@@ -93,13 +94,13 @@ map<unsigned, unsigned> parse_mjpeg_export_cards(char *optarg)
                        fprintf(stderr, "ERROR: Invalid range %u-%u in --mjpeg-export-cards=\n", range_begin, range_end);
                        exit(1);
                }
-               if (range_end >= unsigned(global_flags.num_cards)) {
+               if (range_end >= unsigned(global_flags.max_num_cards)) {
                        // There are situations where we could possibly want to
                        // include FFmpeg inputs (CEF inputs are unlikely),
                        // but they're not necessarily in 4:2:2 Y'CbCr, so it would
                        // require more functionality the the JPEG encoder.
                        fprintf(stderr, "ERROR: Asked for (zero-indexed) card %u in --mjpeg-export-cards=, but there are only %u cards\n",
-                               range_end, global_flags.num_cards);
+                               range_end, global_flags.max_num_cards);
                        exit(1);
                }
                for (unsigned card_idx = range_begin; card_idx <= range_end; ++card_idx) {
@@ -133,7 +134,8 @@ void usage(Program program)
        fprintf(stderr, "  -w, --width                     output width in pixels (default 1280)\n");
        fprintf(stderr, "  -h, --height                    output height in pixels (default 720)\n");
        if (program == PROGRAM_NAGERU) {
-               fprintf(stderr, "  -c, --num-cards                 set number of input cards (default 2)\n");
+               fprintf(stderr, "  -c, --num-cards                 set minimum number of input cards (default 2)\n");
+               fprintf(stderr, "      --max-num-cards             set maximum number of input cards (default %d)\n", MAX_VIDEO_CARDS);
                fprintf(stderr, "  -o, --output-card=CARD          also output signal to the given card (default none)\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");
@@ -233,6 +235,7 @@ void parse_flags(Program program, int argc, char * const argv[])
                { "width", required_argument, 0, 'w' },
                { "height", required_argument, 0, 'h' },
                { "num-cards", required_argument, 0, 'c' },
+               { "max-num-cards", required_argument, 0, OPTION_MAX_NUM_CARDS },
                { "output-card", required_argument, 0, 'o' },
                { "theme", required_argument, 0, 't' },
                { "theme-dir", required_argument, 0, 'I' },
@@ -312,7 +315,10 @@ void parse_flags(Program program, int argc, char * const argv[])
                        global_flags.height = atoi(optarg);
                        break;
                case 'c':
-                       global_flags.num_cards = atoi(optarg);
+                       global_flags.min_num_cards = atoi(optarg);
+                       break;
+               case OPTION_MAX_NUM_CARDS:
+                       global_flags.max_num_cards = atoi(optarg);
                        break;
                case 'o':
                        global_flags.output_card = atoi(optarg);
@@ -587,12 +593,20 @@ void parse_flags(Program program, int argc, char * const argv[])
                fprintf(stderr, "ERROR: --http-uncompressed-video and --http-x264-video are mutually incompatible\n");
                exit(1);
        }
-       if (global_flags.num_cards <= 0) {
+       if (global_flags.min_num_cards <= 0) {
                fprintf(stderr, "ERROR: --num-cards must be at least 1\n");
                exit(1);
        }
+       if (global_flags.max_num_cards <= 0) {
+               fprintf(stderr, "ERROR: --max-num-cards must be at least 1\n");
+               exit(1);
+       }
+       if (global_flags.max_num_cards < global_flags.min_num_cards) {
+               fprintf(stderr, "ERROR: --max-num-cards can not be lower than --num-cards\n");
+               exit(1);
+       }
        if (global_flags.output_card < -1 ||
-           global_flags.output_card >= global_flags.num_cards) {
+           global_flags.output_card >= global_flags.max_num_cards) {
                fprintf(stderr, "ERROR: --output-card points to a nonexistant card\n");
                exit(1);
        }
@@ -624,8 +638,8 @@ void parse_flags(Program program, int argc, char * const argv[])
        }
 
        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",
+               if (mapping.second >= global_flags.max_num_cards) {
+                       fprintf(stderr, "ERROR: Signal %d mapped to card %d, which doesn't exist (try adjusting --max-num-cards)\n",
                                mapping.first, mapping.second);
                        exit(1);
                }
@@ -694,7 +708,7 @@ void parse_flags(Program program, int argc, char * const argv[])
 
        if (!card_to_mjpeg_stream_export_set) {
                // Fill in the default mapping (export all cards, in order).
-               for (unsigned card_idx = 0; card_idx < unsigned(global_flags.num_cards); ++card_idx) {
+               for (unsigned card_idx = 0; card_idx < unsigned(global_flags.max_num_cards); ++card_idx) {
                        global_flags.card_to_mjpeg_stream_export[card_idx] = card_idx;
                }
        }