diff --git a/src/core/adaptive/adaptive_representation_selector.ts b/src/core/adaptive/adaptive_representation_selector.ts index 93493248c9..25856f706b 100644 --- a/src/core/adaptive/adaptive_representation_selector.ts +++ b/src/core/adaptive/adaptive_representation_selector.ts @@ -24,8 +24,8 @@ import type { ISegment, } from "../../manifest"; import type { - ObservationPosition, IReadOnlyPlaybackObserver, + IAdaptationStreamPlaybackObservation, } from "../../playback_observer"; import isNullOrUndefined from "../../utils/is_null_or_undefined"; import noop from "../../utils/noop"; @@ -96,7 +96,7 @@ export default function createAdaptiveRepresentationSelector( context: { manifest: IManifest; period: IPeriod; adaptation: IAdaptation }, currentRepresentation: IReadOnlySharedReference, representations: IReadOnlySharedReference, - playbackObserver: IReadOnlyPlaybackObserver, + playbackObserver: IReadOnlyPlaybackObserver, stopAllEstimates: CancellationSignal, ): IRepresentationEstimatorResponse { const { type } = context.adaptation; @@ -636,29 +636,6 @@ export interface IABREstimate { knownStableBitrate?: number | undefined; } -/** Media properties `getEstimateReference` will need to keep track of. */ -export interface IRepresentationEstimatorPlaybackObservation { - /** - * For the concerned media buffer, difference in seconds between the next - * position where no segment data is available and the current position. - */ - bufferGap: number; - /** - * Information on the current media position in seconds at the time of a - * Playback Observation. - */ - position: ObservationPosition; - /** - * Last "playback rate" set by the user. This is the ideal "playback rate" at - * which the media should play. - */ - speed: number; - /** `duration` property of the HTMLMediaElement on which the content plays. */ - duration: number; - /** Theoretical maximum position on the content that can currently be played. */ - maximumPosition: number; -} - /** Content of the `IABRMetricsEvent` event's payload. */ export interface IMetricsCallbackPayload { /** Time the request took to perform the request, in milliseconds. */ @@ -747,7 +724,7 @@ export interface IRepresentationEstimatorArguments { /** Class allowing to estimate the current network bandwidth. */ bandwidthEstimator: BandwidthEstimator; /** Emit regular playback information. */ - playbackObserver: IReadOnlyPlaybackObserver; + playbackObserver: IReadOnlyPlaybackObserver; /** * The Representation currently loaded. * `null` if no Representation is currently loaded. @@ -797,7 +774,7 @@ export type IRepresentationEstimator = ( /** Reference emitting the list of available Representations to choose from. */ representations: IReadOnlySharedReference, /** Regularly emits playback conditions */ - playbackObserver: IReadOnlyPlaybackObserver, + playbackObserver: IReadOnlyPlaybackObserver, /** * After this `CancellationSignal` emits, resources will be disposed and * estimates will stop to be emitted. diff --git a/src/core/adaptive/index.ts b/src/core/adaptive/index.ts index 7fe3e0bdfb..1353e00db6 100644 --- a/src/core/adaptive/index.ts +++ b/src/core/adaptive/index.ts @@ -21,7 +21,6 @@ import type { IMetricsCallbackPayload, IRepresentationEstimator, IRepresentationEstimatorCallbacks, - IRepresentationEstimatorPlaybackObservation, IRepresentationEstimatorThrottlers as IABRThrottlers, IRequestBeginCallbackPayload, IRequestEndCallbackPayload, @@ -39,7 +38,6 @@ export type { IABREstimate, IMetricsCallbackPayload, IRepresentationEstimatorCallbacks, - IRepresentationEstimatorPlaybackObservation, IRequestBeginCallbackPayload, IRequestProgressCallbackPayload, IRequestEndCallbackPayload, diff --git a/src/core/adaptive/network_analyzer.ts b/src/core/adaptive/network_analyzer.ts index 5941ae12f7..125357c84b 100644 --- a/src/core/adaptive/network_analyzer.ts +++ b/src/core/adaptive/network_analyzer.ts @@ -17,10 +17,10 @@ import config from "../../config"; import log from "../../log"; import type { IRepresentation } from "../../manifest"; +import type { IAdaptationStreamPlaybackObservation } from "../../playback_observer"; import arrayFind from "../../utils/array_find"; import isNullOrUndefined from "../../utils/is_null_or_undefined"; import getMonotonicTimeStamp from "../../utils/monotonic_timestamp"; -import type { IRepresentationEstimatorPlaybackObservation } from "./adaptive_representation_selector"; import type BandwidthEstimator from "./utils/bandwidth_estimator"; import EWMA from "./utils/ewma"; import type { @@ -30,7 +30,7 @@ import type { /** Object describing the current playback conditions. */ type IPlaybackConditionsInfo = Pick< - IRepresentationEstimatorPlaybackObservation, + IAdaptationStreamPlaybackObservation, "bufferGap" | "position" | "speed" | "duration" >; diff --git a/src/core/cmcd/cmcd_data_builder.ts b/src/core/cmcd/cmcd_data_builder.ts index ffad5efcc5..1ca45a5b0d 100644 --- a/src/core/cmcd/cmcd_data_builder.ts +++ b/src/core/cmcd/cmcd_data_builder.ts @@ -8,13 +8,11 @@ import type { } from "../../manifest"; import type { IReadOnlyPlaybackObserver, - IRebufferingStatus, - ObservationPosition, + ICorePlaybackObservation, } from "../../playback_observer"; import type { ICmcdOptions, ICmcdPayload, ITrackType } from "../../public_types"; import createUuid from "../../utils/create_uuid"; import isNullOrUndefined from "../../utils/is_null_or_undefined"; -import type { IRange } from "../../utils/ranges"; import TaskCanceller from "../../utils/task_canceller"; import { getRelativeUrl } from "../../utils/url-utils"; @@ -59,34 +57,6 @@ export interface ICmcdSegmentInfo { nextSegment: ISegment | null | undefined; } -/** - * Media playback observation's properties the `CmcdDataBuilder` wants to have - * access to. - */ -export interface ICmcdDataBuilderPlaybackObservation { - /** - * Ranges of buffered data per type of media. - * `null` if no buffer exists for that type of media. - */ - buffered: Record; - /** - * Information on the current media position in seconds at the time of the - * Observation. - */ - position: ObservationPosition; - /** Target playback rate at which we want to play the content. */ - speed: number; - /** - * Describes when the player is "rebuffering" and what event started that - * status. - * "Rebuffering" is a status where the player has not enough buffer ahead to - * play reliably. - * The RxPlayer should pause playback when a playback observation indicates the - * rebuffering status. - */ - rebuffering: IRebufferingStatus | null; -} - /** * Class allowing to easily obtain "Common Media Client Data" (CMCD) properties * that may be relied on while performing HTTP(S) requests on a CDN. @@ -98,7 +68,7 @@ export default class CmcdDataBuilder { private _contentId: string; private _typePreference: TypePreference; private _lastThroughput: Partial>; - private _playbackObserver: IReadOnlyPlaybackObserver | null; + private _playbackObserver: IReadOnlyPlaybackObserver | null; private _bufferStarvationToggle: boolean; private _canceller: TaskCanceller | null; @@ -131,7 +101,7 @@ export default class CmcdDataBuilder { * @param {Object} playbackObserver */ public startMonitoringPlayback( - playbackObserver: IReadOnlyPlaybackObserver, + playbackObserver: IReadOnlyPlaybackObserver, ): void { this._canceller?.cancel(); this._canceller = new TaskCanceller(); diff --git a/src/core/cmcd/index.ts b/src/core/cmcd/index.ts index fc4f770e64..d8146c54ca 100644 --- a/src/core/cmcd/index.ts +++ b/src/core/cmcd/index.ts @@ -1,7 +1,4 @@ import CmcdDataBuilder from "./cmcd_data_builder"; -export type { - ICmcdSegmentInfo, - ICmcdDataBuilderPlaybackObservation, -} from "./cmcd_data_builder"; +export type { ICmcdSegmentInfo } from "./cmcd_data_builder"; export default CmcdDataBuilder; diff --git a/src/core/main/worker/worker_main.ts b/src/core/main/worker/worker_main.ts index 523d778fba..86466703b9 100644 --- a/src/core/main/worker/worker_main.ts +++ b/src/core/main/worker/worker_main.ts @@ -13,7 +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 { IWorkerPlaybackObservation } from "../../../playback_observer/worker_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"; @@ -79,7 +79,7 @@ export default function initializeWorkerMain() { /** * When set, emit playback observation made on the main thread. */ - let playbackObservationRef: SharedReference | null = null; + let playbackObservationRef: SharedReference | null = null; globalScope.onmessageerror = (_msg: MessageEvent) => { log.error("MTCI: Error when receiving message from main thread."); @@ -140,7 +140,7 @@ export default function initializeWorkerMain() { const currentCanceller = new TaskCanceller(); const currentContentObservationRef = - new SharedReference( + new SharedReference( objectAssign(msg.value.initialObservation, { position: new ObservationPosition(...msg.value.initialObservation.position), }), @@ -484,7 +484,7 @@ interface IBufferingInitializationInformation { function loadOrReloadPreparedContent( val: IBufferingInitializationInformation, contentPreparer: ContentPreparer, - playbackObservationRef: IReadOnlySharedReference, + playbackObservationRef: IReadOnlySharedReference, parentCancelSignal: CancellationSignal, ) { const currentLoadCanceller = new TaskCanceller(); diff --git a/src/core/stream/adaptation/get_representations_switch_strategy.ts b/src/core/stream/adaptation/get_representations_switch_strategy.ts index f57fdf9069..4337b462a6 100644 --- a/src/core/stream/adaptation/get_representations_switch_strategy.ts +++ b/src/core/stream/adaptation/get_representations_switch_strategy.ts @@ -16,7 +16,10 @@ import config from "../../../config"; import type { IAdaptation, IPeriod } from "../../../manifest"; -import type { IReadOnlyPlaybackObserver } from "../../../playback_observer"; +import type { + IReadOnlyPlaybackObserver, + IAdaptationStreamPlaybackObservation, +} from "../../../playback_observer"; import arrayIncludes from "../../../utils/array_includes"; import type { IRange } from "../../../utils/ranges"; import { excludeFromRanges, insertInto } from "../../../utils/ranges"; @@ -26,17 +29,14 @@ import { getLastSegmentBeforePeriod, SegmentSinkOperation, } from "../../segment_sinks"; -import type { - IRepresentationsChoice, - IRepresentationStreamPlaybackObservation, -} from "../representation"; +import type { IRepresentationsChoice } from "../representation"; export default function getRepresentationsSwitchingStrategy( period: IPeriod, adaptation: IAdaptation, settings: IRepresentationsChoice, segmentSink: SegmentSink, - playbackObserver: IReadOnlyPlaybackObserver, + playbackObserver: IReadOnlyPlaybackObserver, ): IRepresentationSwitchStrategy { if (settings.switchingMode === "lazy") { return { type: "continue", value: undefined }; diff --git a/src/core/stream/adaptation/types.ts b/src/core/stream/adaptation/types.ts index 862466a416..5a36efc3ca 100644 --- a/src/core/stream/adaptation/types.ts +++ b/src/core/stream/adaptation/types.ts @@ -1,5 +1,8 @@ import type { IManifest, IAdaptation, IPeriod, IRepresentation } from "../../../manifest"; -import type { IReadOnlyPlaybackObserver } from "../../../playback_observer"; +import type { + IAdaptationStreamPlaybackObservation, + IReadOnlyPlaybackObserver, +} from "../../../playback_observer"; import type { IAudioTrackSwitchingMode, IVideoTrackSwitchingMode, @@ -11,7 +14,6 @@ import type { IBufferType, SegmentSink } from "../../segment_sinks"; import type { IRepresentationsChoice, IRepresentationStreamCallbacks, - IRepresentationStreamPlaybackObservation, } from "../representation"; /** Callbacks called by the `AdaptationStream` on various events. */ @@ -110,20 +112,6 @@ export interface INeedsBufferFlushPayload { relativePosHasBeenDefaulted: boolean; } -/** Regular playback information needed by the AdaptationStream. */ -export interface IAdaptationStreamPlaybackObservation - extends IRepresentationStreamPlaybackObservation { - /** - * For the current SegmentSink, difference in seconds between the next position - * where no segment data is available and the current position. - */ - bufferGap: number; - /** `duration` property of the HTMLMediaElement on which the content plays. */ - duration: number; - /** Theoretical maximum position on the content that can currently be played. */ - maximumPosition: number; -} - /** Arguments given when creating a new `AdaptationStream`. */ export interface IAdaptationStreamArguments { /** Regularly emit playback conditions. */ diff --git a/src/core/stream/period/period_stream.ts b/src/core/stream/period/period_stream.ts index 531c1813ec..71ae18363c 100644 --- a/src/core/stream/period/period_stream.ts +++ b/src/core/stream/period/period_stream.ts @@ -19,7 +19,10 @@ import { formatError, MediaError } from "../../../errors"; import log from "../../../log"; import type { IAdaptation, IPeriod } from "../../../manifest"; import { toTaggedTrack } from "../../../manifest"; -import type { IReadOnlyPlaybackObserver } from "../../../playback_observer"; +import type { + IReadOnlyPlaybackObserver, + IAdaptationStreamPlaybackObservation, +} from "../../../playback_observer"; import type { ITrackType } from "../../../public_types"; import arrayFind from "../../../utils/array_find"; import objectAssign from "../../../utils/object_assign"; @@ -31,11 +34,7 @@ import type { CancellationSignal } from "../../../utils/task_canceller"; import TaskCanceller, { CancellationError } from "../../../utils/task_canceller"; import type { IBufferType, SegmentSink } from "../../segment_sinks"; import SegmentSinksStore from "../../segment_sinks"; -import type { - IAdaptationChoice, - IAdaptationStreamCallbacks, - IAdaptationStreamPlaybackObservation, -} from "../adaptation"; +import type { IAdaptationChoice, IAdaptationStreamCallbacks } from "../adaptation"; import AdaptationStream from "../adaptation"; import type { IRepresentationsChoice } from "../representation"; import type { diff --git a/src/core/stream/representation/types.ts b/src/core/stream/representation/types.ts index 4c37c5cbfc..ea88dbef2e 100644 --- a/src/core/stream/representation/types.ts +++ b/src/core/stream/representation/types.ts @@ -8,8 +8,8 @@ import type { } from "../../../manifest"; import type { IEMSG } from "../../../parsers/containers/isobmff"; import type { - ObservationPosition, IReadOnlyPlaybackObserver, + IAdaptationStreamPlaybackObservation, } from "../../../playback_observer"; import type { IAudioRepresentationsSwitchingMode, @@ -178,22 +178,6 @@ export interface IBufferDiscontinuity { end: number | null; } -/** Object that should be emitted by the given `IReadOnlyPlaybackObserver`. */ -export interface IRepresentationStreamPlaybackObservation { - /** - * Information on the current media position in seconds at the time of a - * Playback Observation. - */ - position: ObservationPosition; - /** - * Information on whether the media element was paused at the time of the - * Observation. - */ - paused: IPausedPlaybackObservation; - /** Last "playback rate" asked by the user. */ - speed: number; -} - /** Pause-related information linked to an emitted Playback observation. */ export interface IPausedPlaybackObservation { /** @@ -269,7 +253,7 @@ export interface IRepresentationStreamArguments { */ terminate: IReadOnlySharedReference; /** Periodically emits the current playback conditions. */ - playbackObserver: IReadOnlyPlaybackObserver; + playbackObserver: IReadOnlyPlaybackObserver; /** Supplementary arguments which configure the RepresentationStream's behavior. */ options: IRepresentationStreamOptions; } diff --git a/src/core/stream/representation/utils/append_segment_to_buffer.ts b/src/core/stream/representation/utils/append_segment_to_buffer.ts index d7d57fb621..c1ed41a605 100644 --- a/src/core/stream/representation/utils/append_segment_to_buffer.ts +++ b/src/core/stream/representation/utils/append_segment_to_buffer.ts @@ -21,7 +21,10 @@ import { MediaError, SourceBufferError } from "../../../../errors"; import log from "../../../../log"; import { toTaggedTrack } from "../../../../manifest"; -import type { IReadOnlyPlaybackObserver } from "../../../../playback_observer"; +import type { + IReadOnlyPlaybackObserver, + IAdaptationStreamPlaybackObservation, +} from "../../../../playback_observer"; import type { IRange } from "../../../../utils/ranges"; import type { IReadOnlySharedReference } from "../../../../utils/reference"; import sleep from "../../../../utils/sleep"; @@ -32,7 +35,6 @@ import type { IPushChunkInfos, SegmentSink, } from "../../../segment_sinks"; -import type { IRepresentationStreamPlaybackObservation } from "../types"; /** * Append a segment to the given segmentSink. @@ -46,7 +48,7 @@ import type { IRepresentationStreamPlaybackObservation } from "../types"; * @returns {Promise} */ export default async function appendSegmentToBuffer( - playbackObserver: IReadOnlyPlaybackObserver, + playbackObserver: IReadOnlyPlaybackObserver, segmentSink: SegmentSink, dataInfos: IPushChunkInfos & { inventoryInfos: IInsertedChunkInfos }, bufferGoal: IReadOnlySharedReference, diff --git a/src/core/stream/representation/utils/get_buffer_status.ts b/src/core/stream/representation/utils/get_buffer_status.ts index 419324cab1..2d3bce886f 100644 --- a/src/core/stream/representation/utils/get_buffer_status.ts +++ b/src/core/stream/representation/utils/get_buffer_status.ts @@ -20,18 +20,17 @@ import type { IPeriod, IRepresentation, } from "../../../../manifest"; -import type { IReadOnlyPlaybackObserver } from "../../../../playback_observer"; +import type { + IReadOnlyPlaybackObserver, + IAdaptationStreamPlaybackObservation, +} from "../../../../playback_observer"; import isNullOrUndefined from "../../../../utils/is_null_or_undefined"; import type { ISignalCompleteSegmentOperation, SegmentSink, } from "../../../segment_sinks"; import SegmentSinksStore, { SegmentSinkOperation } from "../../../segment_sinks"; -import type { - IBufferDiscontinuity, - IRepresentationStreamPlaybackObservation, - IQueuedSegment, -} from "../types"; +import type { IBufferDiscontinuity, IQueuedSegment } from "../types"; import checkForDiscontinuity from "./check_for_discontinuity"; import getNeededSegments from "./get_needed_segments"; import getSegmentPriority from "./get_segment_priority"; @@ -92,7 +91,7 @@ export default function getBufferStatus( representation: IRepresentation; }, initialWantedTime: number, - playbackObserver: IReadOnlyPlaybackObserver, + playbackObserver: IReadOnlyPlaybackObserver, fastSwitchThreshold: number | undefined, bufferGoal: number, maxBufferSize: number, diff --git a/src/core/stream/representation/utils/push_init_segment.ts b/src/core/stream/representation/utils/push_init_segment.ts index e051310e56..1f89ff6fa8 100644 --- a/src/core/stream/representation/utils/push_init_segment.ts +++ b/src/core/stream/representation/utils/push_init_segment.ts @@ -21,15 +21,15 @@ import type { IPeriod, IRepresentation, } from "../../../../manifest"; -import type { IReadOnlyPlaybackObserver } from "../../../../playback_observer"; +import type { + IReadOnlyPlaybackObserver, + IAdaptationStreamPlaybackObservation, +} from "../../../../playback_observer"; import objectAssign from "../../../../utils/object_assign"; import type { IReadOnlySharedReference } from "../../../../utils/reference"; import type { CancellationSignal } from "../../../../utils/task_canceller"; import type { IPushedChunkData, SegmentSink } from "../../../segment_sinks"; -import type { - IRepresentationStreamPlaybackObservation, - IStreamEventAddedSegmentPayload, -} from "../types"; +import type { IStreamEventAddedSegmentPayload } from "../types"; import appendSegmentToBuffer from "./append_segment_to_buffer"; /** @@ -47,7 +47,7 @@ export default async function pushInitSegment( segmentSink, bufferGoal, }: { - playbackObserver: IReadOnlyPlaybackObserver; + playbackObserver: IReadOnlyPlaybackObserver; content: { adaptation: IAdaptation; manifest: IManifest; diff --git a/src/core/stream/representation/utils/push_media_segment.ts b/src/core/stream/representation/utils/push_media_segment.ts index 65eff2a237..b4f34e65d3 100644 --- a/src/core/stream/representation/utils/push_media_segment.ts +++ b/src/core/stream/representation/utils/push_media_segment.ts @@ -22,16 +22,16 @@ import type { IPeriod, IRepresentation, } from "../../../../manifest"; -import type { IReadOnlyPlaybackObserver } from "../../../../playback_observer"; +import type { + IReadOnlyPlaybackObserver, + IAdaptationStreamPlaybackObservation, +} from "../../../../playback_observer"; import type { ISegmentParserParsedMediaChunk } from "../../../../transports"; import objectAssign from "../../../../utils/object_assign"; import type { IReadOnlySharedReference } from "../../../../utils/reference"; import type { CancellationSignal } from "../../../../utils/task_canceller"; import type { SegmentSink } from "../../../segment_sinks"; -import type { - IRepresentationStreamPlaybackObservation, - IStreamEventAddedSegmentPayload, -} from "../types"; +import type { IStreamEventAddedSegmentPayload } from "../types"; import appendSegmentToBuffer from "./append_segment_to_buffer"; /** @@ -50,7 +50,7 @@ export default async function pushMediaSegment( segment, segmentSink, }: { - playbackObserver: IReadOnlyPlaybackObserver; + playbackObserver: IReadOnlyPlaybackObserver; content: { adaptation: IAdaptation; manifest: IManifest; diff --git a/src/main_thread/init/multi_thread_content_initializer.ts b/src/main_thread/init/multi_thread_content_initializer.ts index 107fa1cb14..53374fd49c 100644 --- a/src/main_thread/init/multi_thread_content_initializer.ts +++ b/src/main_thread/init/multi_thread_content_initializer.ts @@ -32,8 +32,8 @@ import { MainThreadMessageType, WorkerMessageType } from "../../multithread_type import type { IReadOnlyPlaybackObserver, IMediaElementPlaybackObserver, + ICorePlaybackObservation, } from "../../playback_observer"; -import type { IWorkerPlaybackObservation } from "../../playback_observer/worker_playback_observer"; import type { ICmcdOptions, IInitialManifest, @@ -1472,7 +1472,7 @@ export default class MultiThreadContentInitializer extends ContentInitializer { playbackObserver: IMediaElementPlaybackObserver; }, cancelSignal: CancellationSignal, - ): IReadOnlyPlaybackObserver | null { + ): IReadOnlyPlaybackObserver | null { if (cancelSignal.isCancelled()) { return null; } 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/index.ts b/src/playback_observer/index.ts index 8cedce3253..d8ffaef1ca 100644 --- a/src/playback_observer/index.ts +++ b/src/playback_observer/index.ts @@ -7,6 +7,9 @@ export type { IRebufferingStatus, IPlaybackObservation, IReadOnlyPlaybackObserver, + ICorePlaybackObservation, + IPeriodStreamPlaybackObservation, + IAdaptationStreamPlaybackObservation, } from "./types"; export type IMediaElementPlaybackObserver = MediaElementPlaybackObserver; export { ObservationPosition }; diff --git a/src/playback_observer/types.ts b/src/playback_observer/types.ts index 554c93b1cb..61cda0e2e8 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,87 @@ export interface IReadOnlyPlaybackObserver { ) => IReadOnlySharedReference, ): IReadOnlyPlaybackObserver; } + +export interface ICorePlaybackObservation extends IPeriodStreamPlaybackObservation { + rebuffering: IRebufferingStatus | null; + freezing: IFreezingStatus | null; + bufferGap: number | undefined; +} + +/** Regular playback information needed by the AdaptationStream. */ +export interface IAdaptationStreamPlaybackObservation { + /** + * 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; + /** + * For the current SegmentSink, difference in seconds between the next position + * where no segment data is available and the current position. + */ + bufferGap: number; + /** + * Ranges of buffered data for the adaptation media type. + * `null` if no buffer exists for the media type. + */ + buffered: IRange[] | null; +} + +export interface IPeriodStreamPlaybackObservation { + /** + * 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; +} + +/** 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 6244d2eabf..61e722fdb9 100644 --- a/src/playback_observer/worker_playback_observer.ts +++ b/src/playback_observer/worker_playback_observer.ts @@ -1,76 +1,20 @@ import type { IUpdatePlaybackRateWorkerMessage } from "../multithread_types"; import { WorkerMessageType } from "../multithread_types"; -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 { - IFreezingStatus, - IReadOnlyPlaybackObserver, - IRebufferingStatus, -} from "./types"; +import type { ICorePlaybackObservation, IReadOnlyPlaybackObserver } from "./types"; import generateReadOnlyObserver from "./utils/generate_read_only_observer"; -import type ObservationPosition from "./utils/observation_position"; - -export interface IWorkerPlaybackObservation { - /** - * 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; -} export default class WorkerPlaybackObserver - implements IReadOnlyPlaybackObserver + implements IReadOnlyPlaybackObserver { - private _src: IReadOnlySharedReference; + private _src: IReadOnlySharedReference; private _cancelSignal: CancellationSignal; private _messageSender: (msg: IUpdatePlaybackRateWorkerMessage) => void; private _contentId: string; constructor( - src: IReadOnlySharedReference, + src: IReadOnlySharedReference, contentId: string, sendMessage: (msg: IUpdatePlaybackRateWorkerMessage) => void, cancellationSignal: CancellationSignal, @@ -93,7 +37,7 @@ export default class WorkerPlaybackObserver return undefined; } - public getReference(): IReadOnlySharedReference { + public getReference(): IReadOnlySharedReference { return this._src; } @@ -110,7 +54,7 @@ export default class WorkerPlaybackObserver } public listen( - cb: (observation: IWorkerPlaybackObservation, stopListening: () => void) => void, + cb: (observation: ICorePlaybackObservation, stopListening: () => void) => void, options?: { includeLastObservation?: boolean | undefined; clearSignal?: CancellationSignal | undefined; @@ -131,7 +75,7 @@ export default class WorkerPlaybackObserver public deriveReadOnlyObserver( transform: ( - observationRef: IReadOnlySharedReference, + observationRef: IReadOnlySharedReference, cancellationSignal: CancellationSignal, ) => IReadOnlySharedReference, ): IReadOnlyPlaybackObserver {