From patchwork Mon Nov 23 07:37:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10460 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id DF8C3BE08A for ; Mon, 23 Nov 2020 07:38:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 956C86332E; Mon, 23 Nov 2020 08:38:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="nmqyWuDu"; dkim-atps=neutral Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5E78163320 for ; Mon, 23 Nov 2020 08:38:31 +0100 (CET) Received: by mail-wr1-x432.google.com with SMTP id p8so17578082wrx.5 for ; Sun, 22 Nov 2020 23:38:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u46CcECDOCNqmkIJKCIsZpcth4nWLgktLU0Jsd2RAiw=; b=nmqyWuDuca7SE4PrYHEMKsdmHIcof61/h9ocmJtQ18mDEESqNDGut6KNfp6ut90Gkz I7IoZ8ZSPO/XlDNjSE5+CvW1DbJYH8tp4dXuN0VZJghpA0I4Y6aHpfc/tBpEwxIUvD/2 M9SwUtTfFrv65ge4PQA8kGx8o84NgDl9105X9UIxpV1AWlgsPinedELvnbM/Znt2MYua vE/sTMu7G+9XL6EnyxC8yJF7BkOCcr78IjKvGPmRj3Sy8gSE19GgDHkHq7V/QlSJhVPk d7+2YZvA6KugLE8Rbqkhh7tW6wnrh0Gx+bM/tywmnMCfFRZ8+w3pkUC7/0AlIpwNfmoe 7q5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u46CcECDOCNqmkIJKCIsZpcth4nWLgktLU0Jsd2RAiw=; b=iQiVa2nqGt7MuiOBywBnyu/7kcIa/XY1nCjtTe7u4rvW04mi8ZK1jcHLRgyJIFI3/P tOoegL8beE+w0/0TUTUMEzJBE5InJD8BgxtIljAQs9H7+acbl6XFs5gmmOZwx9CDNCth xYQA3Li4eFsLTtxryyDl5nw+1GE6Dw8I3zlnvkE7G0wOJTXyVXcYie8vHFiRdyngHyRS VG6/qX200J4S1HvBDriLbPgosO+vQUrAQ5Td2JCOYFZyqB339Ol7Uq20suhU3kyqZXlw YHYwSqyPs+LpRDgXK3WznTxFJCr8SIJ5D6ox/UjJ1DU3f4x2zZ3EM+AlQAdxaKz5u6TO WW3A== X-Gm-Message-State: AOAM532ZC7UuClSVSFPWlr+sSfzFjbHgb1PaSx1+pW6S01nqFy3G3q1r JPrytgxarJoFuBnjCSOEFuGisu1Ibo/9bKcF X-Google-Smtp-Source: ABdhPJw+18J+5cMXhCSFI+G9rob45GmtnNR/So1sGe1sIcEO/s5voLE6HR/d3bcOQlZHngQ7shZ56g== X-Received: by 2002:adf:814f:: with SMTP id 73mr29115330wrm.174.1606117110646; Sun, 22 Nov 2020 23:38:30 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id h15sm17841822wrw.15.2020.11.22.23.38.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2020 23:38:30 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Nov 2020 07:37:55 +0000 Message-Id: <20201123073804.3125-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201123073804.3125-1-david.plowman@raspberrypi.com> References: <20201123073804.3125-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 01/10] libcamera: ipa: raspberrypi: agc: Use libcamera debug X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace Raspberry Pi debug with libcamera debug. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck --- src/ipa/raspberrypi/controller/rpi/agc.cpp | 90 +++++++++++----------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index df4d3647..8079345b 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -9,16 +9,20 @@ #include "linux/bcm2835-isp.h" +#include "libcamera/internal/log.h" + #include "../awb_status.h" #include "../device_status.h" #include "../histogram.hpp" -#include "../logging.hpp" #include "../lux_status.h" #include "../metadata.hpp" #include "agc.hpp" using namespace RPiController; +using namespace libcamera; + +LOG_DEFINE_CATEGORY(RPiAgc) #define NAME "rpi.agc" @@ -128,7 +132,7 @@ static std::string read_constraint_modes( void AgcConfig::Read(boost::property_tree::ptree const ¶ms) { - RPI_LOG("AgcConfig"); + LOG(RPiAgc, Debug) << "AgcConfig"; default_metering_mode = read_metering_modes( metering_modes, params.get_child("metering_modes")); default_exposure_mode = read_exposure_modes( @@ -166,7 +170,7 @@ char const *Agc::Name() const void Agc::Read(boost::property_tree::ptree const ¶ms) { - RPI_LOG("Agc"); + LOG(RPiAgc, Debug) << "Agc"; config_.Read(params); // 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 @@ -254,15 +258,15 @@ void Agc::Prepare(Metadata *image_metadata) status.digital_gain = status_.total_exposure_value / actual_exposure; - RPI_LOG("Want total exposure " << status_.total_exposure_value); + LOG(RPiAgc, Debug) << "Want total exposure " << status_.total_exposure_value; // Never ask for a gain < 1.0, and also impose // some upper limit. Make it customisable? status.digital_gain = std::max( 1.0, std::min(status.digital_gain, 4.0)); - RPI_LOG("Actual exposure " << actual_exposure); - RPI_LOG("Use digital_gain " << status.digital_gain); - RPI_LOG("Effective exposure " << actual_exposure * status.digital_gain); + LOG(RPiAgc, Debug) << "Actual exposure " << actual_exposure; + LOG(RPiAgc, Debug) << "Use digital_gain " << status.digital_gain; + LOG(RPiAgc, Debug) << "Effective exposure " << actual_exposure * status.digital_gain; // Decide whether AEC/AGC has converged. // Insist AGC is steady for MAX_LOCK_COUNT // frames before we say we are "locked". @@ -285,11 +289,11 @@ void Agc::Prepare(Metadata *image_metadata) status.target_exposure_value - 1.5 * err) lock_count_ = lock_count; - RPI_LOG("Lock count: " << lock_count_); + LOG(RPiAgc, Debug) << "Lock count: " << lock_count_; } } } else - RPI_LOG(Name() << ": no device metadata"); + LOG(RPiAgc, Debug) << Name() << ": no device metadata"; status.locked = lock_count_ >= MAX_LOCK_COUNT; //printf("%s\n", status.locked ? "+++++++++" : "-"); image_metadata->Set("agc.status", status); @@ -343,9 +347,9 @@ void Agc::housekeepConfig() status_.fixed_analogue_gain = fixed_analogue_gain_; status_.flicker_period = flicker_period_; } - RPI_LOG("ev " << status_.ev << " fixed_shutter " - << status_.fixed_shutter << " fixed_analogue_gain " - << status_.fixed_analogue_gain); + LOG(RPiAgc, Debug) << "ev " << status_.ev << " fixed_shutter " + << status_.fixed_shutter << " fixed_analogue_gain " + << status_.fixed_analogue_gain; // Make sure the "mode" pointers point to the up-to-date things, if // they've changed. if (strcmp(new_metering_mode_name.c_str(), status_.metering_mode)) { @@ -376,10 +380,10 @@ void Agc::housekeepConfig() copy_string(new_constraint_mode_name, status_.constraint_mode, sizeof(status_.constraint_mode)); } - RPI_LOG("exposure_mode " - << new_exposure_mode_name << " constraint_mode " - << new_constraint_mode_name << " metering_mode " - << new_metering_mode_name); + LOG(RPiAgc, Debug) << "exposure_mode " + << new_exposure_mode_name << " constraint_mode " + << new_constraint_mode_name << " metering_mode " + << new_metering_mode_name; } void Agc::fetchCurrentExposure(Metadata *image_metadata) @@ -404,7 +408,7 @@ static double compute_initial_Y(bcm2835_isp_stats *stats, Metadata *image_metada struct AwbStatus awb; awb.gain_r = awb.gain_g = awb.gain_b = 1.0; // in case no metadata if (image_metadata->Get("awb.status", awb) != 0) - RPI_WARN("Agc: no AWB status found"); + LOG(RPiAgc, Warning) << "Agc: no AWB status found"; double Y_sum = 0, weight_sum = 0; for (int i = 0; i < AGC_STATS_SIZE; i++) { if (regions[i].counted == 0) @@ -443,7 +447,7 @@ void Agc::computeGain(bcm2835_isp_stats *statistics, Metadata *image_metadata, struct LuxStatus lux = {}; lux.lux = 400; // default lux level to 400 in case no metadata found if (image_metadata->Get("lux.status", lux) != 0) - RPI_WARN("Agc: no lux level found"); + LOG(RPiAgc, Warning) << "Agc: no lux level found"; Histogram h(statistics->hist[0].g_hist, NUM_HISTOGRAM_BINS); double ev_gain = status_.ev * config_.base_ev; // The initial gain and target_Y come from some of the regions. After @@ -454,28 +458,28 @@ void Agc::computeGain(bcm2835_isp_stats *statistics, Metadata *image_metadata, double initial_Y = compute_initial_Y(statistics, image_metadata, metering_mode_->weights); gain = std::min(10.0, target_Y / (initial_Y + .001)); - RPI_LOG("Initially Y " << initial_Y << " target " << target_Y - << " gives gain " << gain); + LOG(RPiAgc, Debug) << "Initially Y " << initial_Y << " target " << target_Y + << " gives gain " << gain; for (auto &c : *constraint_mode_) { double new_target_Y; double new_gain = constraint_compute_gain(c, h, lux.lux, ev_gain, new_target_Y); - RPI_LOG("Constraint has target_Y " - << new_target_Y << " giving gain " << new_gain); + LOG(RPiAgc, Debug) << "Constraint has target_Y " + << new_target_Y << " giving gain " << new_gain; if (c.bound == AgcConstraint::Bound::LOWER && new_gain > gain) { - RPI_LOG("Lower bound constraint adopted"); + LOG(RPiAgc, Debug) << "Lower bound constraint adopted"; gain = new_gain, target_Y = new_target_Y; } else if (c.bound == AgcConstraint::Bound::UPPER && new_gain < gain) { - RPI_LOG("Upper bound constraint adopted"); + LOG(RPiAgc, Debug) << "Upper bound constraint adopted"; gain = new_gain, target_Y = new_target_Y; } } - RPI_LOG("Final gain " << gain << " (target_Y " << target_Y << " ev " - << status_.ev << " base_ev " << config_.base_ev - << ")"); + LOG(RPiAgc, Debug) << "Final gain " << gain << " (target_Y " << target_Y << " ev " + << status_.ev << " base_ev " << config_.base_ev + << ")"; } void Agc::computeTargetExposure(double gain) @@ -494,7 +498,7 @@ void Agc::computeTargetExposure(double gain) : exposure_mode_->gain.back()); target_.total_exposure = std::min(target_.total_exposure, max_total_exposure); - RPI_LOG("Target total_exposure " << target_.total_exposure); + LOG(RPiAgc, Debug) << "Target total_exposure " << target_.total_exposure; } bool Agc::applyDigitalGain(Metadata *image_metadata, double gain, @@ -509,9 +513,9 @@ bool Agc::applyDigitalGain(Metadata *image_metadata, double gain, std::min(awb.gain_g, awb.gain_b)); dg *= std::max(1.0, 1.0 / min_gain); } else - RPI_WARN("Agc: no AWB status found"); - RPI_LOG("after AWB, target dg " << dg << " gain " << gain - << " target_Y " << target_Y); + LOG(RPiAgc, Warning) << "Agc: no AWB status found"; + LOG(RPiAgc, Debug) << "after AWB, target dg " << dg << " gain " << gain + << " target_Y " << target_Y; // Finally, if we're trying to reduce exposure but the target_Y is // "close" to 1.0, then the gain computed for that constraint will be // only slightly less than one, because the measured Y can never be @@ -523,9 +527,9 @@ bool Agc::applyDigitalGain(Metadata *image_metadata, double gain, gain < sqrt(target_Y); if (desaturate) dg /= config_.fast_reduce_threshold; - RPI_LOG("Digital gain " << dg << " desaturate? " << desaturate); + LOG(RPiAgc, Debug) << "Digital gain " << dg << " desaturate? " << desaturate; target_.total_exposure_no_dg = target_.total_exposure / dg; - RPI_LOG("Target total_exposure_no_dg " << target_.total_exposure_no_dg); + LOG(RPiAgc, Debug) << "Target total_exposure_no_dg " << target_.total_exposure_no_dg; return desaturate; } @@ -560,8 +564,8 @@ void Agc::filterExposure(bool desaturate) filtered_.total_exposure * config_.fast_reduce_threshold) filtered_.total_exposure_no_dg = filtered_.total_exposure * config_.fast_reduce_threshold; - RPI_LOG("After filtering, total_exposure " << filtered_.total_exposure << - " no dg " << filtered_.total_exposure_no_dg); + LOG(RPiAgc, Debug) << "After filtering, total_exposure " << filtered_.total_exposure + << " no dg " << filtered_.total_exposure_no_dg; } void Agc::divvyupExposure() @@ -602,8 +606,8 @@ void Agc::divvyupExposure() } } } - RPI_LOG("Divided up shutter and gain are " << shutter_time << " and " - << analogue_gain); + LOG(RPiAgc, Debug) << "Divided up shutter and gain are " << shutter_time << " and " + << analogue_gain; // Finally adjust shutter time for flicker avoidance (require both // shutter and gain not to be fixed). if (status_.fixed_shutter == 0.0 && @@ -621,8 +625,8 @@ void Agc::divvyupExposure() exposure_mode_->gain.back()); shutter_time = new_shutter_time; } - RPI_LOG("After flicker avoidance, shutter " - << shutter_time << " gain " << analogue_gain); + LOG(RPiAgc, Debug) << "After flicker avoidance, shutter " + << shutter_time << " gain " << analogue_gain; } filtered_.shutter = shutter_time; filtered_.analogue_gain = analogue_gain; @@ -641,10 +645,10 @@ void Agc::writeAndFinish(Metadata *image_metadata, bool desaturate) // Write to metadata as well, in case anyone wants to update the camera // immediately. image_metadata->Set("agc.status", status_); - RPI_LOG("Output written, total exposure requested is " - << filtered_.total_exposure); - RPI_LOG("Camera exposure update: shutter time " << filtered_.shutter << - " analogue gain " << filtered_.analogue_gain); + LOG(RPiAgc, Debug) << "Output written, total exposure requested is " + << filtered_.total_exposure; + LOG(RPiAgc, Debug) << "Camera exposure update: shutter time " << filtered_.shutter + << " analogue gain " << filtered_.analogue_gain; } // Register algorithm with the system.