问题描述
请考虑以下代码.
HRESULT CSampleGrabber :: Grab(WString szName,long lTime,long width,long height,LONGLONG * lDuration,IStream ** pStream)
HRESULT CSampleGrabber::Grab(WString szName,long lTime,long width, long height, LONGLONG* lDuration, IStream** pStream)
{
if(lDuration == NULL || pStream == NULL)
if(lDuration==NULL || pStream==NULL)
{
返回S_FALSE;
return S_FALSE;
}
HRESULT hr = S_FALSE;
HRESULT hr = S_FALSE;
尝试
{
ComPtr< IGraphBuilder> pGraphBuilder;
ComPtr<IGraphBuilder> pGraphBuilder;
ComPtr< IBaseFilter> pSourceFilter;
ComPtr<IBaseFilter> pSourceFilter;
ComPtr< IBaseFilter> pColorspaceFilter;
ComPtr<IBaseFilter> pColorspaceFilter;
DSHCall(hr,CoCreateInstance(CLSID_FilterGraph,
DSHCall(hr,CoCreateInstance(CLSID_FilterGraph,
NULL,
CLSCTX_INPROC_SERVER,
CLSCTX_INPROC_SERVER,
IID_IGraphBuilder,
IID_IGraphBuilder,
(void **)pGraphBuilder
(void**)pGraphBuilder
));
DSHCall(hr,pGraphBuilder-> AddSourceFilter(szName.c_str(),szName.c_str(),pSourceFilter));
DSHCall(hr,pGraphBuilder->AddSourceFilter(szName.c_str(),szName.c_str(),pSourceFilter));
ComPtr< IPin>出,进;
ComPtr<IPin> out,in;
DSHCall(hr,DShowHelper :: GetVideoPin(pSourceFilter,PINDIR_OUTPUT,false,out));
DSHCall(hr,DShowHelper::GetVideoPin(pSourceFilter,PINDIR_OUTPUT,false,out));
DSHCall(hr,DShowHelper :: CreateFilter(CLSID_Colorspace,pColorspaceFilter));
DSHCall(hr,DShowHelper::CreateFilter(CLSID_Colorspace,pColorspaceFilter));
DSHCall(hr,pGraphBuilder-> AddFilter(pColorspaceFilter,L"Colorspace"));
DSHCall(hr,pGraphBuilder->AddFilter(pColorspaceFilter,L"Colorspace"));
DSHCall(hr,DShowHelper :: GetPin(pColorspaceFilter,PINDIR_INPUT,true,in));
DSHCall(hr,DShowHelper::GetPin(pColorspaceFilter,PINDIR_INPUT,true,in));
DSHCall(hr,pGraphBuilder-> Connect(out,in));
DSHCall(hr,pGraphBuilder->Connect(out,in));
}
}
}
推荐答案
使用以下代码关闭图形
//release after the graph operation has been considered done
if(pGraphBuilder != NULL)
{
pGraphBuilder->Release();
pGraphBuilder = NULL;
}
这篇关于如何发布IGraphBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!