From fa03b7d309eb6f735d436cc4cc3cff5e6d9c03f3 Mon Sep 17 00:00:00 2001 From: Paul Berberian Date: Mon, 18 Mar 2024 15:02:22 +0100 Subject: [PATCH] Change a ContentInitializer dispose method to stop This was done as it makes more sense to have an "idle" state after stopping than disposing (in the latter case, we would have to add something like the "disposed" state) and as it may be more portable to allow re-using a ContentInitializer later, which however for now hasn't any real case. --- src/main_thread/api/public_api.ts | 2 +- src/main_thread/init/directfile_content_initializer.ts | 3 ++- src/main_thread/init/media_source_content_initializer.ts | 3 ++- src/main_thread/init/multi_thread_content_initializer.ts | 3 ++- src/main_thread/init/types.ts | 6 ++++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main_thread/api/public_api.ts b/src/main_thread/api/public_api.ts index d68fef6bab..7603ca44cb 100644 --- a/src/main_thread/api/public_api.ts +++ b/src/main_thread/api/public_api.ts @@ -1106,7 +1106,7 @@ class Player extends EventEmitter { currentContentCanceller.signal, ); currentContentCanceller.signal.register(() => { - initializer.dispose(); + initializer.stop(); }); /** diff --git a/src/main_thread/init/directfile_content_initializer.ts b/src/main_thread/init/directfile_content_initializer.ts index fb83598513..66b07b8e23 100644 --- a/src/main_thread/init/directfile_content_initializer.ts +++ b/src/main_thread/init/directfile_content_initializer.ts @@ -212,8 +212,9 @@ export default class DirectFileContentInitializer extends ContentInitializer { /** * Stop content and free all resources linked to this `ContentIntializer`. */ - public dispose(): void { + public stop(): void { this._initCanceller.cancel(); + this._initCanceller = new TaskCanceller(); this.state = ContentInitializerState.Idle; this.trigger("stateChange", this.state); } diff --git a/src/main_thread/init/media_source_content_initializer.ts b/src/main_thread/init/media_source_content_initializer.ts index 532cf8e4db..953bf9a183 100644 --- a/src/main_thread/init/media_source_content_initializer.ts +++ b/src/main_thread/init/media_source_content_initializer.ts @@ -295,12 +295,13 @@ export default class MediaSourceContentInitializer extends ContentInitializer { * Stop content and free all resources linked to this * `MediaSourceContentInitializer`. */ - public dispose(): void { + public stop(): void { if (this._contentMetadata?.type === "preparing") { this._contentMetadata.reject(new Error("The content has been disposed")); } this._contentMetadata = null; this._initCanceller.cancel(); + this._initCanceller = new TaskCanceller(); this.state = ContentInitializerState.Idle; this.trigger("stateChange", this.state); } diff --git a/src/main_thread/init/multi_thread_content_initializer.ts b/src/main_thread/init/multi_thread_content_initializer.ts index e06e4e5978..f79d1a8aa3 100644 --- a/src/main_thread/init/multi_thread_content_initializer.ts +++ b/src/main_thread/init/multi_thread_content_initializer.ts @@ -1109,8 +1109,9 @@ export default class MultiThreadContentInitializer extends ContentInitializer { }); } - public dispose(): void { + public stop(): void { this._initCanceller.cancel(); + this._initCanceller = new TaskCanceller(); if (this._currentContentInfo !== null) { this._currentContentInfo.mainThreadMediaSource?.dispose(); this._currentContentInfo = null; diff --git a/src/main_thread/init/types.ts b/src/main_thread/init/types.ts index 755f6e8ea0..83a5faaed3 100644 --- a/src/main_thread/init/types.ts +++ b/src/main_thread/init/types.ts @@ -108,10 +108,12 @@ export abstract class ContentInitializer extends EventEmitter