From 5c6163ad5daa01b486e44c394dd7cc9878ec5df5 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 1 May 2016 22:11:05 +0200 Subject: [PATCH] Add an option --map-signal= to override the default signal-to-card mapping. --- NEWS | 3 +++ flags.cpp | 31 +++++++++++++++++++++++++++++++ flags.h | 2 ++ theme.cpp | 3 ++- 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 0efd48c..9e57829 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,9 @@ Nageru 1.3.0, not released yet is now done in a background thread, in order to not disturb the external stream. The audio still goes into a somewhat random stream, though. + - You can now override the default stream-to-card mapping with --map-signal= + on the command line. + Nageru 1.2.1, April 15th, 2016 diff --git a/flags.cpp b/flags.cpp index f782c76..7e8beaf 100644 --- a/flags.cpp +++ b/flags.cpp @@ -3,6 +3,11 @@ #include #include #include +#include + +#include + +using namespace std; Flags global_flags; @@ -15,6 +20,7 @@ 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"); @@ -46,6 +52,7 @@ 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 }, @@ -77,6 +84,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; @@ -138,4 +162,11 @@ void parse_flags(int argc, char * const argv[]) fprintf(stderr, "ERROR: --http-uncompressed-video and --http-x264-video are mutually incompatible\n"); exit(1); } + 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); + } + } } diff --git a/flags.h b/flags.h index 0c01ab1..c3ea0fc 100644 --- a/flags.h +++ b/flags.h @@ -1,6 +1,7 @@ #ifndef _FLAGS_H #define _FLAGS_H +#include #include #include "defs.h" @@ -23,6 +24,7 @@ struct Flags { int x264_vbv_max_bitrate = -1; // In kilobits. 0 = no limit, -1 = same as (CBR). int x264_vbv_buffer_size = -1; // In kilobits. 0 = one-frame VBV, -1 = same as (one-second VBV). bool enable_alsa_output = true; + std::map default_stream_mapping; }; extern Flags global_flags; diff --git a/theme.cpp b/theme.cpp index 1d0cd2d..2b5c5b4 100644 --- a/theme.cpp +++ b/theme.cpp @@ -24,6 +24,7 @@ #include #include "defs.h" +#include "flags.h" #include "image_input.h" #include "mixer.h" @@ -695,7 +696,7 @@ int call_num_channels(lua_State *L) } // namespace Theme::Theme(const char *filename, ResourcePool *resource_pool, unsigned num_cards) - : resource_pool(resource_pool), num_cards(num_cards) + : resource_pool(resource_pool), num_cards(num_cards), signal_to_card_mapping(global_flags.default_stream_mapping) { L = luaL_newstate(); luaL_openlibs(L); -- 2.39.2