From a8e3c9ab310b14ca71610c568cffe108b30d38bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Fri, 28 Apr 2023 07:02:41 +0200 Subject: [PATCH] fix: Fix buffering on the end of MSS streams (#5196) --- lib/mss/mss_parser.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/mss/mss_parser.js b/lib/mss/mss_parser.js index 9e5c42d363..87ea5444a3 100644 --- a/lib/mss/mss_parser.js +++ b/lib/mss/mss_parser.js @@ -54,6 +54,9 @@ shaka.mss.MssParser = class { */ this.updatePeriod_ = 0; + /** @private {?shaka.media.PresentationTimeline} */ + this.presentationTimeline_ = null; + /** * An ewma that tracks how long updates take. * This is to mitigate issues caused by slow parsing on embedded devices. @@ -286,12 +289,8 @@ shaka.mss.MssParser = class { manifestPreprocessor(mss); } - /** @type {!shaka.media.PresentationTimeline} */ - let presentationTimeline; - if (this.manifest_) { - presentationTimeline = this.manifest_.presentationTimeline; - } else { - presentationTimeline = new shaka.media.PresentationTimeline( + if (!this.presentationTimeline_) { + this.presentationTimeline_ = new shaka.media.PresentationTimeline( /* presentationStartTime= */ null, /* delay= */ 0); } @@ -305,7 +304,7 @@ shaka.mss.MssParser = class { shaka.util.Error.Code.MSS_LIVE_CONTENT_NOT_SUPPORTED); } - presentationTimeline.setStatic(!isLive); + this.presentationTimeline_.setStatic(!isLive); const timescale = XmlUtils.parseAttr(mss, 'TimeScale', XmlUtils.parseNonNegativeInt, shaka.mss.MssParser.DEFAULT_TIME_SCALE_); @@ -342,7 +341,7 @@ shaka.mss.MssParser = class { segmentAvailabilityDuration = Infinity; } - presentationTimeline.setSegmentAvailabilityDuration( + this.presentationTimeline_.setSegmentAvailabilityDuration( segmentAvailabilityDuration); // Duration in timescale units. @@ -352,7 +351,7 @@ shaka.mss.MssParser = class { 'Duration must be defined!'); if (!isLive) { - presentationTimeline.setDuration(duration / timescale); + this.presentationTimeline_.setDuration(duration / timescale); } /** @type {!shaka.mss.MssParser.Context} */ @@ -368,7 +367,7 @@ shaka.mss.MssParser = class { // These steps are not done on manifest update. if (!this.manifest_) { this.manifest_ = { - presentationTimeline: presentationTimeline, + presentationTimeline: this.presentationTimeline_, variants: context.variants, textStreams: context.textStreams, imageStreams: [], @@ -382,7 +381,7 @@ shaka.mss.MssParser = class { // This is the first point where we have a meaningful presentation start // time, and we need to tell PresentationTimeline that so that it can // maintain consistency from here on. - presentationTimeline.lockStartTime(); + this.presentationTimeline_.lockStartTime(); } else { // Just update the variants and text streams. this.manifest_.variants = context.variants; @@ -491,6 +490,10 @@ shaka.mss.MssParser = class { duration = end - start; } + const presentationDuration = this.presentationTimeline_.getDuration(); + this.presentationTimeline_.setDuration( + Math.min(duration, presentationDuration)); + /** @type {!shaka.extern.Stream} */ const stream = { id: id,