Skip to content

Commit

Permalink
Don't replace PresentationTimeline on MPD update
Browse files Browse the repository at this point in the history
Only update segment availability duration.

Issue #295

Change-Id: Ia73338be4c308169f28f5394c9d4ef5dbc8af304
  • Loading branch information
Timothy Drews committed Mar 31, 2016
1 parent 13a5f41 commit 0b4398f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 26 deletions.
55 changes: 29 additions & 26 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,40 +437,43 @@ shaka.dash.DashParser.prototype.parseManifest_ =
if (!this.networkingEngine_)
return;

// Determine |segmentAvailabilityDuration|.
if (presentationStartTime == null) {
// If this is not live, then ignore segment availability.
segmentAvailabilityDuration = null;
} else if (segmentAvailabilityDuration == null) {
// If there is no availability given and it's live, then the segments
// will always be available.
segmentAvailabilityDuration = Number.POSITIVE_INFINITY;
}

if (this.manifest_) {
this.manifest_.presentationTimeline.setSegmentAvailabiliyDuration(
segmentAvailabilityDuration);
} else {
if (segmentAvailabilityDuration == null) {
// If there is no availability given and it's live, then the segments
// will always be available.
segmentAvailabilityDuration = Number.POSITIVE_INFINITY;
if (presentationStartTime != null) {
// Offset the start time by @suggestedPresentationDelay. This has the
// effect of making the segments become available later than they
// actually are, so it causes a delay. Note that the DASH spec
// recommends that a default @suggestedPresentationDelay be used when
// one is not explicitly specified.
presentationStartTime +=
suggestedDelay != null ?
suggestedDelay :
shaka.dash.DashParser.DEFAULT_SUGGESTED_PRESENTATION_DELAY_;
}

// Offset the start time by @suggestedPresentationDelay. This has the
// effect of making the segments become available later than they
// actually are, so it causes a delay. Note that the DASH spec
// recommends that a default @suggestedPresentationDelay be used when one
// is not explicitly specified.
presentationStartTime +=
suggestedDelay != null ?
suggestedDelay :
shaka.dash.DashParser.DEFAULT_SUGGESTED_PRESENTATION_DELAY_;
}
shaka.log.v1('maxSegmentDuration:',
'explict=' + maxSegmentDuration,
'derived=' + context.maxSegmentDuration);

shaka.log.v1('maxSegmentDuration:',
'explict=' + maxSegmentDuration,
'derived=' + context.maxSegmentDuration);
var timeline = new shaka.media.PresentationTimeline(
duration || Number.POSITIVE_INFINITY,
presentationStartTime,
segmentAvailabilityDuration,
maxSegmentDuration || context.maxSegmentDuration,
offset);
var timeline = new shaka.media.PresentationTimeline(
duration || Number.POSITIVE_INFINITY,
presentationStartTime,
segmentAvailabilityDuration,
maxSegmentDuration || context.maxSegmentDuration,
offset);

if (this.manifest_) {
this.manifest_.presentationTimeline = timeline;
} else {
this.manifest_ = {
periods: periods,
presentationTimeline: timeline,
Expand Down
19 changes: 19 additions & 0 deletions lib/media/presentation_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ shaka.media.PresentationTimeline.prototype.getSegmentAvailabilityDuration =
};


/**
* Updates the presentation's segment availability duration. The segment
* availability duration can only be updated for live.
*
* @param {?number} segmentAvailabilityDuration The presentation's new segment
* availability duration in seconds.
*/
shaka.media.PresentationTimeline.prototype.setSegmentAvailabiliyDuration =
function(segmentAvailabilityDuration) {
goog.asserts.assert(
(this.segmentAvailabilityDuration_ == null &&
segmentAvailabilityDuration == null) ||
(this.segmentAvailabilityDuration_ != null &&
segmentAvailabilityDuration != null),
'Segment availability duration can only be updated for live');
this.segmentAvailabilityDuration_ = segmentAvailabilityDuration;
};


/**
* Gets the presentation's current segment availability start time. Segments
* ending at or before this time should be assumed to be unavailable.
Expand Down
22 changes: 22 additions & 0 deletions test/presentation_timeline_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,28 @@ describe('PresentationTimeline', function() {
Number.POSITIVE_INFINITY);
});

it('setSegmentAvailabiliyDuration', function() {
setElapsed(0);
var timeline = new shaka.media.PresentationTimeline(60, null, null, 10, 0);
expect(timeline.getSegmentAvailabilityDuration()).toBeNull();

timeline = new shaka.media.PresentationTimeline(
Number.POSITIVE_INFINITY, Date.now() / 1000.0, 20, 10, 0);
timeline.setSegmentAvailabiliyDuration(7);
expect(timeline.getSegmentAvailabilityDuration()).toBe(7);

timeline = new shaka.media.PresentationTimeline(
Number.POSITIVE_INFINITY, Date.now() / 1000.0, 20, 10, 0);
timeline.setSegmentAvailabiliyDuration(Number.POSITIVE_INFINITY);
expect(timeline.getSegmentAvailabilityDuration()).toBe(
Number.POSITIVE_INFINITY);

timeline = new shaka.media.PresentationTimeline(
60, null, null, 10, 0);
timeline.setSegmentAvailabiliyDuration(null);
expect(timeline.getSegmentAvailabilityDuration()).toBe(null);
});

it('clockOffset', function() {
// setElapsed sets the local clock. The server is 10 seconds ahead so it
// should return 10.
Expand Down

0 comments on commit 0b4398f

Please sign in to comment.