Use COINIT_APARTMENTTHREADED or COINIT_MULTITHREADED in Media Foundation?

Viewed 3647

In my research of Media Foundation I've encountered some seemingly contradictory advice from two very reputable sources.

From MSDN: Media Foundation and COM: https://msdn.microsoft.com/en-us/library/windows/desktop/ee892371(v=vs.85).aspx

In Media Foundation, asynchronous processing and callbacks are handled by work queues. Work queues always have multithreaded apartment (MTA) threads, so an application will have a simpler implementation if it runs on an MTA thread as well. Therefore, it is recommended to call CoInitializeEx with the COINIT_MULTITHREADED flag.

Then from the book “Developing Microsoft Media Foundation Applications - By Anton Polinger” page 24:

Note MF is a free-threaded system, which means that COM interface methods can be invoked from arbitrary threads. Therefore, when calling CoInitializeEx(), you must initialize COM with the apartment-threaded object concurrency by passing in the COINIT_ APARTMENTTHREADED parameter. Your objects might also need to use synchronization primitives, such as locks, to control access to internal variables by concurrently running threads.

Additionally I've seen a lot of Media Foundation example code in GitHub that uses COINIT_APARTMENTTHREADED.

I'm developing an RTSP client that uses Media Foundation to stream multiple IP camera video feeds to Windows display. I'll be using multiple threads in my app so I believe it will be very important to get a definitive answer on this issue. Can someone please explain the contradiction and advise on the correct way to proceed?

1 Answers
Related