libcamera: software_isp: Run sw-statistics once every 4th frame

Run sw-statistics once every 4th frame, instead of every frame. There are
2 reasons for this:

1. There really is no need to have statistics for every frame and only
doing this every 4th frame helps save some CPU time.

2. The generic nature of the simple pipeline-handler, so no information
about possible CSI receiver frame-delays. In combination with the software
ISP often being used with sensors without sensor info in the sensor-helper
code, so no reliable control-delay information means that the software ISP
is prone to AGC oscillation. Skipping statistics gathering also means
skipping running the AGC algorithm slowing it down, avoiding this
oscillation.

Note ideally the AGC oscillation problem would be fixed by adding sensor
metadata support all through the stack so that the exact gain and exposure
used for a specific frame are reliably provided by the sensor metadata.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: Milan Zamazal <mzamazal@redhat.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Hans de Goede <hansg@kernel.org>
Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Hans de Goede
2025-09-30 17:04:28 +02:00
committed by Kieran Bingham
parent 9b441cf198
commit c28bb6a6a4
4 changed files with 43 additions and 18 deletions

View File

@@ -62,8 +62,9 @@ namespace libcamera {
*/
/**
* \fn void SwStatsCpu::processLine0(unsigned int y, const uint8_t *src[])
* \fn void SwStatsCpu::processLine0(uint32_t frame, unsigned int y, const uint8_t *src[])
* \brief Process line 0
* \param[in] frame The frame number
* \param[in] y The y coordinate.
* \param[in] src The input data.
*
@@ -74,8 +75,9 @@ namespace libcamera {
*/
/**
* \fn void SwStatsCpu::processLine2(unsigned int y, const uint8_t *src[])
* \fn void SwStatsCpu::processLine2(uint32_t frame, unsigned int y, const uint8_t *src[])
* \brief Process line 2 and 3
* \param[in] frame The frame number
* \param[in] y The y coordinate.
* \param[in] src The input data.
*
@@ -89,6 +91,11 @@ namespace libcamera {
* \brief Signals that the statistics are ready
*/
/**
* \var SwStatsCpu::kStatPerNumFrames
* \brief Run stats once every kStatPerNumFrames frames
*/
/**
* \typedef SwStatsCpu::statsProcessFn
* \brief Called when there is data to get statistics from
@@ -295,11 +302,15 @@ void SwStatsCpu::statsGBRG10PLine0(const uint8_t *src[])
/**
* \brief Reset state to start statistics gathering for a new frame
* \param[in] frame The frame number
*
* This may only be called after a successful setWindow() call.
*/
void SwStatsCpu::startFrame(void)
void SwStatsCpu::startFrame(uint32_t frame)
{
if (frame % kStatPerNumFrames)
return;
if (window_.width == 0)
LOG(SwStatsCpu, Error) << "Calling startFrame() without setWindow()";
@@ -318,7 +329,7 @@ void SwStatsCpu::startFrame(void)
*/
void SwStatsCpu::finishFrame(uint32_t frame, uint32_t bufferId)
{
stats_.valid = true;
stats_.valid = frame % kStatPerNumFrames == 0;
*sharedStats_ = stats_;
statsReady.emit(frame, bufferId);
}