From patchwork Tue Dec 21 05:10:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 15192 X-Patchwork-Delegate: paul.elder@ideasonboard.com 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 AB975BE080 for ; Tue, 21 Dec 2021 05:10:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5EC4F608FB; Tue, 21 Dec 2021 06:10:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="EivcPtmn"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E19AC608A2 for ; Tue, 21 Dec 2021 06:10:37 +0100 (CET) Received: from pyrite.mediacom.info (unknown [IPv6:2604:2d80:ad90:fb00:96fd:8874:873:6c16]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1E128881; Tue, 21 Dec 2021 06:10:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1640063437; bh=LDxye+Yt2azrg2N2mD2kFUpmtKkA2N67mtnHeY03Bxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EivcPtmntobPhOxeyngTyGsOo+/OZNO6X2p2/1niS/AH0fqDXRxCbxOytTXPVTW3q 6bILokoEH7V0VxxTcP2FoYxjPxCysSdo+GxiIS2iP3rSn8sMlTJb4IUO6+8NK7MRfH bL1FMQb+avfVOPsgt38bjEuO7c9ItfaqYxwqbjL4= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Dec 2021 23:10:23 -0600 Message-Id: <20211221051023.2628625-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211221051023.2628625-1-paul.elder@ideasonboard.com> References: <20211221051023.2628625-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/3] android: Plumb noise reduction 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" Add: - hardware level detection based on available noise reduction values (no specific capabilities seem to require it; only FULL in general) - Conversion from android to libcamera noise reduction modes for request (use switch-case instead of direct copy just in case) - Conversion from libcamera to android noise reduction modes for result - noise reduction values to the templates We already have the mechanism to report the available noise reduction modes, so that is not added. Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham --- Changes in v2: - change result metadata generation to switch-case --- src/android/camera_capabilities.cpp | 34 +++++++++++++- src/android/camera_device.cpp | 70 +++++++++++++++++++++++++++-- 2 files changed, 100 insertions(+), 4 deletions(-) diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp index d6a1589e..365937ed 100644 --- a/src/android/camera_capabilities.cpp +++ b/src/android/camera_capabilities.cpp @@ -412,6 +412,31 @@ void CameraCapabilities::computeHwLevel( hwLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; } + found = staticMetadata_->entryContains( + ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, + ANDROID_NOISE_REDUCTION_MODE_OFF); + if (!found) { + LOG(HAL, Info) << noFull << "missing noise reduction mode off"; + hwLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; + } + + found = staticMetadata_->entryContains( + ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, + ANDROID_NOISE_REDUCTION_MODE_FAST); + if (!found) { + LOG(HAL, Info) << noFull << "missing noise reduction mode fast"; + hwLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; + } + + /* Android docs don't say this is required, but CTS does. */ + found = staticMetadata_->entryContains( + ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, + ANDROID_NOISE_REDUCTION_MODE_HIGH_QUALITY); + if (!found) { + LOG(HAL, Info) << noFull << "missing noise reduction mode high quality"; + hwLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; + } + hwLevel_ = hwLevel; } @@ -1727,7 +1752,7 @@ std::unique_ptr CameraCapabilities::requestTemplatePreview() con requestTemplate->addEntry(ANDROID_STATISTICS_FACE_DETECT_MODE, faceDetectMode); - uint8_t noiseReduction = ANDROID_NOISE_REDUCTION_MODE_OFF; + uint8_t noiseReduction = ANDROID_NOISE_REDUCTION_MODE_FAST; requestTemplate->addEntry(ANDROID_NOISE_REDUCTION_MODE, noiseReduction); @@ -1764,6 +1789,13 @@ std::unique_ptr CameraCapabilities::requestTemplateStill() const stillTemplate->appendEntry(ANDROID_EDGE_MODE, edgeMode); } + if (staticMetadata_->entryContains( + ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, + ANDROID_NOISE_REDUCTION_MODE_HIGH_QUALITY)) { + uint8_t noiseReduction = ANDROID_NOISE_REDUCTION_MODE_HIGH_QUALITY; + stillTemplate->appendEntry(ANDROID_NOISE_REDUCTION_MODE, noiseReduction); + } + return stillTemplate; } diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 8861447d..e521ae0a 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -920,6 +920,39 @@ int CameraDevice::processControls(Camera3RequestDescriptor *descriptor) controls.set(controls::DigitalGain, lastDigitalGain_); } + if (settings.getEntry(ANDROID_NOISE_REDUCTION_MODE, &entry)) { + const uint8_t data = *entry.data.u8; + int32_t noiseReductionMode; + switch (data) { + case ANDROID_NOISE_REDUCTION_MODE_OFF: + noiseReductionMode = controls::NoiseReductionModeOff; + break; + + case ANDROID_NOISE_REDUCTION_MODE_FAST: + noiseReductionMode = controls::NoiseReductionModeFast; + break; + + case ANDROID_NOISE_REDUCTION_MODE_HIGH_QUALITY: + noiseReductionMode = controls::NoiseReductionModeHighQuality; + break; + + case ANDROID_NOISE_REDUCTION_MODE_MINIMAL: + noiseReductionMode = controls::NoiseReductionModeRaw; + break; + + case ANDROID_NOISE_REDUCTION_MODE_ZERO_SHUTTER_LAG: + noiseReductionMode = controls::NoiseReductionModeZSL; + break; + + default: + LOG(HAL, Error) + << "Unknown noise reduction mode: " << data; + return -EINVAL; + } + + controls.set(controls::NoiseReductionMode, noiseReductionMode); + } + if (settings.getEntry(ANDROID_EDGE_MODE, &entry)) { const auto &info = camera_->controls().find(&controls::Sharpness); if (info != camera_->controls().end()) { @@ -1587,9 +1620,6 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) cons value = ANDROID_STATISTICS_SCENE_FLICKER_NONE; resultMetadata->addEntry(ANDROID_STATISTICS_SCENE_FLICKER, value); - value = ANDROID_NOISE_REDUCTION_MODE_OFF; - resultMetadata->addEntry(ANDROID_NOISE_REDUCTION_MODE, value); - /* 33.3 msec */ const int64_t rolling_shutter_skew = 33300000; resultMetadata->addEntry(ANDROID_SENSOR_ROLLING_SHUTTER_SKEW, @@ -1643,6 +1673,40 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) cons resultMetadata->addEntry(ANDROID_SCALER_CROP_REGION, cropRect); } + if (metadata.contains(controls::NoiseReductionMode)) { + bool valid; + switch (metadata.get(controls::NoiseReductionMode)) { + case controls::NoiseReductionModeOff: + value = ANDROID_NOISE_REDUCTION_MODE_OFF; + valid = true; + break; + case controls::NoiseReductionModeFast: + value = ANDROID_NOISE_REDUCTION_MODE_FAST; + valid = true; + break; + case controls::NoiseReductionModeHighQuality: + value = ANDROID_NOISE_REDUCTION_MODE_HIGH_QUALITY; + valid = true; + break; + case controls::NoiseReductionModeRaw: + value = ANDROID_NOISE_REDUCTION_MODE_MINIMAL; + valid = true; + break; + case controls::NoiseReductionModeZSL: + value = ANDROID_NOISE_REDUCTION_MODE_ZERO_SHUTTER_LAG; + valid = true; + break; + default: + LOG(HAL, Error) + << "Unknown noise reduction mode"; + valid = false; + } + + /* Can be null on non-FULL */ + if (valid) + resultMetadata->addEntry(ANDROID_NOISE_REDUCTION_MODE, value); + } + if (metadata.contains(controls::draft::TestPatternMode)) { const int32_t testPatternMode = metadata.get(controls::draft::TestPatternMode);