summaryrefslogtreecommitdiff
path: root/src/ipa/raspberrypi/controller/controller.cpp
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2020-05-03 16:48:42 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-05-11 23:54:40 +0300
commit0db2c8dc75e466e7648dc1b95380495c6a126349 (patch)
treefc723a251981ded749c900947a2f510ed56e60da /src/ipa/raspberrypi/controller/controller.cpp
parent740fd1b62f670bd1ad4965ef0866ef5d51bdf947 (diff)
libcamera: ipa: Raspberry Pi IPA
Initial implementation of the Raspberry Pi (BCM2835) libcamera IPA and associated libraries. All code is licensed under the BSD-2-Clause terms. Copyright (c) 2019-2020 Raspberry Pi Trading Ltd. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/ipa/raspberrypi/controller/controller.cpp')
-rw-r--r--src/ipa/raspberrypi/controller/controller.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/ipa/raspberrypi/controller/controller.cpp b/src/ipa/raspberrypi/controller/controller.cpp
new file mode 100644
index 00000000..20dd4c78
--- /dev/null
+++ b/src/ipa/raspberrypi/controller/controller.cpp
@@ -0,0 +1,109 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * Copyright (C) 2019, Raspberry Pi (Trading) Limited
+ *
+ * controller.cpp - ISP controller
+ */
+
+#include "algorithm.hpp"
+#include "controller.hpp"
+
+#include <boost/property_tree/json_parser.hpp>
+#include <boost/property_tree/ptree.hpp>
+
+using namespace RPi;
+
+Controller::Controller()
+ : switch_mode_called_(false) {}
+
+Controller::Controller(char const *json_filename)
+ : switch_mode_called_(false)
+{
+ Read(json_filename);
+ Initialise();
+}
+
+Controller::~Controller() {}
+
+void Controller::Read(char const *filename)
+{
+ RPI_LOG("Controller starting");
+ boost::property_tree::ptree root;
+ boost::property_tree::read_json(filename, root);
+ for (auto const &key_and_value : root) {
+ Algorithm *algo = CreateAlgorithm(key_and_value.first.c_str());
+ if (algo) {
+ algo->Read(key_and_value.second);
+ algorithms_.push_back(AlgorithmPtr(algo));
+ } else
+ RPI_LOG("WARNING: No algorithm found for \""
+ << key_and_value.first << "\"");
+ }
+ RPI_LOG("Controller finished");
+}
+
+Algorithm *Controller::CreateAlgorithm(char const *name)
+{
+ auto it = GetAlgorithms().find(std::string(name));
+ return it != GetAlgorithms().end() ? (*it->second)(this) : nullptr;
+}
+
+void Controller::Initialise()
+{
+ RPI_LOG("Controller starting");
+ for (auto &algo : algorithms_)
+ algo->Initialise();
+ RPI_LOG("Controller finished");
+}
+
+void Controller::SwitchMode(CameraMode const &camera_mode)
+{
+ RPI_LOG("Controller starting");
+ for (auto &algo : algorithms_)
+ algo->SwitchMode(camera_mode);
+ switch_mode_called_ = true;
+ RPI_LOG("Controller finished");
+}
+
+void Controller::Prepare(Metadata *image_metadata)
+{
+ RPI_LOG("Controller::Prepare starting");
+ assert(switch_mode_called_);
+ for (auto &algo : algorithms_)
+ if (!algo->IsPaused())
+ algo->Prepare(image_metadata);
+ RPI_LOG("Controller::Prepare finished");
+}
+
+void Controller::Process(StatisticsPtr stats, Metadata *image_metadata)
+{
+ RPI_LOG("Controller::Process starting");
+ assert(switch_mode_called_);
+ for (auto &algo : algorithms_)
+ if (!algo->IsPaused())
+ algo->Process(stats, image_metadata);
+ RPI_LOG("Controller::Process finished");
+}
+
+Metadata &Controller::GetGlobalMetadata()
+{
+ return global_metadata_;
+}
+
+Algorithm *Controller::GetAlgorithm(std::string const &name) const
+{
+ // The passed name must be the entire algorithm name, or must match the
+ // last part of it with a period (.) just before.
+ size_t name_len = name.length();
+ for (auto &algo : algorithms_) {
+ char const *algo_name = algo->Name();
+ size_t algo_name_len = strlen(algo_name);
+ if (algo_name_len >= name_len &&
+ strcasecmp(name.c_str(),
+ algo_name + algo_name_len - name_len) == 0 &&
+ (name_len == algo_name_len ||
+ algo_name[algo_name_len - name_len - 1] == '.'))
+ return algo.get();
+ }
+ return nullptr;
+}