diff --git a/shared/DeckLinkReceiver.hpp b/shared/DeckLinkReceiver.hpp index c463fe5..0f4c8f9 100644 --- a/shared/DeckLinkReceiver.hpp +++ b/shared/DeckLinkReceiver.hpp @@ -142,16 +142,20 @@ private: IDeckLinkAudioInputPacket* /*audio_packet*/) override { if (!video_frame) return S_OK; + + IDeckLinkVideoBuffer* buf = nullptr; + if (video_frame->QueryInterface(IID_IDeckLinkVideoBuffer, (void**)&buf) != S_OK) + return S_OK; + buf->StartAccess(bmdBufferAccessRead); void* src = nullptr; - video_frame->GetBytes(&src); - if (!src) return S_OK; + buf->GetBytes(&src); - const uint32_t row_bytes = static_cast(video_frame->GetRowBytes()); - const int fw = static_cast(video_frame->GetWidth()); - const int fh = static_cast(video_frame->GetHeight()); - const size_t sz = static_cast(row_bytes) * static_cast(fh); + if (src) { + const uint32_t row_bytes = static_cast(video_frame->GetRowBytes()); + const int fw = static_cast(video_frame->GetWidth()); + const int fh = static_cast(video_frame->GetHeight()); + const size_t sz = static_cast(row_bytes) * static_cast(fh); - { std::lock_guard lk(owner.mutex); if (owner.frame_buffer.size() < sz) owner.frame_buffer.resize(sz); std::memcpy(owner.frame_buffer.data(), src, sz); @@ -160,7 +164,10 @@ private: owner.frame_height = fh; owner.frame_ready = true; } - owner.frame_cv.notify_one(); + + buf->EndAccess(bmdBufferAccessRead); + buf->Release(); + if (src) owner.frame_cv.notify_one(); return S_OK; }