Commit edff52ba by tonihei Committed by Oliver Woodman

Add buffer size based adaptive track selection.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=222221294
parent a3c04698
...@@ -197,9 +197,10 @@ public class DefaultLoadControl implements LoadControl { ...@@ -197,9 +197,10 @@ public class DefaultLoadControl implements LoadControl {
/** Creates a {@link DefaultLoadControl}. */ /** Creates a {@link DefaultLoadControl}. */
public DefaultLoadControl createDefaultLoadControl() { public DefaultLoadControl createDefaultLoadControl() {
Assertions.checkState(!createDefaultLoadControlCalled);
createDefaultLoadControlCalled = true; createDefaultLoadControlCalled = true;
if (allocator == null) { if (allocator == null) {
allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE); allocator = new DefaultAllocator(/* trimOnReset= */ true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
} }
return new DefaultLoadControl( return new DefaultLoadControl(
allocator, allocator,
......
...@@ -774,6 +774,7 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -774,6 +774,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
for (Renderer renderer : enabledRenderers) { for (Renderer renderer : enabledRenderers) {
renderer.resetPosition(rendererPositionUs); renderer.resetPosition(rendererPositionUs);
} }
notifyTrackSelectionDiscontinuity();
} }
private void setPlaybackParametersInternal(PlaybackParameters playbackParameters) { private void setPlaybackParametersInternal(PlaybackParameters playbackParameters) {
...@@ -1172,6 +1173,22 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -1172,6 +1173,22 @@ import java.util.concurrent.atomic.AtomicBoolean;
} }
} }
private void notifyTrackSelectionDiscontinuity() {
MediaPeriodHolder periodHolder = queue.getFrontPeriod();
while (periodHolder != null) {
TrackSelectorResult trackSelectorResult = periodHolder.getTrackSelectorResult();
if (trackSelectorResult != null) {
TrackSelection[] trackSelections = trackSelectorResult.selections.getAll();
for (TrackSelection trackSelection : trackSelections) {
if (trackSelection != null) {
trackSelection.onDiscontinuity();
}
}
}
periodHolder = periodHolder.getNext();
}
}
private boolean shouldTransitionToReadyState(boolean renderersReadyOrEnded) { private boolean shouldTransitionToReadyState(boolean renderersReadyOrEnded) {
if (enabledRenderers.length == 0) { if (enabledRenderers.length == 0) {
// If there are no enabled renderers, determine whether we're ready based on the timeline. // If there are no enabled renderers, determine whether we're ready based on the timeline.
......
...@@ -155,6 +155,13 @@ public interface TrackSelection { ...@@ -155,6 +155,13 @@ public interface TrackSelection {
void onPlaybackSpeed(float speed); void onPlaybackSpeed(float speed);
/** /**
* Called to notify the selection of a position discontinuity.
*
* <p>This happens when the playback position jumps, e.g., as a result of a seek being performed.
*/
default void onDiscontinuity() {}
/**
* @deprecated Use and implement {@link #updateSelectedTrack(long, long, long, List, * @deprecated Use and implement {@link #updateSelectedTrack(long, long, long, List,
* MediaChunkIterator[])} instead. * MediaChunkIterator[])} instead.
*/ */
......
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