Browse Source

H265RtpDepacketizer: Fix multiple NAL units handling

Based on the fix for H264RtpDepacketizer in #1167 (commit
4fc4e9ba822994ddeb5ce1b60075bf6be84a3493).
Robert Edmonds 10 months ago
parent
commit
3dc1a177e0
1 changed files with 5 additions and 2 deletions
  1. 5 2
      src/h265rtpdepacketizer.cpp

+ 5 - 2
src/h265rtpdepacketizer.cpp

@@ -62,7 +62,6 @@ message_vector H265RtpDepacketizer::buildFrames(message_vector::iterator begin,
 	message_vector out = {};
 	auto accessUnit = binary{};
 	auto frameInfo = std::make_shared<FrameInfo>(payloadType, timestamp);
-	auto nFrags = 0;
 
 	for (auto it = begin; it != end; ++it) {
 		auto pkt = it->get();
@@ -87,7 +86,11 @@ message_vector H265RtpDepacketizer::buildFrames(message_vector::iterator begin,
 			auto nalUnitFragmentHeader = H265NalUnitFragmentHeader{
 			    std::to_integer<uint8_t>(pkt->at(rtpHeaderSize + sizeof(H265NalUnitHeader)))};
 
-			if (nFrags++ == 0) {
+			// RFC 7798: "When set to 1, the S bit indicates the start of a fragmented
+			// NAL unit, i.e., the first byte of the FU payload is also the first byte of
+			// the payload of the fragmented NAL unit. When the FU payload is not the start
+			// of the fragmented NAL unit payload, the S bit MUST be set to 0."
+			if (nalUnitFragmentHeader.isStart() || accessUnit.empty()) {
 				addSeparator(accessUnit);
 				nalUnitHeader.setUnitType(nalUnitFragmentHeader.unitType());
 				accessUnit.emplace_back(byte(nalUnitHeader._first));