Skip to content

Commit

Permalink
Improve live stream support
Browse files Browse the repository at this point in the history
* Support minimumUpdatePeriod="PT0S".
* Fix comparisons with very large timestamps.
* Assign default Period ID if not given.
* Increase suggestedPresentationDelay.

Closes #331
Closes #339

Change-Id: I091cb7ab3e2a1cdb38e4161fe139a96a10de3807
  • Loading branch information
TheModMaker committed Apr 21, 2016
1 parent d36bb6b commit cc243fa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
22 changes: 15 additions & 7 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ shaka.dash.DashParser.MIN_UPDATE_PERIOD_ = 3;
* @private
* @const {number}
*/
shaka.dash.DashParser.DEFAULT_SUGGESTED_PRESENTATION_DELAY_ = 2;
shaka.dash.DashParser.DEFAULT_SUGGESTED_PRESENTATION_DELAY_ = 5;


/**
Expand Down Expand Up @@ -301,7 +301,8 @@ shaka.dash.DashParser.prototype.start =
this.filterPeriod_ = filterPeriod;
this.onError_ = onError;
return this.requestManifest_().then(function() {
this.setUpdateTimer_(0);
if (this.networkingEngine_)
this.setUpdateTimer_(0);
return this.manifest_;
}.bind(this));
};
Expand Down Expand Up @@ -413,9 +414,8 @@ shaka.dash.DashParser.prototype.parseManifest_ =

var minBufferTime =
XmlUtils.parseAttr(mpd, 'minBufferTime', XmlUtils.parseDuration);
this.updatePeriod_ =
XmlUtils.parseAttr(mpd, 'minimumUpdatePeriod', XmlUtils.parseDuration) ||
0;
this.updatePeriod_ = /** @type {number} */ (XmlUtils.parseAttr(
mpd, 'minimumUpdatePeriod', XmlUtils.parseDuration, -1));

var presentationStartTime = XmlUtils.parseAttr(
mpd, 'availabilityStartTime', XmlUtils.parseDate);
Expand Down Expand Up @@ -593,6 +593,14 @@ shaka.dash.DashParser.prototype.parsePeriod_ = function(
context.period = this.createFrame_(periodInfo.node, null, baseUris);
context.periodInfo = periodInfo;

// If the period doesn't have an ID, give it one based on its start time.
if (!context.period.id) {
shaka.log.info(
'No Period ID given for Period with start time ' + periodInfo.start +
', Assigning a default');
context.period.id = '__shaka_period_' + periodInfo.start;
}

var adaptationSetNodes =
XmlUtils.findChildren(periodInfo.node, 'AdaptationSet');
var adaptationSets =
Expand Down Expand Up @@ -790,7 +798,7 @@ shaka.dash.DashParser.prototype.parseRepresentation_ = function(
*/
shaka.dash.DashParser.prototype.onUpdate_ = function() {
goog.asserts.assert(this.updateTimer_, 'Should only be called by timer');
goog.asserts.assert(this.updatePeriod_ > 0,
goog.asserts.assert(this.updatePeriod_ >= 0,
'There should be an update period');

shaka.log.info('Updating manifest...');
Expand Down Expand Up @@ -829,7 +837,7 @@ shaka.dash.DashParser.prototype.onUpdate_ = function() {
* @private
*/
shaka.dash.DashParser.prototype.setUpdateTimer_ = function(offset) {
if (this.updatePeriod_ == 0)
if (this.updatePeriod_ < 0)
return;
goog.asserts.assert(this.updateTimer_ == null,
'Timer should not be already set');
Expand Down
2 changes: 1 addition & 1 deletion lib/dash/mpd_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ shaka.dash.MpdUtils.SegmentInfo;
shaka.dash.MpdUtils.fillUriTemplate = function(
uriTemplate, representationId, number, bandwidth, time) {
if (time !== null) {
goog.asserts.assert(Math.abs(time - Math.round(time)) < 0.01,
goog.asserts.assert(Math.abs(time - Math.round(time)) < 0.2,
'Calculated $Time$ values must be close to integers!');
time = Math.round(time);
}
Expand Down
9 changes: 4 additions & 5 deletions lib/media/segment_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,10 @@ shaka.media.SegmentIndex.prototype.merge = function(references) {
shaka.log.warning('Refusing to rewrite original references on update!');
j++;
} else {
// when period is changed, fitSegmentReference will
// expand last segment to the start of the next period
// so, it is valid to have end time updated to the
// last segment reference in a period
if (r1.endTime != r2.endTime) {
// When period is changed, fitSegmentReference will expand the last
// segment to the start of the next period. So, it is valid to have end
// time updated to the last segment reference in a period
if (Math.abs(r1.endTime - r2.endTime) > 0.1) {
goog.asserts.assert(r2.endTime > r1.endTime &&
i == this.references_.length - 1 &&
j == references.length - 1,
Expand Down
6 changes: 3 additions & 3 deletions test/dash_parser_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ describe('DashParser.Live', function() {
expect(stream.findSegmentPosition(0)).not.toBe(null);
Dash.verifySegmentIndex(manifest, basicRefs);

// 15 seconds for @timeShiftBufferDepth and the first segment
// duration.
Date.now = function() { return (2 * 15) * 1000; };
// 15 seconds for @timeShiftBufferDepth, the first segment duration,
// and the @suggestedPresentationDuration.
Date.now = function() { return (2 * 15 + 5) * 1000; };
return delayForUpdatePeriod().then(function() {
// The first reference should have been evicted.
expect(stream.findSegmentPosition(0)).toBe(null);
Expand Down
2 changes: 1 addition & 1 deletion test/segment_index_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() {
var references1 = [
makeReference(1, 10, 20, uri(10)),
makeReference(2, 20, 30, uri(20)),
makeReference(3, 30, 49.987, uri(30))
makeReference(3, 30, 49.887, uri(30))
];
var index1 = new shaka.media.SegmentIndex(references1);

Expand Down

0 comments on commit cc243fa

Please sign in to comment.