Rename createDefaultLoadControl() to build()
The standard, least surprising name, for a builder's method that builds the object is `build`. PiperOrigin-RevId: 319379622
This commit is contained in:
parent
513b268558
commit
cf3fbdd19b
@ -103,7 +103,7 @@ public class DefaultLoadControl implements LoadControl {
|
||||
private boolean prioritizeTimeOverSizeThresholds;
|
||||
private int backBufferDurationMs;
|
||||
private boolean retainBackBufferFromKeyframe;
|
||||
private boolean createDefaultLoadControlCalled;
|
||||
private boolean buildCalled;
|
||||
|
||||
/** Constructs a new instance. */
|
||||
public Builder() {
|
||||
@ -122,10 +122,10 @@ public class DefaultLoadControl implements LoadControl {
|
||||
*
|
||||
* @param allocator The {@link DefaultAllocator}.
|
||||
* @return This builder, for convenience.
|
||||
* @throws IllegalStateException If {@link #createDefaultLoadControl()} has already been called.
|
||||
* @throws IllegalStateException If {@link #build()} has already been called.
|
||||
*/
|
||||
public Builder setAllocator(DefaultAllocator allocator) {
|
||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
||||
Assertions.checkState(!buildCalled);
|
||||
this.allocator = allocator;
|
||||
return this;
|
||||
}
|
||||
@ -143,14 +143,14 @@ public class DefaultLoadControl implements LoadControl {
|
||||
* for playback to resume after a rebuffer, in milliseconds. A rebuffer is defined to be
|
||||
* caused by buffer depletion rather than a user action.
|
||||
* @return This builder, for convenience.
|
||||
* @throws IllegalStateException If {@link #createDefaultLoadControl()} has already been called.
|
||||
* @throws IllegalStateException If {@link #build()} has already been called.
|
||||
*/
|
||||
public Builder setBufferDurationsMs(
|
||||
int minBufferMs,
|
||||
int maxBufferMs,
|
||||
int bufferForPlaybackMs,
|
||||
int bufferForPlaybackAfterRebufferMs) {
|
||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
||||
Assertions.checkState(!buildCalled);
|
||||
assertGreaterOrEqual(bufferForPlaybackMs, 0, "bufferForPlaybackMs", "0");
|
||||
assertGreaterOrEqual(
|
||||
bufferForPlaybackAfterRebufferMs, 0, "bufferForPlaybackAfterRebufferMs", "0");
|
||||
@ -174,10 +174,10 @@ public class DefaultLoadControl implements LoadControl {
|
||||
*
|
||||
* @param targetBufferBytes The target buffer size in bytes.
|
||||
* @return This builder, for convenience.
|
||||
* @throws IllegalStateException If {@link #createDefaultLoadControl()} has already been called.
|
||||
* @throws IllegalStateException If {@link #build()} has already been called.
|
||||
*/
|
||||
public Builder setTargetBufferBytes(int targetBufferBytes) {
|
||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
||||
Assertions.checkState(!buildCalled);
|
||||
this.targetBufferBytes = targetBufferBytes;
|
||||
return this;
|
||||
}
|
||||
@ -189,10 +189,10 @@ public class DefaultLoadControl implements LoadControl {
|
||||
* @param prioritizeTimeOverSizeThresholds Whether the load control prioritizes buffer time
|
||||
* constraints over buffer size constraints.
|
||||
* @return This builder, for convenience.
|
||||
* @throws IllegalStateException If {@link #createDefaultLoadControl()} has already been called.
|
||||
* @throws IllegalStateException If {@link #build()} has already been called.
|
||||
*/
|
||||
public Builder setPrioritizeTimeOverSizeThresholds(boolean prioritizeTimeOverSizeThresholds) {
|
||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
||||
Assertions.checkState(!buildCalled);
|
||||
this.prioritizeTimeOverSizeThresholds = prioritizeTimeOverSizeThresholds;
|
||||
return this;
|
||||
}
|
||||
@ -205,20 +205,26 @@ public class DefaultLoadControl implements LoadControl {
|
||||
* @param retainBackBufferFromKeyframe Whether the back buffer is retained from the previous
|
||||
* keyframe.
|
||||
* @return This builder, for convenience.
|
||||
* @throws IllegalStateException If {@link #createDefaultLoadControl()} has already been called.
|
||||
* @throws IllegalStateException If {@link #build()} has already been called.
|
||||
*/
|
||||
public Builder setBackBuffer(int backBufferDurationMs, boolean retainBackBufferFromKeyframe) {
|
||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
||||
Assertions.checkState(!buildCalled);
|
||||
assertGreaterOrEqual(backBufferDurationMs, 0, "backBufferDurationMs", "0");
|
||||
this.backBufferDurationMs = backBufferDurationMs;
|
||||
this.retainBackBufferFromKeyframe = retainBackBufferFromKeyframe;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Creates a {@link DefaultLoadControl}. */
|
||||
/** @deprecated use {@link #build} instead. */
|
||||
@Deprecated
|
||||
public DefaultLoadControl createDefaultLoadControl() {
|
||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
||||
createDefaultLoadControlCalled = true;
|
||||
return build();
|
||||
}
|
||||
|
||||
/** Creates a {@link DefaultLoadControl}. */
|
||||
public DefaultLoadControl build() {
|
||||
Assertions.checkState(!buildCalled);
|
||||
buildCalled = true;
|
||||
if (allocator == null) {
|
||||
allocator = new DefaultAllocator(/* trimOnReset= */ true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class DefaultLoadControlTest {
|
||||
|
||||
@Test
|
||||
public void shouldContinueLoading_untilMaxBufferExceeded() {
|
||||
createDefaultLoadControl();
|
||||
build();
|
||||
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
@ -68,7 +68,7 @@ public class DefaultLoadControlTest {
|
||||
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US),
|
||||
/* bufferForPlaybackMs= */ 0,
|
||||
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
||||
createDefaultLoadControl();
|
||||
build();
|
||||
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MAX_BUFFER_US, SPEED))
|
||||
.isFalse();
|
||||
@ -91,7 +91,7 @@ public class DefaultLoadControlTest {
|
||||
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US),
|
||||
/* bufferForPlaybackMs= */ 0,
|
||||
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
||||
createDefaultLoadControl();
|
||||
build();
|
||||
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MAX_BUFFER_US, SPEED))
|
||||
.isFalse();
|
||||
@ -111,7 +111,7 @@ public class DefaultLoadControlTest {
|
||||
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US),
|
||||
/* bufferForPlaybackMs= */ 0,
|
||||
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
||||
createDefaultLoadControl();
|
||||
build();
|
||||
makeSureTargetBufferBytesReached();
|
||||
|
||||
assertThat(
|
||||
@ -132,7 +132,7 @@ public class DefaultLoadControlTest {
|
||||
public void
|
||||
shouldContinueLoading_withTargetBufferBytesReachedAndNotPrioritizeTimeOverSize_returnsTrueAsSoonAsTargetBufferReached() {
|
||||
builder.setPrioritizeTimeOverSizeThresholds(false);
|
||||
createDefaultLoadControl();
|
||||
build();
|
||||
|
||||
// Put loadControl in buffering state.
|
||||
assertThat(
|
||||
@ -162,7 +162,7 @@ public class DefaultLoadControlTest {
|
||||
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US),
|
||||
/* bufferForPlaybackMs= */ 0,
|
||||
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
||||
createDefaultLoadControl();
|
||||
build();
|
||||
|
||||
// At normal playback speed, we stop buffering when the buffer reaches the minimum.
|
||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MIN_BUFFER_US, SPEED))
|
||||
@ -176,7 +176,7 @@ public class DefaultLoadControlTest {
|
||||
|
||||
@Test
|
||||
public void shouldNotContinueLoadingWithMaxBufferReached_inFastPlayback() {
|
||||
createDefaultLoadControl();
|
||||
build();
|
||||
|
||||
assertThat(
|
||||
loadControl.shouldContinueLoading(
|
||||
@ -186,7 +186,7 @@ public class DefaultLoadControlTest {
|
||||
|
||||
@Test
|
||||
public void startsPlayback_whenMinBufferSizeReached() {
|
||||
createDefaultLoadControl();
|
||||
build();
|
||||
|
||||
assertThat(loadControl.shouldStartPlayback(MIN_BUFFER_US, SPEED, /* rebuffering= */ false))
|
||||
.isTrue();
|
||||
@ -194,7 +194,7 @@ public class DefaultLoadControlTest {
|
||||
|
||||
@Test
|
||||
public void shouldContinueLoading_withNoSelectedTracks_returnsTrue() {
|
||||
loadControl = builder.createDefaultLoadControl();
|
||||
loadControl = builder.build();
|
||||
loadControl.onTracksSelected(new Renderer[0], TrackGroupArray.EMPTY, new TrackSelectionArray());
|
||||
|
||||
assertThat(
|
||||
@ -203,9 +203,9 @@ public class DefaultLoadControlTest {
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
private void createDefaultLoadControl() {
|
||||
private void build() {
|
||||
builder.setAllocator(allocator).setTargetBufferBytes(TARGET_BUFFER_BYTES);
|
||||
loadControl = builder.createDefaultLoadControl();
|
||||
loadControl = builder.build();
|
||||
loadControl.onTracksSelected(new Renderer[0], null, null);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user