Register DirectShow filter Information reprint _filter

Source: Internet
Author: User
Register DirectShow filter Information collection

Write your own DirectShow Filter, in addition to writing the implementation function of the code, to make their own DLL called a Filter, there is an important job to do, that is, registration information. DirectShow filter has two kinds of information registration, one is the DLL containing the filter as the registration information of the COM component, one kind is registers the filter kind information.

When the application creates the Filter through Cocreateinstane, the DLL is positioned through the first registration information.

After registering the second information, the System device enumerator and filter mapped can be positioned to filter, this information is not required to register, when not registered, Filter is default to Clsid_legacyamfiltercategory type.

Register the Filter type information by step:

One, declare Filter information

View plain Copy to clipboard print? Amoviesetup_mediatype, Amoviesetup_pin, amoviesetup_filter   1. amoviesetup_mediatype   typedef   struct    {       const  CLSID *clsMajorType; Main media type        const  CLSID *clsMinorType; Sub media type, you can use Mediasubtype_null   } regpintypes;   typedef  REGPINTYPES  amoviesetup_mediatype,        * PAMOVIESETUP_MEDIATYPE,     * lpamoviesetup_mediatype;      2. amoviesetup_pin   typedef   struct  {       lpwstr              strName; has been discarded, can be populated output or input, indicating the type of pin        bool                bRendered; True means this is render's input p.In, all others use false        bool                bOutput; True indicates that this is output pin.        bool                bZero; True indicates that the filter can contain 0 instances of this pin.        bool                bMany; True indicates that filter can contain an instance of two or more of this pin.        const  clsid       * Clsconnectstofilter; have been discarded, filled clsid_null        const   WCHAR         *strConnectsToPin; has been discarded, filled with null        uint                nMediaTypes; How many media types        const  REGPINTYPES *LP the pin can supportmediatype;  amoviesetup_mediatype object, describing media type   } regfilterpins;   typedef  regfilterpins  AMOVIESETUP_PIN,        * PAMOVIESETUP_PIN,        * LPAMOVIESETUP_PIN;      3. amoviesetup_filter   typedef   struct  _AMOVIESETUP_FILTER {        const  CLSID           *clsID; Filter ClassID        const   WCHAR           *strName; Name of filter        dword                 dwMerit;        uint                    nPins; A Amoviesetup_pin object in the LppinNumber        const  AMOVIESETUP_PIN *lpPin;  amoviesetup_pin Object Pointers   } amoviesetup_filter, * pamoviesetup_filter, *  FAR LPAMOVIESETUP_FILTER;   Amoviesetup_mediatype, Amoviesetup_pin, Amoviesetup_filter 1. amoviesetup_mediatype typedef struct {const CLSID *clsmajortype;//Primary Media Type const CLSID *clsminortype;//sub Media type, You can use mediasubtype_null} regpintypes; typedef regpintypes AMOVIESETUP_MEDIATYPE, * pamoviesetup_mediatype, * lpamoviesetup_mediatype; 2. amoviesetup_pin typedef struct {LPWSTR strname;//has been discarded and can be populated with output or input, indicating the type of PIN BOOL brendered;// True indicates that this is a render input pin, and all others use false BOOL Boutput;//true to indicate that this is an output pin. BOOL Bzero;//true indicates that the filter can contain 0 instances of this pin. BOOL Bmany;//true indicates that the filter can contain two or more instances of this pin. The const CLSID *clsconnectstofilter;//has been discarded, filled Clsid_null const WCHAR *strconnectstopin;//has been discarded, filled with NULL UINT nmediatypes;// How many media types can the PIN support const regpintypes *lpmediatype;//Amoviesetup_mediatype objects, describing media types} regfiltErpins; typedef regfilterpins Amoviesetup_pin, * pamoviesetup_pin, * lpamoviesetup_pin; 3. ClassID Const WCHAR *strname;//of amoviesetup_filter typedef struct _AMOVIESETUP_FILTER {const CLSID *clsid;//filter The name of the filter the number of Amoviesetup_pin objects in the DWORD dwmerit;//UINT npins;//lppin const amoviesetup_pin *lppin;//Amoviesetup_pin Object pointers } amoviesetup_filter, * pamoviesetup_filter, * FAR lpamoviesetup_filter;

Second, declare class factory

View plain Copy to clipboard print? cfactorytemplate g_templates[] = {           {  l "Myfilter"//filter name            , &clsid_ Myfilter//filter's ClassID            , cmysourcefilter:: Createinstance//filter Interface            , NULL            , &sudballax }// amoviesetup_filter Objects        };   int  g_cTemplates =  sizeof (g_templates)  /   sizeof (G_templates[0]);   cfactorytemplate g_templates[] = {L "myfilter"//filter name, &clsid_ Myfilter//filter ClassID, Cmysourcefilter::createinstance//filter instantiation interface, NULL, &sudballax}//amoviesetup_ Filter Object}; int g_ctemplates = sizeof (g_templates)/sizeof (G_templatEs[0]);

Third, heavy duty DllRegisterServer

View plain Copy to clipboard print? regfilter2 rf2filterreg = {       1,               // pin uses Amoviesetup_pin, so the version is 1         merit_normal,   // merit.        1,               // number of pins.        &sudPins        //  Pointer to pin information.   };      stdapi dllregisterserver (void)    {        hresult  hr;       IFilterMapper2 *pFM2 = NULL;           //here to register DLL information          hr =  amoviedllregisterserver2 (TRUE);       if   (FAILED (HR))             return  hr;          //The following registration filter information         hr = cocreateinstance (Clsid_filtermapper2, null, clsctx_inproc_server,                IID_IFilterMapper2,  ( void  **) &pfm2;          if   (FAILED (HR))             return  hr;          hr  = pfm2->registerfilter (           clsid_ somefilter,                //  Filter CLSID.             g_wszName,                         // filter name.            NULL,                              // Device moniker.              &clsid_videocompressorcategory,  // video compressor category.            g_wszName,                        //  Instance data.            &rf2FilterReg                    &nbSp;// pointer to filter information.        );       pfm2->release ();       return  hr;  }   REGFILTER2 rf2filterreg = {1,//PIN use AMOVIESETUP_ PIN, so the version is 1 merit_normal,//MERIT. 1,//number of pins. &sudpins//Pointer to pin information. }; STDAPI DllRegisterServer (void) {HRESULT hr; IFilterMapper2 *pfm2 = NULL; DLL information is registered here hr = AMovieDllRegisterServer2 (TRUE); if (FAILED (HR)) return to HR; The following registered filter information hr = CoCreateInstance (Clsid_filtermapper2, NULL, clsctx_inproc_server, iid_ifiltermapper2, void * * *) &PFM2); if (FAILED (HR)) return to HR; hr = Pfm2->registerfilter (clsid_somefilter,//filter CLSID. G_wszname,//filter name. NULL,//Device moniker. &clsid_videocompressorcategory,//video compressor category. G_wszname,//Instance data. &rf2filterreg//Pointer to filter information. ); Pfm2->release (); return HR; }

Four, the function of logout Filter

View plain Copy to clipboard print? Stdapi dllunregisterserver ()    {       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_videocompressorcategory,                g_wszname,  clsid_somefilter);          pfm2->release ();        return  hr;  }   Stdapi DllUnregisterServer () {HRESULT hr; IFilterMapper2 *pfm2 = NULL; hr = AMovieDllRegisterServer2 (FALSE); if (FAILED (HR)) return to HR; hr = CoCreateInstance (Clsid_filtermapper2, NULL, Clsctx_inproc_server, Iid_ifiltermapper2, (void * *) &pfm2); if (FAILED (HR)) return to HR; hr = Pfm2->unregisterfilter (&clsid_videocompressorcategory, G_wszname, Clsid_somefilter); Pfm2->release (); return HR; }

IFilterMapper2 's Registerfilter interface registers the filter information, and the fourth parameter of the interface determines what kind of filter it belongs to, and if the clsid_videocompressorcategory is used, in GraphEdit The Filter you see is in the video Capture Source.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.