14 // Long options that have no corresponding short option.
16 OPTION_FAKE_CARDS_AUDIO = 1000,
17 OPTION_HTTP_UNCOMPRESSED_VIDEO,
18 OPTION_HTTP_X264_VIDEO,
21 OPTION_X264_SPEEDCONTROL,
22 OPTION_X264_SPEEDCONTROL_VERBOSE,
24 OPTION_X264_VBV_BUFSIZE,
25 OPTION_X264_VBV_MAX_BITRATE,
28 OPTION_HTTP_COARSE_TIMEBASE,
29 OPTION_HTTP_AUDIO_CODEC,
30 OPTION_HTTP_AUDIO_BITRATE,
35 OPTION_DISABLE_GAIN_STAGING_AUTO,
36 OPTION_ENABLE_GAIN_STAGING_AUTO,
37 OPTION_DISABLE_COMPRESSOR,
38 OPTION_ENABLE_COMPRESSOR,
39 OPTION_DISABLE_LIMITER,
40 OPTION_ENABLE_LIMITER,
41 OPTION_DISABLE_MAKEUP_GAIN_AUTO,
42 OPTION_ENABLE_MAKEUP_GAIN_AUTO,
43 OPTION_DISABLE_ALSA_OUTPUT,
49 fprintf(stderr, "Usage: nageru [OPTION]...\n");
50 fprintf(stderr, "\n");
51 fprintf(stderr, " -h, --help print usage information\n");
52 fprintf(stderr, " -c, --num-cards set number of input cards (default 2)\n");
53 fprintf(stderr, " -t, --theme=FILE choose theme (default theme.lua)\n");
54 fprintf(stderr, " -I, --theme-dir=DIR search for theme in this directory (can be given multiple times)\n");
55 fprintf(stderr, " -v, --va-display=SPEC VA-API device for H.264 encoding\n");
56 fprintf(stderr, " ($DISPLAY spec or /dev/dri/render* path)\n");
57 fprintf(stderr, " -m, --map-signal=SIGNAL,CARD set a default card mapping (can be given multiple times)\n");
58 fprintf(stderr, " -M, --input-mapping=FILE start with the given audio input mapping\n");
59 fprintf(stderr, " --fake-cards-audio make fake (disconnected) cards output a simple tone\n");
60 fprintf(stderr, " --http-uncompressed-video send uncompressed NV12 video to HTTP clients\n");
61 fprintf(stderr, " --http-x264-video send x264-compressed video to HTTP clients\n");
62 fprintf(stderr, " --x264-preset x264 quality preset (default " X264_DEFAULT_PRESET ")\n");
63 fprintf(stderr, " --x264-tune x264 tuning (default " X264_DEFAULT_TUNE ", can be blank)\n");
64 fprintf(stderr, " --x264-speedcontrol try to match x264 preset to available CPU speed\n");
65 fprintf(stderr, " --x264-speedcontrol-verbose output speedcontrol debugging statistics\n");
66 fprintf(stderr, " --x264-bitrate x264 bitrate (in kilobit/sec, default %d)\n",
67 DEFAULT_X264_OUTPUT_BIT_RATE);
68 fprintf(stderr, " --x264-vbv-bufsize x264 VBV size (in kilobits, 0 = one-frame VBV,\n");
69 fprintf(stderr, " default: same as --x264-bitrate, that is, one-second VBV)\n");
70 fprintf(stderr, " --x264-vbv-max-bitrate x264 local max bitrate (in kilobit/sec per --vbv-bufsize,\n");
71 fprintf(stderr, " 0 = no limit, default: same as --x264-bitrate, i.e., CBR)\n");
72 fprintf(stderr, " --x264-param=NAME[,VALUE] set any x264 parameter, for fine tuning\n");
73 fprintf(stderr, " --http-mux=NAME mux to use for HTTP streams (default " DEFAULT_STREAM_MUX_NAME ")\n");
74 fprintf(stderr, " --http-audio-codec=NAME audio codec to use for HTTP streams\n");
75 fprintf(stderr, " (default is to use the same as for the recording)\n");
76 fprintf(stderr, " --http-audio-bitrate=KBITS audio codec bit rate to use for HTTP streams\n");
77 fprintf(stderr, " (default is %d, ignored unless --http-audio-codec is set)\n",
78 DEFAULT_AUDIO_OUTPUT_BIT_RATE / 1000);
79 fprintf(stderr, " --http-coarse-timebase use less timebase for HTTP (recommended for muxers\n");
80 fprintf(stderr, " that handle large pts poorly, like e.g. MP4)\n");
81 fprintf(stderr, " --flat-audio start with most audio processing turned off\n");
82 fprintf(stderr, " (can be overridden by e.g. --enable-limiter)\n");
83 fprintf(stderr, " --gain-staging=DB set initial gain staging to the given value\n");
84 fprintf(stderr, " (--disable-gain-staging-auto)\n");
85 fprintf(stderr, " --disable-locut turn off locut filter (also --enable)\n");
86 fprintf(stderr, " --disable-gain-staging-auto turn off automatic gain staging (also --enable)\n");
87 fprintf(stderr, " --disable-compressor turn off regular compressor (also --enable)\n");
88 fprintf(stderr, " --disable-limiter turn off limiter (also --enable)\n");
89 fprintf(stderr, " --disable-makeup-gain-auto turn off auto-adjustment of final makeup gain (also --enable)\n");
90 fprintf(stderr, " --disable-alsa-output disable audio monitoring via ALSA\n");
91 fprintf(stderr, " --no-flush-pbos do not explicitly signal texture data uploads\n");
92 fprintf(stderr, " (will give display corruption, but makes it\n");
93 fprintf(stderr, " possible to run with apitrace in real time)\n");
96 void parse_flags(int argc, char * const argv[])
98 static const option long_options[] = {
99 { "help", no_argument, 0, 'h' },
100 { "num-cards", required_argument, 0, 'c' },
101 { "theme", required_argument, 0, 't' },
102 { "theme-dir", required_argument, 0, 'I' },
103 { "map-signal", required_argument, 0, 'm' },
104 { "input-mapping", required_argument, 0, 'M' },
105 { "va-display", required_argument, 0, 'v' },
106 { "fake-cards-audio", no_argument, 0, OPTION_FAKE_CARDS_AUDIO },
107 { "http-uncompressed-video", no_argument, 0, OPTION_HTTP_UNCOMPRESSED_VIDEO },
108 { "http-x264-video", no_argument, 0, OPTION_HTTP_X264_VIDEO },
109 { "x264-preset", required_argument, 0, OPTION_X264_PRESET },
110 { "x264-tune", required_argument, 0, OPTION_X264_TUNE },
111 { "x264-speedcontrol", no_argument, 0, OPTION_X264_SPEEDCONTROL },
112 { "x264-speedcontrol-verbose", no_argument, 0, OPTION_X264_SPEEDCONTROL_VERBOSE },
113 { "x264-bitrate", required_argument, 0, OPTION_X264_BITRATE },
114 { "x264-vbv-bufsize", required_argument, 0, OPTION_X264_VBV_BUFSIZE },
115 { "x264-vbv-max-bitrate", required_argument, 0, OPTION_X264_VBV_MAX_BITRATE },
116 { "x264-param", required_argument, 0, OPTION_X264_PARAM },
117 { "http-mux", required_argument, 0, OPTION_HTTP_MUX },
118 { "http-coarse-timebase", no_argument, 0, OPTION_HTTP_COARSE_TIMEBASE },
119 { "http-audio-codec", required_argument, 0, OPTION_HTTP_AUDIO_CODEC },
120 { "http-audio-bitrate", required_argument, 0, OPTION_HTTP_AUDIO_BITRATE },
121 { "flat-audio", no_argument, 0, OPTION_FLAT_AUDIO },
122 { "gain-staging", required_argument, 0, OPTION_GAIN_STAGING },
123 { "disable-locut", no_argument, 0, OPTION_DISABLE_LOCUT },
124 { "enable-locut", no_argument, 0, OPTION_ENABLE_LOCUT },
125 { "disable-gain-staging-auto", no_argument, 0, OPTION_DISABLE_GAIN_STAGING_AUTO },
126 { "enable-gain-staging-auto", no_argument, 0, OPTION_ENABLE_GAIN_STAGING_AUTO },
127 { "disable-compressor", no_argument, 0, OPTION_DISABLE_COMPRESSOR },
128 { "enable-compressor", no_argument, 0, OPTION_ENABLE_COMPRESSOR },
129 { "disable-limiter", no_argument, 0, OPTION_DISABLE_LIMITER },
130 { "enable-limiter", no_argument, 0, OPTION_ENABLE_LIMITER },
131 { "disable-makeup-gain-auto", no_argument, 0, OPTION_DISABLE_MAKEUP_GAIN_AUTO },
132 { "enable-makeup-gain-auto", no_argument, 0, OPTION_ENABLE_MAKEUP_GAIN_AUTO },
133 { "disable-alsa-output", no_argument, 0, OPTION_DISABLE_ALSA_OUTPUT },
134 { "no-flush-pbos", no_argument, 0, OPTION_NO_FLUSH_PBOS },
137 vector<string> theme_dirs;
139 int option_index = 0;
140 int c = getopt_long(argc, argv, "c:t:I:v:m:M:", long_options, &option_index);
147 global_flags.num_cards = atoi(optarg);
150 global_flags.theme_filename = optarg;
153 theme_dirs.push_back(optarg);
156 char *ptr = strchr(optarg, ',');
157 if (ptr == nullptr) {
158 fprintf(stderr, "ERROR: Invalid argument '%s' to --map-signal (needs a signal and a card number, separated by comma)\n", optarg);
162 const int signal_num = atoi(optarg);
163 const int card_num = atoi(ptr + 1);
164 if (global_flags.default_stream_mapping.count(signal_num)) {
165 fprintf(stderr, "ERROR: Signal %d already mapped to card %d\n",
166 signal_num, global_flags.default_stream_mapping[signal_num]);
169 global_flags.default_stream_mapping[signal_num] = card_num;
173 global_flags.input_mapping_filename = optarg;
176 global_flags.va_display = optarg;
178 case OPTION_FAKE_CARDS_AUDIO:
179 global_flags.fake_cards_audio = true;
181 case OPTION_HTTP_UNCOMPRESSED_VIDEO:
182 global_flags.uncompressed_video_to_http = true;
184 case OPTION_HTTP_MUX:
185 global_flags.stream_mux_name = optarg;
187 case OPTION_HTTP_COARSE_TIMEBASE:
188 global_flags.stream_coarse_timebase = true;
190 case OPTION_HTTP_AUDIO_CODEC:
191 global_flags.stream_audio_codec_name = optarg;
193 case OPTION_HTTP_AUDIO_BITRATE:
194 global_flags.stream_audio_codec_bitrate = atoi(optarg) * 1000;
196 case OPTION_HTTP_X264_VIDEO:
197 global_flags.x264_video_to_http = true;
199 case OPTION_X264_PRESET:
200 global_flags.x264_preset = optarg;
202 case OPTION_X264_TUNE:
203 global_flags.x264_tune = optarg;
205 case OPTION_X264_SPEEDCONTROL:
206 global_flags.x264_speedcontrol = true;
208 case OPTION_X264_SPEEDCONTROL_VERBOSE:
209 global_flags.x264_speedcontrol_verbose = true;
211 case OPTION_X264_BITRATE:
212 global_flags.x264_bitrate = atoi(optarg);
214 case OPTION_X264_VBV_BUFSIZE:
215 global_flags.x264_vbv_buffer_size = atoi(optarg);
217 case OPTION_X264_VBV_MAX_BITRATE:
218 global_flags.x264_vbv_max_bitrate = atoi(optarg);
220 case OPTION_X264_PARAM:
221 global_flags.x264_extra_param.push_back(optarg);
223 case OPTION_FLAT_AUDIO:
224 // If --flat-audio is given, turn off everything that messes with the sound,
225 // except the final makeup gain.
226 global_flags.locut_enabled = false;
227 global_flags.gain_staging_auto = false;
228 global_flags.compressor_enabled = false;
229 global_flags.limiter_enabled = false;
231 case OPTION_GAIN_STAGING:
232 global_flags.initial_gain_staging_db = atof(optarg);
233 global_flags.gain_staging_auto = false;
235 case OPTION_DISABLE_LOCUT:
236 global_flags.locut_enabled = false;
238 case OPTION_ENABLE_LOCUT:
239 global_flags.locut_enabled = true;
241 case OPTION_DISABLE_GAIN_STAGING_AUTO:
242 global_flags.gain_staging_auto = false;
244 case OPTION_ENABLE_GAIN_STAGING_AUTO:
245 global_flags.gain_staging_auto = true;
247 case OPTION_DISABLE_COMPRESSOR:
248 global_flags.compressor_enabled = false;
250 case OPTION_ENABLE_COMPRESSOR:
251 global_flags.compressor_enabled = true;
253 case OPTION_DISABLE_LIMITER:
254 global_flags.limiter_enabled = false;
256 case OPTION_ENABLE_LIMITER:
257 global_flags.limiter_enabled = true;
259 case OPTION_DISABLE_MAKEUP_GAIN_AUTO:
260 global_flags.final_makeup_gain_auto = false;
262 case OPTION_ENABLE_MAKEUP_GAIN_AUTO:
263 global_flags.final_makeup_gain_auto = true;
265 case OPTION_DISABLE_ALSA_OUTPUT:
266 global_flags.enable_alsa_output = false;
268 case OPTION_NO_FLUSH_PBOS:
269 global_flags.flush_pbos = false;
275 fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
276 fprintf(stderr, "\n");
282 if (global_flags.uncompressed_video_to_http &&
283 global_flags.x264_video_to_http) {
284 fprintf(stderr, "ERROR: --http-uncompressed-video and --http-x264-video are mutually incompatible\n");
287 if (global_flags.num_cards <= 0) {
288 fprintf(stderr, "ERROR: --num-cards must be at least 1\n");
291 if (global_flags.x264_speedcontrol) {
292 if (!global_flags.x264_preset.empty() && global_flags.x264_preset != "faster") {
293 fprintf(stderr, "WARNING: --x264-preset is overridden by --x264-speedcontrol (implicitly uses \"faster\" as base preset)\n");
295 global_flags.x264_preset = "faster";
296 } else if (global_flags.x264_preset.empty()) {
297 global_flags.x264_preset = X264_DEFAULT_PRESET;
299 if (!theme_dirs.empty()) {
300 global_flags.theme_dirs = theme_dirs;
303 for (pair<int, int> mapping : global_flags.default_stream_mapping) {
304 if (mapping.second >= global_flags.num_cards) {
305 fprintf(stderr, "ERROR: Signal %d mapped to card %d, which doesn't exist (try adjusting --num-cards)\n",
306 mapping.first, mapping.second);