mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +00:00
Scale the minimum buffer size in shouldContinueLoading
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=191885689
This commit is contained in:
parent
9a507db171
commit
f5b568fc7d
2 changed files with 27 additions and 0 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue