From 6f4f5d4a13df2e4562cb9c145fa5b60be2ae63d0 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 27 Jul 2016 21:21:24 +0200 Subject: [PATCH] Rework handling of fake cards. Remove the --num-fake-cards (-C) parameter; instead, allocate PCI and USB cards first, and then just fill up with the remaining fake cards. This makes it possible to just run ./nageru and have things work well by default, no matter how many or few actual cards you have. --- bmusb | 2 +- flags.cpp | 15 +-------------- flags.h | 1 - mixer.cpp | 49 +++++++++++++++++++++---------------------------- 4 files changed, 23 insertions(+), 44 deletions(-) diff --git a/bmusb b/bmusb index 8e0a25a..d53ab27 160000 --- a/bmusb +++ b/bmusb @@ -1 +1 @@ -Subproject commit 8e0a25a2663844905f3daf8fcf9bf9ec995d1074 +Subproject commit d53ab27c6945636a8031e1868c503adeb7dad557 diff --git a/flags.cpp b/flags.cpp index 5c57df7..b48394e 100644 --- a/flags.cpp +++ b/flags.cpp @@ -49,8 +49,7 @@ void usage() fprintf(stderr, "Usage: nageru [OPTION]...\n"); fprintf(stderr, "\n"); fprintf(stderr, " -h, --help print usage information\n"); - fprintf(stderr, " -c, --num-cards set number of input cards, including fake cards (default 2)\n"); - fprintf(stderr, " -C, --num-fake-cards set number of fake cards (default 0)\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"); @@ -97,7 +96,6 @@ void parse_flags(int argc, char * const argv[]) static const option long_options[] = { { "help", no_argument, 0, 'h' }, { "num-cards", required_argument, 0, 'c' }, - { "num-fake-cards", required_argument, 0, 'C' }, { "theme", required_argument, 0, 't' }, { "theme-dir", required_argument, 0, 'I' }, { "map-signal", required_argument, 0, 'm' }, @@ -144,9 +142,6 @@ void parse_flags(int argc, char * const argv[]) case 'c': global_flags.num_cards = atoi(optarg); break; - case 'C': - global_flags.num_fake_cards = atoi(optarg); - break; case 't': global_flags.theme_filename = optarg; break; @@ -279,18 +274,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_fake_cards > global_flags.num_cards) { - fprintf(stderr, "ERROR: More fake cards then total cards makes no sense\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.num_fake_cards < 0) { - fprintf(stderr, "ERROR: --num-fake-cards cannot be negative\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"); diff --git a/flags.h b/flags.h index beddab7..f75ccd0 100644 --- a/flags.h +++ b/flags.h @@ -9,7 +9,6 @@ struct Flags { int num_cards = 2; - int num_fake_cards = 0; std::string va_display; bool uncompressed_video_to_http = false; bool x264_video_to_http = false; diff --git a/mixer.cpp b/mixer.cpp index ff1f83c..fd33abb 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -168,24 +168,12 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards) // Start listening for clients only once VideoEncoder has written its header, if any. httpd.start(9095); - // First try initializing the fake devices, then PCI devices, then USB, - // until we have the desired number of cards. - unsigned num_pci_devices = 0, num_usb_devices = 0; + // First try initializing the then PCI devices, then USB, then + // fill up with fake cards until we have the desired number of cards. + unsigned num_pci_devices = 0; unsigned card_index = 0; - assert(global_flags.num_fake_cards >= 0); // Enforced in flags.cpp. - unsigned num_fake_cards = global_flags.num_fake_cards; - - assert(num_fake_cards <= num_cards); // Enforced in flags.cpp. - for ( ; card_index < num_fake_cards; ++card_index) { - configure_card(card_index, new FakeCapture(WIDTH, HEIGHT, FAKE_FPS, OUTPUT_FREQUENCY, card_index), /*is_fake_capture=*/true); - } - - if (global_flags.num_fake_cards > 0) { - fprintf(stderr, "Initialized %d fake cards.\n", global_flags.num_fake_cards); - } - - if (card_index < num_cards) { + { IDeckLinkIterator *decklink_iterator = CreateDeckLinkIteratorInstance(); if (decklink_iterator != nullptr) { for ( ; card_index < num_cards; ++card_index) { @@ -194,28 +182,35 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards) break; } - configure_card(card_index, new DeckLinkCapture(decklink, card_index - num_fake_cards), /*is_fake_capture=*/false); + configure_card(card_index, new DeckLinkCapture(decklink, card_index), /*is_fake_capture=*/false); ++num_pci_devices; } decklink_iterator->Release(); - fprintf(stderr, "Found %d DeckLink PCI card(s).\n", num_pci_devices); + fprintf(stderr, "Found %u DeckLink PCI card(s).\n", num_pci_devices); } else { fprintf(stderr, "DeckLink drivers not found. Probing for USB cards only.\n"); } } - for ( ; card_index < num_cards; ++card_index) { - BMUSBCapture *capture = new BMUSBCapture(card_index - num_pci_devices - num_fake_cards); + unsigned num_usb_devices = BMUSBCapture::num_cards(); + for (unsigned usb_card_index = 0; usb_card_index < num_usb_devices && card_index < num_cards; ++usb_card_index, ++card_index) { + BMUSBCapture *capture = new BMUSBCapture(usb_card_index); capture->set_card_disconnected_callback(bind(&Mixer::bm_hotplug_remove, this, card_index)); configure_card(card_index, capture, /*is_fake_capture=*/false); - ++num_usb_devices; + } + fprintf(stderr, "Found %u USB card(s).\n", num_usb_devices); + + unsigned num_fake_cards = 0; + for ( ; card_index < num_cards; ++card_index, ++num_fake_cards) { + configure_card(card_index, new FakeCapture(WIDTH, HEIGHT, FAKE_FPS, OUTPUT_FREQUENCY, card_index), /*is_fake_capture=*/true); } - if (num_usb_devices > 0) { - has_bmusb_thread = true; - BMUSBCapture::set_card_connected_callback(bind(&Mixer::bm_hotplug_add, this, _1)); - BMUSBCapture::start_bm_thread(); + if (num_fake_cards > 0) { + fprintf(stderr, "Initialized %u fake cards.\n", num_fake_cards); } + BMUSBCapture::set_card_connected_callback(bind(&Mixer::bm_hotplug_add, this, _1)); + BMUSBCapture::start_bm_thread(); + for (card_index = 0; card_index < num_cards; ++card_index) { cards[card_index].queue_length_policy.reset(card_index); cards[card_index].capture->start_bm_capture(); @@ -289,9 +284,7 @@ Mixer::~Mixer() { resource_pool->release_glsl_program(cbcr_program_num); glDeleteBuffers(1, &cbcr_vbo); - if (has_bmusb_thread) { - BMUSBCapture::stop_bm_thread(); - } + BMUSBCapture::stop_bm_thread(); for (unsigned card_index = 0; card_index < num_cards; ++card_index) { { -- 2.39.2