Scale the minimum buffer size in shouldContinueLoading

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=191885689
This commit is contained in:
andrewlewis 2018-04-06 07:28:22 -07:00 committed by Oliver Woodman
parent 9a507db171
commit f5b568fc7d
2 changed files with 27 additions and 0 deletions

View file

@ -301,6 +301,14 @@ public class DefaultLoadControl implements LoadControl {
public boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed) {
boolean targetBufferSizeReached = allocator.getTotalBytesAllocated() >= targetBufferSize;
boolean wasBuffering = isBuffering;
long minBufferUs = this.minBufferUs;
if (playbackSpeed > 1) {
// The playback speed is faster than real time, so scale up the minimum required media
// duration to keep enough media buffered for a playout duration of minBufferUs.
long mediaDurationMinBufferUs =
Util.getMediaDurationForPlayoutDuration(minBufferUs, playbackSpeed);
minBufferUs = Math.min(mediaDurationMinBufferUs, maxBufferUs);
}
if (bufferedDurationUs < minBufferUs) {
isBuffering = prioritizeTimeOverSizeThresholds || !targetBufferSizeReached;
} else if (bufferedDurationUs > maxBufferUs || targetBufferSizeReached) {

View file

@ -85,6 +85,25 @@ public class DefaultLoadControlTest {
assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US + 1, SPEED)).isFalse();
}
@Test
public void testShouldContinueLoadingWithMinBufferReached_inFastPlayback() {
createDefaultLoadControl();
// At normal playback speed, we stop buffering when the buffer reaches the minimum.
assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, SPEED)).isFalse();
// At double playback speed, we continue loading.
assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, /* playbackSpeed= */ 2f)).isTrue();
}
@Test
public void testShouldNotContinueLoadingWithMaxBufferReached_inFastPlayback() {
createDefaultLoadControl();
assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US + 1, /* playbackSpeed= */ 100f))
.isFalse();
}
@Test
public void testStartsPlayback_whenMinBufferSizeReached() {
createDefaultLoadControl();