【转】Directshow 注册 source filter

原文地址: http://blog.csdn.net/jtujtujtu/archive/2009/04/20/4093773.aspx
300) { text = text + "\r\n\n本文来自CSDN博客,转载请标明出处:" + location.href; clipboardData.setData("text", text); } }, 100); } } 编写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出现。

  1. STDAPI DllRegisterServer()  
  2. {  
  3. //    return AMovieDllRegisterServer2(TRUE);  
  4.     HRESULT hr;  
  5.     IFilterMapper2 *pFM2 = NULL;  
  6.     hr = AMovieDllRegisterServer2(TRUE);  
  7.     if (FAILED(hr))  
  8.     {  
  9.         return hr;  
  10.     }  
  11.     hr = CoCreateInstance(CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, IID_IFilterMapper2, (void**)&pFM2);  
  12.     if (FAILED(hr))  
  13.     {  
  14.         return hr;  
  15.     }  
  16.     hr = pFM2->RegisterFilter(CLSID_UVCPreview, L"UVC preview", NULL, &CLSID_VideoInputDeviceCategory, L"UVC preview", &rf2FilterReg);  
  17.     pFM2->Release();  
  18.     return hr;  
  19. // DllRegisterServer  
  20.   
  21. //  
  22. // DllUnregisterServer  
  23. //  
  24. STDAPI DllUnregisterServer()  
  25. {  
  26. //    return AMovieDllRegisterServer2(FALSE);  
  27.     HRESULT hr;  
  28.     IFilterMapper2 *pFM2 = NULL;  
  29.     hr = AMovieDllRegisterServer2(FALSE);  
  30.     if (FAILED(hr))  
  31.     {  
  32.         return hr;  
  33.     }  
  34.     hr = CoCreateInstance(CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, IID_IFilterMapper2, (void **)&pFM2);  
  35.     if (FAILED(hr))  
  36.     {  
  37.         return hr;  
  38.     }  
  39.     hr = pFM2->UnregisterFilter(&CLSID_VideoInputDeviceCategory, L"UVC preview", CLSID_UVCPreview);  
  40.     pFM2->Release();  
  41.     return hr;  
  42. // DllUnregisterServer  
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()参数:

  1. HRESULT RegisterFilter(  
  2.   REFCLSID clsidFilter,  
  3.   LPCWSTR Name,  
  4.   IMoniker **ppMoniker,  
  5.   const CLSID *pclsidCategory,  
  6.   const OLECHAR *szInstance,  
  7.   const REGFILTER2 *prf2  
  8. );  
  9. Parameters  
  10. clsidFilter  
  11. [in] Class identifier (CLSID) of the filter.  
  12. Name  
  13. [in] Descriptive name for the filter.  
  14. ppMoniker  
  15. [inout] Address of a pointer to a device moniker that determines where this filter's data will be written. Can be NULL.  
  16. pclsidCategory  
  17. [in] Pointer to the filter category of the filter. If NULL, the default category is CLSID_ActiveMovieFilters. (See Filter Categories.)  
  18. szInstance  
  19. [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.  
  20. prf2  
  21. [in] Pointer to a REGFILTER2 structure containing filter information.  
  22. Return Values  
  23. Returns an HRESULT value. Possible values include those shown in the following table.  
  24. Value Description   
  25. S_OK Success.   
  26. VFW_E_BAD_KEY Could not get registry key.   
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主要包括:

  1. The following categories are defined in Uuids.h. They are defiined when you include Dshow.h.  
  2. Friendly Name CLSID Merit   
  3. Audio Capture Sources CLSID_AudioInputDeviceCategory MERIT_DO_NOT_USE   
  4. Audio Compressors CLSID_AudioCompressorCategory MERIT_DO_NOT_USE   
  5. Audio Renderers CLSID_AudioRendererCategory MERIT_NORMAL   
  6. Device Control Filters CLSID_DeviceControlCategory MERIT_DO_NOT_USE   
  7. DirectShow Filters CLSID_LegacyAmFilterCategory MERIT_NORMAL   
  8. External Renderers CLSID_TransmitCategory MERIT_DO_NOT_USE   
  9. Midi Renderers CLSID_MidiRendererCategory MERIT_NORMAL   
  10. Video Capture Sources CLSID_VideoInputDeviceCategory MERIT_DO_NOT_USE   
  11. Video Compressors CLSID_VideoCompressorCategory MERIT_DO_NOT_USE   
  12. Video Effects (1 input) CLSID_VideoEffects1Category MERIT_DO_NOT_USE   
  13. Video Effects (2 inputs) CLSID_VideoEffects2Category MERIT_DO_NOT_USE   
  14. WDM Streaming Capture Devices AM_KSCATEGORY_CAPTURE MERIT_DO_NOT_USE   
  15. WDM Streaming Crossbar Devices AM_KSCATEGORY_CROSSBAR MERIT_DO_NOT_USE   
  16. WDM Streaming Rendering Devices AM_KSCATEGORY_RENDER MERIT_DO_NOT_USE   
  17. WDM Streaming Tee/Splitter Devices AM_KSCATEGORY_SPLITTER MERIT_DO_NOT_USE   
  18. WDM Streaming TV Audio Devices AM_KSCATEGORY_TVAUDIO MERIT_DO_NOT_USE   
  19. WDM Streaming TV Tuner Devices AM_KSCATEGORY_TVTUNER MERIT_DO_NOT_USE   
  20. WDM Streaming VBI Codecs AM_KSCATEGORY_VBICODEC MERIT_DO_NOT_USE   
  21. ActiveMovie Filter Categories CLSID_ActiveMovieCategories Not applicable   
  22.   
  23. The following categories are defined in the header file Ks.h:  
  24. Friendly Name CLSID Merit   
  25. WDM Streaming Communication Transforms KSCATEGORY_COMMUNICATIONSTRANSFORM MERIT_DO_NOT_USE   
  26. WDM Streaming Data Transforms KSCATEGORY_DATATRANSFORM MERIT_DO_NOT_USE   
  27. WDM Streaming Interface Transforms KSCATEGORY_INTERFACETRANSFORM MERIT_DO_NOT_USE   
  28. WDM Streaming Mixer Devices KSCATEGORY_MIXER MERIT_DO_NOT_USE   
  29.   
  30. The following categories are defined in the header file Ksmedia.h. Include these header files, in the order listed:  
  31. #include   
  32. #include   
  33. Friendly Name CLSID Merit   
  34. WDM Streaming System Audio Devices KSCATEGORY_AUDIO_DEVICE MERIT_DO_NOT_USE   
  35.   
  36. The following categories are defined in the header file Bdamedia.h. Include these header files, in the order listed:  
  37. #include   
  38. #include   
  39. #include     
  40. Friendly Name CLSID Merit   
  41. BDA CP/CA Filters Category CLSID_CPCAFiltersCategory MERIT_NORMAL   
  42. BDA Network Providers KSCATEGORY_BDA_NETWORK_PROVIDER MERIT_NORMAL   
  43. BDA Receiver Components KSCATEGORY_BDA_RECEIVER_COMPONENT MERIT_NORMAL   
  44. BDA Rendering Filters KSCATEGORY_IP_SINK MERIT_DO_NOT_USE   
  45. BDA Source Filters KSCATEGORY_BDA_NETWORK_TUNER MERIT_DO_NOT_USE   
  46. BDA Transport Information Renderers KSCATEGORY_BDA_TRANSPORT_INFORMATION MERIT_NORMAL   
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 #include 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 #include #include 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)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/634491/viewspace-661564/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/634491/viewspace-661564/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值