<div dir="ltr"><div dir="ltr">Hi Umang,<div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 23 Jun 2021 at 12:22, Umang Jain <<a href="mailto:umang.jain@ideasonboard.com">umang.jain@ideasonboard.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">std::chrono::Duration is provided quite conveniently by<br>
libcamera::utils::Duration wrapper. Port IPAIPU3 to use that<br>
for duration-type entities (such as exposure time), such that<br>
it becomes consistent with rest of the codebase.<br>
<br>
The commit doesn't introduce any functional changes.<br>
<br>
Signed-off-by: Umang Jain <<a href="mailto:umang.jain@ideasonboard.com" target="_blank">umang.jain@ideasonboard.com</a>><br>
---<br>
src/ipa/ipu3/ipu3_agc.cpp | 21 ++++++++++++---------<br>
src/ipa/ipu3/ipu3_agc.h | 14 ++++++++------<br>
2 files changed, 20 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/src/ipa/ipu3/ipu3_agc.cpp b/src/ipa/ipu3/ipu3_agc.cpp<br>
index 8ca95013..101ef288 100644<br>
--- a/src/ipa/ipu3/ipu3_agc.cpp<br>
+++ b/src/ipa/ipu3/ipu3_agc.cpp<br>
@@ -19,6 +19,8 @@<br>
<br>
namespace libcamera {<br>
<br>
+using namespace std::literals::chrono_literals;<br>
+<br>
namespace ipa::ipu3 {<br>
<br>
LOG_DEFINE_CATEGORY(IPU3Agc)<br>
@@ -51,9 +53,9 @@ static constexpr uint8_t kCellSize = 8;<br>
IPU3Agc::IPU3Agc()<br>
: frameCount_(0), lastFrame_(0), converged_(false),<br>
updateControls_(false), iqMean_(0.0), gamma_(1.0),<br>
- lineDuration_(0.0), maxExposureTime_(0.0),<br>
- prevExposure_(0.0), prevExposureNoDg_(0.0),<br>
- currentExposure_(0.0), currentExposureNoDg_(0.0)<br>
+ lineDuration_(0s), maxExposureTime_(0s),<br>
+ prevExposure_(0s), prevExposureNoDg_(0s),<br>
+ currentExposure_(0s), currentExposureNoDg_(0s)<br>
{<br>
}<br>
<br>
@@ -61,8 +63,9 @@ void IPU3Agc::initialise(struct ipu3_uapi_grid_config &bdsGrid, const IPACameraS<br>
{<br>
aeGrid_ = bdsGrid;<br>
<br>
- /* line duration in microseconds */<br>
- lineDuration_ = sensorInfo.lineLength * 1000000ULL / static_cast<double>(sensorInfo.pixelRate);<br>
+ double ld = sensorInfo.lineLength * 1000000ULL / static_cast<double>(sensorInfo.pixelRate);<br>
+ std::chrono::duration<double, std::micro> lineDuration(ld);<br>
+ lineDuration_ = lineDuration;<br></blockquote><div><br></div><div>You could write this as:</div><div>lineDuration_ = sensorInfo.lineLength * 1.0s / sensorInfo.pixelRate</div><div><br></div><div>and let the compiler worry about any and all conversions.</div><div><br></div><div>Naush</div><div><br></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">
maxExposureTime_ = kMaxExposure * lineDuration_;<br>
}<br>
<br>
@@ -113,7 +116,7 @@ void IPU3Agc::processBrightness(const ipu3_uapi_stats_3a *stats)<br>
void IPU3Agc::filterExposure()<br>
{<br>
double speed = 0.2;<br>
- if (prevExposure_ == 0.0) {<br>
+ if (prevExposure_ == 0s) {<br>
/* DG stands for digital gain.*/<br>
prevExposure_ = currentExposure_;<br>
prevExposureNoDg_ = currentExposureNoDg_;<br>
@@ -162,20 +165,20 @@ void IPU3Agc::lockExposureGain(uint32_t &exposure, uint32_t &gain)<br>
double newGain = kEvGainTarget * knumHistogramBins / iqMean_;<br>
<br>
/* extracted from Rpi::Agc::computeTargetExposure */<br>
- double currentShutter = exposure * lineDuration_;<br>
+ libcamera::utils::Duration currentShutter = exposure * lineDuration_;<br>
currentExposureNoDg_ = currentShutter * gain;<br>
LOG(IPU3Agc, Debug) << "Actual total exposure " << currentExposureNoDg_<br>
<< " Shutter speed " << currentShutter<br>
<< " Gain " << gain;<br>
currentExposure_ = currentExposureNoDg_ * newGain;<br>
- double maxTotalExposure = maxExposureTime_ * kMaxGain;<br>
+ libcamera::utils::Duration maxTotalExposure = maxExposureTime_ * kMaxGain;<br>
currentExposure_ = std::min(currentExposure_, maxTotalExposure);<br>
LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_;<br>
<br>
/* \todo: estimate if we need to desaturate */<br>
filterExposure();<br>
<br>
- double newExposure = 0.0;<br>
+ libcamera::utils::Duration newExposure = 0.0s;<br>
if (currentShutter < maxExposureTime_) {<br>
exposure = std::clamp(static_cast<uint32_t>(exposure * currentExposure_ / currentExposureNoDg_), kMinExposure, kMaxExposure);<br>
newExposure = currentExposure_ / exposure;<br>
diff --git a/src/ipa/ipu3/ipu3_agc.h b/src/ipa/ipu3/ipu3_agc.h<br>
index f3d40557..de3e2dbf 100644<br>
--- a/src/ipa/ipu3/ipu3_agc.h<br>
+++ b/src/ipa/ipu3/ipu3_agc.h<br>
@@ -14,6 +14,8 @@<br>
<br>
#include <libcamera/geometry.h><br>
<br>
+#include "libcamera/internal/utils.h"<br>
+<br>
#include "libipa/algorithm.h"<br>
<br>
namespace libcamera {<br>
@@ -51,13 +53,13 @@ private:<br>
double iqMean_;<br>
double gamma_;<br>
<br>
- double lineDuration_;<br>
- double maxExposureTime_;<br>
+ libcamera::utils::Duration lineDuration_;<br>
+ libcamera::utils::Duration maxExposureTime_;<br>
<br>
- double prevExposure_;<br>
- double prevExposureNoDg_;<br>
- double currentExposure_;<br>
- double currentExposureNoDg_;<br>
+ libcamera::utils::Duration prevExposure_;<br>
+ libcamera::utils::Duration prevExposureNoDg_;<br>
+ libcamera::utils::Duration currentExposure_;<br>
+ libcamera::utils::Duration currentExposureNoDg_;<br>
};<br>
<br>
} /* namespace ipa::ipu3 */<br>
-- <br>
2.31.1<br>
<br>
</blockquote></div></div>