The first thing that needs to be written into the source filter is the filter's register and unregister. The involved functions include:
Dllregisterserver ()
And
Dllunregisterserver ()
In these two functions, the filter's register and unregister are completed.
The real registration is performed through ifiltermapper2: registerfilter () and ifiltermapper2: unregisterfilter ()
.
We need to put the filter into different category during registration, for example, video capture source/DirectShow filters (the filters under different category can be seen through graphedit ). Filters registered under video capture source can appear in amcapture/qq ap and search for video capture source filters.
Stdapi dllregisterserver () <br/>{< br/> // return amoviedllregisterserver2 (true); <br/> hresult hr; <br/> ifiltermapper2 * pfm2 = NULL; <br/> hR = amoviedllregisterserver2 (true); <br/> If (failed (HR) <br/>{< br/> return hr; <br/>}< br/> hR = cocreateinstance (clsid_filtermapper2, null, clsctx_inproc_server, iid_ifiltermapper2, (void **) & pfm2 ); <br/> If (failed (HR) <br/>{< br/> return hr; <br/>}< br/> hR = pfm2-> registerfilter (clsid_uvcpreview, l "UVC preview", null, & clsid_videoinputdevicecategory, l "UVC preview", & rf2filterreg ); <br/> pfm2-> release (); <br/> return hr; <br/>}// dllregisterserver </P> <p> // <br/> // dllunregisterserver <br/> // <br/> stdapi dllunregisterserver () <br/>{< br/> // return amoviedllregisterserver2 (false); <br/> hresult hr; <br/> ifiltermapper2 * pfm2 = NULL; <br/> hR = amoviedllregisterserver2 (false); <br/> If (failed (HR) <br/>{< br/> return hr; <br/>}< br/> hR = cocreateinstance (clsid_filtermapper2, null, clsctx_inproc_server, iid_ifiltermapper2, (void **) & pfm2 ); <br/> If (failed (HR) <br/>{< br/> return hr; <br/>}< br/> hR = pfm2-> unregisterfilter (& clsid_videoinputdevicecategory, l "UVC preview", clsid_uvcpreview); <br/> pfm2-> release (); <br/> return hr; <br/>} // dllunregisterserver
Ifiltermapper2: registerfilter () parameter:
Hresult registerfilter (<br/> refclsid clsidfilter, <br/> lpcwstr name, <br/> imoniker ** ppmoniker, <br/> const CLSID * pclsidcategory, <br/> const olechar * szinstance, <br/> const regfilter2 * prf2 <br/> ); <br/> parameters <br/> clsidfilter <br/> [in] Class Identifier (CLSID) of the filter. <br/> name <br/> [in] descriptive name for the filter. <br/> ppmoniker <br/> [In, out] address of a pointer to a device moniker that determines where this filter's data will be written. can be null. <br/> pclsidcategory <br/> [in] pointer to the filter category of the filter. if null, the default category is clsid_activemoviefilters. (See filter categories .) <br/> szinstance <br/> [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. <br/> prf2 <br/> [in] pointer to a regfilter2 structure containing filter information. <br/> return values <br/> Returns An hresult value. possible values include those shown in the following table. <br/> value description <br/> s_ OK success. <br/> vfw_e_bad_key cocould not get registry key. <br/>
The category mainly includes:
The following categories are defined in uuids. h. they are defiined when you include dshow. h. <br/> friendly name CLSID merit <br/> audio capture sources extends merit_do_not_use <br/> audio compressors extends regular <br/> audio renderers implements merit_normal <br/> device control filters clsid_devicecontrolcategory Category <br/> DirectShow filters regular merit_normal <br/> external renderers clsid_transmitcategory Category <br/> MIDI renderers regular merit_normal <br/> video capture sources regular video <br/> compressors clsid_videocompressorcategory merit_do_not_use <br/> Video Effects (1 input) clsid_videoft-ts1category merit_do_not_use <br/> Video Effects (2 inputs) stored Procedure <br/> WDM streaming capture devices using merit_do_not_use <br/> WDM streaming crossbar devices using merit_do_not_use <br/> WDM streaming rendering devices using procedure <br/> WDM streaming tee/ splitter devices available soon <br/> WDM streaming TV audio devices available merit_do_not_use <br/> WDM streaming TV tuner devices available merit_do_not_use <br/> WDM streaming VBI codecs available soon <br/> activemovie filter categories clsid_activemoviecategories not applicable </P> <p> The following categories are defined in the header file Ks. h: <br/> friendly name CLSID merit <br/> WDM streaming communication transforms authentication <br/> WDM streaming data transforms authentication merit_do_not_use <br/> WDM streaming interface transforms authentication merit_do_not_use <br /> WDM streaming mixer devices kscategory_mixer merit_do_not_use </P> <p> The following categories are defined in the header file ksmedia. h. include these header files, in the order listed: <br/> # include <Ks. h> <br/> # include <ksmedia. h> <br/> friendly name CLSID merit <br/> WDM streaming system audio devices kscategory_audio_device merit_do_not_use </P> <p> The following categories are defined in the header file bdamedia. h. include these header files, in the order listed: <br/> # include <Ks. h> <br/> # include <ksmedia. h> <br/> # include <bdamedia. h> <br/> friendly name CLSID merit <br/> using CP/CA filters category implements merit_normal <br/> using network providers kscategory_bda_provider merit_normal <br/> using javaser components implements merit_normal <br/> specify rendering filters kscategory_ip_sink merit_do_not_use <br/> specify source filters into merit_do_not_use <br/> specify transport information renderers into merit_normal <br/>
Where:
Clsid_videoinputdevicecategory. After registering this category, the filter will appear under the video capture source category and be searched by amcapture/QQ and other APs.
Clsid_legacyamfiltercategory: After you register this category, the filter will appear in DirectShow filters category. Most filters are registered in this category.
Note that register/unregister must be in the same category and use the same refclsid. Otherwise, a register error occurs.
For example:
0x80070002: Register/unregister is not in the same category
0x80070005: Register/unregister permissions are insufficient (permission management in Vista requires register/unregister filter in administor)