Commit f5b568fc by andrewlewis Committed by Oliver Woodman

Scale the minimum buffer size in shouldContinueLoading

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=191885689
parent 9a507db1
...@@ -301,6 +301,14 @@ public class DefaultLoadControl implements LoadControl { ...@@ -301,6 +301,14 @@ public class DefaultLoadControl implements LoadControl {
public boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed) { public boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed) {
boolean targetBufferSizeReached = allocator.getTotalBytesAllocated() >= targetBufferSize; boolean targetBufferSizeReached = allocator.getTotalBytesAllocated() >= targetBufferSize;
boolean wasBuffering = isBuffering; 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) { if (bufferedDurationUs < minBufferUs) {
isBuffering = prioritizeTimeOverSizeThresholds || !targetBufferSizeReached; isBuffering = prioritizeTimeOverSizeThresholds || !targetBufferSizeReached;
} else if (bufferedDurationUs > maxBufferUs || targetBufferSizeReached) { } else if (bufferedDurationUs > maxBufferUs || targetBufferSizeReached) {
......
...@@ -86,6 +86,25 @@ public class DefaultLoadControlTest { ...@@ -86,6 +86,25 @@ public class DefaultLoadControlTest {
} }
@Test @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() { public void testStartsPlayback_whenMinBufferSizeReached() {
createDefaultLoadControl(); createDefaultLoadControl();
assertThat(loadControl.shouldStartPlayback(MIN_BUFFER_US, SPEED, /* rebuffering= */ false)) assertThat(loadControl.shouldStartPlayback(MIN_BUFFER_US, SPEED, /* rebuffering= */ false))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment