Skip to content

Commit a1fd74c

Browse files
aveladjoeyparrish
authored andcommitted
fix(DASH): Ignore early segments in a period (#7910)
Now we always are fitting the timeline Backported to v4.9.x
1 parent 207ab8c commit a1fd74c

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

lib/dash/segment_template.js

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,6 @@ shaka.dash.SegmentTemplate = class {
121121

122122
shaka.log.debug(`New manifest ${periodStart} - ${periodEnd}`);
123123

124-
/* When to fit segments. All refactors should honor/update this table:
125-
*
126-
* | dynamic | infinite | last | should | notes |
127-
* | | period | period | fit | |
128-
* | ------- | -------- | ------ | ------ | ------------------------- |
129-
* | F | F | X | T | typical VOD |
130-
* | F | T | X | X | impossible: infinite VOD |
131-
* | T | F | F | T | typical live, old period |
132-
* | T | F | T | F | typical IPR |
133-
* | T | T | F | X | impossible: old, infinite |
134-
* | T | T | T | F | typical live, new period |
135-
*/
136-
137-
// We never fit the final period of dynamic content, which could be
138-
// infinite live (with no limit to fit to) or IPR (which would expand the
139-
// most recent segment to the end of the presentation).
140-
const shouldFit = !(context.dynamic && context.periodInfo.isLastPeriod);
141-
142124
if (!segmentIndex) {
143125
shaka.log.debug(`Creating TSI with end ${periodEnd}`);
144126
segmentIndex = new TimelineSegmentIndex(
@@ -149,14 +131,13 @@ shaka.dash.SegmentTemplate = class {
149131
periodStart,
150132
periodEnd,
151133
initSegmentReference,
152-
shouldFit,
153134
aesKey,
154135
context.representation.segmentSequenceCadence,
155136
);
156137
} else {
157138
const tsi = /** @type {!TimelineSegmentIndex} */(segmentIndex);
158139
tsi.appendTemplateInfo(
159-
info, periodStart, periodEnd, shouldFit, initSegmentReference);
140+
info, periodStart, periodEnd, initSegmentReference);
160141

161142
const availabilityStart =
162143
context.presentationTimeline.getSegmentAvailabilityStart();
@@ -184,7 +165,7 @@ shaka.dash.SegmentTemplate = class {
184165
if (segmentIndex instanceof shaka.dash.TimelineSegmentIndex &&
185166
segmentIndex.isEmpty()) {
186167
segmentIndex.appendTemplateInfo(info, periodStart,
187-
periodEnd, shouldFit, initSegmentReference);
168+
periodEnd, initSegmentReference);
188169
}
189170
return Promise.resolve(segmentIndex);
190171
},
@@ -668,38 +649,42 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
668649
* @param {number} periodStart
669650
* @param {number} periodEnd
670651
* @param {shaka.media.InitSegmentReference} initSegmentReference
671-
* @param {boolean} shouldFit
672652
* @param {shaka.extern.aesKey|undefined} aesKey
673653
* @param {number} segmentSequenceCadence
674654
*/
675655
constructor(templateInfo, representationId, bandwidth, getBaseUris,
676-
periodStart, periodEnd, initSegmentReference, shouldFit,
656+
periodStart, periodEnd, initSegmentReference,
677657
aesKey, segmentSequenceCadence) {
678658
super([]);
679659

680660
/** @private {?shaka.dash.SegmentTemplate.SegmentTemplateInfo} */
681661
this.templateInfo_ = templateInfo;
662+
682663
/** @private {?string} */
683664
this.representationId_ = representationId;
665+
684666
/** @private {number} */
685667
this.bandwidth_ = bandwidth;
686-
/** @private {function():Array.<string>} */
668+
669+
/** @private {function(): Array<string>} */
687670
this.getBaseUris_ = getBaseUris;
671+
688672
/** @private {number} */
689673
this.periodStart_ = periodStart;
674+
690675
/** @private {number} */
691676
this.periodEnd_ = periodEnd;
677+
692678
/** @private {shaka.media.InitSegmentReference} */
693679
this.initSegmentReference_ = initSegmentReference;
680+
694681
/** @private {shaka.extern.aesKey|undefined} */
695682
this.aesKey_ = aesKey;
683+
696684
/** @private {number} */
697685
this.segmentSequenceCadence_ = segmentSequenceCadence;
698686

699-
700-
if (shouldFit) {
701-
this.fitTimeline();
702-
}
687+
this.fitTimeline();
703688
}
704689

705690
/**
@@ -767,11 +752,9 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
767752
* @param {shaka.dash.SegmentTemplate.SegmentTemplateInfo} info
768753
* @param {number} periodStart
769754
* @param {number} periodEnd
770-
* @param {boolean} shouldFit
771755
* @param {shaka.media.InitSegmentReference} initSegmentReference
772756
*/
773-
appendTemplateInfo(info, periodStart, periodEnd, shouldFit,
774-
initSegmentReference) {
757+
appendTemplateInfo(info, periodStart, periodEnd, initSegmentReference) {
775758
this.updateInitSegmentReference(initSegmentReference);
776759
if (!this.templateInfo_) {
777760
this.templateInfo_ = info;
@@ -805,9 +788,7 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
805788
}
806789
}
807790

808-
if (shouldFit) {
809-
this.fitTimeline();
810-
}
791+
this.fitTimeline();
811792
}
812793

813794
/**
@@ -852,14 +833,19 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
852833
return;
853834
}
854835
const timeline = this.templateInfo_.timeline;
855-
while (timeline.length) {
856-
const lastTimePeriod = timeline[timeline.length - 1];
857-
if (lastTimePeriod.start >= this.periodEnd_) {
858-
timeline.pop();
836+
goog.asserts.assert(timeline, 'Timeline should be non-null!');
837+
const newTimeline = [];
838+
for (const range of timeline) {
839+
if (range.start >= this.periodEnd_) {
840+
// Starts after end of period.
841+
} else if (range.end <= 0) {
842+
// Ends before start of period.
859843
} else {
860-
break;
844+
// Usable.
845+
newTimeline.push(range);
861846
}
862847
}
848+
this.templateInfo_.timeline = newTimeline;
863849

864850
this.evict(this.periodStart_);
865851

0 commit comments

Comments
 (0)