simplify
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "RageLog.h"
|
||||
#include "RageTextureManager.h"
|
||||
#include "RageUtil.h"
|
||||
#include "RageTimer.h"
|
||||
#include "SDL_utils.h"
|
||||
#include "SDL_endian.h"
|
||||
|
||||
@@ -189,8 +190,6 @@ static CString averr_ssprintf( int err, const char *fmt, ... )
|
||||
|
||||
void MovieTexture_FFMpeg::CreateDecoder()
|
||||
{
|
||||
m_Timer = 0;
|
||||
|
||||
RageTextureID actualID = GetID();
|
||||
|
||||
actualID.iAlphaBits = 0;
|
||||
@@ -342,8 +341,11 @@ void MovieTexture_FFMpeg::DecoderThread()
|
||||
bool FrameSkipMode = false;
|
||||
unsigned Frame = 0;
|
||||
float LastFrameDelay = 0;
|
||||
float Clock = 0;
|
||||
RageTimer Timer;
|
||||
|
||||
CHECKPOINT;
|
||||
|
||||
while( m_State != DECODER_QUIT )
|
||||
{
|
||||
if( m_State == PAUSE_DECODER )
|
||||
@@ -351,15 +353,14 @@ void MovieTexture_FFMpeg::DecoderThread()
|
||||
SDL_Delay( 5 );
|
||||
|
||||
/* The video isn't running; skip time. */
|
||||
m_RunningTimer.GetDeltaTime();
|
||||
Timer.GetDeltaTime();
|
||||
continue;
|
||||
}
|
||||
|
||||
CHECKPOINT;
|
||||
|
||||
/* We're playing. Update the play timer. */
|
||||
float TimePassed = m_RunningTimer.GetDeltaTime();
|
||||
m_Timer += TimePassed * m_Rate;
|
||||
/* We're playing. Update the clock. */
|
||||
Clock += Timer.GetDeltaTime() * m_Rate;
|
||||
|
||||
/* Read a packet. */
|
||||
avcodec::AVPacket pkt;
|
||||
@@ -382,6 +383,7 @@ void MovieTexture_FFMpeg::DecoderThread()
|
||||
FrameSkipMode = false;
|
||||
Frame = 0;
|
||||
LastFrameDelay = 0;
|
||||
Clock = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -458,13 +460,13 @@ void MovieTexture_FFMpeg::DecoderThread()
|
||||
|
||||
m_Position = CurrentTimestamp;
|
||||
|
||||
const float Offset = CurrentTimestamp - m_Timer;
|
||||
const float Offset = CurrentTimestamp - Clock;
|
||||
bool SkipThisTextureUpdate = false;
|
||||
|
||||
/* If we're ahead, we're decoding too fast; delay. */
|
||||
if( Offset > 0 )
|
||||
{
|
||||
SDL_Delay( int(1000*(CurrentTimestamp - m_Timer)) );
|
||||
SDL_Delay( int(1000*(CurrentTimestamp - Clock)) );
|
||||
if( FrameSkipMode )
|
||||
{
|
||||
/* We're caught up; stop skipping frames. */
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "RageDisplay.h"
|
||||
#include "RageTexture.h"
|
||||
#include "RageThreads.h"
|
||||
#include "RageTimer.h"
|
||||
|
||||
#include "SDL_mutex.h"
|
||||
|
||||
@@ -39,51 +38,24 @@ public:
|
||||
virtual void SetPlaybackRate( float fRate ) { m_Rate=fRate; }
|
||||
virtual bool IsPlaying() const { return m_State == PLAYING; }
|
||||
void SetLooping(bool looping=true) { m_bLoop = looping; }
|
||||
unsigned GetTexHandle() const { return m_uTexHandle; }
|
||||
|
||||
private:
|
||||
avcodec::AVFormatContext *m_fctx;
|
||||
avcodec::AVStream *m_stream;
|
||||
avcodec::AVCodec *m_codec;
|
||||
|
||||
RageTimer m_RunningTimer;
|
||||
/* The time the movie *should* be at right now: */
|
||||
float m_Timer;
|
||||
|
||||
/* The time the movie is actually at: */
|
||||
float m_Position;
|
||||
|
||||
float m_ActualTimer;
|
||||
float m_Rate;
|
||||
|
||||
bool m_ImageWaiting;
|
||||
bool m_shutdown;
|
||||
bool m_bLoop;
|
||||
|
||||
/* If m_bPausing is true, then the decoder thread will stop on its
|
||||
* next iteration, set m_bPlaying false and post the "paused" semaphore. */
|
||||
|
||||
/*
|
||||
* Only the main thread can change m_State, except to go from the
|
||||
* PAUSING_DECODER to PAUSING_DECODER_OK state.
|
||||
* Only the main thread can change m_State.
|
||||
*
|
||||
* PLAYING->PAUSE_DECODER (main thread only): ask the decoder thread to pause
|
||||
* PAUSE_DECODER->PLAYING (main thread only): ask the decoder thread to resume
|
||||
* *->QUITTING (main thread only):
|
||||
*
|
||||
* If in PLAYING, pause by setting m_State to PAUSE_DECODER.
|
||||
* The decoding thread will notice this, change to PAUSED and post
|
||||
* m_paused. Then, on the next command, CompletePause will
|
||||
* wait for the semaphore. CompletePause must be called before
|
||||
* changing to another state (to clear the semaphore).
|
||||
*
|
||||
* Transitions:
|
||||
* Default: PAUSED
|
||||
* CompletePause: If PAUSE_OK, WAITING_FOR_PAUSE, block on m_paused, then set
|
||||
* to PAUSED.
|
||||
* Play(): If PAUSED, set to PLAYING. If WAITING_FOR_PAUSE, wait
|
||||
* for the "paused" semaphore to
|
||||
*/
|
||||
/* DECODER_QUIT: The decoder thread is not running. We should only
|
||||
* DECODER_QUIT: The decoder thread is not running. We should only
|
||||
* be in this state internally; when we return after a call, we should
|
||||
* never be in this state. Start the thread before returning.
|
||||
*
|
||||
@@ -100,7 +72,7 @@ private:
|
||||
unsigned m_uTexHandle;
|
||||
|
||||
SDL_Surface *m_img;
|
||||
int m_AVTexfmt; /* of m_img */
|
||||
int m_AVTexfmt; /* AVPixelFormat_t of m_img */
|
||||
|
||||
SDL_sem *m_BufferFinished, *m_OneFrameDecoded;
|
||||
|
||||
@@ -115,9 +87,6 @@ private:
|
||||
void CheckFrame();
|
||||
void StartThread();
|
||||
void StopThread();
|
||||
|
||||
|
||||
unsigned GetTexHandle() const { return m_uTexHandle; }
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user