diff --git a/src/manifest/representation.ts b/src/manifest/representation.ts index 3976c03ea97..bb371353e55 100644 --- a/src/manifest/representation.ts +++ b/src/manifest/representation.ts @@ -27,19 +27,44 @@ import { IVideoRepresentation, } 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. @@ -119,6 +144,7 @@ class Representation { */ constructor(args : IParsedRepresentation, opts : { type : IAdaptationType }) { this.id = args.id; + this.uniqueId = generateRepresentationUniqueId(); this.bitrate = args.bitrate; this.codec = args.codecs; diff --git a/src/manifest/utils.ts b/src/manifest/utils.ts index cc76fdd8750..c73fc49b248 100644 --- a/src/manifest/utils.ts +++ b/src/manifest/utils.ts @@ -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); } /**