ipa: raspberrypi: Introduce version 2.0 format for the camera tuning file
The existing tuning file format (version 1.0) requires the controller algorithms to run in the same order as listed in the JSON structure. The JSON specification does not mandate any such ordering, but the Boost JSON parser would maintain this order. In order to remove this reliance on the parser to provide ordering, introduce a new version 2.0 format for the camera tuning file. In this version, the algorithms are specified in a top level list node ("algorithms"), which does require strict ordering of the elements. A "version" node is added to distinguish between the version 1.0 and 2.0 formats. The absence of the "version" node implies version 1.0. A "target" node is also added to specify the target platform for this configuration. Update the controller to support either version of the tuning file by looking at the version node. CreateAlgorithm member function to now load and configure each algorithm. Additionally, make CreateAlgorithm a private member, it does not get called externally. If a version 1.0 format tuning file is used, throw a warning message indicating it will be soon deprecated. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Naushir Patuck <naush@raspberrypi.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
c1597f9896
commit
2ef6eafb6f
2 changed files with 47 additions and 12 deletions
|
@ -44,26 +44,58 @@ int Controller::read(char const *filename)
|
|||
}
|
||||
|
||||
std::unique_ptr<YamlObject> root = YamlParser::parse(file);
|
||||
double version = (*root)["version"].get<double>(1.0);
|
||||
|
||||
for (auto const &[key, value] : root->asDict()) {
|
||||
Algorithm *algo = createAlgorithm(key.c_str());
|
||||
if (algo) {
|
||||
int ret = algo->read(value);
|
||||
if (version < 2.0) {
|
||||
LOG(RPiController, Warning)
|
||||
<< "This format of the tuning file will be deprecated soon!"
|
||||
<< " Please use the convert_tuning.py utility to update to version 2.0.";
|
||||
|
||||
for (auto const &[key, value] : root->asDict()) {
|
||||
int ret = createAlgorithm(key, value);
|
||||
if (ret)
|
||||
return ret;
|
||||
algorithms_.push_back(AlgorithmPtr(algo));
|
||||
} else
|
||||
LOG(RPiController, Warning)
|
||||
<< "No algorithm found for \"" << key << "\"";
|
||||
}
|
||||
} else if (version < 3.0) {
|
||||
if (!root->contains("algorithms")) {
|
||||
LOG(RPiController, Error)
|
||||
<< "Tuning file " << filename
|
||||
<< " does not have an \"algorithms\" list!";
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
for (auto const &rootAlgo : (*root)["algorithms"].asList())
|
||||
for (auto const &[key, value] : rootAlgo.asDict()) {
|
||||
int ret = createAlgorithm(key, value);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
LOG(RPiController, Error)
|
||||
<< "Unrecognised version " << version
|
||||
<< " for the tuning file " << filename;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Algorithm *Controller::createAlgorithm(char const *name)
|
||||
int Controller::createAlgorithm(const std::string &name, const YamlObject ¶ms)
|
||||
{
|
||||
auto it = getAlgorithms().find(std::string(name));
|
||||
return it != getAlgorithms().end() ? (*it->second)(this) : nullptr;
|
||||
auto it = getAlgorithms().find(name);
|
||||
if (it == getAlgorithms().end()) {
|
||||
LOG(RPiController, Warning)
|
||||
<< "No algorithm found for \"" << name << "\"";
|
||||
return 0;
|
||||
}
|
||||
|
||||
Algorithm *algo = (*it->second)(this);
|
||||
int ret = algo->read(params);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
algorithms_.push_back(AlgorithmPtr(algo));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Controller::initialise()
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#include <linux/bcm2835-isp.h>
|
||||
|
||||
#include "libcamera/internal/yaml_parser.h"
|
||||
|
||||
#include "camera_mode.h"
|
||||
#include "device_status.h"
|
||||
#include "metadata.h"
|
||||
|
@ -40,7 +42,6 @@ public:
|
|||
Controller();
|
||||
Controller(char const *jsonFilename);
|
||||
~Controller();
|
||||
Algorithm *createAlgorithm(char const *name);
|
||||
int read(char const *filename);
|
||||
void initialise();
|
||||
void switchMode(CameraMode const &cameraMode, Metadata *metadata);
|
||||
|
@ -50,6 +51,8 @@ public:
|
|||
Algorithm *getAlgorithm(std::string const &name) const;
|
||||
|
||||
protected:
|
||||
int createAlgorithm(const std::string &name, const libcamera::YamlObject ¶ms);
|
||||
|
||||
Metadata globalMetadata_;
|
||||
std::vector<AlgorithmPtr> algorithms_;
|
||||
bool switchModeCalled_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue