[Live-devel] The first H.264 SPS packet gets skipped

Mehran Ansari mehran at stretchinc.com
Fri Oct 15 17:04:49 PDT 2010


I have a H.264 Streamer server, which gets the live encoded video frames from my own encoder device and tries to sent it out to the client requesting it. To do this I sub-classed H264VideoStreamFramer from FramedFilter class. I implemented currentNALUnitEndsAccessUnit() and isH264VideoStreamFramer() and returned TRUE for both since my encoder always provides me with a complete NAL. I also implemented doGetNextFrame() which when it gets called it makes sure to start with a SPS packet. In doGetNextFrame(), I copy the H.264 payload to fTo, assign the packet size to fFrameSize, and set the fNumTruncatedBytes to zero. (Note: I set the OutPacketBuffer::maxSize to the maximum buffer size that my encoder provides which is 256K). At last I call afterGetting() and before I return I scheduleDelayedTask() to be called in 1/30th of a seconds.

Everything works fine except, the very first packet that is SPS which is sent to afterGetting() gets lost.  This packet does not get sent. Instead my doGetNextFrame() gets callback due to alarm handleAlarm(). At this time I get the next frame and so. The result is that the client has a complete h.264 video file except the first SPS is missing. 

To get around this problem, when doGetNextFrame() gets called and only one SPS is sent, then I assume the last buffer was not delivered, I just call afterGetting() without changing anything. Now, everything is working fine.

My question is that what am I doing wrong that for the first very frame which in this case is SPS, the frame does not get sent. Do I need to set fDurationInMicroSeconds and fPresentationTime before calling afterGetting()? Is it possible not setting any of these variables to cause an undesired event schedule which forces doGetNextFrame() be called before sending the packet?

Thanks for any help.


More information about the live-devel mailing list