[Live-devel] Adding streams to already-running event loop
Ross Finlayson
finlayson at live555.com
Tue Nov 11 13:07:04 PST 2014
First you need to figure out exactly when/how you’re going to decide when to add a new stream. I.e., you need to figure out what event will cause this to happen.
If it’s simply a delayed task - within the event loop (i.e., set up using “TaskScheduler::scheduleDelayedTask()”) - then you don’t need ‘event triggers’ at all. Instead, simply add the new stream from the ‘delayed task’. Ditto if the event occurs as a result of reading data from a socket.
If, however, you decide to do this from some external thread (i.e., from the thread that is *not* running the LIVE555 event loop), then you can call “triggerEvent()” from this external thread. Note that “triggerEvent()” is the *only* LIVE555 code that you may call from this external thread; all other LIVE555 calls *must* be done from within the ‘LIVE555 event loop’ thread.
If you decide to use ‘event triggers’ (triggered from an external thread), then you are sort of on the right track, with a couple of corrections:
> myRTSPClient::createNew(env,url,etc.){
> …
> addStreamEventTriggerId = envir().taskScheduler().createEventTrigger(addStreamToLoop);
Note that the function parameter to “createEventTrigger()” has to have the proper “TaskFunc” signature:
typedef void TaskFunc(void* clientData);
> myClient = myRTSPClient::createNew(env, url, etc.);
> ourScheduler->triggerEvent(myRTSPClient::addStreamEventTriggerId, myClient);
Because you are calling “triggerEvent()” from an external thread (again, if you’re in the LIVE555 event loop thread when you decide to create a new stream, then you don’t need event triggers at all), you can’t call “myRTSPClient::createNew()” from within that thread. Instead, the “myRTSPClient::createNew()” call should occur (along with a subsequent “sendDescribeCommand()”) within the event handler function - i.e., within the LIVE555 event loop.
So, to get this, you can do something like:
///// Within the LIVE555 thread:
void newStreamHandler(void* clientData) {
char* url = (char*)clientData;
myRTSPClient* myClient = myRTSPClient::createNew(env, url, etc.);
myClient->addStreamToLoop();
}
TaskScheduler* live555TaskScheduler = &(envir().taskScheduler()); // A global variable
EventTriggerId newStreamEventTrigger = envir().taskScheduler().createEventTrigger(newStreamHandler); // A global variable
// Note that you need to create only one event trigger
envir().taskScheduler().doEventLoop(); // does not return
///// Then later, within a separate thread:
live555TaskScheduler->triggerEvent(newStreamEventTrigger, url_for_the_new_stream);
Ross Finlayson
Live Networks, Inc.
http://www.live555.com/ <http://www.live555.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20141111/4269faec/attachment.html>
More information about the live-devel
mailing list