Commit 30941c41 by tonihei Committed by Oliver Woodman

Ensure DefaultLoadControl.Builder is single-use.

This is needed because the allocator can't be reused for example.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=221638233
parent c08edc5e
...@@ -79,6 +79,7 @@ public class DefaultLoadControl implements LoadControl { ...@@ -79,6 +79,7 @@ public class DefaultLoadControl implements LoadControl {
private PriorityTaskManager priorityTaskManager; private PriorityTaskManager priorityTaskManager;
private int backBufferDurationMs; private int backBufferDurationMs;
private boolean retainBackBufferFromKeyframe; private boolean retainBackBufferFromKeyframe;
private boolean createDefaultLoadControlCalled;
/** Constructs a new instance. */ /** Constructs a new instance. */
public Builder() { public Builder() {
...@@ -99,8 +100,10 @@ public class DefaultLoadControl implements LoadControl { ...@@ -99,8 +100,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.
*/ */
public Builder setAllocator(DefaultAllocator allocator) { public Builder setAllocator(DefaultAllocator allocator) {
Assertions.checkState(!createDefaultLoadControlCalled);
this.allocator = allocator; this.allocator = allocator;
return this; return this;
} }
...@@ -118,12 +121,14 @@ public class DefaultLoadControl implements LoadControl { ...@@ -118,12 +121,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.
*/ */
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);
this.minBufferMs = minBufferMs; this.minBufferMs = minBufferMs;
this.maxBufferMs = maxBufferMs; this.maxBufferMs = maxBufferMs;
this.bufferForPlaybackMs = bufferForPlaybackMs; this.bufferForPlaybackMs = bufferForPlaybackMs;
...@@ -137,8 +142,10 @@ public class DefaultLoadControl implements LoadControl { ...@@ -137,8 +142,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.
*/ */
public Builder setTargetBufferBytes(int targetBufferBytes) { public Builder setTargetBufferBytes(int targetBufferBytes) {
Assertions.checkState(!createDefaultLoadControlCalled);
this.targetBufferBytes = targetBufferBytes; this.targetBufferBytes = targetBufferBytes;
return this; return this;
} }
...@@ -150,8 +157,10 @@ public class DefaultLoadControl implements LoadControl { ...@@ -150,8 +157,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.
*/ */
public Builder setPrioritizeTimeOverSizeThresholds(boolean prioritizeTimeOverSizeThresholds) { public Builder setPrioritizeTimeOverSizeThresholds(boolean prioritizeTimeOverSizeThresholds) {
Assertions.checkState(!createDefaultLoadControlCalled);
this.prioritizeTimeOverSizeThresholds = prioritizeTimeOverSizeThresholds; this.prioritizeTimeOverSizeThresholds = prioritizeTimeOverSizeThresholds;
return this; return this;
} }
...@@ -161,8 +170,10 @@ public class DefaultLoadControl implements LoadControl { ...@@ -161,8 +170,10 @@ public class DefaultLoadControl implements LoadControl {
* *
* @param priorityTaskManager The {@link PriorityTaskManager} to use. * @param priorityTaskManager The {@link PriorityTaskManager} to use.
* @return This builder, for convenience. * @return This builder, for convenience.
* @throws IllegalStateException If {@link #createDefaultLoadControl()} has already been called.
*/ */
public Builder setPriorityTaskManager(PriorityTaskManager priorityTaskManager) { public Builder setPriorityTaskManager(PriorityTaskManager priorityTaskManager) {
Assertions.checkState(!createDefaultLoadControlCalled);
this.priorityTaskManager = priorityTaskManager; this.priorityTaskManager = priorityTaskManager;
return this; return this;
} }
...@@ -175,8 +186,10 @@ public class DefaultLoadControl implements LoadControl { ...@@ -175,8 +186,10 @@ 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.
*/ */
public Builder setBackBuffer(int backBufferDurationMs, boolean retainBackBufferFromKeyframe) { public Builder setBackBuffer(int backBufferDurationMs, boolean retainBackBufferFromKeyframe) {
Assertions.checkState(!createDefaultLoadControlCalled);
this.backBufferDurationMs = backBufferDurationMs; this.backBufferDurationMs = backBufferDurationMs;
this.retainBackBufferFromKeyframe = retainBackBufferFromKeyframe; this.retainBackBufferFromKeyframe = retainBackBufferFromKeyframe;
return this; return this;
...@@ -184,6 +197,7 @@ public class DefaultLoadControl implements LoadControl { ...@@ -184,6 +197,7 @@ public class DefaultLoadControl implements LoadControl {
/** Creates a {@link DefaultLoadControl}. */ /** Creates a {@link DefaultLoadControl}. */
public DefaultLoadControl createDefaultLoadControl() { public DefaultLoadControl createDefaultLoadControl() {
createDefaultLoadControlCalled = true;
if (allocator == null) { if (allocator == null) {
allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE); allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment