diff --git a/lib/dash/dash_parser.js b/lib/dash/dash_parser.js index 9086d27d40..169e49200b 100644 --- a/lib/dash/dash_parser.js +++ b/lib/dash/dash_parser.js @@ -345,6 +345,19 @@ shaka.dash.DashParser = class { let presentationTimeline; if (this.manifest_) { presentationTimeline = this.manifest_.presentationTimeline; + + // Before processing an update, evict from all segment indexes. Some of + // them may not get updated otherwise if their corresponding Period + // element has been dropped from the manifest since the last update. + // Without this, playback will still work, but this is necessary to + // maintain conditions that we assert on for multi-Period content. + // This gives us confidence that our state is maintained correctly, and + // that the complex logic of multi-Period eviction and period-flattening + // is correct. See also: + // https://github.com/google/shaka-player/issues/3169#issuecomment-823580634 + for (const segmentIndex of Object.values(this.segmentIndexMap_)) { + segmentIndex.evict(presentationTimeline.getSegmentAvailabilityStart()); + } } else { // DASH IOP v3.0 suggests using a default delay between minBufferTime // and timeShiftBufferDepth. This is literally the range of all diff --git a/lib/media/segment_index.js b/lib/media/segment_index.js index c0d20c581b..95ffe13b57 100644 --- a/lib/media/segment_index.js +++ b/lib/media/segment_index.js @@ -595,7 +595,7 @@ shaka.media.MetaSegmentIndex = class extends shaka.media.SegmentIndex { appendSegmentIndex(segmentIndex) { goog.asserts.assert( this.indexes_.length == 0 || segmentIndex.numEvicted == 0, - 'Cannot have evicted segments in non-first Periods'); + 'Should not append a new segment index with already-evicted segments'); this.indexes_.push(segmentIndex); } @@ -655,7 +655,7 @@ shaka.media.MetaSegmentIndex = class extends shaka.media.SegmentIndex { for (const index of this.indexes_) { goog.asserts.assert( !sawSegments || index.numEvicted == 0, - 'Cannot have evicted segments in non-first Periods'); + 'Should not see evicted segments after available segments'); const reference = index.get(position - numPassedInEarlierIndexes); if (reference) {