In this example, a custom interface added based on virtualcamera is used to control OSD display by exe.
1. Interface Section
# Ifndef _ h_myfilter __
# DEFINE _ h_myfilter __
# Ifdef _ cplusplus
Extern "C "{
# Endif
// # Include <initguid. h>
// Extern_guid
Extern_guid (iid_imyfilter,
0xef31f705, 0x32a7, 0x477a, 0x90, 0xc9, 0x2c, 0x7e, 0x81, 0xeb, 0x2, 0x5d );
Declare_interface _ (imyfilter, iunknown)
{
Stdmethod (setosd) (This _ int osd_en) pure;
};
# Ifdef _ cplusplus
}
# Endif
# Endif
2. Filter inheritance Interface
# Include "myfilter. H"
Class cvcam: Public csource, public imyfilter
{
Public:
Static cunknown * winapi createinstance (lpunknown lpunk, hresult * phr );
Stdmethodimp nondelegatingqueryinterface (refiid riid, void ** GMM );//????
Declare_iunknown;
Stdmethodimp setosd (INT osd_en );
Ifiltergraph * getgraph () {return m_pgraph ;}
Int osd_enable;
PRIVATE:
Cvcam (lpunknown lpunk, hresult * phr );
Cvcampin * m_ppin;
Public:
};
/////////////////////////////////////
Stdmethodimp cvcam: setosd (INT osd_en)
{
Osd_enable = osd_en;
Return s_ OK;
}
Stdmethodimp cvcam: nondelegatingqueryinterface (refiid riid, void ** GMM)
{
If (riid = _ uuidof (iamstreamconfig) | riid = _ uuidof (ikspropertyset ))
{
// M_pastreams [0]-> QueryInterface (riid, GMM );
Return m_pastreams [0]-> QueryInterface (riid, GMM );
}
Else if (riid = iid_imyfilter)
{
Return getinterface (imyfilter *) This, GMM );
}
Else
Return cbasefilter: nondelegatingqueryinterface (riid, GMM); // modify
}
3. Application call
//Search for Filter Based on guid
HR = cocreateinstance (clsid_myfilter, 0, clsctx_inproc_server, iid_ibasefilter, reinterpret_cast <void **> (& psrcfilter ));
Imyfilter * pinterface = NULL;
HR = psrcfilter-> QueryInterface (iid_imyfilter, (void **) & pinterface );// Query the interface from the filter
Pinterface-> setosd (0 );// Use interface functions
How to add custom interfaces and call Filters