Add Output.cancel

This commit is contained in:
Vanilagy
2025-01-02 19:57:32 +01:00
parent c42495ec7e
commit 141bed1b37
4 changed files with 49 additions and 4 deletions
+12 -2
View File
@@ -20,6 +20,8 @@ export abstract class MediaSource {
/** @internal */
_connectedTrack: OutputTrack | null = null;
/** @internal */
_closing = false;
/** @internal */
_closed = false;
/** @internal */
_offsetTimestamps = false;
@@ -30,6 +32,10 @@ export abstract class MediaSource {
throw new Error('Cannot call digest without connecting the source to an output track.');
}
if (this._connectedTrack.output._canceled) {
throw new Error('Cannot call digest after output has been canceled.');
}
if (!this._connectedTrack.output._started) {
throw new Error('Cannot call digest before output has been started.');
}
@@ -48,8 +54,8 @@ export abstract class MediaSource {
/** @internal */
async _flush() {}
close() {
if (this._closed) {
async close() {
if (this._closing) {
throw new Error('Source already closed.');
}
@@ -61,6 +67,10 @@ export abstract class MediaSource {
throw new Error('Cannot call close before output has been started.');
}
this._closing = true;
await this._flush();
this._closed = true;
if (this._connectedTrack.output._finalizing) {