Reputation: 338
I'm writing an RTSP client and using Media Foundation to stream multiple IP camera video feeds to Windows display. I understand that the built-in MF RTSP doesn't handle IP cameras very well so I'll have to write a custom Media Source:
Writing a Custom Media Source: https://msdn.microsoft.com/en-us/library/windows/desktop/ms700134(v=vs.85).aspx
Also the following post gives some useful tips but not much implementation details:
Capture H264/AAC stream via RTSP using Media Foundation: https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/8f67d241-7e72-4509-b5f8-e2ba3d1a33ad/capture-h264aac-stream-via-rtsp-using-media-foundation?forum=mediafoundationdevelopment
If I write my RTSP code within my custom Media Source object, will it be able to run sufficiently in it's own thread and use the blocking "recv" network call to receive the camera stream data? Or is the COM object not really a separate thread that can handle this type of task? Is there a potential conflict between blocking on the "recv" call and blocking on COM's work queue?
Or should I just create a new thread using "CreateThread" that will handle all the RTSP details and forward the camera stream data to the Media Source object?
Any advice to point me in the right direction would be great!
Upvotes: 2
Views: 742
Reputation: 69642
Media Foundation, by its design, suggests that you implement processing asynchronously. There are work queues, event generators, start/stop and other operations are expected to be initiated and without blocking completed asynchronously with a notification/event.
Following this design you don't need a lot of threads. Media Foundation suggests that instead you use its work queues, which implement thread pools as needed.
However it does not mean you can't use threads. You will have to implement asynchronous patterns when you are implementing interfaces/methods mandatory for a Media Foundation source, but it is okay if you prefer to do actual work on a separate worker thread (which in many cases results in simpler code).
Upvotes: 1
Reputation: 1917
Implement your Media Source and inside the implementation:
You can also introduce GAP if needed or repeat the last sample if not enough data is obtained.
Upvotes: 1