From dfe275ab674d3c4d62f2fecf4f7357fe1c8e36ac Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 17 Jan 2022 15:26:00 -0600 Subject: [PATCH] Avoid consuming stale data during/after decoder reset --- app/streaming/video/ffmpeg.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/streaming/video/ffmpeg.cpp b/app/streaming/video/ffmpeg.cpp index ac9ccd3a..e66c352c 100644 --- a/app/streaming/video/ffmpeg.cpp +++ b/app/streaming/video/ffmpeg.cpp @@ -1045,6 +1045,9 @@ void FFmpegVideoDecoder::decoderThreadProc() SDL_Event event; event.type = SDL_RENDER_DEVICE_RESET; SDL_PushEvent(&event); + + // Don't consume any additional data + SDL_AtomicSet(&m_DecoderThreadShouldQuit, 1); } } } while (err == AVERROR(EAGAIN) && !SDL_AtomicGet(&m_DecoderThreadShouldQuit)); @@ -1064,6 +1067,11 @@ int FFmpegVideoDecoder::submitDecodeUnit(PDECODE_UNIT du) SDL_assert(!m_TestOnly); + // If this is the first frame, reject anything that's not an IDR frame + if (m_FramesIn == 0 && du->frameType != FRAME_TYPE_IDR) { + return DR_NEED_IDR; + } + // Bail immediately if we need an IDR frame to continue if (Session::get()->getAndClearPendingIdrFrameStatus()) { return DR_NEED_IDR; @@ -1148,6 +1156,9 @@ int FFmpegVideoDecoder::submitDecodeUnit(PDECODE_UNIT du) SDL_Event event; event.type = SDL_RENDER_DEVICE_RESET; SDL_PushEvent(&event); + + // Don't consume any additional data + SDL_AtomicSet(&m_DecoderThreadShouldQuit, 1); } return DR_NEED_IDR;