Commit cd297b04 by krocard Committed by bachinger

Make Track selection objects Bundleable

Most of those objects needs to be sent to MediaControler.

`TrackSelectior.Parameters` could have stayed Parcelable,
but it needs to be `Bundleable` as it inherit from
`TrackSelectionParameters` that is and needs to be
serializable anyway for the demo app.
As a result it has also been migrated to bundleable.

PiperOrigin-RevId: 391353293
parent b689fbd4
......@@ -98,7 +98,7 @@ public class PlayerActivity extends AppCompatActivity
// Activity lifecycle.
@Override
public void onCreate(Bundle savedInstanceState) {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dataSourceFactory = DemoUtil.getDataSourceFactory(/* context= */ this);
......@@ -114,7 +114,9 @@ public class PlayerActivity extends AppCompatActivity
playerView.requestFocus();
if (savedInstanceState != null) {
trackSelectorParameters = savedInstanceState.getParcelable(KEY_TRACK_SELECTOR_PARAMETERS);
trackSelectorParameters =
DefaultTrackSelector.Parameters.CREATOR.fromBundle(
savedInstanceState.getBundle(KEY_TRACK_SELECTOR_PARAMETERS));
startAutoPlay = savedInstanceState.getBoolean(KEY_AUTO_PLAY);
startWindow = savedInstanceState.getInt(KEY_WINDOW);
startPosition = savedInstanceState.getLong(KEY_POSITION);
......@@ -207,7 +209,7 @@ public class PlayerActivity extends AppCompatActivity
super.onSaveInstanceState(outState);
updateTrackSelectorParameters();
updateStartPosition();
outState.putParcelable(KEY_TRACK_SELECTOR_PARAMETERS, trackSelectorParameters);
outState.putBundle(KEY_TRACK_SELECTOR_PARAMETERS, trackSelectorParameters.toBundle());
outState.putBoolean(KEY_AUTO_PLAY, startAutoPlay);
outState.putInt(KEY_WINDOW, startWindow);
outState.putLong(KEY_POSITION, startPosition);
......
......@@ -15,17 +15,26 @@
*/
package com.google.android.exoplayer2.source;
import android.os.Parcel;
import android.os.Parcelable;
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import android.os.Bundle;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Bundleable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.BundleableUtils;
import com.google.android.exoplayer2.util.Log;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.List;
/** Defines an immutable group of tracks identified by their format identity. */
public final class TrackGroup implements Parcelable {
public final class TrackGroup implements Bundleable {
private static final String TAG = "TrackGroup";
......@@ -37,22 +46,18 @@ public final class TrackGroup implements Parcelable {
// Lazily initialized hashcode.
private int hashCode;
/** @param formats The track formats. At least one {@link Format} must be provided. */
/**
* Constructs an instance {@code TrackGroup} containing the provided {@code formats}.
*
* @param formats Non empty array of format.
*/
public TrackGroup(Format... formats) {
Assertions.checkState(formats.length > 0);
checkArgument(formats.length > 0);
this.formats = formats;
this.length = formats.length;
verifyCorrectness();
}
/* package */ TrackGroup(Parcel in) {
length = in.readInt();
formats = new Format[length];
for (int i = 0; i < length; i++) {
formats[i] = in.readParcelable(Format.class.getClassLoader());
}
}
/**
* Returns the format of the track at a given index.
*
......@@ -103,35 +108,40 @@ public final class TrackGroup implements Parcelable {
return length == other.length && Arrays.equals(formats, other.formats);
}
// Parcelable implementation.
// Bundleable implementation.
@Override
public int describeContents() {
return 0;
}
@Documented
@Retention(RetentionPolicy.SOURCE)
@IntDef({
FIELD_FORMATS,
})
private @interface FieldNumber {}
private static final int FIELD_FORMATS = 0;
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(length);
for (int i = 0; i < length; i++) {
dest.writeParcelable(formats[i], 0);
}
public Bundle toBundle() {
Bundle bundle = new Bundle();
bundle.putParcelableArrayList(
keyForField(FIELD_FORMATS), BundleableUtils.toBundleArrayList(Lists.newArrayList(formats)));
return bundle;
}
public static final Parcelable.Creator<TrackGroup> CREATOR =
new Parcelable.Creator<TrackGroup>() {
@Override
public TrackGroup createFromParcel(Parcel in) {
return new TrackGroup(in);
}
@Override
public TrackGroup[] newArray(int size) {
return new TrackGroup[size];
}
/** Object that can restore {@code TrackGroup} from a {@link Bundle}. */
public static final Creator<TrackGroup> CREATOR =
bundle -> {
List<Format> formats =
BundleableUtils.fromBundleNullableList(
Format.CREATOR,
bundle.getParcelableArrayList(keyForField(FIELD_FORMATS)),
ImmutableList.of());
return new TrackGroup(formats.toArray(new Format[0]));
};
private static String keyForField(@FieldNumber int field) {
return Integer.toString(field, Character.MAX_RADIX);
}
private void verifyCorrectness() {
// TrackGroups should only contain tracks with exactly the same content (but in different
// qualities). We only log an error instead of throwing to not break backwards-compatibility for
......
......@@ -15,14 +15,22 @@
*/
package com.google.android.exoplayer2.source;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Bundle;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Bundleable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.BundleableUtils;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.List;
/** An immutable array of {@link TrackGroup}s. */
public final class TrackGroupArray implements Parcelable {
public final class TrackGroupArray implements Bundleable {
/** The empty array. */
public static final TrackGroupArray EMPTY = new TrackGroupArray();
......@@ -35,20 +43,12 @@ public final class TrackGroupArray implements Parcelable {
// Lazily initialized hashcode.
private int hashCode;
/** @param trackGroups The groups. May be empty. */
/** Construct a {@code TrackGroupArray} from an array of (possibly empty) trackGroups. */
public TrackGroupArray(TrackGroup... trackGroups) {
this.trackGroups = trackGroups;
this.length = trackGroups.length;
}
/* package */ TrackGroupArray(Parcel in) {
length = in.readInt();
trackGroups = new TrackGroup[length];
for (int i = 0; i < length; i++) {
trackGroups[i] = in.readParcelable(TrackGroup.class.getClassLoader());
}
}
/**
* Returns the group at a given index.
*
......@@ -102,32 +102,38 @@ public final class TrackGroupArray implements Parcelable {
return length == other.length && Arrays.equals(trackGroups, other.trackGroups);
}
// Parcelable implementation.
// Bundleable implementation.
@Override
public int describeContents() {
return 0;
}
@Documented
@Retention(RetentionPolicy.SOURCE)
@IntDef({
FIELD_TRACK_GROUPS,
})
private @interface FieldNumber {}
private static final int FIELD_TRACK_GROUPS = 0;
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(length);
for (int i = 0; i < length; i++) {
dest.writeParcelable(trackGroups[i], 0);
}
public Bundle toBundle() {
Bundle bundle = new Bundle();
bundle.putParcelableArrayList(
keyForField(FIELD_TRACK_GROUPS),
BundleableUtils.toBundleArrayList(Lists.newArrayList(trackGroups)));
return bundle;
}
public static final Parcelable.Creator<TrackGroupArray> CREATOR =
new Parcelable.Creator<TrackGroupArray>() {
@Override
public TrackGroupArray createFromParcel(Parcel in) {
return new TrackGroupArray(in);
}
@Override
public TrackGroupArray[] newArray(int size) {
return new TrackGroupArray[size];
}
/** Object that can restores a TrackGroupArray from a {@link Bundle}. */
public static final Creator<TrackGroupArray> CREATOR =
bundle -> {
List<TrackGroup> trackGroups =
BundleableUtils.fromBundleNullableList(
TrackGroup.CREATOR,
bundle.getParcelableArrayList(keyForField(FIELD_TRACK_GROUPS)),
/* defaultValue= */ ImmutableList.of());
return new TrackGroupArray(trackGroups.toArray(new TrackGroup[0]));
};
private static String keyForField(@FieldNumber int field) {
return Integer.toString(field, Character.MAX_RADIX);
}
}
......@@ -15,7 +15,11 @@
*/
package com.google.android.exoplayer2.util;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.Util.castNonNull;
import android.os.Bundle;
import android.util.SparseArray;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Bundleable;
import com.google.common.collect.ImmutableList;
......@@ -68,7 +72,7 @@ public final class BundleableUtils {
Bundleable.Creator<T> creator, List<Bundle> bundleList) {
ImmutableList.Builder<T> builder = ImmutableList.builder();
for (int i = 0; i < bundleList.size(); i++) {
Bundle bundle = bundleList.get(i);
Bundle bundle = checkNotNull(bundleList.get(i)); // Fail fast during parsing.
T bundleable = creator.fromBundle(bundle);
builder.add(bundleable);
}
......@@ -76,6 +80,34 @@ public final class BundleableUtils {
}
/**
* Converts a list of {@link Bundle} to a list of {@link Bundleable}. Returns {@code defaultValue}
* if {@code bundleList} is null.
*/
public static <T extends Bundleable> List<T> fromBundleNullableList(
Bundleable.Creator<T> creator, @Nullable List<Bundle> bundleList, List<T> defaultValue) {
return (bundleList == null) ? defaultValue : fromBundleList(creator, bundleList);
}
/**
* Converts a {@link SparseArray} of {@link Bundle} to a {@link SparseArray} of {@link
* Bundleable}. Returns {@code defaultValue} if {@code bundleSparseArray} is null.
*/
public static <T extends Bundleable> SparseArray<T> fromBundleNullableSparseArray(
Bundleable.Creator<T> creator,
@Nullable SparseArray<Bundle> bundleSparseArray,
SparseArray<T> defaultValue) {
if (bundleSparseArray == null) {
return defaultValue;
}
// Can't use ImmutableList as it doesn't support null elements.
SparseArray<T> result = new SparseArray<>(bundleSparseArray.size());
for (int i = 0; i < bundleSparseArray.size(); i++) {
result.put(bundleSparseArray.keyAt(i), creator.fromBundle(bundleSparseArray.valueAt(i)));
}
return result;
}
/**
* Converts a list of {@link Bundleable} to an {@link ArrayList} of {@link Bundle} so that the
* returned list can be put to {@link Bundle} using {@link Bundle#putParcelableArrayList}
* conveniently.
......@@ -88,5 +120,31 @@ public final class BundleableUtils {
return arrayList;
}
/**
* Converts a {@link SparseArray} of {@link Bundleable} to an {@link SparseArray} of {@link
* Bundle} so that the returned {@link SparseArray} can be put to {@link Bundle} using {@link
* Bundle#putSparseParcelableArray} conveniently.
*/
public static <T extends Bundleable> SparseArray<Bundle> toBundleSparseArray(
SparseArray<T> bundleableSparseArray) {
SparseArray<Bundle> sparseArray = new SparseArray<>(bundleableSparseArray.size());
for (int i = 0; i < bundleableSparseArray.size(); i++) {
sparseArray.put(bundleableSparseArray.keyAt(i), bundleableSparseArray.valueAt(i).toBundle());
}
return sparseArray;
}
/**
* Set the application class loader to the given {@link Bundle} if no class loader is present.
*
* <p>This assumes that all classes unparceled from {@code bundle} are sharing the class loader of
* {@code BundleableUtils}.
*/
public static void ensureClassLoader(@Nullable Bundle bundle) {
if (bundle != null) {
bundle.setClassLoader(castNonNull(BundleableUtils.class.getClassLoader()));
}
}
private BundleableUtils() {}
}
......@@ -15,17 +15,20 @@
*/
package com.google.android.exoplayer2.video;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Bundle;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Bundleable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.Util;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import org.checkerframework.dataflow.qual.Pure;
/** Stores color info. */
public final class ColorInfo implements Parcelable {
public final class ColorInfo implements Bundleable {
/**
* Returns the {@link C.ColorSpace} corresponding to the given ISO color primary code, as per
......@@ -116,16 +119,6 @@ public final class ColorInfo implements Parcelable {
this.hdrStaticInfo = hdrStaticInfo;
}
@SuppressWarnings("ResourceType")
/* package */ ColorInfo(Parcel in) {
colorSpace = in.readInt();
colorRange = in.readInt();
colorTransfer = in.readInt();
boolean hasHdrStaticInfo = Util.readBoolean(in);
hdrStaticInfo = hasHdrStaticInfo ? in.createByteArray() : null;
}
// Parcelable implementation.
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
......@@ -167,32 +160,42 @@ public final class ColorInfo implements Parcelable {
return hashCode;
}
@Override
public int describeContents() {
return 0;
}
// Bundleable implementation
@Documented
@Retention(RetentionPolicy.SOURCE)
@IntDef({
FIELD_COLOR_SPACE,
FIELD_COLOR_RANGE,
FIELD_COLOR_TRANSFER,
FIELD_HDR_STATIC_INFO,
})
private @interface FieldNumber {}
private static final int FIELD_COLOR_SPACE = 0;
private static final int FIELD_COLOR_RANGE = 1;
private static final int FIELD_COLOR_TRANSFER = 2;
private static final int FIELD_HDR_STATIC_INFO = 3;
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(colorSpace);
dest.writeInt(colorRange);
dest.writeInt(colorTransfer);
Util.writeBoolean(dest, hdrStaticInfo != null);
if (hdrStaticInfo != null) {
dest.writeByteArray(hdrStaticInfo);
}
public Bundle toBundle() {
Bundle bundle = new Bundle();
bundle.putInt(keyForField(FIELD_COLOR_SPACE), colorSpace);
bundle.putInt(keyForField(FIELD_COLOR_RANGE), colorRange);
bundle.putInt(keyForField(FIELD_COLOR_TRANSFER), colorTransfer);
bundle.putByteArray(keyForField(FIELD_HDR_STATIC_INFO), hdrStaticInfo);
return bundle;
}
public static final Parcelable.Creator<ColorInfo> CREATOR =
new Parcelable.Creator<ColorInfo>() {
@Override
public ColorInfo createFromParcel(Parcel in) {
return new ColorInfo(in);
}
@Override
public ColorInfo[] newArray(int size) {
return new ColorInfo[size];
}
};
public static final Creator<ColorInfo> CREATOR =
bundle ->
new ColorInfo(
bundle.getInt(keyForField(FIELD_COLOR_SPACE), Format.NO_VALUE),
bundle.getInt(keyForField(FIELD_COLOR_RANGE), Format.NO_VALUE),
bundle.getInt(keyForField(FIELD_COLOR_TRANSFER), Format.NO_VALUE),
bundle.getByteArray(keyForField(FIELD_HDR_STATIC_INFO)));
private static String keyForField(@FieldNumber int field) {
return Integer.toString(field, Character.MAX_RADIX);
}
}
......@@ -20,7 +20,6 @@ import static com.google.android.exoplayer2.util.MimeTypes.VIDEO_MP4;
import static com.google.android.exoplayer2.util.MimeTypes.VIDEO_WEBM;
import static com.google.common.truth.Truth.assertThat;
import android.os.Parcel;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.drm.DrmInitData;
import com.google.android.exoplayer2.drm.ExoMediaCrypto;
......@@ -46,21 +45,15 @@ public final class FormatTest {
}
@Test
public void parcelFormat_createsEqualFormat_exceptExoMediaCryptoType() {
Format formatToParcel = createTestFormat();
public void roundTripViaBundle_ofParameters_yieldsEqualInstanceExceptExoMediaCryptoType() {
Format formatToBundle = createTestFormat();
Parcel parcel = Parcel.obtain();
formatToParcel.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
Format formatFromBundle = Format.CREATOR.fromBundle(formatToBundle.toBundle());
Format formatFromParcel = Format.CREATOR.createFromParcel(parcel);
Format expectedFormat =
formatToParcel.buildUpon().setExoMediaCryptoType(UnsupportedMediaCrypto.class).build();
assertThat(formatFromParcel.exoMediaCryptoType).isEqualTo(UnsupportedMediaCrypto.class);
assertThat(formatFromParcel).isEqualTo(expectedFormat);
parcel.recycle();
assertThat(formatFromBundle.exoMediaCryptoType).isEqualTo(UnsupportedMediaCrypto.class);
assertThat(formatFromBundle)
.isEqualTo(
formatToBundle.buildUpon().setExoMediaCryptoType(UnsupportedMediaCrypto.class).build());
}
private static Format createTestFormat() {
......
......@@ -25,6 +25,7 @@ import com.google.android.exoplayer2.C.FormatSupport;
import com.google.android.exoplayer2.source.MediaPeriodId;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.BundleableUtils;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
import java.lang.annotation.Documented;
......@@ -234,7 +235,9 @@ public final class ExoPlaybackException extends PlaybackException {
rendererName = bundle.getString(keyForField(FIELD_RENDERER_NAME));
rendererIndex =
bundle.getInt(keyForField(FIELD_RENDERER_INDEX), /* defaultValue= */ C.INDEX_UNSET);
rendererFormat = bundle.getParcelable(keyForField(FIELD_RENDERER_FORMAT));
rendererFormat =
BundleableUtils.fromNullableBundle(
Format.CREATOR, bundle.getBundle(keyForField(FIELD_RENDERER_FORMAT)));
rendererFormatSupport =
bundle.getInt(
keyForField(FIELD_RENDERER_FORMAT_SUPPORT), /* defaultValue= */ C.FORMAT_HANDLED);
......@@ -396,7 +399,8 @@ public final class ExoPlaybackException extends PlaybackException {
bundle.putInt(keyForField(FIELD_TYPE), type);
bundle.putString(keyForField(FIELD_RENDERER_NAME), rendererName);
bundle.putInt(keyForField(FIELD_RENDERER_INDEX), rendererIndex);
bundle.putParcelable(keyForField(FIELD_RENDERER_FORMAT), rendererFormat);
bundle.putBundle(
keyForField(FIELD_RENDERER_FORMAT), BundleableUtils.toNullableBundle(rendererFormat));
bundle.putInt(keyForField(FIELD_RENDERER_FORMAT_SUPPORT), rendererFormatSupport);
bundle.putBoolean(keyForField(FIELD_IS_RECOVERABLE), isRecoverable);
return bundle;
......
......@@ -17,7 +17,6 @@ package com.google.android.exoplayer2.source;
import static com.google.common.truth.Truth.assertThat;
import android.os.Parcel;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.MimeTypes;
......@@ -29,7 +28,7 @@ import org.junit.runner.RunWith;
public final class TrackGroupArrayTest {
@Test
public void parcelable() {
public void roundTripViaBundle_ofTrackGroupArray_yieldsEqualInstance() {
Format.Builder formatBuilder = new Format.Builder();
Format format1 = formatBuilder.setSampleMimeType(MimeTypes.VIDEO_H264).build();
Format format2 = formatBuilder.setSampleMimeType(MimeTypes.AUDIO_AAC).build();
......@@ -38,15 +37,11 @@ public final class TrackGroupArrayTest {
TrackGroup trackGroup1 = new TrackGroup(format1, format2);
TrackGroup trackGroup2 = new TrackGroup(format3);
TrackGroupArray trackGroupArrayToParcel = new TrackGroupArray(trackGroup1, trackGroup2);
TrackGroupArray trackGroupArrayToBundle = new TrackGroupArray(trackGroup1, trackGroup2);
Parcel parcel = Parcel.obtain();
trackGroupArrayToParcel.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
TrackGroupArray trackGroupArrayFromBundle =
TrackGroupArray.CREATOR.fromBundle(trackGroupArrayToBundle.toBundle());
TrackGroupArray trackGroupArrayFromParcel = TrackGroupArray.CREATOR.createFromParcel(parcel);
assertThat(trackGroupArrayFromParcel).isEqualTo(trackGroupArrayToParcel);
parcel.recycle();
assertThat(trackGroupArrayFromBundle).isEqualTo(trackGroupArrayToBundle);
}
}
......@@ -17,7 +17,6 @@ package com.google.android.exoplayer2.source;
import static com.google.common.truth.Truth.assertThat;
import android.os.Parcel;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.MimeTypes;
......@@ -29,20 +28,15 @@ import org.junit.runner.RunWith;
public final class TrackGroupTest {
@Test
public void parcelable() {
public void roundTripViaBundle_ofTrackGroup_yieldsEqualInstance() {
Format.Builder formatBuilder = new Format.Builder();
Format format1 = formatBuilder.setSampleMimeType(MimeTypes.VIDEO_H264).build();
Format format2 = formatBuilder.setSampleMimeType(MimeTypes.AUDIO_AAC).build();
TrackGroup trackGroupToParcel = new TrackGroup(format1, format2);
TrackGroup trackGroupToBundle = new TrackGroup(format1, format2);
Parcel parcel = Parcel.obtain();
trackGroupToParcel.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
TrackGroup trackGroupFromBundle = TrackGroup.CREATOR.fromBundle(trackGroupToBundle.toBundle());
TrackGroup trackGroupFromParcel = TrackGroup.CREATOR.createFromParcel(parcel);
assertThat(trackGroupFromParcel).isEqualTo(trackGroupToParcel);
parcel.recycle();
assertThat(trackGroupFromBundle).isEqualTo(trackGroupToBundle);
}
}
......@@ -29,9 +29,9 @@ import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import android.content.Context;
import android.os.Parcel;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.Bundleable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format;
......@@ -139,37 +139,26 @@ public final class DefaultTrackSelectorTest {
assertThat(parameters.buildUpon().build()).isEqualTo(parameters);
}
/** Tests {@link Parameters} {@link android.os.Parcelable} implementation. */
/** Tests {@link Parameters} {@link Bundleable} implementation. */
@Test
public void parameters_parcelAndUnParcelable() {
Parameters parametersToParcel = buildParametersForEqualsTest();
public void roundTripViaBundle_ofParameters_yieldsEqualInstance() {
Parameters parametersToBundle = buildParametersForEqualsTest();
Parcel parcel = Parcel.obtain();
parametersToParcel.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
Parameters parametersFromBundle = Parameters.CREATOR.fromBundle(parametersToBundle.toBundle());
Parameters parametersFromParcel = Parameters.CREATOR.createFromParcel(parcel);
assertThat(parametersFromParcel).isEqualTo(parametersToParcel);
parcel.recycle();
assertThat(parametersFromBundle).isEqualTo(parametersToBundle);
}
/** Tests {@link SelectionOverride}'s {@link android.os.Parcelable} implementation. */
/** Tests {@link SelectionOverride}'s {@link Bundleable} implementation. */
@Test
public void selectionOverrideParcelable() {
int[] tracks = new int[] {2, 3};
SelectionOverride selectionOverrideToParcel =
new SelectionOverride(/* groupIndex= */ 1, tracks);
Parcel parcel = Parcel.obtain();
selectionOverrideToParcel.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
public void roundTripViaBundle_ofSelectionOverride_yieldsEqualInstance() {
SelectionOverride selectionOverrideToBundle =
new SelectionOverride(/* groupIndex= */ 1, /* tracks...= */ 2, 3);
SelectionOverride selectionOverrideFromParcel =
SelectionOverride.CREATOR.createFromParcel(parcel);
assertThat(selectionOverrideFromParcel).isEqualTo(selectionOverrideToParcel);
SelectionOverride selectionOverrideFromBundle =
SelectionOverride.CREATOR.fromBundle(selectionOverrideToBundle.toBundle());
parcel.recycle();
assertThat(selectionOverrideFromBundle).isEqualTo(selectionOverrideToBundle);
}
/** Tests that a null override clears a track selection. */
......@@ -1764,7 +1753,13 @@ public final class DefaultTrackSelectorTest {
/* rendererIndex= */ 2,
new TrackGroupArray(VIDEO_TRACK_GROUP),
new SelectionOverride(0, 1))
.setSelectionOverride(
/* rendererIndex= */ 2, new TrackGroupArray(AUDIO_TRACK_GROUP), /* override= */ null)
.setSelectionOverride(
/* rendererIndex= */ 5, new TrackGroupArray(VIDEO_TRACK_GROUP), /* override= */ null)
.setRendererDisabled(1, true)
.setRendererDisabled(3, true)
.setRendererDisabled(5, false)
.build();
}
......
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