首页 > 代码库 > 获取Filter的三种途径
获取Filter的三种途径
一、通过CLSID
[cpp] view plaincopyprint?
- IBaseFilter *pF = 0;
- HRESULT hr = CoCreateInstance(clsid, 0, CLSCTX_INPROC_SERVER,
- IID_IBaseFilter, reinterpret_cast<void**>(&pF));
二、通过系统枚举器
[cpp] view plaincopyprint?
- ICreateDevEnum *pSysDevEnum = NULL;
- hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
- IID_ICreateDevEnum, (void **)&pSysDevEnum);
- if (FAILED(hr))
- {
- return hr;
- }
- IEnumMoniker *pEnumCat = NULL;
- hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoCompressorCategory, &pEnumCat, 0);
- if (hr == S_OK)
- {
- IMoniker *pMoniker = NULL;
- ULONG cFetched;
- while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
- {
- IPropertyBag *pPropBag;
- hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
- (void **)&pPropBag);
- if (SUCCEEDED(hr))
- {
- VARIANT varName;
- VariantInit(&varName);
- hr = pPropBag->Read(L"FriendlyName", &varName, 0);
- IBaseFilter *pFilter;
- hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
- (void**)&pFilter);
- pPropBag->Release();
- }
- pMoniker->Release();
- }
- pEnumCat->Release();
- }
- pSysDevEnum->Release();
三、通过Filter Mapper
[cpp] view plaincopyprint?
- IFilterMapper2 *pMapper = NULL;
- IEnumMoniker *pEnum = NULL;
- hr = CoCreateInstance(CLSID_FilterMapper2,
- NULL, CLSCTX_INPROC, IID_IFilterMapper2,
- (void **) &pMapper);
- GUID arrayInTypes[2];
- arrayInTypes[0] = MEDIATYPE_Video;
- arrayInTypes[1] = MEDIASUBTYPE_dvsd;
- hr = pMapper->EnumMatchingFilters(
- &pEnum,
- 0, // Reserved.
- TRUE, // Use exact match?
- MERIT_DO_NOT_USE+1, // Minimum merit.
- TRUE, // At least one input pin?
- 1, // Number of major type/subtype pairs for input.
- arrayInTypes, // Array of major type/subtype pairs for input.
- NULL, // Input medium.
- NULL, // Input pin category.
- FALSE, // Must be a renderer?
- TRUE, // At least one output pin?
- 0, // Number of major type/subtype pairs for output.
- NULL, // Array of major type/subtype pairs for output.
- NULL, // Output medium.
- NULL); // Output pin category.
- IMoniker *pMoniker;
- ULONG cFetched;
- while (pEnum->Next(1, &pMoniker, &cFetched) == S_OK)
- {
- IPropertyBag *pPropBag = NULL;
- hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
- (void **)&pPropBag);
- if (SUCCEEDED(hr))
- {
- VARIANT varName;
- VariantInit(&varName);
- hr = pPropBag->Read(L"FriendlyName", &varName, 0);
- VariantClear(&varName);
- IBaseFilter *pFilter;
- hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, (void**)&pFilter);
- pPropBag->Release();
- }
- pMoniker->Release();
- }
- pMapper->Release();
- pEnum->Release();
第一种方法是最直接的,也最简单,不过当不清楚CLSID的时候,就不得不用后面两种方法。
第二种方法和第三中方法都是使用枚举器枚举Filter,通过匹配Filter的属性来得到Filter,它们不同之处在于:第二种通过确定的种类获得枚举器,第三种通过媒体类型获得枚举器。获得枚举器以后的步骤是相同的。
这三种方法最常用的是第二种。
获取Filter的三种途径
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。