Skip to content

Commit

Permalink
ipa: ipu3: Fill AGC and AWB metadata in algorithms
Browse files Browse the repository at this point in the history
Fill the frame metadata in the AGC and AWB algorithm's prepare()
function. This removes the need to fill metadata manually in the IPA
module's processStatsBuffer() function.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
  • Loading branch information
pinchartl committed Oct 24, 2022
1 parent 32d5f0d commit 11f5c3a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
16 changes: 15 additions & 1 deletion src/ipa/ipu3/algorithms/agc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <libcamera/base/log.h>
#include <libcamera/base/utils.h>

#include <libcamera/control_ids.h>
#include <libcamera/ipa/core_ipa_interface.h>

#include "libipa/histogram.h"
Expand Down Expand Up @@ -328,7 +329,7 @@ double Agc::estimateLuminance(IPAActiveState &activeState,
void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,
IPAFrameContext &frameContext,
const ipu3_uapi_stats_3a *stats,
[[maybe_unused]] ControlList &metadata)
ControlList &metadata)
{
/*
* Estimate the gain needed to have the proportion of pixels in a given
Expand Down Expand Up @@ -365,6 +366,19 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,

computeExposure(context, frameContext, yGain, iqMeanGain);
frameCount_++;

utils::Duration exposureTime = context.configuration.sensor.lineDuration
* frameContext.sensor.exposure;
metadata.set(controls::AnalogueGain, frameContext.sensor.gain);
metadata.set(controls::ExposureTime, exposureTime.get<std::micro>());

/* \todo Use VBlank value calculated from each frame exposure. */
uint32_t vTotal = context.configuration.sensor.size.height
+ context.configuration.sensor.defVBlank;
utils::Duration frameDuration = context.configuration.sensor.lineDuration
* vTotal;
metadata.set(controls::FrameDuration, frameDuration.get<std::micro>());

}

REGISTER_IPA_ALGORITHM(Agc, "Agc")
Expand Down
10 changes: 10 additions & 0 deletions src/ipa/ipu3/algorithms/awb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include <libcamera/base/log.h>

#include <libcamera/control_ids.h>

/**
* \file awb.h
*/
Expand Down Expand Up @@ -403,6 +405,14 @@ void Awb::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,
context.activeState.awb.gains.green = asyncResults_.greenGain;
context.activeState.awb.gains.red = asyncResults_.redGain;
context.activeState.awb.temperatureK = asyncResults_.temperatureK;

metadata.set(controls::AwbEnable, true);
metadata.set(controls::ColourGains, {
static_cast<float>(context.activeState.awb.gains.red),
static_cast<float>(context.activeState.awb.gains.blue)
});
metadata.set(controls::ColourTemperature,
context.activeState.awb.temperatureK);
}

constexpr uint16_t Awb::threshold(float value)
Expand Down
3 changes: 3 additions & 0 deletions src/ipa/ipu3/ipa_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ namespace libcamera::ipa::ipu3 {
*
* \var IPASessionConfiguration::sensor.defVBlank
* \brief The default vblank value of the sensor
*
* \var IPASessionConfiguration::sensor.size
* \brief Sensor output resolution
*/

/**
Expand Down
1 change: 1 addition & 0 deletions src/ipa/ipu3/ipa_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct IPASessionConfiguration {
struct {
int32_t defVBlank;
utils::Duration lineDuration;
Size size;
} sensor;
};

Expand Down
13 changes: 1 addition & 12 deletions src/ipa/ipu3/ipu3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,
/* Initialise the sensor configuration. */
context_.configuration.sensor.lineDuration = sensorInfo_.minLineLength
* 1.0s / sensorInfo_.pixelRate;
context_.configuration.sensor.size = sensorInfo_.outputSize;

/*
* Compute the sensor V4L2 controls to be used by the algorithms and
Expand Down Expand Up @@ -628,25 +629,13 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame,
frameContext.sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get<int32_t>();
frameContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>());

double lineDuration = context_.configuration.sensor.lineDuration.get<std::micro>();
int32_t vBlank = context_.configuration.sensor.defVBlank;
ControlList metadata(controls::controls);

for (auto const &algo : algorithms())
algo->process(context_, frame, frameContext, stats, metadata);

setControls(frame);

/* \todo Use VBlank value calculated from each frame exposure. */
int64_t frameDuration = (vBlank + sensorInfo_.outputSize.height) * lineDuration;
metadata.set(controls::FrameDuration, frameDuration);

metadata.set(controls::AnalogueGain, frameContext.sensor.gain);

metadata.set(controls::ColourTemperature, context_.activeState.awb.temperatureK);

metadata.set(controls::ExposureTime, frameContext.sensor.exposure * lineDuration);

/*
* \todo The Metadata provides a path to getting extended data
* out to the application. Further data such as a simplifed Histogram
Expand Down

0 comments on commit 11f5c3a

Please sign in to comment.