1- import { MediaSource_ } from "../../../compat/browser_compatibility_types" ;
2- import features from "../../../features" ;
3- import log from "../../../log" ;
4- import type { IManifest } from "../../../manifest" ;
5- import { createRepresentationFilterFromFnString } from "../../../manifest" ;
6- import type Manifest from "../../../manifest/classes" ;
7- import type { IMediaSourceInterface } from "../../../mse" ;
8- import MainMediaSourceInterface from "../../../mse/main_media_source_interface" ;
9- import WorkerMediaSourceInterface from "../../../mse/worker_media_source_interface" ;
10- import type {
11- IAttachMediaSourceWorkerMessagePayload ,
12- IContentInitializationData ,
13- IWorkerMessage ,
14- } from "../../../multithread_types" ;
15- import { WorkerMessageType } from "../../../multithread_types" ;
16- import type { IPlayerError } from "../../../public_types" ;
17- import idGenerator from "../../../utils/id_generator" ;
18- import isNullOrUndefined from "../../../utils/is_null_or_undefined" ;
19- import type {
20- CancellationError ,
21- CancellationSignal ,
22- } from "../../../utils/task_canceller" ;
23- import TaskCanceller from "../../../utils/task_canceller" ;
24- import type { IRepresentationEstimator } from "../../adaptive" ;
25- import createAdaptiveRepresentationSelector from "../../adaptive" ;
26- import type { IRepresentationEstimatorThrottlers } from "../../adaptive/adaptive_representation_selector" ;
27- import CmcdDataBuilder from "../../cmcd" ;
28- import type { IManifestRefreshSettings } from "../../fetchers" ;
29- import { ManifestFetcher , SegmentQueueCreator } from "../../fetchers" ;
30- import CdnPrioritizer from "../../fetchers/cdn_prioritizer" ;
31- import createThumbnailFetcher from "../../fetchers/thumbnails/thumbnail_fetcher" ;
32- import type { IThumbnailFetcher } from "../../fetchers/thumbnails/thumbnail_fetcher" ;
33- import SegmentSinksStore from "../../segment_sinks" ;
34- import FreezeResolver from "../common/FreezeResolver" ;
1+ import { MediaSource_ } from "../../compat/browser_compatibility_types" ;
2+ import features from "../../features" ;
3+ import log from "../../log" ;
4+ import type { IContentInitializationData } from "../../main_thread/types" ;
5+ import type { IManifest } from "../../manifest" ;
6+ import { createRepresentationFilterFromFnString } from "../../manifest" ;
7+ import type Manifest from "../../manifest/classes" ;
8+ import type { IMediaSourceInterface } from "../../mse" ;
9+ import MainMediaSourceInterface from "../../mse/main_media_source_interface" ;
10+ import WorkerMediaSourceInterface from "../../mse/worker_media_source_interface" ;
11+ import type { IPlayerError } from "../../public_types" ;
12+ import idGenerator from "../../utils/id_generator" ;
13+ import isNullOrUndefined from "../../utils/is_null_or_undefined" ;
14+ import type { CancellationError , CancellationSignal } from "../../utils/task_canceller" ;
15+ import TaskCanceller from "../../utils/task_canceller" ;
16+ import type { IRepresentationEstimator } from "../adaptive" ;
17+ import createAdaptiveRepresentationSelector from "../adaptive" ;
18+ import type { IRepresentationEstimatorThrottlers } from "../adaptive/adaptive_representation_selector" ;
19+ import CmcdDataBuilder from "../cmcd" ;
20+ import type { IManifestRefreshSettings } from "../fetchers" ;
21+ import { ManifestFetcher , SegmentQueueCreator } from "../fetchers" ;
22+ import CdnPrioritizer from "../fetchers/cdn_prioritizer" ;
23+ import createThumbnailFetcher from "../fetchers/thumbnails/thumbnail_fetcher" ;
24+ import type { IThumbnailFetcher } from "../fetchers/thumbnails/thumbnail_fetcher" ;
25+ import SegmentSinksStore from "../segment_sinks" ;
26+ import type { IAttachMediaSourceCoreMessagePayload , ICoreMessage } from "../types" ;
27+ import { CoreMessageType } from "../types" ;
28+ import CoreTextDisplayerInterface from "./core_text_displayer_interface" ;
29+ import FreezeResolver from "./FreezeResolver" ;
3530import TrackChoiceSetter from "./track_choice_setter" ;
3631import { formatErrorForSender } from "./utils" ;
37- import WorkerTextDisplayerInterface from "./worker_text_displayer_interface" ;
3832
3933/** Function allowing to associate a unique identifier to all created `MediaSource` */
4034const generateMediaSourceId = idGenerator ( ) ;
@@ -110,7 +104,7 @@ export default class ContentPreparer {
110104 * @returns {Promise.<Object> }
111105 */
112106 public initializeNewContent (
113- sendMessage : ( msg : IWorkerMessage , transferables ?: Transferable [ ] ) => void ,
107+ sendMessage : ( msg : ICoreMessage , transferables ?: Transferable [ ] ) => void ,
114108 context : IContentInitializationData ,
115109 /** Allows to filter which Representations can be choosen. */
116110 throttlers : IRepresentationEstimatorThrottlers ,
@@ -192,7 +186,7 @@ export default class ContentPreparer {
192186
193187 const trackChoiceSetter = new TrackChoiceSetter ( ) ;
194188
195- const [ mediaSource , segmentSinksStore , workerTextSender ] =
189+ const [ mediaSource , segmentSinksStore , coreTextSender ] =
196190 createMediaSourceInterfaceAndSegmentSinksStore (
197191 sendMessage ,
198192 contentId ,
@@ -216,7 +210,7 @@ export default class ContentPreparer {
216210 segmentSinksStore,
217211 segmentQueueCreator,
218212 fetchThumbnailData,
219- workerTextSender ,
213+ coreTextSender ,
220214 trackChoiceSetter,
221215 useMseInWorker,
222216 } ;
@@ -235,7 +229,7 @@ export default class ContentPreparer {
235229 "warning" ,
236230 ( err : IPlayerError ) => {
237231 sendMessage ( {
238- type : WorkerMessageType . Warning ,
232+ type : CoreMessageType . Warning ,
239233 contentId,
240234 value : formatErrorForSender ( err ) ,
241235 } ) ;
@@ -261,7 +255,7 @@ export default class ContentPreparer {
261255 "error" ,
262256 ( err : unknown ) => {
263257 sendMessage ( {
264- type : WorkerMessageType . Error ,
258+ type : CoreMessageType . Error ,
265259 contentId,
266260 value : formatErrorForSender ( err ) ,
267261 } ) ;
@@ -288,7 +282,7 @@ export default class ContentPreparer {
288282 return ;
289283 }
290284 sendMessage ( {
291- type : WorkerMessageType . ManifestUpdate ,
285+ type : CoreMessageType . ManifestUpdate ,
292286 contentId,
293287 value : { manifest, updates } ,
294288 } ) ;
@@ -323,13 +317,16 @@ export default class ContentPreparer {
323317 }
324318
325319 /**
326- * Signal the ContentPreparer that the MediaSource is "reloading".
320+ * Change the MediaSource attached for the current content.
321+ * It is assumed that main thread is already notified that such a reload is
322+ * happening.
327323 *
328324 * The returned Promise resolves when it restarts being ready.
325+ * @param {Function } sendMessage
329326 * @returns {Promise }
330327 */
331328 public reloadMediaSource (
332- sendMessage : ( msg : IWorkerMessage , transferables ?: Transferable [ ] ) => void ,
329+ sendMessage : ( msg : ICoreMessage , transferables ?: Transferable [ ] ) => void ,
333330 ) : Promise < void > {
334331 this . _currentMediaSourceCanceller . cancel ( ) ;
335332 if ( this . _currentContent === null ) {
@@ -338,21 +335,21 @@ export default class ContentPreparer {
338335 this . _currentContent . trackChoiceSetter . reset ( ) ;
339336 this . _currentMediaSourceCanceller = new TaskCanceller ( ) ;
340337
341- const [ mediaSourceInterface , segmentSinksStore , workerTextSender ] =
338+ const [ mediaSourceInterface , segmentSinksStore , coreTextSender ] =
342339 createMediaSourceInterfaceAndSegmentSinksStore (
343340 sendMessage ,
344341 this . _currentContent . contentId ,
345342 {
346343 useMseInWorker : this . _currentContent . useMseInWorker ,
347344 hasVideo : this . _hasVideo ,
348- hasText : this . _currentContent . workerTextSender !== null ,
345+ hasText : this . _currentContent . coreTextSender !== null ,
349346 } ,
350347 this . _currentMediaSourceCanceller . signal ,
351348 ) ;
352349 this . _currentContent . mediaSource = mediaSourceInterface ;
353350 this . _currentContent . segmentSinksStore = segmentSinksStore ;
354351 this . _currentContent . freezeResolver = new FreezeResolver ( segmentSinksStore ) ;
355- this . _currentContent . workerTextSender = workerTextSender ;
352+ this . _currentContent . coreTextSender = coreTextSender ;
356353 return new Promise ( ( res , rej ) => {
357354 mediaSourceInterface . addEventListener (
358355 "mediaSourceOpen" ,
@@ -435,7 +432,7 @@ export interface IPreparedContentData {
435432 */
436433 segmentSinksStore : SegmentSinksStore ;
437434 /** Allows to send timed text media data so it can be rendered. */
438- workerTextSender : WorkerTextDisplayerInterface | null ;
435+ coreTextSender : CoreTextDisplayerInterface | null ;
439436 /**
440437 * Allows to create `SegmentQueue` which simplifies complex media segment
441438 * fetching.
@@ -467,21 +464,21 @@ export interface IPreparedContentData {
467464 * @returns {Array.<Object> }
468465 */
469466function createMediaSourceInterfaceAndSegmentSinksStore (
470- sendMessage : ( msg : IWorkerMessage , transferables ?: Transferable [ ] ) => void ,
467+ sendMessage : ( msg : ICoreMessage , transferables ?: Transferable [ ] ) => void ,
471468 contentId : string ,
472469 capabilities : {
473470 useMseInWorker : boolean ;
474471 hasVideo : boolean ;
475472 hasText : boolean ;
476473 } ,
477474 cancelSignal : CancellationSignal ,
478- ) : [ IMediaSourceInterface , SegmentSinksStore , WorkerTextDisplayerInterface | null ] {
475+ ) : [ IMediaSourceInterface , SegmentSinksStore , CoreTextDisplayerInterface | null ] {
479476 let mediaSourceInterface : IMediaSourceInterface ;
480477 if ( capabilities . useMseInWorker ) {
481478 const mainMediaSource = new MainMediaSourceInterface ( generateMediaSourceId ( ) ) ;
482479 mediaSourceInterface = mainMediaSource ;
483480
484- let sentMediaSourceLink : IAttachMediaSourceWorkerMessagePayload ;
481+ let sentMediaSourceLink : IAttachMediaSourceCoreMessagePayload ;
485482 const handle = mainMediaSource . handle ;
486483 if ( handle . type === "handle" ) {
487484 sentMediaSourceLink = { type : "handle" as const , value : handle . value } ;
@@ -495,7 +492,7 @@ function createMediaSourceInterfaceAndSegmentSinksStore(
495492
496493 sendMessage (
497494 {
498- type : WorkerMessageType . AttachMediaSource ,
495+ type : CoreMessageType . AttachMediaSource ,
499496 contentId,
500497 value : sentMediaSourceLink ,
501498 mediaSourceId : mediaSourceInterface . id ,
@@ -511,7 +508,7 @@ function createMediaSourceInterfaceAndSegmentSinksStore(
511508 }
512509
513510 const textSender = capabilities . hasText
514- ? new WorkerTextDisplayerInterface ( contentId , sendMessage )
511+ ? new CoreTextDisplayerInterface ( contentId , sendMessage )
515512 : null ;
516513 const { hasVideo } = capabilities ;
517514 const segmentSinksStore = new SegmentSinksStore (
0 commit comments