Skip to content

Commit

Permalink
fix: exclude "future" segments from presentation timeline auto correc…
Browse files Browse the repository at this point in the history
…t drift calculations (#4945)

Resolves #4944
  • Loading branch information
littlespex authored and joeyparrish committed Apr 26, 2023
1 parent 834c329 commit 0578084
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 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) {
// Exclude segments that are in the "future".
if (now < reference.startTime) {
continue;
}

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
5 changes: 3 additions & 2 deletions test/dash/dash_parser_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ describe('DashParser Live', () => {
template, {updateTime: updateTime, contents: basicLines.join('\n')});

fakeNetEngine.setResponseText('dummy://foo', text);
Date.now = () => 0;
const baseTime = new Date(2015, 11, 30);
Date.now = () => baseTime.getTime();
const manifest = await parser.start('dummy://foo', playerInterface);

expect(manifest).toBeTruthy();
Expand All @@ -211,7 +212,7 @@ describe('DashParser Live', () => {
// seconds long in all of these cases. So 11 seconds after the
// manifest was parsed, the first segment should have fallen out of
// the availability window.
Date.now = () => 11 * 1000;
Date.now = () => baseTime.getTime() + (11 * 1000);
await updateManifest();
// The first reference should have been evicted.
expect(stream.segmentIndex.find(0)).toBe(firstPosition + 1);
Expand Down

0 comments on commit 0578084

Please sign in to comment.