Skip to content

Commit

Permalink
Attempt to fetch one chunk prior on seeking
Browse files Browse the repository at this point in the history
As per issue shaka-project#330, manifests are only required to be approx.
correct with respect to their description of the media segments.
In order to avoid stalling when seeking through content like this,
fetch the chunk prior to the one that supposedly contains the
current time.

This is an attempt to apply a similar fix to Ia7bb74d0120.
  • Loading branch information
Sanborn Hilland committed Jun 30, 2016
1 parent f1715de commit f05b390
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/media/segment_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ shaka.media.SegmentIndex.prototype.find = function(time) {
};


/**
* Finds a SegmentReference immediately prior to the requested time.
*
* This function can trigger an update, which may add or remove
* SegmentReferences.
*
* @param {number} time The time in seconds.
* @return {shaka.media.SegmentReference} The SegmentReference prior to the
* specified time, or null if no such SegmentReference exists.
*/
shaka.media.SegmentIndex.prototype.findBefore = function(time) {
var i = shaka.media.SegmentReference.find(this.references, time);
return i <= 0 ? null : this.references[i - 1];
};


/**
* Integrates |segmentIndex| into this SegmentIndex. "Integration" is
* implementation dependent, but can be assumed to combine the two
Expand Down
6 changes: 5 additions & 1 deletion lib/media/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,13 @@ shaka.media.Stream.prototype.getNext_ = function(
if (last != null) {
return last.endTime != null ? segmentIndex.find(last.endTime) : null;
} else {
// Try to get the segment prior to currentTime in order to gracefully handle
// cases where the manifest description of segment durations is different
// than the actual duration of segments as per #330.
// Return the last SegmentReference if no segments have been inserted so
// that we will always compute a timestamp correction and resolve started().
return segmentIndex.find(currentTime) ||
return segmentIndex.findBefore(currentTime) ||
segmentIndex.find(currentTime) ||
(segmentIndex.length() ? segmentIndex.last() : null);
}
};
Expand Down

0 comments on commit f05b390

Please sign in to comment.