Skip to content

Commit

Permalink
fix(DASH): Allow mixing SegmentTemplate-SegmentTimeline with SegmentT…
Browse files Browse the repository at this point in the history
…emplate-numbering (#7286)

Fixes #7192
  • Loading branch information
avelad authored and joeyparrish committed Sep 13, 2024
1 parent a5b63d0 commit 848bd37
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/dash/segment_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,19 @@ shaka.dash.SegmentTemplate = class {
};
} else if (info.segmentDuration) {
if (!isUpdate && context.adaptationSet.contentType !== 'image') {
const periodStart = context.periodInfo.start;
const periodId = context.period.id;
const initialPeriodDuration = context.periodInfo.duration;
const periodDuration =
(periodId != null && periodDurationMap[periodId]) ||
initialPeriodDuration;
const periodEnd = periodDuration ?
(periodStart + periodDuration) : Infinity;

context.presentationTimeline.notifyMaxSegmentDuration(
info.segmentDuration);
context.presentationTimeline.notifyMinSegmentStartTime(
context.periodInfo.start);
context.presentationTimeline.notifyPeriodDuration(
periodStart, periodEnd);
}

return {
Expand Down
16 changes: 16 additions & 0 deletions lib/media/presentation_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,22 @@ shaka.media.PresentationTimeline = class {
}


/**
* Gives PresentationTimeline an startTime and endTime of the period.
* This should be only set for Dash.
*
* @param {number} startTime
* @param {number} endTime
* @export
*/
notifyPeriodDuration(startTime, endTime) {
this.notifyMinSegmentStartTime(startTime);
if (endTime != Infinity && !this.isLive()) {
this.maxSegmentEndTime_ = Math.max(this.maxSegmentEndTime_, endTime);
}
}


/**
* Gets the end time of the last available segment.
*
Expand Down
66 changes: 66 additions & 0 deletions test/dash/dash_parser_manifest_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3573,4 +3573,70 @@ describe('DashParser Manifest', () => {
.toEqual(['dummy://foo/init.mp4?a=1']);
});
});

it('mixing SegmentTemplate-SegmentTimeline with SegmentTemplate-numbering', async () => { // eslint-disable-line max-len
const manifestText = [
'<MPD type="static">',
' <Period id="1" duration="PT2S">',
' <AdaptationSet id="2" mimeType="video/mp4">',
' <Representation id="3" width="640" height="480">',
' <SegmentTemplate startNumber="1" media="l-$Number$.mp4">',
' <SegmentTimeline>',
' <S t="0" d="2" />',
' </SegmentTimeline>',
' </SegmentTemplate>',
' </Representation>',
' </AdaptationSet>',
' </Period>',
' <Period id="4" duration="PT30S">',
' <AdaptationSet id="5" mimeType="video/mp4">',
' <SegmentTemplate media="$Number$.mp4" duration="1" />',
' <Representation id="6" width="640" height="480" />',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');

fakeNetEngine.setResponseText('dummy://foo', manifestText);

/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);

const timeline = manifest.presentationTimeline;
expect(timeline.getSeekRangeStart()).toBe(0);
expect(timeline.getSeekRangeEnd()).toBe(32);
});

it('mixing SegmentTemplate-numbering with SegmentTemplate-SegmentTimeline', async () => { // eslint-disable-line max-len
const manifestText = [
'<MPD type="static">',
' <Period id="4" duration="PT30S">',
' <AdaptationSet id="5" mimeType="video/mp4">',
' <SegmentTemplate media="$Number$.mp4" duration="1" />',
' <Representation id="6" width="640" height="480" />',
' </AdaptationSet>',
' </Period>',
' <Period id="1" duration="PT2S">',
' <AdaptationSet id="2" mimeType="video/mp4">',
' <Representation id="3" width="640" height="480">',
' <SegmentTemplate startNumber="1" media="l-$Number$.mp4">',
' <SegmentTimeline>',
' <S t="0" d="2" />',
' </SegmentTimeline>',
' </SegmentTemplate>',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');

fakeNetEngine.setResponseText('dummy://foo', manifestText);

/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);

const timeline = manifest.presentationTimeline;
expect(timeline.getSeekRangeStart()).toBe(0);
expect(timeline.getSeekRangeEnd()).toBe(32);
});
});

0 comments on commit 848bd37

Please sign in to comment.