summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apps/common/ppm_writer.cpp7
-rw-r--r--src/gstreamer/gstlibcameraallocator.cpp14
-rw-r--r--src/ipa/libipa/lux.cpp6
-rw-r--r--src/ipa/rkisp1/algorithms/agc.cpp133
-rw-r--r--src/ipa/rkisp1/ipa_context.cpp24
-rw-r--r--src/ipa/rkisp1/ipa_context.h8
-rw-r--r--src/ipa/rpi/common/ipa_base.cpp104
-rw-r--r--src/ipa/rpi/controller/agc_algorithm.h8
-rw-r--r--src/ipa/rpi/controller/rpi/agc.cpp52
-rw-r--r--src/ipa/rpi/controller/rpi/agc.h8
-rw-r--r--src/ipa/rpi/controller/rpi/agc_channel.cpp24
-rw-r--r--src/ipa/rpi/controller/rpi/agc_channel.h8
-rw-r--r--src/libcamera/base/thread.cpp4
-rw-r--r--src/libcamera/camera.cpp20
-rw-r--r--src/libcamera/control_ids_core.yaml279
-rw-r--r--src/libcamera/control_ids_draft.yaml30
-rw-r--r--src/libcamera/dma_buf_allocator.cpp7
-rw-r--r--src/libcamera/ipa_proxy.cpp27
-rw-r--r--src/libcamera/pipeline/rkisp1/rkisp1.cpp15
-rw-r--r--src/libcamera/pipeline/rpi/common/pipeline_base.cpp19
-rw-r--r--src/libcamera/pipeline/uvcvideo/uvcvideo.cpp53
-rw-r--r--src/libcamera/pipeline/virtual/data/meson.build4
-rw-r--r--src/libcamera/pipeline/virtual/meson.build2
-rw-r--r--src/libcamera/pipeline/virtual/virtual.cpp15
-rw-r--r--src/libcamera/pipeline_handler.cpp12
-rw-r--r--src/libcamera/software_isp/software_isp.cpp6
-rw-r--r--src/libcamera/v4l2_subdevice.cpp8
-rw-r--r--src/v4l2/meson.build7
28 files changed, 712 insertions, 192 deletions
diff --git a/src/apps/common/ppm_writer.cpp b/src/apps/common/ppm_writer.cpp
index d6c8641d..368de8bf 100644
--- a/src/apps/common/ppm_writer.cpp
+++ b/src/apps/common/ppm_writer.cpp
@@ -7,6 +7,7 @@
#include "ppm_writer.h"
+#include <errno.h>
#include <fstream>
#include <iostream>
@@ -28,7 +29,7 @@ int PPMWriter::write(const char *filename,
std::ofstream output(filename, std::ios::binary);
if (!output) {
std::cerr << "Failed to open ppm file: " << filename << std::endl;
- return -EINVAL;
+ return -EIO;
}
output << "P6" << std::endl
@@ -36,7 +37,7 @@ int PPMWriter::write(const char *filename,
<< "255" << std::endl;
if (!output) {
std::cerr << "Failed to write the file header" << std::endl;
- return -EINVAL;
+ return -EIO;
}
const unsigned int rowLength = config.size.width * 3;
@@ -45,7 +46,7 @@ int PPMWriter::write(const char *filename,
output.write(row, rowLength);
if (!output) {
std::cerr << "Failed to write image data at row " << y << std::endl;
- return -EINVAL;
+ return -EIO;
}
}
diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp
index 7e4c904d..d4492d99 100644
--- a/src/gstreamer/gstlibcameraallocator.cpp
+++ b/src/gstreamer/gstlibcameraallocator.cpp
@@ -8,6 +8,8 @@
#include "gstlibcameraallocator.h"
+#include <utility>
+
#include <libcamera/camera.h>
#include <libcamera/framebuffer_allocator.h>
#include <libcamera/stream.h>
@@ -199,22 +201,20 @@ GstLibcameraAllocator *
gst_libcamera_allocator_new(std::shared_ptr<Camera> camera,
CameraConfiguration *config_)
{
- auto *self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR,
- nullptr));
+ g_autoptr(GstLibcameraAllocator) self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR,
+ nullptr));
gint ret;
self->cm_ptr = new std::shared_ptr<CameraManager>(gst_libcamera_get_camera_manager(ret));
- if (ret) {
- g_object_unref(self);
+ if (ret)
return nullptr;
- }
self->fb_allocator = new FrameBufferAllocator(camera);
for (StreamConfiguration &streamCfg : *config_) {
Stream *stream = streamCfg.stream();
ret = self->fb_allocator->allocate(stream);
- if (ret == 0)
+ if (ret <= 0)
return nullptr;
GQueue *pool = g_queue_new();
@@ -228,7 +228,7 @@ gst_libcamera_allocator_new(std::shared_ptr<Camera> camera,
g_hash_table_insert(self->pools, stream, pool);
}
- return self;
+ return std::exchange(self, nullptr);
}
bool
diff --git a/src/ipa/libipa/lux.cpp b/src/ipa/libipa/lux.cpp
index bae8198f..61f8fea8 100644
--- a/src/ipa/libipa/lux.cpp
+++ b/src/ipa/libipa/lux.cpp
@@ -76,9 +76,9 @@ namespace ipa {
*/
/**
- * \brief Construct the Lux helper module
- * \param[in] binSize The maximum count of each bin
- */
+ * \brief Construct the Lux helper module
+ * \param[in] binSize The maximum count of each bin
+ */
Lux::Lux(unsigned int binSize)
: binSize_(binSize)
{
diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp
index 40e5a8f4..1680669c 100644
--- a/src/ipa/rkisp1/algorithms/agc.cpp
+++ b/src/ipa/rkisp1/algorithms/agc.cpp
@@ -148,7 +148,16 @@ int Agc::init(IPAContext &context, const YamlObject &tuningData)
if (ret)
return ret;
- context.ctrlMap[&controls::AeEnable] = ControlInfo(false, true);
+ context.ctrlMap[&controls::ExposureTimeMode] =
+ ControlInfo(static_cast<int32_t>(controls::ExposureTimeModeAuto),
+ static_cast<int32_t>(controls::ExposureTimeModeManual),
+ static_cast<int32_t>(controls::ExposureTimeModeAuto));
+ context.ctrlMap[&controls::AnalogueGainMode] =
+ ControlInfo(static_cast<int32_t>(controls::AnalogueGainModeAuto),
+ static_cast<int32_t>(controls::AnalogueGainModeManual),
+ static_cast<int32_t>(controls::AnalogueGainModeAuto));
+ /* \todo Move this to the Camera class */
+ context.ctrlMap[&controls::AeEnable] = ControlInfo(false, true, true);
context.ctrlMap.merge(controls());
return 0;
@@ -169,7 +178,8 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)
10ms / context.configuration.sensor.lineDuration;
context.activeState.agc.manual.gain = context.activeState.agc.automatic.gain;
context.activeState.agc.manual.exposure = context.activeState.agc.automatic.exposure;
- context.activeState.agc.autoEnabled = !context.configuration.raw;
+ context.activeState.agc.autoExposureEnabled = !context.configuration.raw;
+ context.activeState.agc.autoGainEnabled = !context.configuration.raw;
context.activeState.agc.constraintMode =
static_cast<controls::AeConstraintModeEnum>(constraintModes().begin()->first);
@@ -215,18 +225,47 @@ void Agc::queueRequest(IPAContext &context,
auto &agc = context.activeState.agc;
if (!context.configuration.raw) {
- const auto &agcEnable = controls.get(controls::AeEnable);
- if (agcEnable && *agcEnable != agc.autoEnabled) {
- agc.autoEnabled = *agcEnable;
+ const auto &aeEnable = controls.get(controls::ExposureTimeMode);
+ if (aeEnable &&
+ (*aeEnable == controls::ExposureTimeModeAuto) != agc.autoExposureEnabled) {
+ agc.autoExposureEnabled = (*aeEnable == controls::ExposureTimeModeAuto);
LOG(RkISP1Agc, Debug)
- << (agc.autoEnabled ? "Enabling" : "Disabling")
- << " AGC";
+ << (agc.autoExposureEnabled ? "Enabling" : "Disabling")
+ << " AGC (exposure)";
+
+ /*
+ * If we go from auto -> manual with no manual control
+ * set, use the last computed value, which we don't
+ * know until prepare() so save this information.
+ *
+ * \todo Check the previous frame at prepare() time
+ * instead of saving a flag here
+ */
+ if (!agc.autoExposureEnabled && !controls.get(controls::ExposureTime))
+ frameContext.agc.autoExposureModeChange = true;
+ }
+
+ const auto &agEnable = controls.get(controls::AnalogueGainMode);
+ if (agEnable &&
+ (*agEnable == controls::AnalogueGainModeAuto) != agc.autoGainEnabled) {
+ agc.autoGainEnabled = (*agEnable == controls::AnalogueGainModeAuto);
+
+ LOG(RkISP1Agc, Debug)
+ << (agc.autoGainEnabled ? "Enabling" : "Disabling")
+ << " AGC (gain)";
+ /*
+ * If we go from auto -> manual with no manual control
+ * set, use the last computed value, which we don't
+ * know until prepare() so save this information.
+ */
+ if (!agc.autoGainEnabled && !controls.get(controls::AnalogueGain))
+ frameContext.agc.autoGainModeChange = true;
}
}
const auto &exposure = controls.get(controls::ExposureTime);
- if (exposure && !agc.autoEnabled) {
+ if (exposure && !agc.autoExposureEnabled) {
agc.manual.exposure = *exposure * 1.0us
/ context.configuration.sensor.lineDuration;
@@ -235,18 +274,19 @@ void Agc::queueRequest(IPAContext &context,
}
const auto &gain = controls.get(controls::AnalogueGain);
- if (gain && !agc.autoEnabled) {
+ if (gain && !agc.autoGainEnabled) {
agc.manual.gain = *gain;
LOG(RkISP1Agc, Debug) << "Set gain to " << agc.manual.gain;
}
- frameContext.agc.autoEnabled = agc.autoEnabled;
+ frameContext.agc.autoExposureEnabled = agc.autoExposureEnabled;
+ frameContext.agc.autoGainEnabled = agc.autoGainEnabled;
- if (!frameContext.agc.autoEnabled) {
+ if (!frameContext.agc.autoExposureEnabled)
frameContext.agc.exposure = agc.manual.exposure;
+ if (!frameContext.agc.autoGainEnabled)
frameContext.agc.gain = agc.manual.gain;
- }
const auto &meteringMode = controls.get(controls::AeMeteringMode);
if (meteringMode) {
@@ -283,9 +323,26 @@ void Agc::queueRequest(IPAContext &context,
void Agc::prepare(IPAContext &context, const uint32_t frame,
IPAFrameContext &frameContext, RkISP1Params *params)
{
- if (frameContext.agc.autoEnabled) {
- frameContext.agc.exposure = context.activeState.agc.automatic.exposure;
- frameContext.agc.gain = context.activeState.agc.automatic.gain;
+ uint32_t activeAutoExposure = context.activeState.agc.automatic.exposure;
+ double activeAutoGain = context.activeState.agc.automatic.gain;
+
+ /* Populate exposure and gain in auto mode */
+ if (frameContext.agc.autoExposureEnabled)
+ frameContext.agc.exposure = activeAutoExposure;
+ if (frameContext.agc.autoGainEnabled)
+ frameContext.agc.gain = activeAutoGain;
+
+ /*
+ * Populate manual exposure and gain from the active auto values when
+ * transitioning from auto to manual
+ */
+ if (!frameContext.agc.autoExposureEnabled && frameContext.agc.autoExposureModeChange) {
+ context.activeState.agc.manual.exposure = activeAutoExposure;
+ frameContext.agc.exposure = activeAutoExposure;
+ }
+ if (!frameContext.agc.autoGainEnabled && frameContext.agc.autoGainModeChange) {
+ context.activeState.agc.manual.gain = activeAutoGain;
+ frameContext.agc.gain = activeAutoGain;
}
if (frame > 0 && !frameContext.agc.updateMetering)
@@ -333,7 +390,14 @@ void Agc::fillMetadata(IPAContext &context, IPAFrameContext &frameContext,
* frameContext.sensor.exposure;
metadata.set(controls::AnalogueGain, frameContext.sensor.gain);
metadata.set(controls::ExposureTime, exposureTime.get<std::micro>());
- metadata.set(controls::AeEnable, frameContext.agc.autoEnabled);
+ metadata.set(controls::ExposureTimeMode,
+ frameContext.agc.autoExposureEnabled
+ ? controls::ExposureTimeModeAuto
+ : controls::ExposureTimeModeManual);
+ metadata.set(controls::AnalogueGainMode,
+ frameContext.agc.autoGainEnabled
+ ? controls::AnalogueGainModeAuto
+ : controls::AnalogueGainModeManual);
/* \todo Use VBlank value calculated from each frame exposure. */
uint32_t vTotal = context.configuration.sensor.size.height
@@ -424,14 +488,35 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,
[](uint32_t x) { return x >> 4; });
expMeans_ = { params->ae.exp_mean, context.hw->numAeCells };
- utils::Duration maxExposureTime =
- std::clamp(frameContext.agc.maxFrameDuration,
- context.configuration.sensor.minExposureTime,
- context.configuration.sensor.maxExposureTime);
- setLimits(context.configuration.sensor.minExposureTime,
- maxExposureTime,
- context.configuration.sensor.minAnalogueGain,
- context.configuration.sensor.maxAnalogueGain);
+ /*
+ * Set the AGC limits using the fixed exposure time and/or gain in
+ * manual mode, or the sensor limits in auto mode.
+ */
+ utils::Duration minExposureTime;
+ utils::Duration maxExposureTime;
+ double minAnalogueGain;
+ double maxAnalogueGain;
+
+ if (frameContext.agc.autoExposureEnabled) {
+ minExposureTime = context.configuration.sensor.minExposureTime;
+ maxExposureTime = std::clamp(frameContext.agc.maxFrameDuration,
+ context.configuration.sensor.minExposureTime,
+ context.configuration.sensor.maxExposureTime);
+ } else {
+ minExposureTime = context.configuration.sensor.lineDuration
+ * frameContext.agc.exposure;
+ maxExposureTime = minExposureTime;
+ }
+
+ if (frameContext.agc.autoGainEnabled) {
+ minAnalogueGain = context.configuration.sensor.minAnalogueGain;
+ maxAnalogueGain = context.configuration.sensor.maxAnalogueGain;
+ } else {
+ minAnalogueGain = frameContext.agc.gain;
+ maxAnalogueGain = frameContext.agc.gain;
+ }
+
+ setLimits(minExposureTime, maxExposureTime, minAnalogueGain, maxAnalogueGain);
/*
* The Agc algorithm needs to know the effective exposure value that was
diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp
index 80b99df8..261c0472 100644
--- a/src/ipa/rkisp1/ipa_context.cpp
+++ b/src/ipa/rkisp1/ipa_context.cpp
@@ -165,8 +165,11 @@ namespace libcamera::ipa::rkisp1 {
* \var IPAActiveState::agc.automatic.gain
* \brief Automatic analogue gain multiplier
*
- * \var IPAActiveState::agc.autoEnabled
- * \brief Manual/automatic AGC state as set by the AeEnable control
+ * \var IPAActiveState::agc.autoExposureEnabled
+ * \brief Manual/automatic AGC state (exposure) as set by the ExposureTimeMode control
+ *
+ * \var IPAActiveState::agc.autoGainEnabled
+ * \brief Manual/automatic AGC state (gain) as set by the AnalogueGainMode control
*
* \var IPAActiveState::agc.constraintMode
* \brief Constraint mode as set by the AeConstraintMode control
@@ -289,8 +292,11 @@ namespace libcamera::ipa::rkisp1 {
*
* The gain should be adapted to the sensor specific gain code before applying.
*
- * \var IPAFrameContext::agc.autoEnabled
- * \brief Manual/automatic AGC state as set by the AeEnable control
+ * \var IPAFrameContext::agc.autoExposureEnabled
+ * \brief Manual/automatic AGC state (exposure) as set by the ExposureTimeMode control
+ *
+ * \var IPAFrameContext::agc.autoGainEnabled
+ * \brief Manual/automatic AGC state (gain) as set by the AnalogueGainMode control
*
* \var IPAFrameContext::agc.constraintMode
* \brief Constraint mode as set by the AeConstraintMode control
@@ -306,6 +312,16 @@ namespace libcamera::ipa::rkisp1 {
*
* \var IPAFrameContext::agc.updateMetering
* \brief Indicate if new ISP AGC metering parameters need to be applied
+ *
+ * \var IPAFrameContext::agc.autoExposureModeChange
+ * \brief Indicate if autoExposureEnabled has changed from true in the previous
+ * frame to false in the current frame, and no manual exposure value has been
+ * supplied in the current frame.
+ *
+ * \var IPAFrameContext::agc.autoGainModeChange
+ * \brief Indicate if autoGainEnabled has changed from true in the previous
+ * frame to false in the current frame, and no manual gain value has been
+ * supplied in the current frame.
*/
/**
diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h
index b83c1822..5d5b79fa 100644
--- a/src/ipa/rkisp1/ipa_context.h
+++ b/src/ipa/rkisp1/ipa_context.h
@@ -79,7 +79,8 @@ struct IPAActiveState {
double gain;
} automatic;
- bool autoEnabled;
+ bool autoExposureEnabled;
+ bool autoGainEnabled;
controls::AeConstraintModeEnum constraintMode;
controls::AeExposureModeEnum exposureMode;
controls::AeMeteringModeEnum meteringMode;
@@ -124,12 +125,15 @@ struct IPAFrameContext : public FrameContext {
struct {
uint32_t exposure;
double gain;
- bool autoEnabled;
+ bool autoExposureEnabled;
+ bool autoGainEnabled;
controls::AeConstraintModeEnum constraintMode;
controls::AeExposureModeEnum exposureMode;
controls::AeMeteringModeEnum meteringMode;
utils::Duration maxFrameDuration;
bool updateMetering;
+ bool autoExposureModeChange;
+ bool autoGainModeChange;
} agc;
struct {
diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp
index 6ff1e22b..bd3c2200 100644
--- a/src/ipa/rpi/common/ipa_base.cpp
+++ b/src/ipa/rpi/common/ipa_base.cpp
@@ -55,8 +55,17 @@ constexpr Duration controllerMinFrameDuration = 1.0s / 30.0;
/* List of controls handled by the Raspberry Pi IPA */
const ControlInfoMap::Map ipaControls{
- { &controls::AeEnable, ControlInfo(false, true) },
+ /* \todo Move this to the Camera class */
+ { &controls::AeEnable, ControlInfo(false, true, true) },
+ { &controls::ExposureTimeMode,
+ ControlInfo(static_cast<int32_t>(controls::ExposureTimeModeAuto),
+ static_cast<int32_t>(controls::ExposureTimeModeManual),
+ static_cast<int32_t>(controls::ExposureTimeModeAuto)) },
{ &controls::ExposureTime, ControlInfo(0, 66666) },
+ { &controls::AnalogueGainMode,
+ ControlInfo(static_cast<int32_t>(controls::AnalogueGainModeAuto),
+ static_cast<int32_t>(controls::AnalogueGainModeManual),
+ static_cast<int32_t>(controls::AnalogueGainModeAuto)) },
{ &controls::AnalogueGain, ControlInfo(1.0f, 16.0f) },
{ &controls::AeMeteringMode, ControlInfo(controls::AeMeteringModeValues) },
{ &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) },
@@ -749,6 +758,42 @@ void IpaBase::applyControls(const ControlList &controls)
af->setMode(mode->second);
}
+ /*
+ * Because some AE controls are mode-specific, handle the AE-related
+ * mode changes first.
+ */
+ const auto analogueGainMode = controls.get(controls::AnalogueGainMode);
+ const auto exposureTimeMode = controls.get(controls::ExposureTimeMode);
+
+ if (analogueGainMode || exposureTimeMode) {
+ RPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(
+ controller_.getAlgorithm("agc"));
+ if (agc) {
+ if (analogueGainMode) {
+ if (*analogueGainMode == controls::AnalogueGainModeManual)
+ agc->disableAutoGain();
+ else
+ agc->enableAutoGain();
+
+ libcameraMetadata_.set(controls::AnalogueGainMode,
+ *analogueGainMode);
+ }
+
+ if (exposureTimeMode) {
+ if (*exposureTimeMode == controls::ExposureTimeModeManual)
+ agc->disableAutoExposure();
+ else
+ agc->enableAutoExposure();
+
+ libcameraMetadata_.set(controls::ExposureTimeMode,
+ *exposureTimeMode);
+ }
+ } else {
+ LOG(IPARPI, Warning)
+ << "Could not set AnalogueGainMode or ExposureTimeMode - no AGC algorithm";
+ }
+ }
+
/* Iterate over controls */
for (auto const &ctrl : controls) {
LOG(IPARPI, Debug) << "Request ctrl: "
@@ -756,23 +801,8 @@ void IpaBase::applyControls(const ControlList &controls)
<< " = " << ctrl.second.toString();
switch (ctrl.first) {
- case controls::AE_ENABLE: {
- RPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(
- controller_.getAlgorithm("agc"));
- if (!agc) {
- LOG(IPARPI, Warning)
- << "Could not set AE_ENABLE - no AGC algorithm";
- break;
- }
-
- if (ctrl.second.get<bool>() == false)
- agc->disableAuto();
- else
- agc->enableAuto();
-
- libcameraMetadata_.set(controls::AeEnable, ctrl.second.get<bool>());
- break;
- }
+ case controls::EXPOSURE_TIME_MODE:
+ break; /* We already handled this one above */
case controls::EXPOSURE_TIME: {
RPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(
@@ -783,6 +813,13 @@ void IpaBase::applyControls(const ControlList &controls)
break;
}
+ /*
+ * Ignore manual exposure time when the auto exposure
+ * algorithm is running.
+ */
+ if (agc->autoExposureEnabled())
+ break;
+
/* The control provides units of microseconds. */
agc->setFixedExposureTime(0, ctrl.second.get<int32_t>() * 1.0us);
@@ -790,6 +827,9 @@ void IpaBase::applyControls(const ControlList &controls)
break;
}
+ case controls::ANALOGUE_GAIN_MODE:
+ break; /* We already handled this one above */
+
case controls::ANALOGUE_GAIN: {
RPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(
controller_.getAlgorithm("agc"));
@@ -799,6 +839,13 @@ void IpaBase::applyControls(const ControlList &controls)
break;
}
+ /*
+ * Ignore manual analogue gain value when the auto gain
+ * algorithm is running.
+ */
+ if (agc->autoGainEnabled())
+ break;
+
agc->setFixedAnalogueGain(0, ctrl.second.get<float>());
libcameraMetadata_.set(controls::AnalogueGain,
@@ -855,6 +902,13 @@ void IpaBase::applyControls(const ControlList &controls)
break;
}
+ /*
+ * Ignore AE_EXPOSURE_MODE if the shutter or the gain
+ * are in auto mode.
+ */
+ if (agc->autoExposureEnabled() || agc->autoGainEnabled())
+ break;
+
int32_t idx = ctrl.second.get<int32_t>();
if (ExposureModeTable.count(idx)) {
agc->setExposureMode(ExposureModeTable.at(idx));
@@ -1334,9 +1388,19 @@ void IpaBase::reportMetadata(unsigned int ipaContext)
}
AgcPrepareStatus *agcPrepareStatus = rpiMetadata.getLocked<AgcPrepareStatus>("agc.prepare_status");
- if (agcPrepareStatus) {
- libcameraMetadata_.set(controls::AeLocked, agcPrepareStatus->locked);
+ if (agcPrepareStatus)
libcameraMetadata_.set(controls::DigitalGain, agcPrepareStatus->digitalGain);
+
+ RPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(
+ controller_.getAlgorithm("agc"));
+ if (agc) {
+ if (!agc->autoExposureEnabled() && !agc->autoGainEnabled())
+ libcameraMetadata_.set(controls::AeState, controls::AeStateIdle);
+ else if (agcPrepareStatus)
+ libcameraMetadata_.set(controls::AeState,
+ agcPrepareStatus->locked
+ ? controls::AeStateConverged
+ : controls::AeStateSearching);
}
LuxStatus *luxStatus = rpiMetadata.getLocked<LuxStatus>("lux.status");
diff --git a/src/ipa/rpi/controller/agc_algorithm.h b/src/ipa/rpi/controller/agc_algorithm.h
index c9782857..fdaa10e6 100644
--- a/src/ipa/rpi/controller/agc_algorithm.h
+++ b/src/ipa/rpi/controller/agc_algorithm.h
@@ -30,8 +30,12 @@ public:
virtual void setMeteringMode(std::string const &meteringModeName) = 0;
virtual void setExposureMode(std::string const &exposureModeName) = 0;
virtual void setConstraintMode(std::string const &contraintModeName) = 0;
- virtual void enableAuto() = 0;
- virtual void disableAuto() = 0;
+ virtual void enableAutoExposure() = 0;
+ virtual void disableAutoExposure() = 0;
+ virtual bool autoExposureEnabled() const = 0;
+ virtual void enableAutoGain() = 0;
+ virtual void disableAutoGain() = 0;
+ virtual bool autoGainEnabled() const = 0;
virtual void setActiveChannels(const std::vector<unsigned int> &activeChannels) = 0;
};
diff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp
index c48fdf15..02bfdb4a 100644
--- a/src/ipa/rpi/controller/rpi/agc.cpp
+++ b/src/ipa/rpi/controller/rpi/agc.cpp
@@ -74,22 +74,62 @@ int Agc::checkChannel(unsigned int channelIndex) const
return 0;
}
-void Agc::disableAuto()
+void Agc::disableAutoExposure()
{
- LOG(RPiAgc, Debug) << "disableAuto";
+ LOG(RPiAgc, Debug) << "disableAutoExposure";
/* All channels are enabled/disabled together. */
for (auto &data : channelData_)
- data.channel.disableAuto();
+ data.channel.disableAutoExposure();
}
-void Agc::enableAuto()
+void Agc::enableAutoExposure()
{
- LOG(RPiAgc, Debug) << "enableAuto";
+ LOG(RPiAgc, Debug) << "enableAutoExposure";
/* All channels are enabled/disabled together. */
for (auto &data : channelData_)
- data.channel.enableAuto();
+ data.channel.enableAutoExposure();
+}
+
+bool Agc::autoExposureEnabled() const
+{
+ LOG(RPiAgc, Debug) << "autoExposureEnabled";
+
+ /*
+ * We always have at least one channel, and since all channels are
+ * enabled and disabled together we can simply check the first one.
+ */
+ return channelData_[0].channel.autoExposureEnabled();
+}
+
+void Agc::disableAutoGain()
+{
+ LOG(RPiAgc, Debug) << "disableAutoGain";
+
+ /* All channels are enabled/disabled together. */
+ for (auto &data : channelData_)
+ data.channel.disableAutoGain();
+}
+
+void Agc::enableAutoGain()
+{
+ LOG(RPiAgc, Debug) << "enableAutoGain";
+
+ /* All channels are enabled/disabled together. */
+ for (auto &data : channelData_)
+ data.channel.enableAutoGain();
+}
+
+bool Agc::autoGainEnabled() const
+{
+ LOG(RPiAgc, Debug) << "autoGainEnabled";
+
+ /*
+ * We always have at least one channel, and since all channels are
+ * enabled and disabled together we can simply check the first one.
+ */
+ return channelData_[0].channel.autoGainEnabled();
}
unsigned int Agc::getConvergenceFrames() const
diff --git a/src/ipa/rpi/controller/rpi/agc.h b/src/ipa/rpi/controller/rpi/agc.h
index 3aca000b..c3a940bf 100644
--- a/src/ipa/rpi/controller/rpi/agc.h
+++ b/src/ipa/rpi/controller/rpi/agc.h
@@ -40,8 +40,12 @@ public:
void setMeteringMode(std::string const &meteringModeName) override;
void setExposureMode(std::string const &exposureModeName) override;
void setConstraintMode(std::string const &contraintModeName) override;
- void enableAuto() override;
- void disableAuto() override;
+ void enableAutoExposure() override;
+ void disableAutoExposure() override;
+ bool autoExposureEnabled() const override;
+ void enableAutoGain() override;
+ void disableAutoGain() override;
+ bool autoGainEnabled() const override;
void switchMode(CameraMode const &cameraMode, Metadata *metadata) override;
void prepare(Metadata *imageMetadata) override;
void process(StatisticsPtr &stats, Metadata *imageMetadata) override;
diff --git a/src/ipa/rpi/controller/rpi/agc_channel.cpp b/src/ipa/rpi/controller/rpi/agc_channel.cpp
index 79c45973..e79184b7 100644
--- a/src/ipa/rpi/controller/rpi/agc_channel.cpp
+++ b/src/ipa/rpi/controller/rpi/agc_channel.cpp
@@ -319,18 +319,36 @@ int AgcChannel::read(const libcamera::YamlObject &params,
return 0;
}
-void AgcChannel::disableAuto()
+void AgcChannel::disableAutoExposure()
{
fixedExposureTime_ = status_.exposureTime;
- fixedAnalogueGain_ = status_.analogueGain;
}
-void AgcChannel::enableAuto()
+void AgcChannel::enableAutoExposure()
{
fixedExposureTime_ = 0s;
+}
+
+bool AgcChannel::autoExposureEnabled() const
+{
+ return fixedExposureTime_ == 0s;
+}
+
+void AgcChannel::disableAutoGain()
+{
+ fixedAnalogueGain_ = status_.analogueGain;
+}
+
+void AgcChannel::enableAutoGain()
+{
fixedAnalogueGain_ = 0;
}
+bool AgcChannel::autoGainEnabled() const
+{
+ return fixedAnalogueGain_ == 0;
+}
+
unsigned int AgcChannel::getConvergenceFrames() const
{
/*
diff --git a/src/ipa/rpi/controller/rpi/agc_channel.h b/src/ipa/rpi/controller/rpi/agc_channel.h
index 734e5efd..fa697e6f 100644
--- a/src/ipa/rpi/controller/rpi/agc_channel.h
+++ b/src/ipa/rpi/controller/rpi/agc_channel.h
@@ -96,8 +96,12 @@ public:
void setMeteringMode(std::string const &meteringModeName);
void setExposureMode(std::string const &exposureModeName);
void setConstraintMode(std::string const &contraintModeName);
- void enableAuto();
- void disableAuto();
+ void enableAutoExposure();
+ void disableAutoExposure();
+ bool autoExposureEnabled() const;
+ void enableAutoGain();
+ void disableAutoGain();
+ bool autoGainEnabled() const;
void switchMode(CameraMode const &cameraMode, Metadata *metadata);
void prepare(Metadata *imageMetadata);
void process(StatisticsPtr &stats, DeviceStatus const &deviceStatus, Metadata *imageMetadata,
diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp
index f6322fe3..319bfda9 100644
--- a/src/libcamera/base/thread.cpp
+++ b/src/libcamera/base/thread.cpp
@@ -257,6 +257,8 @@ void Thread::start()
data_->exit_.store(false, std::memory_order_relaxed);
thread_ = std::thread(&Thread::startThread, this);
+
+ setThreadAffinityInternal();
}
void Thread::startThread()
@@ -284,8 +286,6 @@ void Thread::startThread()
data_->tid_ = syscall(SYS_gettid);
currentThreadData = data_;
- setThreadAffinityInternal();
-
run();
}
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index 69a7ee53..56c58519 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -19,6 +19,7 @@
#include <libcamera/base/thread.h>
#include <libcamera/color_space.h>
+#include <libcamera/control_ids.h>
#include <libcamera/framebuffer_allocator.h>
#include <libcamera/request.h>
#include <libcamera/stream.h>
@@ -1325,6 +1326,25 @@ int Camera::queueRequest(Request *request)
}
}
+ /* Pre-process AeEnable. */
+ ControlList &controls = request->controls();
+ const auto &aeEnable = controls.get(controls::AeEnable);
+ if (aeEnable) {
+ if (_d()->controlInfo_.count(controls::AnalogueGainMode.id()) &&
+ !controls.contains(controls::AnalogueGainMode.id())) {
+ controls.set(controls::AnalogueGainMode,
+ *aeEnable ? controls::AnalogueGainModeAuto
+ : controls::AnalogueGainModeManual);
+ }
+
+ if (_d()->controlInfo_.count(controls::ExposureTimeMode.id()) &&
+ !controls.contains(controls::ExposureTimeMode.id())) {
+ controls.set(controls::ExposureTimeMode,
+ *aeEnable ? controls::ExposureTimeModeAuto
+ : controls::ExposureTimeModeManual);
+ }
+ }
+
d->pipe_->invokeMethod(&PipelineHandler::queueRequest,
ConnectionTypeQueued, request);
diff --git a/src/libcamera/control_ids_core.yaml b/src/libcamera/control_ids_core.yaml
index 1dfaee0c..aa744864 100644
--- a/src/libcamera/control_ids_core.yaml
+++ b/src/libcamera/control_ids_core.yaml
@@ -10,23 +10,82 @@ vendor: libcamera
controls:
- AeEnable:
type: bool
- direction: inout
+ direction: in
description: |
- Enable or disable the AE.
+ Enable or disable the AEGC algorithm. When this control is set to true,
+ both ExposureTimeMode and AnalogueGainMode are set to auto, and if this
+ control is set to false then both are set to manual.
- \sa ExposureTime AnalogueGain
+ If ExposureTimeMode or AnalogueGainMode are also set in the same
+ request as AeEnable, then the modes supplied by ExposureTimeMode or
+ AnalogueGainMode will take precedence.
- - AeLocked:
- type: bool
+ \sa ExposureTimeMode AnalogueGainMode
+
+ - AeState:
+ type: int32_t
direction: out
description: |
- Report the lock status of a running AE algorithm.
+ Report the AEGC algorithm state.
- If the AE algorithm is locked the value shall be set to true, if it's
- converging it shall be set to false. If the AE algorithm is not
- running the control shall not be present in the metadata control list.
+ The AEGC algorithm computes the exposure time and the analogue gain
+ to be applied to the image sensor.
+
+ The AEGC algorithm behaviour is controlled by the ExposureTimeMode and
+ AnalogueGainMode controls, which allow applications to decide how
+ the exposure time and gain are computed, in Auto or Manual mode,
+ independently from one another.
+
+ The AeState control reports the AEGC algorithm state through a single
+ value and describes it as a single computation block which computes
+ both the exposure time and the analogue gain values.
+
+ When both the exposure time and analogue gain values are configured to
+ be in Manual mode, the AEGC algorithm is quiescent and does not actively
+ compute any value and the AeState control will report AeStateIdle.
+
+ When at least the exposure time or analogue gain are configured to be
+ computed by the AEGC algorithm, the AeState control will report if the
+ algorithm has converged to stable values for all of the controls set
+ to be computed in Auto mode.
+
+ \sa AnalogueGainMode
+ \sa ExposureTimeMode
+
+ enum:
+ - name: AeStateIdle
+ value: 0
+ description: |
+ The AEGC algorithm is inactive.
+
+ This state is returned when both AnalogueGainMode and
+ ExposureTimeMode are set to Manual and the algorithm is not
+ actively computing any value.
+ - name: AeStateSearching
+ value: 1
+ description: |
+ The AEGC algorithm is actively computing new values, for either the
+ exposure time or the analogue gain, but has not converged to a
+ stable result yet.
+
+ This state is returned if at least one of AnalogueGainMode or
+ ExposureTimeMode is auto and the algorithm hasn't converged yet.
+
+ The AEGC algorithm converges once stable values are computed for
+ all of the controls set to be computed in Auto mode. Once the
+ algorithm converges the state is moved to AeStateConverged.
+ - name: AeStateConverged
+ value: 2
+ description: |
+ The AEGC algorithm has converged.
- \sa AeEnable
+ This state is returned if at least one of AnalogueGainMode or
+ ExposureTimeMode is Auto, and the AEGC algorithm has converged to a
+ stable value.
+
+ If the measurements move too far away from the convergence point
+ then the AEGC algorithm might start adjusting again, in which case
+ the state is moved to AeStateSearching.
# AeMeteringMode needs further attention:
# - Auto-generate max enum value.
@@ -109,6 +168,13 @@ controls:
The exposure modes specify how the desired total exposure is divided
between the exposure time and the sensor's analogue gain. They are
platform specific, and not all exposure modes may be supported.
+
+ When one of AnalogueGainMode or ExposureTimeMode is set to Manual,
+ the fixed values will override any choices made by AeExposureMode.
+
+ \sa AnalogueGainMode
+ \sa ExposureTimeMode
+
enum:
- name: ExposureNormal
value: 0
@@ -130,13 +196,15 @@ controls:
Specify an Exposure Value (EV) parameter.
The EV parameter will only be applied if the AE algorithm is currently
- enabled.
+ enabled, that is, at least one of AnalogueGainMode and ExposureTimeMode
+ are in Auto mode.
By convention EV adjusts the exposure as log2. For example
EV = [-2, -1, -0.5, 0, 0.5, 1, 2] results in an exposure adjustment
of [1/4x, 1/2x, 1/sqrt(2)x, 1x, sqrt(2)x, 2x, 4x].
- \sa AeEnable
+ \sa AnalogueGainMode
+ \sa ExposureTimeMode
- ExposureTime:
type: int32_t
@@ -146,17 +214,108 @@ controls:
This value is specified in micro-seconds.
- Setting this value means that it is now fixed and the AE algorithm may
- not change it. Setting it back to zero returns it to the control of the
- AE algorithm.
+ This control will only take effect if ExposureTimeMode is Manual. If
+ this control is set when ExposureTimeMode is Auto, the value will be
+ ignored and will not be retained.
+
+ When reported in metadata, this control indicates what exposure time
+ was used for the current frame, regardless of ExposureTimeMode.
+ ExposureTimeMode will indicate the source of the exposure time value,
+ whether it came from the AE algorithm or not.
+
+ \sa AnalogueGain
+ \sa ExposureTimeMode
+
+ - ExposureTimeMode:
+ type: int32_t
+ direction: inout
+ description: |
+ Controls the source of the exposure time that is applied to the image
+ sensor.
+
+ When set to Auto, the AE algorithm computes the exposure time and
+ configures the image sensor accordingly. When set to Manual, the value
+ of the ExposureTime control is used.
+
+ When transitioning from Auto to Manual mode and no ExposureTime control
+ is provided by the application, the last value computed by the AE
+ algorithm when the mode was Auto will be used. If the ExposureTimeMode
+ was never set to Auto (either because the camera started in Manual mode,
+ or Auto is not supported by the camera), the camera should use a
+ best-effort default value.
- \sa AnalogueGain AeEnable
+ If ExposureTimeModeManual is supported, the ExposureTime control must
+ also be supported.
- \todo Document the interactions between AeEnable and setting a fixed
- value for this control. Consider interactions with other AE features,
- such as aperture and aperture/shutter priority mode, and decide if
- control of which features should be automatically adjusted shouldn't
- better be handled through a separate AE mode control.
+ Cameras that support manual control of the sensor shall support manual
+ mode for both ExposureTimeMode and AnalogueGainMode, and shall expose
+ the ExposureTime and AnalogueGain controls. If the camera also has an
+ AEGC implementation, both ExposureTimeMode and AnalogueGainMode shall
+ support both manual and auto mode. If auto mode is available, it shall
+ be the default mode. These rules do not apply to black box cameras
+ such as UVC cameras, where the available gain and exposure modes are
+ completely dependent on what the device exposes.
+
+ \par Flickerless exposure mode transitions
+
+ Applications that wish to transition from ExposureTimeModeAuto to direct
+ control of the exposure time without causing extra flicker can do so by
+ selecting an ExposureTime value as close as possible to the last value
+ computed by the auto exposure algorithm in order to avoid any visible
+ flickering.
+
+ To select the correct value to use as ExposureTime value, applications
+ should accommodate the natural delay in applying controls caused by the
+ capture pipeline frame depth.
+
+ When switching to manual exposure mode, applications should not
+ immediately specify an ExposureTime value in the same request where
+ ExposureTimeMode is set to Manual. They should instead wait for the
+ first Request where ExposureTimeMode is reported as
+ ExposureTimeModeManual in the Request metadata, and use the reported
+ ExposureTime to populate the control value in the next Request to be
+ queued to the Camera.
+
+ The implementation of the auto-exposure algorithm should equally try to
+ minimize flickering and when transitioning from manual exposure mode to
+ auto exposure use the last value provided by the application as starting
+ point.
+
+ 1. Start with ExposureTimeMode set to Auto
+
+ 2. Set ExposureTimeMode to Manual
+
+ 3. Wait for the first completed request that has ExposureTimeMode
+ set to Manual
+
+ 4. Copy the value reported in ExposureTime into a new request, and
+ submit it
+
+ 5. Proceed to run manual exposure time as desired
+
+ \sa ExposureTime
+ enum:
+ - name: ExposureTimeModeAuto
+ value: 0
+ description: |
+ The exposure time will be calculated automatically and set by the
+ AE algorithm.
+
+ If ExposureTime is set while this mode is active, it will be
+ ignored, and its value will not be retained.
+
+ When transitioning from Manual to Auto mode, the AEGC should start
+ its adjustments based on the last set manual ExposureTime value.
+ - name: ExposureTimeModeManual
+ value: 1
+ description: |
+ The exposure time will not be updated by the AE algorithm.
+
+ When transitioning from Auto to Manual mode, the last computed
+ exposure value is used until a new value is specified through the
+ ExposureTime control. If an ExposureTime value is specified in the
+ same request where the ExposureTimeMode is changed from Auto to
+ Manual, the provided ExposureTime is applied immediately.
- AnalogueGain:
type: float
@@ -167,17 +326,77 @@ controls:
The value of the control specifies the gain multiplier applied to all
colour channels. This value cannot be lower than 1.0.
- Setting this value means that it is now fixed and the AE algorithm may
- not change it. Setting it back to zero returns it to the control of the
- AE algorithm.
+ This control will only take effect if AnalogueGainMode is Manual. If
+ this control is set when AnalogueGainMode is Auto, the value will be
+ ignored and will not be retained.
+
+ When reported in metadata, this control indicates what analogue gain
+ was used for the current request, regardless of AnalogueGainMode.
+ AnalogueGainMode will indicate the source of the analogue gain value,
+ whether it came from the AEGC algorithm or not.
+
+ \sa ExposureTime
+ \sa AnalogueGainMode
+
+ - AnalogueGainMode:
+ type: int32_t
+ direction: inout
+ description: |
+ Controls the source of the analogue gain that is applied to the image
+ sensor.
+
+ When set to Auto, the AEGC algorithm computes the analogue gain and
+ configures the image sensor accordingly. When set to Manual, the value
+ of the AnalogueGain control is used.
+
+ When transitioning from Auto to Manual mode and no AnalogueGain control
+ is provided by the application, the last value computed by the AEGC
+ algorithm when the mode was Auto will be used. If the AnalogueGainMode
+ was never set to Auto (either because the camera started in Manual mode,
+ or Auto is not supported by the camera), the camera should use a
+ best-effort default value.
+
+ If AnalogueGainModeManual is supported, the AnalogueGain control must
+ also be supported.
+
+ For cameras where we have control over the ISP, both ExposureTimeMode
+ and AnalogueGainMode are expected to support manual mode, and both
+ controls (as well as ExposureTimeMode and AnalogueGain) are expected to
+ be present. If the camera also has an AEGC implementation, both
+ ExposureTimeMode and AnalogueGainMode shall support both manual and
+ auto mode. If auto mode is available, it shall be the default mode.
+ These rules do not apply to black box cameras such as UVC cameras,
+ where the available gain and exposure modes are completely dependent on
+ what the hardware exposes.
+
+ The same procedure described for performing flickerless transitions in
+ the ExposureTimeMode control documentation can be applied to analogue
+ gain.
+
+ \sa ExposureTimeMode
+ \sa AnalogueGain
+ enum:
+ - name: AnalogueGainModeAuto
+ value: 0
+ description: |
+ The analogue gain will be calculated automatically and set by the
+ AEGC algorithm.
+
+ If AnalogueGain is set while this mode is active, it will be
+ ignored, and it will also not be retained.
- \sa ExposureTime AeEnable
+ When transitioning from Manual to Auto mode, the AEGC should start
+ its adjustments based on the last set manual AnalogueGain value.
+ - name: AnalogueGainModeManual
+ value: 1
+ description: |
+ The analogue gain will not be updated by the AEGC algorithm.
- \todo Document the interactions between AeEnable and setting a fixed
- value for this control. Consider interactions with other AE features,
- such as aperture and aperture/shutter priority mode, and decide if
- control of which features should be automatically adjusted shouldn't
- better be handled through a separate AE mode control.
+ When transitioning from Auto to Manual mode, the last computed
+ gain value is used until a new value is specified through the
+ AnalogueGain control. If an AnalogueGain value is specified in the
+ same request where the AnalogueGainMode is changed from Auto to
+ Manual, the provided AnalogueGain is applied immediately.
- AeFlickerMode:
type: int32_t
diff --git a/src/libcamera/control_ids_draft.yaml b/src/libcamera/control_ids_draft.yaml
index 87e4e02d..03309eea 100644
--- a/src/libcamera/control_ids_draft.yaml
+++ b/src/libcamera/control_ids_draft.yaml
@@ -80,36 +80,6 @@ controls:
High quality aberration correction which might reduce the frame
rate.
- - AeState:
- type: int32_t
- direction: out
- description: |
- Control to report the current AE algorithm state. Currently identical to
- ANDROID_CONTROL_AE_STATE.
-
- Current state of the AE algorithm.
- enum:
- - name: AeStateInactive
- value: 0
- description: The AE algorithm is inactive.
- - name: AeStateSearching
- value: 1
- description: The AE algorithm has not converged yet.
- - name: AeStateConverged
- value: 2
- description: The AE algorithm has converged.
- - name: AeStateLocked
- value: 3
- description: The AE algorithm is locked.
- - name: AeStateFlashRequired
- value: 4
- description: The AE algorithm would need a flash for good results
- - name: AeStatePrecapture
- value: 5
- description: |
- The AE algorithm has started a pre-capture metering session.
- \sa AePrecaptureTrigger
-
- AwbState:
type: int32_t
direction: out
diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp
index a014c3b4..d8c62dd6 100644
--- a/src/libcamera/dma_buf_allocator.cpp
+++ b/src/libcamera/dma_buf_allocator.cpp
@@ -325,7 +325,12 @@ DmaSyncer::DmaSyncer(SharedFD fd, SyncType type)
DmaSyncer::~DmaSyncer()
{
- sync(DMA_BUF_SYNC_END);
+ /*
+ * DmaSyncer might be moved and left with an empty SharedFD.
+ * Avoid syncing with an invalid file descriptor in this case.
+ */
+ if (fd_.isValid())
+ sync(DMA_BUF_SYNC_END);
}
void DmaSyncer::sync(uint64_t step)
diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp
index 85004737..25f772a4 100644
--- a/src/libcamera/ipa_proxy.cpp
+++ b/src/libcamera/ipa_proxy.cpp
@@ -98,16 +98,33 @@ IPAProxy::~IPAProxy()
std::string IPAProxy::configurationFile(const std::string &name,
const std::string &fallbackName) const
{
- struct stat statbuf;
- int ret;
-
/*
* The IPA module name can be used as-is to build directory names as it
* has been validated when loading the module.
*/
- std::string ipaName = ipam_->info().name;
+ const std::string ipaName = ipam_->info().name;
+
+ /*
+ * Start with any user override through the module-specific environment
+ * variable. Use the name of the IPA module up to the first '/' to
+ * construct the variable name.
+ */
+ std::string ipaEnvName = ipaName.substr(0, ipaName.find('/'));
+ std::transform(ipaEnvName.begin(), ipaEnvName.end(), ipaEnvName.begin(),
+ [](unsigned char c) { return std::toupper(c); });
+ ipaEnvName = "LIBCAMERA_" + ipaEnvName + "_TUNING_FILE";
- /* Check the environment variable first. */
+ char const *configFromEnv = utils::secure_getenv(ipaEnvName.c_str());
+ if (configFromEnv && *configFromEnv == '\0')
+ return { configFromEnv };
+
+ struct stat statbuf;
+ int ret;
+
+ /*
+ * Check the directory pointed to by the IPA config path environment
+ * variable next.
+ */
const char *confPaths = utils::secure_getenv("LIBCAMERA_IPA_CONFIG_PATH");
if (confPaths) {
for (const auto &dir : utils::split(confPaths, ":")) {
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
index 35c793da..1ac8d8ae 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
@@ -380,18 +380,9 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision)
ipa_->paramsComputed.connect(this, &RkISP1CameraData::paramsComputed);
ipa_->metadataReady.connect(this, &RkISP1CameraData::metadataReady);
- /*
- * The API tuning file is made from the sensor name unless the
- * environment variable overrides it.
- */
- std::string ipaTuningFile;
- char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RKISP1_TUNING_FILE");
- if (!configFromEnv || *configFromEnv == '\0') {
- ipaTuningFile =
- ipa_->configurationFile(sensor_->model() + ".yaml", "uncalibrated.yaml");
- } else {
- ipaTuningFile = std::string(configFromEnv);
- }
+ /* The IPA tuning file is made from the sensor name. */
+ std::string ipaTuningFile =
+ ipa_->configurationFile(sensor_->model() + ".yaml", "uncalibrated.yaml");
IPACameraSensorInfo sensorInfo{};
int ret = sensor_->sensorInfo(&sensorInfo);
diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
index 4b147fdb..1f13e523 100644
--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
@@ -1156,20 +1156,11 @@ int CameraData::loadIPA(ipa::RPi::InitResult *result)
if (!ipa_)
return -ENOENT;
- /*
- * The configuration (tuning file) is made from the sensor name unless
- * the environment variable overrides it.
- */
- std::string configurationFile;
- char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RPI_TUNING_FILE");
- if (!configFromEnv || *configFromEnv == '\0') {
- std::string model = sensor_->model();
- if (isMonoSensor(sensor_))
- model += "_mono";
- configurationFile = ipa_->configurationFile(model + ".json");
- } else {
- configurationFile = std::string(configFromEnv);
- }
+ /* The configuration (tuning file) is made from the sensor name. */
+ std::string model = sensor_->model();
+ if (isMonoSensor(sensor_))
+ model += "_mono";
+ std::string configurationFile = ipa_->configurationFile(model + ".json");
IPASettings settings(configurationFile, sensor_->model());
ipa::RPi::InitParams params;
diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
index 8c2c6baf..7470b562 100644
--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
@@ -298,7 +298,7 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,
cid = V4L2_CID_CONTRAST;
else if (id == controls::Saturation)
cid = V4L2_CID_SATURATION;
- else if (id == controls::AeEnable)
+ else if (id == controls::ExposureTimeMode)
cid = V4L2_CID_EXPOSURE_AUTO;
else if (id == controls::ExposureTime)
cid = V4L2_CID_EXPOSURE_ABSOLUTE;
@@ -647,7 +647,7 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,
id = &controls::Saturation;
break;
case V4L2_CID_EXPOSURE_AUTO:
- id = &controls::AeEnable;
+ id = &controls::ExposureTimeMode;
break;
case V4L2_CID_EXPOSURE_ABSOLUTE:
id = &controls::ExposureTime;
@@ -660,6 +660,7 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,
}
/* Map the control info. */
+ const std::vector<ControlValue> &v4l2Values = v4l2Info.values();
int32_t min = v4l2Info.min().get<int32_t>();
int32_t max = v4l2Info.max().get<int32_t>();
int32_t def = v4l2Info.def().get<int32_t>();
@@ -697,10 +698,52 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,
};
break;
- case V4L2_CID_EXPOSURE_AUTO:
- info = ControlInfo{ false, true, true };
+ case V4L2_CID_EXPOSURE_AUTO: {
+ /*
+ * From the V4L2_CID_EXPOSURE_AUTO documentation:
+ *
+ * ------------------------------------------------------------
+ * V4L2_EXPOSURE_AUTO:
+ * Automatic exposure time, automatic iris aperture.
+ *
+ * V4L2_EXPOSURE_MANUAL:
+ * Manual exposure time, manual iris.
+ *
+ * V4L2_EXPOSURE_SHUTTER_PRIORITY:
+ * Manual exposure time, auto iris.
+ *
+ * V4L2_EXPOSURE_APERTURE_PRIORITY:
+ * Auto exposure time, manual iris.
+ *-------------------------------------------------------------
+ *
+ * ExposureTimeModeAuto = { V4L2_EXPOSURE_AUTO,
+ * V4L2_EXPOSURE_APERTURE_PRIORITY }
+ *
+ *
+ * ExposureTimeModeManual = { V4L2_EXPOSURE_MANUAL,
+ * V4L2_EXPOSURE_SHUTTER_PRIORITY }
+ */
+ std::array<int32_t, 2> values{};
+
+ auto it = std::find_if(v4l2Values.begin(), v4l2Values.end(),
+ [&](const ControlValue &val) {
+ return (val.get<int32_t>() == V4L2_EXPOSURE_APERTURE_PRIORITY ||
+ val.get<int32_t>() == V4L2_EXPOSURE_AUTO) ? true : false;
+ });
+ if (it != v4l2Values.end())
+ values.back() = static_cast<int32_t>(controls::ExposureTimeModeAuto);
+
+ it = std::find_if(v4l2Values.begin(), v4l2Values.end(),
+ [&](const ControlValue &val) {
+ return (val.get<int32_t>() == V4L2_EXPOSURE_SHUTTER_PRIORITY ||
+ val.get<int32_t>() == V4L2_EXPOSURE_MANUAL) ? true : false;
+ });
+ if (it != v4l2Values.end())
+ values.back() = static_cast<int32_t>(controls::ExposureTimeModeManual);
+
+ info = ControlInfo{Span<int32_t>{values}, values[0]};
break;
-
+ }
case V4L2_CID_EXPOSURE_ABSOLUTE:
/*
* ExposureTime is in units of 1 µs, and UVC expects
diff --git a/src/libcamera/pipeline/virtual/data/meson.build b/src/libcamera/pipeline/virtual/data/meson.build
new file mode 100644
index 00000000..ce63f9a2
--- /dev/null
+++ b/src/libcamera/pipeline/virtual/data/meson.build
@@ -0,0 +1,4 @@
+install_data('virtual.yaml',
+ install_dir : pipeline_data_dir / 'virtual',
+ install_tag : 'runtime',
+ rename: 'virtual.yaml.example')
diff --git a/src/libcamera/pipeline/virtual/meson.build b/src/libcamera/pipeline/virtual/meson.build
index 4786fe2e..c8434593 100644
--- a/src/libcamera/pipeline/virtual/meson.build
+++ b/src/libcamera/pipeline/virtual/meson.build
@@ -11,3 +11,5 @@ libjpeg = dependency('libjpeg', required : true)
libcamera_deps += [libyuv_dep]
libcamera_deps += [libjpeg]
+
+subdir('data')
diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp
index e692a543..469f5655 100644
--- a/src/libcamera/pipeline/virtual/virtual.cpp
+++ b/src/libcamera/pipeline/virtual/virtual.cpp
@@ -329,10 +329,17 @@ bool PipelineHandlerVirtual::match([[maybe_unused]] DeviceEnumerator *enumerator
created_ = true;
- File file(configurationFile("virtual", "virtual.yaml"));
- bool isOpen = file.open(File::OpenModeFlag::ReadOnly);
- if (!isOpen) {
- LOG(Virtual, Error) << "Failed to open config file: " << file.fileName();
+ std::string configFile = configurationFile("virtual", "virtual.yaml", true);
+ if (configFile.empty()) {
+ LOG(Virtual, Debug)
+ << "Configuration file not found, skipping virtual cameras";
+ return false;
+ }
+
+ File file(configFile);
+ if (!file.open(File::OpenModeFlag::ReadOnly)) {
+ LOG(Virtual, Error)
+ << "Failed to open config file `" << file.fileName() << "`";
return false;
}
diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
index caa5c20e..d84dff3c 100644
--- a/src/libcamera/pipeline_handler.cpp
+++ b/src/libcamera/pipeline_handler.cpp
@@ -581,6 +581,7 @@ void PipelineHandler::cancelRequest(Request *request)
* \brief Retrieve the absolute path to a platform configuration file
* \param[in] subdir The pipeline handler specific subdirectory name
* \param[in] name The configuration file name
+ * \param[in] silent Disable error messages
*
* This function locates a named platform configuration file and returns
* its absolute path to the pipeline handler. It searches the following
@@ -596,7 +597,8 @@ void PipelineHandler::cancelRequest(Request *request)
* string if no configuration file can be found
*/
std::string PipelineHandler::configurationFile(const std::string &subdir,
- const std::string &name) const
+ const std::string &name,
+ bool silent) const
{
std::string confPath;
struct stat statbuf;
@@ -626,9 +628,11 @@ std::string PipelineHandler::configurationFile(const std::string &subdir,
if (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG)
return confPath;
- LOG(Pipeline, Error)
- << "Configuration file '" << confPath
- << "' not found for pipeline handler '" << PipelineHandler::name() << "'";
+ if (!silent)
+ LOG(Pipeline, Error)
+ << "Configuration file '" << confPath
+ << "' not found for pipeline handler '"
+ << PipelineHandler::name() << "'";
return std::string();
}
diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp
index 2bea64d9..44baf200 100644
--- a/src/libcamera/software_isp/software_isp.cpp
+++ b/src/libcamera/software_isp/software_isp.cpp
@@ -291,11 +291,13 @@ int SoftwareIsp::queueBuffers(uint32_t frame, FrameBuffer *input,
if (outputs.empty())
return -EINVAL;
+ /* We only support a single stream for now. */
+ if (outputs.size() != 1)
+ return -EINVAL;
+
for (auto [stream, buffer] : outputs) {
if (!buffer)
return -EINVAL;
- if (outputs.size() != 1) /* only single stream atm */
- return -EINVAL;
}
for (auto iter = outputs.begin(); iter != outputs.end(); iter++)
diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
index 7a064d87..33279654 100644
--- a/src/libcamera/v4l2_subdevice.cpp
+++ b/src/libcamera/v4l2_subdevice.cpp
@@ -8,12 +8,18 @@
#include "libcamera/internal/v4l2_subdevice.h"
#include <fcntl.h>
-#include <regex>
#include <sstream>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
+#pragma GCC diagnostic push
+#if defined __SANITIZE_ADDRESS__ && defined __OPTIMIZE__
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+#include <regex>
+#pragma GCC diagnostic pop
+
#include <linux/media-bus-format.h>
#include <linux/v4l2-subdev.h>
diff --git a/src/v4l2/meson.build b/src/v4l2/meson.build
index 58f53bf3..2c040414 100644
--- a/src/v4l2/meson.build
+++ b/src/v4l2/meson.build
@@ -1,12 +1,11 @@
# SPDX-License-Identifier: CC0-1.0
-if not get_option('v4l2')
- v4l2_enabled = false
+v4l2_enabled = get_option('v4l2').allowed()
+
+if not v4l2_enabled
subdir_done()
endif
-v4l2_enabled = true
-
v4l2_compat_sources = files([
'v4l2_camera.cpp',
'v4l2_camera_file.cpp',