]> git.sesse.net Git - nageru/blobdiff - decklink_output.cpp
Make for clean shutdown of the output cards.
[nageru] / decklink_output.cpp
index 46d9b140cb9214e5940e78c5a4656770769a8c00..c5bf96b3a0c404f0f448535d5da3fd3a286641c1 100644 (file)
@@ -52,13 +52,21 @@ void DeckLinkOutput::set_device(IDeckLink *decklink)
        }
 
        mode_it->Release();
+
+       // HDMI or SDI generally mean “both HDMI and SDI at the same time” on DeckLink cards
+       // that support both; pick_default_video_connection() will generally pick one of those
+       // if they exist. We're not very likely to need analog outputs, so we don't need a way
+       // to change beyond that.
+       video_connection = pick_default_video_connection(decklink, BMDDeckLinkVideoOutputConnections, card_index);
 }
 
 void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts)
 {
        assert(output);
+       assert(!playback_initiated);
 
        should_quit = false;
+       playback_initiated = true;
        playback_started = false;
        this->base_pts = base_pts;
 
@@ -71,9 +79,7 @@ void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts)
                fprintf(stderr, "Failed to set low latency output\n");
                exit(1);
        }
-       // HDMI or SDI generally mean “both HDMI and SDI at the same time” on DeckLink cards.
-       // We're not very likely to need analog outputs.
-       if (config->SetInt(bmdDeckLinkConfigVideoOutputConnection, bmdVideoConnectionHDMI) != S_OK) {
+       if (config->SetInt(bmdDeckLinkConfigVideoOutputConnection, video_connection) != S_OK) {
                fprintf(stderr, "Failed to set video output connection for card %u\n", card_index);
                exit(1);
        }
@@ -149,9 +155,14 @@ void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts)
 
 void DeckLinkOutput::end_output()
 {
+       if (!playback_initiated) {
+               return;
+       }
+
        should_quit = true;
        frame_queues_changed.notify_all();
        present_thread.join();
+       playback_initiated = false;
 
        output->StopScheduledPlayback(0, nullptr, 0);
        output->DisableVideoOutput();