X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fdecklink_output.cpp;fp=nageru%2Fdecklink_output.cpp;h=da172af686acbc3ff7acf489a7befd01a2efb2f7;hb=cd1b6b6b8dd3d4d6f52d917cec3e5a152f87e822;hp=00d80432564c569f437a0817e3dafc22a9a3c37d;hpb=b9a74fdb2aaaec5f2859945f25bff9295da444e1;p=nageru diff --git a/nageru/decklink_output.cpp b/nageru/decklink_output.cpp index 00d8043..da172af 100644 --- a/nageru/decklink_output.cpp +++ b/nageru/decklink_output.cpp @@ -255,7 +255,7 @@ void DeckLinkOutput::end_output() // Wait until all frames are accounted for, and free them. { unique_lock lock(frame_queue_mutex); - while (!(frame_freelist.empty() && num_frames_in_flight == 0)) { + while (!(frame_freelist.empty() && scheduled_frames.empty())) { frame_queues_changed.wait(lock, [this]{ return !frame_freelist.empty(); }); frame_freelist.pop(); } @@ -503,7 +503,8 @@ HRESULT DeckLinkOutput::ScheduledFrameCompleted(/* in */ IDeckLinkVideoFrame *co { lock_guard lock(frame_queue_mutex); frame_freelist.push(unique_ptr(frame)); - --num_frames_in_flight; + assert(scheduled_frames.front() == frame); + scheduled_frames.pop_front(); --metric_decklink_output_inflight_frames; } @@ -573,8 +574,6 @@ void DeckLinkOutput::present_thread_func() } frame = move(pending_video_frames.front()); pending_video_frames.pop(); - ++num_frames_in_flight; - ++metric_decklink_output_inflight_frames; } for ( ;; ) { @@ -601,15 +600,14 @@ void DeckLinkOutput::present_thread_func() BMDTimeValue pts = frame->pts; BMDTimeValue duration = frame->duration; HRESULT res = output->ScheduleVideoFrame(frame.get(), pts, duration, TIMEBASE); + lock_guard lock(frame_queue_mutex); if (res == S_OK) { - frame.release(); // Owned by the driver now. + scheduled_frames.push_back(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); - lock_guard lock(frame_queue_mutex); frame_freelist.push(move(frame)); - --num_frames_in_flight; - --metric_decklink_output_inflight_frames; } } }