<div dir="ltr"><div dir="ltr">Hi David,<div><br></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 16 Nov 2020 at 16:49, David Plowman <<a href="mailto:david.plowman@raspberrypi.com">david.plowman@raspberrypi.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Replace Raspberry Pi debug with libcamera debug.<br>
<br>
Signed-off-by: David Plowman <<a href="mailto:david.plowman@raspberrypi.com" target="_blank">david.plowman@raspberrypi.com</a>><br></blockquote><div><br></div><div>Reviewed-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com">naush@raspberrypi.com</a>></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
 src/ipa/raspberrypi/controller/rpi/agc.cpp | 90 +++++++++++-----------<br>
 1 file changed, 47 insertions(+), 43 deletions(-)<br>
<br>
diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp<br>
index df4d3647..8079345b 100644<br>
--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp<br>
+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp<br>
@@ -9,16 +9,20 @@<br>
<br>
 #include "linux/bcm2835-isp.h"<br>
<br>
+#include "libcamera/internal/log.h"<br>
+<br>
 #include "../awb_status.h"<br>
 #include "../device_status.h"<br>
 #include "../histogram.hpp"<br>
-#include "../logging.hpp"<br>
 #include "../lux_status.h"<br>
 #include "../metadata.hpp"<br>
<br>
 #include "agc.hpp"<br>
<br>
 using namespace RPiController;<br>
+using namespace libcamera;<br>
+<br>
+LOG_DEFINE_CATEGORY(RPiAgc)<br>
<br>
 #define NAME "rpi.agc"<br>
<br>
@@ -128,7 +132,7 @@ static std::string read_constraint_modes(<br>
<br>
 void AgcConfig::Read(boost::property_tree::ptree const &params)<br>
 {<br>
-       RPI_LOG("AgcConfig");<br>
+       LOG(RPiAgc, Debug) << "AgcConfig";<br>
        default_metering_mode = read_metering_modes(<br>
                metering_modes, params.get_child("metering_modes"));<br>
        default_exposure_mode = read_exposure_modes(<br>
@@ -166,7 +170,7 @@ char const *Agc::Name() const<br>
<br>
 void Agc::Read(boost::property_tree::ptree const &params)<br>
 {<br>
-       RPI_LOG("Agc");<br>
+       LOG(RPiAgc, Debug) << "Agc";<br>
        config_.Read(params);<br>
        // Set the config's defaults (which are the first ones it read) as our<br>
        // current modes, until someone changes them.  (they're all known to<br>
@@ -254,15 +258,15 @@ void Agc::Prepare(Metadata *image_metadata)<br>
                                status.digital_gain =<br>
                                        status_.total_exposure_value /<br>
                                        actual_exposure;<br>
-                               RPI_LOG("Want total exposure " << status_.total_exposure_value);<br>
+                               LOG(RPiAgc, Debug) << "Want total exposure " << status_.total_exposure_value;<br>
                                // Never ask for a gain < 1.0, and also impose<br>
                                // some upper limit. Make it customisable?<br>
                                status.digital_gain = std::max(<br>
                                        1.0,<br>
                                        std::min(status.digital_gain, 4.0));<br>
-                               RPI_LOG("Actual exposure " << actual_exposure);<br>
-                               RPI_LOG("Use digital_gain " << status.digital_gain);<br>
-                               RPI_LOG("Effective exposure " << actual_exposure * status.digital_gain);<br>
+                               LOG(RPiAgc, Debug) << "Actual exposure " << actual_exposure;<br>
+                               LOG(RPiAgc, Debug) << "Use digital_gain " << status.digital_gain;<br>
+                               LOG(RPiAgc, Debug) << "Effective exposure " << actual_exposure * status.digital_gain;<br>
                                // Decide whether AEC/AGC has converged.<br>
                                // Insist AGC is steady for MAX_LOCK_COUNT<br>
                                // frames before we say we are "locked".<br>
@@ -285,11 +289,11 @@ void Agc::Prepare(Metadata *image_metadata)<br>
                                                 status.target_exposure_value<br>
                                                 - 1.5 * err)<br>
                                                lock_count_ = lock_count;<br>
-                                       RPI_LOG("Lock count: " << lock_count_);<br>
+                                       LOG(RPiAgc, Debug) << "Lock count: " << lock_count_;<br>
                                }<br>
                        }<br>
                } else<br>
-                       RPI_LOG(Name() << ": no device metadata");<br>
+                       LOG(RPiAgc, Debug) << Name() << ": no device metadata";<br>
                status.locked = lock_count_ >= MAX_LOCK_COUNT;<br>
                //printf("%s\n", status.locked ? "+++++++++" : "-");<br>
                image_metadata->Set("agc.status", status);<br>
@@ -343,9 +347,9 @@ void Agc::housekeepConfig()<br>
                status_.fixed_analogue_gain = fixed_analogue_gain_;<br>
                status_.flicker_period = flicker_period_;<br>
        }<br>
-       RPI_LOG("ev " << status_.ev << " fixed_shutter "<br>
-                     << status_.fixed_shutter << " fixed_analogue_gain "<br>
-                     << status_.fixed_analogue_gain);<br>
+       LOG(RPiAgc, Debug) << "ev " << status_.ev << " fixed_shutter "<br>
+                          << status_.fixed_shutter << " fixed_analogue_gain "<br>
+                          << status_.fixed_analogue_gain;<br>
        // Make sure the "mode" pointers point to the up-to-date things, if<br>
        // they've changed.<br>
        if (strcmp(new_metering_mode_name.c_str(), status_.metering_mode)) {<br>
@@ -376,10 +380,10 @@ void Agc::housekeepConfig()<br>
                copy_string(new_constraint_mode_name, status_.constraint_mode,<br>
                            sizeof(status_.constraint_mode));<br>
        }<br>
-       RPI_LOG("exposure_mode "<br>
-               << new_exposure_mode_name << " constraint_mode "<br>
-               << new_constraint_mode_name << " metering_mode "<br>
-               << new_metering_mode_name);<br>
+       LOG(RPiAgc, Debug) << "exposure_mode "<br>
+                          << new_exposure_mode_name << " constraint_mode "<br>
+                          << new_constraint_mode_name << " metering_mode "<br>
+                          << new_metering_mode_name;<br>
 }<br>
<br>
 void Agc::fetchCurrentExposure(Metadata *image_metadata)<br>
@@ -404,7 +408,7 @@ static double compute_initial_Y(bcm2835_isp_stats *stats, Metadata *image_metada<br>
        struct AwbStatus awb;<br>
        awb.gain_r = awb.gain_g = awb.gain_b = 1.0; // in case no metadata<br>
        if (image_metadata->Get("awb.status", awb) != 0)<br>
-               RPI_WARN("Agc: no AWB status found");<br>
+               LOG(RPiAgc, Warning) << "Agc: no AWB status found";<br>
        double Y_sum = 0, weight_sum = 0;<br>
        for (int i = 0; i < AGC_STATS_SIZE; i++) {<br>
                if (regions[i].counted == 0)<br>
@@ -443,7 +447,7 @@ void Agc::computeGain(bcm2835_isp_stats *statistics, Metadata *image_metadata,<br>
        struct LuxStatus lux = {};<br>
        lux.lux = 400; // default lux level to 400 in case no metadata found<br>
        if (image_metadata->Get("lux.status", lux) != 0)<br>
-               RPI_WARN("Agc: no lux level found");<br>
+               LOG(RPiAgc, Warning) << "Agc: no lux level found";<br>
        Histogram h(statistics->hist[0].g_hist, NUM_HISTOGRAM_BINS);<br>
        double ev_gain = status_.ev * config_.base_ev;<br>
        // The initial gain and target_Y come from some of the regions. After<br>
@@ -454,28 +458,28 @@ void Agc::computeGain(bcm2835_isp_stats *statistics, Metadata *image_metadata,<br>
        double initial_Y = compute_initial_Y(statistics, image_metadata,<br>
                                             metering_mode_->weights);<br>
        gain = std::min(10.0, target_Y / (initial_Y + .001));<br>
-       RPI_LOG("Initially Y " << initial_Y << " target " << target_Y<br>
-                              << " gives gain " << gain);<br>
+       LOG(RPiAgc, Debug) << "Initially Y " << initial_Y << " target " << target_Y<br>
+                          << " gives gain " << gain;<br>
        for (auto &c : *constraint_mode_) {<br>
                double new_target_Y;<br>
                double new_gain =<br>
                        constraint_compute_gain(c, h, lux.lux, ev_gain,<br>
                                                new_target_Y);<br>
-               RPI_LOG("Constraint has target_Y "<br>
-                       << new_target_Y << " giving gain " << new_gain);<br>
+               LOG(RPiAgc, Debug) << "Constraint has target_Y "<br>
+                                  << new_target_Y << " giving gain " << new_gain;<br>
                if (c.bound == AgcConstraint::Bound::LOWER &&<br>
                    new_gain > gain) {<br>
-                       RPI_LOG("Lower bound constraint adopted");<br>
+                       LOG(RPiAgc, Debug) << "Lower bound constraint adopted";<br>
                        gain = new_gain, target_Y = new_target_Y;<br>
                } else if (c.bound == AgcConstraint::Bound::UPPER &&<br>
                           new_gain < gain) {<br>
-                       RPI_LOG("Upper bound constraint adopted");<br>
+                       LOG(RPiAgc, Debug) << "Upper bound constraint adopted";<br>
                        gain = new_gain, target_Y = new_target_Y;<br>
                }<br>
        }<br>
-       RPI_LOG("Final gain " << gain << " (target_Y " << target_Y << " ev "<br>
-                             << status_.ev << " base_ev " << config_.base_ev<br>
-                             << ")");<br>
+       LOG(RPiAgc, Debug) << "Final gain " << gain << " (target_Y " << target_Y << " ev "<br>
+                          << status_.ev << " base_ev " << config_.base_ev<br>
+                          << ")";<br>
 }<br>
<br>
 void Agc::computeTargetExposure(double gain)<br>
@@ -494,7 +498,7 @@ void Agc::computeTargetExposure(double gain)<br>
                         : exposure_mode_->gain.back());<br>
        target_.total_exposure = std::min(target_.total_exposure,<br>
                                          max_total_exposure);<br>
-       RPI_LOG("Target total_exposure " << target_.total_exposure);<br>
+       LOG(RPiAgc, Debug) << "Target total_exposure " << target_.total_exposure;<br>
 }<br>
<br>
 bool Agc::applyDigitalGain(Metadata *image_metadata, double gain,<br>
@@ -509,9 +513,9 @@ bool Agc::applyDigitalGain(Metadata *image_metadata, double gain,<br>
                                           std::min(awb.gain_g, awb.gain_b));<br>
                dg *= std::max(1.0, 1.0 / min_gain);<br>
        } else<br>
-               RPI_WARN("Agc: no AWB status found");<br>
-       RPI_LOG("after AWB, target dg " << dg << " gain " << gain<br>
-                                       << " target_Y " << target_Y);<br>
+               LOG(RPiAgc, Warning) << "Agc: no AWB status found";<br>
+       LOG(RPiAgc, Debug) << "after AWB, target dg " << dg << " gain " << gain<br>
+                          << " target_Y " << target_Y;<br>
        // Finally, if we're trying to reduce exposure but the target_Y is<br>
        // "close" to 1.0, then the gain computed for that constraint will be<br>
        // only slightly less than one, because the measured Y can never be<br>
@@ -523,9 +527,9 @@ bool Agc::applyDigitalGain(Metadata *image_metadata, double gain,<br>
                          gain < sqrt(target_Y);<br>
        if (desaturate)<br>
                dg /= config_.fast_reduce_threshold;<br>
-       RPI_LOG("Digital gain " << dg << " desaturate? " << desaturate);<br>
+       LOG(RPiAgc, Debug) << "Digital gain " << dg << " desaturate? " << desaturate;<br>
        target_.total_exposure_no_dg = target_.total_exposure / dg;<br>
-       RPI_LOG("Target total_exposure_no_dg " << target_.total_exposure_no_dg);<br>
+       LOG(RPiAgc, Debug) << "Target total_exposure_no_dg " << target_.total_exposure_no_dg;<br>
        return desaturate;<br>
 }<br>
<br>
@@ -560,8 +564,8 @@ void Agc::filterExposure(bool desaturate)<br>
            filtered_.total_exposure * config_.fast_reduce_threshold)<br>
                filtered_.total_exposure_no_dg = filtered_.total_exposure *<br>
                                                 config_.fast_reduce_threshold;<br>
-       RPI_LOG("After filtering, total_exposure " << filtered_.total_exposure <<<br>
-               " no dg " << filtered_.total_exposure_no_dg);<br>
+       LOG(RPiAgc, Debug) << "After filtering, total_exposure " << filtered_.total_exposure<br>
+                          << " no dg " << filtered_.total_exposure_no_dg;<br>
 }<br>
<br>
 void Agc::divvyupExposure()<br>
@@ -602,8 +606,8 @@ void Agc::divvyupExposure()<br>
                        }<br>
                }<br>
        }<br>
-       RPI_LOG("Divided up shutter and gain are " << shutter_time << " and "<br>
-                                                  << analogue_gain);<br>
+       LOG(RPiAgc, Debug) << "Divided up shutter and gain are " << shutter_time << " and "<br>
+                          << analogue_gain;<br>
        // Finally adjust shutter time for flicker avoidance (require both<br>
        // shutter and gain not to be fixed).<br>
        if (status_.fixed_shutter == 0.0 &&<br>
@@ -621,8 +625,8 @@ void Agc::divvyupExposure()<br>
                                                 exposure_mode_->gain.back());<br>
                        shutter_time = new_shutter_time;<br>
                }<br>
-               RPI_LOG("After flicker avoidance, shutter "<br>
-                       << shutter_time << " gain " << analogue_gain);<br>
+               LOG(RPiAgc, Debug) << "After flicker avoidance, shutter "<br>
+                                  << shutter_time << " gain " << analogue_gain;<br>
        }<br>
        filtered_.shutter = shutter_time;<br>
        filtered_.analogue_gain = analogue_gain;<br>
@@ -641,10 +645,10 @@ void Agc::writeAndFinish(Metadata *image_metadata, bool desaturate)<br>
        // Write to metadata as well, in case anyone wants to update the camera<br>
        // immediately.<br>
        image_metadata->Set("agc.status", status_);<br>
-       RPI_LOG("Output written, total exposure requested is "<br>
-               << filtered_.total_exposure);<br>
-       RPI_LOG("Camera exposure update: shutter time " << filtered_.shutter <<<br>
-               " analogue gain " << filtered_.analogue_gain);<br>
+       LOG(RPiAgc, Debug) << "Output written, total exposure requested is "<br>
+                          << filtered_.total_exposure;<br>
+       LOG(RPiAgc, Debug) << "Camera exposure update: shutter time " << filtered_.shutter<br>
+                          << " analogue gain " << filtered_.analogue_gain;<br>
 }<br>
<br>
 // Register algorithm with the system.<br>
-- <br>
2.20.1<br>
<br>
_______________________________________________<br>
libcamera-devel mailing list<br>
<a href="mailto:libcamera-devel@lists.libcamera.org" target="_blank">libcamera-devel@lists.libcamera.org</a><br>
<a href="https://lists.libcamera.org/listinfo/libcamera-devel" rel="noreferrer" target="_blank">https://lists.libcamera.org/listinfo/libcamera-devel</a><br>
</blockquote></div></div>