{"id":12510,"url":"https://patchwork.libcamera.org/api/patches/12510/?format=json","web_url":"https://patchwork.libcamera.org/patch/12510/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20210608074225.59862-2-umang.jain@ideasonboard.com>","date":"2021-06-08T07:42:23","name":"[libcamera-devel,v2,1/3] ipa: ipu3: Calculate line duration from IPACameraSensorInfo","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"cb12a0d7ead1641650456d71a903b2daeb5a15ba","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/?format=json","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/12510/mbox/","series":[{"id":2109,"url":"https://patchwork.libcamera.org/api/series/2109/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2109","date":"2021-06-08T07:42:22","name":"IPAIPU3 drive-by improvements","version":2,"mbox":"https://patchwork.libcamera.org/series/2109/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12510/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12510/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 51EDCC320B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  8 Jun 2021 07:42:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 159546892E;\n\tTue,  8 Jun 2021 09:42:40 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8AEEF6892F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jun 2021 09:42:37 +0200 (CEST)","from perceval.ideasonboard.com (unknown [103.251.226.98])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 23FB23E6;\n\tTue,  8 Jun 2021 09:42:35 +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=\"cQecKwef\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1623138157;\n\tbh=29JvRM1DAdnudqlIIoDguhKJwBRIl7s29++81r4K/ho=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=cQecKwefvlOMmgmPfVFb5yjCncOzQYAOuMvYst0vU88DrXofx4b2kZ8MjKO90S/GA\n\tK6mBSoxD31Z5TdxKbTDDhhMhtfRfmVVfwF3zE/lhPZlZx5OxpZbPP84gienoLNQrWQ\n\tXWP/SN7Ib/rs86DKel8OWqpZllmakpW5hQIh0Fac=","From":"Umang Jain <umang.jain@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  8 Jun 2021 13:12:23 +0530","Message-Id":"<20210608074225.59862-2-umang.jain@ideasonboard.com>","X-Mailer":"git-send-email 2.31.1","In-Reply-To":"<20210608074225.59862-1-umang.jain@ideasonboard.com>","References":"<20210608074225.59862-1-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 1/3] ipa: ipu3: Calculate line duration\n\tfrom IPACameraSensorInfo","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":"Squash \\todo by calculating line duration from IPACameraSensorInfo,\nnow passed in, to IPU3Agc::initialise().\n\nSince line duration is now calculated from real values, store it as a\nprivate member in IPU3Agc class. As a further step, replace the\nassociated global constant, kMaxExposureTime, with a private IPU3Agc\nclass member as well, and assign its value correspondingly in\nIPU3Agc::initialise(), similar to previous precedence.\n\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\nTested-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/ipu3/ipu3.cpp     |  2 +-\n src/ipa/ipu3/ipu3_agc.cpp | 24 +++++++++++++-----------\n src/ipa/ipu3/ipu3_agc.h   |  7 ++++++-\n 3 files changed, 20 insertions(+), 13 deletions(-)","diff":"diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 700a5660..2496b0a0 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -174,7 +174,7 @@ void IPAIPU3::configure(const IPAConfigInfo &configInfo)\n \tawbAlgo_->initialise(params_, configInfo.bdsOutputSize, bdsGrid_);\n \n \tagcAlgo_ = std::make_unique<IPU3Agc>();\n-\tagcAlgo_->initialise(bdsGrid_);\n+\tagcAlgo_->initialise(bdsGrid_, configInfo.sensorInfo);\n }\n \n void IPAIPU3::mapBuffers(const std::vector<IPABuffer> &buffers)\ndiff --git a/src/ipa/ipu3/ipu3_agc.cpp b/src/ipa/ipu3/ipu3_agc.cpp\nindex 8bae423f..8ca95013 100644\n--- a/src/ipa/ipu3/ipu3_agc.cpp\n+++ b/src/ipa/ipu3/ipu3_agc.cpp\n@@ -11,6 +11,8 @@\n #include <cmath>\n #include <numeric>\n \n+#include <libcamera/ipa/core_ipa_interface.h>\n+\n #include \"libcamera/internal/log.h\"\n \n #include \"libipa/histogram.h\"\n@@ -39,11 +41,6 @@ static constexpr uint32_t kMaxGain = kMaxISO / 100;\n static constexpr uint32_t kMinExposure = 1;\n static constexpr uint32_t kMaxExposure = 1976;\n \n-/* \\todo those should be got from IPACameraSensorInfo ! */\n-/* line duration in microseconds */\n-static constexpr double kLineDuration = 16.8;\n-static constexpr double kMaxExposureTime = kMaxExposure * kLineDuration;\n-\n /* Histogram constants */\n static constexpr uint32_t knumHistogramBins = 256;\n static constexpr double kEvGainTarget = 0.5;\n@@ -54,14 +51,19 @@ 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 {\n }\n \n-void IPU3Agc::initialise(struct ipu3_uapi_grid_config &bdsGrid)\n+void IPU3Agc::initialise(struct ipu3_uapi_grid_config &bdsGrid, const IPACameraSensorInfo &sensorInfo)\n {\n \taeGrid_ = bdsGrid;\n+\n+\t/* line duration in microseconds */\n+\tlineDuration_ = sensorInfo.lineLength * 1000000ULL / static_cast<double>(sensorInfo.pixelRate);\n+\tmaxExposureTime_ = kMaxExposure * lineDuration_;\n }\n \n void IPU3Agc::processBrightness(const ipu3_uapi_stats_3a *stats)\n@@ -160,13 +162,13 @@ 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 * kLineDuration;\n+\t\tdouble 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 = kMaxExposureTime * kMaxGain;\n+\t\tdouble maxTotalExposure = maxExposureTime_ * kMaxGain;\n \t\tcurrentExposure_ = std::min(currentExposure_, maxTotalExposure);\n \t\tLOG(IPU3Agc, Debug) << \"Target total exposure \" << currentExposure_;\n \n@@ -174,18 +176,18 @@ void IPU3Agc::lockExposureGain(uint32_t &exposure, uint32_t &gain)\n \t\tfilterExposure();\n \n \t\tdouble newExposure = 0.0;\n-\t\tif (currentShutter < kMaxExposureTime) {\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;\n \t\t\tgain = std::clamp(static_cast<uint32_t>(gain * currentExposure_ / newExposure), kMinGain, kMaxGain);\n \t\t\tupdateControls_ = true;\n-\t\t} else if (currentShutter >= kMaxExposureTime) {\n+\t\t} else if (currentShutter >= maxExposureTime_) {\n \t\t\tgain = std::clamp(static_cast<uint32_t>(gain * currentExposure_ / currentExposureNoDg_), kMinGain, kMaxGain);\n \t\t\tnewExposure = currentExposure_ / gain;\n \t\t\texposure = std::clamp(static_cast<uint32_t>(exposure * currentExposure_ / newExposure), kMinExposure, kMaxExposure);\n \t\t\tupdateControls_ = true;\n \t\t}\n-\t\tLOG(IPU3Agc, Debug) << \"Adjust exposure \" << exposure * kLineDuration << \" and gain \" << gain;\n+\t\tLOG(IPU3Agc, Debug) << \"Adjust exposure \" << exposure * lineDuration_ << \" and gain \" << gain;\n \t}\n \tlastFrame_ = frameCount_;\n }\ndiff --git a/src/ipa/ipu3/ipu3_agc.h b/src/ipa/ipu3/ipu3_agc.h\nindex bfdf45d1..99a582a9 100644\n--- a/src/ipa/ipu3/ipu3_agc.h\n+++ b/src/ipa/ipu3/ipu3_agc.h\n@@ -18,6 +18,8 @@\n \n namespace libcamera {\n \n+class IPACameraSensorInfo;\n+\n namespace ipa::ipu3 {\n \n class IPU3Agc : public Algorithm\n@@ -26,7 +28,7 @@ public:\n \tIPU3Agc();\n \t~IPU3Agc() = default;\n \n-\tvoid initialise(struct ipu3_uapi_grid_config &bdsGrid);\n+\tvoid initialise(struct ipu3_uapi_grid_config &bdsGrid, const IPACameraSensorInfo &sensorInfo);\n \tvoid process(const ipu3_uapi_stats_3a *stats, uint32_t &exposure, uint32_t &gain);\n \tbool converged() { return converged_; }\n \tbool updateControls() { return updateControls_; }\n@@ -49,6 +51,9 @@ private:\n \tdouble iqMean_;\n \tdouble gamma_;\n \n+\tdouble lineDuration_;\n+\tdouble maxExposureTime_;\n+\n \tdouble prevExposure_;\n \tdouble prevExposureNoDg_;\n \tdouble currentExposure_;\n","prefixes":["libcamera-devel","v2","1/3"]}