]> git.sesse.net Git - nageru/blobdiff - nageru/decklink_output.cpp
Yet another crash fix in changing output cards.
[nageru] / nageru / decklink_output.cpp
index 20de9229fdc35e42502626c40b571f5741150f4c..56a184e99b326cc6ab3107c985f59bf0345bd384 100644 (file)
@@ -82,9 +82,16 @@ DeckLinkOutput::DeckLinkOutput(ResourcePool *resource_pool, QSurface *surface, u
        });
 }
 
+DeckLinkOutput::~DeckLinkOutput()
+{
+       if (output != nullptr) {
+               output->Release();
+       }
+}
+
 bool DeckLinkOutput::set_device(IDeckLink *decklink, IDeckLinkInput *input_arg)
 {
-       input_arg = input;
+       input = input_arg;
        if (decklink->QueryInterface(IID_IDeckLinkOutput, (void**)&output) != S_OK) {
                fprintf(stderr, "Warning: Card %u has no outputs\n", card_index);
                return false;
@@ -258,15 +265,6 @@ void DeckLinkOutput::end_output()
                        frame_freelist.pop();
                }
        }
-
-       if (input != nullptr) {
-               input->Release();
-               input = nullptr;
-       }
-       if (output != nullptr) {
-               output->Release();
-               output = nullptr;
-       }
 }
 
 void DeckLinkOutput::send_frame(GLuint y_tex, GLuint cbcr_tex, YCbCrLumaCoefficients output_ycbcr_coefficients, const vector<RefCountedFrame> &input_frames, int64_t pts, int64_t duration)
@@ -501,8 +499,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 +598,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);