diff --git a/app/streaming/video/ffmpeg-renderers/pacer/pacer.cpp b/app/streaming/video/ffmpeg-renderers/pacer/pacer.cpp index b7f43011..45552db7 100644 --- a/app/streaming/video/ffmpeg-renderers/pacer/pacer.cpp +++ b/app/streaming/video/ffmpeg-renderers/pacer/pacer.cpp @@ -137,7 +137,7 @@ void Pacer::submitFrame(AVFrame* frame) // Queue the frame until the V-sync callback if // we have a V-sync source, otherwise deliver it // immediately and hope for the best. - if (m_VsyncSource != nullptr) { + if (isUsingFrameQueue()) { SDL_AtomicLock(&m_FrameQueueLock); m_FrameQueue.enqueue(frame); SDL_AtomicUnlock(&m_FrameQueueLock); @@ -147,3 +147,8 @@ void Pacer::submitFrame(AVFrame* frame) av_frame_free(&frame); } } + +bool Pacer::isUsingFrameQueue() +{ + return m_VsyncSource != nullptr; +} diff --git a/app/streaming/video/ffmpeg-renderers/pacer/pacer.h b/app/streaming/video/ffmpeg-renderers/pacer/pacer.h index 6d66bff3..6b1b0f11 100644 --- a/app/streaming/video/ffmpeg-renderers/pacer/pacer.h +++ b/app/streaming/video/ffmpeg-renderers/pacer/pacer.h @@ -23,6 +23,8 @@ public: void vsyncCallback(); + bool isUsingFrameQueue(); + private: QQueue m_FrameQueue; QQueue m_FrameQueueHistory; diff --git a/app/streaming/video/ffmpeg.cpp b/app/streaming/video/ffmpeg.cpp index 97cfa3c2..ef5cf7b9 100644 --- a/app/streaming/video/ffmpeg.cpp +++ b/app/streaming/video/ffmpeg.cpp @@ -399,9 +399,15 @@ void FFmpegVideoDecoder::renderFrame(SDL_UserEvent* event) void FFmpegVideoDecoder::dropFrame(SDL_UserEvent* event) { AVFrame* frame = reinterpret_cast(event->data1); - // We should really call Pacer::submitFrame() here and let it - // take care of it, but that will regress frame dropping for - // clients without an IVsyncSource implementation. - av_frame_free(&frame); + // If Pacer is using a frame queue, we can just queue the + // frame and let it decide whether to drop or not. If Pacer + // is submitting directly for rendering, we drop the frame + // ourselves. + if (m_Pacer->isUsingFrameQueue()) { + m_Pacer->submitFrame(frame); + } + else { + av_frame_free(&frame); + } SDL_AtomicDecRef(&m_QueuedFrames); }