From patchwork Sat Jul 25 14:40:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9005 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9910EBD87A for ; Sat, 25 Jul 2020 14:37:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 117016138C; Sat, 25 Jul 2020 16:37:32 +0200 (CEST) Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 64D4A611A2 for ; Sat, 25 Jul 2020 16:37:30 +0200 (CEST) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id BB3C9240004; Sat, 25 Jul 2020 14:37:29 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 25 Jul 2020 16:40:57 +0200 Message-Id: <20200725144058.129388-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200725144058.129388-1-jacopo@jmondi.org> References: <20200725144058.129388-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 5/6] android: camera_device: Break-out request template X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Currently the request template returned from CameraDevice::constructDefaultRequestSettings() is the same for all the supported template types. To prepare to adjust the template depending on the use case, break out the template generation to a dedicated function that supports the PREVIEW use case. All the other template types use the requestTemplatePreview() function and just update the capture intent property. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 82 ++++++++++++++++++++--------------- src/android/camera_device.h | 1 + 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 48f8090a93db..b294b88367d4 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -821,48 +821,14 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() return staticMetadata_->get(); } -/* - * Produce a metadata pack to be used as template for a capture request. - */ -const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) +CameraMetadata *CameraDevice::requestTemplatePreview() { - auto it = requestTemplates_.find(type); - if (it != requestTemplates_.end()) - return it->second->get(); - - /* Use the capture intent matching the requested template type. */ - uint8_t captureIntent; - switch (type) { - case CAMERA3_TEMPLATE_PREVIEW: - captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; - break; - case CAMERA3_TEMPLATE_STILL_CAPTURE: - captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE; - break; - case CAMERA3_TEMPLATE_VIDEO_RECORD: - captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD; - break; - case CAMERA3_TEMPLATE_VIDEO_SNAPSHOT: - captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT; - break; - case CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG: - captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG; - break; - case CAMERA3_TEMPLATE_MANUAL: - captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_MANUAL; - break; - default: - LOG(HAL, Error) << "Invalid template request type: " << type; - return nullptr; - } - /* * \todo Keep this in sync with the actual number of entries. * Currently: 12 entries, 15 bytes */ CameraMetadata *requestTemplate = new CameraMetadata(15, 20); if (!requestTemplate->isValid()) { - LOG(HAL, Error) << "Failed to allocate template metadata"; delete requestTemplate; return nullptr; } @@ -911,15 +877,59 @@ const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) requestTemplate->addEntry(ANDROID_COLOR_CORRECTION_ABERRATION_MODE, &aberrationMode, 1); + uint8_t captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; requestTemplate->addEntry(ANDROID_CONTROL_CAPTURE_INTENT, &captureIntent, 1); - if (!requestTemplate->isValid()) { + return requestTemplate; +} + +/* + * Produce a metadata pack to be used as template for a capture request. + */ +const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) +{ + auto it = requestTemplates_.find(type); + if (it != requestTemplates_.end()) + return it->second->get(); + + /* Use the capture intent matching the requested template type. */ + CameraMetadata *requestTemplate; + uint8_t captureIntent; + switch (type) { + case CAMERA3_TEMPLATE_PREVIEW: + captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; + break; + case CAMERA3_TEMPLATE_STILL_CAPTURE: + captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE; + break; + case CAMERA3_TEMPLATE_VIDEO_RECORD: + captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD; + break; + case CAMERA3_TEMPLATE_VIDEO_SNAPSHOT: + captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT; + break; + case CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG: + captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG; + break; + case CAMERA3_TEMPLATE_MANUAL: + captureIntent = ANDROID_CONTROL_CAPTURE_INTENT_MANUAL; + break; + default: + LOG(HAL, Error) << "Invalid template request type: " << type; + return nullptr; + } + + requestTemplate = requestTemplatePreview(); + if (!requestTemplate || !requestTemplate->isValid()) { LOG(HAL, Error) << "Failed to construct request template"; delete requestTemplate; return nullptr; } + requestTemplate->updateEntry(ANDROID_CONTROL_CAPTURE_INTENT, + &captureIntent, 1); + requestTemplates_[type] = requestTemplate; return requestTemplate->get(); } diff --git a/src/android/camera_device.h b/src/android/camera_device.h index af1b58ab6b4e..5a52ad8f741c 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -83,6 +83,7 @@ private: libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer); void notifyShutter(uint32_t frameNumber, uint64_t timestamp); void notifyError(uint32_t frameNumber, camera3_stream_t *stream); + CameraMetadata *requestTemplatePreview(); libcamera::PixelFormat toPixelFormat(int format); std::unique_ptr getResultMetadata(int frame_number, int64_t timestamp);