Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/libcamera/internal/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Request::Private : public Extensible::Private
void prepare(std::chrono::milliseconds timeout = 0ms);
Signal<> prepared;

void setError(Errors error);

private:
friend class PipelineHandler;
friend std::ostream &operator<<(std::ostream &out, const Request &r);
Expand All @@ -59,6 +61,8 @@ class Request::Private : public Extensible::Private
std::unordered_set<FrameBuffer *> pending_;
std::map<FrameBuffer *, std::unique_ptr<EventNotifier>> notifiers_;
std::unique_ptr<Timer> timer_;

Errors error_;
};

} /* namespace libcamera */
Expand Down
10 changes: 10 additions & 0 deletions include/libcamera/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <unordered_set>

#include <libcamera/base/class.h>
#include <libcamera/base/flags.h>
#include <libcamera/base/signal.h>

#include <libcamera/controls.h>
Expand Down Expand Up @@ -43,6 +44,14 @@ class Request : public Extensible
ReuseBuffers = (1 << 0),
};

enum ErrorId {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still call this ErrorFlag
Each one is a flag that can be set.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes indeed sense, I'll change it back

NoError = 0,
ControlError = (1 << 0),
PFCError = (1 << 1),
};

using Errors = Flags<ErrorId>;
Comment thread
jmondi marked this conversation as resolved.

using BufferMap = std::map<const Stream *, FrameBuffer *>;

Request(Camera *camera, uint64_t cookie = 0);
Expand All @@ -60,6 +69,7 @@ class Request : public Extensible
uint32_t sequence() const;
uint64_t cookie() const { return cookie_; }
Status status() const { return status_; }
Errors error() const;

bool hasPendingBuffers() const;

Expand Down
10 changes: 8 additions & 2 deletions src/ipa/ipu3/algorithms/af.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ Af::Af()
/**
* \copydoc libcamera::ipa::Algorithm::prepare
*/
void Af::prepare(IPAContext &context, ipu3_uapi_params *params)
void Af::prepare(IPAContext &context,
[[maybe_unused]] unsigned int frame,
[[maybe_unused]] IPU3FrameContext &frameContext,
ipu3_uapi_params *params)
{
const struct ipu3_uapi_grid_config &grid = context.configuration.af.afGrid;
params->acc_param.af.grid_cfg = grid;
Expand Down Expand Up @@ -406,6 +409,7 @@ bool Af::afIsOutOfFocus(IPAContext context)
/**
* \brief Determine the max contrast image and lens position.
* \param[in] context The IPA context.
* \param[in] frame The frame context sequence number
* \param[in] frameContext The current frame context
* \param[in] stats The statistics buffer of IPU3.
*
Expand All @@ -420,7 +424,9 @@ bool Af::afIsOutOfFocus(IPAContext context)
*
* [1] Hill Climbing Algorithm, https://en.wikipedia.org/wiki/Hill_climbing
*/
void Af::process(IPAContext &context, [[maybe_unused]] IPAFrameContext *frameContext,
void Af::process(IPAContext &context,
[[maybe_unused]] unsigned int frame,
[[maybe_unused]] IPU3FrameContext &frameContext,
const ipu3_uapi_stats_3a *stats)
{
/* Evaluate the AF buffer length */
Expand Down
8 changes: 6 additions & 2 deletions src/ipa/ipu3/algorithms/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ class Af : public Algorithm
Af();
~Af() = default;

void prepare(IPAContext &context, ipu3_uapi_params *params) override;
int configure(IPAContext &context, const IPAConfigInfo &configInfo) override;
void process(IPAContext &context, IPAFrameContext *frameContext,

void prepare(IPAContext &context, unsigned int frame,
IPU3FrameContext &frameContext,
ipu3_uapi_params *params) override;
void process(IPAContext &context, unsigned int frame,
IPU3FrameContext &frameContext,
const ipu3_uapi_stats_3a *stats) override;

private:
Expand Down
11 changes: 7 additions & 4 deletions src/ipa/ipu3/algorithms/agc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ utils::Duration Agc::filterExposure(utils::Duration exposureValue)
* \param[in] yGain 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, IPAFrameContext *frameContext,
void Agc::computeExposure(IPAContext &context, IPU3FrameContext &frameContext,
double yGain, double iqMeanGain)
{
const IPASessionConfiguration &configuration = context.configuration;
/* Get the effective exposure and gain applied on the sensor. */
uint32_t exposure = frameContext->sensor.exposure;
double analogueGain = frameContext->sensor.gain;
uint32_t exposure = frameContext.sensor.exposure;
double analogueGain = frameContext.sensor.gain;

/* Use the highest of the two gain estimates. */
double evGain = std::max(yGain, iqMeanGain);
Expand Down Expand Up @@ -317,13 +317,16 @@ double Agc::estimateLuminance(IPAActiveState &activeState,
/**
* \brief Process IPU3 statistics, and run AGC operations
* \param[in] context The shared IPA context
* \param[in] frame The current frame sequence number
* \param[in] frameContext The current frame context
* \param[in] stats The IPU3 statistics and ISP results
*
* Identify the current image brightness, and use that to estimate the optimal
* new exposure and gain for the scene.
*/
void Agc::process(IPAContext &context, [[maybe_unused]] IPAFrameContext *frameContext,
void Agc::process(IPAContext &context,
[[maybe_unused]] unsigned int frame,
IPU3FrameContext &frameContext,
const ipu3_uapi_stats_3a *stats)
{
/*
Expand Down
5 changes: 3 additions & 2 deletions src/ipa/ipu3/algorithms/agc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ class Agc : public Algorithm
~Agc() = default;

int configure(IPAContext &context, const IPAConfigInfo &configInfo) override;
void process(IPAContext &context, IPAFrameContext *frameContext,
void process(IPAContext &context, unsigned int frame,
IPU3FrameContext &frameContext,
const ipu3_uapi_stats_3a *stats) override;

private:
double measureBrightness(const ipu3_uapi_stats_3a *stats,
const ipu3_uapi_grid_config &grid) const;
utils::Duration filterExposure(utils::Duration currentExposure);
void computeExposure(IPAContext &context, IPAFrameContext *frameContext,
void computeExposure(IPAContext &context, IPU3FrameContext &frameContext,
double yGain, double iqMeanGain);
double estimateLuminance(IPAActiveState &activeState,
const ipu3_uapi_grid_config &grid,
Expand Down
9 changes: 7 additions & 2 deletions src/ipa/ipu3/algorithms/awb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,9 @@ void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
/**
* \copydoc libcamera::ipa::Algorithm::process
*/
void Awb::process(IPAContext &context, [[maybe_unused]] IPAFrameContext *frameContext,
void Awb::process(IPAContext &context,
[[maybe_unused]] unsigned int frame,
[[maybe_unused]] IPU3FrameContext &frameContext,
const ipu3_uapi_stats_3a *stats)
{
calculateWBGains(stats);
Expand Down Expand Up @@ -429,7 +431,10 @@ constexpr uint16_t Awb::gainValue(double gain)
/**
* \copydoc libcamera::ipa::Algorithm::prepare
*/
void Awb::prepare(IPAContext &context, ipu3_uapi_params *params)
void Awb::prepare(IPAContext &context,
[[maybe_unused]] unsigned int frame,
[[maybe_unused]] IPU3FrameContext &frameContext,
ipu3_uapi_params *params)
{
/*
* Green saturation thresholds are reduced because we are using the
Expand Down
8 changes: 6 additions & 2 deletions src/ipa/ipu3/algorithms/awb.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ class Awb : public Algorithm
~Awb();

int configure(IPAContext &context, const IPAConfigInfo &configInfo) override;
void prepare(IPAContext &context, ipu3_uapi_params *params) override;
void process(IPAContext &context, IPAFrameContext *frameContext,

void prepare(IPAContext &context, unsigned int frame,
IPU3FrameContext &frameContext,
ipu3_uapi_params *params) override;
void process(IPAContext &context, unsigned int frame,
IPU3FrameContext &frameContext,
const ipu3_uapi_stats_3a *stats) override;

private:
Expand Down
6 changes: 5 additions & 1 deletion src/ipa/ipu3/algorithms/blc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ BlackLevelCorrection::BlackLevelCorrection()
/**
* \brief Fill in the parameter structure, and enable black level correction
* \param context The shared IPA context
* \param[in] frame The frame context sequence number
* \param[in] frameContext The FrameContext for this frame
* \param params The IPU3 parameters
*
* Populate the IPU3 parameter structure with the correction values for each
* channel and enable the corresponding ImgU block processing.
*/
void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context,
ipu3_uapi_params *params)
[[maybe_unused]] unsigned int frame,
[[maybe_unused]] IPU3FrameContext &frameContext,
ipu3_uapi_params *params)
{
/*
* The Optical Black Level correction values
Expand Down
4 changes: 3 additions & 1 deletion src/ipa/ipu3/algorithms/blc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class BlackLevelCorrection : public Algorithm
public:
BlackLevelCorrection();

void prepare(IPAContext &context, ipu3_uapi_params *params) override;
void prepare(IPAContext &context, unsigned int frame,
IPU3FrameContext &frameContext,
ipu3_uapi_params *params) override;
};

} /* namespace ipa::ipu3::algorithms */
Expand Down
9 changes: 8 additions & 1 deletion src/ipa/ipu3/algorithms/tone_mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ int ToneMapping::configure(IPAContext &context,
/**
* \brief Fill in the parameter structure, and enable gamma control
* \param context The shared IPA context
* \param[in] frame The frame context sequence number
* \param[in] frameContext The FrameContext for this frame
* \param params The IPU3 parameters
*
* Populate the IPU3 parameter structure with our tone mapping look up table and
* enable the gamma control module in the processing blocks.
*/
void ToneMapping::prepare([[maybe_unused]] IPAContext &context,
[[maybe_unused]] unsigned int frame,
[[maybe_unused]] IPU3FrameContext &frameContext,
ipu3_uapi_params *params)
{
/* Copy the calculated LUT into the parameters buffer. */
Expand All @@ -72,13 +76,16 @@ void ToneMapping::prepare([[maybe_unused]] IPAContext &context,
/**
* \brief Calculate the tone mapping look up table
* \param context The shared IPA context
* \param frame The current frame sequence number
* \param frameContext The current frame context
* \param stats The IPU3 statistics and ISP results
*
* The tone mapping look up table is generated as an inverse power curve from
* our gamma setting.
*/
void ToneMapping::process(IPAContext &context, [[maybe_unused]] IPAFrameContext *frameContext,
void ToneMapping::process(IPAContext &context,
[[maybe_unused]] unsigned int frame,
[[maybe_unused]] IPU3FrameContext &frameContext,
[[maybe_unused]] const ipu3_uapi_stats_3a *stats)
{
/*
Expand Down
6 changes: 4 additions & 2 deletions src/ipa/ipu3/algorithms/tone_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ class ToneMapping : public Algorithm
ToneMapping();

int configure(IPAContext &context, const IPAConfigInfo &configInfo) override;
void prepare(IPAContext &context, ipu3_uapi_params *params) override;
void process(IPAContext &context, IPAFrameContext *frameContext,
void prepare(IPAContext &context, unsigned int frame,
IPU3FrameContext &frameContext, ipu3_uapi_params *params) override;
void process(IPAContext &context, unsigned int frame,
IPU3FrameContext &frameContext,
const ipu3_uapi_stats_3a *stats) override;

private:
Expand Down
43 changes: 5 additions & 38 deletions src/ipa/ipu3/ipa_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,6 @@ namespace libcamera::ipa::ipu3 {
* most recently computed by the IPA algorithms.
*/

/**
* \struct IPAFrameContext
* \brief Context for a frame
*
* The frame context stores data specific to a single frame processed by the
* IPA. Each frame processed by the IPA has a context associated with it,
* accessible through the IPAContext structure.
*
* Fields in the frame context should reflect values and controls
* associated with the specific frame as requested by the application, and
* as configured by the hardware. Fields can be read by algorithms to
* determine if they should update any specific action for this frame, and
* finally to update the metadata control lists when the frame is fully
* completed.
*/

/**
* \struct IPAContext
* \brief Global IPA context data shared between all algorithms
Expand Down Expand Up @@ -181,33 +165,16 @@ namespace libcamera::ipa::ipu3 {
*/

/**
* \brief Default constructor for IPAFrameContext
*/
IPAFrameContext::IPAFrameContext() = default;

/**
* \brief Construct a IPAFrameContext instance
*/
IPAFrameContext::IPAFrameContext(uint32_t id, const ControlList &reqControls)
: frame(id), frameControls(reqControls)
{
sensor = {};
}

/**
* \var IPAFrameContext::frame
* \brief The frame number
*
* \var IPAFrameContext::frameControls
* \brief Controls sent in by the application while queuing the request
* \struct IPU3FrameContext
* \copybrief libcamera::ipa::IPAFrameContext
*
* \var IPAFrameContext::sensor
* \var IPU3FrameContext::sensor
* \brief Effective sensor values that were applied for the frame
*
* \var IPAFrameContext::sensor.exposure
* \var IPU3FrameContext::sensor.exposure
* \brief Exposure time expressed as a number of lines
*
* \var IPAFrameContext::sensor.gain
* \var IPU3FrameContext::sensor.gain
* \brief Analogue gain multiplier
*/

Expand Down
16 changes: 4 additions & 12 deletions src/ipa/ipu3/ipa_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@

#pragma once

#include <array>

#include <linux/intel-ipu3.h>

#include <libcamera/base/utils.h>

#include <libcamera/controls.h>
#include <libcamera/geometry.h>

#include <libipa/fc_queue.h>

namespace libcamera {

namespace ipa::ipu3 {

/* Maximum number of frame contexts to be held */
static constexpr uint32_t kMaxFrameContexts = 16;

struct IPASessionConfiguration {
struct {
ipu3_uapi_grid_config bdsGrid;
Expand Down Expand Up @@ -76,24 +73,19 @@ struct IPAActiveState {
} toneMapping;
};

struct IPAFrameContext {
IPAFrameContext();
IPAFrameContext(uint32_t id, const ControlList &reqControls);
struct IPU3FrameContext : public IPAFrameContext {

struct {
uint32_t exposure;
double gain;
} sensor;

uint32_t frame;
ControlList frameControls;
};

struct IPAContext {
IPASessionConfiguration configuration;
IPAActiveState activeState;

std::array<IPAFrameContext, kMaxFrameContexts> frameContexts;
FCQueue<IPU3FrameContext> frameContexts;
};

} /* namespace ipa::ipu3 */
Expand Down
Loading