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 | |
Paul Elder | 229653a | 2021-01-21 17:44:14 +0900 | [diff] [blame] | 12 | #include <fstream> |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 13 | #include <sys/mman.h> |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 14 | #include <tuple> |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Jacopo Mondi | 5d91c8d | 2020-09-23 09:41:52 +0200 | [diff] [blame] | 17 | #include <libcamera/control_ids.h> |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 18 | #include <libcamera/controls.h> |
Laurent Pinchart | 8b7e073 | 2020-05-22 04:02:06 +0300 | [diff] [blame] | 19 | #include <libcamera/formats.h> |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 20 | #include <libcamera/property_ids.h> |
| 21 | |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame] | 22 | #include "libcamera/internal/formats.h" |
Laurent Pinchart | 93e72b6 | 2020-05-12 00:58:34 +0300 | [diff] [blame] | 23 | #include "libcamera/internal/log.h" |
| 24 | #include "libcamera/internal/utils.h" |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 25 | |
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 | |
Jacopo Mondi | 9e6eece | 2021-01-21 12:52:10 +0100 | [diff] [blame] | 314 | /* Clone the controls associated with the camera3 request. */ |
| 315 | settings_ = CameraMetadata(camera3Request->settings); |
| 316 | |
Jacopo Mondi | 4b1aa21 | 2020-10-06 17:56:50 +0200 | [diff] [blame] | 317 | /* |
| 318 | * Create the libcamera::Request unique_ptr<> to tie its lifetime |
| 319 | * to the descriptor's one. Set the descriptor's address as the |
| 320 | * request's cookie to retrieve it at completion time. |
| 321 | */ |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 322 | request_ = std::make_unique<CaptureRequest>(camera, |
| 323 | reinterpret_cast<uint64_t>(this)); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor() |
| 327 | { |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 328 | delete[] buffers_; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | /* |
| 332 | * \class CameraDevice |
| 333 | * |
| 334 | * The CameraDevice class wraps a libcamera::Camera instance, and implements |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 335 | * the camera3_device_t interface, bridging calls received from the Android |
| 336 | * camera service to the CameraDevice. |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 337 | * |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 338 | * The class translates parameters and operations from the Camera HALv3 API to |
| 339 | * the libcamera API to provide static information for a Camera, create request |
| 340 | * templates for it, process capture requests and then deliver capture results |
| 341 | * back to the framework using the designated callbacks. |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 342 | */ |
| 343 | |
Laurent Pinchart | 0ed40d2 | 2019-08-18 01:45:01 +0300 | [diff] [blame] | 344 | CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr<Camera> &camera) |
Umang Jain | 035ee23 | 2020-08-05 12:53:49 +0000 | [diff] [blame] | 345 | : id_(id), running_(false), camera_(camera), staticMetadata_(nullptr), |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 346 | facing_(CAMERA_FACING_FRONT), orientation_(0) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 347 | { |
| 348 | camera_->requestCompleted.connect(this, &CameraDevice::requestComplete); |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 349 | |
| 350 | /* |
| 351 | * \todo Determine a more accurate value for this during |
| 352 | * streamConfiguration. |
| 353 | */ |
| 354 | maxJpegBufferSize_ = 13 << 20; /* 13631488 from USB HAL */ |
Paul Elder | 229653a | 2021-01-21 17:44:14 +0900 | [diff] [blame] | 355 | |
| 356 | maker_ = "libcamera"; |
| 357 | model_ = "cameraModel"; |
| 358 | |
| 359 | /* \todo Support getting properties on Android */ |
| 360 | std::ifstream fstream("/var/cache/camera/camera.prop"); |
| 361 | if (!fstream.is_open()) |
| 362 | return; |
| 363 | |
| 364 | std::string line; |
| 365 | while (std::getline(fstream, line)) { |
| 366 | std::string::size_type delimPos = line.find("="); |
| 367 | if (delimPos == std::string::npos) |
| 368 | continue; |
| 369 | std::string key = line.substr(0, delimPos); |
| 370 | std::string val = line.substr(delimPos + 1); |
| 371 | |
| 372 | if (!key.compare("ro.product.model")) |
| 373 | model_ = val; |
| 374 | else if (!key.compare("ro.product.manufacturer")) |
| 375 | maker_ = val; |
| 376 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | CameraDevice::~CameraDevice() |
| 380 | { |
| 381 | if (staticMetadata_) |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 382 | delete staticMetadata_; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 383 | |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 384 | for (auto &it : requestTemplates_) |
| 385 | delete it.second; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 386 | } |
| 387 | |
Umang Jain | f8e2813 | 2020-08-21 14:46:08 +0000 | [diff] [blame] | 388 | std::shared_ptr<CameraDevice> CameraDevice::create(unsigned int id, |
| 389 | const std::shared_ptr<Camera> &cam) |
| 390 | { |
| 391 | CameraDevice *camera = new CameraDevice(id, cam); |
| 392 | return std::shared_ptr<CameraDevice>(camera); |
| 393 | } |
| 394 | |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 395 | /* |
| 396 | * Initialize the camera static information. |
| 397 | * This method is called before the camera device is opened. |
| 398 | */ |
| 399 | int CameraDevice::initialize() |
| 400 | { |
| 401 | /* Initialize orientation and facing side of the camera. */ |
| 402 | const ControlList &properties = camera_->properties(); |
| 403 | |
| 404 | if (properties.contains(properties::Location)) { |
| 405 | int32_t location = properties.get(properties::Location); |
| 406 | switch (location) { |
| 407 | case properties::CameraLocationFront: |
| 408 | facing_ = CAMERA_FACING_FRONT; |
| 409 | break; |
| 410 | case properties::CameraLocationBack: |
| 411 | facing_ = CAMERA_FACING_BACK; |
| 412 | break; |
| 413 | case properties::CameraLocationExternal: |
| 414 | facing_ = CAMERA_FACING_EXTERNAL; |
| 415 | break; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | /* |
Umang Jain | e917655 | 2020-09-09 16:17:54 +0530 | [diff] [blame] | 420 | * The Android orientation metadata specifies its rotation correction |
| 421 | * value in clockwise direction whereas libcamera specifies the |
| 422 | * rotation property in anticlockwise direction. Read the libcamera's |
| 423 | * rotation property (anticlockwise) and compute the corresponding |
| 424 | * value for clockwise direction as required by the Android orientation |
| 425 | * metadata. |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 426 | */ |
Umang Jain | e917655 | 2020-09-09 16:17:54 +0530 | [diff] [blame] | 427 | if (properties.contains(properties::Rotation)) { |
| 428 | int rotation = properties.get(properties::Rotation); |
| 429 | orientation_ = (360 - rotation) % 360; |
| 430 | } |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 431 | |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 432 | int ret = camera_->acquire(); |
| 433 | if (ret) { |
| 434 | LOG(HAL, Error) << "Failed to temporarily acquire the camera"; |
| 435 | return ret; |
| 436 | } |
| 437 | |
| 438 | ret = initializeStreamConfigurations(); |
| 439 | camera_->release(); |
| 440 | return ret; |
| 441 | } |
| 442 | |
Jacopo Mondi | bfee631 | 2020-09-01 17:42:13 +0200 | [diff] [blame] | 443 | std::vector<Size> CameraDevice::getYUVResolutions(CameraConfiguration *cameraConfig, |
| 444 | const PixelFormat &pixelFormat, |
| 445 | const std::vector<Size> &resolutions) |
| 446 | { |
| 447 | std::vector<Size> supportedResolutions; |
| 448 | |
| 449 | StreamConfiguration &cfg = cameraConfig->at(0); |
| 450 | for (const Size &res : resolutions) { |
| 451 | cfg.pixelFormat = pixelFormat; |
| 452 | cfg.size = res; |
| 453 | |
| 454 | CameraConfiguration::Status status = cameraConfig->validate(); |
| 455 | if (status != CameraConfiguration::Valid) { |
| 456 | LOG(HAL, Debug) << cfg.toString() << " not supported"; |
| 457 | continue; |
| 458 | } |
| 459 | |
| 460 | LOG(HAL, Debug) << cfg.toString() << " supported"; |
| 461 | |
| 462 | supportedResolutions.push_back(res); |
| 463 | } |
| 464 | |
| 465 | return supportedResolutions; |
| 466 | } |
| 467 | |
Jacopo Mondi | 4961033 | 2020-09-01 18:11:34 +0200 | [diff] [blame] | 468 | std::vector<Size> CameraDevice::getRawResolutions(const libcamera::PixelFormat &pixelFormat) |
| 469 | { |
| 470 | std::unique_ptr<CameraConfiguration> cameraConfig = |
Niklas Söderlund | dbe8d27 | 2020-05-26 15:04:47 +0200 | [diff] [blame] | 471 | camera_->generateConfiguration({ StreamRole::Raw }); |
Jacopo Mondi | 4961033 | 2020-09-01 18:11:34 +0200 | [diff] [blame] | 472 | StreamConfiguration &cfg = cameraConfig->at(0); |
| 473 | const StreamFormats &formats = cfg.formats(); |
| 474 | std::vector<Size> supportedResolutions = formats.sizes(pixelFormat); |
| 475 | |
| 476 | return supportedResolutions; |
| 477 | } |
| 478 | |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 479 | /* |
| 480 | * Initialize the format conversion map to translate from Android format |
| 481 | * identifier to libcamera pixel formats and fill in the list of supported |
| 482 | * stream configurations to be reported to the Android camera framework through |
| 483 | * the static stream configuration metadata. |
| 484 | */ |
| 485 | int CameraDevice::initializeStreamConfigurations() |
| 486 | { |
| 487 | /* |
| 488 | * Get the maximum output resolutions |
| 489 | * \todo Get this from the camera properties once defined |
| 490 | */ |
| 491 | std::unique_ptr<CameraConfiguration> cameraConfig = |
| 492 | camera_->generateConfiguration({ StillCapture }); |
| 493 | if (!cameraConfig) { |
| 494 | LOG(HAL, Error) << "Failed to get maximum resolution"; |
| 495 | return -EINVAL; |
| 496 | } |
| 497 | StreamConfiguration &cfg = cameraConfig->at(0); |
| 498 | |
| 499 | /* |
| 500 | * \todo JPEG - Adjust the maximum available resolution by taking the |
| 501 | * JPEG encoder requirements into account (alignment and aspect ratio). |
| 502 | */ |
| 503 | const Size maxRes = cfg.size; |
| 504 | LOG(HAL, Debug) << "Maximum supported resolution: " << maxRes.toString(); |
| 505 | |
| 506 | /* |
| 507 | * Build the list of supported image resolutions. |
| 508 | * |
| 509 | * The resolutions listed in camera3Resolution are mandatory to be |
| 510 | * supported, up to the camera maximum resolution. |
| 511 | * |
| 512 | * Augment the list by adding resolutions calculated from the camera |
| 513 | * maximum one. |
| 514 | */ |
| 515 | std::vector<Size> cameraResolutions; |
| 516 | std::copy_if(camera3Resolutions.begin(), camera3Resolutions.end(), |
| 517 | std::back_inserter(cameraResolutions), |
| 518 | [&](const Size &res) { return res < maxRes; }); |
| 519 | |
| 520 | /* |
| 521 | * The Camera3 specification suggests adding 1/2 and 1/4 of the maximum |
| 522 | * resolution. |
| 523 | */ |
| 524 | for (unsigned int divider = 2;; divider <<= 1) { |
| 525 | Size derivedSize{ |
| 526 | maxRes.width / divider, |
| 527 | maxRes.height / divider, |
| 528 | }; |
| 529 | |
| 530 | if (derivedSize.width < 320 || |
| 531 | derivedSize.height < 240) |
| 532 | break; |
| 533 | |
| 534 | cameraResolutions.push_back(derivedSize); |
| 535 | } |
| 536 | cameraResolutions.push_back(maxRes); |
| 537 | |
| 538 | /* Remove duplicated entries from the list of supported resolutions. */ |
| 539 | std::sort(cameraResolutions.begin(), cameraResolutions.end()); |
| 540 | auto last = std::unique(cameraResolutions.begin(), cameraResolutions.end()); |
| 541 | cameraResolutions.erase(last, cameraResolutions.end()); |
| 542 | |
| 543 | /* |
| 544 | * Build the list of supported camera formats. |
| 545 | * |
| 546 | * To each Android format a list of compatible libcamera formats is |
| 547 | * associated. The first libcamera format that tests successful is added |
| 548 | * to the format translation map used when configuring the streams. |
| 549 | * It is then tested against the list of supported camera resolutions to |
| 550 | * build the stream configuration map reported through the camera static |
| 551 | * metadata. |
| 552 | */ |
| 553 | for (const auto &format : camera3FormatsMap) { |
| 554 | int androidFormat = format.first; |
| 555 | const Camera3Format &camera3Format = format.second; |
| 556 | const std::vector<PixelFormat> &libcameraFormats = |
| 557 | camera3Format.libcameraFormats; |
| 558 | |
Jacopo Mondi | af264ec | 2020-09-01 15:40:49 +0200 | [diff] [blame] | 559 | LOG(HAL, Debug) << "Trying to map Android format " |
| 560 | << camera3Format.name; |
| 561 | |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 562 | /* |
Jacopo Mondi | 843565c | 2020-09-01 15:34:13 +0200 | [diff] [blame] | 563 | * JPEG is always supported, either produced directly by the |
| 564 | * camera, or encoded in the HAL. |
| 565 | */ |
| 566 | if (androidFormat == HAL_PIXEL_FORMAT_BLOB) { |
| 567 | formatsMap_[androidFormat] = formats::MJPEG; |
Jacopo Mondi | af264ec | 2020-09-01 15:40:49 +0200 | [diff] [blame] | 568 | LOG(HAL, Debug) << "Mapped Android format " |
| 569 | << camera3Format.name << " to " |
| 570 | << formats::MJPEG.toString() |
| 571 | << " (fixed mapping)"; |
Jacopo Mondi | 843565c | 2020-09-01 15:34:13 +0200 | [diff] [blame] | 572 | continue; |
| 573 | } |
| 574 | |
| 575 | /* |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 576 | * Test the libcamera formats that can produce images |
| 577 | * compatible with the format defined by Android. |
| 578 | */ |
| 579 | PixelFormat mappedFormat; |
| 580 | for (const PixelFormat &pixelFormat : libcameraFormats) { |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 581 | |
Jacopo Mondi | af264ec | 2020-09-01 15:40:49 +0200 | [diff] [blame] | 582 | LOG(HAL, Debug) << "Testing " << pixelFormat.toString(); |
| 583 | |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 584 | /* |
| 585 | * The stream configuration size can be adjusted, |
| 586 | * not the pixel format. |
| 587 | * |
| 588 | * \todo This could be simplified once all pipeline |
| 589 | * handlers will report the StreamFormats list of |
| 590 | * supported formats. |
| 591 | */ |
| 592 | cfg.pixelFormat = pixelFormat; |
| 593 | |
| 594 | CameraConfiguration::Status status = cameraConfig->validate(); |
| 595 | if (status != CameraConfiguration::Invalid && |
| 596 | cfg.pixelFormat == pixelFormat) { |
| 597 | mappedFormat = pixelFormat; |
| 598 | break; |
| 599 | } |
| 600 | } |
Jacopo Mondi | 3533fd4 | 2020-09-01 15:31:56 +0200 | [diff] [blame] | 601 | |
| 602 | if (!mappedFormat.isValid()) { |
| 603 | /* If the format is not mandatory, skip it. */ |
| 604 | if (!camera3Format.mandatory) |
| 605 | continue; |
| 606 | |
| 607 | LOG(HAL, Error) |
| 608 | << "Failed to map mandatory Android format " |
| 609 | << camera3Format.name << " (" |
| 610 | << utils::hex(androidFormat) << "): aborting"; |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 611 | return -EINVAL; |
| 612 | } |
| 613 | |
| 614 | /* |
| 615 | * Record the mapping and then proceed to generate the |
| 616 | * stream configurations map, by testing the image resolutions. |
| 617 | */ |
| 618 | formatsMap_[androidFormat] = mappedFormat; |
Jacopo Mondi | af264ec | 2020-09-01 15:40:49 +0200 | [diff] [blame] | 619 | LOG(HAL, Debug) << "Mapped Android format " |
| 620 | << camera3Format.name << " to " |
| 621 | << mappedFormat.toString(); |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 622 | |
Jacopo Mondi | 4961033 | 2020-09-01 18:11:34 +0200 | [diff] [blame] | 623 | std::vector<Size> resolutions; |
| 624 | const PixelFormatInfo &info = PixelFormatInfo::info(mappedFormat); |
| 625 | if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) |
| 626 | resolutions = getRawResolutions(mappedFormat); |
| 627 | else |
| 628 | resolutions = getYUVResolutions(cameraConfig.get(), |
| 629 | mappedFormat, |
| 630 | cameraResolutions); |
| 631 | |
Jacopo Mondi | bfee631 | 2020-09-01 17:42:13 +0200 | [diff] [blame] | 632 | for (const Size &res : resolutions) { |
Niklas Söderlund | 142a9ee | 2020-07-23 18:32:23 +0200 | [diff] [blame] | 633 | streamConfigurations_.push_back({ res, androidFormat }); |
Jacopo Mondi | 843565c | 2020-09-01 15:34:13 +0200 | [diff] [blame] | 634 | |
| 635 | /* |
| 636 | * If the format is HAL_PIXEL_FORMAT_YCbCr_420_888 |
| 637 | * from which JPEG is produced, add an entry for |
| 638 | * the JPEG stream. |
| 639 | * |
| 640 | * \todo Wire the JPEG encoder to query the supported |
| 641 | * sizes provided a list of formats it can encode. |
| 642 | * |
| 643 | * \todo Support JPEG streams produced by the Camera |
| 644 | * natively. |
| 645 | */ |
| 646 | if (androidFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) |
| 647 | streamConfigurations_.push_back( |
| 648 | { res, HAL_PIXEL_FORMAT_BLOB }); |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
| 652 | LOG(HAL, Debug) << "Collected stream configuration map: "; |
| 653 | for (const auto &entry : streamConfigurations_) |
| 654 | LOG(HAL, Debug) << "{ " << entry.resolution.toString() << " - " |
Niklas Söderlund | 142a9ee | 2020-07-23 18:32:23 +0200 | [diff] [blame] | 655 | << utils::hex(entry.androidFormat) << " }"; |
Jacopo Mondi | 117588b | 2020-05-23 18:53:54 +0200 | [diff] [blame] | 656 | |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | /* |
| 661 | * Open a camera device. The static information on the camera shall have been |
| 662 | * initialized with a call to CameraDevice::initialize(). |
| 663 | */ |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 664 | int CameraDevice::open(const hw_module_t *hardwareModule) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 665 | { |
| 666 | int ret = camera_->acquire(); |
| 667 | if (ret) { |
| 668 | LOG(HAL, Error) << "Failed to acquire the camera"; |
| 669 | return ret; |
| 670 | } |
| 671 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 672 | /* Initialize the hw_device_t in the instance camera3_module_t. */ |
| 673 | camera3Device_.common.tag = HARDWARE_DEVICE_TAG; |
| 674 | camera3Device_.common.version = CAMERA_DEVICE_API_VERSION_3_3; |
| 675 | camera3Device_.common.module = (hw_module_t *)hardwareModule; |
| 676 | camera3Device_.common.close = hal_dev_close; |
| 677 | |
| 678 | /* |
| 679 | * The camera device operations. These actually implement |
| 680 | * the Android Camera HALv3 interface. |
| 681 | */ |
| 682 | camera3Device_.ops = &hal_dev_ops; |
| 683 | camera3Device_.priv = this; |
| 684 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | void CameraDevice::close() |
| 689 | { |
Jacopo Mondi | 6c4999e | 2020-10-03 16:06:34 +0200 | [diff] [blame] | 690 | streams_.clear(); |
| 691 | |
Jacopo Mondi | 4b1aa21 | 2020-10-06 17:56:50 +0200 | [diff] [blame] | 692 | worker_.stop(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 693 | camera_->stop(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 694 | camera_->release(); |
| 695 | |
| 696 | running_ = false; |
| 697 | } |
| 698 | |
| 699 | void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks) |
| 700 | { |
| 701 | callbacks_ = callbacks; |
| 702 | } |
| 703 | |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 704 | std::tuple<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize() |
| 705 | { |
| 706 | /* |
| 707 | * \todo Keep this in sync with the actual number of entries. |
Jacopo Mondi | e9c2875 | 2021-02-03 14:47:45 +0100 | [diff] [blame] | 708 | * Currently: 53 entries, 846 bytes of static metadata |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 709 | */ |
Jacopo Mondi | eec6c54 | 2020-12-09 18:16:11 +0100 | [diff] [blame] | 710 | uint32_t numEntries = 53; |
Jacopo Mondi | e9c2875 | 2021-02-03 14:47:45 +0100 | [diff] [blame] | 711 | uint32_t byteSize = 846; |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 712 | |
| 713 | /* |
| 714 | * Calculate space occupation in bytes for dynamically built metadata |
| 715 | * entries. |
| 716 | * |
Jacopo Mondi | 00982fb | 2021-02-04 16:57:55 +0100 | [diff] [blame] | 717 | * Each stream configuration entry requires 48 bytes: |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 718 | * 4 32bits integers for ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 719 | * 4 64bits integers for ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS |
| 720 | */ |
Niklas Söderlund | 3530614 | 2020-07-23 18:25:04 +0200 | [diff] [blame] | 721 | byteSize += streamConfigurations_.size() * 48; |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 722 | |
Jacopo Mondi | 9e80705 | 2021-02-04 15:32:00 +0100 | [diff] [blame] | 723 | /* |
| 724 | * 2 32bits integers for each HAL_PIXEL_FORMAT_BLOB for thumbnail sizes |
| 725 | * 2 32bits integers for the (0, 0) thumbnail size |
| 726 | * |
| 727 | * This is a worst case estimates as different configurations with the |
| 728 | * same aspect ratio will generate the same size. |
| 729 | */ |
| 730 | for (const auto &entry : streamConfigurations_) { |
| 731 | if (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB) |
| 732 | continue; |
| 733 | |
| 734 | byteSize += 8; |
| 735 | } |
| 736 | byteSize += 8; |
| 737 | |
Laurent Pinchart | 7a88b21 | 2020-06-10 00:07:59 +0300 | [diff] [blame] | 738 | return std::make_tuple(numEntries, byteSize); |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 739 | } |
| 740 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 741 | /* |
| 742 | * Return static information for the camera. |
| 743 | */ |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 744 | const camera_metadata_t *CameraDevice::getStaticMetadata() |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 745 | { |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 746 | if (staticMetadata_) |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 747 | return staticMetadata_->get(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 748 | |
| 749 | /* |
| 750 | * The here reported metadata are enough to implement a basic capture |
| 751 | * example application, but a real camera implementation will require |
| 752 | * more. |
| 753 | */ |
Jacopo Mondi | a80d381 | 2020-05-26 12:31:35 +0200 | [diff] [blame] | 754 | uint32_t numEntries; |
| 755 | uint32_t byteSize; |
| 756 | std::tie(numEntries, byteSize) = calculateStaticMetadataSize(); |
| 757 | staticMetadata_ = new CameraMetadata(numEntries, byteSize); |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 758 | if (!staticMetadata_->isValid()) { |
| 759 | LOG(HAL, Error) << "Failed to allocate static metadata"; |
| 760 | delete staticMetadata_; |
| 761 | staticMetadata_ = nullptr; |
| 762 | return nullptr; |
| 763 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 764 | |
Jacopo Mondi | 5d91c8d | 2020-09-23 09:41:52 +0200 | [diff] [blame] | 765 | const ControlInfoMap &controlsInfo = camera_->controls(); |
Jacopo Mondi | 1889cdc | 2020-11-06 16:08:16 +0100 | [diff] [blame] | 766 | const ControlList &properties = camera_->properties(); |
Jacopo Mondi | 5d91c8d | 2020-09-23 09:41:52 +0200 | [diff] [blame] | 767 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 768 | /* Color correction static metadata. */ |
Jacopo Mondi | 6333686 | 2020-10-08 16:18:26 +0200 | [diff] [blame] | 769 | { |
Jacopo Mondi | c268e4f | 2020-12-01 15:42:15 +0100 | [diff] [blame] | 770 | std::vector<uint8_t> data; |
| 771 | data.reserve(3); |
Jacopo Mondi | 6333686 | 2020-10-08 16:18:26 +0200 | [diff] [blame] | 772 | const auto &infoMap = controlsInfo.find(&controls::draft::ColorCorrectionAberrationMode); |
| 773 | if (infoMap != controlsInfo.end()) { |
| 774 | for (const auto &value : infoMap->second.values()) |
| 775 | data.push_back(value.get<int32_t>()); |
| 776 | } else { |
| 777 | data.push_back(ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF); |
| 778 | } |
| 779 | staticMetadata_->addEntry(ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, |
| 780 | data.data(), data.size()); |
| 781 | } |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 782 | |
| 783 | /* Control static metadata. */ |
| 784 | std::vector<uint8_t> aeAvailableAntiBandingModes = { |
| 785 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF, |
| 786 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_50HZ, |
| 787 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_60HZ, |
| 788 | ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO, |
| 789 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 790 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, |
| 791 | aeAvailableAntiBandingModes.data(), |
| 792 | aeAvailableAntiBandingModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 793 | |
| 794 | std::vector<uint8_t> aeAvailableModes = { |
| 795 | ANDROID_CONTROL_AE_MODE_ON, |
| 796 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 797 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_MODES, |
| 798 | aeAvailableModes.data(), |
| 799 | aeAvailableModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 800 | |
| 801 | std::vector<int32_t> availableAeFpsTarget = { |
| 802 | 15, 30, |
| 803 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 804 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, |
| 805 | availableAeFpsTarget.data(), |
| 806 | availableAeFpsTarget.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 807 | |
| 808 | std::vector<int32_t> aeCompensationRange = { |
| 809 | 0, 0, |
| 810 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 811 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_COMPENSATION_RANGE, |
| 812 | aeCompensationRange.data(), |
| 813 | aeCompensationRange.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 814 | |
| 815 | const camera_metadata_rational_t aeCompensationStep[] = { |
| 816 | { 0, 1 } |
| 817 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 818 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_COMPENSATION_STEP, |
| 819 | aeCompensationStep, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 820 | |
| 821 | std::vector<uint8_t> availableAfModes = { |
| 822 | ANDROID_CONTROL_AF_MODE_OFF, |
| 823 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 824 | staticMetadata_->addEntry(ANDROID_CONTROL_AF_AVAILABLE_MODES, |
| 825 | availableAfModes.data(), |
| 826 | availableAfModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 827 | |
| 828 | std::vector<uint8_t> availableEffects = { |
| 829 | ANDROID_CONTROL_EFFECT_MODE_OFF, |
| 830 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 831 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_EFFECTS, |
| 832 | availableEffects.data(), |
| 833 | availableEffects.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 834 | |
| 835 | std::vector<uint8_t> availableSceneModes = { |
| 836 | ANDROID_CONTROL_SCENE_MODE_DISABLED, |
| 837 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 838 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_SCENE_MODES, |
| 839 | availableSceneModes.data(), |
| 840 | availableSceneModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 841 | |
| 842 | std::vector<uint8_t> availableStabilizationModes = { |
| 843 | ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF, |
| 844 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 845 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, |
| 846 | availableStabilizationModes.data(), |
| 847 | availableStabilizationModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 848 | |
Jacopo Mondi | af088b8 | 2021-01-04 18:26:28 +0100 | [diff] [blame] | 849 | /* |
| 850 | * \todo Inspect the Camera capabilities to report the available |
| 851 | * AWB modes. Default to AUTO as CTS tests require it. |
| 852 | */ |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 853 | std::vector<uint8_t> availableAwbModes = { |
Jacopo Mondi | af088b8 | 2021-01-04 18:26:28 +0100 | [diff] [blame] | 854 | ANDROID_CONTROL_AWB_MODE_AUTO, |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 855 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 856 | staticMetadata_->addEntry(ANDROID_CONTROL_AWB_AVAILABLE_MODES, |
| 857 | availableAwbModes.data(), |
| 858 | availableAwbModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 859 | |
| 860 | std::vector<int32_t> availableMaxRegions = { |
| 861 | 0, 0, 0, |
| 862 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 863 | staticMetadata_->addEntry(ANDROID_CONTROL_MAX_REGIONS, |
| 864 | availableMaxRegions.data(), |
| 865 | availableMaxRegions.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 866 | |
| 867 | std::vector<uint8_t> sceneModesOverride = { |
| 868 | ANDROID_CONTROL_AE_MODE_ON, |
| 869 | ANDROID_CONTROL_AWB_MODE_AUTO, |
Jacopo Mondi | f266c0e | 2021-02-03 16:34:40 +0100 | [diff] [blame^] | 870 | ANDROID_CONTROL_AF_MODE_OFF, |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 871 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 872 | staticMetadata_->addEntry(ANDROID_CONTROL_SCENE_MODE_OVERRIDES, |
| 873 | sceneModesOverride.data(), |
| 874 | sceneModesOverride.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 875 | |
| 876 | uint8_t aeLockAvailable = ANDROID_CONTROL_AE_LOCK_AVAILABLE_FALSE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 877 | staticMetadata_->addEntry(ANDROID_CONTROL_AE_LOCK_AVAILABLE, |
| 878 | &aeLockAvailable, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 879 | |
| 880 | uint8_t awbLockAvailable = ANDROID_CONTROL_AWB_LOCK_AVAILABLE_FALSE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 881 | staticMetadata_->addEntry(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, |
| 882 | &awbLockAvailable, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 883 | |
| 884 | char availableControlModes = ANDROID_CONTROL_MODE_AUTO; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 885 | staticMetadata_->addEntry(ANDROID_CONTROL_AVAILABLE_MODES, |
| 886 | &availableControlModes, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 887 | |
| 888 | /* JPEG static metadata. */ |
Jacopo Mondi | 9e80705 | 2021-02-04 15:32:00 +0100 | [diff] [blame] | 889 | |
| 890 | /* |
| 891 | * Create the list of supported thumbnail sizes by inspecting the |
| 892 | * available JPEG resolutions collected in streamConfigurations_ and |
| 893 | * generate one entry for each aspect ratio. |
| 894 | * |
| 895 | * The JPEG thumbnailer can freely scale, so pick an arbitrary |
| 896 | * (160, 160) size as the bounding rectangle, which is then cropped to |
| 897 | * the different supported aspect ratios. |
| 898 | */ |
| 899 | constexpr Size maxJpegThumbnail(160, 160); |
| 900 | std::vector<Size> thumbnailSizes; |
| 901 | thumbnailSizes.push_back({ 0, 0 }); |
| 902 | for (const auto &entry : streamConfigurations_) { |
| 903 | if (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB) |
| 904 | continue; |
| 905 | |
| 906 | Size thumbnailSize = maxJpegThumbnail |
| 907 | .boundedToAspectRatio({ entry.resolution.width, |
| 908 | entry.resolution.height }); |
| 909 | thumbnailSizes.push_back(thumbnailSize); |
| 910 | } |
| 911 | |
| 912 | std::sort(thumbnailSizes.begin(), thumbnailSizes.end()); |
| 913 | auto last = std::unique(thumbnailSizes.begin(), thumbnailSizes.end()); |
| 914 | thumbnailSizes.erase(last, thumbnailSizes.end()); |
| 915 | |
| 916 | /* Transform sizes in to a list of integers that can be consumed. */ |
| 917 | std::vector<int32_t> thumbnailEntries; |
| 918 | thumbnailEntries.reserve(thumbnailSizes.size() * 2); |
| 919 | for (const auto &size : thumbnailSizes) { |
| 920 | thumbnailEntries.push_back(size.width); |
| 921 | thumbnailEntries.push_back(size.height); |
| 922 | } |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 923 | staticMetadata_->addEntry(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
Jacopo Mondi | 9e80705 | 2021-02-04 15:32:00 +0100 | [diff] [blame] | 924 | thumbnailEntries.data(), thumbnailEntries.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 925 | |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 926 | /* |
| 927 | * \todo Calculate the maximum JPEG buffer size by asking the encoder |
| 928 | * giving the maximum frame size required. |
| 929 | */ |
| 930 | staticMetadata_->addEntry(ANDROID_JPEG_MAX_SIZE, &maxJpegBufferSize_, 1); |
| 931 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 932 | /* Sensor static metadata. */ |
Jacopo Mondi | cda41ff | 2020-12-30 17:18:51 +0100 | [diff] [blame] | 933 | { |
Jacopo Mondi | 1889cdc | 2020-11-06 16:08:16 +0100 | [diff] [blame] | 934 | const Size &size = |
Jacopo Mondi | 0ed0532 | 2020-12-23 18:34:34 +0100 | [diff] [blame] | 935 | properties.get(properties::PixelArraySize); |
Jacopo Mondi | 1889cdc | 2020-11-06 16:08:16 +0100 | [diff] [blame] | 936 | std::vector<int32_t> data{ |
| 937 | static_cast<int32_t>(size.width), |
| 938 | static_cast<int32_t>(size.height), |
| 939 | }; |
| 940 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, |
| 941 | data.data(), data.size()); |
| 942 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 943 | |
Jacopo Mondi | cda41ff | 2020-12-30 17:18:51 +0100 | [diff] [blame] | 944 | { |
Jacopo Mondi | 1889cdc | 2020-11-06 16:08:16 +0100 | [diff] [blame] | 945 | const Span<const Rectangle> &rects = |
Jacopo Mondi | 0ed0532 | 2020-12-23 18:34:34 +0100 | [diff] [blame] | 946 | properties.get(properties::PixelArrayActiveAreas); |
Jacopo Mondi | 1889cdc | 2020-11-06 16:08:16 +0100 | [diff] [blame] | 947 | std::vector<int32_t> data{ |
| 948 | static_cast<int32_t>(rects[0].x), |
| 949 | static_cast<int32_t>(rects[0].y), |
| 950 | static_cast<int32_t>(rects[0].width), |
| 951 | static_cast<int32_t>(rects[0].height), |
| 952 | }; |
| 953 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, |
| 954 | data.data(), data.size()); |
| 955 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 956 | |
| 957 | int32_t sensitivityRange[] = { |
| 958 | 32, 2400, |
| 959 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 960 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_SENSITIVITY_RANGE, |
| 961 | &sensitivityRange, 2); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 962 | |
Jacopo Mondi | cb35ed2 | 2020-12-18 16:28:43 +0100 | [diff] [blame] | 963 | /* Report the color filter arrangement if the camera reports it. */ |
| 964 | if (properties.contains(properties::draft::ColorFilterArrangement)) { |
| 965 | uint8_t filterArr = properties.get(properties::draft::ColorFilterArrangement); |
| 966 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, |
| 967 | &filterArr, 1); |
| 968 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 969 | |
Jacopo Mondi | 753d753 | 2021-01-02 12:34:06 +0100 | [diff] [blame] | 970 | const auto &exposureInfo = controlsInfo.find(&controls::ExposureTime); |
| 971 | if (exposureInfo != controlsInfo.end()) { |
| 972 | int64_t exposureTimeRange[2] = { |
| 973 | exposureInfo->second.min().get<int32_t>() * 1000LL, |
| 974 | exposureInfo->second.max().get<int32_t>() * 1000LL, |
| 975 | }; |
| 976 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE, |
| 977 | &exposureTimeRange, 2); |
| 978 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 979 | |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 980 | staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION, &orientation_, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 981 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 982 | std::vector<int32_t> testPatterModes = { |
| 983 | ANDROID_SENSOR_TEST_PATTERN_MODE_OFF, |
| 984 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 985 | staticMetadata_->addEntry(ANDROID_SENSOR_AVAILABLE_TEST_PATTERN_MODES, |
| 986 | testPatterModes.data(), |
| 987 | testPatterModes.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 988 | |
| 989 | std::vector<float> physicalSize = { |
| 990 | 2592, 1944, |
| 991 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 992 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
| 993 | physicalSize.data(), |
| 994 | physicalSize.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 995 | |
| 996 | uint8_t timestampSource = ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 997 | staticMetadata_->addEntry(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, |
| 998 | ×tampSource, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 999 | |
| 1000 | /* Statistics static metadata. */ |
| 1001 | uint8_t faceDetectMode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1002 | staticMetadata_->addEntry(ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, |
| 1003 | &faceDetectMode, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1004 | |
| 1005 | int32_t maxFaceCount = 0; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1006 | staticMetadata_->addEntry(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, |
| 1007 | &maxFaceCount, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1008 | |
Jacopo Mondi | 2c61850 | 2020-10-08 16:47:36 +0200 | [diff] [blame] | 1009 | { |
Jacopo Mondi | c268e4f | 2020-12-01 15:42:15 +0100 | [diff] [blame] | 1010 | std::vector<uint8_t> data; |
| 1011 | data.reserve(2); |
Jacopo Mondi | 2c61850 | 2020-10-08 16:47:36 +0200 | [diff] [blame] | 1012 | const auto &infoMap = controlsInfo.find(&controls::draft::LensShadingMapMode); |
| 1013 | if (infoMap != controlsInfo.end()) { |
| 1014 | for (const auto &value : infoMap->second.values()) |
| 1015 | data.push_back(value.get<int32_t>()); |
| 1016 | } else { |
| 1017 | data.push_back(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF); |
| 1018 | } |
| 1019 | staticMetadata_->addEntry(ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES, |
| 1020 | data.data(), data.size()); |
| 1021 | } |
| 1022 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1023 | /* Sync static metadata. */ |
| 1024 | int32_t maxLatency = ANDROID_SYNC_MAX_LATENCY_UNKNOWN; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1025 | staticMetadata_->addEntry(ANDROID_SYNC_MAX_LATENCY, &maxLatency, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1026 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1027 | /* Flash static metadata. */ |
| 1028 | char flashAvailable = ANDROID_FLASH_INFO_AVAILABLE_FALSE; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1029 | staticMetadata_->addEntry(ANDROID_FLASH_INFO_AVAILABLE, |
| 1030 | &flashAvailable, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1031 | |
| 1032 | /* Lens static metadata. */ |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1033 | std::vector<float> lensApertures = { |
| 1034 | 2.53 / 100, |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1035 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1036 | staticMetadata_->addEntry(ANDROID_LENS_INFO_AVAILABLE_APERTURES, |
| 1037 | lensApertures.data(), |
| 1038 | lensApertures.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1039 | |
Jacopo Mondi | 64f4f66 | 2020-05-25 16:08:22 +0200 | [diff] [blame] | 1040 | uint8_t lensFacing; |
| 1041 | switch (facing_) { |
| 1042 | default: |
| 1043 | case CAMERA_FACING_FRONT: |
| 1044 | lensFacing = ANDROID_LENS_FACING_FRONT; |
| 1045 | break; |
| 1046 | case CAMERA_FACING_BACK: |
| 1047 | lensFacing = ANDROID_LENS_FACING_BACK; |
| 1048 | break; |
| 1049 | case CAMERA_FACING_EXTERNAL: |
| 1050 | lensFacing = ANDROID_LENS_FACING_EXTERNAL; |
| 1051 | break; |
Jacopo Mondi | 857a216 | 2019-11-20 17:00:49 +0100 | [diff] [blame] | 1052 | } |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1053 | staticMetadata_->addEntry(ANDROID_LENS_FACING, &lensFacing, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1054 | |
| 1055 | std::vector<float> lensFocalLenghts = { |
| 1056 | 1, |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1057 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1058 | staticMetadata_->addEntry(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
| 1059 | lensFocalLenghts.data(), |
| 1060 | lensFocalLenghts.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1061 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1062 | std::vector<uint8_t> opticalStabilizations = { |
| 1063 | ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF, |
| 1064 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1065 | staticMetadata_->addEntry(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, |
| 1066 | opticalStabilizations.data(), |
| 1067 | opticalStabilizations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1068 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1069 | float hypeFocalDistance = 0; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1070 | staticMetadata_->addEntry(ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE, |
| 1071 | &hypeFocalDistance, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1072 | |
| 1073 | float minFocusDistance = 0; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1074 | staticMetadata_->addEntry(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, |
| 1075 | &minFocusDistance, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1076 | |
| 1077 | /* Noise reduction modes. */ |
Jacopo Mondi | 0b5fecc | 2020-10-08 16:01:35 +0200 | [diff] [blame] | 1078 | { |
Jacopo Mondi | c268e4f | 2020-12-01 15:42:15 +0100 | [diff] [blame] | 1079 | std::vector<uint8_t> data; |
| 1080 | data.reserve(5); |
Jacopo Mondi | 0b5fecc | 2020-10-08 16:01:35 +0200 | [diff] [blame] | 1081 | const auto &infoMap = controlsInfo.find(&controls::draft::NoiseReductionMode); |
| 1082 | if (infoMap != controlsInfo.end()) { |
| 1083 | for (const auto &value : infoMap->second.values()) |
| 1084 | data.push_back(value.get<int32_t>()); |
| 1085 | } else { |
| 1086 | data.push_back(ANDROID_NOISE_REDUCTION_MODE_OFF); |
| 1087 | } |
| 1088 | staticMetadata_->addEntry(ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, |
| 1089 | data.data(), data.size()); |
| 1090 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1091 | |
| 1092 | /* Scaler static metadata. */ |
Jacopo Mondi | 31a1a62 | 2021-01-03 19:57:36 +0100 | [diff] [blame] | 1093 | { |
| 1094 | /* |
| 1095 | * \todo The digital zoom factor is a property that depends |
| 1096 | * on the desired output configuration and the sensor frame size |
| 1097 | * input to the ISP. This information is not available to the |
| 1098 | * Android HAL, not at initialization time at least. |
| 1099 | * |
| 1100 | * As a workaround rely on pipeline handlers initializing the |
| 1101 | * ScalerCrop control with the camera default configuration and |
| 1102 | * use the maximum and minimum crop rectangles to calculate the |
| 1103 | * digital zoom factor. |
| 1104 | */ |
| 1105 | const auto info = controlsInfo.find(&controls::ScalerCrop); |
| 1106 | Rectangle min = info->second.min().get<Rectangle>(); |
| 1107 | Rectangle max = info->second.max().get<Rectangle>(); |
| 1108 | float maxZoom = std::min(1.0f * max.width / min.width, |
| 1109 | 1.0f * max.height / min.height); |
| 1110 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, |
| 1111 | &maxZoom, 1); |
| 1112 | } |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1113 | |
Jacopo Mondi | bde7b98 | 2020-05-25 17:18:28 +0200 | [diff] [blame] | 1114 | std::vector<uint32_t> availableStreamConfigurations; |
| 1115 | availableStreamConfigurations.reserve(streamConfigurations_.size() * 4); |
| 1116 | for (const auto &entry : streamConfigurations_) { |
Niklas Söderlund | 142a9ee | 2020-07-23 18:32:23 +0200 | [diff] [blame] | 1117 | availableStreamConfigurations.push_back(entry.androidFormat); |
Jacopo Mondi | bde7b98 | 2020-05-25 17:18:28 +0200 | [diff] [blame] | 1118 | availableStreamConfigurations.push_back(entry.resolution.width); |
| 1119 | availableStreamConfigurations.push_back(entry.resolution.height); |
| 1120 | availableStreamConfigurations.push_back( |
| 1121 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT); |
| 1122 | } |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1123 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, |
| 1124 | availableStreamConfigurations.data(), |
| 1125 | availableStreamConfigurations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1126 | |
| 1127 | std::vector<int64_t> availableStallDurations = { |
| 1128 | ANDROID_SCALER_AVAILABLE_FORMATS_BLOB, 2560, 1920, 33333333, |
| 1129 | }; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1130 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_STALL_DURATIONS, |
| 1131 | availableStallDurations.data(), |
| 1132 | availableStallDurations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1133 | |
Jacopo Mondi | bde7b98 | 2020-05-25 17:18:28 +0200 | [diff] [blame] | 1134 | /* \todo Collect the minimum frame duration from the camera. */ |
| 1135 | std::vector<int64_t> minFrameDurations; |
| 1136 | minFrameDurations.reserve(streamConfigurations_.size() * 4); |
| 1137 | for (const auto &entry : streamConfigurations_) { |
Niklas Söderlund | 142a9ee | 2020-07-23 18:32:23 +0200 | [diff] [blame] | 1138 | minFrameDurations.push_back(entry.androidFormat); |
Jacopo Mondi | bde7b98 | 2020-05-25 17:18:28 +0200 | [diff] [blame] | 1139 | minFrameDurations.push_back(entry.resolution.width); |
| 1140 | minFrameDurations.push_back(entry.resolution.height); |
| 1141 | minFrameDurations.push_back(33333333); |
| 1142 | } |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1143 | staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, |
| 1144 | minFrameDurations.data(), |
| 1145 | minFrameDurations.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1146 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1147 | uint8_t croppingType = ANDROID_SCALER_CROPPING_TYPE_CENTER_ONLY; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1148 | staticMetadata_->addEntry(ANDROID_SCALER_CROPPING_TYPE, &croppingType, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1149 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1150 | /* Info static metadata. */ |
| 1151 | uint8_t supportedHWLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1152 | staticMetadata_->addEntry(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, |
| 1153 | &supportedHWLevel, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1154 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1155 | /* Request static metadata. */ |
| 1156 | int32_t partialResultCount = 1; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1157 | staticMetadata_->addEntry(ANDROID_REQUEST_PARTIAL_RESULT_COUNT, |
| 1158 | &partialResultCount, 1); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1159 | |
Jacopo Mondi | 5d91c8d | 2020-09-23 09:41:52 +0200 | [diff] [blame] | 1160 | { |
| 1161 | /* Default the value to 2 if not reported by the camera. */ |
| 1162 | uint8_t maxPipelineDepth = 2; |
| 1163 | const auto &infoMap = controlsInfo.find(&controls::draft::PipelineDepth); |
| 1164 | if (infoMap != controlsInfo.end()) |
| 1165 | maxPipelineDepth = infoMap->second.max().get<int32_t>(); |
| 1166 | staticMetadata_->addEntry(ANDROID_REQUEST_PIPELINE_MAX_DEPTH, |
| 1167 | &maxPipelineDepth, 1); |
| 1168 | } |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1169 | |
Niklas Söderlund | a2a6f95 | 2020-07-21 00:16:02 +0200 | [diff] [blame] | 1170 | /* LIMITED does not support reprocessing. */ |
| 1171 | uint32_t maxNumInputStreams = 0; |
| 1172 | staticMetadata_->addEntry(ANDROID_REQUEST_MAX_NUM_INPUT_STREAMS, |
| 1173 | &maxNumInputStreams, 1); |
| 1174 | |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1175 | std::vector<uint8_t> availableCapabilities = { |
| 1176 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE, |
| 1177 | }; |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame] | 1178 | |
| 1179 | /* Report if camera supports RAW. */ |
Jacopo Mondi | eec6c54 | 2020-12-09 18:16:11 +0100 | [diff] [blame] | 1180 | bool rawStreamAvailable = false; |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame] | 1181 | std::unique_ptr<CameraConfiguration> cameraConfig = |
Niklas Söderlund | dbe8d27 | 2020-05-26 15:04:47 +0200 | [diff] [blame] | 1182 | camera_->generateConfiguration({ StreamRole::Raw }); |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame] | 1183 | if (cameraConfig && !cameraConfig->empty()) { |
| 1184 | const PixelFormatInfo &info = |
| 1185 | PixelFormatInfo::info(cameraConfig->at(0).pixelFormat); |
Niklas Söderlund | 35de31e | 2020-12-31 00:11:59 +0100 | [diff] [blame] | 1186 | /* Only advertise RAW support if RAW16 is possible. */ |
| 1187 | if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW && |
| 1188 | info.bitsPerPixel == 16) { |
Jacopo Mondi | eec6c54 | 2020-12-09 18:16:11 +0100 | [diff] [blame] | 1189 | rawStreamAvailable = true; |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame] | 1190 | availableCapabilities.push_back(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_RAW); |
Jacopo Mondi | eec6c54 | 2020-12-09 18:16:11 +0100 | [diff] [blame] | 1191 | } |
Niklas Söderlund | 7876d63 | 2020-07-21 00:16:24 +0200 | [diff] [blame] | 1192 | } |
| 1193 | |
Jacopo Mondi | eec6c54 | 2020-12-09 18:16:11 +0100 | [diff] [blame] | 1194 | /* Number of { RAW, YUV, JPEG } supported output streams */ |
| 1195 | int32_t numOutStreams[] = { rawStreamAvailable, 2, 1 }; |
| 1196 | staticMetadata_->addEntry(ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS, |
| 1197 | &numOutStreams, 3); |
| 1198 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1199 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, |
| 1200 | availableCapabilities.data(), |
| 1201 | availableCapabilities.size()); |
Jacopo Mondi | b4893fc | 2019-09-04 16:18:18 +0200 | [diff] [blame] | 1202 | |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1203 | std::vector<int32_t> availableCharacteristicsKeys = { |
| 1204 | ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, |
| 1205 | ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, |
| 1206 | ANDROID_CONTROL_AE_AVAILABLE_MODES, |
| 1207 | ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, |
| 1208 | ANDROID_CONTROL_AE_COMPENSATION_RANGE, |
| 1209 | ANDROID_CONTROL_AE_COMPENSATION_STEP, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1210 | ANDROID_CONTROL_AE_LOCK_AVAILABLE, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1211 | ANDROID_CONTROL_AF_AVAILABLE_MODES, |
| 1212 | ANDROID_CONTROL_AVAILABLE_EFFECTS, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1213 | ANDROID_CONTROL_AVAILABLE_MODES, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1214 | ANDROID_CONTROL_AVAILABLE_SCENE_MODES, |
| 1215 | ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, |
| 1216 | ANDROID_CONTROL_AWB_AVAILABLE_MODES, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1217 | ANDROID_CONTROL_AWB_LOCK_AVAILABLE, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1218 | ANDROID_CONTROL_MAX_REGIONS, |
| 1219 | ANDROID_CONTROL_SCENE_MODE_OVERRIDES, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1220 | ANDROID_FLASH_INFO_AVAILABLE, |
| 1221 | ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1222 | ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1223 | ANDROID_JPEG_MAX_SIZE, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1224 | ANDROID_LENS_FACING, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1225 | ANDROID_LENS_INFO_AVAILABLE_APERTURES, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1226 | ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
| 1227 | ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, |
| 1228 | ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE, |
| 1229 | ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, |
| 1230 | ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1231 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES, |
| 1232 | ANDROID_REQUEST_MAX_NUM_INPUT_STREAMS, |
| 1233 | ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1234 | ANDROID_REQUEST_PARTIAL_RESULT_COUNT, |
| 1235 | ANDROID_REQUEST_PIPELINE_MAX_DEPTH, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1236 | ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, |
| 1237 | ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, |
| 1238 | ANDROID_SCALER_AVAILABLE_STALL_DURATIONS, |
| 1239 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, |
| 1240 | ANDROID_SCALER_CROPPING_TYPE, |
| 1241 | ANDROID_SENSOR_AVAILABLE_TEST_PATTERN_MODES, |
| 1242 | ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, |
| 1243 | ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, |
| 1244 | ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE, |
| 1245 | ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
| 1246 | ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, |
| 1247 | ANDROID_SENSOR_INFO_SENSITIVITY_RANGE, |
| 1248 | ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, |
| 1249 | ANDROID_SENSOR_ORIENTATION, |
| 1250 | ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, |
| 1251 | ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, |
| 1252 | ANDROID_SYNC_MAX_LATENCY, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1253 | }; |
| 1254 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, |
| 1255 | availableCharacteristicsKeys.data(), |
| 1256 | availableCharacteristicsKeys.size()); |
| 1257 | |
| 1258 | std::vector<int32_t> availableRequestKeys = { |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1259 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 1260 | ANDROID_CONTROL_AE_ANTIBANDING_MODE, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1261 | ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1262 | ANDROID_CONTROL_AE_LOCK, |
| 1263 | ANDROID_CONTROL_AE_MODE, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1264 | ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
Jacopo Mondi | 09b1d0f | 2020-07-24 16:10:23 +0200 | [diff] [blame] | 1265 | ANDROID_CONTROL_AE_TARGET_FPS_RANGE, |
Jacopo Mondi | da4b325 | 2021-01-29 14:21:56 +0100 | [diff] [blame] | 1266 | ANDROID_CONTROL_AF_MODE, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1267 | ANDROID_CONTROL_AF_TRIGGER, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1268 | ANDROID_CONTROL_AWB_LOCK, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1269 | ANDROID_CONTROL_AWB_MODE, |
| 1270 | ANDROID_CONTROL_CAPTURE_INTENT, |
Jacopo Mondi | da4b325 | 2021-01-29 14:21:56 +0100 | [diff] [blame] | 1271 | ANDROID_CONTROL_EFFECT_MODE, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1272 | ANDROID_CONTROL_MODE, |
Jacopo Mondi | da4b325 | 2021-01-29 14:21:56 +0100 | [diff] [blame] | 1273 | ANDROID_CONTROL_SCENE_MODE, |
| 1274 | ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1275 | ANDROID_FLASH_MODE, |
Jacopo Mondi | da4b325 | 2021-01-29 14:21:56 +0100 | [diff] [blame] | 1276 | ANDROID_JPEG_ORIENTATION, |
| 1277 | ANDROID_JPEG_QUALITY, |
| 1278 | ANDROID_JPEG_THUMBNAIL_QUALITY, |
| 1279 | ANDROID_JPEG_THUMBNAIL_SIZE, |
Jacopo Mondi | 09b1d0f | 2020-07-24 16:10:23 +0200 | [diff] [blame] | 1280 | ANDROID_LENS_APERTURE, |
| 1281 | ANDROID_LENS_OPTICAL_STABILIZATION_MODE, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1282 | ANDROID_NOISE_REDUCTION_MODE, |
Jacopo Mondi | da4b325 | 2021-01-29 14:21:56 +0100 | [diff] [blame] | 1283 | ANDROID_SCALER_CROP_REGION, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1284 | ANDROID_STATISTICS_FACE_DETECT_MODE |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1285 | }; |
| 1286 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS, |
| 1287 | availableRequestKeys.data(), |
| 1288 | availableRequestKeys.size()); |
| 1289 | |
| 1290 | std::vector<int32_t> availableResultKeys = { |
Jacopo Mondi | 520c366 | 2021-02-03 14:44:34 +0100 | [diff] [blame] | 1291 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 1292 | ANDROID_CONTROL_AE_ANTIBANDING_MODE, |
Jacopo Mondi | e9c2875 | 2021-02-03 14:47:45 +0100 | [diff] [blame] | 1293 | ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1294 | ANDROID_CONTROL_AE_LOCK, |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 1295 | ANDROID_CONTROL_AE_MODE, |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 1296 | ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
| 1297 | ANDROID_CONTROL_AE_STATE, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1298 | ANDROID_CONTROL_AE_TARGET_FPS_RANGE, |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 1299 | ANDROID_CONTROL_AF_MODE, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1300 | ANDROID_CONTROL_AF_STATE, |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 1301 | ANDROID_CONTROL_AF_TRIGGER, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1302 | ANDROID_CONTROL_AWB_LOCK, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1303 | ANDROID_CONTROL_AWB_MODE, |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 1304 | ANDROID_CONTROL_AWB_STATE, |
| 1305 | ANDROID_CONTROL_CAPTURE_INTENT, |
| 1306 | ANDROID_CONTROL_EFFECT_MODE, |
| 1307 | ANDROID_CONTROL_MODE, |
| 1308 | ANDROID_CONTROL_SCENE_MODE, |
| 1309 | ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, |
| 1310 | ANDROID_FLASH_MODE, |
| 1311 | ANDROID_FLASH_STATE, |
Paul Elder | abfabdd | 2021-01-23 13:54:28 +0900 | [diff] [blame] | 1312 | ANDROID_JPEG_GPS_COORDINATES, |
| 1313 | ANDROID_JPEG_GPS_PROCESSING_METHOD, |
| 1314 | ANDROID_JPEG_GPS_TIMESTAMP, |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1315 | ANDROID_JPEG_ORIENTATION, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1316 | ANDROID_JPEG_QUALITY, |
| 1317 | ANDROID_JPEG_SIZE, |
Paul Elder | 1264628 | 2021-01-23 13:56:01 +0900 | [diff] [blame] | 1318 | ANDROID_JPEG_THUMBNAIL_QUALITY, |
| 1319 | ANDROID_JPEG_THUMBNAIL_SIZE, |
Jacopo Mondi | 6741ab8 | 2021-01-29 14:15:17 +0100 | [diff] [blame] | 1320 | ANDROID_LENS_APERTURE, |
| 1321 | ANDROID_LENS_FOCAL_LENGTH, |
| 1322 | ANDROID_LENS_OPTICAL_STABILIZATION_MODE, |
| 1323 | ANDROID_LENS_STATE, |
| 1324 | ANDROID_NOISE_REDUCTION_MODE, |
| 1325 | ANDROID_REQUEST_PIPELINE_DEPTH, |
| 1326 | ANDROID_SCALER_CROP_REGION, |
| 1327 | ANDROID_SENSOR_EXPOSURE_TIME, |
| 1328 | ANDROID_SENSOR_ROLLING_SHUTTER_SKEW, |
| 1329 | ANDROID_SENSOR_TIMESTAMP, |
| 1330 | ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 1331 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, |
| 1332 | ANDROID_STATISTICS_SCENE_FLICKER, |
Jacopo Mondi | 19f85f4 | 2019-09-04 16:18:25 +0200 | [diff] [blame] | 1333 | }; |
| 1334 | staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_RESULT_KEYS, |
| 1335 | availableResultKeys.data(), |
| 1336 | availableResultKeys.size()); |
| 1337 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1338 | if (!staticMetadata_->isValid()) { |
| 1339 | LOG(HAL, Error) << "Failed to construct static metadata"; |
| 1340 | delete staticMetadata_; |
| 1341 | staticMetadata_ = nullptr; |
| 1342 | return nullptr; |
| 1343 | } |
| 1344 | |
| 1345 | return staticMetadata_->get(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1346 | } |
| 1347 | |
Jacopo Mondi | 8a02d44 | 2020-07-24 15:47:50 +0200 | [diff] [blame] | 1348 | CameraMetadata *CameraDevice::requestTemplatePreview() |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1349 | { |
Jacopo Mondi | 6370347 | 2019-09-04 16:18:22 +0200 | [diff] [blame] | 1350 | /* |
| 1351 | * \todo Keep this in sync with the actual number of entries. |
Jacopo Mondi | 09b1d0f | 2020-07-24 16:10:23 +0200 | [diff] [blame] | 1352 | * Currently: 20 entries, 35 bytes |
Jacopo Mondi | 6370347 | 2019-09-04 16:18:22 +0200 | [diff] [blame] | 1353 | */ |
Jacopo Mondi | 09b1d0f | 2020-07-24 16:10:23 +0200 | [diff] [blame] | 1354 | CameraMetadata *requestTemplate = new CameraMetadata(20, 35); |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1355 | if (!requestTemplate->isValid()) { |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1356 | delete requestTemplate; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1357 | return nullptr; |
| 1358 | } |
| 1359 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1360 | uint8_t aeMode = ANDROID_CONTROL_AE_MODE_ON; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1361 | requestTemplate->addEntry(ANDROID_CONTROL_AE_MODE, |
| 1362 | &aeMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1363 | |
| 1364 | int32_t aeExposureCompensation = 0; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1365 | requestTemplate->addEntry(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
| 1366 | &aeExposureCompensation, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1367 | |
| 1368 | uint8_t aePrecaptureTrigger = ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1369 | requestTemplate->addEntry(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
| 1370 | &aePrecaptureTrigger, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1371 | |
| 1372 | uint8_t aeLock = ANDROID_CONTROL_AE_LOCK_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1373 | requestTemplate->addEntry(ANDROID_CONTROL_AE_LOCK, |
| 1374 | &aeLock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1375 | |
Jacopo Mondi | 09b1d0f | 2020-07-24 16:10:23 +0200 | [diff] [blame] | 1376 | std::vector<int32_t> aeFpsTarget = { |
| 1377 | 15, 30, |
| 1378 | }; |
| 1379 | requestTemplate->addEntry(ANDROID_CONTROL_AE_TARGET_FPS_RANGE, |
| 1380 | aeFpsTarget.data(), |
| 1381 | aeFpsTarget.size()); |
| 1382 | |
| 1383 | uint8_t aeAntibandingMode = ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO; |
| 1384 | requestTemplate->addEntry(ANDROID_CONTROL_AE_ANTIBANDING_MODE, |
| 1385 | &aeAntibandingMode, 1); |
| 1386 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1387 | uint8_t afTrigger = ANDROID_CONTROL_AF_TRIGGER_IDLE; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1388 | requestTemplate->addEntry(ANDROID_CONTROL_AF_TRIGGER, |
| 1389 | &afTrigger, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1390 | |
| 1391 | uint8_t awbMode = ANDROID_CONTROL_AWB_MODE_AUTO; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1392 | requestTemplate->addEntry(ANDROID_CONTROL_AWB_MODE, |
| 1393 | &awbMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1394 | |
| 1395 | uint8_t awbLock = ANDROID_CONTROL_AWB_LOCK_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1396 | requestTemplate->addEntry(ANDROID_CONTROL_AWB_LOCK, |
| 1397 | &awbLock, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1398 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1399 | uint8_t flashMode = ANDROID_FLASH_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1400 | requestTemplate->addEntry(ANDROID_FLASH_MODE, |
| 1401 | &flashMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1402 | |
| 1403 | uint8_t faceDetectMode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1404 | requestTemplate->addEntry(ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 1405 | &faceDetectMode, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1406 | |
Jacopo Mondi | 9b361dc | 2019-09-04 16:18:21 +0200 | [diff] [blame] | 1407 | uint8_t noiseReduction = ANDROID_NOISE_REDUCTION_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1408 | requestTemplate->addEntry(ANDROID_NOISE_REDUCTION_MODE, |
| 1409 | &noiseReduction, 1); |
Jacopo Mondi | 9b361dc | 2019-09-04 16:18:21 +0200 | [diff] [blame] | 1410 | |
| 1411 | uint8_t aberrationMode = ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1412 | requestTemplate->addEntry(ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 1413 | &aberrationMode, 1); |
Jacopo Mondi | 9b361dc | 2019-09-04 16:18:21 +0200 | [diff] [blame] | 1414 | |
Jacopo Mondi | 09b1d0f | 2020-07-24 16:10:23 +0200 | [diff] [blame] | 1415 | uint8_t controlMode = ANDROID_CONTROL_MODE_AUTO; |
| 1416 | requestTemplate->addEntry(ANDROID_CONTROL_MODE, &controlMode, 1); |
| 1417 | |
| 1418 | float lensAperture = 2.53 / 100; |
| 1419 | requestTemplate->addEntry(ANDROID_LENS_APERTURE, &lensAperture, 1); |
| 1420 | |
| 1421 | uint8_t opticalStabilization = ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF; |
| 1422 | requestTemplate->addEntry(ANDROID_LENS_OPTICAL_STABILIZATION_MODE, |
| 1423 | &opticalStabilization, 1); |
| 1424 | |
Jacopo Mondi | 8a02d44 | 2020-07-24 15:47:50 +0200 | [diff] [blame] | 1425 | uint8_t captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1426 | requestTemplate->addEntry(ANDROID_CONTROL_CAPTURE_INTENT, |
| 1427 | &captureIntent, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1428 | |
Jacopo Mondi | 8a02d44 | 2020-07-24 15:47:50 +0200 | [diff] [blame] | 1429 | return requestTemplate; |
| 1430 | } |
| 1431 | |
| 1432 | /* |
| 1433 | * Produce a metadata pack to be used as template for a capture request. |
| 1434 | */ |
| 1435 | const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) |
| 1436 | { |
| 1437 | auto it = requestTemplates_.find(type); |
| 1438 | if (it != requestTemplates_.end()) |
| 1439 | return it->second->get(); |
| 1440 | |
| 1441 | /* Use the capture intent matching the requested template type. */ |
| 1442 | CameraMetadata *requestTemplate; |
| 1443 | uint8_t captureIntent; |
| 1444 | switch (type) { |
| 1445 | case CAMERA3_TEMPLATE_PREVIEW: |
| 1446 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; |
| 1447 | break; |
| 1448 | case CAMERA3_TEMPLATE_STILL_CAPTURE: |
| 1449 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE; |
| 1450 | break; |
| 1451 | case CAMERA3_TEMPLATE_VIDEO_RECORD: |
| 1452 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD; |
| 1453 | break; |
| 1454 | case CAMERA3_TEMPLATE_VIDEO_SNAPSHOT: |
| 1455 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT; |
| 1456 | break; |
| 1457 | case CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG: |
| 1458 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG; |
| 1459 | break; |
| 1460 | case CAMERA3_TEMPLATE_MANUAL: |
| 1461 | captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_MANUAL; |
| 1462 | break; |
| 1463 | default: |
| 1464 | LOG(HAL, Error) << "Invalid template request type: " << type; |
| 1465 | return nullptr; |
| 1466 | } |
| 1467 | |
| 1468 | requestTemplate = requestTemplatePreview(); |
| 1469 | if (!requestTemplate || !requestTemplate->isValid()) { |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1470 | LOG(HAL, Error) << "Failed to construct request template"; |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1471 | delete requestTemplate; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1472 | return nullptr; |
| 1473 | } |
| 1474 | |
Jacopo Mondi | 8a02d44 | 2020-07-24 15:47:50 +0200 | [diff] [blame] | 1475 | requestTemplate->updateEntry(ANDROID_CONTROL_CAPTURE_INTENT, |
| 1476 | &captureIntent, 1); |
| 1477 | |
Jacopo Mondi | fcd5a4f | 2019-09-04 16:18:23 +0200 | [diff] [blame] | 1478 | requestTemplates_[type] = requestTemplate; |
| 1479 | return requestTemplate->get(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1480 | } |
| 1481 | |
Hirokazu Honda | c1ae905 | 2020-10-28 18:50:23 +0900 | [diff] [blame] | 1482 | PixelFormat CameraDevice::toPixelFormat(int format) const |
Kieran Bingham | 43e3b80 | 2020-06-26 09:58:49 +0100 | [diff] [blame] | 1483 | { |
| 1484 | /* Translate Android format code to libcamera pixel format. */ |
| 1485 | auto it = formatsMap_.find(format); |
| 1486 | if (it == formatsMap_.end()) { |
| 1487 | LOG(HAL, Error) << "Requested format " << utils::hex(format) |
| 1488 | << " not supported"; |
| 1489 | return PixelFormat(); |
| 1490 | } |
| 1491 | |
| 1492 | return it->second; |
| 1493 | } |
| 1494 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1495 | /* |
| 1496 | * Inspect the stream_list to produce a list of StreamConfiguration to |
| 1497 | * be use to configure the Camera. |
| 1498 | */ |
| 1499 | int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) |
| 1500 | { |
Jacopo Mondi | 8fed613 | 2020-12-04 15:26:47 +0100 | [diff] [blame] | 1501 | /* Before any configuration attempt, stop the camera if it's running. */ |
| 1502 | if (running_) { |
| 1503 | worker_.stop(); |
| 1504 | camera_->stop(); |
| 1505 | running_ = false; |
| 1506 | } |
| 1507 | |
Kieran Bingham | 0a9244e | 2020-06-26 20:19:10 +0100 | [diff] [blame] | 1508 | /* |
| 1509 | * Generate an empty configuration, and construct a StreamConfiguration |
| 1510 | * for each camera3_stream to add to it. |
| 1511 | */ |
| 1512 | config_ = camera_->generateConfiguration(); |
| 1513 | if (!config_) { |
| 1514 | LOG(HAL, Error) << "Failed to generate camera configuration"; |
| 1515 | return -EINVAL; |
| 1516 | } |
| 1517 | |
Kieran Bingham | 2f34f5e | 2020-07-01 16:42:13 +0100 | [diff] [blame] | 1518 | /* |
| 1519 | * Clear and remove any existing configuration from previous calls, and |
| 1520 | * ensure the required entries are available without further |
Jacopo Mondi | 9ac8f3e | 2020-09-04 15:25:55 +0200 | [diff] [blame] | 1521 | * reallocation. |
Kieran Bingham | 2f34f5e | 2020-07-01 16:42:13 +0100 | [diff] [blame] | 1522 | */ |
| 1523 | streams_.clear(); |
| 1524 | streams_.reserve(stream_list->num_streams); |
| 1525 | |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1526 | std::vector<Camera3StreamConfig> streamConfigs; |
| 1527 | streamConfigs.reserve(stream_list->num_streams); |
| 1528 | |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1529 | /* First handle all non-MJPEG streams. */ |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1530 | camera3_stream_t *jpegStream = nullptr; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1531 | for (unsigned int i = 0; i < stream_list->num_streams; ++i) { |
| 1532 | camera3_stream_t *stream = stream_list->streams[i]; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1533 | Size size(stream->width, stream->height); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1534 | |
Kieran Bingham | 43e3b80 | 2020-06-26 09:58:49 +0100 | [diff] [blame] | 1535 | PixelFormat format = toPixelFormat(stream->format); |
| 1536 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1537 | LOG(HAL, Info) << "Stream #" << i |
| 1538 | << ", direction: " << stream->stream_type |
| 1539 | << ", width: " << stream->width |
| 1540 | << ", height: " << stream->height |
Kieran Bingham | 43e3b80 | 2020-06-26 09:58:49 +0100 | [diff] [blame] | 1541 | << ", format: " << utils::hex(stream->format) |
| 1542 | << " (" << format.toString() << ")"; |
Kieran Bingham | 0a9244e | 2020-06-26 20:19:10 +0100 | [diff] [blame] | 1543 | |
| 1544 | if (!format.isValid()) |
| 1545 | return -EINVAL; |
| 1546 | |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1547 | /* Defer handling of MJPEG streams until all others are known. */ |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1548 | if (stream->format == HAL_PIXEL_FORMAT_BLOB) { |
| 1549 | if (jpegStream) { |
| 1550 | LOG(HAL, Error) |
| 1551 | << "Multiple JPEG streams are not supported"; |
| 1552 | return -EINVAL; |
| 1553 | } |
| 1554 | |
| 1555 | jpegStream = stream; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1556 | continue; |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1557 | } |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1558 | |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1559 | Camera3StreamConfig streamConfig; |
| 1560 | streamConfig.streams = { { stream, CameraStream::Type::Direct } }; |
| 1561 | streamConfig.config.size = size; |
| 1562 | streamConfig.config.pixelFormat = format; |
| 1563 | streamConfigs.push_back(std::move(streamConfig)); |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1564 | } |
| 1565 | |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1566 | /* Now handle the MJPEG streams, adding a new stream if required. */ |
| 1567 | if (jpegStream) { |
Jacopo Mondi | 94c4d49 | 2020-09-04 16:06:11 +0200 | [diff] [blame] | 1568 | CameraStream::Type type; |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1569 | int index = -1; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1570 | |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1571 | /* Search for a compatible stream in the non-JPEG ones. */ |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1572 | for (size_t i = 0; i < streamConfigs.size(); ++i) { |
| 1573 | const auto &cfg = streamConfigs[i].config; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1574 | |
| 1575 | /* |
| 1576 | * \todo The PixelFormat must also be compatible with |
| 1577 | * the encoder. |
| 1578 | */ |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1579 | if (cfg.size.width != jpegStream->width || |
| 1580 | cfg.size.height != jpegStream->height) |
| 1581 | continue; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1582 | |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1583 | LOG(HAL, Info) |
| 1584 | << "Android JPEG stream mapped to libcamera stream " << i; |
| 1585 | |
Jacopo Mondi | 94c4d49 | 2020-09-04 16:06:11 +0200 | [diff] [blame] | 1586 | type = CameraStream::Type::Mapped; |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1587 | index = i; |
| 1588 | break; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | /* |
| 1592 | * Without a compatible match for JPEG encoding we must |
| 1593 | * introduce a new stream to satisfy the request requirements. |
| 1594 | */ |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1595 | if (index < 0) { |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1596 | /* |
| 1597 | * \todo The pixelFormat should be a 'best-fit' choice |
| 1598 | * and may require a validation cycle. This is not yet |
| 1599 | * handled, and should be considered as part of any |
| 1600 | * stream configuration reworks. |
| 1601 | */ |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1602 | Camera3StreamConfig streamConfig; |
| 1603 | streamConfig.config.size.width = jpegStream->width; |
| 1604 | streamConfig.config.size.height = jpegStream->height; |
| 1605 | streamConfig.config.pixelFormat = formats::NV12; |
| 1606 | streamConfigs.push_back(std::move(streamConfig)); |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1607 | |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1608 | LOG(HAL, Info) << "Adding " << streamConfig.config.toString() |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1609 | << " for MJPEG support"; |
| 1610 | |
Jacopo Mondi | 94c4d49 | 2020-09-04 16:06:11 +0200 | [diff] [blame] | 1611 | type = CameraStream::Type::Internal; |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1612 | index = streamConfigs.size() - 1; |
Jacopo Mondi | c82f944 | 2020-09-02 11:58:00 +0200 | [diff] [blame] | 1613 | } |
| 1614 | |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1615 | streamConfigs[index].streams.push_back({ jpegStream, type }); |
| 1616 | } |
| 1617 | |
Hirokazu Honda | 26d90af | 2020-12-11 09:53:36 +0000 | [diff] [blame] | 1618 | sortCamera3StreamConfigs(streamConfigs, jpegStream); |
Hirokazu Honda | 2bc6ba2 | 2020-12-11 09:53:35 +0000 | [diff] [blame] | 1619 | for (const auto &streamConfig : streamConfigs) { |
| 1620 | config_->addConfiguration(streamConfig.config); |
| 1621 | |
| 1622 | for (auto &stream : streamConfig.streams) { |
| 1623 | streams_.emplace_back(this, stream.type, stream.stream, |
| 1624 | config_->size() - 1); |
| 1625 | stream.stream->priv = static_cast<void *>(&streams_.back()); |
| 1626 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1627 | } |
| 1628 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1629 | switch (config_->validate()) { |
| 1630 | case CameraConfiguration::Valid: |
| 1631 | break; |
| 1632 | case CameraConfiguration::Adjusted: |
| 1633 | LOG(HAL, Info) << "Camera configuration adjusted"; |
Kieran Bingham | 9f07aeb | 2020-07-20 22:52:14 +0100 | [diff] [blame] | 1634 | |
| 1635 | for (const StreamConfiguration &cfg : *config_) |
| 1636 | LOG(HAL, Info) << " - " << cfg.toString(); |
| 1637 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1638 | config_.reset(); |
| 1639 | return -EINVAL; |
| 1640 | case CameraConfiguration::Invalid: |
| 1641 | LOG(HAL, Info) << "Camera configuration invalid"; |
| 1642 | config_.reset(); |
| 1643 | return -EINVAL; |
| 1644 | } |
| 1645 | |
Jacopo Mondi | 3c84d88 | 2020-10-02 19:40:42 +0200 | [diff] [blame] | 1646 | /* |
Jacopo Mondi | b84e35d | 2020-10-03 13:21:50 +0200 | [diff] [blame] | 1647 | * Once the CameraConfiguration has been adjusted/validated |
| 1648 | * it can be applied to the camera. |
| 1649 | */ |
| 1650 | int ret = camera_->configure(config_.get()); |
| 1651 | if (ret) { |
| 1652 | LOG(HAL, Error) << "Failed to configure camera '" |
| 1653 | << camera_->id() << "'"; |
| 1654 | return ret; |
| 1655 | } |
| 1656 | |
| 1657 | /* |
Jacopo Mondi | 3c84d88 | 2020-10-02 19:40:42 +0200 | [diff] [blame] | 1658 | * Configure the HAL CameraStream instances using the associated |
| 1659 | * StreamConfiguration and set the number of required buffers in |
| 1660 | * the Android camera3_stream_t. |
| 1661 | */ |
Jacopo Mondi | 6c8837d | 2020-10-03 13:45:29 +0200 | [diff] [blame] | 1662 | for (CameraStream &cameraStream : streams_) { |
Kieran Bingham | c7bcae0 | 2020-10-13 15:58:26 +0100 | [diff] [blame] | 1663 | ret = cameraStream.configure(); |
Jacopo Mondi | 6c8837d | 2020-10-03 13:45:29 +0200 | [diff] [blame] | 1664 | if (ret) { |
| 1665 | LOG(HAL, Error) << "Failed to configure camera stream"; |
Jacopo Mondi | 3c84d88 | 2020-10-02 19:40:42 +0200 | [diff] [blame] | 1666 | return ret; |
Jacopo Mondi | 6c8837d | 2020-10-03 13:45:29 +0200 | [diff] [blame] | 1667 | } |
Kieran Bingham | 0a9244e | 2020-06-26 20:19:10 +0100 | [diff] [blame] | 1668 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1669 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1670 | return 0; |
| 1671 | } |
| 1672 | |
Kieran Bingham | 74ab442 | 2020-07-01 13:25:38 +0100 | [diff] [blame] | 1673 | FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer) |
| 1674 | { |
| 1675 | std::vector<FrameBuffer::Plane> planes; |
Kieran Bingham | f4c65be | 2020-07-06 16:12:03 +0100 | [diff] [blame] | 1676 | for (int i = 0; i < camera3buffer->numFds; i++) { |
| 1677 | /* Skip unused planes. */ |
| 1678 | if (camera3buffer->data[i] == -1) |
| 1679 | break; |
| 1680 | |
Kieran Bingham | 74ab442 | 2020-07-01 13:25:38 +0100 | [diff] [blame] | 1681 | FrameBuffer::Plane plane; |
| 1682 | plane.fd = FileDescriptor(camera3buffer->data[i]); |
Kieran Bingham | f4c65be | 2020-07-06 16:12:03 +0100 | [diff] [blame] | 1683 | if (!plane.fd.isValid()) { |
| 1684 | LOG(HAL, Error) << "Failed to obtain FileDescriptor (" |
| 1685 | << camera3buffer->data[i] << ") " |
| 1686 | << " on plane " << i; |
| 1687 | return nullptr; |
| 1688 | } |
| 1689 | |
Kieran Bingham | 6bc652e | 2020-07-17 16:18:32 +0100 | [diff] [blame] | 1690 | off_t length = lseek(plane.fd.fd(), 0, SEEK_END); |
| 1691 | if (length == -1) { |
| 1692 | LOG(HAL, Error) << "Failed to query plane length"; |
| 1693 | return nullptr; |
| 1694 | } |
| 1695 | |
| 1696 | plane.length = length; |
Kieran Bingham | 74ab442 | 2020-07-01 13:25:38 +0100 | [diff] [blame] | 1697 | planes.push_back(std::move(plane)); |
| 1698 | } |
| 1699 | |
| 1700 | return new FrameBuffer(std::move(planes)); |
| 1701 | } |
| 1702 | |
Jacopo Mondi | bb2b400 | 2021-01-04 16:20:05 +0100 | [diff] [blame] | 1703 | int CameraDevice::processControls(Camera3RequestDescriptor *descriptor) |
| 1704 | { |
| 1705 | const CameraMetadata &settings = descriptor->settings_; |
| 1706 | if (!settings.isValid()) |
| 1707 | return 0; |
| 1708 | |
| 1709 | /* Translate the Android request settings to libcamera controls. */ |
| 1710 | camera_metadata_ro_entry_t entry; |
| 1711 | if (settings.getEntry(ANDROID_SCALER_CROP_REGION, &entry)) { |
| 1712 | const int32_t *data = entry.data.i32; |
| 1713 | Rectangle cropRegion{ data[0], data[1], |
| 1714 | static_cast<unsigned int>(data[2]), |
| 1715 | static_cast<unsigned int>(data[3]) }; |
| 1716 | ControlList &controls = descriptor->request_->controls(); |
| 1717 | controls.set(controls::ScalerCrop, cropRegion); |
| 1718 | } |
| 1719 | |
| 1720 | return 0; |
| 1721 | } |
| 1722 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1723 | int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1724 | { |
Jacopo Mondi | c5b732b | 2020-12-01 17:12:19 +0100 | [diff] [blame] | 1725 | if (!camera3Request) { |
| 1726 | LOG(HAL, Error) << "No capture request provided"; |
| 1727 | return -EINVAL; |
| 1728 | } |
| 1729 | |
Kieran Bingham | 61f4296 | 2020-07-01 13:40:17 +0100 | [diff] [blame] | 1730 | if (!camera3Request->num_output_buffers) { |
| 1731 | LOG(HAL, Error) << "No output buffers provided"; |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1732 | return -EINVAL; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | /* Start the camera if that's the first request we handle. */ |
| 1736 | if (!running_) { |
Jacopo Mondi | 4b1aa21 | 2020-10-06 17:56:50 +0200 | [diff] [blame] | 1737 | worker_.start(); |
| 1738 | |
Niklas Söderlund | a1c5450 | 2019-11-25 17:51:06 +0100 | [diff] [blame] | 1739 | int ret = camera_->start(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1740 | if (ret) { |
| 1741 | LOG(HAL, Error) << "Failed to start camera"; |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1742 | return ret; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | running_ = true; |
| 1746 | } |
| 1747 | |
| 1748 | /* |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1749 | * Save the request descriptors for use at completion time. |
| 1750 | * The descriptor and the associated memory reserved here are freed |
| 1751 | * at request complete time. |
| 1752 | */ |
| 1753 | Camera3RequestDescriptor *descriptor = |
Jacopo Mondi | dd1cd53 | 2021-01-21 10:51:05 +0100 | [diff] [blame] | 1754 | new Camera3RequestDescriptor(camera_.get(), camera3Request); |
Paul Elder | a6de3f0 | 2021-01-21 18:59:24 +0900 | [diff] [blame] | 1755 | /* |
| 1756 | * \todo The Android request model is incremental, settings passed in |
| 1757 | * previous requests are to be effective until overridden explicitly in |
| 1758 | * a new request. Do we need to cache settings incrementally here, or is |
| 1759 | * it handled by the Android camera service ? |
| 1760 | */ |
| 1761 | if (camera3Request->settings) |
| 1762 | lastSettings_ = camera3Request->settings; |
| 1763 | else |
| 1764 | descriptor->settings_ = lastSettings_; |
Kieran Bingham | eac0542 | 2020-07-01 13:28:16 +0100 | [diff] [blame] | 1765 | |
Jacopo Mondi | bc64407 | 2021-01-28 09:58:06 +0100 | [diff] [blame] | 1766 | LOG(HAL, Debug) << "Queueing request " << descriptor->request_->cookie() |
| 1767 | << " with " << descriptor->numBuffers_ << " streams"; |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1768 | for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { |
Jacopo Mondi | 4b18b82 | 2021-01-21 11:10:08 +0100 | [diff] [blame] | 1769 | const camera3_stream_buffer_t *camera3Buffer = &descriptor->buffers_[i]; |
| 1770 | camera3_stream *camera3Stream = camera3Buffer->stream; |
| 1771 | CameraStream *cameraStream = static_cast<CameraStream *>(camera3Stream->priv); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1772 | |
Jacopo Mondi | 35f726d | 2020-09-04 18:32:48 +0200 | [diff] [blame] | 1773 | std::stringstream ss; |
| 1774 | ss << i << " - (" << camera3Stream->width << "x" |
| 1775 | << camera3Stream->height << ")" |
| 1776 | << "[" << utils::hex(camera3Stream->format) << "] -> " |
| 1777 | << "(" << cameraStream->configuration().size.toString() << ")[" |
| 1778 | << cameraStream->configuration().pixelFormat.toString() << "]"; |
| 1779 | |
Jacopo Mondi | de8304b | 2020-09-04 17:45:39 +0200 | [diff] [blame] | 1780 | /* |
| 1781 | * Inspect the camera stream type, create buffers opportunely |
| 1782 | * and add them to the Request if required. |
| 1783 | */ |
| 1784 | FrameBuffer *buffer = nullptr; |
| 1785 | switch (cameraStream->type()) { |
| 1786 | case CameraStream::Type::Mapped: |
| 1787 | /* |
| 1788 | * Mapped streams don't need buffers added to the |
| 1789 | * Request. |
| 1790 | */ |
Jacopo Mondi | 35f726d | 2020-09-04 18:32:48 +0200 | [diff] [blame] | 1791 | LOG(HAL, Debug) << ss.str() << " (mapped)"; |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1792 | continue; |
| 1793 | |
Jacopo Mondi | de8304b | 2020-09-04 17:45:39 +0200 | [diff] [blame] | 1794 | case CameraStream::Type::Direct: |
| 1795 | /* |
| 1796 | * Create a libcamera buffer using the dmabuf |
| 1797 | * descriptors of the camera3Buffer for each stream and |
| 1798 | * associate it with the Camera3RequestDescriptor for |
| 1799 | * lifetime management only. |
| 1800 | */ |
Jacopo Mondi | 4b18b82 | 2021-01-21 11:10:08 +0100 | [diff] [blame] | 1801 | buffer = createFrameBuffer(*camera3Buffer->buffer); |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1802 | descriptor->frameBuffers_.emplace_back(buffer); |
Jacopo Mondi | 35f726d | 2020-09-04 18:32:48 +0200 | [diff] [blame] | 1803 | LOG(HAL, Debug) << ss.str() << " (direct)"; |
Jacopo Mondi | de8304b | 2020-09-04 17:45:39 +0200 | [diff] [blame] | 1804 | break; |
| 1805 | |
| 1806 | case CameraStream::Type::Internal: |
| 1807 | /* |
| 1808 | * Get the frame buffer from the CameraStream internal |
| 1809 | * buffer pool. |
| 1810 | * |
| 1811 | * The buffer has to be returned to the CameraStream |
| 1812 | * once it has been processed. |
| 1813 | */ |
| 1814 | buffer = cameraStream->getBuffer(); |
Jacopo Mondi | 35f726d | 2020-09-04 18:32:48 +0200 | [diff] [blame] | 1815 | LOG(HAL, Debug) << ss.str() << " (internal)"; |
Jacopo Mondi | de8304b | 2020-09-04 17:45:39 +0200 | [diff] [blame] | 1816 | break; |
| 1817 | } |
| 1818 | |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1819 | if (!buffer) { |
| 1820 | LOG(HAL, Error) << "Failed to create buffer"; |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1821 | delete descriptor; |
| 1822 | return -ENOMEM; |
| 1823 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1824 | |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1825 | descriptor->request_->addBuffer(cameraStream->stream(), buffer, |
Jacopo Mondi | 4b18b82 | 2021-01-21 11:10:08 +0100 | [diff] [blame] | 1826 | camera3Buffer->acquire_fence); |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1827 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1828 | |
Jacopo Mondi | bb2b400 | 2021-01-04 16:20:05 +0100 | [diff] [blame] | 1829 | /* |
| 1830 | * Translate controls from Android to libcamera and queue the request |
| 1831 | * to the CameraWorker thread. |
| 1832 | */ |
| 1833 | int ret = processControls(descriptor); |
| 1834 | if (ret) |
| 1835 | return ret; |
| 1836 | |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1837 | worker_.queueRequest(descriptor->request_.get()); |
Paul Elder | c753223 | 2020-09-23 19:05:41 +0900 | [diff] [blame] | 1838 | |
Laurent Pinchart | da3f50e | 2020-01-20 01:09:34 +0200 | [diff] [blame] | 1839 | return 0; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1840 | } |
| 1841 | |
Niklas Söderlund | f7ddfd4 | 2019-10-21 20:01:19 +0200 | [diff] [blame] | 1842 | void CameraDevice::requestComplete(Request *request) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1843 | { |
Niklas Söderlund | dac8e95 | 2020-08-11 00:56:13 +0200 | [diff] [blame] | 1844 | const Request::BufferMap &buffers = request->buffers(); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1845 | camera3_buffer_status status = CAMERA3_BUFFER_STATUS_OK; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1846 | std::unique_ptr<CameraMetadata> resultMetadata; |
Kieran Bingham | c09aee4 | 2020-07-28 14:01:19 +0100 | [diff] [blame] | 1847 | Camera3RequestDescriptor *descriptor = |
| 1848 | reinterpret_cast<Camera3RequestDescriptor *>(request->cookie()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1849 | |
| 1850 | if (request->status() != Request::RequestComplete) { |
Kieran Bingham | 98986e0 | 2020-08-03 14:34:11 +0100 | [diff] [blame] | 1851 | LOG(HAL, Error) << "Request not successfully completed: " |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1852 | << request->status(); |
| 1853 | status = CAMERA3_BUFFER_STATUS_ERROR; |
| 1854 | } |
| 1855 | |
Jacopo Mondi | bc64407 | 2021-01-28 09:58:06 +0100 | [diff] [blame] | 1856 | LOG(HAL, Debug) << "Request " << request->cookie() << " completed with " |
| 1857 | << descriptor->numBuffers_ << " streams"; |
| 1858 | |
Kieran Bingham | c09aee4 | 2020-07-28 14:01:19 +0100 | [diff] [blame] | 1859 | /* |
| 1860 | * \todo The timestamp used for the metadata is currently always taken |
| 1861 | * from the first buffer (which may be the first stream) in the Request. |
| 1862 | * It might be appropriate to return a 'correct' (as determined by |
| 1863 | * pipeline handlers) timestamp in the Request itself. |
| 1864 | */ |
Hirokazu Honda | 3a777d8 | 2020-10-28 17:57:26 +0900 | [diff] [blame] | 1865 | uint64_t timestamp = buffers.begin()->second->metadata().timestamp; |
Jacopo Mondi | 3535e0c | 2020-12-09 17:51:57 +0100 | [diff] [blame] | 1866 | resultMetadata = getResultMetadata(descriptor, timestamp); |
Kieran Bingham | c09aee4 | 2020-07-28 14:01:19 +0100 | [diff] [blame] | 1867 | |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1868 | /* Handle any JPEG compression. */ |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1869 | for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1870 | CameraStream *cameraStream = |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1871 | static_cast<CameraStream *>(descriptor->buffers_[i].stream->priv); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1872 | |
Jacopo Mondi | 160bb09 | 2020-10-02 20:48:35 +0200 | [diff] [blame] | 1873 | if (cameraStream->camera3Stream().format != HAL_PIXEL_FORMAT_BLOB) |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1874 | continue; |
| 1875 | |
Jacopo Mondi | 216030a | 2020-10-03 11:36:41 +0200 | [diff] [blame] | 1876 | FrameBuffer *buffer = request->findBuffer(cameraStream->stream()); |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1877 | if (!buffer) { |
| 1878 | LOG(HAL, Error) << "Failed to find a source stream buffer"; |
| 1879 | continue; |
| 1880 | } |
| 1881 | |
| 1882 | /* |
| 1883 | * \todo Buffer mapping and compression should be moved to a |
| 1884 | * separate thread. |
| 1885 | */ |
| 1886 | |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1887 | MappedCamera3Buffer mapped(*descriptor->buffers_[i].buffer, |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1888 | PROT_READ | PROT_WRITE); |
| 1889 | if (!mapped.isValid()) { |
| 1890 | LOG(HAL, Error) << "Failed to mmap android blob buffer"; |
| 1891 | continue; |
| 1892 | } |
| 1893 | |
Jacopo Mondi | 9e95d5e | 2020-10-03 11:28:47 +0200 | [diff] [blame] | 1894 | int ret = cameraStream->process(*buffer, &mapped, |
Paul Elder | abfabdd | 2021-01-23 13:54:28 +0900 | [diff] [blame] | 1895 | descriptor->settings_, |
Jacopo Mondi | 9e95d5e | 2020-10-03 11:28:47 +0200 | [diff] [blame] | 1896 | resultMetadata.get()); |
| 1897 | if (ret) { |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1898 | status = CAMERA3_BUFFER_STATUS_ERROR; |
| 1899 | continue; |
| 1900 | } |
Jacopo Mondi | de8304b | 2020-09-04 17:45:39 +0200 | [diff] [blame] | 1901 | |
| 1902 | /* |
| 1903 | * Return the FrameBuffer to the CameraStream now that we're |
| 1904 | * done processing it. |
| 1905 | */ |
| 1906 | if (cameraStream->type() == CameraStream::Type::Internal) |
| 1907 | cameraStream->putBuffer(buffer); |
Kieran Bingham | 83ae84e | 2020-07-03 12:34:59 +0100 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | /* Prepare to call back the Android camera stack. */ |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1911 | camera3_capture_result_t captureResult = {}; |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1912 | captureResult.frame_number = descriptor->frameNumber_; |
| 1913 | captureResult.num_output_buffers = descriptor->numBuffers_; |
| 1914 | for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { |
| 1915 | descriptor->buffers_[i].acquire_fence = -1; |
| 1916 | descriptor->buffers_[i].release_fence = -1; |
| 1917 | descriptor->buffers_[i].status = status; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1918 | } |
| 1919 | captureResult.output_buffers = |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1920 | const_cast<const camera3_stream_buffer_t *>(descriptor->buffers_); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1921 | |
Kieran Bingham | 0cfdf73 | 2020-07-01 13:36:24 +0100 | [diff] [blame] | 1922 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1923 | if (status == CAMERA3_BUFFER_STATUS_OK) { |
Kieran Bingham | e1f9fdb | 2020-10-21 15:31:10 +0100 | [diff] [blame] | 1924 | notifyShutter(descriptor->frameNumber_, timestamp); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1925 | |
| 1926 | captureResult.partial_result = 1; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 1927 | captureResult.result = resultMetadata->get(); |
| 1928 | } |
| 1929 | |
| 1930 | if (status == CAMERA3_BUFFER_STATUS_ERROR || !captureResult.result) { |
| 1931 | /* \todo Improve error handling. In case we notify an error |
| 1932 | * because the metadata generation fails, a shutter event has |
| 1933 | * already been notified for this frame number before the error |
| 1934 | * is here signalled. Make sure the error path plays well with |
| 1935 | * the camera stack state machine. |
| 1936 | */ |
Kieran Bingham | 37c18c2 | 2020-10-21 14:54:11 +0100 | [diff] [blame] | 1937 | notifyError(descriptor->frameNumber_, |
| 1938 | descriptor->buffers_[0].stream); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | callbacks_->process_capture_result(callbacks_, &captureResult); |
| 1942 | |
| 1943 | delete descriptor; |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1944 | } |
| 1945 | |
Jacopo Mondi | a7b9277 | 2020-05-26 15:41:41 +0200 | [diff] [blame] | 1946 | std::string CameraDevice::logPrefix() const |
| 1947 | { |
Niklas Söderlund | 2e7c80a | 2020-08-02 23:57:17 +0200 | [diff] [blame] | 1948 | return "'" + camera_->id() + "'"; |
Jacopo Mondi | a7b9277 | 2020-05-26 15:41:41 +0200 | [diff] [blame] | 1949 | } |
| 1950 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1951 | void CameraDevice::notifyShutter(uint32_t frameNumber, uint64_t timestamp) |
| 1952 | { |
| 1953 | camera3_notify_msg_t notify = {}; |
| 1954 | |
| 1955 | notify.type = CAMERA3_MSG_SHUTTER; |
| 1956 | notify.message.shutter.frame_number = frameNumber; |
| 1957 | notify.message.shutter.timestamp = timestamp; |
| 1958 | |
| 1959 | callbacks_->notify(callbacks_, ¬ify); |
| 1960 | } |
| 1961 | |
| 1962 | void CameraDevice::notifyError(uint32_t frameNumber, camera3_stream_t *stream) |
| 1963 | { |
| 1964 | camera3_notify_msg_t notify = {}; |
| 1965 | |
Kieran Bingham | 8ad1b9c | 2020-07-01 16:47:58 +0100 | [diff] [blame] | 1966 | /* |
| 1967 | * \todo Report and identify the stream number or configuration to |
| 1968 | * clarify the stream that failed. |
| 1969 | */ |
| 1970 | LOG(HAL, Error) << "Error occurred on frame " << frameNumber << " (" |
| 1971 | << toPixelFormat(stream->format).toString() << ")"; |
| 1972 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1973 | notify.type = CAMERA3_MSG_ERROR; |
| 1974 | notify.message.error.error_stream = stream; |
| 1975 | notify.message.error.frame_number = frameNumber; |
| 1976 | notify.message.error.error_code = CAMERA3_MSG_ERROR_REQUEST; |
| 1977 | |
| 1978 | callbacks_->notify(callbacks_, ¬ify); |
| 1979 | } |
| 1980 | |
| 1981 | /* |
| 1982 | * Produce a set of fixed result metadata. |
| 1983 | */ |
Laurent Pinchart | dbafe16 | 2019-10-27 00:36:13 +0300 | [diff] [blame] | 1984 | std::unique_ptr<CameraMetadata> |
Jacopo Mondi | 3535e0c | 2020-12-09 17:51:57 +0100 | [diff] [blame] | 1985 | CameraDevice::getResultMetadata(Camera3RequestDescriptor *descriptor, |
Laurent Pinchart | dbafe16 | 2019-10-27 00:36:13 +0300 | [diff] [blame] | 1986 | int64_t timestamp) |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 1987 | { |
Jacopo Mondi | 3535e0c | 2020-12-09 17:51:57 +0100 | [diff] [blame] | 1988 | const ControlList &metadata = descriptor->request_->metadata(); |
Jacopo Mondi | 94d42ce | 2021-01-29 14:54:39 +0100 | [diff] [blame] | 1989 | const CameraMetadata &settings = descriptor->settings_; |
Paul Elder | 958c80a | 2021-01-26 09:47:33 +0900 | [diff] [blame] | 1990 | camera_metadata_ro_entry_t entry; |
Jacopo Mondi | 94d42ce | 2021-01-29 14:54:39 +0100 | [diff] [blame] | 1991 | bool found; |
Jacopo Mondi | 3535e0c | 2020-12-09 17:51:57 +0100 | [diff] [blame] | 1992 | |
Jacopo Mondi | 48504ba | 2019-09-04 16:18:19 +0200 | [diff] [blame] | 1993 | /* |
| 1994 | * \todo Keep this in sync with the actual number of entries. |
Paul Elder | 1264628 | 2021-01-23 13:56:01 +0900 | [diff] [blame] | 1995 | * Currently: 40 entries, 156 bytes |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 1996 | * |
| 1997 | * Reserve more space for the JPEG metadata set by the post-processor. |
Paul Elder | abfabdd | 2021-01-23 13:54:28 +0900 | [diff] [blame] | 1998 | * Currently: |
| 1999 | * ANDROID_JPEG_GPS_COORDINATES (double x 3) = 24 bytes |
| 2000 | * ANDROID_JPEG_GPS_PROCESSING_METHOD (byte x 32) = 32 bytes |
| 2001 | * ANDROID_JPEG_GPS_TIMESTAMP (int64) = 8 bytes |
| 2002 | * ANDROID_JPEG_SIZE (int32_t) = 4 bytes |
| 2003 | * ANDROID_JPEG_QUALITY (byte) = 1 byte |
| 2004 | * ANDROID_JPEG_ORIENTATION (int32_t) = 4 bytes |
Paul Elder | 1264628 | 2021-01-23 13:56:01 +0900 | [diff] [blame] | 2005 | * ANDROID_JPEG_THUMBNAIL_QUALITY (byte) = 1 byte |
| 2006 | * ANDROID_JPEG_THUMBNAIL_SIZE (int32 x 2) = 8 bytes |
| 2007 | * Total bytes for JPEG metadata: 82 |
Jacopo Mondi | 48504ba | 2019-09-04 16:18:19 +0200 | [diff] [blame] | 2008 | */ |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 2009 | std::unique_ptr<CameraMetadata> resultMetadata = |
Jacopo Mondi | e9c2875 | 2021-02-03 14:47:45 +0100 | [diff] [blame] | 2010 | std::make_unique<CameraMetadata>(42, 161); |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 2011 | if (!resultMetadata->isValid()) { |
| 2012 | LOG(HAL, Error) << "Failed to allocate static metadata"; |
| 2013 | return nullptr; |
| 2014 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 2015 | |
Jacopo Mondi | 94d42ce | 2021-01-29 14:54:39 +0100 | [diff] [blame] | 2016 | /* |
| 2017 | * \todo The value of the results metadata copied from the settings |
| 2018 | * will have to be passed to the libcamera::Camera and extracted |
| 2019 | * from libcamera::Request::metadata. |
| 2020 | */ |
| 2021 | |
Jacopo Mondi | 520c366 | 2021-02-03 14:44:34 +0100 | [diff] [blame] | 2022 | uint8_t value = ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF; |
| 2023 | resultMetadata->addEntry(ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 2024 | &value, 1); |
| 2025 | |
| 2026 | value = ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF; |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 2027 | resultMetadata->addEntry(ANDROID_CONTROL_AE_ANTIBANDING_MODE, &value, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 2028 | |
Jacopo Mondi | e9c2875 | 2021-02-03 14:47:45 +0100 | [diff] [blame] | 2029 | int32_t value32 = 0; |
| 2030 | resultMetadata->addEntry(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
| 2031 | &value32, 1); |
| 2032 | |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 2033 | value = ANDROID_CONTROL_AE_LOCK_OFF; |
| 2034 | resultMetadata->addEntry(ANDROID_CONTROL_AE_LOCK, &value, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 2035 | |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 2036 | value = ANDROID_CONTROL_AE_MODE_ON; |
| 2037 | resultMetadata->addEntry(ANDROID_CONTROL_AE_MODE, &value, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 2038 | |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 2039 | std::vector<int32_t> aeFpsTarget = { 30, 30 }; |
| 2040 | resultMetadata->addEntry(ANDROID_CONTROL_AE_TARGET_FPS_RANGE, |
| 2041 | aeFpsTarget.data(), aeFpsTarget.size()); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 2042 | |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 2043 | value = ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE; |
Jacopo Mondi | 94d42ce | 2021-01-29 14:54:39 +0100 | [diff] [blame] | 2044 | found = settings.getEntry(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, &entry); |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 2045 | resultMetadata->addEntry(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
Jacopo Mondi | 94d42ce | 2021-01-29 14:54:39 +0100 | [diff] [blame] | 2046 | found ? entry.data.u8 : &value, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 2047 | |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 2048 | value = ANDROID_CONTROL_AE_STATE_CONVERGED; |
| 2049 | resultMetadata->addEntry(ANDROID_CONTROL_AE_STATE, &value, 1); |
| 2050 | |
| 2051 | value = ANDROID_CONTROL_AF_MODE_OFF; |
| 2052 | resultMetadata->addEntry(ANDROID_CONTROL_AF_MODE, &value, 1); |
| 2053 | |
| 2054 | value = ANDROID_CONTROL_AF_STATE_INACTIVE; |
| 2055 | resultMetadata->addEntry(ANDROID_CONTROL_AF_STATE, &value, 1); |
| 2056 | |
| 2057 | value = ANDROID_CONTROL_AF_TRIGGER_IDLE; |
| 2058 | resultMetadata->addEntry(ANDROID_CONTROL_AF_TRIGGER, &value, 1); |
| 2059 | |
| 2060 | value = ANDROID_CONTROL_AWB_MODE_AUTO; |
| 2061 | resultMetadata->addEntry(ANDROID_CONTROL_AWB_MODE, &value, 1); |
| 2062 | |
| 2063 | value = ANDROID_CONTROL_AWB_LOCK_OFF; |
| 2064 | resultMetadata->addEntry(ANDROID_CONTROL_AWB_LOCK, &value, 1); |
| 2065 | |
| 2066 | value = ANDROID_CONTROL_AWB_STATE_CONVERGED; |
| 2067 | resultMetadata->addEntry(ANDROID_CONTROL_AWB_STATE, &value, 1); |
| 2068 | |
| 2069 | value = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; |
| 2070 | resultMetadata->addEntry(ANDROID_CONTROL_CAPTURE_INTENT, &value, 1); |
| 2071 | |
| 2072 | value = ANDROID_CONTROL_EFFECT_MODE_OFF; |
| 2073 | resultMetadata->addEntry(ANDROID_CONTROL_EFFECT_MODE, &value, 1); |
| 2074 | |
| 2075 | value = ANDROID_CONTROL_MODE_AUTO; |
| 2076 | resultMetadata->addEntry(ANDROID_CONTROL_MODE, &value, 1); |
| 2077 | |
| 2078 | value = ANDROID_CONTROL_SCENE_MODE_DISABLED; |
| 2079 | resultMetadata->addEntry(ANDROID_CONTROL_SCENE_MODE, &value, 1); |
| 2080 | |
| 2081 | value = ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF; |
| 2082 | resultMetadata->addEntry(ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, &value, 1); |
| 2083 | |
| 2084 | value = ANDROID_FLASH_MODE_OFF; |
| 2085 | resultMetadata->addEntry(ANDROID_FLASH_MODE, &value, 1); |
| 2086 | |
| 2087 | value = ANDROID_FLASH_STATE_UNAVAILABLE; |
| 2088 | resultMetadata->addEntry(ANDROID_FLASH_STATE, &value, 1); |
| 2089 | |
Jacopo Mondi | 94d42ce | 2021-01-29 14:54:39 +0100 | [diff] [blame] | 2090 | if (settings.getEntry(ANDROID_LENS_APERTURE, &entry)) |
Paul Elder | abfabdd | 2021-01-23 13:54:28 +0900 | [diff] [blame] | 2091 | resultMetadata->addEntry(ANDROID_LENS_APERTURE, entry.data.f, 1); |
| 2092 | |
| 2093 | float focal_length = 1.0; |
| 2094 | resultMetadata->addEntry(ANDROID_LENS_FOCAL_LENGTH, &focal_length, 1); |
| 2095 | |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 2096 | value = ANDROID_LENS_STATE_STATIONARY; |
| 2097 | resultMetadata->addEntry(ANDROID_LENS_STATE, &value, 1); |
| 2098 | |
| 2099 | value = ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF; |
| 2100 | resultMetadata->addEntry(ANDROID_LENS_OPTICAL_STABILIZATION_MODE, |
| 2101 | &value, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 2102 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 2103 | resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, ×tamp, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 2104 | |
Jacopo Mondi | 3e979d7 | 2021-01-04 16:28:24 +0100 | [diff] [blame] | 2105 | value = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; |
| 2106 | resultMetadata->addEntry(ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 2107 | &value, 1); |
| 2108 | |
| 2109 | value = ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF; |
| 2110 | resultMetadata->addEntry(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, |
| 2111 | &value, 1); |
| 2112 | |
| 2113 | value = ANDROID_STATISTICS_SCENE_FLICKER_NONE; |
| 2114 | resultMetadata->addEntry(ANDROID_STATISTICS_SCENE_FLICKER, |
| 2115 | &value, 1); |
| 2116 | |
| 2117 | value = ANDROID_NOISE_REDUCTION_MODE_OFF; |
| 2118 | resultMetadata->addEntry(ANDROID_NOISE_REDUCTION_MODE, &value, 1); |
| 2119 | |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 2120 | /* 33.3 msec */ |
| 2121 | const int64_t rolling_shutter_skew = 33300000; |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 2122 | resultMetadata->addEntry(ANDROID_SENSOR_ROLLING_SHUTTER_SKEW, |
| 2123 | &rolling_shutter_skew, 1); |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 2124 | |
Jacopo Mondi | 3535e0c | 2020-12-09 17:51:57 +0100 | [diff] [blame] | 2125 | /* Add metadata tags reported by libcamera. */ |
| 2126 | if (metadata.contains(controls::draft::PipelineDepth)) { |
| 2127 | uint8_t pipeline_depth = |
| 2128 | metadata.get<int32_t>(controls::draft::PipelineDepth); |
| 2129 | resultMetadata->addEntry(ANDROID_REQUEST_PIPELINE_DEPTH, |
| 2130 | &pipeline_depth, 1); |
| 2131 | } |
| 2132 | |
Jacopo Mondi | c9705a5 | 2021-01-05 19:30:48 +0100 | [diff] [blame] | 2133 | if (metadata.contains(controls::ExposureTime)) { |
Paul Elder | 78f49d5 | 2021-01-28 17:45:44 +0900 | [diff] [blame] | 2134 | int64_t exposure = metadata.get(controls::ExposureTime) * 1000ULL; |
Jacopo Mondi | c9705a5 | 2021-01-05 19:30:48 +0100 | [diff] [blame] | 2135 | resultMetadata->addEntry(ANDROID_SENSOR_EXPOSURE_TIME, |
| 2136 | &exposure, 1); |
| 2137 | } |
| 2138 | |
Jacopo Mondi | bb2b400 | 2021-01-04 16:20:05 +0100 | [diff] [blame] | 2139 | if (metadata.contains(controls::ScalerCrop)) { |
| 2140 | Rectangle crop = metadata.get(controls::ScalerCrop); |
| 2141 | int32_t cropRect[] = { |
| 2142 | crop.x, crop.y, static_cast<int32_t>(crop.width), |
| 2143 | static_cast<int32_t>(crop.height), |
| 2144 | }; |
| 2145 | resultMetadata->addEntry(ANDROID_SCALER_CROP_REGION, cropRect, 4); |
| 2146 | } |
| 2147 | |
Laurent Pinchart | 3986009 | 2019-09-05 03:12:34 +0300 | [diff] [blame] | 2148 | /* |
| 2149 | * Return the result metadata pack even is not valid: get() will return |
| 2150 | * nullptr. |
| 2151 | */ |
| 2152 | if (!resultMetadata->isValid()) { |
| 2153 | LOG(HAL, Error) << "Failed to construct result metadata"; |
| 2154 | } |
Jacopo Mondi | 667d8ea | 2019-05-10 17:40:02 +0200 | [diff] [blame] | 2155 | |
| 2156 | return resultMetadata; |
| 2157 | } |