From patchwork Fri Jul 30 10:35:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 13163 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 6AEE8C322E for ; Fri, 30 Jul 2021 10:35:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0B5E8687BF; Fri, 30 Jul 2021 12:35:58 +0200 (CEST) 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="sHljtk9H"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DA54D687CA for ; Fri, 30 Jul 2021 12:35:56 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7945989B; Fri, 30 Jul 2021 12:35:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1627641356; bh=H0mID5rZOzSMlfaY+POUcSbeqquTRz719E8VxID2t+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sHljtk9Hw/wJ4ZBw1aYXW9JMZFIzAPY0NtPCdGLCkJ0/Dy/wcbqEpx+kt4/EHjT50 SgPjMrdmx3fa/VXL16HkR4ZObNLXo2fh1qact4+al3l3w5svptIqpnIGFRVQXH3/tv tBXmnQfbLK0sBwA3bNcdMUNvZ0Ft3ilpCYcciTgk= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Fri, 30 Jul 2021 19:35:32 +0900 Message-Id: <20210730103536.81117-6-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210730103536.81117-1-paul.elder@ideasonboard.com> References: <20210730103536.81117-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 5/9] android: Add infrastructure for determining capabilities and hardware level 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 the infrastructure for checking and reporting capabilities. Use these capabilities to determine the hardware level as well. Bug: https://bugs.libcamera.org/show_bug.cgi?id=55 Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- Changes in v7: - use entryContains for the single-presence checks - go back to set - use the staticMetadata_ member variable instead of passing it - return false in the capaibilities detector, with a todo item Changes in v6: - make all args const - convert the caps list from set to vector Changes in v5: - change the whole thing to turn on capabilities after they are all confirmed, instead of disabling them as conditions are not met Changes in v4: - rebase on camera capabilities refactoring - switch to std::set from std::map - make hwlevel similar to capabilities Changes in v3: - fix some compiler errors - go ahead and initialize the capabilities to true, update the commit message accordingly Changes in v2: - add a flag for FULL, since there are a few requirements that are not obtained from capabilities alone - add burst capture capability, since that is required for FULL as well --- src/android/camera_capabilities.cpp | 202 +++++++++++++++++++++++++--- src/android/camera_capabilities.h | 11 ++ 2 files changed, 198 insertions(+), 15 deletions(-) diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp index 3596b136..b59a854f 100644 --- a/src/android/camera_capabilities.cpp +++ b/src/android/camera_capabilities.cpp @@ -7,8 +7,10 @@ #include "camera_capabilities.h" +#include #include #include +#include #include @@ -114,8 +116,180 @@ const std::map camera3FormatsMap = { }, }; +const std::map +hwLevelStrings = { + { ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED, "LIMITED" }, + { ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_FULL, "FULL" }, + { ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY, "LEGACY" }, + { ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_3, "LEVEL_3" }, + { ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL, "EXTERNAL" }, +}; + } /* namespace */ +bool CameraCapabilities::validateManualSensorCapability() +{ + const char *noMode = "Manual sensor capability unavailable: "; + + if (!staticMetadata_->entryContains(ANDROID_CONTROL_AE_AVAILABLE_MODES, + ANDROID_CONTROL_AE_MODE_OFF)) { + LOG(HAL, Info) << noMode << "missing AE mode off"; + return false; + } + + if (!staticMetadata_->entryContains(ANDROID_CONTROL_AE_LOCK_AVAILABLE, + ANDROID_CONTROL_AE_LOCK_AVAILABLE_TRUE)) { + LOG(HAL, Info) << noMode << "missing AE lock"; + return false; + } + + /* + * \todo Return true here after we satisfy all the requirements: + * https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR + * Manual frame duration control + * android.sensor.frameDuration + * android.sensor.info.maxFrameDuration + * Manual exposure control + * android.sensor.exposureTime + * android.sensor.info.exposureTimeRange + * Manual sensitivity control + * android.sensor.sensitivity + * android.sensor.info.sensitivityRange + * Manual lens control (if the lens is adjustable) + * android.lens.* + * Manual flash control (if a flash unit is present) + * android.flash.* + * Manual black level locking + * android.blackLevel.lock + * Auto exposure lock + * android.control.aeLock + */ + return false; +} + +bool CameraCapabilities::validateManualPostProcessingCapability() +{ + const char *noMode = "Manual post processing capability unavailable: "; + + if (!staticMetadata_->entryContains(ANDROID_CONTROL_AWB_AVAILABLE_MODES, + ANDROID_CONTROL_AWB_MODE_OFF)) { + LOG(HAL, Info) << noMode << "missing AWB mode off"; + return false; + } + + if (!staticMetadata_->entryContains(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, + ANDROID_CONTROL_AWB_LOCK_AVAILABLE_TRUE)) { + LOG(HAL, Info) << noMode << "missing AWB lock"; + return false; + } + + /* + * \todo return true here after we satisfy all the requirements: + * https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING + * Manual tonemap control + * android.tonemap.curve + * android.tonemap.mode + * android.tonemap.maxCurvePoints + * android.tonemap.gamma + * android.tonemap.presetCurve + * Manual white balance control + * android.colorCorrection.transform + * android.colorCorrection.gains + * Manual lens shading map control + * android.shading.mode + * android.statistics.lensShadingMapMode + * android.statistics.lensShadingMap + * android.lens.info.shadingMapSize + * Manual aberration correction control (if aberration correction is supported) + * android.colorCorrection.aberrationMode + * android.colorCorrection.availableAberrationModes + * Auto white balance lock + * android.control.awbLock + */ + return false; +} + +bool CameraCapabilities::validateBurstCaptureCapability() +{ + camera_metadata_ro_entry_t entry; + bool found; + + const char *noMode = "Burst capture capability unavailable: "; + + if (!staticMetadata_->entryContains(ANDROID_CONTROL_AE_LOCK_AVAILABLE, + ANDROID_CONTROL_AE_LOCK_AVAILABLE_TRUE)) { + LOG(HAL, Info) << noMode << "missing AE lock"; + return false; + } + + if (!staticMetadata_->entryContains(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, + ANDROID_CONTROL_AWB_LOCK_AVAILABLE_TRUE)) { + LOG(HAL, Info) << noMode << "missing AWB lock"; + return false; + } + + found = staticMetadata_->getEntry(ANDROID_SYNC_MAX_LATENCY, &entry); + if (!found || *entry.data.i32 < 0 || 4 < *entry.data.i32) { + LOG(HAL, Info) + << noMode << "max sync latency is " + << (found ? std::to_string(*entry.data.i32) : "not present"); + return false; + } + + /* + * \todo return true here after we satisfy all the requirements + * https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE + */ + return false; +} + +std::set +CameraCapabilities::computeCapabilities() +{ + std::set + capabilities; + + capabilities.insert(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE); + + if (validateManualSensorCapability()) + capabilities.insert(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR); + + if (validateManualPostProcessingCapability()) + capabilities.insert(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING); + + if (validateBurstCaptureCapability()) + capabilities.insert(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE); + + if (rawStreamAvailable_) + capabilities.insert(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_RAW); + + return capabilities; +} + +void CameraCapabilities::computeHwLevel( + const std::set &caps) +{ + camera_metadata_ro_entry_t entry; + bool found; + camera_metadata_enum_android_info_supported_hardware_level + hwLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_FULL; + + if (!caps.count(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR)) + hwLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; + + if (!caps.count(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING)) + hwLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; + + if (!caps.count(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE)) + hwLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; + + found = staticMetadata_->getEntry(ANDROID_SYNC_MAX_LATENCY, &entry); + if (!found || *entry.data.i32 != 0) + hwLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; + + hwLevel_ = hwLevel; +} + int CameraCapabilities::initialize(std::shared_ptr camera, int orientation, int facing) { @@ -851,11 +1025,6 @@ int CameraCapabilities::initializeStaticMetadata() uint8_t croppingType = ANDROID_SCALER_CROPPING_TYPE_CENTER_ONLY; staticMetadata_->addEntry(ANDROID_SCALER_CROPPING_TYPE, croppingType); - /* Info static metadata. */ - uint8_t supportedHWLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; - staticMetadata_->addEntry(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, - supportedHWLevel); - /* Request static metadata. */ int32_t partialResultCount = 1; staticMetadata_->addEntry(ANDROID_REQUEST_PARTIAL_RESULT_COUNT, @@ -876,21 +1045,24 @@ int CameraCapabilities::initializeStaticMetadata() staticMetadata_->addEntry(ANDROID_REQUEST_MAX_NUM_INPUT_STREAMS, maxNumInputStreams); - std::vector availableCapabilities = { - ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE, - }; - - /* Report if camera supports RAW. */ - if (rawStreamAvailable_) - availableCapabilities.push_back(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_RAW); - /* Number of { RAW, YUV, JPEG } supported output streams */ int32_t numOutStreams[] = { rawStreamAvailable_, 2, 1 }; staticMetadata_->addEntry(ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS, numOutStreams); - staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, - availableCapabilities); + /* Check capabilities */ + std::set + capabilities = computeCapabilities(); + std::vector + capsVec(capabilities.begin(), capabilities.end()); + staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, capsVec); + + computeHwLevel(capabilities); + staticMetadata_->addEntry(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, hwLevel_); + + LOG(HAL, Info) + << "Hardware level: " + << hwLevelStrings.find(hwLevel_)->second; std::vector availableCharacteristicsKeys = { ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, diff --git a/src/android/camera_capabilities.h b/src/android/camera_capabilities.h index 42a976d3..c7a966ce 100644 --- a/src/android/camera_capabilities.h +++ b/src/android/camera_capabilities.h @@ -42,6 +42,16 @@ private: int androidFormat; }; + bool validateManualSensorCapability(); + bool validateManualPostProcessingCapability(); + bool validateBurstCaptureCapability(); + + std::set + computeCapabilities(); + + void computeHwLevel( + const std::set &caps); + std::vector initializeYUVResolutions(const libcamera::PixelFormat &pixelFormat, const std::vector &resolutions); @@ -56,6 +66,7 @@ private: int facing_; int orientation_; bool rawStreamAvailable_; + camera_metadata_enum_android_info_supported_hardware_level hwLevel_; std::vector streamConfigurations_; std::map formatsMap_;