Skip to content

Commit

Permalink
Add uniqueId property to Representations
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Feb 9, 2023
1 parent 4101cde commit b402ef2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
28 changes: 27 additions & 1 deletion src/manifest/representation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,44 @@ import {
} from "../parsers/manifest";
import { IHDRInformation } from "../public_types";
import areArraysOfNumbersEqual from "../utils/are_arrays_of_numbers_equal";
import idGenerator from "../utils/id_generator";
import { IRepresentationIndex } from "./representation_index";
import {
IAdaptationType,
} from "./types";

const generateRepresentationUniqueId = idGenerator();

/**
* Normalized Representation structure.
* @class Representation
*/
class Representation {
/** ID uniquely identifying the Representation in the Adaptation. */
/**
* ID uniquely identifying the `Representation` in its parent `Adaptation`.
*
* This identifier might be linked to an identifier present in the original
* Manifest file, it is thus the identifier to use to determine if a
* `Representation` from a refreshed `Manifest` is actually the same one than
* one in the previously loaded Manifest (as long as the `Adaptation` and
* `Period` are also the same).
*
* For a globally unique identifier regardless of the `Adaptation`, `Period`
* or even `Manifest`, you can rely on `uniqueId` instead.
*/
public readonly id : string;

/**
* Globally unique identifier for this `Representation` object.
*
* This identifier is guaranteed to be unique for any `Representation`s of all
* `Manifest` objects created in the current JS Realm.
* As such, it can be used as an identifier for the JS object itself, whereas
* `id` is the identifier for the original Manifest's Representation in the
* scope of its parent `Adaptation`.
*/
public readonly uniqueId : string;

/**
* Interface allowing to get information about segments available for this
* Representation.
Expand Down Expand Up @@ -115,6 +140,7 @@ class Representation {
*/
constructor(args : IParsedRepresentation, opts : { type : IAdaptationType }) {
this.id = args.id;
this.uniqueId = generateRepresentationUniqueId();
this.bitrate = args.bitrate;
this.codec = args.codecs;

Expand Down
4 changes: 1 addition & 3 deletions src/manifest/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ export function areSameContent(
content2: IBufferedChunkInfos
): boolean {
return (content1.segment.id === content2.segment.id &&
content1.representation.id === content2.representation.id &&
content1.adaptation.id === content2.adaptation.id &&
content1.period.id === content2.period.id);
content1.representation.uniqueId === content2.representation.uniqueId);
}

/**
Expand Down

0 comments on commit b402ef2

Please sign in to comment.