Skip to content

Commit 9678b1c

Browse files
authored
perf: Do not process stream DRM info several times (#8505)
1 parent 3fab47c commit 9678b1c

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

lib/media/manifest_filterer.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,17 @@ shaka.media.ManifestFilterer = class {
9191
this.drmEngine_ ? this.drmEngine_.getDrmInfo() : null;
9292
// DrmEngine.newInitData() requires mediaKeys to be available.
9393
if (currentDrmInfo && this.drmEngine_.getMediaKeys()) {
94+
const streams = new Set();
9495
for (const variant of manifest.variants) {
95-
this.processDrmInfos(currentDrmInfo.keySystem, variant.video);
96-
this.processDrmInfos(currentDrmInfo.keySystem, variant.audio);
96+
if (variant.audio) {
97+
streams.add(variant.audio);
98+
}
99+
if (variant.video) {
100+
streams.add(variant.video);
101+
}
102+
}
103+
for (const stream of streams) {
104+
this.processDrmInfos(currentDrmInfo.keySystem, stream);
97105
}
98106
}
99107
this.checkRestrictedVariants(manifest);
@@ -122,13 +130,9 @@ shaka.media.ManifestFilterer = class {
122130

123131
/**
124132
* @param {string} keySystem
125-
* @param {?shaka.extern.Stream} stream
133+
* @param {!shaka.extern.Stream} stream
126134
*/
127135
processDrmInfos(keySystem, stream) {
128-
if (!stream) {
129-
return;
130-
}
131-
132136
for (const drmInfo of stream.drmInfos) {
133137
// Ignore any data for different key systems.
134138
if (drmInfo.keySystem == keySystem) {
@@ -162,27 +166,15 @@ shaka.media.ManifestFilterer = class {
162166
/** @type {!Set<string>} */
163167
const badKeyStatuses = new Set();
164168

169+
const streams = new Set();
170+
165171
for (const variant of manifest.variants) {
166172
// TODO: Combine with onKeyStatus_.
167-
const streams = [];
168173
if (variant.audio) {
169-
streams.push(variant.audio);
174+
streams.add(variant.audio);
170175
}
171176
if (variant.video) {
172-
streams.push(variant.video);
173-
}
174-
175-
for (const stream of streams) {
176-
if (stream.keyIds.size) {
177-
for (const keyId of stream.keyIds) {
178-
const keyStatus = keyStatusMap[isGlobalStatus ? '00' : keyId];
179-
if (!keyStatus) {
180-
missingKeys.add(keyId);
181-
} else if (restrictedStatuses.includes(keyStatus)) {
182-
badKeyStatuses.add(keyStatus);
183-
}
184-
}
185-
} // if (stream.keyIds.size)
177+
streams.add(variant.video);
186178
}
187179

188180
if (!variant.allowedByApplication) {
@@ -192,6 +184,19 @@ shaka.media.ManifestFilterer = class {
192184
}
193185
}
194186

187+
for (const stream of streams) {
188+
if (stream.keyIds.size) {
189+
for (const keyId of stream.keyIds) {
190+
const keyStatus = keyStatusMap[isGlobalStatus ? '00' : keyId];
191+
if (!keyStatus) {
192+
missingKeys.add(keyId);
193+
} else if (restrictedStatuses.includes(keyStatus)) {
194+
badKeyStatuses.add(keyStatus);
195+
}
196+
}
197+
} // if (stream.keyIds.size)
198+
}
199+
195200
if (!hasPlayable) {
196201
/** @type {shaka.extern.RestrictionInfo} */
197202
const data = {

0 commit comments

Comments
 (0)