From 362d8a535435dd39a03b7214d3db77c41e68c0e1 Mon Sep 17 00:00:00 2001 From: Costel Madalin Grecu Date: Tue, 29 Mar 2016 11:20:56 +0300 Subject: [PATCH 1/5] Reproduce issue with merging last segment in a period --- test/segment_index_unit.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/segment_index_unit.js b/test/segment_index_unit.js index 116e50490c..25dce1a68b 100644 --- a/test/segment_index_unit.js +++ b/test/segment_index_unit.js @@ -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() { From 1060db901530759628daf6de70d413b761dec58c Mon Sep 17 00:00:00 2001 From: Costel Madalin Grecu Date: Tue, 29 Mar 2016 11:21:47 +0300 Subject: [PATCH 2/5] Fix issue with merging last segment in a period --- lib/media/segment_index.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/media/segment_index.js b/lib/media/segment_index.js index 5f9378a380..d6415a7664 100644 --- a/lib/media/segment_index.js +++ b/lib/media/segment_index.js @@ -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 the 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 <= + shaka.dash.MpdUtils.GAP_OVERLAP_TOLERANCE_SECONDS && + i == this.references_.length - 1 && + j == references.length - 1, + 'This should be un 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++; } From 013f1e6478f96f7ec3343ccbfd74f8a5a76d80e9 Mon Sep 17 00:00:00 2001 From: Costel Madalin Grecu Date: Tue, 29 Mar 2016 11:24:15 +0300 Subject: [PATCH 3/5] Remove outdated todo item --- lib/dash/mpd_utils.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/dash/mpd_utils.js b/lib/dash/mpd_utils.js index c3b47f2858..744a2055cd 100644 --- a/lib/dash/mpd_utils.js +++ b/lib/dash/mpd_utils.js @@ -298,9 +298,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] = From 862334e3ea91476ef556d0ad7247ab2f5503861e Mon Sep 17 00:00:00 2001 From: Costel Madalin Grecu Date: Tue, 29 Mar 2016 13:33:32 +0300 Subject: [PATCH 4/5] Fix coding style issues --- lib/media/segment_index.js | 2 +- test/segment_index_unit.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/media/segment_index.js b/lib/media/segment_index.js index d6415a7664..b2c20d3894 100644 --- a/lib/media/segment_index.js +++ b/lib/media/segment_index.js @@ -133,7 +133,7 @@ shaka.media.SegmentIndex.prototype.merge = function(references) { // expand last segment to the start of the next the period // so, it is valid to have end time updated to the // last segment reference in a period - if(r1.endTime != r2.endTime) + if (r1.endTime != r2.endTime) { goog.asserts.assert(r2.endTime - r1.endTime <= shaka.dash.MpdUtils.GAP_OVERLAP_TOLERANCE_SECONDS && diff --git a/test/segment_index_unit.js b/test/segment_index_unit.js index 25dce1a68b..7082ac5e66 100644 --- a/test/segment_index_unit.js +++ b/test/segment_index_unit.js @@ -238,7 +238,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { var references1 = [ makeReference(1, 10, 20, uri(10)), makeReference(2, 20, 30, uri(20)), - makeReference(3, 30, 49.987, uri(30)), + makeReference(3, 30, 49.987, uri(30)) ]; var index1 = new shaka.media.SegmentIndex(references1); From 863666de2b935c9e17f23290a34a8fb1dd00d8b9 Mon Sep 17 00:00:00 2001 From: Costel Madalin Grecu Date: Tue, 29 Mar 2016 23:11:19 +0300 Subject: [PATCH 5/5] Fix typos, update style --- lib/media/segment_index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/media/segment_index.js b/lib/media/segment_index.js index b2c20d3894..6fd0873d64 100644 --- a/lib/media/segment_index.js +++ b/lib/media/segment_index.js @@ -130,19 +130,19 @@ shaka.media.SegmentIndex.prototype.merge = function(references) { j++; } else { // when period is changed, fitSegmentReference will - // expand last segment to the start of the next the period + // 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 <= + 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 un update of the last segment in a period'); + 'This should be an update of the last segment in a period'); newReferences.push(r2); - } - else { + } else { // Drop the new reference if there's an old reference with the // same time. newReferences.push(r1);