rebroadcast: remove some bit shifting in favor of read/write uintbe

This commit is contained in:
Koushik Dutta
2026-01-08 21:35:04 -08:00
parent 1349bb7433
commit 0185680791
2 changed files with 3 additions and 9 deletions

View File

@@ -29,11 +29,8 @@ export function createAUHeader(
// Combine size and index into a single value
const combinedValue = (frameSize << indexLength) | auIndex;
// Convert to bytes (little-endian within the multi-byte value)
const header = new Buffer(totalBytes);
for (let i = 0; i < totalBytes; i++) {
header[i] = (combinedValue >> ((totalBytes - 1 - i) * 8)) & 0xFF;
}
const header = Buffer.alloc(totalBytes);
header.writeUintBE(combinedValue, 0, totalBytes);
return header;
}

View File

@@ -224,10 +224,7 @@ function parseNALUUnits(buffer: Buffer, offset: number, length: number, naluLeng
}
while (pos + naluLengthSize <= offset + length) {
let naluLength = 0;
for (let i = 0; i < naluLengthSize; i++) {
naluLength = (naluLength << 8) | buffer[pos + i];
}
const naluLength = buffer.readUintBE(pos, naluLengthSize);
pos += naluLengthSize;
if (naluLength === 0) {