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 boolean prioritizeTimeOverSizeThresholds;
|
||||||
private int backBufferDurationMs;
|
private int backBufferDurationMs;
|
||||||
private boolean retainBackBufferFromKeyframe;
|
private boolean retainBackBufferFromKeyframe;
|
||||||
private boolean createDefaultLoadControlCalled;
|
private boolean buildCalled;
|
||||||
|
|
||||||
/** Constructs a new instance. */
|
/** Constructs a new instance. */
|
||||||
public Builder() {
|
public Builder() {
|
||||||
@ -122,10 +122,10 @@ public class DefaultLoadControl implements LoadControl {
|
|||||||
*
|
*
|
||||||
* @param allocator The {@link DefaultAllocator}.
|
* @param allocator The {@link DefaultAllocator}.
|
||||||
* @return This builder, for convenience.
|
* @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) {
|
public Builder setAllocator(DefaultAllocator allocator) {
|
||||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
Assertions.checkState(!buildCalled);
|
||||||
this.allocator = allocator;
|
this.allocator = allocator;
|
||||||
return this;
|
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
|
* for playback to resume after a rebuffer, in milliseconds. A rebuffer is defined to be
|
||||||
* caused by buffer depletion rather than a user action.
|
* caused by buffer depletion rather than a user action.
|
||||||
* @return This builder, for convenience.
|
* @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(
|
public Builder setBufferDurationsMs(
|
||||||
int minBufferMs,
|
int minBufferMs,
|
||||||
int maxBufferMs,
|
int maxBufferMs,
|
||||||
int bufferForPlaybackMs,
|
int bufferForPlaybackMs,
|
||||||
int bufferForPlaybackAfterRebufferMs) {
|
int bufferForPlaybackAfterRebufferMs) {
|
||||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
Assertions.checkState(!buildCalled);
|
||||||
assertGreaterOrEqual(bufferForPlaybackMs, 0, "bufferForPlaybackMs", "0");
|
assertGreaterOrEqual(bufferForPlaybackMs, 0, "bufferForPlaybackMs", "0");
|
||||||
assertGreaterOrEqual(
|
assertGreaterOrEqual(
|
||||||
bufferForPlaybackAfterRebufferMs, 0, "bufferForPlaybackAfterRebufferMs", "0");
|
bufferForPlaybackAfterRebufferMs, 0, "bufferForPlaybackAfterRebufferMs", "0");
|
||||||
@ -174,10 +174,10 @@ public class DefaultLoadControl implements LoadControl {
|
|||||||
*
|
*
|
||||||
* @param targetBufferBytes The target buffer size in bytes.
|
* @param targetBufferBytes The target buffer size in bytes.
|
||||||
* @return This builder, for convenience.
|
* @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) {
|
public Builder setTargetBufferBytes(int targetBufferBytes) {
|
||||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
Assertions.checkState(!buildCalled);
|
||||||
this.targetBufferBytes = targetBufferBytes;
|
this.targetBufferBytes = targetBufferBytes;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -189,10 +189,10 @@ public class DefaultLoadControl implements LoadControl {
|
|||||||
* @param prioritizeTimeOverSizeThresholds Whether the load control prioritizes buffer time
|
* @param prioritizeTimeOverSizeThresholds Whether the load control prioritizes buffer time
|
||||||
* constraints over buffer size constraints.
|
* constraints over buffer size constraints.
|
||||||
* @return This builder, for convenience.
|
* @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) {
|
public Builder setPrioritizeTimeOverSizeThresholds(boolean prioritizeTimeOverSizeThresholds) {
|
||||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
Assertions.checkState(!buildCalled);
|
||||||
this.prioritizeTimeOverSizeThresholds = prioritizeTimeOverSizeThresholds;
|
this.prioritizeTimeOverSizeThresholds = prioritizeTimeOverSizeThresholds;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -205,20 +205,26 @@ public class DefaultLoadControl implements LoadControl {
|
|||||||
* @param retainBackBufferFromKeyframe Whether the back buffer is retained from the previous
|
* @param retainBackBufferFromKeyframe Whether the back buffer is retained from the previous
|
||||||
* keyframe.
|
* keyframe.
|
||||||
* @return This builder, for convenience.
|
* @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) {
|
public Builder setBackBuffer(int backBufferDurationMs, boolean retainBackBufferFromKeyframe) {
|
||||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
Assertions.checkState(!buildCalled);
|
||||||
assertGreaterOrEqual(backBufferDurationMs, 0, "backBufferDurationMs", "0");
|
assertGreaterOrEqual(backBufferDurationMs, 0, "backBufferDurationMs", "0");
|
||||||
this.backBufferDurationMs = backBufferDurationMs;
|
this.backBufferDurationMs = backBufferDurationMs;
|
||||||
this.retainBackBufferFromKeyframe = retainBackBufferFromKeyframe;
|
this.retainBackBufferFromKeyframe = retainBackBufferFromKeyframe;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a {@link DefaultLoadControl}. */
|
/** @deprecated use {@link #build} instead. */
|
||||||
|
@Deprecated
|
||||||
public DefaultLoadControl createDefaultLoadControl() {
|
public DefaultLoadControl createDefaultLoadControl() {
|
||||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
return build();
|
||||||
createDefaultLoadControlCalled = true;
|
}
|
||||||
|
|
||||||
|
/** Creates a {@link DefaultLoadControl}. */
|
||||||
|
public DefaultLoadControl build() {
|
||||||
|
Assertions.checkState(!buildCalled);
|
||||||
|
buildCalled = true;
|
||||||
if (allocator == null) {
|
if (allocator == null) {
|
||||||
allocator = new DefaultAllocator(/* trimOnReset= */ true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
|
allocator = new DefaultAllocator(/* trimOnReset= */ true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ public class DefaultLoadControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldContinueLoading_untilMaxBufferExceeded() {
|
public void shouldContinueLoading_untilMaxBufferExceeded() {
|
||||||
createDefaultLoadControl();
|
build();
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
loadControl.shouldContinueLoading(
|
loadControl.shouldContinueLoading(
|
||||||
@ -68,7 +68,7 @@ public class DefaultLoadControlTest {
|
|||||||
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US),
|
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US),
|
||||||
/* bufferForPlaybackMs= */ 0,
|
/* bufferForPlaybackMs= */ 0,
|
||||||
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
||||||
createDefaultLoadControl();
|
build();
|
||||||
|
|
||||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MAX_BUFFER_US, SPEED))
|
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MAX_BUFFER_US, SPEED))
|
||||||
.isFalse();
|
.isFalse();
|
||||||
@ -91,7 +91,7 @@ public class DefaultLoadControlTest {
|
|||||||
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US),
|
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US),
|
||||||
/* bufferForPlaybackMs= */ 0,
|
/* bufferForPlaybackMs= */ 0,
|
||||||
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
||||||
createDefaultLoadControl();
|
build();
|
||||||
|
|
||||||
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MAX_BUFFER_US, SPEED))
|
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MAX_BUFFER_US, SPEED))
|
||||||
.isFalse();
|
.isFalse();
|
||||||
@ -111,7 +111,7 @@ public class DefaultLoadControlTest {
|
|||||||
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US),
|
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US),
|
||||||
/* bufferForPlaybackMs= */ 0,
|
/* bufferForPlaybackMs= */ 0,
|
||||||
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
||||||
createDefaultLoadControl();
|
build();
|
||||||
makeSureTargetBufferBytesReached();
|
makeSureTargetBufferBytesReached();
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
@ -132,7 +132,7 @@ public class DefaultLoadControlTest {
|
|||||||
public void
|
public void
|
||||||
shouldContinueLoading_withTargetBufferBytesReachedAndNotPrioritizeTimeOverSize_returnsTrueAsSoonAsTargetBufferReached() {
|
shouldContinueLoading_withTargetBufferBytesReachedAndNotPrioritizeTimeOverSize_returnsTrueAsSoonAsTargetBufferReached() {
|
||||||
builder.setPrioritizeTimeOverSizeThresholds(false);
|
builder.setPrioritizeTimeOverSizeThresholds(false);
|
||||||
createDefaultLoadControl();
|
build();
|
||||||
|
|
||||||
// Put loadControl in buffering state.
|
// Put loadControl in buffering state.
|
||||||
assertThat(
|
assertThat(
|
||||||
@ -162,7 +162,7 @@ public class DefaultLoadControlTest {
|
|||||||
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US),
|
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US),
|
||||||
/* bufferForPlaybackMs= */ 0,
|
/* bufferForPlaybackMs= */ 0,
|
||||||
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
/* bufferForPlaybackAfterRebufferMs= */ 0);
|
||||||
createDefaultLoadControl();
|
build();
|
||||||
|
|
||||||
// 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(/* playbackPositionUs= */ 0, MIN_BUFFER_US, SPEED))
|
assertThat(loadControl.shouldContinueLoading(/* playbackPositionUs= */ 0, MIN_BUFFER_US, SPEED))
|
||||||
@ -176,7 +176,7 @@ public class DefaultLoadControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotContinueLoadingWithMaxBufferReached_inFastPlayback() {
|
public void shouldNotContinueLoadingWithMaxBufferReached_inFastPlayback() {
|
||||||
createDefaultLoadControl();
|
build();
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
loadControl.shouldContinueLoading(
|
loadControl.shouldContinueLoading(
|
||||||
@ -186,7 +186,7 @@ public class DefaultLoadControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void startsPlayback_whenMinBufferSizeReached() {
|
public void startsPlayback_whenMinBufferSizeReached() {
|
||||||
createDefaultLoadControl();
|
build();
|
||||||
|
|
||||||
assertThat(loadControl.shouldStartPlayback(MIN_BUFFER_US, SPEED, /* rebuffering= */ false))
|
assertThat(loadControl.shouldStartPlayback(MIN_BUFFER_US, SPEED, /* rebuffering= */ false))
|
||||||
.isTrue();
|
.isTrue();
|
||||||
@ -194,7 +194,7 @@ public class DefaultLoadControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldContinueLoading_withNoSelectedTracks_returnsTrue() {
|
public void shouldContinueLoading_withNoSelectedTracks_returnsTrue() {
|
||||||
loadControl = builder.createDefaultLoadControl();
|
loadControl = builder.build();
|
||||||
loadControl.onTracksSelected(new Renderer[0], TrackGroupArray.EMPTY, new TrackSelectionArray());
|
loadControl.onTracksSelected(new Renderer[0], TrackGroupArray.EMPTY, new TrackSelectionArray());
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
@ -203,9 +203,9 @@ public class DefaultLoadControlTest {
|
|||||||
.isTrue();
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDefaultLoadControl() {
|
private void build() {
|
||||||
builder.setAllocator(allocator).setTargetBufferBytes(TARGET_BUFFER_BYTES);
|
builder.setAllocator(allocator).setTargetBufferBytes(TARGET_BUFFER_BYTES);
|
||||||
loadControl = builder.createDefaultLoadControl();
|
loadControl = builder.build();
|
||||||
loadControl.onTracksSelected(new Renderer[0], null, null);
|
loadControl.onTracksSelected(new Renderer[0], null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user