[Live-devel] Proper function calls from other threads (was: RE: All client termination)

Ross Finlayson finlayson at live555.com
Tue Sep 11 15:36:09 PDT 2012


> One last question on this, as I'm in the middle of reorganizing the code.
> Shouldn't it be safe to create the rtspClient object in another thread?

Once again, NO!  "RTSPClient" objects - like all subclasses of class "Medium" - update shared data structures (stored within the "UsageEnvironment" object) when they are constructed.  A single "UsageEnvironment" object MUST NOT be accessed from multiple threads (except that the "triggerEvent()" member function may be called from a non-LIVE555-event-loop thread).


> Having to create the rtspClient objects using triggers would introduce additional callbacks and making passing arguments a bit more complex.

Nonetheless, if you are creating these "RTSPClient" objects dynamically, then the creation of each of these objects has to be done as an 'event' - i.e., done from a handler function that's called from the LIVE555 thread.  And the only way to signal this from an external thread is to call "triggerEvent()", or to use the 'watch variable' mechanism.


> This is now the "main startup code":
>  
> void InitStreamEngine()
> {
>      TaskScheduler* scheduler = BasicTaskScheduler::createNew();
>      usageEnvironment = BasicUsageEnvironment::createNew(*scheduler);
>  
>      myStartStreamEvent = usageEnvironment->taskScheduler().createEventTrigger((TaskFunc*)StartStreamEvent);
>      myStopStreamEvent = usageEnvironment->taskScheduler().createEventTrigger((TaskFunc*)StopStreamEvent);
>      mySeekAbsoluteEvent = usageEnvironment->taskScheduler().createEventTrigger((TaskFunc*)SeekAbsoluteEvent);
>  
>      usageEnvironment->taskScheduler().doEventLoop(&eventLoopWatchVariable);
> }

This looks fine. 


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/20120911/67177fd0/attachment.html>


More information about the live-devel mailing list