Skip to content

Commit

Permalink
Fix chopped playback in MS Edge
Browse files Browse the repository at this point in the history
Fudge the append window end to fix a playback bug in Edge.

Because Edge does not seem to implement MP4 edit lists correctly, we
may end up with some audio truncation and a gap.  If we fudge the end
of the append window a bit, we avoid this truncation and we get a
continuous buffered range and smooth playback.

Fixes #1597
Fixed #1435

Change-Id: If28f3f5499dbf5ad9d33ee4859f95ebd91ad3e59
  • Loading branch information
joeyparrish committed Nov 30, 2018
1 parent 71322df commit 49ce58b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/media/gap_jumping_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ shaka.media.GapJumpingController.prototype.onPollGapJump_ = function() {
if (this.config_.jumpLargeGaps && !event.defaultPrevented) {
jumpLargeGap = true;
} else {
shaka.log.info('Ignoring large gap at', currentTime);
shaka.log.info('Ignoring large gap at', currentTime, 'size', jumpSize);
}
}

Expand Down
39 changes: 29 additions & 10 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ shaka.media.StreamingEngine.MediaState_;


/**
* The fudge factor for the appendWindowStart. By adjusting the window
* backward, we avoid rounding errors that could cause us to remove the keyframe
* at the start of the Period.
* The fudge factor for appendWindowStart. By adjusting the window backward, we
* avoid rounding errors that could cause us to remove the keyframe at the start
* of the Period.
*
* NOTE: This was increased as part of the solution to
* https://github.com/google/shaka-player/issues/1281
Expand All @@ -307,6 +307,20 @@ shaka.media.StreamingEngine.MediaState_;
shaka.media.StreamingEngine.APPEND_WINDOW_START_FUDGE_ = 0.1;


/**
* The fudge factor for appendWindowEnd. By adjusting the window backward, we
* avoid rounding errors that could cause us to remove the last few samples of
* the Period. This rounding error could then create an artificial gap and a
* stutter when the gap-jumping logic takes over.
*
* https://github.com/google/shaka-player/issues/1597
*
* @const {number}
* @private
*/
shaka.media.StreamingEngine.APPEND_WINDOW_END_FUDGE_ = 0.01;


/**
* The maximum number of segments by which a stream can get ahead of other
* streams.
Expand Down Expand Up @@ -1482,9 +1496,10 @@ shaka.media.StreamingEngine.prototype.getSegmentReferenceIfAvailable_ =
*/
shaka.media.StreamingEngine.prototype.fetchAndAppend_ = function(
mediaState, playheadTime, currentPeriodIndex, reference) {
let logPrefix = shaka.media.StreamingEngine.logPrefix_(mediaState);
const ContentType = shaka.util.ManifestParserUtils.ContentType;
let currentPeriod = this.manifest_.periods[currentPeriodIndex];
const StreamingEngine = shaka.media.StreamingEngine;
const logPrefix = StreamingEngine.logPrefix_(mediaState);
const currentPeriod = this.manifest_.periods[currentPeriodIndex];

shaka.log.v1(logPrefix,
'fetchAndAppend_:',
Expand All @@ -1504,11 +1519,15 @@ shaka.media.StreamingEngine.prototype.fetchAndAppend_ = function(
// Compute the append window.
let duration = this.manifest_.presentationTimeline.getDuration();
let followingPeriod = this.manifest_.periods[currentPeriodIndex + 1];

// Rounding issues can cause us to remove the first frame of the Period, so
// reduce the start time slightly.
let windowFudge = shaka.media.StreamingEngine.APPEND_WINDOW_START_FUDGE_;
let appendWindowStart = Math.max(0, currentPeriod.startTime - windowFudge);
let appendWindowEnd = followingPeriod ? followingPeriod.startTime : duration;
const appendWindowStart = Math.max(0,
currentPeriod.startTime - StreamingEngine.APPEND_WINDOW_START_FUDGE_);
const appendWindowEnd = followingPeriod ?
followingPeriod.startTime + StreamingEngine.APPEND_WINDOW_END_FUDGE_ :
duration;

goog.asserts.assert(
reference.startTime <= appendWindowEnd,
logPrefix + ' segment should start before append window end');
Expand Down Expand Up @@ -1709,7 +1728,7 @@ shaka.media.StreamingEngine.prototype.initSourceBuffer_ = function(
currentPeriod.startTime - mediaState.stream.presentationTimeOffset;
shaka.log.v1(logPrefix, 'setting timestamp offset to ' + timestampOffset);
shaka.log.v1(logPrefix,
'setting appstart window start to ' + appendWindowStart);
'setting append window start to ' + appendWindowStart);
shaka.log.v1(logPrefix, 'setting append window end to ' + appendWindowEnd);
let setStreamProperties =
this.playerInterface_.mediaSourceEngine.setStreamProperties(
Expand Down Expand Up @@ -2187,7 +2206,7 @@ shaka.media.StreamingEngine.prototype.fetch_ = function(reference) {
if (reference.endByte != null) range += reference.endByte;
request.headers['Range'] = range;
}
shaka.log.v2('fetching: reference=' + reference);
shaka.log.v2('fetching: reference=', reference);
let op = this.playerInterface_.netEngine.request(requestType, request);
return op.promise.then(function(response) {
return response.data;
Expand Down

0 comments on commit 49ce58b

Please sign in to comment.