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:
- create graph builder, filter graph, device object, grabber...
- render stream
- run media control
- wait until user signals to stop the video
- stop media control (StopWhenReady)
- release / destroy created objects
精彩评论