From fbbbd5e0b8c28794f9e663d7a91ff5778c7f5ddc Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 5 Oct 2022 00:53:31 -0500 Subject: [PATCH] Use new LiRequestIdrFrame() API --- app/streaming/session.cpp | 15 ++------------- app/streaming/session.h | 3 --- app/streaming/video/ffmpeg.cpp | 9 ++++----- moonlight-common-c/moonlight-common-c | 2 +- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index 1f26d330..0593f539 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -291,14 +291,9 @@ int Session::drSubmitDecodeUnit(PDECODE_UNIT du) // We need to destroy the decoder on the main thread to satisfy // some API constraints (like DXVA2). If we can't acquire it, // that means the decoder is about to be destroyed, so we can - // safely return DR_OK and wait for m_NeedsIdr to be set by + // safely return DR_OK and wait for the IDR frame request by // the decoder reinitialization code. - if (s_ActiveSession->getAndClearPendingIdrFrameStatus()) { - // If we reset our decoder, we'll need to request an IDR frame - return DR_NEED_IDR; - } - if (SDL_AtomicTryLock(&s_ActiveSession->m_DecoderLock)) { IVideoDecoder* decoder = s_ActiveSession->m_VideoDecoder; if (decoder != nullptr) { @@ -469,7 +464,6 @@ Session::Session(NvComputer* computer, NvApp& app, StreamingPreferences *prefere m_AudioSampleCount(0), m_DropAudioEndTime(0) { - SDL_AtomicSet(&m_NeedsIdr, 0); } bool Session::initialize() @@ -1266,11 +1260,6 @@ void Session::flushWindowEvents() SDL_PushEvent(&flushEvent); } -bool Session::getAndClearPendingIdrFrameStatus() -{ - return SDL_AtomicSet(&m_NeedsIdr, 0); -} - class ExecThread : public QThread { public: @@ -1746,7 +1735,7 @@ void Session::execInternal() } // Request an IDR frame to complete the reset - SDL_AtomicSet(&m_NeedsIdr, 1); + LiRequestIdrFrame(); // Set HDR mode. We may miss the callback if we're in the middle // of recreating our decoder at the time the HDR transition happens. diff --git a/app/streaming/session.h b/app/streaming/session.h index bf5bbfc9..646bb8a5 100644 --- a/app/streaming/session.h +++ b/app/streaming/session.h @@ -45,8 +45,6 @@ public: void flushWindowEvents(); - bool getAndClearPendingIdrFrameStatus(); - signals: void stageStarting(QString stage); @@ -156,7 +154,6 @@ private: SDL_Window* m_Window; IVideoDecoder* m_VideoDecoder; SDL_SpinLock m_DecoderLock; - SDL_atomic_t m_NeedsIdr; bool m_AudioDisabled; bool m_AudioMuted; Uint32 m_FullScreenFlag; diff --git a/app/streaming/video/ffmpeg.cpp b/app/streaming/video/ffmpeg.cpp index 7dba7041..9a71f083 100644 --- a/app/streaming/video/ffmpeg.cpp +++ b/app/streaming/video/ffmpeg.cpp @@ -1108,6 +1108,10 @@ void FFmpegVideoDecoder::decoderThreadProc() // Don't consume any additional data SDL_AtomicSet(&m_DecoderThreadShouldQuit, 1); } + + // Just in case the error resulted in the loss of the frame, + // request an IDR frame to reset our decoder state. + LiRequestIdrFrame(); } } while (err == AVERROR(EAGAIN) && !SDL_AtomicGet(&m_DecoderThreadShouldQuit)); @@ -1131,11 +1135,6 @@ int FFmpegVideoDecoder::submitDecodeUnit(PDECODE_UNIT du) return DR_NEED_IDR; } - // Bail immediately if we need an IDR frame to continue - if (Session::get()->getAndClearPendingIdrFrameStatus()) { - return DR_NEED_IDR; - } - if (!m_LastFrameNumber) { m_ActiveWndVideoStats.measurementStartTimestamp = SDL_GetTicks(); m_LastFrameNumber = du->frameNumber; diff --git a/moonlight-common-c/moonlight-common-c b/moonlight-common-c/moonlight-common-c index 502f799a..92400909 160000 --- a/moonlight-common-c/moonlight-common-c +++ b/moonlight-common-c/moonlight-common-c @@ -1 +1 @@ -Subproject commit 502f799a735f4c1b042819ebbf4b79f734473345 +Subproject commit 9240090983d588bf7c40138c9a23ac1403c551f7