Message ID | 20210325135116.21548-1-jacopo@jmondi.org |
---|---|
Headers | show |
Series |
|
Related | show |
Hi Jacopo, Thanks for your work. On 2021-03-25 14:51:14 +0100, Jacopo Mondi wrote: > Introduce a 'database' of camera sensor information, which contains > a the camera sensor properties which is not possible, or desirable, > to retrieve at run-time. > > The camera sensor database is accessed through the static SensorDatabase > class which provides a single method to obtain the sensor information. > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> > --- > include/libcamera/internal/meson.build | 1 + > include/libcamera/internal/sensor_database.h | 28 +++++ > src/libcamera/meson.build | 1 + > src/libcamera/sensor_database.cpp | 102 +++++++++++++++++++ > 4 files changed, 132 insertions(+) > create mode 100644 include/libcamera/internal/sensor_database.h > create mode 100644 src/libcamera/sensor_database.cpp > > diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build > index 1fe3918cfe93..4aaa76ac1db1 100644 > --- a/include/libcamera/internal/meson.build > +++ b/include/libcamera/internal/meson.build > @@ -38,6 +38,7 @@ libcamera_internal_headers = files([ > 'process.h', > 'pub_key.h', > 'semaphore.h', > + 'sensor_database.h', > 'sysfs.h', > 'thread.h', > 'timer.h', > diff --git a/include/libcamera/internal/sensor_database.h b/include/libcamera/internal/sensor_database.h > new file mode 100644 > index 000000000000..e074b3029932 > --- /dev/null > +++ b/include/libcamera/internal/sensor_database.h > @@ -0,0 +1,28 @@ > +/* SPDX-License-Identifier: LGPL-2.1-or-later */ > +/* > + * Copyright (C) 2020, Google Inc. s/2020/2021/ Same for .cpp > + * > + * sensor_database.h - Database of camera sensor properties > + */ > +#ifndef __LIBCAMERA_SENSOR_DATABASE_H__ > +#define __LIBCAMERA_SENSOR_DATABASE_H__ > + > +#include <string> > + > +#include <libcamera/geometry.h> > + > +namespace libcamera { > + > +struct SensorInfo { > + Size unitCellSize; > +}; > + > +class SensorDatabase > +{ > +public: > + static const SensorInfo *get(const std::string &sensor); > +}; > + > +} /* namespace libcamera */ > + > +#endif /* __LIBCAMERA_SENSOR_DATABASE_H__ */ > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build > index 815629db8488..17b44cc1dfa8 100644 > --- a/src/libcamera/meson.build > +++ b/src/libcamera/meson.build > @@ -44,6 +44,7 @@ libcamera_sources = files([ > 'pub_key.cpp', > 'request.cpp', > 'semaphore.cpp', > + 'sensor_database.cpp', > 'signal.cpp', > 'stream.cpp', > 'sysfs.cpp', > diff --git a/src/libcamera/sensor_database.cpp b/src/libcamera/sensor_database.cpp > new file mode 100644 > index 000000000000..5f8538a62388 > --- /dev/null > +++ b/src/libcamera/sensor_database.cpp > @@ -0,0 +1,102 @@ > +/* SPDX-License-Identifier: LGPL-2.1-or-later */ > +/* > + * Copyright (C) 2020, Google Inc. > + * > + * sensor_database.cpp - Database of camera sensor properties > + */ > + > +#include "libcamera/internal/sensor_database.h" > + > +#include <algorithm> > + > +namespace libcamera { > + > +/** > + * \file 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. > + */ > + > +/** > + * \class SensorDatabase > + * \brief Access the 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 > + * SensorInfo list of properties. > + * > + * The class provides a single static getInfo() method to access the sensor > + * database entries. If the sensor is not supported in the database nullptr is > + * returned. > + */ > + > +/** > + * \struct SensorInfo > + * \brief List of sensor properties > + * > + * \var SensorInfo::unitCellSize > + * \brief The physical size of pixel, including pixel edges. Width x height in > + * nano-meters. > + */ > + > +namespace { > + > +/** > + * \brief Sony IMX219 sensor properties > + */ > +constexpr SensorInfo imx219Info = { > + .unitCellSize = { 1120, 1120 } > +}; > + > +/** > + * \brief Omnivision ov5670 sensor properties > + */ > +constexpr SensorInfo ov5670Info = { > + .unitCellSize = { 1120, 1120 } > +}; > + > +/** > + * \brief Omnivision 13858 sensor properties > + */ > +constexpr SensorInfo ov13858Info = { > + .unitCellSize = { 1120, 1120 } > +}; > + > +#define SENSOR_INFO(_sensor) \ > + { #_sensor, &_sensor##Info } > + > +/* > + * \brief The database of sensor properties > + */ > +constexpr std::pair<const char *const, const SensorInfo *> sensorDatabase__[] = { > + SENSOR_INFO(imx219), > + SENSOR_INFO(ov5670), > + SENSOR_INFO(ov13858), > +}; > + > +const SensorInfo *getInfo(const std::string &sensor) > +{ > + for (unsigned int i = 0; i < std::size(sensorDatabase__); ++i) { > + if (sensorDatabase__[i].first == sensor) > + return sensorDatabase__[i].second; > + } > + > + return nullptr; > +} > + > +} /* namespace */ > + > +/** > + * \brief Retrieve the properties associated with a sensor > + * \param sensor The sensor model name > + * \return A pointer to the SensorInfo instance associated with a sensor or > + * nullptr if the sensor is not supported in the database > + */ > +const SensorInfo *SensorDatabase::get(const std::string &sensor) > +{ > + return getInfo(sensor); Maybe I'm missing something can't getInfo() be inlined here? If not I think getInfo() should be decorated with 'static const'. Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> > +} > + > +} /* namespace libcamera */ > -- > 2.30.0 > > _______________________________________________ > libcamera-devel mailing list > libcamera-devel@lists.libcamera.org > https://lists.libcamera.org/listinfo/libcamera-devel