mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 10:53:50 +02:00
Merge pull request #209 from JonnyBurger/flac-consecutive-headers
Ensure FLAC headers are consecutive
This commit is contained in:
@@ -339,16 +339,34 @@ export class FlacDemuxer extends Demuxer {
|
||||
slice.skip(-2);
|
||||
const lengthIfNextFlacFrameHeaderIsLegit = slice.filePos - startPos;
|
||||
|
||||
const nextIsLegit = this.readFlacFrameHeader({
|
||||
const nextFrameHeader = this.readFlacFrameHeader({
|
||||
slice,
|
||||
isFirstPacket: false,
|
||||
});
|
||||
|
||||
if (!nextIsLegit) {
|
||||
if (!nextFrameHeader) {
|
||||
slice.skip(-1);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ensure the frameOrSampleNum is consecutive.
|
||||
// https://github.com/Vanilagy/mediabunny/issues/194
|
||||
|
||||
if (this.blockingBit === 0) {
|
||||
// Case A: If the stream is fixed block size, this is the frame number, which increments by 1
|
||||
if (nextFrameHeader.num - frameHeader.num !== 1) {
|
||||
slice.skip(-1);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// Case B: If the stream is variable block size, this is the sample number, which increments by
|
||||
// amount of samples in a frame.
|
||||
if (nextFrameHeader.num - frameHeader.num !== frameHeader.blockSize) {
|
||||
slice.skip(-1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
num: frameHeader.num,
|
||||
blockSize: frameHeader.blockSize,
|
||||
@@ -442,6 +460,11 @@ export class FlacDemuxer extends Demuxer {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (sampleRate !== this.audioInfo.sampleRate) {
|
||||
// This cannot be a valid FLAC frame, the sample rate is not the same as in the stream info
|
||||
return null;
|
||||
}
|
||||
|
||||
const size = slice.filePos - startOffset;
|
||||
const crc = readU8(slice);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user