自建DirectShow Filter Graph的流程

1.初始化COM组件,在实例初始化部分加入
::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
在实例终止部分加入
::CoUninitialize();

2.首先构建Graph Manager
IGraphBuilder *pGraph = NULL;
HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);

3.查询Graph各接口
HRESULT hr = NOERROR;
hr |= pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
hr |= pGraph->QueryInterface(IID_IMediaEventEx, (void **)&pEvent);
hr |= pGraph->QueryInterface(IID_IBasicVideo, (void **)&pBasicVideo);
hr |= pGraph->QueryInterface(IID_IBasicAudio, (void **)&pBasicAudio);
hr |= pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVideoWindow);
hr |= pGraph->QueryInterface(IID_IMediaSeeking, (void **)&pSeeking);
if (pSeeking)
{
     pSeeking->SetTimeFormat(&TIME_FORMAT_MEDIA_TIME);
}
return SUCCEEDED(hr);

4.根据CLSID,创建相应的Filter,连接到Graph
IBaseFilter * pFilter = NULL;
CoCreateInstance(mClsid, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pFilter);
pGraph->AddFilter(pFilter, name);

5.枚举各Filter要连接的引脚
//建立枚举器
IEnumPins * pinEnum = NULL;
inFilter->EnumPins(&pinEnum);
//枚举各引脚
IPin * pin = NULL;
ULONG fetchCount = 0;
IPin * foundPin = NULL;
while (!foundPin && SUCCEEDED(pinEnum->Next(1, &pin, &fetchCount)) && fetchCount)
{
     if (pin)
     {
          PIN_INFO pinInfo;
          if (SUCCEEDED(pin->QueryPinInfo(&pinInfo)))
          //判断pin是否符合条件(方向、名字等),不符合则继续循环
          //若符合
          pin->AddRef();
          foundPin = pin;
          pinInfo.pFilter->Release();
     }
     pin->Release();
}
//释放枚举器
pinEnum->Release();
//避免多余引用
if (foundPin)
     foundPin->Release();
return foundPin;

6.连接引脚
HRESULT hr = pGraph->ConnectDirect(outputPin, inputPin, inMediaType);
//其中outputPin和inputPin通过上一步方法获得

7.运行Graph
pMediaControl->Run();
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值