From patchwork Tue Dec 8 09:00:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10610 X-Patchwork-Delegate: jacopo@jmondi.org 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 36D3EBDB21 for ; Tue, 8 Dec 2020 09:00:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 63BB567E6F; Tue, 8 Dec 2020 10:00:40 +0100 (CET) Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 35C3B635F2 for ; Tue, 8 Dec 2020 10:00:38 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id E9BD310000A for ; Tue, 8 Dec 2020 09:00:37 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Dec 2020 10:00:41 +0100 Message-Id: <20201208090042.4824-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201208090042.4824-1-jacopo@jmondi.org> References: <20201208090042.4824-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: Introduce camera sensor database 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 information, which contains a list of camera sensor properties which is not possible, or desirable, to retrieve at run-time. The camera sensor database is a global read-only library object, accessible by all the library components. Signed-off-by: Jacopo Mondi --- include/libcamera/camera_sensor_database.h | 41 +++++++ include/libcamera/meson.build | 1 + src/libcamera/camera_sensor_database.cpp | 119 +++++++++++++++++++++ src/libcamera/meson.build | 1 + 4 files changed, 162 insertions(+) create mode 100644 include/libcamera/camera_sensor_database.h create mode 100644 src/libcamera/camera_sensor_database.cpp diff --git a/include/libcamera/camera_sensor_database.h b/include/libcamera/camera_sensor_database.h new file mode 100644 index 000000000000..bbc38546e60e --- /dev/null +++ b/include/libcamera/camera_sensor_database.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * camera_sensor_database.h - Database of camera sensor properties + */ +#ifndef __LIBCAMERA_CAMERA_SENSOR_DATABASE_H__ +#define __LIBCAMERA_CAMERA_SENSOR_DATABASE_H__ + +#include +#include + +#include + +namespace libcamera { + +struct SensorEntry { + Size physicalSize; + Size pixelPhysicalSize; +}; + +class SensorDatabase : private std::unordered_map +{ +private: + using Map = std::unordered_map; + +public: + SensorDatabase(std::initializer_list items) + : Map(items) + { + } + + bool contains(Map::key_type sensor) const; + const SensorEntry &get(Map::key_type sensor) const; +}; + +extern const SensorDatabase sensorDatabase; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_CAMERA_SENSOR_DATABASE_H__ */ diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index cf2935f1ee95..0747adbda90a 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -5,6 +5,7 @@ libcamera_public_headers = files([ 'buffer.h', 'camera.h', 'camera_manager.h', + 'camera_sensor_database.h', 'controls.h', 'extensible.h', 'file_descriptor.h', diff --git a/src/libcamera/camera_sensor_database.cpp b/src/libcamera/camera_sensor_database.cpp new file mode 100644 index 000000000000..67800fa641c7 --- /dev/null +++ b/src/libcamera/camera_sensor_database.cpp @@ -0,0 +1,119 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * camera_sensor_database.cpp - Database of camera sensor properties + */ + +#include "libcamera/camera_sensor_database.h" + +namespace libcamera { + +/** + * \file camera_sensor_database.h + * \brief Database of camera sensor properties + * + * The camera sensor database collects information on camera sensors + * which is not possible or desirable to retrieve at run-time. + */ + +/** + * \struct SensorEntry + * \brief List of sensor properties + * + * \var SensorEntry::physicalSize + * \brief The physical size of the sensor area covered by pixels (active and non + * active ones). Width x height in nano-meters. + * + * \var SensorEntry::pixelPhysicalSize + * \brief The physical size of pixel, including pixel edges. Width x height in + * nano-meters. + */ + +/** + * \class SensorDatabase + * \brief Database of camera sensor properties + * + * The database is indexed using the camera sensor model, as reported by the + * properties::Model property, and for each supported sensor it contains a + * SensorEntry instance. + * + * The database is statically allocated and cannot be modified at runtime, and + * only provides two methods: one to verify if a sensor is supported + * (SensorDatabase::contains()) and one to retrieve the SensorEntry that + * describes a sensor (SensorDatabase::get()) + */ + +/** + * \fn SensorDatabase::SensorDatabase() + * \brief Contruct the sensor database with a list of values + * \param[in] items The list of sensor entries + */ + +/** + * \brief Verify if a sensor is part of the database + * \param sensor The sensor model name + * \return True if the sensor has an associated entry in the database, false + * otherwise + */ +bool SensorDatabase::contains(Map::key_type sensor) const +{ + return Map::find(sensor) != Map::end(); +} + +/** + * \brief Retrieve the properties associated with a sensor + * \param sensor The sensor model name + * \return The SensorEntry associated with a sensor or an empty SensorEntry if + * the sensor is not supported + */ +const SensorEntry &SensorDatabase::get(Map::key_type sensor) const +{ + static SensorEntry empty{}; + + auto it = Map::find(sensor); + if (it != Map::end()) + return it->second; + + return empty; +} + +/** \todo Autogenerate the per-sensor entries from a yaml schema. */ + +/** + * \brief Sony IMX219 sensor properties + */ +extern const SensorEntry imx219SensorEntry = { + .physicalSize = { 5095000, 4930000 }, + .pixelPhysicalSize = { 1120, 1120 } +}; + +/** + * \brief Omnivision ov5670 sensor properties + */ +extern const SensorEntry ov5670SensorEntry = { + .physicalSize = { 2945700, 2214000 }, + .pixelPhysicalSize = { 1120, 1120 } +}; + +/** + * \brief Omnivision 13858 sensor properties + */ +extern const SensorEntry ov13858SensorEntry = { + .physicalSize = { 4749700, 3535490 }, + .pixelPhysicalSize = { 1120, 1120 } +}; + +#define SENSOR_ENTRY(_sensor) \ + { #_sensor, _sensor ## SensorEntry } + +/** + * \brief Database of sensor information + */ +extern const SensorDatabase sensorDatabase = { + SENSOR_ENTRY(imx219), + SENSOR_ENTRY(ov5670), + SENSOR_ENTRY(ov13858), +}; + +} /* namespace libcamera */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 387d5d88ecae..3495d9ce45f8 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_database.cpp', 'controls.cpp', 'control_serializer.cpp', 'control_validator.cpp', From patchwork Tue Dec 8 09:00:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10611 X-Patchwork-Delegate: jacopo@jmondi.org 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 99376BDB22 for ; Tue, 8 Dec 2020 09:00:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8D60267E74; Tue, 8 Dec 2020 10:00:40 +0100 (CET) Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A20F8635F2 for ; Tue, 8 Dec 2020 10:00:38 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 657F2100009 for ; Tue, 8 Dec 2020 09:00:38 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Dec 2020 10:00:42 +0100 Message-Id: <20201208090042.4824-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201208090042.4824-1-jacopo@jmondi.org> References: <20201208090042.4824-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] android: camera_device: Get sensor properties from DB 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" Use the newly introduced camera sensor database to retrieve the physical size of the sensor to register the ANDROID_SENSOR_INFO_PHYSICAL_SIZE property. Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 872c7b18ee49..0c756f14c29c 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -595,6 +596,19 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() const ControlInfoMap &controlsInfo = camera_->controls(); const ControlList &properties = camera_->properties(); + /* + * If the camera sensor is not supported we get an empty SensorEntry. + * Record that in the log as all the properties retrieved from the + * empty SensorEntry will be zero. + */ + const std::string sensorModel = properties.get(properties::Model); + if (!sensorDatabase.contains(sensorModel)) { + LOG(HAL, Info) << "Camera sensor " << sensorModel + << " not supported."; + LOG(HAL, Info) << "All sensor-related properties will be set to zero"; + } + const SensorEntry &sensorEntry = sensorDatabase.get(sensorModel); + /* Color correction static metadata. */ { std::vector data; @@ -775,12 +789,15 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() testPatterModes.data(), testPatterModes.size()); - std::vector physicalSize = { - 2592, 1944, - }; + /* + * ANDROID_SENSOR_INFO_PHYSICAL_SIZE is in expressed in millimeters + * while the sensor database reports the physical sizes in nanometers. + */ + std::vector physicalSize; + physicalSize[0] = static_cast(sensorEntry.physicalSize.width * 10e6); + physicalSize[1] = static_cast(sensorEntry.physicalSize.height * 10e6); staticMetadata_->addEntry(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, - physicalSize.data(), - physicalSize.size()); + physicalSize.data(), physicalSize.size()); uint8_t timestampSource = ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN; staticMetadata_->addEntry(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE,