mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Make SelectionOverride parcelable
Issue: #3915 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=193494016
This commit is contained in:
parent
5fe0b0a13b
commit
cdb13dd548
2 changed files with 73 additions and 1 deletions
|
|
@ -37,6 +37,7 @@ import com.google.android.exoplayer2.upstream.BandwidthMeter;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -630,7 +631,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A track selection override. */
|
/** A track selection override. */
|
||||||
public static class SelectionOverride {
|
public static final class SelectionOverride implements Parcelable {
|
||||||
|
|
||||||
public final int groupIndex;
|
public final int groupIndex;
|
||||||
public final int[] tracks;
|
public final int[] tracks;
|
||||||
|
|
@ -646,6 +647,13 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
||||||
this.length = tracks.length;
|
this.length = tracks.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* package */ SelectionOverride(Parcel in) {
|
||||||
|
groupIndex = in.readInt();
|
||||||
|
length = in.readByte();
|
||||||
|
tracks = new int[length];
|
||||||
|
in.readIntArray(tracks);
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns whether this override contains the specified track index. */
|
/** Returns whether this override contains the specified track index. */
|
||||||
public boolean containsTrack(int track) {
|
public boolean containsTrack(int track) {
|
||||||
for (int overrideTrack : tracks) {
|
for (int overrideTrack : tracks) {
|
||||||
|
|
@ -655,6 +663,51 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return 31 * groupIndex + Arrays.hashCode(tracks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj == null || getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SelectionOverride other = (SelectionOverride) obj;
|
||||||
|
return groupIndex == other.groupIndex && Arrays.equals(tracks, other.tracks);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parcelable implementation.
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeInt(groupIndex);
|
||||||
|
dest.writeInt(tracks.length);
|
||||||
|
dest.writeIntArray(tracks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<SelectionOverride> CREATOR =
|
||||||
|
new Parcelable.Creator<SelectionOverride>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SelectionOverride createFromParcel(Parcel in) {
|
||||||
|
return new SelectionOverride(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SelectionOverride[] newArray(int size) {
|
||||||
|
return new SelectionOverride[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import com.google.android.exoplayer2.source.TrackGroup;
|
||||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Parameters;
|
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Parameters;
|
||||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder;
|
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder;
|
||||||
|
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride;
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelector.InvalidationListener;
|
import com.google.android.exoplayer2.trackselection.TrackSelector.InvalidationListener;
|
||||||
import com.google.android.exoplayer2.util.MimeTypes;
|
import com.google.android.exoplayer2.util.MimeTypes;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -147,6 +148,24 @@ public final class DefaultTrackSelectorTest {
|
||||||
parcel.recycle();
|
parcel.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Tests {@link SelectionOverride}'s {@link android.os.Parcelable} implementation. */
|
||||||
|
@Test
|
||||||
|
public void testSelectionOverrideParcelable() {
|
||||||
|
int[] tracks = new int[] {2, 3};
|
||||||
|
SelectionOverride selectionOverrideToParcel =
|
||||||
|
new SelectionOverride(/* groupIndex= */ 1, tracks);
|
||||||
|
|
||||||
|
Parcel parcel = Parcel.obtain();
|
||||||
|
selectionOverrideToParcel.writeToParcel(parcel, 0);
|
||||||
|
parcel.setDataPosition(0);
|
||||||
|
|
||||||
|
SelectionOverride selectionOverrideFromParcel =
|
||||||
|
SelectionOverride.CREATOR.createFromParcel(parcel);
|
||||||
|
assertThat(selectionOverrideFromParcel).isEqualTo(selectionOverrideToParcel);
|
||||||
|
|
||||||
|
parcel.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
/** Tests that a null override clears a track selection. */
|
/** Tests that a null override clears a track selection. */
|
||||||
@Test
|
@Test
|
||||||
public void testSelectTracksWithNullOverride() throws ExoPlaybackException {
|
public void testSelectTracksWithNullOverride() throws ExoPlaybackException {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue