[libcamera-devel,v3,17/17] ipa: rkisp1: Store configuration data in context
diff mbox series

Message ID 20220818094410.1671-18-jacopo@jmondi.org
State New
Headers show
Series
  • libcamera: Align IPU3 and RKISP1 interfaces
Related show

Commit Message

Jacopo Mondi Aug. 18, 2022, 9:44 a.m. UTC
The RkISP1 IPA module stores per-configuration session data, such as the
sensor and lens controls and the sensor information, in class member
variables.

As the IPAContext structure has exactly a place for session-specific
configuration data, move those information in the context_ and remove
them from the class.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/ipa/rkisp1/ipa_context.cpp | 15 +++++++++++++++
 src/ipa/rkisp1/ipa_context.h   |  6 ++++++
 src/ipa/rkisp1/rkisp1.cpp      | 33 ++++++++++++++-------------------
 3 files changed, 35 insertions(+), 19 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp
index ef8bb8e931c8..e31059e52cee 100644
--- a/src/ipa/rkisp1/ipa_context.cpp
+++ b/src/ipa/rkisp1/ipa_context.cpp
@@ -100,6 +100,21 @@  namespace libcamera::ipa::rkisp1 {
  * \brief Sensor output resolution
  */
 
+/**
+ * \var IPASessionConfiguration::sensorCtrls
+ * \brief The list of V4L2 sensor controls limits
+ */
+
+/**
+ * \var IPASessionConfiguration::lensCtrls
+ * \brief The list of V4L2 lens controls limits
+ */
+
+/**
+ * \var IPASessionConfiguration::sensorInfo
+ * \brief The sensor configuration for the streaming session
+ */
+
 /**
  * \var IPAFrameContext::agc
  * \brief Context for the Automatic Gain Control algorithm
diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h
index dd756f4025d1..6151f35af900 100644
--- a/src/ipa/rkisp1/ipa_context.h
+++ b/src/ipa/rkisp1/ipa_context.h
@@ -14,6 +14,8 @@ 
 
 #include <libcamera/geometry.h>
 
+#include <libcamera/ipa/core_ipa_interface.h>
+
 #include <libipa/fc_queue.h>
 
 namespace libcamera {
@@ -41,6 +43,10 @@  struct IPASessionConfiguration {
 	struct {
 		rkisp1_cif_isp_version revision;
 	} hw;
+
+	ControlInfoMap sensorCtrls;
+	ControlInfoMap lensCtrls;
+	IPACameraSensorInfo sensorInfo;
 };
 
 struct IPAActiveState {
diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp
index a1834034e617..01d64c48b126 100644
--- a/src/ipa/rkisp1/rkisp1.cpp
+++ b/src/ipa/rkisp1/rkisp1.cpp
@@ -71,9 +71,6 @@  private:
 	std::map<unsigned int, FrameBuffer> buffers_;
 	std::map<unsigned int, MappedFrameBuffer> mappedBuffers_;
 
-	ControlInfoMap sensorCtrls_;
-	std::optional<ControlInfoMap> lensCtrls_;
-
 	/* revision-specific data */
 	rkisp1_cif_isp_version hwRevision_;
 	unsigned int hwHistBinNMax_;
@@ -211,9 +208,17 @@  bool IPARkISP1::validateSensorControls(const ControlInfoMap &sensorControls)
 
 void IPARkISP1::updateSessionConfiguration(const IPAConfigInfo &configInfo)
 {
-	const IPACameraSensorInfo &sensorInfo = configInfo.sensorInfo;
-	const ControlInfoMap &sensorControls = configInfo.sensorControls;
+	/* Clear the IPA context before the streaming session. */
+	context_.frameContexts.clear();
+	context_ = {};
+
+	context_.configuration.sensorCtrls = configInfo.sensorControls;
+	context_.configuration.lensCtrls = configInfo.lensControls;
+
+	/* Set the hardware revision for the algorithms. */
+	context_.configuration.hw.revision = hwRevision_;
 
+	const ControlInfoMap &sensorControls = configInfo.sensorControls;
 	const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
 	const ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second;
 	int32_t minExposure = v4l2Exposure.min().get<int32_t>();
@@ -226,16 +231,9 @@  void IPARkISP1::updateSessionConfiguration(const IPAConfigInfo &configInfo)
 		<< "Exposure: " << minExposure << "-" << maxExposure
 		<< " Gain: " << minGain << "-" << maxGain;
 
-	/* Clear the IPA context before the streaming session. */
-	context_.frameContexts.clear();
-	context_ = {};
-
-	/* Set the hardware revision for the algorithms. */
-	context_.configuration.hw.revision = hwRevision_;
-
-	context_.configuration.sensor.size = sensorInfo.outputSize;
-	context_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s
-						   / sensorInfo.pixelRate;
+	context_.configuration.sensor.size = configInfo.sensorInfo.outputSize;
+	context_.configuration.sensor.lineDuration = configInfo.sensorInfo.lineLength * 1.0s
+						   / configInfo.sensorInfo.pixelRate;
 
 	/*
 	 * When the AGC computes the new exposure values for a frame, it needs
@@ -259,9 +257,6 @@  int IPARkISP1::configure(const IPAConfigInfo &configInfo)
 		return -EINVAL;
 	}
 
-	sensorCtrls_ = configInfo.sensorControls;
-	lensCtrls_ = configInfo.lensControls;
-
 	updateSessionConfiguration(configInfo);
 
 	for (auto const &algo : algorithms()) {
@@ -358,7 +353,7 @@  void IPARkISP1::setControls(unsigned int frame)
 	uint32_t exposure = context_.activeState.agc.exposure;
 	uint32_t gain = camHelper_->gainCode(context_.activeState.agc.gain);
 
-	ControlList ctrls(sensorCtrls_);
+	ControlList ctrls(context_.configuration.sensorCtrls);
 	ctrls.set(V4L2_CID_EXPOSURE, static_cast<int32_t>(exposure));
 	ctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast<int32_t>(gain));