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
  • Loading branch information
avelad authored and joeyparrish committed Dec 11, 2024
1 parent 8318911 commit 77859b5
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 @@ -444,6 +444,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 @@ -492,15 +509,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 @@ -517,31 +536,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 @@ -3563,6 +3563,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 77859b5

Please sign in to comment.