[Live-devel] RTP MJPEG: block network packets without data

Ross Finlayson finlayson at live555.com
Tue Dec 3 18:59:38 PST 2013


> Thank you for your answer, you right, I modify data source class and, I
> think, problem solved.
> 
> Class Frame is sublass FramedSource.
> void Frame::doGetNextFrame()
> {
>    fFrameSize = 0;
>    fNumTruncatedBytes = 0;
> 
>    get data code
> 
>    if (fFrameSize)
>        FramedSource::afterGetting(this);
>    else
>        doGetNextFrame();
> 
> }
> 
> But I not sure what this method optimal.

The problem with this is that you're making (potentially) infinite recursive calls.  If the next frame doesn't become available 'soon', you'll overflow the call stack.  It'd be better to turn this into a loop - i.e.:

void Frame::doGetNextFrame()
{
   fFrameSize = 0;
   fNumTruncatedBytes = 0;

  do {
     get data code
  } while (fFrameSize == 0);

   FramedSource::afterGetting(this);
}

But even this is suboptimal, because it chews up CPU time (in the loop) when no frame is available.  During that time, you won't be returning to the event loop to handle other events.  It'd be better to do asynchronous I/O, e.g, as illustrated in our "DeviceSource.cpp" example code.


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/20131204/7c7928aa/attachment.html>


More information about the live-devel mailing list