[libcamera-devel] [PATCH 1/2] libcamera: Introduce camera sensor database

Jacopo Mondi jacopo at jmondi.org
Tue Dec 8 10:00:41 CET 2020


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 at 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

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 <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__ */
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',
-- 
2.29.1



More information about the libcamera-devel mailing list