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