Commit 00191848 by olly Committed by Oliver Woodman

Make TrackSelection implement equals/hashCode.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=116638211
parent 73400907
...@@ -169,8 +169,8 @@ public final class FrameworkSampleSource implements SampleSource { ...@@ -169,8 +169,8 @@ public final class FrameworkSampleSource implements SampleSource {
@Override @Override
public TrackStream enable(TrackSelection selection, long positionUs) { public TrackStream enable(TrackSelection selection, long positionUs) {
Assertions.checkState(prepared); Assertions.checkState(prepared);
Assertions.checkState(selection.tracks.length == 1); Assertions.checkState(selection.length == 1);
Assertions.checkState(selection.tracks[0] == 0); Assertions.checkState(selection.getTrack(0) == 0);
int track = selection.group; int track = selection.group;
Assertions.checkState(trackStates[track] == TRACK_STATE_DISABLED); Assertions.checkState(trackStates[track] == TRACK_STATE_DISABLED);
enabledTrackCount++; enabledTrackCount++;
......
...@@ -80,7 +80,7 @@ public class MultiSampleSource implements SampleSource { ...@@ -80,7 +80,7 @@ public class MultiSampleSource implements SampleSource {
public TrackStream enable(TrackSelection selection, long positionUs) { public TrackStream enable(TrackSelection selection, long positionUs) {
Pair<Integer, Integer> sourceAndGroup = getSourceAndTrackGroupIndices(selection.group); Pair<Integer, Integer> sourceAndGroup = getSourceAndTrackGroupIndices(selection.group);
return sources[sourceAndGroup.first].enable( return sources[sourceAndGroup.first].enable(
new TrackSelection(sourceAndGroup.second, selection.tracks), positionUs); new TrackSelection(sourceAndGroup.second, selection.getTracks()), positionUs);
} }
@Override @Override
......
...@@ -15,27 +15,80 @@ ...@@ -15,27 +15,80 @@
*/ */
package com.google.android.exoplayer; package com.google.android.exoplayer;
import com.google.android.exoplayer.util.Assertions;
import java.util.Arrays;
/** /**
* Defines a track selection. * Defines a track selection.
*/ */
public final class TrackSelection { public final class TrackSelection {
/** /**
* The index of the {@link TrackGroup}. * The index of the selected {@link TrackGroup}.
*/ */
public final int group; public final int group;
/** /**
* The indices of the individual tracks within the {@link TrackGroup}. * The number of selected tracks within the {@link TrackGroup}. Always greater than zero.
*/ */
public final int[] tracks; public final int length;
private final int[] tracks;
// Lazily initialized hashcode.
private int hashCode;
/** /**
* @param group The index of the {@link TrackGroup}. * @param group The index of the {@link TrackGroup}.
* @param tracks The indices of the individual tracks within the {@link TrackGroup}. * @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
* null or empty.
*/ */
public TrackSelection(int group, int... tracks) { public TrackSelection(int group, int... tracks) {
Assertions.checkState(tracks.length > 0);
this.group = group; this.group = group;
this.tracks = tracks; this.tracks = tracks;
this.length = tracks.length;
}
/**
* Gets the index of the selected track at a given index in the selection.
*
* @param index The index in the selection.
* @return The index of the selected track.
*/
public int getTrack(int index) {
return getTracks()[index];
}
/**
* Gets a copy of the individual track indices.
*
* @return The track indices.
*/
public int[] getTracks() {
return tracks.clone();
}
@Override
public int hashCode() {
if (hashCode == 0) {
int result = 17;
result = 31 * result + group;
result = 31 * result + Arrays.hashCode(tracks);
}
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
TrackSelection other = (TrackSelection) obj;
return group == other.group && Arrays.equals(tracks, other.tracks);
} }
} }
...@@ -188,7 +188,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call ...@@ -188,7 +188,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
Assertions.checkState(state == STATE_PREPARED); Assertions.checkState(state == STATE_PREPARED);
Assertions.checkState(enabledTrackCount++ == 0); Assertions.checkState(enabledTrackCount++ == 0);
state = STATE_ENABLED; state = STATE_ENABLED;
chunkSource.enable(selection.tracks); chunkSource.enable(selection.getTracks());
loadControl.register(this, bufferSizeContribution); loadControl.register(this, bufferSizeContribution);
downstreamFormat = null; downstreamFormat = null;
downstreamSampleFormat = null; downstreamSampleFormat = null;
......
...@@ -299,8 +299,8 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu ...@@ -299,8 +299,8 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
@Override @Override
public TrackStream enable(TrackSelection selection, long positionUs) { public TrackStream enable(TrackSelection selection, long positionUs) {
Assertions.checkState(prepared); Assertions.checkState(prepared);
Assertions.checkState(selection.tracks.length == 1); Assertions.checkState(selection.length == 1);
Assertions.checkState(selection.tracks[0] == 0); Assertions.checkState(selection.getTrack(0) == 0);
int track = selection.group; int track = selection.group;
Assertions.checkState(!trackEnabledStates[track]); Assertions.checkState(!trackEnabledStates[track]);
enabledTrackCount++; enabledTrackCount++;
......
...@@ -191,7 +191,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback { ...@@ -191,7 +191,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
public TrackStream enable(TrackSelection selection, long positionUs) { public TrackStream enable(TrackSelection selection, long positionUs) {
Assertions.checkState(prepared); Assertions.checkState(prepared);
int group = selection.group; int group = selection.group;
int[] tracks = selection.tracks; int[] tracks = selection.getTracks();
setTrackGroupEnabledState(group, true); setTrackGroupEnabledState(group, true);
downstreamSampleFormats[group] = null; downstreamSampleFormats[group] = null;
pendingResets[group] = false; pendingResets[group] = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment