Skip to content

Commit b740b68

Browse files
committed
Fix AV1 packetizer length field for 127-byte fragments
packetize(List) used the 2-byte LEB128 length branch for any fragment >= 127 bytes, but 127 fits in a single LEB128 byte (0x7F). For an exactly 127-byte fragment LEB128.encode returned 0x7F and the 2-byte split wrote a malformed length of [0x00, 0x7F]; the depacketizer then read a zero-length fragment followed by a spurious second OBU, splitting one OBU into two and corrupting the frame. Use the 2-byte branch only for sizes > 127. Verified: a frame whose final fragment is exactly 127 bytes now reconstructs to a single OBU of the full length (previously two elements). Caught by the byte-for-byte AV1 framing self-check added on the consumer side.
1 parent e11a662 commit b740b68

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

io/src/main/java/org/red5/io/rtp/AV1Packetizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public List<byte[]> packetize(List<OBUInfo> obuInfos, int mtu) {
292292
int currentFragmentSize = Math.min(maxFragmentSize, payloadDataRemaining);
293293
int leb128Value = LEB128.encode(currentFragmentSize);
294294
byte[] out;
295-
if (currentFragmentSize >= 127) { // leb takes at least 2 bytes
295+
if (currentFragmentSize > 127) { // leb takes 2 bytes only above 127 (0-127 fit in one byte)
296296
int outLen = aggregationHeaderLength + 2 + currentFragmentSize;
297297
out = new byte[outLen];
298298
out[1] = (byte) (leb128Value >> 8);

0 commit comments

Comments
 (0)