Skip to content

Commit

Permalink
Fix SegmentTemplate w/ duration for live
Browse files Browse the repository at this point in the history
When calculating segment references, the end time should be capped at
the period's end, except when the period has no end.

Closes #1204

Change-Id: Ia608452706bbc3fd847a645197e8a0cb57d7aaec
  • Loading branch information
joeyparrish committed Jan 19, 2018
1 parent 86377ab commit 00843a2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/dash/segment_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ shaka.dash.SegmentTemplate.createFromDuration_ = function(context, info) {
position * segmentDuration - scaledPresentationTimeOffset;
// Cap the segment end at the period end, to avoid period transition issues
// in StreamingEngine.
var segmentEnd = Math.min(segmentStart + segmentDuration, periodDuration);
var segmentEnd = segmentStart + segmentDuration;
if (periodDuration) segmentEnd = Math.min(segmentEnd, periodDuration);

// Do not construct segments references that should not exist.
if (segmentEnd < 0)
Expand Down
23 changes: 23 additions & 0 deletions test/dash/dash_parser_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,29 @@ describe('DashParser Live', function() {
basicLines, basicRefs, updateLines, updateRefs, partialUpdateLines);
});

describe('SegmentTemplate w/ duration', function() {
var templateLines = [
'<SegmentTemplate startNumber="1" media="s$Number$.mp4" duration="2" />'
];

it('produces sane references without assertions', function(done) {
var manifest = makeSimpleLiveManifestText(templateLines, updateTime);

fakeNetEngine.setResponseMapAsText({'dummy://foo': manifest});
parser.start('dummy://foo', playerInterface).then(function(manifest) {
expect(manifest.periods.length).toBe(1);
var stream = manifest.periods[0].variants[0].video;

// In https://github.com/google/shaka-player/issues/1204, this
// failed an assertion and returned endTime == 0.
var ref = stream.getSegmentReference(1);
expect(ref.endTime).toBeGreaterThan(0);
}).catch(fail).then(done);
shaka.polyfill.Promise.flush();
});
});


describe('EventStream', function() {
/** @const */
var originalManifest = [
Expand Down

0 comments on commit 00843a2

Please sign in to comment.