From f6a5b2445b7237e33c87655bbcbe0fc31a4ffb53 Mon Sep 17 00:00:00 2001 From: Theodore Abshire Date: Tue, 29 May 2018 14:47:51 -0700 Subject: [PATCH] Fix bug with merging a period into itself When we try to merge two SegmentIndex objects, we check to make sure that they are sequential. Then, after merging the various SegmentIndexes, they are fit. This causes problems when trying to merge two identical periods together, an operation that could potentially happen in a live stream. SegmentIndex.merge was comparing the post-fit version of one SegmentIndex with the pre-fit version of another, causing it to believe that the two SegmentIndex had different end times when really they were identical. This change causes SegmentTemplate.createStream to perform an extra fit operation before merging, to avoid that problem. Closes #1448 Backported to v2.4.x Change-Id: If2e9a9a91de344b7ab8cd9004da0553b324cb599 --- lib/dash/segment_template.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/dash/segment_template.js b/lib/dash/segment_template.js index ef28cad529..2a7c7acbda 100644 --- a/lib/dash/segment_template.js +++ b/lib/dash/segment_template.js @@ -78,7 +78,19 @@ shaka.dash.SegmentTemplate.createStream = function( let references = SegmentTemplate.createFromTimeline_(context, info); + // Don't fit live content, since it might receive more segments. + // Unless that live content is multi-period; it's safe to fit every period + // but the last one, since only the last period might receive new segments. + let shouldFit = !context.dynamic || !context.periodInfo.isLastPeriod; + if (segmentIndex) { + if (shouldFit) { + // Fit the new references before merging them, so that the merge + // algorithm has a more accurate view of their start and end times. + let wrapper = new shaka.media.SegmentIndex(references); + wrapper.fit(context.periodInfo.duration); + } + segmentIndex.merge(references); let start = context.presentationTimeline.getSegmentAvailabilityStart(); segmentIndex.evict(start - context.periodInfo.start); @@ -91,7 +103,7 @@ shaka.dash.SegmentTemplate.createStream = function( } } - if (!context.dynamic || !context.periodInfo.isLastPeriod) { + if (shouldFit) { segmentIndex.fit(context.periodInfo.duration); }