Remove deprecated LoadControl method
PiperOrigin-RevId: 308031992
This commit is contained in:
parent
1699ab0d18
commit
c452d6dfc2
@ -370,7 +370,8 @@ public class DefaultLoadControl implements LoadControl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed) {
|
||||
public boolean shouldContinueLoading(
|
||||
long playbackPositionUs, long bufferedDurationUs, float playbackSpeed) {
|
||||
boolean targetBufferSizeReached = allocator.getTotalBytesAllocated() >= targetBufferBytes;
|
||||
long minBufferUs = this.minBufferUs;
|
||||
if (playbackSpeed > 1) {
|
||||
|
@ -87,28 +87,20 @@ public interface LoadControl {
|
||||
*/
|
||||
boolean retainBackBufferFromKeyframe();
|
||||
|
||||
/** @deprecated Use {@link LoadControl#shouldContinueLoading(long, long, float)}. */
|
||||
@Deprecated
|
||||
default boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the player to determine whether it should continue to load the source.
|
||||
*
|
||||
* @param playbackPositionUs The current playback position in microseconds, relative to the start
|
||||
* of the {@link Timeline.Period period} that will continue to be loaded if this method
|
||||
* returns {@code true}. If the playback for this period has not yet started, the value will
|
||||
* returns {@code true}. If playback of this period has not yet started, the value will be
|
||||
* negative and equal in magnitude to the duration of any media in previous periods still to
|
||||
* be played.
|
||||
* @param bufferedDurationUs The duration of media that's currently buffered.
|
||||
* @param playbackSpeed The current playback speed.
|
||||
* @return Whether the loading should continue.
|
||||
*/
|
||||
default boolean shouldContinueLoading(
|
||||
long playbackPositionUs, long bufferedDurationUs, float playbackSpeed) {
|
||||
return shouldContinueLoading(bufferedDurationUs, playbackSpeed);
|
||||
}
|
||||
boolean shouldContinueLoading(
|
||||
long playbackPositionUs, long bufferedDurationUs, float playbackSpeed);
|
||||
|
||||
/**
|
||||
* Called repeatedly by the player when it's loading the source, has yet to start playback, and
|
||||
|
@ -49,9 +49,16 @@ public class DefaultLoadControlTest {
|
||||
public void shouldContinueLoading_untilMaxBufferExceeded() {
|
||||
createDefaultLoadControl();
|
||||
|
||||
assertThat(loadControl.shouldContinueLoading(/* bufferedDurationUs= */ 0, SPEED)).isTrue();
|
||||
assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US - 1, SPEED)).isTrue();
|
||||
assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US, SPEED)).isFalse();
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, /* bufferedDurationUs= */ 0, SPEED))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, MAX_BUFFER_US - 1, SPEED))
|
||||
.isTrue();
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MAX_BUFFER_US, SPEED))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -63,10 +70,18 @@ public class DefaultLoadControlTest {
|
||||
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
||||
createDefaultLoadControl();
|
||||
|
||||
assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US, SPEED)).isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US - 1, SPEED)).isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, SPEED)).isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US - 1, SPEED)).isTrue();
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MAX_BUFFER_US, SPEED))
|
||||
.isFalse();
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, MAX_BUFFER_US - 1, SPEED))
|
||||
.isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MIN_BUFFER_US, SPEED))
|
||||
.isFalse();
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, MIN_BUFFER_US - 1, SPEED))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -78,9 +93,14 @@ public class DefaultLoadControlTest {
|
||||
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
||||
createDefaultLoadControl();
|
||||
|
||||
assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US, SPEED)).isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(5 * C.MICROS_PER_SECOND, SPEED)).isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(500L, SPEED)).isTrue();
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MAX_BUFFER_US, SPEED))
|
||||
.isFalse();
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, 5 * C.MICROS_PER_SECOND, SPEED))
|
||||
.isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, 500L, SPEED))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -94,10 +114,18 @@ public class DefaultLoadControlTest {
|
||||
createDefaultLoadControl();
|
||||
makeSureTargetBufferBytesReached();
|
||||
|
||||
assertThat(loadControl.shouldContinueLoading(/* bufferedDurationUs= */ 0, SPEED)).isTrue();
|
||||
assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US - 1, SPEED)).isTrue();
|
||||
assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, SPEED)).isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US, SPEED)).isFalse();
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, /* bufferedDurationUs= */ 0, SPEED))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, MIN_BUFFER_US - 1, SPEED))
|
||||
.isTrue();
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MIN_BUFFER_US, SPEED))
|
||||
.isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MAX_BUFFER_US, SPEED))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -107,13 +135,24 @@ public class DefaultLoadControlTest {
|
||||
createDefaultLoadControl();
|
||||
|
||||
// Put loadControl in buffering state.
|
||||
assertThat(loadControl.shouldContinueLoading(/* bufferedDurationUs= */ 0, SPEED)).isTrue();
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, /* bufferedDurationUs= */ 0, SPEED))
|
||||
.isTrue();
|
||||
makeSureTargetBufferBytesReached();
|
||||
|
||||
assertThat(loadControl.shouldContinueLoading(/* bufferedDurationUs= */ 0, SPEED)).isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US - 1, SPEED)).isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, SPEED)).isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US, SPEED)).isFalse();
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, /* bufferedDurationUs= */ 0, SPEED))
|
||||
.isFalse();
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, MIN_BUFFER_US - 1, SPEED))
|
||||
.isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MIN_BUFFER_US, SPEED))
|
||||
.isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MAX_BUFFER_US, SPEED))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -126,16 +165,22 @@ public class DefaultLoadControlTest {
|
||||
createDefaultLoadControl();
|
||||
|
||||
// At normal playback speed, we stop buffering when the buffer reaches the minimum.
|
||||
assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, SPEED)).isFalse();
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MIN_BUFFER_US, SPEED))
|
||||
.isFalse();
|
||||
// At double playback speed, we continue loading.
|
||||
assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, /* playbackSpeed= */ 2f)).isTrue();
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, MIN_BUFFER_US, /* playbackSpeed= */ 2f))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotContinueLoadingWithMaxBufferReached_inFastPlayback() {
|
||||
createDefaultLoadControl();
|
||||
|
||||
assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US, /* playbackSpeed= */ 100f))
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, MAX_BUFFER_US, /* playbackSpeed= */ 100f))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@ -153,7 +198,8 @@ public class DefaultLoadControlTest {
|
||||
loadControl.onTracksSelected(new Renderer[0], TrackGroupArray.EMPTY, new TrackSelectionArray());
|
||||
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(/* bufferedDurationUs= */ 0, /* playbackSpeed= */ 1f))
|
||||
loadControl.shouldContinueLoading(
|
||||
/* playbackPositionUs= */ 0, /* bufferedDurationUs= */ 0, /* playbackSpeed= */ 1f))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
|
@ -3507,11 +3507,12 @@ public final class ExoPlayerTest {
|
||||
// Disabled until the flag to throw exceptions for [internal: b/144538905] is enabled by default.
|
||||
@Ignore
|
||||
@Test
|
||||
public void loadControlNeverWantsToLoad_throwsIllegalStateException() throws Exception {
|
||||
public void loadControlNeverWantsToLoad_throwsIllegalStateException() {
|
||||
LoadControl neverLoadingLoadControl =
|
||||
new DefaultLoadControl() {
|
||||
@Override
|
||||
public boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed) {
|
||||
public boolean shouldContinueLoading(
|
||||
long playbackPositionUs, long bufferedDurationUs, float playbackSpeed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3553,7 +3554,8 @@ public final class ExoPlayerTest {
|
||||
LoadControl loadControlWithMaxBufferUs =
|
||||
new DefaultLoadControl() {
|
||||
@Override
|
||||
public boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed) {
|
||||
public boolean shouldContinueLoading(
|
||||
long playbackPositionUs, long bufferedDurationUs, float playbackSpeed) {
|
||||
return bufferedDurationUs < maxBufferUs;
|
||||
}
|
||||
|
||||
@ -3623,7 +3625,8 @@ public final class ExoPlayerTest {
|
||||
LoadControl neverLoadingOrPlayingLoadControl =
|
||||
new DefaultLoadControl() {
|
||||
@Override
|
||||
public boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed) {
|
||||
public boolean shouldContinueLoading(
|
||||
long playbackPositionUs, long bufferedDurationUs, float playbackSpeed) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user