Skip to content

Commit

Permalink
fix: Fix buffering on the end of MSS streams
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Apr 27, 2023
1 parent 330f04b commit 0b82270
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/mss/mss_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

Expand All @@ -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_);
Expand Down Expand Up @@ -342,7 +341,7 @@ shaka.mss.MssParser = class {
segmentAvailabilityDuration = Infinity;
}

presentationTimeline.setSegmentAvailabilityDuration(
this.presentationTimeline_.setSegmentAvailabilityDuration(
segmentAvailabilityDuration);

// Duration in timescale units.
Expand All @@ -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} */
Expand All @@ -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: [],
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0b82270

Please sign in to comment.