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