Skip to content

Commit 947cbd8

Browse files
yajin2021robwalch
authored andcommitted
Parse keyid from multi-key widevine PSSH (#7415)
(cherry picked from commit 3fd4bf3)
1 parent 178333c commit 947cbd8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/loader/level-key.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { hexToArrayBuffer } from '../utils/hex';
44
import { convertDataUriToArrayBytes } from '../utils/keysystem-util';
55
import { logger } from '../utils/logger';
66
import { KeySystemFormats, parsePlayReadyWRM } from '../utils/mediakeys-helper';
7-
import { mp4pssh } from '../utils/mp4-tools';
7+
import { mp4pssh, parseMultiPssh } from '../utils/mp4-tools';
88

99
let keyUriToKeyIdMap: { [uri: string]: Uint8Array<ArrayBuffer> } = {};
1010

@@ -141,7 +141,14 @@ export class LevelKey implements DecryptData {
141141
// the playlist-key before the "encrypted" event. (Comment out to only use "encrypted" path.)
142142
this.pssh = keyBytes;
143143
// In case of Widevine, if KEYID is not in the playlist, assume only two fields in the pssh KEY tag URI.
144-
if (!this.keyId && keyBytes.length >= 22) {
144+
if (!this.keyId) {
145+
const [psshData] = parseMultiPssh(keyBytes.buffer);
146+
this.keyId =
147+
psshData && 'kids' in psshData && psshData.kids?.[0]
148+
? psshData.kids[0]
149+
: null;
150+
}
151+
if (!this.keyId) {
145152
const offset = keyBytes.length - 22;
146153
this.keyId = keyBytes.subarray(offset, offset + 16);
147154
}

0 commit comments

Comments
 (0)