Implement improved StreamSource, restructure source code (hah, get it?)

This commit is contained in:
Vanilagy
2025-08-29 22:50:24 +02:00
parent c93755def1
commit c222973571
13 changed files with 362 additions and 170 deletions
+3 -3
View File
@@ -8,7 +8,7 @@
import { MediaCodec } from '../codec';
import { assertNever, textDecoder, textEncoder } from '../misc';
import { FileSlice, readBytes, Reader2, readF32Be, readF64Be, readU8 } from '../reader2';
import { FileSlice, readBytes, Reader, readF32Be, readF64Be, readU8 } from '../reader2';
import { Writer } from '../writer';
export interface EBMLElement {
@@ -554,7 +554,7 @@ export const readFloat = (slice: FileSlice, width: number) => {
};
/** Returns the byte offset in the file of the next element with a matching ID. */
export const searchForNextElementId = async (reader: Reader2, startPos: number, ids: EBMLId[], until: number) => {
export const searchForNextElementId = async (reader: Reader, startPos: number, ids: EBMLId[], until: number) => {
const idsSet = new Set(ids);
let currentPos = startPos;
@@ -581,7 +581,7 @@ export const searchForNextElementId = async (reader: Reader2, startPos: number,
};
/** Searches for the next occurrence of an element ID using a naive byte-wise search. */
export const resync = async (reader: Reader2, startPos: number, ids: EBMLId[], until: number) => {
export const resync = async (reader: Reader, startPos: number, ids: EBMLId[], until: number) => {
const CHUNK_SIZE = 2 ** 16; // So we don't need to grab thousands of slices
const idsSet = new Set(ids);
let currentPos = startPos;
+3 -3
View File
@@ -69,7 +69,7 @@ import {
searchForNextElementId,
} from './ebml';
import { buildMatroskaMimeType } from './matroska-misc';
import { FileSlice, readBytes, Reader2, readI16Be, readU8 } from '../reader2';
import { FileSlice, readBytes, Reader, readI16Be, readU8 } from '../reader2';
type Segment = {
seekHeadSeen: boolean;
@@ -188,7 +188,7 @@ const METADATA_ELEMENTS = [
const MAX_RESYNC_LENGTH = 10 * 2 ** 20; // 10 MiB
export class MatroskaDemuxer extends Demuxer {
reader: Reader2;
reader: Reader;
readMetadataPromise: Promise<void> | null = null;
@@ -204,7 +204,7 @@ export class MatroskaDemuxer extends Demuxer {
constructor(input: Input) {
super(input);
this.reader = input._reader2;
this.reader = input._reader;
}
override async computeDuration() {