Implement ADTS demuxer, Fix MP3 demuxer race conditions

This commit is contained in:
Ally
2025-08-18 01:29:52 +02:00
parent 1ce5e108a7
commit 8da619a624
10 changed files with 560 additions and 85 deletions
+16
View File
@@ -73,6 +73,22 @@ export class Bitstream {
return result;
}
writeBits(n: number, value: number) {
const end = this.pos + n;
for (let i = this.pos; i < end; i++) {
const byteIndex = Math.floor(i / 8);
let byte = this.bytes[byteIndex]!;
const bitIndex = 0b111 - (i & 0b111);
byte &= ~(1 << bitIndex);
byte |= ((value & (1 << (end - i - 1))) >> (end - i - 1)) << bitIndex;
this.bytes[byteIndex] = byte;
}
this.pos = end;
};
readAlignedByte() {
// Ensure we're byte-aligned
if (this.pos % 8 !== 0) {