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 wrong timing calculation for client/server clock drift. #3759

Merged
merged 2 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/dash/utils/SegmentsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ function isSegmentAvailable(timelineConverter, representation, segment, isDynami
// SAST = Period@start + seg@presentationStartTime + seg@duration
// ASAST = SAST - ATO
// SAET = SAST + TSBD + seg@duration

const refTime = timelineConverter.getAvailabilityWindowAnchorTime();
// refTime serves as an anchor time to compare the availability time of the segments against. Note that we already compensated for the client/server drift when calculating the availability time of a segment. Thats why we do not subtract clientServerTimeShift here again.
const refTime = Date.now() - ((timelineConverter.getTimelineAnchorAvailabilityOffset()) * 1000);
return segment.availabilityStartTime.getTime() <= refTime && (!isFinite(segment.availabilityEndTime) || segment.availabilityEndTime.getTime() >= refTime);
}

Expand Down
18 changes: 9 additions & 9 deletions src/dash/utils/TimelineConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function TimelineConverter() {
clientServerTimeShift = value;
}

function calcAvailabilityTimeFromPresentationTime(presentationEndTime, representation, isDynamic, calculateAvailabilityEndTime) {
function _calcAvailabilityTimeFromPresentationTime(presentationEndTime, representation, isDynamic, calculateAvailabilityEndTime) {
let availabilityTime;
let mpd = representation.adaptation.period.mpd;
const availabilityStartTime = mpd.availabilityStartTime;
Expand Down Expand Up @@ -99,15 +99,15 @@ function TimelineConverter() {
}

function calcAvailabilityStartTimeFromPresentationTime(presentationEndTime, representation, isDynamic) {
return calcAvailabilityTimeFromPresentationTime.call(this, presentationEndTime, representation, isDynamic);
return _calcAvailabilityTimeFromPresentationTime(presentationEndTime, representation, isDynamic);
}

function calcAvailabilityEndTimeFromPresentationTime(presentationEndTime, representation, isDynamic) {
return calcAvailabilityTimeFromPresentationTime.call(this, presentationEndTime, representation, isDynamic, true);
return _calcAvailabilityTimeFromPresentationTime(presentationEndTime, representation, isDynamic, true);
}

function calcPresentationTimeFromWallTime(wallTime, period) {
return ((wallTime.getTime() - period.mpd.availabilityStartTime.getTime() - clientServerTimeShift * 1000) / 1000);
return ((wallTime.getTime() - period.mpd.availabilityStartTime.getTime() + clientServerTimeShift * 1000) / 1000);
}

function calcPresentationTimeFromMediaTime(mediaTime, representation) {
Expand Down Expand Up @@ -138,10 +138,6 @@ function TimelineConverter() {
return wallTime;
}

function getAvailabilityWindowAnchorTime() {
return Date.now() - ((timelineAnchorAvailabilityOffset + clientServerTimeShift) * 1000);
}

/**
* Calculates the timeshiftbuffer range. This range might overlap multiple periods and is not limited to period boundaries. However, we make sure that the range is potentially covered by period.
* @param {Array} streams
Expand Down Expand Up @@ -272,6 +268,10 @@ function TimelineConverter() {
timelineAnchorAvailabilityOffset = now - range.end;
}

function getTimelineAnchorAvailabilityOffset() {
return timelineAnchorAvailabilityOffset;
}

function _adjustTimeBasedOnPeriodRanges(streams, time, isEndOfDvrWindow = false) {
try {
let i = 0;
Expand Down Expand Up @@ -360,7 +360,7 @@ function TimelineConverter() {
initialize,
getClientTimeOffset,
setClientTimeOffset,
getAvailabilityWindowAnchorTime,
getTimelineAnchorAvailabilityOffset,
calcAvailabilityStartTimeFromPresentationTime,
calcAvailabilityEndTimeFromPresentationTime,
calcPresentationTimeFromWallTime,
Expand Down