Skip to content

Commit

Permalink
Feature / Parse labels for adaptation sets (#1105)
Browse files Browse the repository at this point in the history
* mob sessioe

* Mob session

* Some cleanups

* Return labels for available videotracks and available text tracks

* Return labels for chosen tracks

* Correct types

* Review fixes: Simplified label parsing

* Reverted changes in dist/rx-player.js

* Revert changes in dist/rx-player.js

Co-authored-by: stephanterning <[email protected]>
  • Loading branch information
2 people authored and peaBerberian committed Jun 3, 2022
1 parent 52d40f0 commit c63bbd4
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@
/tools

/src/parsers/manifest/dash/wasm-parser/target

/.idea
13 changes: 11 additions & 2 deletions src/core/api/track_choice_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ export interface ITMAudioTrack { language : string;
audioDescription : boolean;
dub? : boolean;
id : number|string;
label?: string|undefined;
representations: ITMAudioRepresentation[]; }

/** Text track returned by the TrackChoiceManager. */
export interface ITMTextTrack { language : string;
normalized : string;
closedCaption : boolean;
id : number|string; }
id : number|string;
label?: string|undefined; }

/**
* Definition of a single video Representation as represented by the
Expand All @@ -96,7 +98,8 @@ export interface ITMVideoTrack { id : number|string;
signInterpreted?: boolean;
isTrickModeTrack?: boolean;
trickModeTracks?: ITMVideoTrack[];
representations: ITMVideoRepresentation[]; }
representations: ITMVideoRepresentation[];
label?: string|undefined; }

/** Audio track from a list of audio tracks returned by the TrackChoiceManager. */
export interface ITMAudioTrackListItem
Expand Down Expand Up @@ -684,6 +687,7 @@ export default class TrackChoiceManager {
audioDescription: chosenTrack.isAudioDescription === true,
id: chosenTrack.id,
representations: chosenTrack.representations.map(parseAudioRepresentation),
label: chosenTrack.label,
};
if (chosenTrack.isDub === true) {
audioTrack.dub = true;
Expand Down Expand Up @@ -719,6 +723,7 @@ export default class TrackChoiceManager {
normalized: takeFirstSet<string>(chosenTextAdaptation.normalizedLanguage, ""),
closedCaption: chosenTextAdaptation.isClosedCaption === true,
id: chosenTextAdaptation.id,
label: chosenTextAdaptation.label,
};
}

Expand Down Expand Up @@ -763,6 +768,7 @@ export default class TrackChoiceManager {
const videoTrack: ITMVideoTrack = {
id: currAdaptation.id,
representations: currAdaptation.representations.map(parseVideoRepresentation),
label: currAdaptation.label,
};
if (currAdaptation.isSignInterpreted === true) {
videoTrack.signInterpreted = true;
Expand Down Expand Up @@ -805,6 +811,7 @@ export default class TrackChoiceManager {
active: currentId === null ? false :
currentId === adaptation.id,
representations: adaptation.representations.map(parseAudioRepresentation),
label: adaptation.label,
};
if (adaptation.isDub === true) {
formatted.dub = true;
Expand Down Expand Up @@ -841,6 +848,7 @@ export default class TrackChoiceManager {
id: adaptation.id,
active: currentId === null ? false :
currentId === adaptation.id,
label: adaptation.label,
}));
}

Expand Down Expand Up @@ -887,6 +895,7 @@ export default class TrackChoiceManager {
active: currentId === null ? false :
currentId === adaptation.id,
representations: adaptation.representations.map(parseVideoRepresentation),
label: adaptation.label,
};
if (adaptation.isSignInterpreted === true) {
formatted.signInterpreted = true;
Expand Down
6 changes: 6 additions & 0 deletions src/manifest/adaptation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export default class Adaptation {
/** Tells if the track is a trick mode track. */
public isTrickModeTrack? : boolean;

/** Label of the adaptionSet */
public label?: string;

public readonly trickModeTracks? : Adaptation[];

/**
Expand Down Expand Up @@ -138,6 +141,9 @@ export default class Adaptation {
if (parsedAdaptation.isSignInterpreted !== undefined) {
this.isSignInterpreted = parsedAdaptation.isSignInterpreted;
}
if (parsedAdaptation.label !== undefined) {
this.label = parsedAdaptation.label;
}

if (trickModeTracks !== undefined &&
trickModeTracks.length > 0) {
Expand Down
8 changes: 6 additions & 2 deletions src/parsers/manifest/dash/common/parse_adaptation_sets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import isNonEmptyString from "../../../../utils/is_non_empty_string";
import {
IParsedAdaptation,
IParsedAdaptations,
} from "../../types";
} from "../../types";
import {
IAdaptationSetIntermediateRepresentation,
ISegmentTemplateIntermediateRepresentation,
Expand Down Expand Up @@ -266,7 +266,7 @@ export default function parseAdaptationSets(
const adaptation = adaptationsIR[adaptationIdx];
const adaptationChildren = adaptation.children;
const { essentialProperties,
roles } = adaptationChildren;
roles, label } = adaptationChildren;

const isMainAdaptation = Array.isArray(roles) &&
roles.some((role) => role.value === "main") &&
Expand Down Expand Up @@ -425,6 +425,10 @@ export default function parseAdaptationSets(
parsedAdaptationSet.isSignInterpreted = true;
}

if (label !== undefined) {
parsedAdaptationSet.label = label;
}

if (trickModeAttachedAdaptationIds !== undefined) {
trickModeAdaptations.push({ adaptation: parsedAdaptationSet,
trickModeAttachedAdaptationIds });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ function parseAdaptationSetChildren(
children.inbandEventStreams.push(parseScheme(currentElement));
break;

case "Label":
const label = currentElement.textContent;

if (label !== null && label !== undefined) {
children.label = label;
}
break;

case "Representation":
const [representation, representationWarnings] =
createRepresentationIntermediateRepresentation(currentElement);
Expand Down
1 change: 1 addition & 0 deletions src/parsers/manifest/dash/node_parser_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export interface IAdaptationSetChildren {
segmentBase? : ISegmentBaseIntermediateRepresentation | undefined;
segmentList? : ISegmentListIntermediateRepresentation | undefined;
segmentTemplate? : ISegmentTemplateIntermediateRepresentation | undefined;
label? : string | undefined;
}

/* Intermediate representation for An AdaptationSet node's attributes. */
Expand Down
4 changes: 4 additions & 0 deletions src/parsers/manifest/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ export interface IParsedAdaptation {
* Not set if unknown or if it makes no sense for the current track.
*/
language?: string | undefined;
/**
* Label of the `Adaptation` if it exists.
*/
label?: string;
/**
* TrickMode tracks attached to the adaptation.
*/
Expand Down

0 comments on commit c63bbd4

Please sign in to comment.