552
社区成员
发帖
与我相关
我的任务
分享
//设备枚举类
IEnumMoniker *pClassEnum = NULL;
//创建视频设备枚举类
CHECK_RESULT(m_pCDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
&pClassEnum,0));
//枚举视频设备
ULONG cFetched;
if(S_OK == pClassEnum->Next(1,&this->m_pMoniker,&cFetched))
{
//将找到的视频设备,绑定到源过滤器中
this->m_pMoniker->BindToObject(0,0,IID_IBaseFilter,(void**)&this->m_pVideoFilter);
this->m_pMoniker = NULL;
}
else
{
SAFE_RELEASE(pClassEnum);
ShowMessage("ClassEnum Failed");
return;
}
SAFE_RELEASE(pClassEnum);
assert(m_pVideoFilter);
//添加过滤器到graph builder 管理器中
CHECK_RESULT(m_pGBuilder->AddFilter(m_pVideoFilter,L"Video"));
//采用ICaptureGraphBuilder2接口能自动查看并链接引脚
//把源过滤器的预览引脚链接到预览输出口
CHECK_RESULT(m_pCGBuilder2->RenderStream(&PIN_CATEGORY_PREVIEW,&MEDIATYPE_Video,
m_pVideoFilter,NULL,NULL));
// //手动查找并链接引脚
// IPin *pSourceOut = this->FindPin(this->m_pVideoFilter,PINDIR_OUTPUT);
// assert(pSourceOut);
// IPin *pPreIn = FindPin(this->m_pPrevFilter,PINDIR_INPUT);
// assert(pPreIn);
// hr = this->m_pGBuilder->Connect(pSourceOut,pPreIn);
//获取预览窗口句柄
IVideoWindow * pViewWnd= NULL;
//m_pPrevFilter->QueryInterface(IID_IVideoWindow,(void**)&pViewWnd);
CHECK_RESULT(m_pGBuilder->QueryInterface(IID_IVideoWindow,(void**)&pViewWnd));
if (pViewWnd)
{
//设置预览窗口的拥有者
pViewWnd->put_Owner((long)this->Handle);
pViewWnd->put_Left(1);
pViewWnd->put_Top(1);
//获取预览窗口风格
long style;
pViewWnd->get_WindowStyle(&style);
style = style & ~WS_CAPTION;
style = style & ~WS_DLGFRAME;
style = style & WS_CHILD;
pViewWnd->put_WindowStyle(style);
//设置预览窗口宽度和高度
TRect rc;
rc = this->GetClientRect();
pViewWnd->put_Height(rc.Height()-60);
pViewWnd->put_Width(rc.Width()-2);
}
CHECK_RESULT(m_pMCtrlCam->Run());