use RageSemaphore
This commit is contained in:
@@ -20,7 +20,6 @@
|
|||||||
#include "RageException.h"
|
#include "RageException.h"
|
||||||
#include "RageSurface.h"
|
#include "RageSurface.h"
|
||||||
#include "arch/Dialog/Dialog.h"
|
#include "arch/Dialog/Dialog.h"
|
||||||
#include "SDL_utils.h"
|
|
||||||
|
|
||||||
#include <vfw.h> /* for GetVideoCodecDebugInfo */
|
#include <vfw.h> /* for GetVideoCodecDebugInfo */
|
||||||
#pragma comment(lib, "vfw32.lib")
|
#pragma comment(lib, "vfw32.lib")
|
||||||
@@ -123,7 +122,9 @@ static void GetVideoCodecDebugInfo()
|
|||||||
// MovieTexture_DShow constructor
|
// MovieTexture_DShow constructor
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
MovieTexture_DShow::MovieTexture_DShow( RageTextureID ID ) :
|
MovieTexture_DShow::MovieTexture_DShow( RageTextureID ID ) :
|
||||||
RageMovieTexture( ID )
|
RageMovieTexture( ID ),
|
||||||
|
buffer_lock( "buffer_lock", 1 ),
|
||||||
|
buffer_finished( "buffer_finished", 0 )
|
||||||
{
|
{
|
||||||
LOG->Trace( "RageBitmapTexture::RageBitmapTexture()" );
|
LOG->Trace( "RageBitmapTexture::RageBitmapTexture()" );
|
||||||
|
|
||||||
@@ -139,8 +140,6 @@ MovieTexture_DShow::MovieTexture_DShow( RageTextureID ID ) :
|
|||||||
|
|
||||||
m_uTexHandle = 0;
|
m_uTexHandle = 0;
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
buffer_lock = SDL_CreateSemaphore(1);
|
|
||||||
buffer_finished = SDL_CreateSemaphore(0);
|
|
||||||
|
|
||||||
Create();
|
Create();
|
||||||
CreateFrameRects();
|
CreateFrameRects();
|
||||||
@@ -154,13 +153,13 @@ MovieTexture_DShow::MovieTexture_DShow( RageTextureID ID ) :
|
|||||||
* for us to process a frame; do so. */
|
* for us to process a frame; do so. */
|
||||||
void MovieTexture_DShow::SkipUpdates()
|
void MovieTexture_DShow::SkipUpdates()
|
||||||
{
|
{
|
||||||
while(SDL_SemTryWait(buffer_lock))
|
while( buffer_lock.TryWait() )
|
||||||
CheckFrame();
|
CheckFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovieTexture_DShow::StopSkippingUpdates()
|
void MovieTexture_DShow::StopSkippingUpdates()
|
||||||
{
|
{
|
||||||
SDL_SemPost(buffer_lock);
|
buffer_lock.Post();
|
||||||
}
|
}
|
||||||
|
|
||||||
MovieTexture_DShow::~MovieTexture_DShow()
|
MovieTexture_DShow::~MovieTexture_DShow()
|
||||||
@@ -190,9 +189,6 @@ MovieTexture_DShow::~MovieTexture_DShow()
|
|||||||
LOG->Flush();
|
LOG->Flush();
|
||||||
if(m_uTexHandle)
|
if(m_uTexHandle)
|
||||||
DISPLAY->DeleteTexture( m_uTexHandle );
|
DISPLAY->DeleteTexture( m_uTexHandle );
|
||||||
|
|
||||||
SDL_DestroySemaphore(buffer_lock);
|
|
||||||
SDL_DestroySemaphore(buffer_finished);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovieTexture_DShow::Reload()
|
void MovieTexture_DShow::Reload()
|
||||||
@@ -247,7 +243,7 @@ void MovieTexture_DShow::CheckFrame()
|
|||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
|
|
||||||
/* Start the decoding thread again. */
|
/* Start the decoding thread again. */
|
||||||
SDL_SemPost(buffer_finished);
|
buffer_finished.Post();
|
||||||
|
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
}
|
}
|
||||||
@@ -403,7 +399,7 @@ void MovieTexture_DShow::Create()
|
|||||||
Pause();
|
Pause();
|
||||||
|
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
SDL_SemWait( pCTR->m_OneFrameDecoded );
|
pCTR->m_OneFrameDecoded.Wait();
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
CheckFrame();
|
CheckFrame();
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
@@ -418,7 +414,7 @@ void MovieTexture_DShow::NewData(const char *data)
|
|||||||
ASSERT(data);
|
ASSERT(data);
|
||||||
|
|
||||||
/* Try to lock. */
|
/* Try to lock. */
|
||||||
if(SDL_SemTryWait(buffer_lock))
|
if( buffer_lock.TryWait() )
|
||||||
{
|
{
|
||||||
/* The main thread is doing something uncommon, such as pausing.
|
/* The main thread is doing something uncommon, such as pausing.
|
||||||
* Drop this frame. */
|
* Drop this frame. */
|
||||||
@@ -427,11 +423,11 @@ void MovieTexture_DShow::NewData(const char *data)
|
|||||||
|
|
||||||
buffer = data;
|
buffer = data;
|
||||||
|
|
||||||
SDL_SemWait(buffer_finished);
|
buffer_finished.Wait();
|
||||||
|
|
||||||
ASSERT(buffer == NULL);
|
ASSERT(buffer == NULL);
|
||||||
|
|
||||||
SDL_SemPost(buffer_lock);
|
buffer_lock.Post();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ typedef char TCHAR, *PTCHAR;
|
|||||||
#include "RageTexture.h"
|
#include "RageTexture.h"
|
||||||
#include "RageThreads.h"
|
#include "RageThreads.h"
|
||||||
|
|
||||||
#include "SDL_mutex.h"
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// RageMovieTexture Class Declarations
|
// RageMovieTexture Class Declarations
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -55,7 +53,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const char *buffer;
|
const char *buffer;
|
||||||
SDL_sem *buffer_lock, *buffer_finished;
|
RageSemaphore buffer_lock, buffer_finished;
|
||||||
|
|
||||||
void Create();
|
void Create();
|
||||||
|
|
||||||
|
|||||||
@@ -10,21 +10,19 @@
|
|||||||
struct __declspec(uuid("{71771540-2017-11cf-ae26-0020afd79767}")) CLSID_TextureRenderer;
|
struct __declspec(uuid("{71771540-2017-11cf-ae26-0020afd79767}")) CLSID_TextureRenderer;
|
||||||
|
|
||||||
static HRESULT CBV_ret;
|
static HRESULT CBV_ret;
|
||||||
CTextureRenderer::CTextureRenderer()
|
CTextureRenderer::CTextureRenderer():
|
||||||
: CBaseVideoRenderer(__uuidof(CLSID_TextureRenderer),
|
CBaseVideoRenderer(__uuidof(CLSID_TextureRenderer),
|
||||||
NAME("Texture Renderer"), NULL, &CBV_ret)
|
NAME("Texture Renderer"), NULL, &CBV_ret),
|
||||||
|
m_OneFrameDecoded( "m_OneFrameDecoded", 0 )
|
||||||
{
|
{
|
||||||
if( FAILED(CBV_ret) )
|
if( FAILED(CBV_ret) )
|
||||||
RageException::Throw( hr_ssprintf(CBV_ret, "Could not create texture renderer object!") );
|
RageException::Throw( hr_ssprintf(CBV_ret, "Could not create texture renderer object!") );
|
||||||
|
|
||||||
m_pTexture = NULL;
|
m_pTexture = NULL;
|
||||||
|
|
||||||
m_OneFrameDecoded = SDL_CreateSemaphore(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CTextureRenderer::~CTextureRenderer()
|
CTextureRenderer::~CTextureRenderer()
|
||||||
{
|
{
|
||||||
SDL_DestroySemaphore( m_OneFrameDecoded );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -90,8 +88,8 @@ HRESULT CTextureRenderer::DoRenderSample( IMediaSample * pSample )
|
|||||||
void CTextureRenderer::OnReceiveFirstSample( IMediaSample * pSample )
|
void CTextureRenderer::OnReceiveFirstSample( IMediaSample * pSample )
|
||||||
{
|
{
|
||||||
/* If the main thread is in MovieTexture_DShow::Create, kick: */
|
/* If the main thread is in MovieTexture_DShow::Create, kick: */
|
||||||
if( SDL_SemValue(m_OneFrameDecoded) == 0 )
|
if( m_OneFrameDecoded.GetValue() == 0 )
|
||||||
SDL_SemPost( m_OneFrameDecoded );
|
m_OneFrameDecoded.Post();
|
||||||
|
|
||||||
DoRenderSample( pSample );
|
DoRenderSample( pSample );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public:
|
|||||||
long GetVidHeight() const { return m_lVidHeight; }
|
long GetVidHeight() const { return m_lVidHeight; }
|
||||||
void SetRenderTarget( MovieTexture_DShow* pTexture );
|
void SetRenderTarget( MovieTexture_DShow* pTexture );
|
||||||
|
|
||||||
SDL_sem *m_OneFrameDecoded;
|
RageSemaphore m_OneFrameDecoded;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Video width, height, and pitch.
|
// Video width, height, and pitch.
|
||||||
|
|||||||
@@ -7,11 +7,14 @@
|
|||||||
#include "RageTimer.h"
|
#include "RageTimer.h"
|
||||||
#include "RageFile.h"
|
#include "RageFile.h"
|
||||||
#include "RageSurface.h"
|
#include "RageSurface.h"
|
||||||
#include "SDL_utils.h"
|
|
||||||
#include "PrefsManager.h"
|
#include "PrefsManager.h"
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
|
||||||
|
#if defined(WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace avcodec
|
namespace avcodec
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
@@ -409,7 +412,8 @@ static avcodec::AVStream *FindVideoStream( avcodec::AVFormatContext *m_fctx )
|
|||||||
}
|
}
|
||||||
|
|
||||||
MovieTexture_FFMpeg::MovieTexture_FFMpeg( RageTextureID ID ):
|
MovieTexture_FFMpeg::MovieTexture_FFMpeg( RageTextureID ID ):
|
||||||
RageMovieTexture( ID )
|
RageMovieTexture( ID ),
|
||||||
|
m_BufferFinished( "BufferFinished", 0 )
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
LOG->Trace( "MovieTexture_FFMpeg::MovieTexture_FFMpeg(%s)", ID.filename.c_str() );
|
LOG->Trace( "MovieTexture_FFMpeg::MovieTexture_FFMpeg(%s)", ID.filename.c_str() );
|
||||||
@@ -429,8 +433,6 @@ try {
|
|||||||
m_FrameSkipMode = false;
|
m_FrameSkipMode = false;
|
||||||
m_bThreaded = PREFSMAN->m_bThreadedMovieDecode;
|
m_bThreaded = PREFSMAN->m_bThreadedMovieDecode;
|
||||||
|
|
||||||
m_BufferFinished = SDL_CreateSemaphore(0);
|
|
||||||
|
|
||||||
CreateDecoder();
|
CreateDecoder();
|
||||||
LOG->Trace("Bitrate: %i", decoder->m_stream->codec.bit_rate );
|
LOG->Trace("Bitrate: %i", decoder->m_stream->codec.bit_rate );
|
||||||
LOG->Trace("Codec pixel format: %s", avcodec::avcodec_get_pix_fmt_name(decoder->m_stream->codec.pix_fmt) );
|
LOG->Trace("Codec pixel format: %s", avcodec::avcodec_get_pix_fmt_name(decoder->m_stream->codec.pix_fmt) );
|
||||||
@@ -470,7 +472,6 @@ catch(...)
|
|||||||
|
|
||||||
delete decoder;
|
delete decoder;
|
||||||
|
|
||||||
SDL_DestroySemaphore( m_BufferFinished );
|
|
||||||
throw;
|
throw;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -482,8 +483,6 @@ MovieTexture_FFMpeg::~MovieTexture_FFMpeg()
|
|||||||
DestroyTexture();
|
DestroyTexture();
|
||||||
|
|
||||||
delete decoder;
|
delete decoder;
|
||||||
|
|
||||||
SDL_DestroySemaphore( m_BufferFinished );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -882,25 +881,14 @@ void MovieTexture_FFMpeg::DecoderThread()
|
|||||||
{
|
{
|
||||||
/* The only reason m_BufferFinished might be non-zero right now (before
|
/* The only reason m_BufferFinished might be non-zero right now (before
|
||||||
* ConvertFrame()) is if we're quitting. */
|
* ConvertFrame()) is if we're quitting. */
|
||||||
int n = SDL_SemValue( m_BufferFinished );
|
int n = m_BufferFinished.GetValue();
|
||||||
ASSERT_M( n == 0 || m_State == DECODER_QUIT, ssprintf("%i, %i", n, m_State) );
|
ASSERT_M( n == 0 || m_State == DECODER_QUIT, ssprintf("%i, %i", n, m_State) );
|
||||||
}
|
}
|
||||||
ConvertFrame();
|
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();
|
||||||
/* SDL_SemWait does not properly retry sem_wait in Linux on EINTR. */
|
|
||||||
int ret;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
CHECKPOINT;
|
|
||||||
errno = 0;
|
|
||||||
ret = SDL_SemWait( m_BufferFinished );
|
|
||||||
}
|
|
||||||
while( ret == -1 && errno == EINTR );
|
|
||||||
|
|
||||||
ASSERT_M( ret != -1, ssprintf("%s, %s", SDL_GetError(), strerror(errno)) );
|
|
||||||
|
|
||||||
/* 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) );
|
||||||
@@ -941,7 +929,7 @@ void MovieTexture_FFMpeg::Update(float fDeltaTime)
|
|||||||
UpdateFrame();
|
UpdateFrame();
|
||||||
|
|
||||||
if( m_bThreaded )
|
if( m_bThreaded )
|
||||||
SDL_SemPost(m_BufferFinished);
|
m_BufferFinished.Post();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Call from the main thread when m_ImageWaiting == FRAME_WAITING to update the
|
/* Call from the main thread when m_ImageWaiting == FRAME_WAITING to update the
|
||||||
@@ -988,7 +976,7 @@ void MovieTexture_FFMpeg::StopThread()
|
|||||||
m_State = DECODER_QUIT;
|
m_State = DECODER_QUIT;
|
||||||
|
|
||||||
/* Make sure we don't deadlock waiting for m_BufferFinished. */
|
/* Make sure we don't deadlock waiting for m_BufferFinished. */
|
||||||
SDL_SemPost(m_BufferFinished);
|
m_BufferFinished.Post();
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
m_DecoderThread.Wait();
|
m_DecoderThread.Wait();
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
@@ -996,7 +984,7 @@ void MovieTexture_FFMpeg::StopThread()
|
|||||||
m_ImageWaiting = FRAME_NONE;
|
m_ImageWaiting = FRAME_NONE;
|
||||||
|
|
||||||
/* Clear the above post, if the thread didn't. */
|
/* Clear the above post, if the thread didn't. */
|
||||||
SDL_SemTryWait(m_BufferFinished);
|
m_BufferFinished.TryWait();
|
||||||
|
|
||||||
LOG->Trace("Decoder thread shut down.");
|
LOG->Trace("Decoder thread shut down.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ private:
|
|||||||
RageSurface *m_img;
|
RageSurface *m_img;
|
||||||
int m_AVTexfmt; /* AVPixelFormat_t of m_img */
|
int m_AVTexfmt; /* AVPixelFormat_t of m_img */
|
||||||
|
|
||||||
SDL_sem *m_BufferFinished;
|
RageSemaphore m_BufferFinished;
|
||||||
|
|
||||||
RageTimer m_Timer;
|
RageTimer m_Timer;
|
||||||
float m_Clock;
|
float m_Clock;
|
||||||
|
|||||||
Reference in New Issue
Block a user