LoadControler no longer uses TrackSelectionArray

Instead it uses a TrackSelection[].

#player-to-common

PiperOrigin-RevId: 353584567
This commit is contained in:
krocard 2021-01-25 07:23:04 +00:00 committed by Ian Baker
parent bf3816bd41
commit 6a900ab11b
4 changed files with 33 additions and 44 deletions

View File

@ -21,16 +21,14 @@ import static java.lang.Math.min;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.source.TrackGroupArray; 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.Allocator;
import com.google.android.exoplayer2.upstream.DefaultAllocator; import com.google.android.exoplayer2.upstream.DefaultAllocator;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
/** /** The default {@link LoadControl} implementation. */
* The default {@link LoadControl} implementation.
*/
public class DefaultLoadControl implements LoadControl { public class DefaultLoadControl implements LoadControl {
/** /**
@ -318,8 +316,8 @@ public class DefaultLoadControl implements LoadControl {
} }
@Override @Override
public void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups, public void onTracksSelected(
TrackSelectionArray trackSelections) { Renderer[] renderers, TrackGroupArray trackGroups, TrackSelection[] trackSelections) {
targetBufferBytes = targetBufferBytes =
targetBufferBytesOverwrite == C.LENGTH_UNSET targetBufferBytesOverwrite == C.LENGTH_UNSET
? calculateTargetBufferBytes(renderers, trackSelections) ? calculateTargetBufferBytes(renderers, trackSelections)
@ -402,10 +400,10 @@ public class DefaultLoadControl implements LoadControl {
* @return The target buffer size in bytes. * @return The target buffer size in bytes.
*/ */
protected int calculateTargetBufferBytes( protected int calculateTargetBufferBytes(
Renderer[] renderers, TrackSelectionArray trackSelectionArray) { Renderer[] renderers, TrackSelection[] trackSelectionArray) {
int targetBufferSize = 0; int targetBufferSize = 0;
for (int i = 0; i < renderers.length; i++) { for (int i = 0; i < renderers.length; i++) {
if (trackSelectionArray.get(i) != null) { if (trackSelectionArray[i] != null) {
targetBufferSize += getDefaultBufferSize(renderers[i].getTrackType()); targetBufferSize += getDefaultBufferSize(renderers[i].getTrackType());
} }
} }

View File

@ -41,7 +41,6 @@ import com.google.android.exoplayer2.source.SampleStream;
import com.google.android.exoplayer2.source.ShuffleOrder; import com.google.android.exoplayer2.source.ShuffleOrder;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.TrackSelection; 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.TrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelectorResult; import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.BandwidthMeter;
@ -2396,8 +2395,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
private void updateLoadControlTrackSelection( private void updateLoadControlTrackSelection(
TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) { TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
TrackSelectionArray newSelection = new TrackSelectionArray(trackSelectorResult.selections); loadControl.onTracksSelected(renderers, trackGroups, trackSelectorResult.selections);
loadControl.onTracksSelected(renderers, trackGroups, newSelection);
} }
private boolean shouldPlayWhenReady() { private boolean shouldPlayWhenReady() {

View File

@ -17,12 +17,10 @@ package com.google.android.exoplayer2;
import com.google.android.exoplayer2.source.TrackGroup; import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray; 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.Allocator;
/** /** Controls buffering of media. */
* Controls buffering of media.
*/
public interface LoadControl { public interface LoadControl {
/** Called by the player when prepared with a new source. */ /** 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 trackGroups The {@link TrackGroup}s from which the selection was made.
* @param trackSelections The track selections that were made. * @param trackSelections The track selections that were made.
*/ */
void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups, void onTracksSelected(
TrackSelectionArray trackSelections); Renderer[] renderers, TrackGroupArray trackGroups, TrackSelection[] trackSelections);
/** /** Called by the player when stopped. */
* Called by the player when stopped.
*/
void onStopped(); void onStopped();
/** /** Called by the player when released. */
* Called by the player when released.
*/
void onReleased(); 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(); Allocator getAllocator();
/** /**
* Returns the duration of media to retain in the buffer prior to the current playback position, * Returns the duration of media to retain in the buffer prior to the current playback position,
* for fast backward seeking. * for fast backward seeking.
* <p> *
* Note: If {@link #retainBackBufferFromKeyframe()} is false then seeking in the back-buffer will * <p>Note: If {@link #retainBackBufferFromKeyframe()} is false then seeking in the back-buffer
* only be fast if the back-buffer contains a keyframe prior to the seek position. * will only be fast if the back-buffer contains a keyframe prior to the seek position.
* <p> *
* Note: Implementations should return a single value. Dynamic changes to the back-buffer are not * <p>Note: Implementations should return a single value. Dynamic changes to the back-buffer are
* currently supported. * not currently supported.
* *
* @return The duration of media to retain in the buffer prior to the current playback position, * @return The duration of media to retain in the buffer prior to the current playback position,
* in microseconds. * in microseconds.
@ -71,17 +63,19 @@ public interface LoadControl {
/** /**
* Returns whether media should be retained from the keyframe before the current playback position * 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. * minus {@link #getBackBufferDurationUs()}, rather than any sample before or at that position.
* <p> *
* Warning: Returning true will cause the back-buffer size to depend on the spacing of keyframes * <p>Warning: Returning true will cause the back-buffer size to depend on the spacing of
* in the media being played. Returning true is not recommended unless you control the media and * keyframes in the media being played. Returning true is not recommended unless you control the
* are comfortable with the back-buffer size exceeding {@link #getBackBufferDurationUs()} by as * media and are comfortable with the back-buffer size exceeding {@link
* much as the maximum duration between adjacent keyframes in the media. * #getBackBufferDurationUs()} by as much as the maximum duration between adjacent keyframes in
* <p> * the media.
* Note: Implementations should return a single value. Dynamic changes to the back-buffer are not *
* currently supported. * <p>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 * @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(); boolean retainBackBufferFromKeyframe();

View File

@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.DefaultLoadControl.Builder; import com.google.android.exoplayer2.DefaultLoadControl.Builder;
import com.google.android.exoplayer2.source.TrackGroupArray; 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 com.google.android.exoplayer2.upstream.DefaultAllocator;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -177,7 +177,7 @@ public class DefaultLoadControlTest {
@Test @Test
public void shouldContinueLoading_withNoSelectedTracks_returnsTrue() { public void shouldContinueLoading_withNoSelectedTracks_returnsTrue() {
loadControl = builder.build(); loadControl = builder.build();
loadControl.onTracksSelected(new Renderer[0], TrackGroupArray.EMPTY, new TrackSelectionArray()); loadControl.onTracksSelected(new Renderer[0], TrackGroupArray.EMPTY, new TrackSelection[0]);
assertThat( assertThat(
loadControl.shouldContinueLoading( loadControl.shouldContinueLoading(
@ -321,5 +321,4 @@ public class DefaultLoadControlTest {
allocator.allocate(); allocator.allocate();
} }
} }
} }