开发者

How to disconnect from the webcam using directshow?

I used directshow.net with my web-cam and it worked so well. But when I closed the form and opened it again, it gives me an error 开发者_开发问答in the method SetupGraph() because the value that come from the next code line is negative.

hr = capGraph.RenderStream(ref cat, ref med, capFilter, null, null);

but when I unplugged my camera, it works good the second time.

I hope it's not a big deal.


You can try to call yourMediaControl.StopWhenReady() method and after that release all com object instances like graph, source, grabber, capture graph with Marshal.ReleaseComObject.

The IMediaControl.StopWhenReady method pauses the filter graph, allowing filters to queue data, and then stops the filter graph.

Main thing is that each time you start webcam video you need to do all this:

  1. create graph builder, filter graph, device object, grabber...
  2. render stream
  3. run media control
  4. wait until user signals to stop the video
  5. stop media control (StopWhenReady)
  6. release / destroy created objects
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜