]> git.sesse.net Git - nageru/blobdiff - flags.cpp
Make it possible to set width/height on the command line, instead of compiling it...
[nageru] / flags.cpp
index 5c57df7fa3beed67336831bf9c00e8f4b315e418..279ea426e92d0644a4a1eb82cd00edd1fc6df3e9 100644 (file)
--- a/flags.cpp
+++ b/flags.cpp
@@ -13,7 +13,10 @@ Flags global_flags;
 
 // Long options that have no corresponding short option.
 enum LongOption {
-       OPTION_VA_DISPLAY = 1000,
+       OPTION_HELP = 1000,
+       OPTION_MULTICHANNEL,
+       OPTION_MIDI_MAPPING,
+       OPTION_FAKE_CARDS_AUDIO,
        OPTION_HTTP_UNCOMPRESSED_VIDEO,
        OPTION_HTTP_X264_VIDEO,
        OPTION_X264_PRESET,
@@ -48,14 +51,19 @@ void usage()
 {
        fprintf(stderr, "Usage: nageru [OPTION]...\n");
        fprintf(stderr, "\n");
-       fprintf(stderr, "  -h, --help                      print usage information\n");
-       fprintf(stderr, "  -c, --num-cards                 set number of input cards, including fake cards (default 2)\n");
-       fprintf(stderr, "  -C, --num-fake-cards            set number of fake cards (default 0)\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");
        fprintf(stderr, "  -v, --va-display=SPEC           VA-API device for H.264 encoding\n");
        fprintf(stderr, "                                    ($DISPLAY spec or /dev/dri/render* path)\n");
        fprintf(stderr, "  -m, --map-signal=SIGNAL,CARD    set a default card mapping (can be given multiple times)\n");
+       fprintf(stderr, "  -M, --input-mapping=FILE        start with the given audio input mapping (implies --multichannel)\n");
+       fprintf(stderr, "      --multichannel              start in multichannel audio mapping mode\n");
+       fprintf(stderr, "      --midi-mapping=FILE         start with the given MIDI controller mapping (implies --multichannel)\n");
+       fprintf(stderr, "      --fake-cards-audio          make fake (disconnected) cards output a simple tone\n");
        fprintf(stderr, "      --http-uncompressed-video   send uncompressed NV12 video to HTTP clients\n");
        fprintf(stderr, "      --http-x264-video           send x264-compressed video to HTTP clients\n");
        fprintf(stderr, "      --x264-preset               x264 quality preset (default " X264_DEFAULT_PRESET ")\n");
@@ -95,13 +103,18 @@ void usage()
 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' },
-               { "num-fake-cards", required_argument, 0, 'C' },
                { "theme", required_argument, 0, 't' },
                { "theme-dir", required_argument, 0, 'I' },
                { "map-signal", required_argument, 0, 'm' },
-               { "va-display", required_argument, 0, OPTION_VA_DISPLAY },
+               { "input-mapping", required_argument, 0, 'M' },
+               { "va-display", required_argument, 0, 'v' },
+               { "multichannel", no_argument, 0, OPTION_MULTICHANNEL },
+               { "midi-mapping", required_argument, 0, OPTION_MIDI_MAPPING },
+               { "fake-cards-audio", no_argument, 0, OPTION_FAKE_CARDS_AUDIO },
                { "http-uncompressed-video", no_argument, 0, OPTION_HTTP_UNCOMPRESSED_VIDEO },
                { "http-x264-video", no_argument, 0, OPTION_HTTP_X264_VIDEO },
                { "x264-preset", required_argument, 0, OPTION_X264_PRESET },
@@ -135,18 +148,21 @@ void parse_flags(int argc, char * const argv[])
        vector<string> theme_dirs;
        for ( ;; ) {
                int option_index = 0;
-               int c = getopt_long(argc, argv, "c:C:t:v: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;
-               case 'C':
-                       global_flags.num_fake_cards = atoi(optarg);
-                       break;
                case 't':
                        global_flags.theme_filename = optarg;
                        break;
@@ -170,9 +186,22 @@ void parse_flags(int argc, char * const argv[])
                        global_flags.default_stream_mapping[signal_num] = card_num;
                        break;
                }
-               case OPTION_VA_DISPLAY:
+               case 'M':
+                       global_flags.input_mapping_filename = optarg;
+                       break;
+               case OPTION_MULTICHANNEL:
+                       global_flags.multichannel_mapping_mode = true;
+                       break;
+               case 'v':
                        global_flags.va_display = optarg;
                        break;
+               case OPTION_MIDI_MAPPING:
+                       global_flags.midi_mapping_filename = optarg;
+                       global_flags.multichannel_mapping_mode = true;
+                       break;
+               case OPTION_FAKE_CARDS_AUDIO:
+                       global_flags.fake_cards_audio = true;
+                       break;
                case OPTION_HTTP_UNCOMPRESSED_VIDEO:
                        global_flags.uncompressed_video_to_http = true;
                        break;
@@ -263,7 +292,7 @@ void parse_flags(int argc, char * const argv[])
                case OPTION_NO_FLUSH_PBOS:
                        global_flags.flush_pbos = false;
                        break;
-               case 'h':
+               case OPTION_HELP:
                        usage();
                        exit(0);
                default:
@@ -279,18 +308,10 @@ void parse_flags(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_fake_cards > global_flags.num_cards) {
-               fprintf(stderr, "ERROR: More fake cards then total cards makes no sense\n");
-               exit(1);
-       }
        if (global_flags.num_cards <= 0) {
                fprintf(stderr, "ERROR: --num-cards must be at least 1\n");
                exit(1);
        }
-       if (global_flags.num_fake_cards < 0) {
-               fprintf(stderr, "ERROR: --num-fake-cards cannot be negative\n");
-               exit(1);
-       }
        if (global_flags.x264_speedcontrol) {
                if (!global_flags.x264_preset.empty() && global_flags.x264_preset != "faster") {
                        fprintf(stderr, "WARNING: --x264-preset is overridden by --x264-speedcontrol (implicitly uses \"faster\" as base preset)\n");
@@ -303,6 +324,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",