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>

Backported to v4.3.x
  • Loading branch information
vanyaxk authored and joeyparrish committed Feb 17, 2024
1 parent af79ca4 commit e471bfc
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 @@ -434,19 +434,33 @@ shaka.util.StreamUtils = class {

await shaka.util.StreamUtils.getDecodingInfosForVariants(
manifest.variants, usePersistentLicenses, /* srcEquals= */ false);

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 @@ -455,7 +469,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 @@ -497,17 +510,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 e471bfc

Please sign in to comment.