Skip to content

Commit

Permalink
Account for presentation delay in IPR seek range
Browse files Browse the repository at this point in the history
Closes #477

Change-Id: Ic171e89ab00c9af6b35ae205555e108946270c76
  • Loading branch information
joeyparrish committed Aug 30, 2016
1 parent 6bf002a commit b5334d6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/media/presentation_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ shaka.media.PresentationTimeline.prototype.getSegmentAvailabilityEnd =
* @export
*/
shaka.media.PresentationTimeline.prototype.getSeekRangeEnd = function() {
var delay = this.isLive() ? this.presentationDelay_ : 0;
var useDelay = this.isLive() || this.isInProgress();
var delay = useDelay ? this.presentationDelay_ : 0;
return Math.max(0, this.getSegmentAvailabilityEnd() - delay);
};

Expand Down
40 changes: 32 additions & 8 deletions test/media/presentation_timeline_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('PresentationTimeline', function() {
* @param {number} segmentAvailabilityDuration
* @param {number} maxSegmentDuration
* @param {number} clockOffset
* @param {number} presentationDelay
*
* @return {shaka.media.PresentationTimeline}
*/
Expand All @@ -53,9 +54,10 @@ describe('PresentationTimeline', function() {
presentationStartTime,
segmentAvailabilityDuration,
maxSegmentDuration,
clockOffset) {
var timeline =
new shaka.media.PresentationTimeline(presentationStartTime, 0);
clockOffset,
presentationDelay) {
var timeline = new shaka.media.PresentationTimeline(
presentationStartTime, presentationDelay);
timeline.setStatic(isStatic);
timeline.setDuration(duration || Infinity);
timeline.setSegmentAvailabilityDuration(segmentAvailabilityDuration);
Expand All @@ -75,7 +77,7 @@ describe('PresentationTimeline', function() {
var timeline = makePresentationTimeline(
/* static */ true, duration, /* start time */ null,
/* availability */ Infinity, /* max seg dur */ 10,
/* clock offset */ 0);
/* clock offset */ 0, /* presentation delay */ 0);
expect(timeline.isLive()).toBe(false);
expect(timeline.isInProgress()).toBe(false);
return timeline;
Expand All @@ -85,14 +87,15 @@ describe('PresentationTimeline', function() {
* Creates a IPR PresentationTimeline.
*
* @param {number} duration
* @param {number=} opt_delay
* @return {shaka.media.PresentationTimeline}
*/
function makeIprTimeline(duration) {
function makeIprTimeline(duration, opt_delay) {
var now = Date.now() / 1000;
var timeline = makePresentationTimeline(
/* static */ false, duration, /* start time */ now,
/* availability */ Infinity, /* max seg dur */ 10,
/* clock offset */ 0);
/* clock offset */ 0, opt_delay || 0);
expect(timeline.isLive()).toBe(false);
expect(timeline.isInProgress()).toBe(true);
return timeline;
Expand All @@ -102,13 +105,15 @@ describe('PresentationTimeline', function() {
* Creates a live PresentationTimeline.
*
* @param {number} availability
* @param {number=} opt_delay
* @return {shaka.media.PresentationTimeline}
*/
function makeLiveTimeline(availability) {
function makeLiveTimeline(availability, opt_delay) {
var now = Date.now() / 1000;
var timeline = makePresentationTimeline(
/* static */ false, /* duration */ Infinity, /* start time */ now,
availability, /* max seg dur */ 10, /* clock offset */ 0);
availability, /* max seg dur */ 10,
/* clock offset */ 0, opt_delay || 0);
expect(timeline.isLive()).toBe(true);
expect(timeline.isInProgress()).toBe(false);
return timeline;
Expand Down Expand Up @@ -309,5 +314,24 @@ describe('PresentationTimeline', function() {
expect(timeline.getSegmentAvailabilityEnd()).toBe(6);
});
});

describe('getSeekRangeEnd', function() {
it('accounts for delay for live and IPR', function() {
var timeline1 = makeIprTimeline(/* duration */ 60, /* delay */ 7);
var timeline2 = makeLiveTimeline(/* duration */ 60, /* delay */ 7);

setElapsed(11);
expect(timeline1.getSeekRangeEnd()).toBe(0);
expect(timeline2.getSeekRangeEnd()).toBe(0);

setElapsed(18);
expect(timeline1.getSeekRangeEnd()).toBe(1);
expect(timeline2.getSeekRangeEnd()).toBe(1);

setElapsed(37);
expect(timeline1.getSeekRangeEnd()).toBe(20);
expect(timeline2.getSeekRangeEnd()).toBe(20);
});
});
});

0 comments on commit b5334d6

Please sign in to comment.