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 4 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
35 changes: 5 additions & 30 deletions src/core/adaptive/adaptive_representation_selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import type {
IRepresentation,
ISegment,
} from "../../manifest";
import type {
ObservationPosition,
IReadOnlyPlaybackObserver,
} from "../../playback_observer";
import type { IReadOnlyPlaybackObserver } from "../../playback_observer";
import isNullOrUndefined from "../../utils/is_null_or_undefined";
import noop from "../../utils/noop";
import type { IRange } from "../../utils/ranges";
Expand All @@ -36,6 +33,7 @@ import SharedReference from "../../utils/reference";
import type { CancellationSignal } from "../../utils/task_canceller";
import TaskCanceller from "../../utils/task_canceller";
import type { IBufferType } from "../segment_sinks";
import type { IAdaptationStreamPlaybackObservation } from "../stream/adaptation";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it weird that the ABR rely on a type defined inside another module it does not care about?

Maybe we should put that type in a more neutral place

import BufferBasedChooser from "./buffer_based_chooser";
import GuessBasedChooser from "./guess_based_chooser";
import NetworkAnalyzer from "./network_analyzer";
Expand Down Expand Up @@ -96,7 +94,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 +634,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 +722,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 +772,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 @@ -20,7 +20,7 @@ import type { IRepresentation } from "../../manifest";
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 { IAdaptationStreamPlaybackObservation } from "../stream/adaptation";
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
40 changes: 4 additions & 36 deletions src/core/cmcd/cmcd_data_builder.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import log from "../../log";
import type { ICorePlaybackObservation } from "../../main_thread/init/utils/create_core_playback_observer";
import type {
IAdaptation,
IManifest,
IPeriod,
IRepresentation,
ISegment,
} from "../../manifest";
import type {
IReadOnlyPlaybackObserver,
IRebufferingStatus,
ObservationPosition,
} from "../../playback_observer";
import type { IReadOnlyPlaybackObserver } 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 +55,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 +66,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 +99,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 @@ -2,6 +2,7 @@ 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,
Expand All @@ -13,7 +14,6 @@ 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 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 @@ -26,17 +26,15 @@ import {
getLastSegmentBeforePeriod,
SegmentSinkOperation,
} from "../../segment_sinks";
import type {
IRepresentationsChoice,
IRepresentationStreamPlaybackObservation,
} from "../representation";
import type { IRepresentationsChoice } from "../representation";
import type { IAdaptationStreamPlaybackObservation } from "./types";

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
14 changes: 8 additions & 6 deletions src/core/stream/adaptation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import type {
IAudioTrackSwitchingMode,
IVideoTrackSwitchingMode,
} from "../../../public_types";
import type { IRange } from "../../../utils/ranges";
import type { IReadOnlySharedReference } from "../../../utils/reference";
import type { IRepresentationEstimator } from "../../adaptive";
import type { SegmentQueueCreator } from "../../fetchers";
import type { IBufferType, SegmentSink } from "../../segment_sinks";
import type { IPeriodStreamPlaybackObservation } from "../period";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me the PeriodStream depends on the AdaptationStream, not the other way around

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that they don't overlap well, IAdaptationStreamPlaybackObservation has bufferGap attribute in addition of the other attributes that as IPeriodStreamPlaybackObservation.
But they both defines the buffered attribute in a different way.

I will just define them as both types with no extends nor Omit

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also use different property names to explicit that difference

import type {
IRepresentationsChoice,
IRepresentationStreamCallbacks,
IRepresentationStreamPlaybackObservation,
} from "../representation";

/** Callbacks called by the `AdaptationStream` on various events. */
Expand Down Expand Up @@ -112,16 +113,17 @@ export interface INeedsBufferFlushPayload {

/** Regular playback information needed by the AdaptationStream. */
export interface IAdaptationStreamPlaybackObservation
extends IRepresentationStreamPlaybackObservation {
extends Omit<IPeriodStreamPlaybackObservation, "buffered"> {
/**
* 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;
/**
* Ranges of buffered data for the adaptation media type.
* `null` if no buffer exists for the media type.
*/
buffered: IRange[] | null;
}

/** Arguments given when creating a new `AdaptationStream`. */
Expand Down
24 changes: 3 additions & 21 deletions src/core/stream/representation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import type {
IRepresentation,
} from "../../../manifest";
import type { IEMSG } from "../../../parsers/containers/isobmff";
import type {
ObservationPosition,
IReadOnlyPlaybackObserver,
} from "../../../playback_observer";
import type { IReadOnlyPlaybackObserver } from "../../../playback_observer";
import type {
IAudioRepresentationsSwitchingMode,
IPlayerError,
Expand All @@ -20,6 +17,7 @@ import type { IRange } from "../../../utils/ranges";
import type { IReadOnlySharedReference } from "../../../utils/reference";
import type { SegmentQueue } from "../../fetchers";
import type { IBufferType, SegmentSink } from "../../segment_sinks";
import type { IAdaptationStreamPlaybackObservation } from "../adaptation";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote it as a comment but you may have not seen it:

As the AdaptationStream is the one that has a dependency on the RepresentationStream, shouldn't the type be coming from the RepresentationStream to the AdaptationStream and not the reverse?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IAdaptationStreamPlaybackObservation and IRepresentationStreamPlaybackObservation are the same so I deleted the Representation one.
Yeah name is a bit off because of that, should I rename it? Any idea of a name that would fit for both? Or I can duplicate it but I'm not fan of..


/** Callbacks called by the `RepresentationStream` on various events. */
export interface IRepresentationStreamCallbacks {
Expand Down Expand Up @@ -178,22 +176,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 +251,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 @@ -32,7 +32,7 @@ import type {
IPushChunkInfos,
SegmentSink,
} from "../../../segment_sinks";
import type { IRepresentationStreamPlaybackObservation } from "../types";
import type { IAdaptationStreamPlaybackObservation } from "../../adaptation";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same


/**
* Append a segment to the given segmentSink.
Expand All @@ -46,7 +46,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
9 changes: 3 additions & 6 deletions src/core/stream/representation/utils/get_buffer_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ import type {
SegmentSink,
} from "../../../segment_sinks";
import SegmentSinksStore, { SegmentSinkOperation } from "../../../segment_sinks";
import type {
IBufferDiscontinuity,
IRepresentationStreamPlaybackObservation,
IQueuedSegment,
} from "../types";
import type { IAdaptationStreamPlaybackObservation } from "../../adaptation";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

import type { IBufferDiscontinuity, IQueuedSegment } from "../types";
import checkForDiscontinuity from "./check_for_discontinuity";
import getNeededSegments from "./get_needed_segments";
import getSegmentPriority from "./get_segment_priority";
Expand Down Expand Up @@ -92,7 +89,7 @@ export default function getBufferStatus(
representation: IRepresentation;
},
initialWantedTime: number,
playbackObserver: IReadOnlyPlaybackObserver<IRepresentationStreamPlaybackObservation>,
playbackObserver: IReadOnlyPlaybackObserver<IAdaptationStreamPlaybackObservation>,
fastSwitchThreshold: number | undefined,
bufferGoal: number,
maxBufferSize: number,
Expand Down
Loading
Loading