From patchwork Fri Apr 30 17:38:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 12157 X-Patchwork-Delegate: laurent.pinchart@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 43A71BDE4F for ; Fri, 30 Apr 2021 17:37:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 13D0968914; Fri, 30 Apr 2021 19:37:28 +0200 (CEST) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9AB3B688A5 for ; Fri, 30 Apr 2021 19:37:26 +0200 (CEST) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 31DEF200006; Fri, 30 Apr 2021 17:37:26 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 30 Apr 2021 19:38:01 +0200 Message-Id: <20210430173803.198220-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210430173803.198220-1-jacopo@jmondi.org> References: <20210430173803.198220-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 1/3] libcamera: Introduce camera sensor properties 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" Introduce a database of camera sensor properties, which contains information on the camera sensor which are not possible, or desirable, to retrieve from the device at run time. The camera sensor database is accessed through a static function and is indexed using the camera sensor model as reported by properties::Model. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- .../internal/camera_sensor_properties.h | 24 +++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/camera_sensor_properties.cpp | 71 +++++++++++++++++++ src/libcamera/meson.build | 1 + 4 files changed, 97 insertions(+) create mode 100644 include/libcamera/internal/camera_sensor_properties.h create mode 100644 src/libcamera/camera_sensor_properties.cpp diff --git a/include/libcamera/internal/camera_sensor_properties.h b/include/libcamera/internal/camera_sensor_properties.h new file mode 100644 index 000000000000..f5e242cb34a2 --- /dev/null +++ b/include/libcamera/internal/camera_sensor_properties.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * camera_sensor_properties.h - Database of camera sensor properties + */ +#ifndef __LIBCAMERA_SENSOR_CAMERA_SENSOR_PROPERTIES_H__ +#define __LIBCAMERA_SENSOR_CAMERA_SENSOR_PROPERTIES_H__ + +#include + +#include + +namespace libcamera { + +struct CameraSensorProperties { + static const CameraSensorProperties *get(const std::string &sensor); + + Size unitCellSize; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_SENSOR_CAMERA_SENSOR_PROPERTIES_H__ */ diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index 1fe3918cfe93..6cff1b9032c6 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -15,6 +15,7 @@ libcamera_internal_headers = files([ 'byte_stream_buffer.h', 'camera_controls.h', 'camera_sensor.h', + 'camera_sensor_properties.h', 'control_serializer.h', 'control_validator.h', 'delayed_controls.h', diff --git a/src/libcamera/camera_sensor_properties.cpp b/src/libcamera/camera_sensor_properties.cpp new file mode 100644 index 000000000000..6ded31dcae4f --- /dev/null +++ b/src/libcamera/camera_sensor_properties.cpp @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * camera_sensor_properties.cpp - Database of camera sensor properties + */ + +#include "libcamera/internal/camera_sensor_properties.h" + +#include + +#include "libcamera/internal/log.h" + +/** + * \file camera_sensor_properties.h + * \brief Database of camera sensor properties + * + * The database of camera sensor properties collects static information about + * camera sensors that is not possible or desirable to retrieve from the device + * at run time. + * + * The database is indexed using the camera sensor model, as reported by the + * properties::Model property, and for each supported sensor it contains a + * list of properties. + */ + +namespace libcamera { + +LOG_DEFINE_CATEGORY(CameraSensorProperties) + +/** + * \struct CameraSensorProperties + * \brief Database of camera sensor properties + * + * \var CameraSensorProperties::unitCellSize + * \brief The physical size of a pixel, including pixel edges, in nanometers. + */ + +/** + * \brief Retrieve the properties associated with a sensor + * \param sensor The sensor model name as reported by properties::Model + * \return A pointer to the CameraSensorProperties instance associated with a sensor + * or nullptr if the sensor is not supported + */ +const CameraSensorProperties *CameraSensorProperties::get(const std::string &sensor) +{ + static const std::map sensorProps = { + { "imx219", { + .unitCellSize = { 1120, 1120 }, + } }, + { "ov5670", { + .unitCellSize = { 1120, 1120 }, + } }, + { "ov13858", { + .unitCellSize = { 1120, 1120 }, + } }, + }; + + const auto it = sensorProps.find(sensor); + if (it == sensorProps.end()) { + LOG(CameraSensorProperties, Warning) + << "No static properties available for '" << sensor << "'"; + LOG(CameraSensorProperties, Warning) + << "Please consider updating the camera sensor properties database"; + return nullptr; + } + + return &it->second; +} + +} /* namespace libcamera */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index e0a48aa23ea5..675053d41513 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -9,6 +9,7 @@ libcamera_sources = files([ 'camera_controls.cpp', 'camera_manager.cpp', 'camera_sensor.cpp', + 'camera_sensor_properties.cpp', 'class.cpp', 'controls.cpp', 'control_serializer.cpp', From patchwork Fri Apr 30 17:38:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 12158 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 141ACBDE4F for ; Fri, 30 Apr 2021 17:37:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7C02868909; Fri, 30 Apr 2021 19:37:30 +0200 (CEST) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C0B62688E4 for ; Fri, 30 Apr 2021 19:37:27 +0200 (CEST) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id C6EA8200006; Fri, 30 Apr 2021 17:37:26 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 30 Apr 2021 19:38:02 +0200 Message-Id: <20210430173803.198220-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210430173803.198220-1-jacopo@jmondi.org> References: <20210430173803.198220-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 2/3] libcamera: camera_sensor: Register static properties 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: , Cc: =?utf-8?q?Niklas_S=C3=B6derlund?= Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Register static properties in the CameraSensor class by inspecting the camera sensor properties database. Static properties are overridden by properties retrieved from the kernel interface at run-time if any overlap between the two sets occurs. Reviewed-by: Hirokazu Honda Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 1 + src/libcamera/camera_sensor.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 3e98f71b5e7f..3fa3a419f94a 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -77,6 +77,7 @@ private: int generateId(); int validateSensorDriver(); void initVimcDefaultProperties(); + void initStaticProperties(); int initProperties(); const MediaEntity *entity_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 2887bb69ca02..1db263cfae2d 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -19,6 +19,7 @@ #include #include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/camera_sensor_properties.h" #include "libcamera/internal/formats.h" #include "libcamera/internal/sysfs.h" #include "libcamera/internal/utils.h" @@ -407,6 +408,16 @@ void CameraSensor::initVimcDefaultProperties() activeArea_ = Rectangle(pixelArraySize_); } +void CameraSensor::initStaticProperties() +{ + const CameraSensorProperties *props = CameraSensorProperties::get(model_); + if (!props) + return; + + /* Register the properties retrieved from the sensor database. */ + properties_.set(properties::UnitCellSize, props->unitCellSize); +} + int CameraSensor::initProperties() { /* @@ -444,7 +455,10 @@ int CameraSensor::initProperties() if (ret) return ret; - /* Retrieve and store the camera sensor properties. */ + /* Initialize the static properties from the sensor database. */ + initStaticProperties(); + + /* Retrieve and register properties from the kernel interface. */ const ControlInfoMap &controls = subdev_->controls(); int32_t propertyValue; From patchwork Fri Apr 30 17:38:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 12159 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 E2C7CBDE4F for ; Fri, 30 Apr 2021 17:37:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9FF0468901; Fri, 30 Apr 2021 19:37:32 +0200 (CEST) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F0A40688A5 for ; Fri, 30 Apr 2021 19:37:28 +0200 (CEST) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id EA07C200008; Fri, 30 Apr 2021 17:37:27 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 30 Apr 2021 19:38:03 +0200 Message-Id: <20210430173803.198220-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210430173803.198220-1-jacopo@jmondi.org> References: <20210430173803.198220-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 3/3] android: camera_device: Report sensor physical size 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" Calculate the value of the ANDROID_SENSOR_INFO_PHYSICAL_SIZE property multiplying the number of sensor's readable pixels with the pixel unit cell size if provided by the Camera. Reviewed-by: Laurent Pinchart Reviewed-by: Hirokazu Honda Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index a71aee2fc734..3d5b5f2432ad 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -9,6 +9,7 @@ #include "camera_ops.h" #include "post_processor.h" +#include #include #include #include @@ -1032,15 +1033,23 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() staticMetadata_->addEntry(ANDROID_JPEG_MAX_SIZE, &maxJpegBufferSize_, 1); /* Sensor static metadata. */ + std::array pixelArraySize; { - const Size &size = - properties.get(properties::PixelArraySize); - std::vector data{ - static_cast(size.width), - static_cast(size.height), - }; + const Size &size = properties.get(properties::PixelArraySize); + pixelArraySize[0] = size.width; + pixelArraySize[1] = size.height; staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, - data.data(), data.size()); + pixelArraySize.data(), pixelArraySize.size()); + } + + if (properties.contains(properties::UnitCellSize)) { + const Size &cellSize = properties.get(properties::UnitCellSize); + std::array physicalSize{ + cellSize.width * pixelArraySize[0] / 1e6f, + cellSize.height * pixelArraySize[1] / 1e6f + }; + staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, + physicalSize.data(), physicalSize.size()); } { @@ -1088,13 +1097,6 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() testPatterModes.data(), testPatterModes.size()); - std::vector physicalSize = { - 2592, 1944, - }; - staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, - physicalSize.data(), - physicalSize.size()); - uint8_t timestampSource = ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN; staticMetadata_->addEntry(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, ×tampSource, 1);