From 99eb66b31bd4f72fccffbaa0e82e6c42796502ee Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 21 Oct 2005 00:49:18 +0000 Subject: [PATCH] - if m_bWantRewind is true at the start of DecodeFrame (probably called Seek), don't make spurious calls to GetFrame (waste of CPU) - fix DecodeFrame setting FRAME_DECODED without actually decoding a frame on EOF after loop update comment (probably not related to "movie not looping" problems) --- .../MovieTexture/MovieTexture_Generic.cpp | 81 +++++++++++-------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/stepmania/src/arch/MovieTexture/MovieTexture_Generic.cpp b/stepmania/src/arch/MovieTexture/MovieTexture_Generic.cpp index 0f54251b81..f2557e3275 100644 --- a/stepmania/src/arch/MovieTexture/MovieTexture_Generic.cpp +++ b/stepmania/src/arch/MovieTexture/MovieTexture_Generic.cpp @@ -161,53 +161,64 @@ void MovieTexture_Generic::CreateTexture() /* Handle decoding for a frame. Return true if a frame was decoded, false if not - * (due to pause, EOF, etc). If true is returned, we'll be in FRAME_DECODED. */ + * (due to quit, error, EOF, etc). If true is returned, we'll be in FRAME_DECODED. */ bool MovieTexture_Generic::DecodeFrame() { ASSERT_M( m_ImageWaiting == FRAME_NONE, ssprintf("%i", m_ImageWaiting) ); - if( m_State == DECODER_QUIT ) - return false; - CHECKPOINT; - - /* Read a frame. */ - int ret = m_pDecoder->GetFrame(); - if( ret == -1 ) - return false; - - if( m_bWantRewind && m_pDecoder->GetTimestamp() == 0 ) - m_bWantRewind = false; /* ignore */ - - if( ret == 0 ) + bool bTriedRewind = false; + do { - /* EOF. */ - if( !m_bLoop ) + if( m_State == DECODER_QUIT ) return false; - LOG->Trace( "File \"%s\" looping", GetID().filename.c_str() ); - m_bWantRewind = true; - } + if( m_bWantRewind ) + { + if( bTriedRewind ) + { + LOG->Trace( "File \"%s\" looped more than once in one frame", GetID().filename.c_str() ); + return false; + } + m_bWantRewind = false; + bTriedRewind = true; - if( m_bWantRewind ) - { - m_bWantRewind = false; + /* When resetting the clock, set it back by the length of the last frame, + * so it has a proper delay. */ + float fDelay = m_pDecoder->GetFrameDuration(); - /* When resetting the clock, set it back by the length of the last frame, - * so it has a proper delay. */ - float fDelay = m_pDecoder->GetFrameDuration(); + /* Restart. */ + m_pDecoder->Close(); + CString sError = m_pDecoder->Open( GetID().filename ); + if( sError != "" ) + RageException::Throw( "Error rewinding stream %s: %s", GetID().filename.c_str(), sError.c_str() ); - /* Restart. */ - m_pDecoder->Close(); - CString sError = m_pDecoder->Open( GetID().filename ); - if( sError != "" ) - RageException::Throw( "Error rewinding stream %s: %s", GetID().filename.c_str(), sError.c_str() ); + m_fClock = -fDelay; + } - m_fClock = -fDelay; - return false; - } + CHECKPOINT; - /* We got a frame. */ - m_ImageWaiting = FRAME_DECODED; + /* Read a frame. */ + int ret = m_pDecoder->GetFrame(); + if( ret == -1 ) + return false; + + if( m_bWantRewind && m_pDecoder->GetTimestamp() == 0 ) + m_bWantRewind = false; /* ignore */ + + if( ret == 0 ) + { + /* EOF. */ + if( !m_bLoop ) + return false; + + LOG->Trace( "File \"%s\" looping", GetID().filename.c_str() ); + m_bWantRewind = true; + continue; + } + + /* We got a frame. */ + m_ImageWaiting = FRAME_DECODED; + } while( m_bWantRewind ); return true; }