Skip to content

Commit bcb6a92

Browse files
committed
fix(DASH): Ignore early segments in a period (#7910)
Now we always are fitting the timeline
1 parent c5a1ead commit bcb6a92

File tree

1 file changed

+25
-38
lines changed

1 file changed

+25
-38
lines changed

lib/dash/segment_template.js

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

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

134-
/* When to fit segments. All refactors should honor/update this table:
135-
*
136-
* | dynamic | infinite | last | should | notes |
137-
* | | period | period | fit | |
138-
* | ------- | -------- | ------ | ------ | ------------------------- |
139-
* | F | F | X | T | typical VOD |
140-
* | F | T | X | X | impossible: infinite VOD |
141-
* | T | F | F | T | typical live, old period |
142-
* | T | F | T | F | typical IPR |
143-
* | T | T | F | X | impossible: old, infinite |
144-
* | T | T | T | F | typical live, new period |
145-
*/
146-
147-
// We never fit the final period of dynamic content, which could be
148-
// infinite live (with no limit to fit to) or IPR (which would expand the
149-
// most recent segment to the end of the presentation).
150-
const shouldFit = !(context.dynamic && context.periodInfo.isLastPeriod);
151-
152134
if (!segmentIndex) {
153135
shaka.log.debug(`Creating TSI with end ${periodEnd}`);
154136
segmentIndex = new TimelineSegmentIndex(
@@ -160,14 +142,13 @@ shaka.dash.SegmentTemplate = class {
160142
periodStart,
161143
periodEnd,
162144
initSegmentReference,
163-
shouldFit,
164145
aesKey,
165146
context.representation.segmentSequenceCadence,
166147
);
167148
} else {
168149
const tsi = /** @type {!TimelineSegmentIndex} */(segmentIndex);
169150
tsi.appendTemplateInfo(
170-
info, periodStart, periodEnd, shouldFit, initSegmentReference);
151+
info, periodStart, periodEnd, initSegmentReference);
171152

172153
const availabilityStart =
173154
context.presentationTimeline.getSegmentAvailabilityStart();
@@ -195,7 +176,7 @@ shaka.dash.SegmentTemplate = class {
195176
if (segmentIndex instanceof shaka.dash.TimelineSegmentIndex &&
196177
segmentIndex.isEmpty()) {
197178
segmentIndex.appendTemplateInfo(info, periodStart,
198-
periodEnd, shouldFit, initSegmentReference);
179+
periodEnd, initSegmentReference);
199180
}
200181
return Promise.resolve(segmentIndex);
201182
},
@@ -744,40 +725,45 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
744725
* @param {number} periodStart
745726
* @param {number} periodEnd
746727
* @param {shaka.media.InitSegmentReference} initSegmentReference
747-
* @param {boolean} shouldFit
748728
* @param {shaka.extern.aesKey|undefined} aesKey
749729
* @param {number} segmentSequenceCadence
750730
*/
751731
constructor(templateInfo, representationId, bandwidth, getBaseUris,
752-
urlParams, periodStart, periodEnd, initSegmentReference, shouldFit,
732+
urlParams, periodStart, periodEnd, initSegmentReference,
753733
aesKey, segmentSequenceCadence) {
754734
super([]);
755735

756736
/** @private {?shaka.dash.SegmentTemplate.SegmentTemplateInfo} */
757737
this.templateInfo_ = templateInfo;
738+
758739
/** @private {?string} */
759740
this.representationId_ = representationId;
741+
760742
/** @private {number} */
761743
this.bandwidth_ = bandwidth;
744+
762745
/** @private {function():Array.<string>} */
763746
this.getBaseUris_ = getBaseUris;
747+
764748
/** @private {function():string} */
765749
this.urlParams_ = urlParams;
750+
766751
/** @private {number} */
767752
this.periodStart_ = periodStart;
753+
768754
/** @private {number} */
769755
this.periodEnd_ = periodEnd;
756+
770757
/** @private {shaka.media.InitSegmentReference} */
771758
this.initSegmentReference_ = initSegmentReference;
759+
772760
/** @private {shaka.extern.aesKey|undefined} */
773761
this.aesKey_ = aesKey;
762+
774763
/** @private {number} */
775764
this.segmentSequenceCadence_ = segmentSequenceCadence;
776765

777-
778-
if (shouldFit) {
779-
this.fitTimeline();
780-
}
766+
this.fitTimeline();
781767
}
782768

783769
/**
@@ -845,11 +831,9 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
845831
* @param {shaka.dash.SegmentTemplate.SegmentTemplateInfo} info
846832
* @param {number} periodStart
847833
* @param {number} periodEnd
848-
* @param {boolean} shouldFit
849834
* @param {shaka.media.InitSegmentReference} initSegmentReference
850835
*/
851-
appendTemplateInfo(info, periodStart, periodEnd, shouldFit,
852-
initSegmentReference) {
836+
appendTemplateInfo(info, periodStart, periodEnd, initSegmentReference) {
853837
this.updateInitSegmentReference(initSegmentReference);
854838
if (!this.templateInfo_) {
855839
this.templateInfo_ = info;
@@ -883,9 +867,7 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
883867
}
884868
}
885869

886-
if (shouldFit) {
887-
this.fitTimeline();
888-
}
870+
this.fitTimeline();
889871
}
890872

891873
/**
@@ -930,14 +912,19 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
930912
return;
931913
}
932914
const timeline = this.templateInfo_.timeline;
933-
while (timeline.length) {
934-
const lastTimePeriod = timeline[timeline.length - 1];
935-
if (lastTimePeriod.start >= this.periodEnd_) {
936-
timeline.pop();
915+
goog.asserts.assert(timeline, 'Timeline should be non-null!');
916+
const newTimeline = [];
917+
for (const range of timeline) {
918+
if (range.start >= this.periodEnd_) {
919+
// Starts after end of period.
920+
} else if (range.end <= 0) {
921+
// Ends before start of period.
937922
} else {
938-
break;
923+
// Usable.
924+
newTimeline.push(range);
939925
}
940926
}
927+
this.templateInfo_.timeline = newTimeline;
941928

942929
this.evict(this.periodStart_);
943930

0 commit comments

Comments
 (0)