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