Add open @IntDef for track types

Also add handling of `C.TRACK_TYPE_IMAGE` in a couple of places where it was
missing.

#exofixit

PiperOrigin-RevId: 395078312
This commit is contained in:
andrewlewis 2021-09-06 13:26:34 +01:00 committed by Ian Baker
parent 00dda049ea
commit d05c15dee0
25 changed files with 105 additions and 65 deletions

View File

@ -649,6 +649,29 @@ public final class 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. */

View File

@ -1008,7 +1008,7 @@ public final class Format implements Bundleable {
return this;
}
int trackType = MimeTypes.getTrackType(sampleMimeType);
@C.TrackType int trackType = MimeTypes.getTrackType(sampleMimeType);
// Use manifest value only.
@Nullable String id = manifestFormat.id;

View File

@ -352,8 +352,8 @@ public final class MediaItem implements Bundleable {
}
/**
* 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.

View File

@ -486,13 +486,14 @@ public final class MimeTypes {
}
/**
* 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;
@ -559,9 +560,10 @@ public final class MimeTypes {
* 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));
}

View File

@ -1498,7 +1498,7 @@ public final class Util {
}
/** 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) {
@ -2333,27 +2333,29 @@ public final class Util {
}
/**
* 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 + ")" : "?";
}

View File

@ -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;
@ -421,7 +424,7 @@ public class DefaultLoadControl implements LoadControl {
}
}
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;
@ -435,8 +438,11 @@ public class DefaultLoadControl implements LoadControl {
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();
}

View File

@ -208,8 +208,9 @@ public interface Renderer extends PlayerMessage.Target {
* 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();
/**

View File

@ -1837,7 +1837,8 @@ public class SimpleExoPlayer extends BasePlayer
}
}
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();

View File

@ -73,7 +73,7 @@ import java.nio.ByteBuffer;
* {@link MediaCodec}.
*/
public Factory(
int trackType,
@C.TrackType int trackType,
boolean forceQueueingSynchronizationWorkaround,
boolean synchronizeCodecInteractionsWithQueueing) {
this(
@ -331,15 +331,15 @@ import java.nio.ByteBuffer;
}
}
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");

View File

@ -360,8 +360,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
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
@ -371,7 +370,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
* explicitly using {@link MediaFormat#KEY_OPERATING_RATE}).
*/
public MediaCodecRenderer(
int trackType,
@C.TrackType int trackType,
MediaCodecAdapter.Factory codecAdapterFactory,
MediaCodecSelector mediaCodecSelector,
boolean enableDecoderFallback,

View File

@ -18,6 +18,7 @@ package com.google.android.exoplayer2.source;
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}. */
@ -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.

View File

@ -69,7 +69,7 @@ public class ChunkSampleStream<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;
@ -99,8 +99,7 @@ public class ChunkSampleStream<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.
@ -115,7 +114,7 @@ public class ChunkSampleStream<T extends ChunkSource>
* events.
*/
public ChunkSampleStream(
int primaryTrackType,
@C.TrackType int primaryTrackType,
@Nullable int[] embeddedTrackTypes,
@Nullable Format[] embeddedTrackFormats,
T chunkSource,

View File

@ -429,6 +429,7 @@ public final class OutputConsumerAdapterV30 implements MediaParser.OutputConsume
tracksEnded = true;
}
@C.TrackType
private static int toTrackTypeConstant(@Nullable String string) {
if (string == null) {
return C.TRACK_TYPE_UNKNOWN;

View File

@ -921,7 +921,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
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;
@ -981,7 +981,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
}
private TrackGroupInfo(
int trackType,
@C.TrackType int trackType,
@TrackGroupCategory int trackGroupCategory,
int[] adaptationSetIndices,
int primaryTrackGroupIndex,

View File

@ -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;
@ -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;
@ -51,8 +49,7 @@ 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.
@ -60,7 +57,7 @@ public class AdaptationSet {
*/
public AdaptationSet(
int id,
int type,
@C.TrackType int type,
List<Representation> representations,
List<Descriptor> accessibilityDescriptors,
List<Descriptor> essentialProperties,

View File

@ -376,7 +376,7 @@ public class DashManifestParser extends DefaultHandler
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");
@ -514,7 +514,7 @@ public class DashManifestParser extends DefaultHandler
protected AdaptationSet buildAdaptationSet(
int id,
int contentType,
@C.TrackType int contentType,
List<Representation> representations,
List<Descriptor> accessibilityDescriptors,
List<Descriptor> essentialProperties,
@ -528,6 +528,7 @@ public class DashManifestParser extends DefaultHandler
supplementalProperties);
}
@C.TrackType
protected int parseContentType(XmlPullParser xpp) {
String contentType = xpp.getAttributeValue(null, "contentType");
return TextUtils.isEmpty(contentType)
@ -1676,7 +1677,8 @@ public class DashManifestParser extends DefaultHandler
* @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) {

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.extractor;
import com.google.android.exoplayer2.C;
/** Receives stream level data extracted by an {@link Extractor}. */
public interface ExtractorOutput {
@ -48,11 +50,10 @@ public interface ExtractorOutput {
* id}.
*
* @param id A track identifier.
* @param type The type of the track. Typically one of the {@link com.google.android.exoplayer2.C}
* {@code TRACK_TYPE_*} constants.
* @param type The {@link C.TrackType track type}.
* @return The {@link TrackOutput} for the given track identifier.
*/
TrackOutput track(int id, int type);
TrackOutput track(int id, @C.TrackType int type);
/**
* Called when all tracks have been identified, meaning no new {@code trackId} values will be

View File

@ -866,6 +866,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
}
/** Returns the track type for a given handler value. */
@C.TrackType
private static int getTrackTypeForHdlr(int hdlr) {
if (hdlr == TYPE_soun) {
return C.TRACK_TYPE_AUDIO;

View File

@ -45,7 +45,7 @@ public final class Track {
/**
* One of {@link C#TRACK_TYPE_AUDIO}, {@link C#TRACK_TYPE_VIDEO} and {@link C#TRACK_TYPE_TEXT}.
*/
public final int type;
@C.TrackType public final int type;
/** The track timescale, defined as the number of time units that pass in one second. */
public final long timescale;
@ -81,7 +81,7 @@ public final class Track {
public Track(
int id,
int type,
@C.TrackType int type,
long timescale,
long movieTimescale,
long durationUs,

View File

@ -628,6 +628,7 @@ public final class HlsMediaPeriod
numberOfAudioCodecs <= 1
&& numberOfVideoCodecs <= 1
&& numberOfAudioCodecs + numberOfVideoCodecs > 0;
@C.TrackType
int trackType =
!useVideoVariantsOnly && numberOfAudioCodecs > 0
? C.TRACK_TYPE_AUDIO
@ -754,7 +755,7 @@ public final class HlsMediaPeriod
}
private HlsSampleStreamWrapper buildSampleStreamWrapper(
int trackType,
@C.TrackType int trackType,
Uri[] playlistUrls,
Format[] playlistFormats,
@Nullable Format muxedAudioFormat,

View File

@ -125,7 +125,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
new HashSet<>(
Arrays.asList(C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_VIDEO, C.TRACK_TYPE_METADATA)));
private final int trackType;
@C.TrackType private final int trackType;
private final Callback callback;
private final HlsChunkSource chunkSource;
private final Allocator allocator;
@ -135,7 +135,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
private final Loader loader;
private final MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher;
private final @HlsMediaSource.MetadataType int metadataType;
@HlsMediaSource.MetadataType private final int metadataType;
private final HlsChunkSource.HlsChunkHolder nextChunkHolder;
private final ArrayList<HlsMediaChunk> mediaChunks;
private final List<HlsMediaChunk> readOnlyMediaChunks;
@ -185,7 +185,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
@Nullable private HlsMediaChunk sourceChunk;
/**
* @param trackType The type of the track. One of the {@link C} {@code TRACK_TYPE_*} constants.
* @param trackType The {@link C.TrackType track type}.
* @param callback A callback for the wrapper.
* @param chunkSource A {@link HlsChunkSource} from which chunks to load are obtained.
* @param overridingDrmInitData Overriding {@link DrmInitData}, keyed by protection scheme type
@ -203,7 +203,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
* events.
*/
public HlsSampleStreamWrapper(
int trackType,
@C.TrackType int trackType,
Callback callback,
HlsChunkSource chunkSource,
Map<String, DrmInitData> overridingDrmInitData,

View File

@ -60,7 +60,7 @@ public class SsManifest implements FilterableManifest<SsManifest> {
private static final String URL_PLACEHOLDER_BITRATE_1 = "{bitrate}";
private static final String URL_PLACEHOLDER_BITRATE_2 = "{Bitrate}";
public final int type;
@C.TrackType public final int type;
public final String subType;
public final long timescale;
public final String name;
@ -82,7 +82,7 @@ public class SsManifest implements FilterableManifest<SsManifest> {
public StreamElement(
String baseUri,
String chunkTemplate,
int type,
@C.TrackType int type,
String subType,
long timescale,
String name,
@ -115,7 +115,7 @@ public class SsManifest implements FilterableManifest<SsManifest> {
private StreamElement(
String baseUri,
String chunkTemplate,
int type,
@C.TrackType int type,
String subType,
long timescale,
String name,

View File

@ -59,7 +59,8 @@ public class SsTestUtils {
}
/** Creates test video stream element with the given name, track type and formats. */
public static StreamElement createStreamElement(String name, int trackType, Format... formats) {
public static StreamElement createStreamElement(
String name, @C.TrackType int trackType, Format... formats) {
return new StreamElement(
TEST_BASE_URI,
TEST_CHUNK_TEMPLATE,

View File

@ -23,6 +23,7 @@ import static com.google.common.truth.Truth.assertThat;
import android.os.Handler;
import android.os.Looper;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
@ -45,7 +46,8 @@ public final class DefaultRenderersFactoryAsserts {
* @param clazz The extension renderer class.
* @param type The type of the renderer.
*/
public static void assertExtensionRendererCreated(Class<? extends Renderer> clazz, int type) {
public static void assertExtensionRendererCreated(
Class<? extends Renderer> clazz, @C.TrackType int type) {
// In EXTENSION_RENDERER_MODE_OFF the renderer should not be created.
Renderer[] renderers = createRenderers(EXTENSION_RENDERER_MODE_OFF);
for (Renderer renderer : renderers) {

View File

@ -62,7 +62,7 @@ public class FakeRenderer extends BaseRenderer {
public int positionResetCount;
public int sampleBufferReadCount;
public FakeRenderer(int trackType) {
public FakeRenderer(@C.TrackType int trackType) {
super(trackType);
buffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL);
lastSamplePositionUs = Long.MIN_VALUE;