From d28e56f852ded83aac95c7c3db89579cdb7de9c2 Mon Sep 17 00:00:00 2001 From: Paul-Louis Ageneau Date: Mon, 6 May 2024 14:43:11 +0200 Subject: [PATCH] Fix multiple NAL units handling in H264RtpDepacketizer --- src/h264rtpdepacketizer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/h264rtpdepacketizer.cpp b/src/h264rtpdepacketizer.cpp index f2ddabb4c..72636838a 100644 --- a/src/h264rtpdepacketizer.cpp +++ b/src/h264rtpdepacketizer.cpp @@ -44,7 +44,6 @@ message_vector H264RtpDepacketizer::buildFrames(message_vector::iterator begin, message_vector out = {}; auto accessUnit = binary{}; auto frameInfo = std::make_shared(payloadType, timestamp); - auto nFrags = 0; for (auto it = begin; it != end; ++it) { auto pkt = it->get(); @@ -67,7 +66,10 @@ message_vector H264RtpDepacketizer::buildFrames(message_vector::iterator begin, auto nalUnitFragmentHeader = NalUnitFragmentHeader{ std::to_integer(pkt->at(rtpHeaderSize + sizeof(NalUnitHeader)))}; - if (nFrags++ == 0) { + // RFC 6184: When set to one, the Start bit indicates the start of a fragmented NAL + // unit. When the following FU payload is not the start of a fragmented NAL unit + // payload, the Start bit is set to zero. + if (nalUnitFragmentHeader.isStart() || accessUnit.empty()) { addSeparator(accessUnit); accessUnit.emplace_back( byte(nalUnitHeader.idc() | nalUnitFragmentHeader.unitType()));