diff --git a/lib/dash/segment_template.js b/lib/dash/segment_template.js index 28fc98f82b..4ff063aba9 100644 --- a/lib/dash/segment_template.js +++ b/lib/dash/segment_template.js @@ -131,24 +131,6 @@ shaka.dash.SegmentTemplate = class { shaka.log.debug(`New manifest ${periodStart} - ${periodEnd}`); - /* When to fit segments. All refactors should honor/update this table: - * - * | dynamic | infinite | last | should | notes | - * | | period | period | fit | | - * | ------- | -------- | ------ | ------ | ------------------------- | - * | F | F | X | T | typical VOD | - * | F | T | X | X | impossible: infinite VOD | - * | T | F | F | T | typical live, old period | - * | T | F | T | F | typical IPR | - * | T | T | F | X | impossible: old, infinite | - * | T | T | T | F | typical live, new period | - */ - - // We never fit the final period of dynamic content, which could be - // infinite live (with no limit to fit to) or IPR (which would expand the - // most recent segment to the end of the presentation). - const shouldFit = !(context.dynamic && context.periodInfo.isLastPeriod); - if (!segmentIndex) { shaka.log.debug(`Creating TSI with end ${periodEnd}`); segmentIndex = new TimelineSegmentIndex( @@ -160,14 +142,13 @@ shaka.dash.SegmentTemplate = class { periodStart, periodEnd, initSegmentReference, - shouldFit, aesKey, context.representation.segmentSequenceCadence, ); } else { const tsi = /** @type {!TimelineSegmentIndex} */(segmentIndex); tsi.appendTemplateInfo( - info, periodStart, periodEnd, shouldFit, initSegmentReference); + info, periodStart, periodEnd, initSegmentReference); const availabilityStart = context.presentationTimeline.getSegmentAvailabilityStart(); @@ -195,7 +176,7 @@ shaka.dash.SegmentTemplate = class { if (segmentIndex instanceof shaka.dash.TimelineSegmentIndex && segmentIndex.isEmpty()) { segmentIndex.appendTemplateInfo(info, periodStart, - periodEnd, shouldFit, initSegmentReference); + periodEnd, initSegmentReference); } return Promise.resolve(segmentIndex); }, @@ -744,40 +725,45 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex { * @param {number} periodStart * @param {number} periodEnd * @param {shaka.media.InitSegmentReference} initSegmentReference - * @param {boolean} shouldFit * @param {shaka.extern.aesKey|undefined} aesKey * @param {number} segmentSequenceCadence */ constructor(templateInfo, representationId, bandwidth, getBaseUris, - urlParams, periodStart, periodEnd, initSegmentReference, shouldFit, + urlParams, periodStart, periodEnd, initSegmentReference, aesKey, segmentSequenceCadence) { super([]); /** @private {?shaka.dash.SegmentTemplate.SegmentTemplateInfo} */ this.templateInfo_ = templateInfo; + /** @private {?string} */ this.representationId_ = representationId; + /** @private {number} */ this.bandwidth_ = bandwidth; + /** @private {function(): Array} */ this.getBaseUris_ = getBaseUris; + /** @private {function():string} */ this.urlParams_ = urlParams; + /** @private {number} */ this.periodStart_ = periodStart; + /** @private {number} */ this.periodEnd_ = periodEnd; + /** @private {shaka.media.InitSegmentReference} */ this.initSegmentReference_ = initSegmentReference; + /** @private {shaka.extern.aesKey|undefined} */ this.aesKey_ = aesKey; + /** @private {number} */ this.segmentSequenceCadence_ = segmentSequenceCadence; - - if (shouldFit) { - this.fitTimeline(); - } + this.fitTimeline(); } /** @@ -845,11 +831,9 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex { * @param {shaka.dash.SegmentTemplate.SegmentTemplateInfo} info * @param {number} periodStart * @param {number} periodEnd - * @param {boolean} shouldFit * @param {shaka.media.InitSegmentReference} initSegmentReference */ - appendTemplateInfo(info, periodStart, periodEnd, shouldFit, - initSegmentReference) { + appendTemplateInfo(info, periodStart, periodEnd, initSegmentReference) { this.updateInitSegmentReference(initSegmentReference); if (!this.templateInfo_) { this.templateInfo_ = info; @@ -883,9 +867,7 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex { } } - if (shouldFit) { - this.fitTimeline(); - } + this.fitTimeline(); } /** @@ -930,14 +912,19 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex { return; } const timeline = this.templateInfo_.timeline; - while (timeline.length) { - const lastTimePeriod = timeline[timeline.length - 1]; - if (lastTimePeriod.start >= this.periodEnd_) { - timeline.pop(); + goog.asserts.assert(timeline, 'Timeline should be non-null!'); + const newTimeline = []; + for (const range of timeline) { + if (range.start >= this.periodEnd_) { + // Starts after end of period. + } else if (range.end <= 0) { + // Ends before start of period. } else { - break; + // Usable. + newTimeline.push(range); } } + this.templateInfo_.timeline = newTimeline; this.evict(this.periodStart_);