CameraCapabilities.java revision c36e3c983c232dc45ed31f3d8e98d8cdd7ac14ba
1/* 2 * Copyright (C) 2014 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 17package com.android.ex.camera2.portability; 18 19import android.graphics.Point; 20 21import com.android.ex.camera2.portability.debug.Log; 22 23import java.util.ArrayList; 24import java.util.EnumSet; 25import java.util.HashSet; 26import java.util.List; 27import java.util.Set; 28import java.util.TreeSet; 29 30public class CameraCapabilities { 31 32 private static Log.Tag TAG = new Log.Tag("CameraCapabilities"); 33 34 protected final ArrayList<int[]> mSupportedPreviewFpsRange = new ArrayList<int[]>(); 35 protected final ArrayList<Point> mSupportedPreviewSizes = new ArrayList<Point>(); 36 protected final TreeSet<Integer> mSupportedPreviewFormats = new TreeSet<Integer>(); 37 protected final ArrayList<Point> mSupportedVideoSizes = new ArrayList<Point>(); 38 protected final ArrayList<Point> mSupportedPictureSizes = new ArrayList<Point>(); 39 protected final TreeSet<Integer> mSupportedPictureFormats = new TreeSet<Integer>(); 40 protected final EnumSet<SceneMode> mSupportedSceneModes = EnumSet.noneOf(SceneMode.class); 41 protected final EnumSet<FlashMode> mSupportedFlashModes = EnumSet.noneOf(FlashMode.class); 42 protected final EnumSet<FocusMode> mSupportedFocusModes = EnumSet.noneOf(FocusMode.class); 43 protected final EnumSet<WhiteBalance> mSupportedWhiteBalances = 44 EnumSet.noneOf(WhiteBalance.class); 45 protected final EnumSet<Feature> mSupportedFeatures = EnumSet.noneOf(Feature.class); 46 protected int mMinExposureCompensation; 47 protected int mMaxExposureCompensation; 48 protected float mExposureCompensationStep; 49 protected int mMaxNumOfFacesSupported; 50 protected int mMaxNumOfFocusAreas; 51 protected int mMaxNumOfMeteringArea; 52 private final Stringifier mStringifier; 53 54 // Focus modes. 55 public enum FocusMode { 56 /** 57 * Continuous auto focus mode intended for taking pictures. 58 * @see {@link android.hardware.Camera.Parameters#FOCUS_MODE_AUTO}. 59 */ 60 AUTO, 61 /** 62 * Continuous auto focus mode intended for taking pictures. 63 * @see {@link android.hardware.Camera.Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. 64 */ 65 CONTINUOUS_PICTURE, 66 /** 67 * Continuous auto focus mode intended for video recording. 68 * @see {@link android.hardware.Camera.Parameters#FOCUS_MODE_CONTINUOUS_VIDEO}. 69 */ 70 CONTINUOUS_VIDEO, 71 /** 72 * Extended depth of field (EDOF). 73 * @see {@link android.hardware.Camera.Parameters#FOCUS_MODE_EDOF}. 74 */ 75 EXTENDED_DOF, 76 /** 77 * Focus is fixed. 78 * @see {@link android.hardware.Camera.Parameters#FOCUS_MODE_FIXED}. 79 */ 80 FIXED, 81 /** 82 * Focus is set at infinity. 83 * @see {@link android.hardware.Camera.Parameters#FOCUS_MODE_INFINITY}. 84 */ 85 INFINITY, 86 /** 87 * Macro (close-up) focus mode. 88 * @see {@link android.hardware.Camera.Parameters#FOCUS_MODE_MACRO}. 89 */ 90 MACRO, 91 } 92 93 // Flash modes. 94 public enum FlashMode { 95 /** 96 * Flash will be fired automatically when required. 97 * @see {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}. 98 */ 99 AUTO, 100 /** 101 * Flash will not be fired. 102 * @see {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}. 103 */ 104 OFF, 105 /** 106 * Flash will always be fired during snapshot. 107 * @see {@link android.hardware.Camera.Parameters#FLASH_MODE_ON}. 108 */ 109 ON, 110 /** 111 * Constant emission of light during preview, auto-focus and snapshot. 112 * @see {@link android.hardware.Camera.Parameters#FLASH_MODE_TORCH}. 113 */ 114 TORCH, 115 /** 116 * Flash will be fired in red-eye reduction mode. 117 * @see {@link android.hardware.Camera.Parameters#FLASH_MODE_RED_EYE}. 118 */ 119 RED_EYE, 120 } 121 122 public enum SceneMode { 123 /** 124 * Scene mode is off. 125 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_AUTO}. 126 */ 127 AUTO, 128 /** 129 * Take photos of fast moving objects. 130 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_ACTION}. 131 */ 132 ACTION, 133 /** 134 * Applications are looking for a barcode. 135 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_BARCODE}. 136 */ 137 BARCODE, 138 /** 139 * Take pictures on the beach. 140 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_BEACH}. 141 */ 142 BEACH, 143 /** 144 * Capture the naturally warm color of scenes lit by candles. 145 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_CANDLELIGHT}. 146 */ 147 CANDLELIGHT, 148 /** 149 * For shooting firework displays. 150 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_FIREWORKS}. 151 */ 152 FIREWORKS, 153 /** 154 * Capture a scene using high dynamic range imaging techniques. 155 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_HDR}. 156 */ 157 HDR, 158 /** 159 * Take pictures on distant objects. 160 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_LANDSCAPE}. 161 */ 162 LANDSCAPE, 163 /** 164 * Take photos at night. 165 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_NIGHT}. 166 */ 167 NIGHT, 168 /** 169 * Take people pictures at night. 170 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_NIGHT_PORTRAIT}. 171 */ 172 NIGHT_PORTRAIT, 173 /** 174 * Take indoor low-light shot. 175 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_PARTY}. 176 */ 177 PARTY, 178 /** 179 * Take people pictures. 180 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_PORTRAIT}. 181 */ 182 PORTRAIT, 183 /** 184 * Take pictures on the snow. 185 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_SNOW}. 186 */ 187 SNOW, 188 /** 189 * Take photos of fast moving objects. 190 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_SPORTS}. 191 */ 192 SPORTS, 193 /** 194 * Avoid blurry pictures (for example, due to hand shake). 195 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_STEADYPHOTO}. 196 */ 197 STEADYPHOTO, 198 /** 199 * Take sunset photos. 200 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_SUNSET}. 201 */ 202 SUNSET, 203 /** 204 * Take photos in a theater. 205 * @see {@link android.hardware.Camera.Parameters#SCENE_MODE_THEATRE}. 206 */ 207 THEATRE, 208 } 209 210 // White balances. 211 public enum WhiteBalance { 212 /** 213 * @see {@link android.hardware.Camera.Parameters#WHITE_BALANCE_AUTO}. 214 */ 215 AUTO, 216 /** 217 * @see {@link android.hardware.Camera.Parameters#WHITE_BALANCE_CLOUDY_DAYLIGHT}. 218 */ 219 CLOUDY_DAYLIGHT, 220 /** 221 * @see {@link android.hardware.Camera.Parameters#WHITE_BALANCE_DAYLIGHT}. 222 */ 223 DAYLIGHT, 224 /** 225 * @see {@link android.hardware.Camera.Parameters#WHITE_BALANCE_FLUORESCENT}. 226 */ 227 FLUORESCENT, 228 /** 229 * @see {@link android.hardware.Camera.Parameters#WHITE_BALANCE_INCANDESCENT}. 230 */ 231 INCANDESCENT, 232 /** 233 * @see {@link android.hardware.Camera.Parameters#WHITE_BALANCE_SHADE}. 234 */ 235 SHADE, 236 /** 237 * @see {@link android.hardware.Camera.Parameters#WHITE_BALANCE_TWILIGHT}. 238 */ 239 TWILIGHT, 240 /** 241 * @see {@link android.hardware.Camera.Parameters#WHITE_BALANCE_WARM_FLUORESCENT}. 242 */ 243 WARM_FLUORESCENT, 244 } 245 246 public enum Feature { 247 /** 248 * Support zoom-related methods. 249 */ 250 ZOOM, 251 /** 252 * Support for photo capturing during video recording. 253 */ 254 VIDEO_SNAPSHOT, 255 /** 256 * Support for focus area settings. 257 */ 258 FOCUS_AREA, 259 /** 260 * Support for metering area settings. 261 */ 262 METERING_AREA, 263 /** 264 * Support for automatic exposure lock. 265 */ 266 AUTO_EXPOSURE_LOCK, 267 /** 268 * Support for automatic white balance lock. 269 */ 270 AUTO_WHITE_BALANCE_LOCK, 271 } 272 273 /** 274 * A interface stringifier to convert abstract representations to API 275 * related string representation. 276 */ 277 public interface Stringifier { 278 /** 279 * Converts the focus mode to API-related string representation. 280 * 281 * @param focus The focus mode to convert. 282 * @return The string used by the camera framework API to represent the 283 * focus mode. 284 */ 285 String stringify(FocusMode focus); 286 287 /** 288 * Converts the API-related string representation of the focus mode to the 289 * abstract representation. 290 * 291 * @param val The string representation. 292 * @return The focus mode represented by the input string. 293 */ 294 FocusMode focusModeFromString(String val); 295 296 /** 297 * Converts the flash mode to API-related string representation. 298 * 299 * @param flash The focus mode to convert. 300 * @return The string used by the camera framework API to represent the 301 * flash mode. 302 */ 303 String stringify(FlashMode flash); 304 305 /** 306 * Converts the API-related string representation of the flash mode to the 307 * abstract representation. 308 * 309 * @param val The string representation. 310 * @return The flash mode represented by the input string. 311 */ 312 FlashMode flashModeFromString(String val); 313 314 /** 315 * Converts the scene mode to API-related string representation. 316 * 317 * @param scene The focus mode to convert. 318 * @return The string used by the camera framework API to represent the 319 * scene mode. 320 */ 321 String stringify(SceneMode scene); 322 323 /** 324 * Converts the API-related string representation of the scene mode to the 325 * abstract representation. 326 * 327 * @param val The string representation. 328 * @return The scene mode represented by the input string. 329 */ 330 SceneMode sceneModeFromString(String val); 331 332 /** 333 * Converts the white balance to API-related string representation. 334 * 335 * @param wb The focus mode to convert. 336 * @return The string used by the camera framework API to represent the 337 * white balance. 338 */ 339 String stringify(WhiteBalance wb); 340 341 /** 342 * Converts the API-related string representation of the white balance to 343 * the abstract representation. 344 * 345 * @param val The string representation. 346 * @return The white balance represented by the input string. 347 */ 348 WhiteBalance whiteBalanceFromString(String val); 349 } 350 351 /** 352 * constructor. 353 * @param mStringifier The stringifier used by this instance. 354 */ 355 CameraCapabilities(Stringifier mStringifier) { 356 this.mStringifier = mStringifier; 357 } 358 359 /** 360 * Copy constructor. 361 * @param src The source instance. 362 */ 363 public CameraCapabilities(CameraCapabilities src) { 364 mSupportedPreviewFpsRange.addAll(src.mSupportedPreviewFpsRange); 365 mSupportedPreviewSizes.addAll(src.mSupportedPreviewSizes); 366 mSupportedPreviewFormats.addAll(src.mSupportedPreviewFormats); 367 mSupportedVideoSizes.addAll(src.mSupportedVideoSizes); 368 mSupportedPictureSizes.addAll(src.mSupportedPictureSizes); 369 mSupportedPictureFormats.addAll(src.mSupportedPictureFormats); 370 mSupportedSceneModes.addAll(src.mSupportedSceneModes); 371 mSupportedFlashModes.addAll(src.mSupportedFlashModes); 372 mSupportedFocusModes.addAll(src.mSupportedFocusModes); 373 mSupportedWhiteBalances.addAll(src.mSupportedWhiteBalances); 374 mSupportedFeatures.addAll(src.mSupportedFeatures); 375 mMaxExposureCompensation = src.mMaxExposureCompensation; 376 mMinExposureCompensation = src.mMinExposureCompensation; 377 mExposureCompensationStep = src.mExposureCompensationStep; 378 mMaxNumOfFacesSupported = src.mMaxNumOfFacesSupported; 379 mMaxNumOfFocusAreas = src.mMaxNumOfFocusAreas; 380 mStringifier = src.mStringifier; 381 } 382 383 /** 384 * @return the supported picture formats. See {@link android.graphics.ImageFormat}. 385 */ 386 public Set<Integer> getSupportedPictureFormats() { 387 return new TreeSet<Integer>(mSupportedPictureFormats); 388 } 389 390 /** 391 * Gets the supported preview formats. 392 * @return The supported preview {@link android.graphics.ImageFormat}s. 393 */ 394 public Set<Integer> getSupportedPreviewFormats() { 395 return new TreeSet<Integer>(mSupportedPreviewFormats); 396 } 397 398 /** 399 * Gets the supported picture sizes. 400 */ 401 public List<Point> getSupportedPictureSizes() { 402 return new ArrayList<Point>(mSupportedPictureSizes); 403 } 404 405 406 /** 407 * @return The supported preview fps (frame-per-second) ranges. The returned 408 * list is sorted by maximum fps then minimum fps in a descending order. 409 * The values are multiplied by 1000. 410 */ 411 public final List<int[]> getSupportedPreviewFpsRange() { 412 return new ArrayList<int[]>(mSupportedPreviewFpsRange); 413 } 414 415 /** 416 * @return The supported preview sizes. The width and height are stored in 417 * Point.x and Point.y respectively and the list is sorted by width then 418 * height in a descending order. 419 */ 420 public final List<Point> getSupportedPreviewSizes() { 421 return new ArrayList<Point>(mSupportedPreviewSizes); 422 } 423 424 /** 425 * @return The supported video frame sizes that can be used by MediaRecorder. 426 * The width and height are stored in Point.x and Point.y respectively and 427 * the list is sorted by width then height in a descending order. 428 */ 429 public final List<Point> getSupportedVideoSizes() { 430 return new ArrayList<Point>(mSupportedVideoSizes); 431 } 432 433 /** 434 * @return The supported scene modes. 435 */ 436 public final Set<SceneMode> getSupportedSceneModes() { 437 return new HashSet<SceneMode>(mSupportedSceneModes); 438 } 439 440 /** 441 * @return Whether the scene mode is supported. 442 */ 443 public final boolean supports(SceneMode scene) { 444 return (scene != null && mSupportedSceneModes.contains(scene)); 445 } 446 447 /** 448 * @return The supported flash modes. 449 */ 450 public final Set<FlashMode> getSupportedFlashModes() { 451 return new HashSet<FlashMode>(mSupportedFlashModes); 452 } 453 454 /** 455 * @return Whether the flash mode is supported. 456 */ 457 public final boolean supports(FlashMode flash) { 458 return (flash != null && mSupportedFlashModes.contains(flash)); 459 } 460 461 /** 462 * @return The supported focus modes. 463 */ 464 public final Set<FocusMode> getSupportedFocusModes() { 465 return new HashSet<FocusMode>(mSupportedFocusModes); 466 } 467 468 /** 469 * @return Whether the focus mode is supported. 470 */ 471 public final boolean supports(FocusMode focus) { 472 return (focus != null && mSupportedFocusModes.contains(focus)); 473 } 474 475 /** 476 * @return The supported white balanceas. 477 */ 478 public final Set<WhiteBalance> getSupportedWhiteBalance() { 479 return new HashSet<WhiteBalance>(mSupportedWhiteBalances); 480 } 481 482 /** 483 * @return Whether the white balance is supported. 484 */ 485 public boolean supports(WhiteBalance wb) { 486 return (wb != null && mSupportedWhiteBalances.contains(wb)); 487 } 488 489 public final Set<Feature> getSupportedFeature() { 490 return new HashSet<Feature>(mSupportedFeatures); 491 } 492 493 public boolean supports(Feature ft) { 494 return (ft != null && mSupportedFeatures.contains(ft)); 495 } 496 497 /** 498 * @return The min exposure compensation index. The EV is the compensation 499 * index multiplied by the step value. If unsupported, both this method and 500 * {@link #getMaxExposureCompensation()} return 0. 501 */ 502 public final int getMinExposureCompensation() { 503 return mMinExposureCompensation; 504 } 505 506 /** 507 * @return The max exposure compensation index. The EV is the compensation 508 * index multiplied by the step value. If unsupported, both this method and 509 * {@link #getMinExposureCompensation()} return 0. 510 */ 511 public final int getMaxExposureCompensation() { 512 return mMaxExposureCompensation; 513 } 514 515 /** 516 * @return The exposure compensation step. The EV is the compensation index 517 * multiplied by the step value. 518 */ 519 public final float getExposureCompensationStep() { 520 return mExposureCompensationStep; 521 } 522 523 /** 524 * @return The max number of faces supported by the face detection. 0 if 525 * unsupported. 526 */ 527 public final int getMaxNumOfFacesSupported() { 528 return mMaxNumOfFacesSupported; 529 } 530 531 /** 532 * @return The stringifier used by this instance. 533 */ 534 public Stringifier getStringifier() { 535 return mStringifier; 536 } 537} 538