Skip to content

Commit

Permalink
Add Representation.prototype.isPlayable method
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Nov 15, 2024
1 parent 4ce9eb6 commit c3e72d3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/core/cmcd/cmcd_data_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {
IRepresentation,
ISegment,
} from "../../manifest";
import { isRepresentationPlayable } from "../../manifest";
import type {
IReadOnlyPlaybackObserver,
IRebufferingStatus,
Expand Down Expand Up @@ -334,7 +333,7 @@ export default class CmcdDataBuilder {
props.st = content.manifest.isDynamic ? "l" : "v";
props.tb = content.adaptation.representations.reduce(
(acc: number | undefined, representation: IRepresentation) => {
if (isRepresentationPlayable(representation) !== true) {
if (representation.isPlayable() !== true) {
return acc;
}
if (acc === undefined) {
Expand Down
3 changes: 1 addition & 2 deletions src/core/stream/adaptation/adaptation_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import config from "../../../config";
import { formatError } from "../../../errors";
import log from "../../../log";
import type { IRepresentation } from "../../../manifest";
import { isRepresentationPlayable } from "../../../manifest";
import arrayIncludes from "../../../utils/array_includes";
import { assertUnreachable } from "../../../utils/assert";
import cancellableSleep from "../../../utils/cancellable_sleep";
Expand Down Expand Up @@ -96,7 +95,7 @@ export default function AdaptationStream(

const initialRepIds = content.representations.getValue().representationIds;
const initialRepresentations = content.adaptation.representations.filter(
(r) => arrayIncludes(initialRepIds, r.id) && isRepresentationPlayable(r) !== false,
(r) => arrayIncludes(initialRepIds, r.id) && r.isPlayable() !== false,
);

/** Emit the list of Representation for the adaptive logic. */
Expand Down
4 changes: 2 additions & 2 deletions src/core/stream/period/period_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import config from "../../../config";
import { formatError, MediaError } from "../../../errors";
import log from "../../../log";
import type { IAdaptation, IPeriod } from "../../../manifest";
import { isRepresentationPlayable, toTaggedTrack } from "../../../manifest";
import { toTaggedTrack } from "../../../manifest";
import type { IReadOnlyPlaybackObserver } from "../../../playback_observer";
import type { ITrackType } from "../../../public_types";
import arrayFind from "../../../utils/array_find";
Expand Down Expand Up @@ -473,7 +473,7 @@ function createOrReuseSegmentSink(
*/
function getFirstDeclaredMimeType(adaptation: IAdaptation): string {
const representations = adaptation.representations.filter(
(r) => isRepresentationPlayable(r) !== false,
(r) => r.isPlayable() !== false,
);
if (representations.length === 0) {
const noRepErr = new MediaError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import config from "../../../../config";
import type { IAdaptation, IPeriod } from "../../../../manifest";
import { isRepresentationPlayable } from "../../../../manifest";
import type { IReadOnlyPlaybackObserver } from "../../../../playback_observer";
import areCodecsCompatible from "../../../../utils/are_codecs_compatible";
import type { IRange } from "../../../../utils/ranges";
Expand Down Expand Up @@ -190,7 +189,7 @@ export default function getAdaptationSwitchStrategy(
function hasCompatibleCodec(adaptation: IAdaptation, segmentSinkCodec: string): boolean {
return adaptation.representations.some(
(rep) =>
isRepresentationPlayable(rep) === true &&
rep.isPlayable() === true &&
areCodecsCompatible(rep.getMimeTypeString(), segmentSinkCodec),
);
}
19 changes: 18 additions & 1 deletion src/manifest/classes/representation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import log from "../../log";
import type { IRepresentationMetadata } from "../../manifest";
import { isRepresentationPlayable, type IRepresentationMetadata } from "../../manifest";
import type {
ICdnMetadata,
IContentProtections,
Expand Down Expand Up @@ -429,6 +429,23 @@ class Representation implements IRepresentationMetadata {
return true;
}

/**
* Returns `true` if the `Representation` has a high chance of being playable on
* the current device (its codec seems supported and we don't consider it to be
* un-decipherable).
*
* Returns `false` if the `Representation` has a high chance of being unplayable
* on the current device (its codec seems unsupported and/or we consider it to
* be un-decipherable).
*
* Returns `undefined` if we don't know as the codec has not been checked yet.
*
* @returns {boolean|undefined}
*/
public isPlayable(): boolean | undefined {
return isRepresentationPlayable(this);
}

/**
* Format the current `Representation`'s properties into a
* `IRepresentationMetadata` format which can better be communicated through
Expand Down

0 comments on commit c3e72d3

Please sign in to comment.