mirror of
https://github.com/samsonjs/media.git
synced 2026-04-26 14:57:47 +00:00
Make TrackSelection implement equals/hashCode.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=116638211
This commit is contained in:
parent
73400907fc
commit
00191848f7
6 changed files with 64 additions and 11 deletions
|
|
@ -169,8 +169,8 @@ public final class FrameworkSampleSource implements SampleSource {
|
|||
@Override
|
||||
public TrackStream enable(TrackSelection selection, long positionUs) {
|
||||
Assertions.checkState(prepared);
|
||||
Assertions.checkState(selection.tracks.length == 1);
|
||||
Assertions.checkState(selection.tracks[0] == 0);
|
||||
Assertions.checkState(selection.length == 1);
|
||||
Assertions.checkState(selection.getTrack(0) == 0);
|
||||
int track = selection.group;
|
||||
Assertions.checkState(trackStates[track] == TRACK_STATE_DISABLED);
|
||||
enabledTrackCount++;
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public class MultiSampleSource implements SampleSource {
|
|||
public TrackStream enable(TrackSelection selection, long positionUs) {
|
||||
Pair<Integer, Integer> sourceAndGroup = getSourceAndTrackGroupIndices(selection.group);
|
||||
return sources[sourceAndGroup.first].enable(
|
||||
new TrackSelection(sourceAndGroup.second, selection.tracks), positionUs);
|
||||
new TrackSelection(sourceAndGroup.second, selection.getTracks()), positionUs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -15,27 +15,80 @@
|
|||
*/
|
||||
package com.google.android.exoplayer;
|
||||
|
||||
import com.google.android.exoplayer.util.Assertions;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Defines a track selection.
|
||||
*/
|
||||
public final class TrackSelection {
|
||||
|
||||
/**
|
||||
* The index of the {@link TrackGroup}.
|
||||
* The index of the selected {@link TrackGroup}.
|
||||
*/
|
||||
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 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) {
|
||||
Assertions.checkState(tracks.length > 0);
|
||||
this.group = group;
|
||||
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
|
|||
Assertions.checkState(state == STATE_PREPARED);
|
||||
Assertions.checkState(enabledTrackCount++ == 0);
|
||||
state = STATE_ENABLED;
|
||||
chunkSource.enable(selection.tracks);
|
||||
chunkSource.enable(selection.getTracks());
|
||||
loadControl.register(this, bufferSizeContribution);
|
||||
downstreamFormat = null;
|
||||
downstreamSampleFormat = null;
|
||||
|
|
|
|||
|
|
@ -299,8 +299,8 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||
@Override
|
||||
public TrackStream enable(TrackSelection selection, long positionUs) {
|
||||
Assertions.checkState(prepared);
|
||||
Assertions.checkState(selection.tracks.length == 1);
|
||||
Assertions.checkState(selection.tracks[0] == 0);
|
||||
Assertions.checkState(selection.length == 1);
|
||||
Assertions.checkState(selection.getTrack(0) == 0);
|
||||
int track = selection.group;
|
||||
Assertions.checkState(!trackEnabledStates[track]);
|
||||
enabledTrackCount++;
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||
public TrackStream enable(TrackSelection selection, long positionUs) {
|
||||
Assertions.checkState(prepared);
|
||||
int group = selection.group;
|
||||
int[] tracks = selection.tracks;
|
||||
int[] tracks = selection.getTracks();
|
||||
setTrackGroupEnabledState(group, true);
|
||||
downstreamSampleFormats[group] = null;
|
||||
pendingResets[group] = false;
|
||||
|
|
|
|||
Loading…
Reference in a new issue