Add open @IntDef for track selection type

#exofixit

PiperOrigin-RevId: 396780460
This commit is contained in:
andrewlewis 2021-09-15 09:28:54 +01:00 committed by Christos Tsilopoulos
parent aa8fe5df86
commit 8540b7266c
6 changed files with 29 additions and 16 deletions

View File

@ -15,9 +15,15 @@
*/
package com.google.android.exoplayer2.trackselection;
import androidx.annotation.IntDef;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.TrackGroup;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* A track selection consisting of a static subset of selected tracks belonging to a {@link
@ -27,6 +33,17 @@ import com.google.android.exoplayer2.source.TrackGroup;
*/
public interface TrackSelection {
/**
* Represents a type track selection. Either {@link #TYPE_UNSET} or an app-defined value (see
* {@link #TYPE_CUSTOM_BASE}).
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.TYPE_USE})
@IntDef(
open = true,
value = {TYPE_UNSET})
@interface Type {}
/** An unspecified track selection type. */
int TYPE_UNSET = 0;
/** The first value that can be used for application specific track selection types. */
@ -40,6 +57,7 @@ public interface TrackSelection {
* starting from {@link #TYPE_CUSTOM_BASE} to ensure they don't conflict with any types that may
* be added to the library in the future.
*/
@Type
int getType();
/** Returns the {@link TrackGroup} to which the selected tracks belong. */

View File

@ -273,7 +273,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
protected AdaptiveTrackSelection(
TrackGroup group,
int[] tracks,
int type,
@Type int type,
BandwidthMeter bandwidthMeter,
long minDurationForQualityIncreaseMs,
long maxDurationForQualityDecreaseMs,

View File

@ -39,7 +39,7 @@ public abstract class BaseTrackSelection implements ExoTrackSelection {
protected final int[] tracks;
/** The type of the selection. */
private final int type;
private final @Type int type;
/** The {@link Format}s of the selected tracks, in order of decreasing bandwidth. */
private final Format[] formats;
/** Selected track exclusion timestamps, in order of decreasing bandwidth. */
@ -63,7 +63,7 @@ public abstract class BaseTrackSelection implements ExoTrackSelection {
* null or empty. May be in any order.
* @param type The type that will be returned from {@link TrackSelection#getType()}.
*/
public BaseTrackSelection(TrackGroup group, int[] tracks, int type) {
public BaseTrackSelection(TrackGroup group, int[] tracks, @Type int type) {
Assertions.checkState(tracks.length > 0);
this.type = type;
this.group = Assertions.checkNotNull(group);

View File

@ -1262,7 +1262,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
public final int groupIndex;
public final int[] tracks;
public final int length;
public final int type;
public final @TrackSelection.Type int type;
/**
* Constructs a {@code SelectionOverride} to override tracks of a group.
@ -1281,7 +1281,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
* @param tracks The overriding track indices within the track group.
* @param type The type that will be returned from {@link TrackSelection#getType()}.
*/
public SelectionOverride(int groupIndex, int[] tracks, int type) {
public SelectionOverride(int groupIndex, int[] tracks, @TrackSelection.Type int type) {
this.groupIndex = groupIndex;
this.tracks = Arrays.copyOf(tracks, tracks.length);
this.length = tracks.length;

View File

@ -43,7 +43,7 @@ public interface ExoTrackSelection extends TrackSelection {
/** The indices of the selected tracks in {@link #group}. */
public final int[] tracks;
/** The type that will be returned from {@link TrackSelection#getType()}. */
public final int type;
public final @Type int type;
/**
* @param group The {@link TrackGroup}. Must not be null.
@ -60,7 +60,7 @@ public interface ExoTrackSelection extends TrackSelection {
* null or empty. May be in any order.
* @param type The type that will be returned from {@link TrackSelection#getType()}.
*/
public Definition(TrackGroup group, int[] tracks, int type) {
public Definition(TrackGroup group, int[] tracks, @Type int type) {
this.group = group;
this.tracks = tracks;
this.type = type;

View File

@ -41,13 +41,8 @@ public final class FixedTrackSelection extends BaseTrackSelection {
* @param track The index of the selected track within the {@link TrackGroup}.
* @param type The type that will be returned from {@link TrackSelection#getType()}.
*/
public FixedTrackSelection(TrackGroup group, int track, int type) {
this(
group,
/* track= */ track,
/* type= */ type,
/* reason= */ C.SELECTION_REASON_UNKNOWN,
null);
public FixedTrackSelection(TrackGroup group, int track, @Type int type) {
this(group, track, type, C.SELECTION_REASON_UNKNOWN, /* data= */ null);
}
/**
@ -58,8 +53,8 @@ public final class FixedTrackSelection extends BaseTrackSelection {
* @param data Optional data associated with the track selection.
*/
public FixedTrackSelection(
TrackGroup group, int track, int type, int reason, @Nullable Object data) {
super(group, /* tracks= */ new int[] {track}, /* type= */ type);
TrackGroup group, int track, @Type int type, int reason, @Nullable Object data) {
super(group, /* tracks= */ new int[] {track}, type);
this.reason = reason;
this.data = data;
}