Skip to content

Commit

Permalink
Remove clientServerTimeShift from _calcAvailabilityTimeFromPresentati…
Browse files Browse the repository at this point in the history
…onTime and use it in getClientReferenceTime() instead before requesting a segment.
  • Loading branch information
dsilhavy committed Sep 6, 2021
1 parent 66bc8f9 commit 6a0d37c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
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
// 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);
// refTime serves as an anchor time to compare the availability time of the segments against.
const refTime = timelineConverter.getClientReferenceTime();
return segment.availabilityStartTime.getTime() <= refTime && (!isFinite(segment.availabilityEndTime) || segment.availabilityEndTime.getTime() >= refTime);
}

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

/**
* Returns a "now" reference time for the client to compare the availability time of a segment against.
* Takes the client/server drift into account
*/
function getClientReferenceTime() {
return Date.now() - (timelineAnchorAvailabilityOffset * 1000) + (clientServerTimeShift * 1000);
}

function _calcAvailabilityTimeFromPresentationTime(presentationEndTime, representation, isDynamic, calculateAvailabilityEndTime) {
let availabilityTime;
let mpd = representation.adaptation.period.mpd;
Expand All @@ -78,7 +86,7 @@ function TimelineConverter() {
// When not present, the value is infinite.
if (isDynamic && mpd.timeShiftBufferDepth !== Number.POSITIVE_INFINITY) {
// SAET = SAST + TSBD + seg@duration
availabilityTime = new Date(availabilityStartTime.getTime() + ((presentationEndTime - clientServerTimeShift + mpd.timeShiftBufferDepth) * 1000));
availabilityTime = new Date(availabilityStartTime.getTime() + ((presentationEndTime + mpd.timeShiftBufferDepth) * 1000));
} else {
availabilityTime = mpd.availabilityEndTime;
}
Expand All @@ -88,7 +96,7 @@ function TimelineConverter() {
// ASAST = SAST - ATO
const availabilityTimeOffset = representation.availabilityTimeOffset;
// presentationEndTime = Period@start + seg@presentationStartTime + Segment@duration
availabilityTime = new Date(availabilityStartTime.getTime() + (presentationEndTime - clientServerTimeShift - availabilityTimeOffset) * 1000);
availabilityTime = new Date(availabilityStartTime.getTime() + (presentationEndTime - availabilityTimeOffset) * 1000);
} else {
// in static mpd, all segments are available at the same time
availabilityTime = availabilityStartTime;
Expand Down Expand Up @@ -268,10 +276,6 @@ 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 +364,7 @@ function TimelineConverter() {
initialize,
getClientTimeOffset,
setClientTimeOffset,
getTimelineAnchorAvailabilityOffset,
getClientReferenceTime,
calcAvailabilityStartTimeFromPresentationTime,
calcAvailabilityEndTimeFromPresentationTime,
calcPresentationTimeFromWallTime,
Expand Down

0 comments on commit 6a0d37c

Please sign in to comment.