I have a program that receives webcam video and displays it on a C# application using directshowlib-2005.dll.
In my application I also use GMFBridge so that I can stream and record video whenever indicated.
In this program, my application controls are in the main loop, and the video streaming are done in a separate thread. I have options to either record the current streaming video from the main thread by pressing a button and using:
play.filesink = (IFileSinkFilter)play.file;
play.filesink.SetFileName(GetDateTimeString("Video") + ".avi", null);
IMediaControl Second_Graph = play.s_mediaCtrl;
Second_Graph.Run();
play.bridge.BridgeGraphs(play.BridgeSink, play.sourceFilter);
where the play class is the class which converts the incoming video from yuv to rgb and then sets up both the streaming and recording graphs
file is the filter file writer. I convert file write to an IFileSinkFilter so that i can put a name on it, as seen in the second line. then I play create a media controller and run the graph and bridge the streaming and recording graph.
I also have the option to set up future recordings at later times and dates, as entered. The future recordings are entered, and stored inside a static list that is sorted based on when the recordings occur. Inside the streaming thread, I poll the list to see if its time for a recording to start, if it is I run the same code as above:
play.filesink = (IFileSinkFilter)play.file;
play.filesink.SetFileName(GetDateTimeString("Video") + ".avi", null);
IMediaControl Second_Graph = play.s_mediaCtrl;
Second_Graph.Run();
play.bridge.BridgeGraphs(play.BridgeSink, play.sourceFilter);
This occurs inside the thread and when there is a recording, the application will crash on the first and/or second line. the error is the same, it doesn’t know what IFileSinkFilter is so in both invocations in the first and second lines, it crashes.
The error received is:
Unable to cast COM object of type 'System.__ComObject' to interface type 'DirectShowLib.IFileSinkFilter'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A2104830-7C70-11CF-8BCE-00AA00A3F1A6}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
I am not sure why it fails or how to fix it. It had no issues when this block of code was part of a button in the main thread, but when its threaded separately it fails.
Any help on how to fix this would be appreciated.
There are issues with creating the graph in one thread and controlling it in another thread because of COM thread affinity issues.
When you were using the block of code on a button handler, it worked because everything was executed in the same thread.
One of addressing your problem is instead of trying to play the graph on your processing thread, send a user defined windows message instead, the process the message in the main thread where you actually play the graph.
This would ensure that playback happens on the same thread that created the graph.