{"id":12694,"url":"https://patchwork.libcamera.org/api/1.1/patches/12694/?format=json","web_url":"https://patchwork.libcamera.org/patch/12694/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210623112203.33561-1-umang.jain@ideasonboard.com>","date":"2021-06-23T11:22:03","name":"[libcamera-devel] ipa: ipu3: Use libcamera::utils::Duration helper class for durations","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"57e13ea289ccb2ea07e103bc4443b273f1be7d84","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/1.1/people/86/?format=json","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/12694/mbox/","series":[{"id":2169,"url":"https://patchwork.libcamera.org/api/1.1/series/2169/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2169","date":"2021-06-23T11:22:03","name":"[libcamera-devel] ipa: ipu3: Use libcamera::utils::Duration helper class for durations","version":1,"mbox":"https://patchwork.libcamera.org/series/2169/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12694/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12694/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 71481C321A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 23 Jun 2021 11:22:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E916668937;\n\tWed, 23 Jun 2021 13:22:12 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4674668932\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Jun 2021 13:22:11 +0200 (CEST)","from perceval.ideasonboard.com (unknown [103.251.226.162])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CEF819AA;\n\tWed, 23 Jun 2021 13:22:09 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"rEbmHI2+\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1624447330;\n\tbh=+nAoDtm5jY0rbufgISno2RMseJ15ss8yh0MuPzK7HS4=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=rEbmHI2+YeizSyQdumUT0F+mluHd8USpTVK6LvqfvUU9FKPQ/6+jwiLwbkYZJg9Od\n\ty68XBlREGdq+d6ZakUXo759exF4nwiL9XmwKIKnGBk1upK+6YnDfn/Jx1AXADIgJZW\n\tfAIrqZdAkagvfKG6M6vngf9sh4qx9LmcpqtMVQMg=","From":"Umang Jain <umang.jain@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 23 Jun 2021 16:52:03 +0530","Message-Id":"<20210623112203.33561-1-umang.jain@ideasonboard.com>","X-Mailer":"git-send-email 2.31.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH] ipa: ipu3: Use libcamera::utils::Duration\n\thelper class for durations","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"std::chrono::Duration is provided quite conveniently by\nlibcamera::utils::Duration wrapper. Port IPAIPU3 to use that\nfor duration-type entities (such as exposure time), such that\nit becomes consistent with rest of the codebase.\n\nThe commit doesn't introduce any functional changes.\n\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\n---\n src/ipa/ipu3/ipu3_agc.cpp | 21 ++++++++++++---------\n src/ipa/ipu3/ipu3_agc.h   | 14 ++++++++------\n 2 files changed, 20 insertions(+), 15 deletions(-)","diff":"diff --git a/src/ipa/ipu3/ipu3_agc.cpp b/src/ipa/ipu3/ipu3_agc.cpp\nindex 8ca95013..101ef288 100644\n--- a/src/ipa/ipu3/ipu3_agc.cpp\n+++ b/src/ipa/ipu3/ipu3_agc.cpp\n@@ -19,6 +19,8 @@\n \n namespace libcamera {\n \n+using namespace std::literals::chrono_literals;\n+\n namespace ipa::ipu3 {\n \n LOG_DEFINE_CATEGORY(IPU3Agc)\n@@ -51,9 +53,9 @@ static constexpr uint8_t kCellSize = 8;\n IPU3Agc::IPU3Agc()\n \t: frameCount_(0), lastFrame_(0), converged_(false),\n \t  updateControls_(false), iqMean_(0.0), gamma_(1.0),\n-\t  lineDuration_(0.0), maxExposureTime_(0.0),\n-\t  prevExposure_(0.0), prevExposureNoDg_(0.0),\n-\t  currentExposure_(0.0), currentExposureNoDg_(0.0)\n+\t  lineDuration_(0s), maxExposureTime_(0s),\n+\t  prevExposure_(0s), prevExposureNoDg_(0s),\n+\t  currentExposure_(0s), currentExposureNoDg_(0s)\n {\n }\n \n@@ -61,8 +63,9 @@ void IPU3Agc::initialise(struct ipu3_uapi_grid_config &bdsGrid, const IPACameraS\n {\n \taeGrid_ = bdsGrid;\n \n-\t/* line duration in microseconds */\n-\tlineDuration_ = sensorInfo.lineLength * 1000000ULL / static_cast<double>(sensorInfo.pixelRate);\n+\tdouble ld = sensorInfo.lineLength * 1000000ULL / static_cast<double>(sensorInfo.pixelRate);\n+\tstd::chrono::duration<double, std::micro> lineDuration(ld);\n+\tlineDuration_ = lineDuration;\n \tmaxExposureTime_ = kMaxExposure * lineDuration_;\n }\n \n@@ -113,7 +116,7 @@ void IPU3Agc::processBrightness(const ipu3_uapi_stats_3a *stats)\n void IPU3Agc::filterExposure()\n {\n \tdouble speed = 0.2;\n-\tif (prevExposure_ == 0.0) {\n+\tif (prevExposure_ == 0s) {\n \t\t/* DG stands for digital gain.*/\n \t\tprevExposure_ = currentExposure_;\n \t\tprevExposureNoDg_ = currentExposureNoDg_;\n@@ -162,20 +165,20 @@ void IPU3Agc::lockExposureGain(uint32_t &exposure, uint32_t &gain)\n \t\tdouble newGain = kEvGainTarget * knumHistogramBins / iqMean_;\n \n \t\t/* extracted from Rpi::Agc::computeTargetExposure */\n-\t\tdouble currentShutter = exposure * lineDuration_;\n+\t\tlibcamera::utils::Duration currentShutter = exposure * lineDuration_;\n \t\tcurrentExposureNoDg_ = currentShutter * gain;\n \t\tLOG(IPU3Agc, Debug) << \"Actual total exposure \" << currentExposureNoDg_\n \t\t\t\t    << \" Shutter speed \" << currentShutter\n \t\t\t\t    << \" Gain \" << gain;\n \t\tcurrentExposure_ = currentExposureNoDg_ * newGain;\n-\t\tdouble maxTotalExposure = maxExposureTime_ * kMaxGain;\n+\t\tlibcamera::utils::Duration maxTotalExposure = maxExposureTime_ * kMaxGain;\n \t\tcurrentExposure_ = std::min(currentExposure_, maxTotalExposure);\n \t\tLOG(IPU3Agc, Debug) << \"Target total exposure \" << currentExposure_;\n \n \t\t/* \\todo: estimate if we need to desaturate */\n \t\tfilterExposure();\n \n-\t\tdouble newExposure = 0.0;\n+\t\tlibcamera::utils::Duration newExposure = 0.0s;\n \t\tif (currentShutter < maxExposureTime_) {\n \t\t\texposure = std::clamp(static_cast<uint32_t>(exposure * currentExposure_ / currentExposureNoDg_), kMinExposure, kMaxExposure);\n \t\t\tnewExposure = currentExposure_ / exposure;\ndiff --git a/src/ipa/ipu3/ipu3_agc.h b/src/ipa/ipu3/ipu3_agc.h\nindex f3d40557..de3e2dbf 100644\n--- a/src/ipa/ipu3/ipu3_agc.h\n+++ b/src/ipa/ipu3/ipu3_agc.h\n@@ -14,6 +14,8 @@\n \n #include <libcamera/geometry.h>\n \n+#include \"libcamera/internal/utils.h\"\n+\n #include \"libipa/algorithm.h\"\n \n namespace libcamera {\n@@ -51,13 +53,13 @@ private:\n \tdouble iqMean_;\n \tdouble gamma_;\n \n-\tdouble lineDuration_;\n-\tdouble maxExposureTime_;\n+\tlibcamera::utils::Duration lineDuration_;\n+\tlibcamera::utils::Duration maxExposureTime_;\n \n-\tdouble prevExposure_;\n-\tdouble prevExposureNoDg_;\n-\tdouble currentExposure_;\n-\tdouble currentExposureNoDg_;\n+\tlibcamera::utils::Duration prevExposure_;\n+\tlibcamera::utils::Duration prevExposureNoDg_;\n+\tlibcamera::utils::Duration currentExposure_;\n+\tlibcamera::utils::Duration currentExposureNoDg_;\n };\n \n } /* namespace ipa::ipu3 */\n","prefixes":["libcamera-devel"]}