Skip to content

Commit

Permalink
perf: Reduce calls to isTypeSupported (#7729)
Browse files Browse the repository at this point in the history
There should not be any call to isTypeSupported if we have already used
Mcap with the same codecs/mimeType

Release-As: 4.9.2-caf3
  • Loading branch information
avelad authored and joeyparrish committed Dec 11, 2024
1 parent 1e3e65f commit c1da00a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
64 changes: 36 additions & 28 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,23 @@ shaka.util.StreamUtils = class {
* @private
*/
static checkVariantSupported_(variant, keySystem) {
const variantSupported = variant.decodingInfos.some((decodingInfo) => {
if (!decodingInfo.supported) {
return false;
}
if (keySystem) {
const keySystemAccess = decodingInfo.keySystemAccess;
if (keySystemAccess) {
if (keySystemAccess.keySystem != keySystem) {
return false;
}
}
}
return true;
});
if (!variantSupported) {
return false;
}
const ContentType = shaka.util.ManifestParserUtils.ContentType;
const Capabilities = shaka.media.Capabilities;
const ManifestParserUtils = shaka.util.ManifestParserUtils;
Expand Down Expand Up @@ -453,15 +470,17 @@ shaka.util.StreamUtils = class {
videoCodecs = [videoCodecs, audioCodecs].join(',');
}

const fullType = MimeUtils.getFullOrConvertedType(
video.mimeType, videoCodecs, ContentType.VIDEO);
if (video.codecs != videoCodecs) {
const fullType = MimeUtils.getFullOrConvertedType(
video.mimeType, videoCodecs, ContentType.VIDEO);

if (!Capabilities.isTypeSupported(fullType)) {
return false;
}
if (!Capabilities.isTypeSupported(fullType)) {
return false;
}

// Update the codec string with the (possibly) converted codecs.
video.codecs = videoCodecs;
// Update the codec string with the (possibly) converted codecs.
video.codecs = videoCodecs;
}
}

const audio = variant.audio;
Expand All @@ -478,31 +497,20 @@ shaka.util.StreamUtils = class {
if (audio) {
const codecs = StreamUtils.getCorrectAudioCodecs(
audio.codecs, audio.mimeType);
const fullType = MimeUtils.getFullOrConvertedType(
audio.mimeType, codecs, ContentType.AUDIO);
if (audio.codecs != codecs) {
const fullType = MimeUtils.getFullOrConvertedType(
audio.mimeType, codecs, ContentType.AUDIO);

if (!Capabilities.isTypeSupported(fullType)) {
return false;
}
if (!Capabilities.isTypeSupported(fullType)) {
return false;
}

// Update the codec string with the (possibly) converted codecs.
audio.codecs = codecs;
// Update the codec string with the (possibly) converted codecs.
audio.codecs = codecs;
}
}

return variant.decodingInfos.some((decodingInfo) => {
if (!decodingInfo.supported) {
return false;
}
if (keySystem) {
const keySystemAccess = decodingInfo.keySystemAccess;
if (keySystemAccess) {
if (keySystemAccess.keySystem != keySystem) {
return false;
}
}
}
return true;
});
return true;
}


Expand Down
2 changes: 2 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3487,6 +3487,8 @@ describe('Player', () => {
stream.mimeType = 'video';
stream.codecs = 'unsupported';
stream.addDrmInfo('foo.bar');
stream.fullMimeTypes = new Set([shaka.util.MimeUtils.getFullType(
stream.mimeType, stream.codecs)]);
});
});
manifest.addVariant(1, (variant) => {
Expand Down

0 comments on commit c1da00a

Please sign in to comment.