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