Files
external_libcamera/src/ipa/libipa/module.h
T
Isaac ScottandKieran Bingham 43ab0d487b libipa: module: Allow algorithms to be disabled via the tuning file
It is beneficial to have the option during development to disable and
enable algorithms via the tuning file without having to delete their
entries.

Add support for an optional "enabled" parameter to accomplish this.

Usage example:
version: 1
algorithms:
  - Agc:
      enabled: true
  - Awb:
      enabled: false

This will enable AGC, and disable AWB. If the enabled flag is not
present, the algorithm will be enabled.

Signed-off-by: Isaac Scott <isaac.scott@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[Kieran: Reflow text]
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2025-11-24 17:29:11 +00:00

137 lines
3.0 KiB
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2022, Ideas On Board
*
* IPA module
*/
#pragma once
#include <list>
#include <memory>
#include <string>
#include <vector>
#include <libcamera/base/log.h>
#include <libcamera/base/utils.h>
#include "libcamera/internal/yaml_parser.h"
#include "algorithm.h"
namespace libcamera {
LOG_DECLARE_CATEGORY(IPAModuleAlgo)
namespace ipa {
template<typename _Context, typename _FrameContext, typename _Config,
typename _Params, typename _Stats>
class Module : public Loggable
{
public:
using Context = _Context;
using FrameContext = _FrameContext;
using Config = _Config;
using Params = _Params;
using Stats = _Stats;
virtual ~Module() {}
const std::list<std::unique_ptr<Algorithm<Module>>> &algorithms() const
{
return algorithms_;
}
int createAlgorithms(Context &context, const YamlObject &algorithms)
{
const auto &list = algorithms.asList();
for (const auto &[i, algo] : utils::enumerate(list)) {
if (!algo.isDictionary()) {
LOG(IPAModuleAlgo, Error)
<< "Invalid YAML syntax for algorithm " << i;
algorithms_.clear();
return -EINVAL;
}
int ret = createAlgorithm(context, algo);
if (ret) {
algorithms_.clear();
return ret;
}
}
return 0;
}
static void registerAlgorithm(AlgorithmFactoryBase<Module> *factory)
{
factories().push_back(factory);
}
private:
int createAlgorithm(Context &context, const YamlObject &data)
{
const auto &[name, algoData] = *data.asDict().begin();
/*
* Optionally, algorithms can be disabled via the tuning file
* by including enabled: false as a parameter within the
* algorithm tuning data. This is not an error, so we return 0.
*/
if (!algoData["enabled"].get<bool>(true)) {
LOG(IPAModuleAlgo, Info)
<< "Algorithm '" << name << "' disabled via tuning file";
return 0;
}
std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name);
if (!algo) {
LOG(IPAModuleAlgo, Error)
<< "Algorithm '" << name << "' not found";
return -EINVAL;
}
int ret = algo->init(context, algoData);
if (ret) {
LOG(IPAModuleAlgo, Error)
<< "Algorithm '" << name << "' failed to initialize";
return ret;
}
LOG(IPAModuleAlgo, Debug)
<< "Instantiated algorithm '" << name << "'";
algorithms_.push_back(std::move(algo));
return 0;
}
static std::unique_ptr<Algorithm<Module>> createAlgorithm(const std::string &name)
{
for (const AlgorithmFactoryBase<Module> *factory : factories()) {
if (factory->name() == name)
return factory->create();
}
return nullptr;
}
static std::vector<AlgorithmFactoryBase<Module> *> &factories()
{
/*
* The static factories map is defined inside the function to ensure
* it gets initialized on first use, without any dependency on
* link order.
*/
static std::vector<AlgorithmFactoryBase<Module> *> factories;
return factories;
}
std::list<std::unique_ptr<Algorithm<Module>>> algorithms_;
};
} /* namespace ipa */
} /* namespace libcamera */