Rename indexes to indices in TrackSelectionOverrides

And in a couple of related places.

This is for consistency with the rest of the codebase where
we exclusively use indices.

#minor-release

PiperOrigin-RevId: 408273372
This commit is contained in:
tonihei 2021-11-08 09:12:03 +00:00 committed by Ian Baker
parent 39d6ad855f
commit 8900d655d9
6 changed files with 41 additions and 41 deletions

View File

@ -111,7 +111,7 @@ public final class TrackSelectionOverrides implements Bundleable {
} }
/** /**
* Forces the selection of {@link #trackIndexes} for a {@link TrackGroup}. * Forces the selection of {@link #trackIndices} for a {@link TrackGroup}.
* *
* <p>If multiple {link #tracks} are overridden, as many as possible will be selected depending on * <p>If multiple {link #tracks} are overridden, as many as possible will be selected depending on
* the player capabilities. * the player capabilities.
@ -124,10 +124,10 @@ public final class TrackSelectionOverrides implements Bundleable {
*/ */
public static final class TrackSelectionOverride implements Bundleable { public static final class TrackSelectionOverride implements Bundleable {
/** The {@link TrackGroup} whose {@link #trackIndexes} are forced to be selected. */ /** The {@link TrackGroup} whose {@link #trackIndices} are forced to be selected. */
public final TrackGroup trackGroup; public final TrackGroup trackGroup;
/** The index of tracks in a {@link TrackGroup} to be selected. */ /** The indices of tracks in a {@link TrackGroup} to be selected. */
public final ImmutableList<Integer> trackIndexes; public final ImmutableList<Integer> trackIndices;
/** Constructs an instance to force all tracks in {@code trackGroup} to be selected. */ /** Constructs an instance to force all tracks in {@code trackGroup} to be selected. */
public TrackSelectionOverride(TrackGroup trackGroup) { public TrackSelectionOverride(TrackGroup trackGroup) {
@ -136,23 +136,23 @@ public final class TrackSelectionOverrides implements Bundleable {
for (int i = 0; i < trackGroup.length; i++) { for (int i = 0; i < trackGroup.length; i++) {
builder.add(i); builder.add(i);
} }
this.trackIndexes = builder.build(); this.trackIndices = builder.build();
} }
/** /**
* Constructs an instance to force {@code trackIndexes} in {@code trackGroup} to be selected. * Constructs an instance to force {@code trackIndices} in {@code trackGroup} to be selected.
* *
* @param trackGroup The {@link TrackGroup} for which to override the track selection. * @param trackGroup The {@link TrackGroup} for which to override the track selection.
* @param trackIndexes The indexes of the tracks in the {@link TrackGroup} to select. * @param trackIndices The indices of the tracks in the {@link TrackGroup} to select.
*/ */
public TrackSelectionOverride(TrackGroup trackGroup, List<Integer> trackIndexes) { public TrackSelectionOverride(TrackGroup trackGroup, List<Integer> trackIndices) {
if (!trackIndexes.isEmpty()) { if (!trackIndices.isEmpty()) {
if (min(trackIndexes) < 0 || max(trackIndexes) >= trackGroup.length) { if (min(trackIndices) < 0 || max(trackIndices) >= trackGroup.length) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
} }
this.trackGroup = trackGroup; this.trackGroup = trackGroup;
this.trackIndexes = ImmutableList.copyOf(trackIndexes); this.trackIndices = ImmutableList.copyOf(trackIndices);
} }
@Override @Override
@ -164,12 +164,12 @@ public final class TrackSelectionOverrides implements Bundleable {
return false; return false;
} }
TrackSelectionOverride that = (TrackSelectionOverride) obj; TrackSelectionOverride that = (TrackSelectionOverride) obj;
return trackGroup.equals(that.trackGroup) && trackIndexes.equals(that.trackIndexes); return trackGroup.equals(that.trackGroup) && trackIndices.equals(that.trackIndices);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return trackGroup.hashCode() + 31 * trackIndexes.hashCode(); return trackGroup.hashCode() + 31 * trackIndices.hashCode();
} }
private @C.TrackType int getTrackType() { private @C.TrackType int getTrackType() {
@ -194,7 +194,7 @@ public final class TrackSelectionOverrides implements Bundleable {
public Bundle toBundle() { public Bundle toBundle() {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putBundle(keyForField(FIELD_TRACK_GROUP), trackGroup.toBundle()); bundle.putBundle(keyForField(FIELD_TRACK_GROUP), trackGroup.toBundle());
bundle.putIntArray(keyForField(FIELD_TRACKS), Ints.toArray(trackIndexes)); bundle.putIntArray(keyForField(FIELD_TRACKS), Ints.toArray(trackIndices));
return bundle; return bundle;
} }

View File

@ -45,7 +45,7 @@ public final class TrackSelectionOverridesTest {
new TrackSelectionOverride(newTrackGroupWithIds(1, 2)); new TrackSelectionOverride(newTrackGroupWithIds(1, 2));
assertThat(trackSelectionOverride.trackGroup).isEqualTo(newTrackGroupWithIds(1, 2)); assertThat(trackSelectionOverride.trackGroup).isEqualTo(newTrackGroupWithIds(1, 2));
assertThat(trackSelectionOverride.trackIndexes).containsExactly(0, 1).inOrder(); assertThat(trackSelectionOverride.trackIndices).containsExactly(0, 1).inOrder();
} }
@Test @Test
@ -54,7 +54,7 @@ public final class TrackSelectionOverridesTest {
new TrackSelectionOverride(newTrackGroupWithIds(1, 2), ImmutableList.of(1)); new TrackSelectionOverride(newTrackGroupWithIds(1, 2), ImmutableList.of(1));
assertThat(trackSelectionOverride.trackGroup).isEqualTo(newTrackGroupWithIds(1, 2)); assertThat(trackSelectionOverride.trackGroup).isEqualTo(newTrackGroupWithIds(1, 2));
assertThat(trackSelectionOverride.trackIndexes).containsExactly(1); assertThat(trackSelectionOverride.trackIndices).containsExactly(1);
} }
@Test @Test
@ -63,7 +63,7 @@ public final class TrackSelectionOverridesTest {
new TrackSelectionOverride(newTrackGroupWithIds(1, 2), ImmutableList.of()); new TrackSelectionOverride(newTrackGroupWithIds(1, 2), ImmutableList.of());
assertThat(trackSelectionOverride.trackGroup).isEqualTo(newTrackGroupWithIds(1, 2)); assertThat(trackSelectionOverride.trackGroup).isEqualTo(newTrackGroupWithIds(1, 2));
assertThat(trackSelectionOverride.trackIndexes).isEmpty(); assertThat(trackSelectionOverride.trackIndices).isEmpty();
} }
@Test @Test
@ -114,9 +114,9 @@ public final class TrackSelectionOverridesTest {
public void addOverride_onSameGroup_replacesOverride() { public void addOverride_onSameGroup_replacesOverride() {
TrackGroup trackGroup = newTrackGroupWithIds(1, 2, 3); TrackGroup trackGroup = newTrackGroupWithIds(1, 2, 3);
TrackSelectionOverride override1 = TrackSelectionOverride override1 =
new TrackSelectionOverride(trackGroup, /* trackIndexes= */ ImmutableList.of(0)); new TrackSelectionOverride(trackGroup, /* trackIndices= */ ImmutableList.of(0));
TrackSelectionOverride override2 = TrackSelectionOverride override2 =
new TrackSelectionOverride(trackGroup, /* trackIndexes= */ ImmutableList.of(1)); new TrackSelectionOverride(trackGroup, /* trackIndices= */ ImmutableList.of(1));
TrackSelectionOverrides trackSelectionOverrides = TrackSelectionOverrides trackSelectionOverrides =
new TrackSelectionOverrides.Builder().addOverride(override1).addOverride(override2).build(); new TrackSelectionOverrides.Builder().addOverride(override1).addOverride(override2).build();

View File

@ -73,7 +73,7 @@ public final class TrackSelectionParametersTest {
new TrackGroup( new TrackGroup(
new Format.Builder().setId(4).build(), new Format.Builder().setId(4).build(),
new Format.Builder().setId(5).build()), new Format.Builder().setId(5).build()),
/* trackIndexes= */ ImmutableList.of(1))) /* trackIndices= */ ImmutableList.of(1)))
.build(); .build();
TrackSelectionParameters parameters = TrackSelectionParameters parameters =
TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT

View File

@ -312,7 +312,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
rendererDisabledFlags = rendererDisabledFlags =
makeSparseBooleanArrayFromTrueKeys( makeSparseBooleanArrayFromTrueKeys(
bundle.getIntArray( bundle.getIntArray(
Parameters.keyForField(Parameters.FIELD_RENDERER_DISABLED_INDEXES))); Parameters.keyForField(Parameters.FIELD_RENDERER_DISABLED_INDICES)));
} }
@Override @Override
@ -830,9 +830,9 @@ public class DefaultTrackSelector extends MappingTrackSelector {
private void setSelectionOverridesFromBundle(Bundle bundle) { private void setSelectionOverridesFromBundle(Bundle bundle) {
@Nullable @Nullable
int[] rendererIndexes = int[] rendererIndices =
bundle.getIntArray( bundle.getIntArray(
Parameters.keyForField(Parameters.FIELD_SELECTION_OVERRIDES_RENDERER_INDEXES)); Parameters.keyForField(Parameters.FIELD_SELECTION_OVERRIDES_RENDERER_INDICES));
List<TrackGroupArray> trackGroupArrays = List<TrackGroupArray> trackGroupArrays =
BundleableUtil.fromBundleNullableList( BundleableUtil.fromBundleNullableList(
TrackGroupArray.CREATOR, TrackGroupArray.CREATOR,
@ -846,11 +846,11 @@ public class DefaultTrackSelector extends MappingTrackSelector {
Parameters.keyForField(Parameters.FIELD_SELECTION_OVERRIDES)), Parameters.keyForField(Parameters.FIELD_SELECTION_OVERRIDES)),
/* defaultValue= */ new SparseArray<>()); /* defaultValue= */ new SparseArray<>());
if (rendererIndexes == null || rendererIndexes.length != trackGroupArrays.size()) { if (rendererIndices == null || rendererIndices.length != trackGroupArrays.size()) {
return; // Incorrect format, ignore all overrides. return; // Incorrect format, ignore all overrides.
} }
for (int i = 0; i < rendererIndexes.length; i++) { for (int i = 0; i < rendererIndices.length; i++) {
int rendererIndex = rendererIndexes[i]; int rendererIndex = rendererIndices[i];
TrackGroupArray groups = trackGroupArrays.get(i); TrackGroupArray groups = trackGroupArrays.get(i);
@Nullable SelectionOverride selectionOverride = selectionOverrides.get(i); @Nullable SelectionOverride selectionOverride = selectionOverrides.get(i);
setSelectionOverride(rendererIndex, groups, selectionOverride); setSelectionOverride(rendererIndex, groups, selectionOverride);
@ -1112,10 +1112,10 @@ public class DefaultTrackSelector extends MappingTrackSelector {
FIELD_EXCEED_RENDERER_CAPABILITIES_IF_NECESSARY, FIELD_EXCEED_RENDERER_CAPABILITIES_IF_NECESSARY,
FIELD_TUNNELING_ENABLED, FIELD_TUNNELING_ENABLED,
FIELD_ALLOW_MULTIPLE_ADAPTIVE_SELECTIONS, FIELD_ALLOW_MULTIPLE_ADAPTIVE_SELECTIONS,
FIELD_SELECTION_OVERRIDES_RENDERER_INDEXES, FIELD_SELECTION_OVERRIDES_RENDERER_INDICES,
FIELD_SELECTION_OVERRIDES_TRACK_GROUP_ARRAYS, FIELD_SELECTION_OVERRIDES_TRACK_GROUP_ARRAYS,
FIELD_SELECTION_OVERRIDES, FIELD_SELECTION_OVERRIDES,
FIELD_RENDERER_DISABLED_INDEXES, FIELD_RENDERER_DISABLED_INDICES,
}) })
private @interface FieldNumber {} private @interface FieldNumber {}
@ -1131,10 +1131,10 @@ public class DefaultTrackSelector extends MappingTrackSelector {
private static final int FIELD_EXCEED_RENDERER_CAPABILITIES_IF_NECESSARY = 1008; private static final int FIELD_EXCEED_RENDERER_CAPABILITIES_IF_NECESSARY = 1008;
private static final int FIELD_TUNNELING_ENABLED = 1009; private static final int FIELD_TUNNELING_ENABLED = 1009;
private static final int FIELD_ALLOW_MULTIPLE_ADAPTIVE_SELECTIONS = 1010; private static final int FIELD_ALLOW_MULTIPLE_ADAPTIVE_SELECTIONS = 1010;
private static final int FIELD_SELECTION_OVERRIDES_RENDERER_INDEXES = 1011; private static final int FIELD_SELECTION_OVERRIDES_RENDERER_INDICES = 1011;
private static final int FIELD_SELECTION_OVERRIDES_TRACK_GROUP_ARRAYS = 1012; private static final int FIELD_SELECTION_OVERRIDES_TRACK_GROUP_ARRAYS = 1012;
private static final int FIELD_SELECTION_OVERRIDES = 1013; private static final int FIELD_SELECTION_OVERRIDES = 1013;
private static final int FIELD_RENDERER_DISABLED_INDEXES = 1014; private static final int FIELD_RENDERER_DISABLED_INDICES = 1014;
@Override @Override
public Bundle toBundle() { public Bundle toBundle() {
@ -1177,7 +1177,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
putSelectionOverridesToBundle(bundle, selectionOverrides); putSelectionOverridesToBundle(bundle, selectionOverrides);
// Only true values are put into rendererDisabledFlags. // Only true values are put into rendererDisabledFlags.
bundle.putIntArray( bundle.putIntArray(
keyForField(FIELD_RENDERER_DISABLED_INDEXES), keyForField(FIELD_RENDERER_DISABLED_INDICES),
getKeysFromSparseBooleanArray(rendererDisabledFlags)); getKeysFromSparseBooleanArray(rendererDisabledFlags));
return bundle; return bundle;
@ -1199,7 +1199,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
private static void putSelectionOverridesToBundle( private static void putSelectionOverridesToBundle(
Bundle bundle, Bundle bundle,
SparseArray<Map<TrackGroupArray, @NullableType SelectionOverride>> selectionOverrides) { SparseArray<Map<TrackGroupArray, @NullableType SelectionOverride>> selectionOverrides) {
ArrayList<Integer> rendererIndexes = new ArrayList<>(); ArrayList<Integer> rendererIndices = new ArrayList<>();
ArrayList<TrackGroupArray> trackGroupArrays = new ArrayList<>(); ArrayList<TrackGroupArray> trackGroupArrays = new ArrayList<>();
SparseArray<SelectionOverride> selections = new SparseArray<>(); SparseArray<SelectionOverride> selections = new SparseArray<>();
@ -1212,10 +1212,10 @@ public class DefaultTrackSelector extends MappingTrackSelector {
selections.put(trackGroupArrays.size(), selection); selections.put(trackGroupArrays.size(), selection);
} }
trackGroupArrays.add(override.getKey()); trackGroupArrays.add(override.getKey());
rendererIndexes.add(rendererIndex); rendererIndices.add(rendererIndex);
} }
bundle.putIntArray( bundle.putIntArray(
keyForField(FIELD_SELECTION_OVERRIDES_RENDERER_INDEXES), Ints.toArray(rendererIndexes)); keyForField(FIELD_SELECTION_OVERRIDES_RENDERER_INDICES), Ints.toArray(rendererIndices));
bundle.putParcelableArrayList( bundle.putParcelableArrayList(
keyForField(FIELD_SELECTION_OVERRIDES_TRACK_GROUP_ARRAYS), keyForField(FIELD_SELECTION_OVERRIDES_TRACK_GROUP_ARRAYS),
BundleableUtil.toBundleArrayList(trackGroupArrays)); BundleableUtil.toBundleArrayList(trackGroupArrays));
@ -1579,7 +1579,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
TrackSelectionOverride overrideTracks = TrackSelectionOverride overrideTracks =
params.trackSelectionOverrides.getOverride(trackGroup); params.trackSelectionOverrides.getOverride(trackGroup);
if (overrideTracks != null) { if (overrideTracks != null) {
if (overrideTracks.trackIndexes.isEmpty()) { if (overrideTracks.trackIndices.isEmpty()) {
// TrackGroup is disabled. Deselect the currentDefinition if applicable. Otherwise ignore. // TrackGroup is disabled. Deselect the currentDefinition if applicable. Otherwise ignore.
if (currentDefinition != null && currentDefinition.group.equals(trackGroup)) { if (currentDefinition != null && currentDefinition.group.equals(trackGroup)) {
currentDefinition = null; currentDefinition = null;
@ -1588,7 +1588,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
// Override current definition with new selection. // Override current definition with new selection.
currentDefinition = currentDefinition =
new ExoTrackSelection.Definition( new ExoTrackSelection.Definition(
trackGroup, Ints.toArray(overrideTracks.trackIndexes)); trackGroup, Ints.toArray(overrideTracks.trackIndices));
} }
} }
} }

View File

@ -470,7 +470,7 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
/** /**
* Returns initial bitrate group assignments for a {@code country}. The initial bitrate is a list * Returns initial bitrate group assignments for a {@code country}. The initial bitrate is a list
* of indexes for [Wifi, 2G, 3G, 4G, 5G_NSA, 5G_SA]. * of indices for [Wifi, 2G, 3G, 4G, 5G_NSA, 5G_SA].
*/ */
private static int[] getInitialBitrateCountryGroupAssignment(String country) { private static int[] getInitialBitrateCountryGroupAssignment(String country) {
switch (country) { switch (country) {

View File

@ -222,13 +222,13 @@ public final class DefaultTrackSelectorTest {
new TrackSelectionOverrides.Builder() new TrackSelectionOverrides.Builder()
.addOverride( .addOverride(
new TrackSelectionOverride( new TrackSelectionOverride(
videoGroupHighBitrate, /* trackIndexes= */ ImmutableList.of())) videoGroupHighBitrate, /* trackIndices= */ ImmutableList.of()))
.addOverride( .addOverride(
new TrackSelectionOverride( new TrackSelectionOverride(
videoGroupMidBitrate, /* trackIndexes= */ ImmutableList.of(0))) videoGroupMidBitrate, /* trackIndices= */ ImmutableList.of(0)))
.addOverride( .addOverride(
new TrackSelectionOverride( new TrackSelectionOverride(
videoGroupLowBitrate, /* trackIndexes= */ ImmutableList.of())) videoGroupLowBitrate, /* trackIndices= */ ImmutableList.of()))
.build())); .build()));
TrackSelectorResult result = TrackSelectorResult result =
@ -1935,7 +1935,7 @@ public final class DefaultTrackSelectorTest {
.setOverrideForType( .setOverrideForType(
new TrackSelectionOverride( new TrackSelectionOverride(
new TrackGroup(AUDIO_FORMAT, AUDIO_FORMAT, AUDIO_FORMAT, AUDIO_FORMAT), new TrackGroup(AUDIO_FORMAT, AUDIO_FORMAT, AUDIO_FORMAT, AUDIO_FORMAT),
/* trackIndexes= */ ImmutableList.of(0, 2, 3))) /* trackIndices= */ ImmutableList.of(0, 2, 3)))
.build()) .build())
.setDisabledTrackTypes(ImmutableSet.of(C.TRACK_TYPE_AUDIO)) .setDisabledTrackTypes(ImmutableSet.of(C.TRACK_TYPE_AUDIO))
.build(); .build();