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

Horst Weglanz weglanz12 at yahoo.com
Thu Nov 13 06:03:49 PST 2008


Thank you very much,

the clue not to schedule a call to *afterGetting()* solved also another bug which I didn't at all correlate to that issue. But when calling doNextFrame() recursively like this:

| if ( isFrameAvailable() )
| {
|    processFrame();
| }
| else
| {
|    usleep(10);
|    doNextFrame();
| }

means it would also block for so long till isFrameAvailable()==true? Which means without the recursive impact on the stack equals this:

| while( !isFrameAvailable() )
| {
|    usleep(10);
| }
| processFrame();

Is there maybe a way to directly schedule a call to *doGetNextFrame()* in the event loop since this is not a static function or what would be the alternative - if I shouldn't block the event loop with usleep but also call *doNextFrame()* when no data is available? Is there another static exit-point to call *doNextFrame()* and enter into the event loop when no data is available?

So something like this, but on a member function and not a static one?
| if ( isFrameAvailable() )
| {
|    processFrame();
| }
| else
| {
|    nextTask() = envir().taskScheduler().scheduleDelayedTask(10,(TaskFunc*)MySource::doGetNextFrame, NULL);
| }

thank you,
HW



----- Original Message ----
From: Ross Finlayson <finlayson at live555.com>
To: LIVE555 Streaming Media - development & use <live-devel at ns.live555.com>
Sent: Thursday, November 13, 2008 9:22:24 AM
Subject: Re: [Live-devel] doGetNextFrame() timing in mpeg2ts context

> | 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/



      



More information about the live-devel mailing list