Skip to content

Commit

Permalink
Adjust appendWindowStart to help rounding errors.
Browse files Browse the repository at this point in the history
Since we set the appendWindowStart to exactly the start of the Period,
we can get rounding issues where the first frame of the next Period
is removed.  If we remove the first frame, then MSE will remove up to
the next keyframe, causing a large gap.  Avoid slight rounding errors
by adjusting appendWindowStart back a little.

Bug: 71808910
Change-Id: I933352441c34046db7bf777264eb1ee4225d55e1
  • Loading branch information
TheModMaker authored and joeyparrish committed Jan 19, 2018
1 parent 140079d commit 39383e7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,13 @@ shaka.media.StreamingEngine.MediaState_;


/**
* The minimum number seconds that will remain buffered after evicting media.
*
* 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.
* @const {number}
* @private
*/
shaka.media.StreamingEngine.prototype.MIN_BUFFER_LENGTH = 2;
shaka.media.StreamingEngine.APPEND_WINDOW_START_FUDGE_ = 0.00001;


/** @override */
Expand Down Expand Up @@ -1306,7 +1308,10 @@ shaka.media.StreamingEngine.prototype.fetchAndAppend_ = function(
// Compute the append window.
var duration = this.manifest_.presentationTimeline.getDuration();
var followingPeriod = this.manifest_.periods[currentPeriodIndex + 1];
var appendWindowStart = currentPeriod.startTime;
// Rounding issues can cause us to remove the first frame of the Period, so
// reduce the start time slightly.
var windowFudge = shaka.media.StreamingEngine.APPEND_WINDOW_START_FUDGE_;
var appendWindowStart = Math.max(0, currentPeriod.startTime - windowFudge);
var appendWindowEnd = followingPeriod ? followingPeriod.startTime : duration;
goog.asserts.assert(
reference.startTime <= appendWindowEnd,
Expand Down
24 changes: 24 additions & 0 deletions test/media/streaming_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,30 @@ describe('StreamingEngine', function() {
expect(timeline.setDuration).toHaveBeenCalledWith(35);
});

it('applies fudge factor for appendWindowStart', function() {
setupVod();
mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData);
createStreamingEngine();

playhead.getTime.and.returnValue(0);
onStartupComplete.and.callFake(setupFakeGetTime.bind(null, 0));
onChooseStreams.and.callFake(defaultOnChooseStreams);

// Here we go!
streamingEngine.init();
runTest();

// The second Period starts at 20, so we should set the appendWindowStart to
// 20, but reduced by a small fudge factor.
var lt20 = {
asymmetricMatch: function(val) {
return val > 19.9 && val < 20;
}
};
expect(mediaSourceEngine.setStreamProperties)
.toHaveBeenCalledWith('video', 20, lt20, 40);
});

describe('switchVariant/switchTextStream', function() {
var initialVariant;
var sameAudioVariant;
Expand Down

0 comments on commit 39383e7

Please sign in to comment.