Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix buffering on the end of MSS streams #5196

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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