]> git.sesse.net Git - nageru/commitdiff
Add an option --map-signal= to override the default signal-to-card mapping.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 1 May 2016 20:11:05 +0000 (22:11 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 1 May 2016 20:11:18 +0000 (22:11 +0200)
NEWS
flags.cpp
flags.h
theme.cpp

diff --git a/NEWS b/NEWS
index 0efd48c5203a097862fb050b93a273ca0ae68d6d..9e5782921f503201c96a492985ab34e897f07c81 100644 (file)
--- 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
 
index f782c769cbc0329aacce8178c40a08442e03bdbc..7e8beaf84dab139a978b33d9bc1302949419f0d1 100644 (file)
--- a/flags.cpp
+++ b/flags.cpp
@@ -3,6 +3,11 @@
 #include <getopt.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+
+#include <utility>
+
+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<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",
+                               mapping.first, mapping.second);
+                       exit(1);
+               }
+       }
 }
diff --git a/flags.h b/flags.h
index 0c01ab1d4c57d75686276104c5cb4c4cc651d061..c3ea0fc5e40d23db712553be8947ca8269c70506 100644 (file)
--- a/flags.h
+++ b/flags.h
@@ -1,6 +1,7 @@
 #ifndef _FLAGS_H
 #define _FLAGS_H
 
+#include <map>
 #include <string>
 
 #include "defs.h"
@@ -23,6 +24,7 @@ struct Flags {
        int x264_vbv_max_bitrate = -1;  // In kilobits. 0 = no limit, -1 = same as <x264_bitrate> (CBR).
        int x264_vbv_buffer_size = -1;  // In kilobits. 0 = one-frame VBV, -1 = same as <x264_bitrate> (one-second VBV).
        bool enable_alsa_output = true;
+       std::map<int, int> default_stream_mapping;
 };
 extern Flags global_flags;
 
index 1d0cd2d643db006a4fae075f8aed7c817e5e176f..2b5c5b4257eeef1b0270e5dfc862702e11af0b89 100644 (file)
--- a/theme.cpp
+++ b/theme.cpp
@@ -24,6 +24,7 @@
 #include <memory>
 
 #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);