[libcamera-devel,IPAIPU3,v5,6/6] ipa: ipu3: Inline parseStatistics() into processStatsBuffer()
diff mbox series

Message ID 20220406141709.164794-7-umang.jain@ideasonboard.com
State Accepted
Headers show
Series
  • ipa: ipu3: Replace event-based ops with dedicated functions
Related show

Commit Message

Umang Jain April 6, 2022, 2:17 p.m. UTC
Since we have moved away from switch/case on the operation ID,
there's little reason to split the operation in two functions.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 ipu3.cpp | 74 ++++++++++++++++++++++++--------------------------------
 1 file changed, 31 insertions(+), 43 deletions(-)

Comments

Kieran Bingham April 7, 2022, 10:20 p.m. UTC | #1
Quoting Umang Jain via libcamera-devel (2022-04-06 15:17:09)
> Since we have moved away from switch/case on the operation ID,
> there's little reason to split the operation in two functions.
> 
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  ipu3.cpp | 74 ++++++++++++++++++++++++--------------------------------
>  1 file changed, 31 insertions(+), 43 deletions(-)
> 
> diff --git a/ipu3.cpp b/ipu3.cpp
> index 0543a2e..7ecd377 100644
> --- a/ipu3.cpp
> +++ b/ipu3.cpp
> @@ -60,10 +60,6 @@ private:
>                             const ControlInfoMap &sensorControls,
>                             ControlInfoMap *ipaControls);
>         void runAiq(unsigned int frame);
> -       void parseStatistics(unsigned int frame,
> -                            int64_t frameTimestamp,
> -                            const ipu3_uapi_stats_3a *stats,
> -                            const ControlList& sensorCtrls);
>  
>         void setControls(unsigned int frame);
>  
> @@ -379,43 +375,6 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, const int64_t frameTimest
>         const ipu3_uapi_stats_3a *stats =
>                 reinterpret_cast<ipu3_uapi_stats_3a *>(mem.data());
>  
> -       parseStatistics(frame, frameTimestamp, stats, sensorControls);
> -}
> -
> -void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame)
> -{
> -       /* Run algorithms into/using this context structure */
> -       resultsHistory_.extendOne();
> -       aiq::AiqResults& latestResults = resultsHistory_.latest();
> -
> -       /* Todo: Refactor AiqInputParameters interface to set following parameters. */
> -       aiqInputParams_.afParams.lens_position = lensPosition_;
> -       aiqInputParams_.afParams.lens_movement_start_timestamp = lensMovementStartTime_;
> -
> -       aiq_.run2a(frame, aiqInputParams_, latestResults);
> -
> -       exposure_ = latestResults.ae()->exposures[0].sensor_exposure->coarse_integration_time;
> -       gain_ = latestResults.ae()->exposures[0].sensor_exposure->analog_gain_code_global;
> -
> -       /*
> -        * Af algorithm compares the timestamp of start of the lens movement and
> -        * that of the statistics generated to estimate whether next lens
> -        * position should be produced.
> -        * \todo use the lens movement start time reported by the pipeline handler.
> -        */
> -       if (lensPosition_ != latestResults.af()->next_lens_position) {
> -               utils::time_point time = utils::clock::now();
> -               uint64_t usecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();
> -               lensMovementStartTime_ = usecs;
> -       }
> -       lensPosition_ = latestResults.af()->next_lens_position;
> -}
> -
> -void IPAIPU3::parseStatistics(unsigned int frame,
> -                             int64_t frameTimestamp,
> -                             const ipu3_uapi_stats_3a *stats,
> -                             const ControlList& sensorCtrls)
> -{
>         ControlList ctrls(controls::controls);
>  
>         /* \todo React to statistics and update internal state machine. */
> @@ -438,11 +397,11 @@ void IPAIPU3::parseStatistics(unsigned int frame,
>         int32_t effectiveGain = 0;
>         ControlValue ctrlValue;
>  
> -       ctrlValue = sensorCtrls.get(V4L2_CID_EXPOSURE);
> +       ctrlValue = sensorControls.get(V4L2_CID_EXPOSURE);
>         if (!ctrlValue.isNone())
>                 effectiveExpo = ctrlValue.get<int32_t>();
>  
> -       ctrlValue = sensorCtrls.get(V4L2_CID_ANALOGUE_GAIN);
> +       ctrlValue = sensorControls.get(V4L2_CID_ANALOGUE_GAIN);
>         if (!ctrlValue.isNone())
>                 effectiveGain = ctrlValue.get<int32_t>();
>  
> @@ -472,6 +431,35 @@ void IPAIPU3::parseStatistics(unsigned int frame,
>         metadataReady.emit(frame, ctrls);
>  }
>  
> +void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame)
> +{
> +       /* Run algorithms into/using this context structure */
> +       resultsHistory_.extendOne();
> +       aiq::AiqResults& latestResults = resultsHistory_.latest();
> +
> +       /* Todo: Refactor AiqInputParameters interface to set following parameters. */
> +       aiqInputParams_.afParams.lens_position = lensPosition_;
> +       aiqInputParams_.afParams.lens_movement_start_timestamp = lensMovementStartTime_;
> +
> +       aiq_.run2a(frame, aiqInputParams_, latestResults);
> +
> +       exposure_ = latestResults.ae()->exposures[0].sensor_exposure->coarse_integration_time;
> +       gain_ = latestResults.ae()->exposures[0].sensor_exposure->analog_gain_code_global;
> +
> +       /*
> +        * Af algorithm compares the timestamp of start of the lens movement and
> +        * that of the statistics generated to estimate whether next lens
> +        * position should be produced.
> +        * \todo use the lens movement start time reported by the pipeline handler.
> +        */
> +       if (lensPosition_ != latestResults.af()->next_lens_position) {
> +               utils::time_point time = utils::clock::now();
> +               uint64_t usecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();
> +               lensMovementStartTime_ = usecs;
> +       }
> +       lensPosition_ = latestResults.af()->next_lens_position;
> +}
> +
>  void IPAIPU3::setControls(unsigned int frame)
>  {
>         ControlList sensorCtrls(ctrls_);
> -- 
> 2.31.0
>
Nicolas Dufresne via libcamera-devel April 8, 2022, 7:19 a.m. UTC | #2
Hi Umang,

On Wed, Apr 06, 2022 at 07:47:09PM +0530, Umang Jain via libcamera-devel wrote:
> Since we have moved away from switch/case on the operation ID,
> there's little reason to split the operation in two functions.
> 
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  ipu3.cpp | 74 ++++++++++++++++++++++++--------------------------------
>  1 file changed, 31 insertions(+), 43 deletions(-)
> 
> diff --git a/ipu3.cpp b/ipu3.cpp
> index 0543a2e..7ecd377 100644
> --- a/ipu3.cpp
> +++ b/ipu3.cpp
> @@ -60,10 +60,6 @@ private:
>  			    const ControlInfoMap &sensorControls,
>  			    ControlInfoMap *ipaControls);
>  	void runAiq(unsigned int frame);
> -	void parseStatistics(unsigned int frame,
> -			     int64_t frameTimestamp,
> -			     const ipu3_uapi_stats_3a *stats,
> -			     const ControlList& sensorCtrls);
>  
>  	void setControls(unsigned int frame);
>  
> @@ -379,43 +375,6 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, const int64_t frameTimest
>  	const ipu3_uapi_stats_3a *stats =
>  		reinterpret_cast<ipu3_uapi_stats_3a *>(mem.data());
>  
> -	parseStatistics(frame, frameTimestamp, stats, sensorControls);
> -}
> -
> -void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame)
> -{
> -	/* Run algorithms into/using this context structure */
> -	resultsHistory_.extendOne();
> -	aiq::AiqResults& latestResults = resultsHistory_.latest();
> -
> -	/* Todo: Refactor AiqInputParameters interface to set following parameters. */
> -	aiqInputParams_.afParams.lens_position = lensPosition_;
> -	aiqInputParams_.afParams.lens_movement_start_timestamp = lensMovementStartTime_;
> -
> -	aiq_.run2a(frame, aiqInputParams_, latestResults);
> -
> -	exposure_ = latestResults.ae()->exposures[0].sensor_exposure->coarse_integration_time;
> -	gain_ = latestResults.ae()->exposures[0].sensor_exposure->analog_gain_code_global;
> -
> -	/*
> -	 * Af algorithm compares the timestamp of start of the lens movement and
> -	 * that of the statistics generated to estimate whether next lens
> -	 * position should be produced.
> -	 * \todo use the lens movement start time reported by the pipeline handler.
> -	 */
> -	if (lensPosition_ != latestResults.af()->next_lens_position) {
> -		utils::time_point time = utils::clock::now();
> -		uint64_t usecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();
> -		lensMovementStartTime_ = usecs;
> -	}
> -	lensPosition_ = latestResults.af()->next_lens_position;
> -}
> -
> -void IPAIPU3::parseStatistics(unsigned int frame,
> -			      int64_t frameTimestamp,
> -			      const ipu3_uapi_stats_3a *stats,
> -			      const ControlList& sensorCtrls)
> -{
>  	ControlList ctrls(controls::controls);
>  
>  	/* \todo React to statistics and update internal state machine. */
> @@ -438,11 +397,11 @@ void IPAIPU3::parseStatistics(unsigned int frame,
>  	int32_t effectiveGain = 0;
>  	ControlValue ctrlValue;
>  
> -	ctrlValue = sensorCtrls.get(V4L2_CID_EXPOSURE);
> +	ctrlValue = sensorControls.get(V4L2_CID_EXPOSURE);
>  	if (!ctrlValue.isNone())
>  		effectiveExpo = ctrlValue.get<int32_t>();
>  
> -	ctrlValue = sensorCtrls.get(V4L2_CID_ANALOGUE_GAIN);
> +	ctrlValue = sensorControls.get(V4L2_CID_ANALOGUE_GAIN);
>  	if (!ctrlValue.isNone())
>  		effectiveGain = ctrlValue.get<int32_t>();
>  
> @@ -472,6 +431,35 @@ void IPAIPU3::parseStatistics(unsigned int frame,
>  	metadataReady.emit(frame, ctrls);
>  }
>  
> +void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame)
> +{
> +	/* Run algorithms into/using this context structure */
> +	resultsHistory_.extendOne();
> +	aiq::AiqResults& latestResults = resultsHistory_.latest();
> +
> +	/* Todo: Refactor AiqInputParameters interface to set following parameters. */
> +	aiqInputParams_.afParams.lens_position = lensPosition_;
> +	aiqInputParams_.afParams.lens_movement_start_timestamp = lensMovementStartTime_;
> +
> +	aiq_.run2a(frame, aiqInputParams_, latestResults);
> +
> +	exposure_ = latestResults.ae()->exposures[0].sensor_exposure->coarse_integration_time;
> +	gain_ = latestResults.ae()->exposures[0].sensor_exposure->analog_gain_code_global;
> +
> +	/*
> +	 * Af algorithm compares the timestamp of start of the lens movement and
> +	 * that of the statistics generated to estimate whether next lens
> +	 * position should be produced.
> +	 * \todo use the lens movement start time reported by the pipeline handler.
> +	 */
> +	if (lensPosition_ != latestResults.af()->next_lens_position) {
> +		utils::time_point time = utils::clock::now();
> +		uint64_t usecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();
> +		lensMovementStartTime_ = usecs;
> +	}
> +	lensPosition_ = latestResults.af()->next_lens_position;
> +}
> +
>  void IPAIPU3::setControls(unsigned int frame)
>  {
>  	ControlList sensorCtrls(ctrls_);
> -- 
> 2.31.0
>

Patch
diff mbox series

diff --git a/ipu3.cpp b/ipu3.cpp
index 0543a2e..7ecd377 100644
--- a/ipu3.cpp
+++ b/ipu3.cpp
@@ -60,10 +60,6 @@  private:
 			    const ControlInfoMap &sensorControls,
 			    ControlInfoMap *ipaControls);
 	void runAiq(unsigned int frame);
-	void parseStatistics(unsigned int frame,
-			     int64_t frameTimestamp,
-			     const ipu3_uapi_stats_3a *stats,
-			     const ControlList& sensorCtrls);
 
 	void setControls(unsigned int frame);
 
@@ -379,43 +375,6 @@  void IPAIPU3::processStatsBuffer(const uint32_t frame, const int64_t frameTimest
 	const ipu3_uapi_stats_3a *stats =
 		reinterpret_cast<ipu3_uapi_stats_3a *>(mem.data());
 
-	parseStatistics(frame, frameTimestamp, stats, sensorControls);
-}
-
-void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame)
-{
-	/* Run algorithms into/using this context structure */
-	resultsHistory_.extendOne();
-	aiq::AiqResults& latestResults = resultsHistory_.latest();
-
-	/* Todo: Refactor AiqInputParameters interface to set following parameters. */
-	aiqInputParams_.afParams.lens_position = lensPosition_;
-	aiqInputParams_.afParams.lens_movement_start_timestamp = lensMovementStartTime_;
-
-	aiq_.run2a(frame, aiqInputParams_, latestResults);
-
-	exposure_ = latestResults.ae()->exposures[0].sensor_exposure->coarse_integration_time;
-	gain_ = latestResults.ae()->exposures[0].sensor_exposure->analog_gain_code_global;
-
-	/*
-	 * Af algorithm compares the timestamp of start of the lens movement and
-	 * that of the statistics generated to estimate whether next lens
-	 * position should be produced.
-	 * \todo use the lens movement start time reported by the pipeline handler.
-	 */
-	if (lensPosition_ != latestResults.af()->next_lens_position) {
-		utils::time_point time = utils::clock::now();
-		uint64_t usecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();
-		lensMovementStartTime_ = usecs;
-	}
-	lensPosition_ = latestResults.af()->next_lens_position;
-}
-
-void IPAIPU3::parseStatistics(unsigned int frame,
-			      int64_t frameTimestamp,
-			      const ipu3_uapi_stats_3a *stats,
-			      const ControlList& sensorCtrls)
-{
 	ControlList ctrls(controls::controls);
 
 	/* \todo React to statistics and update internal state machine. */
@@ -438,11 +397,11 @@  void IPAIPU3::parseStatistics(unsigned int frame,
 	int32_t effectiveGain = 0;
 	ControlValue ctrlValue;
 
-	ctrlValue = sensorCtrls.get(V4L2_CID_EXPOSURE);
+	ctrlValue = sensorControls.get(V4L2_CID_EXPOSURE);
 	if (!ctrlValue.isNone())
 		effectiveExpo = ctrlValue.get<int32_t>();
 
-	ctrlValue = sensorCtrls.get(V4L2_CID_ANALOGUE_GAIN);
+	ctrlValue = sensorControls.get(V4L2_CID_ANALOGUE_GAIN);
 	if (!ctrlValue.isNone())
 		effectiveGain = ctrlValue.get<int32_t>();
 
@@ -472,6 +431,35 @@  void IPAIPU3::parseStatistics(unsigned int frame,
 	metadataReady.emit(frame, ctrls);
 }
 
+void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame)
+{
+	/* Run algorithms into/using this context structure */
+	resultsHistory_.extendOne();
+	aiq::AiqResults& latestResults = resultsHistory_.latest();
+
+	/* Todo: Refactor AiqInputParameters interface to set following parameters. */
+	aiqInputParams_.afParams.lens_position = lensPosition_;
+	aiqInputParams_.afParams.lens_movement_start_timestamp = lensMovementStartTime_;
+
+	aiq_.run2a(frame, aiqInputParams_, latestResults);
+
+	exposure_ = latestResults.ae()->exposures[0].sensor_exposure->coarse_integration_time;
+	gain_ = latestResults.ae()->exposures[0].sensor_exposure->analog_gain_code_global;
+
+	/*
+	 * Af algorithm compares the timestamp of start of the lens movement and
+	 * that of the statistics generated to estimate whether next lens
+	 * position should be produced.
+	 * \todo use the lens movement start time reported by the pipeline handler.
+	 */
+	if (lensPosition_ != latestResults.af()->next_lens_position) {
+		utils::time_point time = utils::clock::now();
+		uint64_t usecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();
+		lensMovementStartTime_ = usecs;
+	}
+	lensPosition_ = latestResults.af()->next_lens_position;
+}
+
 void IPAIPU3::setControls(unsigned int frame)
 {
 	ControlList sensorCtrls(ctrls_);