X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=flags.cpp;h=f3d9b658d286c125d057a1384cec6c1aff5538ad;hb=02f65224836f4e7ccecfb89ccd8dc38ee32f319a;hp=33d47b9d481e23de79d5c56d10b1624475c2b96a;hpb=dba2304d2acb23e3e56c03686f010a7c3f0c2739;p=nageru diff --git a/flags.cpp b/flags.cpp index 33d47b9..f3d9b65 100644 --- a/flags.cpp +++ b/flags.cpp @@ -11,6 +11,41 @@ using namespace std; Flags global_flags; +// Long options that have no corresponding short option. +enum LongOption { + OPTION_MULTICHANNEL = 1000, + OPTION_MIDI_MAPPING, + OPTION_FAKE_CARDS_AUDIO, + OPTION_HTTP_UNCOMPRESSED_VIDEO, + OPTION_HTTP_X264_VIDEO, + OPTION_X264_PRESET, + OPTION_X264_TUNE, + OPTION_X264_SPEEDCONTROL, + OPTION_X264_SPEEDCONTROL_VERBOSE, + OPTION_X264_BITRATE, + OPTION_X264_VBV_BUFSIZE, + OPTION_X264_VBV_MAX_BITRATE, + OPTION_X264_PARAM, + OPTION_HTTP_MUX, + OPTION_HTTP_COARSE_TIMEBASE, + OPTION_HTTP_AUDIO_CODEC, + OPTION_HTTP_AUDIO_BITRATE, + OPTION_FLAT_AUDIO, + OPTION_GAIN_STAGING, + OPTION_DISABLE_LOCUT, + OPTION_ENABLE_LOCUT, + OPTION_DISABLE_GAIN_STAGING_AUTO, + OPTION_ENABLE_GAIN_STAGING_AUTO, + OPTION_DISABLE_COMPRESSOR, + OPTION_ENABLE_COMPRESSOR, + OPTION_DISABLE_LIMITER, + OPTION_ENABLE_LIMITER, + OPTION_DISABLE_MAKEUP_GAIN_AUTO, + OPTION_ENABLE_MAKEUP_GAIN_AUTO, + OPTION_DISABLE_ALSA_OUTPUT, + OPTION_NO_FLUSH_PBOS +}; + void usage() { fprintf(stderr, "Usage: nageru [OPTION]...\n"); @@ -18,9 +53,14 @@ void usage() fprintf(stderr, " -h, --help print usage information\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"); @@ -43,6 +83,14 @@ void usage() fprintf(stderr, " --http-coarse-timebase use less timebase for HTTP (recommended for muxers\n"); fprintf(stderr, " that handle large pts poorly, like e.g. MP4)\n"); fprintf(stderr, " --flat-audio start with most audio processing turned off\n"); + fprintf(stderr, " (can be overridden by e.g. --enable-limiter)\n"); + fprintf(stderr, " --gain-staging=DB set initial gain staging to the given value\n"); + fprintf(stderr, " (--disable-gain-staging-auto)\n"); + fprintf(stderr, " --disable-locut turn off locut filter (also --enable)\n"); + fprintf(stderr, " --disable-gain-staging-auto turn off automatic gain staging (also --enable)\n"); + fprintf(stderr, " --disable-compressor turn off regular compressor (also --enable)\n"); + fprintf(stderr, " --disable-limiter turn off limiter (also --enable)\n"); + fprintf(stderr, " --disable-makeup-gain-auto turn off auto-adjustment of final makeup gain (also --enable)\n"); fprintf(stderr, " --disable-alsa-output disable audio monitoring via ALSA\n"); fprintf(stderr, " --no-flush-pbos do not explicitly signal texture data uploads\n"); fprintf(stderr, " (will give display corruption, but makes it\n"); @@ -55,30 +103,47 @@ void parse_flags(int argc, char * const argv[]) { "help", no_argument, 0, 'h' }, { "num-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, 1000 }, - { "http-uncompressed-video", no_argument, 0, 1001 }, - { "http-x264-video", no_argument, 0, 1008 }, - { "x264-preset", required_argument, 0, 1009 }, - { "x264-tune", required_argument, 0, 1010 }, - { "x264-speedcontrol", no_argument, 0, 1015 }, - { "x264-speedcontrol-verbose", no_argument, 0, 1016 }, - { "x264-bitrate", required_argument, 0, 1011 }, - { "x264-vbv-bufsize", required_argument, 0, 1012 }, - { "x264-vbv-max-bitrate", required_argument, 0, 1013 }, - { "x264-param", required_argument, 0, 1017 }, - { "http-mux", required_argument, 0, 1004 }, - { "http-coarse-timebase", no_argument, 0, 1005 }, - { "http-audio-codec", required_argument, 0, 1006 }, - { "http-audio-bitrate", required_argument, 0, 1007 }, - { "flat-audio", no_argument, 0, 1002 }, - { "disable-alsa-output", no_argument, 0, 1014 }, - { "no-flush-pbos", no_argument, 0, 1003 }, + { "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 }, + { "x264-tune", required_argument, 0, OPTION_X264_TUNE }, + { "x264-speedcontrol", no_argument, 0, OPTION_X264_SPEEDCONTROL }, + { "x264-speedcontrol-verbose", no_argument, 0, OPTION_X264_SPEEDCONTROL_VERBOSE }, + { "x264-bitrate", required_argument, 0, OPTION_X264_BITRATE }, + { "x264-vbv-bufsize", required_argument, 0, OPTION_X264_VBV_BUFSIZE }, + { "x264-vbv-max-bitrate", required_argument, 0, OPTION_X264_VBV_MAX_BITRATE }, + { "x264-param", required_argument, 0, OPTION_X264_PARAM }, + { "http-mux", required_argument, 0, OPTION_HTTP_MUX }, + { "http-coarse-timebase", no_argument, 0, OPTION_HTTP_COARSE_TIMEBASE }, + { "http-audio-codec", required_argument, 0, OPTION_HTTP_AUDIO_CODEC }, + { "http-audio-bitrate", required_argument, 0, OPTION_HTTP_AUDIO_BITRATE }, + { "flat-audio", no_argument, 0, OPTION_FLAT_AUDIO }, + { "gain-staging", required_argument, 0, OPTION_GAIN_STAGING }, + { "disable-locut", no_argument, 0, OPTION_DISABLE_LOCUT }, + { "enable-locut", no_argument, 0, OPTION_ENABLE_LOCUT }, + { "disable-gain-staging-auto", no_argument, 0, OPTION_DISABLE_GAIN_STAGING_AUTO }, + { "enable-gain-staging-auto", no_argument, 0, OPTION_ENABLE_GAIN_STAGING_AUTO }, + { "disable-compressor", no_argument, 0, OPTION_DISABLE_COMPRESSOR }, + { "enable-compressor", no_argument, 0, OPTION_ENABLE_COMPRESSOR }, + { "disable-limiter", no_argument, 0, OPTION_DISABLE_LIMITER }, + { "enable-limiter", no_argument, 0, OPTION_ENABLE_LIMITER }, + { "disable-makeup-gain-auto", no_argument, 0, OPTION_DISABLE_MAKEUP_GAIN_AUTO }, + { "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 }, { 0, 0, 0, 0 } }; + vector theme_dirs; for ( ;; ) { int option_index = 0; - int c = getopt_long(argc, argv, "c:t:v:m:", long_options, &option_index); + int c = getopt_long(argc, argv, "c:t:I:v:m:M:", long_options, &option_index); if (c == -1) { break; @@ -90,6 +155,9 @@ void parse_flags(int argc, char * const argv[]) case 't': global_flags.theme_filename = optarg; break; + case 'I': + theme_dirs.push_back(optarg); + break; case 'm': { char *ptr = strchr(optarg, ','); if (ptr == nullptr) { @@ -107,58 +175,110 @@ void parse_flags(int argc, char * const argv[]) global_flags.default_stream_mapping[signal_num] = card_num; break; } - case 1000: + 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 1001: + 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; - case 1004: + case OPTION_HTTP_MUX: global_flags.stream_mux_name = optarg; break; - case 1005: + case OPTION_HTTP_COARSE_TIMEBASE: global_flags.stream_coarse_timebase = true; break; - case 1006: + case OPTION_HTTP_AUDIO_CODEC: global_flags.stream_audio_codec_name = optarg; break; - case 1007: + case OPTION_HTTP_AUDIO_BITRATE: global_flags.stream_audio_codec_bitrate = atoi(optarg) * 1000; break; - case 1008: + case OPTION_HTTP_X264_VIDEO: global_flags.x264_video_to_http = true; break; - case 1009: + case OPTION_X264_PRESET: global_flags.x264_preset = optarg; break; - case 1010: + case OPTION_X264_TUNE: global_flags.x264_tune = optarg; break; - case 1015: + case OPTION_X264_SPEEDCONTROL: global_flags.x264_speedcontrol = true; break; - case 1016: + case OPTION_X264_SPEEDCONTROL_VERBOSE: global_flags.x264_speedcontrol_verbose = true; break; - case 1011: + case OPTION_X264_BITRATE: global_flags.x264_bitrate = atoi(optarg); break; - case 1012: + case OPTION_X264_VBV_BUFSIZE: global_flags.x264_vbv_buffer_size = atoi(optarg); break; - case 1013: + case OPTION_X264_VBV_MAX_BITRATE: global_flags.x264_vbv_max_bitrate = atoi(optarg); break; - case 1017: + case OPTION_X264_PARAM: global_flags.x264_extra_param.push_back(optarg); break; - case 1002: - global_flags.flat_audio = true; + case OPTION_FLAT_AUDIO: + // If --flat-audio is given, turn off everything that messes with the sound, + // except the final makeup gain. + global_flags.locut_enabled = false; + global_flags.gain_staging_auto = false; + global_flags.compressor_enabled = false; + global_flags.limiter_enabled = false; + break; + case OPTION_GAIN_STAGING: + global_flags.initial_gain_staging_db = atof(optarg); + global_flags.gain_staging_auto = false; + break; + case OPTION_DISABLE_LOCUT: + global_flags.locut_enabled = false; + break; + case OPTION_ENABLE_LOCUT: + global_flags.locut_enabled = true; + break; + case OPTION_DISABLE_GAIN_STAGING_AUTO: + global_flags.gain_staging_auto = false; break; - case 1014: + case OPTION_ENABLE_GAIN_STAGING_AUTO: + global_flags.gain_staging_auto = true; + break; + case OPTION_DISABLE_COMPRESSOR: + global_flags.compressor_enabled = false; + break; + case OPTION_ENABLE_COMPRESSOR: + global_flags.compressor_enabled = true; + break; + case OPTION_DISABLE_LIMITER: + global_flags.limiter_enabled = false; + break; + case OPTION_ENABLE_LIMITER: + global_flags.limiter_enabled = true; + break; + case OPTION_DISABLE_MAKEUP_GAIN_AUTO: + global_flags.final_makeup_gain_auto = false; + break; + case OPTION_ENABLE_MAKEUP_GAIN_AUTO: + global_flags.final_makeup_gain_auto = true; + break; + case OPTION_DISABLE_ALSA_OUTPUT: global_flags.enable_alsa_output = false; break; - case 1003: + case OPTION_NO_FLUSH_PBOS: global_flags.flush_pbos = false; break; case 'h': @@ -177,6 +297,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_cards <= 0) { + fprintf(stderr, "ERROR: --num-cards must be at least 1\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"); @@ -185,6 +309,9 @@ void parse_flags(int argc, char * const argv[]) } else if (global_flags.x264_preset.empty()) { global_flags.x264_preset = X264_DEFAULT_PRESET; } + if (!theme_dirs.empty()) { + global_flags.theme_dirs = theme_dirs; + } for (pair mapping : global_flags.default_stream_mapping) { if (mapping.second >= global_flags.num_cards) {