From f357b1bf6ea39d8118e90f8a371974d29bd054e3 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 26 Jul 2022 02:36:38 +0300 Subject: ipa: raspberrypi: Return an error code from Algorithm::read() When encountering errors, the Algorithm::read() function either uses LOG(Fatal) or throws exceptions from the boost property_tree functions. To prepare for replacing boost JSON parse with the YamlParser class, give the Algorithm::read() function the ability to return an error code, and propagate it all the way to the IPA module init() function. All algorithm classes return a hardcoded 0 value for now, subsequent commits will change that. Signed-off-by: Laurent Pinchart Reviewed-by: Naushir Patuck Tested-by: Naushir Patuck --- src/ipa/raspberrypi/controller/rpi/agc.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/ipa/raspberrypi/controller/rpi/agc.cpp') diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index 4d916cd3..7d3e1b18 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -30,7 +30,7 @@ LOG_DEFINE_CATEGORY(RPiAgc) static constexpr unsigned int PipelineBits = 13; /* seems to be a 13-bit pipeline */ -void AgcMeteringMode::read(boost::property_tree::ptree const ¶ms) +int AgcMeteringMode::read(boost::property_tree::ptree const ¶ms) { int num = 0; for (auto &p : params.get_child("weights")) { @@ -40,6 +40,7 @@ void AgcMeteringMode::read(boost::property_tree::ptree const ¶ms) } if (num != AgcStatsSize) LOG(RPiAgc, Fatal) << "AgcMeteringMode: insufficient weights"; + return 0; } static std::string @@ -73,7 +74,7 @@ static int readList(std::vector &list, return list.size(); } -void AgcExposureMode::read(boost::property_tree::ptree const ¶ms) +int AgcExposureMode::read(boost::property_tree::ptree const ¶ms) { int numShutters = readList(shutter, params.get_child("shutter")); int numAgs = readList(gain, params.get_child("gain")); @@ -83,6 +84,7 @@ void AgcExposureMode::read(boost::property_tree::ptree const ¶ms) if (numShutters != numAgs) LOG(RPiAgc, Fatal) << "AgcExposureMode: expect same number of exposure and gain entries in exposure profile"; + return 0; } static std::string @@ -100,7 +102,7 @@ readExposureModes(std::map &exposureModes, return first; } -void AgcConstraint::read(boost::property_tree::ptree const ¶ms) +int AgcConstraint::read(boost::property_tree::ptree const ¶ms) { std::string boundString = params.get("bound", ""); transform(boundString.begin(), boundString.end(), @@ -110,7 +112,7 @@ void AgcConstraint::read(boost::property_tree::ptree const ¶ms) bound = boundString == "UPPER" ? Bound::UPPER : Bound::LOWER; qLo = params.get("q_lo"); qHi = params.get("q_hi"); - yTarget.read(params.get_child("y_target")); + return yTarget.read(params.get_child("y_target")); } static AgcConstraintMode @@ -137,13 +139,17 @@ static std::string readConstraintModes(std::map return first; } -void AgcConfig::read(boost::property_tree::ptree const ¶ms) +int AgcConfig::read(boost::property_tree::ptree const ¶ms) { LOG(RPiAgc, Debug) << "AgcConfig"; defaultMeteringMode = readMeteringModes(meteringModes, params.get_child("metering_modes")); defaultExposureMode = readExposureModes(exposureModes, params.get_child("exposure_modes")); defaultConstraintMode = readConstraintModes(constraintModes, params.get_child("constraint_modes")); - yTarget.read(params.get_child("y_target")); + + int ret = yTarget.read(params.get_child("y_target")); + if (ret) + return ret; + speed = params.get("speed", 0.2); startupFrames = params.get("startup_frames", 10); convergenceFrames = params.get("convergence_frames", 6); @@ -152,6 +158,7 @@ void AgcConfig::read(boost::property_tree::ptree const ¶ms) /* Start with quite a low value as ramping up is easier than ramping down. */ defaultExposureTime = params.get("default_exposure_time", 1000) * 1us; defaultAnalogueGain = params.get("default_analogueGain", 1.0); + return 0; } Agc::ExposureValues::ExposureValues() @@ -182,10 +189,14 @@ char const *Agc::name() const return NAME; } -void Agc::read(boost::property_tree::ptree const ¶ms) +int Agc::read(boost::property_tree::ptree const ¶ms) { LOG(RPiAgc, Debug) << "Agc"; - config_.read(params); + + int ret = config_.read(params); + if (ret) + return ret; + /* * Set the config's defaults (which are the first ones it read) as our * current modes, until someone changes them. (they're all known to @@ -200,6 +211,7 @@ void Agc::read(boost::property_tree::ptree const ¶ms) /* Set up the "last shutter/gain" values, in case AGC starts "disabled". */ status_.shutterTime = config_.defaultExposureTime; status_.analogueGain = config_.defaultAnalogueGain; + return 0; } bool Agc::isPaused() const -- cgit v1.2.1