|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +package io.flutter.plugins.camera; |
| 6 | + |
| 7 | +import android.graphics.Rect; |
| 8 | +import android.hardware.camera2.CameraAccessException; |
| 9 | +import android.hardware.camera2.CameraCharacteristics; |
| 10 | +import android.hardware.camera2.CameraManager; |
| 11 | +import android.os.Build.VERSION_CODES; |
| 12 | +import android.util.Range; |
| 13 | +import android.util.Rational; |
| 14 | +import android.util.Size; |
| 15 | +import androidx.annotation.RequiresApi; |
| 16 | + |
| 17 | +/** An interface allowing access to the different characteristics of the device's camera. */ |
| 18 | +public interface CameraProperties { |
| 19 | + |
| 20 | + /** |
| 21 | + * Returns the name (or identifier) of the camera device. |
| 22 | + * |
| 23 | + * @return String The name of the camera device. |
| 24 | + */ |
| 25 | + String getCameraName(); |
| 26 | + |
| 27 | + /** |
| 28 | + * Returns the list of frame rate ranges for @see android.control.aeTargetFpsRange supported by |
| 29 | + * this camera device. |
| 30 | + * |
| 31 | + * <p>By default maps to the @see |
| 32 | + * android.hardware.camera2.CameraCharacteristics#CONTROL_AE_TARGET_FPS_RANGE key. |
| 33 | + * |
| 34 | + * @return android.util.Range<Integer>[] List of frame rate ranges supported by this camera |
| 35 | + * device. |
| 36 | + */ |
| 37 | + Range<Integer>[] getControlAutoExposureAvailableTargetFpsRanges(); |
| 38 | + |
| 39 | + /** |
| 40 | + * Returns the maximum and minimum exposure compensation values for @see |
| 41 | + * android.control.aeExposureCompensation, in counts of @see android.control.aeCompensationStep, |
| 42 | + * that are supported by this camera device. |
| 43 | + * |
| 44 | + * <p>By default maps to the @see |
| 45 | + * android.hardware.camera2.CameraCharacteristics#CONTROL_AE_COMPENSATION_RANGE key. |
| 46 | + * |
| 47 | + * @return android.util.Range<Integer> Maximum and minimum exposure compensation supported by this |
| 48 | + * camera device. |
| 49 | + */ |
| 50 | + Range<Integer> getControlAutoExposureCompensationRange(); |
| 51 | + |
| 52 | + /** |
| 53 | + * Returns the smallest step by which the exposure compensation can be changed. |
| 54 | + * |
| 55 | + * <p>By default maps to the @see |
| 56 | + * android.hardware.camera2.CameraCharacteristics#CONTROL_AE_COMPENSATION_STEP key. |
| 57 | + * |
| 58 | + * @return double Smallest step by which the exposure compensation can be changed. |
| 59 | + */ |
| 60 | + double getControlAutoExposureCompensationStep(); |
| 61 | + |
| 62 | + /** |
| 63 | + * Returns a list of auto-focus modes for @see android.control.afMode that are supported by this |
| 64 | + * camera device. |
| 65 | + * |
| 66 | + * <p>By default maps to the @see |
| 67 | + * android.hardware.camera2.CameraCharacteristics#CONTROL_AF_AVAILABLE_MODES key. |
| 68 | + * |
| 69 | + * @return int[] List of auto-focus modes supported by this camera device. |
| 70 | + */ |
| 71 | + int[] getControlAutoFocusAvailableModes(); |
| 72 | + |
| 73 | + /** |
| 74 | + * Returns the maximum number of metering regions that can be used by the auto-exposure routine. |
| 75 | + * |
| 76 | + * <p>By default maps to the @see |
| 77 | + * android.hardware.camera2.CameraCharacteristics#CONTROL_MAX_REGIONS_AE key. |
| 78 | + * |
| 79 | + * @return Integer Maximum number of metering regions that can be used by the auto-exposure |
| 80 | + * routine. |
| 81 | + */ |
| 82 | + Integer getControlMaxRegionsAutoExposure(); |
| 83 | + |
| 84 | + /** |
| 85 | + * Returns the maximum number of metering regions that can be used by the auto-focus routine. |
| 86 | + * |
| 87 | + * <p>By default maps to the @see |
| 88 | + * android.hardware.camera2.CameraCharacteristics#CONTROL_MAX_REGIONS_AF key. |
| 89 | + * |
| 90 | + * @return Integer Maximum number of metering regions that can be used by the auto-focus routine. |
| 91 | + */ |
| 92 | + Integer getControlMaxRegionsAutoFocus(); |
| 93 | + |
| 94 | + /** |
| 95 | + * Returns a list of distortion correction modes for @see android.distortionCorrection.mode that |
| 96 | + * are supported by this camera device. |
| 97 | + * |
| 98 | + * <p>By default maps to the @see |
| 99 | + * android.hardware.camera2.CameraCharacteristics#DISTORTION_CORRECTION_AVAILABLE_MODES key. |
| 100 | + * |
| 101 | + * @return int[] List of distortion correction modes supported by this camera device. |
| 102 | + */ |
| 103 | + @RequiresApi(api = VERSION_CODES.P) |
| 104 | + int[] getDistortionCorrectionAvailableModes(); |
| 105 | + |
| 106 | + /** |
| 107 | + * Returns whether this camera device has a flash unit. |
| 108 | + * |
| 109 | + * <p>By default maps to the @see |
| 110 | + * android.hardware.camera2.CameraCharacteristics#FLASH_INFO_AVAILABLE key. |
| 111 | + * |
| 112 | + * @return Boolean Whether this camera device has a flash unit. |
| 113 | + */ |
| 114 | + Boolean getFlashInfoAvailable(); |
| 115 | + |
| 116 | + /** |
| 117 | + * Returns the direction the camera faces relative to device screen. |
| 118 | + * |
| 119 | + * <p><string>Possible values:</string> |
| 120 | + * |
| 121 | + * <ul> |
| 122 | + * <li>@see android.hardware.camera2.CameraMetadata.LENS_FACING_FRONT |
| 123 | + * <li>@see android.hardware.camera2.CameraMetadata.LENS_FACING_BACK |
| 124 | + * <li>@see android.hardware.camera2.CameraMetadata.LENS_FACING_EXTERNAL |
| 125 | + * </ul> |
| 126 | + * |
| 127 | + * By default maps to the @see android.hardware.camera2.CameraCharacteristics.LENS_FACING key. |
| 128 | + * |
| 129 | + * @return int Direction the camera faces relative to device screen. |
| 130 | + */ |
| 131 | + int getLensFacing(); |
| 132 | + |
| 133 | + /** |
| 134 | + * Returns the shortest distance from front most surface of the lens that can be brought into |
| 135 | + * sharp focus. |
| 136 | + * |
| 137 | + * <p>By default maps to the @see |
| 138 | + * android.hardware.camera2.CameraCharacteristics#LENS_INFO_MINIMUM_FOCUS_DISTANCE key. |
| 139 | + * |
| 140 | + * @return Float Shortest distance from front most surface of the lens that can be brought into |
| 141 | + * sharp focus. |
| 142 | + */ |
| 143 | + Float getLensInfoMinimumFocusDistance(); |
| 144 | + |
| 145 | + /** |
| 146 | + * Returns the maximum ratio between both active area width and crop region width, and active area |
| 147 | + * height and crop region height, for @see android.scaler.cropRegion. |
| 148 | + * |
| 149 | + * <p>By default maps to the @see |
| 150 | + * android.hardware.camera2.CameraCharacteristics#SCALER_AVAILABLE_MAX_DIGITAL_ZOOM key. |
| 151 | + * |
| 152 | + * @return Float Maximum ratio between both active area width and crop region width, and active |
| 153 | + * area height and crop region height |
| 154 | + */ |
| 155 | + Float getScalerAvailableMaxDigitalZoom(); |
| 156 | + |
| 157 | + /** |
| 158 | + * Returns the area of the image sensor which corresponds to active pixels after any geometric |
| 159 | + * distortion correction has been applied. |
| 160 | + * |
| 161 | + * <p>By default maps to the @see |
| 162 | + * android.hardware.camera2.CameraCharacteristics#SENSOR_INFO_ACTIVE_ARRAY_SIZE key. |
| 163 | + * |
| 164 | + * @return android.graphics.Rect area of the image sensor which corresponds to active pixels after |
| 165 | + * any geometric distortion correction has been applied. |
| 166 | + */ |
| 167 | + Rect getSensorInfoActiveArraySize(); |
| 168 | + |
| 169 | + /** |
| 170 | + * Returns the dimensions of the full pixel array, possibly including black calibration pixels. |
| 171 | + * |
| 172 | + * <p>By default maps to the @see |
| 173 | + * android.hardware.camera2.CameraCharacteristics#SENSOR_INFO_PIXEL_ARRAY_SIZE key. |
| 174 | + * |
| 175 | + * @return android.util.Size Dimensions of the full pixel array, possibly including black |
| 176 | + * calibration pixels. |
| 177 | + */ |
| 178 | + Size getSensorInfoPixelArraySize(); |
| 179 | + |
| 180 | + /** |
| 181 | + * Returns the area of the image sensor which corresponds to active pixels prior to the |
| 182 | + * application of any geometric distortion correction. |
| 183 | + * |
| 184 | + * <p>By default maps to the @see |
| 185 | + * android.hardware.camera2.CameraCharacteristics#SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE |
| 186 | + * key. |
| 187 | + * |
| 188 | + * @return android.graphics.Rect Area of the image sensor which corresponds to active pixels prior |
| 189 | + * to the application of any geometric distortion correction. |
| 190 | + */ |
| 191 | + @RequiresApi(api = VERSION_CODES.M) |
| 192 | + Rect getSensorInfoPreCorrectionActiveArraySize(); |
| 193 | + |
| 194 | + /** |
| 195 | + * Returns the clockwise angle through which the output image needs to be rotated to be upright on |
| 196 | + * the device screen in its native orientation. |
| 197 | + * |
| 198 | + * <p>By default maps to the @see |
| 199 | + * android.hardware.camera2.CameraCharacteristics#SENSOR_ORIENTATION key. |
| 200 | + * |
| 201 | + * @return int Clockwise angle through which the output image needs to be rotated to be upright on |
| 202 | + * the device screen in its native orientation. |
| 203 | + */ |
| 204 | + int getSensorOrientation(); |
| 205 | + |
| 206 | + /** |
| 207 | + * Returns a level which generally classifies the overall set of the camera device functionality. |
| 208 | + * |
| 209 | + * <p><strong>Possible values:</strong> |
| 210 | + * |
| 211 | + * <ul> |
| 212 | + * <li>@see android.hardware.camera2.CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY |
| 213 | + * <li>@see android.hardware.camera2.CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED |
| 214 | + * <li>@see android.hardware.camera2.CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_FULL |
| 215 | + * <li>@see android.hardware.camera2.CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEVEL_3 |
| 216 | + * <li>@see android.hardware.camera2.CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL |
| 217 | + * </ul> |
| 218 | + * |
| 219 | + * By default maps to the @see |
| 220 | + * android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL key. |
| 221 | + * |
| 222 | + * @return int Level which generally classifies the overall set of the camera device |
| 223 | + * functionality. |
| 224 | + */ |
| 225 | + int getHardwareLevel(); |
| 226 | + |
| 227 | + /** |
| 228 | + * Returns a list of noise reduction modes for @see android.noiseReduction.mode that are supported |
| 229 | + * by this camera device. |
| 230 | + * |
| 231 | + * <p>By default maps to the @see |
| 232 | + * android.hardware.camera2.CameraCharacteristics#NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES |
| 233 | + * key. |
| 234 | + * |
| 235 | + * @return int[] List of noise reduction modes that are supported by this camera device. |
| 236 | + */ |
| 237 | + int[] getAvailableNoiseReductionModes(); |
| 238 | +} |
| 239 | + |
| 240 | +/** |
| 241 | + * Implementation of the @see CameraProperties interface using the @see |
| 242 | + * android.hardware.camera2.CameraCharacteristics class to access the different characteristics. |
| 243 | + */ |
| 244 | +class CameraPropertiesImpl implements CameraProperties { |
| 245 | + private final CameraCharacteristics cameraCharacteristics; |
| 246 | + private final String cameraName; |
| 247 | + |
| 248 | + public CameraPropertiesImpl(String cameraName, CameraManager cameraManager) |
| 249 | + throws CameraAccessException { |
| 250 | + this.cameraName = cameraName; |
| 251 | + this.cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName); |
| 252 | + } |
| 253 | + |
| 254 | + @Override |
| 255 | + public String getCameraName() { |
| 256 | + return cameraName; |
| 257 | + } |
| 258 | + |
| 259 | + @Override |
| 260 | + public Range<Integer>[] getControlAutoExposureAvailableTargetFpsRanges() { |
| 261 | + return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES); |
| 262 | + } |
| 263 | + |
| 264 | + @Override |
| 265 | + public Range<Integer> getControlAutoExposureCompensationRange() { |
| 266 | + return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE); |
| 267 | + } |
| 268 | + |
| 269 | + @Override |
| 270 | + public double getControlAutoExposureCompensationStep() { |
| 271 | + Rational rational = |
| 272 | + cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP); |
| 273 | + |
| 274 | + return rational == null ? 0.0 : rational.doubleValue(); |
| 275 | + } |
| 276 | + |
| 277 | + @Override |
| 278 | + public int[] getControlAutoFocusAvailableModes() { |
| 279 | + return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES); |
| 280 | + } |
| 281 | + |
| 282 | + @Override |
| 283 | + public Integer getControlMaxRegionsAutoExposure() { |
| 284 | + return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE); |
| 285 | + } |
| 286 | + |
| 287 | + @Override |
| 288 | + public Integer getControlMaxRegionsAutoFocus() { |
| 289 | + return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF); |
| 290 | + } |
| 291 | + |
| 292 | + @RequiresApi(api = VERSION_CODES.P) |
| 293 | + @Override |
| 294 | + public int[] getDistortionCorrectionAvailableModes() { |
| 295 | + return cameraCharacteristics.get(CameraCharacteristics.DISTORTION_CORRECTION_AVAILABLE_MODES); |
| 296 | + } |
| 297 | + |
| 298 | + @Override |
| 299 | + public Boolean getFlashInfoAvailable() { |
| 300 | + return cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); |
| 301 | + } |
| 302 | + |
| 303 | + @Override |
| 304 | + public int getLensFacing() { |
| 305 | + return cameraCharacteristics.get(CameraCharacteristics.LENS_FACING); |
| 306 | + } |
| 307 | + |
| 308 | + @Override |
| 309 | + public Float getLensInfoMinimumFocusDistance() { |
| 310 | + return cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE); |
| 311 | + } |
| 312 | + |
| 313 | + @Override |
| 314 | + public Float getScalerAvailableMaxDigitalZoom() { |
| 315 | + return cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM); |
| 316 | + } |
| 317 | + |
| 318 | + @Override |
| 319 | + public Rect getSensorInfoActiveArraySize() { |
| 320 | + return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); |
| 321 | + } |
| 322 | + |
| 323 | + @Override |
| 324 | + public Size getSensorInfoPixelArraySize() { |
| 325 | + return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE); |
| 326 | + } |
| 327 | + |
| 328 | + @RequiresApi(api = VERSION_CODES.M) |
| 329 | + @Override |
| 330 | + public Rect getSensorInfoPreCorrectionActiveArraySize() { |
| 331 | + return cameraCharacteristics.get( |
| 332 | + CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE); |
| 333 | + } |
| 334 | + |
| 335 | + @Override |
| 336 | + public int getSensorOrientation() { |
| 337 | + return cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); |
| 338 | + } |
| 339 | + |
| 340 | + @Override |
| 341 | + public int getHardwareLevel() { |
| 342 | + return cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); |
| 343 | + } |
| 344 | + |
| 345 | + @Override |
| 346 | + public int[] getAvailableNoiseReductionModes() { |
| 347 | + return cameraCharacteristics.get( |
| 348 | + CameraCharacteristics.NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES); |
| 349 | + } |
| 350 | +} |
0 commit comments