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
vanyaxk and Ivan Kohut authored Oct 22, 2023
1 parent bcc2c24 commit 041a08f
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 @@ -2045,15 +2045,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 041a08f

Please sign in to comment.