IBaseFilter::JoinFilterGraph


Microsoft DirectShow 9.0

IFilterGraph::AddFilter

The AddFilter method adds a filter to the graph.

Syntax

HRESULT AddFilter(   IBaseFilter *pFilter,   LPCWSTR pName ); 

Parameters

pFilter

[in] Pointer to the IBaseFilter interface of the filter to add.

pName

[in] Pointer to a wide-character string containing a name for filter.

Return Values

Returns an HRESULT value. Possible values include the following.

ValueDescription
S_OKSuccess.
VFW_S_DUPLICATE_NAMESuccessfully added a filter with a duplicate name.
E_FAILFailure.
E_OUTOFMEMORYInsufficient memory.
E_POINTERNull pointer argument.
VFW_E_CERTIFICATION_FAILUREUse of this filter is restricted by a software key.
VFW_E_DUPLICATE_NAMEFailed to add a filter with a duplicate name.

Remarks

The name of the filter can be NULL, in which case the Filter Graph Manager generates a name. If the name is not NULL and is not unique, this method will modify the name in an attempt to generate a new unique name. If this is successful, this method returns VFW_S_DUPLICATE_NAME. If it cannot generate a unique name, it returns VFW_E_DUPLICATE_NAME.

AddFilter calls the filter's IBaseFilter::JoinFilterGraph method to inform the filter that it has been added. AddFilter must be called before attempting to use theIGraphBuilder::ConnectIFilterGraph::ConnectDirect, or IGraphBuilder::Render method to connect or render pins belonging to the added filter.

The Filter Graph Manager holds a reference count on the filter until the filter is removed from the graph or the Filter Graph Manager is released.

Requirements

Header: Declared in Strmif.h; include Dshow.h.

Library: Use Strmiids.lib.


例子:

 
 

HRESULT CVMR_Capture::InitializeWindowlessVMR(HWND hWnd)//初始化无窗口模式的VMR
{
IBaseFilter* pVmr = NULL;

// 创建VMR并添加它到过滤器图表
HRESULT hr = CoCreateInstance(CLSID_VideoMixingRenderer, NULL,
  CLSCTX_INPROC, IID_IBaseFilter, (void**)&pVmr);

if (SUCCEEDED(hr))
{

  hr = m_pGB->AddFilter(pVmr, L"Video Mixing Renderer");

  if (SUCCEEDED(hr))

  {

... ...



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
//指定视频采集设备的友好名字,为它创建一个Filter IBaseFilter * CTestPreviewDlg::CreateVideoDevice(const char * inFriendlyName) { return CreateHardwareFilter(CLSID_VideoInputDeviceCategory,inFriendlyName); } //根据设备的友好名字,创建一个代表该设备的Filter IBaseFilter * CTestPreviewDlg::CreateHardwareFilter(GUID inCategory,const char * inFriendlyName) { //创建一个系统枚举组件对象 ICreateDevEnum * enumHardware = NULL; HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum,NULL,CLSCTX_ALL, IID_ICreateDevEnum,(void**)&enumHardware); if(FAILED(hr)) { return NULL; } IBaseFilter * hardwareFilter = NULL; IEnumMoniker * enumMoniker = NULL; //为指定的目录创建枚举器 hr = enumHardware->CreateClassEnumerator(inCategory,&enumMoniker,0); if(enumMoniker) { enumMoniker->Reset(); ULONG fetched = 0; IMoniker * moniker = NULL; char friendlyName[256]; //枚举得到该目录下所有的设备,逐个进行名字匹配 while(!hardwareFilter && SUCCEEDED(enumMoniker->Next(1,&moniker, &fetched)) && fetched) { if(moniker) { IPropertyBag * propertyBag = NULL; VARIANT name; friendlyName[0] = 0; hr = moniker->BindToStorage(0,0,IID_IPropertyBag,(void**)&propertyBag); //读取设备的友好名字 if(SUCCEEDED(hr)) { name.vt = VT_BSTR; hr = propertyBag->Read(L"Friendlyname",&name,NULL); } if(SUCCEEDED(hr)) { WideCharToMultiByte(CP_ACP,0,name.bstrVal,-1, friendlyName,256,NULL,NULL); //如果当前设备的友好名字与用户指定的设备名字相同, //则将当前设备标识绑定为Filter形式 if(strcmp(friendlyName,inFriendlyName) == 0) { moniker->BindToObject(0,0,IID_IBaseFilter, (void**)&hardwareFilter); } } //释放使用过的接口 if(propertyBag) { propertyBag->Release(); propertyBag = NULL; } moniker->Release(); } } enumMoniker->Release(); } enumHardware->Release(); return hardwareFilter; }

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值