[libcamera-devel,4/4] ipa: ipu3: agc: Introduce lineDuration in IPASessionConfiguration
diff mbox series

Message ID 20211125102143.52556-5-jeanmichel.hautbois@ideasonboard.com
State Superseded
Headers show
Series
  • ipa: ipu3: Misc clean up
Related show

Commit Message

Jean-Michel Hautbois Nov. 25, 2021, 10:21 a.m. UTC
Instead of having a local cached value for line duration, store it in
the IPASessionConfiguration::agc structure.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
---
 src/ipa/ipu3/algorithms/agc.cpp | 20 +++++++++++---------
 src/ipa/ipu3/algorithms/agc.h   |  2 --
 src/ipa/ipu3/ipa_context.cpp    |  3 +++
 src/ipa/ipu3/ipa_context.h      |  1 +
 4 files changed, 15 insertions(+), 11 deletions(-)

Comments

Kieran Bingham Nov. 25, 2021, 12:05 p.m. UTC | #1
Quoting Jean-Michel Hautbois (2021-11-25 10:21:43)
> Instead of having a local cached value for line duration, store it in
> the IPASessionConfiguration::agc structure.

in the ... sensor specific session configuration structure ;-)

--
Kieran


> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> ---
>  src/ipa/ipu3/algorithms/agc.cpp | 20 +++++++++++---------
>  src/ipa/ipu3/algorithms/agc.h   |  2 --
>  src/ipa/ipu3/ipa_context.cpp    |  3 +++
>  src/ipa/ipu3/ipa_context.h      |  1 +
>  4 files changed, 15 insertions(+), 11 deletions(-)
> 
> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp
> index b822c79b..c463e688 100644
> --- a/src/ipa/ipu3/algorithms/agc.cpp
> +++ b/src/ipa/ipu3/algorithms/agc.cpp
> @@ -70,7 +70,7 @@ static constexpr uint32_t kNumStartupFrames = 10;
>  static constexpr double kRelativeLuminanceTarget = 0.16;
>  
>  Agc::Agc()
> -       : frameCount_(0), lineDuration_(0s), filteredExposure_(0s)
> +       : frameCount_(0), filteredExposure_(0s)
>  {
>  }
>  
> @@ -83,16 +83,18 @@ Agc::Agc()
>   */
>  int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)
>  {
> -       stride_ = context.configuration.grid.stride;
> +       IPASessionConfiguration &configuration = context.configuration;
> +       IPAFrameContext &frameContext = context.frameContext;
> +
> +       stride_ = configuration.grid.stride;
>  
>         /* \todo use the IPAContext to provide the limits */
> -       lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s
> -                     / configInfo.sensorInfo.pixelRate;
> +       configuration.agc.lineDuration = configInfo.sensorInfo.lineLength * 1.0s
> +                                      / configInfo.sensorInfo.pixelRate;
>  
>         /* Configure the default exposure and gain. */
> -       context.frameContext.agc.gain =
> -               std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);
> -       context.frameContext.agc.exposure = 10ms / lineDuration_;
> +       frameContext.agc.gain = std::max(configuration.agc.minAnalogueGain, kMinAnalogueGain);
> +       frameContext.agc.exposure = 10ms / configuration.agc.lineDuration;
>  
>         return 0;
>  }
> @@ -200,7 +202,7 @@ void Agc::computeExposure(IPAContext &context, double yGain, double iqMeanGain)
>         /* extracted from Rpi::Agc::computeTargetExposure */
>  
>         /* Calculate the shutter time in seconds */
> -       utils::Duration currentShutter = exposure * lineDuration_;
> +       utils::Duration currentShutter = exposure * configuration.agc.lineDuration;
>  
>         /*
>          * Update the exposure value for the next computation using the values
> @@ -245,7 +247,7 @@ void Agc::computeExposure(IPAContext &context, double yGain, double iqMeanGain)
>                             << stepGain;
>  
>         /* Update the estimated exposure and gain. */
> -       frameContext.agc.exposure = shutterTime / lineDuration_;
> +       frameContext.agc.exposure = shutterTime / configuration.agc.lineDuration;
>         frameContext.agc.gain = stepGain;
>  }
>  
> diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h
> index d9f17e6f..ed997e67 100644
> --- a/src/ipa/ipu3/algorithms/agc.h
> +++ b/src/ipa/ipu3/algorithms/agc.h
> @@ -42,8 +42,6 @@ private:
>  
>         uint64_t frameCount_;
>  
> -       utils::Duration lineDuration_;
> -
>         utils::Duration filteredExposure_;
>  
>         uint32_t stride_;
> diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp
> index 86794ac1..ace9c66f 100644
> --- a/src/ipa/ipu3/ipa_context.cpp
> +++ b/src/ipa/ipu3/ipa_context.cpp
> @@ -84,6 +84,9 @@ namespace libcamera::ipa::ipu3 {
>   *
>   * \var IPASessionConfiguration::agc.maxAnalogueGain
>   * \brief Maximum analogue gain supported with the configured sensor
> + *
> + * \var IPASessionConfiguration::agc.lineDuration
> + * \brief Line duration in microseconds
>   */
>  
>  /**
> diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h
> index c6dc0814..7696fd14 100644
> --- a/src/ipa/ipu3/ipa_context.h
> +++ b/src/ipa/ipu3/ipa_context.h
> @@ -30,6 +30,7 @@ struct IPASessionConfiguration {
>                 utils::Duration maxShutterSpeed;
>                 double minAnalogueGain;
>                 double maxAnalogueGain;
> +               utils::Duration lineDuration;
>         } agc;
>  };
>  
> -- 
> 2.32.0
>

Patch
diff mbox series

diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp
index b822c79b..c463e688 100644
--- a/src/ipa/ipu3/algorithms/agc.cpp
+++ b/src/ipa/ipu3/algorithms/agc.cpp
@@ -70,7 +70,7 @@  static constexpr uint32_t kNumStartupFrames = 10;
 static constexpr double kRelativeLuminanceTarget = 0.16;
 
 Agc::Agc()
-	: frameCount_(0), lineDuration_(0s), filteredExposure_(0s)
+	: frameCount_(0), filteredExposure_(0s)
 {
 }
 
@@ -83,16 +83,18 @@  Agc::Agc()
  */
 int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)
 {
-	stride_ = context.configuration.grid.stride;
+	IPASessionConfiguration &configuration = context.configuration;
+	IPAFrameContext &frameContext = context.frameContext;
+
+	stride_ = configuration.grid.stride;
 
 	/* \todo use the IPAContext to provide the limits */
-	lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s
-		      / configInfo.sensorInfo.pixelRate;
+	configuration.agc.lineDuration = configInfo.sensorInfo.lineLength * 1.0s
+				       / configInfo.sensorInfo.pixelRate;
 
 	/* Configure the default exposure and gain. */
-	context.frameContext.agc.gain =
-		std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);
-	context.frameContext.agc.exposure = 10ms / lineDuration_;
+	frameContext.agc.gain = std::max(configuration.agc.minAnalogueGain, kMinAnalogueGain);
+	frameContext.agc.exposure = 10ms / configuration.agc.lineDuration;
 
 	return 0;
 }
@@ -200,7 +202,7 @@  void Agc::computeExposure(IPAContext &context, double yGain, double iqMeanGain)
 	/* extracted from Rpi::Agc::computeTargetExposure */
 
 	/* Calculate the shutter time in seconds */
-	utils::Duration currentShutter = exposure * lineDuration_;
+	utils::Duration currentShutter = exposure * configuration.agc.lineDuration;
 
 	/*
 	 * Update the exposure value for the next computation using the values
@@ -245,7 +247,7 @@  void Agc::computeExposure(IPAContext &context, double yGain, double iqMeanGain)
 			    << stepGain;
 
 	/* Update the estimated exposure and gain. */
-	frameContext.agc.exposure = shutterTime / lineDuration_;
+	frameContext.agc.exposure = shutterTime / configuration.agc.lineDuration;
 	frameContext.agc.gain = stepGain;
 }
 
diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h
index d9f17e6f..ed997e67 100644
--- a/src/ipa/ipu3/algorithms/agc.h
+++ b/src/ipa/ipu3/algorithms/agc.h
@@ -42,8 +42,6 @@  private:
 
 	uint64_t frameCount_;
 
-	utils::Duration lineDuration_;
-
 	utils::Duration filteredExposure_;
 
 	uint32_t stride_;
diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp
index 86794ac1..ace9c66f 100644
--- a/src/ipa/ipu3/ipa_context.cpp
+++ b/src/ipa/ipu3/ipa_context.cpp
@@ -84,6 +84,9 @@  namespace libcamera::ipa::ipu3 {
  *
  * \var IPASessionConfiguration::agc.maxAnalogueGain
  * \brief Maximum analogue gain supported with the configured sensor
+ *
+ * \var IPASessionConfiguration::agc.lineDuration
+ * \brief Line duration in microseconds
  */
 
 /**
diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h
index c6dc0814..7696fd14 100644
--- a/src/ipa/ipu3/ipa_context.h
+++ b/src/ipa/ipu3/ipa_context.h
@@ -30,6 +30,7 @@  struct IPASessionConfiguration {
 		utils::Duration maxShutterSpeed;
 		double minAnalogueGain;
 		double maxAnalogueGain;
+		utils::Duration lineDuration;
 	} agc;
 };