+ if (!running) {
+ return;
+ }
+ HRESULT result = input->StopStreams();
+ if (result != S_OK) {
+ fprintf(stderr, "StopStreams failed with error 0x%x\n", result);
+ 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, so StopStreams() will suffice.
+
+ running = false;
+}
+
+void DeckLinkCapture::set_video_mode(uint32_t video_mode_id)
+{
+ if (running) {
+ if (input->PauseStreams() != S_OK) {
+ fprintf(stderr, "PauseStreams failed\n");
+ exit(1);
+ }
+ if (input->FlushStreams() != S_OK) {
+ fprintf(stderr, "FlushStreams failed\n");
+ exit(1);
+ }
+ }
+
+ set_video_mode_no_restart(video_mode_id);
+
+ if (running) {
+ if (input->StartStreams() != S_OK) {
+ fprintf(stderr, "StartStreams failed\n");
+ exit(1);
+ }
+ }
+}
+
+void DeckLinkCapture::set_pixel_format(PixelFormat pixel_format)
+{
+ current_pixel_format = pixel_format;
+ set_video_mode(current_video_mode);
+}
+
+void DeckLinkCapture::set_video_mode_no_restart(uint32_t video_mode_id)
+{
+ BMDDisplayModeSupport support;
+ IDeckLinkDisplayMode *display_mode;
+ if (input->DoesSupportVideoMode(video_mode_id, pixel_format_to_bmd(current_pixel_format), /*flags=*/0, &support, &display_mode)) {
+ fprintf(stderr, "Failed to query display mode for card %d\n", card_index);
+ exit(1);
+ }
+
+ if (support == bmdDisplayModeNotSupported) {
+ fprintf(stderr, "Card %d does not support display mode\n", card_index);
+ exit(1);
+ }
+
+ if (display_mode->GetFrameRate(&frame_duration, &time_scale) != S_OK) {
+ fprintf(stderr, "Could not get frame rate for card %d\n", card_index);
+ exit(1);
+ }
+
+ field_dominance = display_mode->GetFieldDominance();
+
+ if (running) {
+ if (input->EnableVideoInput(video_mode_id, pixel_format_to_bmd(current_pixel_format), supports_autodetect ? bmdVideoInputEnableFormatDetection : 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;
+}
+
+void DeckLinkCapture::set_video_input(uint32_t video_input_id)
+{
+ if (config->SetInt(bmdDeckLinkConfigVideoInputConnection, video_input_id) != S_OK) {
+ fprintf(stderr, "Failed to set video input connection for card %d\n", card_index);