From b3166db4bc7cac968a03796bc9c2d7e598fb88c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Fri, 9 Jul 2021 04:21:39 +0200 Subject: [PATCH] fix: Fix DASH transition from dynamic to static (#3497) Close: #3376 --- lib/media/presentation_timeline.js | 4 +++- test/media/presentation_timeline_unit.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/media/presentation_timeline.js b/lib/media/presentation_timeline.js index ceeaccd2fb..04202c771a 100644 --- a/lib/media/presentation_timeline.js +++ b/lib/media/presentation_timeline.js @@ -361,8 +361,10 @@ shaka.media.PresentationTimeline = class { */ getSegmentAvailabilityEnd() { if (!this.isLive() && !this.isInProgress()) { - return this.duration_; + // It's a static manifest (can also be a dynamic->static conversion) + return this.maxSegmentEndTime_ || this.duration_; } + // Can be either live or "in-progress recording" (live with known duration) return Math.min(this.getLiveEdge_() + this.availabilityTimeOffset_, this.duration_); } diff --git a/test/media/presentation_timeline_unit.js b/test/media/presentation_timeline_unit.js index 38a8a9e01a..73c71fd606 100644 --- a/test/media/presentation_timeline_unit.js +++ b/test/media/presentation_timeline_unit.js @@ -290,6 +290,25 @@ describe('PresentationTimeline', () => { // last segment time (50) expect(timeline.getSegmentAvailabilityEnd()).toBe(50); }); + + it('calculates time when there a transition of live to static', () => { + const timeline = makeLiveTimeline(/* availability= */ 20); + + const ref1 = makeSegmentReference(0, 10); + const ref2 = makeSegmentReference(10, 20); + const ref3 = makeSegmentReference(20, 30); + const ref4 = makeSegmentReference(30, 40); + const ref5 = makeSegmentReference(40, 50); + + setElapsed(50); + timeline.notifySegments([ref1, ref2, ref3, ref4, ref5]); + + expect(timeline.getSegmentAvailabilityEnd()).toBe(50); + + timeline.setStatic(true); + + expect(timeline.getSegmentAvailabilityEnd()).toBe(50); + }); }); describe('getDuration', () => {