HRESULT ConfigureVMR9(HWND window)
{
    assert(g_graph != NULL);

    HRESULT hr = S_OK;
    RECT rect;

    SmartPtr<IVMRFilterConfig9> filterConfig;

    // Create the VMR-9.
    FAIL_RET( CoCreateInstance(CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&g_filter) );

    // Configure the VMR-9.
    // Set the maximum number of video streams, and set windowless mode. 
    FAIL_RET( g_filter->QueryInterface(IID_IVMRFilterConfig9, reinterpret_cast<void**>(&filterConfig)) );

    FAIL_RET( filterConfig->SetNumberOfStreams( MAX_VIDEO_STREAMS ) );
    FAIL_RET( filterConfig->SetRenderingMode( VMR9Mode_Windowless ) );

    FAIL_RET( g_filter->QueryInterface(IID_IVMRWindowlessControl9, reinterpret_cast<void**>(&g_windowlessControl)) );
    FAIL_RET( g_windowlessControl->SetVideoClippingWindow( window ) );

    GetClientRect( window, & rect );
    FAIL_RET( g_windowlessControl->SetVideoPosition(NULL, & rect) );

    // Set the custom compositor on the VMR-9.

    g_compositor.Attach( new CMyCompositor9() );
    FAIL_RET( filterConfig->SetImageCompositor( g_compositor ));

    // Add the VMR-9 to the filter graph.
    FAIL_RET( g_graph->AddFilter(g_filter, L"Video Mixing Renderer 9") );

    return hr;
}
Esempio n. 2
0
HRESULT CSampleCGB::CreateAudioPin( IMpeg2Demultiplexer *pIMpeg2Demux )
{
	if(!pIMpeg2Demux)return E_INVALIDARG;

	//
	// for audio: could be Mpeg1, Mpeg2, AC3: if Mpeg1 failed (connect failed) try Mpeg2.if failed tried AC3
	// Audio struct of AC3 can be copied from dev code.
	//
	AM_MEDIA_TYPE amTypeAudio;
	amTypeAudio.majortype = MEDIATYPE_Audio;
	amTypeAudio.subtype = MEDIASUBTYPE_MPEG2_AUDIO;
	amTypeAudio.bFixedSizeSamples = TRUE;
	amTypeAudio.bTemporalCompression = 0;
	amTypeAudio.formattype = FORMAT_WaveFormatEx;
	amTypeAudio.pUnk = NULL;
	amTypeAudio.cbFormat = sizeof( MPEG1AudioFormat );
	amTypeAudio.pbFormat = MPEG1AudioFormat;

	SmartPtr<IPin> pAudioOutPin;
	HRESULT hr = pIMpeg2Demux->CreateOutputPin(&amTypeAudio,L"MpegAudio",&pAudioOutPin);
	if(FAILED(hr))return hr;

	SmartPtr<IMPEG2StreamIdMap> pIAudioPIDMap;
	hr = pAudioOutPin->QueryInterface(&pIAudioPIDMap);
	if(FAILED(hr))return hr;

	hr = pIAudioPIDMap->MapStreamId(AudPID_,MPEG2_PROGRAM_ELEMENTARY_STREAM,0,0);
	if(FAILED(hr))return hr;
	return hr;
}
Esempio n. 3
0
HRESULT CSampleCGB::CreateVideoPin( IMpeg2Demultiplexer *pIMpeg2Demux )
{
	if(!pIMpeg2Demux)return E_INVALIDARG;

	AM_MEDIA_TYPE amTypeVideo;
	amTypeVideo.majortype = MEDIATYPE_Video;
	amTypeVideo.subtype = MEDIASUBTYPE_MPEG2_VIDEO;
	amTypeVideo.bFixedSizeSamples = TRUE;
	amTypeVideo.bTemporalCompression = 0;
	amTypeVideo.formattype = FORMAT_MPEG2_VIDEO;
	amTypeVideo.pUnk = NULL;
	amTypeVideo.cbFormat = sizeof(Mpeg2ProgramVideo);
	amTypeVideo.pbFormat = Mpeg2ProgramVideo;

	//
	// Create video pin
	//

	SmartPtr<IPin> pVideoOutPin;
	HRESULT hr = pIMpeg2Demux->CreateOutputPin(&amTypeVideo,L"MpegVideo",&pVideoOutPin);
	if(FAILED(hr))return hr;

	SmartPtr<IMPEG2StreamIdMap> pIVideoPIDMap;
	hr = pVideoOutPin->QueryInterface(&pIVideoPIDMap);
	if(FAILED(hr))return hr;


	hr = pIVideoPIDMap->MapStreamId(VidPID_,MPEG2_PROGRAM_ELEMENTARY_STREAM,0,0);
	if(FAILED(hr))return hr;
	return hr;
}
Esempio n. 4
0
HRESULT 
ISampleCaptureGraphBuilder::SetOutputFileName(  const GUID *pType,
                                                LPCOLESTR lpwstrFile,
                                                IBaseFilter **ppf,
                                                IFileSinkFilter **pSink )
{
    if( ! pType || ! lpwstrFile || !ppf || !pSink )
    {
        return E_INVALIDARG;
    }

    if( !::IsEqualGUID( *pType, MEDIASUBTYPE_Mpeg2 ) )
    {
        return graphBuilder2_->SetOutputFileName(pType, lpwstrFile, ppf, pSink );
    }

    HRESULT hr;
    if( !graph_ )
    {
        hr = GetFiltergraph( &graph_ );
        if( FAILED( hr ) )
        {
            return hr;
        }
    }

    //
    //  Configure the dump filter
    //
    SmartPtr< IFileSinkFilter > pDump;
    hr = CoCreateInstance(CLSID_Dump, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&pDump);
    if( FAILED( hr ) )
    {
        return hr;
    }
    
    hr = pDump->SetFileName( lpwstrFile, NULL );
    if( FAILED( hr ) )
    {
        return hr;
    }

    hr = pDump.QueryInterface( &pMPEG2Demux_ );
    if( FAILED( hr ) )
    {
        return hr;
    }

    hr = graph_->AddFilter( pMPEG2Demux_, L"Dump" );
    if( FAILED( hr ) )
    {
        pMPEG2Demux_ = NULL;
        return hr;
    }

    
    *pSink = pDump;
    return S_OK;
}
Esempio n. 5
0
HRESULT SceneGraph::RecurentNotifyAddSceneContent(__in ISceneChangesNotificationListener *pListener, __in ISceneObjectGroup *pGroup)
{
    HRESULT hr = S_OK;
    UINT cnt = pGroup->GetObjectCount();
    for (UINT i = 0; i < cnt; i++)
    {
        SmartPtr<ISceneObject> spObj;
        hr = pGroup->GetObject(i, &spObj);
        if (FAILED(hr))
            break;

        (void)pListener->OnSceneObjectChanged(spObj, SOCT_OBJECT_ADD);

        SmartPtr<ISceneObjectGroup> spGroup;
        (void)spObj->QueryInterface(&spGroup);
        if (spGroup != NULL)
        {
            hr = RecurentNotifyAddSceneContent(pListener, spGroup); 
            if (FAILED(hr))
                break;
        }
    }
    return hr;
}
HRESULT StartGraph(HWND window)
{
    HRESULT hr = S_OK;

    const DWORD BUFFER_SIZE = MAX_PATH * MAX_VIDEO_STREAMS;

    MultiSelectFileList<BUFFER_SIZE> selectList;

    OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize         = sizeof(OPENFILENAME);
    ofn.hwndOwner           = g_hWnd;
    ofn.lpstrFilter         = TEXT("Video Files (.AVI, .MPG, .MPEG, .VOB, .WMV)\0*.AVI;*.MPG;*.MPEG;*.VOB;*.WMV\0") 
                              TEXT("All Files (*.*)\0*.*\0\0");
    ofn.nFilterIndex        = 1;
    ofn.lpstrFile           = selectList.BufferPtr();
    ofn.nMaxFile            = selectList.BufferSizeCch();
    ofn.lpstrTitle          = TEXT("Select a video file to play...");
    ofn.Flags               = OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST | OFN_EXPLORER;
    ofn.lpstrDefExt         = TEXT("AVI");
    
    // Launch the Open File dialog.
	DWORD result = GetOpenFileName(&ofn);

    // Check for errors.
    if (CommDlgExtendedError() != 0)
    {

        // NOTE: For mult-selection, CommDlgExtendedError can return FNERR_BUFFERTOOSMALL even when
        // GetOpenFileName returns TRUE.

        MessageBox(NULL, TEXT( "Could not open files." ), NULL, MB_OK | MB_ICONERROR);
        return E_FAIL;
    }
    else if (!result)
    {
        // The user cancelled. (No error occurred.)
        return S_OK;
    }

    FAIL_RET(hr = selectList.ParseBuffer());

    // Clear all DirectShow interfaces (COM smart pointers)
    g_compositor            = NULL;
    g_windowlessControl     = NULL;
    g_mediaControl          = NULL;
    g_filter                = NULL;
    g_graph                 = NULL;

    // Create the Filter Graph Manager.
    FAIL_RET( CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&g_graph) );

    // Configure the VMR-9.
    FAIL_RET( ConfigureVMR9(window) );

    // Render every file that the user selected.
    for (DWORD i = 0; i < MAX_VIDEO_STREAMS; i++)
    {
        TCHAR *pFileName = NULL;

        FAIL_RET(hr = selectList.Next(&pFileName));
        if (hr == S_FALSE)
        {
            hr = S_OK;
            break;
        }

		hr = g_graph->RenderFile( pFileName, NULL );

        CoTaskMemFree(pFileName);

        FAIL_RET(hr);

	}

    // Run the graph.

    FAIL_RET( g_graph->QueryInterface(IID_IMediaControl, reinterpret_cast<void**>(&g_mediaControl)) );

    FAIL_RET( g_mediaControl->Run() );

    return hr;
}
Esempio n. 7
0
HRESULT 
ISampleCaptureGraphBuilder::CreateVideoPin(
        IMpeg2Demultiplexer *pIMpeg2Demux )
{
    if( !pIMpeg2Demux )
    {
        return E_INVALIDARG;
    }

    AM_MEDIA_TYPE amTypeVideo;
    amTypeVideo.majortype = MEDIATYPE_Video;
    amTypeVideo.subtype = MEDIASUBTYPE_MPEG2_VIDEO;
    amTypeVideo.bFixedSizeSamples = TRUE;
    amTypeVideo.bTemporalCompression = 0;
    amTypeVideo.formattype = FORMAT_MPEG2Video;
    amTypeVideo.pUnk = NULL;
    amTypeVideo.cbFormat = sizeof( Mpeg2ProgramVideo );
    amTypeVideo.pbFormat = Mpeg2ProgramVideo;

    //
    // Create video pin
    //

    SmartPtr<IPin> pVideoOutPin;
    HRESULT hr = pIMpeg2Demux->CreateOutputPin( &amTypeVideo, L"MpegVideo", &pVideoOutPin );
    if( FAILED( hr ) )
    {
        return hr;
    }


    SmartPtr<IMPEG2StreamIdMap> pIVideoPIDMap;
    hr = pVideoOutPin->QueryInterface( &pIVideoPIDMap );
    if( FAILED( hr ) )
    {
        return hr;
    }

    hr = pIVideoPIDMap->MapStreamId(VidPID_, MPEG2_PROGRAM_ELEMENTARY_STREAM , 0, 0);
    if( FAILED( hr ) )
    {
        return hr;
    }


#ifdef USE_VMR
    //
    //  Get the VMR interface and add it to the graph
    //
    SmartPtr<IBaseFilter> pVMR;
    hr = pVMR.CoCreateInstance( CLSID_VideoMixingRenderer );
    if( FAILED( hr ) )
    {
        return hr;
    }

    hr = graph_->AddFilter( pVMR, L"VMR" );
    if( FAILED( hr ) )
    {
        return hr;
    }

    //
    //before rendering the VMR, make the number of streams 1
    //
    SmartPtr<IVMRFilterConfig> pConfig;
    hr = pVMR.QueryInterface( &pConfig );
    if( FAILED( hr ) )
    {
        return hr;
    }
    hr = pConfig->SetNumberOfStreams( 1 );
    if( FAILED( hr ) )
    {
        return hr;
    }


    //
    //  Get the input pin from the VMR
    //
    SmartPtr<IPin> pInputPin;
    hr = graphBuilder2_->FindPin(
            static_cast<IBaseFilter *>( pVMR ),  
            PINDIR_INPUT, 
            NULL, 
            NULL, 
            TRUE, 
            0, 
            &pInputPin
        );
    if( FAILED( hr ) )
    {

        hr = pIMpeg2Demux->DeleteOutputPin(L"MpegVideo");
        graph_->RemoveFilter( pVMR );
        return hr;
    }

    return graph_->Connect( pVideoOutPin, pInputPin );
#endif

    return hr;
}
HRESULT StartGraph(HWND window)
{
    // Clear DirectShow interfaces (COM smart pointers)
    CloseGraph(window);

    SmartPtr<IVMRFilterConfig9> filterConfig;


    BSTR path = GetMoviePath();
    if( ! path )
    {
        return E_FAIL;
    }

    HRESULT hr;
    
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&g_graph);

    if (SUCCEEDED(hr))
    {
        hr = CoCreateInstance(CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&g_filter);
    }

    if (SUCCEEDED(hr))
    {
        hr = g_filter->QueryInterface(IID_IVMRFilterConfig9, reinterpret_cast<void**>(&filterConfig));
    }

    if (SUCCEEDED(hr))
    {
        hr = filterConfig->SetRenderingMode( VMR9Mode_Renderless );

    }

    if (SUCCEEDED(hr))
    {
        hr = filterConfig->SetNumberOfStreams(2);

    }

    if (SUCCEEDED(hr))
    {
        hr = SetAllocatorPresenter( g_filter, window );
    }

    if (SUCCEEDED(hr))
    {
        hr = g_graph->AddFilter(g_filter, L"Video Mixing Renderer 9");
    }

    if (SUCCEEDED(hr))
    {
        hr = g_graph->QueryInterface(IID_IMediaControl, reinterpret_cast<void**>(&g_mediaControl));
    }

    if (SUCCEEDED(hr))
    {
        hr = g_graph->RenderFile( path, NULL );
    }

    if (SUCCEEDED(hr))
    {
        hr = g_mediaControl->Run();
    }

    SysFreeString(path);

    return hr;
}