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" |
Umang Jain | b2b8c4d | 2020-10-16 11:07:54 +0530 | [diff] [blame] | 10 | #include "post_processor.h" |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 11 | |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 12 | #include <sys/mman.h> |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 13 | #include <tuple> |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
Jacopo Mondi | 5d91c8d | 2020-09-23 09:41:52 +0200 | [diff] [blame] | 16 | #include <libcamera/control_ids.h> |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 17 | #include <libcamera/controls.h> |
Laurent Pinchart | 8b7e073 | 2020-05-22 04:02:06 +0300 | [diff] [blame] | 18 | #include <libcamera/formats.h> |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 19 | #include <libcamera/property_ids.h> |
| 20 | |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame] | 21 | #include "libcamera/internal/formats.h" |
Laurent Pinchart | 93e72b6 | 2020-05-12 00:58:34 +0300 | [diff] [blame] | 22 | #include "libcamera/internal/log.h" |
| 23 | #include "libcamera/internal/utils.h" |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 24 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 25 | #include "camera_metadata.h" |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 26 | #include "system/graphics.h" |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 27 | |
| 28 | using namespace libcamera; |
| 29 | |
Hirokazu Honda | 26d90af | 2020-12-11 09:53:36 +0000 | [diff] [blame] | 30 | LOG_DECLARE_CATEGORY(HAL) |
| 31 | |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 32 | namespace { |
| 33 | |
| 34 | /* |
| 35 | * \var camera3Resolutions |
| 36 | * \brief The list of image resolutions defined as mandatory to be supported by |
| 37 | * the Android Camera3 specification |
| 38 | */ |
| 39 | const std::vector<Size> camera3Resolutions = { |
| 40 | { 320, 240 }, |
| 41 | { 640, 480 }, |
| 42 | { 1280, 720 }, |
| 43 | { 1920, 1080 } |
| 44 | }; |
| 45 | |
| 46 | /* |
| 47 | * \struct Camera3Format |
| 48 | * \brief Data associated with an Android format identifier |
| 49 | * \var libcameraFormats List of libcamera pixel formats compatible with the |
| 50 | * Android format |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 51 | * \var name The human-readable representation of the Android format code |
| 52 | */ |
| 53 | struct Camera3Format { |
| 54 | std::vector<PixelFormat> libcameraFormats; |
Niklas Söderlund | 8c1fedc | 2020-07-28 19:43:12 +0200 | [diff] [blame] | 55 | bool mandatory; |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 56 | const char *name; |
| 57 | }; |
| 58 | |
| 59 | /* |
| 60 | * \var camera3FormatsMap |
| 61 | * \brief Associate Android format code with ancillary data |
| 62 | */ |
| 63 | const std::map<int, const Camera3Format> camera3FormatsMap = { |
| 64 | { |
| 65 | HAL_PIXEL_FORMAT_BLOB, { |
Laurent Pinchart | 8b7e073 | 2020-05-22 04:02:06 +0300 | [diff] [blame] | 66 | { formats::MJPEG }, |
Niklas Söderlund | 8c1fedc | 2020-07-28 19:43:12 +0200 | [diff] [blame] | 67 | true, |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 68 | "BLOB" |
| 69 | } |
| 70 | }, { |
| 71 | HAL_PIXEL_FORMAT_YCbCr_420_888, { |
Laurent Pinchart | 8b7e073 | 2020-05-22 04:02:06 +0300 | [diff] [blame] | 72 | { formats::NV12, formats::NV21 }, |
Niklas Söderlund | 8c1fedc | 2020-07-28 19:43:12 +0200 | [diff] [blame] | 73 | true, |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 74 | "YCbCr_420_888" |
| 75 | } |
| 76 | }, { |
| 77 | /* |
| 78 | * \todo Translate IMPLEMENTATION_DEFINED inspecting the gralloc |
| 79 | * usage flag. For now, copy the YCbCr_420 configuration. |
| 80 | */ |
| 81 | HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, { |
Laurent Pinchart | 8b7e073 | 2020-05-22 04:02:06 +0300 | [diff] [blame] | 82 | { formats::NV12, formats::NV21 }, |
Niklas Söderlund | 8c1fedc | 2020-07-28 19:43:12 +0200 | [diff] [blame] | 83 | true, |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 84 | "IMPLEMENTATION_DEFINED" |
| 85 | } |
Niklas Söderlund | d4de037 | 2020-07-21 00:16:14 +0200 | [diff] [blame] | 86 | }, { |
| 87 | HAL_PIXEL_FORMAT_RAW10, { |
| 88 | { |
| 89 | formats::SBGGR10_CSI2P, |
| 90 | formats::SGBRG10_CSI2P, |
| 91 | formats::SGRBG10_CSI2P, |
| 92 | formats::SRGGB10_CSI2P |
| 93 | }, |
| 94 | false, |
| 95 | "RAW10" |
| 96 | } |
| 97 | }, { |
| 98 | HAL_PIXEL_FORMAT_RAW12, { |
| 99 | { |
| 100 | formats::SBGGR12_CSI2P, |
| 101 | formats::SGBRG12_CSI2P, |
| 102 | formats::SGRBG12_CSI2P, |
| 103 | formats::SRGGB12_CSI2P |
| 104 | }, |
| 105 | false, |
| 106 | "RAW12" |
| 107 | } |
| 108 | }, { |
| 109 | HAL_PIXEL_FORMAT_RAW16, { |
| 110 | { |
| 111 | formats::SBGGR16, |
| 112 | formats::SGBRG16, |
| 113 | formats::SGRBG16, |
| 114 | formats::SRGGB16 |
| 115 | }, |
| 116 | false, |
| 117 | "RAW16" |
| 118 | } |
| 119 | }, { |
| 120 | HAL_PIXEL_FORMAT_RAW_OPAQUE, { |
| 121 | { |
| 122 | formats::SBGGR10_IPU3, |
| 123 | formats::SGBRG10_IPU3, |
| 124 | formats::SGRBG10_IPU3, |
| 125 | formats::SRGGB10_IPU3 |
| 126 | }, |
| 127 | false, |
| 128 | "RAW_OPAQUE" |
| 129 | } |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 130 | }, |
| 131 | }; |
| 132 | |
Hirokazu Honda | c2df743 | 2020-12-11 09:53:34 +0000 | [diff] [blame] | 133 | /* |
| 134 | * \struct Camera3StreamConfig |
| 135 | * \brief Data to store StreamConfiguration associated with camera3_stream(s) |
| 136 | * \var streams List of the pairs of a stream requested by Android HAL client |
| 137 | * and CameraStream::Type associated with the stream |
| 138 | * \var config StreamConfiguration for streams |
| 139 | */ |
| 140 | struct Camera3StreamConfig { |
| 141 | struct Camera3Stream { |
| 142 | camera3_stream_t *stream; |
| 143 | CameraStream::Type type; |
| 144 | }; |
| 145 | |
| 146 | std::vector<Camera3Stream> streams; |
| 147 | StreamConfiguration config; |
| 148 | }; |
| 149 | |
Hirokazu Honda | 26d90af | 2020-12-11 09:53:36 +0000 | [diff] [blame] | 150 | /* |
| 151 | * Reorder the configurations so that libcamera::Camera can accept them as much |
| 152 | * as possible. The sort rule is as follows. |
| 153 | * 1.) The configuration for NV12 request whose resolution is the largest. |
| 154 | * 2.) The configuration for JPEG request. |
| 155 | * 3.) Others. Larger resolutions and different formats are put earlier. |
| 156 | */ |
| 157 | void sortCamera3StreamConfigs(std::vector<Camera3StreamConfig> &unsortedConfigs, |
| 158 | const camera3_stream_t *jpegStream) |
| 159 | { |
| 160 | const Camera3StreamConfig *jpegConfig = nullptr; |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 161 | |
Hirokazu Honda | 26d90af | 2020-12-11 09:53:36 +0000 | [diff] [blame] | 162 | std::map<PixelFormat, std::vector<const Camera3StreamConfig *>> formatToConfigs; |
| 163 | for (const auto &streamConfig : unsortedConfigs) { |
| 164 | if (jpegStream && !jpegConfig) { |
| 165 | const auto &streams = streamConfig.streams; |
| 166 | if (std::find_if(streams.begin(), streams.end(), |
| 167 | [jpegStream](const auto &stream) { |
| 168 | return stream.stream == jpegStream; |
| 169 | }) != streams.end()) { |
| 170 | jpegConfig = &streamConfig; |
| 171 | continue; |
| 172 | } |
| 173 | } |
| 174 | formatToConfigs[streamConfig.config.pixelFormat].push_back(&streamConfig); |
| 175 | } |
| 176 | |
| 177 | if (jpegStream && !jpegConfig) |
| 178 | LOG(HAL, Fatal) << "No Camera3StreamConfig is found for JPEG"; |
| 179 | |
| 180 | for (auto &fmt : formatToConfigs) { |
| 181 | auto &streamConfigs = fmt.second; |
| 182 | |
| 183 | /* Sorted by resolution. Smaller is put first. */ |
| 184 | std::sort(streamConfigs.begin(), streamConfigs.end(), |
| 185 | [](const auto *streamConfigA, const auto *streamConfigB) { |
| 186 | const Size &sizeA = streamConfigA->config.size; |
| 187 | const Size &sizeB = streamConfigB->config.size; |
| 188 | return sizeA < sizeB; |
| 189 | }); |
| 190 | } |
| 191 | |
| 192 | std::vector<Camera3StreamConfig> sortedConfigs; |
| 193 | sortedConfigs.reserve(unsortedConfigs.size()); |
| 194 | |
| 195 | /* |
| 196 | * NV12 is the most prioritized format. Put the configuration with NV12 |
| 197 | * and the largest resolution first. |
| 198 | */ |
| 199 | const auto nv12It = formatToConfigs.find(formats::NV12); |
| 200 | if (nv12It != formatToConfigs.end()) { |
| 201 | auto &nv12Configs = nv12It->second; |
Laurent Pinchart | bd4894d | 2020-12-12 05:22:31 +0200 | [diff] [blame] | 202 | const Camera3StreamConfig *nv12Largest = nv12Configs.back(); |
Hirokazu Honda | 26d90af | 2020-12-11 09:53:36 +0000 | [diff] [blame] | 203 | |
| 204 | /* |
| 205 | * If JPEG will be created from NV12 and the size is larger than |
| 206 | * the largest NV12 configurations, then put the NV12 |
| 207 | * configuration for JPEG first. |
| 208 | */ |
| 209 | if (jpegConfig && jpegConfig->config.pixelFormat == formats::NV12) { |
| 210 | const Size &nv12SizeForJpeg = jpegConfig->config.size; |
| 211 | const Size &nv12LargestSize = nv12Largest->config.size; |
| 212 | |
| 213 | if (nv12LargestSize < nv12SizeForJpeg) { |
| 214 | LOG(HAL, Debug) << "Insert " << jpegConfig->config.toString(); |
| 215 | sortedConfigs.push_back(std::move(*jpegConfig)); |
| 216 | jpegConfig = nullptr; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | LOG(HAL, Debug) << "Insert " << nv12Largest->config.toString(); |
| 221 | sortedConfigs.push_back(*nv12Largest); |
| 222 | nv12Configs.pop_back(); |
| 223 | |
| 224 | if (nv12Configs.empty()) |
| 225 | formatToConfigs.erase(nv12It); |
| 226 | } |
| 227 | |
| 228 | /* If the configuration for JPEG is there, then put it. */ |
| 229 | if (jpegConfig) { |
| 230 | LOG(HAL, Debug) << "Insert " << jpegConfig->config.toString(); |
| 231 | sortedConfigs.push_back(std::move(*jpegConfig)); |
| 232 | jpegConfig = nullptr; |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | * Put configurations with different formats and larger resolutions |
| 237 | * earlier. |
| 238 | */ |
| 239 | while (!formatToConfigs.empty()) { |
| 240 | for (auto it = formatToConfigs.begin(); it != formatToConfigs.end();) { |
| 241 | auto &configs = it->second; |
| 242 | LOG(HAL, Debug) << "Insert " << configs.back()->config.toString(); |
| 243 | sortedConfigs.push_back(*configs.back()); |
| 244 | configs.pop_back(); |
| 245 | |
| 246 | if (configs.empty()) |
| 247 | it = formatToConfigs.erase(it); |
| 248 | else |
| 249 | it++; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | ASSERT(sortedConfigs.size() == unsortedConfigs.size()); |
| 254 | |
| 255 | unsortedConfigs = sortedConfigs; |
| 256 | } |
| 257 | |
| 258 | } /* namespace */ |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 259 | |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 260 | MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, |
| 261 | int flags) |
| 262 | { |
| 263 | maps_.reserve(camera3buffer->numFds); |
| 264 | error_ = 0; |
| 265 | |
| 266 | for (int i = 0; i < camera3buffer->numFds; i++) { |
| 267 | if (camera3buffer->data[i] == -1) |
| 268 | continue; |
| 269 | |
| 270 | off_t length = lseek(camera3buffer->data[i], 0, SEEK_END); |
| 271 | if (length < 0) { |
| 272 | error_ = -errno; |
| 273 | LOG(HAL, Error) << "Failed to query plane length"; |
| 274 | break; |
| 275 | } |
| 276 | |
| 277 | void *address = mmap(nullptr, length, flags, MAP_SHARED, |
| 278 | camera3buffer->data[i], 0); |
| 279 | if (address == MAP_FAILED) { |
| 280 | error_ = -errno; |
| 281 | LOG(HAL, Error) << "Failed to mmap plane"; |
| 282 | break; |
| 283 | } |
| 284 | |
| 285 | maps_.emplace_back(static_cast<uint8_t *>(address), |
| 286 | static_cast<size_t>(length)); |
| 287 | } |
| 288 | } |
| 289 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 290 | /* |
| 291 | * \struct Camera3RequestDescriptor |
| 292 | * |
| 293 | * A utility structure that groups information about a capture request to be |
| 294 | * later re-used at request complete time to notify the framework. |
| 295 | */ |
| 296 | |
| 297 | CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor( |
Jacopo Mondi | dd1cd53 | 2021-01-21 10:51:05 +0100 | [diff] [blame] | 298 | Camera *camera, const camera3_capture_request_t *camera3Request) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 299 | { |
Jacopo Mondi | dd1cd53 | 2021-01-21 10:51:05 +0100 | [diff] [blame] | 300 | frameNumber_ = camera3Request->frame_number; |
| 301 | |
Jacopo Mondi | 4b18b82 | 2021-01-21 11:10:08 +0100 | [diff] [blame^] | 302 | /* Copy the camera3 request stream information for later access. */ |
Jacopo Mondi | dd1cd53 | 2021-01-21 10:51:05 +0100 | [diff] [blame] | 303 | numBuffers_ = camera3Request->num_output_buffers; |
| 304 | buffers_ = new camera3_stream_buffer_t[numBuffers_]; |
Jacopo Mondi | 4b18b82 | 2021-01-21 11:10:08 +0100 | [diff] [blame^] | 305 | for (unsigned int i = 0; i < numBuffers_; ++i) |
| 306 | buffers_[i] = camera3Request->output_buffers[i]; |
Jacopo Mondi | 4b1aa21 | 2020-10-06 17:56:50 +0200 | [diff] [blame] | 307 | |
| 308 | /* |
| 309 | * FrameBuffer instances created by wrapping a camera3 provided dmabuf |
| 310 | * are emplaced in this vector of unique_ptr<> for lifetime management. |
| 311 | */ |
Jacopo Mondi | dd1cd53 | 2021-01-21 10:51:05 +0100 | [diff] [blame] | 312 | frameBuffers_.reserve(numBuffers_); |
Jacopo Mondi | 4b1aa21 | 2020-10-06 17:56:50 +0200 | [diff] [blame] | 313 | |
| 314 | /* |
| 315 | * Create the libcamera::Request unique_ptr<> to tie its lifetime |
| 316 | * to the descriptor's one. Set the descriptor's address as the |
| 317 | * request's cookie to retrieve it at completion time. |
| 318 | */ |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 319 | request_ = std::make_unique<CaptureRequest>(camera, |
| 320 | reinterpret_cast<uint64_t>(this)); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor() |
| 324 | { |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 325 | delete[] buffers_; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /* |
| 329 | * \class CameraDevice |
| 330 | * |
| 331 | * The CameraDevice class wraps a libcamera::Camera instance, and implements |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 332 | * the camera3_device_t interface, bridging calls received from the Android |
| 333 | * camera service to the CameraDevice. |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 334 | * |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 335 | * The class translates parameters and operations from the Camera HALv3 API to |
| 336 | * the libcamera API to provide static information for a Camera, create request |
| 337 | * templates for it, process capture requests and then deliver capture results |
| 338 | * back to the framework using the designated callbacks. |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 339 | */ |
| 340 | |
Laurent Pinchart | 0ed40d2 | 2019-08-18 01:45:01 +0300 | [diff] [blame] | 341 | CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr<Camera> &camera) |
Umang Jain | 035ee23 | 2020-08-05 12:53:49 +0000 | [diff] [blame] | 342 | : id_(id), running_(false), camera_(camera), staticMetadata_(nullptr), |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 343 | facing_(CAMERA_FACING_FRONT), orientation_(0) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 344 | { |
| 345 | camera_->requestCompleted.connect(this, &CameraDevice::requestComplete); |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 346 | |
| 347 | /* |
| 348 | * \todo Determine a more accurate value for this during |
| 349 | * streamConfiguration. |
| 350 | */ |
| 351 | maxJpegBufferSize_ = 13 << 20; /* 13631488 from USB HAL */ |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | CameraDevice::~CameraDevice() |
| 355 | { |
| 356 | if (staticMetadata_) |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 357 | delete staticMetadata_; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 358 | |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 359 | for (auto &it : requestTemplates_) |
| 360 | delete it.second; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 361 | } |
| 362 | |
Umang Jain | f8e2813 | 2020-08-21 14:46:08 +0000 | [diff] [blame] | 363 | std::shared_ptr<CameraDevice> CameraDevice::create(unsigned int id, |
| 364 | const std::shared_ptr<Camera> &cam) |
| 365 | { |
| 366 | CameraDevice *camera = new CameraDevice(id, cam); |
| 367 | return std::shared_ptr<CameraDevice>(camera); |
| 368 | } |
| 369 | |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 370 | /* |
| 371 | * Initialize the camera static information. |
| 372 | * This method is called before the camera device is opened. |
| 373 | */ |
| 374 | int CameraDevice::initialize() |
| 375 | { |
| 376 | /* Initialize orientation and facing side of the camera. */ |
| 377 | const ControlList &properties = camera_->properties(); |
| 378 | |
| 379 | if (properties.contains(properties::Location)) { |
| 380 | int32_t location = properties.get(properties::Location); |
| 381 | switch (location) { |
| 382 | case properties::CameraLocationFront: |
| 383 | facing_ = CAMERA_FACING_FRONT; |
| 384 | break; |
| 385 | case properties::CameraLocationBack: |
| 386 | facing_ = CAMERA_FACING_BACK; |
| 387 | break; |
| 388 | case properties::CameraLocationExternal: |
| 389 | facing_ = CAMERA_FACING_EXTERNAL; |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | /* |
Umang Jain | e917655 | 2020-09-09 16:17:54 +0530 | [diff] [blame] | 395 | * The Android orientation metadata specifies its rotation correction |
| 396 | * value in clockwise direction whereas libcamera specifies the |
| 397 | * rotation property in anticlockwise direction. Read the libcamera's |
| 398 | * rotation property (anticlockwise) and compute the corresponding |
| 399 | * value for clockwise direction as required by the Android orientation |
| 400 | * metadata. |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 401 | */ |
Umang Jain | e917655 | 2020-09-09 16:17:54 +0530 | [diff] [blame] | 402 | if (properties.contains(properties::Rotation)) { |
| 403 | int rotation = properties.get(properties::Rotation); |
| 404 | orientation_ = (360 - rotation) % 360; |
| 405 | } |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 406 | |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 407 | int ret = camera_->acquire(); |
| 408 | if (ret) { |
| 409 | LOG(HAL, Error) << "Failed to temporarily acquire the camera"; |
| 410 | return ret; |
| 411 | } |
| 412 | |
| 413 | ret = initializeStreamConfigurations(); |
| 414 | camera_->release(); |
| 415 | return ret; |
| 416 | } |
| 417 | |
Jacopo Mondi | bfee631 | 2020-09-01 17:42:13 +0200 | [diff] [blame] | 418 | std::vector<Size> CameraDevice::getYUVResolutions(CameraConfiguration *cameraConfig, |
| 419 | const PixelFormat &pixelFormat, |
| 420 | const std::vector<Size> &resolutions) |
| 421 | { |
| 422 | std::vector<Size> supportedResolutions; |
| 423 | |
| 424 | StreamConfiguration &cfg = cameraConfig->at(0); |
| 425 | for (const Size &res : resolutions) { |
| 426 | cfg.pixelFormat = pixelFormat; |
| 427 | cfg.size = res; |
| 428 | |
| 429 | CameraConfiguration::Status status = cameraConfig->validate(); |
| 430 | if (status != CameraConfiguration::Valid) { |
| 431 | LOG(HAL, Debug) << cfg.toString() << " not supported"; |
| 432 | continue; |
| 433 | } |
| 434 | |
| 435 | LOG(HAL, Debug) << cfg.toString() << " supported"; |
| 436 | |
| 437 | supportedResolutions.push_back(res); |
| 438 | } |
| 439 | |
| 440 | return supportedResolutions; |
| 441 | } |
| 442 | |
Jacopo Mondi | 4961033 | 2020-09-01 18:11:34 +0200 | [diff] [blame] | 443 | std::vector<Size> CameraDevice::getRawResolutions(const libcamera::PixelFormat &pixelFormat) |
| 444 | { |
| 445 | std::unique_ptr<CameraConfiguration> cameraConfig = |
Niklas Söderlund | dbe8d27 | 2020-05-26 15:04:47 +0200 | [diff] [blame] | 446 | camera_->generateConfiguration({ StreamRole::Raw }); |
Jacopo Mondi | 4961033 | 2020-09-01 18:11:34 +0200 | [diff] [blame] | 447 | StreamConfiguration &cfg = cameraConfig->at(0); |
| 448 | const StreamFormats &formats = cfg.formats(); |
| 449 | std::vector<Size> supportedResolutions = formats.sizes(pixelFormat); |
| 450 | |
| 451 | return supportedResolutions; |
| 452 | } |
| 453 | |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 454 | /* |
| 455 | * Initialize the format conversion map to translate from Android format |
| 456 | * identifier to libcamera pixel formats and fill in the list of supported |
| 457 | * stream configurations to be reported to the Android camera framework through |
| 458 | * the static stream configuration metadata. |
| 459 | */ |
| 460 | int CameraDevice::initializeStreamConfigurations() |
| 461 | { |
| 462 | /* |
| 463 | * Get the maximum output resolutions |
| 464 | * \todo Get this from the camera properties once defined |
| 465 | */ |
| 466 | std::unique_ptr<CameraConfiguration> cameraConfig = |
| 467 | camera_->generateConfiguration({ StillCapture }); |
| 468 | if (!cameraConfig) { |
| 469 | LOG(HAL, Error) << "Failed to get maximum resolution"; |
| 470 | return -EINVAL; |
| 471 | } |
| 472 | StreamConfiguration &cfg = cameraConfig->at(0); |
| 473 | |
| 474 | /* |
| 475 | * \todo JPEG - Adjust the maximum available resolution by taking the |
| 476 | * JPEG encoder requirements into account (alignment and aspect ratio). |
| 477 | */ |
| 478 | const Size maxRes = cfg.size; |
| 479 | LOG(HAL, Debug) << "Maximum supported resolution: " << maxRes.toString(); |
| 480 | |
| 481 | /* |
| 482 | * Build the list of supported image resolutions. |
| 483 | * |
| 484 | * The resolutions listed in camera3Resolution are mandatory to be |
| 485 | * supported, up to the camera maximum resolution. |
| 486 | * |
| 487 | * Augment the list by adding resolutions calculated from the camera |
| 488 | * maximum one. |
| 489 | */ |
| 490 | std::vector<Size> cameraResolutions; |
| 491 | std::copy_if(camera3Resolutions.begin(), camera3Resolutions.end(), |
| 492 | std::back_inserter(cameraResolutions), |
| 493 | [&](const Size &res) { return res < maxRes; }); |
| 494 | |
| 495 | /* |
| 496 | * The Camera3 specification suggests adding 1/2 and 1/4 of the maximum |
| 497 | * resolution. |
| 498 | */ |
| 499 | for (unsigned int divider = 2;; divider <<= 1) { |
| 500 | Size derivedSize{ |
| 501 | maxRes.width / divider, |
| 502 | maxRes.height / divider, |
| 503 | }; |
| 504 | |
| 505 | if (derivedSize.width < 320 || |
| 506 | derivedSize.height < 240) |
| 507 | break; |
| 508 | |
| 509 | cameraResolutions.push_back(derivedSize); |
| 510 | } |
| 511 | cameraResolutions.push_back(maxRes); |
| 512 | |
| 513 | /* Remove duplicated entries from the list of supported resolutions. */ |
| 514 | std::sort(cameraResolutions.begin(), cameraResolutions.end()); |
| 515 | auto last = std::unique(cameraResolutions.begin(), cameraResolutions.end()); |
| 516 | cameraResolutions.erase(last, cameraResolutions.end()); |
| 517 | |
| 518 | /* |
| 519 | * Build the list of supported camera formats. |
| 520 | * |
| 521 | * To each Android format a list of compatible libcamera formats is |
| 522 | * associated. The first libcamera format that tests successful is added |
| 523 | * to the format translation map used when configuring the streams. |
| 524 | * It is then tested against the list of supported camera resolutions to |
| 525 | * build the stream configuration map reported through the camera static |
| 526 | * metadata. |
| 527 | */ |
| 528 | for (const auto &format : camera3FormatsMap) { |
| 529 | int androidFormat = format.first; |
| 530 | const Camera3Format &camera3Format = format.second; |
| 531 | const std::vector<PixelFormat> &libcameraFormats = |
| 532 | camera3Format.libcameraFormats; |
| 533 | |
Jacopo Mondi | af264ec | 2020-09-01 15:40:49 +0200 | [diff] [blame] | 534 | LOG(HAL, Debug) << "Trying to map Android format " |
| 535 | << camera3Format.name; |
| 536 | |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 537 | /* |
Jacopo Mondi | 843565c | 2020-09-01 15:34:13 +0200 | [diff] [blame] | 538 | * JPEG is always supported, either produced directly by the |
| 539 | * camera, or encoded in the HAL. |
| 540 | */ |
| 541 | if (androidFormat == HAL_PIXEL_FORMAT_BLOB) { |
| 542 | formatsMap_[androidFormat] = formats::MJPEG; |
Jacopo Mondi | af264ec | 2020-09-01 15:40:49 +0200 | [diff] [blame] | 543 | LOG(HAL, Debug) << "Mapped Android format " |
| 544 | << camera3Format.name << " to " |
| 545 | << formats::MJPEG.toString() |
| 546 | << " (fixed mapping)"; |
Jacopo Mondi | 843565c | 2020-09-01 15:34:13 +0200 | [diff] [blame] | 547 | continue; |
| 548 | } |
| 549 | |
| 550 | /* |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 551 | * Test the libcamera formats that can produce images |
| 552 | * compatible with the format defined by Android. |
| 553 | */ |
| 554 | PixelFormat mappedFormat; |
| 555 | for (const PixelFormat &pixelFormat : libcameraFormats) { |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 556 | |
Jacopo Mondi | af264ec | 2020-09-01 15:40:49 +0200 | [diff] [blame] | 557 | LOG(HAL, Debug) << "Testing " << pixelFormat.toString(); |
| 558 | |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 559 | /* |
| 560 | * The stream configuration size can be adjusted, |
| 561 | * not the pixel format. |
| 562 | * |
| 563 | * \todo This could be simplified once all pipeline |
| 564 | * handlers will report the StreamFormats list of |
| 565 | * supported formats. |
| 566 | */ |
| 567 | cfg.pixelFormat = pixelFormat; |
| 568 | |
| 569 | CameraConfiguration::Status status = cameraConfig->validate(); |
| 570 | if (status != CameraConfiguration::Invalid && |
| 571 | cfg.pixelFormat == pixelFormat) { |
| 572 | mappedFormat = pixelFormat; |
| 573 | break; |
| 574 | } |
| 575 | } |
Jacopo Mondi | 3533fd4 | 2020-09-01 15:31:56 +0200 | [diff] [blame] | 576 | |
| 577 | if (!mappedFormat.isValid()) { |
| 578 | /* If the format is not mandatory, skip it. */ |
| 579 | if (!camera3Format.mandatory) |
| 580 | continue; |
| 581 | |
| 582 | LOG(HAL, Error) |
| 583 | << "Failed to map mandatory Android format " |
| 584 | << camera3Format.name << " (" |
| 585 | << utils::hex(androidFormat) << "): aborting"; |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 586 | return -EINVAL; |
| 587 | } |
| 588 | |
| 589 | /* |
| 590 | * Record the mapping and then proceed to generate the |
| 591 | * stream configurations map, by testing the image resolutions. |
| 592 | */ |
| 593 | formatsMap_[androidFormat] = mappedFormat; |
Jacopo Mondi | af264ec | 2020-09-01 15:40:49 +0200 | [diff] [blame] | 594 | LOG(HAL, Debug) << "Mapped Android format " |
| 595 | << camera3Format.name << " to " |
| 596 | << mappedFormat.toString(); |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 597 | |
Jacopo Mondi | 4961033 | 2020-09-01 18:11:34 +0200 | [diff] [blame] | 598 | std::vector<Size> resolutions; |
| 599 | const PixelFormatInfo &info = PixelFormatInfo::info(mappedFormat); |
| 600 | if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) |
| 601 | resolutions = getRawResolutions(mappedFormat); |
| 602 | else |
| 603 | resolutions = getYUVResolutions(cameraConfig.get(), |
| 604 | mappedFormat, |
| 605 | cameraResolutions); |
| 606 | |
Jacopo Mondi | bfee631 | 2020-09-01 17:42:13 +0200 | [diff] [blame] | 607 | for (const Size &res : resolutions) { |
Niklas Söderlund | 142a9ee | 2020-07-23 18:32:23 +0200 | [diff] [blame] | 608 | streamConfigurations_.push_back({ res, androidFormat }); |
Jacopo Mondi | 843565c | 2020-09-01 15:34:13 +0200 | [diff] [blame] | 609 | |
| 610 | /* |
| 611 | * If the format is HAL_PIXEL_FORMAT_YCbCr_420_888 |
| 612 | * from which JPEG is produced, add an entry for |
| 613 | * the JPEG stream. |
| 614 | * |
| 615 | * \todo Wire the JPEG encoder to query the supported |
| 616 | * sizes provided a list of formats it can encode. |
| 617 | * |
| 618 | * \todo Support JPEG streams produced by the Camera |
| 619 | * natively. |
| 620 | */ |
| 621 | if (androidFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) |
| 622 | streamConfigurations_.push_back( |
| 623 | { res, HAL_PIXEL_FORMAT_BLOB }); |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | |
| 627 | LOG(HAL, Debug) << "Collected stream configuration map: "; |
| 628 | for (const auto &entry : streamConfigurations_) |
| 629 | LOG(HAL, Debug) << "{ " << entry.resolution.toString() << " - " |
Niklas Söderlund | 142a9ee | 2020-07-23 18:32:23 +0200 | [diff] [blame] | 630 | << utils::hex(entry.androidFormat) << " }"; |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 631 | |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | * Open a camera device. The static information on the camera shall have been |
| 637 | * initialized with a call to CameraDevice::initialize(). |
| 638 | */ |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 639 | int CameraDevice::open(const hw_module_t *hardwareModule) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 640 | { |
| 641 | int ret = camera_->acquire(); |
| 642 | if (ret) { |
| 643 | LOG(HAL, Error) << "Failed to acquire the camera"; |
| 644 | return ret; |
| 645 | } |
| 646 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 647 | /* Initialize the hw_device_t in the instance camera3_module_t. */ |
| 648 | camera3Device_.common.tag = HARDWARE_DEVICE_TAG; |
| 649 | camera3Device_.common.version = CAMERA_DEVICE_API_VERSION_3_3; |
| 650 | camera3Device_.common.module = (hw_module_t *)hardwareModule; |
| 651 | camera3Device_.common.close = hal_dev_close; |
| 652 | |
| 653 | /* |
| 654 | * The camera device operations. These actually implement |
| 655 | * the Android Camera HALv3 interface. |
| 656 | */ |
| 657 | camera3Device_.ops = &hal_dev_ops; |
| 658 | camera3Device_.priv = this; |
| 659 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 660 | return 0; |
| 661 | } |
| 662 | |
| 663 | void CameraDevice::close() |
| 664 | { |
Jacopo Mondi | 6c4999e | 2020-10-03 16:06:34 +0200 | [diff] [blame] | 665 | streams_.clear(); |
| 666 | |
Jacopo Mondi | 4b1aa21 | 2020-10-06 17:56:50 +0200 | [diff] [blame] | 667 | worker_.stop(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 668 | camera_->stop(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 669 | camera_->release(); |
| 670 | |
| 671 | running_ = false; |
| 672 | } |
| 673 | |
| 674 | void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks) |
| 675 | { |
| 676 | callbacks_ = callbacks; |
| 677 | } |
| 678 | |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 679 | std::tuple<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize() |
| 680 | { |
| 681 | /* |
| 682 | * \todo Keep this in sync with the actual number of entries. |
Jacopo Mondi | eec6c54 | 2020-12-09 18:16:11 +0100 | [diff] [blame] | 683 | * Currently: 53 entries, 714 bytes of static metadata |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 684 | */ |
Jacopo Mondi | eec6c54 | 2020-12-09 18:16:11 +0100 | [diff] [blame] | 685 | uint32_t numEntries = 53; |
| 686 | uint32_t byteSize = 714; |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 687 | |
| 688 | /* |
| 689 | * Calculate space occupation in bytes for dynamically built metadata |
| 690 | * entries. |
| 691 | * |
| 692 | * Each stream configuration entry requires 52 bytes: |
| 693 | * 4 32bits integers for ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 694 | * 4 64bits integers for ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS |
| 695 | */ |
Niklas Söderlund | 3530614 | 2020-07-23 18:25:04 +0200 | [diff] [blame] | 696 | byteSize += streamConfigurations_.size() * 48; |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 697 | |
Laurent Pinchart | 7a88b21 | 2020-06-10 00:07:59 +0300 | [diff] [blame] | 698 | return std::make_tuple(numEntries, byteSize); |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 699 | } |
| 700 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 701 | /* |
| 702 | * Return static information for the camera. |
| 703 | */ |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 704 | const camera_metadata_t *CameraDevice::getStaticMetadata() |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 705 | { |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 706 | if (staticMetadata_) |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 707 | return staticMetadata_->get(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 708 | |
| 709 | /* |
| 710 | * The here reported metadata are enough to implement a basic capture |
| 711 | * example application, but a real camera implementation will require |
| 712 | * more. |
| 713 | */ |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 714 | uint32_t numEntries; |
| 715 | uint32_t byteSize; |
| 716 | std::tie(numEntries, byteSize) = calculateStaticMetadataSize(); |
| 717 | staticMetadata_ = new CameraMetadata(numEntries, byteSize); |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 718 | if (!staticMetadata_->isValid()) { |
| 719 | LOG(HAL, Error) << "Failed to allocate static metadata"; |
| 720 | delete staticMetadata_; |
| 721 | staticMetadata_ = nullptr; |
| 722 | return nullptr; |
| 723 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 724 | |
Jacopo Mondi | 5d91c8d | 2020-09-23 09:41:52 +0200 | [diff] [blame] | 725 | const ControlInfoMap &controlsInfo = camera_->controls(); |
Jacopo Mondi | 1889cdc | 2020-11-06 16:08:16 +0100 | [diff] [blame] | 726 | const ControlList &properties = camera_->properties(); |
Jacopo Mondi | 5d91c8d | 2020-09-23 09:41:52 +0200 | [diff] [blame] | 727 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 728 | /* Color correction static metadata. */ |
Jacopo Mondi | 6333686 | 2020-10-08 16:18:26 +0200 | [diff] [blame] | 729 | { |
Jacopo Mondi | c268e4f | 2020-12-01 15:42:15 +0100 | [diff] [blame] | 730 | std::vector<uint8_t> data; |
| 731 | data.reserve(3); |
Jacopo Mondi | 6333686 | 2020-10-08 16:18:26 +0200 | [diff] [blame] | 732 | const auto &infoMap = controlsInfo.find(&controls::draft::ColorCorrectionAberrationMode); |
| 733 | if (infoMap != controlsInfo.end()) { |
| 734 | for (const auto &value : infoMap->second.values()) |
| 735 | data.push_back(value.get<int32_t>()); |
| 736 | } else { |
| 737 | data.push_back(ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF); |
| 738 | } |
| 739 | staticMetadata_->addEntry(ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, |
| 740 | data.data(), data.size()); |
| 741 | } |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 742 | |
| 743 | /* Control static metadata. */ |
| 744 | std::vector<uint8_t> aeAvailableAntiBandingModes = { |
| 745 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF, |
| 746 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_50HZ, |
| 747 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_60HZ, |
| 748 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO, |
| 749 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 750 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, |
| 751 | aeAvailableAntiBandingModes.data(), |
| 752 | aeAvailableAntiBandingModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 753 | |
| 754 | std::vector<uint8_t> aeAvailableModes = { |
| 755 | ANDROID_CONTROL_AE_MODE_ON, |
| 756 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 757 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_MODES, |
| 758 | aeAvailableModes.data(), |
| 759 | aeAvailableModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 760 | |
| 761 | std::vector<int32_t> availableAeFpsTarget = { |
| 762 | 15, 30, |
| 763 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 764 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, |
| 765 | availableAeFpsTarget.data(), |
| 766 | availableAeFpsTarget.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 767 | |
| 768 | std::vector<int32_t> aeCompensationRange = { |
| 769 | 0, 0, |
| 770 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 771 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_COMPENSATION_RANGE, |
| 772 | aeCompensationRange.data(), |
| 773 | aeCompensationRange.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 774 | |
| 775 | const camera_metadata_rational_t aeCompensationStep[] = { |
| 776 | { 0, 1 } |
| 777 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 778 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_COMPENSATION_STEP, |
| 779 | aeCompensationStep, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 780 | |
| 781 | std::vector<uint8_t> availableAfModes = { |
| 782 | ANDROID_CONTROL_AF_MODE_OFF, |
| 783 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 784 | staticMetadata_->addEntry(ANDROID_CONTROL_AF_AVAILABLE_MODES, |
| 785 | availableAfModes.data(), |
| 786 | availableAfModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 787 | |
| 788 | std::vector<uint8_t> availableEffects = { |
| 789 | ANDROID_CONTROL_EFFECT_MODE_OFF, |
| 790 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 791 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_EFFECTS, |
| 792 | availableEffects.data(), |
| 793 | availableEffects.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 794 | |
| 795 | std::vector<uint8_t> availableSceneModes = { |
| 796 | ANDROID_CONTROL_SCENE_MODE_DISABLED, |
| 797 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 798 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_SCENE_MODES, |
| 799 | availableSceneModes.data(), |
| 800 | availableSceneModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 801 | |
| 802 | std::vector<uint8_t> availableStabilizationModes = { |
| 803 | ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF, |
| 804 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 805 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, |
| 806 | availableStabilizationModes.data(), |
| 807 | availableStabilizationModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 808 | |
| 809 | std::vector<uint8_t> availableAwbModes = { |
| 810 | ANDROID_CONTROL_AWB_MODE_OFF, |
| 811 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 812 | staticMetadata_->addEntry(ANDROID_CONTROL_AWB_AVAILABLE_MODES, |
| 813 | availableAwbModes.data(), |
| 814 | availableAwbModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 815 | |
| 816 | std::vector<int32_t> availableMaxRegions = { |
| 817 | 0, 0, 0, |
| 818 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 819 | staticMetadata_->addEntry(ANDROID_CONTROL_MAX_REGIONS, |
| 820 | availableMaxRegions.data(), |
| 821 | availableMaxRegions.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 822 | |
| 823 | std::vector<uint8_t> sceneModesOverride = { |
| 824 | ANDROID_CONTROL_AE_MODE_ON, |
| 825 | ANDROID_CONTROL_AWB_MODE_AUTO, |
| 826 | ANDROID_CONTROL_AF_MODE_AUTO, |
| 827 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 828 | staticMetadata_->addEntry(ANDROID_CONTROL_SCENE_MODE_OVERRIDES, |
| 829 | sceneModesOverride.data(), |
| 830 | sceneModesOverride.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 831 | |
| 832 | uint8_t aeLockAvailable = ANDROID_CONTROL_AE_LOCK_AVAILABLE_FALSE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 833 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_LOCK_AVAILABLE, |
| 834 | &aeLockAvailable, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 835 | |
| 836 | uint8_t awbLockAvailable = ANDROID_CONTROL_AWB_LOCK_AVAILABLE_FALSE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 837 | staticMetadata_->addEntry(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, |
| 838 | &awbLockAvailable, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 839 | |
| 840 | char availableControlModes = ANDROID_CONTROL_MODE_AUTO; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 841 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_MODES, |
| 842 | &availableControlModes, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 843 | |
| 844 | /* JPEG static metadata. */ |
| 845 | std::vector<int32_t> availableThumbnailSizes = { |
| 846 | 0, 0, |
| 847 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 848 | staticMetadata_->addEntry(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
| 849 | availableThumbnailSizes.data(), |
| 850 | availableThumbnailSizes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 851 | |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 852 | /* |
| 853 | * \todo Calculate the maximum JPEG buffer size by asking the encoder |
| 854 | * giving the maximum frame size required. |
| 855 | */ |
| 856 | staticMetadata_->addEntry(ANDROID_JPEG_MAX_SIZE, &maxJpegBufferSize_, 1); |
| 857 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 858 | /* Sensor static metadata. */ |
Jacopo Mondi | cda41ff | 2020-12-30 17:18:51 +0100 | [diff] [blame] | 859 | { |
Jacopo Mondi | 1889cdc | 2020-11-06 16:08:16 +0100 | [diff] [blame] | 860 | const Size &size = |
Jacopo Mondi | 0ed0532 | 2020-12-23 18:34:34 +0100 | [diff] [blame] | 861 | properties.get(properties::PixelArraySize); |
Jacopo Mondi | 1889cdc | 2020-11-06 16:08:16 +0100 | [diff] [blame] | 862 | std::vector<int32_t> data{ |
| 863 | static_cast<int32_t>(size.width), |
| 864 | static_cast<int32_t>(size.height), |
| 865 | }; |
| 866 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, |
| 867 | data.data(), data.size()); |
| 868 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 869 | |
Jacopo Mondi | cda41ff | 2020-12-30 17:18:51 +0100 | [diff] [blame] | 870 | { |
Jacopo Mondi | 1889cdc | 2020-11-06 16:08:16 +0100 | [diff] [blame] | 871 | const Span<const Rectangle> &rects = |
Jacopo Mondi | 0ed0532 | 2020-12-23 18:34:34 +0100 | [diff] [blame] | 872 | properties.get(properties::PixelArrayActiveAreas); |
Jacopo Mondi | 1889cdc | 2020-11-06 16:08:16 +0100 | [diff] [blame] | 873 | std::vector<int32_t> data{ |
| 874 | static_cast<int32_t>(rects[0].x), |
| 875 | static_cast<int32_t>(rects[0].y), |
| 876 | static_cast<int32_t>(rects[0].width), |
| 877 | static_cast<int32_t>(rects[0].height), |
| 878 | }; |
| 879 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, |
| 880 | data.data(), data.size()); |
| 881 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 882 | |
| 883 | int32_t sensitivityRange[] = { |
| 884 | 32, 2400, |
| 885 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 886 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_SENSITIVITY_RANGE, |
| 887 | &sensitivityRange, 2); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 888 | |
Jacopo Mondi | cb35ed2 | 2020-12-18 16:28:43 +0100 | [diff] [blame] | 889 | /* Report the color filter arrangement if the camera reports it. */ |
| 890 | if (properties.contains(properties::draft::ColorFilterArrangement)) { |
| 891 | uint8_t filterArr = properties.get(properties::draft::ColorFilterArrangement); |
| 892 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, |
| 893 | &filterArr, 1); |
| 894 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 895 | |
| 896 | int64_t exposureTimeRange[] = { |
| 897 | 100000, 200000000, |
| 898 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 899 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE, |
| 900 | &exposureTimeRange, 2); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 901 | |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 902 | staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION, &orientation_, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 903 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 904 | std::vector<int32_t> testPatterModes = { |
| 905 | ANDROID_SENSOR_TEST_PATTERN_MODE_OFF, |
| 906 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 907 | staticMetadata_->addEntry(ANDROID_SENSOR_AVAILABLE_TEST_PATTERN_MODES, |
| 908 | testPatterModes.data(), |
| 909 | testPatterModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 910 | |
| 911 | std::vector<float> physicalSize = { |
| 912 | 2592, 1944, |
| 913 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 914 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
| 915 | physicalSize.data(), |
| 916 | physicalSize.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 917 | |
| 918 | uint8_t timestampSource = ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 919 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, |
| 920 | ×tampSource, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 921 | |
| 922 | /* Statistics static metadata. */ |
| 923 | uint8_t faceDetectMode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 924 | staticMetadata_->addEntry(ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, |
| 925 | &faceDetectMode, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 926 | |
| 927 | int32_t maxFaceCount = 0; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 928 | staticMetadata_->addEntry(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, |
| 929 | &maxFaceCount, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 930 | |
Jacopo Mondi | 2c61850 | 2020-10-08 16:47:36 +0200 | [diff] [blame] | 931 | { |
Jacopo Mondi | c268e4f | 2020-12-01 15:42:15 +0100 | [diff] [blame] | 932 | std::vector<uint8_t> data; |
| 933 | data.reserve(2); |
Jacopo Mondi | 2c61850 | 2020-10-08 16:47:36 +0200 | [diff] [blame] | 934 | const auto &infoMap = controlsInfo.find(&controls::draft::LensShadingMapMode); |
| 935 | if (infoMap != controlsInfo.end()) { |
| 936 | for (const auto &value : infoMap->second.values()) |
| 937 | data.push_back(value.get<int32_t>()); |
| 938 | } else { |
| 939 | data.push_back(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF); |
| 940 | } |
| 941 | staticMetadata_->addEntry(ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES, |
| 942 | data.data(), data.size()); |
| 943 | } |
| 944 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 945 | /* Sync static metadata. */ |
| 946 | int32_t maxLatency = ANDROID_SYNC_MAX_LATENCY_UNKNOWN; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 947 | staticMetadata_->addEntry(ANDROID_SYNC_MAX_LATENCY, &maxLatency, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 948 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 949 | /* Flash static metadata. */ |
| 950 | char flashAvailable = ANDROID_FLASH_INFO_AVAILABLE_FALSE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 951 | staticMetadata_->addEntry(ANDROID_FLASH_INFO_AVAILABLE, |
| 952 | &flashAvailable, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 953 | |
| 954 | /* Lens static metadata. */ |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 955 | std::vector<float> lensApertures = { |
| 956 | 2.53 / 100, |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 957 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 958 | staticMetadata_->addEntry(ANDROID_LENS_INFO_AVAILABLE_APERTURES, |
| 959 | lensApertures.data(), |
| 960 | lensApertures.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 961 | |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 962 | uint8_t lensFacing; |
| 963 | switch (facing_) { |
| 964 | default: |
| 965 | case CAMERA_FACING_FRONT: |
| 966 | lensFacing = ANDROID_LENS_FACING_FRONT; |
| 967 | break; |
| 968 | case CAMERA_FACING_BACK: |
| 969 | lensFacing = ANDROID_LENS_FACING_BACK; |
| 970 | break; |
| 971 | case CAMERA_FACING_EXTERNAL: |
| 972 | lensFacing = ANDROID_LENS_FACING_EXTERNAL; |
| 973 | break; |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 974 | } |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 975 | staticMetadata_->addEntry(ANDROID_LENS_FACING, &lensFacing, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 976 | |
| 977 | std::vector<float> lensFocalLenghts = { |
| 978 | 1, |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 979 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 980 | staticMetadata_->addEntry(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
| 981 | lensFocalLenghts.data(), |
| 982 | lensFocalLenghts.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 983 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 984 | std::vector<uint8_t> opticalStabilizations = { |
| 985 | ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF, |
| 986 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 987 | staticMetadata_->addEntry(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, |
| 988 | opticalStabilizations.data(), |
| 989 | opticalStabilizations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 990 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 991 | float hypeFocalDistance = 0; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 992 | staticMetadata_->addEntry(ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE, |
| 993 | &hypeFocalDistance, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 994 | |
| 995 | float minFocusDistance = 0; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 996 | staticMetadata_->addEntry(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, |
| 997 | &minFocusDistance, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 998 | |
| 999 | /* Noise reduction modes. */ |
Jacopo Mondi | 0b5fecc | 2020-10-08 16:01:35 +0200 | [diff] [blame] | 1000 | { |
Jacopo Mondi | c268e4f | 2020-12-01 15:42:15 +0100 | [diff] [blame] | 1001 | std::vector<uint8_t> data; |
| 1002 | data.reserve(5); |
Jacopo Mondi | 0b5fecc | 2020-10-08 16:01:35 +0200 | [diff] [blame] | 1003 | const auto &infoMap = controlsInfo.find(&controls::draft::NoiseReductionMode); |
| 1004 | if (infoMap != controlsInfo.end()) { |
| 1005 | for (const auto &value : infoMap->second.values()) |
| 1006 | data.push_back(value.get<int32_t>()); |
| 1007 | } else { |
| 1008 | data.push_back(ANDROID_NOISE_REDUCTION_MODE_OFF); |
| 1009 | } |
| 1010 | staticMetadata_->addEntry(ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, |
| 1011 | data.data(), data.size()); |
| 1012 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1013 | |
| 1014 | /* Scaler static metadata. */ |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1015 | float maxDigitalZoom = 1; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1016 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, |
| 1017 | &maxDigitalZoom, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1018 | |
Jacopo Mondi | bde7b98 | 2020-05-25 17:18:28 +0200 | [diff] [blame] | 1019 | std::vector<uint32_t> availableStreamConfigurations; |
| 1020 | availableStreamConfigurations.reserve(streamConfigurations_.size() * 4); |
| 1021 | for (const auto &entry : streamConfigurations_) { |
Niklas Söderlund | 142a9ee | 2020-07-23 18:32:23 +0200 | [diff] [blame] | 1022 | availableStreamConfigurations.push_back(entry.androidFormat); |
Jacopo Mondi | bde7b98 | 2020-05-25 17:18:28 +0200 | [diff] [blame] | 1023 | availableStreamConfigurations.push_back(entry.resolution.width); |
| 1024 | availableStreamConfigurations.push_back(entry.resolution.height); |
| 1025 | availableStreamConfigurations.push_back( |
| 1026 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT); |
| 1027 | } |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1028 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, |
| 1029 | availableStreamConfigurations.data(), |
| 1030 | availableStreamConfigurations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1031 | |
| 1032 | std::vector<int64_t> availableStallDurations = { |
| 1033 | ANDROID_SCALER_AVAILABLE_FORMATS_BLOB, 2560, 1920, 33333333, |
| 1034 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1035 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_STALL_DURATIONS, |
| 1036 | availableStallDurations.data(), |
| 1037 | availableStallDurations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1038 | |
Jacopo Mondi | bde7b98 | 2020-05-25 17:18:28 +0200 | [diff] [blame] | 1039 | /* \todo Collect the minimum frame duration from the camera. */ |
| 1040 | std::vector<int64_t> minFrameDurations; |
| 1041 | minFrameDurations.reserve(streamConfigurations_.size() * 4); |
| 1042 | for (const auto &entry : streamConfigurations_) { |
Niklas Söderlund | 142a9ee | 2020-07-23 18:32:23 +0200 | [diff] [blame] | 1043 | minFrameDurations.push_back(entry.androidFormat); |
Jacopo Mondi | bde7b98 | 2020-05-25 17:18:28 +0200 | [diff] [blame] | 1044 | minFrameDurations.push_back(entry.resolution.width); |
| 1045 | minFrameDurations.push_back(entry.resolution.height); |
| 1046 | minFrameDurations.push_back(33333333); |
| 1047 | } |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1048 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, |
| 1049 | minFrameDurations.data(), |
| 1050 | minFrameDurations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1051 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1052 | uint8_t croppingType = ANDROID_SCALER_CROPPING_TYPE_CENTER_ONLY; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1053 | staticMetadata_->addEntry(ANDROID_SCALER_CROPPING_TYPE, &croppingType, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1054 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1055 | /* Info static metadata. */ |
| 1056 | uint8_t supportedHWLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1057 | staticMetadata_->addEntry(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, |
| 1058 | &supportedHWLevel, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1059 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1060 | /* Request static metadata. */ |
| 1061 | int32_t partialResultCount = 1; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1062 | staticMetadata_->addEntry(ANDROID_REQUEST_PARTIAL_RESULT_COUNT, |
| 1063 | &partialResultCount, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1064 | |
Jacopo Mondi | 5d91c8d | 2020-09-23 09:41:52 +0200 | [diff] [blame] | 1065 | { |
| 1066 | /* Default the value to 2 if not reported by the camera. */ |
| 1067 | uint8_t maxPipelineDepth = 2; |
| 1068 | const auto &infoMap = controlsInfo.find(&controls::draft::PipelineDepth); |
| 1069 | if (infoMap != controlsInfo.end()) |
| 1070 | maxPipelineDepth = infoMap->second.max().get<int32_t>(); |
| 1071 | staticMetadata_->addEntry(ANDROID_REQUEST_PIPELINE_MAX_DEPTH, |
| 1072 | &maxPipelineDepth, 1); |
| 1073 | } |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1074 | |
Niklas Söderlund | a2a6f95 | 2020-07-21 00:16:02 +0200 | [diff] [blame] | 1075 | /* LIMITED does not support reprocessing. */ |
| 1076 | uint32_t maxNumInputStreams = 0; |
| 1077 | staticMetadata_->addEntry(ANDROID_REQUEST_MAX_NUM_INPUT_STREAMS, |
| 1078 | &maxNumInputStreams, 1); |
| 1079 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1080 | std::vector<uint8_t> availableCapabilities = { |
| 1081 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE, |
| 1082 | }; |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame] | 1083 | |
| 1084 | /* Report if camera supports RAW. */ |
Jacopo Mondi | eec6c54 | 2020-12-09 18:16:11 +0100 | [diff] [blame] | 1085 | bool rawStreamAvailable = false; |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame] | 1086 | std::unique_ptr<CameraConfiguration> cameraConfig = |
Niklas Söderlund | dbe8d27 | 2020-05-26 15:04:47 +0200 | [diff] [blame] | 1087 | camera_->generateConfiguration({ StreamRole::Raw }); |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame] | 1088 | if (cameraConfig && !cameraConfig->empty()) { |
| 1089 | const PixelFormatInfo &info = |
| 1090 | PixelFormatInfo::info(cameraConfig->at(0).pixelFormat); |
Niklas Söderlund | 35de31e | 2020-12-31 00:11:59 +0100 | [diff] [blame] | 1091 | /* Only advertise RAW support if RAW16 is possible. */ |
| 1092 | if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW && |
| 1093 | info.bitsPerPixel == 16) { |
Jacopo Mondi | eec6c54 | 2020-12-09 18:16:11 +0100 | [diff] [blame] | 1094 | rawStreamAvailable = true; |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame] | 1095 | availableCapabilities.push_back(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_RAW); |
Jacopo Mondi | eec6c54 | 2020-12-09 18:16:11 +0100 | [diff] [blame] | 1096 | } |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame] | 1097 | } |
| 1098 | |
Jacopo Mondi | eec6c54 | 2020-12-09 18:16:11 +0100 | [diff] [blame] | 1099 | /* Number of { RAW, YUV, JPEG } supported output streams */ |
| 1100 | int32_t numOutStreams[] = { rawStreamAvailable, 2, 1 }; |
| 1101 | staticMetadata_->addEntry(ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS, |
| 1102 | &numOutStreams, 3); |
| 1103 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1104 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, |
| 1105 | availableCapabilities.data(), |
| 1106 | availableCapabilities.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1107 | |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1108 | std::vector<int32_t> availableCharacteristicsKeys = { |
| 1109 | ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, |
| 1110 | ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, |
| 1111 | ANDROID_CONTROL_AE_AVAILABLE_MODES, |
| 1112 | ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, |
| 1113 | ANDROID_CONTROL_AE_COMPENSATION_RANGE, |
| 1114 | ANDROID_CONTROL_AE_COMPENSATION_STEP, |
| 1115 | ANDROID_CONTROL_AF_AVAILABLE_MODES, |
| 1116 | ANDROID_CONTROL_AVAILABLE_EFFECTS, |
| 1117 | ANDROID_CONTROL_AVAILABLE_SCENE_MODES, |
| 1118 | ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, |
| 1119 | ANDROID_CONTROL_AWB_AVAILABLE_MODES, |
| 1120 | ANDROID_CONTROL_MAX_REGIONS, |
| 1121 | ANDROID_CONTROL_SCENE_MODE_OVERRIDES, |
| 1122 | ANDROID_CONTROL_AE_LOCK_AVAILABLE, |
| 1123 | ANDROID_CONTROL_AWB_LOCK_AVAILABLE, |
| 1124 | ANDROID_CONTROL_AVAILABLE_MODES, |
| 1125 | ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1126 | ANDROID_JPEG_MAX_SIZE, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1127 | ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, |
| 1128 | ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, |
| 1129 | ANDROID_SENSOR_INFO_SENSITIVITY_RANGE, |
| 1130 | ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, |
| 1131 | ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE, |
| 1132 | ANDROID_SENSOR_ORIENTATION, |
| 1133 | ANDROID_SENSOR_AVAILABLE_TEST_PATTERN_MODES, |
| 1134 | ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
| 1135 | ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, |
| 1136 | ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, |
| 1137 | ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, |
| 1138 | ANDROID_SYNC_MAX_LATENCY, |
| 1139 | ANDROID_FLASH_INFO_AVAILABLE, |
| 1140 | ANDROID_LENS_INFO_AVAILABLE_APERTURES, |
| 1141 | ANDROID_LENS_FACING, |
| 1142 | ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
| 1143 | ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, |
| 1144 | ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE, |
| 1145 | ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, |
| 1146 | ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, |
| 1147 | ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1148 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, |
| 1149 | ANDROID_SCALER_AVAILABLE_STALL_DURATIONS, |
| 1150 | ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, |
| 1151 | ANDROID_SCALER_CROPPING_TYPE, |
| 1152 | ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, |
| 1153 | ANDROID_REQUEST_PARTIAL_RESULT_COUNT, |
| 1154 | ANDROID_REQUEST_PIPELINE_MAX_DEPTH, |
Jacopo Mondi | eec6c54 | 2020-12-09 18:16:11 +0100 | [diff] [blame] | 1155 | ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS, |
Niklas Söderlund | a2a6f95 | 2020-07-21 00:16:02 +0200 | [diff] [blame] | 1156 | ANDROID_REQUEST_MAX_NUM_INPUT_STREAMS, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1157 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES, |
| 1158 | }; |
| 1159 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, |
| 1160 | availableCharacteristicsKeys.data(), |
| 1161 | availableCharacteristicsKeys.size()); |
| 1162 | |
| 1163 | std::vector<int32_t> availableRequestKeys = { |
| 1164 | ANDROID_CONTROL_AE_MODE, |
| 1165 | ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
| 1166 | ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
Jacopo Mondi | 09b1d0f | 2020-07-24 16:10:23 +0200 | [diff] [blame] | 1167 | ANDROID_CONTROL_AE_TARGET_FPS_RANGE, |
| 1168 | ANDROID_CONTROL_AE_ANTIBANDING_MODE, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1169 | ANDROID_CONTROL_AE_LOCK, |
| 1170 | ANDROID_CONTROL_AF_TRIGGER, |
| 1171 | ANDROID_CONTROL_AWB_MODE, |
| 1172 | ANDROID_CONTROL_AWB_LOCK, |
| 1173 | ANDROID_FLASH_MODE, |
| 1174 | ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 1175 | ANDROID_NOISE_REDUCTION_MODE, |
| 1176 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
Jacopo Mondi | 09b1d0f | 2020-07-24 16:10:23 +0200 | [diff] [blame] | 1177 | ANDROID_LENS_APERTURE, |
| 1178 | ANDROID_LENS_OPTICAL_STABILIZATION_MODE, |
| 1179 | ANDROID_CONTROL_MODE, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1180 | ANDROID_CONTROL_CAPTURE_INTENT, |
| 1181 | }; |
| 1182 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS, |
| 1183 | availableRequestKeys.data(), |
| 1184 | availableRequestKeys.size()); |
| 1185 | |
| 1186 | std::vector<int32_t> availableResultKeys = { |
| 1187 | ANDROID_CONTROL_AE_STATE, |
| 1188 | ANDROID_CONTROL_AE_LOCK, |
| 1189 | ANDROID_CONTROL_AF_STATE, |
| 1190 | ANDROID_CONTROL_AWB_STATE, |
| 1191 | ANDROID_CONTROL_AWB_LOCK, |
| 1192 | ANDROID_LENS_STATE, |
Jacopo Mondi | 3535e0c | 2020-12-09 17:51:57 +0100 | [diff] [blame] | 1193 | ANDROID_REQUEST_PIPELINE_DEPTH, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1194 | ANDROID_SCALER_CROP_REGION, |
| 1195 | ANDROID_SENSOR_TIMESTAMP, |
| 1196 | ANDROID_SENSOR_ROLLING_SHUTTER_SKEW, |
| 1197 | ANDROID_SENSOR_EXPOSURE_TIME, |
| 1198 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, |
| 1199 | ANDROID_STATISTICS_SCENE_FLICKER, |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1200 | ANDROID_JPEG_SIZE, |
| 1201 | ANDROID_JPEG_QUALITY, |
| 1202 | ANDROID_JPEG_ORIENTATION, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1203 | }; |
| 1204 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_RESULT_KEYS, |
| 1205 | availableResultKeys.data(), |
| 1206 | availableResultKeys.size()); |
| 1207 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1208 | if (!staticMetadata_->isValid()) { |
| 1209 | LOG(HAL, Error) << "Failed to construct static metadata"; |
| 1210 | delete staticMetadata_; |
| 1211 | staticMetadata_ = nullptr; |
| 1212 | return nullptr; |
| 1213 | } |
| 1214 | |
| 1215 | return staticMetadata_->get(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1216 | } |
| 1217 | |
Jacopo Mondi | 8a02d44 | 2020-07-24 15:47:50 +0200 | [diff] [blame] | 1218 | CameraMetadata *CameraDevice::requestTemplatePreview() |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1219 | { |
Jacopo Mondi | 6370347 | 2019-09-04 16:18:22 +0200 | [diff] [blame] | 1220 | /* |
| 1221 | * \todo Keep this in sync with the actual number of entries. |
Jacopo Mondi | 09b1d0f | 2020-07-24 16:10:23 +0200 | [diff] [blame] | 1222 | * Currently: 20 entries, 35 bytes |
Jacopo Mondi | 6370347 | 2019-09-04 16:18:22 +0200 | [diff] [blame] | 1223 | */ |
Jacopo Mondi | 09b1d0f | 2020-07-24 16:10:23 +0200 | [diff] [blame] | 1224 | CameraMetadata *requestTemplate = new CameraMetadata(20, 35); |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1225 | if (!requestTemplate->isValid()) { |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1226 | delete requestTemplate; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1227 | return nullptr; |
| 1228 | } |
| 1229 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1230 | uint8_t aeMode = ANDROID_CONTROL_AE_MODE_ON; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1231 | requestTemplate->addEntry(ANDROID_CONTROL_AE_MODE, |
| 1232 | &aeMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1233 | |
| 1234 | int32_t aeExposureCompensation = 0; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1235 | requestTemplate->addEntry(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
| 1236 | &aeExposureCompensation, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1237 | |
| 1238 | uint8_t aePrecaptureTrigger = ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1239 | requestTemplate->addEntry(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
| 1240 | &aePrecaptureTrigger, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1241 | |
| 1242 | uint8_t aeLock = ANDROID_CONTROL_AE_LOCK_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1243 | requestTemplate->addEntry(ANDROID_CONTROL_AE_LOCK, |
| 1244 | &aeLock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1245 | |
Jacopo Mondi | 09b1d0f | 2020-07-24 16:10:23 +0200 | [diff] [blame] | 1246 | std::vector<int32_t> aeFpsTarget = { |
| 1247 | 15, 30, |
| 1248 | }; |
| 1249 | requestTemplate->addEntry(ANDROID_CONTROL_AE_TARGET_FPS_RANGE, |
| 1250 | aeFpsTarget.data(), |
| 1251 | aeFpsTarget.size()); |
| 1252 | |
| 1253 | uint8_t aeAntibandingMode = ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO; |
| 1254 | requestTemplate->addEntry(ANDROID_CONTROL_AE_ANTIBANDING_MODE, |
| 1255 | &aeAntibandingMode, 1); |
| 1256 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1257 | uint8_t afTrigger = ANDROID_CONTROL_AF_TRIGGER_IDLE; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1258 | requestTemplate->addEntry(ANDROID_CONTROL_AF_TRIGGER, |
| 1259 | &afTrigger, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1260 | |
| 1261 | uint8_t awbMode = ANDROID_CONTROL_AWB_MODE_AUTO; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1262 | requestTemplate->addEntry(ANDROID_CONTROL_AWB_MODE, |
| 1263 | &awbMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1264 | |
| 1265 | uint8_t awbLock = ANDROID_CONTROL_AWB_LOCK_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1266 | requestTemplate->addEntry(ANDROID_CONTROL_AWB_LOCK, |
| 1267 | &awbLock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1268 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1269 | uint8_t flashMode = ANDROID_FLASH_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1270 | requestTemplate->addEntry(ANDROID_FLASH_MODE, |
| 1271 | &flashMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1272 | |
| 1273 | uint8_t faceDetectMode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1274 | requestTemplate->addEntry(ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 1275 | &faceDetectMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1276 | |
Jacopo Mondi | 9b361dc | 2019-09-04 16:18:21 +0200 | [diff] [blame] | 1277 | uint8_t noiseReduction = ANDROID_NOISE_REDUCTION_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1278 | requestTemplate->addEntry(ANDROID_NOISE_REDUCTION_MODE, |
| 1279 | &noiseReduction, 1); |
Jacopo Mondi | 9b361dc | 2019-09-04 16:18:21 +0200 | [diff] [blame] | 1280 | |
| 1281 | uint8_t aberrationMode = ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1282 | requestTemplate->addEntry(ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 1283 | &aberrationMode, 1); |
Jacopo Mondi | 9b361dc | 2019-09-04 16:18:21 +0200 | [diff] [blame] | 1284 | |
Jacopo Mondi | 09b1d0f | 2020-07-24 16:10:23 +0200 | [diff] [blame] | 1285 | uint8_t controlMode = ANDROID_CONTROL_MODE_AUTO; |
| 1286 | requestTemplate->addEntry(ANDROID_CONTROL_MODE, &controlMode, 1); |
| 1287 | |
| 1288 | float lensAperture = 2.53 / 100; |
| 1289 | requestTemplate->addEntry(ANDROID_LENS_APERTURE, &lensAperture, 1); |
| 1290 | |
| 1291 | uint8_t opticalStabilization = ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF; |
| 1292 | requestTemplate->addEntry(ANDROID_LENS_OPTICAL_STABILIZATION_MODE, |
| 1293 | &opticalStabilization, 1); |
| 1294 | |
Jacopo Mondi | 8a02d44 | 2020-07-24 15:47:50 +0200 | [diff] [blame] | 1295 | uint8_t captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1296 | requestTemplate->addEntry(ANDROID_CONTROL_CAPTURE_INTENT, |
| 1297 | &captureIntent, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1298 | |
Jacopo Mondi | 8a02d44 | 2020-07-24 15:47:50 +0200 | [diff] [blame] | 1299 | return requestTemplate; |
| 1300 | } |
| 1301 | |
| 1302 | /* |
| 1303 | * Produce a metadata pack to be used as template for a capture request. |
| 1304 | */ |
| 1305 | const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) |
| 1306 | { |
| 1307 | auto it = requestTemplates_.find(type); |
| 1308 | if (it != requestTemplates_.end()) |
| 1309 | return it->second->get(); |
| 1310 | |
| 1311 | /* Use the capture intent matching the requested template type. */ |
| 1312 | CameraMetadata *requestTemplate; |
| 1313 | uint8_t captureIntent; |
| 1314 | switch (type) { |
| 1315 | case CAMERA3_TEMPLATE_PREVIEW: |
| 1316 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; |
| 1317 | break; |
| 1318 | case CAMERA3_TEMPLATE_STILL_CAPTURE: |
| 1319 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE; |
| 1320 | break; |
| 1321 | case CAMERA3_TEMPLATE_VIDEO_RECORD: |
| 1322 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD; |
| 1323 | break; |
| 1324 | case CAMERA3_TEMPLATE_VIDEO_SNAPSHOT: |
| 1325 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT; |
| 1326 | break; |
| 1327 | case CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG: |
| 1328 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG; |
| 1329 | break; |
| 1330 | case CAMERA3_TEMPLATE_MANUAL: |
| 1331 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_MANUAL; |
| 1332 | break; |
| 1333 | default: |
| 1334 | LOG(HAL, Error) << "Invalid template request type: " << type; |
| 1335 | return nullptr; |
| 1336 | } |
| 1337 | |
| 1338 | requestTemplate = requestTemplatePreview(); |
| 1339 | if (!requestTemplate || !requestTemplate->isValid()) { |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1340 | LOG(HAL, Error) << "Failed to construct request template"; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1341 | delete requestTemplate; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1342 | return nullptr; |
| 1343 | } |
| 1344 | |
Jacopo Mondi | 8a02d44 | 2020-07-24 15:47:50 +0200 | [diff] [blame] | 1345 | requestTemplate->updateEntry(ANDROID_CONTROL_CAPTURE_INTENT, |
| 1346 | &captureIntent, 1); |
| 1347 | |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1348 | requestTemplates_[type] = requestTemplate; |
| 1349 | return requestTemplate->get(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1350 | } |
| 1351 | |
Hirokazu Honda | c1ae905 | 2020-10-28 18:50:23 +0900 | [diff] [blame] | 1352 | PixelFormat CameraDevice::toPixelFormat(int format) const |
Kieran Bingham | 43e3b80 | 2020-06-26 09:58:49 +0100 | [diff] [blame] | 1353 | { |
| 1354 | /* Translate Android format code to libcamera pixel format. */ |
| 1355 | auto it = formatsMap_.find(format); |
| 1356 | if (it == formatsMap_.end()) { |
| 1357 | LOG(HAL, Error) << "Requested format " << utils::hex(format) |
| 1358 | << " not supported"; |
| 1359 | return PixelFormat(); |
| 1360 | } |
| 1361 | |
| 1362 | return it->second; |
| 1363 | } |
| 1364 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1365 | /* |
| 1366 | * Inspect the stream_list to produce a list of StreamConfiguration to |
| 1367 | * be use to configure the Camera. |
| 1368 | */ |
| 1369 | int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) |
| 1370 | { |
Jacopo Mondi | 8fed613 | 2020-12-04 15:26:47 +0100 | [diff] [blame] | 1371 | /* Before any configuration attempt, stop the camera if it's running. */ |
| 1372 | if (running_) { |
| 1373 | worker_.stop(); |
| 1374 | camera_->stop(); |
| 1375 | running_ = false; |
| 1376 | } |
| 1377 | |
Kieran Bingham | 0a9244e | 2020-06-26 20:19:10 +0100 | [diff] [blame] | 1378 | /* |
| 1379 | * Generate an empty configuration, and construct a StreamConfiguration |
| 1380 | * for each camera3_stream to add to it. |
| 1381 | */ |
| 1382 | config_ = camera_->generateConfiguration(); |
| 1383 | if (!config_) { |
| 1384 | LOG(HAL, Error) << "Failed to generate camera configuration"; |
| 1385 | return -EINVAL; |
| 1386 | } |
| 1387 | |
Kieran Bingham | 2f34f5e | 2020-07-01 16:42:13 +0100 | [diff] [blame] | 1388 | /* |
| 1389 | * Clear and remove any existing configuration from previous calls, and |
| 1390 | * ensure the required entries are available without further |
Jacopo Mondi | 9ac8f3e | 2020-09-04 15:25:55 +0200 | [diff] [blame] | 1391 | * reallocation. |
Kieran Bingham | 2f34f5e | 2020-07-01 16:42:13 +0100 | [diff] [blame] | 1392 | */ |
| 1393 | streams_.clear(); |
| 1394 | streams_.reserve(stream_list->num_streams); |
| 1395 | |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1396 | std::vector<Camera3StreamConfig> streamConfigs; |
| 1397 | streamConfigs.reserve(stream_list->num_streams); |
| 1398 | |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1399 | /* First handle all non-MJPEG streams. */ |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1400 | camera3_stream_t *jpegStream = nullptr; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1401 | for (unsigned int i = 0; i < stream_list->num_streams; ++i) { |
| 1402 | camera3_stream_t *stream = stream_list->streams[i]; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1403 | Size size(stream->width, stream->height); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1404 | |
Kieran Bingham | 43e3b80 | 2020-06-26 09:58:49 +0100 | [diff] [blame] | 1405 | PixelFormat format = toPixelFormat(stream->format); |
| 1406 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1407 | LOG(HAL, Info) << "Stream #" << i |
| 1408 | << ", direction: " << stream->stream_type |
| 1409 | << ", width: " << stream->width |
| 1410 | << ", height: " << stream->height |
Kieran Bingham | 43e3b80 | 2020-06-26 09:58:49 +0100 | [diff] [blame] | 1411 | << ", format: " << utils::hex(stream->format) |
| 1412 | << " (" << format.toString() << ")"; |
Kieran Bingham | 0a9244e | 2020-06-26 20:19:10 +0100 | [diff] [blame] | 1413 | |
| 1414 | if (!format.isValid()) |
| 1415 | return -EINVAL; |
| 1416 | |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1417 | /* Defer handling of MJPEG streams until all others are known. */ |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1418 | if (stream->format == HAL_PIXEL_FORMAT_BLOB) { |
| 1419 | if (jpegStream) { |
| 1420 | LOG(HAL, Error) |
| 1421 | << "Multiple JPEG streams are not supported"; |
| 1422 | return -EINVAL; |
| 1423 | } |
| 1424 | |
| 1425 | jpegStream = stream; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1426 | continue; |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1427 | } |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1428 | |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1429 | Camera3StreamConfig streamConfig; |
| 1430 | streamConfig.streams = { { stream, CameraStream::Type::Direct } }; |
| 1431 | streamConfig.config.size = size; |
| 1432 | streamConfig.config.pixelFormat = format; |
| 1433 | streamConfigs.push_back(std::move(streamConfig)); |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1434 | } |
| 1435 | |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1436 | /* Now handle the MJPEG streams, adding a new stream if required. */ |
| 1437 | if (jpegStream) { |
Jacopo Mondi | 94c4d49 | 2020-09-04 16:06:11 +0200 | [diff] [blame] | 1438 | CameraStream::Type type; |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1439 | int index = -1; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1440 | |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1441 | /* Search for a compatible stream in the non-JPEG ones. */ |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1442 | for (size_t i = 0; i < streamConfigs.size(); ++i) { |
| 1443 | const auto &cfg = streamConfigs[i].config; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1444 | |
| 1445 | /* |
| 1446 | * \todo The PixelFormat must also be compatible with |
| 1447 | * the encoder. |
| 1448 | */ |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1449 | if (cfg.size.width != jpegStream->width || |
| 1450 | cfg.size.height != jpegStream->height) |
| 1451 | continue; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1452 | |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1453 | LOG(HAL, Info) |
| 1454 | << "Android JPEG stream mapped to libcamera stream " << i; |
| 1455 | |
Jacopo Mondi | 94c4d49 | 2020-09-04 16:06:11 +0200 | [diff] [blame] | 1456 | type = CameraStream::Type::Mapped; |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1457 | index = i; |
| 1458 | break; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | /* |
| 1462 | * Without a compatible match for JPEG encoding we must |
| 1463 | * introduce a new stream to satisfy the request requirements. |
| 1464 | */ |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1465 | if (index < 0) { |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1466 | /* |
| 1467 | * \todo The pixelFormat should be a 'best-fit' choice |
| 1468 | * and may require a validation cycle. This is not yet |
| 1469 | * handled, and should be considered as part of any |
| 1470 | * stream configuration reworks. |
| 1471 | */ |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1472 | Camera3StreamConfig streamConfig; |
| 1473 | streamConfig.config.size.width = jpegStream->width; |
| 1474 | streamConfig.config.size.height = jpegStream->height; |
| 1475 | streamConfig.config.pixelFormat = formats::NV12; |
| 1476 | streamConfigs.push_back(std::move(streamConfig)); |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1477 | |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1478 | LOG(HAL, Info) << "Adding " << streamConfig.config.toString() |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1479 | << " for MJPEG support"; |
| 1480 | |
Jacopo Mondi | 94c4d49 | 2020-09-04 16:06:11 +0200 | [diff] [blame] | 1481 | type = CameraStream::Type::Internal; |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1482 | index = streamConfigs.size() - 1; |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1483 | } |
| 1484 | |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1485 | streamConfigs[index].streams.push_back({ jpegStream, type }); |
| 1486 | } |
| 1487 | |
Hirokazu Honda | 26d90af | 2020-12-11 09:53:36 +0000 | [diff] [blame] | 1488 | sortCamera3StreamConfigs(streamConfigs, jpegStream); |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1489 | for (const auto &streamConfig : streamConfigs) { |
| 1490 | config_->addConfiguration(streamConfig.config); |
| 1491 | |
| 1492 | for (auto &stream : streamConfig.streams) { |
| 1493 | streams_.emplace_back(this, stream.type, stream.stream, |
| 1494 | config_->size() - 1); |
| 1495 | stream.stream->priv = static_cast<void *>(&streams_.back()); |
| 1496 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1497 | } |
| 1498 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1499 | switch (config_->validate()) { |
| 1500 | case CameraConfiguration::Valid: |
| 1501 | break; |
| 1502 | case CameraConfiguration::Adjusted: |
| 1503 | LOG(HAL, Info) << "Camera configuration adjusted"; |
Kieran Bingham | 9f07aeb | 2020-07-20 22:52:14 +0100 | [diff] [blame] | 1504 | |
| 1505 | for (const StreamConfiguration &cfg : *config_) |
| 1506 | LOG(HAL, Info) << " - " << cfg.toString(); |
| 1507 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1508 | config_.reset(); |
| 1509 | return -EINVAL; |
| 1510 | case CameraConfiguration::Invalid: |
| 1511 | LOG(HAL, Info) << "Camera configuration invalid"; |
| 1512 | config_.reset(); |
| 1513 | return -EINVAL; |
| 1514 | } |
| 1515 | |
Jacopo Mondi | 3c84d88 | 2020-10-02 19:40:42 +0200 | [diff] [blame] | 1516 | /* |
Jacopo Mondi | b84e35d | 2020-10-03 13:21:50 +0200 | [diff] [blame] | 1517 | * Once the CameraConfiguration has been adjusted/validated |
| 1518 | * it can be applied to the camera. |
| 1519 | */ |
| 1520 | int ret = camera_->configure(config_.get()); |
| 1521 | if (ret) { |
| 1522 | LOG(HAL, Error) << "Failed to configure camera '" |
| 1523 | << camera_->id() << "'"; |
| 1524 | return ret; |
| 1525 | } |
| 1526 | |
| 1527 | /* |
Jacopo Mondi | 3c84d88 | 2020-10-02 19:40:42 +0200 | [diff] [blame] | 1528 | * Configure the HAL CameraStream instances using the associated |
| 1529 | * StreamConfiguration and set the number of required buffers in |
| 1530 | * the Android camera3_stream_t. |
| 1531 | */ |
Jacopo Mondi | 6c8837d | 2020-10-03 13:45:29 +0200 | [diff] [blame] | 1532 | for (CameraStream &cameraStream : streams_) { |
Kieran Bingham | c7bcae0 | 2020-10-13 15:58:26 +0100 | [diff] [blame] | 1533 | ret = cameraStream.configure(); |
Jacopo Mondi | 6c8837d | 2020-10-03 13:45:29 +0200 | [diff] [blame] | 1534 | if (ret) { |
| 1535 | LOG(HAL, Error) << "Failed to configure camera stream"; |
Jacopo Mondi | 3c84d88 | 2020-10-02 19:40:42 +0200 | [diff] [blame] | 1536 | return ret; |
Jacopo Mondi | 6c8837d | 2020-10-03 13:45:29 +0200 | [diff] [blame] | 1537 | } |
Kieran Bingham | 0a9244e | 2020-06-26 20:19:10 +0100 | [diff] [blame] | 1538 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1539 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1540 | return 0; |
| 1541 | } |
| 1542 | |
Kieran Bingham | 74ab442 | 2020-07-01 13:25:38 +0100 | [diff] [blame] | 1543 | FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer) |
| 1544 | { |
| 1545 | std::vector<FrameBuffer::Plane> planes; |
Kieran Bingham | f4c65be | 2020-07-06 16:12:03 +0100 | [diff] [blame] | 1546 | for (int i = 0; i < camera3buffer->numFds; i++) { |
| 1547 | /* Skip unused planes. */ |
| 1548 | if (camera3buffer->data[i] == -1) |
| 1549 | break; |
| 1550 | |
Kieran Bingham | 74ab442 | 2020-07-01 13:25:38 +0100 | [diff] [blame] | 1551 | FrameBuffer::Plane plane; |
| 1552 | plane.fd = FileDescriptor(camera3buffer->data[i]); |
Kieran Bingham | f4c65be | 2020-07-06 16:12:03 +0100 | [diff] [blame] | 1553 | if (!plane.fd.isValid()) { |
| 1554 | LOG(HAL, Error) << "Failed to obtain FileDescriptor (" |
| 1555 | << camera3buffer->data[i] << ") " |
| 1556 | << " on plane " << i; |
| 1557 | return nullptr; |
| 1558 | } |
| 1559 | |
Kieran Bingham | 6bc652e | 2020-07-17 16:18:32 +0100 | [diff] [blame] | 1560 | off_t length = lseek(plane.fd.fd(), 0, SEEK_END); |
| 1561 | if (length == -1) { |
| 1562 | LOG(HAL, Error) << "Failed to query plane length"; |
| 1563 | return nullptr; |
| 1564 | } |
| 1565 | |
| 1566 | plane.length = length; |
Kieran Bingham | 74ab442 | 2020-07-01 13:25:38 +0100 | [diff] [blame] | 1567 | planes.push_back(std::move(plane)); |
| 1568 | } |
| 1569 | |
| 1570 | return new FrameBuffer(std::move(planes)); |
| 1571 | } |
| 1572 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1573 | int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1574 | { |
Jacopo Mondi | c5b732b | 2020-12-01 17:12:19 +0100 | [diff] [blame] | 1575 | if (!camera3Request) { |
| 1576 | LOG(HAL, Error) << "No capture request provided"; |
| 1577 | return -EINVAL; |
| 1578 | } |
| 1579 | |
Kieran Bingham | 61f4296 | 2020-07-01 13:40:17 +0100 | [diff] [blame] | 1580 | if (!camera3Request->num_output_buffers) { |
| 1581 | LOG(HAL, Error) << "No output buffers provided"; |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1582 | return -EINVAL; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | /* Start the camera if that's the first request we handle. */ |
| 1586 | if (!running_) { |
Jacopo Mondi | 4b1aa21 | 2020-10-06 17:56:50 +0200 | [diff] [blame] | 1587 | worker_.start(); |
| 1588 | |
Niklas Söderlund | a1c5450 | 2019-11-25 17:51:06 +0100 | [diff] [blame] | 1589 | int ret = camera_->start(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1590 | if (ret) { |
| 1591 | LOG(HAL, Error) << "Failed to start camera"; |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1592 | return ret; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | running_ = true; |
| 1596 | } |
| 1597 | |
| 1598 | /* |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1599 | * Save the request descriptors for use at completion time. |
| 1600 | * The descriptor and the associated memory reserved here are freed |
| 1601 | * at request complete time. |
| 1602 | */ |
| 1603 | Camera3RequestDescriptor *descriptor = |
Jacopo Mondi | dd1cd53 | 2021-01-21 10:51:05 +0100 | [diff] [blame] | 1604 | new Camera3RequestDescriptor(camera_.get(), camera3Request); |
Kieran Bingham | eac0542 | 2020-07-01 13:28:16 +0100 | [diff] [blame] | 1605 | |
Jacopo Mondi | 35f726d | 2020-09-04 18:32:48 +0200 | [diff] [blame] | 1606 | LOG(HAL, Debug) << "Queueing Request to libcamera with " |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1607 | << descriptor->numBuffers_ << " HAL streams"; |
| 1608 | for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { |
Jacopo Mondi | 4b18b82 | 2021-01-21 11:10:08 +0100 | [diff] [blame^] | 1609 | const camera3_stream_buffer_t *camera3Buffer = &descriptor->buffers_[i]; |
| 1610 | camera3_stream *camera3Stream = camera3Buffer->stream; |
| 1611 | CameraStream *cameraStream = static_cast<CameraStream *>(camera3Stream->priv); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1612 | |
Jacopo Mondi | 35f726d | 2020-09-04 18:32:48 +0200 | [diff] [blame] | 1613 | std::stringstream ss; |
| 1614 | ss << i << " - (" << camera3Stream->width << "x" |
| 1615 | << camera3Stream->height << ")" |
| 1616 | << "[" << utils::hex(camera3Stream->format) << "] -> " |
| 1617 | << "(" << cameraStream->configuration().size.toString() << ")[" |
| 1618 | << cameraStream->configuration().pixelFormat.toString() << "]"; |
| 1619 | |
Jacopo Mondi | de8304b | 2020-09-04 17:45:39 +0200 | [diff] [blame] | 1620 | /* |
| 1621 | * Inspect the camera stream type, create buffers opportunely |
| 1622 | * and add them to the Request if required. |
| 1623 | */ |
| 1624 | FrameBuffer *buffer = nullptr; |
| 1625 | switch (cameraStream->type()) { |
| 1626 | case CameraStream::Type::Mapped: |
| 1627 | /* |
| 1628 | * Mapped streams don't need buffers added to the |
| 1629 | * Request. |
| 1630 | */ |
Jacopo Mondi | 35f726d | 2020-09-04 18:32:48 +0200 | [diff] [blame] | 1631 | LOG(HAL, Debug) << ss.str() << " (mapped)"; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1632 | continue; |
| 1633 | |
Jacopo Mondi | de8304b | 2020-09-04 17:45:39 +0200 | [diff] [blame] | 1634 | case CameraStream::Type::Direct: |
| 1635 | /* |
| 1636 | * Create a libcamera buffer using the dmabuf |
| 1637 | * descriptors of the camera3Buffer for each stream and |
| 1638 | * associate it with the Camera3RequestDescriptor for |
| 1639 | * lifetime management only. |
| 1640 | */ |
Jacopo Mondi | 4b18b82 | 2021-01-21 11:10:08 +0100 | [diff] [blame^] | 1641 | buffer = createFrameBuffer(*camera3Buffer->buffer); |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1642 | descriptor->frameBuffers_.emplace_back(buffer); |
Jacopo Mondi | 35f726d | 2020-09-04 18:32:48 +0200 | [diff] [blame] | 1643 | LOG(HAL, Debug) << ss.str() << " (direct)"; |
Jacopo Mondi | de8304b | 2020-09-04 17:45:39 +0200 | [diff] [blame] | 1644 | break; |
| 1645 | |
| 1646 | case CameraStream::Type::Internal: |
| 1647 | /* |
| 1648 | * Get the frame buffer from the CameraStream internal |
| 1649 | * buffer pool. |
| 1650 | * |
| 1651 | * The buffer has to be returned to the CameraStream |
| 1652 | * once it has been processed. |
| 1653 | */ |
| 1654 | buffer = cameraStream->getBuffer(); |
Jacopo Mondi | 35f726d | 2020-09-04 18:32:48 +0200 | [diff] [blame] | 1655 | LOG(HAL, Debug) << ss.str() << " (internal)"; |
Jacopo Mondi | de8304b | 2020-09-04 17:45:39 +0200 | [diff] [blame] | 1656 | break; |
| 1657 | } |
| 1658 | |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1659 | if (!buffer) { |
| 1660 | LOG(HAL, Error) << "Failed to create buffer"; |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1661 | delete descriptor; |
| 1662 | return -ENOMEM; |
| 1663 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1664 | |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1665 | descriptor->request_->addBuffer(cameraStream->stream(), buffer, |
Jacopo Mondi | 4b18b82 | 2021-01-21 11:10:08 +0100 | [diff] [blame^] | 1666 | camera3Buffer->acquire_fence); |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1667 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1668 | |
Jacopo Mondi | 4b1aa21 | 2020-10-06 17:56:50 +0200 | [diff] [blame] | 1669 | /* Queue the request to the CameraWorker. */ |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1670 | worker_.queueRequest(descriptor->request_.get()); |
Paul Elder | c753223 | 2020-09-23 19:05:41 +0900 | [diff] [blame] | 1671 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1672 | return 0; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1673 | } |
| 1674 | |
Niklas Söderlund | f7ddfd4 | 2019-10-21 20:01:19 +0200 | [diff] [blame] | 1675 | void CameraDevice::requestComplete(Request *request) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1676 | { |
Niklas Söderlund | dac8e95 | 2020-08-11 00:56:13 +0200 | [diff] [blame] | 1677 | const Request::BufferMap &buffers = request->buffers(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1678 | camera3_buffer_status status = CAMERA3_BUFFER_STATUS_OK; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1679 | std::unique_ptr<CameraMetadata> resultMetadata; |
Kieran Bingham | c09aee4 | 2020-07-28 14:01:19 +0100 | [diff] [blame] | 1680 | Camera3RequestDescriptor *descriptor = |
| 1681 | reinterpret_cast<Camera3RequestDescriptor *>(request->cookie()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1682 | |
| 1683 | if (request->status() != Request::RequestComplete) { |
Kieran Bingham | 98986e0 | 2020-08-03 14:34:11 +0100 | [diff] [blame] | 1684 | LOG(HAL, Error) << "Request not successfully completed: " |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1685 | << request->status(); |
| 1686 | status = CAMERA3_BUFFER_STATUS_ERROR; |
| 1687 | } |
| 1688 | |
Kieran Bingham | c09aee4 | 2020-07-28 14:01:19 +0100 | [diff] [blame] | 1689 | /* |
| 1690 | * \todo The timestamp used for the metadata is currently always taken |
| 1691 | * from the first buffer (which may be the first stream) in the Request. |
| 1692 | * It might be appropriate to return a 'correct' (as determined by |
| 1693 | * pipeline handlers) timestamp in the Request itself. |
| 1694 | */ |
Hirokazu Honda | 3a777d8 | 2020-10-28 17:57:26 +0900 | [diff] [blame] | 1695 | uint64_t timestamp = buffers.begin()->second->metadata().timestamp; |
Jacopo Mondi | 3535e0c | 2020-12-09 17:51:57 +0100 | [diff] [blame] | 1696 | resultMetadata = getResultMetadata(descriptor, timestamp); |
Kieran Bingham | c09aee4 | 2020-07-28 14:01:19 +0100 | [diff] [blame] | 1697 | |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1698 | /* Handle any JPEG compression. */ |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1699 | for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1700 | CameraStream *cameraStream = |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1701 | static_cast<CameraStream *>(descriptor->buffers_[i].stream->priv); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1702 | |
Jacopo Mondi | 160bb09 | 2020-10-02 20:48:35 +0200 | [diff] [blame] | 1703 | if (cameraStream->camera3Stream().format != HAL_PIXEL_FORMAT_BLOB) |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1704 | continue; |
| 1705 | |
Jacopo Mondi | 216030a | 2020-10-03 11:36:41 +0200 | [diff] [blame] | 1706 | FrameBuffer *buffer = request->findBuffer(cameraStream->stream()); |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1707 | if (!buffer) { |
| 1708 | LOG(HAL, Error) << "Failed to find a source stream buffer"; |
| 1709 | continue; |
| 1710 | } |
| 1711 | |
| 1712 | /* |
| 1713 | * \todo Buffer mapping and compression should be moved to a |
| 1714 | * separate thread. |
| 1715 | */ |
| 1716 | |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1717 | MappedCamera3Buffer mapped(*descriptor->buffers_[i].buffer, |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1718 | PROT_READ | PROT_WRITE); |
| 1719 | if (!mapped.isValid()) { |
| 1720 | LOG(HAL, Error) << "Failed to mmap android blob buffer"; |
| 1721 | continue; |
| 1722 | } |
| 1723 | |
Jacopo Mondi | 9e95d5e | 2020-10-03 11:28:47 +0200 | [diff] [blame] | 1724 | int ret = cameraStream->process(*buffer, &mapped, |
| 1725 | resultMetadata.get()); |
| 1726 | if (ret) { |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1727 | status = CAMERA3_BUFFER_STATUS_ERROR; |
| 1728 | continue; |
| 1729 | } |
Jacopo Mondi | de8304b | 2020-09-04 17:45:39 +0200 | [diff] [blame] | 1730 | |
| 1731 | /* |
| 1732 | * Return the FrameBuffer to the CameraStream now that we're |
| 1733 | * done processing it. |
| 1734 | */ |
| 1735 | if (cameraStream->type() == CameraStream::Type::Internal) |
| 1736 | cameraStream->putBuffer(buffer); |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | /* Prepare to call back the Android camera stack. */ |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1740 | camera3_capture_result_t captureResult = {}; |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1741 | captureResult.frame_number = descriptor->frameNumber_; |
| 1742 | captureResult.num_output_buffers = descriptor->numBuffers_; |
| 1743 | for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { |
| 1744 | descriptor->buffers_[i].acquire_fence = -1; |
| 1745 | descriptor->buffers_[i].release_fence = -1; |
| 1746 | descriptor->buffers_[i].status = status; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1747 | } |
| 1748 | captureResult.output_buffers = |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1749 | const_cast<const camera3_stream_buffer_t *>(descriptor->buffers_); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1750 | |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1751 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1752 | if (status == CAMERA3_BUFFER_STATUS_OK) { |
Kieran Bingham | e1f9fdb | 2020-10-21 15:31:10 +0100 | [diff] [blame] | 1753 | notifyShutter(descriptor->frameNumber_, timestamp); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1754 | |
| 1755 | captureResult.partial_result = 1; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1756 | captureResult.result = resultMetadata->get(); |
| 1757 | } |
| 1758 | |
| 1759 | if (status == CAMERA3_BUFFER_STATUS_ERROR || !captureResult.result) { |
| 1760 | /* \todo Improve error handling. In case we notify an error |
| 1761 | * because the metadata generation fails, a shutter event has |
| 1762 | * already been notified for this frame number before the error |
| 1763 | * is here signalled. Make sure the error path plays well with |
| 1764 | * the camera stack state machine. |
| 1765 | */ |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1766 | notifyError(descriptor->frameNumber_, |
| 1767 | descriptor->buffers_[0].stream); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | callbacks_->process_capture_result(callbacks_, &captureResult); |
| 1771 | |
| 1772 | delete descriptor; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1773 | } |
| 1774 | |
Jacopo Mondi | a7b9277 | 2020-05-26 15:41:41 +0200 | [diff] [blame] | 1775 | std::string CameraDevice::logPrefix() const |
| 1776 | { |
Niklas Söderlund | 2e7c80a | 2020-08-02 23:57:17 +0200 | [diff] [blame] | 1777 | return "'" + camera_->id() + "'"; |
Jacopo Mondi | a7b9277 | 2020-05-26 15:41:41 +0200 | [diff] [blame] | 1778 | } |
| 1779 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1780 | void CameraDevice::notifyShutter(uint32_t frameNumber, uint64_t timestamp) |
| 1781 | { |
| 1782 | camera3_notify_msg_t notify = {}; |
| 1783 | |
| 1784 | notify.type = CAMERA3_MSG_SHUTTER; |
| 1785 | notify.message.shutter.frame_number = frameNumber; |
| 1786 | notify.message.shutter.timestamp = timestamp; |
| 1787 | |
| 1788 | callbacks_->notify(callbacks_, ¬ify); |
| 1789 | } |
| 1790 | |
| 1791 | void CameraDevice::notifyError(uint32_t frameNumber, camera3_stream_t *stream) |
| 1792 | { |
| 1793 | camera3_notify_msg_t notify = {}; |
| 1794 | |
Kieran Bingham | 8ad1b9c | 2020-07-01 16:47:58 +0100 | [diff] [blame] | 1795 | /* |
| 1796 | * \todo Report and identify the stream number or configuration to |
| 1797 | * clarify the stream that failed. |
| 1798 | */ |
| 1799 | LOG(HAL, Error) << "Error occurred on frame " << frameNumber << " (" |
| 1800 | << toPixelFormat(stream->format).toString() << ")"; |
| 1801 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1802 | notify.type = CAMERA3_MSG_ERROR; |
| 1803 | notify.message.error.error_stream = stream; |
| 1804 | notify.message.error.frame_number = frameNumber; |
| 1805 | notify.message.error.error_code = CAMERA3_MSG_ERROR_REQUEST; |
| 1806 | |
| 1807 | callbacks_->notify(callbacks_, ¬ify); |
| 1808 | } |
| 1809 | |
| 1810 | /* |
| 1811 | * Produce a set of fixed result metadata. |
| 1812 | */ |
Laurent Pinchart | dbafe16 | 2019-10-27 00:36:13 +0300 | [diff] [blame] | 1813 | std::unique_ptr<CameraMetadata> |
Jacopo Mondi | 3535e0c | 2020-12-09 17:51:57 +0100 | [diff] [blame] | 1814 | CameraDevice::getResultMetadata(Camera3RequestDescriptor *descriptor, |
Laurent Pinchart | dbafe16 | 2019-10-27 00:36:13 +0300 | [diff] [blame] | 1815 | int64_t timestamp) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1816 | { |
Jacopo Mondi | 3535e0c | 2020-12-09 17:51:57 +0100 | [diff] [blame] | 1817 | const ControlList &metadata = descriptor->request_->metadata(); |
| 1818 | |
Jacopo Mondi | 48504ba | 2019-09-04 16:18:19 +0200 | [diff] [blame] | 1819 | /* |
| 1820 | * \todo Keep this in sync with the actual number of entries. |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1821 | * Currently: 18 entries, 62 bytes |
Jacopo Mondi | 48504ba | 2019-09-04 16:18:19 +0200 | [diff] [blame] | 1822 | */ |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1823 | std::unique_ptr<CameraMetadata> resultMetadata = |
Jacopo Mondi | 3535e0c | 2020-12-09 17:51:57 +0100 | [diff] [blame] | 1824 | std::make_unique<CameraMetadata>(19, 63); |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1825 | if (!resultMetadata->isValid()) { |
| 1826 | LOG(HAL, Error) << "Failed to allocate static metadata"; |
| 1827 | return nullptr; |
| 1828 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1829 | |
| 1830 | const uint8_t ae_state = ANDROID_CONTROL_AE_STATE_CONVERGED; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1831 | resultMetadata->addEntry(ANDROID_CONTROL_AE_STATE, &ae_state, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1832 | |
| 1833 | const uint8_t ae_lock = ANDROID_CONTROL_AE_LOCK_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1834 | resultMetadata->addEntry(ANDROID_CONTROL_AE_LOCK, &ae_lock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1835 | |
| 1836 | uint8_t af_state = ANDROID_CONTROL_AF_STATE_INACTIVE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1837 | resultMetadata->addEntry(ANDROID_CONTROL_AF_STATE, &af_state, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1838 | |
| 1839 | const uint8_t awb_state = ANDROID_CONTROL_AWB_STATE_CONVERGED; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1840 | resultMetadata->addEntry(ANDROID_CONTROL_AWB_STATE, &awb_state, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1841 | |
| 1842 | const uint8_t awb_lock = ANDROID_CONTROL_AWB_LOCK_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1843 | resultMetadata->addEntry(ANDROID_CONTROL_AWB_LOCK, &awb_lock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1844 | |
| 1845 | const uint8_t lens_state = ANDROID_LENS_STATE_STATIONARY; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1846 | resultMetadata->addEntry(ANDROID_LENS_STATE, &lens_state, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1847 | |
| 1848 | int32_t sensorSizes[] = { |
| 1849 | 0, 0, 2560, 1920, |
| 1850 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1851 | resultMetadata->addEntry(ANDROID_SCALER_CROP_REGION, sensorSizes, 4); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1852 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1853 | resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, ×tamp, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1854 | |
| 1855 | /* 33.3 msec */ |
| 1856 | const int64_t rolling_shutter_skew = 33300000; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1857 | resultMetadata->addEntry(ANDROID_SENSOR_ROLLING_SHUTTER_SKEW, |
| 1858 | &rolling_shutter_skew, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1859 | |
| 1860 | /* 16.6 msec */ |
| 1861 | const int64_t exposure_time = 16600000; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1862 | resultMetadata->addEntry(ANDROID_SENSOR_EXPOSURE_TIME, |
| 1863 | &exposure_time, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1864 | |
| 1865 | const uint8_t lens_shading_map_mode = |
| 1866 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1867 | resultMetadata->addEntry(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, |
| 1868 | &lens_shading_map_mode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1869 | |
| 1870 | const uint8_t scene_flicker = ANDROID_STATISTICS_SCENE_FLICKER_NONE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1871 | resultMetadata->addEntry(ANDROID_STATISTICS_SCENE_FLICKER, |
| 1872 | &scene_flicker, 1); |
| 1873 | |
Jacopo Mondi | 3535e0c | 2020-12-09 17:51:57 +0100 | [diff] [blame] | 1874 | /* Add metadata tags reported by libcamera. */ |
| 1875 | if (metadata.contains(controls::draft::PipelineDepth)) { |
| 1876 | uint8_t pipeline_depth = |
| 1877 | metadata.get<int32_t>(controls::draft::PipelineDepth); |
| 1878 | resultMetadata->addEntry(ANDROID_REQUEST_PIPELINE_DEPTH, |
| 1879 | &pipeline_depth, 1); |
| 1880 | } |
| 1881 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1882 | /* |
| 1883 | * Return the result metadata pack even is not valid: get() will return |
| 1884 | * nullptr. |
| 1885 | */ |
| 1886 | if (!resultMetadata->isValid()) { |
| 1887 | LOG(HAL, Error) << "Failed to construct result metadata"; |
| 1888 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1889 | |
| 1890 | return resultMetadata; |
| 1891 | } |