make MovieTexture act more like other drivers: MovieTexture itself
is a factory for RageTexture objects, not a RageTexture itself. The actual RageTexture objects don't need to be exposed in the headers (DShow still does it for DShow_Helpers), so we don't need to expose the headers of the movie API to user code. (We could also eliminate reconstructing the factory driver each time we make a movie, but there's no real reason to currently.)
This commit is contained in:
@@ -57,14 +57,10 @@ bool RageMovieTexture::GetFourCC( RString fn, RString &handler, RString &type )
|
||||
#undef HANDLE_ERROR
|
||||
}
|
||||
|
||||
map<istring, CreateMovieTextureFn> *RegisterMovieTexture::g_pRegistrees = NULL;
|
||||
RegisterMovieTexture::RegisterMovieTexture( const istring &sName, CreateMovieTextureFn pfn )
|
||||
static DriverList g_pRegistrees;
|
||||
RegisterMovieTextureDriver::RegisterMovieTextureDriver( const istring &sName, CreateRageDriverFn pfn )
|
||||
{
|
||||
if( g_pRegistrees == NULL )
|
||||
g_pRegistrees = new map<istring, CreateMovieTextureFn>;
|
||||
|
||||
ASSERT( g_pRegistrees->find(sName) == g_pRegistrees->end() );
|
||||
(*g_pRegistrees)[sName] = pfn;
|
||||
g_pRegistrees.Add( sName, pfn );
|
||||
}
|
||||
|
||||
// Helper for MakeRageMovieTexture()
|
||||
@@ -100,17 +96,22 @@ RageMovieTexture *MakeRageMovieTexture( RageTextureID ID )
|
||||
FOREACH_CONST( RString, DriversToTry, Driver )
|
||||
{
|
||||
LOG->Trace( "Initializing driver: %s", Driver->c_str() );
|
||||
map<istring, CreateMovieTextureFn>::const_iterator iter = RegisterMovieTexture::g_pRegistrees->find( istring(*Driver) );
|
||||
RageDriver *pDriverBase = g_pRegistrees.Create( *Driver );
|
||||
|
||||
if( iter == RegisterMovieTexture::g_pRegistrees->end() )
|
||||
if( pDriverBase == NULL )
|
||||
{
|
||||
LOG->Trace( "Unknown movie driver name: %s", Driver->c_str() );
|
||||
continue;
|
||||
}
|
||||
ret = (iter->second)( ID );
|
||||
DEBUG_ASSERT( ret );
|
||||
const RString sError = ret->Init();
|
||||
if( sError != "" )
|
||||
|
||||
RageMovieTextureDriver *pDriver = dynamic_cast<RageMovieTextureDriver *>( pDriverBase );
|
||||
ASSERT( pDriver );
|
||||
|
||||
RString sError;
|
||||
ret = pDriver->Create( ID, sError );
|
||||
delete pDriver;
|
||||
|
||||
if( ret == NULL )
|
||||
{
|
||||
LOG->Info( "Couldn't load driver %s: %s", Driver->c_str(), sError.c_str() );
|
||||
SAFE_DELETE( ret );
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MOVIE_TEXTURE_H
|
||||
|
||||
#include "RageTexture.h"
|
||||
#include "arch/RageDriver.h"
|
||||
#include <map>
|
||||
|
||||
class RageMovieTexture : public RageTexture
|
||||
@@ -9,7 +10,6 @@ class RageMovieTexture : public RageTexture
|
||||
public:
|
||||
RageMovieTexture( RageTextureID ID ): RageTexture(ID) { }
|
||||
virtual ~RageMovieTexture() { }
|
||||
virtual RString Init() { return RString(); }
|
||||
virtual void Update( float fDeltaTime ) { }
|
||||
|
||||
virtual void Reload() = 0;
|
||||
@@ -23,15 +23,19 @@ public:
|
||||
static bool GetFourCC( RString fn, RString &handler, RString &type );
|
||||
};
|
||||
|
||||
typedef RageMovieTexture *(*CreateMovieTextureFn)( RageTextureID );
|
||||
struct RegisterMovieTexture
|
||||
class RageMovieTextureDriver: public RageDriver
|
||||
{
|
||||
static map<istring, CreateMovieTextureFn> *g_pRegistrees;
|
||||
RegisterMovieTexture( const istring &sName, CreateMovieTextureFn );
|
||||
public:
|
||||
virtual ~RageMovieTextureDriver() { }
|
||||
virtual RageMovieTexture *Create( RageTextureID ID, RString &sError ) = 0;
|
||||
};
|
||||
|
||||
struct RegisterMovieTextureDriver
|
||||
{
|
||||
RegisterMovieTextureDriver( const istring &sName, CreateRageDriverFn );
|
||||
};
|
||||
#define REGISTER_MOVIE_TEXTURE_CLASS( name ) \
|
||||
static RageMovieTexture *Create##name( RageTextureID ID ) { return new MovieTexture_##name( ID ); } \
|
||||
static RegisterMovieTexture register_##className( #name, Create##name )
|
||||
static RegisterMovieTextureDriver register_##name( #name, CreateClass<RageMovieTextureDriver_##name, RageDriver> )
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -29,6 +29,15 @@
|
||||
#pragma comment(lib, "vfw32.lib")
|
||||
#endif
|
||||
|
||||
RageMovieTexture *RageMovieTextureDriver_DShow::Create( RageTextureID ID, RString &sError )
|
||||
{
|
||||
MovieTexture_DShow *pRet = new MovieTexture_DShow( ID );
|
||||
sError = pRet->Init();
|
||||
if( !sError.empty() )
|
||||
SAFE_DELETE( pRet );
|
||||
return pRet;
|
||||
}
|
||||
|
||||
REGISTER_MOVIE_TEXTURE_CLASS( DShow );
|
||||
|
||||
static RString FourCCToString( int fcc )
|
||||
|
||||
@@ -71,6 +71,12 @@ private:
|
||||
bool m_bPlaying;
|
||||
};
|
||||
|
||||
class RageMovieTextureDriver_DShow: public RageMovieTextureDriver
|
||||
{
|
||||
public:
|
||||
virtual RageMovieTexture *Create( RageTextureID ID, RString &sError );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
#include <cerrno>
|
||||
|
||||
REGISTER_MOVIE_TEXTURE_CLASS( FFMpeg );
|
||||
|
||||
namespace avcodec
|
||||
{
|
||||
#include <ffmpeg/avformat.h>
|
||||
@@ -129,6 +127,15 @@ static int FindCompatibleAVFormat( bool bHighColor )
|
||||
return -1;
|
||||
}
|
||||
|
||||
class MovieTexture_FFMpeg: public MovieTexture_Generic
|
||||
{
|
||||
public:
|
||||
MovieTexture_FFMpeg( RageTextureID ID );
|
||||
|
||||
static void RegisterProtocols();
|
||||
static RageSurface *AVCodecCreateCompatibleSurface( int iTextureWidth, int iTextureHeight, bool bPreferHighColor, int &iAVTexfmt );
|
||||
};
|
||||
|
||||
RageSurface *MovieTexture_FFMpeg::AVCodecCreateCompatibleSurface( int iTextureWidth, int iTextureHeight, bool bPreferHighColor, int &iAVTexfmt )
|
||||
{
|
||||
FixLilEndian();
|
||||
@@ -599,6 +606,17 @@ MovieTexture_FFMpeg::MovieTexture_FFMpeg( RageTextureID ID ):
|
||||
{
|
||||
}
|
||||
|
||||
RageMovieTexture *RageMovieTextureDriver_FFMpeg::Create( RageTextureID ID, RString &sError )
|
||||
{
|
||||
MovieTexture_FFMpeg *pRet = new MovieTexture_FFMpeg( ID );
|
||||
sError = pRet->Init();
|
||||
if( !sError.empty() )
|
||||
SAFE_DELETE( pRet );
|
||||
return pRet;
|
||||
}
|
||||
|
||||
REGISTER_MOVIE_TEXTURE_CLASS( FFMpeg );
|
||||
|
||||
/*
|
||||
* (c) 2003-2005 Glenn Maynard
|
||||
* All rights reserved.
|
||||
|
||||
@@ -5,13 +5,10 @@
|
||||
|
||||
#include "MovieTexture_Generic.h"
|
||||
|
||||
class MovieTexture_FFMpeg: public MovieTexture_Generic
|
||||
class RageMovieTextureDriver_FFMpeg: public RageMovieTextureDriver
|
||||
{
|
||||
public:
|
||||
MovieTexture_FFMpeg( RageTextureID ID );
|
||||
|
||||
static void RegisterProtocols();
|
||||
static RageSurface *AVCodecCreateCompatibleSurface( int iTextureWidth, int iTextureHeight, bool bPreferHighColor, int &iAVTexfmt );
|
||||
virtual RageMovieTexture *Create( RageTextureID ID, RString &sError );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,24 @@
|
||||
#include "MovieTexture_Null.h"
|
||||
#include "RageSurface.h"
|
||||
|
||||
REGISTER_MOVIE_TEXTURE_CLASS( Null );
|
||||
class MovieTexture_Null : public RageMovieTexture {
|
||||
public:
|
||||
MovieTexture_Null(RageTextureID ID);
|
||||
virtual ~MovieTexture_Null();
|
||||
void Invalidate() { texHandle = 0; }
|
||||
unsigned GetTexHandle() const { return texHandle; }
|
||||
void Update(float delta) { }
|
||||
void Reload() { }
|
||||
void SetPosition(float seconds) { }
|
||||
void SetPlaybackRate(float rate) { }
|
||||
void SetLooping(bool looping=true) { loop = looping; }
|
||||
|
||||
private:
|
||||
bool playing;
|
||||
bool loop;
|
||||
unsigned texHandle;
|
||||
};
|
||||
|
||||
MovieTexture_Null::MovieTexture_Null(RageTextureID ID) : RageMovieTexture(ID)
|
||||
{
|
||||
LOG->Trace("MovieTexture_Null::MovieTexture_Null(ID)");
|
||||
@@ -47,6 +64,13 @@ MovieTexture_Null::~MovieTexture_Null()
|
||||
DISPLAY->DeleteTexture( texHandle );
|
||||
}
|
||||
|
||||
REGISTER_MOVIE_TEXTURE_CLASS( Null );
|
||||
|
||||
RageMovieTexture *RageMovieTextureDriver_Null::Create( RageTextureID ID, RString &sError )
|
||||
{
|
||||
return new MovieTexture_Null( ID );
|
||||
}
|
||||
|
||||
/*
|
||||
* (c) 2003 Steve Checkoway
|
||||
* All rights reserved.
|
||||
|
||||
@@ -10,24 +10,11 @@
|
||||
*/
|
||||
|
||||
#include "MovieTexture.h"
|
||||
#include "RageTexture.h"
|
||||
|
||||
class MovieTexture_Null : public RageMovieTexture {
|
||||
class RageMovieTextureDriver_Null: public RageMovieTextureDriver
|
||||
{
|
||||
public:
|
||||
MovieTexture_Null(RageTextureID ID);
|
||||
virtual ~MovieTexture_Null();
|
||||
void Invalidate() { texHandle = 0; }
|
||||
unsigned GetTexHandle() const { return texHandle; }
|
||||
void Update(float delta) { }
|
||||
void Reload() { }
|
||||
void SetPosition(float seconds) { }
|
||||
void SetPlaybackRate(float rate) { }
|
||||
void SetLooping(bool looping=true) { loop = looping; }
|
||||
|
||||
private:
|
||||
bool playing;
|
||||
bool loop;
|
||||
unsigned texHandle;
|
||||
virtual RageMovieTexture *Create( RageTextureID ID, RString &sError );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#include "RageUtil.h"
|
||||
#include "MovieTexture_FFMpeg.h" /* for AVCodecCreateCompatibleSurface */
|
||||
|
||||
REGISTER_MOVIE_TEXTURE_CLASS( Theora );
|
||||
|
||||
namespace avcodec
|
||||
{
|
||||
#include <ffmpeg/avcodec.h> /* for avcodec::img_convert */
|
||||
@@ -699,11 +697,28 @@ void MovieDecoder_Theora::Close()
|
||||
}
|
||||
#endif
|
||||
|
||||
class MovieTexture_Theora: public MovieTexture_Generic
|
||||
{
|
||||
public:
|
||||
MovieTexture_Theora( RageTextureID ID );
|
||||
};
|
||||
|
||||
MovieTexture_Theora::MovieTexture_Theora( RageTextureID ID ):
|
||||
MovieTexture_Generic( ID, new MovieDecoder_Theora )
|
||||
{
|
||||
}
|
||||
|
||||
RageMovieTexture *RageMovieTextureDriver_Theora::Create( RageTextureID ID, RString &sError )
|
||||
{
|
||||
MovieTexture_Theora *pRet = new MovieTexture_Theora( ID );
|
||||
sError = pRet->Init();
|
||||
if( !sError.empty() )
|
||||
SAFE_DELETE( pRet );
|
||||
return pRet;
|
||||
}
|
||||
|
||||
REGISTER_MOVIE_TEXTURE_CLASS( Theora );
|
||||
|
||||
/*
|
||||
* (c) 2005 Glenn Maynard
|
||||
* All rights reserved.
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
|
||||
#include "MovieTexture_Generic.h"
|
||||
|
||||
class MovieTexture_Theora: public MovieTexture_Generic
|
||||
class RageMovieTextureDriver_Theora: public RageMovieTextureDriver
|
||||
{
|
||||
public:
|
||||
MovieTexture_Theora( RageTextureID ID );
|
||||
virtual RageMovieTexture *Create( RageTextureID ID, RString &sError );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user