[libcamera-devel,v1,1/3] ipa: raspberrypi: Replace setMaxShutter with setSensorLimits in AGC
diff mbox series

Message ID 20230322161317.18055-2-naush@raspberrypi.com
State Superseded
Headers show
Series
  • Raspberry Pi: Sensor limits
Related show

Commit Message

Naushir Patuck March 22, 2023, 4:13 p.m. UTC
Create a SensorLimits structure in the AgcAlgorithm class. The maximum
shutter time is stored in this structure from the IPA. In a subsequent
commit, all gain and shutter limits will additionally be stored.

Pass the SensorLimits structure with the maximum shutter time into the
AGC algorithm through the new setSensorLimits() member function,
replacing the call to setMaxShutter().

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
---
 src/ipa/raspberrypi/controller/agc_algorithm.h | 11 ++++++++++-
 src/ipa/raspberrypi/controller/rpi/agc.cpp     | 10 +++++-----
 src/ipa/raspberrypi/controller/rpi/agc.h       |  4 ++--
 src/ipa/raspberrypi/raspberrypi.cpp            |  7 ++++---
 4 files changed, 21 insertions(+), 11 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/controller/agc_algorithm.h b/src/ipa/raspberrypi/controller/agc_algorithm.h
index 36e6c11058ee..c2759689c7f9 100644
--- a/src/ipa/raspberrypi/controller/agc_algorithm.h
+++ b/src/ipa/raspberrypi/controller/agc_algorithm.h
@@ -15,13 +15,22 @@  namespace RPiController {
 class AgcAlgorithm : public Algorithm
 {
 public:
+	struct SensorLimits {
+		libcamera::utils::Duration minShutter;
+		libcamera::utils::Duration maxShutter;
+		libcamera::utils::Duration minFrameDuration;
+		libcamera::utils::Duration maxFrameDuration;
+		double minAnalogueGain;
+		double maxAnalogueGain;
+	};
+
 	AgcAlgorithm(Controller *controller) : Algorithm(controller) {}
 	/* An AGC algorithm must provide the following: */
 	virtual unsigned int getConvergenceFrames() const = 0;
 	virtual void setEv(double ev) = 0;
 	virtual void setFlickerPeriod(libcamera::utils::Duration flickerPeriod) = 0;
 	virtual void setFixedShutter(libcamera::utils::Duration fixedShutter) = 0;
-	virtual void setMaxShutter(libcamera::utils::Duration maxShutter) = 0;
+	virtual void setSensorLimits(const SensorLimits &limits) = 0;
 	virtual void setFixedAnalogueGain(double fixedAnalogueGain) = 0;
 	virtual void setMeteringMode(std::string const &meteringModeName) = 0;
 	virtual void setExposureMode(std::string const &exposureModeName) = 0;
diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp
index 4ea0dd41e66c..eaabc5fa9cd0 100644
--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp
+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp
@@ -225,7 +225,7 @@  Agc::Agc(Controller *controller)
 	  frameCount_(0), lockCount_(0),
 	  lastTargetExposure_(0s), lastSensitivity_(0.0),
 	  ev_(1.0), flickerPeriod_(0s),
-	  maxShutter_(0s), fixedShutter_(0s), fixedAnalogueGain_(0.0)
+	  fixedShutter_(0s), fixedAnalogueGain_(0.0)
 {
 	memset(&awb_, 0, sizeof(awb_));
 	/*
@@ -300,9 +300,9 @@  void Agc::setFlickerPeriod(Duration flickerPeriod)
 	flickerPeriod_ = flickerPeriod;
 }
 
-void Agc::setMaxShutter(Duration maxShutter)
+void Agc::setSensorLimits(const SensorLimits &limits)
 {
-	maxShutter_ = maxShutter;
+	sensorLimits_ = limits;
 }
 
 void Agc::setFixedShutter(Duration fixedShutter)
@@ -874,8 +874,8 @@  void Agc::writeAndFinish(Metadata *imageMetadata, bool desaturate)
 
 Duration Agc::clipShutter(Duration shutter)
 {
-	if (maxShutter_)
-		shutter = std::min(shutter, maxShutter_);
+	if (sensorLimits_.maxShutter)
+		shutter = std::min(shutter, sensorLimits_.maxShutter);
 	return shutter;
 }
 
diff --git a/src/ipa/raspberrypi/controller/rpi/agc.h b/src/ipa/raspberrypi/controller/rpi/agc.h
index f04896ca25ad..150a5f6e4428 100644
--- a/src/ipa/raspberrypi/controller/rpi/agc.h
+++ b/src/ipa/raspberrypi/controller/rpi/agc.h
@@ -78,7 +78,7 @@  public:
 	unsigned int getConvergenceFrames() const override;
 	void setEv(double ev) override;
 	void setFlickerPeriod(libcamera::utils::Duration flickerPeriod) override;
-	void setMaxShutter(libcamera::utils::Duration maxShutter) override;
+	void setSensorLimits(const SensorLimits &limits) override;
 	void setFixedShutter(libcamera::utils::Duration fixedShutter) override;
 	void setFixedAnalogueGain(double fixedAnalogueGain) override;
 	void setMeteringMode(std::string const &meteringModeName) override;
@@ -131,7 +131,7 @@  private:
 	std::string constraintModeName_;
 	double ev_;
 	libcamera::utils::Duration flickerPeriod_;
-	libcamera::utils::Duration maxShutter_;
+	SensorLimits sensorLimits_;
 	libcamera::utils::Duration fixedShutter_;
 	double fixedAnalogueGain_;
 };
diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index 1375795568e2..c3b2c375036f 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -1505,12 +1505,13 @@  void IPARPi::applyFrameDurations(Duration minFrameDuration, Duration maxFrameDur
 	 * getBlanking() will update maxShutter with the largest exposure
 	 * value possible.
 	 */
-	Duration maxShutter = Duration::max();
-	helper_->getBlanking(maxShutter, minFrameDuration_, maxFrameDuration_);
+	RPiController::AgcAlgorithm::SensorLimits limits;
+	limits.maxShutter = Duration::max();
+	helper_->getBlanking(limits.maxShutter, minFrameDuration_, maxFrameDuration_);
 
 	RPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(
 		controller_.getAlgorithm("agc"));
-	agc->setMaxShutter(maxShutter);
+	agc->setSensorLimits(limits);
 }
 
 void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls)