diff --git a/library/core/src/main/java/com/google/android/exoplayer2/DefaultLoadControl.java b/library/core/src/main/java/com/google/android/exoplayer2/DefaultLoadControl.java index e4b6edba5b..c3ae1f52ac 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/DefaultLoadControl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/DefaultLoadControl.java @@ -21,16 +21,14 @@ import static java.lang.Math.min; import androidx.annotation.Nullable; import com.google.android.exoplayer2.source.TrackGroupArray; -import com.google.android.exoplayer2.trackselection.TrackSelectionArray; +import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.DefaultAllocator; import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Util; -/** - * The default {@link LoadControl} implementation. - */ +/** The default {@link LoadControl} implementation. */ public class DefaultLoadControl implements LoadControl { /** @@ -318,8 +316,8 @@ public class DefaultLoadControl implements LoadControl { } @Override - public void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups, - TrackSelectionArray trackSelections) { + public void onTracksSelected( + Renderer[] renderers, TrackGroupArray trackGroups, TrackSelection[] trackSelections) { targetBufferBytes = targetBufferBytesOverwrite == C.LENGTH_UNSET ? calculateTargetBufferBytes(renderers, trackSelections) @@ -402,10 +400,10 @@ public class DefaultLoadControl implements LoadControl { * @return The target buffer size in bytes. */ protected int calculateTargetBufferBytes( - Renderer[] renderers, TrackSelectionArray trackSelectionArray) { + Renderer[] renderers, TrackSelection[] trackSelectionArray) { int targetBufferSize = 0; for (int i = 0; i < renderers.length; i++) { - if (trackSelectionArray.get(i) != null) { + if (trackSelectionArray[i] != null) { targetBufferSize += getDefaultBufferSize(renderers[i].getTrackType()); } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index d025b73ac1..d925e99055 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -41,7 +41,6 @@ import com.google.android.exoplayer2.source.SampleStream; import com.google.android.exoplayer2.source.ShuffleOrder; import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.trackselection.TrackSelection; -import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelectorResult; import com.google.android.exoplayer2.upstream.BandwidthMeter; @@ -2396,8 +2395,7 @@ import java.util.concurrent.atomic.AtomicBoolean; private void updateLoadControlTrackSelection( TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) { - TrackSelectionArray newSelection = new TrackSelectionArray(trackSelectorResult.selections); - loadControl.onTracksSelected(renderers, trackGroups, newSelection); + loadControl.onTracksSelected(renderers, trackGroups, trackSelectorResult.selections); } private boolean shouldPlayWhenReady() { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/LoadControl.java b/library/core/src/main/java/com/google/android/exoplayer2/LoadControl.java index f04ae8027d..445bc4eb19 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/LoadControl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/LoadControl.java @@ -17,12 +17,10 @@ package com.google.android.exoplayer2; import com.google.android.exoplayer2.source.TrackGroup; import com.google.android.exoplayer2.source.TrackGroupArray; -import com.google.android.exoplayer2.trackselection.TrackSelectionArray; +import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.upstream.Allocator; -/** - * Controls buffering of media. - */ +/** Controls buffering of media. */ public interface LoadControl { /** Called by the player when prepared with a new source. */ @@ -35,33 +33,27 @@ public interface LoadControl { * @param trackGroups The {@link TrackGroup}s from which the selection was made. * @param trackSelections The track selections that were made. */ - void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups, - TrackSelectionArray trackSelections); + void onTracksSelected( + Renderer[] renderers, TrackGroupArray trackGroups, TrackSelection[] trackSelections); - /** - * Called by the player when stopped. - */ + /** Called by the player when stopped. */ void onStopped(); - /** - * Called by the player when released. - */ + /** Called by the player when released. */ void onReleased(); - /** - * Returns the {@link Allocator} that should be used to obtain media buffer allocations. - */ + /** Returns the {@link Allocator} that should be used to obtain media buffer allocations. */ Allocator getAllocator(); /** * Returns the duration of media to retain in the buffer prior to the current playback position, * for fast backward seeking. - *

- * Note: If {@link #retainBackBufferFromKeyframe()} is false then seeking in the back-buffer will - * only be fast if the back-buffer contains a keyframe prior to the seek position. - *

- * Note: Implementations should return a single value. Dynamic changes to the back-buffer are not - * currently supported. + * + *

Note: If {@link #retainBackBufferFromKeyframe()} is false then seeking in the back-buffer + * will only be fast if the back-buffer contains a keyframe prior to the seek position. + * + *

Note: Implementations should return a single value. Dynamic changes to the back-buffer are + * not currently supported. * * @return The duration of media to retain in the buffer prior to the current playback position, * in microseconds. @@ -71,17 +63,19 @@ public interface LoadControl { /** * Returns whether media should be retained from the keyframe before the current playback position * minus {@link #getBackBufferDurationUs()}, rather than any sample before or at that position. - *

- * Warning: Returning true will cause the back-buffer size to depend on the spacing of keyframes - * in the media being played. Returning true is not recommended unless you control the media and - * are comfortable with the back-buffer size exceeding {@link #getBackBufferDurationUs()} by as - * much as the maximum duration between adjacent keyframes in the media. - *

- * Note: Implementations should return a single value. Dynamic changes to the back-buffer are not - * currently supported. + * + *

Warning: Returning true will cause the back-buffer size to depend on the spacing of + * keyframes in the media being played. Returning true is not recommended unless you control the + * media and are comfortable with the back-buffer size exceeding {@link + * #getBackBufferDurationUs()} by as much as the maximum duration between adjacent keyframes in + * the media. + * + *

Note: Implementations should return a single value. Dynamic changes to the back-buffer are + * not currently supported. * * @return Whether media should be retained from the keyframe before the current playback position - * minus {@link #getBackBufferDurationUs()}, rather than any sample before or at that position. + * minus {@link #getBackBufferDurationUs()}, rather than any sample before or at that + * position. */ boolean retainBackBufferFromKeyframe(); diff --git a/library/core/src/test/java/com/google/android/exoplayer2/DefaultLoadControlTest.java b/library/core/src/test/java/com/google/android/exoplayer2/DefaultLoadControlTest.java index 241da059ab..3079939179 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/DefaultLoadControlTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/DefaultLoadControlTest.java @@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.DefaultLoadControl.Builder; import com.google.android.exoplayer2.source.TrackGroupArray; -import com.google.android.exoplayer2.trackselection.TrackSelectionArray; +import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.upstream.DefaultAllocator; import org.junit.Before; import org.junit.Test; @@ -177,7 +177,7 @@ public class DefaultLoadControlTest { @Test public void shouldContinueLoading_withNoSelectedTracks_returnsTrue() { loadControl = builder.build(); - loadControl.onTracksSelected(new Renderer[0], TrackGroupArray.EMPTY, new TrackSelectionArray()); + loadControl.onTracksSelected(new Renderer[0], TrackGroupArray.EMPTY, new TrackSelection[0]); assertThat( loadControl.shouldContinueLoading( @@ -321,5 +321,4 @@ public class DefaultLoadControlTest { allocator.allocate(); } } - }