1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.exoplayer2;
17 
18 import android.content.Context;
19 import android.media.AudioAttributes;
20 import android.media.AudioFormat;
21 import android.media.AudioManager;
22 import android.media.MediaCodec;
23 import android.media.MediaFormat;
24 import androidx.annotation.IntDef;
25 import androidx.annotation.RequiresApi;
26 import com.google.android.exoplayer2.util.Util;
27 import java.lang.annotation.Documented;
28 import java.lang.annotation.Retention;
29 import java.lang.annotation.RetentionPolicy;
30 import java.util.UUID;
31 
32 /**
33  * Defines constants used by the library.
34  */
35 @SuppressWarnings("InlinedApi")
36 public final class C {
37 
C()38   private C() {}
39 
40   /**
41    * Special constant representing a time corresponding to the end of a source. Suitable for use in
42    * any time base.
43    */
44   public static final long TIME_END_OF_SOURCE = Long.MIN_VALUE;
45 
46   /**
47    * Special constant representing an unset or unknown time or duration. Suitable for use in any
48    * time base.
49    */
50   public static final long TIME_UNSET = Long.MIN_VALUE + 1;
51 
52   /**
53    * Represents an unset or unknown index.
54    */
55   public static final int INDEX_UNSET = -1;
56 
57   /**
58    * Represents an unset or unknown position.
59    */
60   public static final int POSITION_UNSET = -1;
61 
62   /**
63    * Represents an unset or unknown length.
64    */
65   public static final int LENGTH_UNSET = -1;
66 
67   /** Represents an unset or unknown percentage. */
68   public static final int PERCENTAGE_UNSET = -1;
69 
70   /** The number of milliseconds in one second. */
71   public static final long MILLIS_PER_SECOND = 1000L;
72 
73   /** The number of microseconds in one second. */
74   public static final long MICROS_PER_SECOND = 1000000L;
75 
76   /**
77    * The number of nanoseconds in one second.
78    */
79   public static final long NANOS_PER_SECOND = 1000000000L;
80 
81   /** The number of bits per byte. */
82   public static final int BITS_PER_BYTE = 8;
83 
84   /** The number of bytes per float. */
85   public static final int BYTES_PER_FLOAT = 4;
86 
87   /**
88    * The name of the ASCII charset.
89    */
90   public static final String ASCII_NAME = "US-ASCII";
91 
92   /**
93    * The name of the UTF-8 charset.
94    */
95   public static final String UTF8_NAME = "UTF-8";
96 
97   /** The name of the ISO-8859-1 charset. */
98   public static final String ISO88591_NAME = "ISO-8859-1";
99 
100   /** The name of the UTF-16 charset. */
101   public static final String UTF16_NAME = "UTF-16";
102 
103   /** The name of the UTF-16 little-endian charset. */
104   public static final String UTF16LE_NAME = "UTF-16LE";
105 
106   /**
107    * The name of the serif font family.
108    */
109   public static final String SERIF_NAME = "serif";
110 
111   /**
112    * The name of the sans-serif font family.
113    */
114   public static final String SANS_SERIF_NAME = "sans-serif";
115 
116   /**
117    * Crypto modes for a codec. One of {@link #CRYPTO_MODE_UNENCRYPTED}, {@link #CRYPTO_MODE_AES_CTR}
118    * or {@link #CRYPTO_MODE_AES_CBC}.
119    */
120   @Documented
121   @Retention(RetentionPolicy.SOURCE)
122   @IntDef({CRYPTO_MODE_UNENCRYPTED, CRYPTO_MODE_AES_CTR, CRYPTO_MODE_AES_CBC})
123   public @interface CryptoMode {}
124   /**
125    * @see MediaCodec#CRYPTO_MODE_UNENCRYPTED
126    */
127   public static final int CRYPTO_MODE_UNENCRYPTED = MediaCodec.CRYPTO_MODE_UNENCRYPTED;
128   /**
129    * @see MediaCodec#CRYPTO_MODE_AES_CTR
130    */
131   public static final int CRYPTO_MODE_AES_CTR = MediaCodec.CRYPTO_MODE_AES_CTR;
132   /**
133    * @see MediaCodec#CRYPTO_MODE_AES_CBC
134    */
135   public static final int CRYPTO_MODE_AES_CBC = MediaCodec.CRYPTO_MODE_AES_CBC;
136 
137   /**
138    * Represents an unset {@link android.media.AudioTrack} session identifier. Equal to
139    * {@link AudioManager#AUDIO_SESSION_ID_GENERATE}.
140    */
141   public static final int AUDIO_SESSION_ID_UNSET = AudioManager.AUDIO_SESSION_ID_GENERATE;
142 
143   /**
144    * Represents an audio encoding, or an invalid or unset value. One of {@link Format#NO_VALUE},
145    * {@link #ENCODING_INVALID}, {@link #ENCODING_PCM_8BIT}, {@link #ENCODING_PCM_16BIT}, {@link
146    * #ENCODING_PCM_16BIT_BIG_ENDIAN}, {@link #ENCODING_PCM_24BIT}, {@link #ENCODING_PCM_32BIT},
147    * {@link #ENCODING_PCM_FLOAT}, {@link #ENCODING_MP3}, {@link #ENCODING_AC3}, {@link
148    * #ENCODING_E_AC3}, {@link #ENCODING_E_AC3_JOC}, {@link #ENCODING_AC4}, {@link #ENCODING_DTS},
149    * {@link #ENCODING_DTS_HD} or {@link #ENCODING_DOLBY_TRUEHD}.
150    */
151   @Documented
152   @Retention(RetentionPolicy.SOURCE)
153   @IntDef({
154     Format.NO_VALUE,
155     ENCODING_INVALID,
156     ENCODING_PCM_8BIT,
157     ENCODING_PCM_16BIT,
158     ENCODING_PCM_16BIT_BIG_ENDIAN,
159     ENCODING_PCM_24BIT,
160     ENCODING_PCM_32BIT,
161     ENCODING_PCM_FLOAT,
162     ENCODING_MP3,
163     ENCODING_AAC_LC,
164     ENCODING_AAC_HE_V1,
165     ENCODING_AAC_HE_V2,
166     ENCODING_AAC_XHE,
167     ENCODING_AAC_ELD,
168     ENCODING_AC3,
169     ENCODING_E_AC3,
170     ENCODING_E_AC3_JOC,
171     ENCODING_AC4,
172     ENCODING_DTS,
173     ENCODING_DTS_HD,
174     ENCODING_DOLBY_TRUEHD
175   })
176   public @interface Encoding {}
177 
178   /**
179    * Represents a PCM audio encoding, or an invalid or unset value. One of {@link Format#NO_VALUE},
180    * {@link #ENCODING_INVALID}, {@link #ENCODING_PCM_8BIT}, {@link #ENCODING_PCM_16BIT}, {@link
181    * #ENCODING_PCM_16BIT_BIG_ENDIAN}, {@link #ENCODING_PCM_24BIT}, {@link #ENCODING_PCM_32BIT},
182    * {@link #ENCODING_PCM_FLOAT}.
183    */
184   @Documented
185   @Retention(RetentionPolicy.SOURCE)
186   @IntDef({
187     Format.NO_VALUE,
188     ENCODING_INVALID,
189     ENCODING_PCM_8BIT,
190     ENCODING_PCM_16BIT,
191     ENCODING_PCM_16BIT_BIG_ENDIAN,
192     ENCODING_PCM_24BIT,
193     ENCODING_PCM_32BIT,
194     ENCODING_PCM_FLOAT
195   })
196   public @interface PcmEncoding {}
197   /** @see AudioFormat#ENCODING_INVALID */
198   public static final int ENCODING_INVALID = AudioFormat.ENCODING_INVALID;
199   /** @see AudioFormat#ENCODING_PCM_8BIT */
200   public static final int ENCODING_PCM_8BIT = AudioFormat.ENCODING_PCM_8BIT;
201   /** @see AudioFormat#ENCODING_PCM_16BIT */
202   public static final int ENCODING_PCM_16BIT = AudioFormat.ENCODING_PCM_16BIT;
203   /** Like {@link #ENCODING_PCM_16BIT}, but with the bytes in big endian order. */
204   public static final int ENCODING_PCM_16BIT_BIG_ENDIAN = 0x10000000;
205   /** PCM encoding with 24 bits per sample. */
206   public static final int ENCODING_PCM_24BIT = 0x20000000;
207   /** PCM encoding with 32 bits per sample. */
208   public static final int ENCODING_PCM_32BIT = 0x30000000;
209   /** @see AudioFormat#ENCODING_PCM_FLOAT */
210   public static final int ENCODING_PCM_FLOAT = AudioFormat.ENCODING_PCM_FLOAT;
211   /** @see AudioFormat#ENCODING_MP3 */
212   public static final int ENCODING_MP3 = AudioFormat.ENCODING_MP3;
213   /** @see AudioFormat#ENCODING_AAC_LC */
214   public static final int ENCODING_AAC_LC = AudioFormat.ENCODING_AAC_LC;
215   /** @see AudioFormat#ENCODING_AAC_HE_V1 */
216   public static final int ENCODING_AAC_HE_V1 = AudioFormat.ENCODING_AAC_HE_V1;
217   /** @see AudioFormat#ENCODING_AAC_HE_V2 */
218   public static final int ENCODING_AAC_HE_V2 = AudioFormat.ENCODING_AAC_HE_V2;
219   /** @see AudioFormat#ENCODING_AAC_XHE */
220   public static final int ENCODING_AAC_XHE = AudioFormat.ENCODING_AAC_XHE;
221   /** @see AudioFormat#ENCODING_AAC_ELD */
222   public static final int ENCODING_AAC_ELD = AudioFormat.ENCODING_AAC_ELD;
223   /** @see AudioFormat#ENCODING_AC3 */
224   public static final int ENCODING_AC3 = AudioFormat.ENCODING_AC3;
225   /** @see AudioFormat#ENCODING_E_AC3 */
226   public static final int ENCODING_E_AC3 = AudioFormat.ENCODING_E_AC3;
227   /** @see AudioFormat#ENCODING_E_AC3_JOC */
228   public static final int ENCODING_E_AC3_JOC = AudioFormat.ENCODING_E_AC3_JOC;
229   /** @see AudioFormat#ENCODING_AC4 */
230   public static final int ENCODING_AC4 = AudioFormat.ENCODING_AC4;
231   /** @see AudioFormat#ENCODING_DTS */
232   public static final int ENCODING_DTS = AudioFormat.ENCODING_DTS;
233   /** @see AudioFormat#ENCODING_DTS_HD */
234   public static final int ENCODING_DTS_HD = AudioFormat.ENCODING_DTS_HD;
235   /** @see AudioFormat#ENCODING_DOLBY_TRUEHD */
236   public static final int ENCODING_DOLBY_TRUEHD = AudioFormat.ENCODING_DOLBY_TRUEHD;
237 
238   /**
239    * Stream types for an {@link android.media.AudioTrack}. One of {@link #STREAM_TYPE_ALARM}, {@link
240    * #STREAM_TYPE_DTMF}, {@link #STREAM_TYPE_MUSIC}, {@link #STREAM_TYPE_NOTIFICATION}, {@link
241    * #STREAM_TYPE_RING}, {@link #STREAM_TYPE_SYSTEM}, {@link #STREAM_TYPE_VOICE_CALL} or {@link
242    * #STREAM_TYPE_USE_DEFAULT}.
243    */
244   @Documented
245   @Retention(RetentionPolicy.SOURCE)
246   @IntDef({
247     STREAM_TYPE_ALARM,
248     STREAM_TYPE_DTMF,
249     STREAM_TYPE_MUSIC,
250     STREAM_TYPE_NOTIFICATION,
251     STREAM_TYPE_RING,
252     STREAM_TYPE_SYSTEM,
253     STREAM_TYPE_VOICE_CALL,
254     STREAM_TYPE_USE_DEFAULT
255   })
256   public @interface StreamType {}
257   /**
258    * @see AudioManager#STREAM_ALARM
259    */
260   public static final int STREAM_TYPE_ALARM = AudioManager.STREAM_ALARM;
261   /**
262    * @see AudioManager#STREAM_DTMF
263    */
264   public static final int STREAM_TYPE_DTMF = AudioManager.STREAM_DTMF;
265   /**
266    * @see AudioManager#STREAM_MUSIC
267    */
268   public static final int STREAM_TYPE_MUSIC = AudioManager.STREAM_MUSIC;
269   /**
270    * @see AudioManager#STREAM_NOTIFICATION
271    */
272   public static final int STREAM_TYPE_NOTIFICATION = AudioManager.STREAM_NOTIFICATION;
273   /**
274    * @see AudioManager#STREAM_RING
275    */
276   public static final int STREAM_TYPE_RING = AudioManager.STREAM_RING;
277   /**
278    * @see AudioManager#STREAM_SYSTEM
279    */
280   public static final int STREAM_TYPE_SYSTEM = AudioManager.STREAM_SYSTEM;
281   /**
282    * @see AudioManager#STREAM_VOICE_CALL
283    */
284   public static final int STREAM_TYPE_VOICE_CALL = AudioManager.STREAM_VOICE_CALL;
285   /**
286    * @see AudioManager#USE_DEFAULT_STREAM_TYPE
287    */
288   public static final int STREAM_TYPE_USE_DEFAULT = AudioManager.USE_DEFAULT_STREAM_TYPE;
289   /**
290    * The default stream type used by audio renderers.
291    */
292   public static final int STREAM_TYPE_DEFAULT = STREAM_TYPE_MUSIC;
293 
294   /**
295    * Content types for audio attributes. One of {@link #CONTENT_TYPE_MOVIE}, {@link
296    * #CONTENT_TYPE_MUSIC}, {@link #CONTENT_TYPE_SONIFICATION}, {@link #CONTENT_TYPE_SPEECH} or
297    * {@link #CONTENT_TYPE_UNKNOWN}.
298    */
299   @Documented
300   @Retention(RetentionPolicy.SOURCE)
301   @IntDef({
302     CONTENT_TYPE_MOVIE,
303     CONTENT_TYPE_MUSIC,
304     CONTENT_TYPE_SONIFICATION,
305     CONTENT_TYPE_SPEECH,
306     CONTENT_TYPE_UNKNOWN
307   })
308   public @interface AudioContentType {}
309   /**
310    * @see android.media.AudioAttributes#CONTENT_TYPE_MOVIE
311    */
312   public static final int CONTENT_TYPE_MOVIE = android.media.AudioAttributes.CONTENT_TYPE_MOVIE;
313   /**
314    * @see android.media.AudioAttributes#CONTENT_TYPE_MUSIC
315    */
316   public static final int CONTENT_TYPE_MUSIC = android.media.AudioAttributes.CONTENT_TYPE_MUSIC;
317   /**
318    * @see android.media.AudioAttributes#CONTENT_TYPE_SONIFICATION
319    */
320   public static final int CONTENT_TYPE_SONIFICATION =
321       android.media.AudioAttributes.CONTENT_TYPE_SONIFICATION;
322   /**
323    * @see android.media.AudioAttributes#CONTENT_TYPE_SPEECH
324    */
325   public static final int CONTENT_TYPE_SPEECH =
326       android.media.AudioAttributes.CONTENT_TYPE_SPEECH;
327   /**
328    * @see android.media.AudioAttributes#CONTENT_TYPE_UNKNOWN
329    */
330   public static final int CONTENT_TYPE_UNKNOWN =
331       android.media.AudioAttributes.CONTENT_TYPE_UNKNOWN;
332 
333   /**
334    * Flags for audio attributes. Possible flag value is {@link #FLAG_AUDIBILITY_ENFORCED}.
335    *
336    * <p>Note that {@code FLAG_HW_AV_SYNC} is not available because the player takes care of setting
337    * the flag when tunneling is enabled via a track selector.
338    */
339   @Documented
340   @Retention(RetentionPolicy.SOURCE)
341   @IntDef(
342       flag = true,
343       value = {FLAG_AUDIBILITY_ENFORCED})
344   public @interface AudioFlags {}
345   /**
346    * @see android.media.AudioAttributes#FLAG_AUDIBILITY_ENFORCED
347    */
348   public static final int FLAG_AUDIBILITY_ENFORCED =
349       android.media.AudioAttributes.FLAG_AUDIBILITY_ENFORCED;
350 
351   /**
352    * Usage types for audio attributes. One of {@link #USAGE_ALARM}, {@link
353    * #USAGE_ASSISTANCE_ACCESSIBILITY}, {@link #USAGE_ASSISTANCE_NAVIGATION_GUIDANCE}, {@link
354    * #USAGE_ASSISTANCE_SONIFICATION}, {@link #USAGE_ASSISTANT}, {@link #USAGE_GAME}, {@link
355    * #USAGE_MEDIA}, {@link #USAGE_NOTIFICATION}, {@link #USAGE_NOTIFICATION_COMMUNICATION_DELAYED},
356    * {@link #USAGE_NOTIFICATION_COMMUNICATION_INSTANT}, {@link
357    * #USAGE_NOTIFICATION_COMMUNICATION_REQUEST}, {@link #USAGE_NOTIFICATION_EVENT}, {@link
358    * #USAGE_NOTIFICATION_RINGTONE}, {@link #USAGE_UNKNOWN}, {@link #USAGE_VOICE_COMMUNICATION} or
359    * {@link #USAGE_VOICE_COMMUNICATION_SIGNALLING}.
360    */
361   @Documented
362   @Retention(RetentionPolicy.SOURCE)
363   @IntDef({
364     USAGE_ALARM,
365     USAGE_ASSISTANCE_ACCESSIBILITY,
366     USAGE_ASSISTANCE_NAVIGATION_GUIDANCE,
367     USAGE_ASSISTANCE_SONIFICATION,
368     USAGE_ASSISTANT,
369     USAGE_GAME,
370     USAGE_MEDIA,
371     USAGE_NOTIFICATION,
372     USAGE_NOTIFICATION_COMMUNICATION_DELAYED,
373     USAGE_NOTIFICATION_COMMUNICATION_INSTANT,
374     USAGE_NOTIFICATION_COMMUNICATION_REQUEST,
375     USAGE_NOTIFICATION_EVENT,
376     USAGE_NOTIFICATION_RINGTONE,
377     USAGE_UNKNOWN,
378     USAGE_VOICE_COMMUNICATION,
379     USAGE_VOICE_COMMUNICATION_SIGNALLING
380   })
381   public @interface AudioUsage {}
382   /**
383    * @see android.media.AudioAttributes#USAGE_ALARM
384    */
385   public static final int USAGE_ALARM = android.media.AudioAttributes.USAGE_ALARM;
386   /** @see android.media.AudioAttributes#USAGE_ASSISTANCE_ACCESSIBILITY */
387   public static final int USAGE_ASSISTANCE_ACCESSIBILITY =
388       android.media.AudioAttributes.USAGE_ASSISTANCE_ACCESSIBILITY;
389   /**
390    * @see android.media.AudioAttributes#USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
391    */
392   public static final int USAGE_ASSISTANCE_NAVIGATION_GUIDANCE =
393       android.media.AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE;
394   /**
395    * @see android.media.AudioAttributes#USAGE_ASSISTANCE_SONIFICATION
396    */
397   public static final int USAGE_ASSISTANCE_SONIFICATION =
398       android.media.AudioAttributes.USAGE_ASSISTANCE_SONIFICATION;
399   /** @see android.media.AudioAttributes#USAGE_ASSISTANT */
400   public static final int USAGE_ASSISTANT = android.media.AudioAttributes.USAGE_ASSISTANT;
401   /**
402    * @see android.media.AudioAttributes#USAGE_GAME
403    */
404   public static final int USAGE_GAME = android.media.AudioAttributes.USAGE_GAME;
405   /**
406    * @see android.media.AudioAttributes#USAGE_MEDIA
407    */
408   public static final int USAGE_MEDIA = android.media.AudioAttributes.USAGE_MEDIA;
409   /**
410    * @see android.media.AudioAttributes#USAGE_NOTIFICATION
411    */
412   public static final int USAGE_NOTIFICATION = android.media.AudioAttributes.USAGE_NOTIFICATION;
413   /**
414    * @see android.media.AudioAttributes#USAGE_NOTIFICATION_COMMUNICATION_DELAYED
415    */
416   public static final int USAGE_NOTIFICATION_COMMUNICATION_DELAYED =
417       android.media.AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_DELAYED;
418   /**
419    * @see android.media.AudioAttributes#USAGE_NOTIFICATION_COMMUNICATION_INSTANT
420    */
421   public static final int USAGE_NOTIFICATION_COMMUNICATION_INSTANT =
422       android.media.AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT;
423   /**
424    * @see android.media.AudioAttributes#USAGE_NOTIFICATION_COMMUNICATION_REQUEST
425    */
426   public static final int USAGE_NOTIFICATION_COMMUNICATION_REQUEST =
427       android.media.AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_REQUEST;
428   /**
429    * @see android.media.AudioAttributes#USAGE_NOTIFICATION_EVENT
430    */
431   public static final int USAGE_NOTIFICATION_EVENT =
432       android.media.AudioAttributes.USAGE_NOTIFICATION_EVENT;
433   /**
434    * @see android.media.AudioAttributes#USAGE_NOTIFICATION_RINGTONE
435    */
436   public static final int USAGE_NOTIFICATION_RINGTONE =
437       android.media.AudioAttributes.USAGE_NOTIFICATION_RINGTONE;
438   /**
439    * @see android.media.AudioAttributes#USAGE_UNKNOWN
440    */
441   public static final int USAGE_UNKNOWN = android.media.AudioAttributes.USAGE_UNKNOWN;
442   /**
443    * @see android.media.AudioAttributes#USAGE_VOICE_COMMUNICATION
444    */
445   public static final int USAGE_VOICE_COMMUNICATION =
446       android.media.AudioAttributes.USAGE_VOICE_COMMUNICATION;
447   /**
448    * @see android.media.AudioAttributes#USAGE_VOICE_COMMUNICATION_SIGNALLING
449    */
450   public static final int USAGE_VOICE_COMMUNICATION_SIGNALLING =
451       android.media.AudioAttributes.USAGE_VOICE_COMMUNICATION_SIGNALLING;
452 
453   /**
454    * Capture policies for audio attributes. One of {@link #ALLOW_CAPTURE_BY_ALL}, {@link
455    * #ALLOW_CAPTURE_BY_NONE} or {@link #ALLOW_CAPTURE_BY_SYSTEM}.
456    */
457   @Documented
458   @Retention(RetentionPolicy.SOURCE)
459   @IntDef({ALLOW_CAPTURE_BY_ALL, ALLOW_CAPTURE_BY_NONE, ALLOW_CAPTURE_BY_SYSTEM})
460   public @interface AudioAllowedCapturePolicy {}
461   /** See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_ALL}. */
462   public static final int ALLOW_CAPTURE_BY_ALL = AudioAttributes.ALLOW_CAPTURE_BY_ALL;
463   /** See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_NONE}. */
464   public static final int ALLOW_CAPTURE_BY_NONE = AudioAttributes.ALLOW_CAPTURE_BY_NONE;
465   /** See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_SYSTEM}. */
466   public static final int ALLOW_CAPTURE_BY_SYSTEM = AudioAttributes.ALLOW_CAPTURE_BY_SYSTEM;
467 
468   /**
469    * Audio focus types. One of {@link #AUDIOFOCUS_NONE}, {@link #AUDIOFOCUS_GAIN}, {@link
470    * #AUDIOFOCUS_GAIN_TRANSIENT}, {@link #AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK} or {@link
471    * #AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE}.
472    */
473   @Documented
474   @Retention(RetentionPolicy.SOURCE)
475   @IntDef({
476     AUDIOFOCUS_NONE,
477     AUDIOFOCUS_GAIN,
478     AUDIOFOCUS_GAIN_TRANSIENT,
479     AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK,
480     AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
481   })
482   public @interface AudioFocusGain {}
483   /** @see AudioManager#AUDIOFOCUS_NONE */
484   public static final int AUDIOFOCUS_NONE = AudioManager.AUDIOFOCUS_NONE;
485   /** @see AudioManager#AUDIOFOCUS_GAIN */
486   public static final int AUDIOFOCUS_GAIN = AudioManager.AUDIOFOCUS_GAIN;
487   /** @see AudioManager#AUDIOFOCUS_GAIN_TRANSIENT */
488   public static final int AUDIOFOCUS_GAIN_TRANSIENT = AudioManager.AUDIOFOCUS_GAIN_TRANSIENT;
489   /** @see AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK */
490   public static final int AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK =
491       AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK;
492   /** @see AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE */
493   public static final int AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE =
494       AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE;
495 
496   /**
497    * Flags which can apply to a buffer containing a media sample. Possible flag values are {@link
498    * #BUFFER_FLAG_KEY_FRAME}, {@link #BUFFER_FLAG_END_OF_STREAM}, {@link #BUFFER_FLAG_LAST_SAMPLE},
499    * {@link #BUFFER_FLAG_ENCRYPTED} and {@link #BUFFER_FLAG_DECODE_ONLY}.
500    */
501   @Documented
502   @Retention(RetentionPolicy.SOURCE)
503   @IntDef(
504       flag = true,
505       value = {
506         BUFFER_FLAG_KEY_FRAME,
507         BUFFER_FLAG_END_OF_STREAM,
508         BUFFER_FLAG_HAS_SUPPLEMENTAL_DATA,
509         BUFFER_FLAG_LAST_SAMPLE,
510         BUFFER_FLAG_ENCRYPTED,
511         BUFFER_FLAG_DECODE_ONLY
512       })
513   public @interface BufferFlags {}
514   /**
515    * Indicates that a buffer holds a synchronization sample.
516    */
517   public static final int BUFFER_FLAG_KEY_FRAME = MediaCodec.BUFFER_FLAG_KEY_FRAME;
518   /**
519    * Flag for empty buffers that signal that the end of the stream was reached.
520    */
521   public static final int BUFFER_FLAG_END_OF_STREAM = MediaCodec.BUFFER_FLAG_END_OF_STREAM;
522   /** Indicates that a buffer has supplemental data. */
523   public static final int BUFFER_FLAG_HAS_SUPPLEMENTAL_DATA = 1 << 28; // 0x10000000
524   /** Indicates that a buffer is known to contain the last media sample of the stream. */
525   public static final int BUFFER_FLAG_LAST_SAMPLE = 1 << 29; // 0x20000000
526   /** Indicates that a buffer is (at least partially) encrypted. */
527   public static final int BUFFER_FLAG_ENCRYPTED = 1 << 30; // 0x40000000
528   /** Indicates that a buffer should be decoded but not rendered. */
529   public static final int BUFFER_FLAG_DECODE_ONLY = 1 << 31; // 0x80000000
530 
531   // LINT.IfChange
532   /**
533    * Video decoder output modes. Possible modes are {@link #VIDEO_OUTPUT_MODE_NONE}, {@link
534    * #VIDEO_OUTPUT_MODE_YUV} and {@link #VIDEO_OUTPUT_MODE_SURFACE_YUV}.
535    */
536   @Documented
537   @Retention(RetentionPolicy.SOURCE)
538   @IntDef(value = {VIDEO_OUTPUT_MODE_NONE, VIDEO_OUTPUT_MODE_YUV, VIDEO_OUTPUT_MODE_SURFACE_YUV})
539   public @interface VideoOutputMode {}
540   /** Video decoder output mode is not set. */
541   public static final int VIDEO_OUTPUT_MODE_NONE = -1;
542   /** Video decoder output mode that outputs raw 4:2:0 YUV planes. */
543   public static final int VIDEO_OUTPUT_MODE_YUV = 0;
544   /** Video decoder output mode that renders 4:2:0 YUV planes directly to a surface. */
545   public static final int VIDEO_OUTPUT_MODE_SURFACE_YUV = 1;
546   // LINT.ThenChange(
547   //     ../../../../../../../../../extensions/av1/src/main/jni/gav1_jni.cc,
548   //     ../../../../../../../../../extensions/vp9/src/main/jni/vpx_jni.cc
549   // )
550 
551   /** @deprecated Use {@code Renderer.VideoScalingMode}. */
552   @Documented
553   @Retention(RetentionPolicy.SOURCE)
554   @IntDef(value = {VIDEO_SCALING_MODE_SCALE_TO_FIT, VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING})
555   @Deprecated
556   public @interface VideoScalingMode {}
557   /** @deprecated Use {@code Renderer.VIDEO_SCALING_MODE_SCALE_TO_FIT}. */
558   @Deprecated
559   public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT =
560       MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT;
561   /** @deprecated Use {@code Renderer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING}. */
562   @Deprecated
563   public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING =
564       MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING;
565   /** @deprecated Use {@code Renderer.VIDEO_SCALING_MODE_DEFAULT}. */
566   @Deprecated public static final int VIDEO_SCALING_MODE_DEFAULT = VIDEO_SCALING_MODE_SCALE_TO_FIT;
567 
568   /**
569    * Track selection flags. Possible flag values are {@link #SELECTION_FLAG_DEFAULT}, {@link
570    * #SELECTION_FLAG_FORCED} and {@link #SELECTION_FLAG_AUTOSELECT}.
571    */
572   @Documented
573   @Retention(RetentionPolicy.SOURCE)
574   @IntDef(
575       flag = true,
576       value = {SELECTION_FLAG_DEFAULT, SELECTION_FLAG_FORCED, SELECTION_FLAG_AUTOSELECT})
577   public @interface SelectionFlags {}
578   /**
579    * Indicates that the track should be selected if user preferences do not state otherwise.
580    */
581   public static final int SELECTION_FLAG_DEFAULT = 1;
582   /** Indicates that the track must be displayed. Only applies to text tracks. */
583   public static final int SELECTION_FLAG_FORCED = 1 << 1; // 2
584   /**
585    * Indicates that the player may choose to play the track in absence of an explicit user
586    * preference.
587    */
588   public static final int SELECTION_FLAG_AUTOSELECT = 1 << 2; // 4
589 
590   /** Represents an undetermined language as an ISO 639-2 language code. */
591   public static final String LANGUAGE_UNDETERMINED = "und";
592 
593   /**
594    * Represents a streaming or other media type. One of {@link #TYPE_DASH}, {@link #TYPE_SS}, {@link
595    * #TYPE_HLS} or {@link #TYPE_OTHER}.
596    */
597   @Documented
598   @Retention(RetentionPolicy.SOURCE)
599   @IntDef({TYPE_DASH, TYPE_SS, TYPE_HLS, TYPE_OTHER})
600   public @interface ContentType {}
601   /**
602    * Value returned by {@link Util#inferContentType(String)} for DASH manifests.
603    */
604   public static final int TYPE_DASH = 0;
605   /**
606    * Value returned by {@link Util#inferContentType(String)} for Smooth Streaming manifests.
607    */
608   public static final int TYPE_SS = 1;
609   /**
610    * Value returned by {@link Util#inferContentType(String)} for HLS manifests.
611    */
612   public static final int TYPE_HLS = 2;
613   /**
614    * Value returned by {@link Util#inferContentType(String)} for files other than DASH, HLS or
615    * Smooth Streaming manifests.
616    */
617   public static final int TYPE_OTHER = 3;
618 
619   /**
620    * A return value for methods where the end of an input was encountered.
621    */
622   public static final int RESULT_END_OF_INPUT = -1;
623   /**
624    * A return value for methods where the length of parsed data exceeds the maximum length allowed.
625    */
626   public static final int RESULT_MAX_LENGTH_EXCEEDED = -2;
627   /**
628    * A return value for methods where nothing was read.
629    */
630   public static final int RESULT_NOTHING_READ = -3;
631   /**
632    * A return value for methods where a buffer was read.
633    */
634   public static final int RESULT_BUFFER_READ = -4;
635   /**
636    * A return value for methods where a format was read.
637    */
638   public static final int RESULT_FORMAT_READ = -5;
639 
640   /** A data type constant for data of unknown or unspecified type. */
641   public static final int DATA_TYPE_UNKNOWN = 0;
642   /** A data type constant for media, typically containing media samples. */
643   public static final int DATA_TYPE_MEDIA = 1;
644   /** A data type constant for media, typically containing only initialization data. */
645   public static final int DATA_TYPE_MEDIA_INITIALIZATION = 2;
646   /** A data type constant for drm or encryption data. */
647   public static final int DATA_TYPE_DRM = 3;
648   /** A data type constant for a manifest file. */
649   public static final int DATA_TYPE_MANIFEST = 4;
650   /** A data type constant for time synchronization data. */
651   public static final int DATA_TYPE_TIME_SYNCHRONIZATION = 5;
652   /** A data type constant for ads loader data. */
653   public static final int DATA_TYPE_AD = 6;
654   /**
655    * A data type constant for live progressive media streams, typically containing media samples.
656    */
657   public static final int DATA_TYPE_MEDIA_PROGRESSIVE_LIVE = 7;
658   /**
659    * Applications or extensions may define custom {@code DATA_TYPE_*} constants greater than or
660    * equal to this value.
661    */
662   public static final int DATA_TYPE_CUSTOM_BASE = 10000;
663 
664   /** A type constant for tracks of unknown type. */
665   public static final int TRACK_TYPE_UNKNOWN = -1;
666   /** A type constant for tracks of some default type, where the type itself is unknown. */
667   public static final int TRACK_TYPE_DEFAULT = 0;
668   /** A type constant for audio tracks. */
669   public static final int TRACK_TYPE_AUDIO = 1;
670   /** A type constant for video tracks. */
671   public static final int TRACK_TYPE_VIDEO = 2;
672   /** A type constant for text tracks. */
673   public static final int TRACK_TYPE_TEXT = 3;
674   /** A type constant for metadata tracks. */
675   public static final int TRACK_TYPE_METADATA = 4;
676   /** A type constant for camera motion tracks. */
677   public static final int TRACK_TYPE_CAMERA_MOTION = 5;
678   /** A type constant for a dummy or empty track. */
679   public static final int TRACK_TYPE_NONE = 6;
680   /**
681    * Applications or extensions may define custom {@code TRACK_TYPE_*} constants greater than or
682    * equal to this value.
683    */
684   public static final int TRACK_TYPE_CUSTOM_BASE = 10000;
685 
686   /**
687    * A selection reason constant for selections whose reasons are unknown or unspecified.
688    */
689   public static final int SELECTION_REASON_UNKNOWN = 0;
690   /**
691    * A selection reason constant for an initial track selection.
692    */
693   public static final int SELECTION_REASON_INITIAL = 1;
694   /**
695    * A selection reason constant for an manual (i.e. user initiated) track selection.
696    */
697   public static final int SELECTION_REASON_MANUAL = 2;
698   /**
699    * A selection reason constant for an adaptive track selection.
700    */
701   public static final int SELECTION_REASON_ADAPTIVE = 3;
702   /**
703    * A selection reason constant for a trick play track selection.
704    */
705   public static final int SELECTION_REASON_TRICK_PLAY = 4;
706   /**
707    * Applications or extensions may define custom {@code SELECTION_REASON_*} constants greater than
708    * or equal to this value.
709    */
710   public static final int SELECTION_REASON_CUSTOM_BASE = 10000;
711 
712   /** A default size in bytes for an individual allocation that forms part of a larger buffer. */
713   public static final int DEFAULT_BUFFER_SEGMENT_SIZE = 64 * 1024;
714 
715   /** "cenc" scheme type name as defined in ISO/IEC 23001-7:2016. */
716   @SuppressWarnings("ConstantField")
717   public static final String CENC_TYPE_cenc = "cenc";
718 
719   /** "cbc1" scheme type name as defined in ISO/IEC 23001-7:2016. */
720   @SuppressWarnings("ConstantField")
721   public static final String CENC_TYPE_cbc1 = "cbc1";
722 
723   /** "cens" scheme type name as defined in ISO/IEC 23001-7:2016. */
724   @SuppressWarnings("ConstantField")
725   public static final String CENC_TYPE_cens = "cens";
726 
727   /** "cbcs" scheme type name as defined in ISO/IEC 23001-7:2016. */
728   @SuppressWarnings("ConstantField")
729   public static final String CENC_TYPE_cbcs = "cbcs";
730 
731   /**
732    * The Nil UUID as defined by
733    * <a href="https://tools.ietf.org/html/rfc4122#section-4.1.7">RFC4122</a>.
734    */
735   public static final UUID UUID_NIL = new UUID(0L, 0L);
736 
737   /**
738    * UUID for the W3C
739    * <a href="https://w3c.github.io/encrypted-media/format-registry/initdata/cenc.html">Common PSSH
740    * box</a>.
741    */
742   public static final UUID COMMON_PSSH_UUID = new UUID(0x1077EFECC0B24D02L, 0xACE33C1E52E2FB4BL);
743 
744   /**
745    * UUID for the ClearKey DRM scheme.
746    * <p>
747    * ClearKey is supported on Android devices running Android 5.0 (API Level 21) and up.
748    */
749   public static final UUID CLEARKEY_UUID = new UUID(0xE2719D58A985B3C9L, 0x781AB030AF78D30EL);
750 
751   /**
752    * UUID for the Widevine DRM scheme.
753    * <p>
754    * Widevine is supported on Android devices running Android 4.3 (API Level 18) and up.
755    */
756   public static final UUID WIDEVINE_UUID = new UUID(0xEDEF8BA979D64ACEL, 0xA3C827DCD51D21EDL);
757 
758   /**
759    * UUID for the PlayReady DRM scheme.
760    * <p>
761    * PlayReady is supported on all AndroidTV devices. Note that most other Android devices do not
762    * provide PlayReady support.
763    */
764   public static final UUID PLAYREADY_UUID = new UUID(0x9A04F07998404286L, 0xAB92E65BE0885F95L);
765 
766   /** @deprecated Use {@code Renderer.MSG_SET_SURFACE}. */
767   @Deprecated public static final int MSG_SET_SURFACE = 1;
768 
769   /** @deprecated Use {@code Renderer.MSG_SET_VOLUME}. */
770   @Deprecated public static final int MSG_SET_VOLUME = 2;
771 
772   /** @deprecated Use {@code Renderer.MSG_SET_AUDIO_ATTRIBUTES}. */
773   @Deprecated public static final int MSG_SET_AUDIO_ATTRIBUTES = 3;
774 
775   /** @deprecated Use {@code Renderer.MSG_SET_SCALING_MODE}. */
776   @Deprecated public static final int MSG_SET_SCALING_MODE = 4;
777 
778   /** @deprecated Use {@code Renderer.MSG_SET_AUX_EFFECT_INFO}. */
779   @Deprecated public static final int MSG_SET_AUX_EFFECT_INFO = 5;
780 
781   /** @deprecated Use {@code Renderer.MSG_SET_VIDEO_FRAME_METADATA_LISTENER}. */
782   @Deprecated public static final int MSG_SET_VIDEO_FRAME_METADATA_LISTENER = 6;
783 
784   /** @deprecated Use {@code Renderer.MSG_SET_CAMERA_MOTION_LISTENER}. */
785   @Deprecated public static final int MSG_SET_CAMERA_MOTION_LISTENER = 7;
786 
787   /** @deprecated Use {@code Renderer.MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER}. */
788   @Deprecated public static final int MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER = 8;
789 
790   /** @deprecated Use {@code Renderer.MSG_CUSTOM_BASE}. */
791   @Deprecated public static final int MSG_CUSTOM_BASE = 10000;
792 
793   /**
794    * The stereo mode for 360/3D/VR videos. One of {@link Format#NO_VALUE}, {@link
795    * #STEREO_MODE_MONO}, {@link #STEREO_MODE_TOP_BOTTOM}, {@link #STEREO_MODE_LEFT_RIGHT} or {@link
796    * #STEREO_MODE_STEREO_MESH}.
797    */
798   @Documented
799   @Retention(RetentionPolicy.SOURCE)
800   @IntDef({
801     Format.NO_VALUE,
802     STEREO_MODE_MONO,
803     STEREO_MODE_TOP_BOTTOM,
804     STEREO_MODE_LEFT_RIGHT,
805     STEREO_MODE_STEREO_MESH
806   })
807   public @interface StereoMode {}
808   /**
809    * Indicates Monoscopic stereo layout, used with 360/3D/VR videos.
810    */
811   public static final int STEREO_MODE_MONO = 0;
812   /**
813    * Indicates Top-Bottom stereo layout, used with 360/3D/VR videos.
814    */
815   public static final int STEREO_MODE_TOP_BOTTOM = 1;
816   /**
817    * Indicates Left-Right stereo layout, used with 360/3D/VR videos.
818    */
819   public static final int STEREO_MODE_LEFT_RIGHT = 2;
820   /**
821    * Indicates a stereo layout where the left and right eyes have separate meshes,
822    * used with 360/3D/VR videos.
823    */
824   public static final int STEREO_MODE_STEREO_MESH = 3;
825 
826   /**
827    * Video colorspaces. One of {@link Format#NO_VALUE}, {@link #COLOR_SPACE_BT709}, {@link
828    * #COLOR_SPACE_BT601} or {@link #COLOR_SPACE_BT2020}.
829    */
830   @Documented
831   @Retention(RetentionPolicy.SOURCE)
832   @IntDef({Format.NO_VALUE, COLOR_SPACE_BT709, COLOR_SPACE_BT601, COLOR_SPACE_BT2020})
833   public @interface ColorSpace {}
834   /**
835    * @see MediaFormat#COLOR_STANDARD_BT709
836    */
837   public static final int COLOR_SPACE_BT709 = MediaFormat.COLOR_STANDARD_BT709;
838   /**
839    * @see MediaFormat#COLOR_STANDARD_BT601_PAL
840    */
841   public static final int COLOR_SPACE_BT601 = MediaFormat.COLOR_STANDARD_BT601_PAL;
842   /**
843    * @see MediaFormat#COLOR_STANDARD_BT2020
844    */
845   public static final int COLOR_SPACE_BT2020 = MediaFormat.COLOR_STANDARD_BT2020;
846 
847   /**
848    * Video color transfer characteristics. One of {@link Format#NO_VALUE}, {@link
849    * #COLOR_TRANSFER_SDR}, {@link #COLOR_TRANSFER_ST2084} or {@link #COLOR_TRANSFER_HLG}.
850    */
851   @Documented
852   @Retention(RetentionPolicy.SOURCE)
853   @IntDef({Format.NO_VALUE, COLOR_TRANSFER_SDR, COLOR_TRANSFER_ST2084, COLOR_TRANSFER_HLG})
854   public @interface ColorTransfer {}
855   /**
856    * @see MediaFormat#COLOR_TRANSFER_SDR_VIDEO
857    */
858   public static final int COLOR_TRANSFER_SDR = MediaFormat.COLOR_TRANSFER_SDR_VIDEO;
859   /**
860    * @see MediaFormat#COLOR_TRANSFER_ST2084
861    */
862   public static final int COLOR_TRANSFER_ST2084 = MediaFormat.COLOR_TRANSFER_ST2084;
863   /**
864    * @see MediaFormat#COLOR_TRANSFER_HLG
865    */
866   public static final int COLOR_TRANSFER_HLG = MediaFormat.COLOR_TRANSFER_HLG;
867 
868   /**
869    * Video color range. One of {@link Format#NO_VALUE}, {@link #COLOR_RANGE_LIMITED} or {@link
870    * #COLOR_RANGE_FULL}.
871    */
872   @Documented
873   @Retention(RetentionPolicy.SOURCE)
874   @IntDef({Format.NO_VALUE, COLOR_RANGE_LIMITED, COLOR_RANGE_FULL})
875   public @interface ColorRange {}
876   /**
877    * @see MediaFormat#COLOR_RANGE_LIMITED
878    */
879   public static final int COLOR_RANGE_LIMITED = MediaFormat.COLOR_RANGE_LIMITED;
880   /**
881    * @see MediaFormat#COLOR_RANGE_FULL
882    */
883   public static final int COLOR_RANGE_FULL = MediaFormat.COLOR_RANGE_FULL;
884 
885   /** Video projection types. */
886   @Documented
887   @Retention(RetentionPolicy.SOURCE)
888   @IntDef({
889     Format.NO_VALUE,
890     PROJECTION_RECTANGULAR,
891     PROJECTION_EQUIRECTANGULAR,
892     PROJECTION_CUBEMAP,
893     PROJECTION_MESH
894   })
895   public @interface Projection {}
896   /** Conventional rectangular projection. */
897   public static final int PROJECTION_RECTANGULAR = 0;
898   /** Equirectangular spherical projection. */
899   public static final int PROJECTION_EQUIRECTANGULAR = 1;
900   /** Cube map projection. */
901   public static final int PROJECTION_CUBEMAP = 2;
902   /** 3-D mesh projection. */
903   public static final int PROJECTION_MESH = 3;
904 
905   /**
906    * Priority for media playback.
907    *
908    * <p>Larger values indicate higher priorities.
909    */
910   public static final int PRIORITY_PLAYBACK = 0;
911 
912   /**
913    * Priority for media downloading.
914    *
915    * <p>Larger values indicate higher priorities.
916    */
917   public static final int PRIORITY_DOWNLOAD = PRIORITY_PLAYBACK - 1000;
918 
919   /**
920    * Network connection type. One of {@link #NETWORK_TYPE_UNKNOWN}, {@link #NETWORK_TYPE_OFFLINE},
921    * {@link #NETWORK_TYPE_WIFI}, {@link #NETWORK_TYPE_2G}, {@link #NETWORK_TYPE_3G}, {@link
922    * #NETWORK_TYPE_4G}, {@link #NETWORK_TYPE_5G}, {@link #NETWORK_TYPE_CELLULAR_UNKNOWN}, {@link
923    * #NETWORK_TYPE_ETHERNET} or {@link #NETWORK_TYPE_OTHER}.
924    */
925   @Documented
926   @Retention(RetentionPolicy.SOURCE)
927   @IntDef({
928     NETWORK_TYPE_UNKNOWN,
929     NETWORK_TYPE_OFFLINE,
930     NETWORK_TYPE_WIFI,
931     NETWORK_TYPE_2G,
932     NETWORK_TYPE_3G,
933     NETWORK_TYPE_4G,
934     NETWORK_TYPE_5G,
935     NETWORK_TYPE_CELLULAR_UNKNOWN,
936     NETWORK_TYPE_ETHERNET,
937     NETWORK_TYPE_OTHER
938   })
939   public @interface NetworkType {}
940   /** Unknown network type. */
941   public static final int NETWORK_TYPE_UNKNOWN = 0;
942   /** No network connection. */
943   public static final int NETWORK_TYPE_OFFLINE = 1;
944   /** Network type for a Wifi connection. */
945   public static final int NETWORK_TYPE_WIFI = 2;
946   /** Network type for a 2G cellular connection. */
947   public static final int NETWORK_TYPE_2G = 3;
948   /** Network type for a 3G cellular connection. */
949   public static final int NETWORK_TYPE_3G = 4;
950   /** Network type for a 4G cellular connection. */
951   public static final int NETWORK_TYPE_4G = 5;
952   /** Network type for a 5G cellular connection. */
953   public static final int NETWORK_TYPE_5G = 9;
954   /**
955    * Network type for cellular connections which cannot be mapped to one of {@link
956    * #NETWORK_TYPE_2G}, {@link #NETWORK_TYPE_3G}, or {@link #NETWORK_TYPE_4G}.
957    */
958   public static final int NETWORK_TYPE_CELLULAR_UNKNOWN = 6;
959   /** Network type for an Ethernet connection. */
960   public static final int NETWORK_TYPE_ETHERNET = 7;
961   /** Network type for other connections which are not Wifi or cellular (e.g. VPN, Bluetooth). */
962   public static final int NETWORK_TYPE_OTHER = 8;
963 
964   /**
965    * Mode specifying whether the player should hold a WakeLock and a WifiLock. One of {@link
966    * #WAKE_MODE_NONE}, {@link #WAKE_MODE_LOCAL} and {@link #WAKE_MODE_NETWORK}.
967    */
968   @Documented
969   @Retention(RetentionPolicy.SOURCE)
970   @IntDef({WAKE_MODE_NONE, WAKE_MODE_LOCAL, WAKE_MODE_NETWORK})
971   public @interface WakeMode {}
972   /**
973    * A wake mode that will not cause the player to hold any locks.
974    *
975    * <p>This is suitable for applications that do not play media with the screen off.
976    */
977   public static final int WAKE_MODE_NONE = 0;
978   /**
979    * A wake mode that will cause the player to hold a {@link android.os.PowerManager.WakeLock}
980    * during playback.
981    *
982    * <p>This is suitable for applications that play media with the screen off and do not load media
983    * over wifi.
984    */
985   public static final int WAKE_MODE_LOCAL = 1;
986   /**
987    * A wake mode that will cause the player to hold a {@link android.os.PowerManager.WakeLock} and a
988    * {@link android.net.wifi.WifiManager.WifiLock} during playback.
989    *
990    * <p>This is suitable for applications that play media with the screen off and may load media
991    * over wifi.
992    */
993   public static final int WAKE_MODE_NETWORK = 2;
994 
995   /**
996    * Track role flags. Possible flag values are {@link #ROLE_FLAG_MAIN}, {@link
997    * #ROLE_FLAG_ALTERNATE}, {@link #ROLE_FLAG_SUPPLEMENTARY}, {@link #ROLE_FLAG_COMMENTARY}, {@link
998    * #ROLE_FLAG_DUB}, {@link #ROLE_FLAG_EMERGENCY}, {@link #ROLE_FLAG_CAPTION}, {@link
999    * #ROLE_FLAG_SUBTITLE}, {@link #ROLE_FLAG_SIGN}, {@link #ROLE_FLAG_DESCRIBES_VIDEO}, {@link
1000    * #ROLE_FLAG_DESCRIBES_MUSIC_AND_SOUND}, {@link #ROLE_FLAG_ENHANCED_DIALOG_INTELLIGIBILITY},
1001    * {@link #ROLE_FLAG_TRANSCRIBES_DIALOG}, {@link #ROLE_FLAG_EASY_TO_READ} and {@link
1002    * #ROLE_FLAG_TRICK_PLAY}.
1003    */
1004   @Documented
1005   @Retention(RetentionPolicy.SOURCE)
1006   @IntDef(
1007       flag = true,
1008       value = {
1009         ROLE_FLAG_MAIN,
1010         ROLE_FLAG_ALTERNATE,
1011         ROLE_FLAG_SUPPLEMENTARY,
1012         ROLE_FLAG_COMMENTARY,
1013         ROLE_FLAG_DUB,
1014         ROLE_FLAG_EMERGENCY,
1015         ROLE_FLAG_CAPTION,
1016         ROLE_FLAG_SUBTITLE,
1017         ROLE_FLAG_SIGN,
1018         ROLE_FLAG_DESCRIBES_VIDEO,
1019         ROLE_FLAG_DESCRIBES_MUSIC_AND_SOUND,
1020         ROLE_FLAG_ENHANCED_DIALOG_INTELLIGIBILITY,
1021         ROLE_FLAG_TRANSCRIBES_DIALOG,
1022         ROLE_FLAG_EASY_TO_READ,
1023         ROLE_FLAG_TRICK_PLAY
1024       })
1025   public @interface RoleFlags {}
1026   /** Indicates a main track. */
1027   public static final int ROLE_FLAG_MAIN = 1;
1028   /**
1029    * Indicates an alternate track. For example a video track recorded from an different view point
1030    * than the main track(s).
1031    */
1032   public static final int ROLE_FLAG_ALTERNATE = 1 << 1;
1033   /**
1034    * Indicates a supplementary track, meaning the track has lower importance than the main track(s).
1035    * For example a video track that provides a visual accompaniment to a main audio track.
1036    */
1037   public static final int ROLE_FLAG_SUPPLEMENTARY = 1 << 2;
1038   /** Indicates the track contains commentary, for example from the director. */
1039   public static final int ROLE_FLAG_COMMENTARY = 1 << 3;
1040   /**
1041    * Indicates the track is in a different language from the original, for example dubbed audio or
1042    * translated captions.
1043    */
1044   public static final int ROLE_FLAG_DUB = 1 << 4;
1045   /** Indicates the track contains information about a current emergency. */
1046   public static final int ROLE_FLAG_EMERGENCY = 1 << 5;
1047   /**
1048    * Indicates the track contains captions. This flag may be set on video tracks to indicate the
1049    * presence of burned in captions.
1050    */
1051   public static final int ROLE_FLAG_CAPTION = 1 << 6;
1052   /**
1053    * Indicates the track contains subtitles. This flag may be set on video tracks to indicate the
1054    * presence of burned in subtitles.
1055    */
1056   public static final int ROLE_FLAG_SUBTITLE = 1 << 7;
1057   /** Indicates the track contains a visual sign-language interpretation of an audio track. */
1058   public static final int ROLE_FLAG_SIGN = 1 << 8;
1059   /** Indicates the track contains an audio or textual description of a video track. */
1060   public static final int ROLE_FLAG_DESCRIBES_VIDEO = 1 << 9;
1061   /** Indicates the track contains a textual description of music and sound. */
1062   public static final int ROLE_FLAG_DESCRIBES_MUSIC_AND_SOUND = 1 << 10;
1063   /** Indicates the track is designed for improved intelligibility of dialogue. */
1064   public static final int ROLE_FLAG_ENHANCED_DIALOG_INTELLIGIBILITY = 1 << 11;
1065   /** Indicates the track contains a transcription of spoken dialog. */
1066   public static final int ROLE_FLAG_TRANSCRIBES_DIALOG = 1 << 12;
1067   /** Indicates the track contains a text that has been edited for ease of reading. */
1068   public static final int ROLE_FLAG_EASY_TO_READ = 1 << 13;
1069   /** Indicates the track is intended for trick play. */
1070   public static final int ROLE_FLAG_TRICK_PLAY = 1 << 14;
1071 
1072   /**
1073    * Converts a time in microseconds to the corresponding time in milliseconds, preserving
1074    * {@link #TIME_UNSET} and {@link #TIME_END_OF_SOURCE} values.
1075    *
1076    * @param timeUs The time in microseconds.
1077    * @return The corresponding time in milliseconds.
1078    */
usToMs(long timeUs)1079   public static long usToMs(long timeUs) {
1080     return (timeUs == TIME_UNSET || timeUs == TIME_END_OF_SOURCE) ? timeUs : (timeUs / 1000);
1081   }
1082 
1083   /**
1084    * Converts a time in milliseconds to the corresponding time in microseconds, preserving
1085    * {@link #TIME_UNSET} values and {@link #TIME_END_OF_SOURCE} values.
1086    *
1087    * @param timeMs The time in milliseconds.
1088    * @return The corresponding time in microseconds.
1089    */
msToUs(long timeMs)1090   public static long msToUs(long timeMs) {
1091     return (timeMs == TIME_UNSET || timeMs == TIME_END_OF_SOURCE) ? timeMs : (timeMs * 1000);
1092   }
1093 
1094   /**
1095    * Returns a newly generated audio session identifier, or {@link AudioManager#ERROR} if an error
1096    * occurred in which case audio playback may fail.
1097    *
1098    * @see AudioManager#generateAudioSessionId()
1099    */
1100   @RequiresApi(21)
generateAudioSessionIdV21(Context context)1101   public static int generateAudioSessionIdV21(Context context) {
1102     return ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE))
1103         .generateAudioSessionId();
1104   }
1105 
1106 }
1107