From 9a0f617093e7cde02a824b90f82f129c47193939 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 29 Mar 2020 14:33:32 +0200 Subject: [PATCH] Reintroduce faster DeckLink shutdown; now with a fix for the UI switcher. --- nageru/decklink_capture.cpp | 14 ++++++-------- nageru/decklink_output.cpp | 16 ++++++++++++++++ nageru/decklink_output.h | 1 + 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/nageru/decklink_capture.cpp b/nageru/decklink_capture.cpp index eefb537..6ccbadc 100644 --- a/nageru/decklink_capture.cpp +++ b/nageru/decklink_capture.cpp @@ -350,14 +350,12 @@ void DeckLinkCapture::stop_dequeue_thread() fprintf(stderr, "StopStreams failed with error 0x%x\n", result); abort(); } - if (input->DisableVideoInput() != S_OK) { - fprintf(stderr, "Failed to disable video input for card %d\n", card_index); - exit(1); - } - if (input->DisableAudioInput() != S_OK) { - fprintf(stderr, "Failed to disable audio input for card %d\n", card_index); - exit(1); - } + + // We could call DisableVideoInput() and DisableAudioInput() here, + // but they seem to be taking a really long time, and we only do this + // during shutdown anyway (except when switching to output mode, + // where DeckLinkOutput does the disabling), so StopStreams() will suffice. + running = false; } diff --git a/nageru/decklink_output.cpp b/nageru/decklink_output.cpp index 6b21edb..f1e06e8 100644 --- a/nageru/decklink_output.cpp +++ b/nageru/decklink_output.cpp @@ -84,6 +84,9 @@ DeckLinkOutput::DeckLinkOutput(ResourcePool *resource_pool, QSurface *surface, u bool DeckLinkOutput::set_device(IDeckLink *decklink) { + if (decklink->QueryInterface(IID_IDeckLinkInput, (void**)&input) != S_OK) { + input = nullptr; + } if (decklink->QueryInterface(IID_IDeckLinkOutput, (void**)&output) != S_OK) { fprintf(stderr, "Warning: Card %u has no outputs\n", card_index); return false; @@ -193,6 +196,15 @@ void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts) display_mode->Release(); + if (input != nullptr) { + if (input->DisableVideoInput() != S_OK) { + fprintf(stderr, "Warning: Failed to disable video input for card %d\n", card_index); + } + if (input->DisableAudioInput() != S_OK) { + fprintf(stderr, "Warning: Failed to disable audio input for card %d\n", card_index); + } + } + HRESULT result = output->EnableVideoOutput(mode, bmdVideoOutputFlagDefault); if (result != S_OK) { fprintf(stderr, "Couldn't enable output with error 0x%x\n", result); @@ -249,6 +261,10 @@ void DeckLinkOutput::end_output() } } + if (input != nullptr) { + input->Release(); + input = nullptr; + } if (output != nullptr) { output->Release(); output = nullptr; diff --git a/nageru/decklink_output.h b/nageru/decklink_output.h index 90b89a2..2c07bc7 100644 --- a/nageru/decklink_output.h +++ b/nageru/decklink_output.h @@ -141,6 +141,7 @@ private: bool last_frame_had_mode_mismatch = false; movit::ResourcePool *resource_pool; + IDeckLinkInput *input = nullptr; IDeckLinkOutput *output = nullptr; BMDVideoConnection video_connection; QSurface *surface; -- 2.39.2