Skip to content

Commit

Permalink
move ICorePlaybackObservation in src/playbackObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent-Bouisset committed Nov 4, 2024
1 parent 6791b75 commit f60ae8c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/core/cmcd/cmcd_data_builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import log from "../../log";
import type { ICorePlaybackObservation } from "../../main_thread/init/utils/create_core_playback_observer";
import type {
IAdaptation,
IManifest,
Expand All @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/core/main/worker/worker_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion src/main_thread/init/multi_thread_content_initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {
IReadOnlyPlaybackObserver,
IMediaElementPlaybackObserver,
} from "../../playback_observer";
import type { ICorePlaybackObservation } from "../../playback_observer/types";
import type {
ICmcdOptions,
IInitialManifest,
Expand All @@ -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";
Expand Down
36 changes: 1 addition & 35 deletions src/main_thread/init/utils/create_core_playback_observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@
*/

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";
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";
Expand All @@ -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<ITrackType, IRange[] | null>;
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
Expand Down
51 changes: 51 additions & 0 deletions src/playback_observer/types.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -236,3 +238,52 @@ export interface IReadOnlyPlaybackObserver<TObservationType> {
) => IReadOnlySharedReference<TDest>,
): IReadOnlyPlaybackObserver<TDest>;
}

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<ITrackType, IRange[] | null>;
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;
}

0 comments on commit f60ae8c

Please sign in to comment.