HRESULT hr = CoCreateInstance(CLSID_SampleGrabber,
NULL,
CLSCTX_INPROC,
IID_IBaseFilter,
(void **)&sample_grabber_filter);
if(FAILED(hr)) {
printf("(Fatal) Error setting up Sample Grabber.\n");
return hr;
}
hr = CoCreateInstance(CLSID_NullRenderer,
NULL,
CLSCTX_INPROC,
IID_IBaseFilter,
(void **)&null_renderer);
if(FAILED(hr)) {
printf("(Fatal) Error seeting up Null Renderer.\n");
return hr;
}
然后我可以使用FilterGraph :: AddFilter()函数添加所有3个过滤器并使用另一个接口(如CaptureGraphBuilder2)来呈现流。但是当我想同时从多个来源渲染时会发生什么?我可以将所有源过滤器添加到图表中,但Sample Grabber和Null Renderer过滤器如何为每个视频流完成图表?我可以这样做:
IGraphBuilder *graph_builder;
ICaptureGraphBuilder2 *cap_graph;
IMediaControl *media_control;
// ... set up graph_builder and cap_graph and media_control
cap_graph->AddFilterGraph(graph_builder);
IBaseFilter *new_source;
wchar_t *source_name; // Allocate some memory
while(ScanForSource(&new_source, &source_name)) {
graph_builder->AddFilter(new_source, source_name);
graph_builder->AddFilter(sample_grabber_filter, new_sg_name);
graph_builder->AddFilter(null_renderer, new_nr_name);
cap_graph->RenderStream(&PIN_CATEGORY_PREVIEW,
&MEDIATYPE_Video, new_source, sample_grabber_filter, null_renderer);
}
上述实现会有用吗?如果没有,那么还有其他方法吗?任何帮助深表感谢。谢谢!
答案 0 :(得分:1)
是的,您可以在图表中创建并插入样本抓取器和渲染器的许多实例。只是不要忘记单独创建它们(为每一个调用CoCreateInstance),不要尝试多次插入相同的实例。