diff --git a/src/core/cmcd/cmcd_data_builder.ts b/src/core/cmcd/cmcd_data_builder.ts index 33ed192f69..dea5efd748 100644 --- a/src/core/cmcd/cmcd_data_builder.ts +++ b/src/core/cmcd/cmcd_data_builder.ts @@ -1,5 +1,4 @@ import log from "../../log"; -import type { ICorePlaybackObservation } from "../../main_thread/init/utils/create_core_playback_observer"; import type { IAdaptation, IManifest, @@ -8,6 +7,7 @@ import type { ISegment, } from "../../manifest"; import type { IReadOnlyPlaybackObserver } from "../../playback_observer"; +import type { ICorePlaybackObservation } from "../../playback_observer/types"; import type { ICmcdOptions, ICmcdPayload, ITrackType } from "../../public_types"; import createUuid from "../../utils/create_uuid"; import isNullOrUndefined from "../../utils/is_null_or_undefined"; diff --git a/src/core/main/worker/worker_main.ts b/src/core/main/worker/worker_main.ts index c974f25834..86466703b9 100644 --- a/src/core/main/worker/worker_main.ts +++ b/src/core/main/worker/worker_main.ts @@ -2,7 +2,6 @@ import config from "../../../config"; import { MediaError, OtherError } from "../../../errors"; import features from "../../../features"; import log from "../../../log"; -import type { ICorePlaybackObservation } from "../../../main_thread/init/utils/create_core_playback_observer"; import Manifest, { Adaptation, Period, Representation } from "../../../manifest/classes"; import type { IContentInitializationData, @@ -14,6 +13,7 @@ import { MainThreadMessageType, WorkerMessageType } from "../../../multithread_t import DashFastJsParser from "../../../parsers/manifest/dash/fast-js-parser"; import DashWasmParser from "../../../parsers/manifest/dash/wasm-parser"; import { ObservationPosition } from "../../../playback_observer"; +import type { ICorePlaybackObservation } from "../../../playback_observer/types"; import WorkerPlaybackObserver from "../../../playback_observer/worker_playback_observer"; import type { IPlayerError, ITrackType } from "../../../public_types"; import createDashPipelines from "../../../transports/dash"; diff --git a/src/main_thread/init/multi_thread_content_initializer.ts b/src/main_thread/init/multi_thread_content_initializer.ts index d2671283b2..492a0775a1 100644 --- a/src/main_thread/init/multi_thread_content_initializer.ts +++ b/src/main_thread/init/multi_thread_content_initializer.ts @@ -33,6 +33,7 @@ import type { IReadOnlyPlaybackObserver, IMediaElementPlaybackObserver, } from "../../playback_observer"; +import type { ICorePlaybackObservation } from "../../playback_observer/types"; import type { ICmcdOptions, IInitialManifest, @@ -57,7 +58,7 @@ import type { ITextDisplayer } from "../text_displayer"; import sendMessage from "./send_message"; import type { ITextDisplayerOptions } from "./types"; import { ContentInitializer } from "./types"; -import type { ICorePlaybackObservation } from "./utils/create_core_playback_observer"; + import createCorePlaybackObserver from "./utils/create_core_playback_observer"; import { resetMediaElement } from "./utils/create_media_source"; import type { IInitialTimeOptions } from "./utils/get_initial_time"; diff --git a/src/main_thread/init/utils/create_core_playback_observer.ts b/src/main_thread/init/utils/create_core_playback_observer.ts index 1d18caf1a4..5109754a62 100644 --- a/src/main_thread/init/utils/create_core_playback_observer.ts +++ b/src/main_thread/init/utils/create_core_playback_observer.ts @@ -15,7 +15,6 @@ */ import getBufferedDataPerMediaBuffer from "../../../core/main/common/get_buffered_data_per_media_buffer"; -import type { IPausedPlaybackObservation } from "../../../core/types"; import type { IManifestMetadata } from "../../../manifest"; import { getMaximumSafePosition } from "../../../manifest"; import type { IMediaSourceInterface } from "../../../mse"; @@ -23,12 +22,8 @@ import type { IPlaybackObservation, IReadOnlyPlaybackObserver, IMediaElementPlaybackObserver, - ObservationPosition, - IRebufferingStatus, - IFreezingStatus, } from "../../../playback_observer"; -import type { ITrackType } from "../../../public_types"; -import type { IRange } from "../../../utils/ranges"; +import type { ICorePlaybackObservation } from "../../../playback_observer/types"; import type { IReadOnlySharedReference } from "../../../utils/reference"; import SharedReference from "../../../utils/reference"; import type { CancellationSignal } from "../../../utils/task_canceller"; @@ -55,35 +50,6 @@ export interface ICorePlaybackObserverArguments { mediaSource: IMediaSourceInterface | null; } -export interface ICorePlaybackObservation { - /** - * Information on whether the media element was paused at the time of the - * Observation. - */ - paused: IPausedPlaybackObservation; - /** - * Information on the current media position in seconds at the time of the - * Observation. - */ - position: ObservationPosition; - /** `duration` property of the HTMLMediaElement. */ - duration: number; - /** `readyState` property of the HTMLMediaElement. */ - readyState: number; - /** Target playback rate at which we want to play the content. */ - speed: number; - /** Theoretical maximum position on the content that can currently be played. */ - maximumPosition: number; - /** - * Ranges of buffered data per type of media. - * `null` if no buffer exists for that type of media. - */ - buffered: Record; - rebuffering: IRebufferingStatus | null; - freezing: IFreezingStatus | null; - bufferGap: number | undefined; -} - /** * Create PlaybackObserver for the core part of the code. * @param {Object} srcPlaybackObserver - Base `PlaybackObserver` from which we diff --git a/src/playback_observer/types.ts b/src/playback_observer/types.ts index 554c93b1cb..a3902a8ae5 100644 --- a/src/playback_observer/types.ts +++ b/src/playback_observer/types.ts @@ -1,3 +1,5 @@ +import type { ITrackType } from "../public_types"; +import type { IRange } from "../utils/ranges"; import type { IReadOnlySharedReference } from "../utils/reference"; import type { CancellationSignal } from "../utils/task_canceller"; import type ObservationPosition from "./utils/observation_position"; @@ -236,3 +238,52 @@ export interface IReadOnlyPlaybackObserver { ) => IReadOnlySharedReference, ): IReadOnlyPlaybackObserver; } + +export interface ICorePlaybackObservation { + /** + * Information on whether the media element was paused at the time of the + * Observation. + */ + paused: IPausedPlaybackObservation; + /** + * Information on the current media position in seconds at the time of the + * Observation. + */ + position: ObservationPosition; + /** `duration` property of the HTMLMediaElement. */ + duration: number; + /** `readyState` property of the HTMLMediaElement. */ + readyState: number; + /** Target playback rate at which we want to play the content. */ + speed: number; + /** Theoretical maximum position on the content that can currently be played. */ + maximumPosition: number; + /** + * Ranges of buffered data per type of media. + * `null` if no buffer exists for that type of media. + */ + buffered: Record; + rebuffering: IRebufferingStatus | null; + freezing: IFreezingStatus | null; + bufferGap: number | undefined; +} + +/** Pause-related information linked to an emitted Playback observation. */ +export interface IPausedPlaybackObservation { + /** + * Known paused state at the time the Observation was emitted. + * + * `true` indicating that the HTMLMediaElement was in a paused state. + * + * Note that it might have changed since. If you want truly precize + * information, you should recuperate it from the HTMLMediaElement directly + * through another mean. + */ + last: boolean; + /** + * Actually wanted paused state not yet reached. + * This might for example be set to `false` when the content is currently + * loading (and thus paused) but with autoPlay enabled. + */ + pending: boolean | undefined; +} diff --git a/src/playback_observer/worker_playback_observer.ts b/src/playback_observer/worker_playback_observer.ts index e8ac66a1ea..61e722fdb9 100644 --- a/src/playback_observer/worker_playback_observer.ts +++ b/src/playback_observer/worker_playback_observer.ts @@ -1,9 +1,8 @@ -import type { ICorePlaybackObservation } from "../main_thread/init/utils/create_core_playback_observer"; import type { IUpdatePlaybackRateWorkerMessage } from "../multithread_types"; import { WorkerMessageType } from "../multithread_types"; import type { IReadOnlySharedReference } from "../utils/reference"; import type { CancellationSignal } from "../utils/task_canceller"; -import type { IReadOnlyPlaybackObserver } from "./types"; +import type { ICorePlaybackObservation, IReadOnlyPlaybackObserver } from "./types"; import generateReadOnlyObserver from "./utils/generate_read_only_observer"; export default class WorkerPlaybackObserver