Skip to content

Commit

Permalink
Merge pull request #315 from cmgrecu/master
Browse files Browse the repository at this point in the history
Update end time of last segment in a period when new periods are added

Fixes #310
  • Loading branch information
joeyparrish committed Mar 29, 2016
2 parents 8b85e58 + 863666d commit a9b4cd8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
3 changes: 0 additions & 3 deletions lib/dash/mpd_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ shaka.dash.MpdUtils.fitSegmentReferences = function(
/** @const {number} */
var tolerance = shaka.dash.MpdUtils.GAP_OVERLAP_TOLERANCE_SECONDS;

// TODO: Update this function if we modify the SegmentReference to account
// for @presentationTimeOffset.

var firstReference = references[0];
if (firstReference.startTime <= tolerance) {
references[0] =
Expand Down
21 changes: 18 additions & 3 deletions lib/media/segment_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,24 @@ shaka.media.SegmentIndex.prototype.merge = function(references) {
shaka.log.warning('Refusing to rewrite original references on update!');
j++;
} else {
// Drop the new reference if there's an old reference with the same
// time.
newReferences.push(r1);
// when period is changed, fitSegmentReference will
// expand last segment to the start of the next period
// so, it is valid to have end time updated to the
// last segment reference in a period
if (r1.endTime != r2.endTime)
{
goog.asserts.assert(r2.endTime > r1.endTime &&
r2.endTime - r1.endTime <=
shaka.dash.MpdUtils.GAP_OVERLAP_TOLERANCE_SECONDS &&
i == this.references_.length - 1 &&
j == references.length - 1,
'This should be an update of the last segment in a period');
newReferences.push(r2);
} else {
// Drop the new reference if there's an old reference with the
// same time.
newReferences.push(r1);
}
i++;
j++;
}
Expand Down
22 changes: 22 additions & 0 deletions test/segment_index_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,28 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() {
expect(index1.references_[1]).toEqual(references2[0]);
expect(index1.references_[2]).toEqual(references2[1]);
});

it('last live stream reference when period change', function() {
var references1 = [
makeReference(1, 10, 20, uri(10)),
makeReference(2, 20, 30, uri(20)),
makeReference(3, 30, 49.987, uri(30))
];
var index1 = new shaka.media.SegmentIndex(references1);

// when period is changed, fitSegmentReference will
// expand last segment to the start of the next the period
var references2 = [
makeReference(2, 20, 30, uri(20)),
makeReference(3, 30, 50, uri(30))
];

index1.merge(references2);
expect(index1.references_.length).toBe(3);
expect(index1.references_[0]).toEqual(references1[0]);
expect(index1.references_[1]).toEqual(references2[0]);
expect(index1.references_[2]).toEqual(references2[1]);
});
});

describe('evict', function() {
Expand Down

0 comments on commit a9b4cd8

Please sign in to comment.