From b0c8f70c87d4fd63df00ac266abafbca09099265 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 18 Oct 2004 18:40:28 +0000 Subject: [PATCH] handle decoding multiple frames in one Update() when not threaded --- .../arch/MovieTexture/MovieTexture_FFMpeg.cpp | 59 +++++++++++-------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp b/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp index 38b6bca325..6b45fd24b5 100644 --- a/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp +++ b/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp @@ -893,36 +893,45 @@ void MovieTexture_FFMpeg::DecoderThread() void MovieTexture_FFMpeg::Update(float fDeltaTime) { - if( !m_bThreaded ) + /* We might need to decode more than one frame per update. However, there + * have been bugs in ffmpeg that cause it to not handle EOF properly, which + * could make this never return, so let's play it safe. */ + int iMax = 4; + while( --iMax ) { - /* If we don't have a frame decoded, decode one. */ - if( m_ImageWaiting == FRAME_NONE ) - DecodeFrame(); - - /* If we have a frame decoded, see if it's time to display it. */ - if( m_ImageWaiting == FRAME_DECODED ) + if( !m_bThreaded ) { - float fTime = CheckFrameTime(); - if( fTime > 0 ) - return; - else if( fTime == -1 ) - DiscardFrame(); - else - ConvertFrame(); + /* If we don't have a frame decoded, decode one. */ + if( m_ImageWaiting == FRAME_NONE ) + DecodeFrame(); + + /* If we have a frame decoded, see if it's time to display it. */ + if( m_ImageWaiting == FRAME_DECODED ) + { + float fTime = CheckFrameTime(); + if( fTime > 0 ) + return; + else if( fTime == -1 ) + DiscardFrame(); + else + ConvertFrame(); + } } + + /* Note that if there's an image waiting, we *must* signal m_BufferFinished, or + * the decoder thread may sit around waiting for it, even though Pause and Play + * calls, causing the clock to keep running. */ + if( m_ImageWaiting != FRAME_WAITING ) + return; + CHECKPOINT; + + UpdateFrame(); + + if( m_bThreaded ) + m_BufferFinished.Post(); } - /* Note that if there's an image waiting, we *must* signal m_BufferFinished, or - * the decoder thread may sit around waiting for it, even though Pause and Play - * calls, causing the clock to keep running. */ - if( m_ImageWaiting != FRAME_WAITING ) - return; - CHECKPOINT; - - UpdateFrame(); - - if( m_bThreaded ) - m_BufferFinished.Post(); + LOG->MapLog( "ffmpeg_looping", "MovieTexture_FFMpeg::Update looping" ); } /* Call from the main thread when m_ImageWaiting == FRAME_WAITING to update the