]> git.sesse.net Git - nageru/blobdiff - decklink_capture.cpp
Add a menu entry to go to the online manual.
[nageru] / decklink_capture.cpp
index 892660da09eb64793c8f1490baf5368ace61c31d..d38cc73a3ae432f62d9c368f766a74861f17622b 100644 (file)
@@ -8,6 +8,7 @@
 #ifdef __SSE2__
 #include <immintrin.h>
 #endif
+#include <pthread.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -205,6 +206,22 @@ DeckLinkCapture::DeckLinkCapture(IDeckLink *card, int card_index)
                }
        }
 
+       // Check if we the card supports input autodetection.
+       if (attr->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &supports_autodetect) != S_OK) {
+               fprintf(stderr, "Warning: Failed to ask card %d whether it supports input format autodetection\n", card_index);
+               supports_autodetect = false;
+       }
+
+       // If there's more than one subdevice on this card, label them.
+       int64_t num_subdevices, subdevice_idx;
+       if (attr->GetInt(BMDDeckLinkNumberOfSubDevices, &num_subdevices) == S_OK && num_subdevices > 1) {
+               if (attr->GetInt(BMDDeckLinkSubDeviceIndex, &subdevice_idx) == S_OK) {
+                       char buf[256];
+                       snprintf(buf, sizeof(buf), " (subdevice %d)", int(subdevice_idx));
+                       description += buf;
+               }
+       }
+
        attr->Release();
 
        /* Set up the video and audio sources. */
@@ -263,8 +280,15 @@ ULONG STDMETHODCALLTYPE DeckLinkCapture::Release(void)
 HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFormatChanged(
        BMDVideoInputFormatChangedEvents,
        IDeckLinkDisplayMode* display_mode,
-       BMDDetectedVideoInputFormatFlags)
+       BMDDetectedVideoInputFormatFlags format_flags)
 {
+       if (format_flags & bmdDetectedVideoInputRGB444) {
+               fprintf(stderr, "WARNING: Input detected as 4:4:4 RGB, but Nageru can't consume that yet.\n");
+               fprintf(stderr, "Doing hardware conversion to 4:2:2 Y'CbCr.\n");
+       }
+       if (supports_autodetect && display_mode->GetDisplayMode() != current_video_mode) {
+               set_video_mode(display_mode->GetDisplayMode());
+       }
        if (display_mode->GetFrameRate(&frame_duration, &time_scale) != S_OK) {
                fprintf(stderr, "Could not get new frame rate\n");
                exit(1);
@@ -278,6 +302,9 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived(
        IDeckLinkAudioInputPacket *audio_frame)
 {
        if (!done_init) {
+               char thread_name[16];
+               snprintf(thread_name, sizeof(thread_name), "DeckLink_C_%d", card_index);
+               pthread_setname_np(pthread_self(), thread_name);
                if (has_dequeue_callbacks) {
                        dequeue_init_callback();
                }
@@ -381,7 +408,7 @@ void DeckLinkCapture::start_bm_capture()
        if (running) {
                return;
        }
-       if (input->EnableVideoInput(current_video_mode, bmdFormat8BitYUV, 0) != S_OK) {
+       if (input->EnableVideoInput(current_video_mode, bmdFormat8BitYUV, supports_autodetect ? bmdVideoInputEnableFormatDetection : 0) != S_OK) {
                fprintf(stderr, "Failed to set video mode 0x%04x for card %d\n", current_video_mode, card_index);
                exit(1);
        }
@@ -420,8 +447,12 @@ void DeckLinkCapture::stop_dequeue_thread()
 
 void DeckLinkCapture::set_video_mode(uint32_t video_mode_id)
 {
-       if (input->StopStreams() != S_OK) {
-               fprintf(stderr, "StopStreams failed\n");
+       if (input->PauseStreams() != S_OK) {
+               fprintf(stderr, "PauseStreams failed\n");
+               exit(1);
+       }
+       if (input->FlushStreams() != S_OK) {
+               fprintf(stderr, "FlushStreams failed\n");
                exit(1);
        }
 
@@ -455,7 +486,7 @@ void DeckLinkCapture::set_video_mode_no_restart(uint32_t video_mode_id)
        field_dominance = display_mode->GetFieldDominance();
 
        if (running) {
-               if (input->EnableVideoInput(video_mode_id, bmdFormat8BitYUV, 0) != S_OK) {
+               if (input->EnableVideoInput(video_mode_id, bmdFormat8BitYUV, 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);
                }