1

I'm currently working on a small program using directshow library.The program among others should be able to select any camera connected to computer and record stream. My problem is that I'm not sure how to free of memory dshow filters. Let's give you an example:

For example when I want to set the output filename I have to create an AVI Mux filter like so:

IBaseFilter * aviMux;
bGraph->SetOutputFileName(
    &MEDIASUBTYPE_Avi,   
    L"example.avi",  
    &aviMux,       
    NULL);  

Now I'd like to change the filename and use the SetOutputFileName() function again, but how to free of memory AVI Mux (by the way obviously the function creates a FileWriter filter as well which I'd like to free as well)? Only I can do is that:

aviMux->Release();
fGraph->RemoveFilter(aviMux);

But will the memory be freed before the end of the program now? I'd like to do something like this:

delete aviMux;

but that's an error obviously. Thanks in advice for any answers and help..

4

1 回答 1

2

标准 COM 规则适用:

  • 您不再需要接口指针-您需要IUnkonwn::Release
  • 一旦您想明确停止过滤器图形活动 - 您IGraphBuilder::Stop可以停止过滤器
  • 一旦你释放所有你持有的图和过滤器及其接口的接口指针,所有底层资源都会自动释放

为了使其更可靠,您还可以考虑从已停止的图中显式删除所有过滤器(这会在内部强制断开引脚连接)。

特别是为了捕获过滤器图,更改文件名与从头开始构建新图的复杂性几乎相同。所以这是有意义的事情:停止、完全清理、新图、开始新文件的新捕获。重用过滤器是可能的(IFileSinkFilter::SetFileName在已经添加到停止过滤器图中的过滤器编写器上使用),但是不太可能明显加快文件切换 - 无论如何都会涉及一定的延迟。

对于无缝文件切换,您需要两个图表 - 一个捕获图表和一个写入图表。以及两者之间的通信,例如桥接

于 2013-07-05T12:09:41.720 回答