Ejemplo n.º 1
0
bool CVideoRenderer::Initialize ( const WCHAR * fileName )
{
	HRESULT hr;
	#define EIF( _x ) if( FAILED( hr=_x ) ) goto error

	// --- check for a valid device
	if ( !m_pDevice ) return false;

	Lock ();

	// --- create the filter graph
	EIF( CoCreateInstance( CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&m_pGraph ) );
	m_pFilter = CreateTextureRenderer ( &hr, m_pDevice, this );
	EIF( hr );

	// --- add our texture filter and set up the graph to render to this filter
	m_pGraph->AddFilter( m_pFilter,	L"Texture renderer" );

	EIF( RenderFileToVideoRenderer( m_pGraph, fileName, FALSE ) );

#ifdef _DEBUG
	// --- register this graph for use with graphedt
	if( FAILED( hr = AddGraphToRot( m_pGraph, &m_dwGraphRegister ) ) ) {
		// ACHTUNG: failure, report and move on
	}
#endif

	// --- get some interfaces
	m_pGraph->QueryInterface( IID_IMediaSeeking, (void**)&m_pMediaSeeking );
	m_pGraph->QueryInterface( IID_IMediaControl, (void**)&m_pMediaControl );
	m_pGraph->QueryInterface( IID_IBasicAudio, (void**)&m_pBasicAudio );

	m_pBasicAudio->get_Volume ( &lDefaultVolume );

	// --- clean up
	m_pGraph->Release ();
	m_pGraph = NULL;

	// --- unlock the mutex
	Unlock ();

	return true;

error:
	// --- failure occurred
	hr = hr;

	return false;
}
Ejemplo n.º 2
0
bool CVideoRenderer::Initialize ( const char * szFile )
{
    IBaseFilter * pDSound, * pXVID, * pVorbis;
    IBaseFilter * pSource;
    IFileSourceFilter * pFileSource;
    HRESULT hr;

    // Get the codecs
    CVideoManager *pManager = CVideoManager::GetSingletonPtr ();
    if ( pManager->CreateCodecSource ( &pSource ) != S_OK ) return false;
    if ( pManager->CreateCodecVorbis ( &pVorbis ) != S_OK ) return false;
    if ( pManager->CreateCodecXVID ( &pXVID ) != S_OK ) return false;

    // Check for a valid device
    if ( !m_pDevice ) return false;

    // Lock so we don't f**k up
    Lock ();

    CCore::GetSingleton ().GetConsole ()->Printf ( "Creating DirectShow graph instance" );

    // Initialize the graph builder
    CoCreateInstance ( CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, reinterpret_cast < void** > ( &m_pGraph ) );
    if ( m_pGraph == NULL ) return false;

    CCore::GetSingleton ().GetConsole ()->Printf ( "Creating DirectSound renderer instance" );

    // Initialize the DirectSound filter
    CoCreateInstance ( CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, reinterpret_cast < void** > ( &pDSound ) );
    if ( pDSound == NULL ) return false;

#ifdef MTA_DEBUG
    CCore::GetSingleton ().GetConsole ()->Printf ( "Adding ROT for debug stuff" );

    // Enable GraphView debugging
    AddToROT(m_pGraph);
#endif

    CCore::GetSingleton ().GetConsole ()->Printf ( "Creating video renderer instance" );

    // Create an instance of the texture renderer and add it to the graph
    m_pFilter = CreateTextureRenderer ( &hr, m_pDevice, this );
    if ( hr != S_OK ) return false;

    // Add the source file filter to the grap h
    int iBufferSize = MultiByteToWideChar ( CP_ACP, 0, szFile, -1, NULL, 0 );
    wchar_t *wszFile = new wchar_t[iBufferSize];
    MultiByteToWideChar ( CP_ACP, 0, szFile, -1, wszFile, iBufferSize );

    CCore::GetSingleton ().GetConsole ()->Printf ( "Registering filter (Matroska)" );

    // Add the filters to the graph
    m_pGraph->AddFilter         ( pSource,      L"[MTA] MKV source" );
    
    CCore::GetSingleton ().GetConsole ()->Printf ( "Loading video file" );

    pSource->QueryInterface ( IID_IFileSourceFilter, reinterpret_cast < void** > ( &pFileSource ) );
    if ( pFileSource->Load ( wszFile, NULL ) != S_OK ) return false;

    CCore::GetSingleton ().GetConsole ()->Printf ( "Registering filter (Output)" );

    m_pGraph->AddFilter         ( m_pFilter,    L"[MTA] Texture renderer" );
    CCore::GetSingleton ().GetConsole ()->Printf ( "Registering filter (Vorbis)" );
    m_pGraph->AddFilter         ( pVorbis,      L"[MTA] Vorbis decoder" );
    CCore::GetSingleton ().GetConsole ()->Printf ( "Registering filter (XVID)" );
    m_pGraph->AddFilter         ( pXVID,        L"[MTA] XVID codec" );
    CCore::GetSingleton ().GetConsole ()->Printf ( "Registering filter (DirectSound)" );
    m_pGraph->AddFilter         ( pDSound,      L"[MTA] DirectSound renderer" );

    CCore::GetSingleton ().GetConsole ()->Printf ( "Connecting video renderer" );

    // Connect the video pins
    IPin *pOut, *pSourceOut;
    hr = ConnectFilters ( m_pGraph, pSource, pXVID, &pSourceOut );      // MKV Source       -> XVID
    assert ( hr == S_OK );
    hr = ConnectFilters ( m_pGraph, pXVID, m_pFilter, &pOut );          // XVID             -> Texture Renderer
    assert ( hr == S_OK );

    // Connect the audio pins (not necessary)
    hr = ConnectFilters ( m_pGraph, pSource, pVorbis, &pOut );          // MKV Source       -> Vorbis Decoder
    hr = ConnectFilters ( m_pGraph, pVorbis, pDSound, &pOut );          // Vorbis Decoder   -> DirectSound renderer

    m_pGraph->QueryInterface ( IID_IMediaSeeking, reinterpret_cast < void** > ( &m_pMediaSeeking ) );
    assert ( m_pMediaSeeking != NULL );
    m_pGraph->QueryInterface ( IID_IMediaControl, reinterpret_cast < void** > ( &m_pMediaControl ) );
    if ( m_pMediaControl == NULL || m_pMediaSeeking == NULL ) return false;

    m_pGraph->QueryInterface ( IID_IBasicAudio, reinterpret_cast < void** > ( &m_pBasicAudio ) );
    if ( m_pBasicAudio == NULL ) return false;

    CCore::GetSingleton ().GetConsole ()->Printf ( "Successfully loaded video renderer" );

    m_pBasicAudio->get_Volume ( &lDefaultVolume );

    // Clean up
    delete [] wszFile;
//  m_pGraph->Release ();

    // Unlock the mutex
    Unlock ();

    return true;
}