Implement ReadOrchestrator class, add highly optimized UrlSource

This commit is contained in:
Vanilagy
2025-08-29 19:39:50 +02:00
parent 641cdd02e3
commit c93755def1
15 changed files with 704 additions and 824 deletions
-63
View File
@@ -1,63 +0,0 @@
/*!
* Copyright (c) 2025-present, Vanilagy and contributors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { Reader } from '../reader';
export class RiffReader {
pos = 0;
littleEndian = true;
constructor(public reader: Reader) {}
readBytes(length: number) {
const { view, offset } = this.reader.getViewAndOffset(this.pos, this.pos + length);
this.pos += length;
return new Uint8Array(view.buffer, offset, length);
}
readU16() {
const { view, offset } = this.reader.getViewAndOffset(this.pos, this.pos + 2);
this.pos += 2;
return view.getUint16(offset, this.littleEndian);
}
readU32() {
const { view, offset } = this.reader.getViewAndOffset(this.pos, this.pos + 4);
this.pos += 4;
return view.getUint32(offset, this.littleEndian);
}
readU64() {
let low: number;
let high: number;
if (this.littleEndian) {
low = this.readU32();
high = this.readU32();
} else {
high = this.readU32();
low = this.readU32();
}
return high * 0x100000000 + low;
}
readAscii(length: number) {
const { view, offset } = this.reader.getViewAndOffset(this.pos, this.pos + length);
this.pos += length;
let str = '';
for (let i = 0; i < length; i++) {
str += String.fromCharCode(view.getUint8(offset + i));
}
return str;
}
}
+2 -5
View File
@@ -47,9 +47,6 @@ export class WaveDemuxer extends Demuxer {
async readMetadata() {
return this.metadataPromise ??= (async () => {
let actualFileSize = this.reader.requestSize();
if (actualFileSize instanceof Promise) actualFileSize = await actualFileSize;
let slice = this.reader.requestSlice(0, 12);
if (slice instanceof Promise) slice = await slice;
assert(slice);
@@ -61,7 +58,7 @@ export class WaveDemuxer extends Demuxer {
const outerChunkSize = readU32(slice, littleEndian);
let totalFileSize = isRf64 ? actualFileSize : Math.min(outerChunkSize + 8, actualFileSize);
let totalFileSize = isRf64 ? this.reader.fileSize : Math.min(outerChunkSize + 8, this.reader.fileSize);
const format = readAscii(slice, 4);
if (format !== 'WAVE') {
@@ -98,7 +95,7 @@ export class WaveDemuxer extends Demuxer {
const riffChunkSize = readU64(slice, littleEndian);
dataChunkSize = readU64(slice, littleEndian);
totalFileSize = Math.min(riffChunkSize + 8, actualFileSize);
totalFileSize = Math.min(riffChunkSize + 8, this.reader.fileSize);
}
currentPos = startPos + chunkSize + (chunkSize & 1); // Handle padding