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> |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 20 | #include <linux/videodev2.h> |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
| 23 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 24 | #include <cstdlib> |
| 25 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 26 | #include <camera/CameraMetadata.h> |
| 27 | #include <hardware/camera3.h> |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 28 | #include <nativehelper/ScopedFd.h> |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 29 | |
| 30 | #include "Common.h" |
| 31 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 32 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) |
| 33 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 34 | namespace v4l2_camera_hal { |
| 35 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 36 | // Helper function for managing metadata. |
| 37 | static std::vector<int32_t> getMetadataKeys( |
| 38 | const camera_metadata_t* metadata) { |
| 39 | std::vector<int32_t> keys; |
| 40 | size_t num_entries = get_camera_metadata_entry_count(metadata); |
| 41 | for (size_t i = 0; i < num_entries; ++i) { |
| 42 | camera_metadata_ro_entry_t entry; |
| 43 | get_camera_metadata_ro_entry(metadata, i, &entry); |
| 44 | keys.push_back(entry.tag); |
| 45 | } |
| 46 | return keys; |
| 47 | } |
| 48 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 49 | V4L2Camera::V4L2Camera(int id, std::string path) |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 50 | : default_camera_hal::Camera(id), |
| 51 | mDevicePath(std::move(path)), |
| 52 | mTemplatesInitialized(false), |
| 53 | mCharacteristicsInitialized(false) { |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 54 | HAL_LOG_ENTER(); |
| 55 | } |
| 56 | |
| 57 | V4L2Camera::~V4L2Camera() { |
| 58 | HAL_LOG_ENTER(); |
| 59 | } |
| 60 | |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 61 | int V4L2Camera::connect() { |
| 62 | HAL_LOG_ENTER(); |
| 63 | |
| 64 | if (mDeviceFd.get() >= 0) { |
| 65 | HAL_LOGE("Camera device %s is opened. Close it first", mDevicePath.c_str()); |
| 66 | return -EIO; |
| 67 | } |
| 68 | |
| 69 | int fd = TEMP_FAILURE_RETRY(open(mDevicePath.c_str(), O_RDWR)); |
| 70 | if (fd < 0) { |
| 71 | HAL_LOGE("failed to open %s (%s)", mDevicePath.c_str(), strerror(errno)); |
| 72 | return -errno; |
| 73 | } |
| 74 | mDeviceFd.reset(fd); |
| 75 | |
| 76 | // TODO(b/29185945): confirm this is a supported device. |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 77 | // This is checked by the HAL, but the device at mDevicePath may |
| 78 | // not be the same one that was there when the HAL was loaded. |
| 79 | // (Alternatively, better hotplugging support may make this unecessary |
| 80 | // by disabling cameras that get disconnected and checking newly connected |
| 81 | // cameras, so connect() is never called on an unsupported camera) |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 82 | |
| 83 | // TODO(b/29158098): Inform service of any flashes that are no longer available |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 84 | // because this camera is in use. |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | void V4L2Camera::disconnect() { |
| 89 | HAL_LOG_ENTER(); |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 90 | // TODO(b/29158098): Inform service of any flashes that are available again |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 91 | // because this camera is no longer in use. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 92 | |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 93 | mDeviceFd.reset(); |
| 94 | } |
| 95 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 96 | int V4L2Camera::initStaticInfo(camera_metadata_t** out) { |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 97 | HAL_LOG_ENTER(); |
| 98 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 99 | android::status_t res; |
| 100 | // Device characteristics need to be queried prior |
| 101 | // to static info setup. |
| 102 | if (!mCharacteristicsInitialized) { |
| 103 | res = initCharacteristics(); |
| 104 | if (res) { |
| 105 | return res; |
| 106 | } |
| 107 | } |
| 108 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 109 | android::CameraMetadata info; |
Ari Hausman-Cohen | 63f6982 | 2016-06-10 11:40:35 -0700 | [diff] [blame] | 110 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 111 | // Static metadata characteristics from /system/media/camera/docs/docs.html. |
| 112 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 113 | /* android.colorCorrection. */ |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 114 | |
| 115 | // No easy way to turn chromatic aberration correction OFF in v4l2, |
| 116 | // though this may be supportable via a collection of other user controls. |
| 117 | uint8_t avail_aberration_modes[] = { |
| 118 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE_FAST, |
| 119 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 120 | res = info.update(ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, |
| 121 | avail_aberration_modes, ARRAY_SIZE(avail_aberration_modes)); |
| 122 | if (res != android::OK) { |
| 123 | return res; |
| 124 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 125 | |
| 126 | /* android.control. */ |
| 127 | |
| 128 | /* 3As */ |
| 129 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 130 | res = info.update(ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, |
| 131 | mAeAntibandingModes.data(), mAeAntibandingModes.size()); |
| 132 | if (res != android::OK) { |
| 133 | return res; |
| 134 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 135 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 136 | res = info.update(ANDROID_CONTROL_AE_AVAILABLE_MODES, |
| 137 | mAeModes.data(), mAeModes.size()); |
| 138 | if (res != android::OK) { |
| 139 | return res; |
| 140 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 141 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 142 | // Flatten mFpsRanges. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 143 | res = info.update(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, |
| 144 | mFpsRanges.data(), mFpsRanges.total_num_elements()); |
| 145 | if (res != android::OK) { |
| 146 | return res; |
| 147 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 148 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 149 | res = info.update(ANDROID_CONTROL_AE_COMPENSATION_RANGE, |
| 150 | mAeCompensationRange.data(), mAeCompensationRange.size()); |
| 151 | if (res != android::OK) { |
| 152 | return res; |
| 153 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 154 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 155 | res = info.update(ANDROID_CONTROL_AE_COMPENSATION_STEP, |
| 156 | &mAeCompensationStep, 1); |
| 157 | if (res != android::OK) { |
| 158 | return res; |
| 159 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 160 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 161 | res = info.update(ANDROID_CONTROL_AF_AVAILABLE_MODES, |
| 162 | mAfModes.data(), mAfModes.size()); |
| 163 | if (res != android::OK) { |
| 164 | return res; |
| 165 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 166 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 167 | res = info.update(ANDROID_CONTROL_AWB_AVAILABLE_MODES, |
| 168 | mAwbModes.data(), mAwbModes.size()); |
| 169 | if (res != android::OK) { |
| 170 | return res; |
| 171 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 172 | |
| 173 | // Couldn't find any V4L2 support for regions, though maybe it's out there. |
| 174 | int32_t max_regions[] = {/*AE*/ 0,/*AWB*/ 0,/*AF*/ 0}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 175 | res = info.update(ANDROID_CONTROL_MAX_REGIONS, |
| 176 | max_regions, ARRAY_SIZE(max_regions)); |
| 177 | if (res != android::OK) { |
| 178 | return res; |
| 179 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 180 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 181 | res = info.update(ANDROID_CONTROL_AE_LOCK_AVAILABLE, |
| 182 | &mAeLockAvailable, 1); |
| 183 | if (res != android::OK) { |
| 184 | return res; |
| 185 | } |
| 186 | res = info.update(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, |
| 187 | &mAwbLockAvailable, 1); |
| 188 | if (res != android::OK) { |
| 189 | return res; |
| 190 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 191 | |
| 192 | /* Scene modes. */ |
| 193 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 194 | res = info.update(ANDROID_CONTROL_AVAILABLE_SCENE_MODES, |
| 195 | mSceneModes.data(), mSceneModes.size()); |
| 196 | if (res != android::OK) { |
| 197 | return res; |
| 198 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 199 | |
| 200 | // A 3-tuple of AE, AWB, AF overrides for each scene mode. |
| 201 | // Ignored for DISABLED, FACE_PRIORITY and FACE_PRIORITY_LOW_LIGHT. |
| 202 | uint8_t scene_mode_overrides[] = { |
| 203 | /*SCENE_MODE_DISABLED*/ /*AE*/0, /*AW*/0, /*AF*/0}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 204 | res = info.update(ANDROID_CONTROL_SCENE_MODE_OVERRIDES, |
| 205 | scene_mode_overrides, ARRAY_SIZE(scene_mode_overrides)); |
| 206 | if (res != android::OK) { |
| 207 | return res; |
| 208 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 209 | |
| 210 | /* Top level 3A/Scenes switch. */ |
| 211 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 212 | res = info.update(ANDROID_CONTROL_AVAILABLE_MODES, |
| 213 | mControlModes.data(), mControlModes.size()); |
| 214 | if (res != android::OK) { |
| 215 | return res; |
| 216 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 217 | |
| 218 | /* Other android.control configuration. */ |
| 219 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 220 | res = info.update(ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, |
| 221 | mVideoStabilizationModes.data(), |
| 222 | mVideoStabilizationModes.size()); |
| 223 | if (res != android::OK) { |
| 224 | return res; |
| 225 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 226 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 227 | res = info.update(ANDROID_CONTROL_AVAILABLE_EFFECTS, |
| 228 | mEffects.data(), mEffects.size()); |
| 229 | if (res != android::OK) { |
| 230 | return res; |
| 231 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 232 | |
| 233 | // AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS only necessary |
| 234 | // for devices supporting CONSTRAINED_HIGH_SPEED_VIDEO, |
| 235 | // which this HAL doesn't support. |
| 236 | |
| 237 | // POST_RAW_SENSITIVITY_BOOST_RANGE only necessary |
| 238 | // for devices supporting RAW format outputs. |
| 239 | |
| 240 | /* android.edge. */ |
| 241 | |
| 242 | // Not sure if V4L2 does or doesn't do this, but HAL documentation says |
| 243 | // all devices must support FAST, and FAST can be equivalent to OFF, so |
| 244 | // either way it's fine to list. |
| 245 | uint8_t avail_edge_modes[] = { |
| 246 | ANDROID_EDGE_MODE_FAST}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 247 | res = info.update(ANDROID_EDGE_AVAILABLE_EDGE_MODES, |
| 248 | avail_edge_modes, ARRAY_SIZE(avail_edge_modes)); |
| 249 | if (res != android::OK) { |
| 250 | return res; |
| 251 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 252 | |
| 253 | /* android.flash. */ |
| 254 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 255 | res = info.update(ANDROID_FLASH_INFO_AVAILABLE, |
| 256 | &mFlashAvailable, 1); |
| 257 | if (res != android::OK) { |
| 258 | return res; |
| 259 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 260 | |
| 261 | // info.chargeDuration, color.Temperature, maxEnergy marked FUTURE. |
| 262 | |
| 263 | /* android.hotPixel. */ |
| 264 | |
| 265 | // No known V4L2 hot pixel correction. But it might be happening, |
| 266 | // so we report FAST/HIGH_QUALITY. |
| 267 | uint8_t avail_hot_pixel_modes[] = { |
| 268 | ANDROID_HOT_PIXEL_MODE_FAST, |
| 269 | ANDROID_HOT_PIXEL_MODE_HIGH_QUALITY}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 270 | res = info.update(ANDROID_HOT_PIXEL_AVAILABLE_HOT_PIXEL_MODES, |
| 271 | avail_hot_pixel_modes, ARRAY_SIZE(avail_hot_pixel_modes)); |
| 272 | if (res != android::OK) { |
| 273 | return res; |
| 274 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 275 | |
| 276 | /* android.jpeg. */ |
| 277 | |
| 278 | // For now, no thumbnails available (only [0,0], the "no thumbnail" size). |
| 279 | // TODO(b/29580107): Could end up with a mismatch between request & result, |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 280 | // since V4L2 doesn't actually allow for thumbnail size control. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 281 | int32_t thumbnail_sizes[] = { |
| 282 | 0, 0}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 283 | res = info.update(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
| 284 | thumbnail_sizes, ARRAY_SIZE(thumbnail_sizes)); |
| 285 | if (res != android::OK) { |
| 286 | return res; |
| 287 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 288 | |
| 289 | // V4L2 doesn't support querying this, so we generously assume up to 3 MB. |
| 290 | int32_t max_jpeg_size = 3000000; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 291 | res = info.update(ANDROID_JPEG_MAX_SIZE, |
| 292 | &max_jpeg_size, 1); |
| 293 | if (res != android::OK) { |
| 294 | return res; |
| 295 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 296 | |
| 297 | /* android.lens. */ |
| 298 | |
| 299 | /* Misc. lens control. */ |
| 300 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 301 | res = info.update(ANDROID_LENS_INFO_AVAILABLE_APERTURES, |
| 302 | &mAperture, 1); |
| 303 | if (res != android::OK) { |
| 304 | return res; |
| 305 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 306 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 307 | res = info.update(ANDROID_LENS_INFO_AVAILABLE_FILTER_DENSITIES, |
| 308 | &mFilterDensity, 1); |
| 309 | if (res != android::OK) { |
| 310 | return res; |
| 311 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 312 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 313 | res = info.update(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, |
| 314 | mOpticalStabilizationModes.data(), |
| 315 | mOpticalStabilizationModes.size()); |
| 316 | if (res != android::OK) { |
| 317 | return res; |
| 318 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 319 | |
| 320 | // No known V4L2 shading map info. |
| 321 | int32_t shading_map_size[] = {1, 1}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 322 | res = info.update(ANDROID_LENS_INFO_SHADING_MAP_SIZE, |
| 323 | shading_map_size, ARRAY_SIZE(shading_map_size)); |
| 324 | if (res != android::OK) { |
| 325 | return res; |
| 326 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 327 | |
| 328 | // All V4L2 devices are considered to be external facing. |
| 329 | uint8_t facing = ANDROID_LENS_FACING_EXTERNAL; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 330 | res = info.update(ANDROID_LENS_FACING, &facing, 1); |
| 331 | if (res != android::OK) { |
| 332 | return res; |
| 333 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 334 | |
| 335 | /* Zoom/Focus. */ |
| 336 | |
| 337 | // No way to actually get the focal length in V4L2, but it's a required key, |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 338 | // so we just fake it. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 339 | res = info.update(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
| 340 | &mFocalLength, 1); |
| 341 | if (res != android::OK) { |
| 342 | return res; |
| 343 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 344 | |
| 345 | // V4L2 focal units do not correspond to a particular physical unit. |
| 346 | uint8_t focus_calibration = |
| 347 | ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_UNCALIBRATED; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 348 | res = info.update(ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION, |
| 349 | &focus_calibration, 1); |
| 350 | if (res != android::OK) { |
| 351 | return res; |
| 352 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 353 | |
| 354 | // info.hyperfocalDistance not required for UNCALIBRATED. |
| 355 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 356 | res = info.update(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, |
| 357 | &mFocusDistance, 1); |
| 358 | if (res != android::OK) { |
| 359 | return res; |
| 360 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 361 | |
| 362 | /* Depth. */ |
| 363 | |
| 364 | // DEPTH capability not supported by this HAL. Not implemented: |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 365 | // poseRotation |
| 366 | // poseTranslation |
| 367 | // intrinsicCalibration |
| 368 | // radialDistortion |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 369 | |
| 370 | /* anroid.noise. */ |
| 371 | |
| 372 | // Unable to control noise reduction in V4L2 devices, |
| 373 | // but FAST is allowed to be the same as OFF. |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 374 | uint8_t avail_noise_reduction_modes[] = {ANDROID_NOISE_REDUCTION_MODE_FAST}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 375 | res = info.update(ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, |
| 376 | avail_noise_reduction_modes, |
| 377 | ARRAY_SIZE(avail_noise_reduction_modes)); |
| 378 | if (res != android::OK) { |
| 379 | return res; |
| 380 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 381 | |
| 382 | /* android.request. */ |
| 383 | |
| 384 | // Resources may be an issue, so just using minimum allowable |
| 385 | // for LIMITED devices. |
| 386 | int32_t max_num_output_streams[] = { |
| 387 | /*Raw*/0, /*YUV*/2, /*JPEG*/1}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 388 | res = info.update(ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS, |
| 389 | max_num_output_streams, ARRAY_SIZE(max_num_output_streams)); |
| 390 | if (res != android::OK) { |
| 391 | return res; |
| 392 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 393 | |
| 394 | // Reprocessing not supported, so no maxNumInputStreams. |
| 395 | |
| 396 | // No way to know for V4L2, so fake with max allowable latency. |
| 397 | // Doesn't mean much without per-frame controls. |
| 398 | uint8_t pipeline_max_depth = 4; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 399 | res = info.update(ANDROID_REQUEST_PIPELINE_MAX_DEPTH, |
| 400 | &pipeline_max_depth, 1); |
| 401 | if (res != android::OK) { |
| 402 | return res; |
| 403 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 404 | |
| 405 | // Partial results not supported; partialResultCount defaults to 1. |
| 406 | |
| 407 | // Available capabilities & keys queried at very end of this method. |
| 408 | |
| 409 | /* android.scaler. */ |
| 410 | |
| 411 | /* Cropping. */ |
| 412 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 413 | res = info.update(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, |
| 414 | &mMaxZoom, 1); |
| 415 | if (res != android::OK) { |
| 416 | return res; |
| 417 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 418 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 419 | res = info.update(ANDROID_SCALER_CROPPING_TYPE, &mCropType, 1); |
| 420 | if (res != android::OK) { |
| 421 | return res; |
| 422 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 423 | |
| 424 | /* Streams. */ |
| 425 | |
| 426 | // availableInputOutputFormatsMap only required for reprocessing capability. |
| 427 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 428 | // Flatten mStreamConfigs. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 429 | res = info.update(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, |
| 430 | mStreamConfigs.data(), |
| 431 | mStreamConfigs.total_num_elements()); |
| 432 | if (res != android::OK) { |
| 433 | return res; |
| 434 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 435 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 436 | // Flatten mMinFrameDurations. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 437 | res = info.update(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, |
| 438 | mMinFrameDurations.data(), |
| 439 | mMinFrameDurations.total_num_elements()); |
| 440 | if (res != android::OK) { |
| 441 | return res; |
| 442 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 443 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 444 | // Flatten mStallDurations. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 445 | res = info.update(ANDROID_SCALER_AVAILABLE_STALL_DURATIONS, |
| 446 | mStallDurations.data(), |
| 447 | mStallDurations.total_num_elements()); |
| 448 | if (res != android::OK) { |
| 449 | return res; |
| 450 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 451 | |
| 452 | /* android.sensor. */ |
| 453 | |
| 454 | /* Sizes. */ |
| 455 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 456 | res = info.update(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, |
| 457 | mPixelArraySize.data(), mPixelArraySize.size()); |
| 458 | if (res != android::OK) { |
| 459 | return res; |
| 460 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 461 | // No V4L2 way to differentiate active vs. inactive parts of the rectangle. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 462 | res = info.update(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, |
| 463 | mPixelArraySize.data(), mPixelArraySize.size()); |
| 464 | if (res != android::OK) { |
| 465 | return res; |
| 466 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 467 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 468 | res = info.update(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
| 469 | mPhysicalSize.data(), mPhysicalSize.size()); |
| 470 | if (res != android::OK) { |
| 471 | return res; |
| 472 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 473 | |
| 474 | /* Misc sensor information. */ |
| 475 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 476 | res = info.update(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION, |
| 477 | &mMaxFrameDuration, 1); |
| 478 | if (res != android::OK) { |
| 479 | return res; |
| 480 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 481 | |
| 482 | // HAL uses BOOTTIME timestamps. |
| 483 | // TODO(b/29457051): make sure timestamps are consistent throughout the HAL. |
| 484 | uint8_t timestamp_source = ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 485 | res = info.update(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, |
| 486 | ×tamp_source, 1); |
| 487 | if (res != android::OK) { |
| 488 | return res; |
| 489 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 490 | |
| 491 | // As in initDeviceInfo, no way to actually get orientation. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 492 | res = info.update(ANDROID_SENSOR_ORIENTATION, &mOrientation, 1); |
| 493 | if (res != android::OK) { |
| 494 | return res; |
| 495 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 496 | |
| 497 | // availableTestPatternModes just defaults to OFF, which is fine. |
| 498 | |
| 499 | // info.exposureTimeRange, info.sensitivityRange: |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 500 | // exposure/sensitivity manual control not supported. |
| 501 | // Could query V4L2_CID_ISO_SENSITIVITY to support sensitivity if desired. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 502 | |
| 503 | // info.whiteLevel, info.lensShadingApplied, |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 504 | // info.preCorrectionPixelArraySize, referenceIlluminant1/2, |
| 505 | // calibrationTransform1/2, colorTransform1/2, forwardMatrix1/2, |
| 506 | // blackLevelPattern, profileHueSatMapDimensions |
| 507 | // all only necessary for RAW. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 508 | |
| 509 | // baseGainFactor marked FUTURE. |
| 510 | |
| 511 | // maxAnalogSensitivity optional for LIMITED device. |
| 512 | |
| 513 | // opticalBlackRegions: No known way to get in V4L2, but not necessary. |
| 514 | |
| 515 | // opaqueRawSize not necessary since RAW_OPAQUE format not supported. |
| 516 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 517 | /* android.shading */ |
| 518 | |
| 519 | // No known V4L2 lens shading. But it might be happening, |
| 520 | // so we report FAST/HIGH_QUALITY. |
| 521 | uint8_t avail_shading_modes[] = { |
| 522 | ANDROID_SHADING_MODE_FAST, |
| 523 | ANDROID_SHADING_MODE_HIGH_QUALITY}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 524 | res = info.update(ANDROID_SHADING_AVAILABLE_MODES, |
| 525 | avail_shading_modes, ARRAY_SIZE(avail_shading_modes)); |
| 526 | if (res != android::OK) { |
| 527 | return res; |
| 528 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 529 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 530 | /* android.statistics */ |
| 531 | |
| 532 | // Face detection not supported. |
| 533 | uint8_t avail_face_detect_modes[] = { |
| 534 | ANDROID_STATISTICS_FACE_DETECT_MODE_OFF}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 535 | res = info.update(ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, |
| 536 | avail_face_detect_modes, |
| 537 | ARRAY_SIZE(avail_face_detect_modes)); |
| 538 | if (res != android::OK) { |
| 539 | return res; |
| 540 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 541 | |
| 542 | int32_t max_face_count = 0; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 543 | res = info.update(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, |
| 544 | &max_face_count, 1); |
| 545 | if (res != android::OK) { |
| 546 | return res; |
| 547 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 548 | |
| 549 | // info.histogramBucketCount, info.maxHistogramCount, |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 550 | // info.maxSharpnessMapValue, info.sharpnessMapSizemarked FUTURE. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 551 | |
| 552 | // ON only needs to be supported for RAW capable devices. |
| 553 | uint8_t avail_hot_pixel_map_modes[] = { |
| 554 | ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE_OFF}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 555 | res = info.update(ANDROID_STATISTICS_INFO_AVAILABLE_HOT_PIXEL_MAP_MODES, |
| 556 | avail_hot_pixel_map_modes, |
| 557 | ARRAY_SIZE(avail_hot_pixel_map_modes)); |
| 558 | if (res != android::OK) { |
| 559 | return res; |
| 560 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 561 | |
| 562 | // ON only needs to be supported for RAW capable devices. |
| 563 | uint8_t avail_lens_shading_map_modes[] = { |
| 564 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 565 | res = info.update(ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES, |
| 566 | avail_lens_shading_map_modes, |
| 567 | ARRAY_SIZE(avail_lens_shading_map_modes)); |
| 568 | if (res != android::OK) { |
| 569 | return res; |
| 570 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 571 | |
| 572 | /* android.tonemap. */ |
| 573 | |
| 574 | // tonemapping only required for MANUAL_POST_PROCESSING capability. |
| 575 | |
| 576 | /* android.led. */ |
| 577 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 578 | // May or may not have LEDs available. |
| 579 | if (!mLeds.empty()) { |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 580 | res = info.update(ANDROID_LED_AVAILABLE_LEDS, mLeds.data(), mLeds.size()); |
| 581 | if (res != android::OK) { |
| 582 | return res; |
| 583 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 584 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 585 | |
| 586 | /* android.sync. */ |
| 587 | |
| 588 | // "LIMITED devices are strongly encouraged to use a non-negative value. |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 589 | // If UNKNOWN is used here then app developers do not have a way to know |
| 590 | // when sensor settings have been applied." - Unfortunately, V4L2 doesn't |
| 591 | // really help here either. Could even be that adjusting settings mid-stream |
| 592 | // blocks in V4L2, and should be avoided. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 593 | int32_t max_latency = ANDROID_SYNC_MAX_LATENCY_UNKNOWN; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 594 | res = info.update(ANDROID_SYNC_MAX_LATENCY, |
| 595 | &max_latency, 1); |
| 596 | if (res != android::OK) { |
| 597 | return res; |
| 598 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 599 | |
| 600 | /* android.reprocess. */ |
| 601 | |
| 602 | // REPROCESSING not supported by this HAL. |
| 603 | |
| 604 | /* android.depth. */ |
| 605 | |
| 606 | // DEPTH not supported by this HAL. |
| 607 | |
| 608 | /* Capabilities and android.info. */ |
| 609 | |
| 610 | uint8_t hw_level = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 611 | res = info.update(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, |
| 612 | &hw_level, 1); |
| 613 | if (res != android::OK) { |
| 614 | return res; |
| 615 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 616 | |
| 617 | uint8_t capabilities[] = { |
| 618 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 619 | res = info.update(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, |
| 620 | capabilities, ARRAY_SIZE(capabilities)); |
| 621 | if (res != android::OK) { |
| 622 | return res; |
| 623 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 624 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 625 | // Scan a default request template for included request keys. |
| 626 | if (!mTemplatesInitialized) { |
| 627 | res = initTemplates(); |
| 628 | if (res) { |
| 629 | return res; |
| 630 | } |
| 631 | } |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 632 | const camera_metadata_t* preview_request = nullptr; |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 633 | // Search templates from the beginning for a supported one. |
| 634 | for (uint8_t template_id = 1; template_id < CAMERA3_TEMPLATE_COUNT; |
| 635 | ++template_id) { |
| 636 | preview_request = constructDefaultRequestSettings(template_id); |
| 637 | if (preview_request != nullptr) { |
| 638 | break; |
| 639 | } |
| 640 | } |
| 641 | if (preview_request == nullptr) { |
| 642 | HAL_LOGE("No valid templates, can't get request keys."); |
| 643 | return -ENODEV; |
| 644 | } |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 645 | std::vector<int32_t> avail_request_keys = getMetadataKeys(preview_request); |
| 646 | res = info.update(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS, |
| 647 | avail_request_keys.data(), avail_request_keys.size()); |
| 648 | if (res != android::OK) { |
| 649 | return res; |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 650 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 651 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 652 | // Result keys will be duplicated from the request, plus a few extras. |
| 653 | // TODO(b/29335262): additonal available result keys. |
| 654 | std::vector<int32_t> avail_result_keys(avail_request_keys); |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 655 | res = info.update(ANDROID_REQUEST_AVAILABLE_RESULT_KEYS, |
| 656 | avail_result_keys.data(), avail_result_keys.size()); |
| 657 | if (res != android::OK) { |
| 658 | return res; |
| 659 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 660 | |
| 661 | // Last thing, once all the available characteristics have been added. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 662 | const camera_metadata_t* static_characteristics = info.getAndLock(); |
| 663 | std::vector<int32_t> avail_characteristics_keys = |
| 664 | getMetadataKeys(static_characteristics); |
| 665 | res = info.unlock(static_characteristics); |
| 666 | if (res != android::OK) { |
| 667 | return res; |
| 668 | } |
| 669 | avail_characteristics_keys.push_back( |
| 670 | ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS); |
| 671 | res = info.update(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, |
| 672 | avail_characteristics_keys.data(), |
| 673 | avail_characteristics_keys.size()); |
| 674 | if (res != android::OK) { |
| 675 | return res; |
| 676 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 677 | |
| 678 | *out = info.release(); |
| 679 | return 0; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | void V4L2Camera::initDeviceInfo(camera_info_t* info) { |
| 683 | HAL_LOG_ENTER(); |
| 684 | |
| 685 | // For now, just constants. |
| 686 | info->facing = CAMERA_FACING_EXTERNAL; |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 687 | info->orientation = mOrientation; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 688 | info->resource_cost = 100; |
| 689 | info->conflicting_devices = nullptr; |
| 690 | info->conflicting_devices_length = 0; |
| 691 | } |
| 692 | |
| 693 | int V4L2Camera::initDevice() { |
| 694 | HAL_LOG_ENTER(); |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 695 | int res; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 696 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 697 | // Templates should be set up if they haven't already been. |
| 698 | if (!mTemplatesInitialized) { |
| 699 | res = initTemplates(); |
| 700 | if (res) { |
| 701 | return res; |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | int V4L2Camera::initTemplates() { |
| 709 | HAL_LOG_ENTER(); |
| 710 | int res; |
| 711 | |
| 712 | // Device characteristics need to be queried prior |
| 713 | // to template setup. |
| 714 | if (!mCharacteristicsInitialized) { |
| 715 | res = initCharacteristics(); |
| 716 | if (res) { |
| 717 | return res; |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | // Note: static metadata expects all templates/requests |
| 722 | // to provide values for all supported keys. |
| 723 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 724 | android::CameraMetadata base_metadata; |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 725 | |
| 726 | // Start with defaults for all templates. |
| 727 | |
| 728 | /* android.colorCorrection. */ |
| 729 | |
| 730 | uint8_t aberration_mode = ANDROID_COLOR_CORRECTION_ABERRATION_MODE_FAST; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 731 | res = base_metadata.update(ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 732 | &aberration_mode, 1); |
| 733 | if (res != android::OK) { |
| 734 | return res; |
| 735 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 736 | |
| 737 | uint8_t color_correction_mode = ANDROID_COLOR_CORRECTION_MODE_FAST; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 738 | res = base_metadata.update(ANDROID_COLOR_CORRECTION_MODE, |
| 739 | &color_correction_mode, 1); |
| 740 | if (res != android::OK) { |
| 741 | return res; |
| 742 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 743 | |
| 744 | // transform and gains are for the unsupported MANUAL_POST_PROCESSING only. |
| 745 | |
| 746 | /* android.control. */ |
| 747 | |
| 748 | /* AE. */ |
| 749 | uint8_t ae_antibanding_mode = ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 750 | res = base_metadata.update(ANDROID_CONTROL_AE_ANTIBANDING_MODE, |
| 751 | &ae_antibanding_mode, 1); |
| 752 | if (res != android::OK) { |
| 753 | return res; |
| 754 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 755 | |
| 756 | // Only matters if AE_MODE = OFF |
| 757 | int32_t ae_exposure_compensation = 0; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 758 | res = base_metadata.update(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
| 759 | &ae_exposure_compensation, 1); |
| 760 | if (res != android::OK) { |
| 761 | return res; |
| 762 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 763 | |
| 764 | uint8_t ae_lock = ANDROID_CONTROL_AE_LOCK_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 765 | res = base_metadata.update(ANDROID_CONTROL_AE_LOCK, &ae_lock, 1); |
| 766 | if (res != android::OK) { |
| 767 | return res; |
| 768 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 769 | |
| 770 | uint8_t ae_mode = ANDROID_CONTROL_AE_MODE_ON; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 771 | res = base_metadata.update(ANDROID_CONTROL_AE_MODE, &ae_mode, 1); |
| 772 | if (res != android::OK) { |
| 773 | return res; |
| 774 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 775 | |
| 776 | // AE regions not supported. |
| 777 | |
| 778 | // FPS set per-template. |
| 779 | |
| 780 | uint8_t ae_precapture_trigger = ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 781 | res = base_metadata.update(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
| 782 | &ae_precapture_trigger, 1); |
| 783 | if (res != android::OK) { |
| 784 | return res; |
| 785 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 786 | |
| 787 | /* AF. */ |
| 788 | |
| 789 | // AF mode set per-template. |
| 790 | |
| 791 | // AF regions not supported. |
| 792 | |
| 793 | uint8_t af_trigger = ANDROID_CONTROL_AF_TRIGGER_IDLE; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 794 | res = base_metadata.update(ANDROID_CONTROL_AF_TRIGGER, &af_trigger, 1); |
| 795 | if (res != android::OK) { |
| 796 | return res; |
| 797 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 798 | |
| 799 | /* AWB. */ |
| 800 | |
| 801 | // Priority: auto > off > Whatever is available. |
| 802 | uint8_t default_awb_mode = mAwbModes[0]; |
| 803 | if (std::count(mAwbModes.begin(), mAwbModes.end(), |
| 804 | ANDROID_CONTROL_AWB_MODE_AUTO)) { |
| 805 | default_awb_mode = ANDROID_CONTROL_AWB_MODE_AUTO; |
| 806 | } else if (std::count(mAwbModes.begin(), mAwbModes.end(), |
| 807 | ANDROID_CONTROL_AWB_MODE_OFF)) { |
| 808 | default_awb_mode = ANDROID_CONTROL_AWB_MODE_OFF; |
| 809 | } |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 810 | res = base_metadata.update(ANDROID_CONTROL_AWB_MODE, &default_awb_mode, 1); |
| 811 | if (res != android::OK) { |
| 812 | return res; |
| 813 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 814 | |
| 815 | // AWB regions not supported. |
| 816 | |
| 817 | /* Other controls. */ |
| 818 | |
| 819 | uint8_t effect_mode = ANDROID_CONTROL_EFFECT_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 820 | res = base_metadata.update(ANDROID_CONTROL_EFFECT_MODE, &effect_mode, 1); |
| 821 | if (res != android::OK) { |
| 822 | return res; |
| 823 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 824 | |
| 825 | uint8_t control_mode = ANDROID_CONTROL_MODE_AUTO; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 826 | res = base_metadata.update(ANDROID_CONTROL_MODE, &control_mode, 1); |
| 827 | if (res != android::OK) { |
| 828 | return res; |
| 829 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 830 | |
| 831 | uint8_t scene_mode = ANDROID_CONTROL_SCENE_MODE_DISABLED; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 832 | res = base_metadata.update(ANDROID_CONTROL_SCENE_MODE, |
| 833 | &scene_mode, 1); |
| 834 | if (res != android::OK) { |
| 835 | return res; |
| 836 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 837 | |
| 838 | uint8_t video_stabilization = ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 839 | res = base_metadata.update(ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, |
| 840 | &video_stabilization, 1); |
| 841 | if (res != android::OK) { |
| 842 | return res; |
| 843 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 844 | |
| 845 | // postRawSensitivityBoost: RAW not supported, leave null. |
| 846 | |
| 847 | /* android.demosaic. */ |
| 848 | |
| 849 | // mode marked FUTURE. |
| 850 | |
| 851 | /* android.edge. */ |
| 852 | |
| 853 | uint8_t edge_mode = ANDROID_EDGE_MODE_FAST; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 854 | res = base_metadata.update(ANDROID_EDGE_MODE, &edge_mode, 1); |
| 855 | if (res != android::OK) { |
| 856 | return res; |
| 857 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 858 | |
| 859 | // strength marked FUTURE. |
| 860 | |
| 861 | /* android.flash. */ |
| 862 | |
| 863 | // firingPower, firingTime marked FUTURE. |
| 864 | |
| 865 | uint8_t flash_mode = ANDROID_FLASH_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 866 | res = base_metadata.update(ANDROID_FLASH_MODE, &flash_mode, 1); |
| 867 | if (res != android::OK) { |
| 868 | return res; |
| 869 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 870 | |
| 871 | /* android.hotPixel. */ |
| 872 | |
| 873 | uint8_t hp_mode = ANDROID_HOT_PIXEL_MODE_FAST; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 874 | res = base_metadata.update(ANDROID_HOT_PIXEL_MODE, &hp_mode, 1); |
| 875 | if (res != android::OK) { |
| 876 | return res; |
| 877 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 878 | |
| 879 | /* android.jpeg. */ |
| 880 | |
| 881 | double gps_coords[] = {/*latitude*/0, /*longitude*/0, /*altitude*/0}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 882 | res = base_metadata.update(ANDROID_JPEG_GPS_COORDINATES, gps_coords, 3); |
| 883 | if (res != android::OK) { |
| 884 | return res; |
| 885 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 886 | |
| 887 | uint8_t gps_processing_method[] = "none"; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 888 | res = base_metadata.update(ANDROID_JPEG_GPS_PROCESSING_METHOD, |
| 889 | gps_processing_method, |
| 890 | ARRAY_SIZE(gps_processing_method)); |
| 891 | if (res != android::OK) { |
| 892 | return res; |
| 893 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 894 | |
| 895 | int64_t gps_timestamp = 0; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 896 | res = base_metadata.update(ANDROID_JPEG_GPS_TIMESTAMP, &gps_timestamp, 1); |
| 897 | if (res != android::OK) { |
| 898 | return res; |
| 899 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 900 | |
| 901 | // JPEG orientation is relative to sensor orientation (mOrientation). |
| 902 | int32_t jpeg_orientation = 0; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 903 | res = base_metadata.update(ANDROID_JPEG_ORIENTATION, &jpeg_orientation, 1); |
| 904 | if (res != android::OK) { |
| 905 | return res; |
| 906 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 907 | |
| 908 | // 1-100, larger is higher quality. |
| 909 | uint8_t jpeg_quality = 80; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 910 | res = base_metadata.update(ANDROID_JPEG_QUALITY, &jpeg_quality, 1); |
| 911 | if (res != android::OK) { |
| 912 | return res; |
| 913 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 914 | |
| 915 | // TODO(b/29580107): If thumbnail quality actually matters/can be adjusted, |
| 916 | // adjust this. |
| 917 | uint8_t thumbnail_quality = 80; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 918 | res = base_metadata.update(ANDROID_JPEG_THUMBNAIL_QUALITY, |
| 919 | &thumbnail_quality, 1); |
| 920 | if (res != android::OK) { |
| 921 | return res; |
| 922 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 923 | |
| 924 | // TODO(b/29580107): Choose a size matching the resolution. |
| 925 | int32_t thumbnail_size[] = {0, 0}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 926 | res = base_metadata.update(ANDROID_JPEG_THUMBNAIL_SIZE, thumbnail_size, 2); |
| 927 | if (res != android::OK) { |
| 928 | return res; |
| 929 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 930 | |
| 931 | /* android.lens. */ |
| 932 | |
| 933 | // Fixed values. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 934 | res = base_metadata.update(ANDROID_LENS_APERTURE, &mAperture, 1); |
| 935 | if (res != android::OK) { |
| 936 | return res; |
| 937 | } |
| 938 | res = base_metadata.update(ANDROID_LENS_FILTER_DENSITY, &mFilterDensity, 1); |
| 939 | if (res != android::OK) { |
| 940 | return res; |
| 941 | } |
| 942 | res = base_metadata.update(ANDROID_LENS_FOCAL_LENGTH, &mFocalLength, 1); |
| 943 | if (res != android::OK) { |
| 944 | return res; |
| 945 | } |
| 946 | res = base_metadata.update(ANDROID_LENS_FOCUS_DISTANCE, &mFocusDistance, 1); |
| 947 | if (res != android::OK) { |
| 948 | return res; |
| 949 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 950 | |
| 951 | uint8_t optical_stabilization = ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 952 | res = base_metadata.update(ANDROID_LENS_OPTICAL_STABILIZATION_MODE, |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 953 | &optical_stabilization, 1); |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 954 | if (res != android::OK) { |
| 955 | return res; |
| 956 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 957 | |
| 958 | /* android.noiseReduction. */ |
| 959 | |
| 960 | uint8_t noise_reduction_mode = ANDROID_NOISE_REDUCTION_MODE_FAST; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 961 | res = base_metadata.update(ANDROID_NOISE_REDUCTION_MODE, |
| 962 | &noise_reduction_mode, 1); |
| 963 | if (res != android::OK) { |
| 964 | return res; |
| 965 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 966 | |
| 967 | // strength marked FUTURE. |
| 968 | |
| 969 | /* android.request. */ |
| 970 | |
| 971 | // Request Id unused by the HAL for now, and these are just |
| 972 | // templates, so just fill it in with a dummy. |
| 973 | int32_t id = 0; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 974 | res = base_metadata.update(ANDROID_REQUEST_ID, &id, 1); |
| 975 | if (res != android::OK) { |
| 976 | return res; |
| 977 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 978 | |
| 979 | // metadataMode marked FUTURE. |
| 980 | |
| 981 | /* android.scaler. */ |
| 982 | |
| 983 | // No cropping by default; use the full active array. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 984 | res = base_metadata.update(ANDROID_SCALER_CROP_REGION, mPixelArraySize.data(), |
| 985 | mPixelArraySize.size()); |
| 986 | if (res != android::OK) { |
| 987 | return res; |
| 988 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 989 | |
| 990 | /* android.sensor. */ |
| 991 | |
| 992 | // exposureTime, sensitivity, testPattern[Data,Mode] not supported. |
| 993 | |
| 994 | // Ignored when AE is OFF. |
| 995 | int64_t frame_duration = 33333333L; // 1/30 s. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 996 | res = base_metadata.update(ANDROID_SENSOR_FRAME_DURATION, &frame_duration, 1); |
| 997 | if (res != android::OK) { |
| 998 | return res; |
| 999 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1000 | |
| 1001 | /* android.shading. */ |
| 1002 | |
| 1003 | uint8_t shading_mode = ANDROID_SHADING_MODE_FAST; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 1004 | res = base_metadata.update(ANDROID_SHADING_MODE, &shading_mode, 1); |
| 1005 | if (res != android::OK) { |
| 1006 | return res; |
| 1007 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1008 | |
| 1009 | /* android.statistics. */ |
| 1010 | |
| 1011 | uint8_t face_detect_mode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 1012 | res = base_metadata.update(ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 1013 | &face_detect_mode, 1); |
| 1014 | if (res != android::OK) { |
| 1015 | return res; |
| 1016 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1017 | |
| 1018 | // histogramMode, sharpnessMapMode marked FUTURE. |
| 1019 | |
| 1020 | uint8_t hp_map_mode = ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 1021 | res = base_metadata.update(ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE, |
| 1022 | &hp_map_mode, 1); |
| 1023 | if (res != android::OK) { |
| 1024 | return res; |
| 1025 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1026 | |
| 1027 | uint8_t lens_shading_map_mode = ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 1028 | res = base_metadata.update(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, |
| 1029 | &lens_shading_map_mode, 1); |
| 1030 | if (res != android::OK) { |
| 1031 | return res; |
| 1032 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1033 | |
| 1034 | /* android.tonemap. */ |
| 1035 | |
| 1036 | // Tonemap only required for MANUAL_POST_PROCESSING capability. |
| 1037 | |
| 1038 | /* android.led. */ |
| 1039 | |
| 1040 | uint8_t transmit = ANDROID_LED_TRANSMIT_ON; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 1041 | res = base_metadata.update(ANDROID_LED_TRANSMIT, &transmit, 1); |
| 1042 | if (res != android::OK) { |
| 1043 | return res; |
| 1044 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1045 | |
| 1046 | /* android.reprocess */ |
| 1047 | |
| 1048 | // Only needed for REPROCESS capability. |
| 1049 | |
| 1050 | |
| 1051 | /* Template variable values. */ |
| 1052 | |
| 1053 | // Find the FPS ranges "closest" to a desired range |
| 1054 | // (minimum abs distance from min to min and max to max). |
| 1055 | // Find both a fixed rate and a variable rate, for different purposes. |
| 1056 | std::array<int32_t, 2> desired_flat_fps_range = {{30, 30}}; |
| 1057 | std::array<int32_t, 2> desired_variable_fps_range = {{5, 30}}; |
| 1058 | std::array<int32_t, 2> flat_fps_range; |
| 1059 | std::array<int32_t, 2> variable_fps_range; |
| 1060 | int32_t best_flat_distance = std::numeric_limits<int32_t>::max(); |
| 1061 | int32_t best_variable_distance = std::numeric_limits<int32_t>::max(); |
| 1062 | size_t num_fps_ranges = mFpsRanges.num_arrays(); |
| 1063 | for (size_t i = 0; i < num_fps_ranges; ++i) { |
| 1064 | const int32_t* range = mFpsRanges[i]; |
| 1065 | // Variable fps. |
| 1066 | int32_t distance = std::abs(range[0] - desired_variable_fps_range[0]) + |
| 1067 | std::abs(range[1] - desired_variable_fps_range[1]); |
| 1068 | if (distance < best_variable_distance) { |
| 1069 | variable_fps_range[0] = range[0]; |
| 1070 | variable_fps_range[1] = range[1]; |
| 1071 | best_variable_distance = distance; |
| 1072 | } |
| 1073 | // Flat fps. Only do if range is actually flat. |
| 1074 | // Note at least one flat range is required, |
| 1075 | // so something will always be filled in. |
| 1076 | if (range[0] == range[1]) { |
| 1077 | distance = std::abs(range[0] - desired_flat_fps_range[0]) + |
| 1078 | std::abs(range[1] - desired_flat_fps_range[1]); |
| 1079 | if (distance < best_flat_distance) { |
| 1080 | flat_fps_range[0] = range[0]; |
| 1081 | flat_fps_range[1] = range[1]; |
| 1082 | best_flat_distance = distance; |
| 1083 | } |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | // Priority: continuous > auto > off > whatever is available. |
| 1088 | bool continuous_still_avail = std::count( |
| 1089 | mAfModes.begin(), mAfModes.end(), |
| 1090 | ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE); |
| 1091 | bool continuous_video_avail = std::count( |
| 1092 | mAfModes.begin(), mAfModes.end(), |
| 1093 | ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO); |
| 1094 | uint8_t non_continuous_af_mode = mAfModes[0]; |
| 1095 | if (std::count(mAfModes.begin(), mAfModes.end(), |
| 1096 | ANDROID_CONTROL_AF_MODE_AUTO)) { |
| 1097 | non_continuous_af_mode = ANDROID_CONTROL_AF_MODE_AUTO; |
| 1098 | } else if (std::count(mAfModes.begin(), mAfModes.end(), |
| 1099 | ANDROID_CONTROL_AF_MODE_OFF)) { |
| 1100 | non_continuous_af_mode = ANDROID_CONTROL_AF_MODE_OFF; |
| 1101 | } |
| 1102 | uint8_t still_af_mode = continuous_still_avail ? |
| 1103 | ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE : non_continuous_af_mode; |
| 1104 | uint8_t video_af_mode = continuous_video_avail ? |
| 1105 | ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO : non_continuous_af_mode; |
| 1106 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 1107 | for (uint8_t template_id = 1; template_id < CAMERA3_TEMPLATE_COUNT; |
| 1108 | ++template_id) { |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1109 | // General differences/support. |
| 1110 | uint8_t intent; |
| 1111 | uint8_t af_mode; |
| 1112 | std::array<int32_t, 2> fps_range; |
| 1113 | switch(template_id) { |
| 1114 | case CAMERA3_TEMPLATE_PREVIEW: |
| 1115 | intent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; |
| 1116 | af_mode = still_af_mode; |
| 1117 | fps_range = flat_fps_range; |
| 1118 | break; |
| 1119 | case CAMERA3_TEMPLATE_STILL_CAPTURE: |
| 1120 | intent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE; |
| 1121 | af_mode = still_af_mode; |
| 1122 | fps_range = variable_fps_range; |
| 1123 | break; |
| 1124 | case CAMERA3_TEMPLATE_VIDEO_RECORD: |
| 1125 | intent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD; |
| 1126 | af_mode = video_af_mode; |
| 1127 | fps_range = flat_fps_range; |
| 1128 | break; |
| 1129 | case CAMERA3_TEMPLATE_VIDEO_SNAPSHOT: |
| 1130 | intent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT; |
| 1131 | af_mode = video_af_mode; |
| 1132 | fps_range = flat_fps_range; |
| 1133 | break; |
| 1134 | case CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG: // Fall through. |
| 1135 | case CAMERA3_TEMPLATE_MANUAL: // Fall though. |
| 1136 | default: |
| 1137 | // Unsupported/unrecognized. Don't add this template; skip it. |
| 1138 | continue; |
| 1139 | } |
| 1140 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame^] | 1141 | // Copy our base metadata and add the new items. |
| 1142 | android::CameraMetadata template_metadata(base_metadata); |
| 1143 | res = template_metadata.update(ANDROID_CONTROL_CAPTURE_INTENT, &intent, 1); |
| 1144 | if (res != android::OK) { |
| 1145 | return res; |
| 1146 | } |
| 1147 | res = template_metadata.update(ANDROID_CONTROL_AE_TARGET_FPS_RANGE, |
| 1148 | fps_range.data(), fps_range.size()); |
| 1149 | if (res != android::OK) { |
| 1150 | return res; |
| 1151 | } |
| 1152 | res = template_metadata.update(ANDROID_CONTROL_AF_MODE, &af_mode, 1); |
| 1153 | if (res != android::OK) { |
| 1154 | return res; |
| 1155 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1156 | |
| 1157 | const camera_metadata_t* template_raw_metadata = |
| 1158 | template_metadata.getAndLock(); |
| 1159 | res = setTemplate(template_id, template_raw_metadata); |
| 1160 | if (res != android::OK) { |
| 1161 | return res; |
| 1162 | } |
| 1163 | res = template_metadata.unlock(template_raw_metadata); |
| 1164 | if (res != android::OK) { |
| 1165 | return res; |
| 1166 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | mTemplatesInitialized = true; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 1170 | return 0; |
| 1171 | } |
| 1172 | |
| 1173 | bool V4L2Camera::isValidCaptureSettings(const camera_metadata_t* settings) { |
| 1174 | HAL_LOG_ENTER(); |
| 1175 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1176 | // TODO(b/29335262): reject capture settings this camera isn't capable of. |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 1177 | return true; |
| 1178 | } |
| 1179 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1180 | int V4L2Camera::initCharacteristics() { |
| 1181 | HAL_LOG_ENTER(); |
| 1182 | |
| 1183 | /* Physical characteristics. */ |
| 1184 | // No way to get these in V4L2, so faked. |
| 1185 | // Note: While many of these are primarily informative for post-processing |
| 1186 | // calculations by the app and will potentially cause bad results there, |
| 1187 | // focal length and physical size are actually used in framework |
| 1188 | // calculations (field of view, pixel pitch, etc), so faking them may |
| 1189 | // have unexpected results. |
| 1190 | mAperture = 2.0; // RPi camera v2 is f/2.0. |
| 1191 | mFilterDensity = 0.0; |
| 1192 | mFocalLength = 3.04; // RPi camera v2 is 3.04mm. |
| 1193 | mOrientation = 0; |
| 1194 | mPhysicalSize = {{3.674, 2.760}}; // RPi camera v2 is 3.674 x 2.760 mm. |
| 1195 | |
| 1196 | /* Fixed features. */ |
| 1197 | |
| 1198 | // TODO(b/29394024): query VIDIOC_CROPCAP to get pixel rectangle. |
| 1199 | // Spoofing as 640 x 480 for now. |
| 1200 | mPixelArraySize = {{/*xmin*/0, /*ymin*/0, /*width*/640, /*height*/480}}; |
| 1201 | |
| 1202 | // V4L2 VIDIOC_CROPCAP doesn't give a way to query this; |
| 1203 | // it's driver dependent. For now, assume freeform, and |
| 1204 | // some cameras may just behave badly. |
| 1205 | // TODO(b/29579652): Figure out a way to determine this. |
| 1206 | mCropType = ANDROID_SCALER_CROPPING_TYPE_FREEFORM; |
| 1207 | |
| 1208 | // TODO(b/29394024): query VIDIOC_CROPCAP to get cropping ranges, |
| 1209 | // and VIDIOC_G_CROP to determine if cropping is supported. |
| 1210 | // If the ioctl isn't available (or cropping has non-square pixelaspect), |
| 1211 | // assume no cropping/scaling. |
| 1212 | // May need to try setting some crops to determine what the driver actually |
| 1213 | // supports (including testing center vs freeform). |
| 1214 | mMaxZoom = 1; |
| 1215 | |
| 1216 | // TODO(b/29394024): query V4L2_CID_EXPOSURE_BIAS. |
| 1217 | mAeCompensationRange = {{0, 0}}; |
| 1218 | mAeCompensationStep = {1, 1}; |
| 1219 | |
| 1220 | // TODO(b/29394024): query V4L2_CID_3A_LOCK. |
| 1221 | mAeLockAvailable = ANDROID_CONTROL_AE_LOCK_AVAILABLE_FALSE; |
| 1222 | mAwbLockAvailable = ANDROID_CONTROL_AWB_LOCK_AVAILABLE_FALSE; |
| 1223 | |
| 1224 | // TODO(b/29394024): query V4L2_CID_FLASH_LED_MODE. |
| 1225 | mFlashAvailable = 0; |
| 1226 | |
| 1227 | // TODO(b/29394024): query V4L2_CID_FOCUS_ABSOLUTE for focus range. |
| 1228 | mFocusDistance = 0; // Fixed focus. |
| 1229 | |
| 1230 | /* Features with (potentially) multiple options. */ |
| 1231 | |
| 1232 | // TODO(b/29394024): query V4L2_CID_EXPOSURE_AUTO for ae modes. |
| 1233 | mAeModes.push_back(ANDROID_CONTROL_AE_MODE_ON); |
| 1234 | |
| 1235 | // TODO(b/29394024): query V4L2_CID_POWER_LINE_FREQUENCY. |
| 1236 | // Auto as the default, since it could mean anything, while OFF would |
| 1237 | // require guaranteeing no antibanding happens. |
| 1238 | mAeAntibandingModes.push_back(ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO); |
| 1239 | |
| 1240 | // TODO(b/29394024): query V4L2_CID_FOCUS_AUTO for |
| 1241 | // CONTINUOUS_VIDEO/CONTINUOUS_PICTURE. V4L2_CID_AUTO_FOCUS_START |
| 1242 | // supports what Android thinks of as auto focus (single auto focus). |
| 1243 | // V4L2_CID_AUTO_FOCUS_RANGE allows MACRO. |
| 1244 | mAfModes.push_back(ANDROID_CONTROL_AF_MODE_OFF); |
| 1245 | |
| 1246 | // TODO(b/29394024): query V4L2_CID_AUTO_WHITE_BALANCE, or |
| 1247 | // V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE if available. |
| 1248 | mAwbModes.push_back(ANDROID_CONTROL_AWB_MODE_AUTO); |
| 1249 | |
| 1250 | // TODO(b/29394024): query V4L2_CID_SCENE_MODE. |
| 1251 | mSceneModes.push_back(ANDROID_CONTROL_SCENE_MODE_DISABLED); |
| 1252 | |
| 1253 | mControlModes.push_back(ANDROID_CONTROL_MODE_AUTO); |
| 1254 | if (mSceneModes.size() > 1) { |
| 1255 | // We have some mode other than just DISABLED available. |
| 1256 | mControlModes.push_back(ANDROID_CONTROL_MODE_USE_SCENE_MODE); |
| 1257 | } |
| 1258 | |
| 1259 | // TODO(b/29394024): query V4L2_CID_COLORFX. |
| 1260 | mEffects.push_back(ANDROID_CONTROL_EFFECT_MODE_OFF); |
| 1261 | |
| 1262 | // TODO(b/29394024): query V4L2_CID_FLASH_INDICATOR_INTENSITY. |
| 1263 | // For now, no indicator LED available; nothing to push back. |
| 1264 | // When there is, push back ANDROID_LED_AVAILABLE_LEDS_TRANSMIT. |
| 1265 | |
| 1266 | // TODO(b/29394024): query V4L2_CID_IMAGE_STABILIZATION. |
| 1267 | mOpticalStabilizationModes.push_back( |
| 1268 | ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF); |
| 1269 | mVideoStabilizationModes.push_back( |
| 1270 | ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF); |
| 1271 | |
| 1272 | // Need to support YUV_420_888 and JPEG. |
| 1273 | // TODO(b/29394024): query VIDIOC_ENUM_FMT. |
| 1274 | std::vector<uint32_t> formats = {{V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_YUV420}}; |
| 1275 | int32_t hal_format; |
| 1276 | // We want to find the smallest maximum frame duration amongst formats. |
| 1277 | mMaxFrameDuration = std::numeric_limits<int64_t>::max(); |
| 1278 | int64_t min_yuv_frame_duration = std::numeric_limits<int64_t>::max(); |
| 1279 | for (auto format : formats) { |
| 1280 | // Translate V4L2 format to HAL format. |
| 1281 | switch (format) { |
| 1282 | case V4L2_PIX_FMT_JPEG: |
| 1283 | hal_format = HAL_PIXEL_FORMAT_BLOB; |
| 1284 | break; |
| 1285 | case V4L2_PIX_FMT_YUV420: |
| 1286 | hal_format = HAL_PIXEL_FORMAT_YCbCr_420_888; |
| 1287 | default: |
| 1288 | // Unrecognized/unused format. Skip it. |
| 1289 | continue; |
| 1290 | } |
| 1291 | |
| 1292 | // TODO(b/29394024): query VIDIOC_ENUM_FRAMESIZES. |
| 1293 | // For now, just 640x480. |
| 1294 | ArrayVector<int32_t, 2> frame_sizes; |
| 1295 | frame_sizes.push_back({{640, 480}}); |
| 1296 | size_t num_frame_sizes = frame_sizes.num_arrays(); |
| 1297 | for (size_t i = 0; i < num_frame_sizes; ++i) { |
| 1298 | const int32_t* frame_size = frame_sizes[i]; |
| 1299 | mStreamConfigs.push_back({{hal_format, frame_size[0], frame_size[1], |
| 1300 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT}}); |
| 1301 | |
| 1302 | // TODO(b/29394024): query VIDIOC_ENUM_FRAMEINTERVALS. |
| 1303 | // For now, using the emulator max value of .3 sec. |
| 1304 | int64_t max_frame_duration = 300000000; |
| 1305 | // For now, min value of 30 fps = 1/30 spf ~= 33333333 ns. |
| 1306 | // For whatever reason the goldfish/qcom cameras report this as |
| 1307 | // 33331760, so copying that. |
| 1308 | int64_t min_frame_duration = 33331760; |
| 1309 | |
| 1310 | mMinFrameDurations.push_back( |
| 1311 | {{hal_format, frame_size[0], frame_size[1], min_frame_duration}}); |
| 1312 | |
| 1313 | // In theory max frame duration (min frame rate) should be consistent |
| 1314 | // between all formats, but we check and only advertise the smallest |
| 1315 | // available max duration just in case. |
| 1316 | if (max_frame_duration < mMaxFrameDuration) { |
| 1317 | mMaxFrameDuration = max_frame_duration; |
| 1318 | } |
| 1319 | |
| 1320 | // We only care about min frame duration (max frame rate) for YUV. |
| 1321 | if (hal_format == HAL_PIXEL_FORMAT_YCbCr_420_888 && |
| 1322 | min_frame_duration < min_yuv_frame_duration) { |
| 1323 | min_yuv_frame_duration = min_frame_duration; |
| 1324 | } |
| 1325 | |
| 1326 | // Usually 0 for non-jpeg, non-zero for JPEG. |
| 1327 | // Randomly choosing absurd 1 sec for JPEG. Unsure what this breaks. |
| 1328 | int64_t stall_duration = 0; |
| 1329 | if (hal_format == HAL_PIXEL_FORMAT_BLOB) { |
| 1330 | stall_duration = 1000000000; |
| 1331 | } |
| 1332 | mStallDurations.push_back( |
| 1333 | {{hal_format, frame_size[0], frame_size[1], stall_duration}}); |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | // This should be at minimum {mi, ma}, {ma, ma} where mi and ma |
| 1338 | // are min and max frame rates for YUV_420_888. Min should be at most 15. |
| 1339 | // Convert from frame durations measured in ns. |
| 1340 | int32_t min_yuv_fps = 1000000000 / mMaxFrameDuration; |
| 1341 | if (min_yuv_fps > 15) { |
| 1342 | return -ENODEV; |
| 1343 | } |
| 1344 | int32_t max_yuv_fps = 1000000000 / min_yuv_frame_duration; |
| 1345 | mFpsRanges.push_back({{min_yuv_fps, max_yuv_fps}}); |
| 1346 | mFpsRanges.push_back({{max_yuv_fps, max_yuv_fps}}); |
| 1347 | // Always advertise {30, 30} if max is even higher, |
| 1348 | // since this is what the default video requests use. |
| 1349 | if (max_yuv_fps > 30) { |
| 1350 | mFpsRanges.push_back({{30, 30}}); |
| 1351 | } |
| 1352 | |
| 1353 | mCharacteristicsInitialized = true; |
| 1354 | return 0; |
| 1355 | } |
| 1356 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 1357 | } // namespace v4l2_camera_hal |