Skip to content

Commit

Permalink
perf(Xbox): drop incompatible variants for XBOX early (#5777)
Browse files Browse the repository at this point in the history
This change:

- drops incompatible variants for XBOX before parsing codes and checking them against media capabilities API
- avoids redeclaring variables each time in the loop

Co-authored-by: Ivan Kohut <ivan.kohut@lamin.ar>
  • Loading branch information
vanyaxk and Ivan Kohut authored Oct 18, 2023
1 parent be755e8 commit 170a40c
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,19 +347,33 @@ shaka.util.StreamUtils = class {
await shaka.util.StreamUtils.getDecodingInfosForVariants(
manifest.variants, usePersistentLicenses, /* srcEquals= */ false,
/** preferredKeySystems= */ []);

const ContentType = shaka.util.ManifestParserUtils.ContentType;
const Capabilities = shaka.media.Capabilities;
const ManifestParserUtils = shaka.util.ManifestParserUtils;
const MimeUtils = shaka.util.MimeUtils;
const StreamUtils = shaka.util.StreamUtils;
const isXboxOne = shaka.util.Platform.isXboxOne();

manifest.variants = manifest.variants.filter((variant) => {
// See: https://github.com/shaka-project/shaka-player/issues/3860
const video = variant.video;
const videoWidth = (video && video.width) || 0;
const videoHeight = (video && video.height) || 0;

const ContentType = shaka.util.ManifestParserUtils.ContentType;
const Capabilities = shaka.media.Capabilities;
const ManifestParserUtils = shaka.util.ManifestParserUtils;
const MimeUtils = shaka.util.MimeUtils;
const StreamUtils = shaka.util.StreamUtils;
// See: https://github.com/shaka-project/shaka-player/issues/3380
// Note: it makes sense to drop early
if (isXboxOne && video &&
(videoWidth > 1920 || videoHeight > 1080) &&
(video.codecs.includes('avc1.') || video.codecs.includes('avc3.'))
) {
shaka.log.debug('Dropping variant - not compatible with platform',
StreamUtils.getVariantSummaryString_(variant));
return false;
}

if (video) {
let videoCodecs = StreamUtils.getCorrectVideoCodecs_(video.codecs);

// For multiplexed streams. Here we must check the audio of the
// stream to see if it is compatible.
if (video.codecs.includes(',')) {
Expand All @@ -368,7 +382,6 @@ shaka.util.StreamUtils = class {
videoCodecs = ManifestParserUtils.guessCodecs(
ContentType.VIDEO, allCodecs);
videoCodecs = StreamUtils.getCorrectVideoCodecs_(videoCodecs);

let audioCodecs = ManifestParserUtils.guessCodecs(
ContentType.AUDIO, allCodecs);
audioCodecs = StreamUtils.getCorrectAudioCodecs_(audioCodecs);
Expand Down Expand Up @@ -410,17 +423,6 @@ shaka.util.StreamUtils = class {
audio.codecs = codecs;
}

// See: https://github.com/shaka-project/shaka-player/issues/3380
if (shaka.util.Platform.isXboxOne() && video &&
((video.width && video.width > 1920) ||
(video.height && video.height > 1080)) &&
(video.codecs.includes('avc1.') ||
video.codecs.includes('avc3.'))) {
shaka.log.debug('Dropping variant - not compatible with platform',
StreamUtils.getVariantSummaryString_(variant));
return false;
}

const supported = variant.decodingInfos.some((decodingInfo) => {
return decodingInfo.supported;
});
Expand Down

0 comments on commit 170a40c

Please sign in to comment.