libcamera: pipeline: Move tuning file override handling to IPAProxy
The rkisp1 and rpi pipeline handlers duplicate code to handle the LIBCAMERA_RKISP1_TUNING_FILE and LIBCAMERA_RPI_TUNING_FILE environment variables that override tuning file selection. Move the common code to IPAProxy::configurationFile() to avoid the duplication, and make the feature available to all pipeline handlers with the same behaviour. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>
This commit is contained in:
parent
3e753e2273
commit
f5da05ed03
4 changed files with 32 additions and 33 deletions
|
@ -57,8 +57,8 @@ LIBCAMERA_RPI_CONFIG_FILE
|
||||||
|
|
||||||
Example value: ``/usr/local/share/libcamera/pipeline/rpi/vc4/minimal_mem.yaml``
|
Example value: ``/usr/local/share/libcamera/pipeline/rpi/vc4/minimal_mem.yaml``
|
||||||
|
|
||||||
LIBCAMERA_RPI_TUNING_FILE
|
LIBCAMERA_<NAME>_TUNING_FILE
|
||||||
Define a custom JSON tuning file to use in the Raspberry Pi.
|
Define a custom IPA tuning file to use with the pipeline handler `NAME`.
|
||||||
|
|
||||||
Example value: ``/usr/local/share/libcamera/ipa/rpi/vc4/custom_sensor.json``
|
Example value: ``/usr/local/share/libcamera/ipa/rpi/vc4/custom_sensor.json``
|
||||||
|
|
||||||
|
|
|
@ -98,16 +98,33 @@ IPAProxy::~IPAProxy()
|
||||||
std::string IPAProxy::configurationFile(const std::string &name,
|
std::string IPAProxy::configurationFile(const std::string &name,
|
||||||
const std::string &fallbackName) const
|
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
|
* The IPA module name can be used as-is to build directory names as it
|
||||||
* has been validated when loading the module.
|
* has been validated when loading the module.
|
||||||
*/
|
*/
|
||||||
std::string ipaName = ipam_->info().name;
|
const std::string ipaName = ipam_->info().name;
|
||||||
|
|
||||||
/* Check the environment variable first. */
|
/*
|
||||||
|
* 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";
|
||||||
|
|
||||||
|
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");
|
const char *confPaths = utils::secure_getenv("LIBCAMERA_IPA_CONFIG_PATH");
|
||||||
if (confPaths) {
|
if (confPaths) {
|
||||||
for (const auto &dir : utils::split(confPaths, ":")) {
|
for (const auto &dir : utils::split(confPaths, ":")) {
|
||||||
|
|
|
@ -380,18 +380,9 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision)
|
||||||
ipa_->paramsComputed.connect(this, &RkISP1CameraData::paramsComputed);
|
ipa_->paramsComputed.connect(this, &RkISP1CameraData::paramsComputed);
|
||||||
ipa_->metadataReady.connect(this, &RkISP1CameraData::metadataReady);
|
ipa_->metadataReady.connect(this, &RkISP1CameraData::metadataReady);
|
||||||
|
|
||||||
/*
|
/* The IPA tuning file is made from the sensor name. */
|
||||||
* The API tuning file is made from the sensor name unless the
|
std::string ipaTuningFile =
|
||||||
* environment variable overrides it.
|
ipa_->configurationFile(sensor_->model() + ".yaml", "uncalibrated.yaml");
|
||||||
*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
IPACameraSensorInfo sensorInfo{};
|
IPACameraSensorInfo sensorInfo{};
|
||||||
int ret = sensor_->sensorInfo(&sensorInfo);
|
int ret = sensor_->sensorInfo(&sensorInfo);
|
||||||
|
|
|
@ -1156,20 +1156,11 @@ int CameraData::loadIPA(ipa::RPi::InitResult *result)
|
||||||
if (!ipa_)
|
if (!ipa_)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
/*
|
/* The configuration (tuning file) is made from the sensor name. */
|
||||||
* The configuration (tuning file) is made from the sensor name unless
|
std::string model = sensor_->model();
|
||||||
* the environment variable overrides it.
|
if (isMonoSensor(sensor_))
|
||||||
*/
|
model += "_mono";
|
||||||
std::string configurationFile;
|
std::string configurationFile = ipa_->configurationFile(model + ".json");
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
IPASettings settings(configurationFile, sensor_->model());
|
IPASettings settings(configurationFile, sensor_->model());
|
||||||
ipa::RPi::InitParams params;
|
ipa::RPi::InitParams params;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue