]> git.sesse.net Git - nageru/blobdiff - nageru/decklink_capture.cpp
Fix a Clang 19 warning.
[nageru] / nageru / decklink_capture.cpp
index ab5e1ec818f720c6fba4dc35935c1986df1aaaba..90d86b15dd580f0fe73d96148fa4f728ff280c9f 100644 (file)
@@ -1,10 +1,16 @@
 #include "decklink_capture.h"
+#include "defs.h"
 
 #include <DeckLinkAPI.h>
 #include <DeckLinkAPIConfiguration.h>
 #include <DeckLinkAPIDiscovery.h>
 #include <DeckLinkAPIModes.h>
+#include <DeckLinkAPITypes.h>
+#include <LinuxCOM.h>
 #include <assert.h>
+#include <errno.h>
+#include <sched.h>
+#include <string>
 #ifdef __SSE2__
 #include <immintrin.h>
 #endif
@@ -24,8 +30,6 @@
 #include "shared/memcpy_interleaved.h"
 #include "v210_converter.h"
 
-#define FRAME_SIZE (8 << 20)  // 8 MB.
-
 using namespace std;
 using namespace std::chrono;
 using namespace std::placeholders;
@@ -246,13 +250,20 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived(
                const int stride = video_frame->GetRowBytes();
                const BMDPixelFormat format = video_frame->GetPixelFormat();
                assert(format == pixel_format_to_bmd(current_pixel_format));
-               if (global_flags.ten_bit_input) {
+               if (global_flags.bit_depth > 8) {
                        assert(stride == int(v210Converter::get_v210_stride(width)));
                } else {
                        assert(stride == width * 2);
                }
 
-               current_video_frame = video_frame_allocator->create_frame(width, height, stride);
+               if (width * stride > FRAME_SIZE) {
+                       // TODO: If we had an OpenGL context here, calling create_frame()
+                       // would be completely fine.
+                       fprintf(stderr, "Card %u: Captured frame %d x %d (stride %d) would be larger than supported frame size (%d > %d), skipping.\n",
+                               card_index, width, height, stride, width * stride, FRAME_SIZE);
+               } else {
+                       current_video_frame = video_frame_allocator->create_frame(width, height, stride);
+               }
                if (current_video_frame.data != nullptr) {
                        const uint8_t *src;
                        video_frame->GetBytes((void **)&src);
@@ -283,12 +294,12 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived(
                if (current_audio_frame.data != nullptr) {
                        const uint8_t *src;
                        audio_frame->GetBytes((void **)&src);
-                       current_audio_frame.len = sizeof(int32_t) * 2 * num_samples;
+                       current_audio_frame.len = sizeof(int32_t) * 8 * num_samples;
 
                        memcpy(current_audio_frame.data, src, current_audio_frame.len);
 
                        audio_format.bits_per_sample = 32;
-                       audio_format.num_channels = 2;
+                       audio_format.num_channels = 8;
                }
        }
 
@@ -328,7 +339,7 @@ void DeckLinkCapture::start_bm_capture()
                fprintf(stderr, "Failed to set video mode 0x%04x for card %d\n", current_video_mode, card_index);
                abort();
        }
-       if (input->EnableAudioInput(48000, bmdAudioSampleType32bitInteger, 2) != S_OK) {
+       if (input->EnableAudioInput(48000, bmdAudioSampleType32bitInteger, 8) != S_OK) {
                fprintf(stderr, "Failed to enable audio input for card %d\n", card_index);
                abort();
        }
@@ -353,7 +364,8 @@ void DeckLinkCapture::stop_dequeue_thread()
 
        // 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.
+       // during shutdown anyway (except when switching to output mode,
+       // where DeckLinkOutput does the disabling), so StopStreams() will suffice.
 
        running = false;
 }