Skip to content

Commit

Permalink
fix(DASH): Ignore early segments in a period (shaka-project#7910)
Browse files Browse the repository at this point in the history
Now we always are fitting the timeline
  • Loading branch information
avelad authored Jan 20, 2025
1 parent ad4f6b1 commit c7a93d7
Showing 1 changed file with 25 additions and 38 deletions.
63 changes: 25 additions & 38 deletions lib/dash/segment_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
Expand Down Expand Up @@ -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);
},
Expand Down Expand Up @@ -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<string>} */
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();
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -883,9 +867,7 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
}
}

if (shouldFit) {
this.fitTimeline();
}
this.fitTimeline();
}

/**
Expand Down Expand Up @@ -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_);

Expand Down

0 comments on commit c7a93d7

Please sign in to comment.