From b2415f5c379b10ac5facd343007bb643f7e33860 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 31 Aug 2004 03:52:00 +0000 Subject: [PATCH] fix "frames still decode when m_Rate == 0" --- .../arch/MovieTexture/MovieTexture_FFMpeg.cpp | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp b/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp index 243f09169c..13c46c6e8c 100644 --- a/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp +++ b/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp @@ -774,7 +774,10 @@ float MovieTexture_FFMpeg::CheckFrameTime() { 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( Offset > 0 ) @@ -844,7 +847,9 @@ void MovieTexture_FFMpeg::DecoderThread() 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 ); continue; } @@ -856,29 +861,33 @@ void MovieTexture_FFMpeg::DecoderThread() continue; const float fTime = CheckFrameTime(); - if( fTime == -1 ) + if( fTime == -1 ) // skip frame { DiscardFrame(); - continue; } - - if( fTime > 0 ) - usleep( int(1000000*fTime) ); - + else if( fTime > 0 ) // not time to decode a new frame yet { - /* 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) ); + /* This needs to be relatively short so that we wake up quickly + * from being paused or for changes in m_Rate. */ + usleep( 10000 ); } - 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 - * will change us back to FRAME_NONE without locking, and poke m_BufferFinished. */ - m_BufferFinished.Wait(); + /* 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. */ + m_BufferFinished.Wait(); - /* 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) ); + /* 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) ); + } } CHECKPOINT; }