Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "V4L2Camera.h" |
| 18 | |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 19 | #include <fcntl.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <sys/stat.h> |
| 22 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 23 | #include <camera/CameraMetadata.h> |
| 24 | #include <hardware/camera3.h> |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 25 | #include <nativehelper/ScopedFd.h> |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 26 | |
| 27 | #include "Common.h" |
| 28 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame^] | 29 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) |
| 30 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 31 | namespace v4l2_camera_hal { |
| 32 | |
| 33 | V4L2Camera::V4L2Camera(int id, std::string path) |
| 34 | : default_camera_hal::Camera(id), mDevicePath(std::move(path)) { |
| 35 | HAL_LOG_ENTER(); |
| 36 | } |
| 37 | |
| 38 | V4L2Camera::~V4L2Camera() { |
| 39 | HAL_LOG_ENTER(); |
| 40 | } |
| 41 | |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 42 | int V4L2Camera::connect() { |
| 43 | HAL_LOG_ENTER(); |
| 44 | |
| 45 | if (mDeviceFd.get() >= 0) { |
| 46 | HAL_LOGE("Camera device %s is opened. Close it first", mDevicePath.c_str()); |
| 47 | return -EIO; |
| 48 | } |
| 49 | |
| 50 | int fd = TEMP_FAILURE_RETRY(open(mDevicePath.c_str(), O_RDWR)); |
| 51 | if (fd < 0) { |
| 52 | HAL_LOGE("failed to open %s (%s)", mDevicePath.c_str(), strerror(errno)); |
| 53 | return -errno; |
| 54 | } |
| 55 | mDeviceFd.reset(fd); |
| 56 | |
| 57 | // TODO(b/29185945): confirm this is a supported device. |
| 58 | // This is checked by the HAL, but the device at mDevicePath may |
| 59 | // not be the same one that was there when the HAL was loaded. |
| 60 | // (Alternatively, better hotplugging support may make this unecessary |
| 61 | // by disabling cameras that get disconnected and checking newly connected |
| 62 | // cameras, so connect() is never called on an unsupported camera) |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame^] | 63 | |
| 64 | // TODO(b/29158098): Inform service of any flashes that are no longer available |
| 65 | // because this camera is in use. |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | void V4L2Camera::disconnect() { |
| 70 | HAL_LOG_ENTER(); |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame^] | 71 | // TODO(b/29158098): Inform service of any flashes that are available again |
| 72 | // because this camera is no longer in use. |
| 73 | |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 74 | mDeviceFd.reset(); |
| 75 | } |
| 76 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame^] | 77 | int V4L2Camera::initStaticInfo(camera_metadata_t** out) { |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 78 | HAL_LOG_ENTER(); |
| 79 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame^] | 80 | android::CameraMetadata info; |
Ari Hausman-Cohen | 63f6982 | 2016-06-10 11:40:35 -0700 | [diff] [blame] | 81 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame^] | 82 | std::vector<int32_t> avail_characteristics_keys; |
| 83 | android::status_t res; |
| 84 | |
| 85 | #define ADD_STATIC_ENTRY(name, varptr, count) \ |
| 86 | avail_characteristics_keys.push_back(name); \ |
| 87 | res = info.update(name, varptr, count); \ |
| 88 | if (res != android::OK) return res |
| 89 | |
| 90 | // Static metadata characteristics from /system/media/camera/docs/docs.html. |
| 91 | |
| 92 | /* android.color. */ |
| 93 | |
| 94 | // No easy way to turn chromatic aberration correction OFF in v4l2, |
| 95 | // though this may be supportable via a collection of other user controls. |
| 96 | uint8_t avail_aberration_modes[] = { |
| 97 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE_FAST, |
| 98 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY}; |
| 99 | ADD_STATIC_ENTRY(ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, |
| 100 | avail_aberration_modes, ARRAY_SIZE(avail_aberration_modes)); |
| 101 | |
| 102 | /* android.control. */ |
| 103 | |
| 104 | /* 3As */ |
| 105 | |
| 106 | // TODO(b/29394024): query V4L2_CID_POWER_LINE_FREQUENCY |
| 107 | uint8_t avail_ae_antibanding_modes[] = { |
| 108 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF}; |
| 109 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, |
| 110 | avail_ae_antibanding_modes, |
| 111 | ARRAY_SIZE(avail_ae_antibanding_modes)); |
| 112 | |
| 113 | // TODO(b/29394024): query V4L2_CID_EXPOSURE_AUTO for ae modes. |
| 114 | uint8_t avail_ae_modes[] = { |
| 115 | ANDROID_CONTROL_AE_MODE_ON}; |
| 116 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AE_AVAILABLE_MODES, |
| 117 | avail_ae_modes, ARRAY_SIZE(avail_ae_modes)); |
| 118 | |
| 119 | // TODO(b/29394034): query available YUV_420_888 frame rates. |
| 120 | // This should be {mi, ma, ma, ma} where mi is min(15, min frame rate), |
| 121 | // and ma is max frame rate (for YUV_420_888). |
| 122 | int32_t avail_fps_ranges[] = { |
| 123 | 15, 30, |
| 124 | 30, 30}; |
| 125 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, |
| 126 | avail_fps_ranges, ARRAY_SIZE(avail_fps_ranges)); |
| 127 | |
| 128 | // TODO(b/29394024): query V4L2_CID_EXPOSURE_BIAS. |
| 129 | int32_t ae_comp_range[] = {0, 0}; |
| 130 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AE_COMPENSATION_RANGE, |
| 131 | ae_comp_range, ARRAY_SIZE(ae_comp_range)); |
| 132 | |
| 133 | // TODO(b/29394024): set based on V4L2_CID_EXPOSURE_BIAS step size. |
| 134 | camera_metadata_rational ae_comp_step = {1, 1}; |
| 135 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AE_COMPENSATION_STEP, |
| 136 | &ae_comp_step, 1); |
| 137 | |
| 138 | // TODO(b/29394024): query V4L2_CID_FOCUS_AUTO for |
| 139 | // CONTINUOUS_VIDEO/CONTINUOUS_PICTURE. V4L2_CID_AUTO_FOCUS_START |
| 140 | // supports what Android thinks of as auto focus (single auto focus). |
| 141 | // V4L2_CID_AUTO_FOCUS_RANGE allows MACRO. |
| 142 | uint8_t avail_af_modes[] = { |
| 143 | ANDROID_CONTROL_AF_MODE_OFF}; |
| 144 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AF_AVAILABLE_MODES, |
| 145 | avail_af_modes, ARRAY_SIZE(avail_af_modes)); |
| 146 | |
| 147 | // TODO(b/29394024): query V4L2_CID_AUTO_WHITE_BALANCE, or |
| 148 | // V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE if available. |
| 149 | // If manual is supported, must look at android.colorCorrection |
| 150 | // transform and gains for the manual control. Not sure if this |
| 151 | // is supported by V4L2 or not, or if this is even a HAL job. |
| 152 | uint8_t avail_awb_modes[] = { |
| 153 | ANDROID_CONTROL_AWB_MODE_AUTO}; |
| 154 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AWB_AVAILABLE_MODES, |
| 155 | avail_awb_modes, ARRAY_SIZE(avail_awb_modes)); |
| 156 | |
| 157 | // Couldn't find any V4L2 support for regions, though maybe it's out there. |
| 158 | int32_t max_regions[] = {/*AE*/ 0,/*AWB*/ 0,/*AF*/ 0}; |
| 159 | ADD_STATIC_ENTRY(ANDROID_CONTROL_MAX_REGIONS, |
| 160 | max_regions, ARRAY_SIZE(max_regions)); |
| 161 | |
| 162 | // TODO(b/29394024): query V4L2_CID_3A_LOCK. |
| 163 | uint8_t ae_lock_avail = ANDROID_CONTROL_AE_LOCK_AVAILABLE_FALSE; |
| 164 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AE_LOCK_AVAILABLE, |
| 165 | &ae_lock_avail, 1); |
| 166 | uint8_t awb_lock_avail = ANDROID_CONTROL_AWB_LOCK_AVAILABLE_FALSE; |
| 167 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, |
| 168 | &awb_lock_avail, 1); |
| 169 | |
| 170 | /* Scene modes. */ |
| 171 | |
| 172 | // TODO(b/29394024): query V4L2_CID_SCENE_MODE. |
| 173 | uint8_t avail_scene_modes[] = { |
| 174 | ANDROID_CONTROL_SCENE_MODE_DISABLED}; |
| 175 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AVAILABLE_SCENE_MODES, |
| 176 | avail_scene_modes, ARRAY_SIZE(avail_scene_modes)); |
| 177 | |
| 178 | // A 3-tuple of AE, AWB, AF overrides for each scene mode. |
| 179 | // Ignored for DISABLED, FACE_PRIORITY and FACE_PRIORITY_LOW_LIGHT. |
| 180 | uint8_t scene_mode_overrides[] = { |
| 181 | /*SCENE_MODE_DISABLED*/ /*AE*/0, /*AW*/0, /*AF*/0}; |
| 182 | ADD_STATIC_ENTRY(ANDROID_CONTROL_SCENE_MODE_OVERRIDES, |
| 183 | scene_mode_overrides, ARRAY_SIZE(scene_mode_overrides)); |
| 184 | |
| 185 | /* Top level 3A/Scenes switch. */ |
| 186 | |
| 187 | // TODO(b/29394024): Add USE_SCENE_MODE if scene modes are enabled. |
| 188 | uint8_t avail_modes[] = { |
| 189 | ANDROID_CONTROL_MODE_AUTO}; |
| 190 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AVAILABLE_MODES, |
| 191 | avail_modes, ARRAY_SIZE(avail_modes)); |
| 192 | |
| 193 | /* Other android.control configuration. */ |
| 194 | |
| 195 | // TODO(b/29394024): query V4L2_CID_IMAGE_STABILIZATION. |
| 196 | uint8_t avail_stabilization[] = { |
| 197 | ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF}; |
| 198 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, |
| 199 | avail_stabilization, ARRAY_SIZE(avail_stabilization)); |
| 200 | |
| 201 | // TODO(b/29394024): query V4L2_CID_COLORFX. |
| 202 | uint8_t avail_effects[] = { |
| 203 | ANDROID_CONTROL_EFFECT_MODE_OFF}; |
| 204 | ADD_STATIC_ENTRY(ANDROID_CONTROL_AVAILABLE_EFFECTS, |
| 205 | avail_effects, ARRAY_SIZE(avail_effects)); |
| 206 | |
| 207 | // AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS only necessary |
| 208 | // for devices supporting CONSTRAINED_HIGH_SPEED_VIDEO, |
| 209 | // which this HAL doesn't support. |
| 210 | |
| 211 | // POST_RAW_SENSITIVITY_BOOST_RANGE only necessary |
| 212 | // for devices supporting RAW format outputs. |
| 213 | |
| 214 | /* android.edge. */ |
| 215 | |
| 216 | // Not sure if V4L2 does or doesn't do this, but HAL documentation says |
| 217 | // all devices must support FAST, and FAST can be equivalent to OFF, so |
| 218 | // either way it's fine to list. |
| 219 | uint8_t avail_edge_modes[] = { |
| 220 | ANDROID_EDGE_MODE_FAST}; |
| 221 | ADD_STATIC_ENTRY(ANDROID_EDGE_AVAILABLE_EDGE_MODES, |
| 222 | avail_edge_modes, ARRAY_SIZE(avail_edge_modes)); |
| 223 | |
| 224 | /* android.flash. */ |
| 225 | |
| 226 | // TODO(b/29394024): query V4L2_CID_FLASH_LED_MODE. |
| 227 | uint8_t flash_avail = 0; |
| 228 | ADD_STATIC_ENTRY(ANDROID_FLASH_INFO_AVAILABLE, |
| 229 | &flash_avail, 1); |
| 230 | |
| 231 | // info.chargeDuration, color.Temperature, maxEnergy marked FUTURE. |
| 232 | |
| 233 | /* android.hotPixel. */ |
| 234 | |
| 235 | // No known V4L2 hot pixel correction. But it might be happening, |
| 236 | // so we report FAST/HIGH_QUALITY. |
| 237 | uint8_t avail_hot_pixel_modes[] = { |
| 238 | ANDROID_HOT_PIXEL_MODE_FAST, |
| 239 | ANDROID_HOT_PIXEL_MODE_HIGH_QUALITY}; |
| 240 | ADD_STATIC_ENTRY(ANDROID_HOT_PIXEL_AVAILABLE_HOT_PIXEL_MODES, |
| 241 | avail_hot_pixel_modes, ARRAY_SIZE(avail_hot_pixel_modes)); |
| 242 | |
| 243 | /* android.jpeg. */ |
| 244 | |
| 245 | // For now, no thumbnails available (only [0,0], the "no thumbnail" size). |
| 246 | // TODO(b/29580107): Could end up with a mismatch between request & result, |
| 247 | // since V4L2 doesn't actually allow for thumbnail size control. |
| 248 | int32_t thumbnail_sizes[] = { |
| 249 | 0, 0}; |
| 250 | ADD_STATIC_ENTRY(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
| 251 | thumbnail_sizes, ARRAY_SIZE(thumbnail_sizes)); |
| 252 | |
| 253 | // V4L2 doesn't support querying this, so we generously assume up to 3 MB. |
| 254 | int32_t max_jpeg_size = 3000000; |
| 255 | ADD_STATIC_ENTRY(ANDROID_JPEG_MAX_SIZE, |
| 256 | &max_jpeg_size, 1); |
| 257 | |
| 258 | /* android.lens. */ |
| 259 | |
| 260 | /* Misc. lens control. */ |
| 261 | |
| 262 | // No way to actually get the f-value in V4L2, but it's a required key, |
| 263 | // so we just fake it. Raspberry Pi camera v2 is f/2.0. |
| 264 | float avail_apertures[] = {2.0}; |
| 265 | ADD_STATIC_ENTRY(ANDROID_LENS_INFO_AVAILABLE_APERTURES, |
| 266 | avail_apertures, ARRAY_SIZE(avail_apertures)); |
| 267 | |
| 268 | // No known V4L2 neutral density filter control. |
| 269 | float avail_filter_densities[] = {0.0}; |
| 270 | ADD_STATIC_ENTRY(ANDROID_LENS_INFO_AVAILABLE_FILTER_DENSITIES, |
| 271 | avail_filter_densities, ARRAY_SIZE(avail_filter_densities)); |
| 272 | |
| 273 | // TODO(b/29394024): query V4L2_CID_IMAGE_STABILIZATION. |
| 274 | uint8_t avail_optical_stabilization[] = { |
| 275 | ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF}; |
| 276 | ADD_STATIC_ENTRY(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, |
| 277 | avail_optical_stabilization, |
| 278 | ARRAY_SIZE(avail_optical_stabilization)); |
| 279 | |
| 280 | // No known V4L2 shading map info. |
| 281 | int32_t shading_map_size[] = {1, 1}; |
| 282 | ADD_STATIC_ENTRY(ANDROID_LENS_INFO_SHADING_MAP_SIZE, |
| 283 | shading_map_size, ARRAY_SIZE(shading_map_size)); |
| 284 | |
| 285 | // All V4L2 devices are considered to be external facing. |
| 286 | uint8_t facing = ANDROID_LENS_FACING_EXTERNAL; |
| 287 | ADD_STATIC_ENTRY(ANDROID_LENS_FACING, &facing, 1); |
| 288 | |
| 289 | /* Zoom/Focus. */ |
| 290 | |
| 291 | // No way to actually get the focal length in V4L2, but it's a required key, |
| 292 | // so we just fake it. Raspberry Pi camera v2 is 3.04mm. |
| 293 | // Note: unlike f values, this key is actually used in calculations |
| 294 | // (field of view), so other cameras may see inaccurate results. |
| 295 | float focal_length = 3.04; |
| 296 | ADD_STATIC_ENTRY(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
| 297 | &focal_length, 1); |
| 298 | |
| 299 | // V4L2 focal units do not correspond to a particular physical unit. |
| 300 | uint8_t focus_calibration = |
| 301 | ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_UNCALIBRATED; |
| 302 | ADD_STATIC_ENTRY(ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION, |
| 303 | &focus_calibration, 1); |
| 304 | |
| 305 | // info.hyperfocalDistance not required for UNCALIBRATED. |
| 306 | |
| 307 | // TODO(b/29394024): query V4L2_CID_ZOOM_ABSOLUTE for focus range. |
| 308 | // 0 is fixed focus. |
| 309 | float min_focus_distance = 0.0; |
| 310 | ADD_STATIC_ENTRY(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, |
| 311 | &min_focus_distance, 1); |
| 312 | |
| 313 | /* Depth. */ |
| 314 | |
| 315 | // DEPTH capability not supported by this HAL. Not implemented: |
| 316 | // poseRotation |
| 317 | // poseTranslation |
| 318 | // intrinsicCalibration |
| 319 | // radialDistortion |
| 320 | |
| 321 | /* anroid.noise. */ |
| 322 | |
| 323 | // Unable to control noise reduction in V4L2 devices, |
| 324 | // but FAST is allowed to be the same as OFF. |
| 325 | uint8_t avail_noise_reduction_modes[] = { |
| 326 | ANDROID_NOISE_REDUCTION_MODE_FAST}; |
| 327 | ADD_STATIC_ENTRY(ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, |
| 328 | avail_noise_reduction_modes, |
| 329 | ARRAY_SIZE(avail_noise_reduction_modes)); |
| 330 | |
| 331 | /* android.request. */ |
| 332 | |
| 333 | // Resources may be an issue, so just using minimum allowable |
| 334 | // for LIMITED devices. |
| 335 | int32_t max_num_output_streams[] = { |
| 336 | /*Raw*/0, /*YUV*/2, /*JPEG*/1}; |
| 337 | ADD_STATIC_ENTRY(ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS, |
| 338 | max_num_output_streams, ARRAY_SIZE(max_num_output_streams)); |
| 339 | |
| 340 | // Reprocessing not supported, so no maxNumInputStreams. |
| 341 | |
| 342 | // No way to know for V4L2, so fake with max allowable latency. |
| 343 | // Doesn't mean much without per-frame controls. |
| 344 | uint8_t pipeline_max_depth = 4; |
| 345 | ADD_STATIC_ENTRY(ANDROID_REQUEST_PIPELINE_MAX_DEPTH, |
| 346 | &pipeline_max_depth, 1); |
| 347 | |
| 348 | // Partial results not supported; partialResultCount defaults to 1. |
| 349 | |
| 350 | // Available capabilities & keys queried at very end of this method. |
| 351 | |
| 352 | /* android.scaler. */ |
| 353 | |
| 354 | /* Cropping. */ |
| 355 | |
| 356 | // TODO(b/29394024): query VIDIOC_CROPCAP to get cropping ranges, |
| 357 | // and VIDIOC_G_CROP to determine if cropping is supported. |
| 358 | // If the ioctl isn't available (or cropping has non-square pixelaspect), |
| 359 | // assume no cropping/scaling. |
| 360 | // May need to try setting some crops to determine what the driver actually |
| 361 | // supports (including testing center vs freeform). |
| 362 | float max_zoom = 1; |
| 363 | ADD_STATIC_ENTRY(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, |
| 364 | &max_zoom, 1); |
| 365 | |
| 366 | // V4L2 VIDIOC_CROPCAP doesn't give a way to query this; |
| 367 | // it's driver dependent. For now, assume freeform, and |
| 368 | // some cameras may just behave badly. |
| 369 | // TODO(b/29579652): Figure out a way to determine this. |
| 370 | uint8_t crop_type = ANDROID_SCALER_CROPPING_TYPE_FREEFORM; |
| 371 | ADD_STATIC_ENTRY(ANDROID_SCALER_CROPPING_TYPE, &crop_type, 1); |
| 372 | |
| 373 | /* Streams. */ |
| 374 | |
| 375 | // availableInputOutputFormatsMap only required for reprocessing capability. |
| 376 | |
| 377 | // TODO(b/29394024): query VIDIOC_ENUM_FMT to get pixel formats, pull out |
| 378 | // YUV_420_888 and JPEG, query VIDIOC_ENUM_FRAMESIZES on those. |
| 379 | // TODO(b/29581206): Need behavior if YUV_420_888 and JPEG aren't available. |
| 380 | // For now, just 640x480 JPEG. |
| 381 | int32_t avail_stream_configs[] = { |
| 382 | HAL_PIXEL_FORMAT_BLOB, 640, 480, |
| 383 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT}; |
| 384 | ADD_STATIC_ENTRY(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, |
| 385 | avail_stream_configs, ARRAY_SIZE(avail_stream_configs)); |
| 386 | |
| 387 | // Per format and size, minimum frame duration (max frame rate). |
| 388 | // For now, just 30 fps = 1/30 spf ~= 33333333 ns. |
| 389 | // For whatever reason the goldfish/qcom cameras report this as |
| 390 | // 33331760, so copying that. |
| 391 | // TODO(b/29394024): query the available format frame rates. |
| 392 | int64_t avail_min_frame_durations[] = { |
| 393 | HAL_PIXEL_FORMAT_BLOB, 640, 480, 33331760}; |
| 394 | ADD_STATIC_ENTRY(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, |
| 395 | avail_min_frame_durations, |
| 396 | ARRAY_SIZE(avail_min_frame_durations)); |
| 397 | |
| 398 | // Per format and size, usually 0 for non-jpeg, non-zero for JPEG. |
| 399 | // Randomly choosing absurdly long 1 sec for JPEG. Unsure what this breaks. |
| 400 | int64_t avail_stall_durations[] = { |
| 401 | HAL_PIXEL_FORMAT_BLOB, 640, 480, 1000000000}; |
| 402 | ADD_STATIC_ENTRY(ANDROID_SCALER_AVAILABLE_STALL_DURATIONS, |
| 403 | avail_stall_durations, ARRAY_SIZE(avail_stall_durations)); |
| 404 | |
| 405 | /* android.sensor. */ |
| 406 | |
| 407 | /* Sizes. */ |
| 408 | |
| 409 | // Spoof as 640 x 480 for now. |
| 410 | // TODO(b/29394024): query VIDIOC_CROPCAP to get pixel rectangle. |
| 411 | int32_t array_rect[] = { |
| 412 | /*xmin*/0, /*ymin*/0, /*width*/640, /*height*/480}; |
| 413 | ADD_STATIC_ENTRY(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, |
| 414 | array_rect, ARRAY_SIZE(array_rect)); |
| 415 | // No V4L2 way to differentiate active vs. inactive parts of the rectangle. |
| 416 | ADD_STATIC_ENTRY(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, |
| 417 | array_rect, ARRAY_SIZE(array_rect)); |
| 418 | |
| 419 | // No way to get actual physical size from V4L2. Field of view/pixel pitch |
| 420 | // calculations will be off. Using Raspberry Pi camera v2 measurements |
| 421 | // (3.674 x 2.760 mm). |
| 422 | float physical_size[] = {3.674, 2.760}; |
| 423 | ADD_STATIC_ENTRY(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
| 424 | physical_size, ARRAY_SIZE(physical_size)); |
| 425 | |
| 426 | /* Misc sensor information. */ |
| 427 | |
| 428 | // For now, using the emulator value of .3 sec. |
| 429 | // TODO(b/29394024): query for min frame rate. |
| 430 | int64_t max_frame_duration = 300000000; |
| 431 | ADD_STATIC_ENTRY(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION, |
| 432 | &max_frame_duration, 1); |
| 433 | |
| 434 | // HAL uses BOOTTIME timestamps. |
| 435 | // TODO(b/29457051): make sure timestamps are consistent throughout the HAL. |
| 436 | uint8_t timestamp_source = ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN; |
| 437 | ADD_STATIC_ENTRY(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, |
| 438 | ×tamp_source, 1); |
| 439 | |
| 440 | // As in initDeviceInfo, no way to actually get orientation. |
| 441 | int32_t orientation = 0; |
| 442 | ADD_STATIC_ENTRY(ANDROID_SENSOR_ORIENTATION, &orientation, 1); |
| 443 | |
| 444 | // availableTestPatternModes just defaults to OFF, which is fine. |
| 445 | |
| 446 | // info.exposureTimeRange, info.sensitivityRange: |
| 447 | // exposure/sensitivity manual control not supported. |
| 448 | // Could query V4L2_CID_ISO_SENSITIVITY to support sensitivity if desired. |
| 449 | |
| 450 | // info.whiteLevel, info.lensShadingApplied, |
| 451 | // info.preCorrectionActiveArraySize, referenceIlluminant1/2, |
| 452 | // calibrationTransform1/2, colorTransform1/2, forwardMatrix1/2, |
| 453 | // blackLevelPattern, profileHueSatMapDimensions |
| 454 | // all only necessary for RAW. |
| 455 | |
| 456 | // baseGainFactor marked FUTURE. |
| 457 | |
| 458 | // maxAnalogSensitivity optional for LIMITED device. |
| 459 | |
| 460 | // opticalBlackRegions: No known way to get in V4L2, but not necessary. |
| 461 | |
| 462 | // opaqueRawSize not necessary since RAW_OPAQUE format not supported. |
| 463 | |
| 464 | /* android.statistics */ |
| 465 | |
| 466 | // Face detection not supported. |
| 467 | uint8_t avail_face_detect_modes[] = { |
| 468 | ANDROID_STATISTICS_FACE_DETECT_MODE_OFF}; |
| 469 | ADD_STATIC_ENTRY(ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, |
| 470 | avail_face_detect_modes, |
| 471 | ARRAY_SIZE(avail_face_detect_modes)); |
| 472 | |
| 473 | int32_t max_face_count = 0; |
| 474 | ADD_STATIC_ENTRY(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, |
| 475 | &max_face_count, 1); |
| 476 | |
| 477 | // info.histogramBucketCount, info.maxHistogramCount, |
| 478 | // info.maxSharpnessMapValue, info.sharpnessMapSizemarked FUTURE. |
| 479 | |
| 480 | // ON only needs to be supported for RAW capable devices. |
| 481 | uint8_t avail_hot_pixel_map_modes[] = { |
| 482 | ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE_OFF}; |
| 483 | ADD_STATIC_ENTRY(ANDROID_STATISTICS_INFO_AVAILABLE_HOT_PIXEL_MAP_MODES, |
| 484 | avail_hot_pixel_map_modes, |
| 485 | ARRAY_SIZE(avail_hot_pixel_map_modes)); |
| 486 | |
| 487 | // ON only needs to be supported for RAW capable devices. |
| 488 | uint8_t avail_lens_shading_map_modes[] = { |
| 489 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF}; |
| 490 | ADD_STATIC_ENTRY(ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES, |
| 491 | avail_lens_shading_map_modes, |
| 492 | ARRAY_SIZE(avail_lens_shading_map_modes)); |
| 493 | |
| 494 | /* android.tonemap. */ |
| 495 | |
| 496 | // tonemapping only required for MANUAL_POST_PROCESSING capability. |
| 497 | |
| 498 | /* android.led. */ |
| 499 | |
| 500 | // availableLeds: for now, none available, so no need to set. |
| 501 | // TODO(b/29394024): query V4L2_CID_FLASH_INDICATOR_INTENSITY? |
| 502 | // if it's there, assume indicator exists? |
| 503 | |
| 504 | /* android.sync. */ |
| 505 | |
| 506 | // "LIMITED devices are strongly encouraged to use a non-negative value. |
| 507 | // If UNKNOWN is used here then app developers do not have a way to know |
| 508 | // when sensor settings have been applied." - Unfortunately, V4L2 doesn't |
| 509 | // really help here either. Could even be that adjusting settings mid-stream |
| 510 | // blocks in V4L2, and should be avoided. |
| 511 | int32_t max_latency = ANDROID_SYNC_MAX_LATENCY_UNKNOWN; |
| 512 | ADD_STATIC_ENTRY(ANDROID_SYNC_MAX_LATENCY, |
| 513 | &max_latency, 1); |
| 514 | |
| 515 | /* android.reprocess. */ |
| 516 | |
| 517 | // REPROCESSING not supported by this HAL. |
| 518 | |
| 519 | /* android.depth. */ |
| 520 | |
| 521 | // DEPTH not supported by this HAL. |
| 522 | |
| 523 | /* Capabilities and android.info. */ |
| 524 | |
| 525 | uint8_t hw_level = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; |
| 526 | ADD_STATIC_ENTRY(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, |
| 527 | &hw_level, 1); |
| 528 | |
| 529 | uint8_t capabilities[] = { |
| 530 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE}; |
| 531 | ADD_STATIC_ENTRY(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, |
| 532 | capabilities, ARRAY_SIZE(capabilities)); |
| 533 | |
| 534 | // TODO(b/29221795): available request keys |
| 535 | // (fill in when writing default requests). |
| 536 | |
| 537 | // TODO(b/29335262): available result keys |
| 538 | // (fill in when writing actual result capture). |
| 539 | |
| 540 | // Last thing, once all the available characteristics have been added. |
| 541 | info.update(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, |
| 542 | &avail_characteristics_keys[0], |
| 543 | avail_characteristics_keys.size()); |
| 544 | |
| 545 | *out = info.release(); |
| 546 | return 0; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | void V4L2Camera::initDeviceInfo(camera_info_t* info) { |
| 550 | HAL_LOG_ENTER(); |
| 551 | |
| 552 | // For now, just constants. |
| 553 | info->facing = CAMERA_FACING_EXTERNAL; |
| 554 | info->orientation = 0; |
| 555 | info->resource_cost = 100; |
| 556 | info->conflicting_devices = nullptr; |
| 557 | info->conflicting_devices_length = 0; |
| 558 | } |
| 559 | |
| 560 | int V4L2Camera::initDevice() { |
| 561 | HAL_LOG_ENTER(); |
| 562 | |
| 563 | // TODO(b/29221795): fill in templates, etc. |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | bool V4L2Camera::isValidCaptureSettings(const camera_metadata_t* settings) { |
| 568 | HAL_LOG_ENTER(); |
| 569 | |
| 570 | // TODO(b): reject capture settings this camera isn't capable of. |
| 571 | return true; |
| 572 | } |
| 573 | |
| 574 | } // namespace v4l2_camera_hal |