From c1da00a6099984c2b8a87c9f91049d560b045046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Mon, 9 Dec 2024 13:29:38 +0100 Subject: [PATCH] perf: Reduce calls to isTypeSupported (#7729) 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 --- lib/util/stream_utils.js | 64 ++++++++++++++++++++++------------------ test/player_unit.js | 2 ++ 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/lib/util/stream_utils.js b/lib/util/stream_utils.js index 4f58a09554..40c2dd04e1 100644 --- a/lib/util/stream_utils.js +++ b/lib/util/stream_utils.js @@ -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; @@ -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; @@ -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; } diff --git a/test/player_unit.js b/test/player_unit.js index 76bf1edef4..74a8264536 100644 --- a/test/player_unit.js +++ b/test/player_unit.js @@ -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) => {