1 /* 2 * Copyright (C) 2012 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 17 package android.media; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.compat.annotation.UnsupportedAppUsage; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 import java.nio.ByteBuffer; 27 import java.nio.ByteOrder; 28 import java.util.AbstractSet; 29 import java.util.HashMap; 30 import java.util.Iterator; 31 import java.util.Map; 32 import java.util.Set; 33 import java.util.stream.Collectors; 34 35 /** 36 * Encapsulates the information describing the format of media data, be it audio or video, as 37 * well as optional feature metadata. 38 * <p> 39 * The format of the media data is specified as key/value pairs. Keys are strings. Values can 40 * be integer, long, float, String or ByteBuffer. 41 * <p> 42 * The feature metadata is specificed as string/boolean pairs. 43 * <p> 44 * Keys common to all audio/video formats, <b>all keys not marked optional are mandatory</b>: 45 * 46 * <table> 47 * <tr><th>Name</th><th>Value Type</th><th>Description</th></tr> 48 * <tr><td>{@link #KEY_MIME}</td><td>String</td><td>The type of the format.</td></tr> 49 * <tr><td>{@link #KEY_CODECS_STRING}</td><td>String</td><td>optional, the RFC 6381 codecs string of the MediaFormat</td></tr> 50 * <tr><td>{@link #KEY_MAX_INPUT_SIZE}</td><td>Integer</td><td>optional, maximum size of a buffer of input data</td></tr> 51 * <tr><td>{@link #KEY_PIXEL_ASPECT_RATIO_WIDTH}</td><td>Integer</td><td>optional, the pixel aspect ratio width</td></tr> 52 * <tr><td>{@link #KEY_PIXEL_ASPECT_RATIO_HEIGHT}</td><td>Integer</td><td>optional, the pixel aspect ratio height</td></tr> 53 * <tr><td>{@link #KEY_BIT_RATE}</td><td>Integer</td><td><b>encoder-only</b>, desired bitrate in bits/second</td></tr> 54 * <tr><td>{@link #KEY_DURATION}</td><td>long</td><td>the duration of the content (in microseconds)</td></tr> 55 * </table> 56 * 57 * Video formats have the following keys: 58 * <table> 59 * <tr><th>Name</th><th>Value Type</th><th>Description</th></tr> 60 * <tr><td>{@link #KEY_WIDTH}</td><td>Integer</td><td></td></tr> 61 * <tr><td>{@link #KEY_HEIGHT}</td><td>Integer</td><td></td></tr> 62 * <tr><td>{@link #KEY_COLOR_FORMAT}</td><td>Integer</td><td>set by the user 63 * for encoders, readable in the output format of decoders</b></td></tr> 64 * <tr><td>{@link #KEY_FRAME_RATE}</td><td>Integer or Float</td><td>required for <b>encoders</b>, 65 * optional for <b>decoders</b></td></tr> 66 * <tr><td>{@link #KEY_CAPTURE_RATE}</td><td>Integer</td><td></td></tr> 67 * <tr><td>{@link #KEY_I_FRAME_INTERVAL}</td><td>Integer (or Float)</td><td><b>encoder-only</b>, 68 * time-interval between key frames. 69 * Float support added in {@link android.os.Build.VERSION_CODES#N_MR1}</td></tr> 70 * <tr><td>{@link #KEY_INTRA_REFRESH_PERIOD}</td><td>Integer</td><td><b>encoder-only</b>, optional</td></tr> 71 * <tr><td>{@link #KEY_LATENCY}</td><td>Integer</td><td><b>encoder-only</b>, optional</td></tr> 72 * <tr><td>{@link #KEY_MAX_WIDTH}</td><td>Integer</td><td><b>decoder-only</b>, optional, max-resolution width</td></tr> 73 * <tr><td>{@link #KEY_MAX_HEIGHT}</td><td>Integer</td><td><b>decoder-only</b>, optional, max-resolution height</td></tr> 74 * <tr><td>{@link #KEY_REPEAT_PREVIOUS_FRAME_AFTER}</td><td>Long</td><td><b>encoder in surface-mode 75 * only</b>, optional</td></tr> 76 * <tr><td>{@link #KEY_PUSH_BLANK_BUFFERS_ON_STOP}</td><td>Integer(1)</td><td><b>decoder rendering 77 * to a surface only</b>, optional</td></tr> 78 * <tr><td>{@link #KEY_TEMPORAL_LAYERING}</td><td>String</td><td><b>encoder only</b>, optional, 79 * temporal-layering schema</td></tr> 80 * </table> 81 * Specify both {@link #KEY_MAX_WIDTH} and {@link #KEY_MAX_HEIGHT} to enable 82 * adaptive playback (seamless resolution change) for a video decoder that 83 * supports it ({@link MediaCodecInfo.CodecCapabilities#FEATURE_AdaptivePlayback}). 84 * The values are used as hints for the codec: they are the maximum expected 85 * resolution to prepare for. Depending on codec support, preparing for larger 86 * maximum resolution may require more memory even if that resolution is never 87 * reached. These fields have no effect for codecs that do not support adaptive 88 * playback.<br /><br /> 89 * 90 * Audio formats have the following keys: 91 * <table> 92 * <tr><th>Name</th><th>Value Type</th><th>Description</th></tr> 93 * <tr><td>{@link #KEY_CHANNEL_COUNT}</td><td>Integer</td><td></td></tr> 94 * <tr><td>{@link #KEY_SAMPLE_RATE}</td><td>Integer</td><td></td></tr> 95 * <tr><td>{@link #KEY_PCM_ENCODING}</td><td>Integer</td><td>optional</td></tr> 96 * <tr><td>{@link #KEY_IS_ADTS}</td><td>Integer</td><td>optional, if <em>decoding</em> AAC audio content, setting this key to 1 indicates that each audio frame is prefixed by the ADTS header.</td></tr> 97 * <tr><td>{@link #KEY_AAC_PROFILE}</td><td>Integer</td><td><b>encoder-only</b>, optional, if content is AAC audio, specifies the desired profile.</td></tr> 98 * <tr><td>{@link #KEY_AAC_SBR_MODE}</td><td>Integer</td><td><b>encoder-only</b>, optional, if content is AAC audio, specifies the desired SBR mode.</td></tr> 99 * <tr><td>{@link #KEY_AAC_DRC_TARGET_REFERENCE_LEVEL}</td><td>Integer</td><td><b>decoder-only</b>, optional, if content is AAC audio, specifies the target reference level.</td></tr> 100 * <tr><td>{@link #KEY_AAC_ENCODED_TARGET_LEVEL}</td><td>Integer</td><td><b>decoder-only</b>, optional, if content is AAC audio, specifies the target reference level used at encoder.</td></tr> 101 * <tr><td>{@link #KEY_AAC_DRC_BOOST_FACTOR}</td><td>Integer</td><td><b>decoder-only</b>, optional, if content is AAC audio, specifies the DRC boost factor.</td></tr> 102 * <tr><td>{@link #KEY_AAC_DRC_ATTENUATION_FACTOR}</td><td>Integer</td><td><b>decoder-only</b>, optional, if content is AAC audio, specifies the DRC attenuation factor.</td></tr> 103 * <tr><td>{@link #KEY_AAC_DRC_HEAVY_COMPRESSION}</td><td>Integer</td><td><b>decoder-only</b>, optional, if content is AAC audio, specifies whether to use heavy compression.</td></tr> 104 * <tr><td>{@link #KEY_AAC_MAX_OUTPUT_CHANNEL_COUNT}</td><td>Integer</td><td><b>decoder-only</b>, optional, if content is AAC audio, specifies the maximum number of channels the decoder outputs.</td></tr> 105 * <tr><td>{@link #KEY_AAC_DRC_EFFECT_TYPE}</td><td>Integer</td><td><b>decoder-only</b>, optional, if content is AAC audio, specifies the MPEG-D DRC effect type to use.</td></tr> 106 * <tr><td>{@link #KEY_AAC_DRC_OUTPUT_LOUDNESS}</td><td>Integer</td><td><b>decoder-only</b>, optional, if content is AAC audio, returns the DRC output loudness.</td></tr> 107 * <tr><td>{@link #KEY_AAC_DRC_ALBUM_MODE}</td><td>Integer</td><td><b>decoder-only</b>, optional, if content is AAC audio, specifies the whether MPEG-D DRC Album Mode is active or not.</td></tr> 108 * <tr><td>{@link #KEY_CHANNEL_MASK}</td><td>Integer</td><td>optional, a mask of audio channel assignments</td></tr> 109 * <tr><td>{@link #KEY_ENCODER_DELAY}</td><td>Integer</td><td>optional, the number of frames to trim from the start of the decoded audio stream.</td></tr> 110 * <tr><td>{@link #KEY_ENCODER_PADDING}</td><td>Integer</td><td>optional, the number of frames to trim from the end of the decoded audio stream.</td></tr> 111 * <tr><td>{@link #KEY_FLAC_COMPRESSION_LEVEL}</td><td>Integer</td><td><b>encoder-only</b>, optional, if content is FLAC audio, specifies the desired compression level.</td></tr> 112 * <tr><td>{@link #KEY_MPEGH_PROFILE_LEVEL_INDICATION}</td><td>Integer</td> 113 * <td><b>decoder-only</b>, optional, if content is MPEG-H audio, 114 * specifies the profile and level of the stream.</td></tr> 115 * <tr><td>{@link #KEY_MPEGH_COMPATIBLE_SETS}</td><td>ByteBuffer</td> 116 * <td><b>decoder-only</b>, optional, if content is MPEG-H audio, 117 * specifies the compatible sets (profile and level) of the stream.</td></tr> 118 * <tr><td>{@link #KEY_MPEGH_REFERENCE_CHANNEL_LAYOUT}</td> 119 * <td>Integer</td><td><b>decoder-only</b>, optional, if content is MPEG-H audio, 120 * specifies the preferred reference channel layout of the stream.</td></tr> 121 * </table> 122 * 123 * Subtitle formats have the following keys: 124 * <table> 125 * <tr><td>{@link #KEY_MIME}</td><td>String</td><td>The type of the format.</td></tr> 126 * <tr><td>{@link #KEY_LANGUAGE}</td><td>String</td><td>The language of the content.</td></tr> 127 * <tr><td>{@link #KEY_CAPTION_SERVICE_NUMBER}</td><td>int</td><td>optional, the closed-caption service or channel number.</td></tr> 128 * </table> 129 * 130 * Image formats have the following keys: 131 * <table> 132 * <tr><td>{@link #KEY_MIME}</td><td>String</td><td>The type of the format.</td></tr> 133 * <tr><td>{@link #KEY_WIDTH}</td><td>Integer</td><td></td></tr> 134 * <tr><td>{@link #KEY_HEIGHT}</td><td>Integer</td><td></td></tr> 135 * <tr><td>{@link #KEY_COLOR_FORMAT}</td><td>Integer</td><td>set by the user 136 * for encoders, readable in the output format of decoders</b></td></tr> 137 * <tr><td>{@link #KEY_TILE_WIDTH}</td><td>Integer</td><td>required if the image has grid</td></tr> 138 * <tr><td>{@link #KEY_TILE_HEIGHT}</td><td>Integer</td><td>required if the image has grid</td></tr> 139 * <tr><td>{@link #KEY_GRID_ROWS}</td><td>Integer</td><td>required if the image has grid</td></tr> 140 * <tr><td>{@link #KEY_GRID_COLUMNS}</td><td>Integer</td><td>required if the image has grid</td></tr> 141 * </table> 142 */ 143 public final class MediaFormat { 144 public static final String MIMETYPE_VIDEO_VP8 = "video/x-vnd.on2.vp8"; 145 public static final String MIMETYPE_VIDEO_VP9 = "video/x-vnd.on2.vp9"; 146 public static final String MIMETYPE_VIDEO_AV1 = "video/av01"; 147 public static final String MIMETYPE_VIDEO_AVC = "video/avc"; 148 public static final String MIMETYPE_VIDEO_HEVC = "video/hevc"; 149 public static final String MIMETYPE_VIDEO_MPEG4 = "video/mp4v-es"; 150 public static final String MIMETYPE_VIDEO_H263 = "video/3gpp"; 151 public static final String MIMETYPE_VIDEO_MPEG2 = "video/mpeg2"; 152 public static final String MIMETYPE_VIDEO_RAW = "video/raw"; 153 public static final String MIMETYPE_VIDEO_DOLBY_VISION = "video/dolby-vision"; 154 public static final String MIMETYPE_VIDEO_SCRAMBLED = "video/scrambled"; 155 156 public static final String MIMETYPE_AUDIO_AMR_NB = "audio/3gpp"; 157 public static final String MIMETYPE_AUDIO_AMR_WB = "audio/amr-wb"; 158 public static final String MIMETYPE_AUDIO_MPEG = "audio/mpeg"; 159 public static final String MIMETYPE_AUDIO_AAC = "audio/mp4a-latm"; 160 public static final String MIMETYPE_AUDIO_QCELP = "audio/qcelp"; 161 public static final String MIMETYPE_AUDIO_VORBIS = "audio/vorbis"; 162 public static final String MIMETYPE_AUDIO_OPUS = "audio/opus"; 163 public static final String MIMETYPE_AUDIO_G711_ALAW = "audio/g711-alaw"; 164 public static final String MIMETYPE_AUDIO_G711_MLAW = "audio/g711-mlaw"; 165 public static final String MIMETYPE_AUDIO_RAW = "audio/raw"; 166 public static final String MIMETYPE_AUDIO_FLAC = "audio/flac"; 167 public static final String MIMETYPE_AUDIO_MSGSM = "audio/gsm"; 168 public static final String MIMETYPE_AUDIO_AC3 = "audio/ac3"; 169 public static final String MIMETYPE_AUDIO_EAC3 = "audio/eac3"; 170 public static final String MIMETYPE_AUDIO_EAC3_JOC = "audio/eac3-joc"; 171 public static final String MIMETYPE_AUDIO_AC4 = "audio/ac4"; 172 public static final String MIMETYPE_AUDIO_SCRAMBLED = "audio/scrambled"; 173 /** MIME type for MPEG-H Audio single stream */ 174 public static final String MIMETYPE_AUDIO_MPEGH_MHA1 = "audio/mha1"; 175 /** MIME type for MPEG-H Audio single stream, encapsulated in MHAS */ 176 public static final String MIMETYPE_AUDIO_MPEGH_MHM1 = "audio/mhm1"; 177 /** MIME type for DTS (up to 5.1 channels) audio stream. */ 178 public static final String MIMETYPE_AUDIO_DTS = "audio/vnd.dts"; 179 /** MIME type for DTS HD (up to 7.1 channels) audio stream. */ 180 public static final String MIMETYPE_AUDIO_DTS_HD = "audio/vnd.dts.hd"; 181 /** MIME type for DTS UHD (object-based) audio stream. */ 182 public static final String MIMETYPE_AUDIO_DTS_UHD = "audio/vnd.dts.uhd"; 183 /** MIME type for Dynamic Resolution Adaptation (DRA) audio stream. */ 184 public static final String MIMETYPE_AUDIO_DRA = "audio/vnd.dra"; 185 /** MIME type for Dolby Metadata-enhanced Audio Transmission (MAT) audio stream. */ 186 public static final String MIMETYPE_AUDIO_DOLBY_MAT = "audio/vnd.dolby.mat"; 187 /** MIME type for Dolby TrueHD audio format, based on Meridian Lossless Packing (MLP). */ 188 public static final String MIMETYPE_AUDIO_DOLBY_TRUEHD = "audio/vnd.dolby.mlp"; 189 /** 190 * MIME type for AAC Low Complexity (LC) audio stream. Uses the scheme defined by 191 * RFC 6381 with OTI of MPEG-4 (40) and AOT of AAC LC (2) from ISO/IEC 14496-3. 192 */ 193 public static final String MIMETYPE_AUDIO_AAC_LC = "audio/mp4a.40.02"; 194 /** 195 * MIME type for HE-AAC v1 (LC + SBR) audio stream. Uses the scheme defined by 196 * RFC 6381 with OTI of MPEG-4 (40) and AOT of AAC SBR (5) from ISO/IEC 14496-3. 197 */ 198 public static final String MIMETYPE_AUDIO_AAC_HE_V1 = "audio/mp4a.40.05"; 199 /** 200 * MIME type for HE-AAC v2 (LC + SBR + PS) audio stream. Uses the scheme defined by 201 * RFC 6381 with OTI of MPEG-4 (40) and AOT of PS (29) from ISO/IEC 14496-3. 202 */ 203 public static final String MIMETYPE_AUDIO_AAC_HE_V2 = "audio/mp4a.40.29"; 204 /** 205 * MIME type for AAC Enhanced Low Delay (ELD) audio stream. Uses the scheme defined by 206 * RFC 6381 with OTI of MPEG-4 (40) and AOT of ELD (39) from ISO/IEC 14496-3. 207 */ 208 public static final String MIMETYPE_AUDIO_AAC_ELD = "audio/mp4a.40.39"; 209 /** 210 * MIME type for AAC XHE audio stream. Uses the scheme defined by 211 * RFC 6381 with OTI of MPEG-4 (40) and AOT of USAC (42) from ISO/IEC 14496-3. 212 */ 213 public static final String MIMETYPE_AUDIO_AAC_XHE = "audio/mp4a.40.42"; 214 /** 215 * MIME type for MPEG-H Baseline (BL) Profile L3 audio stream. Uses the scheme defined by 216 * RFC 6381 with mpegh3daProfileLevelIndication for main profile/L3 (0x3) from ISO/IEC 23008-3. 217 */ 218 public static final String MIMETYPE_AUDIO_MPEGH_BL_L3 = "audio/mhm1.03"; 219 /** 220 * MIME type for MPEG-H Baseline (BL) Profile L4 audio stream. Uses the scheme defined by 221 * RFC 6381 with mpegh3daProfileLevelIndication for main profile/L4 (0x4) from ISO/IEC 23008-3. 222 */ 223 public static final String MIMETYPE_AUDIO_MPEGH_BL_L4 = "audio/mhm1.04"; 224 /** 225 * MIME type for MPEG-H Low Complexity (LC) L3 audio stream. Uses the scheme defined by 226 * RFC 6381 with mpegh3daProfileLevelIndication for LC profile/L3 (0xD) from ISO/IEC 23008-3. 227 */ 228 public static final String MIMETYPE_AUDIO_MPEGH_LC_L3 = "audio/mhm1.0d"; 229 /** 230 * MIME type for MPEG-H Low Complexity (LC) L4 audio stream. Uses the scheme defined by 231 * RFC 6381 with mpegh3daProfileLevelIndication for LC profile/L4 (0xE) from ISO/IEC 23008-3. 232 */ 233 public static final String MIMETYPE_AUDIO_MPEGH_LC_L4 = "audio/mhm1.0e"; 234 /** 235 * MIME type for the IEC61937 audio stream encapsulation. This type isn't defined by IANA. 236 */ 237 public static final String MIMETYPE_AUDIO_IEC61937 = "audio/x-iec61937"; 238 239 /** 240 * MIME type for HEIF still image data encoded in HEVC. 241 * 242 * To decode such an image, {@link MediaCodec} decoder for 243 * {@link #MIMETYPE_VIDEO_HEVC} shall be used. The client needs to form 244 * the correct {@link #MediaFormat} based on additional information in 245 * the track format, and send it to {@link MediaCodec#configure}. 246 * 247 * The track's MediaFormat will come with {@link #KEY_WIDTH} and 248 * {@link #KEY_HEIGHT} keys, which describes the width and height 249 * of the image. If the image doesn't contain grid (i.e. none of 250 * {@link #KEY_TILE_WIDTH}, {@link #KEY_TILE_HEIGHT}, 251 * {@link #KEY_GRID_ROWS}, {@link #KEY_GRID_COLUMNS} are present}), the 252 * track will contain a single sample of coded data for the entire image, 253 * and the image width and height should be used to set up the decoder. 254 * 255 * If the image does come with grid, each sample from the track will 256 * contain one tile in the grid, of which the size is described by 257 * {@link #KEY_TILE_WIDTH} and {@link #KEY_TILE_HEIGHT}. This size 258 * (instead of {@link #KEY_WIDTH} and {@link #KEY_HEIGHT}) should be 259 * used to set up the decoder. The track contains {@link #KEY_GRID_ROWS} 260 * by {@link #KEY_GRID_COLUMNS} samples in row-major, top-row first, 261 * left-to-right order. The output image should be reconstructed by 262 * first tiling the decoding results of the tiles in the correct order, 263 * then trimming (before rotation is applied) on the bottom and right 264 * side, if the tiled area is larger than the image width and height. 265 */ 266 public static final String MIMETYPE_IMAGE_ANDROID_HEIC = "image/vnd.android.heic"; 267 268 /** 269 * MIME type for WebVTT subtitle data. 270 */ 271 public static final String MIMETYPE_TEXT_VTT = "text/vtt"; 272 273 /** 274 * MIME type for SubRip (SRT) container. 275 */ 276 public static final String MIMETYPE_TEXT_SUBRIP = "application/x-subrip"; 277 278 /** 279 * MIME type for CEA-608 closed caption data. 280 */ 281 public static final String MIMETYPE_TEXT_CEA_608 = "text/cea-608"; 282 283 /** 284 * MIME type for CEA-708 closed caption data. 285 */ 286 public static final String MIMETYPE_TEXT_CEA_708 = "text/cea-708"; 287 288 @UnsupportedAppUsage 289 private Map<String, Object> mMap; 290 291 /** 292 * A key describing the log session ID for MediaCodec. The log session ID is a random 32-byte 293 * hexadecimal string that is used to associate metrics from multiple media codec instances 294 * to the same playback or recording session. 295 * The associated value is a string. 296 * @hide 297 */ 298 public static final String LOG_SESSION_ID = "log-session-id"; 299 300 /** 301 * A key describing the mime type of the MediaFormat. 302 * The associated value is a string. 303 */ 304 public static final String KEY_MIME = "mime"; 305 306 /** 307 * A key describing the codecs string of the MediaFormat. See RFC 6381 section 3.2 for the 308 * syntax of the value. The value does not hold {@link MediaCodec}-exposed codec names. 309 * The associated value is a string. 310 * 311 * @see MediaParser.TrackData#mediaFormat 312 */ 313 public static final String KEY_CODECS_STRING = "codecs-string"; 314 315 /** 316 * An optional key describing the low latency decoding mode. This is an optional parameter 317 * that applies only to decoders. If enabled, the decoder doesn't hold input and output 318 * data more than required by the codec standards. 319 * The associated value is an integer (0 or 1): 1 when low-latency decoding is enabled, 320 * 0 otherwise. The default value is 0. 321 */ 322 public static final String KEY_LOW_LATENCY = "low-latency"; 323 324 /** 325 * A key describing the language of the content, using either ISO 639-1 326 * or 639-2/T codes. The associated value is a string. 327 */ 328 public static final String KEY_LANGUAGE = "language"; 329 330 /** 331 * A key describing the closed caption service number. For CEA-608 caption tracks, holds the 332 * channel number. For CEA-708, holds the service number. 333 * The associated value is an int. 334 */ 335 public static final String KEY_CAPTION_SERVICE_NUMBER = "caption-service-number"; 336 337 /** 338 * A key describing the sample rate of an audio format. 339 * The associated value is an integer 340 */ 341 public static final String KEY_SAMPLE_RATE = "sample-rate"; 342 343 /** 344 * A key describing the number of channels in an audio format. 345 * The associated value is an integer 346 */ 347 public static final String KEY_CHANNEL_COUNT = "channel-count"; 348 349 /** 350 * A key describing the width of the content in a video format. 351 * The associated value is an integer 352 */ 353 public static final String KEY_WIDTH = "width"; 354 355 /** 356 * A key describing the height of the content in a video format. 357 * The associated value is an integer 358 */ 359 public static final String KEY_HEIGHT = "height"; 360 361 /** 362 * A key describing the bottom-coordinate (y) of the crop rectangle. 363 * This is the bottom-most row included in the crop frame, 364 * where row indices start at 0. 365 * Additional information on the crop rectangle semantics can be found at 366 * {@link android.media.MediaCodec}. 367 */ 368 public static final String KEY_CROP_BOTTOM = "crop-bottom"; 369 370 /** 371 * A key describing the left-coordinate (x) of the crop rectangle. 372 * This is the left-most column included in the crop frame, 373 * where column indices start at 0. 374 * Additional information on the crop rectangle semantics can be found at 375 * {@link android.media.MediaCodec}. 376 */ 377 public static final String KEY_CROP_LEFT = "crop-left"; 378 379 /** 380 * A key describing the right-coordinate (x) of the crop rectangle. 381 * This is the right-most column included in the crop frame, 382 * where column indices start at 0. 383 * Additional information on the crop rectangle semantics can be found at 384 * {@link android.media.MediaCodec}. 385 */ 386 public static final String KEY_CROP_RIGHT = "crop-right"; 387 388 /** 389 * A key describing the top-coordinate (y) of the crop rectangle. 390 * This is the top-most row included in the crop frame, 391 * where row indices start at 0. 392 * Additional information on the crop rectangle semantics can be found at 393 * {@link android.media.MediaCodec}. 394 */ 395 public static final String KEY_CROP_TOP = "crop-top"; 396 397 /** 398 * A key describing the maximum expected width of the content in a video 399 * decoder format, in case there are resolution changes in the video content. 400 * The associated value is an integer 401 */ 402 public static final String KEY_MAX_WIDTH = "max-width"; 403 404 /** 405 * A key describing the maximum expected height of the content in a video 406 * decoder format, in case there are resolution changes in the video content. 407 * The associated value is an integer 408 */ 409 public static final String KEY_MAX_HEIGHT = "max-height"; 410 411 /** A key describing the maximum size in bytes of a buffer of data 412 * described by this MediaFormat. 413 * The associated value is an integer 414 */ 415 public static final String KEY_MAX_INPUT_SIZE = "max-input-size"; 416 417 /** 418 * A key describing the pixel aspect ratio width. 419 * The associated value is an integer 420 */ 421 public static final String KEY_PIXEL_ASPECT_RATIO_WIDTH = "sar-width"; 422 423 /** 424 * A key describing the pixel aspect ratio height. 425 * The associated value is an integer 426 */ 427 public static final String KEY_PIXEL_ASPECT_RATIO_HEIGHT = "sar-height"; 428 429 /** 430 * A key describing the average bitrate in bits/sec. 431 * The associated value is an integer 432 */ 433 public static final String KEY_BIT_RATE = "bitrate"; 434 435 /** 436 * A key describing the hardware AV sync id. 437 * The associated value is an integer 438 * 439 * See android.media.tv.tuner.Tuner#getAvSyncHwId. 440 */ 441 public static final String KEY_HARDWARE_AV_SYNC_ID = "hw-av-sync-id"; 442 443 /** 444 * A key describing the max bitrate in bits/sec. 445 * This is usually over a one-second sliding window (e.g. over any window of one second). 446 * The associated value is an integer 447 * @hide 448 */ 449 public static final String KEY_MAX_BIT_RATE = "max-bitrate"; 450 451 /** 452 * A key describing the color format of the content in a video format. 453 * Constants are declared in {@link android.media.MediaCodecInfo.CodecCapabilities}. 454 */ 455 public static final String KEY_COLOR_FORMAT = "color-format"; 456 457 /** 458 * A key describing the frame rate of a video format in frames/sec. 459 * <p> 460 * The associated value is normally an integer when the value is used by the platform, 461 * but video codecs also accept float configuration values. 462 * Specifically, {@link MediaExtractor#getTrackFormat MediaExtractor} provides an integer 463 * value corresponding to the frame rate information of the track if specified and non-zero. 464 * Otherwise, this key is not present. {@link MediaCodec#configure MediaCodec} accepts both 465 * float and integer values. 466 * <p> 467 * This represents the desired operating frame rate if the 468 * {@link #KEY_OPERATING_RATE} is not present and {@link #KEY_PRIORITY} is {@code 0} 469 * (realtime). Otherwise, this is just informational. 470 * <p> 471 * For video encoders this value corresponds to the intended frame rate (the rate at which 472 * the application intends to send frames to the encoder, as calculated by the buffer 473 * timestamps, and not from the actual real-time rate that the frames are sent to 474 * the encoder). Encoders use this hint for rate control, specifically for the initial 475 * frames, as encoders are expected to support variable frame rate (for rate control) based 476 * on the actual {@link MediaCodec.BufferInfo#presentationTimeUs buffer timestamps} of 477 * subsequent frames. 478 * <p> 479 * This key is not used in the {@code MediaCodec} 480 * {@link MediaCodec#getInputFormat input}/{@link MediaCodec#getOutputFormat output} formats, 481 * nor by {@link MediaMuxer#addTrack MediaMuxer}. 482 */ 483 public static final String KEY_FRAME_RATE = "frame-rate"; 484 485 /** 486 * A key describing the width (in pixels) of each tile of the content in a 487 * {@link #MIMETYPE_IMAGE_ANDROID_HEIC} track. The associated value is an integer. 488 * 489 * Refer to {@link #MIMETYPE_IMAGE_ANDROID_HEIC} on decoding instructions of such tracks. 490 * 491 * @see #KEY_TILE_HEIGHT 492 * @see #KEY_GRID_ROWS 493 * @see #KEY_GRID_COLUMNS 494 */ 495 public static final String KEY_TILE_WIDTH = "tile-width"; 496 497 /** 498 * A key describing the height (in pixels) of each tile of the content in a 499 * {@link #MIMETYPE_IMAGE_ANDROID_HEIC} track. The associated value is an integer. 500 * 501 * Refer to {@link #MIMETYPE_IMAGE_ANDROID_HEIC} on decoding instructions of such tracks. 502 * 503 * @see #KEY_TILE_WIDTH 504 * @see #KEY_GRID_ROWS 505 * @see #KEY_GRID_COLUMNS 506 */ 507 public static final String KEY_TILE_HEIGHT = "tile-height"; 508 509 /** 510 * A key describing the number of grid rows in the content in a 511 * {@link #MIMETYPE_IMAGE_ANDROID_HEIC} track. The associated value is an integer. 512 * 513 * Refer to {@link #MIMETYPE_IMAGE_ANDROID_HEIC} on decoding instructions of such tracks. 514 * 515 * @see #KEY_TILE_WIDTH 516 * @see #KEY_TILE_HEIGHT 517 * @see #KEY_GRID_COLUMNS 518 */ 519 public static final String KEY_GRID_ROWS = "grid-rows"; 520 521 /** 522 * A key describing the number of grid columns in the content in a 523 * {@link #MIMETYPE_IMAGE_ANDROID_HEIC} track. The associated value is an integer. 524 * 525 * Refer to {@link #MIMETYPE_IMAGE_ANDROID_HEIC} on decoding instructions of such tracks. 526 * 527 * @see #KEY_TILE_WIDTH 528 * @see #KEY_TILE_HEIGHT 529 * @see #KEY_GRID_ROWS 530 */ 531 public static final String KEY_GRID_COLUMNS = "grid-cols"; 532 533 /** 534 * A key describing the raw audio sample encoding/format. 535 * 536 * <p>The associated value is an integer, using one of the 537 * {@link AudioFormat}.ENCODING_PCM_ values.</p> 538 * 539 * <p>This is an optional key for audio decoders and encoders specifying the 540 * desired raw audio sample format during {@link MediaCodec#configure 541 * MediaCodec.configure(…)} call. Use {@link MediaCodec#getInputFormat 542 * MediaCodec.getInput}/{@link MediaCodec#getOutputFormat OutputFormat(…)} 543 * to confirm the actual format. For the PCM decoder this key specifies both 544 * input and output sample encodings.</p> 545 * 546 * <p>This key is also used by {@link MediaExtractor} to specify the sample 547 * format of audio data, if it is specified.</p> 548 * 549 * <p>If this key is missing, the raw audio sample format is signed 16-bit short.</p> 550 */ 551 public static final String KEY_PCM_ENCODING = "pcm-encoding"; 552 553 /** 554 * A key describing the capture rate of a video format in frames/sec. 555 * <p> 556 * When capture rate is different than the frame rate, it means that the 557 * video is acquired at a different rate than the playback, which produces 558 * slow motion or timelapse effect during playback. Application can use the 559 * value of this key to tell the relative speed ratio between capture and 560 * playback rates when the video was recorded. 561 * </p> 562 * <p> 563 * The associated value is an integer or a float. 564 * </p> 565 */ 566 public static final String KEY_CAPTURE_RATE = "capture-rate"; 567 568 /** 569 * A key for retrieving the slow-motion marker information associated with a video track. 570 * <p> 571 * The associated value is a ByteBuffer in {@link ByteOrder#BIG_ENDIAN} 572 * (networking order) of the following format: 573 * </p> 574 * <pre class="prettyprint"> 575 * float(32) playbackRate; 576 * unsigned int(32) numMarkers; 577 * for (i = 0;i < numMarkers; i++) { 578 * int(64) timestampUs; 579 * float(32) speedRatio; 580 * }</pre> 581 * The meaning of each field is as follows: 582 * <table border="1" width="90%" align="center" cellpadding="5"> 583 * <tbody> 584 * <tr> 585 * <td>playbackRate</td> 586 * <td>The frame rate at which the playback should happen (or the flattened 587 * clip should be).</td> 588 * </tr> 589 * <tr> 590 * <td>numMarkers</td> 591 * <td>The number of slow-motion markers that follows.</td> 592 * </tr> 593 * <tr> 594 * <td>timestampUs</td> 595 * <td>The starting point of a new segment.</td> 596 * </tr> 597 * <tr> 598 * <td>speedRatio</td> 599 * <td>The playback speed for that segment. The playback speed is a floating 600 * point number, indicating how fast the time progresses relative to that 601 * written in the container. (Eg. 4.0 means time goes 4x as fast, which 602 * makes 30fps become 120fps.)</td> 603 * </tr> 604 * </table> 605 * <p> 606 * The following constraints apply to the timestampUs of the markers: 607 * </p> 608 * <li>The timestampUs shall be monotonically increasing.</li> 609 * <li>The timestampUs shall fall within the time span of the video track.</li> 610 * <li>The first timestampUs should match that of the first video sample.</li> 611 */ 612 public static final String KEY_SLOW_MOTION_MARKERS = "slow-motion-markers"; 613 614 /** 615 * A key describing the frequency of key frames expressed in seconds between key frames. 616 * <p> 617 * This key is used by video encoders. 618 * A negative value means no key frames are requested after the first frame. 619 * A zero value means a stream containing all key frames is requested. 620 * <p class=note> 621 * Most video encoders will convert this value of the number of non-key-frames between 622 * key-frames, using the {@linkplain #KEY_FRAME_RATE frame rate} information; therefore, 623 * if the actual frame rate differs (e.g. input frames are dropped or the frame rate 624 * changes), the <strong>time interval</strong> between key frames will not be the 625 * configured value. 626 * <p> 627 * The associated value is an integer (or float since 628 * {@link android.os.Build.VERSION_CODES#N_MR1}). 629 */ 630 public static final String KEY_I_FRAME_INTERVAL = "i-frame-interval"; 631 632 /** 633 * An optional key describing the period of intra refresh in frames. This is an 634 * optional parameter that applies only to video encoders. If encoder supports it 635 * ({@link MediaCodecInfo.CodecCapabilities#FEATURE_IntraRefresh}), the whole 636 * frame is completely refreshed after the specified period. Also for each frame, 637 * a fix subset of macroblocks must be intra coded which leads to more constant bitrate 638 * than inserting a key frame. This key is recommended for video streaming applications 639 * as it provides low-delay and good error-resilience. This key is ignored if the 640 * video encoder does not support the intra refresh feature. Use the output format to 641 * verify that this feature was enabled. 642 * The associated value is an integer. 643 */ 644 public static final String KEY_INTRA_REFRESH_PERIOD = "intra-refresh-period"; 645 646 /** 647 * An optional key describing whether encoders prepend headers to sync frames (e.g. 648 * SPS and PPS to IDR frames for H.264). This is an optional parameter that applies only 649 * to video encoders. A video encoder may not support this feature; the component will fail 650 * to configure in that case. For other components, this key is ignored. 651 * 652 * The value is an integer, with 1 indicating to prepend headers to every sync frames, 653 * or 0 otherwise. The default value is 0. 654 */ 655 public static final String KEY_PREPEND_HEADER_TO_SYNC_FRAMES = "prepend-sps-pps-to-idr-frames"; 656 657 /** 658 * A key describing the temporal layering schema. This is an optional parameter 659 * that applies only to video encoders. Use {@link MediaCodec#getOutputFormat} 660 * after {@link MediaCodec#configure configure} to query if the encoder supports 661 * the desired schema. Supported values are {@code webrtc.vp8.N-layer}, 662 * {@code android.generic.N}, {@code android.generic.N+M} and {@code none}, where 663 * {@code N} denotes the total number of non-bidirectional layers (which must be at least 1) 664 * and {@code M} denotes the total number of bidirectional layers (which must be non-negative). 665 * <p class=note>{@code android.generic.*} schemas have been added in {@link 666 * android.os.Build.VERSION_CODES#N_MR1}. 667 * <p> 668 * The encoder may support fewer temporal layers, in which case the output format 669 * will contain the configured schema. If the encoder does not support temporal 670 * layering, the output format will not have an entry with this key. 671 * The associated value is a string. 672 */ 673 public static final String KEY_TEMPORAL_LAYERING = "ts-schema"; 674 675 /** 676 * A key describing the stride of the video bytebuffer layout. 677 * Stride (or row increment) is the difference between the index of a pixel 678 * and that of the pixel directly underneath. For YUV 420 formats, the 679 * stride corresponds to the Y plane; the stride of the U and V planes can 680 * be calculated based on the color format, though it is generally undefined 681 * and depends on the device and release. 682 * The associated value is an integer, representing number of bytes. 683 */ 684 public static final String KEY_STRIDE = "stride"; 685 686 /** 687 * A key describing the plane height of a multi-planar (YUV) video bytebuffer layout. 688 * Slice height (or plane height/vertical stride) is the number of rows that must be skipped 689 * to get from the top of the Y plane to the top of the U plane in the bytebuffer. In essence 690 * the offset of the U plane is sliceHeight * stride. The height of the U/V planes 691 * can be calculated based on the color format, though it is generally undefined 692 * and depends on the device and release. 693 * The associated value is an integer, representing number of rows. 694 */ 695 public static final String KEY_SLICE_HEIGHT = "slice-height"; 696 697 /** 698 * Applies only when configuring a video encoder in "surface-input" mode. 699 * The associated value is a long and gives the time in microseconds 700 * after which the frame previously submitted to the encoder will be 701 * repeated (once) if no new frame became available since. 702 */ 703 public static final String KEY_REPEAT_PREVIOUS_FRAME_AFTER 704 = "repeat-previous-frame-after"; 705 706 /** 707 * Instruct the video encoder in "surface-input" mode to drop excessive 708 * frames from the source, so that the input frame rate to the encoder 709 * does not exceed the specified fps. 710 * 711 * The associated value is a float, representing the max frame rate to 712 * feed the encoder at. 713 * 714 */ 715 public static final String KEY_MAX_FPS_TO_ENCODER 716 = "max-fps-to-encoder"; 717 718 /** 719 * Instruct the video encoder in "surface-input" mode to limit the gap of 720 * timestamp between any two adjacent frames fed to the encoder to the 721 * specified amount (in micro-second). 722 * 723 * The associated value is a long int. When positive, it represents the max 724 * timestamp gap between two adjacent frames fed to the encoder. When negative, 725 * the absolute value represents a fixed timestamp gap between any two adjacent 726 * frames fed to the encoder. Note that this will also apply even when the 727 * original timestamp goes backward in time. Under normal conditions, such frames 728 * would be dropped and not sent to the encoder. 729 * 730 * The output timestamp will be restored to the original timestamp and will 731 * not be affected. 732 * 733 * This is used in some special scenarios where input frames arrive sparingly 734 * but it's undesirable to allocate more bits to any single frame, or when it's 735 * important to ensure all frames are captured (rather than captured in the 736 * correct order). 737 * 738 */ 739 public static final String KEY_MAX_PTS_GAP_TO_ENCODER 740 = "max-pts-gap-to-encoder"; 741 742 /** 743 * If specified when configuring a video encoder that's in "surface-input" 744 * mode, it will instruct the encoder to put the surface source in suspended 745 * state when it's connected. No video frames will be accepted until a resume 746 * operation (see {@link MediaCodec#PARAMETER_KEY_SUSPEND}), optionally with 747 * timestamp specified via {@link MediaCodec#PARAMETER_KEY_SUSPEND_TIME}, is 748 * received. 749 * 750 * The value is an integer, with 1 indicating to create with the surface 751 * source suspended, or 0 otherwise. The default value is 0. 752 * 753 * If this key is not set or set to 0, the surface source will accept buffers 754 * as soon as it's connected to the encoder (although they may not be encoded 755 * immediately). This key can be used when the client wants to prepare the 756 * encoder session in advance, but do not want to accept buffers immediately. 757 */ 758 public static final String KEY_CREATE_INPUT_SURFACE_SUSPENDED 759 = "create-input-buffers-suspended"; 760 761 /** 762 * If specified when configuring a video decoder rendering to a surface, 763 * causes the decoder to output "blank", i.e. black frames to the surface 764 * when stopped to clear out any previously displayed contents. 765 * The associated value is an integer of value 1. 766 */ 767 public static final String KEY_PUSH_BLANK_BUFFERS_ON_STOP 768 = "push-blank-buffers-on-shutdown"; 769 770 /** 771 * A key describing the duration (in microseconds) of the content. 772 * The associated value is a long. 773 */ 774 public static final String KEY_DURATION = "durationUs"; 775 776 /** 777 * A key mapping to a value of 1 if the content is AAC audio and 778 * audio frames are prefixed with an ADTS header. 779 * The associated value is an integer (0 or 1). 780 * This key is only supported when _decoding_ content, it cannot 781 * be used to configure an encoder to emit ADTS output. 782 */ 783 public static final String KEY_IS_ADTS = "is-adts"; 784 785 /** 786 * A key describing the channel composition of audio content. This mask 787 * is composed of bits drawn from channel mask definitions in {@link android.media.AudioFormat}. 788 * The associated value is an integer. 789 */ 790 public static final String KEY_CHANNEL_MASK = "channel-mask"; 791 792 /** 793 * A key describing the maximum number of channels that can be output by an audio decoder. 794 * By default, the decoder will output the same number of channels as present in the encoded 795 * stream, if supported. Set this value to limit the number of output channels, and use 796 * the downmix information in the stream, if available. 797 * <p>Values larger than the number of channels in the content to decode behave like the number 798 * of channels in the content (if applicable), for instance passing 99 for a 5.1 audio stream 799 * behaves like passing 6. 800 * <p>This key is only used during decoding. 801 */ 802 public static final String KEY_MAX_OUTPUT_CHANNEL_COUNT = 803 "max-output-channel-count"; 804 805 /** 806 * A key describing the number of frames to trim from the start of the decoded audio stream. 807 * The associated value is an integer. 808 */ 809 public static final String KEY_ENCODER_DELAY = "encoder-delay"; 810 811 /** 812 * A key describing the number of frames to trim from the end of the decoded audio stream. 813 * The associated value is an integer. 814 */ 815 public static final String KEY_ENCODER_PADDING = "encoder-padding"; 816 817 /** 818 * A key describing the AAC profile to be used (AAC audio formats only). 819 * Constants are declared in {@link android.media.MediaCodecInfo.CodecProfileLevel}. 820 */ 821 public static final String KEY_AAC_PROFILE = "aac-profile"; 822 823 /** 824 * A key describing the AAC SBR mode to be used (AAC audio formats only). 825 * The associated value is an integer and can be set to following values: 826 * <ul> 827 * <li>0 - no SBR should be applied</li> 828 * <li>1 - single rate SBR</li> 829 * <li>2 - double rate SBR</li> 830 * </ul> 831 * Note: If this key is not defined the default SRB mode for the desired AAC profile will 832 * be used. 833 * <p>This key is only used during encoding. 834 */ 835 public static final String KEY_AAC_SBR_MODE = "aac-sbr-mode"; 836 837 /** 838 * A key describing the maximum number of channels that can be output by the AAC decoder. 839 * By default, the decoder will output the same number of channels as present in the encoded 840 * stream, if supported. Set this value to limit the number of output channels, and use 841 * the downmix information in the stream, if available. 842 * <p>Values larger than the number of channels in the content to decode behave just 843 * like the actual channel count of the content (e.g. passing 99 for the decoding of 5.1 content 844 * will behave like using 6). 845 * <p>This key is only used during decoding. 846 * @deprecated Use the non-AAC-specific key {@link #KEY_MAX_OUTPUT_CHANNEL_COUNT} instead 847 */ 848 public static final String KEY_AAC_MAX_OUTPUT_CHANNEL_COUNT = "aac-max-output-channel_count"; 849 850 /** 851 * A key describing the Target Reference Level (Target Loudness). 852 * <p>For normalizing loudness across program items, a gain is applied to the audio output so 853 * that the output loudness matches the Target Reference Level. The gain is derived as the 854 * difference between the Target Reference Level and the Program Reference Level (Program 855 * Loudness). The latter can be given in the bitstream and indicates the actual loudness value 856 * of the program item.</p> 857 * <p>The Target Reference Level controls loudness normalization for both MPEG-4 DRC and 858 * MPEG-D DRC. 859 * <p>The value is given as an integer value between 860 * 40 and 127, and is calculated as -4 * Target Reference Level in LKFS. 861 * Therefore, it represents the range of -10 to -31.75 LKFS. 862 * <p>For MPEG-4 DRC, a value of -1 switches off loudness normalization and DRC processing.</p> 863 * <p>For MPEG-D DRC, a value of -1 switches off loudness normalization only. For DRC processing 864 * options of MPEG-D DRC, see {@link #KEY_AAC_DRC_EFFECT_TYPE}</p> 865 * <p>The default value on mobile devices is 64 (-16 LKFS). 866 * <p>This key is only used during decoding. 867 */ 868 public static final String KEY_AAC_DRC_TARGET_REFERENCE_LEVEL = "aac-target-ref-level"; 869 870 /** 871 * A key describing for selecting the DRC effect type for MPEG-D DRC. 872 * The supported values are defined in ISO/IEC 23003-4:2015 and are described as follows: 873 * <table> 874 * <tr><th>Value</th><th>Effect</th></tr> 875 * <tr><th>-1</th><th>Off</th></tr> 876 * <tr><th>0</th><th>None</th></tr> 877 * <tr><th>1</th><th>Late night</th></tr> 878 * <tr><th>2</th><th>Noisy environment</th></tr> 879 * <tr><th>3</th><th>Limited playback range</th></tr> 880 * <tr><th>4</th><th>Low playback level</th></tr> 881 * <tr><th>5</th><th>Dialog enhancement</th></tr> 882 * <tr><th>6</th><th>General compression</th></tr> 883 * </table> 884 * <p>The value -1 (Off) disables DRC processing, while loudness normalization may still be 885 * active and dependent on {@link #KEY_AAC_DRC_TARGET_REFERENCE_LEVEL}.<br> 886 * The value 0 (None) automatically enables DRC processing if necessary to prevent signal 887 * clipping<br> 888 * The value 6 (General compression) can be used for enabling MPEG-D DRC without particular 889 * DRC effect type request.<br> 890 * The default DRC effect type is 3 ("Limited playback range") on mobile devices. 891 * <p>This key is only used during decoding. 892 */ 893 public static final String KEY_AAC_DRC_EFFECT_TYPE = "aac-drc-effect-type"; 894 895 /** 896 * A key describing the target reference level that was assumed at the encoder for 897 * calculation of attenuation gains for clipping prevention. 898 * <p>If it is known, this information can be provided as an integer value between 899 * 0 and 127, which is calculated as -4 * Encoded Target Level in LKFS. 900 * If the Encoded Target Level is unknown, the value can be set to -1. 901 * <p>The default value is -1 (unknown). 902 * <p>The value is ignored when heavy compression (see {@link #KEY_AAC_DRC_HEAVY_COMPRESSION}) 903 * or MPEG-D DRC is used. 904 * <p>This key is only used during decoding. 905 */ 906 public static final String KEY_AAC_ENCODED_TARGET_LEVEL = "aac-encoded-target-level"; 907 908 /** 909 * A key describing the boost factor allowing to adapt the dynamics of the output to the 910 * actual listening requirements. This relies on DRC gain sequences that can be transmitted in 911 * the encoded bitstream to be able to reduce the dynamics of the output signal upon request. 912 * This factor enables the user to select how much of the gains are applied. 913 * <p>Positive gains (boost) and negative gains (attenuation, see 914 * {@link #KEY_AAC_DRC_ATTENUATION_FACTOR}) can be controlled separately for a better match 915 * to different use-cases. 916 * <p>Typically, attenuation gains are sent for loud signal segments, and boost gains are sent 917 * for soft signal segments. If the output is listened to in a noisy environment, for example, 918 * the boost factor is used to enable the positive gains, i.e. to amplify soft signal segments 919 * beyond the noise floor. But for listening late at night, the attenuation 920 * factor is used to enable the negative gains, to prevent loud signal from surprising 921 * the listener. In applications which generally need a low dynamic range, both the boost factor 922 * and the attenuation factor are used in order to enable all DRC gains. 923 * <p>In order to prevent clipping, it is also recommended to apply the attenuation gains 924 * in case of a downmix and/or loudness normalization to high target reference levels. 925 * <p>Both the boost and the attenuation factor parameters are given as integer values 926 * between 0 and 127, representing the range of the factor of 0 (i.e. don't apply) 927 * to 1 (i.e. fully apply boost/attenuation gains respectively). 928 * <p>The default value is 127 (fully apply boost DRC gains). 929 * <p>This key is only used during decoding. 930 */ 931 public static final String KEY_AAC_DRC_BOOST_FACTOR = "aac-drc-boost-level"; 932 933 /** 934 * A key describing the attenuation factor allowing to adapt the dynamics of the output to the 935 * actual listening requirements. 936 * See {@link #KEY_AAC_DRC_BOOST_FACTOR} for a description of the role of this attenuation 937 * factor and the value range. 938 * <p>The default value is 127 (fully apply attenuation DRC gains). 939 * <p>This key is only used during decoding. 940 */ 941 public static final String KEY_AAC_DRC_ATTENUATION_FACTOR = "aac-drc-cut-level"; 942 943 /** 944 * A key describing the selection of the heavy compression profile for MPEG-4 DRC. 945 * <p>Two separate DRC gain sequences can be transmitted in one bitstream: light compression 946 * and heavy compression. When selecting the application of the heavy compression, one of 947 * the sequences is selected: 948 * <ul> 949 * <li>0 enables light compression,</li> 950 * <li>1 enables heavy compression instead. 951 * </ul> 952 * Note that heavy compression doesn't offer the features of scaling of DRC gains 953 * (see {@link #KEY_AAC_DRC_BOOST_FACTOR} and {@link #KEY_AAC_DRC_ATTENUATION_FACTOR} for the 954 * boost and attenuation factors), and frequency-selective (multiband) DRC. 955 * Light compression usually contains clipping prevention for stereo downmixing while heavy 956 * compression, if additionally provided in the bitstream, is usually stronger, and contains 957 * clipping prevention for stereo and mono downmixing. 958 * <p>The default is 1 (heavy compression). 959 * <p>This key is only used during decoding. 960 */ 961 public static final String KEY_AAC_DRC_HEAVY_COMPRESSION = "aac-drc-heavy-compression"; 962 963 /** 964 * A key to retrieve the output loudness of a decoded bitstream. 965 * <p>If loudness normalization is active, the value corresponds to the Target Reference Level 966 * (see {@link #KEY_AAC_DRC_TARGET_REFERENCE_LEVEL}).<br> 967 * If loudness normalization is not active, the value corresponds to the loudness metadata 968 * given in the bitstream. 969 * <p>The value is retrieved with getInteger() and is given as an integer value between 0 and 970 * 231. It is calculated as -4 * Output Loudness in LKFS. Therefore, it represents the range of 971 * 0 to -57.75 LKFS. 972 * <p>A value of -1 indicates that no loudness metadata is present in the bitstream. 973 * <p>Loudness metadata can originate from MPEG-4 DRC or MPEG-D DRC. 974 * <p>This key is only used during decoding. 975 */ 976 public static final String KEY_AAC_DRC_OUTPUT_LOUDNESS = "aac-drc-output-loudness"; 977 978 /** 979 * A key describing the album mode for MPEG-D DRC as defined in ISO/IEC 23003-4. 980 * <p>The associated value is an integer and can be set to following values: 981 * <table> 982 * <tr><th>Value</th><th>Album Mode</th></tr> 983 * <tr><th>0</th><th>disabled</th></tr> 984 * <tr><th>1</th><th>enabled</th></tr> 985 * </table> 986 * <p>Disabled album mode leads to application of gain sequences for fading in and out, if 987 * provided in the bitstream. Enabled album mode makes use of dedicated album loudness 988 * information, if provided in the bitstream. 989 * <p>The default value is 0 (album mode disabled). 990 * <p>This key is only used during decoding. 991 */ 992 public static final String KEY_AAC_DRC_ALBUM_MODE = "aac-drc-album-mode"; 993 994 /** 995 * A key describing the FLAC compression level to be used (FLAC audio format only). 996 * The associated value is an integer ranging from 0 (fastest, least compression) 997 * to 8 (slowest, most compression). 998 */ 999 public static final String KEY_FLAC_COMPRESSION_LEVEL = "flac-compression-level"; 1000 1001 /** 1002 * A key describing the MPEG-H stream profile-level indication. 1003 * 1004 * See ISO_IEC_23008-3;2019 MHADecoderConfigurationRecord mpegh3daProfileLevelIndication. 1005 */ 1006 public static final String KEY_MPEGH_PROFILE_LEVEL_INDICATION = 1007 "mpegh-profile-level-indication"; 1008 1009 /** 1010 * A key describing the MPEG-H stream compatible sets. 1011 * 1012 * See FDAmd_2 of ISO_IEC_23008-3;2019 MHAProfileAndLevelCompatibilitySetBox. 1013 */ 1014 public static final String KEY_MPEGH_COMPATIBLE_SETS = "mpegh-compatible-sets"; 1015 1016 /** 1017 * A key describing the MPEG-H stream reference channel layout. 1018 * 1019 * See ISO_IEC_23008-3;2019 MHADecoderConfigurationRecord referenceChannelLayout 1020 * and ISO_IEC_23001‐8 ChannelConfiguration value. 1021 */ 1022 public static final String KEY_MPEGH_REFERENCE_CHANNEL_LAYOUT = 1023 "mpegh-reference-channel-layout"; 1024 1025 /** 1026 * A key describing the encoding complexity. 1027 * The associated value is an integer. These values are device and codec specific, 1028 * but lower values generally result in faster and/or less power-hungry encoding. 1029 * 1030 * @see MediaCodecInfo.EncoderCapabilities#getComplexityRange() 1031 */ 1032 public static final String KEY_COMPLEXITY = "complexity"; 1033 1034 /** 1035 * A key describing the desired encoding quality. 1036 * The associated value is an integer. This key is only supported for encoders 1037 * that are configured in constant-quality mode. These values are device and 1038 * codec specific, but lower values generally result in more efficient 1039 * (smaller-sized) encoding. 1040 * 1041 * @see MediaCodecInfo.EncoderCapabilities#getQualityRange() 1042 */ 1043 public static final String KEY_QUALITY = "quality"; 1044 1045 /** 1046 * A key describing the desired codec priority. 1047 * <p> 1048 * The associated value is an integer. Higher value means lower priority. 1049 * <p> 1050 * Currently, only two levels are supported:<br> 1051 * 0: realtime priority - meaning that the codec shall support the given 1052 * performance configuration (e.g. framerate) at realtime. This should 1053 * only be used by media playback, capture, and possibly by realtime 1054 * communication scenarios if best effort performance is not suitable.<br> 1055 * 1: non-realtime priority (best effort). 1056 * <p> 1057 * This is a hint used at codec configuration and resource planning - to understand 1058 * the realtime requirements of the application; however, due to the nature of 1059 * media components, performance is not guaranteed. 1060 * 1061 */ 1062 public static final String KEY_PRIORITY = "priority"; 1063 1064 /** 1065 * A key describing the desired operating frame rate for video or sample rate for audio 1066 * that the codec will need to operate at. 1067 * <p> 1068 * The associated value is an integer or a float representing frames-per-second or 1069 * samples-per-second 1070 * <p> 1071 * This is used for cases like high-speed/slow-motion video capture, where the video encoder 1072 * format contains the target playback rate (e.g. 30fps), but the component must be able to 1073 * handle the high operating capture rate (e.g. 240fps). 1074 * <p> 1075 * This rate will be used by codec for resource planning and setting the operating points. 1076 * 1077 */ 1078 public static final String KEY_OPERATING_RATE = "operating-rate"; 1079 1080 /** 1081 * A key describing the desired profile to be used by an encoder. 1082 * <p> 1083 * The associated value is an integer. 1084 * Constants are declared in {@link MediaCodecInfo.CodecProfileLevel}. 1085 * This key is used as a hint, and is only supported for codecs 1086 * that specify a profile. When configuring profile, encoder configuration 1087 * may fail if other parameters are not compatible with the desired 1088 * profile or if the desired profile is not supported, but it may also 1089 * fail silently (where the encoder ends up using a different, compatible profile.) 1090 * <p class="note"> 1091 * <strong>Note:</strong> Codecs are free to use all the available 1092 * coding tools at the specified profile, but may ultimately choose to not do so. 1093 * <p class="note"> 1094 * <strong>Note:</strong> When configuring video encoders, profile must be 1095 * set together with {@link #KEY_LEVEL level}. 1096 * 1097 * @see MediaCodecInfo.CodecCapabilities#profileLevels 1098 */ 1099 public static final String KEY_PROFILE = "profile"; 1100 1101 /** 1102 * A key describing the desired profile to be used by an encoder. 1103 * <p> 1104 * The associated value is an integer. 1105 * Constants are declared in {@link MediaCodecInfo.CodecProfileLevel}. 1106 * This key is used as a further hint when specifying a desired profile, 1107 * and is only supported for codecs that specify a level. 1108 * <p> 1109 * This key is ignored if the {@link #KEY_PROFILE profile} is not specified. 1110 * Otherwise, the value should be a level compatible with the configured encoding 1111 * parameters. 1112 * <p class="note"> 1113 * <strong>Note:</strong> This key cannot be used to constrain the encoder's 1114 * output to a maximum encoding level. Encoders are free to target a different 1115 * level if the configured encoding parameters dictate it. Nevertheless, 1116 * encoders shall use (and encode) a level sufficient to decode the generated 1117 * bitstream, though they may exceed the (Video) Buffering Verifier limits for 1118 * that encoded level. 1119 * 1120 * @see MediaCodecInfo.CodecCapabilities#profileLevels 1121 */ 1122 public static final String KEY_LEVEL = "level"; 1123 1124 /** 1125 * An optional key describing the desired encoder latency in frames. This is an optional 1126 * parameter that applies only to video encoders. If encoder supports it, it should ouput 1127 * at least one output frame after being queued the specified number of frames. This key 1128 * is ignored if the video encoder does not support the latency feature. Use the output 1129 * format to verify that this feature was enabled and the actual value used by the encoder. 1130 * <p> 1131 * If the key is not specified, the default latency will be implenmentation specific. 1132 * The associated value is an integer. 1133 */ 1134 public static final String KEY_LATENCY = "latency"; 1135 1136 /** 1137 * An optional key describing the maximum number of non-display-order coded frames. 1138 * This is an optional parameter that applies only to video encoders. Application should 1139 * check the value for this key in the output format to see if codec will produce 1140 * non-display-order coded frames. If encoder supports it, the output frames' order will be 1141 * different from the display order and each frame's display order could be retrived from 1142 * {@link MediaCodec.BufferInfo#presentationTimeUs}. Before API level 27, application may 1143 * receive non-display-order coded frames even though the application did not request it. 1144 * Note: Application should not rearrange the frames to display order before feeding them 1145 * to {@link MediaMuxer#writeSampleData}. 1146 * <p> 1147 * The default value is 0. 1148 */ 1149 public static final String KEY_OUTPUT_REORDER_DEPTH = "output-reorder-depth"; 1150 1151 /** 1152 * A key describing the desired clockwise rotation on an output surface. 1153 * This key is only used when the codec is configured using an output surface. 1154 * The associated value is an integer, representing degrees. Supported values 1155 * are 0, 90, 180 or 270. This is an optional field; if not specified, rotation 1156 * defaults to 0. 1157 * 1158 * @see MediaCodecInfo.CodecCapabilities#profileLevels 1159 */ 1160 public static final String KEY_ROTATION = "rotation-degrees"; 1161 1162 /** 1163 * A key describing the desired bitrate mode to be used by an encoder. 1164 * Constants are declared in {@link MediaCodecInfo.CodecCapabilities}. 1165 * 1166 * @see MediaCodecInfo.EncoderCapabilities#isBitrateModeSupported(int) 1167 */ 1168 public static final String KEY_BITRATE_MODE = "bitrate-mode"; 1169 1170 /** 1171 * A key describing the maximum Quantization Parameter allowed for encoding video. 1172 * This key applies to all three video picture types (I, P, and B). 1173 * The value is used directly for picture type I; a per-mime formula is used 1174 * to calculate the value for the remaining picture types. 1175 * 1176 * This calculation can be avoided by directly specifying values for each picture type 1177 * using the type-specific keys {@link #KEY_VIDEO_QP_I_MAX}, {@link #KEY_VIDEO_QP_P_MAX}, 1178 * and {@link #KEY_VIDEO_QP_B_MAX}. 1179 * 1180 * The associated value is an integer. 1181 */ 1182 public static final String KEY_VIDEO_QP_MAX = "video-qp-max"; 1183 1184 /** 1185 * A key describing the minimum Quantization Parameter allowed for encoding video. 1186 * This key applies to all three video frame types (I, P, and B). 1187 * The value is used directly for picture type I; a per-mime formula is used 1188 * to calculate the value for the remaining picture types. 1189 * 1190 * This calculation can be avoided by directly specifying values for each picture type 1191 * using the type-specific keys {@link #KEY_VIDEO_QP_I_MIN}, {@link #KEY_VIDEO_QP_P_MIN}, 1192 * and {@link #KEY_VIDEO_QP_B_MIN}. 1193 * 1194 * The associated value is an integer. 1195 */ 1196 public static final String KEY_VIDEO_QP_MIN = "video-qp-min"; 1197 1198 /** 1199 * A key describing the maximum Quantization Parameter allowed for encoding video. 1200 * This value applies to video I-frames. 1201 * 1202 * The associated value is an integer. 1203 */ 1204 public static final String KEY_VIDEO_QP_I_MAX = "video-qp-i-max"; 1205 1206 /** 1207 * A key describing the minimum Quantization Parameter allowed for encoding video. 1208 * This value applies to video I-frames. 1209 * 1210 * The associated value is an integer. 1211 */ 1212 public static final String KEY_VIDEO_QP_I_MIN = "video-qp-i-min"; 1213 1214 /** 1215 * A key describing the maximum Quantization Parameter allowed for encoding video. 1216 * This value applies to video P-frames. 1217 * 1218 * The associated value is an integer. 1219 */ 1220 public static final String KEY_VIDEO_QP_P_MAX = "video-qp-p-max"; 1221 1222 /** 1223 * A key describing the minimum Quantization Parameter allowed for encoding video. 1224 * This value applies to video P-frames. 1225 * 1226 * The associated value is an integer. 1227 */ 1228 public static final String KEY_VIDEO_QP_P_MIN = "video-qp-p-min"; 1229 1230 /** 1231 * A key describing the maximum Quantization Parameter allowed for encoding video. 1232 * This value applies to video B-frames. 1233 * 1234 * The associated value is an integer. 1235 */ 1236 public static final String KEY_VIDEO_QP_B_MAX = "video-qp-b-max"; 1237 1238 /** 1239 * A key describing the minimum Quantization Parameter allowed for encoding video. 1240 * This value applies to video B-frames. 1241 * 1242 * The associated value is an integer. 1243 */ 1244 public static final String KEY_VIDEO_QP_B_MIN = "video-qp-b-min"; 1245 1246 /** 1247 * A key describing the level of encoding statistics information emitted from video encoder. 1248 * 1249 * The associated value is an integer. 1250 */ 1251 public static final String KEY_VIDEO_ENCODING_STATISTICS_LEVEL = 1252 "video-encoding-statistics-level"; 1253 1254 /** 1255 * Encoding Statistics Level None. 1256 * Encoder generates no information about Encoding statistics. 1257 */ 1258 public static final int VIDEO_ENCODING_STATISTICS_LEVEL_NONE = 0; 1259 1260 /** 1261 * Encoding Statistics Level 1. 1262 * Encoder generates {@link MediaFormat#KEY_PICTURE_TYPE} and 1263 * {@link MediaFormat#KEY_VIDEO_QP_AVERAGE} for each frame. 1264 */ 1265 public static final int VIDEO_ENCODING_STATISTICS_LEVEL_1 = 1; 1266 1267 /** @hide */ 1268 @IntDef({ 1269 VIDEO_ENCODING_STATISTICS_LEVEL_NONE, 1270 VIDEO_ENCODING_STATISTICS_LEVEL_1, 1271 }) 1272 @Retention(RetentionPolicy.SOURCE) 1273 public @interface VideoEncodingStatisticsLevel {} 1274 1275 /** 1276 * A key describing the per-frame average block QP (Quantization Parameter). 1277 * This is a part of a video 'Encoding Statistics' export feature. 1278 * This value is emitted from video encoder for a video frame. 1279 * The average value is rounded to the nearest integer value. 1280 * 1281 * The associated value is an integer. 1282 */ 1283 public static final String KEY_VIDEO_QP_AVERAGE = "video-qp-average"; 1284 1285 /** 1286 * A key describing the picture type of the encoded frame. 1287 * This is a part of a video 'Encoding Statistics' export feature. 1288 * This value is emitted from video encoder for a video frame. 1289 * 1290 * The associated value is an integer. 1291 */ 1292 public static final String KEY_PICTURE_TYPE = "picture-type"; 1293 1294 /** Picture Type is unknown. */ 1295 public static final int PICTURE_TYPE_UNKNOWN = 0; 1296 1297 /** Picture Type is I Frame. */ 1298 public static final int PICTURE_TYPE_I = 1; 1299 1300 /** Picture Type is P Frame. */ 1301 public static final int PICTURE_TYPE_P = 2; 1302 1303 /** Picture Type is B Frame. */ 1304 public static final int PICTURE_TYPE_B = 3; 1305 1306 /** @hide */ 1307 @IntDef({ 1308 PICTURE_TYPE_UNKNOWN, 1309 PICTURE_TYPE_I, 1310 PICTURE_TYPE_P, 1311 PICTURE_TYPE_B, 1312 }) 1313 @Retention(RetentionPolicy.SOURCE) 1314 public @interface PictureType {} 1315 1316 /** 1317 * A key describing the audio session ID of the AudioTrack associated 1318 * to a tunneled video codec. 1319 * The associated value is an integer. 1320 * 1321 * @see MediaCodecInfo.CodecCapabilities#FEATURE_TunneledPlayback 1322 */ 1323 public static final String KEY_AUDIO_SESSION_ID = "audio-session-id"; 1324 1325 /** 1326 * A key describing the audio hardware sync ID of the AudioTrack associated 1327 * to a tunneled video codec. The associated value is an integer. 1328 * 1329 * @hide 1330 * 1331 * @see MediaCodecInfo.CodecCapabilities#FEATURE_TunneledPlayback 1332 * @see AudioManager#getAudioHwSyncForSession 1333 */ 1334 public static final String KEY_AUDIO_HW_SYNC = "audio-hw-sync"; 1335 1336 /** 1337 * A key for boolean AUTOSELECT behavior for the track. Tracks with AUTOSELECT=true 1338 * are considered when automatically selecting a track without specific user 1339 * choice, based on the current locale. 1340 * This is currently only used for subtitle tracks, when the user selected 1341 * 'Default' for the captioning locale. 1342 * The associated value is an integer, where non-0 means TRUE. This is an optional 1343 * field; if not specified, AUTOSELECT defaults to TRUE. 1344 */ 1345 public static final String KEY_IS_AUTOSELECT = "is-autoselect"; 1346 1347 /** 1348 * A key for boolean DEFAULT behavior for the track. The track with DEFAULT=true is 1349 * selected in the absence of a specific user choice. 1350 * This is currently used in two scenarios: 1351 * 1) for subtitle tracks, when the user selected 'Default' for the captioning locale. 1352 * 2) for a {@link #MIMETYPE_IMAGE_ANDROID_HEIC} track, indicating the image is the 1353 * primary item in the file. 1354 1355 * The associated value is an integer, where non-0 means TRUE. This is an optional 1356 * field; if not specified, DEFAULT is considered to be FALSE. 1357 */ 1358 public static final String KEY_IS_DEFAULT = "is-default"; 1359 1360 /** 1361 * A key for the FORCED field for subtitle tracks. True if it is a 1362 * forced subtitle track. Forced subtitle tracks are essential for the 1363 * content and are shown even when the user turns off Captions. They 1364 * are used for example to translate foreign/alien dialogs or signs. 1365 * The associated value is an integer, where non-0 means TRUE. This is an 1366 * optional field; if not specified, FORCED defaults to FALSE. 1367 */ 1368 public static final String KEY_IS_FORCED_SUBTITLE = "is-forced-subtitle"; 1369 1370 /** 1371 * A key describing the number of haptic channels in an audio format. 1372 * The associated value is an integer. 1373 */ 1374 public static final String KEY_HAPTIC_CHANNEL_COUNT = "haptic-channel-count"; 1375 1376 /** @hide */ 1377 public static final String KEY_IS_TIMED_TEXT = "is-timed-text"; 1378 1379 // The following color aspect values must be in sync with the ones in HardwareAPI.h. 1380 /** 1381 * An optional key describing the color primaries, white point and 1382 * luminance factors for video content. 1383 * 1384 * The associated value is an integer: 0 if unspecified, or one of the 1385 * COLOR_STANDARD_ values. 1386 */ 1387 public static final String KEY_COLOR_STANDARD = "color-standard"; 1388 1389 /** BT.709 color chromacity coordinates with KR = 0.2126, KB = 0.0722. */ 1390 public static final int COLOR_STANDARD_BT709 = 1; 1391 1392 /** BT.601 625 color chromacity coordinates with KR = 0.299, KB = 0.114. */ 1393 public static final int COLOR_STANDARD_BT601_PAL = 2; 1394 1395 /** BT.601 525 color chromacity coordinates with KR = 0.299, KB = 0.114. */ 1396 public static final int COLOR_STANDARD_BT601_NTSC = 4; 1397 1398 /** BT.2020 color chromacity coordinates with KR = 0.2627, KB = 0.0593. */ 1399 public static final int COLOR_STANDARD_BT2020 = 6; 1400 1401 /** @hide */ 1402 @IntDef({ 1403 COLOR_STANDARD_BT709, 1404 COLOR_STANDARD_BT601_PAL, 1405 COLOR_STANDARD_BT601_NTSC, 1406 COLOR_STANDARD_BT2020, 1407 }) 1408 @Retention(RetentionPolicy.SOURCE) 1409 public @interface ColorStandard {} 1410 1411 /** 1412 * An optional key describing the opto-electronic transfer function used 1413 * for the video content. 1414 * 1415 * The associated value is an integer: 0 if unspecified, or one of the 1416 * COLOR_TRANSFER_ values. 1417 */ 1418 public static final String KEY_COLOR_TRANSFER = "color-transfer"; 1419 1420 /** Linear transfer characteristic curve. */ 1421 public static final int COLOR_TRANSFER_LINEAR = 1; 1422 1423 /** SMPTE 170M transfer characteristic curve used by BT.601/BT.709/BT.2020. This is the curve 1424 * used by most non-HDR video content. */ 1425 public static final int COLOR_TRANSFER_SDR_VIDEO = 3; 1426 1427 /** SMPTE ST 2084 transfer function. This is used by some HDR video content. */ 1428 public static final int COLOR_TRANSFER_ST2084 = 6; 1429 1430 /** ARIB STD-B67 hybrid-log-gamma transfer function. This is used by some HDR video content. */ 1431 public static final int COLOR_TRANSFER_HLG = 7; 1432 1433 /** @hide */ 1434 @IntDef({ 1435 COLOR_TRANSFER_LINEAR, 1436 COLOR_TRANSFER_SDR_VIDEO, 1437 COLOR_TRANSFER_ST2084, 1438 COLOR_TRANSFER_HLG, 1439 }) 1440 @Retention(RetentionPolicy.SOURCE) 1441 public @interface ColorTransfer {} 1442 1443 /** 1444 * An optional key describing the range of the component values of the video content. 1445 * 1446 * The associated value is an integer: 0 if unspecified, or one of the 1447 * COLOR_RANGE_ values. 1448 */ 1449 public static final String KEY_COLOR_RANGE = "color-range"; 1450 1451 /** Limited range. Y component values range from 16 to 235 for 8-bit content. 1452 * Cr, Cy values range from 16 to 240 for 8-bit content. 1453 * This is the default for video content. */ 1454 public static final int COLOR_RANGE_LIMITED = 2; 1455 1456 /** Full range. Y, Cr and Cb component values range from 0 to 255 for 8-bit content. */ 1457 public static final int COLOR_RANGE_FULL = 1; 1458 1459 /** @hide */ 1460 @IntDef({ 1461 COLOR_RANGE_LIMITED, 1462 COLOR_RANGE_FULL, 1463 }) 1464 @Retention(RetentionPolicy.SOURCE) 1465 public @interface ColorRange {} 1466 1467 /** 1468 * An optional key describing the static metadata of HDR (high-dynamic-range) video content. 1469 * 1470 * The associated value is a ByteBuffer. This buffer contains the raw contents of the 1471 * Static Metadata Descriptor (including the descriptor ID) of an HDMI Dynamic Range and 1472 * Mastering InfoFrame as defined by CTA-861.3. This key must be provided to video decoders 1473 * for HDR video content unless this information is contained in the bitstream and the video 1474 * decoder supports an HDR-capable profile. This key must be provided to video encoders for 1475 * HDR video content. 1476 */ 1477 public static final String KEY_HDR_STATIC_INFO = "hdr-static-info"; 1478 1479 /** 1480 * An optional key describing the HDR10+ metadata of the video content. 1481 * 1482 * The associated value is a ByteBuffer containing HDR10+ metadata conforming to the 1483 * user_data_registered_itu_t_t35() syntax of SEI message for ST 2094-40. This key will 1484 * be present on: 1485 *<p> 1486 * - The formats of output buffers of a decoder configured for HDR10+ profiles (such as 1487 * {@link MediaCodecInfo.CodecProfileLevel#VP9Profile2HDR10Plus}, {@link 1488 * MediaCodecInfo.CodecProfileLevel#VP9Profile3HDR10Plus} or {@link 1489 * MediaCodecInfo.CodecProfileLevel#HEVCProfileMain10HDR10Plus}), or 1490 *<p> 1491 * - The formats of output buffers of an encoder configured for an HDR10+ profiles that 1492 * uses out-of-band metadata (such as {@link 1493 * MediaCodecInfo.CodecProfileLevel#VP9Profile2HDR10Plus} or {@link 1494 * MediaCodecInfo.CodecProfileLevel#VP9Profile3HDR10Plus}). 1495 * 1496 * @see MediaCodec#PARAMETER_KEY_HDR10_PLUS_INFO 1497 */ 1498 public static final String KEY_HDR10_PLUS_INFO = "hdr10-plus-info"; 1499 1500 /** 1501 * An optional key describing the opto-electronic transfer function 1502 * requested for the output video content. 1503 * 1504 * The associated value is an integer: 0 if unspecified, or one of the 1505 * COLOR_TRANSFER_ values. When unspecified the component will not touch the 1506 * video content; otherwise the component will tone-map the raw video frame 1507 * to match the requested transfer function. 1508 * 1509 * After configure, component's input format will contain this key to note 1510 * whether the request is supported or not. If the value in the input format 1511 * is the same as the requested value, the request is supported. The value 1512 * is set to 0 if unsupported. 1513 */ 1514 public static final String KEY_COLOR_TRANSFER_REQUEST = "color-transfer-request"; 1515 1516 /** 1517 * A key describing a unique ID for the content of a media track. 1518 * 1519 * <p>This key is used by {@link MediaExtractor}. Some extractors provide multiple encodings 1520 * of the same track (e.g. float audio tracks for FLAC and WAV may be expressed as two 1521 * tracks via MediaExtractor: a normal PCM track for backward compatibility, and a float PCM 1522 * track for added fidelity. Similarly, Dolby Vision extractor may provide a baseline SDR 1523 * version of a DV track.) This key can be used to identify which MediaExtractor tracks refer 1524 * to the same underlying content. 1525 * </p> 1526 * 1527 * The associated value is an integer. 1528 */ 1529 public static final String KEY_TRACK_ID = "track-id"; 1530 1531 /** 1532 * A key describing the system id of the conditional access system used to scramble 1533 * a media track. 1534 * <p> 1535 * This key is set by {@link MediaExtractor} if the track is scrambled with a conditional 1536 * access system, regardless of the presence of a valid {@link MediaCas} object. 1537 * <p> 1538 * The associated value is an integer. 1539 * @hide 1540 */ 1541 public static final String KEY_CA_SYSTEM_ID = "ca-system-id"; 1542 1543 /** 1544 * A key describing the {@link MediaCas.Session} object associated with a media track. 1545 * <p> 1546 * This key is set by {@link MediaExtractor} if the track is scrambled with a conditional 1547 * access system, after it receives a valid {@link MediaCas} object. 1548 * <p> 1549 * The associated value is a ByteBuffer. 1550 * @hide 1551 */ 1552 public static final String KEY_CA_SESSION_ID = "ca-session-id"; 1553 1554 /** 1555 * A key describing the private data in the CA_descriptor associated with a media track. 1556 * <p> 1557 * This key is set by {@link MediaExtractor} if the track is scrambled with a conditional 1558 * access system, before it receives a valid {@link MediaCas} object. 1559 * <p> 1560 * The associated value is a ByteBuffer. 1561 * @hide 1562 */ 1563 public static final String KEY_CA_PRIVATE_DATA = "ca-private-data"; 1564 1565 /** 1566 * A key describing the maximum number of B frames between I or P frames, 1567 * to be used by a video encoder. 1568 * The associated value is an integer. The default value is 0, which means 1569 * that no B frames are allowed. Note that non-zero value does not guarantee 1570 * B frames; it's up to the encoder to decide. 1571 */ 1572 public static final String KEY_MAX_B_FRAMES = "max-bframes"; 1573 1574 /** 1575 * A key for applications to opt out of allowing 1576 * a Surface to discard undisplayed/unconsumed frames 1577 * as means to catch up after falling behind. 1578 * This value is an integer. 1579 * The value 0 indicates the surface is not allowed to drop frames. 1580 * The value 1 indicates the surface is allowed to drop frames. 1581 * 1582 * {@link MediaCodec} describes the semantics. 1583 */ 1584 public static final String KEY_ALLOW_FRAME_DROP = "allow-frame-drop"; 1585 MediaFormat(@onNull Map<String, Object> map)1586 /* package private */ MediaFormat(@NonNull Map<String, Object> map) { 1587 mMap = map; 1588 } 1589 1590 /** 1591 * Creates an empty MediaFormat 1592 */ MediaFormat()1593 public MediaFormat() { 1594 mMap = new HashMap(); 1595 } 1596 1597 @UnsupportedAppUsage getMap()1598 /* package private */ Map<String, Object> getMap() { 1599 return mMap; 1600 } 1601 1602 /** 1603 * Returns true iff a key of the given name exists in the format. 1604 */ containsKey(@onNull String name)1605 public final boolean containsKey(@NonNull String name) { 1606 return mMap.containsKey(name); 1607 } 1608 1609 /** 1610 * Returns true iff a feature of the given name exists in the format. 1611 */ containsFeature(@onNull String name)1612 public final boolean containsFeature(@NonNull String name) { 1613 return mMap.containsKey(KEY_FEATURE_ + name); 1614 } 1615 1616 public static final int TYPE_NULL = 0; 1617 public static final int TYPE_INTEGER = 1; 1618 public static final int TYPE_LONG = 2; 1619 public static final int TYPE_FLOAT = 3; 1620 public static final int TYPE_STRING = 4; 1621 public static final int TYPE_BYTE_BUFFER = 5; 1622 1623 /** @hide */ 1624 @IntDef({ 1625 TYPE_NULL, 1626 TYPE_INTEGER, 1627 TYPE_LONG, 1628 TYPE_FLOAT, 1629 TYPE_STRING, 1630 TYPE_BYTE_BUFFER 1631 }) 1632 @Retention(RetentionPolicy.SOURCE) 1633 public @interface Type {} 1634 1635 /** 1636 * Returns the value type for a key. If the key does not exist, it returns TYPE_NULL. 1637 */ getValueTypeForKey(@onNull String name)1638 public final @Type int getValueTypeForKey(@NonNull String name) { 1639 Object value = mMap.get(name); 1640 if (value == null) { 1641 return TYPE_NULL; 1642 } else if (value instanceof Integer) { 1643 return TYPE_INTEGER; 1644 } else if (value instanceof Long) { 1645 return TYPE_LONG; 1646 } else if (value instanceof Float) { 1647 return TYPE_FLOAT; 1648 } else if (value instanceof String) { 1649 return TYPE_STRING; 1650 } else if (value instanceof ByteBuffer) { 1651 return TYPE_BYTE_BUFFER; 1652 } 1653 throw new RuntimeException("invalid value for key"); 1654 } 1655 1656 /** 1657 * A key prefix used together with a {@link MediaCodecInfo.CodecCapabilities} 1658 * feature name describing a required or optional feature for a codec capabilities 1659 * query. 1660 * The associated value is an integer, where non-0 value means the feature is 1661 * requested to be present, while 0 value means the feature is requested to be not 1662 * present. 1663 * @see MediaCodecList#findDecoderForFormat 1664 * @see MediaCodecList#findEncoderForFormat 1665 * @see MediaCodecInfo.CodecCapabilities#isFormatSupported 1666 * 1667 * @hide 1668 */ 1669 public static final String KEY_FEATURE_ = "feature-"; 1670 1671 /** 1672 * Returns the value of a numeric key. This is provided as a convenience method for keys 1673 * that may take multiple numeric types, such as {@link #KEY_FRAME_RATE}, or {@link 1674 * #KEY_I_FRAME_INTERVAL}. 1675 * 1676 * @return null if the key does not exist or the stored value for the key is null 1677 * @throws ClassCastException if the stored value for the key is ByteBuffer or String 1678 */ getNumber(@onNull String name)1679 public final @Nullable Number getNumber(@NonNull String name) { 1680 return (Number) mMap.get(name); 1681 } 1682 1683 /** 1684 * Returns the value of a numeric key, or the default value if the key is missing. 1685 * 1686 * @return defaultValue if the key does not exist or the stored value for the key is null 1687 * @throws ClassCastException if the stored value for the key is ByteBuffer or String 1688 */ getNumber(@onNull String name, @NonNull Number defaultValue)1689 public final @NonNull Number getNumber(@NonNull String name, @NonNull Number defaultValue) { 1690 Number ret = getNumber(name); 1691 return ret == null ? defaultValue : ret; 1692 } 1693 1694 /** 1695 * Returns the value of an integer key. 1696 * 1697 * @throws NullPointerException if the key does not exist or the stored value for the key is 1698 * null 1699 * @throws ClassCastException if the stored value for the key is long, float, ByteBuffer or 1700 * String 1701 */ getInteger(@onNull String name)1702 public final int getInteger(@NonNull String name) { 1703 return (int) mMap.get(name); 1704 } 1705 1706 /** 1707 * Returns the value of an integer key, or the default value if the key is missing. 1708 * 1709 * @return defaultValue if the key does not exist or the stored value for the key is null 1710 * @throws ClassCastException if the stored value for the key is long, float, ByteBuffer or 1711 * String 1712 */ getInteger(@onNull String name, int defaultValue)1713 public final int getInteger(@NonNull String name, int defaultValue) { 1714 try { 1715 return getInteger(name); 1716 } catch (NullPointerException e) { 1717 /* no such field or field is null */ 1718 return defaultValue; 1719 } 1720 } 1721 1722 /** 1723 * Returns the value of a long key. 1724 * 1725 * @throws NullPointerException if the key does not exist or the stored value for the key is 1726 * null 1727 * @throws ClassCastException if the stored value for the key is int, float, ByteBuffer or 1728 * String 1729 */ getLong(@onNull String name)1730 public final long getLong(@NonNull String name) { 1731 return (long) mMap.get(name); 1732 } 1733 1734 /** 1735 * Returns the value of a long key, or the default value if the key is missing. 1736 * 1737 * @return defaultValue if the key does not exist or the stored value for the key is null 1738 * @throws ClassCastException if the stored value for the key is int, float, ByteBuffer or 1739 * String 1740 */ getLong(@onNull String name, long defaultValue)1741 public final long getLong(@NonNull String name, long defaultValue) { 1742 try { 1743 return getLong(name); 1744 } catch (NullPointerException e) { 1745 /* no such field or field is null */ 1746 return defaultValue; 1747 } 1748 } 1749 1750 /** 1751 * Returns the value of a float key. 1752 * 1753 * @throws NullPointerException if the key does not exist or the stored value for the key is 1754 * null 1755 * @throws ClassCastException if the stored value for the key is int, long, ByteBuffer or 1756 * String 1757 */ getFloat(@onNull String name)1758 public final float getFloat(@NonNull String name) { 1759 return (float) mMap.get(name); 1760 } 1761 1762 /** 1763 * Returns the value of a float key, or the default value if the key is missing. 1764 * 1765 * @return defaultValue if the key does not exist or the stored value for the key is null 1766 * @throws ClassCastException if the stored value for the key is int, long, ByteBuffer or 1767 * String 1768 */ getFloat(@onNull String name, float defaultValue)1769 public final float getFloat(@NonNull String name, float defaultValue) { 1770 Object value = mMap.get(name); 1771 return value != null ? (float) value : defaultValue; 1772 } 1773 1774 /** 1775 * Returns the value of a string key. 1776 * 1777 * @return null if the key does not exist or the stored value for the key is null 1778 * @throws ClassCastException if the stored value for the key is int, long, float or ByteBuffer 1779 */ getString(@onNull String name)1780 public final @Nullable String getString(@NonNull String name) { 1781 return (String)mMap.get(name); 1782 } 1783 1784 /** 1785 * Returns the value of a string key, or the default value if the key is missing. 1786 * 1787 * @return defaultValue if the key does not exist or the stored value for the key is null 1788 * @throws ClassCastException if the stored value for the key is int, long, float or ByteBuffer 1789 */ getString(@onNull String name, @NonNull String defaultValue)1790 public final @NonNull String getString(@NonNull String name, @NonNull String defaultValue) { 1791 String ret = getString(name); 1792 return ret == null ? defaultValue : ret; 1793 } 1794 1795 /** 1796 * Returns the value of a ByteBuffer key. 1797 * 1798 * @return null if the key does not exist or the stored value for the key is null 1799 * @throws ClassCastException if the stored value for the key is int, long, float or String 1800 */ getByteBuffer(@onNull String name)1801 public final @Nullable ByteBuffer getByteBuffer(@NonNull String name) { 1802 return (ByteBuffer)mMap.get(name); 1803 } 1804 1805 /** 1806 * Returns the value of a ByteBuffer key, or the default value if the key is missing. 1807 * 1808 * @return defaultValue if the key does not exist or the stored value for the key is null 1809 * @throws ClassCastException if the stored value for the key is int, long, float or String 1810 */ getByteBuffer( @onNull String name, @NonNull ByteBuffer defaultValue)1811 public final @NonNull ByteBuffer getByteBuffer( 1812 @NonNull String name, @NonNull ByteBuffer defaultValue) { 1813 ByteBuffer ret = getByteBuffer(name); 1814 return ret == null ? defaultValue : ret; 1815 } 1816 1817 /** 1818 * Returns whether a feature is to be enabled ({@code true}) or disabled 1819 * ({@code false}). 1820 * 1821 * @param feature the name of a {@link MediaCodecInfo.CodecCapabilities} feature. 1822 * 1823 * @throws IllegalArgumentException if the feature was neither set to be enabled 1824 * nor to be disabled. 1825 */ getFeatureEnabled(@onNull String feature)1826 public boolean getFeatureEnabled(@NonNull String feature) { 1827 Integer enabled = (Integer)mMap.get(KEY_FEATURE_ + feature); 1828 if (enabled == null) { 1829 throw new IllegalArgumentException("feature is not specified"); 1830 } 1831 return enabled != 0; 1832 } 1833 1834 /** 1835 * Sets the value of an integer key. 1836 */ setInteger(@onNull String name, int value)1837 public final void setInteger(@NonNull String name, int value) { 1838 mMap.put(name, value); 1839 } 1840 1841 /** 1842 * Sets the value of a long key. 1843 */ setLong(@onNull String name, long value)1844 public final void setLong(@NonNull String name, long value) { 1845 mMap.put(name, value); 1846 } 1847 1848 /** 1849 * Sets the value of a float key. 1850 */ setFloat(@onNull String name, float value)1851 public final void setFloat(@NonNull String name, float value) { 1852 mMap.put(name, value); 1853 } 1854 1855 /** 1856 * Sets the value of a string key. 1857 * <p> 1858 * If value is {@code null}, it sets a null value that behaves similarly to a missing key. 1859 * This could be used prior to API level {@link android os.Build.VERSION_CODES#Q} to effectively 1860 * remove a key. 1861 */ setString(@onNull String name, @Nullable String value)1862 public final void setString(@NonNull String name, @Nullable String value) { 1863 mMap.put(name, value); 1864 } 1865 1866 /** 1867 * Sets the value of a ByteBuffer key. 1868 * <p> 1869 * If value is {@code null}, it sets a null value that behaves similarly to a missing key. 1870 * This could be used prior to API level {@link android os.Build.VERSION_CODES#Q} to effectively 1871 * remove a key. 1872 */ setByteBuffer(@onNull String name, @Nullable ByteBuffer bytes)1873 public final void setByteBuffer(@NonNull String name, @Nullable ByteBuffer bytes) { 1874 mMap.put(name, bytes); 1875 } 1876 1877 /** 1878 * Removes a value of a given key if present. Has no effect if the key is not present. 1879 */ removeKey(@onNull String name)1880 public final void removeKey(@NonNull String name) { 1881 // exclude feature mappings 1882 if (!name.startsWith(KEY_FEATURE_)) { 1883 mMap.remove(name); 1884 } 1885 } 1886 1887 /** 1888 * Removes a given feature setting if present. Has no effect if the feature setting is not 1889 * present. 1890 */ removeFeature(@onNull String name)1891 public final void removeFeature(@NonNull String name) { 1892 mMap.remove(KEY_FEATURE_ + name); 1893 } 1894 1895 /** 1896 * A Partial set view for a portion of the keys in a MediaFormat object. 1897 * 1898 * This class is needed as we want to return a portion of the actual format keys in getKeys() 1899 * and another portion of the keys in getFeatures(), and still allow the view properties. 1900 */ 1901 private abstract class FilteredMappedKeySet extends AbstractSet<String> { 1902 private Set<String> mKeys; 1903 1904 // Returns true if this set should include this key keepKey(String key)1905 abstract protected boolean keepKey(String key); 1906 1907 // Maps a key from the underlying key set into its new value in this key set mapKeyToItem(String key)1908 abstract protected String mapKeyToItem(String key); 1909 1910 // Maps a key from this key set into its original value in the underlying key set mapItemToKey(String item)1911 abstract protected String mapItemToKey(String item); 1912 FilteredMappedKeySet()1913 public FilteredMappedKeySet() { 1914 mKeys = mMap.keySet(); 1915 } 1916 1917 // speed up contains and remove from abstract implementation (that would iterate 1918 // over each element) 1919 @Override contains(Object o)1920 public boolean contains(Object o) { 1921 if (o instanceof String) { 1922 String key = mapItemToKey((String)o); 1923 return keepKey(key) && mKeys.contains(key); 1924 } 1925 return false; 1926 } 1927 1928 @Override remove(Object o)1929 public boolean remove(Object o) { 1930 if (o instanceof String) { 1931 String key = mapItemToKey((String)o); 1932 if (keepKey(key) && mKeys.remove(key)) { 1933 mMap.remove(key); 1934 return true; 1935 } 1936 } 1937 return false; 1938 } 1939 1940 private class KeyIterator implements Iterator<String> { 1941 Iterator<String> mIterator; 1942 String mLast; 1943 KeyIterator()1944 public KeyIterator() { 1945 // We must create a copy of the filtered stream, as remove operation has to modify 1946 // the underlying data structure (mMap), so the iterator's operation is undefined. 1947 // Use a list as it is likely less memory consuming than the other alternative: set. 1948 mIterator = 1949 mKeys.stream().filter(k -> keepKey(k)).collect(Collectors.toList()).iterator(); 1950 } 1951 1952 @Override hasNext()1953 public boolean hasNext() { 1954 return mIterator.hasNext(); 1955 } 1956 1957 @Override next()1958 public String next() { 1959 mLast = mIterator.next(); 1960 return mapKeyToItem(mLast); 1961 } 1962 1963 @Override remove()1964 public void remove() { 1965 mIterator.remove(); 1966 mMap.remove(mLast); 1967 } 1968 } 1969 1970 @Override iterator()1971 public Iterator<String> iterator() { 1972 return new KeyIterator(); 1973 } 1974 1975 @Override size()1976 public int size() { 1977 return (int) mKeys.stream().filter(this::keepKey).count(); 1978 } 1979 } 1980 1981 /** 1982 * A Partial set view for a portion of the keys in a MediaFormat object for keys that 1983 * don't start with a prefix, such as "feature-" 1984 */ 1985 private class UnprefixedKeySet extends FilteredMappedKeySet { 1986 private String mPrefix; 1987 UnprefixedKeySet(String prefix)1988 public UnprefixedKeySet(String prefix) { 1989 super(); 1990 mPrefix = prefix; 1991 } 1992 keepKey(String key)1993 protected boolean keepKey(String key) { 1994 return !key.startsWith(mPrefix); 1995 } 1996 mapKeyToItem(String key)1997 protected String mapKeyToItem(String key) { 1998 return key; 1999 } 2000 mapItemToKey(String item)2001 protected String mapItemToKey(String item) { 2002 return item; 2003 } 2004 } 2005 2006 /** 2007 * A Partial set view for a portion of the keys in a MediaFormat object for keys that 2008 * start with a prefix, such as "feature-", with the prefix removed 2009 */ 2010 private class PrefixedKeySetWithPrefixRemoved extends FilteredMappedKeySet { 2011 private String mPrefix; 2012 private int mPrefixLength; 2013 PrefixedKeySetWithPrefixRemoved(String prefix)2014 public PrefixedKeySetWithPrefixRemoved(String prefix) { 2015 super(); 2016 mPrefix = prefix; 2017 mPrefixLength = prefix.length(); 2018 } 2019 keepKey(String key)2020 protected boolean keepKey(String key) { 2021 return key.startsWith(mPrefix); 2022 } 2023 mapKeyToItem(String key)2024 protected String mapKeyToItem(String key) { 2025 return key.substring(mPrefixLength); 2026 } 2027 mapItemToKey(String item)2028 protected String mapItemToKey(String item) { 2029 return mPrefix + item; 2030 } 2031 } 2032 2033 2034 /** 2035 * Returns a {@link java.util.Set Set} view of the keys contained in this MediaFormat. 2036 * 2037 * The set is backed by the MediaFormat object, so changes to the format are reflected in the 2038 * set, and vice-versa. If the format is modified while an iteration over the set is in progress 2039 * (except through the iterator's own remove operation), the results of the iteration are 2040 * undefined. The set supports element removal, which removes the corresponding mapping from the 2041 * format, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. 2042 * It does not support the add or addAll operations. 2043 */ getKeys()2044 public final @NonNull java.util.Set<String> getKeys() { 2045 return new UnprefixedKeySet(KEY_FEATURE_); 2046 } 2047 2048 /** 2049 * Returns a {@link java.util.Set Set} view of the features contained in this MediaFormat. 2050 * 2051 * The set is backed by the MediaFormat object, so changes to the format are reflected in the 2052 * set, and vice-versa. If the format is modified while an iteration over the set is in progress 2053 * (except through the iterator's own remove operation), the results of the iteration are 2054 * undefined. The set supports element removal, which removes the corresponding mapping from the 2055 * format, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. 2056 * It does not support the add or addAll operations. 2057 */ getFeatures()2058 public final @NonNull java.util.Set<String> getFeatures() { 2059 return new PrefixedKeySetWithPrefixRemoved(KEY_FEATURE_); 2060 } 2061 2062 /** 2063 * Create a copy of a media format object. 2064 */ MediaFormat(@onNull MediaFormat other)2065 public MediaFormat(@NonNull MediaFormat other) { 2066 this(); 2067 mMap.putAll(other.mMap); 2068 } 2069 2070 /** 2071 * Sets whether a feature is to be enabled ({@code true}) or disabled 2072 * ({@code false}). 2073 * 2074 * If {@code enabled} is {@code true}, the feature is requested to be present. 2075 * Otherwise, the feature is requested to be not present. 2076 * 2077 * @param feature the name of a {@link MediaCodecInfo.CodecCapabilities} feature. 2078 * 2079 * @see MediaCodecList#findDecoderForFormat 2080 * @see MediaCodecList#findEncoderForFormat 2081 * @see MediaCodecInfo.CodecCapabilities#isFormatSupported 2082 */ setFeatureEnabled(@onNull String feature, boolean enabled)2083 public void setFeatureEnabled(@NonNull String feature, boolean enabled) { 2084 setInteger(KEY_FEATURE_ + feature, enabled ? 1 : 0); 2085 } 2086 2087 /** 2088 * Creates a minimal audio format. 2089 * @param mime The mime type of the content. 2090 * @param sampleRate The sampling rate of the content. 2091 * @param channelCount The number of audio channels in the content. 2092 */ createAudioFormat( @onNull String mime, int sampleRate, int channelCount)2093 public static final @NonNull MediaFormat createAudioFormat( 2094 @NonNull String mime, 2095 int sampleRate, 2096 int channelCount) { 2097 MediaFormat format = new MediaFormat(); 2098 format.setString(KEY_MIME, mime); 2099 format.setInteger(KEY_SAMPLE_RATE, sampleRate); 2100 format.setInteger(KEY_CHANNEL_COUNT, channelCount); 2101 2102 return format; 2103 } 2104 2105 /** 2106 * Creates a minimal subtitle format. 2107 * @param mime The mime type of the content. 2108 * @param language The language of the content, using either ISO 639-1 or 639-2/T 2109 * codes. Specify null or "und" if language information is only included 2110 * in the content. (This will also work if there are multiple language 2111 * tracks in the content.) 2112 */ createSubtitleFormat( @onNull String mime, String language)2113 public static final @NonNull MediaFormat createSubtitleFormat( 2114 @NonNull String mime, 2115 String language) { 2116 MediaFormat format = new MediaFormat(); 2117 format.setString(KEY_MIME, mime); 2118 format.setString(KEY_LANGUAGE, language); 2119 2120 return format; 2121 } 2122 2123 /** 2124 * Creates a minimal video format. 2125 * @param mime The mime type of the content. 2126 * @param width The width of the content (in pixels) 2127 * @param height The height of the content (in pixels) 2128 */ createVideoFormat( @onNull String mime, int width, int height)2129 public static final @NonNull MediaFormat createVideoFormat( 2130 @NonNull String mime, 2131 int width, 2132 int height) { 2133 MediaFormat format = new MediaFormat(); 2134 format.setString(KEY_MIME, mime); 2135 format.setInteger(KEY_WIDTH, width); 2136 format.setInteger(KEY_HEIGHT, height); 2137 2138 return format; 2139 } 2140 2141 @Override toString()2142 public @NonNull String toString() { 2143 return mMap.toString(); 2144 } 2145 } 2146