Skip to content

Commit

Permalink
Change bufferedAhead value calculation when switching periods.
Browse files Browse the repository at this point in the history
Our new logic calculating bufferedAhead value doesn't work when
it comes to switching periods for content with SegmentTemplates.
This change partially reorders code from the 12c07efc change.

Closes #545
Closes #537

Change-Id: I1d9c3ab8a185d0a3f419bbc442b366e697115dd2
  • Loading branch information
ismena committed Oct 11, 2016
1 parent 696332f commit 6d0f081
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,15 +841,24 @@ shaka.media.StreamingEngine.prototype.update_ = function(mediaState) {
// Compute how far we've buffered ahead of the playhead.
var playheadTime = this.playhead_.getTime();

var reference;

// Get the next timestamp we need.
// TODO: see if we can refactor this logic to be less cumbersome
var bufferEnd = this.mediaSourceEngine_.bufferEnd(mediaState.type);
var timeNeeded = this.getTimeNeeded_(mediaState, playheadTime);
shaka.log.v2(logPrefix, 'timeNeeded=' + timeNeeded);

var currentPeriodIndex = this.findPeriodContainingStream_(mediaState.stream);
var needPeriodIndex = this.findPeriodContainingTime_(timeNeeded);
var needPeriod = this.manifest_.periods[needPeriodIndex];
var reference = this.getSegmentReferenceNeeded_(
mediaState, playheadTime, bufferEnd, needPeriodIndex);

if (currentPeriodIndex != needPeriodIndex) {
reference = null;
} else {
reference = this.getSegmentReferenceNeeded_(
mediaState, playheadTime, bufferEnd, needPeriodIndex);
}

var bufferedAhead;
if (reference) {
Expand Down Expand Up @@ -893,8 +902,6 @@ shaka.media.StreamingEngine.prototype.update_ = function(mediaState) {
}
mediaState.endOfStream = false;

var currentPeriodIndex = this.findPeriodContainingStream_(mediaState.stream);

// Check if we've buffered to the end of the Period. This should be done
// before checking segment availability because the new Period may become
// available once it's switched to. Note that we don't use the non-existence
Expand Down

0 comments on commit 6d0f081

Please sign in to comment.