From 658386bf936341230c3c3015293b5f89801d0d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Thu, 25 Jan 2024 18:41:23 +0100 Subject: [PATCH] fix(HLS): Set the bandwidth correctly for audio/video-only variants (#6165) --- lib/hls/hls_parser.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index 1e67365257..21d332d03d 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -450,8 +450,9 @@ shaka.hls.HlsParser = class { const {segments, bandwidth} = this.createSegments_( playlist, stream, mediaSequenceToStartTime, mediaVariables, streamInfo.getUris); - - stream.bandwidth = bandwidth; + if (bandwidth) { + stream.bandwidth = bandwidth; + } stream.segmentIndex.mergeAndEvict( segments, this.presentationTimeline_.getSegmentAvailabilityStart()); @@ -1386,7 +1387,7 @@ shaka.hls.HlsParser = class { videoLayout = videoLayout || 'CH-MONO'; const streamInfos = this.createStreamInfosForVariantTags_(tags, - mediaTags, resolution, frameRate); + mediaTags, resolution, frameRate, bandwidth); goog.asserts.assert(streamInfos.audio.length || streamInfos.video.length, 'We should have created a stream!'); @@ -1414,10 +1415,12 @@ shaka.hls.HlsParser = class { * @param {!Array.} mediaTags * @param {?string} resolution * @param {?string} frameRate + * @param {number} bandwidth * @return {!shaka.hls.HlsParser.StreamInfos} * @private */ - createStreamInfosForVariantTags_(tags, mediaTags, resolution, frameRate) { + createStreamInfosForVariantTags_( + tags, mediaTags, resolution, frameRate, bandwidth) { const ContentType = shaka.util.ManifestParserUtils.ContentType; /** @type {shaka.hls.HlsParser.StreamInfos} */ @@ -1552,6 +1555,9 @@ shaka.hls.HlsParser = class { if (globalGroupId) { streamInfo.stream.groupId = globalGroupId; } + if (!streamInfos.length) { + streamInfo.stream.bandwidth = bandwidth; + } res[streamInfo.stream.type] = [streamInfo]; } return res; @@ -2239,7 +2245,7 @@ shaka.hls.HlsParser = class { stream.drmInfos = realStream.drmInfos; stream.keyIds = realStream.keyIds; stream.mimeType = realStream.mimeType; - stream.bandwidth = realStream.bandwidth; + stream.bandwidth = stream.bandwidth || realStream.bandwidth; stream.codecs = stream.codecs || realStream.codecs; // Since we lazy-loaded this content, the player may need to create new @@ -2518,7 +2524,9 @@ shaka.hls.HlsParser = class { const {segments, bandwidth} = this.createSegments_( playlist, stream, mediaSequenceToStartTime, mediaVariables, getUris); - stream.bandwidth = bandwidth; + if (bandwidth) { + stream.bandwidth = bandwidth; + } // This new calculation is necessary for Low Latency streams. if (this.isLive_()) {