Skip to content

Commit

Permalink
Add open @IntDef for track types
Browse files Browse the repository at this point in the history
Also add handling of `C.TRACK_TYPE_IMAGE` in a couple of places where it was
missing.

#exofixit

PiperOrigin-RevId: 395078312
  • Loading branch information
andrewlewis authored and icbaker committed Sep 6, 2021
1 parent 00dda04 commit d05c15d
Show file tree
Hide file tree
Showing 25 changed files with 105 additions and 65 deletions.
23 changes: 23 additions & 0 deletions library/common/src/main/java/com/google/android/exoplayer2/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,29 @@ private C() {}
*/
public static final int DATA_TYPE_CUSTOM_BASE = 10000;

/**
* Represents a type of media track. May be one of {@link #TRACK_TYPE_UNKNOWN}, {@link
* #TRACK_TYPE_DEFAULT}, {@link #TRACK_TYPE_AUDIO}, {@link #TRACK_TYPE_VIDEO}, {@link
* #TRACK_TYPE_TEXT}, {@link #TRACK_TYPE_IMAGE}, {@link #TRACK_TYPE_METADATA}, {@link
* #TRACK_TYPE_CAMERA_MOTION} or {@link #TRACK_TYPE_NONE}. May also be an app-defined value (see
* {@link #TRACK_TYPE_CUSTOM_BASE}).
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@IntDef(
open = true,
value = {
TRACK_TYPE_UNKNOWN,
TRACK_TYPE_DEFAULT,
TRACK_TYPE_AUDIO,
TRACK_TYPE_VIDEO,
TRACK_TYPE_TEXT,
TRACK_TYPE_IMAGE,
TRACK_TYPE_METADATA,
TRACK_TYPE_CAMERA_MOTION,
TRACK_TYPE_NONE,
})
public @interface TrackType {}
/** A type constant for tracks of unknown type. */
public static final int TRACK_TYPE_UNKNOWN = -1;
/** A type constant for tracks of some default type, where the type itself is unknown. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ public Format withManifestFormatInfo(Format manifestFormat) {
return this;
}

int trackType = MimeTypes.getTrackType(sampleMimeType);
@C.TrackType int trackType = MimeTypes.getTrackType(sampleMimeType);

// Use manifest value only.
@Nullable String id = manifestFormat.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ public Builder setDrmSessionForClearPeriods(boolean sessionForClearPeriods) {
}

/**
* Sets a list of {@link C}{@code .TRACK_TYPE_*} constants for which to use a DRM session even
* when the tracks are in the clear.
* Sets a list of {@link C.TrackType track types} for which to use a DRM session even when the
* tracks are in the clear.
*
* <p>For the common case of using a DRM session for {@link C#TRACK_TYPE_VIDEO} and {@link
* C#TRACK_TYPE_AUDIO} the {@link #setDrmSessionForClearPeriods(boolean)} can be used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,14 @@ public static String getMimeTypeFromMp4ObjectType(int objectType) {
}

/**
* Returns the {@link C}{@code .TRACK_TYPE_*} constant corresponding to a specified MIME type, or
* {@link C#TRACK_TYPE_UNKNOWN} if it could not be determined.
* Returns the {@link C.TrackType track type} constant corresponding to a specified MIME type,
* which may be {@link C#TRACK_TYPE_UNKNOWN} if it could not be determined.
*
* @param mimeType A MIME type.
* @return The corresponding {@link C}{@code .TRACK_TYPE_*}, or {@link C#TRACK_TYPE_UNKNOWN} if it
* could not be determined.
* @return The corresponding {@link C.TrackType track type}, which may be {@link
* C#TRACK_TYPE_UNKNOWN} if it could not be determined.
*/
@C.TrackType
public static int getTrackType(@Nullable String mimeType) {
if (TextUtils.isEmpty(mimeType)) {
return C.TRACK_TYPE_UNKNOWN;
Expand Down Expand Up @@ -559,9 +560,10 @@ public static int getEncoding(String mimeType, @Nullable String codec) {
* Equivalent to {@code getTrackType(getMediaMimeType(codec))}.
*
* @param codec An RFC 6381 codec string.
* @return The corresponding {@link C}{@code .TRACK_TYPE_*}, or {@link C#TRACK_TYPE_UNKNOWN} if it
* could not be determined.
* @return The corresponding {@link C.TrackType track type}, which may be {@link
* C#TRACK_TYPE_UNKNOWN} if it could not be determined.
*/
@C.TrackType
public static int getTrackTypeOfCodec(String codec) {
return getTrackType(getMediaMimeType(codec));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ public static String getUserAgent(Context context, String applicationName) {
}

/** Returns the number of codec strings in {@code codecs} whose type matches {@code trackType}. */
public static int getCodecCountOfType(@Nullable String codecs, int trackType) {
public static int getCodecCountOfType(@Nullable String codecs, @C.TrackType int trackType) {
String[] codecArray = splitCodecs(codecs);
int count = 0;
for (String codec : codecArray) {
Expand Down Expand Up @@ -2333,27 +2333,29 @@ public static Point getCurrentDisplayModeSize(Context context, Display display)
}

/**
* Returns a string representation of a {@code TRACK_TYPE_*} constant defined in {@link C}.
* Returns a string representation of a {@link C.TrackType}.
*
* @param trackType A {@code TRACK_TYPE_*} constant,
* @param trackType A {@link C.TrackType} constant,
* @return A string representation of this constant.
*/
public static String getTrackTypeString(int trackType) {
public static String getTrackTypeString(@C.TrackType int trackType) {
switch (trackType) {
case C.TRACK_TYPE_AUDIO:
return "audio";
case C.TRACK_TYPE_DEFAULT:
return "default";
case C.TRACK_TYPE_AUDIO:
return "audio";
case C.TRACK_TYPE_VIDEO:
return "video";
case C.TRACK_TYPE_TEXT:
return "text";
case C.TRACK_TYPE_IMAGE:
return "image";
case C.TRACK_TYPE_METADATA:
return "metadata";
case C.TRACK_TYPE_CAMERA_MOTION:
return "camera motion";
case C.TRACK_TYPE_NONE:
return "none";
case C.TRACK_TYPE_TEXT:
return "text";
case C.TRACK_TYPE_VIDEO:
return "video";
default:
return trackType >= C.TRACK_TYPE_CUSTOM_BASE ? "custom (" + trackType + ")" : "?";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public class DefaultLoadControl implements LoadControl {
/** A default size in bytes for a camera motion buffer. */
public static final int DEFAULT_CAMERA_MOTION_BUFFER_SIZE = 2 * C.DEFAULT_BUFFER_SEGMENT_SIZE;

/** A default size in bytes for an image buffer. */
public static final int DEFAULT_IMAGE_BUFFER_SIZE = 2 * C.DEFAULT_BUFFER_SEGMENT_SIZE;

/** A default size in bytes for a muxed buffer (e.g. containing video, audio and text). */
public static final int DEFAULT_MUXED_BUFFER_SIZE =
DEFAULT_VIDEO_BUFFER_SIZE + DEFAULT_AUDIO_BUFFER_SIZE + DEFAULT_TEXT_BUFFER_SIZE;
Expand Down Expand Up @@ -421,7 +424,7 @@ private void reset(boolean resetAllocator) {
}
}

private static int getDefaultBufferSize(int trackType) {
private static int getDefaultBufferSize(@C.TrackType int trackType) {
switch (trackType) {
case C.TRACK_TYPE_DEFAULT:
return DEFAULT_MUXED_BUFFER_SIZE;
Expand All @@ -435,8 +438,11 @@ private static int getDefaultBufferSize(int trackType) {
return DEFAULT_METADATA_BUFFER_SIZE;
case C.TRACK_TYPE_CAMERA_MOTION:
return DEFAULT_CAMERA_MOTION_BUFFER_SIZE;
case C.TRACK_TYPE_IMAGE:
return DEFAULT_IMAGE_BUFFER_SIZE;
case C.TRACK_TYPE_NONE:
return 0;
case C.TRACK_TYPE_UNKNOWN:
default:
throw new IllegalArgumentException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ interface WakeupListener {
* Returns the track type that the renderer handles.
*
* @see ExoPlayer#getRendererType(int)
* @return One of the {@code TRACK_TYPE_*} constants defined in {@link C}.
* @return The {@link C.TrackType track type}.
*/
@C.TrackType
int getTrackType();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,8 @@ private void verifyApplicationThread() {
}
}

private void sendRendererMessage(int trackType, int messageType, @Nullable Object payload) {
private void sendRendererMessage(
@C.TrackType int trackType, int messageType, @Nullable Object payload) {
for (Renderer renderer : renderers) {
if (renderer.getTrackType() == trackType) {
player.createMessage(renderer).setType(messageType).setPayload(payload).send();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Factory(int trackType) {
* {@link MediaCodec}.
*/
public Factory(
int trackType,
@C.TrackType int trackType,
boolean forceQueueingSynchronizationWorkaround,
boolean synchronizeCodecInteractionsWithQueueing) {
this(
Expand Down Expand Up @@ -331,15 +331,15 @@ private void maybeBlockOnQueueing() {
}
}

private static String createCallbackThreadLabel(int trackType) {
private static String createCallbackThreadLabel(@C.TrackType int trackType) {
return createThreadLabel(trackType, /* prefix= */ "ExoPlayer:MediaCodecAsyncAdapter:");
}

private static String createQueueingThreadLabel(int trackType) {
private static String createQueueingThreadLabel(@C.TrackType int trackType) {
return createThreadLabel(trackType, /* prefix= */ "ExoPlayer:MediaCodecQueueingThread:");
}

private static String createThreadLabel(int trackType, String prefix) {
private static String createThreadLabel(@C.TrackType int trackType, String prefix) {
StringBuilder labelBuilder = new StringBuilder(prefix);
if (trackType == C.TRACK_TYPE_AUDIO) {
labelBuilder.append("Audio");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ private static String buildCustomDiagnosticInfo(int errorCode) {
private int pendingOutputStreamOffsetCount;

/**
* @param trackType The track type that the renderer handles. One of the {@code C.TRACK_TYPE_*}
* constants defined in {@link C}.
* @param trackType The {@link C.TrackType track type} that the renderer handles.
* @param mediaCodecSelector A decoder selector.
* @param enableDecoderFallback Whether to enable fallback to lower-priority decoders if decoder
* initialization fails. This may result in using a decoder that is less efficient or slower
Expand All @@ -371,7 +370,7 @@ private static String buildCustomDiagnosticInfo(int errorCode) {
* explicitly using {@link MediaFormat#KEY_OPERATING_RATE}).
*/
public MediaCodecRenderer(
int trackType,
@C.TrackType int trackType,
MediaCodecAdapter.Factory codecAdapterFactory,
MediaCodecSelector mediaCodecSelector,
boolean enableDecoderFallback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.C.DataType;
import com.google.android.exoplayer2.C.TrackType;
import com.google.android.exoplayer2.Format;

/** Descriptor for data being loaded or selected by a {@link MediaSource}. */
Expand All @@ -26,10 +27,10 @@ public final class MediaLoadData {
/** The {@link DataType data type}. */
@DataType public final int dataType;
/**
* One of the {@link C} {@code TRACK_TYPE_*} constants if the data corresponds to media of a
* specific type. {@link C#TRACK_TYPE_UNKNOWN} otherwise.
* One of the {@link TrackType track type}, which is a media track type if the data corresponds to
* media of a specific type, or {@link C#TRACK_TYPE_UNKNOWN} otherwise.
*/
public final int trackType;
@TrackType public final int trackType;
/**
* The format of the track to which the data belongs. Null if the data does not belong to a
* specific track.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public interface ReleaseCallback<T extends ChunkSource> {

private static final String TAG = "ChunkSampleStream";

public final int primaryTrackType;
@C.TrackType public final int primaryTrackType;

private final int[] embeddedTrackTypes;
private final Format[] embeddedTrackFormats;
Expand Down Expand Up @@ -99,8 +99,7 @@ public interface ReleaseCallback<T extends ChunkSource> {
/**
* Constructs an instance.
*
* @param primaryTrackType The type of the primary track. One of the {@link C} {@code
* TRACK_TYPE_*} constants.
* @param primaryTrackType The {@link C.TrackType type} of the primary track.
* @param embeddedTrackTypes The types of any embedded tracks, or null.
* @param embeddedTrackFormats The formats of the embedded tracks, or null.
* @param chunkSource A {@link ChunkSource} from which chunks to load are obtained.
Expand All @@ -115,7 +114,7 @@ public interface ReleaseCallback<T extends ChunkSource> {
* events.
*/
public ChunkSampleStream(
int primaryTrackType,
@C.TrackType int primaryTrackType,
@Nullable int[] embeddedTrackTypes,
@Nullable Format[] embeddedTrackFormats,
T chunkSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ private void maybeEndTracks() {
tracksEnded = true;
}

@C.TrackType
private static int toTrackTypeConstant(@Nullable String string) {
if (string == null) {
return C.TRACK_TYPE_UNKNOWN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ private static final class TrackGroupInfo {
private static final int CATEGORY_MANIFEST_EVENTS = 2;

public final int[] adaptationSetIndices;
public final int trackType;
@C.TrackType public final int trackType;
@TrackGroupCategory public final int trackGroupCategory;

public final int eventStreamGroupIndex;
Expand Down Expand Up @@ -981,7 +981,7 @@ public static TrackGroupInfo mpdEventTrack(int eventStreamIndex) {
}

private TrackGroupInfo(
int trackType,
@C.TrackType int trackType,
@TrackGroupCategory int trackGroupCategory,
int[] adaptationSetIndices,
int primaryTrackGroupIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.source.dash.manifest;

import com.google.android.exoplayer2.C;
import java.util.Collections;
import java.util.List;

Expand All @@ -30,11 +31,8 @@ public class AdaptationSet {
*/
public final int id;

/**
* The type of the adaptation set. One of the {@link com.google.android.exoplayer2.C} {@code
* TRACK_TYPE_*} constants.
*/
public final int type;
/** The {@link C.TrackType track type} of the adaptation set. */
@C.TrackType public final int type;

/** {@link Representation}s in the adaptation set. */
public final List<Representation> representations;
Expand All @@ -51,16 +49,15 @@ public class AdaptationSet {
/**
* @param id A non-negative identifier for the adaptation set that's unique in the scope of its
* containing period, or {@link #ID_UNSET} if not specified.
* @param type The type of the adaptation set. One of the {@link com.google.android.exoplayer2.C}
* {@code TRACK_TYPE_*} constants.
* @param type The {@link C.TrackType track type} of the adaptation set.
* @param representations {@link Representation}s in the adaptation set.
* @param accessibilityDescriptors Accessibility descriptors in the adaptation set.
* @param essentialProperties Essential properties in the adaptation set.
* @param supplementalProperties Supplemental properties in the adaptation set.
*/
public AdaptationSet(
int id,
int type,
@C.TrackType int type,
List<Representation> representations,
List<Descriptor> accessibilityDescriptors,
List<Descriptor> essentialProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ protected AdaptationSet parseAdaptationSet(
long timeShiftBufferDepthMs)
throws XmlPullParserException, IOException {
int id = parseInt(xpp, "id", AdaptationSet.ID_UNSET);
int contentType = parseContentType(xpp);
@C.TrackType int contentType = parseContentType(xpp);

String mimeType = xpp.getAttributeValue(null, "mimeType");
String codecs = xpp.getAttributeValue(null, "codecs");
Expand Down Expand Up @@ -514,7 +514,7 @@ protected AdaptationSet parseAdaptationSet(

protected AdaptationSet buildAdaptationSet(
int id,
int contentType,
@C.TrackType int contentType,
List<Representation> representations,
List<Descriptor> accessibilityDescriptors,
List<Descriptor> essentialProperties,
Expand All @@ -528,6 +528,7 @@ protected AdaptationSet buildAdaptationSet(
supplementalProperties);
}

@C.TrackType
protected int parseContentType(XmlPullParser xpp) {
String contentType = xpp.getAttributeValue(null, "contentType");
return TextUtils.isEmpty(contentType)
Expand Down Expand Up @@ -1676,7 +1677,8 @@ private static String checkLanguageConsistency(
* @param secondType The second type.
* @return The consistent type.
*/
private static int checkContentTypeConsistency(int firstType, int secondType) {
private static int checkContentTypeConsistency(
@C.TrackType int firstType, @C.TrackType int secondType) {
if (firstType == C.TRACK_TYPE_UNKNOWN) {
return secondType;
} else if (secondType == C.TRACK_TYPE_UNKNOWN) {
Expand Down
Loading

0 comments on commit d05c15d

Please sign in to comment.