Skip to content

Commit

Permalink
fix(DASH): Segments being fetched out of the range of the timeline (#…
Browse files Browse the repository at this point in the history
…5889)

Fixes: #3952
  • Loading branch information
dave-nicholas authored Nov 16, 2023
1 parent 8e0ee8a commit d8aa24f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ coverage/
.DS_Store
.vscode
.babel-cache
.idea/
6 changes: 4 additions & 2 deletions lib/dash/mpd_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ shaka.dash.MpdUtils = class {
* @param {number} unscaledPresentationTimeOffset
* @param {number} periodDuration The Period's duration in seconds.
* Infinity indicates that the Period continues indefinitely.
* @param {number} startNumber
* @return {!Array.<shaka.media.PresentationTimeline.TimeRange>}
*/
static createTimeline(
segmentTimeline, timescale, unscaledPresentationTimeOffset,
periodDuration) {
periodDuration, startNumber) {
goog.asserts.assert(
timescale > 0 && timescale < Infinity,
'timescale must be a positive, finite integer');
Expand Down Expand Up @@ -243,6 +244,7 @@ shaka.dash.MpdUtils = class {
end: endTime / timescale,
unscaledStart: startTime,
partialSegments: partialSegments,
segmentPosition: timeline.length + startNumber,
};
timeline.push(item);

Expand Down Expand Up @@ -306,7 +308,7 @@ shaka.dash.MpdUtils = class {
if (timelineNode) {
timeline = MpdUtils.createTimeline(
timelineNode, timescale, unscaledPresentationTimeOffset,
context.periodInfo.duration || Infinity);
context.periodInfo.duration || Infinity, startNumber);
}

const scaledPresentationTimeOffset =
Expand Down
2 changes: 1 addition & 1 deletion lib/dash/segment_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
if (!ref) {
const mediaTemplate = this.templateInfo_.mediaTemplate;
const range = this.templateInfo_.timeline[correctedPosition];
const segmentReplacement = position + this.templateInfo_.startNumber;
const segmentReplacement = range.segmentPosition;
const timeReplacement = this.templateInfo_
.unscaledPresentationTimeOffset + range.unscaledStart;
const timestampOffset = this.periodStart_ -
Expand Down
5 changes: 4 additions & 1 deletion lib/media/presentation_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ shaka.media.PresentationTimeline = class {
* start: number,
* unscaledStart: number,
* end: number,
* partialSegments: number
* partialSegments: number,
* segmentPosition: number
* }}
*
* @description
Expand All @@ -634,6 +635,8 @@ shaka.media.PresentationTimeline = class {
* The end time (exclusive) of the range.
* @property {number} partialSegments
* The number of partial segments
* @property {number} segmentPosition
* The segment position of the timeline entry as it appears in the manifest
*
* @export
*/
Expand Down
3 changes: 2 additions & 1 deletion test/dash/mpd_utils_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ describe('MpdUtils', () => {
console.assert(segmentTimeline);

const timeline = MpdUtils.createTimeline(
segmentTimeline, timescale, presentationTimeOffset, periodDuration);
segmentTimeline, timescale, presentationTimeOffset,
periodDuration, 0);
expect(timeline).toEqual(
expected.map((c) => jasmine.objectContaining(c)));
}
Expand Down

0 comments on commit d8aa24f

Please sign in to comment.