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 | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 11 | #include <tuple> |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 14 | #include <libcamera/controls.h> |
Laurent Pinchart | 8b7e073 | 2020-05-22 04:02:06 +0300 | [diff] [blame] | 15 | #include <libcamera/formats.h> |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 16 | #include <libcamera/property_ids.h> |
| 17 | |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame^] | 18 | #include "libcamera/internal/formats.h" |
Laurent Pinchart | 93e72b6 | 2020-05-12 00:58:34 +0300 | [diff] [blame] | 19 | #include "libcamera/internal/log.h" |
| 20 | #include "libcamera/internal/utils.h" |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 21 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 22 | #include "camera_metadata.h" |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 23 | #include "system/graphics.h" |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 24 | |
| 25 | using namespace libcamera; |
| 26 | |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 27 | namespace { |
| 28 | |
| 29 | /* |
| 30 | * \var camera3Resolutions |
| 31 | * \brief The list of image resolutions defined as mandatory to be supported by |
| 32 | * the Android Camera3 specification |
| 33 | */ |
| 34 | const std::vector<Size> camera3Resolutions = { |
| 35 | { 320, 240 }, |
| 36 | { 640, 480 }, |
| 37 | { 1280, 720 }, |
| 38 | { 1920, 1080 } |
| 39 | }; |
| 40 | |
| 41 | /* |
| 42 | * \struct Camera3Format |
| 43 | * \brief Data associated with an Android format identifier |
| 44 | * \var libcameraFormats List of libcamera pixel formats compatible with the |
| 45 | * Android format |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 46 | * \var name The human-readable representation of the Android format code |
| 47 | */ |
| 48 | struct Camera3Format { |
| 49 | std::vector<PixelFormat> libcameraFormats; |
Niklas Söderlund | 8c1fedc | 2020-07-28 19:43:12 +0200 | [diff] [blame] | 50 | bool mandatory; |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 51 | const char *name; |
| 52 | }; |
| 53 | |
| 54 | /* |
| 55 | * \var camera3FormatsMap |
| 56 | * \brief Associate Android format code with ancillary data |
| 57 | */ |
| 58 | const std::map<int, const Camera3Format> camera3FormatsMap = { |
| 59 | { |
| 60 | HAL_PIXEL_FORMAT_BLOB, { |
Laurent Pinchart | 8b7e073 | 2020-05-22 04:02:06 +0300 | [diff] [blame] | 61 | { formats::MJPEG }, |
Niklas Söderlund | 8c1fedc | 2020-07-28 19:43:12 +0200 | [diff] [blame] | 62 | true, |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 63 | "BLOB" |
| 64 | } |
| 65 | }, { |
| 66 | HAL_PIXEL_FORMAT_YCbCr_420_888, { |
Laurent Pinchart | 8b7e073 | 2020-05-22 04:02:06 +0300 | [diff] [blame] | 67 | { formats::NV12, formats::NV21 }, |
Niklas Söderlund | 8c1fedc | 2020-07-28 19:43:12 +0200 | [diff] [blame] | 68 | true, |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 69 | "YCbCr_420_888" |
| 70 | } |
| 71 | }, { |
| 72 | /* |
| 73 | * \todo Translate IMPLEMENTATION_DEFINED inspecting the gralloc |
| 74 | * usage flag. For now, copy the YCbCr_420 configuration. |
| 75 | */ |
| 76 | HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, { |
Laurent Pinchart | 8b7e073 | 2020-05-22 04:02:06 +0300 | [diff] [blame] | 77 | { formats::NV12, formats::NV21 }, |
Niklas Söderlund | 8c1fedc | 2020-07-28 19:43:12 +0200 | [diff] [blame] | 78 | true, |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 79 | "IMPLEMENTATION_DEFINED" |
| 80 | } |
Niklas Söderlund | d4de037 | 2020-07-21 00:16:14 +0200 | [diff] [blame] | 81 | }, { |
| 82 | HAL_PIXEL_FORMAT_RAW10, { |
| 83 | { |
| 84 | formats::SBGGR10_CSI2P, |
| 85 | formats::SGBRG10_CSI2P, |
| 86 | formats::SGRBG10_CSI2P, |
| 87 | formats::SRGGB10_CSI2P |
| 88 | }, |
| 89 | false, |
| 90 | "RAW10" |
| 91 | } |
| 92 | }, { |
| 93 | HAL_PIXEL_FORMAT_RAW12, { |
| 94 | { |
| 95 | formats::SBGGR12_CSI2P, |
| 96 | formats::SGBRG12_CSI2P, |
| 97 | formats::SGRBG12_CSI2P, |
| 98 | formats::SRGGB12_CSI2P |
| 99 | }, |
| 100 | false, |
| 101 | "RAW12" |
| 102 | } |
| 103 | }, { |
| 104 | HAL_PIXEL_FORMAT_RAW16, { |
| 105 | { |
| 106 | formats::SBGGR16, |
| 107 | formats::SGBRG16, |
| 108 | formats::SGRBG16, |
| 109 | formats::SRGGB16 |
| 110 | }, |
| 111 | false, |
| 112 | "RAW16" |
| 113 | } |
| 114 | }, { |
| 115 | HAL_PIXEL_FORMAT_RAW_OPAQUE, { |
| 116 | { |
| 117 | formats::SBGGR10_IPU3, |
| 118 | formats::SGBRG10_IPU3, |
| 119 | formats::SGRBG10_IPU3, |
| 120 | formats::SRGGB10_IPU3 |
| 121 | }, |
| 122 | false, |
| 123 | "RAW_OPAQUE" |
| 124 | } |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 125 | }, |
| 126 | }; |
| 127 | |
| 128 | } /* namespace */ |
| 129 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 130 | LOG_DECLARE_CATEGORY(HAL); |
| 131 | |
| 132 | /* |
| 133 | * \struct Camera3RequestDescriptor |
| 134 | * |
| 135 | * A utility structure that groups information about a capture request to be |
| 136 | * later re-used at request complete time to notify the framework. |
| 137 | */ |
| 138 | |
| 139 | CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor( |
| 140 | unsigned int frameNumber, unsigned int numBuffers) |
| 141 | : frameNumber(frameNumber), numBuffers(numBuffers) |
| 142 | { |
| 143 | buffers = new camera3_stream_buffer_t[numBuffers]; |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 144 | frameBuffers.reserve(numBuffers); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor() |
| 148 | { |
| 149 | delete[] buffers; |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | * \class CameraDevice |
| 154 | * |
| 155 | * The CameraDevice class wraps a libcamera::Camera instance, and implements |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 156 | * the camera3_device_t interface, bridging calls received from the Android |
| 157 | * camera service to the CameraDevice. |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 158 | * |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 159 | * The class translates parameters and operations from the Camera HALv3 API to |
| 160 | * the libcamera API to provide static information for a Camera, create request |
| 161 | * templates for it, process capture requests and then deliver capture results |
| 162 | * back to the framework using the designated callbacks. |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 163 | */ |
| 164 | |
Laurent Pinchart | 0ed40d2 | 2019-08-18 01:45:01 +0300 | [diff] [blame] | 165 | CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr<Camera> &camera) |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 166 | : running_(false), camera_(camera), staticMetadata_(nullptr), |
| 167 | facing_(CAMERA_FACING_FRONT), orientation_(0) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 168 | { |
| 169 | camera_->requestCompleted.connect(this, &CameraDevice::requestComplete); |
| 170 | } |
| 171 | |
| 172 | CameraDevice::~CameraDevice() |
| 173 | { |
| 174 | if (staticMetadata_) |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 175 | delete staticMetadata_; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 176 | |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 177 | for (auto &it : requestTemplates_) |
| 178 | delete it.second; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 179 | } |
| 180 | |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 181 | /* |
| 182 | * Initialize the camera static information. |
| 183 | * This method is called before the camera device is opened. |
| 184 | */ |
| 185 | int CameraDevice::initialize() |
| 186 | { |
| 187 | /* Initialize orientation and facing side of the camera. */ |
| 188 | const ControlList &properties = camera_->properties(); |
| 189 | |
| 190 | if (properties.contains(properties::Location)) { |
| 191 | int32_t location = properties.get(properties::Location); |
| 192 | switch (location) { |
| 193 | case properties::CameraLocationFront: |
| 194 | facing_ = CAMERA_FACING_FRONT; |
| 195 | break; |
| 196 | case properties::CameraLocationBack: |
| 197 | facing_ = CAMERA_FACING_BACK; |
| 198 | break; |
| 199 | case properties::CameraLocationExternal: |
| 200 | facing_ = CAMERA_FACING_EXTERNAL; |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /* |
| 206 | * The Android orientation metadata and libcamera rotation property are |
| 207 | * defined differently but have identical numerical values for Android |
| 208 | * devices such as phones and tablets. |
| 209 | */ |
| 210 | if (properties.contains(properties::Rotation)) |
| 211 | orientation_ = properties.get(properties::Rotation); |
| 212 | |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 213 | int ret = camera_->acquire(); |
| 214 | if (ret) { |
| 215 | LOG(HAL, Error) << "Failed to temporarily acquire the camera"; |
| 216 | return ret; |
| 217 | } |
| 218 | |
| 219 | ret = initializeStreamConfigurations(); |
| 220 | camera_->release(); |
| 221 | return ret; |
| 222 | } |
| 223 | |
| 224 | /* |
| 225 | * Initialize the format conversion map to translate from Android format |
| 226 | * identifier to libcamera pixel formats and fill in the list of supported |
| 227 | * stream configurations to be reported to the Android camera framework through |
| 228 | * the static stream configuration metadata. |
| 229 | */ |
| 230 | int CameraDevice::initializeStreamConfigurations() |
| 231 | { |
| 232 | /* |
| 233 | * Get the maximum output resolutions |
| 234 | * \todo Get this from the camera properties once defined |
| 235 | */ |
| 236 | std::unique_ptr<CameraConfiguration> cameraConfig = |
| 237 | camera_->generateConfiguration({ StillCapture }); |
| 238 | if (!cameraConfig) { |
| 239 | LOG(HAL, Error) << "Failed to get maximum resolution"; |
| 240 | return -EINVAL; |
| 241 | } |
| 242 | StreamConfiguration &cfg = cameraConfig->at(0); |
| 243 | |
| 244 | /* |
| 245 | * \todo JPEG - Adjust the maximum available resolution by taking the |
| 246 | * JPEG encoder requirements into account (alignment and aspect ratio). |
| 247 | */ |
| 248 | const Size maxRes = cfg.size; |
| 249 | LOG(HAL, Debug) << "Maximum supported resolution: " << maxRes.toString(); |
| 250 | |
| 251 | /* |
| 252 | * Build the list of supported image resolutions. |
| 253 | * |
| 254 | * The resolutions listed in camera3Resolution are mandatory to be |
| 255 | * supported, up to the camera maximum resolution. |
| 256 | * |
| 257 | * Augment the list by adding resolutions calculated from the camera |
| 258 | * maximum one. |
| 259 | */ |
| 260 | std::vector<Size> cameraResolutions; |
| 261 | std::copy_if(camera3Resolutions.begin(), camera3Resolutions.end(), |
| 262 | std::back_inserter(cameraResolutions), |
| 263 | [&](const Size &res) { return res < maxRes; }); |
| 264 | |
| 265 | /* |
| 266 | * The Camera3 specification suggests adding 1/2 and 1/4 of the maximum |
| 267 | * resolution. |
| 268 | */ |
| 269 | for (unsigned int divider = 2;; divider <<= 1) { |
| 270 | Size derivedSize{ |
| 271 | maxRes.width / divider, |
| 272 | maxRes.height / divider, |
| 273 | }; |
| 274 | |
| 275 | if (derivedSize.width < 320 || |
| 276 | derivedSize.height < 240) |
| 277 | break; |
| 278 | |
| 279 | cameraResolutions.push_back(derivedSize); |
| 280 | } |
| 281 | cameraResolutions.push_back(maxRes); |
| 282 | |
| 283 | /* Remove duplicated entries from the list of supported resolutions. */ |
| 284 | std::sort(cameraResolutions.begin(), cameraResolutions.end()); |
| 285 | auto last = std::unique(cameraResolutions.begin(), cameraResolutions.end()); |
| 286 | cameraResolutions.erase(last, cameraResolutions.end()); |
| 287 | |
| 288 | /* |
| 289 | * Build the list of supported camera formats. |
| 290 | * |
| 291 | * To each Android format a list of compatible libcamera formats is |
| 292 | * associated. The first libcamera format that tests successful is added |
| 293 | * to the format translation map used when configuring the streams. |
| 294 | * It is then tested against the list of supported camera resolutions to |
| 295 | * build the stream configuration map reported through the camera static |
| 296 | * metadata. |
| 297 | */ |
| 298 | for (const auto &format : camera3FormatsMap) { |
| 299 | int androidFormat = format.first; |
| 300 | const Camera3Format &camera3Format = format.second; |
| 301 | const std::vector<PixelFormat> &libcameraFormats = |
| 302 | camera3Format.libcameraFormats; |
| 303 | |
| 304 | /* |
| 305 | * Test the libcamera formats that can produce images |
| 306 | * compatible with the format defined by Android. |
| 307 | */ |
| 308 | PixelFormat mappedFormat; |
| 309 | for (const PixelFormat &pixelFormat : libcameraFormats) { |
| 310 | /* \todo Fixed mapping for JPEG. */ |
| 311 | if (androidFormat == HAL_PIXEL_FORMAT_BLOB) { |
Laurent Pinchart | 8b7e073 | 2020-05-22 04:02:06 +0300 | [diff] [blame] | 312 | mappedFormat = formats::MJPEG; |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 313 | break; |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | * The stream configuration size can be adjusted, |
| 318 | * not the pixel format. |
| 319 | * |
| 320 | * \todo This could be simplified once all pipeline |
| 321 | * handlers will report the StreamFormats list of |
| 322 | * supported formats. |
| 323 | */ |
| 324 | cfg.pixelFormat = pixelFormat; |
| 325 | |
| 326 | CameraConfiguration::Status status = cameraConfig->validate(); |
| 327 | if (status != CameraConfiguration::Invalid && |
| 328 | cfg.pixelFormat == pixelFormat) { |
| 329 | mappedFormat = pixelFormat; |
| 330 | break; |
| 331 | } |
| 332 | } |
Niklas Söderlund | 8c1fedc | 2020-07-28 19:43:12 +0200 | [diff] [blame] | 333 | if (camera3Format.mandatory && !mappedFormat.isValid()) { |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 334 | LOG(HAL, Error) << "Failed to map Android format " |
| 335 | << camera3Format.name << " (" |
| 336 | << utils::hex(androidFormat) << ")"; |
| 337 | return -EINVAL; |
| 338 | } |
| 339 | |
| 340 | /* |
| 341 | * Record the mapping and then proceed to generate the |
| 342 | * stream configurations map, by testing the image resolutions. |
| 343 | */ |
| 344 | formatsMap_[androidFormat] = mappedFormat; |
| 345 | |
| 346 | for (const Size &res : cameraResolutions) { |
| 347 | cfg.pixelFormat = mappedFormat; |
| 348 | cfg.size = res; |
| 349 | |
| 350 | CameraConfiguration::Status status = cameraConfig->validate(); |
| 351 | /* |
| 352 | * Unconditionally report we can produce JPEG. |
| 353 | * |
| 354 | * \todo The JPEG stream will be implemented as an |
| 355 | * HAL-only stream, but some cameras can produce it |
| 356 | * directly. As of now, claim support for JPEG without |
| 357 | * inspecting where the JPEG stream is produced. |
| 358 | */ |
| 359 | if (androidFormat != HAL_PIXEL_FORMAT_BLOB && |
| 360 | status != CameraConfiguration::Valid) |
| 361 | continue; |
| 362 | |
Niklas Söderlund | 142a9ee | 2020-07-23 18:32:23 +0200 | [diff] [blame] | 363 | streamConfigurations_.push_back({ res, androidFormat }); |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
| 367 | LOG(HAL, Debug) << "Collected stream configuration map: "; |
| 368 | for (const auto &entry : streamConfigurations_) |
| 369 | LOG(HAL, Debug) << "{ " << entry.resolution.toString() << " - " |
Niklas Söderlund | 142a9ee | 2020-07-23 18:32:23 +0200 | [diff] [blame] | 370 | << utils::hex(entry.androidFormat) << " }"; |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 371 | |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | /* |
| 376 | * Open a camera device. The static information on the camera shall have been |
| 377 | * initialized with a call to CameraDevice::initialize(). |
| 378 | */ |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 379 | int CameraDevice::open(const hw_module_t *hardwareModule) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 380 | { |
| 381 | int ret = camera_->acquire(); |
| 382 | if (ret) { |
| 383 | LOG(HAL, Error) << "Failed to acquire the camera"; |
| 384 | return ret; |
| 385 | } |
| 386 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 387 | /* Initialize the hw_device_t in the instance camera3_module_t. */ |
| 388 | camera3Device_.common.tag = HARDWARE_DEVICE_TAG; |
| 389 | camera3Device_.common.version = CAMERA_DEVICE_API_VERSION_3_3; |
| 390 | camera3Device_.common.module = (hw_module_t *)hardwareModule; |
| 391 | camera3Device_.common.close = hal_dev_close; |
| 392 | |
| 393 | /* |
| 394 | * The camera device operations. These actually implement |
| 395 | * the Android Camera HALv3 interface. |
| 396 | */ |
| 397 | camera3Device_.ops = &hal_dev_ops; |
| 398 | camera3Device_.priv = this; |
| 399 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | void CameraDevice::close() |
| 404 | { |
| 405 | camera_->stop(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 406 | camera_->release(); |
| 407 | |
| 408 | running_ = false; |
| 409 | } |
| 410 | |
| 411 | void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks) |
| 412 | { |
| 413 | callbacks_ = callbacks; |
| 414 | } |
| 415 | |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 416 | std::tuple<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize() |
| 417 | { |
| 418 | /* |
| 419 | * \todo Keep this in sync with the actual number of entries. |
| 420 | * Currently: 50 entries, 647 bytes of static metadata |
| 421 | */ |
Niklas Söderlund | a2a6f95 | 2020-07-21 00:16:02 +0200 | [diff] [blame] | 422 | uint32_t numEntries = 50; |
| 423 | uint32_t byteSize = 651; |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 424 | |
| 425 | /* |
| 426 | * Calculate space occupation in bytes for dynamically built metadata |
| 427 | * entries. |
| 428 | * |
| 429 | * Each stream configuration entry requires 52 bytes: |
| 430 | * 4 32bits integers for ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 431 | * 4 64bits integers for ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS |
| 432 | */ |
Niklas Söderlund | 3530614 | 2020-07-23 18:25:04 +0200 | [diff] [blame] | 433 | byteSize += streamConfigurations_.size() * 48; |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 434 | |
Laurent Pinchart | 7a88b21 | 2020-06-10 00:07:59 +0300 | [diff] [blame] | 435 | return std::make_tuple(numEntries, byteSize); |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 436 | } |
| 437 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 438 | /* |
| 439 | * Return static information for the camera. |
| 440 | */ |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 441 | const camera_metadata_t *CameraDevice::getStaticMetadata() |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 442 | { |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 443 | if (staticMetadata_) |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 444 | return staticMetadata_->get(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 445 | |
| 446 | /* |
| 447 | * The here reported metadata are enough to implement a basic capture |
| 448 | * example application, but a real camera implementation will require |
| 449 | * more. |
| 450 | */ |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 451 | uint32_t numEntries; |
| 452 | uint32_t byteSize; |
| 453 | std::tie(numEntries, byteSize) = calculateStaticMetadataSize(); |
| 454 | staticMetadata_ = new CameraMetadata(numEntries, byteSize); |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 455 | if (!staticMetadata_->isValid()) { |
| 456 | LOG(HAL, Error) << "Failed to allocate static metadata"; |
| 457 | delete staticMetadata_; |
| 458 | staticMetadata_ = nullptr; |
| 459 | return nullptr; |
| 460 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 461 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 462 | /* Color correction static metadata. */ |
| 463 | std::vector<uint8_t> aberrationModes = { |
| 464 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF, |
| 465 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 466 | staticMetadata_->addEntry(ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, |
| 467 | aberrationModes.data(), |
| 468 | aberrationModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 469 | |
| 470 | /* Control static metadata. */ |
| 471 | std::vector<uint8_t> aeAvailableAntiBandingModes = { |
| 472 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF, |
| 473 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_50HZ, |
| 474 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_60HZ, |
| 475 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO, |
| 476 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 477 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, |
| 478 | aeAvailableAntiBandingModes.data(), |
| 479 | aeAvailableAntiBandingModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 480 | |
| 481 | std::vector<uint8_t> aeAvailableModes = { |
| 482 | ANDROID_CONTROL_AE_MODE_ON, |
| 483 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 484 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_MODES, |
| 485 | aeAvailableModes.data(), |
| 486 | aeAvailableModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 487 | |
| 488 | std::vector<int32_t> availableAeFpsTarget = { |
| 489 | 15, 30, |
| 490 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 491 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, |
| 492 | availableAeFpsTarget.data(), |
| 493 | availableAeFpsTarget.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 494 | |
| 495 | std::vector<int32_t> aeCompensationRange = { |
| 496 | 0, 0, |
| 497 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 498 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_COMPENSATION_RANGE, |
| 499 | aeCompensationRange.data(), |
| 500 | aeCompensationRange.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 501 | |
| 502 | const camera_metadata_rational_t aeCompensationStep[] = { |
| 503 | { 0, 1 } |
| 504 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 505 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_COMPENSATION_STEP, |
| 506 | aeCompensationStep, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 507 | |
| 508 | std::vector<uint8_t> availableAfModes = { |
| 509 | ANDROID_CONTROL_AF_MODE_OFF, |
| 510 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 511 | staticMetadata_->addEntry(ANDROID_CONTROL_AF_AVAILABLE_MODES, |
| 512 | availableAfModes.data(), |
| 513 | availableAfModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 514 | |
| 515 | std::vector<uint8_t> availableEffects = { |
| 516 | ANDROID_CONTROL_EFFECT_MODE_OFF, |
| 517 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 518 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_EFFECTS, |
| 519 | availableEffects.data(), |
| 520 | availableEffects.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 521 | |
| 522 | std::vector<uint8_t> availableSceneModes = { |
| 523 | ANDROID_CONTROL_SCENE_MODE_DISABLED, |
| 524 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 525 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_SCENE_MODES, |
| 526 | availableSceneModes.data(), |
| 527 | availableSceneModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 528 | |
| 529 | std::vector<uint8_t> availableStabilizationModes = { |
| 530 | ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF, |
| 531 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 532 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, |
| 533 | availableStabilizationModes.data(), |
| 534 | availableStabilizationModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 535 | |
| 536 | std::vector<uint8_t> availableAwbModes = { |
| 537 | ANDROID_CONTROL_AWB_MODE_OFF, |
| 538 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 539 | staticMetadata_->addEntry(ANDROID_CONTROL_AWB_AVAILABLE_MODES, |
| 540 | availableAwbModes.data(), |
| 541 | availableAwbModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 542 | |
| 543 | std::vector<int32_t> availableMaxRegions = { |
| 544 | 0, 0, 0, |
| 545 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 546 | staticMetadata_->addEntry(ANDROID_CONTROL_MAX_REGIONS, |
| 547 | availableMaxRegions.data(), |
| 548 | availableMaxRegions.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 549 | |
| 550 | std::vector<uint8_t> sceneModesOverride = { |
| 551 | ANDROID_CONTROL_AE_MODE_ON, |
| 552 | ANDROID_CONTROL_AWB_MODE_AUTO, |
| 553 | ANDROID_CONTROL_AF_MODE_AUTO, |
| 554 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 555 | staticMetadata_->addEntry(ANDROID_CONTROL_SCENE_MODE_OVERRIDES, |
| 556 | sceneModesOverride.data(), |
| 557 | sceneModesOverride.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 558 | |
| 559 | uint8_t aeLockAvailable = ANDROID_CONTROL_AE_LOCK_AVAILABLE_FALSE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 560 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_LOCK_AVAILABLE, |
| 561 | &aeLockAvailable, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 562 | |
| 563 | uint8_t awbLockAvailable = ANDROID_CONTROL_AWB_LOCK_AVAILABLE_FALSE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 564 | staticMetadata_->addEntry(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, |
| 565 | &awbLockAvailable, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 566 | |
| 567 | char availableControlModes = ANDROID_CONTROL_MODE_AUTO; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 568 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_MODES, |
| 569 | &availableControlModes, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 570 | |
| 571 | /* JPEG static metadata. */ |
| 572 | std::vector<int32_t> availableThumbnailSizes = { |
| 573 | 0, 0, |
| 574 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 575 | staticMetadata_->addEntry(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
| 576 | availableThumbnailSizes.data(), |
| 577 | availableThumbnailSizes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 578 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 579 | /* Sensor static metadata. */ |
| 580 | int32_t pixelArraySize[] = { |
| 581 | 2592, 1944, |
| 582 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 583 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, |
| 584 | &pixelArraySize, 2); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 585 | |
| 586 | int32_t sensorSizes[] = { |
| 587 | 0, 0, 2560, 1920, |
| 588 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 589 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, |
| 590 | &sensorSizes, 4); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 591 | |
| 592 | int32_t sensitivityRange[] = { |
| 593 | 32, 2400, |
| 594 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 595 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_SENSITIVITY_RANGE, |
| 596 | &sensitivityRange, 2); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 597 | |
| 598 | uint16_t filterArr = ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_GRBG; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 599 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, |
| 600 | &filterArr, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 601 | |
| 602 | int64_t exposureTimeRange[] = { |
| 603 | 100000, 200000000, |
| 604 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 605 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE, |
| 606 | &exposureTimeRange, 2); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 607 | |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 608 | staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION, &orientation_, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 609 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 610 | std::vector<int32_t> testPatterModes = { |
| 611 | ANDROID_SENSOR_TEST_PATTERN_MODE_OFF, |
| 612 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 613 | staticMetadata_->addEntry(ANDROID_SENSOR_AVAILABLE_TEST_PATTERN_MODES, |
| 614 | testPatterModes.data(), |
| 615 | testPatterModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 616 | |
| 617 | std::vector<float> physicalSize = { |
| 618 | 2592, 1944, |
| 619 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 620 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
| 621 | physicalSize.data(), |
| 622 | physicalSize.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 623 | |
| 624 | uint8_t timestampSource = ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 625 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, |
| 626 | ×tampSource, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 627 | |
| 628 | /* Statistics static metadata. */ |
| 629 | uint8_t faceDetectMode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 630 | staticMetadata_->addEntry(ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, |
| 631 | &faceDetectMode, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 632 | |
| 633 | int32_t maxFaceCount = 0; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 634 | staticMetadata_->addEntry(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, |
| 635 | &maxFaceCount, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 636 | |
| 637 | /* Sync static metadata. */ |
| 638 | int32_t maxLatency = ANDROID_SYNC_MAX_LATENCY_UNKNOWN; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 639 | staticMetadata_->addEntry(ANDROID_SYNC_MAX_LATENCY, &maxLatency, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 640 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 641 | /* Flash static metadata. */ |
| 642 | char flashAvailable = ANDROID_FLASH_INFO_AVAILABLE_FALSE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 643 | staticMetadata_->addEntry(ANDROID_FLASH_INFO_AVAILABLE, |
| 644 | &flashAvailable, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 645 | |
| 646 | /* Lens static metadata. */ |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 647 | std::vector<float> lensApertures = { |
| 648 | 2.53 / 100, |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 649 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 650 | staticMetadata_->addEntry(ANDROID_LENS_INFO_AVAILABLE_APERTURES, |
| 651 | lensApertures.data(), |
| 652 | lensApertures.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 653 | |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 654 | uint8_t lensFacing; |
| 655 | switch (facing_) { |
| 656 | default: |
| 657 | case CAMERA_FACING_FRONT: |
| 658 | lensFacing = ANDROID_LENS_FACING_FRONT; |
| 659 | break; |
| 660 | case CAMERA_FACING_BACK: |
| 661 | lensFacing = ANDROID_LENS_FACING_BACK; |
| 662 | break; |
| 663 | case CAMERA_FACING_EXTERNAL: |
| 664 | lensFacing = ANDROID_LENS_FACING_EXTERNAL; |
| 665 | break; |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 666 | } |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 667 | staticMetadata_->addEntry(ANDROID_LENS_FACING, &lensFacing, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 668 | |
| 669 | std::vector<float> lensFocalLenghts = { |
| 670 | 1, |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 671 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 672 | staticMetadata_->addEntry(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
| 673 | lensFocalLenghts.data(), |
| 674 | lensFocalLenghts.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 675 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 676 | std::vector<uint8_t> opticalStabilizations = { |
| 677 | ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF, |
| 678 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 679 | staticMetadata_->addEntry(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, |
| 680 | opticalStabilizations.data(), |
| 681 | opticalStabilizations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 682 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 683 | float hypeFocalDistance = 0; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 684 | staticMetadata_->addEntry(ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE, |
| 685 | &hypeFocalDistance, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 686 | |
| 687 | float minFocusDistance = 0; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 688 | staticMetadata_->addEntry(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, |
| 689 | &minFocusDistance, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 690 | |
| 691 | /* Noise reduction modes. */ |
| 692 | uint8_t noiseReductionModes = ANDROID_NOISE_REDUCTION_MODE_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 693 | staticMetadata_->addEntry(ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, |
| 694 | &noiseReductionModes, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 695 | |
| 696 | /* Scaler static metadata. */ |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 697 | float maxDigitalZoom = 1; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 698 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, |
| 699 | &maxDigitalZoom, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 700 | |
Jacopo Mondi | bde7b98 | 2020-05-25 17:18:28 +0200 | [diff] [blame] | 701 | std::vector<uint32_t> availableStreamConfigurations; |
| 702 | availableStreamConfigurations.reserve(streamConfigurations_.size() * 4); |
| 703 | for (const auto &entry : streamConfigurations_) { |
Niklas Söderlund | 142a9ee | 2020-07-23 18:32:23 +0200 | [diff] [blame] | 704 | availableStreamConfigurations.push_back(entry.androidFormat); |
Jacopo Mondi | bde7b98 | 2020-05-25 17:18:28 +0200 | [diff] [blame] | 705 | availableStreamConfigurations.push_back(entry.resolution.width); |
| 706 | availableStreamConfigurations.push_back(entry.resolution.height); |
| 707 | availableStreamConfigurations.push_back( |
| 708 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT); |
| 709 | } |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 710 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, |
| 711 | availableStreamConfigurations.data(), |
| 712 | availableStreamConfigurations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 713 | |
| 714 | std::vector<int64_t> availableStallDurations = { |
| 715 | ANDROID_SCALER_AVAILABLE_FORMATS_BLOB, 2560, 1920, 33333333, |
| 716 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 717 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_STALL_DURATIONS, |
| 718 | availableStallDurations.data(), |
| 719 | availableStallDurations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 720 | |
Jacopo Mondi | bde7b98 | 2020-05-25 17:18:28 +0200 | [diff] [blame] | 721 | /* \todo Collect the minimum frame duration from the camera. */ |
| 722 | std::vector<int64_t> minFrameDurations; |
| 723 | minFrameDurations.reserve(streamConfigurations_.size() * 4); |
| 724 | for (const auto &entry : streamConfigurations_) { |
Niklas Söderlund | 142a9ee | 2020-07-23 18:32:23 +0200 | [diff] [blame] | 725 | minFrameDurations.push_back(entry.androidFormat); |
Jacopo Mondi | bde7b98 | 2020-05-25 17:18:28 +0200 | [diff] [blame] | 726 | minFrameDurations.push_back(entry.resolution.width); |
| 727 | minFrameDurations.push_back(entry.resolution.height); |
| 728 | minFrameDurations.push_back(33333333); |
| 729 | } |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 730 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, |
| 731 | minFrameDurations.data(), |
| 732 | minFrameDurations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 733 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 734 | uint8_t croppingType = ANDROID_SCALER_CROPPING_TYPE_CENTER_ONLY; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 735 | staticMetadata_->addEntry(ANDROID_SCALER_CROPPING_TYPE, &croppingType, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 736 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 737 | /* Info static metadata. */ |
| 738 | uint8_t supportedHWLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 739 | staticMetadata_->addEntry(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, |
| 740 | &supportedHWLevel, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 741 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 742 | /* Request static metadata. */ |
| 743 | int32_t partialResultCount = 1; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 744 | staticMetadata_->addEntry(ANDROID_REQUEST_PARTIAL_RESULT_COUNT, |
| 745 | &partialResultCount, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 746 | |
| 747 | uint8_t maxPipelineDepth = 2; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 748 | staticMetadata_->addEntry(ANDROID_REQUEST_PIPELINE_MAX_DEPTH, |
| 749 | &maxPipelineDepth, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 750 | |
Niklas Söderlund | a2a6f95 | 2020-07-21 00:16:02 +0200 | [diff] [blame] | 751 | /* LIMITED does not support reprocessing. */ |
| 752 | uint32_t maxNumInputStreams = 0; |
| 753 | staticMetadata_->addEntry(ANDROID_REQUEST_MAX_NUM_INPUT_STREAMS, |
| 754 | &maxNumInputStreams, 1); |
| 755 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 756 | std::vector<uint8_t> availableCapabilities = { |
| 757 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE, |
| 758 | }; |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame^] | 759 | |
| 760 | /* Report if camera supports RAW. */ |
| 761 | std::unique_ptr<CameraConfiguration> cameraConfig = |
| 762 | camera_->generateConfiguration({ StillCaptureRaw }); |
| 763 | if (cameraConfig && !cameraConfig->empty()) { |
| 764 | const PixelFormatInfo &info = |
| 765 | PixelFormatInfo::info(cameraConfig->at(0).pixelFormat); |
| 766 | if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) |
| 767 | availableCapabilities.push_back(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_RAW); |
| 768 | } |
| 769 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 770 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, |
| 771 | availableCapabilities.data(), |
| 772 | availableCapabilities.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 773 | |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 774 | std::vector<int32_t> availableCharacteristicsKeys = { |
| 775 | ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, |
| 776 | ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, |
| 777 | ANDROID_CONTROL_AE_AVAILABLE_MODES, |
| 778 | ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, |
| 779 | ANDROID_CONTROL_AE_COMPENSATION_RANGE, |
| 780 | ANDROID_CONTROL_AE_COMPENSATION_STEP, |
| 781 | ANDROID_CONTROL_AF_AVAILABLE_MODES, |
| 782 | ANDROID_CONTROL_AVAILABLE_EFFECTS, |
| 783 | ANDROID_CONTROL_AVAILABLE_SCENE_MODES, |
| 784 | ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, |
| 785 | ANDROID_CONTROL_AWB_AVAILABLE_MODES, |
| 786 | ANDROID_CONTROL_MAX_REGIONS, |
| 787 | ANDROID_CONTROL_SCENE_MODE_OVERRIDES, |
| 788 | ANDROID_CONTROL_AE_LOCK_AVAILABLE, |
| 789 | ANDROID_CONTROL_AWB_LOCK_AVAILABLE, |
| 790 | ANDROID_CONTROL_AVAILABLE_MODES, |
| 791 | ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
| 792 | ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, |
| 793 | ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, |
| 794 | ANDROID_SENSOR_INFO_SENSITIVITY_RANGE, |
| 795 | ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, |
| 796 | ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE, |
| 797 | ANDROID_SENSOR_ORIENTATION, |
| 798 | ANDROID_SENSOR_AVAILABLE_TEST_PATTERN_MODES, |
| 799 | ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
| 800 | ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, |
| 801 | ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, |
| 802 | ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, |
| 803 | ANDROID_SYNC_MAX_LATENCY, |
| 804 | ANDROID_FLASH_INFO_AVAILABLE, |
| 805 | ANDROID_LENS_INFO_AVAILABLE_APERTURES, |
| 806 | ANDROID_LENS_FACING, |
| 807 | ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
| 808 | ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, |
| 809 | ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE, |
| 810 | ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, |
| 811 | ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, |
| 812 | ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 813 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, |
| 814 | ANDROID_SCALER_AVAILABLE_STALL_DURATIONS, |
| 815 | ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, |
| 816 | ANDROID_SCALER_CROPPING_TYPE, |
| 817 | ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, |
| 818 | ANDROID_REQUEST_PARTIAL_RESULT_COUNT, |
| 819 | ANDROID_REQUEST_PIPELINE_MAX_DEPTH, |
Niklas Söderlund | a2a6f95 | 2020-07-21 00:16:02 +0200 | [diff] [blame] | 820 | ANDROID_REQUEST_MAX_NUM_INPUT_STREAMS, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 821 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES, |
| 822 | }; |
| 823 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, |
| 824 | availableCharacteristicsKeys.data(), |
| 825 | availableCharacteristicsKeys.size()); |
| 826 | |
| 827 | std::vector<int32_t> availableRequestKeys = { |
| 828 | ANDROID_CONTROL_AE_MODE, |
| 829 | ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
| 830 | ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
| 831 | ANDROID_CONTROL_AE_LOCK, |
| 832 | ANDROID_CONTROL_AF_TRIGGER, |
| 833 | ANDROID_CONTROL_AWB_MODE, |
| 834 | ANDROID_CONTROL_AWB_LOCK, |
| 835 | ANDROID_FLASH_MODE, |
| 836 | ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 837 | ANDROID_NOISE_REDUCTION_MODE, |
| 838 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 839 | ANDROID_CONTROL_CAPTURE_INTENT, |
| 840 | }; |
| 841 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS, |
| 842 | availableRequestKeys.data(), |
| 843 | availableRequestKeys.size()); |
| 844 | |
| 845 | std::vector<int32_t> availableResultKeys = { |
| 846 | ANDROID_CONTROL_AE_STATE, |
| 847 | ANDROID_CONTROL_AE_LOCK, |
| 848 | ANDROID_CONTROL_AF_STATE, |
| 849 | ANDROID_CONTROL_AWB_STATE, |
| 850 | ANDROID_CONTROL_AWB_LOCK, |
| 851 | ANDROID_LENS_STATE, |
| 852 | ANDROID_SCALER_CROP_REGION, |
| 853 | ANDROID_SENSOR_TIMESTAMP, |
| 854 | ANDROID_SENSOR_ROLLING_SHUTTER_SKEW, |
| 855 | ANDROID_SENSOR_EXPOSURE_TIME, |
| 856 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, |
| 857 | ANDROID_STATISTICS_SCENE_FLICKER, |
| 858 | }; |
| 859 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_RESULT_KEYS, |
| 860 | availableResultKeys.data(), |
| 861 | availableResultKeys.size()); |
| 862 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 863 | if (!staticMetadata_->isValid()) { |
| 864 | LOG(HAL, Error) << "Failed to construct static metadata"; |
| 865 | delete staticMetadata_; |
| 866 | staticMetadata_ = nullptr; |
| 867 | return nullptr; |
| 868 | } |
| 869 | |
| 870 | return staticMetadata_->get(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | /* |
| 874 | * Produce a metadata pack to be used as template for a capture request. |
| 875 | */ |
| 876 | const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) |
| 877 | { |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 878 | auto it = requestTemplates_.find(type); |
| 879 | if (it != requestTemplates_.end()) |
| 880 | return it->second->get(); |
| 881 | |
| 882 | /* Use the capture intent matching the requested template type. */ |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 883 | uint8_t captureIntent; |
| 884 | switch (type) { |
| 885 | case CAMERA3_TEMPLATE_PREVIEW: |
| 886 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; |
| 887 | break; |
| 888 | case CAMERA3_TEMPLATE_STILL_CAPTURE: |
| 889 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE; |
| 890 | break; |
| 891 | case CAMERA3_TEMPLATE_VIDEO_RECORD: |
| 892 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD; |
| 893 | break; |
| 894 | case CAMERA3_TEMPLATE_VIDEO_SNAPSHOT: |
| 895 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT; |
| 896 | break; |
| 897 | case CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG: |
| 898 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG; |
| 899 | break; |
| 900 | case CAMERA3_TEMPLATE_MANUAL: |
| 901 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_MANUAL; |
| 902 | break; |
| 903 | default: |
| 904 | LOG(HAL, Error) << "Invalid template request type: " << type; |
| 905 | return nullptr; |
| 906 | } |
| 907 | |
Jacopo Mondi | 6370347 | 2019-09-04 16:18:22 +0200 | [diff] [blame] | 908 | /* |
| 909 | * \todo Keep this in sync with the actual number of entries. |
| 910 | * Currently: 12 entries, 15 bytes |
| 911 | */ |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 912 | CameraMetadata *requestTemplate = new CameraMetadata(15, 20); |
| 913 | if (!requestTemplate->isValid()) { |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 914 | LOG(HAL, Error) << "Failed to allocate template metadata"; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 915 | delete requestTemplate; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 916 | return nullptr; |
| 917 | } |
| 918 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 919 | uint8_t aeMode = ANDROID_CONTROL_AE_MODE_ON; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 920 | requestTemplate->addEntry(ANDROID_CONTROL_AE_MODE, |
| 921 | &aeMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 922 | |
| 923 | int32_t aeExposureCompensation = 0; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 924 | requestTemplate->addEntry(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
| 925 | &aeExposureCompensation, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 926 | |
| 927 | uint8_t aePrecaptureTrigger = ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 928 | requestTemplate->addEntry(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
| 929 | &aePrecaptureTrigger, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 930 | |
| 931 | uint8_t aeLock = ANDROID_CONTROL_AE_LOCK_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 932 | requestTemplate->addEntry(ANDROID_CONTROL_AE_LOCK, |
| 933 | &aeLock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 934 | |
| 935 | uint8_t afTrigger = ANDROID_CONTROL_AF_TRIGGER_IDLE; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 936 | requestTemplate->addEntry(ANDROID_CONTROL_AF_TRIGGER, |
| 937 | &afTrigger, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 938 | |
| 939 | uint8_t awbMode = ANDROID_CONTROL_AWB_MODE_AUTO; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 940 | requestTemplate->addEntry(ANDROID_CONTROL_AWB_MODE, |
| 941 | &awbMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 942 | |
| 943 | uint8_t awbLock = ANDROID_CONTROL_AWB_LOCK_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 944 | requestTemplate->addEntry(ANDROID_CONTROL_AWB_LOCK, |
| 945 | &awbLock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 946 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 947 | uint8_t flashMode = ANDROID_FLASH_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 948 | requestTemplate->addEntry(ANDROID_FLASH_MODE, |
| 949 | &flashMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 950 | |
| 951 | uint8_t faceDetectMode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 952 | requestTemplate->addEntry(ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 953 | &faceDetectMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 954 | |
Jacopo Mondi | 9b361dc | 2019-09-04 16:18:21 +0200 | [diff] [blame] | 955 | uint8_t noiseReduction = ANDROID_NOISE_REDUCTION_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 956 | requestTemplate->addEntry(ANDROID_NOISE_REDUCTION_MODE, |
| 957 | &noiseReduction, 1); |
Jacopo Mondi | 9b361dc | 2019-09-04 16:18:21 +0200 | [diff] [blame] | 958 | |
| 959 | uint8_t aberrationMode = ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 960 | requestTemplate->addEntry(ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 961 | &aberrationMode, 1); |
Jacopo Mondi | 9b361dc | 2019-09-04 16:18:21 +0200 | [diff] [blame] | 962 | |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 963 | requestTemplate->addEntry(ANDROID_CONTROL_CAPTURE_INTENT, |
| 964 | &captureIntent, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 965 | |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 966 | if (!requestTemplate->isValid()) { |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 967 | LOG(HAL, Error) << "Failed to construct request template"; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 968 | delete requestTemplate; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 969 | return nullptr; |
| 970 | } |
| 971 | |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 972 | requestTemplates_[type] = requestTemplate; |
| 973 | return requestTemplate->get(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 974 | } |
| 975 | |
Kieran Bingham | 43e3b80 | 2020-06-26 09:58:49 +0100 | [diff] [blame] | 976 | PixelFormat CameraDevice::toPixelFormat(int format) |
| 977 | { |
| 978 | /* Translate Android format code to libcamera pixel format. */ |
| 979 | auto it = formatsMap_.find(format); |
| 980 | if (it == formatsMap_.end()) { |
| 981 | LOG(HAL, Error) << "Requested format " << utils::hex(format) |
| 982 | << " not supported"; |
| 983 | return PixelFormat(); |
| 984 | } |
| 985 | |
| 986 | return it->second; |
| 987 | } |
| 988 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 989 | /* |
| 990 | * Inspect the stream_list to produce a list of StreamConfiguration to |
| 991 | * be use to configure the Camera. |
| 992 | */ |
| 993 | int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) |
| 994 | { |
Kieran Bingham | 0a9244e | 2020-06-26 20:19:10 +0100 | [diff] [blame] | 995 | /* |
| 996 | * Generate an empty configuration, and construct a StreamConfiguration |
| 997 | * for each camera3_stream to add to it. |
| 998 | */ |
| 999 | config_ = camera_->generateConfiguration(); |
| 1000 | if (!config_) { |
| 1001 | LOG(HAL, Error) << "Failed to generate camera configuration"; |
| 1002 | return -EINVAL; |
| 1003 | } |
| 1004 | |
Kieran Bingham | 2f34f5e | 2020-07-01 16:42:13 +0100 | [diff] [blame] | 1005 | /* |
| 1006 | * Clear and remove any existing configuration from previous calls, and |
| 1007 | * ensure the required entries are available without further |
| 1008 | * re-allcoation. |
| 1009 | */ |
| 1010 | streams_.clear(); |
| 1011 | streams_.reserve(stream_list->num_streams); |
| 1012 | |
| 1013 | /* |
| 1014 | * Track actually created streams, as there may not be a 1:1 mapping of |
| 1015 | * camera3 streams to libcamera streams. |
| 1016 | */ |
| 1017 | unsigned int streamIndex = 0; |
| 1018 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1019 | for (unsigned int i = 0; i < stream_list->num_streams; ++i) { |
| 1020 | camera3_stream_t *stream = stream_list->streams[i]; |
| 1021 | |
Kieran Bingham | 43e3b80 | 2020-06-26 09:58:49 +0100 | [diff] [blame] | 1022 | PixelFormat format = toPixelFormat(stream->format); |
| 1023 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1024 | LOG(HAL, Info) << "Stream #" << i |
| 1025 | << ", direction: " << stream->stream_type |
| 1026 | << ", width: " << stream->width |
| 1027 | << ", height: " << stream->height |
Kieran Bingham | 43e3b80 | 2020-06-26 09:58:49 +0100 | [diff] [blame] | 1028 | << ", format: " << utils::hex(stream->format) |
| 1029 | << " (" << format.toString() << ")"; |
Kieran Bingham | 0a9244e | 2020-06-26 20:19:10 +0100 | [diff] [blame] | 1030 | |
| 1031 | if (!format.isValid()) |
| 1032 | return -EINVAL; |
| 1033 | |
| 1034 | StreamConfiguration streamConfiguration; |
| 1035 | |
| 1036 | streamConfiguration.size.width = stream->width; |
| 1037 | streamConfiguration.size.height = stream->height; |
| 1038 | streamConfiguration.pixelFormat = format; |
| 1039 | |
| 1040 | config_->addConfiguration(streamConfiguration); |
Kieran Bingham | 2f34f5e | 2020-07-01 16:42:13 +0100 | [diff] [blame] | 1041 | |
| 1042 | streams_[i].index = streamIndex++; |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1043 | stream->priv = static_cast<void *>(&streams_[i]); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1044 | } |
| 1045 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1046 | switch (config_->validate()) { |
| 1047 | case CameraConfiguration::Valid: |
| 1048 | break; |
| 1049 | case CameraConfiguration::Adjusted: |
| 1050 | LOG(HAL, Info) << "Camera configuration adjusted"; |
| 1051 | config_.reset(); |
| 1052 | return -EINVAL; |
| 1053 | case CameraConfiguration::Invalid: |
| 1054 | LOG(HAL, Info) << "Camera configuration invalid"; |
| 1055 | config_.reset(); |
| 1056 | return -EINVAL; |
| 1057 | } |
| 1058 | |
Kieran Bingham | 0a9244e | 2020-06-26 20:19:10 +0100 | [diff] [blame] | 1059 | for (unsigned int i = 0; i < stream_list->num_streams; ++i) { |
| 1060 | camera3_stream_t *stream = stream_list->streams[i]; |
Kieran Bingham | 2f34f5e | 2020-07-01 16:42:13 +0100 | [diff] [blame] | 1061 | CameraStream *cameraStream = &streams_[i]; |
| 1062 | StreamConfiguration &cfg = config_->at(cameraStream->index); |
Kieran Bingham | 0a9244e | 2020-06-26 20:19:10 +0100 | [diff] [blame] | 1063 | |
| 1064 | /* Use the bufferCount confirmed by the validation process. */ |
Kieran Bingham | 2f34f5e | 2020-07-01 16:42:13 +0100 | [diff] [blame] | 1065 | stream->max_buffers = cfg.bufferCount; |
Kieran Bingham | 0a9244e | 2020-06-26 20:19:10 +0100 | [diff] [blame] | 1066 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1067 | |
| 1068 | /* |
| 1069 | * Once the CameraConfiguration has been adjusted/validated |
| 1070 | * it can be applied to the camera. |
| 1071 | */ |
| 1072 | int ret = camera_->configure(config_.get()); |
| 1073 | if (ret) { |
| 1074 | LOG(HAL, Error) << "Failed to configure camera '" |
| 1075 | << camera_->name() << "'"; |
| 1076 | return ret; |
| 1077 | } |
| 1078 | |
| 1079 | return 0; |
| 1080 | } |
| 1081 | |
Kieran Bingham | 74ab442 | 2020-07-01 13:25:38 +0100 | [diff] [blame] | 1082 | FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer) |
| 1083 | { |
| 1084 | std::vector<FrameBuffer::Plane> planes; |
| 1085 | for (unsigned int i = 0; i < 3; i++) { |
| 1086 | FrameBuffer::Plane plane; |
| 1087 | plane.fd = FileDescriptor(camera3buffer->data[i]); |
| 1088 | /* |
| 1089 | * Setting length to zero here is OK as the length is only used |
| 1090 | * to map the memory of the plane. Libcamera do not need to poke |
| 1091 | * at the memory content queued by the HAL. |
| 1092 | */ |
| 1093 | plane.length = 0; |
| 1094 | planes.push_back(std::move(plane)); |
| 1095 | } |
| 1096 | |
| 1097 | return new FrameBuffer(std::move(planes)); |
| 1098 | } |
| 1099 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1100 | int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1101 | { |
Kieran Bingham | 61f4296 | 2020-07-01 13:40:17 +0100 | [diff] [blame] | 1102 | if (!camera3Request->num_output_buffers) { |
| 1103 | LOG(HAL, Error) << "No output buffers provided"; |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1104 | return -EINVAL; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | /* Start the camera if that's the first request we handle. */ |
| 1108 | if (!running_) { |
Niklas Söderlund | a1c5450 | 2019-11-25 17:51:06 +0100 | [diff] [blame] | 1109 | int ret = camera_->start(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1110 | if (ret) { |
| 1111 | LOG(HAL, Error) << "Failed to start camera"; |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1112 | return ret; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | running_ = true; |
| 1116 | } |
| 1117 | |
| 1118 | /* |
| 1119 | * Queue a request for the Camera with the provided dmabuf file |
| 1120 | * descriptors. |
| 1121 | */ |
| 1122 | const camera3_stream_buffer_t *camera3Buffers = |
| 1123 | camera3Request->output_buffers; |
| 1124 | |
| 1125 | /* |
| 1126 | * Save the request descriptors for use at completion time. |
| 1127 | * The descriptor and the associated memory reserved here are freed |
| 1128 | * at request complete time. |
| 1129 | */ |
| 1130 | Camera3RequestDescriptor *descriptor = |
| 1131 | new Camera3RequestDescriptor(camera3Request->frame_number, |
| 1132 | camera3Request->num_output_buffers); |
Kieran Bingham | eac0542 | 2020-07-01 13:28:16 +0100 | [diff] [blame] | 1133 | |
| 1134 | Request *request = |
| 1135 | camera_->createRequest(reinterpret_cast<uint64_t>(descriptor)); |
| 1136 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1137 | for (unsigned int i = 0; i < descriptor->numBuffers; ++i) { |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1138 | CameraStream *cameraStream = |
| 1139 | static_cast<CameraStream *>(camera3Buffers[i].stream->priv); |
| 1140 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1141 | /* |
| 1142 | * Keep track of which stream the request belongs to and store |
| 1143 | * the native buffer handles. |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1144 | */ |
| 1145 | descriptor->buffers[i].stream = camera3Buffers[i].stream; |
| 1146 | descriptor->buffers[i].buffer = camera3Buffers[i].buffer; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1147 | |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1148 | /* |
| 1149 | * Create a libcamera buffer using the dmabuf descriptors of |
| 1150 | * the camera3Buffer for each stream. The FrameBuffer is |
| 1151 | * directly associated with the Camera3RequestDescriptor for |
| 1152 | * lifetime management only. |
| 1153 | */ |
| 1154 | FrameBuffer *buffer = createFrameBuffer(*camera3Buffers[i].buffer); |
| 1155 | if (!buffer) { |
| 1156 | LOG(HAL, Error) << "Failed to create buffer"; |
| 1157 | delete request; |
| 1158 | delete descriptor; |
| 1159 | return -ENOMEM; |
| 1160 | } |
| 1161 | descriptor->frameBuffers.emplace_back(buffer); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1162 | |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1163 | StreamConfiguration *streamConfiguration = &config_->at(cameraStream->index); |
| 1164 | Stream *stream = streamConfiguration->stream(); |
| 1165 | |
| 1166 | request->addBuffer(stream, buffer); |
| 1167 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1168 | |
| 1169 | int ret = camera_->queueRequest(request); |
| 1170 | if (ret) { |
| 1171 | LOG(HAL, Error) << "Failed to queue request"; |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1172 | delete request; |
| 1173 | delete descriptor; |
| 1174 | return ret; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1175 | } |
| 1176 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1177 | return 0; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1178 | } |
| 1179 | |
Niklas Söderlund | f7ddfd4 | 2019-10-21 20:01:19 +0200 | [diff] [blame] | 1180 | void CameraDevice::requestComplete(Request *request) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1181 | { |
Niklas Söderlund | 9217f27 | 2019-11-22 16:22:56 +0100 | [diff] [blame] | 1182 | const std::map<Stream *, FrameBuffer *> &buffers = request->buffers(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1183 | camera3_buffer_status status = CAMERA3_BUFFER_STATUS_OK; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1184 | std::unique_ptr<CameraMetadata> resultMetadata; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1185 | |
| 1186 | if (request->status() != Request::RequestComplete) { |
| 1187 | LOG(HAL, Error) << "Request not succesfully completed: " |
| 1188 | << request->status(); |
| 1189 | status = CAMERA3_BUFFER_STATUS_ERROR; |
| 1190 | } |
| 1191 | |
| 1192 | /* Prepare to call back the Android camera stack. */ |
| 1193 | Camera3RequestDescriptor *descriptor = |
| 1194 | reinterpret_cast<Camera3RequestDescriptor *>(request->cookie()); |
| 1195 | |
| 1196 | camera3_capture_result_t captureResult = {}; |
| 1197 | captureResult.frame_number = descriptor->frameNumber; |
| 1198 | captureResult.num_output_buffers = descriptor->numBuffers; |
| 1199 | for (unsigned int i = 0; i < descriptor->numBuffers; ++i) { |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1200 | descriptor->buffers[i].acquire_fence = -1; |
| 1201 | descriptor->buffers[i].release_fence = -1; |
| 1202 | descriptor->buffers[i].status = status; |
| 1203 | } |
| 1204 | captureResult.output_buffers = |
| 1205 | const_cast<const camera3_stream_buffer_t *>(descriptor->buffers); |
| 1206 | |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1207 | /* |
| 1208 | * \todo The timestamp used for the metadata is currently always taken |
| 1209 | * from the first buffer (which may be the first stream) in the Request. |
| 1210 | * It might be appropriate to return a 'correct' (as determined by |
| 1211 | * pipeline handlers) timestamp in the Request itself. |
| 1212 | */ |
| 1213 | FrameBuffer *buffer = buffers.begin()->second; |
| 1214 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1215 | if (status == CAMERA3_BUFFER_STATUS_OK) { |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1216 | notifyShutter(descriptor->frameNumber, |
Niklas Söderlund | 9217f27 | 2019-11-22 16:22:56 +0100 | [diff] [blame] | 1217 | buffer->metadata().timestamp); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1218 | |
| 1219 | captureResult.partial_result = 1; |
| 1220 | resultMetadata = getResultMetadata(descriptor->frameNumber, |
Niklas Söderlund | 9217f27 | 2019-11-22 16:22:56 +0100 | [diff] [blame] | 1221 | buffer->metadata().timestamp); |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1222 | captureResult.result = resultMetadata->get(); |
| 1223 | } |
| 1224 | |
| 1225 | if (status == CAMERA3_BUFFER_STATUS_ERROR || !captureResult.result) { |
| 1226 | /* \todo Improve error handling. In case we notify an error |
| 1227 | * because the metadata generation fails, a shutter event has |
| 1228 | * already been notified for this frame number before the error |
| 1229 | * is here signalled. Make sure the error path plays well with |
| 1230 | * the camera stack state machine. |
| 1231 | */ |
| 1232 | notifyError(descriptor->frameNumber, |
| 1233 | descriptor->buffers[0].stream); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | callbacks_->process_capture_result(callbacks_, &captureResult); |
| 1237 | |
| 1238 | delete descriptor; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1239 | } |
| 1240 | |
Jacopo Mondi | a7b9277 | 2020-05-26 15:41:41 +0200 | [diff] [blame] | 1241 | std::string CameraDevice::logPrefix() const |
| 1242 | { |
| 1243 | return "'" + camera_->name() + "'"; |
| 1244 | } |
| 1245 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1246 | void CameraDevice::notifyShutter(uint32_t frameNumber, uint64_t timestamp) |
| 1247 | { |
| 1248 | camera3_notify_msg_t notify = {}; |
| 1249 | |
| 1250 | notify.type = CAMERA3_MSG_SHUTTER; |
| 1251 | notify.message.shutter.frame_number = frameNumber; |
| 1252 | notify.message.shutter.timestamp = timestamp; |
| 1253 | |
| 1254 | callbacks_->notify(callbacks_, ¬ify); |
| 1255 | } |
| 1256 | |
| 1257 | void CameraDevice::notifyError(uint32_t frameNumber, camera3_stream_t *stream) |
| 1258 | { |
| 1259 | camera3_notify_msg_t notify = {}; |
| 1260 | |
| 1261 | notify.type = CAMERA3_MSG_ERROR; |
| 1262 | notify.message.error.error_stream = stream; |
| 1263 | notify.message.error.frame_number = frameNumber; |
| 1264 | notify.message.error.error_code = CAMERA3_MSG_ERROR_REQUEST; |
| 1265 | |
| 1266 | callbacks_->notify(callbacks_, ¬ify); |
| 1267 | } |
| 1268 | |
| 1269 | /* |
| 1270 | * Produce a set of fixed result metadata. |
| 1271 | */ |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1272 | std::unique_ptr<CameraMetadata> CameraDevice::getResultMetadata(int frame_number, |
| 1273 | int64_t timestamp) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1274 | { |
Jacopo Mondi | 48504ba | 2019-09-04 16:18:19 +0200 | [diff] [blame] | 1275 | /* |
| 1276 | * \todo Keep this in sync with the actual number of entries. |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1277 | * Currently: 12 entries, 36 bytes |
Jacopo Mondi | 48504ba | 2019-09-04 16:18:19 +0200 | [diff] [blame] | 1278 | */ |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1279 | std::unique_ptr<CameraMetadata> resultMetadata = |
Laurent Pinchart | acf18e4 | 2020-01-14 01:35:22 +0200 | [diff] [blame] | 1280 | std::make_unique<CameraMetadata>(15, 50); |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1281 | if (!resultMetadata->isValid()) { |
| 1282 | LOG(HAL, Error) << "Failed to allocate static metadata"; |
| 1283 | return nullptr; |
| 1284 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1285 | |
| 1286 | const uint8_t ae_state = ANDROID_CONTROL_AE_STATE_CONVERGED; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1287 | resultMetadata->addEntry(ANDROID_CONTROL_AE_STATE, &ae_state, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1288 | |
| 1289 | const uint8_t ae_lock = ANDROID_CONTROL_AE_LOCK_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1290 | resultMetadata->addEntry(ANDROID_CONTROL_AE_LOCK, &ae_lock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1291 | |
| 1292 | uint8_t af_state = ANDROID_CONTROL_AF_STATE_INACTIVE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1293 | resultMetadata->addEntry(ANDROID_CONTROL_AF_STATE, &af_state, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1294 | |
| 1295 | const uint8_t awb_state = ANDROID_CONTROL_AWB_STATE_CONVERGED; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1296 | resultMetadata->addEntry(ANDROID_CONTROL_AWB_STATE, &awb_state, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1297 | |
| 1298 | const uint8_t awb_lock = ANDROID_CONTROL_AWB_LOCK_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1299 | resultMetadata->addEntry(ANDROID_CONTROL_AWB_LOCK, &awb_lock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1300 | |
| 1301 | const uint8_t lens_state = ANDROID_LENS_STATE_STATIONARY; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1302 | resultMetadata->addEntry(ANDROID_LENS_STATE, &lens_state, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1303 | |
| 1304 | int32_t sensorSizes[] = { |
| 1305 | 0, 0, 2560, 1920, |
| 1306 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1307 | resultMetadata->addEntry(ANDROID_SCALER_CROP_REGION, sensorSizes, 4); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1308 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1309 | resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, ×tamp, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1310 | |
| 1311 | /* 33.3 msec */ |
| 1312 | const int64_t rolling_shutter_skew = 33300000; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1313 | resultMetadata->addEntry(ANDROID_SENSOR_ROLLING_SHUTTER_SKEW, |
| 1314 | &rolling_shutter_skew, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1315 | |
| 1316 | /* 16.6 msec */ |
| 1317 | const int64_t exposure_time = 16600000; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1318 | resultMetadata->addEntry(ANDROID_SENSOR_EXPOSURE_TIME, |
| 1319 | &exposure_time, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1320 | |
| 1321 | const uint8_t lens_shading_map_mode = |
| 1322 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1323 | resultMetadata->addEntry(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, |
| 1324 | &lens_shading_map_mode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1325 | |
| 1326 | const uint8_t scene_flicker = ANDROID_STATISTICS_SCENE_FLICKER_NONE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1327 | resultMetadata->addEntry(ANDROID_STATISTICS_SCENE_FLICKER, |
| 1328 | &scene_flicker, 1); |
| 1329 | |
| 1330 | /* |
| 1331 | * Return the result metadata pack even is not valid: get() will return |
| 1332 | * nullptr. |
| 1333 | */ |
| 1334 | if (!resultMetadata->isValid()) { |
| 1335 | LOG(HAL, Error) << "Failed to construct result metadata"; |
| 1336 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1337 | |
| 1338 | return resultMetadata; |
| 1339 | } |