From 39383e757098318ff55b7c9646a26d0ca612d165 Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Wed, 17 Jan 2018 09:58:36 -0800 Subject: [PATCH] Adjust appendWindowStart to help rounding errors. 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 --- lib/media/streaming_engine.js | 13 +++++++++---- test/media/streaming_engine_unit.js | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index 2e6399dc4f..cc675b96b7 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -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 */ @@ -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, diff --git a/test/media/streaming_engine_unit.js b/test/media/streaming_engine_unit.js index fa273c6236..57094e26bd 100644 --- a/test/media/streaming_engine_unit.js +++ b/test/media/streaming_engine_unit.js @@ -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;