[v2,3/4] ipa: rpi: controller: Ignore algorithms that are not enabled
diff mbox series

Message ID 20251211142824.26635-4-david.plowman@raspberrypi.com
State Superseded
Headers show
Series
  • Raspberry Pi AWB using neural networks
Related show

Commit Message

David Plowman Dec. 11, 2025, 2:25 p.m. UTC
From: Peter Bailey <peter.bailey@raspberrypi.com>

Algorithms may now contain an "enabled" field which can be set to
false to disable it and prevent it from being loaded. If not present,
algorithms are treated as enabled by default for backwards
compatability.

We additionally prevent duplicate versions of the same algorithm type
(such as AWB) from loading, and flag an error. This will prevent
undefined behaviour if (for example) two distinct AWB algorithms are
trying to run simultaneously.

Signed-off-by: Peter Bailey <peter.bailey@raspberrypi.com>
---
 src/ipa/rpi/controller/controller.cpp | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Patch
diff mbox series

diff --git a/src/ipa/rpi/controller/controller.cpp b/src/ipa/rpi/controller/controller.cpp
index df45dcd3..88de6f36 100644
--- a/src/ipa/rpi/controller/controller.cpp
+++ b/src/ipa/rpi/controller/controller.cpp
@@ -145,6 +145,14 @@  int Controller::read(char const *filename)
 
 int Controller::createAlgorithm(const std::string &name, const YamlObject &params)
 {
+	/* Any algorithm may be disabled by setting "enabled" to false. */
+	bool enabled = params["enabled"].get<bool>(true);
+	LOG(RPiController, Debug)
+		<< "Algorithm " << name << ": "
+		<< (enabled ? "enabled" : "disabled");
+	if (!enabled)
+		return 0;
+
 	auto it = getAlgorithms().find(name);
 	if (it == getAlgorithms().end()) {
 		LOG(RPiController, Warning)
@@ -152,6 +160,16 @@  int Controller::createAlgorithm(const std::string &name, const YamlObject &param
 		return 0;
 	}
 
+	/* Do not allow duplicate versions of algorithms (e.g. AWB) to run. */
+	size_t pos = name.find_last_of('.');
+	std::string const &algoType =
+		pos == std::string::npos ? name : name.substr(pos + 1);
+	if (getAlgorithm(algoType)) {
+		LOG(RPiController, Error)
+			<< "Algorithm type '" << algoType << "' already exists";
+		return -1;
+	}
+
 	Algorithm *algo = (*it->second)(this);
 	int ret = algo->read(params);
 	if (ret)