Skip to content

Commit

Permalink
perf: simplify and improve performance of parsing initData when dedup…
Browse files Browse the repository at this point in the history
…ing (#5775)

This change simplifies code that parses initData in the `getCommonDrmInfos` method

Co-authored-by: Ivan Kohut <ivan.kohut@lamin.ar>
  • Loading branch information
2 people authored and joeyparrish committed Feb 17, 2024
1 parent b16acc3 commit 0350f9d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1924,15 +1924,17 @@ shaka.media.DrmEngine = class {
// audio adaptations, so we shouldn't have to worry about checking
// robustness.
if (drm1.keySystem == drm2.keySystem) {
/** @type {Array<shaka.extern.InitDataOverride>} */
let initData = [];
initData = initData.concat(drm1.initData || []);
initData = initData.concat(drm2.initData || []);
initData = initData.filter((d, i) => {
return d.keyId === undefined || i === initData.findIndex((d2) => {
return d2.keyId === d.keyId;
});
});
const initDataMap = new Map();
const bothInitDatas = (drm1.initData || [])
.concat(drm2.initData || []);
for (const d of bothInitDatas) {
if (typeof d !== 'string' && !initDataMap.has(d.keyId)) {
initDataMap.set(d.keyId, d);
} else if (typeof d === 'string' && !initDataMap.has(d)) {
initDataMap.set(d, d);
}
}
const initData = Array.from(initDataMap.values());

const keyIds = drm1.keyIds && drm2.keyIds ?
new Set([...drm1.keyIds, ...drm2.keyIds]) :
Expand Down

0 comments on commit 0350f9d

Please sign in to comment.