1 /* 2 * Copyright (C) 2010 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 import android.hardware.Camera; 24 import android.hardware.Camera.CameraInfo; 25 import android.hardware.camera2.CameraManager; 26 import android.hardware.camera2.CameraMetadata; 27 import android.os.Build; 28 29 import java.lang.annotation.Retention; 30 import java.lang.annotation.RetentionPolicy; 31 32 /** 33 * Retrieves the 34 * predefined camcorder profile settings for camcorder applications. 35 * These settings are read-only. 36 * 37 * <p>The compressed output from a recording session with a given 38 * CamcorderProfile contains two tracks: one for audio and one for video. 39 * 40 * <p>Each profile specifies the following set of parameters: 41 * <ul> 42 * <li> The file output format 43 * <li> Video codec format 44 * <li> Video bit rate in bits per second 45 * <li> Video frame rate in frames per second 46 * <li> Video frame width and height, 47 * <li> Audio codec format 48 * <li> Audio bit rate in bits per second, 49 * <li> Audio sample rate 50 * <li> Number of audio channels for recording. 51 * </ul> 52 */ 53 public class CamcorderProfile 54 { 55 // Do not change these values/ordinals without updating their counterpart 56 // in include/media/MediaProfiles.h! 57 58 /** 59 * Quality level corresponding to the lowest available resolution. 60 */ 61 public static final int QUALITY_LOW = 0; 62 63 /** 64 * Quality level corresponding to the highest available resolution. 65 */ 66 public static final int QUALITY_HIGH = 1; 67 68 /** 69 * Quality level corresponding to the qcif (176 x 144) resolution. 70 */ 71 public static final int QUALITY_QCIF = 2; 72 73 /** 74 * Quality level corresponding to the cif (352 x 288) resolution. 75 */ 76 public static final int QUALITY_CIF = 3; 77 78 /** 79 * Quality level corresponding to the 480p (720 x 480) resolution. 80 * Note that the horizontal resolution for 480p can also be other 81 * values, such as 640 or 704, instead of 720. 82 */ 83 public static final int QUALITY_480P = 4; 84 85 /** 86 * Quality level corresponding to the 720p (1280 x 720) resolution. 87 */ 88 public static final int QUALITY_720P = 5; 89 90 /** 91 * Quality level corresponding to the 1080p (1920 x 1080) resolution. 92 * Note that the vertical resolution for 1080p can also be 1088, 93 * instead of 1080 (used by some vendors to avoid cropping during 94 * video playback). 95 */ 96 public static final int QUALITY_1080P = 6; 97 98 /** 99 * Quality level corresponding to the QVGA (320x240) resolution. 100 */ 101 public static final int QUALITY_QVGA = 7; 102 103 /** 104 * Quality level corresponding to the 2160p (3840x2160) resolution. 105 */ 106 public static final int QUALITY_2160P = 8; 107 108 /** 109 * Quality level corresponding to the VGA (640 x 480) resolution. 110 */ 111 public static final int QUALITY_VGA = 9; 112 113 /** 114 * Quality level corresponding to 4k-DCI (4096 x 2160) resolution. 115 */ 116 public static final int QUALITY_4KDCI = 10; 117 118 /** 119 * Quality level corresponding to QHD (2560 x 1440) resolution 120 */ 121 public static final int QUALITY_QHD = 11; 122 123 /** 124 * Quality level corresponding to 2K (2048 x 1080) resolution 125 */ 126 public static final int QUALITY_2K = 12; 127 128 /** 129 * Quality level corresponding to 8K UHD (7680 x 4320) resolution 130 */ 131 public static final int QUALITY_8KUHD = 13; 132 133 // Start and end of quality list 134 private static final int QUALITY_LIST_START = QUALITY_LOW; 135 private static final int QUALITY_LIST_END = QUALITY_8KUHD; 136 137 /** 138 * Time lapse quality level corresponding to the lowest available resolution. 139 */ 140 public static final int QUALITY_TIME_LAPSE_LOW = 1000; 141 142 /** 143 * Time lapse quality level corresponding to the highest available resolution. 144 */ 145 public static final int QUALITY_TIME_LAPSE_HIGH = 1001; 146 147 /** 148 * Time lapse quality level corresponding to the qcif (176 x 144) resolution. 149 */ 150 public static final int QUALITY_TIME_LAPSE_QCIF = 1002; 151 152 /** 153 * Time lapse quality level corresponding to the cif (352 x 288) resolution. 154 */ 155 public static final int QUALITY_TIME_LAPSE_CIF = 1003; 156 157 /** 158 * Time lapse quality level corresponding to the 480p (720 x 480) resolution. 159 */ 160 public static final int QUALITY_TIME_LAPSE_480P = 1004; 161 162 /** 163 * Time lapse quality level corresponding to the 720p (1280 x 720) resolution. 164 */ 165 public static final int QUALITY_TIME_LAPSE_720P = 1005; 166 167 /** 168 * Time lapse quality level corresponding to the 1080p (1920 x 1088) resolution. 169 */ 170 public static final int QUALITY_TIME_LAPSE_1080P = 1006; 171 172 /** 173 * Time lapse quality level corresponding to the QVGA (320 x 240) resolution. 174 */ 175 public static final int QUALITY_TIME_LAPSE_QVGA = 1007; 176 177 /** 178 * Time lapse quality level corresponding to the 2160p (3840 x 2160) resolution. 179 */ 180 public static final int QUALITY_TIME_LAPSE_2160P = 1008; 181 182 /** 183 * Time lapse quality level corresponding to the VGA (640 x 480) resolution. 184 */ 185 public static final int QUALITY_TIME_LAPSE_VGA = 1009; 186 187 /** 188 * Time lapse quality level corresponding to the 4k-DCI (4096 x 2160) resolution. 189 */ 190 public static final int QUALITY_TIME_LAPSE_4KDCI = 1010; 191 192 /** 193 * Time lapse quality level corresponding to the QHD (2560 x 1440) resolution. 194 */ 195 public static final int QUALITY_TIME_LAPSE_QHD = 1011; 196 197 /** 198 * Time lapse quality level corresponding to the 2K (2048 x 1080) resolution. 199 */ 200 public static final int QUALITY_TIME_LAPSE_2K = 1012; 201 202 /** 203 * Time lapse quality level corresponding to the 8K UHD (7680 x 4320) resolution. 204 */ 205 public static final int QUALITY_TIME_LAPSE_8KUHD = 1013; 206 207 // Start and end of timelapse quality list 208 private static final int QUALITY_TIME_LAPSE_LIST_START = QUALITY_TIME_LAPSE_LOW; 209 private static final int QUALITY_TIME_LAPSE_LIST_END = QUALITY_TIME_LAPSE_8KUHD; 210 211 /** 212 * High speed ( >= 100fps) quality level corresponding to the lowest available resolution. 213 * <p> 214 * For all the high speed profiles defined below ((from {@link #QUALITY_HIGH_SPEED_LOW} to 215 * {@link #QUALITY_HIGH_SPEED_2160P}), they are similar as normal recording profiles, with just 216 * higher output frame rate and bit rate. Therefore, setting these profiles with 217 * {@link MediaRecorder#setProfile} without specifying any other encoding parameters will 218 * produce high speed videos rather than slow motion videos that have different capture and 219 * output (playback) frame rates. To record slow motion videos, the application must set video 220 * output (playback) frame rate and bit rate appropriately via 221 * {@link MediaRecorder#setVideoFrameRate} and {@link MediaRecorder#setVideoEncodingBitRate} 222 * based on the slow motion factor. If the application intends to do the video recording with 223 * {@link MediaCodec} encoder, it must set each individual field of {@link MediaFormat} 224 * similarly according to this CamcorderProfile. 225 * </p> 226 * 227 * @see #videoBitRate 228 * @see #videoFrameRate 229 * @see MediaRecorder 230 * @see MediaCodec 231 * @see MediaFormat 232 */ 233 public static final int QUALITY_HIGH_SPEED_LOW = 2000; 234 235 /** 236 * High speed ( >= 100fps) quality level corresponding to the highest available resolution. 237 */ 238 public static final int QUALITY_HIGH_SPEED_HIGH = 2001; 239 240 /** 241 * High speed ( >= 100fps) quality level corresponding to the 480p (720 x 480) resolution. 242 * 243 * Note that the horizontal resolution for 480p can also be other 244 * values, such as 640 or 704, instead of 720. 245 */ 246 public static final int QUALITY_HIGH_SPEED_480P = 2002; 247 248 /** 249 * High speed ( >= 100fps) quality level corresponding to the 720p (1280 x 720) resolution. 250 */ 251 public static final int QUALITY_HIGH_SPEED_720P = 2003; 252 253 /** 254 * High speed ( >= 100fps) quality level corresponding to the 1080p (1920 x 1080 or 1920x1088) 255 * resolution. 256 */ 257 public static final int QUALITY_HIGH_SPEED_1080P = 2004; 258 259 /** 260 * High speed ( >= 100fps) quality level corresponding to the 2160p (3840 x 2160) 261 * resolution. 262 */ 263 public static final int QUALITY_HIGH_SPEED_2160P = 2005; 264 265 /** 266 * High speed ( >= 100fps) quality level corresponding to the CIF (352 x 288) 267 */ 268 public static final int QUALITY_HIGH_SPEED_CIF = 2006; 269 270 /** 271 * High speed ( >= 100fps) quality level corresponding to the VGA (640 x 480) 272 */ 273 public static final int QUALITY_HIGH_SPEED_VGA = 2007; 274 275 /** 276 * High speed ( >= 100fps) quality level corresponding to the 4K-DCI (4096 x 2160) 277 */ 278 public static final int QUALITY_HIGH_SPEED_4KDCI = 2008; 279 280 // Start and end of high speed quality list 281 private static final int QUALITY_HIGH_SPEED_LIST_START = QUALITY_HIGH_SPEED_LOW; 282 private static final int QUALITY_HIGH_SPEED_LIST_END = QUALITY_HIGH_SPEED_4KDCI; 283 284 /** 285 * @hide 286 */ 287 @IntDef({ 288 QUALITY_LOW, 289 QUALITY_HIGH, 290 QUALITY_QCIF, 291 QUALITY_CIF, 292 QUALITY_480P, 293 QUALITY_720P, 294 QUALITY_1080P, 295 QUALITY_QVGA, 296 QUALITY_2160P, 297 QUALITY_VGA, 298 QUALITY_4KDCI, 299 QUALITY_QHD, 300 QUALITY_2K, 301 QUALITY_8KUHD, 302 303 QUALITY_TIME_LAPSE_LOW , 304 QUALITY_TIME_LAPSE_HIGH, 305 QUALITY_TIME_LAPSE_QCIF, 306 QUALITY_TIME_LAPSE_CIF, 307 QUALITY_TIME_LAPSE_480P, 308 QUALITY_TIME_LAPSE_720P, 309 QUALITY_TIME_LAPSE_1080P, 310 QUALITY_TIME_LAPSE_QVGA, 311 QUALITY_TIME_LAPSE_2160P, 312 QUALITY_TIME_LAPSE_VGA, 313 QUALITY_TIME_LAPSE_4KDCI, 314 QUALITY_TIME_LAPSE_QHD, 315 QUALITY_TIME_LAPSE_2K, 316 QUALITY_TIME_LAPSE_8KUHD, 317 318 QUALITY_HIGH_SPEED_LOW, 319 QUALITY_HIGH_SPEED_HIGH, 320 QUALITY_HIGH_SPEED_480P, 321 QUALITY_HIGH_SPEED_720P, 322 QUALITY_HIGH_SPEED_1080P, 323 QUALITY_HIGH_SPEED_2160P, 324 QUALITY_HIGH_SPEED_CIF, 325 QUALITY_HIGH_SPEED_VGA, 326 QUALITY_HIGH_SPEED_4KDCI, 327 }) 328 @Retention(RetentionPolicy.SOURCE) 329 public @interface Quality {} 330 331 /** 332 * Default recording duration in seconds before the session is terminated. 333 * This is useful for applications like MMS has limited file size requirement. 334 */ 335 public int duration; 336 337 /** 338 * The quality level of the camcorder profile 339 */ 340 public int quality; 341 342 /** 343 * The file output format of the camcorder profile 344 * @see android.media.MediaRecorder.OutputFormat 345 */ 346 public int fileFormat; 347 348 /** 349 * The video encoder being used for the video track 350 * @see android.media.MediaRecorder.VideoEncoder 351 */ 352 public int videoCodec; 353 354 /** 355 * The target video output bit rate in bits per second 356 * <p> 357 * This is the target recorded video output bit rate if the application configures the video 358 * recording via {@link MediaRecorder#setProfile} without specifying any other 359 * {@link MediaRecorder} encoding parameters. For example, for high speed quality profiles (from 360 * {@link #QUALITY_HIGH_SPEED_LOW} to {@link #QUALITY_HIGH_SPEED_2160P}), this is the bit rate 361 * where the video is recorded with. If the application intends to record slow motion videos 362 * with the high speed quality profiles, it must set a different video bit rate that is 363 * corresponding to the desired recording output bit rate (i.e., the encoded video bit rate 364 * during normal playback) via {@link MediaRecorder#setVideoEncodingBitRate}. For example, if 365 * {@link #QUALITY_HIGH_SPEED_720P} advertises 240fps {@link #videoFrameRate} and 64Mbps 366 * {@link #videoBitRate} in the high speed CamcorderProfile, and the application intends to 367 * record 1/8 factor slow motion recording videos, the application must set 30fps via 368 * {@link MediaRecorder#setVideoFrameRate} and 8Mbps ( {@link #videoBitRate} * slow motion 369 * factor) via {@link MediaRecorder#setVideoEncodingBitRate}. Failing to do so will result in 370 * videos with unexpected frame rate and bit rate, or {@link MediaRecorder} error if the output 371 * bit rate exceeds the encoder limit. If the application intends to do the video recording with 372 * {@link MediaCodec} encoder, it must set each individual field of {@link MediaFormat} 373 * similarly according to this CamcorderProfile. 374 * </p> 375 * 376 * @see #videoFrameRate 377 * @see MediaRecorder 378 * @see MediaCodec 379 * @see MediaFormat 380 */ 381 public int videoBitRate; 382 383 /** 384 * The target video frame rate in frames per second. 385 * <p> 386 * This is the target recorded video output frame rate per second if the application configures 387 * the video recording via {@link MediaRecorder#setProfile} without specifying any other 388 * {@link MediaRecorder} encoding parameters. For example, for high speed quality profiles (from 389 * {@link #QUALITY_HIGH_SPEED_LOW} to {@link #QUALITY_HIGH_SPEED_2160P}), this is the frame rate 390 * where the video is recorded and played back with. If the application intends to create slow 391 * motion use case with the high speed quality profiles, it must set a different video frame 392 * rate that is corresponding to the desired output (playback) frame rate via 393 * {@link MediaRecorder#setVideoFrameRate}. For example, if {@link #QUALITY_HIGH_SPEED_720P} 394 * advertises 240fps {@link #videoFrameRate} in the CamcorderProfile, and the application 395 * intends to create 1/8 factor slow motion recording videos, the application must set 30fps via 396 * {@link MediaRecorder#setVideoFrameRate}. Failing to do so will result in high speed videos 397 * with normal speed playback frame rate (240fps for above example). If the application intends 398 * to do the video recording with {@link MediaCodec} encoder, it must set each individual field 399 * of {@link MediaFormat} similarly according to this CamcorderProfile. 400 * </p> 401 * 402 * @see #videoBitRate 403 * @see MediaRecorder 404 * @see MediaCodec 405 * @see MediaFormat 406 */ 407 public int videoFrameRate; 408 409 /** 410 * The target video frame width in pixels 411 */ 412 public int videoFrameWidth; 413 414 /** 415 * The target video frame height in pixels 416 */ 417 public int videoFrameHeight; 418 419 /** 420 * The audio encoder being used for the audio track. 421 * @see android.media.MediaRecorder.AudioEncoder 422 */ 423 public int audioCodec; 424 425 /** 426 * The target audio output bit rate in bits per second 427 */ 428 public int audioBitRate; 429 430 /** 431 * The audio sampling rate used for the audio track 432 */ 433 public int audioSampleRate; 434 435 /** 436 * The number of audio channels used for the audio track 437 */ 438 public int audioChannels; 439 440 /** 441 * Returns the default camcorder profile at the given quality level for the first back-facing 442 * camera on the device. If the device has no back-facing camera, this returns null. 443 * @param quality the target quality level for the camcorder profile 444 * @see #get(int, int) 445 * @deprecated Use {@link #getAll} instead 446 */ get(int quality)447 public static CamcorderProfile get(int quality) { 448 int numberOfCameras = Camera.getNumberOfCameras(); 449 CameraInfo cameraInfo = new CameraInfo(); 450 for (int i = 0; i < numberOfCameras; i++) { 451 Camera.getCameraInfo(i, cameraInfo); 452 if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { 453 return get(i, quality); 454 } 455 } 456 return null; 457 } 458 459 /** 460 * Returns the default camcorder profile for the given camera at the given quality level. 461 * 462 * Quality levels QUALITY_LOW, QUALITY_HIGH are guaranteed to be supported, while 463 * other levels may or may not be supported. The supported levels can be checked using 464 * {@link #hasProfile(int, int)}. 465 * QUALITY_LOW refers to the lowest quality available, while QUALITY_HIGH refers to 466 * the highest quality available. 467 * QUALITY_LOW/QUALITY_HIGH have to match one of qcif, cif, 480p, 720p, 1080p or 2160p. 468 * E.g. if the device supports 480p, 720p, 1080p and 2160p, then low is 480p and high is 469 * 2160p. 470 * 471 * The same is true for time lapse quality levels, i.e. QUALITY_TIME_LAPSE_LOW, 472 * QUALITY_TIME_LAPSE_HIGH are guaranteed to be supported and have to match one of 473 * qcif, cif, 480p, 720p, 1080p, or 2160p. 474 * 475 * For high speed quality levels, they may or may not be supported. If a subset of the levels 476 * are supported, QUALITY_HIGH_SPEED_LOW and QUALITY_HIGH_SPEED_HIGH are guaranteed to be 477 * supported and have to match one of 480p, 720p, or 1080p. 478 * 479 * A camcorder recording session with higher quality level usually has higher output 480 * bit rate, better video and/or audio recording quality, larger video frame 481 * resolution and higher audio sampling rate, etc, than those with lower quality 482 * level. 483 * 484 * @param cameraId the id for the camera. Integer camera ids parsed from the list received by 485 * invoking {@link CameraManager#getCameraIdList} can be used as long as they 486 * are {@link CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE} 487 * and not 488 * {@link CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL EXTERNAL}. 489 * @param quality the target quality level for the camcorder profile. 490 * @see #QUALITY_LOW 491 * @see #QUALITY_HIGH 492 * @see #QUALITY_QCIF 493 * @see #QUALITY_CIF 494 * @see #QUALITY_480P 495 * @see #QUALITY_720P 496 * @see #QUALITY_1080P 497 * @see #QUALITY_2160P 498 * @see #QUALITY_TIME_LAPSE_LOW 499 * @see #QUALITY_TIME_LAPSE_HIGH 500 * @see #QUALITY_TIME_LAPSE_QCIF 501 * @see #QUALITY_TIME_LAPSE_CIF 502 * @see #QUALITY_TIME_LAPSE_480P 503 * @see #QUALITY_TIME_LAPSE_720P 504 * @see #QUALITY_TIME_LAPSE_1080P 505 * @see #QUALITY_TIME_LAPSE_2160P 506 * @see #QUALITY_HIGH_SPEED_LOW 507 * @see #QUALITY_HIGH_SPEED_HIGH 508 * @see #QUALITY_HIGH_SPEED_480P 509 * @see #QUALITY_HIGH_SPEED_720P 510 * @see #QUALITY_HIGH_SPEED_1080P 511 * @see #QUALITY_HIGH_SPEED_2160P 512 * @deprecated Use {@link #getAll} instead 513 * @throws IllegalArgumentException if quality is not one of the defined QUALITY_ values. 514 */ get(int cameraId, int quality)515 public static CamcorderProfile get(int cameraId, int quality) { 516 if (!((quality >= QUALITY_LIST_START && 517 quality <= QUALITY_LIST_END) || 518 (quality >= QUALITY_TIME_LAPSE_LIST_START && 519 quality <= QUALITY_TIME_LAPSE_LIST_END) || 520 (quality >= QUALITY_HIGH_SPEED_LIST_START && 521 quality <= QUALITY_HIGH_SPEED_LIST_END))) { 522 String errMessage = "Unsupported quality level: " + quality; 523 throw new IllegalArgumentException(errMessage); 524 } 525 return native_get_camcorder_profile(cameraId, quality); 526 } 527 528 /** 529 * Returns all encoder profiles of a camcorder profile for the given camera at 530 * the given quality level. 531 * 532 * Quality levels QUALITY_LOW, QUALITY_HIGH are guaranteed to be supported, while 533 * other levels may or may not be supported. The supported levels can be checked using 534 * {@link #hasProfile(int, int)}. 535 * QUALITY_LOW refers to the lowest quality available, while QUALITY_HIGH refers to 536 * the highest quality available. 537 * QUALITY_LOW/QUALITY_HIGH have to match one of qcif, cif, 480p, 720p, 1080p or 2160p. 538 * E.g. if the device supports 480p, 720p, 1080p and 2160p, then low is 480p and high is 539 * 2160p. 540 * 541 * The same is true for time lapse quality levels, i.e. QUALITY_TIME_LAPSE_LOW, 542 * QUALITY_TIME_LAPSE_HIGH are guaranteed to be supported and have to match one of 543 * qcif, cif, 480p, 720p, 1080p, or 2160p. 544 * 545 * For high speed quality levels, they may or may not be supported. If a subset of the levels 546 * are supported, QUALITY_HIGH_SPEED_LOW and QUALITY_HIGH_SPEED_HIGH are guaranteed to be 547 * supported and have to match one of 480p, 720p, or 1080p. 548 * 549 * A camcorder recording session with higher quality level usually has higher output 550 * bit rate, better video and/or audio recording quality, larger video frame 551 * resolution and higher audio sampling rate, etc, than those with lower quality 552 * level. 553 * 554 * @param cameraId the id for the camera. Numeric camera ids from the list received by invoking 555 * {@link CameraManager#getCameraIdList} can be used as long as they are 556 * {@link CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE} 557 * and not 558 * {@link CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL EXTERNAL}. 559 * @param quality the target quality level for the camcorder profile. 560 * @return null if there are no encoder profiles defined for the quality level for the 561 * given camera. 562 * @throws IllegalArgumentException if quality is not one of the defined QUALITY_ values. 563 * @see #QUALITY_LOW 564 * @see #QUALITY_HIGH 565 * @see #QUALITY_QCIF 566 * @see #QUALITY_CIF 567 * @see #QUALITY_480P 568 * @see #QUALITY_720P 569 * @see #QUALITY_1080P 570 * @see #QUALITY_2160P 571 * @see #QUALITY_TIME_LAPSE_LOW 572 * @see #QUALITY_TIME_LAPSE_HIGH 573 * @see #QUALITY_TIME_LAPSE_QCIF 574 * @see #QUALITY_TIME_LAPSE_CIF 575 * @see #QUALITY_TIME_LAPSE_480P 576 * @see #QUALITY_TIME_LAPSE_720P 577 * @see #QUALITY_TIME_LAPSE_1080P 578 * @see #QUALITY_TIME_LAPSE_2160P 579 * @see #QUALITY_HIGH_SPEED_LOW 580 * @see #QUALITY_HIGH_SPEED_HIGH 581 * @see #QUALITY_HIGH_SPEED_480P 582 * @see #QUALITY_HIGH_SPEED_720P 583 * @see #QUALITY_HIGH_SPEED_1080P 584 * @see #QUALITY_HIGH_SPEED_2160P 585 */ getAll( @onNull String cameraId, @Quality int quality)586 @Nullable public static EncoderProfiles getAll( 587 @NonNull String cameraId, @Quality int quality) { 588 if (!((quality >= QUALITY_LIST_START && 589 quality <= QUALITY_LIST_END) || 590 (quality >= QUALITY_TIME_LAPSE_LIST_START && 591 quality <= QUALITY_TIME_LAPSE_LIST_END) || 592 (quality >= QUALITY_HIGH_SPEED_LIST_START && 593 quality <= QUALITY_HIGH_SPEED_LIST_END))) { 594 String errMessage = "Unsupported quality level: " + quality; 595 throw new IllegalArgumentException(errMessage); 596 } 597 598 // TODO: get all profiles 599 int id; 600 try { 601 id = Integer.valueOf(cameraId); 602 } catch (NumberFormatException e) { 603 return null; 604 } 605 return native_get_camcorder_profiles(id, quality); 606 } 607 608 /** 609 * Returns true if a camcorder profile exists for the first back-facing 610 * camera at the given quality level. 611 * 612 * <p> 613 * When using the Camera 2 API in {@code LEGACY} mode (i.e. when 614 * {@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL} is set 615 * to 616 * {@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY}), 617 * {@link #hasProfile} may return {@code true} for unsupported resolutions. To ensure a 618 * a given resolution is supported in LEGACY mode, the configuration given in 619 * {@link android.hardware.camera2.CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP} 620 * must contain the the resolution in the supported output sizes. The recommended way to check 621 * this is with 622 * {@link android.hardware.camera2.params.StreamConfigurationMap#getOutputSizes(Class)} with the 623 * class of the desired recording endpoint, and check that the desired resolution is contained 624 * in the list returned. 625 * </p> 626 * @see android.hardware.camera2.CameraManager 627 * @see android.hardware.camera2.CameraCharacteristics 628 * 629 * @param quality the target quality level for the camcorder profile 630 */ hasProfile(int quality)631 public static boolean hasProfile(int quality) { 632 int numberOfCameras = Camera.getNumberOfCameras(); 633 CameraInfo cameraInfo = new CameraInfo(); 634 for (int i = 0; i < numberOfCameras; i++) { 635 Camera.getCameraInfo(i, cameraInfo); 636 if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { 637 return hasProfile(i, quality); 638 } 639 } 640 return false; 641 } 642 643 /** 644 * Returns true if a camcorder profile exists for the given camera at 645 * the given quality level. 646 * 647 * <p> 648 * When using the Camera 2 API in LEGACY mode (i.e. when 649 * {@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL} is set 650 * to 651 * {@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY}), 652 * {@link #hasProfile} may return {@code true} for unsupported resolutions. To ensure a 653 * a given resolution is supported in LEGACY mode, the configuration given in 654 * {@link android.hardware.camera2.CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP} 655 * must contain the the resolution in the supported output sizes. The recommended way to check 656 * this is with 657 * {@link android.hardware.camera2.params.StreamConfigurationMap#getOutputSizes(Class)} with the 658 * class of the desired recording endpoint, and check that the desired resolution is contained 659 * in the list returned. 660 * </p> 661 * @see android.hardware.camera2.CameraManager 662 * @see android.hardware.camera2.CameraCharacteristics 663 * 664 * @param cameraId the id for the camera. Integer camera ids parsed from the list received by 665 * invoking {@link CameraManager#getCameraIdList} can be used as long as they 666 * are {@link CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE} 667 * and not 668 * {@link CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL EXTERNAL}. 669 * @param quality the target quality level for the camcorder profile 670 */ hasProfile(int cameraId, int quality)671 public static boolean hasProfile(int cameraId, int quality) { 672 return native_has_camcorder_profile(cameraId, quality); 673 } 674 675 static { 676 System.loadLibrary("media_jni"); native_init()677 native_init(); 678 } 679 680 // Private constructor called by JNI CamcorderProfile(int duration, int quality, int fileFormat, int videoCodec, int videoBitRate, int videoFrameRate, int videoWidth, int videoHeight, int audioCodec, int audioBitRate, int audioSampleRate, int audioChannels)681 private CamcorderProfile(int duration, 682 int quality, 683 int fileFormat, 684 int videoCodec, 685 int videoBitRate, 686 int videoFrameRate, 687 int videoWidth, 688 int videoHeight, 689 int audioCodec, 690 int audioBitRate, 691 int audioSampleRate, 692 int audioChannels) { 693 694 this.duration = duration; 695 this.quality = quality; 696 this.fileFormat = fileFormat; 697 this.videoCodec = videoCodec; 698 this.videoBitRate = videoBitRate; 699 this.videoFrameRate = videoFrameRate; 700 this.videoFrameWidth = videoWidth; 701 this.videoFrameHeight = videoHeight; 702 this.audioCodec = audioCodec; 703 this.audioBitRate = audioBitRate; 704 this.audioSampleRate = audioSampleRate; 705 this.audioChannels = audioChannels; 706 } 707 708 // Methods implemented by JNI 709 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) native_init()710 private static native final void native_init(); 711 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) native_get_camcorder_profile( int cameraId, int quality)712 private static native final CamcorderProfile native_get_camcorder_profile( 713 int cameraId, int quality); native_get_camcorder_profiles( int cameraId, int quality)714 private static native final EncoderProfiles native_get_camcorder_profiles( 715 int cameraId, int quality); native_has_camcorder_profile( int cameraId, int quality)716 private static native final boolean native_has_camcorder_profile( 717 int cameraId, int quality); 718 } 719