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

Message ID 20220818094410.1671-17-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 IPU3 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/ipu3/ipa_context.cpp | 15 ++++++++++
 src/ipa/ipu3/ipa_context.h   |  6 ++++
 src/ipa/ipu3/ipu3.cpp        | 54 ++++++++++++++++--------------------
 3 files changed, 45 insertions(+), 30 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp
index 536d76ecd63b..3c6f470e7f25 100644
--- a/src/ipa/ipu3/ipa_context.cpp
+++ b/src/ipa/ipu3/ipa_context.cpp
@@ -114,6 +114,21 @@  namespace libcamera::ipa::ipu3 {
  * \brief The default vblank value of the sensor
  */
 
+/**
+ * \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 IPAActiveState::agc
  * \brief Context for the Automatic Gain Control algorithm
diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h
index c4aa4c3f4f6a..2629d0db9f9a 100644
--- a/src/ipa/ipu3/ipa_context.h
+++ b/src/ipa/ipu3/ipa_context.h
@@ -15,6 +15,8 @@ 
 #include <libcamera/controls.h>
 #include <libcamera/geometry.h>
 
+#include <libcamera/ipa/core_ipa_interface.h>
+
 #include <libipa/fc_queue.h>
 
 namespace libcamera {
@@ -43,6 +45,10 @@  struct IPASessionConfiguration {
 		int32_t defVBlank;
 		utils::Duration lineDuration;
 	} sensor;
+
+	ControlInfoMap sensorCtrls;
+	ControlInfoMap lensCtrls;
+	IPACameraSensorInfo sensorInfo;
 };
 
 struct IPAActiveState {
diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp
index dd9d21e4df52..6d40f3d0cd9e 100644
--- a/src/ipa/ipu3/ipu3.cpp
+++ b/src/ipa/ipu3/ipu3.cpp
@@ -172,11 +172,6 @@  private:
 
 	std::map<unsigned int, MappedFrameBuffer> buffers_;
 
-	ControlInfoMap sensorCtrls_;
-	ControlInfoMap lensCtrls_;
-
-	IPACameraSensorInfo sensorInfo_;
-
 	/* Interface to the Camera Helper */
 	std::unique_ptr<CameraSensorHelper> camHelper_;
 
@@ -209,7 +204,7 @@  int IPAIPU3::init(const IPASettings &settings,
 		return -ENODEV;
 	}
 
-	/* Clean context */
+	/* Clean context. */
 	context_.configuration = {};
 
 	/* Load the tuning data file. */
@@ -379,7 +374,6 @@  void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,
 			     ControlInfoMap *ipaControls)
 {
 	ControlInfoMap::Map controls{};
-	double lineDuration = context_.configuration.sensor.lineDuration.get<std::micro>();
 
 	/*
 	 * Compute exposure time limits by using line length and pixel rate
@@ -388,6 +382,7 @@  void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,
 	 * microseconds.
 	 */
 	const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
+	double lineDuration = sensorInfo.lineLength / sensorInfo.pixelRate;
 	int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;
 	int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;
 	int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;
@@ -431,9 +426,22 @@  void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,
  */
 void IPAIPU3::updateSessionConfiguration(const IPAConfigInfo &configInfo)
 {
-	const IPACameraSensorInfo &sensorInfo = configInfo.sensorInfo;
-	const ControlInfoMap &sensorControls = configInfo.sensorControls;
+	/* Clear and intialize the IPA context before the streaming session. */
+	context_.frameContexts.clear();
+	context_ = {};
+
+	context_.configuration.sensorCtrls = configInfo.sensorControls;
+	context_.configuration.lensCtrls = configInfo.lensControls;
+	context_.configuration.sensorInfo = configInfo.sensorInfo;
 
+	/*
+	 * When the AGC computes the new exposure values for a frame, it needs
+	 * to know the limits for shutter speed and analogue gain.
+	 * As it depends on the sensor, update it with the controls.
+	 *
+	 * \todo take VBLANK into account for maximum shutter speed
+	 */
+	const ControlInfoMap &sensorControls = configInfo.sensorControls;
 	const ControlInfo vBlank = sensorControls.find(V4L2_CID_VBLANK)->second;
 	context_.configuration.sensor.defVBlank = vBlank.def().get<int32_t>();
 
@@ -445,19 +453,8 @@  void IPAIPU3::updateSessionConfiguration(const IPAConfigInfo &configInfo)
 	int32_t minGain = v4l2Gain.min().get<int32_t>();
 	int32_t maxGain = v4l2Gain.max().get<int32_t>();
 
-	/* Clear the IPA context before the streaming session. */
-	context_.frameContexts.clear();
-	context_ = {};
-
-	/*
-	 * When the AGC computes the new exposure values for a frame, it needs
-	 * to know the limits for shutter speed and analogue gain.
-	 * As it depends on the sensor, update it with the controls.
-	 *
-	 * \todo take VBLANK into account for maximum shutter speed
-	 */
-	context_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s
-						   / sensorInfo.pixelRate;
+	context_.configuration.sensor.lineDuration = configInfo.sensorInfo.lineLength * 1.0s
+						   / configInfo.sensorInfo.pixelRate;
 	context_.configuration.agc.minShutterSpeed = minExposure * context_.configuration.sensor.lineDuration;
 	context_.configuration.agc.maxShutterSpeed = maxExposure * context_.configuration.sensor.lineDuration;
 	context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);
@@ -487,14 +484,10 @@  int IPAIPU3::configure(const IPAConfigInfo &configInfo,
 		return -EINVAL;
 	}
 
-	sensorCtrls_ = configInfo.sensorControls;
-	sensorInfo_ = configInfo.sensorInfo;
-	lensCtrls_ = configInfo.lensControls;
-
 	calculateBdsGrid(configInfo.bdsOutputSize);
 
 	/* Update the camera controls using the new sensor settings. */
-	updateControls(sensorInfo_, sensorCtrls_, ipaControls);
+	updateControls(configInfo.sensorInfo, configInfo.sensorControls, ipaControls);
 
 	/* Update the IPASessionConfiguration using the sensor settings. */
 	updateSessionConfiguration(configInfo);
@@ -618,7 +611,8 @@  void IPAIPU3::processStatsBuffer(const uint32_t frame,
 	setControls(frame);
 
 	/* \todo Use VBlank value calculated from each frame exposure. */
-	int64_t frameDuration = (vBlank + sensorInfo_.outputSize.height) * lineDuration;
+	const IPACameraSensorInfo &sensorInfo = context_.configuration.sensorInfo;
+	int64_t frameDuration = (vBlank + sensorInfo.outputSize.height) * lineDuration;
 	ctrls.set(controls::FrameDuration, frameDuration);
 
 	ctrls.set(controls::AnalogueGain, frameContext.sensor.gain);
@@ -667,11 +661,11 @@  void IPAIPU3::setControls(unsigned int frame)
 	int32_t exposure = context_.activeState.agc.exposure;
 	int32_t gain = camHelper_->gainCode(context_.activeState.agc.gain);
 
-	ControlList ctrls(sensorCtrls_);
+	ControlList ctrls(context_.configuration.sensorCtrls);
 	ctrls.set(V4L2_CID_EXPOSURE, exposure);
 	ctrls.set(V4L2_CID_ANALOGUE_GAIN, gain);
 
-	ControlList lensCtrls(lensCtrls_);
+	ControlList lensCtrls(context_.configuration.lensCtrls);
 	lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE,
 		      static_cast<int32_t>(context_.activeState.af.focus));