Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] types: simplify types for PlaybackObserver #1589

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 4 additions & 27 deletions src/core/adaptive/adaptive_representation_selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -96,7 +96,7 @@ export default function createAdaptiveRepresentationSelector(
context: { manifest: IManifest; period: IPeriod; adaptation: IAdaptation },
currentRepresentation: IReadOnlySharedReference<IRepresentation | null>,
representations: IReadOnlySharedReference<IRepresentation[]>,
playbackObserver: IReadOnlyPlaybackObserver<IRepresentationEstimatorPlaybackObservation>,
playbackObserver: IReadOnlyPlaybackObserver<IAdaptationStreamPlaybackObservation>,
stopAllEstimates: CancellationSignal,
): IRepresentationEstimatorResponse {
const { type } = context.adaptation;
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -747,7 +724,7 @@ export interface IRepresentationEstimatorArguments {
/** Class allowing to estimate the current network bandwidth. */
bandwidthEstimator: BandwidthEstimator;
/** Emit regular playback information. */
playbackObserver: IReadOnlyPlaybackObserver<IRepresentationEstimatorPlaybackObservation>;
playbackObserver: IReadOnlyPlaybackObserver<IAdaptationStreamPlaybackObservation>;
/**
* The Representation currently loaded.
* `null` if no Representation is currently loaded.
Expand Down Expand Up @@ -797,7 +774,7 @@ export type IRepresentationEstimator = (
/** Reference emitting the list of available Representations to choose from. */
representations: IReadOnlySharedReference<IRepresentation[]>,
/** Regularly emits playback conditions */
playbackObserver: IReadOnlyPlaybackObserver<IRepresentationEstimatorPlaybackObservation>,
playbackObserver: IReadOnlyPlaybackObserver<IAdaptationStreamPlaybackObservation>,
/**
* After this `CancellationSignal` emits, resources will be disposed and
* estimates will stop to be emitted.
Expand Down
2 changes: 0 additions & 2 deletions src/core/adaptive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {
IMetricsCallbackPayload,
IRepresentationEstimator,
IRepresentationEstimatorCallbacks,
IRepresentationEstimatorPlaybackObservation,
IRepresentationEstimatorThrottlers as IABRThrottlers,
IRequestBeginCallbackPayload,
IRequestEndCallbackPayload,
Expand All @@ -39,7 +38,6 @@ export type {
IABREstimate,
IMetricsCallbackPayload,
IRepresentationEstimatorCallbacks,
IRepresentationEstimatorPlaybackObservation,
IRequestBeginCallbackPayload,
IRequestProgressCallbackPayload,
IRequestEndCallbackPayload,
Expand Down
4 changes: 2 additions & 2 deletions src/core/adaptive/network_analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,7 +30,7 @@ import type {

/** Object describing the current playback conditions. */
type IPlaybackConditionsInfo = Pick<
IRepresentationEstimatorPlaybackObservation,
IAdaptationStreamPlaybackObservation,
"bufferGap" | "position" | "speed" | "duration"
>;

Expand Down
36 changes: 3 additions & 33 deletions src/core/cmcd/cmcd_data_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<ITrackType, IRange[] | null>;
/**
* 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.
Expand All @@ -98,7 +68,7 @@ export default class CmcdDataBuilder {
private _contentId: string;
private _typePreference: TypePreference;
private _lastThroughput: Partial<Record<ITrackType, number | undefined>>;
private _playbackObserver: IReadOnlyPlaybackObserver<ICmcdDataBuilderPlaybackObservation> | null;
private _playbackObserver: IReadOnlyPlaybackObserver<ICorePlaybackObservation> | null;
private _bufferStarvationToggle: boolean;
private _canceller: TaskCanceller | null;

Expand Down Expand Up @@ -131,7 +101,7 @@ export default class CmcdDataBuilder {
* @param {Object} playbackObserver
*/
public startMonitoringPlayback(
playbackObserver: IReadOnlyPlaybackObserver<ICmcdDataBuilderPlaybackObservation>,
playbackObserver: IReadOnlyPlaybackObserver<ICorePlaybackObservation>,
): void {
this._canceller?.cancel();
this._canceller = new TaskCanceller();
Expand Down
5 changes: 1 addition & 4 deletions src/core/cmcd/index.ts
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 4 additions & 4 deletions src/core/main/worker/worker_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -79,7 +79,7 @@ export default function initializeWorkerMain() {
/**
* When set, emit playback observation made on the main thread.
*/
let playbackObservationRef: SharedReference<IWorkerPlaybackObservation> | null = null;
let playbackObservationRef: SharedReference<ICorePlaybackObservation> | null = null;

globalScope.onmessageerror = (_msg: MessageEvent) => {
log.error("MTCI: Error when receiving message from main thread.");
Expand Down Expand Up @@ -140,7 +140,7 @@ export default function initializeWorkerMain() {

const currentCanceller = new TaskCanceller();
const currentContentObservationRef =
new SharedReference<IWorkerPlaybackObservation>(
new SharedReference<ICorePlaybackObservation>(
objectAssign(msg.value.initialObservation, {
position: new ObservationPosition(...msg.value.initialObservation.position),
}),
Expand Down Expand Up @@ -484,7 +484,7 @@ interface IBufferingInitializationInformation {
function loadOrReloadPreparedContent(
val: IBufferingInitializationInformation,
contentPreparer: ContentPreparer,
playbackObservationRef: IReadOnlySharedReference<IWorkerPlaybackObservation>,
playbackObservationRef: IReadOnlySharedReference<ICorePlaybackObservation>,
parentCancelSignal: CancellationSignal,
) {
const currentLoadCanceller = new TaskCanceller();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<IRepresentationStreamPlaybackObservation>,
playbackObserver: IReadOnlyPlaybackObserver<IAdaptationStreamPlaybackObservation>,
): IRepresentationSwitchStrategy {
if (settings.switchingMode === "lazy") {
return { type: "continue", value: undefined };
Expand Down
20 changes: 4 additions & 16 deletions src/core/stream/adaptation/types.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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. */
Expand Down Expand Up @@ -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. */
Expand Down
11 changes: 5 additions & 6 deletions src/core/stream/period/period_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {
Expand Down
20 changes: 2 additions & 18 deletions src/core/stream/representation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -269,7 +253,7 @@ export interface IRepresentationStreamArguments<TSegmentDataType> {
*/
terminate: IReadOnlySharedReference<null | ITerminationOrder>;
/** Periodically emits the current playback conditions. */
playbackObserver: IReadOnlyPlaybackObserver<IRepresentationStreamPlaybackObservation>;
playbackObserver: IReadOnlyPlaybackObserver<IAdaptationStreamPlaybackObservation>;
/** Supplementary arguments which configure the RepresentationStream's behavior. */
options: IRepresentationStreamOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -32,7 +35,6 @@ import type {
IPushChunkInfos,
SegmentSink,
} from "../../../segment_sinks";
import type { IRepresentationStreamPlaybackObservation } from "../types";

/**
* Append a segment to the given segmentSink.
Expand All @@ -46,7 +48,7 @@ import type { IRepresentationStreamPlaybackObservation } from "../types";
* @returns {Promise}
*/
export default async function appendSegmentToBuffer<T>(
playbackObserver: IReadOnlyPlaybackObserver<IRepresentationStreamPlaybackObservation>,
playbackObserver: IReadOnlyPlaybackObserver<IAdaptationStreamPlaybackObservation>,
segmentSink: SegmentSink,
dataInfos: IPushChunkInfos<T> & { inventoryInfos: IInsertedChunkInfos },
bufferGoal: IReadOnlySharedReference<number>,
Expand Down
Loading
Loading