]> git.sesse.net Git - nageru/commitdiff
Newer drivers can seemingly send completions out-of-order on shutdown, so adjust...
authorSteinar H. Gunderson <steinar+nageru@gunderson.no>
Sat, 2 Oct 2021 14:12:24 +0000 (16:12 +0200)
committerSteinar H. Gunderson <steinar+nageru@gunderson.no>
Sat, 2 Oct 2021 14:12:24 +0000 (16:12 +0200)
nageru/decklink_output.cpp
nageru/decklink_output.h

index fc8de57db9172f3071f140017102e30ea3f2df0f..5cf3abf5f391f6c301e51f6378256aad87cae8a4 100644 (file)
@@ -501,8 +501,8 @@ HRESULT DeckLinkOutput::ScheduledFrameCompleted(/* in */ IDeckLinkVideoFrame *co
        {
                lock_guard<mutex> lock(frame_queue_mutex);
                frame_freelist.push(unique_ptr<Frame>(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<mutex> 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);
index 8213f498a9d0677df7fe77b928acc7dce8951825..f008dc3b32bec8f0c1aba542c4d3de3a8167b047 100644 (file)
@@ -12,6 +12,7 @@
 #include <mutex>
 #include <queue>
 #include <thread>
+#include <unordered_set>
 #include <vector>
 
 #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<std::unique_ptr<Frame>> pending_video_frames;  // Under <frame_queue_mutex>.
        std::queue<std::unique_ptr<Frame>> frame_freelist;  // Under <frame_queue_mutex>.
-       std::deque<Frame *> scheduled_frames;  // Owned by the driver, so no unique_ptr. Under <frame_queue_mutex>.
+       std::unordered_set<Frame *> scheduled_frames;  // Owned by the driver, so no unique_ptr. Under <frame_queue_mutex>.
 
        std::condition_variable frame_queues_changed;
        bool playback_initiated = false, playback_started = false;