Allow configuration of DefaultLoadControl back buffer

Issue: #4857

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=214254231
This commit is contained in:
olly 2018-09-24 06:00:38 -07:00 committed by Oliver Woodman
parent 614f964cfe
commit b0cd6cf622
2 changed files with 76 additions and 15 deletions

View File

@ -112,6 +112,8 @@
([#4791](https://github.com/google/ExoPlayer/issues/4791)). ([#4791](https://github.com/google/ExoPlayer/issues/4791)).
* MPEG-TS: Support CEA-608/708 in H262 * MPEG-TS: Support CEA-608/708 in H262
([#2565](https://github.com/google/ExoPlayer/issues/2565)). ([#2565](https://github.com/google/ExoPlayer/issues/2565)).
* Allow configuration of the back buffer in `DefaultLoadControl.Builder`
([#4857](https://github.com/google/ExoPlayer/issues/4857)).
* Allow apps to pass a `CacheKeyFactory` for setting custom cache keys when * Allow apps to pass a `CacheKeyFactory` for setting custom cache keys when
creating a `CacheDataSource`. creating a `CacheDataSource`.
* Provide additional information for adaptive track selection. * Provide additional information for adaptive track selection.

View File

@ -52,14 +52,20 @@ public class DefaultLoadControl implements LoadControl {
public static final int DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS = 5000; public static final int DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS = 5000;
/** /**
* The default target buffer size in bytes. When set to {@link C#LENGTH_UNSET}, the load control * The default target buffer size in bytes. The value ({@link C#LENGTH_UNSET}) means that the load
* automatically determines its target buffer size. * control will calculate the target buffer size based on the selected tracks.
*/ */
public static final int DEFAULT_TARGET_BUFFER_BYTES = C.LENGTH_UNSET; public static final int DEFAULT_TARGET_BUFFER_BYTES = C.LENGTH_UNSET;
/** The default prioritization of buffer time constraints over size constraints. */ /** The default prioritization of buffer time constraints over size constraints. */
public static final boolean DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS = true; public static final boolean DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS = true;
/** The default back buffer duration in milliseconds. */
public static final int DEFAULT_BACK_BUFFER_DURATION_MS = 0;
/** The default for whether the back buffer is retained from the previous keyframe. */
public static final boolean DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME = false;
/** Builder for {@link DefaultLoadControl}. */ /** Builder for {@link DefaultLoadControl}. */
public static final class Builder { public static final class Builder {
@ -71,6 +77,8 @@ public class DefaultLoadControl implements LoadControl {
private int targetBufferBytes; private int targetBufferBytes;
private boolean prioritizeTimeOverSizeThresholds; private boolean prioritizeTimeOverSizeThresholds;
private PriorityTaskManager priorityTaskManager; private PriorityTaskManager priorityTaskManager;
private int backBufferDurationMs;
private boolean retainBackBufferFromKeyframe;
/** Constructs a new instance. */ /** Constructs a new instance. */
public Builder() { public Builder() {
@ -82,6 +90,8 @@ public class DefaultLoadControl implements LoadControl {
targetBufferBytes = DEFAULT_TARGET_BUFFER_BYTES; targetBufferBytes = DEFAULT_TARGET_BUFFER_BYTES;
prioritizeTimeOverSizeThresholds = DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS; prioritizeTimeOverSizeThresholds = DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS;
priorityTaskManager = null; priorityTaskManager = null;
backBufferDurationMs = DEFAULT_BACK_BUFFER_DURATION_MS;
retainBackBufferFromKeyframe = DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME;
} }
/** /**
@ -123,8 +133,7 @@ public class DefaultLoadControl implements LoadControl {
/** /**
* Sets the target buffer size in bytes. If set to {@link C#LENGTH_UNSET}, the target buffer * Sets the target buffer size in bytes. If set to {@link C#LENGTH_UNSET}, the target buffer
* size will be calculated using {@link #calculateTargetBufferSize(Renderer[], * size will be calculated based on the selected tracks.
* TrackSelectionArray)}.
* *
* @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.
@ -147,14 +156,33 @@ public class DefaultLoadControl implements LoadControl {
return this; return this;
} }
/** Sets the {@link PriorityTaskManager} to use. */ /**
* Sets the {@link PriorityTaskManager} to use.
*
* @param priorityTaskManager The {@link PriorityTaskManager} to use.
* @return This builder, for convenience.
*/
public Builder setPriorityTaskManager(PriorityTaskManager priorityTaskManager) { public Builder setPriorityTaskManager(PriorityTaskManager priorityTaskManager) {
this.priorityTaskManager = priorityTaskManager; this.priorityTaskManager = priorityTaskManager;
return this; return this;
} }
/**
* Sets the back buffer duration, and whether the back buffer is retained from the previous
* keyframe.
*
* @param backBufferDurationMs The back buffer duration in milliseconds.
* @param retainBackBufferFromKeyframe Whether the back buffer is retained from the previous
* keyframe.
* @return This builder, for convenience.
*/
public Builder setBackBuffer(int backBufferDurationMs, boolean retainBackBufferFromKeyframe) {
this.backBufferDurationMs = backBufferDurationMs;
this.retainBackBufferFromKeyframe = retainBackBufferFromKeyframe;
return this;
}
/** Creates a {@link DefaultLoadControl}. */ /** Creates a {@link DefaultLoadControl}. */
@SuppressWarnings("deprecation")
public DefaultLoadControl createDefaultLoadControl() { public DefaultLoadControl createDefaultLoadControl() {
if (allocator == null) { if (allocator == null) {
allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE); allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
@ -167,7 +195,9 @@ public class DefaultLoadControl implements LoadControl {
bufferForPlaybackAfterRebufferMs, bufferForPlaybackAfterRebufferMs,
targetBufferBytes, targetBufferBytes,
prioritizeTimeOverSizeThresholds, prioritizeTimeOverSizeThresholds,
priorityTaskManager); priorityTaskManager,
backBufferDurationMs,
retainBackBufferFromKeyframe);
} }
} }
@ -180,6 +210,8 @@ public class DefaultLoadControl implements LoadControl {
private final int targetBufferBytesOverwrite; private final int targetBufferBytesOverwrite;
private final boolean prioritizeTimeOverSizeThresholds; private final boolean prioritizeTimeOverSizeThresholds;
private final PriorityTaskManager priorityTaskManager; private final PriorityTaskManager priorityTaskManager;
private final long backBufferDurationUs;
private final boolean retainBackBufferFromKeyframe;
private int targetBufferSize; private int targetBufferSize;
private boolean isBuffering; private boolean isBuffering;
@ -223,7 +255,7 @@ public class DefaultLoadControl implements LoadControl {
bufferForPlaybackAfterRebufferMs, bufferForPlaybackAfterRebufferMs,
targetBufferBytes, targetBufferBytes,
prioritizeTimeOverSizeThresholds, prioritizeTimeOverSizeThresholds,
null); /* priorityTaskManager= */ null);
} }
/** @deprecated Use {@link Builder} instead. */ /** @deprecated Use {@link Builder} instead. */
@ -237,6 +269,30 @@ public class DefaultLoadControl implements LoadControl {
int targetBufferBytes, int targetBufferBytes,
boolean prioritizeTimeOverSizeThresholds, boolean prioritizeTimeOverSizeThresholds,
PriorityTaskManager priorityTaskManager) { PriorityTaskManager priorityTaskManager) {
this(
allocator,
minBufferMs,
maxBufferMs,
bufferForPlaybackMs,
bufferForPlaybackAfterRebufferMs,
targetBufferBytes,
prioritizeTimeOverSizeThresholds,
priorityTaskManager,
DEFAULT_BACK_BUFFER_DURATION_MS,
DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME);
}
protected DefaultLoadControl(
DefaultAllocator allocator,
int minBufferMs,
int maxBufferMs,
int bufferForPlaybackMs,
int bufferForPlaybackAfterRebufferMs,
int targetBufferBytes,
boolean prioritizeTimeOverSizeThresholds,
PriorityTaskManager priorityTaskManager,
int backBufferDurationMs,
boolean retainBackBufferFromKeyframe) {
assertGreaterOrEqual(bufferForPlaybackMs, 0, "bufferForPlaybackMs", "0"); assertGreaterOrEqual(bufferForPlaybackMs, 0, "bufferForPlaybackMs", "0");
assertGreaterOrEqual( assertGreaterOrEqual(
bufferForPlaybackAfterRebufferMs, 0, "bufferForPlaybackAfterRebufferMs", "0"); bufferForPlaybackAfterRebufferMs, 0, "bufferForPlaybackAfterRebufferMs", "0");
@ -247,15 +303,18 @@ public class DefaultLoadControl implements LoadControl {
"minBufferMs", "minBufferMs",
"bufferForPlaybackAfterRebufferMs"); "bufferForPlaybackAfterRebufferMs");
assertGreaterOrEqual(maxBufferMs, minBufferMs, "maxBufferMs", "minBufferMs"); assertGreaterOrEqual(maxBufferMs, minBufferMs, "maxBufferMs", "minBufferMs");
assertGreaterOrEqual(backBufferDurationMs, 0, "backBufferDurationMs", "0");
this.allocator = allocator; this.allocator = allocator;
minBufferUs = minBufferMs * 1000L; this.minBufferUs = C.msToUs(minBufferMs);
maxBufferUs = maxBufferMs * 1000L; this.maxBufferUs = C.msToUs(maxBufferMs);
bufferForPlaybackUs = bufferForPlaybackMs * 1000L; this.bufferForPlaybackUs = C.msToUs(bufferForPlaybackMs);
bufferForPlaybackAfterRebufferUs = bufferForPlaybackAfterRebufferMs * 1000L; this.bufferForPlaybackAfterRebufferUs = C.msToUs(bufferForPlaybackAfterRebufferMs);
targetBufferBytesOverwrite = targetBufferBytes; this.targetBufferBytesOverwrite = targetBufferBytes;
this.prioritizeTimeOverSizeThresholds = prioritizeTimeOverSizeThresholds; this.prioritizeTimeOverSizeThresholds = prioritizeTimeOverSizeThresholds;
this.priorityTaskManager = priorityTaskManager; this.priorityTaskManager = priorityTaskManager;
this.backBufferDurationUs = C.msToUs(backBufferDurationMs);
this.retainBackBufferFromKeyframe = retainBackBufferFromKeyframe;
} }
@Override @Override
@ -290,12 +349,12 @@ public class DefaultLoadControl implements LoadControl {
@Override @Override
public long getBackBufferDurationUs() { public long getBackBufferDurationUs() {
return 0; return backBufferDurationUs;
} }
@Override @Override
public boolean retainBackBufferFromKeyframe() { public boolean retainBackBufferFromKeyframe() {
return false; return retainBackBufferFromKeyframe;
} }
@Override @Override