[Live-devel] Non Blocking doGetNextFrame

Ross Finlayson finlayson at live555.com
Fri Mar 31 11:28:33 PST 2006


>The queue is designed such that if nothing is present it will return 
>null. In all the classes implementing filter, we have a wait() call 
>to our pthread wrapper class. Where the problem occurs is live is 
>not using our threading model and therefore this design will not work.

That's correct

>  How we did set it up was to just not call our start() and allow 
> live to take care of everything with a simple:
>
>while(pkt != null)
>             pkt = buffer->getPacket();
>deliverFrame();
>
>within the doGetNextFrame. As you can see this is a serious polling problem.

Yes.  Note that - because the "LIVE555 Streaming Media" code has a 
single-threaded, event-based execution model, data reads should not 
be done synchronously.  Instead, data reads should be done 
asynchronously, using the event loop.  I.e., the arrival of new data 
needs to be (somehow) signalled as an event, and handled within the event loop.

Probably the simplest way to do this is using the "watchVariable" 
feature of "doEventLoop()".  See 
<http://lists.live555.com/pipermail/live-devel/2005-September/003276.html>. 
Your separate thread - that delivers incoming data to your buffer - 
should set the global "watchVariable" whenever it delivers 
data.  Then, modify your call to "doEventLoop()" - as shown in the 
example - to handle the setting of this watch variable.  (I.e., what 
you're doing here is modifying the event loop to include testing of 
the watch variable.)

One way to handle the watch variable 'event' is to just call
         yourSource->doGetNextFrame();

Your "doGetNextFrame()" would then look something like:

void YourSource::doGetNextFrame() {
         if (!isCurrentlyAwaitingData()) return; // noone is awaiting data

         if (/*no data is available on your queue*/) return;

         // Get data from your queue, and deliver it to the client
         // (see "DeviceSource.cpp")

         // After delivering the data, switch to another task, and inform
         // the reader that he has data:
         nextTask()
                 = 
envir().taskScheduler().scheduleDelayedTask(0, 
(TaskFunc*)afterGetting, this);
}




More information about the live-devel mailing list