Remove non Player use of TrackSelectionArray, use TrackSelection[]

This is necessary for the child cl that `TrackSelection`
in two distinct class. It avoids to split the array
version of such class too.

TrackSelectionArray exist to have an immutable array of TrackSelection.
Internal users are trusted to not mutate the array.

One drawback of this approach is that a `TrackSelectionArray`
has to be allocated on the boundary of the `Player` interface.
This should not be a performance issue as this only happens
on trackSelection changes, when the user calls
`Player.getCurrentTrackSelections` and on
`updateLoadControlTrackSelection`.

#player-to-common

PiperOrigin-RevId: 353582654
This commit is contained in:
krocard 2021-01-25 06:59:26 +00:00 committed by Ian Baker
parent c5a8154970
commit bf3816bd41
6 changed files with 144 additions and 143 deletions

View File

@ -138,8 +138,15 @@ import java.util.List;
Clock clock, Clock clock,
Looper applicationLooper, Looper applicationLooper,
@Nullable Player wrappingPlayer) { @Nullable Player wrappingPlayer) {
Log.i(TAG, "Init " + Integer.toHexString(System.identityHashCode(this)) + " [" Log.i(
+ ExoPlayerLibraryInfo.VERSION_SLASHY + "] [" + Util.DEVICE_DEBUG_INFO + "]"); TAG,
"Init "
+ Integer.toHexString(System.identityHashCode(this))
+ " ["
+ ExoPlayerLibraryInfo.VERSION_SLASHY
+ "] ["
+ Util.DEVICE_DEBUG_INFO
+ "]");
checkState(renderers.length > 0); checkState(renderers.length > 0);
this.renderers = checkNotNull(renderers); this.renderers = checkNotNull(renderers);
this.trackSelector = checkNotNull(trackSelector); this.trackSelector = checkNotNull(trackSelector);
@ -731,9 +738,17 @@ import java.util.List;
@Override @Override
public void release() { public void release() {
Log.i(TAG, "Release " + Integer.toHexString(System.identityHashCode(this)) + " [" Log.i(
+ ExoPlayerLibraryInfo.VERSION_SLASHY + "] [" + Util.DEVICE_DEBUG_INFO + "] [" TAG,
+ ExoPlayerLibraryInfo.registeredModules() + "]"); "Release "
+ Integer.toHexString(System.identityHashCode(this))
+ " ["
+ ExoPlayerLibraryInfo.VERSION_SLASHY
+ "] ["
+ Util.DEVICE_DEBUG_INFO
+ "] ["
+ ExoPlayerLibraryInfo.registeredModules()
+ "]");
if (!internalPlayer.release()) { if (!internalPlayer.release()) {
// One of the renderers timed out releasing its resources. // One of the renderers timed out releasing its resources.
listeners.sendEvent( listeners.sendEvent(
@ -890,7 +905,7 @@ import java.util.List;
@Override @Override
public TrackSelectionArray getCurrentTrackSelections() { public TrackSelectionArray getCurrentTrackSelections() {
return playbackInfo.trackSelectorResult.selections; return new TrackSelectionArray(playbackInfo.trackSelectorResult.selections);
} }
@Override @Override
@ -1013,11 +1028,11 @@ import java.util.List;
} }
if (previousPlaybackInfo.trackSelectorResult != newPlaybackInfo.trackSelectorResult) { if (previousPlaybackInfo.trackSelectorResult != newPlaybackInfo.trackSelectorResult) {
trackSelector.onSelectionActivated(newPlaybackInfo.trackSelectorResult.info); trackSelector.onSelectionActivated(newPlaybackInfo.trackSelectorResult.info);
TrackSelectionArray newSelection =
new TrackSelectionArray(newPlaybackInfo.trackSelectorResult.selections);
listeners.queueEvent( listeners.queueEvent(
Player.EVENT_TRACKS_CHANGED, Player.EVENT_TRACKS_CHANGED,
listener -> listener -> listener.onTracksChanged(newPlaybackInfo.trackGroups, newSelection));
listener.onTracksChanged(
newPlaybackInfo.trackGroups, newPlaybackInfo.trackSelectorResult.selections));
} }
if (!previousPlaybackInfo.staticMetadata.equals(newPlaybackInfo.staticMetadata)) { if (!previousPlaybackInfo.staticMetadata.equals(newPlaybackInfo.staticMetadata)) {
listeners.queueEvent( listeners.queueEvent(

View File

@ -726,8 +726,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
private void notifyTrackSelectionPlayWhenReadyChanged(boolean playWhenReady) { private void notifyTrackSelectionPlayWhenReadyChanged(boolean playWhenReady) {
MediaPeriodHolder periodHolder = queue.getPlayingPeriod(); MediaPeriodHolder periodHolder = queue.getPlayingPeriod();
while (periodHolder != null) { while (periodHolder != null) {
TrackSelection[] trackSelections = periodHolder.getTrackSelectorResult().selections.getAll(); for (TrackSelection trackSelection : periodHolder.getTrackSelectorResult().selections) {
for (TrackSelection trackSelection : trackSelections) {
if (trackSelection != null) { if (trackSelection != null) {
trackSelection.onPlayWhenReadyChanged(playWhenReady); trackSelection.onPlayWhenReadyChanged(playWhenReady);
} }
@ -901,8 +900,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
private void notifyTrackSelectionRebuffer() { private void notifyTrackSelectionRebuffer() {
MediaPeriodHolder periodHolder = queue.getPlayingPeriod(); MediaPeriodHolder periodHolder = queue.getPlayingPeriod();
while (periodHolder != null) { while (periodHolder != null) {
TrackSelection[] trackSelections = periodHolder.getTrackSelectorResult().selections.getAll(); for (TrackSelection trackSelection : periodHolder.getTrackSelectorResult().selections) {
for (TrackSelection trackSelection : trackSelections) {
if (trackSelection != null) { if (trackSelection != null) {
trackSelection.onRebuffer(); trackSelection.onRebuffer();
} }
@ -1692,8 +1690,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
private void updateTrackSelectionPlaybackSpeed(float playbackSpeed) { private void updateTrackSelectionPlaybackSpeed(float playbackSpeed) {
MediaPeriodHolder periodHolder = queue.getPlayingPeriod(); MediaPeriodHolder periodHolder = queue.getPlayingPeriod();
while (periodHolder != null) { while (periodHolder != null) {
TrackSelection[] trackSelections = periodHolder.getTrackSelectorResult().selections.getAll(); for (TrackSelection trackSelection : periodHolder.getTrackSelectorResult().selections) {
for (TrackSelection trackSelection : trackSelections) {
if (trackSelection != null) { if (trackSelection != null) {
trackSelection.onPlaybackSpeed(playbackSpeed); trackSelection.onPlaybackSpeed(playbackSpeed);
} }
@ -1705,8 +1702,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
private void notifyTrackSelectionDiscontinuity() { private void notifyTrackSelectionDiscontinuity() {
MediaPeriodHolder periodHolder = queue.getPlayingPeriod(); MediaPeriodHolder periodHolder = queue.getPlayingPeriod();
while (periodHolder != null) { while (periodHolder != null) {
TrackSelection[] trackSelections = periodHolder.getTrackSelectorResult().selections.getAll(); for (TrackSelection trackSelection : periodHolder.getTrackSelectorResult().selections) {
for (TrackSelection trackSelection : trackSelections) {
if (trackSelection != null) { if (trackSelection != null) {
trackSelection.onDiscontinuity(); trackSelection.onDiscontinuity();
} }
@ -2018,7 +2014,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
} }
if (!renderer.isCurrentStreamFinal()) { if (!renderer.isCurrentStreamFinal()) {
// The renderer stream is not final, so we can replace the sample streams immediately. // The renderer stream is not final, so we can replace the sample streams immediately.
Format[] formats = getFormats(newTrackSelectorResult.selections.get(i)); Format[] formats = getFormats(newTrackSelectorResult.selections[i]);
renderer.replaceStream( renderer.replaceStream(
formats, formats,
readingPeriodHolder.sampleStreams[i], readingPeriodHolder.sampleStreams[i],
@ -2268,11 +2264,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
} }
private ImmutableList<Metadata> extractMetadataFromTrackSelectionArray( private ImmutableList<Metadata> extractMetadataFromTrackSelectionArray(
TrackSelectionArray trackSelectionArray) { TrackSelection[] trackSelections) {
ImmutableList.Builder<Metadata> result = new ImmutableList.Builder<>(); ImmutableList.Builder<Metadata> result = new ImmutableList.Builder<>();
boolean seenNonEmptyMetadata = false; boolean seenNonEmptyMetadata = false;
for (int i = 0; i < trackSelectionArray.length; i++) { for (TrackSelection trackSelection : trackSelections) {
@Nullable TrackSelection trackSelection = trackSelectionArray.get(i);
if (trackSelection != null) { if (trackSelection != null) {
Format format = trackSelection.getFormat(/* index= */ 0); Format format = trackSelection.getFormat(/* index= */ 0);
if (format.metadata == null) { if (format.metadata == null) {
@ -2320,7 +2315,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
TrackSelectorResult trackSelectorResult = periodHolder.getTrackSelectorResult(); TrackSelectorResult trackSelectorResult = periodHolder.getTrackSelectorResult();
RendererConfiguration rendererConfiguration = RendererConfiguration rendererConfiguration =
trackSelectorResult.rendererConfigurations[rendererIndex]; trackSelectorResult.rendererConfigurations[rendererIndex];
TrackSelection newSelection = trackSelectorResult.selections.get(rendererIndex); TrackSelection newSelection = trackSelectorResult.selections[rendererIndex];
Format[] formats = getFormats(newSelection); Format[] formats = getFormats(newSelection);
// The renderer needs enabling with its new track selection. // The renderer needs enabling with its new track selection.
boolean playing = shouldPlayWhenReady() && playbackInfo.playbackState == Player.STATE_READY; boolean playing = shouldPlayWhenReady() && playbackInfo.playbackState == Player.STATE_READY;
@ -2401,7 +2396,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
private void updateLoadControlTrackSelection( private void updateLoadControlTrackSelection(
TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) { TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
loadControl.onTracksSelected(renderers, trackGroups, trackSelectorResult.selections); TrackSelectionArray newSelection = new TrackSelectionArray(trackSelectorResult.selections);
loadControl.onTracksSelected(renderers, trackGroups, newSelection);
} }
private boolean shouldPlayWhenReady() { private boolean shouldPlayWhenReady() {

View File

@ -25,7 +25,6 @@ import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.SampleStream; import com.google.android.exoplayer2.source.SampleStream;
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.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
@ -233,7 +232,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
throws ExoPlaybackException { throws ExoPlaybackException {
TrackSelectorResult selectorResult = TrackSelectorResult selectorResult =
trackSelector.selectTracks(rendererCapabilities, getTrackGroups(), info.id, timeline); trackSelector.selectTracks(rendererCapabilities, getTrackGroups(), info.id, timeline);
for (TrackSelection trackSelection : selectorResult.selections.getAll()) { for (TrackSelection trackSelection : selectorResult.selections) {
if (trackSelection != null) { if (trackSelection != null) {
trackSelection.onPlaybackSpeed(playbackSpeed); trackSelection.onPlaybackSpeed(playbackSpeed);
} }
@ -289,10 +288,9 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
trackSelectorResult = newTrackSelectorResult; trackSelectorResult = newTrackSelectorResult;
enableTrackSelectionsInResult(); enableTrackSelectionsInResult();
// Disable streams on the period and get new streams for updated/newly-enabled tracks. // Disable streams on the period and get new streams for updated/newly-enabled tracks.
TrackSelectionArray trackSelections = newTrackSelectorResult.selections;
positionUs = positionUs =
mediaPeriod.selectTracks( mediaPeriod.selectTracks(
trackSelections.getAll(), newTrackSelectorResult.selections,
mayRetainStreamFlags, mayRetainStreamFlags,
sampleStreams, sampleStreams,
streamResetFlags, streamResetFlags,
@ -309,7 +307,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
hasEnabledTracks = true; hasEnabledTracks = true;
} }
} else { } else {
Assertions.checkState(trackSelections.get(i) == null); Assertions.checkState(newTrackSelectorResult.selections[i] == null);
} }
} }
return positionUs; return positionUs;
@ -361,7 +359,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
} }
for (int i = 0; i < trackSelectorResult.length; i++) { for (int i = 0; i < trackSelectorResult.length; i++) {
boolean rendererEnabled = trackSelectorResult.isRendererEnabled(i); boolean rendererEnabled = trackSelectorResult.isRendererEnabled(i);
TrackSelection trackSelection = trackSelectorResult.selections.get(i); TrackSelection trackSelection = trackSelectorResult.selections[i];
if (rendererEnabled && trackSelection != null) { if (rendererEnabled && trackSelection != null) {
trackSelection.enable(); trackSelection.enable();
} }
@ -374,7 +372,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
} }
for (int i = 0; i < trackSelectorResult.length; i++) { for (int i = 0; i < trackSelectorResult.length; i++) {
boolean rendererEnabled = trackSelectorResult.isRendererEnabled(i); boolean rendererEnabled = trackSelectorResult.isRendererEnabled(i);
TrackSelection trackSelection = trackSelectorResult.selections.get(i); TrackSelection trackSelection = trackSelectorResult.selections[i];
if (rendererEnabled && trackSelection != null) { if (rendererEnabled && trackSelection != null) {
trackSelection.disable(); trackSelection.disable();
} }

View File

@ -847,7 +847,7 @@ public final class DownloadHelper {
new MediaPeriodId(mediaPreparer.timeline.getUidOfPeriod(periodIndex)), new MediaPeriodId(mediaPreparer.timeline.getUidOfPeriod(periodIndex)),
mediaPreparer.timeline); mediaPreparer.timeline);
for (int i = 0; i < trackSelectorResult.length; i++) { for (int i = 0; i < trackSelectorResult.length; i++) {
@Nullable TrackSelection newSelection = trackSelectorResult.selections.get(i); @Nullable TrackSelection newSelection = trackSelectorResult.selections[i];
if (newSelection == null) { if (newSelection == null) {
continue; continue;
} }

View File

@ -20,9 +20,7 @@ import com.google.android.exoplayer2.RendererConfiguration;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import org.checkerframework.checker.nullness.compatqual.NullableType; import org.checkerframework.checker.nullness.compatqual.NullableType;
/** /** The result of a {@link TrackSelector} operation. */
* The result of a {@link TrackSelector} operation.
*/
public final class TrackSelectorResult { public final class TrackSelectorResult {
/** The number of selections in the result. Greater than or equal to zero. */ /** The number of selections in the result. Greater than or equal to zero. */
@ -32,10 +30,8 @@ public final class TrackSelectorResult {
* renderer should be disabled. * renderer should be disabled.
*/ */
public final @NullableType RendererConfiguration[] rendererConfigurations; public final @NullableType RendererConfiguration[] rendererConfigurations;
/** /** A {@link TrackSelection} array containing the track selection for each renderer. */
* A {@link TrackSelectionArray} containing the track selection for each renderer. public final @NullableType TrackSelection[] selections;
*/
public final TrackSelectionArray selections;
/** /**
* An opaque object that will be returned to {@link TrackSelector#onSelectionActivated(Object)} * An opaque object that will be returned to {@link TrackSelector#onSelectionActivated(Object)}
* should the selections be activated. * should the selections be activated.
@ -45,7 +41,7 @@ public final class TrackSelectorResult {
/** /**
* @param rendererConfigurations A {@link RendererConfiguration} for each renderer. A null entry * @param rendererConfigurations A {@link RendererConfiguration} for each renderer. A null entry
* indicates the corresponding renderer should be disabled. * indicates the corresponding renderer should be disabled.
* @param selections A {@link TrackSelectionArray} containing the selection for each renderer. * @param selections A {@link TrackSelection} array containing the selection for each renderer.
* @param info An opaque object that will be returned to {@link * @param info An opaque object that will be returned to {@link
* TrackSelector#onSelectionActivated(Object)} should the selection be activated. May be * TrackSelector#onSelectionActivated(Object)} should the selection be activated. May be
* {@code null}. * {@code null}.
@ -55,7 +51,7 @@ public final class TrackSelectorResult {
@NullableType TrackSelection[] selections, @NullableType TrackSelection[] selections,
@Nullable Object info) { @Nullable Object info) {
this.rendererConfigurations = rendererConfigurations; this.rendererConfigurations = rendererConfigurations;
this.selections = new TrackSelectionArray(selections); this.selections = selections.clone();
this.info = info; this.info = info;
length = rendererConfigurations.length; length = rendererConfigurations.length;
} }
@ -100,7 +96,6 @@ public final class TrackSelectorResult {
return false; return false;
} }
return Util.areEqual(rendererConfigurations[index], other.rendererConfigurations[index]) return Util.areEqual(rendererConfigurations[index], other.rendererConfigurations[index])
&& Util.areEqual(selections.get(index), other.selections.get(index)); && Util.areEqual(selections[index], other.selections[index]);
} }
} }

View File

@ -323,7 +323,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, formatWithSelectionFlag); assertFixedSelection(result.selections[0], trackGroups, formatWithSelectionFlag);
} }
/** Tests that adaptive audio track selections respect the maximum audio bitrate. */ /** Tests that adaptive audio track selections respect the maximum audio bitrate. */
@ -341,25 +341,25 @@ public final class DefaultTrackSelectorTest {
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 2, 0, 1); assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 2, 0, 1);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector.buildUponParameters().setMaxAudioBitrate(256 * 1024 - 1)); trackSelector.buildUponParameters().setMaxAudioBitrate(256 * 1024 - 1));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1); assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 0, 1);
trackSelector.setParameters(trackSelector.buildUponParameters().setMaxAudioBitrate(192 * 1024)); trackSelector.setParameters(trackSelector.buildUponParameters().setMaxAudioBitrate(192 * 1024));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1); assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 0, 1);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector.buildUponParameters().setMaxAudioBitrate(192 * 1024 - 1)); trackSelector.buildUponParameters().setMaxAudioBitrate(192 * 1024 - 1));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups.get(0), 1); assertFixedSelection(result.selections[0], trackGroups.get(0), 1);
trackSelector.setParameters(trackSelector.buildUponParameters().setMaxAudioBitrate(10)); trackSelector.setParameters(trackSelector.buildUponParameters().setMaxAudioBitrate(10));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups.get(0), 1); assertFixedSelection(result.selections[0], trackGroups.get(0), 1);
} }
/** /**
@ -380,7 +380,7 @@ public final class DefaultTrackSelectorTest {
wrapFormats(frAudioFormat, enAudioFormat), wrapFormats(frAudioFormat, enAudioFormat),
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, enAudioFormat); assertFixedSelection(result.selections[0], trackGroups, enAudioFormat);
} }
/** /**
@ -408,7 +408,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, moreRoleFlags); assertFixedSelection(result.selections[0], trackGroups, moreRoleFlags);
} }
/** /**
@ -429,7 +429,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, defaultFormat); assertFixedSelection(result.selections[0], trackGroups, defaultFormat);
} }
/** /**
@ -449,7 +449,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, firstFormat); assertFixedSelection(result.selections[0], trackGroups, firstFormat);
} }
/** /**
@ -471,7 +471,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, enNonDefaultFormat); assertFixedSelection(result.selections[0], trackGroups, enNonDefaultFormat);
} }
/** /**
@ -497,7 +497,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, supportedFormat); assertFixedSelection(result.selections[0], trackGroups, supportedFormat);
} }
/** /**
@ -515,7 +515,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, AUDIO_FORMAT); assertFixedSelection(result.selections[0], trackGroups, AUDIO_FORMAT);
} }
/** /**
@ -536,7 +536,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertNoSelection(result.selections.get(0)); assertNoSelection(result.selections[0]);
} }
/** /**
@ -563,7 +563,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, supportedFormat); assertFixedSelection(result.selections[0], trackGroups, supportedFormat);
} }
/** /**
@ -591,7 +591,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, supportedFrFormat); assertFixedSelection(result.selections[0], trackGroups, supportedFrFormat);
} }
/** /**
@ -626,7 +626,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, supportedFrFormat); assertFixedSelection(result.selections[0], trackGroups, supportedFrFormat);
} }
/** /**
@ -646,7 +646,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, higherChannelFormat); assertFixedSelection(result.selections[0], trackGroups, higherChannelFormat);
} }
/** /**
@ -666,7 +666,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, higherSampleRateFormat); assertFixedSelection(result.selections[0], trackGroups, higherSampleRateFormat);
} }
/** /**
@ -687,7 +687,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, higherBitrateFormat); assertFixedSelection(result.selections[0], trackGroups, higherBitrateFormat);
} }
/** /**
@ -709,7 +709,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, firstLanguageFormat); assertFixedSelection(result.selections[0], trackGroups, firstLanguageFormat);
} }
/** /**
@ -733,7 +733,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, higherChannelLowerSampleRateFormat); assertFixedSelection(result.selections[0], trackGroups, higherChannelLowerSampleRateFormat);
} }
/** /**
@ -756,7 +756,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, higherSampleRateLowerBitrateFormat); assertFixedSelection(result.selections[0], trackGroups, higherSampleRateLowerBitrateFormat);
} }
/** /**
@ -776,7 +776,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, lowerChannelFormat); assertFixedSelection(result.selections[0], trackGroups, lowerChannelFormat);
} }
/** /**
@ -796,7 +796,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, lowerSampleRateFormat); assertFixedSelection(result.selections[0], trackGroups, lowerSampleRateFormat);
} }
/** /**
@ -816,7 +816,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, lowerBitrateFormat); assertFixedSelection(result.selections[0], trackGroups, lowerBitrateFormat);
} }
/** /**
@ -841,7 +841,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, lowerChannelHigherSampleRateFormat); assertFixedSelection(result.selections[0], trackGroups, lowerChannelHigherSampleRateFormat);
} }
/** /**
@ -865,7 +865,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, lowerSampleRateHigherBitrateFormat); assertFixedSelection(result.selections[0], trackGroups, lowerSampleRateHigherBitrateFormat);
} }
/** Tests text track selection flags. */ /** Tests text track selection flags. */
@ -885,12 +885,12 @@ public final class DefaultTrackSelectorTest {
TrackGroupArray trackGroups = wrapFormats(forcedOnly, forcedDefault, defaultOnly, noFlag); TrackGroupArray trackGroups = wrapFormats(forcedOnly, forcedDefault, defaultOnly, noFlag);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE); trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, forcedDefault); assertFixedSelection(result.selections[0], trackGroups, forcedDefault);
// Ditto. // Ditto.
trackGroups = wrapFormats(forcedOnly, noFlag, defaultOnly); trackGroups = wrapFormats(forcedOnly, noFlag, defaultOnly);
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, defaultOnly); assertFixedSelection(result.selections[0], trackGroups, defaultOnly);
// Default flags are disabled and no language preference is provided, so no text track is // Default flags are disabled and no language preference is provided, so no text track is
// selected. // selected.
@ -898,7 +898,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.setParameters( trackSelector.setParameters(
defaultParameters.buildUpon().setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT)); defaultParameters.buildUpon().setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT));
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections.get(0)); assertNoSelection(result.selections[0]);
// All selection flags are disabled and there is no language preference, so nothing should be // All selection flags are disabled and there is no language preference, so nothing should be
// selected. // selected.
@ -910,13 +910,13 @@ public final class DefaultTrackSelectorTest {
.setDisabledTextTrackSelectionFlags( .setDisabledTextTrackSelectionFlags(
C.SELECTION_FLAG_DEFAULT | C.SELECTION_FLAG_FORCED)); C.SELECTION_FLAG_DEFAULT | C.SELECTION_FLAG_FORCED));
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections.get(0)); assertNoSelection(result.selections[0]);
// There is a preferred language, so a language-matching track flagged as default should // There is a preferred language, so a language-matching track flagged as default should
// be selected, and the one without forced flag should be preferred. // be selected, and the one without forced flag should be preferred.
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextLanguage("eng")); trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextLanguage("eng"));
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, defaultOnly); assertFixedSelection(result.selections[0], trackGroups, defaultOnly);
// Same as above, but the default flag is disabled. If multiple tracks match the preferred // Same as above, but the default flag is disabled. If multiple tracks match the preferred
// language, those not flagged as forced are preferred, as they likely include the contents of // language, those not flagged as forced are preferred, as they likely include the contents of
@ -928,7 +928,7 @@ public final class DefaultTrackSelectorTest {
.buildUpon() .buildUpon()
.setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT)); .setDisabledTextTrackSelectionFlags(C.SELECTION_FLAG_DEFAULT));
result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(textRendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, noFlag); assertFixedSelection(result.selections[0], trackGroups, noFlag);
} }
/** /**
@ -957,23 +957,23 @@ public final class DefaultTrackSelectorTest {
TrackGroupArray trackGroups = wrapFormats(noLanguageAudio, forcedNoLanguage); TrackGroupArray trackGroups = wrapFormats(noLanguageAudio, forcedNoLanguage);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(1), trackGroups, forcedNoLanguage); assertFixedSelection(result.selections[1], trackGroups, forcedNoLanguage);
// No forced text track should be selected because none of the forced text tracks' languages // No forced text track should be selected because none of the forced text tracks' languages
// matches the selected audio language. // matches the selected audio language.
trackGroups = wrapFormats(noLanguageAudio, forcedEnglish, forcedGerman); trackGroups = wrapFormats(noLanguageAudio, forcedEnglish, forcedGerman);
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections.get(1)); assertNoSelection(result.selections[1]);
// The audio declares german. The german forced track should be selected. // The audio declares german. The german forced track should be selected.
trackGroups = wrapFormats(germanAudio, forcedGerman, forcedEnglish); trackGroups = wrapFormats(germanAudio, forcedGerman, forcedEnglish);
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(1), trackGroups, forcedGerman); assertFixedSelection(result.selections[1], trackGroups, forcedGerman);
// Ditto // Ditto
trackGroups = wrapFormats(germanAudio, forcedEnglish, forcedGerman); trackGroups = wrapFormats(germanAudio, forcedEnglish, forcedGerman);
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(1), trackGroups, forcedGerman); assertFixedSelection(result.selections[1], trackGroups, forcedGerman);
} }
/** /**
@ -995,34 +995,34 @@ public final class DefaultTrackSelectorTest {
TrackGroupArray trackGroups = wrapFormats(spanish, german, undeterminedUnd, undeterminedNull); TrackGroupArray trackGroups = wrapFormats(spanish, german, undeterminedUnd, undeterminedNull);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE); trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections.get(0)); assertNoSelection(result.selections[0]);
trackSelector.setParameters( trackSelector.setParameters(
defaultParameters.buildUpon().setSelectUndeterminedTextLanguage(true)); defaultParameters.buildUpon().setSelectUndeterminedTextLanguage(true));
result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, undeterminedUnd); assertFixedSelection(result.selections[0], trackGroups, undeterminedUnd);
ParametersBuilder builder = defaultParameters.buildUpon().setPreferredTextLanguage("spa"); ParametersBuilder builder = defaultParameters.buildUpon().setPreferredTextLanguage("spa");
trackSelector.setParameters(builder); trackSelector.setParameters(builder);
result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, spanish); assertFixedSelection(result.selections[0], trackGroups, spanish);
trackGroups = wrapFormats(german, undeterminedUnd, undeterminedNull); trackGroups = wrapFormats(german, undeterminedUnd, undeterminedNull);
result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections.get(0)); assertNoSelection(result.selections[0]);
trackSelector.setParameters(builder.setSelectUndeterminedTextLanguage(true)); trackSelector.setParameters(builder.setSelectUndeterminedTextLanguage(true));
result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, undeterminedUnd); assertFixedSelection(result.selections[0], trackGroups, undeterminedUnd);
trackGroups = wrapFormats(german, undeterminedNull); trackGroups = wrapFormats(german, undeterminedNull);
result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, undeterminedNull); assertFixedSelection(result.selections[0], trackGroups, undeterminedNull);
trackGroups = wrapFormats(german); trackGroups = wrapFormats(german);
result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections.get(0)); assertNoSelection(result.selections[0]);
} }
/** Tests audio track selection when there are multiple audio renderers. */ /** Tests audio track selection when there are multiple audio renderers. */
@ -1053,20 +1053,20 @@ public final class DefaultTrackSelectorTest {
// Without an explicit language preference, nothing should be selected. // Without an explicit language preference, nothing should be selected.
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections.get(0)); assertNoSelection(result.selections[0]);
assertNoSelection(result.selections.get(1)); assertNoSelection(result.selections[1]);
// Explicit language preference for english. First renderer should be used. // Explicit language preference for english. First renderer should be used.
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextLanguage("en")); trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextLanguage("en"));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, english); assertFixedSelection(result.selections[0], trackGroups, english);
assertNoSelection(result.selections.get(1)); assertNoSelection(result.selections[1]);
// Explicit language preference for German. Second renderer should be used. // Explicit language preference for German. Second renderer should be used.
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextLanguage("de")); trackSelector.setParameters(defaultParameters.buildUpon().setPreferredTextLanguage("de"));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections.get(0)); assertNoSelection(result.selections[0]);
assertFixedSelection(result.selections.get(1), trackGroups, german); assertFixedSelection(result.selections[1], trackGroups, german);
} }
/** /**
@ -1098,7 +1098,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, lowerBitrateFormat); assertFixedSelection(result.selections[0], trackGroups, lowerBitrateFormat);
} }
/** /**
@ -1130,7 +1130,7 @@ public final class DefaultTrackSelectorTest {
trackGroups, trackGroups,
periodId, periodId,
TIMELINE); TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, higherBitrateFormat); assertFixedSelection(result.selections[0], trackGroups, higherBitrateFormat);
} }
@Test @Test
@ -1143,7 +1143,7 @@ public final class DefaultTrackSelectorTest {
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1); assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 0, 1);
} }
@Test @Test
@ -1174,7 +1174,7 @@ public final class DefaultTrackSelectorTest {
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 6); assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 0, 6);
} }
@Test @Test
@ -1189,7 +1189,7 @@ public final class DefaultTrackSelectorTest {
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups.get(0), /* expectedTrack= */ 0); assertFixedSelection(result.selections[0], trackGroups.get(0), /* expectedTrack= */ 0);
} }
@Test @Test
@ -1206,7 +1206,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, highSampleRateAudioFormat); assertFixedSelection(result.selections[0], trackGroups, highSampleRateAudioFormat);
// The same applies if the tracks are provided in the opposite order. // The same applies if the tracks are provided in the opposite order.
trackGroups = singleTrackGroup(lowSampleRateAudioFormat, highSampleRateAudioFormat); trackGroups = singleTrackGroup(lowSampleRateAudioFormat, highSampleRateAudioFormat);
@ -1214,7 +1214,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, highSampleRateAudioFormat); assertFixedSelection(result.selections[0], trackGroups, highSampleRateAudioFormat);
// If we explicitly enable mixed sample rate adaptiveness, expect an adaptive selection. // If we explicitly enable mixed sample rate adaptiveness, expect an adaptive selection.
trackSelector.setParameters( trackSelector.setParameters(
@ -1223,7 +1223,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1); assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 0, 1);
} }
@Test @Test
@ -1239,7 +1239,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, aacAudioFormat); assertFixedSelection(result.selections[0], trackGroups, aacAudioFormat);
// The same applies if the tracks are provided in the opposite order. // The same applies if the tracks are provided in the opposite order.
trackGroups = singleTrackGroup(opusAudioFormat, aacAudioFormat); trackGroups = singleTrackGroup(opusAudioFormat, aacAudioFormat);
@ -1247,7 +1247,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, opusAudioFormat); assertFixedSelection(result.selections[0], trackGroups, opusAudioFormat);
// If we explicitly enable mixed mime type adaptiveness, expect an adaptive selection. // If we explicitly enable mixed mime type adaptiveness, expect an adaptive selection.
trackSelector.setParameters( trackSelector.setParameters(
@ -1256,7 +1256,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1); assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 0, 1);
} }
@Test @Test
@ -1272,7 +1272,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, surroundAudioFormat); assertFixedSelection(result.selections[0], trackGroups, surroundAudioFormat);
// The same applies if the tracks are provided in the opposite order. // The same applies if the tracks are provided in the opposite order.
trackGroups = singleTrackGroup(surroundAudioFormat, stereoAudioFormat); trackGroups = singleTrackGroup(surroundAudioFormat, stereoAudioFormat);
@ -1280,7 +1280,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, surroundAudioFormat); assertFixedSelection(result.selections[0], trackGroups, surroundAudioFormat);
// If we constrain the channel count to 4 we expect a fixed selection containing the track with // If we constrain the channel count to 4 we expect a fixed selection containing the track with
// fewer channels. // fewer channels.
@ -1289,7 +1289,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, stereoAudioFormat); assertFixedSelection(result.selections[0], trackGroups, stereoAudioFormat);
// If we constrain the channel count to 2 we expect a fixed selection containing the track with // If we constrain the channel count to 2 we expect a fixed selection containing the track with
// fewer channels. // fewer channels.
@ -1298,7 +1298,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, stereoAudioFormat); assertFixedSelection(result.selections[0], trackGroups, stereoAudioFormat);
// If we constrain the channel count to 1 we expect a fixed selection containing the track with // If we constrain the channel count to 1 we expect a fixed selection containing the track with
// fewer channels. // fewer channels.
@ -1307,7 +1307,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, stereoAudioFormat); assertFixedSelection(result.selections[0], trackGroups, stereoAudioFormat);
// If we disable exceeding of constraints we expect no selection. // If we disable exceeding of constraints we expect no selection.
trackSelector.setParameters( trackSelector.setParameters(
@ -1319,7 +1319,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertNoSelection(result.selections.get(0)); assertNoSelection(result.selections[0]);
} }
@Test @Test
@ -1343,7 +1343,7 @@ public final class DefaultTrackSelectorTest {
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 1, 2); assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 1, 2);
} }
/** Tests audio track selection when there are multiple audio renderers. */ /** Tests audio track selection when there are multiple audio renderers. */
@ -1374,20 +1374,20 @@ public final class DefaultTrackSelectorTest {
TrackGroupArray trackGroups = wrapFormats(english, german); TrackGroupArray trackGroups = wrapFormats(english, german);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, english); assertFixedSelection(result.selections[0], trackGroups, english);
assertNoSelection(result.selections.get(1)); assertNoSelection(result.selections[1]);
// Explicit language preference for english. First renderer should be used. // Explicit language preference for english. First renderer should be used.
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioLanguage("en")); trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioLanguage("en"));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections.get(0), trackGroups, english); assertFixedSelection(result.selections[0], trackGroups, english);
assertNoSelection(result.selections.get(1)); assertNoSelection(result.selections[1]);
// Explicit language preference for German. Second renderer should be used. // Explicit language preference for German. Second renderer should be used.
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioLanguage("de")); trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioLanguage("de"));
result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE); result = trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
assertNoSelection(result.selections.get(0)); assertNoSelection(result.selections[0]);
assertFixedSelection(result.selections.get(1), trackGroups, german); assertFixedSelection(result.selections[1], trackGroups, german);
} }
@Test @Test
@ -1400,7 +1400,7 @@ public final class DefaultTrackSelectorTest {
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1); assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 0, 1);
} }
@Test @Test
@ -1424,7 +1424,7 @@ public final class DefaultTrackSelectorTest {
periodId, periodId,
TIMELINE); TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1); assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 0, 1);
// If we explicitly disable non-seamless adaptiveness, expect a fixed selection. // If we explicitly disable non-seamless adaptiveness, expect a fixed selection.
trackSelector.setParameters( trackSelector.setParameters(
@ -1436,7 +1436,7 @@ public final class DefaultTrackSelectorTest {
periodId, periodId,
TIMELINE); TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups.get(0), 0); assertFixedSelection(result.selections[0], trackGroups.get(0), 0);
} }
@Test @Test
@ -1452,7 +1452,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, h264VideoFormat); assertFixedSelection(result.selections[0], trackGroups, h264VideoFormat);
// The same applies if the tracks are provided in the opposite order. // The same applies if the tracks are provided in the opposite order.
trackGroups = singleTrackGroup(h265VideoFormat, h264VideoFormat); trackGroups = singleTrackGroup(h265VideoFormat, h264VideoFormat);
@ -1460,7 +1460,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, h265VideoFormat); assertFixedSelection(result.selections[0], trackGroups, h265VideoFormat);
// If we explicitly enable mixed mime type adaptiveness, expect an adaptive selection. // If we explicitly enable mixed mime type adaptiveness, expect an adaptive selection.
trackSelector.setParameters( trackSelector.setParameters(
@ -1469,7 +1469,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 0, 1); assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 0, 1);
} }
@Test @Test
@ -1493,7 +1493,7 @@ public final class DefaultTrackSelectorTest {
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections.get(0), trackGroups.get(0), 1, 2); assertAdaptiveSelection(result.selections[0], trackGroups.get(0), 1, 2);
} }
@Test @Test
@ -1518,9 +1518,9 @@ public final class DefaultTrackSelectorTest {
assertThat(result.length).isEqualTo(2); assertThat(result.length).isEqualTo(2);
assertAdaptiveSelection( assertAdaptiveSelection(
result.selections.get(0), trackGroups.get(0), /* expectedTracks...= */ 1, 0); result.selections[0], trackGroups.get(0), /* expectedTracks...= */ 1, 0);
assertAdaptiveSelection( assertAdaptiveSelection(
result.selections.get(1), trackGroups.get(1), /* expectedTracks...= */ 1, 0); result.selections[1], trackGroups.get(1), /* expectedTracks...= */ 1, 0);
// Multiple adaptive selection disallowed. // Multiple adaptive selection disallowed.
trackSelector.setParameters( trackSelector.setParameters(
@ -1534,8 +1534,8 @@ public final class DefaultTrackSelectorTest {
assertThat(result.length).isEqualTo(2); assertThat(result.length).isEqualTo(2);
assertAdaptiveSelection( assertAdaptiveSelection(
result.selections.get(0), trackGroups.get(0), /* expectedTracks...= */ 1, 0); result.selections[0], trackGroups.get(0), /* expectedTracks...= */ 1, 0);
assertFixedSelection(result.selections.get(1), trackGroups.get(1), /* expectedTrack= */ 1); assertFixedSelection(result.selections[1], trackGroups.get(1), /* expectedTrack= */ 1);
} }
@Test @Test
@ -1552,7 +1552,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, formatVp9); assertFixedSelection(result.selections[0], trackGroups, formatVp9);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
@ -1562,7 +1562,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, formatVp9); assertFixedSelection(result.selections[0], trackGroups, formatVp9);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
@ -1572,7 +1572,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, formatH264); assertFixedSelection(result.selections[0], trackGroups, formatH264);
// Select first in the list if no preference is specified. // Select first in the list if no preference is specified.
trackSelector.setParameters( trackSelector.setParameters(
@ -1581,7 +1581,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, formatAv1); assertFixedSelection(result.selections[0], trackGroups, formatAv1);
} }
@Test @Test
@ -1598,7 +1598,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, formatAc4); assertFixedSelection(result.selections[0], trackGroups, formatAc4);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
@ -1608,7 +1608,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, formatAc4); assertFixedSelection(result.selections[0], trackGroups, formatAc4);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
@ -1618,7 +1618,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, formatEAc3); assertFixedSelection(result.selections[0], trackGroups, formatEAc3);
// Select first in the list if no preference is specified. // Select first in the list if no preference is specified.
trackSelector.setParameters( trackSelector.setParameters(
@ -1627,13 +1627,13 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {AUDIO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertFixedSelection(result.selections.get(0), trackGroups, formatAac); assertFixedSelection(result.selections[0], trackGroups, formatAac);
} }
private static void assertSelections(TrackSelectorResult result, TrackSelection[] expected) { private static void assertSelections(TrackSelectorResult result, TrackSelection[] expected) {
assertThat(result.length).isEqualTo(expected.length); assertThat(result.length).isEqualTo(expected.length);
for (int i = 0; i < expected.length; i++) { for (int i = 0; i < expected.length; i++) {
assertThat(result.selections.get(i)).isEqualTo(expected[i]); assertThat(result.selections[i]).isEqualTo(expected[i]);
} }
} }
@ -1771,11 +1771,11 @@ public final class DefaultTrackSelectorTest {
@Capabilities private final int supportValue; @Capabilities private final int supportValue;
/** /**
* Returns {@link FakeRendererCapabilities} that advertises adaptive support for all * Returns {@link FakeRendererCapabilities} that advertises adaptive support for all tracks of
* tracks of the given type. * the given type.
* *
* @param trackType the track type of all formats that this renderer capabilities advertises * @param trackType the track type of all formats that this renderer capabilities advertises
* support for. * support for.
*/ */
FakeRendererCapabilities(int trackType) { FakeRendererCapabilities(int trackType) {
this( this(
@ -1820,7 +1820,6 @@ public final class DefaultTrackSelectorTest {
public int supportsMixedMimeTypeAdaptation() { public int supportsMixedMimeTypeAdaptation() {
return ADAPTIVE_SEAMLESS; return ADAPTIVE_SEAMLESS;
} }
} }
/** /**
@ -1869,7 +1868,5 @@ public final class DefaultTrackSelectorTest {
public int supportsMixedMimeTypeAdaptation() { public int supportsMixedMimeTypeAdaptation() {
return ADAPTIVE_SEAMLESS; return ADAPTIVE_SEAMLESS;
} }
} }
} }