Obtaining a Pointer to the Reader Object
Microsoft DirectShow 9.0 |
Obtaining a Pointer to the Reader Object
In certain cases, for example when determining which data unit extensions are set on a given stream, you may need to access the Reader Object of the Windows Media Format SDK directly. The following function shows how to obtain the IWMReaderAdvanced2 interface on the Reader Object itself:
#include <wmsdk.h> HRESULT GetReaderAdvanced(IGraphBuilder *pGraph, IWMReaderAdvanced2** pReaderAdvanced2) { // We use CComPtr's to avoid headaches at cleanup time CComPtr<IEnumFilters> pEnum; CComPtr<IBaseFilter> pFilter; ULONG cFetched; HRESULT hr = pGraph->EnumFilters(&pEnum); if (FAILED(hr)) { return hr; } while(pEnum->Next(1, &pFilter, &cFetched) == S_OK) { IWMHeaderInfo *pHI = NULL; // Only the WM ASF Reader will have interface. hr = pFilter->QueryInterface(__uuidof(IWMHeaderInfo), (void**)&pHI); if (SUCCEEDED(hr)) { // We use the IWMDRMReader interface only as a way to get // a pointer to the Reader Object. CComPtr<IWMDRMReader> pWMDRMReader; CComQIPtr<IServiceProvider, &IID_IServiceProvider> pSP; hr = pHI->QueryInterface(__uuidof(IServiceProvider), (void**)&pSP); if (!pSP) { return E_NOINTERFACE; } hr = pSP->QueryService(IID_IWMDRMReader, IID_IWMDRMReader, (void **) &pWMDRMReader); if (FAILED(hr)) { return hr; } CComQIPtr<IWMReaderAdvanced2, &IID_IWMReaderAdvanced2> pRA2(pWMDRMReader); if (pRA2) { *pReaderAdvanced2 = pRA2.Detach(); return S_OK; } } pFilter.Release(); } //if we get here, we didn't find the WM ASF Reader return E_FAIL; }
See Also