Skip to content

Commit

Permalink
chore: lint issue
Browse files Browse the repository at this point in the history
  • Loading branch information
CeilingFANC committed May 17, 2024
1 parent 928233f commit 07ca2ea
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,10 @@ shaka.util.StreamUtils = class {
* Group similar variants, and share results.
* Helpful for video with a lot of variants on LR.
*/
const enableCahe = enableMediaCapabilitiesCache &&
const enableCache = enableMediaCapabilitiesCache &&
!srcEquals && !shaka.util.Platform.isChromecast();
if (enableCahe) {
if (enableCache) {
/** @type {!Object.<string, MediaCapabilitiesDecodingInfo>} */
const decodeInfoCache = {};
const buildCacheKey = (variant) => {
if (variant.audio.fullMimeTypes.size < 1 ||
Expand All @@ -726,13 +727,16 @@ shaka.util.StreamUtils = class {
const audioDrmInfos = audio ? audio.drmInfos : [];
const allDrmInfos = videoDrmInfos.concat(audioDrmInfos);

const keySystems= new Set(allDrmInfos.map((info) => info.keySystem));
const keySystems = new Set(allDrmInfos.map((info) => info.keySystem));
const cacheKeys = [];
for (const keySystem of keySystems) {
for (const videoFullMimeType of video.fullMimeTypes) {
for (const audioFullMimeType of audio.fullMimeTypes) {
cacheKeys.push(
`${videoFullMimeType}#${audioFullMimeType}#${keySystem}`);
`${videoFullMimeType}#${video.hdr}
#${audioFullMimeType}#${audio.spatialAudio}
#${audio.channelsCount}
#${keySystem}`);
// video.hdr + audio.spatialAudio + audio.channelsCount
}
}
Expand All @@ -748,42 +752,42 @@ shaka.util.StreamUtils = class {
for (const variant of sortedVariants) {
const cacheKeys = buildCacheKey(variant);
const useCache = cacheKeys && cacheKeys.length &&
cacheKeys.reduce((hasCache, key) =>
(hasCache && decodeInfoCache[key] &&
// If not meet criteria, won't use cache.
decodeInfoCache[key][keyToCheck])
, true);
cacheKeys.reduce((hasCache, key) =>
(hasCache && decodeInfoCache[key] &&
// If not meet criteria, won't use cache.
decodeInfoCache[key][keyToCheck])
, true);
shaka.log.info('getDecodingInfosForVariants used cache.',
useCache, cacheKeys, variant);
if (useCache) {
variant.decodingInfos =
cacheKeys.map((key) => decodeInfoCache[key]);
cacheKeys.map((key) => decodeInfoCache[key]);
continue;
}

/** @type {!Array.<!Array.<!MediaDecodingConfiguration>>} */
const decodingConfigs = shaka.util.StreamUtils.getDecodingConfigs_(
variant, usePersistentLicenses, srcEquals)
.filter((configs) => {
// All configs in a batch will have the same keySystem.
// All configs in a batch will have the same keySystem.
const config = configs[0];
const keySystem = config.keySystemConfiguration &&
config.keySystemConfiguration.keySystem;
config.keySystemConfiguration.keySystem;
// Avoid checking preferred systems twice.
return !keySystem || !preferredKeySystems.includes(keySystem);
});

// The reason we are performing this await in a loop rather than
// batching into a `promise.all` is performance related.
// https://github.com/shaka-project/shaka-player/pull/4708#discussion_r1022581178
for (let i=0; i<decodingConfigs.length; i++) {
for (let i = 0; i < decodingConfigs.length; i++) {
const configs = decodingConfigs[i];
// eslint-disable-next-line no-await-in-loop
await shaka.util.StreamUtils.getDecodingInfosForVariant_(
variant, configs);

// getDecodingInfosForVariant_ could fail.
const result = variant.decodingInfos.length?
const result = variant.decodingInfos.length ?
variant.decodingInfos[i] : null;
if (cacheKeys && result) {
const cacheKey = cacheKeys[i];
Expand Down

0 comments on commit 07ca2ea

Please sign in to comment.