[libcamera-devel] [PATCH 2/2] android: camera_device: Get sensor properties from DB
Jacopo Mondi
jacopo at jmondi.org
Tue Dec 8 10:00:42 CET 2020
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 <jacopo at jmondi.org>
---
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 <tuple>
#include <vector>
+#include <libcamera/camera_sensor_database.h>
#include <libcamera/control_ids.h>
#include <libcamera/controls.h>
#include <libcamera/formats.h>
@@ -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<std::string>(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<uint8_t> data;
@@ -775,12 +789,15 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()
testPatterModes.data(),
testPatterModes.size());
- std::vector<float> 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<float> physicalSize;
+ physicalSize[0] = static_cast<float>(sensorEntry.physicalSize.width * 10e6);
+ physicalSize[1] = static_cast<float>(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,
--
2.29.1
More information about the libcamera-devel
mailing list