new file mode 100644
@@ -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 <initializer_list>
+#include <unordered_map>
+
+#include <libcamera/geometry.h>
+
+namespace libcamera {
+
+struct SensorEntry {
+ Size physicalSize;
+ Size pixelPhysicalSize;
+};
+
+class SensorDatabase : private std::unordered_map<std::string, const SensorEntry>
+{
+private:
+ using Map = std::unordered_map<std::string, const SensorEntry>;
+
+public:
+ SensorDatabase(std::initializer_list<Map::value_type> 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__ */
@@ -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',
new file mode 100644
@@ -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 */
@@ -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',
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 <jacopo@jmondi.org> --- 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