Skip to content

Commit

Permalink
Notify min segment start time when creating stream.
Browse files Browse the repository at this point in the history
Fixes #1601

Change-Id: I132f05a23129fca944e955cbf8a347e735724b37
  • Loading branch information
ismena committed Nov 7, 2018
1 parent 19a38ed commit 34408b9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/dash/segment_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ shaka.dash.SegmentTemplate.createStream = function(
if (!isUpdate) {
context.presentationTimeline.notifyMaxSegmentDuration(
info.segmentDuration);
context.presentationTimeline.notifyMinSegmentStartTime(
context.periodInfo.start);
}
segmentIndexFunctions = SegmentTemplate.createFromDuration_(context, info);
} else {
Expand Down
28 changes: 20 additions & 8 deletions lib/media/presentation_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,7 @@ shaka.media.PresentationTimeline.prototype.notifySegments = function(
const lastReferenceEndTime =
references[references.length - 1].endTime + periodStart;

if (this.minSegmentStartTime_ == null) {
// No data yet, and Math.min(null, startTime) is always 0. So just store
// the segment startTime.
this.minSegmentStartTime_ = firstReferenceStartTime;
} else {
this.minSegmentStartTime_ =
Math.min(this.minSegmentStartTime_, firstReferenceStartTime);
}
this.notifyMinSegmentStartTime(firstReferenceStartTime);

this.maxSegmentDuration_ = references.reduce(
function(max, r) { return Math.max(max, r.endTime - r.startTime); },
Expand All @@ -253,6 +246,25 @@ shaka.media.PresentationTimeline.prototype.notifySegments = function(
};


/**
* Gives PresentationTimeline a Stream's minimum segment start time.
*
* @param {number} startTime
* @export
*/
shaka.media.PresentationTimeline.prototype.notifyMinSegmentStartTime = function(
startTime) {
if (this.minSegmentStartTime_ == null) {
// No data yet, and Math.min(null, startTime) is always 0. So just store
// startTime.
this.minSegmentStartTime_ = startTime;
} else {
this.minSegmentStartTime_ =
Math.min(this.minSegmentStartTime_, startTime);
}
};


/**
* Gives PresentationTimeline a Stream's maximum segment duration so it can
* size and position the segment availability window. This function should be
Expand Down
13 changes: 13 additions & 0 deletions test/dash/dash_parser_segment_template_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ describe('DashParser SegmentTemplate', function() {
];
await Dash.testSegmentIndex(source, references);
});

it('presentation start is parsed correctly', function(done) {
let source = Dash.makeSimpleManifestText([
'<SegmentTemplate media="s$Number$.mp4" duration="60" />',
], 30 /* duration */, /* startTime */ 30);

fakeNetEngine.setResponseText('dummy://foo', source);
parser.start('dummy://foo', playerInterface)
.then(function(manifest) {
expect(manifest.presentationTimeline.getSeekRangeStart()).toBe(30);
})
.catch(fail).then(done);
});
});

describe('index', function() {
Expand Down

0 comments on commit 34408b9

Please sign in to comment.