Question

I have a graph which takes long to create and get ready (5-10 sec). To aviod freezing, I decided to create my graph in thread but something weird happens. After I run my graph, while debugging; when I'm in the thread I can see video in my window. But when thread ends, video disappears. I defined everything globally about my graph. What's wrong with creating a graph in separate thread?

Thanks

Was it helpful?

Solution

It is possible to create graph in a side thread and this is a workable scenario. However this piece of information alone is insufficient to reliably explain the symptoms. As you have video, you supposedly have video renderer filter, esp. running in windowed mode. If it creates a window on this background thread, then the window expects the thread to be alive and even more, it is expected that you deliver window messages on this thread. This means, you cannot exit as soon as you run the graph.

Because of windows, including possibly internal that filters might create for their own needs, it is safer to create filter graphs on STA threads. This can be a side STA thread you create graph on, you keep it alive until you destroy the graph, you run a message loop on it in the meantime. Note there is a version of the Fitler Graph Manager suitable for this scenario:

CLSID_FilterGraphNoThread creates the Filter Graph Manager on the application's thread. If you use this CLSID, the thread that calls CoCreateInstance must have a message loop that dispatches messages; otherwise, deadlocks can occur. Also, before the application thread exits, it must release the Filter Graph Manager and all graph objects (such as filters, pins, reference clocks, and so forth).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top