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.

This commit is contained in:
Cameron Gutman 2017-05-11 20:10:20 -07:00
parent 417c8be124
commit 20821e7eb6

View File

@ -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) {