- 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)
This commit is contained in:
Glenn Maynard
2005-10-21 00:49:18 +00:00
parent e2eba96101
commit 99eb66b31b
@@ -161,53 +161,64 @@ void MovieTexture_Generic::CreateTexture()
/* Handle decoding for a frame. Return true if a frame was decoded, false if not /* 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() bool MovieTexture_Generic::DecodeFrame()
{ {
ASSERT_M( m_ImageWaiting == FRAME_NONE, ssprintf("%i", m_ImageWaiting) ); ASSERT_M( m_ImageWaiting == FRAME_NONE, ssprintf("%i", m_ImageWaiting) );
if( m_State == DECODER_QUIT ) bool bTriedRewind = false;
return false; do
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 )
{ {
/* EOF. */ if( m_State == DECODER_QUIT )
if( !m_bLoop )
return false; return false;
LOG->Trace( "File \"%s\" looping", GetID().filename.c_str() ); if( m_bWantRewind )
m_bWantRewind = true; {
} 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 ) /* When resetting the clock, set it back by the length of the last frame,
{ * so it has a proper delay. */
m_bWantRewind = false; float fDelay = m_pDecoder->GetFrameDuration();
/* When resetting the clock, set it back by the length of the last frame, /* Restart. */
* so it has a proper delay. */ m_pDecoder->Close();
float fDelay = m_pDecoder->GetFrameDuration(); 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_fClock = -fDelay;
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; CHECKPOINT;
return false;
}
/* We got a frame. */ /* Read a frame. */
m_ImageWaiting = FRAME_DECODED; 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; return true;
} }