Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 | /* |
| 3 | * Copyright (C) 2019, Google Inc. |
| 4 | * |
| 5 | * camera_device.cpp - libcamera Android Camera Device |
| 6 | */ |
| 7 | |
| 8 | #include "camera_device.h" |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 9 | #include "camera_ops.h" |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 10 | |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 11 | #include <libcamera/controls.h> |
| 12 | #include <libcamera/property_ids.h> |
| 13 | |
Laurent Pinchart | 93e72b6 | 2020-05-12 00:58:34 +0300 | [diff] [blame] | 14 | #include "libcamera/internal/log.h" |
| 15 | #include "libcamera/internal/utils.h" |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 16 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 17 | #include "camera_metadata.h" |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 18 | |
| 19 | using namespace libcamera; |
| 20 | |
| 21 | LOG_DECLARE_CATEGORY(HAL); |
| 22 | |
| 23 | /* |
| 24 | * \struct Camera3RequestDescriptor |
| 25 | * |
| 26 | * A utility structure that groups information about a capture request to be |
| 27 | * later re-used at request complete time to notify the framework. |
| 28 | */ |
| 29 | |
| 30 | CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor( |
| 31 | unsigned int frameNumber, unsigned int numBuffers) |
| 32 | : frameNumber(frameNumber), numBuffers(numBuffers) |
| 33 | { |
| 34 | buffers = new camera3_stream_buffer_t[numBuffers]; |
| 35 | } |
| 36 | |
| 37 | CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor() |
| 38 | { |
| 39 | delete[] buffers; |
| 40 | } |
| 41 | |
| 42 | /* |
| 43 | * \class CameraDevice |
| 44 | * |
| 45 | * The CameraDevice class wraps a libcamera::Camera instance, and implements |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 46 | * the camera3_device_t interface, bridging calls received from the Android |
| 47 | * camera service to the CameraDevice. |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 48 | * |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 49 | * The class translates parameters and operations from the Camera HALv3 API to |
| 50 | * the libcamera API to provide static information for a Camera, create request |
| 51 | * templates for it, process capture requests and then deliver capture results |
| 52 | * back to the framework using the designated callbacks. |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 53 | */ |
| 54 | |
Laurent Pinchart | 0ed40d2 | 2019-08-18 01:45:01 +0300 | [diff] [blame] | 55 | CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr<Camera> &camera) |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 56 | : running_(false), camera_(camera), staticMetadata_(nullptr) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 57 | { |
| 58 | camera_->requestCompleted.connect(this, &CameraDevice::requestComplete); |
| 59 | } |
| 60 | |
| 61 | CameraDevice::~CameraDevice() |
| 62 | { |
| 63 | if (staticMetadata_) |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 64 | delete staticMetadata_; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 65 | |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 66 | for (auto &it : requestTemplates_) |
| 67 | delete it.second; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 68 | } |
| 69 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 70 | int CameraDevice::open(const hw_module_t *hardwareModule) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 71 | { |
| 72 | int ret = camera_->acquire(); |
| 73 | if (ret) { |
| 74 | LOG(HAL, Error) << "Failed to acquire the camera"; |
| 75 | return ret; |
| 76 | } |
| 77 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 78 | /* Initialize the hw_device_t in the instance camera3_module_t. */ |
| 79 | camera3Device_.common.tag = HARDWARE_DEVICE_TAG; |
| 80 | camera3Device_.common.version = CAMERA_DEVICE_API_VERSION_3_3; |
| 81 | camera3Device_.common.module = (hw_module_t *)hardwareModule; |
| 82 | camera3Device_.common.close = hal_dev_close; |
| 83 | |
| 84 | /* |
| 85 | * The camera device operations. These actually implement |
| 86 | * the Android Camera HALv3 interface. |
| 87 | */ |
| 88 | camera3Device_.ops = &hal_dev_ops; |
| 89 | camera3Device_.priv = this; |
| 90 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | void CameraDevice::close() |
| 95 | { |
| 96 | camera_->stop(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 97 | camera_->release(); |
| 98 | |
| 99 | running_ = false; |
| 100 | } |
| 101 | |
| 102 | void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks) |
| 103 | { |
| 104 | callbacks_ = callbacks; |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * Return static information for the camera. |
| 109 | */ |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 110 | const camera_metadata_t *CameraDevice::getStaticMetadata() |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 111 | { |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 112 | if (staticMetadata_) |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 113 | return staticMetadata_->get(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 114 | |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 115 | const ControlList &properties = camera_->properties(); |
| 116 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 117 | /* |
| 118 | * The here reported metadata are enough to implement a basic capture |
| 119 | * example application, but a real camera implementation will require |
| 120 | * more. |
| 121 | */ |
| 122 | |
Jacopo Mondi | 48504ba | 2019-09-04 16:18:19 +0200 | [diff] [blame] | 123 | /* |
| 124 | * \todo Keep this in sync with the actual number of entries. |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 125 | * Currently: 50 entries, 666 bytes |
Jacopo Mondi | 48504ba | 2019-09-04 16:18:19 +0200 | [diff] [blame] | 126 | */ |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 127 | staticMetadata_ = new CameraMetadata(50, 700); |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 128 | if (!staticMetadata_->isValid()) { |
| 129 | LOG(HAL, Error) << "Failed to allocate static metadata"; |
| 130 | delete staticMetadata_; |
| 131 | staticMetadata_ = nullptr; |
| 132 | return nullptr; |
| 133 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 134 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 135 | /* Color correction static metadata. */ |
| 136 | std::vector<uint8_t> aberrationModes = { |
| 137 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF, |
| 138 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 139 | staticMetadata_->addEntry(ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, |
| 140 | aberrationModes.data(), |
| 141 | aberrationModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 142 | |
| 143 | /* Control static metadata. */ |
| 144 | std::vector<uint8_t> aeAvailableAntiBandingModes = { |
| 145 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF, |
| 146 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_50HZ, |
| 147 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_60HZ, |
| 148 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO, |
| 149 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 150 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, |
| 151 | aeAvailableAntiBandingModes.data(), |
| 152 | aeAvailableAntiBandingModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 153 | |
| 154 | std::vector<uint8_t> aeAvailableModes = { |
| 155 | ANDROID_CONTROL_AE_MODE_ON, |
| 156 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 157 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_MODES, |
| 158 | aeAvailableModes.data(), |
| 159 | aeAvailableModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 160 | |
| 161 | std::vector<int32_t> availableAeFpsTarget = { |
| 162 | 15, 30, |
| 163 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 164 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, |
| 165 | availableAeFpsTarget.data(), |
| 166 | availableAeFpsTarget.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 167 | |
| 168 | std::vector<int32_t> aeCompensationRange = { |
| 169 | 0, 0, |
| 170 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 171 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_COMPENSATION_RANGE, |
| 172 | aeCompensationRange.data(), |
| 173 | aeCompensationRange.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 174 | |
| 175 | const camera_metadata_rational_t aeCompensationStep[] = { |
| 176 | { 0, 1 } |
| 177 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 178 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_COMPENSATION_STEP, |
| 179 | aeCompensationStep, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 180 | |
| 181 | std::vector<uint8_t> availableAfModes = { |
| 182 | ANDROID_CONTROL_AF_MODE_OFF, |
| 183 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 184 | staticMetadata_->addEntry(ANDROID_CONTROL_AF_AVAILABLE_MODES, |
| 185 | availableAfModes.data(), |
| 186 | availableAfModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 187 | |
| 188 | std::vector<uint8_t> availableEffects = { |
| 189 | ANDROID_CONTROL_EFFECT_MODE_OFF, |
| 190 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 191 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_EFFECTS, |
| 192 | availableEffects.data(), |
| 193 | availableEffects.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 194 | |
| 195 | std::vector<uint8_t> availableSceneModes = { |
| 196 | ANDROID_CONTROL_SCENE_MODE_DISABLED, |
| 197 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 198 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_SCENE_MODES, |
| 199 | availableSceneModes.data(), |
| 200 | availableSceneModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 201 | |
| 202 | std::vector<uint8_t> availableStabilizationModes = { |
| 203 | ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF, |
| 204 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 205 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, |
| 206 | availableStabilizationModes.data(), |
| 207 | availableStabilizationModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 208 | |
| 209 | std::vector<uint8_t> availableAwbModes = { |
| 210 | ANDROID_CONTROL_AWB_MODE_OFF, |
| 211 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 212 | staticMetadata_->addEntry(ANDROID_CONTROL_AWB_AVAILABLE_MODES, |
| 213 | availableAwbModes.data(), |
| 214 | availableAwbModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 215 | |
| 216 | std::vector<int32_t> availableMaxRegions = { |
| 217 | 0, 0, 0, |
| 218 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 219 | staticMetadata_->addEntry(ANDROID_CONTROL_MAX_REGIONS, |
| 220 | availableMaxRegions.data(), |
| 221 | availableMaxRegions.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 222 | |
| 223 | std::vector<uint8_t> sceneModesOverride = { |
| 224 | ANDROID_CONTROL_AE_MODE_ON, |
| 225 | ANDROID_CONTROL_AWB_MODE_AUTO, |
| 226 | ANDROID_CONTROL_AF_MODE_AUTO, |
| 227 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 228 | staticMetadata_->addEntry(ANDROID_CONTROL_SCENE_MODE_OVERRIDES, |
| 229 | sceneModesOverride.data(), |
| 230 | sceneModesOverride.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 231 | |
| 232 | uint8_t aeLockAvailable = ANDROID_CONTROL_AE_LOCK_AVAILABLE_FALSE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 233 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_LOCK_AVAILABLE, |
| 234 | &aeLockAvailable, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 235 | |
| 236 | uint8_t awbLockAvailable = ANDROID_CONTROL_AWB_LOCK_AVAILABLE_FALSE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 237 | staticMetadata_->addEntry(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, |
| 238 | &awbLockAvailable, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 239 | |
| 240 | char availableControlModes = ANDROID_CONTROL_MODE_AUTO; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 241 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_MODES, |
| 242 | &availableControlModes, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 243 | |
| 244 | /* JPEG static metadata. */ |
| 245 | std::vector<int32_t> availableThumbnailSizes = { |
| 246 | 0, 0, |
| 247 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 248 | staticMetadata_->addEntry(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
| 249 | availableThumbnailSizes.data(), |
| 250 | availableThumbnailSizes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 251 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 252 | /* Sensor static metadata. */ |
| 253 | int32_t pixelArraySize[] = { |
| 254 | 2592, 1944, |
| 255 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 256 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, |
| 257 | &pixelArraySize, 2); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 258 | |
| 259 | int32_t sensorSizes[] = { |
| 260 | 0, 0, 2560, 1920, |
| 261 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 262 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, |
| 263 | &sensorSizes, 4); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 264 | |
| 265 | int32_t sensitivityRange[] = { |
| 266 | 32, 2400, |
| 267 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 268 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_SENSITIVITY_RANGE, |
| 269 | &sensitivityRange, 2); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 270 | |
| 271 | uint16_t filterArr = ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_GRBG; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 272 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, |
| 273 | &filterArr, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 274 | |
| 275 | int64_t exposureTimeRange[] = { |
| 276 | 100000, 200000000, |
| 277 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 278 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE, |
| 279 | &exposureTimeRange, 2); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 280 | |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 281 | /* |
| 282 | * The Android orientation metadata and libcamera rotation property are |
| 283 | * defined differently but have identical numerical values for Android |
| 284 | * devices such as phones and tablets. |
| 285 | */ |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 286 | int32_t orientation = 0; |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 287 | if (properties.contains(properties::Rotation)) |
| 288 | orientation = properties.get(properties::Rotation); |
| 289 | staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION, &orientation, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 290 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 291 | std::vector<int32_t> testPatterModes = { |
| 292 | ANDROID_SENSOR_TEST_PATTERN_MODE_OFF, |
| 293 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 294 | staticMetadata_->addEntry(ANDROID_SENSOR_AVAILABLE_TEST_PATTERN_MODES, |
| 295 | testPatterModes.data(), |
| 296 | testPatterModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 297 | |
| 298 | std::vector<float> physicalSize = { |
| 299 | 2592, 1944, |
| 300 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 301 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
| 302 | physicalSize.data(), |
| 303 | physicalSize.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 304 | |
| 305 | uint8_t timestampSource = ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 306 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, |
| 307 | ×tampSource, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 308 | |
| 309 | /* Statistics static metadata. */ |
| 310 | uint8_t faceDetectMode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 311 | staticMetadata_->addEntry(ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, |
| 312 | &faceDetectMode, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 313 | |
| 314 | int32_t maxFaceCount = 0; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 315 | staticMetadata_->addEntry(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, |
| 316 | &maxFaceCount, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 317 | |
| 318 | /* Sync static metadata. */ |
| 319 | int32_t maxLatency = ANDROID_SYNC_MAX_LATENCY_UNKNOWN; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 320 | staticMetadata_->addEntry(ANDROID_SYNC_MAX_LATENCY, &maxLatency, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 321 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 322 | /* Flash static metadata. */ |
| 323 | char flashAvailable = ANDROID_FLASH_INFO_AVAILABLE_FALSE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 324 | staticMetadata_->addEntry(ANDROID_FLASH_INFO_AVAILABLE, |
| 325 | &flashAvailable, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 326 | |
| 327 | /* Lens static metadata. */ |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 328 | std::vector<float> lensApertures = { |
| 329 | 2.53 / 100, |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 330 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 331 | staticMetadata_->addEntry(ANDROID_LENS_INFO_AVAILABLE_APERTURES, |
| 332 | lensApertures.data(), |
| 333 | lensApertures.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 334 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 335 | uint8_t lensFacing = ANDROID_LENS_FACING_FRONT; |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 336 | if (properties.contains(properties::Location)) { |
| 337 | int32_t location = properties.get(properties::Location); |
| 338 | switch (location) { |
| 339 | case properties::CameraLocationFront: |
| 340 | lensFacing = ANDROID_LENS_FACING_FRONT; |
| 341 | break; |
| 342 | case properties::CameraLocationBack: |
| 343 | lensFacing = ANDROID_LENS_FACING_BACK; |
| 344 | break; |
| 345 | case properties::CameraLocationExternal: |
| 346 | lensFacing = ANDROID_LENS_FACING_EXTERNAL; |
| 347 | break; |
| 348 | } |
| 349 | } |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 350 | staticMetadata_->addEntry(ANDROID_LENS_FACING, &lensFacing, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 351 | |
| 352 | std::vector<float> lensFocalLenghts = { |
| 353 | 1, |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 354 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 355 | staticMetadata_->addEntry(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
| 356 | lensFocalLenghts.data(), |
| 357 | lensFocalLenghts.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 358 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 359 | std::vector<uint8_t> opticalStabilizations = { |
| 360 | ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF, |
| 361 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 362 | staticMetadata_->addEntry(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, |
| 363 | opticalStabilizations.data(), |
| 364 | opticalStabilizations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 365 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 366 | float hypeFocalDistance = 0; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 367 | staticMetadata_->addEntry(ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE, |
| 368 | &hypeFocalDistance, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 369 | |
| 370 | float minFocusDistance = 0; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 371 | staticMetadata_->addEntry(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, |
| 372 | &minFocusDistance, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 373 | |
| 374 | /* Noise reduction modes. */ |
| 375 | uint8_t noiseReductionModes = ANDROID_NOISE_REDUCTION_MODE_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 376 | staticMetadata_->addEntry(ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, |
| 377 | &noiseReductionModes, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 378 | |
| 379 | /* Scaler static metadata. */ |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 380 | float maxDigitalZoom = 1; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 381 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, |
| 382 | &maxDigitalZoom, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 383 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 384 | std::vector<uint32_t> availableStreamFormats = { |
| 385 | ANDROID_SCALER_AVAILABLE_FORMATS_BLOB, |
| 386 | ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888, |
| 387 | ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED, |
| 388 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 389 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_FORMATS, |
| 390 | availableStreamFormats.data(), |
| 391 | availableStreamFormats.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 392 | |
| 393 | std::vector<uint32_t> availableStreamConfigurations = { |
| 394 | ANDROID_SCALER_AVAILABLE_FORMATS_BLOB, 2560, 1920, |
| 395 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT, |
| 396 | ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888, 2560, 1920, |
| 397 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT, |
| 398 | ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED, 2560, 1920, |
| 399 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT, |
| 400 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 401 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, |
| 402 | availableStreamConfigurations.data(), |
| 403 | availableStreamConfigurations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 404 | |
| 405 | std::vector<int64_t> availableStallDurations = { |
| 406 | ANDROID_SCALER_AVAILABLE_FORMATS_BLOB, 2560, 1920, 33333333, |
| 407 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 408 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_STALL_DURATIONS, |
| 409 | availableStallDurations.data(), |
| 410 | availableStallDurations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 411 | |
| 412 | std::vector<int64_t> minFrameDurations = { |
| 413 | ANDROID_SCALER_AVAILABLE_FORMATS_BLOB, 2560, 1920, 33333333, |
| 414 | ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED, 2560, 1920, 33333333, |
| 415 | ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888, 2560, 1920, 33333333, |
| 416 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 417 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, |
| 418 | minFrameDurations.data(), |
| 419 | minFrameDurations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 420 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 421 | uint8_t croppingType = ANDROID_SCALER_CROPPING_TYPE_CENTER_ONLY; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 422 | staticMetadata_->addEntry(ANDROID_SCALER_CROPPING_TYPE, &croppingType, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 423 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 424 | /* Info static metadata. */ |
| 425 | uint8_t supportedHWLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 426 | staticMetadata_->addEntry(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, |
| 427 | &supportedHWLevel, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 428 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 429 | /* Request static metadata. */ |
| 430 | int32_t partialResultCount = 1; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 431 | staticMetadata_->addEntry(ANDROID_REQUEST_PARTIAL_RESULT_COUNT, |
| 432 | &partialResultCount, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 433 | |
| 434 | uint8_t maxPipelineDepth = 2; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 435 | staticMetadata_->addEntry(ANDROID_REQUEST_PIPELINE_MAX_DEPTH, |
| 436 | &maxPipelineDepth, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 437 | |
| 438 | std::vector<uint8_t> availableCapabilities = { |
| 439 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE, |
| 440 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 441 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, |
| 442 | availableCapabilities.data(), |
| 443 | availableCapabilities.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 444 | |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 445 | std::vector<int32_t> availableCharacteristicsKeys = { |
| 446 | ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, |
| 447 | ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, |
| 448 | ANDROID_CONTROL_AE_AVAILABLE_MODES, |
| 449 | ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, |
| 450 | ANDROID_CONTROL_AE_COMPENSATION_RANGE, |
| 451 | ANDROID_CONTROL_AE_COMPENSATION_STEP, |
| 452 | ANDROID_CONTROL_AF_AVAILABLE_MODES, |
| 453 | ANDROID_CONTROL_AVAILABLE_EFFECTS, |
| 454 | ANDROID_CONTROL_AVAILABLE_SCENE_MODES, |
| 455 | ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, |
| 456 | ANDROID_CONTROL_AWB_AVAILABLE_MODES, |
| 457 | ANDROID_CONTROL_MAX_REGIONS, |
| 458 | ANDROID_CONTROL_SCENE_MODE_OVERRIDES, |
| 459 | ANDROID_CONTROL_AE_LOCK_AVAILABLE, |
| 460 | ANDROID_CONTROL_AWB_LOCK_AVAILABLE, |
| 461 | ANDROID_CONTROL_AVAILABLE_MODES, |
| 462 | ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
| 463 | ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, |
| 464 | ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, |
| 465 | ANDROID_SENSOR_INFO_SENSITIVITY_RANGE, |
| 466 | ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, |
| 467 | ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE, |
| 468 | ANDROID_SENSOR_ORIENTATION, |
| 469 | ANDROID_SENSOR_AVAILABLE_TEST_PATTERN_MODES, |
| 470 | ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
| 471 | ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, |
| 472 | ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, |
| 473 | ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, |
| 474 | ANDROID_SYNC_MAX_LATENCY, |
| 475 | ANDROID_FLASH_INFO_AVAILABLE, |
| 476 | ANDROID_LENS_INFO_AVAILABLE_APERTURES, |
| 477 | ANDROID_LENS_FACING, |
| 478 | ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
| 479 | ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, |
| 480 | ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE, |
| 481 | ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, |
| 482 | ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, |
| 483 | ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, |
| 484 | ANDROID_SCALER_AVAILABLE_FORMATS, |
| 485 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, |
| 486 | ANDROID_SCALER_AVAILABLE_STALL_DURATIONS, |
| 487 | ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, |
| 488 | ANDROID_SCALER_CROPPING_TYPE, |
| 489 | ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, |
| 490 | ANDROID_REQUEST_PARTIAL_RESULT_COUNT, |
| 491 | ANDROID_REQUEST_PIPELINE_MAX_DEPTH, |
| 492 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES, |
| 493 | }; |
| 494 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, |
| 495 | availableCharacteristicsKeys.data(), |
| 496 | availableCharacteristicsKeys.size()); |
| 497 | |
| 498 | std::vector<int32_t> availableRequestKeys = { |
| 499 | ANDROID_CONTROL_AE_MODE, |
| 500 | ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
| 501 | ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
| 502 | ANDROID_CONTROL_AE_LOCK, |
| 503 | ANDROID_CONTROL_AF_TRIGGER, |
| 504 | ANDROID_CONTROL_AWB_MODE, |
| 505 | ANDROID_CONTROL_AWB_LOCK, |
| 506 | ANDROID_FLASH_MODE, |
| 507 | ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 508 | ANDROID_NOISE_REDUCTION_MODE, |
| 509 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 510 | ANDROID_CONTROL_CAPTURE_INTENT, |
| 511 | }; |
| 512 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS, |
| 513 | availableRequestKeys.data(), |
| 514 | availableRequestKeys.size()); |
| 515 | |
| 516 | std::vector<int32_t> availableResultKeys = { |
| 517 | ANDROID_CONTROL_AE_STATE, |
| 518 | ANDROID_CONTROL_AE_LOCK, |
| 519 | ANDROID_CONTROL_AF_STATE, |
| 520 | ANDROID_CONTROL_AWB_STATE, |
| 521 | ANDROID_CONTROL_AWB_LOCK, |
| 522 | ANDROID_LENS_STATE, |
| 523 | ANDROID_SCALER_CROP_REGION, |
| 524 | ANDROID_SENSOR_TIMESTAMP, |
| 525 | ANDROID_SENSOR_ROLLING_SHUTTER_SKEW, |
| 526 | ANDROID_SENSOR_EXPOSURE_TIME, |
| 527 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, |
| 528 | ANDROID_STATISTICS_SCENE_FLICKER, |
| 529 | }; |
| 530 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_RESULT_KEYS, |
| 531 | availableResultKeys.data(), |
| 532 | availableResultKeys.size()); |
| 533 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 534 | if (!staticMetadata_->isValid()) { |
| 535 | LOG(HAL, Error) << "Failed to construct static metadata"; |
| 536 | delete staticMetadata_; |
| 537 | staticMetadata_ = nullptr; |
| 538 | return nullptr; |
| 539 | } |
| 540 | |
| 541 | return staticMetadata_->get(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /* |
| 545 | * Produce a metadata pack to be used as template for a capture request. |
| 546 | */ |
| 547 | const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) |
| 548 | { |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 549 | auto it = requestTemplates_.find(type); |
| 550 | if (it != requestTemplates_.end()) |
| 551 | return it->second->get(); |
| 552 | |
| 553 | /* Use the capture intent matching the requested template type. */ |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 554 | uint8_t captureIntent; |
| 555 | switch (type) { |
| 556 | case CAMERA3_TEMPLATE_PREVIEW: |
| 557 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; |
| 558 | break; |
| 559 | case CAMERA3_TEMPLATE_STILL_CAPTURE: |
| 560 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE; |
| 561 | break; |
| 562 | case CAMERA3_TEMPLATE_VIDEO_RECORD: |
| 563 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD; |
| 564 | break; |
| 565 | case CAMERA3_TEMPLATE_VIDEO_SNAPSHOT: |
| 566 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT; |
| 567 | break; |
| 568 | case CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG: |
| 569 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG; |
| 570 | break; |
| 571 | case CAMERA3_TEMPLATE_MANUAL: |
| 572 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_MANUAL; |
| 573 | break; |
| 574 | default: |
| 575 | LOG(HAL, Error) << "Invalid template request type: " << type; |
| 576 | return nullptr; |
| 577 | } |
| 578 | |
Jacopo Mondi | 6370347 | 2019-09-04 16:18:22 +0200 | [diff] [blame] | 579 | /* |
| 580 | * \todo Keep this in sync with the actual number of entries. |
| 581 | * Currently: 12 entries, 15 bytes |
| 582 | */ |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 583 | CameraMetadata *requestTemplate = new CameraMetadata(15, 20); |
| 584 | if (!requestTemplate->isValid()) { |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 585 | LOG(HAL, Error) << "Failed to allocate template metadata"; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 586 | delete requestTemplate; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 587 | return nullptr; |
| 588 | } |
| 589 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 590 | uint8_t aeMode = ANDROID_CONTROL_AE_MODE_ON; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 591 | requestTemplate->addEntry(ANDROID_CONTROL_AE_MODE, |
| 592 | &aeMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 593 | |
| 594 | int32_t aeExposureCompensation = 0; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 595 | requestTemplate->addEntry(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
| 596 | &aeExposureCompensation, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 597 | |
| 598 | uint8_t aePrecaptureTrigger = ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 599 | requestTemplate->addEntry(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
| 600 | &aePrecaptureTrigger, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 601 | |
| 602 | uint8_t aeLock = ANDROID_CONTROL_AE_LOCK_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 603 | requestTemplate->addEntry(ANDROID_CONTROL_AE_LOCK, |
| 604 | &aeLock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 605 | |
| 606 | uint8_t afTrigger = ANDROID_CONTROL_AF_TRIGGER_IDLE; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 607 | requestTemplate->addEntry(ANDROID_CONTROL_AF_TRIGGER, |
| 608 | &afTrigger, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 609 | |
| 610 | uint8_t awbMode = ANDROID_CONTROL_AWB_MODE_AUTO; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 611 | requestTemplate->addEntry(ANDROID_CONTROL_AWB_MODE, |
| 612 | &awbMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 613 | |
| 614 | uint8_t awbLock = ANDROID_CONTROL_AWB_LOCK_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 615 | requestTemplate->addEntry(ANDROID_CONTROL_AWB_LOCK, |
| 616 | &awbLock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 617 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 618 | uint8_t flashMode = ANDROID_FLASH_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 619 | requestTemplate->addEntry(ANDROID_FLASH_MODE, |
| 620 | &flashMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 621 | |
| 622 | uint8_t faceDetectMode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 623 | requestTemplate->addEntry(ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 624 | &faceDetectMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 625 | |
Jacopo Mondi | 9b361dc | 2019-09-04 16:18:21 +0200 | [diff] [blame] | 626 | uint8_t noiseReduction = ANDROID_NOISE_REDUCTION_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 627 | requestTemplate->addEntry(ANDROID_NOISE_REDUCTION_MODE, |
| 628 | &noiseReduction, 1); |
Jacopo Mondi | 9b361dc | 2019-09-04 16:18:21 +0200 | [diff] [blame] | 629 | |
| 630 | uint8_t aberrationMode = ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 631 | requestTemplate->addEntry(ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 632 | &aberrationMode, 1); |
Jacopo Mondi | 9b361dc | 2019-09-04 16:18:21 +0200 | [diff] [blame] | 633 | |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 634 | requestTemplate->addEntry(ANDROID_CONTROL_CAPTURE_INTENT, |
| 635 | &captureIntent, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 636 | |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 637 | if (!requestTemplate->isValid()) { |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 638 | LOG(HAL, Error) << "Failed to construct request template"; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 639 | delete requestTemplate; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 640 | return nullptr; |
| 641 | } |
| 642 | |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 643 | requestTemplates_[type] = requestTemplate; |
| 644 | return requestTemplate->get(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /* |
| 648 | * Inspect the stream_list to produce a list of StreamConfiguration to |
| 649 | * be use to configure the Camera. |
| 650 | */ |
| 651 | int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) |
| 652 | { |
| 653 | for (unsigned int i = 0; i < stream_list->num_streams; ++i) { |
| 654 | camera3_stream_t *stream = stream_list->streams[i]; |
| 655 | |
| 656 | LOG(HAL, Info) << "Stream #" << i |
| 657 | << ", direction: " << stream->stream_type |
| 658 | << ", width: " << stream->width |
| 659 | << ", height: " << stream->height |
Laurent Pinchart | f391048 | 2019-10-13 22:22:04 +0300 | [diff] [blame] | 660 | << ", format: " << utils::hex(stream->format); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /* Hardcode viewfinder role, collecting sizes from the stream config. */ |
| 664 | if (stream_list->num_streams != 1) { |
| 665 | LOG(HAL, Error) << "Only one stream supported"; |
| 666 | return -EINVAL; |
| 667 | } |
| 668 | |
| 669 | StreamRoles roles = { StreamRole::Viewfinder }; |
| 670 | config_ = camera_->generateConfiguration(roles); |
| 671 | if (!config_ || config_->empty()) { |
| 672 | LOG(HAL, Error) << "Failed to generate camera configuration"; |
| 673 | return -EINVAL; |
| 674 | } |
| 675 | |
| 676 | /* Only one stream is supported. */ |
| 677 | camera3_stream_t *camera3Stream = stream_list->streams[0]; |
| 678 | StreamConfiguration *streamConfiguration = &config_->at(0); |
| 679 | streamConfiguration->size.width = camera3Stream->width; |
| 680 | streamConfiguration->size.height = camera3Stream->height; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 681 | |
| 682 | /* |
| 683 | * \todo We'll need to translate from Android defined pixel format codes |
| 684 | * to the libcamera image format codes. For now, do not change the |
| 685 | * format returned from Camera::generateConfiguration(). |
| 686 | */ |
| 687 | |
| 688 | switch (config_->validate()) { |
| 689 | case CameraConfiguration::Valid: |
| 690 | break; |
| 691 | case CameraConfiguration::Adjusted: |
| 692 | LOG(HAL, Info) << "Camera configuration adjusted"; |
| 693 | config_.reset(); |
| 694 | return -EINVAL; |
| 695 | case CameraConfiguration::Invalid: |
| 696 | LOG(HAL, Info) << "Camera configuration invalid"; |
| 697 | config_.reset(); |
| 698 | return -EINVAL; |
| 699 | } |
| 700 | |
| 701 | camera3Stream->max_buffers = streamConfiguration->bufferCount; |
| 702 | |
| 703 | /* |
| 704 | * Once the CameraConfiguration has been adjusted/validated |
| 705 | * it can be applied to the camera. |
| 706 | */ |
| 707 | int ret = camera_->configure(config_.get()); |
| 708 | if (ret) { |
| 709 | LOG(HAL, Error) << "Failed to configure camera '" |
| 710 | << camera_->name() << "'"; |
| 711 | return ret; |
| 712 | } |
| 713 | |
| 714 | return 0; |
| 715 | } |
| 716 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 717 | int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 718 | { |
| 719 | StreamConfiguration *streamConfiguration = &config_->at(0); |
| 720 | Stream *stream = streamConfiguration->stream(); |
| 721 | |
| 722 | if (camera3Request->num_output_buffers != 1) { |
| 723 | LOG(HAL, Error) << "Invalid number of output buffers: " |
| 724 | << camera3Request->num_output_buffers; |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 725 | return -EINVAL; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | /* Start the camera if that's the first request we handle. */ |
| 729 | if (!running_) { |
Niklas Söderlund | a1c5450 | 2019-11-25 17:51:06 +0100 | [diff] [blame] | 730 | int ret = camera_->start(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 731 | if (ret) { |
| 732 | LOG(HAL, Error) << "Failed to start camera"; |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 733 | return ret; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | running_ = true; |
| 737 | } |
| 738 | |
| 739 | /* |
| 740 | * Queue a request for the Camera with the provided dmabuf file |
| 741 | * descriptors. |
| 742 | */ |
| 743 | const camera3_stream_buffer_t *camera3Buffers = |
| 744 | camera3Request->output_buffers; |
| 745 | |
| 746 | /* |
| 747 | * Save the request descriptors for use at completion time. |
| 748 | * The descriptor and the associated memory reserved here are freed |
| 749 | * at request complete time. |
| 750 | */ |
| 751 | Camera3RequestDescriptor *descriptor = |
| 752 | new Camera3RequestDescriptor(camera3Request->frame_number, |
| 753 | camera3Request->num_output_buffers); |
| 754 | for (unsigned int i = 0; i < descriptor->numBuffers; ++i) { |
| 755 | /* |
| 756 | * Keep track of which stream the request belongs to and store |
| 757 | * the native buffer handles. |
| 758 | * |
| 759 | * \todo Currently we only support one capture buffer. Copy |
| 760 | * all of them to be ready once we'll support more. |
| 761 | */ |
| 762 | descriptor->buffers[i].stream = camera3Buffers[i].stream; |
| 763 | descriptor->buffers[i].buffer = camera3Buffers[i].buffer; |
| 764 | } |
| 765 | |
| 766 | /* |
| 767 | * Create a libcamera buffer using the dmabuf descriptors of the first |
| 768 | * and (currently) only supported request buffer. |
| 769 | */ |
| 770 | const buffer_handle_t camera3Handle = *camera3Buffers[0].buffer; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 771 | |
Niklas Söderlund | 9217f27 | 2019-11-22 16:22:56 +0100 | [diff] [blame] | 772 | std::vector<FrameBuffer::Plane> planes; |
| 773 | for (int i = 0; i < 3; i++) { |
| 774 | FrameBuffer::Plane plane; |
| 775 | plane.fd = FileDescriptor(camera3Handle->data[i]); |
| 776 | /* |
| 777 | * Setting length to zero here is OK as the length is only used |
| 778 | * to map the memory of the plane. Libcamera do not need to poke |
| 779 | * at the memory content queued by the HAL. |
| 780 | */ |
| 781 | plane.length = 0; |
| 782 | planes.push_back(std::move(plane)); |
| 783 | } |
| 784 | |
| 785 | FrameBuffer *buffer = new FrameBuffer(std::move(planes)); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 786 | if (!buffer) { |
| 787 | LOG(HAL, Error) << "Failed to create buffer"; |
| 788 | delete descriptor; |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 789 | return -ENOMEM; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | Request *request = |
| 793 | camera_->createRequest(reinterpret_cast<uint64_t>(descriptor)); |
Niklas Söderlund | 9217f27 | 2019-11-22 16:22:56 +0100 | [diff] [blame] | 794 | request->addBuffer(stream, buffer); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 795 | |
| 796 | int ret = camera_->queueRequest(request); |
| 797 | if (ret) { |
| 798 | LOG(HAL, Error) << "Failed to queue request"; |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 799 | delete request; |
| 800 | delete descriptor; |
| 801 | return ret; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 802 | } |
| 803 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 804 | return 0; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 805 | } |
| 806 | |
Niklas Söderlund | f7ddfd4 | 2019-10-21 20:01:19 +0200 | [diff] [blame] | 807 | void CameraDevice::requestComplete(Request *request) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 808 | { |
Niklas Söderlund | 9217f27 | 2019-11-22 16:22:56 +0100 | [diff] [blame] | 809 | const std::map<Stream *, FrameBuffer *> &buffers = request->buffers(); |
| 810 | FrameBuffer *buffer = buffers.begin()->second; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 811 | camera3_buffer_status status = CAMERA3_BUFFER_STATUS_OK; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 812 | std::unique_ptr<CameraMetadata> resultMetadata; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 813 | |
| 814 | if (request->status() != Request::RequestComplete) { |
| 815 | LOG(HAL, Error) << "Request not succesfully completed: " |
| 816 | << request->status(); |
| 817 | status = CAMERA3_BUFFER_STATUS_ERROR; |
| 818 | } |
| 819 | |
| 820 | /* Prepare to call back the Android camera stack. */ |
| 821 | Camera3RequestDescriptor *descriptor = |
| 822 | reinterpret_cast<Camera3RequestDescriptor *>(request->cookie()); |
| 823 | |
| 824 | camera3_capture_result_t captureResult = {}; |
| 825 | captureResult.frame_number = descriptor->frameNumber; |
| 826 | captureResult.num_output_buffers = descriptor->numBuffers; |
| 827 | for (unsigned int i = 0; i < descriptor->numBuffers; ++i) { |
| 828 | /* |
| 829 | * \todo Currently we only support one capture buffer. Prepare |
| 830 | * all of them to be ready once we'll support more. |
| 831 | */ |
| 832 | descriptor->buffers[i].acquire_fence = -1; |
| 833 | descriptor->buffers[i].release_fence = -1; |
| 834 | descriptor->buffers[i].status = status; |
| 835 | } |
| 836 | captureResult.output_buffers = |
| 837 | const_cast<const camera3_stream_buffer_t *>(descriptor->buffers); |
| 838 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 839 | if (status == CAMERA3_BUFFER_STATUS_OK) { |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 840 | notifyShutter(descriptor->frameNumber, |
Niklas Söderlund | 9217f27 | 2019-11-22 16:22:56 +0100 | [diff] [blame] | 841 | buffer->metadata().timestamp); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 842 | |
| 843 | captureResult.partial_result = 1; |
| 844 | resultMetadata = getResultMetadata(descriptor->frameNumber, |
Niklas Söderlund | 9217f27 | 2019-11-22 16:22:56 +0100 | [diff] [blame] | 845 | buffer->metadata().timestamp); |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 846 | captureResult.result = resultMetadata->get(); |
| 847 | } |
| 848 | |
| 849 | if (status == CAMERA3_BUFFER_STATUS_ERROR || !captureResult.result) { |
| 850 | /* \todo Improve error handling. In case we notify an error |
| 851 | * because the metadata generation fails, a shutter event has |
| 852 | * already been notified for this frame number before the error |
| 853 | * is here signalled. Make sure the error path plays well with |
| 854 | * the camera stack state machine. |
| 855 | */ |
| 856 | notifyError(descriptor->frameNumber, |
| 857 | descriptor->buffers[0].stream); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | callbacks_->process_capture_result(callbacks_, &captureResult); |
| 861 | |
| 862 | delete descriptor; |
Niklas Söderlund | 9217f27 | 2019-11-22 16:22:56 +0100 | [diff] [blame] | 863 | delete buffer; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 864 | } |
| 865 | |
Jacopo Mondi | a7b9277 | 2020-05-26 15:41:41 +0200 | [diff] [blame^] | 866 | std::string CameraDevice::logPrefix() const |
| 867 | { |
| 868 | return "'" + camera_->name() + "'"; |
| 869 | } |
| 870 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 871 | void CameraDevice::notifyShutter(uint32_t frameNumber, uint64_t timestamp) |
| 872 | { |
| 873 | camera3_notify_msg_t notify = {}; |
| 874 | |
| 875 | notify.type = CAMERA3_MSG_SHUTTER; |
| 876 | notify.message.shutter.frame_number = frameNumber; |
| 877 | notify.message.shutter.timestamp = timestamp; |
| 878 | |
| 879 | callbacks_->notify(callbacks_, ¬ify); |
| 880 | } |
| 881 | |
| 882 | void CameraDevice::notifyError(uint32_t frameNumber, camera3_stream_t *stream) |
| 883 | { |
| 884 | camera3_notify_msg_t notify = {}; |
| 885 | |
| 886 | notify.type = CAMERA3_MSG_ERROR; |
| 887 | notify.message.error.error_stream = stream; |
| 888 | notify.message.error.frame_number = frameNumber; |
| 889 | notify.message.error.error_code = CAMERA3_MSG_ERROR_REQUEST; |
| 890 | |
| 891 | callbacks_->notify(callbacks_, ¬ify); |
| 892 | } |
| 893 | |
| 894 | /* |
| 895 | * Produce a set of fixed result metadata. |
| 896 | */ |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 897 | std::unique_ptr<CameraMetadata> CameraDevice::getResultMetadata(int frame_number, |
| 898 | int64_t timestamp) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 899 | { |
Jacopo Mondi | 48504ba | 2019-09-04 16:18:19 +0200 | [diff] [blame] | 900 | /* |
| 901 | * \todo Keep this in sync with the actual number of entries. |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 902 | * Currently: 12 entries, 36 bytes |
Jacopo Mondi | 48504ba | 2019-09-04 16:18:19 +0200 | [diff] [blame] | 903 | */ |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 904 | std::unique_ptr<CameraMetadata> resultMetadata = |
Laurent Pinchart | acf18e4 | 2020-01-14 01:35:22 +0200 | [diff] [blame] | 905 | std::make_unique<CameraMetadata>(15, 50); |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 906 | if (!resultMetadata->isValid()) { |
| 907 | LOG(HAL, Error) << "Failed to allocate static metadata"; |
| 908 | return nullptr; |
| 909 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 910 | |
| 911 | const uint8_t ae_state = ANDROID_CONTROL_AE_STATE_CONVERGED; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 912 | resultMetadata->addEntry(ANDROID_CONTROL_AE_STATE, &ae_state, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 913 | |
| 914 | const uint8_t ae_lock = ANDROID_CONTROL_AE_LOCK_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 915 | resultMetadata->addEntry(ANDROID_CONTROL_AE_LOCK, &ae_lock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 916 | |
| 917 | uint8_t af_state = ANDROID_CONTROL_AF_STATE_INACTIVE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 918 | resultMetadata->addEntry(ANDROID_CONTROL_AF_STATE, &af_state, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 919 | |
| 920 | const uint8_t awb_state = ANDROID_CONTROL_AWB_STATE_CONVERGED; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 921 | resultMetadata->addEntry(ANDROID_CONTROL_AWB_STATE, &awb_state, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 922 | |
| 923 | const uint8_t awb_lock = ANDROID_CONTROL_AWB_LOCK_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 924 | resultMetadata->addEntry(ANDROID_CONTROL_AWB_LOCK, &awb_lock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 925 | |
| 926 | const uint8_t lens_state = ANDROID_LENS_STATE_STATIONARY; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 927 | resultMetadata->addEntry(ANDROID_LENS_STATE, &lens_state, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 928 | |
| 929 | int32_t sensorSizes[] = { |
| 930 | 0, 0, 2560, 1920, |
| 931 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 932 | resultMetadata->addEntry(ANDROID_SCALER_CROP_REGION, sensorSizes, 4); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 933 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 934 | resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, ×tamp, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 935 | |
| 936 | /* 33.3 msec */ |
| 937 | const int64_t rolling_shutter_skew = 33300000; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 938 | resultMetadata->addEntry(ANDROID_SENSOR_ROLLING_SHUTTER_SKEW, |
| 939 | &rolling_shutter_skew, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 940 | |
| 941 | /* 16.6 msec */ |
| 942 | const int64_t exposure_time = 16600000; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 943 | resultMetadata->addEntry(ANDROID_SENSOR_EXPOSURE_TIME, |
| 944 | &exposure_time, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 945 | |
| 946 | const uint8_t lens_shading_map_mode = |
| 947 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 948 | resultMetadata->addEntry(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, |
| 949 | &lens_shading_map_mode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 950 | |
| 951 | const uint8_t scene_flicker = ANDROID_STATISTICS_SCENE_FLICKER_NONE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 952 | resultMetadata->addEntry(ANDROID_STATISTICS_SCENE_FLICKER, |
| 953 | &scene_flicker, 1); |
| 954 | |
| 955 | /* |
| 956 | * Return the result metadata pack even is not valid: get() will return |
| 957 | * nullptr. |
| 958 | */ |
| 959 | if (!resultMetadata->isValid()) { |
| 960 | LOG(HAL, Error) << "Failed to construct result metadata"; |
| 961 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 962 | |
| 963 | return resultMetadata; |
| 964 | } |