From b5334d6e8a910d2b6770f5f2ef4095316bbda514 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Mon, 29 Aug 2016 16:50:00 -0700 Subject: [PATCH] Account for presentation delay in IPR seek range Closes #477 Change-Id: Ic171e89ab00c9af6b35ae205555e108946270c76 --- lib/media/presentation_timeline.js | 3 +- test/media/presentation_timeline_unit.js | 40 +++++++++++++++++++----- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/lib/media/presentation_timeline.js b/lib/media/presentation_timeline.js index 2d196d83e5..832a415302 100644 --- a/lib/media/presentation_timeline.js +++ b/lib/media/presentation_timeline.js @@ -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); }; diff --git a/test/media/presentation_timeline_unit.js b/test/media/presentation_timeline_unit.js index 6d322ab37a..b545e3eb10 100644 --- a/test/media/presentation_timeline_unit.js +++ b/test/media/presentation_timeline_unit.js @@ -44,6 +44,7 @@ describe('PresentationTimeline', function() { * @param {number} segmentAvailabilityDuration * @param {number} maxSegmentDuration * @param {number} clockOffset + * @param {number} presentationDelay * * @return {shaka.media.PresentationTimeline} */ @@ -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); @@ -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; @@ -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; @@ -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; @@ -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); + }); + }); });