Skip to content

Commit 767ff47

Browse files
committed
Merge branch 'patch/v1.6.x'
* patch/v1.6.x: Increase minimum Windows test version for saucelabs Fix FairPlay key ID patching Fixes "keyId is null" error mentioned in #7542 (comment) #7654 Fix fallback to primary on live start Fixes #7641 Do not reset interstitial when seeking between assets Fixes #7640 Fixed issue with progressive loading of subtitles by disabling progressive loading for webVTT (#7649) Fix audio TS segment duration calculation ##7646 (comment) Resolve end-of-stream with empty or gap segments at end of playlist Fixes #7572 (and maybe #7564) Fix issue where some devices not works with playready (#7631) Fix switching back to main audio after end-of-stream buffered Fixes #7643
2 parents 3492794 + b001910 commit 767ff47

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

api-extractor/report/hls.js.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,6 +3358,8 @@ export class LevelDetails {
33583358
export class LevelKey implements DecryptData {
33593359
constructor(method: string, uri: string, format: string, formatversions?: number[], iv?: Uint8Array<ArrayBuffer> | null, keyId?: string);
33603360
// (undocumented)
3361+
static addKeyIdForUri(uri: string): Uint8Array<ArrayBuffer>;
3362+
// (undocumented)
33613363
static clearKeyUriToKeyIdMap(): void;
33623364
// (undocumented)
33633365
readonly encrypted: boolean;

src/loader/key-loader.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,22 @@ export default class KeyLoader extends Logger implements ComponentAPI {
265265
frag.initSegment.data as Uint8Array<ArrayBuffer>,
266266
);
267267
if (keyIds.length) {
268-
const keyId = keyIds[0];
268+
let keyId = keyIds[0];
269269
if (keyId.some((b) => b !== 0)) {
270270
this.log(`Using keyId found in init segment ${arrayToHex(keyId)}`);
271-
keyInfo.decryptdata.keyId = keyId;
272271
LevelKey.setKeyIdForUri(keyInfo.decryptdata.uri, keyId);
272+
} else {
273+
keyId = LevelKey.addKeyIdForUri(keyInfo.decryptdata.uri);
274+
this.log(`Generating keyId to patch media ${arrayToHex(keyId)}`);
273275
}
276+
keyInfo.decryptdata.keyId = keyId;
274277
}
275278
}
279+
if (!keyInfo.decryptdata.keyId && !isMediaFragment(frag)) {
280+
// Resolve so that unencrypted init segment is loaded
281+
// key id is extracted from tenc box when processing key for next segment above
282+
return Promise.resolve(keyLoadedData);
283+
}
276284
const keySessionContextPromise =
277285
this.emeController.loadKey(keyLoadedData);
278286
return (keyInfo.keyLoadPromise = keySessionContextPromise.then(

src/loader/level-key.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ export class LevelKey implements DecryptData {
4141
keyUriToKeyIdMap[uri] = keyId;
4242
}
4343

44+
static addKeyIdForUri(uri: string): Uint8Array<ArrayBuffer> {
45+
const val = Object.keys(keyUriToKeyIdMap).length % Number.MAX_SAFE_INTEGER;
46+
const keyId = new Uint8Array(16);
47+
const dv = new DataView(keyId.buffer, 12, 4); // Just set the last 4 bytes
48+
dv.setUint32(0, val);
49+
keyUriToKeyIdMap[uri] = keyId;
50+
return keyId;
51+
}
52+
4453
constructor(
4554
method: string,
4655
uri: string,

0 commit comments

Comments
 (0)