[libcamera-devel,v3,6/8] libcamera: camera_sensor: Break out properties initialization

Message ID 20200605141002.49119-7-jacopo@jmondi.org
State Superseded, archived
Delegated to: Jacopo Mondi
Headers show
Series
  • android: Build stream configuration map
Related show

Commit Message

Jacopo Mondi June 5, 2020, 2:10 p.m. UTC
Refactor the CameraSensor properties initialization to a dedicated
function as it is expected to grow as we augment the number of
properties.

While at it, move documentation of the properties() method to match the
declaration order in the class definition.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 include/libcamera/internal/camera_sensor.h |  2 +
 src/libcamera/camera_sensor.cpp            | 83 ++++++++++++----------
 2 files changed, 49 insertions(+), 36 deletions(-)

Patch

diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index d79bd9ce9d58..44dd4b099913 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -69,6 +69,8 @@  protected:
 	std::string logPrefix() const;
 
 private:
+	int initProperties();
+
 	const MediaEntity *entity_;
 	std::unique_ptr<V4L2Subdevice> subdev_;
 	unsigned int pad_;
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index b14b4051dca6..b9428175c55e 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -205,7 +205,47 @@  int CameraSensor::init()
 	if (ret < 0)
 		return ret;
 
-	/* Retrieve and store the camera sensor properties. */
+	/* Enumerate, sort and cache media bus codes and sizes. */
+	formats_ = subdev_->formats(pad_);
+	if (formats_.isEmpty()) {
+		LOG(CameraSensor, Error) << "No image format found";
+		return -EINVAL;
+	}
+
+	mbusCodes_ = formats_.formats();
+	std::sort(mbusCodes_.begin(), mbusCodes_.end());
+
+	for (const auto &format : formats_.data()) {
+		const std::vector<SizeRange> &ranges = format.second;
+		std::transform(ranges.begin(), ranges.end(), std::back_inserter(sizes_),
+			       [](const SizeRange &range) { return range.max; });
+	}
+
+	std::sort(sizes_.begin(), sizes_.end());
+
+	/* Remove duplicates. */
+	auto last = std::unique(sizes_.begin(), sizes_.end());
+	sizes_.erase(last, sizes_.end());
+
+	/*
+	 * The sizes_ vector is sorted in ascending order, the resolution is
+	 * thus the last element of the vector.
+	 */
+	resolution_ = sizes_.back();
+
+	return initProperties();
+}
+
+/**
+ * \brief Initialize the camera sensor standard properties
+ *
+ * This method initializes the camera sensor standard properties, by inspecting
+ * the control information reported by the sensor subdevice.
+ *
+ * \return 0 on success, a negative error code otherwise
+ */
+int CameraSensor::initProperties()
+{
 	const ControlInfoMap &controls = subdev_->controls();
 	int32_t propertyValue;
 
@@ -243,35 +283,6 @@  int CameraSensor::init()
 		propertyValue = 0;
 	properties_.set(properties::Rotation, propertyValue);
 
-	/* Enumerate, sort and cache media bus codes and sizes. */
-	formats_ = subdev_->formats(pad_);
-	if (formats_.isEmpty()) {
-		LOG(CameraSensor, Error) << "No image format found";
-		return -EINVAL;
-	}
-
-	mbusCodes_ = formats_.formats();
-	std::sort(mbusCodes_.begin(), mbusCodes_.end());
-
-	for (const auto &format : formats_.data()) {
-		const std::vector<SizeRange> &ranges = format.second;
-		std::transform(ranges.begin(), ranges.end(), std::back_inserter(sizes_),
-			       [](const SizeRange &range) { return range.max; });
-	}
-
-	std::sort(sizes_.begin(), sizes_.end());
-
-	/* Remove duplicates. */
-	auto last = std::unique(sizes_.begin(), sizes_.end());
-	sizes_.erase(last, sizes_.end());
-
-	/*
-	 * The sizes_ vector is sorted in ascending order, the resolution is
-	 * thus the last element of the vector.
-	 */
-	resolution_ = sizes_.back();
-
-	return 0;
 }
 
 /**
@@ -438,12 +449,6 @@  ControlList CameraSensor::getControls(const std::vector<uint32_t> &ids)
 	return subdev_->getControls(ids);
 }
 
-/**
- * \fn CameraSensor::properties()
- * \brief Retrieve the camera sensor properties
- * \return The list of camera sensor properties
- */
-
 /**
  * \brief Write controls to the sensor
  * \param[in] ctrls The list of controls to write
@@ -535,6 +540,12 @@  int CameraSensor::sensorInfo(CameraSensorInfo *info) const
 	return 0;
 }
 
+/**
+ * \fn CameraSensor::properties()
+ * \brief Retrieve the camera sensor properties
+ * \return The list of camera sensor properties
+ */
+
 std::string CameraSensor::logPrefix() const
 {
 	return "'" + entity_->name() + "'";