X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=flags.cpp;h=25f11b46d9fbe835a1e03dbaafcf67162fd360b5;hb=16c0e5da7fa7b4eeea79470c24697a1ba193f071;hp=0fe2236e44b51801808eee8228d7652e7798d6e8;hpb=77cc363c7e4db05eb8c1b7fef1a56e2ee308e0d4;p=nageru diff --git a/flags.cpp b/flags.cpp index 0fe2236..25f11b4 100644 --- a/flags.cpp +++ b/flags.cpp @@ -3,6 +3,11 @@ #include #include #include +#include + +#include + +using namespace std; Flags global_flags; @@ -15,9 +20,29 @@ void usage() fprintf(stderr, " -t, --theme=FILE choose theme (default theme.lua)\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, " --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"); + fprintf(stderr, " --x264-tune x264 tuning (default " X264_DEFAULT_TUNE ", can be blank)\n"); + fprintf(stderr, " --x264-speedcontrol try to match x264 preset to available CPU speed\n"); + fprintf(stderr, " --x264-speedcontrol-verbose output speedcontrol debugging statistics\n"); + fprintf(stderr, " --x264-bitrate x264 bitrate (in kilobit/sec, default %d)\n", + DEFAULT_X264_OUTPUT_BIT_RATE); + fprintf(stderr, " --x264-vbv-bufsize x264 VBV size (in kilobits, 0 = one-frame VBV,\n"); + fprintf(stderr, " default: same as --x264-bitrate, that is, one-second VBV)\n"); + fprintf(stderr, " --x264-vbv-max-bitrate x264 local max bitrate (in kilobit/sec per --vbv-bufsize,\n"); + fprintf(stderr, " 0 = no limit, default: same as --x264-bitrate, i.e., CBR)\n"); fprintf(stderr, " --http-mux=NAME mux to use for HTTP streams (default " DEFAULT_STREAM_MUX_NAME ")\n"); + fprintf(stderr, " --http-audio-codec=NAME audio codec to use for HTTP streams\n"); + fprintf(stderr, " (default is to use the same as for the recording)\n"); + fprintf(stderr, " --http-audio-bitrate=KBITS audio codec bit rate to use for HTTP streams\n"); + fprintf(stderr, " (default is %d, ignored unless --http-audio-codec is set)\n", + DEFAULT_AUDIO_OUTPUT_BIT_RATE / 1000); + 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, " --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"); fprintf(stderr, " possible to run with apitrace in real time)\n"); @@ -29,10 +54,23 @@ void parse_flags(int argc, char * const argv[]) { "help", no_argument, 0, 'h' }, { "num-cards", required_argument, 0, 'c' }, { "theme", required_argument, 0, 't' }, + { "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 }, { "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 }, { 0, 0, 0, 0 } }; @@ -50,6 +88,23 @@ void parse_flags(int argc, char * const argv[]) case 't': global_flags.theme_filename = optarg; break; + case 'm': { + char *ptr = strchr(optarg, ','); + if (ptr == nullptr) { + fprintf(stderr, "ERROR: Invalid argument '%s' to --map-signal (needs a signal and a card number, separated by comma)\n", optarg); + exit(1); + } + *ptr = '\0'; + const int signal_num = atoi(optarg); + const int card_num = atoi(ptr + 1); + if (global_flags.default_stream_mapping.count(signal_num)) { + fprintf(stderr, "ERROR: Signal %d already mapped to card %d\n", + signal_num, global_flags.default_stream_mapping[signal_num]); + exit(1); + } + global_flags.default_stream_mapping[signal_num] = card_num; + break; + } case 1000: global_flags.va_display = optarg; break; @@ -59,9 +114,45 @@ void parse_flags(int argc, char * const argv[]) case 1004: global_flags.stream_mux_name = optarg; break; + case 1005: + global_flags.stream_coarse_timebase = true; + break; + case 1006: + global_flags.stream_audio_codec_name = optarg; + break; + case 1007: + global_flags.stream_audio_codec_bitrate = atoi(optarg) * 1000; + break; + case 1008: + global_flags.x264_video_to_http = true; + break; + case 1009: + global_flags.x264_preset = optarg; + break; + case 1010: + global_flags.x264_tune = optarg; + break; + case 1015: + global_flags.x264_speedcontrol = true; + break; + case 1016: + global_flags.x264_speedcontrol_verbose = true; + break; + case 1011: + global_flags.x264_bitrate = atoi(optarg); + break; + case 1012: + global_flags.x264_vbv_buffer_size = atoi(optarg); + break; + case 1013: + global_flags.x264_vbv_max_bitrate = atoi(optarg); + break; case 1002: global_flags.flat_audio = true; break; + case 1014: + global_flags.enable_alsa_output = false; + break; case 1003: global_flags.flush_pbos = false; break; @@ -75,4 +166,26 @@ void parse_flags(int argc, char * const argv[]) exit(1); } } + + if (global_flags.uncompressed_video_to_http && + global_flags.x264_video_to_http) { + fprintf(stderr, "ERROR: --http-uncompressed-video and --http-x264-video are mutually incompatible\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"); + } + global_flags.x264_preset = "faster"; + } else if (global_flags.x264_preset.empty()) { + global_flags.x264_preset = X264_DEFAULT_PRESET; + } + + for (pair 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", + mapping.first, mapping.second); + exit(1); + } + } }