All-in-one Decoder Directshow Filter

How to use the All-in-one Decoder Directshow Filter



This article is intended to show you how to use the All-in-one Decoder Directshow Filters in a simple application with default parameters.

Start by calling CoInitialize to initialize the COM library:     

HRESULT hr = CoInitialize(NULL);


Next, call CoCreateInstance to create the Filter Graph Manager.

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


Next, call CoCreateInstance to create the All-in-one Decoder filter.

CComPtr <IBaseFilter> pSourceFilter;
pSourceFilter.CoCreateInstance(CLSID_AllInOneDecoder);
pGraph->AddFilter(pSourceFilter,L"All-in-one Decoder");
CComQIPtr< IFileSourceFilter, &IID_IFileSourceFilter > pLoad( pSourceFilter );
hr=pLoad->Load(strFile, NULL);
if( FAILED(hr) )
{
return hr;
}


Next, call CoCreateInstance to create the VMR9 Video Renderer.

CComPtr <IBaseFilter> pVideoRenderer;
hr=pVideoRenderer.CoCreateInstance(CLSID_VideoMixingRenderer9);
if( FAILED(hr) )
{
return hr;
}
pGraph->AddFilter(pVideoRenderer,L"VMR9 Renderer");
CComPtr <IVMRFilterConfig9> pConfig;
pVideoRenderer->QueryInterface(IID_IVMRFilterConfig9, (void**)&pConfig);
pConfig->SetRenderingMode(VMR9Mode_Windowless);


Next, Setup the VMR9 Video Renderer.

CComPtr<IVMRWindowlessControl9> windowlessCtrl;
RECT rc;
if (pVideoRenderer) {
hr = pVideoRenderer->QueryInterface(IID_IVMRWindowlessControl9, (void**)&windowlessCtrl);
 if (FAILED(hr)) {
 return hr;
 }
}
if (windowlessCtrl) {
windowlessCtrl->SetVideoClippingWindow(m_hWnd);
::GetClientRect(m_hWnd, &rc);
windowlessCtrl->SetVideoPosition(0, &rc);
windowlessCtrl->SetAspectRatioMode(VMR9ARMode_LetterBox);
windowlessCtrl.Release();
}


 Next, Render the Video Pin and Audio Pin of All-in-one Decoder

CComPtr<IEnumPins> pEnumPins;
if(FAILED(hr = pSourceFilter->EnumPins(&pEnumPins)))
{
return hr;
}
CComPtr<IPin> pPin;
ULONG uFetched = 0;
while(S_OK == pEnumPins->Next(1, &pPin, &uFetched))
{
 if(FAILED(hr = pGraph->Render(pPin)))
 {
 return hr;
 }
pPin.Release();
}



Finally, run the graph
 

OAFilterState fs = State_Paused;
CComQIPtr<IMediaControl,&IID_IMediaControl> pMediaControl(pGraph);
if( !pMediaControl )
return E_NOINTERFACE;
hr = pMediaControl->GetState(INFINITE,&fs);
if( FAILED(hr) )
return hr;
hr=pMediaControl->Run();


When the filter graph runs, data moves through the filters and is rendered as video and audio. Playback occurs on a separate thread. You can wait for playback to complete by calling the IMediaEvent::WaitForCompletion method:

 

long evCode = 0;
pEvent->WaitForCompletion(INFINITE, &evCode);

When you close your application, close the COM library.
 

CoUninitialize();