import features from "../../features"; import log from "../../log"; import type { IContentInitializationData } from "../../main_thread/types"; import type { IManifest } from "../../manifest"; import type { IMediaSourceInterface } from "../../mse"; import MainMediaSourceInterface from "../../mse/main_media_source_interface"; import WorkerMediaSourceInterface from "../../mse/worker_media_source_interface"; import type { IPlayerError } from "../../public_types"; import idGenerator from "../../utils/id_generator"; import type { CancellationError, CancellationSignal } from "../../utils/task_canceller"; import TaskCanceller from "../../utils/task_canceller"; import type { IRepresentationEstimator } from "../adaptive"; import createAdaptiveRepresentationSelector from "../adaptive"; import type { IRepresentationEstimatorThrottlers } from "../adaptive/adaptive_representation_selector"; import CmcdDataBuilder from "../cmcd"; import type { IManifestRefreshSettings } from "../fetchers"; import { ManifestFetcher, SegmentQueueCreator } from "../fetchers"; import CdnPrioritizer from "../fetchers/cdn_prioritizer"; import createThumbnailFetcher from "../fetchers/thumbnails/thumbnail_fetcher"; import type { IThumbnailFetcher } from "../fetchers/thumbnails/thumbnail_fetcher"; import SegmentSinksStore from "../segment_sinks"; import type { IAttachMediaSourceCoreMessagePayload, ICoreMessage } from "../types"; import { CoreMessageType } from "../types"; import CoreTextDisplayerInterface from "./core_text_displayer_interface"; import FreezeResolver from "./FreezeResolver"; import TrackChoiceSetter from "./track_choice_setter"; import type { ICorePlugins } from "./utils"; import { extractExternalPlugins, formatErrorForSender, updateCodecSupportInWorkerMode, } from "./utils"; /** Function allowing to associate a unique identifier to all created `MediaSource` */ const generateMediaSourceId = idGenerator(); /** * Class facilitating the workflows behind loading a new content for the * RxPlayer Core: * * - Handle Manifest fetching and Manifest updates. * * - Handle the `MediaSource`'s creation and indirectly of its `SourceBuffer`s * as well as handling "MediaSource reloading". * * - initialize various modules (`segmentQueueCreator`, CmcdDataBuilder`, * `RepresentationEstimator`) linked to the initialized content. * * You can start loading a content through the `initializeNewContent` method. * * When a content is linked to the `ContentPreparer` you can inspect the * different initialized modules by calling its `getCurrentContent` method. * * @class ContentPreparer */ export default class ContentPreparer { /** * Information on the content linked to that `ContentPreparer` through its * `initializeNewContent` method. * `null` if no content is initialized. */ private _currentContent: IPreparedContentData | null; /** * TaskCanceller which is triggered when the currently-initialized content is * not needed anymore, because we stopped it since or switched to a new content. */ private _contentCanceller: TaskCanceller; /** * TaskCanceller which is triggered when the currently-created MediaSource is * not needed anymore, either because the content has changed or because we * had to reload. */ private _currentMediaSourceCanceller: TaskCanceller; /** @see constructor */ private _hasVideo: boolean; /** * @param {Object} capabilities * @param {boolean} capabilities.hasVideo - If `true`, we're playing on an * element which has video capabilities. * If `false`, we're only able to play audio, optionally with subtitles. * * Typically this boolean is `true` for `