From bb2b400638d290fc91953017b1a4c9eb2402f588 Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Mon, 4 Jan 2021 16:20:05 +0100 Subject: android: camera_device: Handle SCALER_CROP_REGION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 43 +++++++++++++++++++++++++++++++++++++------ src/android/camera_device.h | 1 + src/android/camera_worker.h | 1 + 3 files changed, 39 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(data[2]), + static_cast(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(crop.width), + static_cast(crop.height), + }; + resultMetadata->addEntry(ANDROID_SCALER_CROP_REGION, cropRect, 4); + } + /* * Return the result metadata pack even is not valid: get() will return * nullptr. diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 96b7fd99..597d11fc 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -104,6 +104,7 @@ private: void notifyError(uint32_t frameNumber, camera3_stream_t *stream); CameraMetadata *requestTemplatePreview(); libcamera::PixelFormat toPixelFormat(int format) const; + int processControls(Camera3RequestDescriptor *descriptor); std::unique_ptr getResultMetadata( Camera3RequestDescriptor *descriptor, int64_t timestamp); diff --git a/src/android/camera_worker.h b/src/android/camera_worker.h index 847a2fc4..6522f1d6 100644 --- a/src/android/camera_worker.h +++ b/src/android/camera_worker.h @@ -25,6 +25,7 @@ public: CaptureRequest(libcamera::Camera *camera, uint64_t cookie); const std::vector &fences() const { return acquireFences_; } + libcamera::ControlList &controls() { return request_->controls(); } const libcamera::ControlList &metadata() const { return request_->metadata(); -- cgit v1.2.1