[Live-devel] doGetNextFrame() timing in mpeg2ts context

Ross Finlayson finlayson at live555.com
Thu Nov 13 00:22:24 PST 2008


>| if ( isFrameAvailable() )
>| {
>|    processFrame();
>| }
>| else
>| {
>|    usleep(10);
>|    nextTask() = 
>envir().taskScheduler().scheduleDelayedTask(0,(TaskFunc*)FramedSource::afterGetting, 
>this);
>| }

The big problem with this code is that if "isFrameAvailable()" 
returns False, then you end up returning control to the downstream 
object (by arranging for "FramedSource::afterGetting"  to be called). 
This is wrong - you should do that only after you've successfully 
copied data to the downstream object.

If no data is immediately available, you should instead arrange to 
call *this same* code again, *not* "FramedSource::afterGetting".

Also, calling "usleep()" is bad, because that will block the code. 
Instead, to delay, it's better to include the delay period - instead 
of 0 - in the call to "scheduleDelayedTask()".  That way, you'll 
return control to the event loop, rather than blocking.

Finally, to create a Transport Stream (multiplexed from separate data 
sources), be sure to use the "MPEG2TransportStreamMultiplexor" class. 
For an example of how to use this, see the "wis-streamer" code: 
http://www.live555.com/wis-streamer/
-- 

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


More information about the live-devel mailing list