怎样给filter加入自己定义接口及调用

本样例是在VirtualCamera的基础上加入的自己定义接口用来实现exe控制osd的显示。

1. 接口部分

#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继承接口


#include "myfilter.h"
class CVCam : public CSource ,public IMyFilter
{
public:


    static CUnknown * WINAPI CreateInstance(LPUNKNOWN lpunk, HRESULT *phr); 
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);//????
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 **ppv)
{
if(riid == _uuidof(IAMStreamConfig) || riid == _uuidof(IKsPropertySet))
{
// m_paStreams[0]->QueryInterface(riid, ppv);
return m_paStreams[0]->QueryInterface(riid, ppv);
}
else if (riid == IID_IMyFilter)
{
return GetInterface((IMyFilter *) this, ppv);
}
else
return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);//改动
}

3.应用程序调用

        //依据guid 查找filter

  hr = CoCreateInstance(CLSID_myFilter, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, reinterpret_cast<void**>(&pSrcFilter));  

         IMyFilter *pInterface = NULL; 

         hr = pSrcFilter->QueryInterface(IID_IMyFilter, (void **)&pInterface);//从filter上查询接口

        pInterface->setOSD(0);//使用接口函数


怎样给filter加入自己定义接口及调用





本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5308098.html,如需转载请自行联系原作者

上一篇:全网最全95道MongoDB面试题1万字详细解析


下一篇:OSSIM远程连接与文件传输图示