Fix SourceRef race conditions, fix "source" and "target" getter returning unused instances, add missing validation, make "getDurationFromMetadata" only exist on tracks, fix examples, expand media player to support live playback, change the signatures of some Input APIs

This commit is contained in:
Vanilagy
2026-04-10 13:38:14 +02:00
parent 0813bcab28
commit aa810fc433
24 changed files with 493 additions and 476 deletions
+10
View File
@@ -11,6 +11,8 @@ import { Target } from './target';
export class Writer {
target: Target;
finalized = false;
started = false;
private pos = 0;
@@ -19,7 +21,9 @@ export class Writer {
}
start() {
assert(!this.started);
this.target._start();
this.started = true;
}
ensureMonotonicity() {
@@ -29,6 +33,8 @@ export class Writer {
/** Writes the given data to the target, at the current position. */
write(data: Uint8Array) {
assert(this.started && !this.finalized);
this.maybeTrackWrites(data);
this.target._write(data, this.pos);
this.pos += data.byteLength;
@@ -46,15 +52,19 @@ export class Writer {
/** Signals to the writer that it may be time to flush. */
async flush() {
assert(this.started && !this.finalized);
return this.target._flush();
}
/** Called after muxing has finished. */
async finalize() {
assert(this.started && !this.finalized);
assert(this.target._output);
await this.target._finalize();
this.target._output._targets.delete(this.target);
this.finalized = true;
}
private trackedWrites: Uint8Array | null = null;