From f2c703f883d511cdf850de0d69902a820f371237 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 3 Jun 2020 23:45:02 +0200 Subject: [PATCH] Skip DeckLink cards marked as inactive. This prevents a crash on startup with e.g. Duo 2 in the default mode, which disables connectors 3 and 4 by default (well, uses them for dual link). --- nageru/decklink_util.cpp | 19 +++++++++++++++++++ nageru/decklink_util.h | 2 ++ nageru/mixer.cpp | 7 +++++++ 3 files changed, 28 insertions(+) diff --git a/nageru/decklink_util.cpp b/nageru/decklink_util.cpp index 33a7933..c2ebd57 100644 --- a/nageru/decklink_util.cpp +++ b/nageru/decklink_util.cpp @@ -90,3 +90,22 @@ BMDVideoConnection pick_default_video_connection(IDeckLink *card, BMDDeckLinkAtt return connection_mask & (-connection_mask); } } + +bool decklink_card_is_active(IDeckLink *card, unsigned card_index) +{ + IDeckLinkStatus *status; + if (card->QueryInterface(IID_IDeckLinkStatus, (void**)&status) != S_OK) { + fprintf(stderr, "Card %u has no status interface\n", card_index); + abort(); + } + + int64_t duplex_mode; + if (status->GetInt(bmdDeckLinkStatusDuplexMode, &duplex_mode) != S_OK) { + fprintf(stderr, "Could not query duplex mode for card %u\n", card_index); + abort(); + } + + status->Release(); + + return (duplex_mode != bmdDuplexStatusInactive); +} diff --git a/nageru/decklink_util.h b/nageru/decklink_util.h index 2850a21..cbc012a 100644 --- a/nageru/decklink_util.h +++ b/nageru/decklink_util.h @@ -14,4 +14,6 @@ std::map summarize_video_modes(IDeckLinkDisplayModeI // Picks a video connection that the card supports. Priority list: HDMI, SDI, anything else. BMDVideoConnection pick_default_video_connection(IDeckLink *card, BMDDeckLinkAttributeID attribute_id, unsigned card_index); +bool decklink_card_is_active(IDeckLink *card, unsigned card_index); + #endif // !defined(_DECKLINK_UTIL) diff --git a/nageru/mixer.cpp b/nageru/mixer.cpp index 5df80df..80fcb64 100644 --- a/nageru/mixer.cpp +++ b/nageru/mixer.cpp @@ -41,6 +41,7 @@ #include "shared/context.h" #include "decklink_capture.h" #include "decklink_output.h" +#include "decklink_util.h" #include "defs.h" #include "shared/disk_space_estimator.h" #include "ffmpeg_capture.h" @@ -410,6 +411,12 @@ Mixer::Mixer(const QSurfaceFormat &format) break; } + if (!decklink_card_is_active(decklink, card_index)) { + fprintf(stderr, "DeckLink card %u is inactive in current profile, skipping (try changing it in Desktop Video Setup)\n", card_index); + decklink->Release(); + continue; + } + DeckLinkCapture *capture = new DeckLinkCapture(decklink, card_index); DeckLinkOutput *output = new DeckLinkOutput(resource_pool.get(), decklink_output_surface, global_flags.width, global_flags.height, card_index); if (!output->set_device(decklink)) { -- 2.39.2