Directshow 注册 source filter
编写source filter最初需要接触的就是 filter的register和unregister,涉及到的函数有两个
DllRegisterServer()
以及
DllUnregisterServer()
在这两个函数中,完成了filter的register和unregister
而其中真正的注册,又是通过IFilterMapper2::RegisterFilter() 和 IFilterMapper2::UnregisterFilter()
来实现的。
我们需要在注册时将Filter放入不同的category,譬如 video capture source / directshow filters (使用GraphEdit可以看到,不同的category下的filters)。注册在video capture source下的filter可以在AMCapture / QQ 等AP,搜索video capture source filters出现。
- STDAPI DllRegisterServer()
- {
- // return AMovieDllRegisterServer2(TRUE);
- HRESULT hr;
- IFilterMapper2 *pFM2 = NULL;
- hr = AMovieDllRegisterServer2(TRUE);
- if (FAILED(hr))
- {
- return hr;
- }
- hr = CoCreateInstance(CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, IID_IFilterMapper2, (void**)&pFM2);
- if (FAILED(hr))
- {
- return hr;
- }
- hr = pFM2->RegisterFilter(CLSID_UVCPreview, L"UVC preview", NULL, &CLSID_VideoInputDeviceCategory, L"UVC preview", &rf2FilterReg);
- pFM2->Release();
- return hr;
- } // DllRegisterServer
- //
- // DllUnregisterServer
- //
- STDAPI DllUnregisterServer()
- {
- // return AMovieDllRegisterServer2(FALSE);
- HRESULT hr;
- IFilterMapper2 *pFM2 = NULL;
- hr = AMovieDllRegisterServer2(FALSE);
- if (FAILED(hr))
- {
- return hr;
- }
- hr = CoCreateInstance(CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, IID_IFilterMapper2, (void **)&pFM2);
- if (FAILED(hr))
- {
- return hr;
- }
- hr = pFM2->UnregisterFilter(&CLSID_VideoInputDeviceCategory, L"UVC preview", CLSID_UVCPreview);
- pFM2->Release();
- return hr;
- } // DllUnregisterServer
其中 IFilterMapper2::RegisterFilter()参数:
- HRESULT RegisterFilter(
- REFCLSID clsidFilter,
- LPCWSTR Name,
- IMoniker **ppMoniker,
- const CLSID *pclsidCategory,
- const OLECHAR *szInstance,
- const REGFILTER2 *prf2
- );
- Parameters
- clsidFilter
- [in] Class identifier (CLSID) of the filter.
- Name
- [in] Descriptive name for the filter.
- ppMoniker
- [in, out] Address of a pointer to a device moniker that determines where this filter's data will be written. Can be NULL.
- pclsidCategory
- [in] Pointer to the filter category of the filter. If NULL, the default category is CLSID_ActiveMovieFilters. (See Filter Categories.)
- szInstance
- [in] Instance data for constructing the device moniker's display name. Can be the friendly name, or the string representation of the filter CLSID. If NULL, defaults to the filter CLSID.
- prf2
- [in] Pointer to a REGFILTER2 structure containing filter information.
- Return Values
- Returns an HRESULT value. Possible values include those shown in the following table.
- Value Description
- S_OK Success.
- VFW_E_BAD_KEY Could not get registry key.
而Category主要包括:
- The following categories are defined in Uuids.h. They are defiined when you include Dshow.h.
- Friendly Name CLSID Merit
- Audio Capture Sources CLSID_AudioInputDeviceCategory MERIT_DO_NOT_USE
- Audio Compressors CLSID_AudioCompressorCategory MERIT_DO_NOT_USE
- Audio Renderers CLSID_AudioRendererCategory MERIT_NORMAL
- Device Control Filters CLSID_DeviceControlCategory MERIT_DO_NOT_USE
- DirectShow Filters CLSID_LegacyAmFilterCategory MERIT_NORMAL
- External Renderers CLSID_TransmitCategory MERIT_DO_NOT_USE
- Midi Renderers CLSID_MidiRendererCategory MERIT_NORMAL
- Video Capture Sources CLSID_VideoInputDeviceCategory MERIT_DO_NOT_USE
- Video Compressors CLSID_VideoCompressorCategory MERIT_DO_NOT_USE
- Video Effects (1 input) CLSID_VideoEffects1Category MERIT_DO_NOT_USE
- Video Effects (2 inputs) CLSID_VideoEffects2Category MERIT_DO_NOT_USE
- WDM Streaming Capture Devices AM_KSCATEGORY_CAPTURE MERIT_DO_NOT_USE
- WDM Streaming Crossbar Devices AM_KSCATEGORY_CROSSBAR MERIT_DO_NOT_USE
- WDM Streaming Rendering Devices AM_KSCATEGORY_RENDER MERIT_DO_NOT_USE
- WDM Streaming Tee/Splitter Devices AM_KSCATEGORY_SPLITTER MERIT_DO_NOT_USE
- WDM Streaming TV Audio Devices AM_KSCATEGORY_TVAUDIO MERIT_DO_NOT_USE
- WDM Streaming TV Tuner Devices AM_KSCATEGORY_TVTUNER MERIT_DO_NOT_USE
- WDM Streaming VBI Codecs AM_KSCATEGORY_VBICODEC MERIT_DO_NOT_USE
- ActiveMovie Filter Categories CLSID_ActiveMovieCategories Not applicable
- The following categories are defined in the header file Ks.h:
- Friendly Name CLSID Merit
- WDM Streaming Communication Transforms KSCATEGORY_COMMUNICATIONSTRANSFORM MERIT_DO_NOT_USE
- WDM Streaming Data Transforms KSCATEGORY_DATATRANSFORM MERIT_DO_NOT_USE
- WDM Streaming Interface Transforms KSCATEGORY_INTERFACETRANSFORM MERIT_DO_NOT_USE
- WDM Streaming Mixer Devices KSCATEGORY_MIXER MERIT_DO_NOT_USE
- The following categories are defined in the header file Ksmedia.h. Include these header files, in the order listed:
- #include <ks.h>
- #include <ksmedia.h>
- Friendly Name CLSID Merit
- WDM Streaming System Audio Devices KSCATEGORY_AUDIO_DEVICE MERIT_DO_NOT_USE
- The following categories are defined in the header file Bdamedia.h. Include these header files, in the order listed:
- #include <ks.h>
- #include <ksmedia.h>
- #include <bdamedia.h>
- Friendly Name CLSID Merit
- BDA CP/CA Filters Category CLSID_CPCAFiltersCategory MERIT_NORMAL
- BDA Network Providers KSCATEGORY_BDA_NETWORK_PROVIDER MERIT_NORMAL
- BDA Receiver Components KSCATEGORY_BDA_RECEIVER_COMPONENT MERIT_NORMAL
- BDA Rendering Filters KSCATEGORY_IP_SINK MERIT_DO_NOT_USE
- BDA Source Filters KSCATEGORY_BDA_NETWORK_TUNER MERIT_DO_NOT_USE
- BDA Transport Information Renderers KSCATEGORY_BDA_TRANSPORT_INFORMATION MERIT_NORMAL
其中:
CLSID_VideoInputDeviceCategory, 注册到此category后,filter会出现在video capture source category下,被AMCapture / QQ等AP搜索到。
CLSID_LegacyAmFilterCategory, 注册到此category后,filter会出现在 directshow filters category,大部分的filter注册在此category。
需要注意的是 register / unregister 必须在同一个category, 使用同一 REFCLSID, 否则会出现register error。
譬如:
0x80070002 : register / unregister 未在同一个 category
0x80070005 : register / unregister 权限不够 (vista下权限管理,需要在administor下register/unregister filter)