[libcamera-devel,19/20] ipa: rpi: agc: Avoid overwriting caller's statistics pointer
diff mbox series

Message ID 20231006132000.23504-20-naush@raspberrypi.com
State Superseded
Headers show
Series
  • Raspberry Pi: Preliminary PiSP support
Related show

Commit Message

Naushir Patuck Oct. 6, 2023, 1:19 p.m. UTC
From: David Plowman <david.plowman@raspberrypi.com>

The code was inadvertently overwriting the caller's StatisticsPtr,
meaning that subsequent algorithms would get the wrong image
statistics when AGC channels changed.

This could be fix using std::ref, though I find the C-style pointer
fix easier to understand!

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
---
 src/ipa/rpi/controller/rpi/agc.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Jacopo Mondi Oct. 12, 2023, 10:54 a.m. UTC | #1
Hi Naush

On Fri, Oct 06, 2023 at 02:19:59PM +0100, Naushir Patuck via libcamera-devel wrote:
> From: David Plowman <david.plowman@raspberrypi.com>
>
> The code was inadvertently overwriting the caller's StatisticsPtr,
> meaning that subsequent algorithms would get the wrong image
> statistics when AGC channels changed.
>
> This could be fix using std::ref, though I find the C-style pointer
> fix easier to understand!
>
> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
> Reviewed-by: Naushir Patuck <naush@raspberrypi.com>

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

> ---
>  src/ipa/rpi/controller/rpi/agc.cpp | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp
> index 870cb4315c42..758da0719b9b 100644
> --- a/src/ipa/rpi/controller/rpi/agc.cpp
> +++ b/src/ipa/rpi/controller/rpi/agc.cpp
> @@ -311,15 +311,16 @@ void Agc::process(StatisticsPtr &stats, Metadata *imageMetadata)
>  	 * exist, and call process(). We must make the agc.status metadata record correctly
>  	 * which channel this is.
>  	 */
> +	StatisticsPtr *statsPtr = &stats;
>  	if (channelData.statistics && channelData.deviceStatus) {
>  		deviceStatus = *channelData.deviceStatus;
> -		stats = channelData.statistics;
> +		statsPtr = &channelData.statistics;
>  	} else {
>  		/* Can also happen when new channels start. */
>  		LOG(RPiAgc, Debug) << "process: channel " << channelIndex << " not seen yet";
>  	}
>
> -	channelData.channel.process(stats, deviceStatus, imageMetadata, channelTotalExposures_);
> +	channelData.channel.process(*statsPtr, deviceStatus, imageMetadata, channelTotalExposures_);
>  	auto dur = setCurrentChannelIndexGetExposure(imageMetadata, "process: no AGC status found",
>  						     channelIndex);
>  	if (dur)
> --
> 2.34.1
>

Patch
diff mbox series

diff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp
index 870cb4315c42..758da0719b9b 100644
--- a/src/ipa/rpi/controller/rpi/agc.cpp
+++ b/src/ipa/rpi/controller/rpi/agc.cpp
@@ -311,15 +311,16 @@  void Agc::process(StatisticsPtr &stats, Metadata *imageMetadata)
 	 * exist, and call process(). We must make the agc.status metadata record correctly
 	 * which channel this is.
 	 */
+	StatisticsPtr *statsPtr = &stats;
 	if (channelData.statistics && channelData.deviceStatus) {
 		deviceStatus = *channelData.deviceStatus;
-		stats = channelData.statistics;
+		statsPtr = &channelData.statistics;
 	} else {
 		/* Can also happen when new channels start. */
 		LOG(RPiAgc, Debug) << "process: channel " << channelIndex << " not seen yet";
 	}
 
-	channelData.channel.process(stats, deviceStatus, imageMetadata, channelTotalExposures_);
+	channelData.channel.process(*statsPtr, deviceStatus, imageMetadata, channelTotalExposures_);
 	auto dur = setCurrentChannelIndexGetExposure(imageMetadata, "process: no AGC status found",
 						     channelIndex);
 	if (dur)