fix "frames still decode when m_Rate == 0"

This commit is contained in:
Chris Danford
2004-08-31 03:52:00 +00:00
parent 5ec0d7034f
commit b2415f5c37
@@ -774,7 +774,10 @@ float MovieTexture_FFMpeg::CheckFrameTime()
{ {
ASSERT_M( m_ImageWaiting == FRAME_DECODED, ssprintf("%i", m_ImageWaiting) ); ASSERT_M( m_ImageWaiting == FRAME_DECODED, ssprintf("%i", m_ImageWaiting) );
const float Offset = decoder->GetTimestamp() - m_Clock; if( m_Rate == 0 )
return 1; // "a long time until the next frame"
const float Offset = (decoder->GetTimestamp() - m_Clock) / m_Rate;
/* If we're ahead, we're decoding too fast; delay. */ /* If we're ahead, we're decoding too fast; delay. */
if( Offset > 0 ) if( Offset > 0 )
@@ -844,7 +847,9 @@ void MovieTexture_FFMpeg::DecoderThread()
if( m_State == PAUSE_DECODER ) if( m_State == PAUSE_DECODER )
{ {
/* We aren't feeding frames, so we aren't waiting; don't chew CPU. */ /* We aren't feeding frames, so we aren't waiting; don't chew CPU.
* This needs to be relatively short so that we wake up quickly
* from being paused or for changes in m_Rate. */
usleep( 10000 ); usleep( 10000 );
continue; continue;
} }
@@ -856,29 +861,33 @@ void MovieTexture_FFMpeg::DecoderThread()
continue; continue;
const float fTime = CheckFrameTime(); const float fTime = CheckFrameTime();
if( fTime == -1 ) if( fTime == -1 ) // skip frame
{ {
DiscardFrame(); DiscardFrame();
continue;
} }
else if( fTime > 0 ) // not time to decode a new frame yet
if( fTime > 0 )
usleep( int(1000000*fTime) );
{ {
/* The only reason m_BufferFinished might be non-zero right now (before /* This needs to be relatively short so that we wake up quickly
* ConvertFrame()) is if we're quitting. */ * from being paused or for changes in m_Rate. */
int n = m_BufferFinished.GetValue(); usleep( 10000 );
ASSERT_M( n == 0 || m_State == DECODER_QUIT, ssprintf("%i, %i", n, m_State) );
} }
ConvertFrame(); else // fTime == 0
{
{
/* The only reason m_BufferFinished might be non-zero right now (before
* ConvertFrame()) is if we're quitting. */
int n = m_BufferFinished.GetValue();
ASSERT_M( n == 0 || m_State == DECODER_QUIT, ssprintf("%i, %i", n, m_State) );
}
ConvertFrame();
/* We just went into FRAME_WAITING. Don't actually check; the main thread /* We just went into FRAME_WAITING. Don't actually check; the main thread
* will change us back to FRAME_NONE without locking, and poke m_BufferFinished. */ * will change us back to FRAME_NONE without locking, and poke m_BufferFinished. */
m_BufferFinished.Wait(); m_BufferFinished.Wait();
/* If the frame wasn't used, then we must be shutting down. */ /* If the frame wasn't used, then we must be shutting down. */
ASSERT_M( m_ImageWaiting == FRAME_NONE || m_State == DECODER_QUIT, ssprintf("%i, %i", m_ImageWaiting, m_State) ); ASSERT_M( m_ImageWaiting == FRAME_NONE || m_State == DECODER_QUIT, ssprintf("%i, %i", m_ImageWaiting, m_State) );
}
} }
CHECKPOINT; CHECKPOINT;
} }