Skip to content

Commit

Permalink
Fix bug with merging a period into itself
Browse files Browse the repository at this point in the history
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
  • Loading branch information
theodab authored and joeyparrish committed Jun 1, 2018
1 parent e76b9d1 commit f6a5b24
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/dash/segment_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -91,7 +103,7 @@ shaka.dash.SegmentTemplate.createStream = function(
}
}

if (!context.dynamic || !context.periodInfo.isLastPeriod) {
if (shouldFit) {
segmentIndex.fit(context.periodInfo.duration);
}

Expand Down

0 comments on commit f6a5b24

Please sign in to comment.