diff options
author | Jacopo Mondi <jacopo@jmondi.org> | 2021-01-04 16:20:05 +0100 |
---|---|---|
committer | Jacopo Mondi <jacopo@jmondi.org> | 2021-01-25 15:20:36 +0100 |
commit | bb2b400638d290fc91953017b1a4c9eb2402f588 (patch) | |
tree | e0cea8df3c7efb953cf4c98bb8a185dafb81e5a5 /src/android/camera_device.cpp | |
parent | 953403288ef17e7f332a621b9113e75564f44407 (diff) |
android: camera_device: Handle SCALER_CROP_REGION
Handle the SCALER_CROP_REGION control and dynamic metadata by
translating it from the Android format to the associated libcamera
control when processing a request, and the other way around when
handling a request completion.
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/android/camera_device.cpp')
-rw-r--r-- | src/android/camera_device.cpp | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index edc89bdb..9f045777 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1593,6 +1593,26 @@ FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer return new FrameBuffer(std::move(planes)); } +int CameraDevice::processControls(Camera3RequestDescriptor *descriptor) +{ + const CameraMetadata &settings = descriptor->settings_; + if (!settings.isValid()) + return 0; + + /* Translate the Android request settings to libcamera controls. */ + camera_metadata_ro_entry_t entry; + if (settings.getEntry(ANDROID_SCALER_CROP_REGION, &entry)) { + const int32_t *data = entry.data.i32; + Rectangle cropRegion{ data[0], data[1], + static_cast<unsigned int>(data[2]), + static_cast<unsigned int>(data[3]) }; + ControlList &controls = descriptor->request_->controls(); + controls.set(controls::ScalerCrop, cropRegion); + } + + return 0; +} + int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) { if (!camera3Request) { @@ -1689,7 +1709,14 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques camera3Buffer->acquire_fence); } - /* Queue the request to the CameraWorker. */ + /* + * Translate controls from Android to libcamera and queue the request + * to the CameraWorker thread. + */ + int ret = processControls(descriptor); + if (ret) + return ret; + worker_.queueRequest(descriptor->request_.get()); return 0; @@ -1868,11 +1895,6 @@ CameraDevice::getResultMetadata(Camera3RequestDescriptor *descriptor, const uint8_t lens_state = ANDROID_LENS_STATE_STATIONARY; resultMetadata->addEntry(ANDROID_LENS_STATE, &lens_state, 1); - int32_t sensorSizes[] = { - 0, 0, 2560, 1920, - }; - resultMetadata->addEntry(ANDROID_SCALER_CROP_REGION, sensorSizes, 4); - resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, ×tamp, 1); /* 33.3 msec */ @@ -1903,6 +1925,15 @@ CameraDevice::getResultMetadata(Camera3RequestDescriptor *descriptor, &exposure, 1); } + if (metadata.contains(controls::ScalerCrop)) { + Rectangle crop = metadata.get(controls::ScalerCrop); + int32_t cropRect[] = { + crop.x, crop.y, static_cast<int32_t>(crop.width), + static_cast<int32_t>(crop.height), + }; + resultMetadata->addEntry(ANDROID_SCALER_CROP_REGION, cropRect, 4); + } + /* * Return the result metadata pack even is not valid: get() will return * nullptr. |