停止IMediaControl永远不会结束

停止IMediaControl永远不会结束

本文介绍了停止IMediaControl永远不会结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#/ WPF项目中使用DirectShowLib-2005。摄像头启动时,我运行媒体控制:

I'm using DirectShowLib-2005 for my C#/WPF project. When camera starts, I run media control:

m_FilterGraph = new FilterGraph() as IFilterGraph2;
/* Initializations */
IMediaControl mediaCtrl = m_FilterGraph as IMediaControl;
hr = mediaCtrl.Run();
DsError.ThrowExceptionForHR(hr);

应用程序运行,相机效果很好。但是有时(并非总是如此)当我退出应用程序时冻结。我暂停了调试器,发现应用程序停止在以下行上:

Application Runs, camera works good. But sometimes (not always) when I quit the application freeze. I paused the debugger and I saw that the application is stop on the following line:

if (m_FilterGraph != null)
{
    IMediaControl mediaCtrl = m_FilterGraph as IMediaControl;
    mediaCtrl.Stop();  // <= *** Blocked here ***
    Marshal.ReleaseComObject(m_FilterGraph);
    m_FilterGraph = null;
}

如何防止冻结?我可以添加超时时间还是尝试/捕获?

How can I prevent this freeze ? Can I add a time out or try/catch ?

推荐答案

如果您,许多对话都讨论了类似的冻结现象,试图停止流式传输。

You will find around, if you look for it, a number of conversations discussing similar symptoms of freeze in attempt to stop streaming.

仅执行 IMediaControl.Stop 以及代码段即可。重要的是流是多线程的,并且调用涉及与流线程的同步:发信号通知它停止并等待完成;这还涉及停止所有参与的过滤器。线程问题,任何过滤器或-经常-甚至是从过滤器的回调到粗心地忽略线程概念的控制代码的回调都可能导致死锁。

Implementation of IMediaControl.Stop alone is fine as well as code snippets posted. Important is that streaming is multi-threaded and the call involves synchronization with streaming thread: signaling it to stop and waiting for completion; also this involves stopping of all participating filters. A problem with threading, any of the filters or - pretty often - even a callback from a filter to controlling code carelessly ignoring threading concepts might cause a deadlock.

问题是这不完整。当遇到这种冻结时,您需要:

Your description of the problem is this incomplete. When you face a freeze of this kind, you need:


  1. 确保您了解管道的拓扑;您需要了解(并在这样的问题中包含)参与过滤器和引脚连接的详细信息

  2. 确保您从适当的线程中停止图形,尤其是从某些过滤器回调中停止

  3. 附加调试器并检查线程状态,但是不仅是调用冻结的 Stop (可能具有零个有意义的细节)的线程,还包括其他线程

  1. make sure you understand the topology of the pipeline; you need to understand (and include in a question like this) details on participating filters and pin connections
  2. make sure you stop graph from proper thread, specifically not from certain filter callback
  3. attach a debugger and check thread states, however not just the thread which calls the freezing Stop (which is likely to have zero meaningful detail) but other threads as well, to find others relevant that prevent from stop synchronization.

问题通常是您的代码在停止流传输时导致死锁或越野车参与过滤器。

The problem is typically your code causing a deadlock on stop of streaming, or a buggy participating filter.





这篇关于停止IMediaControl永远不会结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 17:20