From 20821e7eb67000b76180e77a735a37abe6b66736 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 11 May 2017 20:10:20 -0700 Subject: [PATCH] Leave the zero padding bytes on FEC-recovered packets alone. Decoders are required to cope with trailing zero bytes in NALUs and they are not safe to remove because they may actually be part of the byte stream itself. --- src/RtpFecQueue.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/RtpFecQueue.c b/src/RtpFecQueue.c index e9e8a15..f63d11b 100644 --- a/src/RtpFecQueue.c +++ b/src/RtpFecQueue.c @@ -140,15 +140,13 @@ cleanup_packets: PNV_VIDEO_PACKET nvPacket = (PNV_VIDEO_PACKET)(((char*)rtpPacket) + dataOffset); nvPacket->frameIndex = queue->currentFrameNumber; - - //Remove padding of generated packet - int size = StreamConfig.packetSize + dataOffset; - if (rtpPacket->sequenceNumber == ushort(queue->bufferLowestSequenceNumber + queue->bufferDataPackets - 1)) { - while (packets[i][size-1] == 0) { - size--; - } - } + // FEC recovered frames may have extra zero padding at the end. This is + // fine per H.264 Annex B which states trailing zero bytes must be + // discarded by decoders. It's not safe to strip all zero padding because + // it may be a legitimate part of the H.264 bytestream. + + int size = StreamConfig.packetSize + dataOffset; memcpy(&packets[i][receiveSize], &size, sizeof(int)); queuePacket(queue, queueEntry, 0, rtpPacket); } else if (packets[i] != NULL) {