[Live-devel] To use openRTSP in a multi-thread program

Ross Finlayson finlayson at live555.com
Mon Jan 6 02:21:53 PST 2014


> I am trying to use the openRTSP code in my program and use it to record from multiple sources at the same time. Therefore, I need to run each instance in a separate thread.

No, the second sentence does not follow logically from the first.  (See below.)


> But openRTSP code is not thread safe (many global variables). I will be left with three options:
> 1- To run openRTSP as a stand-alone process for each client stream.

Yes, that is what you should do.  E.g., use a shell script to exec multiple "openRTSP" commands concurrently.

> This would not be efficient, and I would lose control over each openRTSP running process. 

No, this would still be efficient, and you could easily control each "openRTSP" process, from your shell script.  E.g., your shell script could note the pid of each "openRTSP" process, so it can kill them, if necessary.

I continue to be surprised how - in this century - so many programmers have become afraid of (or unaware of) structuring applications as multiple processes, resorting instead to using multiple threads within a single process - which is *much* more difficult, and *much* more error-prone (and is something that's required only when you need shared memory).


> 2- To re-implement openRTSP with a same scheme as in testRTSPClient test program. Creating my own StreamClientState, ourRTSPClient and DummySink classes. But I would lose all the functionality implemented in openRTSP. Implementing every one of them would be hard.

You wouldn't need 'all' the functionality of "openRTSP" - just the parts that you want.  But in any case, I don't recommend that you do this, unless you need only very basic functionality of "openRTSP".  (Especially as this is a hobby for you.)


> 3- Try to make the current openRTSP implementation thread-safe, by defining StreamClientState and putting all global variables in playcomm.cpp in that class and trying to over ride RTSPClient used there. But the RTSPClient is initiated in the HandlerServerForREGISTERCommand and finding the correspondences is a bit hard.

No, I don't recommend that you do this.  The "openRTSP" code is very complex (in part because it's also used for "playSIP" - a SIP client).  It's not something to mess with.


Ross Finlayson
Live Networks, Inc.
http://www.live555.com/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20140106/4243f656/attachment.html>


More information about the live-devel mailing list