本文整理汇总了C++中CComPtr::AddSourceFilter方法的典型用法代码示例。如果您正苦于以下问题:C++ CComPtr::AddSourceFilter方法的具体用法?C++ CComPtr::AddSourceFilter怎么用?C++ CComPtr::AddSourceFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CComPtr
的用法示例。
在下文中一共展示了CComPtr::AddSourceFilter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
bool DShowAudioSource::load(const RString& path)
{
mPath = path;
HRESULT hr = S_OK;
// Create the graph builder
CComPtr<IGraphBuilder> pGraphBuilder;
hr = pGraphBuilder.CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER);
if(FAILED(hr))
return false;
// Create the sample grabber filter
CComPtr<IBaseFilter> pSampleGrabberBaseFilter;
hr = pSampleGrabberBaseFilter.CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER);
if(FAILED(hr))
return false;
// Add the sample grabber filter to the graph
hr = pGraphBuilder->AddFilter(pSampleGrabberBaseFilter, L"Sample Grabber");
if(FAILED(hr))
return false;
// Get the Sample Grabber interface
CComQIPtr<ISampleGrabber> pSampleGrabberFilter(pSampleGrabberBaseFilter);
if(pSampleGrabberFilter == 0)
return false;
// Set the sample grabber's media type
AM_MEDIA_TYPE mt;
ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
mt.majortype = MEDIATYPE_Audio;
mt.subtype = MEDIASUBTYPE_PCM;
mt.formattype = FORMAT_WaveFormatEx;
hr = pSampleGrabberFilter->SetMediaType(&mt);
if(FAILED(hr))
return false;
// Create the sample grabber callback
mpSampleGrabberCallback.Attach(new SampleGrabberCallback(this));
hr = pSampleGrabberFilter->SetCallback(mpSampleGrabberCallback, 1);
if(FAILED(hr))
return false;
// Add the source filter to the graph
WCHAR filename[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0,mPath.c_str(), -1, filename, MAX_PATH);
CComPtr<IBaseFilter> pSourceFilter;
hr = pGraphBuilder->AddSourceFilter(filename, L"Audio Source", &pSourceFilter);
if(FAILED(hr))
return false;
// Create the NULL renderer. We are only decoding
CComPtr<IBaseFilter> pNullRenderer;
hr = pNullRenderer.CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER);
hr = pGraphBuilder->AddFilter(pNullRenderer, L"NULL Renderer");
// Connect input to sample grabber
hr = ConnectFilters(pGraphBuilder, pSourceFilter, pSampleGrabberBaseFilter);
if(FAILED(hr))
return false;
// Connect sample grabber to NULL renderer
hr = ConnectFilters(pGraphBuilder, pSampleGrabberBaseFilter, pNullRenderer);
if(FAILED(hr))
return false;
// Get some useful interfaces
mpMediaControl = pGraphBuilder;
if(mpMediaControl == 0)
return false;
mpMediaEvent = pGraphBuilder;
if(mpMediaEvent == 0)
return false;
mpMediaSeeking = pGraphBuilder;
if(mpMediaSeeking == 0)
return false;
// Get the waveformatex structure
pSampleGrabberFilter->GetConnectedMediaType(&mt);
mpWaveFormatEx = reinterpret_cast<WAVEFORMATEX*>(mt.pbFormat);
hr = mpMediaSeeking->SetTimeFormat(&TIME_FORMAT_MEDIA_TIME);
if(FAILED(hr))
return false;
CComQIPtr<IMediaFilter> pMediaFilter(pGraphBuilder);
pMediaFilter->SetSyncSource(0);
mCurrentPosition = 0;
mEOF = false;
printf("# channels = %d\n", mpWaveFormatEx->nChannels);
printf("Sample rate = %d\n", mpWaveFormatEx->nSamplesPerSec);
return true;
}