Skip to content

Commit

Permalink
fix: exclude "future" segments from presentation timeline calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
littlespex committed Jan 26, 2023
1 parent dc64ede commit 7bee999
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/media/presentation_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,16 @@ shaka.media.PresentationTimeline = class {

let firstReferenceStartTime = references[0].startTime;
let lastReferenceEndTime = references[0].endTime;

// Date.now() is in milliseconds, from which we compute "now" in seconds.
const now = (Date.now() + this.clockOffset_) / 1000.0;

for (const reference of references) {
// Stop if we've reached segments that are in the "future".
if (now < reference.startTime) {
break;
}

firstReferenceStartTime = Math.min(
firstReferenceStartTime, reference.startTime);
lastReferenceEndTime = Math.max(lastReferenceEndTime, reference.endTime);
Expand All @@ -251,8 +260,6 @@ shaka.media.PresentationTimeline = class {
!this.startTimeLocked_) {
// Since we have explicit segment end times, calculate a presentation
// start based on them. This start time accounts for drift.
// Date.now() is in milliseconds, from which we compute "now" in seconds.
const now = (Date.now() + this.clockOffset_) / 1000.0;
this.presentationStartTime_ =
now - this.maxSegmentEndTime_ - this.maxSegmentDuration_;
}
Expand Down

0 comments on commit 7bee999

Please sign in to comment.