]> git.sesse.net Git - nageru/commitdiff
Make for cleaner on/off transitions in DeckLinkCapture.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 14 Jan 2017 10:32:17 +0000 (11:32 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 15 Jan 2017 21:04:41 +0000 (22:04 +0100)
decklink_capture.cpp
decklink_capture.h

index 5e41da436ef71b0920495e38137390661f4b09fb..2df01aa2dab80a069eb087bfa12b8365dd35a2b2 100644 (file)
@@ -254,11 +254,6 @@ DeckLinkCapture::DeckLinkCapture(IDeckLink *card, int card_index)
 
        set_video_mode_no_restart(bmdModeHD720p5994);
 
-       if (input->EnableAudioInput(48000, bmdAudioSampleType32bitInteger, 2) != S_OK) {
-               fprintf(stderr, "Failed to enable audio input for card %d\n", card_index);
-               exit(1);
-       }
-
        input->SetCallback(this);
 }
 
@@ -404,18 +399,44 @@ void DeckLinkCapture::configure_card()
 
 void DeckLinkCapture::start_bm_capture()
 {
+       if (running) {
+               return;
+       }
+       if (input->EnableVideoInput(current_video_mode, bmdFormat8BitYUV, 0) != S_OK) {
+               fprintf(stderr, "Failed to set video mode 0x%04x for card %d\n", current_video_mode, card_index);
+               exit(1);
+       }
+       if (input->EnableAudioInput(48000, bmdAudioSampleType32bitInteger, 2) != S_OK) {
+               fprintf(stderr, "Failed to enable audio input for card %d\n", card_index);
+               exit(1);
+       }
+
        if (input->StartStreams() != S_OK) {
                fprintf(stderr, "StartStreams failed\n");
                exit(1);
        }
+       running = true;
 }
 
 void DeckLinkCapture::stop_dequeue_thread()
 {
-       if (input->StopStreams() != S_OK) {
-               fprintf(stderr, "StopStreams failed\n");
+       if (!running) {
+               return;
+       }
+       HRESULT result = input->StopStreams();
+       if (result != S_OK) {
+               fprintf(stderr, "StopStreams failed with error 0x%x\n", result);
+               exit(1);
+       }
+       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);
+       }
+       running = false;
 }
 
 void DeckLinkCapture::set_video_mode(uint32_t video_mode_id)
@@ -452,9 +473,11 @@ void DeckLinkCapture::set_video_mode_no_restart(uint32_t video_mode_id)
                exit(1);
        }
 
-       if (input->EnableVideoInput(video_mode_id, bmdFormat8BitYUV, 0) != S_OK) {
-               fprintf(stderr, "Failed to set video mode 0x%04x for card %d\n", video_mode_id, card_index);
-               exit(1);
+       if (running) {
+               if (input->EnableVideoInput(video_mode_id, bmdFormat8BitYUV, 0) != S_OK) {
+                       fprintf(stderr, "Failed to set video mode 0x%04x for card %d\n", video_mode_id, card_index);
+                       exit(1);
+               }
        }
 
        current_video_mode = video_mode_id;
index 05eb4a8d29a027b2e5725a93710b8b80b16219c5..aac403fa666b655a3ed9fb7aea777dad30fc9444 100644 (file)
@@ -126,6 +126,7 @@ private:
        IDeckLinkInput *input = nullptr;
        BMDTimeValue frame_duration;
        BMDTimeScale time_scale;
+       bool running = false;
 
        std::map<uint32_t, bmusb::VideoMode> video_modes;
        BMDDisplayMode current_video_mode;