Skip to content

Commit

Permalink
fix(HLS): Fix SAMPLE-AES playback
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Apr 4, 2024
1 parent 25427c7 commit 04b65cb
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2314,9 +2314,15 @@ shaka.media.DrmEngine = class {
shaka.util.BufferUtils.equal(a.initData, b.initData);
};

const clearkeyDataStart = 'data:application/json;base64,';
const clearKeyLicenseServers = [];

for (const drmInfo of drmInfos) {
// Build an array of unique license servers.
if (!licenseServers.includes(drmInfo.licenseServerUri)) {
if (drmInfo.keySystem == 'org.w3.clearkey' &&
drmInfo.licenseServerUri.startsWith(clearkeyDataStart)) {
clearKeyLicenseServers.push(drmInfo.licenseServerUri);
} else if (!licenseServers.includes(drmInfo.licenseServerUri)) {
licenseServers.push(drmInfo.licenseServerUri);
}

Expand Down Expand Up @@ -2353,6 +2359,21 @@ shaka.media.DrmEngine = class {
}
}
}

if (clearKeyLicenseServers.length == 1) {
licenseServers.push(clearKeyLicenseServers[0]);
} else if (clearKeyLicenseServers.length > 0) {
const keys = [];
for (const clearKeyLicenseServer of clearKeyLicenseServers) {
const license = window.atob(
clearKeyLicenseServer.split(clearkeyDataStart).pop());
const jwkSet = /** @type {{keys: !Array}} */(JSON.parse(license));
keys.push(...jwkSet.keys);
}
const newJwkSet = {keys: keys};
const newLicense = JSON.stringify(newJwkSet);
licenseServers.push(clearkeyDataStart + window.btoa(newLicense));
}
}

/**
Expand Down

0 comments on commit 04b65cb

Please sign in to comment.