mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-19 02:15:05 +03:00
ipa: rkisp1: agc: Store per-frame information in frame context
Rework the algorithm's usage of the active state to store the value of controls for the last queued request in the queueRequest() function, and store a copy of the values in the corresponding frame context. The frame context is used in the prepare() function to populate the ISP parameters with values corresponding to the right frame. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
b3724d3766
commit
310b7a6a30
5 changed files with 66 additions and 31 deletions
|
@ -144,17 +144,19 @@ utils::Duration Agc::filterExposure(utils::Duration exposureValue)
|
||||||
/**
|
/**
|
||||||
* \brief Estimate the new exposure and gain values
|
* \brief Estimate the new exposure and gain values
|
||||||
* \param[inout] context The shared IPA Context
|
* \param[inout] context The shared IPA Context
|
||||||
|
* \param[in] frameContext The FrameContext for this frame
|
||||||
* \param[in] yGain The gain calculated on the current brightness level
|
* \param[in] yGain The gain calculated on the current brightness level
|
||||||
* \param[in] iqMeanGain The gain calculated based on the relative luminance target
|
* \param[in] iqMeanGain The gain calculated based on the relative luminance target
|
||||||
*/
|
*/
|
||||||
void Agc::computeExposure(IPAContext &context, double yGain, double iqMeanGain)
|
void Agc::computeExposure(IPAContext &context, IPAFrameContext &frameContext,
|
||||||
|
double yGain, double iqMeanGain)
|
||||||
{
|
{
|
||||||
IPASessionConfiguration &configuration = context.configuration;
|
IPASessionConfiguration &configuration = context.configuration;
|
||||||
IPAActiveState &activeState = context.activeState;
|
IPAActiveState &activeState = context.activeState;
|
||||||
|
|
||||||
/* Get the effective exposure and gain applied on the sensor. */
|
/* Get the effective exposure and gain applied on the sensor. */
|
||||||
uint32_t exposure = activeState.sensor.exposure;
|
uint32_t exposure = frameContext.sensor.exposure;
|
||||||
double analogueGain = activeState.sensor.gain;
|
double analogueGain = frameContext.sensor.gain;
|
||||||
|
|
||||||
/* Use the highest of the two gain estimates. */
|
/* Use the highest of the two gain estimates. */
|
||||||
double evGain = std::max(yGain, iqMeanGain);
|
double evGain = std::max(yGain, iqMeanGain);
|
||||||
|
@ -286,9 +288,16 @@ double Agc::measureBrightness(const rkisp1_cif_isp_hist_stat *hist) const
|
||||||
* new exposure and gain for the scene.
|
* new exposure and gain for the scene.
|
||||||
*/
|
*/
|
||||||
void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,
|
void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,
|
||||||
[[maybe_unused]] IPAFrameContext &frameContext,
|
IPAFrameContext &frameContext, const rkisp1_stat_buffer *stats)
|
||||||
const rkisp1_stat_buffer *stats)
|
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* \todo Verify that the exposure and gain applied by the sensor for
|
||||||
|
* this frame match what has been requested. This isn't a hard
|
||||||
|
* requirement for stability of the AGC (the guarantee we need in
|
||||||
|
* automatic mode is a perfect match between the frame and the values
|
||||||
|
* we receive), but is important in manual mode.
|
||||||
|
*/
|
||||||
|
|
||||||
const rkisp1_cif_isp_stat *params = &stats->params;
|
const rkisp1_cif_isp_stat *params = &stats->params;
|
||||||
ASSERT(stats->meas_type & RKISP1_CIF_ISP_STAT_AUTOEXP);
|
ASSERT(stats->meas_type & RKISP1_CIF_ISP_STAT_AUTOEXP);
|
||||||
|
|
||||||
|
@ -320,7 +329,7 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
computeExposure(context, yGain, iqMeanGain);
|
computeExposure(context, frameContext, yGain, iqMeanGain);
|
||||||
frameCount_++;
|
frameCount_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,9 +337,11 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,
|
||||||
* \copydoc libcamera::ipa::Algorithm::prepare
|
* \copydoc libcamera::ipa::Algorithm::prepare
|
||||||
*/
|
*/
|
||||||
void Agc::prepare(IPAContext &context, const uint32_t frame,
|
void Agc::prepare(IPAContext &context, const uint32_t frame,
|
||||||
[[maybe_unused]] IPAFrameContext &frameContext,
|
IPAFrameContext &frameContext, rkisp1_params_cfg *params)
|
||||||
rkisp1_params_cfg *params)
|
|
||||||
{
|
{
|
||||||
|
frameContext.agc.exposure = context.activeState.agc.exposure;
|
||||||
|
frameContext.agc.gain = context.activeState.agc.gain;
|
||||||
|
|
||||||
if (frame > 0)
|
if (frame > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ public:
|
||||||
const rkisp1_stat_buffer *stats) override;
|
const rkisp1_stat_buffer *stats) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void computeExposure(IPAContext &Context, double yGain, double iqMeanGain);
|
void computeExposure(IPAContext &Context, IPAFrameContext &frameContext,
|
||||||
|
double yGain, double iqMeanGain);
|
||||||
utils::Duration filterExposure(utils::Duration exposureValue);
|
utils::Duration filterExposure(utils::Duration exposureValue);
|
||||||
double estimateLuminance(const rkisp1_cif_isp_ae_stat *ae, double gain);
|
double estimateLuminance(const rkisp1_cif_isp_ae_stat *ae, double gain);
|
||||||
double measureBrightness(const rkisp1_cif_isp_hist_stat *hist) const;
|
double measureBrightness(const rkisp1_cif_isp_hist_stat *hist) const;
|
||||||
|
|
|
@ -104,16 +104,13 @@ namespace libcamera::ipa::rkisp1 {
|
||||||
* \var IPAActiveState::agc
|
* \var IPAActiveState::agc
|
||||||
* \brief State for the Automatic Gain Control algorithm
|
* \brief State for the Automatic Gain Control algorithm
|
||||||
*
|
*
|
||||||
* The exposure and gain determined are expected to be applied to the sensor
|
* The exposure and gain are the latest values computed by the AGC algorithm.
|
||||||
* at the earliest opportunity.
|
|
||||||
*
|
*
|
||||||
* \var IPAActiveState::agc.exposure
|
* \var IPAActiveState::agc.exposure
|
||||||
* \brief Exposure time expressed as a number of lines
|
* \brief Exposure time expressed as a number of lines
|
||||||
*
|
*
|
||||||
* \var IPAActiveState::agc.gain
|
* \var IPAActiveState::agc.gain
|
||||||
* \brief Analogue gain multiplier
|
* \brief Analogue gain multiplier
|
||||||
*
|
|
||||||
* The gain should be adapted to the sensor specific gain code before applying.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -181,17 +178,6 @@ namespace libcamera::ipa::rkisp1 {
|
||||||
* \brief Indicates if ISP parameters need to be updated
|
* \brief Indicates if ISP parameters need to be updated
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* \var IPAActiveState::sensor
|
|
||||||
* \brief Effective sensor values
|
|
||||||
*
|
|
||||||
* \var IPAActiveState::sensor.exposure
|
|
||||||
* \brief Exposure time expressed as a number of lines
|
|
||||||
*
|
|
||||||
* \var IPAActiveState::sensor.gain
|
|
||||||
* \brief Analogue gain multiplier
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \struct IPAFrameContext
|
* \struct IPAFrameContext
|
||||||
* \brief Per-frame context for algorithms
|
* \brief Per-frame context for algorithms
|
||||||
|
@ -199,6 +185,33 @@ namespace libcamera::ipa::rkisp1 {
|
||||||
* \todo Populate the frame context for all algorithms
|
* \todo Populate the frame context for all algorithms
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \var IPAFrameContext::agc
|
||||||
|
* \brief Automatic Gain Control parameters for this frame
|
||||||
|
*
|
||||||
|
* The exposure and gain are provided by the AGC algorithm, and are to be
|
||||||
|
* applied to the sensor in order to take effect for this frame.
|
||||||
|
*
|
||||||
|
* \var IPAFrameContext::agc.exposure
|
||||||
|
* \brief Exposure time expressed as a number of lines
|
||||||
|
*
|
||||||
|
* \var IPAFrameContext::agc.gain
|
||||||
|
* \brief Analogue gain multiplier
|
||||||
|
*
|
||||||
|
* The gain should be adapted to the sensor specific gain code before applying.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \var IPAFrameContext::sensor
|
||||||
|
* \brief Sensor configuration that used been used for this frame
|
||||||
|
*
|
||||||
|
* \var IPAFrameContext::sensor.exposure
|
||||||
|
* \brief Exposure time expressed as a number of lines
|
||||||
|
*
|
||||||
|
* \var IPAFrameContext::sensor.gain
|
||||||
|
* \brief Analogue gain multiplier
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \struct IPAContext
|
* \struct IPAContext
|
||||||
* \brief Global IPA context data shared between all algorithms
|
* \brief Global IPA context data shared between all algorithms
|
||||||
|
|
|
@ -82,6 +82,13 @@ struct IPAActiveState {
|
||||||
uint8_t sharpness;
|
uint8_t sharpness;
|
||||||
bool updateParams;
|
bool updateParams;
|
||||||
} filter;
|
} filter;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct IPAFrameContext : public FrameContext {
|
||||||
|
struct {
|
||||||
|
uint32_t exposure;
|
||||||
|
double gain;
|
||||||
|
} agc;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint32_t exposure;
|
uint32_t exposure;
|
||||||
|
@ -89,9 +96,6 @@ struct IPAActiveState {
|
||||||
} sensor;
|
} sensor;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IPAFrameContext : public FrameContext {
|
|
||||||
};
|
|
||||||
|
|
||||||
struct IPAContext {
|
struct IPAContext {
|
||||||
IPASessionConfiguration configuration;
|
IPASessionConfiguration configuration;
|
||||||
IPAActiveState activeState;
|
IPAActiveState activeState;
|
||||||
|
|
|
@ -333,9 +333,9 @@ void IPARkISP1::processStatsBuffer(const uint32_t frame, const uint32_t bufferId
|
||||||
reinterpret_cast<rkisp1_stat_buffer *>(
|
reinterpret_cast<rkisp1_stat_buffer *>(
|
||||||
mappedBuffers_.at(bufferId).planes()[0].data());
|
mappedBuffers_.at(bufferId).planes()[0].data());
|
||||||
|
|
||||||
context_.activeState.sensor.exposure =
|
frameContext.sensor.exposure =
|
||||||
sensorControls.get(V4L2_CID_EXPOSURE).get<int32_t>();
|
sensorControls.get(V4L2_CID_EXPOSURE).get<int32_t>();
|
||||||
context_.activeState.sensor.gain =
|
frameContext.sensor.gain =
|
||||||
camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>());
|
camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>());
|
||||||
|
|
||||||
unsigned int aeState = 0;
|
unsigned int aeState = 0;
|
||||||
|
@ -350,8 +350,14 @@ void IPARkISP1::processStatsBuffer(const uint32_t frame, const uint32_t bufferId
|
||||||
|
|
||||||
void IPARkISP1::setControls(unsigned int frame)
|
void IPARkISP1::setControls(unsigned int frame)
|
||||||
{
|
{
|
||||||
uint32_t exposure = context_.activeState.agc.exposure;
|
/*
|
||||||
uint32_t gain = camHelper_->gainCode(context_.activeState.agc.gain);
|
* \todo The frame number is most likely wrong here, we need to take
|
||||||
|
* internal sensor delays and other timing parameters into account.
|
||||||
|
*/
|
||||||
|
|
||||||
|
IPAFrameContext &frameContext = context_.frameContexts.get(frame);
|
||||||
|
uint32_t exposure = frameContext.agc.exposure;
|
||||||
|
uint32_t gain = camHelper_->gainCode(frameContext.agc.gain);
|
||||||
|
|
||||||
ControlList ctrls(ctrls_);
|
ControlList ctrls(ctrls_);
|
||||||
ctrls.set(V4L2_CID_EXPOSURE, static_cast<int32_t>(exposure));
|
ctrls.set(V4L2_CID_EXPOSURE, static_cast<int32_t>(exposure));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue