Skip to content

Commit

Permalink
multiperiod fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tykus160 committed May 28, 2024
1 parent 682654c commit 9985e66
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
7 changes: 5 additions & 2 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,12 @@ shaka.dash.DashParser = class {
* @private
*/
removePatchPeriod_(periodId) {
const SegmentTemplate = shaka.dash.SegmentTemplate;
for (const contextId of this.contextCache_.keys()) {
if (contextId.startsWith(periodId)) {
const context = this.contextCache_.get(contextId);
SegmentTemplate.removeTimepoints(context);
this.parsePatchSegment_(contextId);
this.contextCache_.delete(contextId);
}
}
Expand Down Expand Up @@ -2062,8 +2066,7 @@ shaka.dash.DashParser = class {
const contextId = context.representation.id ?
context.period.id + ',' + context.representation.id : '';

if (this.patchLocationNodes_.length && context.periodInfo.isLastPeriod &&
representationId) {
if (this.patchLocationNodes_.length && representationId) {
this.contextCache_.set(`${context.period.id},${representationId}`,
this.cloneContext_(context));
}
Expand Down
28 changes: 24 additions & 4 deletions lib/dash/segment_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ shaka.dash.SegmentTemplate = class {
timelineNode.children = timepoints;
}

/**
* Removes all segments from timeline.
*
* @param {!shaka.dash.DashParser.Context} context
*/
static removeTimepoints(context) {
const MpdUtils = shaka.dash.MpdUtils;
const SegmentTemplate = shaka.dash.SegmentTemplate;

const timelineNode = MpdUtils.inheritChild(context,
SegmentTemplate.fromInheritance_, 'SegmentTimeline');
goog.asserts.assert(timelineNode, 'timeline node not found');
timelineNode.children = [];
}

/**
* @param {?shaka.dash.DashParser.InheritanceFrame} frame
* @return {?shaka.extern.xml.Node}
Expand Down Expand Up @@ -752,10 +767,15 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
this.templateInfo_.mediaTemplate = info.mediaTemplate;

// Append timeline
const lastCurrentEntry = currentTimeline[currentTimeline.length - 1];
const newEntries = info.timeline.filter((entry) => {
return entry.start >= lastCurrentEntry.end;
});
let newEntries;
if (currentTimeline.length) {
const lastCurrentEntry = currentTimeline[currentTimeline.length - 1];
newEntries = info.timeline.filter((entry) => {
return entry.start >= lastCurrentEntry.end;
});
} else {
newEntries = info.timeline.slice();
}

if (newEntries.length > 0) {
shaka.log.debug(`Appending ${newEntries.length} entries`);
Expand Down
21 changes: 18 additions & 3 deletions test/dash/dash_parser_segment_template_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,19 @@ describe('DashParser SegmentTemplate', () => {
expect(index.find(newStart)).toBe(10);
expect(index.find(newEnd - 1.0)).toBe(19);
});

it('appends new timeline to empty one', async () => {
const info = makeTemplateInfo([]);
const index = await makeTimelineSegmentIndex(info, false);

const newRanges = makeRanges(0, 2.0, 10);
const newTemplateInfo = makeTemplateInfo(newRanges);

const newEnd = newRanges[newRanges.length - 1].end;
index.appendTemplateInfo(newTemplateInfo, /* periodStart= */ 0, newEnd);
expect(index.find(0)).toBe(0);
expect(index.find(newEnd - 1.0)).toBe(9);
});
});

describe('evict', () => {
Expand All @@ -814,8 +827,10 @@ describe('DashParser SegmentTemplate', () => {
*/
async function makeTimelineSegmentIndex(info, delayPeriodEnd = true,
shouldFit = false) {
const isTimeline = info.timeline.length > 0;
// Period end may be a bit after the last timeline entry
let periodEnd = info.timeline[info.timeline.length - 1].end;
let periodEnd = isTimeline ?
info.timeline[info.timeline.length - 1].end : 0;
if (delayPeriodEnd) {
periodEnd += 1.0;
}
Expand All @@ -824,7 +839,7 @@ describe('DashParser SegmentTemplate', () => {
'<SegmentTemplate startNumber="0" duration="10"',
' media="$Number$-$Time$-$Bandwidth$.mp4">',
' <SegmentTimeline>',
' <S t="0" d="15" r="2" />',
isTimeline ? ' <S t="0" d="15" r="2" />' : '',
' </SegmentTimeline>',
'</SegmentTemplate>',
], /* duration= */ 45);
Expand All @@ -841,7 +856,7 @@ describe('DashParser SegmentTemplate', () => {
/** @type {?} */
const index = stream.segmentIndex;
index.release();
index.appendTemplateInfo(info, info.timeline[0].start,
index.appendTemplateInfo(info, isTimeline ? info.timeline[0].start : 0,
periodEnd, shouldFit);

return index;
Expand Down

0 comments on commit 9985e66

Please sign in to comment.