From 2ffcdac576b7fdcef4bfe2a06ae46f732ea5fa9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Thu, 2 Jan 2025 08:55:24 +0100 Subject: [PATCH] fix: Remove useless calls to isTypeSupported (#7817) It also enables a test that has been disabled due to this bug. --- lib/media/media_source_engine.js | 5 ++ lib/util/stream_utils.js | 60 ----------------------- test/transmuxer/transmuxer_integration.js | 15 ++++-- 3 files changed, 17 insertions(+), 63 deletions(-) diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index b921dbf7b8..1c2121392c 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -333,6 +333,11 @@ shaka.media.MediaSourceEngine = class { for (const ref of stream.segmentIndex) { const mimeType = ref.mimeType || stream.mimeType || ''; let codecs = ref.codecs || stream.codecs || ''; + // Optimization for the case where the codecs and mimetype of the stream + // match the reference. + if (mimeType == stream.mimeType && codecs == stream.codecs) { + continue; + } // Don't check the same combination of mimetype + codecs twice. const combo = mimeType + ':' + codecs; if (seenCombos.has(combo)) { diff --git a/lib/util/stream_utils.js b/lib/util/stream_utils.js index c37915c534..252f9fca32 100644 --- a/lib/util/stream_utils.js +++ b/lib/util/stream_utils.js @@ -516,11 +516,6 @@ shaka.util.StreamUtils = class { if (!variantSupported) { return 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(); const isFirefoxAndroid = shaka.util.Platform.isFirefox() && @@ -538,45 +533,6 @@ shaka.util.StreamUtils = class { 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(',')) { - const allCodecs = video.codecs.split(','); - - videoCodecs = ManifestParserUtils.guessCodecs( - ContentType.VIDEO, allCodecs); - videoCodecs = StreamUtils.getCorrectVideoCodecs(videoCodecs); - let audioCodecs = ManifestParserUtils.guessCodecs( - ContentType.AUDIO, allCodecs); - audioCodecs = StreamUtils.getCorrectAudioCodecs( - audioCodecs, video.mimeType); - - const audioFullType = MimeUtils.getFullOrConvertedType( - video.mimeType, audioCodecs, ContentType.AUDIO); - - if (!Capabilities.isTypeSupported(audioFullType)) { - return false; - } - - // Update the codec string with the (possibly) converted codecs. - videoCodecs = [videoCodecs, audioCodecs].join(','); - } - - if (video.codecs != videoCodecs) { - const fullType = MimeUtils.getFullOrConvertedType( - video.mimeType, videoCodecs, ContentType.VIDEO); - - if (!Capabilities.isTypeSupported(fullType)) { - return false; - } - - // Update the codec string with the (possibly) converted codecs. - video.codecs = videoCodecs; - } - } - const audio = variant.audio; // See: https://github.com/shaka-project/shaka-player/issues/6111 @@ -588,22 +544,6 @@ shaka.util.StreamUtils = class { return false; } - if (audio) { - const codecs = StreamUtils.getCorrectAudioCodecs( - audio.codecs, audio.mimeType); - if (audio.codecs != codecs) { - const fullType = MimeUtils.getFullOrConvertedType( - audio.mimeType, codecs, ContentType.AUDIO); - - if (!Capabilities.isTypeSupported(fullType)) { - return false; - } - - // Update the codec string with the (possibly) converted codecs. - audio.codecs = codecs; - } - } - return true; } diff --git a/test/transmuxer/transmuxer_integration.js b/test/transmuxer/transmuxer_integration.js index f0fbc74962..be8c2a83a9 100644 --- a/test/transmuxer/transmuxer_integration.js +++ b/test/transmuxer/transmuxer_integration.js @@ -339,13 +339,22 @@ describe('Transmuxer Player', () => { }); it('H.264+MP3 in TS', async () => { - if (!await Util.isTypeSupported('audio/mp4; codecs="mp3"')) { - pending('Codec MP3 in MP4 is not supported by the platform.'); + if (!await Util.isTypeSupported('audio/mp4; codecs="mp3"') && + !await Util.isTypeSupported('audio/mpeg')) { + pending('Codec MP3 is not supported by the platform.'); + } + if (!shaka.util.Platform.supportsSequenceMode()) { + pending('Sequence mode is not supported by the platform.'); } // eslint-disable-next-line max-len await player.load('/base/test/test/assets/hls-ts-muxed-mp3-h264/index.m3u8'); - await video.play(); + try { + await video.play(); + // eslint-disable-next-line no-restricted-syntax + } catch (e) { + // Ignore play errors + } expect(player.isLive()).toBe(false); // Wait for the video to start playback. If it takes longer than 10