From a823a1f7d9f454913044ff8e0e17acbc73f86316 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 2 Oct 2021 16:12:24 +0200 Subject: [PATCH] Newer drivers can seemingly send completions out-of-order on shutdown, so adjust asserts accordingly. --- nageru/decklink_output.cpp | 6 +++--- nageru/decklink_output.h | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/nageru/decklink_output.cpp b/nageru/decklink_output.cpp index fc8de57..5cf3abf 100644 --- a/nageru/decklink_output.cpp +++ b/nageru/decklink_output.cpp @@ -501,8 +501,8 @@ HRESULT DeckLinkOutput::ScheduledFrameCompleted(/* in */ IDeckLinkVideoFrame *co { lock_guard lock(frame_queue_mutex); frame_freelist.push(unique_ptr(frame)); - assert(scheduled_frames.front() == frame); - scheduled_frames.pop_front(); + assert(scheduled_frames.count(frame)); + scheduled_frames.erase(frame); --metric_decklink_output_inflight_frames; } @@ -600,7 +600,7 @@ void DeckLinkOutput::present_thread_func() HRESULT res = output->ScheduleVideoFrame(frame.get(), pts, duration, TIMEBASE); lock_guard lock(frame_queue_mutex); if (res == S_OK) { - scheduled_frames.push_back(frame.release()); // Owned by the driver now. + scheduled_frames.insert(frame.release()); // Owned by the driver now. ++metric_decklink_output_inflight_frames; } else { fprintf(stderr, "Could not schedule video frame! (error=0x%08x)\n", res); diff --git a/nageru/decklink_output.h b/nageru/decklink_output.h index 8213f49..f008dc3 100644 --- a/nageru/decklink_output.h +++ b/nageru/decklink_output.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "DeckLinkAPI.h" @@ -38,6 +39,7 @@ class QSurface; class DeckLinkOutput : public IDeckLinkVideoOutputCallback { public: DeckLinkOutput(movit::ResourcePool *resource_pool, QSurface *surface, unsigned width, unsigned height, unsigned card_index); + ~DeckLinkOutput(); // The IDecklinkInput argument is to work around a bug // in the 11.7 and newer drivers against older SDKs, @@ -138,7 +140,7 @@ private: std::mutex frame_queue_mutex; std::queue> pending_video_frames; // Under . std::queue> frame_freelist; // Under . - std::deque scheduled_frames; // Owned by the driver, so no unique_ptr. Under . + std::unordered_set scheduled_frames; // Owned by the driver, so no unique_ptr. Under . std::condition_variable frame_queues_changed; bool playback_initiated = false, playback_started = false; -- 2.39.2