From patchwork Thu Feb 23 12:49:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18302 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 746ADC3259 for ; Thu, 23 Feb 2023 12:49:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C4FB56265E; Thu, 23 Feb 2023 13:49:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1677156594; bh=zeJASNYiblWKKexCvMJ+Ho4CHyPrKUIqI2hvFNBfeuQ=; h=To:Date:In-Reply-To:References:List-Id:List-Post:From: List-Subscribe:List-Unsubscribe:List-Archive:Reply-To:List-Help: Subject:From; b=jbZkbsMbSAnphqPwiMCcO3CCtZhDwLNWCmi9lujgUZ9fJX9MnAGlKesHEgxjbDNvs Ncmz7G/gfiq9bRznAYRmw9wPyRQGPL9EA9aRC9bllbzXriHjgqvoDSiPRyOCOcXgL9 7SNnjFldH2Prjl5OIFqKtMEvNMWKLUKNW+NHBAZLyBLpHAGUcoWcDP/NWT/SLjlEu+ iBPq1P1AfqHwqjN4p+7r5rLpNgNezeuxEJTsZ5ssWTxZ3Qqvz1X6ya0J6p+HvaO6MW 6nXLNH1ydiuhmZTrdF2DxhayguOSa6ojYXtjodPsWgnzzvsYiLySLskorCq5Fcyt80 tb+nGIoWDb9Aw== To: libcamera-devel@lists.libcamera.org Date: Thu, 23 Feb 2023 12:49:56 +0000 In-Reply-To: <20230223124957.11084-1-naush@raspberrypi.com> References: <20230223124957.11084-1-naush@raspberrypi.com> MIME-Version: 1.0 Message-ID: List-Id: List-Post: X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Precedence: list X-Mailman-Version: 2.1.29 X-BeenThere: libcamera-devel@lists.libcamera.org List-Subscribe: , List-Unsubscribe: , List-Archive: Reply-To: Naushir Patuck List-Help: Subject: [libcamera-devel] [PATCH v1 2/3] ipa: raspberrypi: Better heruistics for calculating Unicam timeout Content-Disposition: inline Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The existing mechanism of setting a timeout value simply uses the maximum possible frame length advertised by the sensor mode. This can be problematic when, for example, the IMX477 sensor can use a frame length of over 600 seconds. However, for typical usage the frame length will never go over several 100s of milliseconds, making the timeout very impractical. Store a list of the last 10 frame length values requested by the AGC. On startup, and at the end of every frame, take the maximum frame length value from this list and return that to the pipeline handler through the setCameraTimeoutValue() signal. This allows the timeout value to better track the actual sensor usage. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- src/ipa/raspberrypi/raspberrypi.cpp | 33 +++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index f6826bf27fe1..b8fe0c002a13 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,9 @@ using utils::Duration; /* Number of metadata objects available in the context list. */ constexpr unsigned int numMetadataContexts = 16; +/* Number of frame length times to hold in the queue. */ +constexpr unsigned int FrameLengthsQueueSize = 10; + /* Configure the sensor with these values initially. */ constexpr double defaultAnalogueGain = 1.0; constexpr Duration defaultExposureTime = 20.0ms; @@ -155,6 +159,7 @@ private: void fillDeviceStatus(const ControlList &sensorControls, unsigned int ipaContext); RPiController::StatisticsPtr fillStatistics(bcm2835_isp_stats *stats) const; void processStats(unsigned int bufferId, unsigned int ipaContext); + void setCameraTimeoutValue(); void applyFrameDurations(Duration minFrameDuration, Duration maxFrameDuration); void applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls); void applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls); @@ -220,6 +225,9 @@ private: /* Maximum gain code for the sensor. */ uint32_t maxSensorGainCode_; + + /* Track the frame length times over FrameLengthsQueueSize frames. */ + std::deque frameLengths_; }; int IPARPi::init(const IPASettings &settings, bool lensPresent, IPAInitResult *result) @@ -294,6 +302,7 @@ void IPARPi::start(const ControlList &controls, StartConfig *startConfig) ControlList ctrls(sensorCtrls_); applyAGC(&agcStatus, ctrls); startConfig->controls = std::move(ctrls); + setCameraTimeoutValue(); } /* @@ -340,8 +349,6 @@ void IPARPi::start(const ControlList &controls, StartConfig *startConfig) } startConfig->dropFrameCount = dropFrameCount_; - const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.maxLineLength; - setCameraTimeout.emit(maxSensorFrameDuration.get()); firstStart_ = false; lastRunTimestamp_ = 0; @@ -1434,9 +1441,20 @@ void IPARPi::processStats(unsigned int bufferId, unsigned int ipaContext) applyAGC(&agcStatus, ctrls); setDelayedControls.emit(ctrls, ipaContext); + setCameraTimeoutValue(); } } +void IPARPi::setCameraTimeoutValue() +{ + /* + * Take the maximum value of the exposure queue as the camera timeout + * value to pass back to the pipe line handler. + */ + auto max = std::max_element(frameLengths_.begin(), frameLengths_.end()); + setCameraTimeout.emit(max->get()); +} + void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls) { LOG(IPARPI, Debug) << "Applying WB R: " << awbStatus->gainR << " B: " @@ -1522,6 +1540,17 @@ void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) */ if (mode_.minLineLength != mode_.maxLineLength) ctrls.set(V4L2_CID_HBLANK, static_cast(hblank)); + + /* + * Store the frame length times in a circular queue, up-to FrameLengthsQueueSize + * elements. This will be used to advertise a camera timeout value to the + * pipeline handler. + */ + if (frameLengths_.size() == FrameLengthsQueueSize) + frameLengths_.pop_front(); + + frameLengths_.push_back(helper_->exposure(vblank + mode_.height, + helper_->hblankToLineLength(hblank))); } void IPARPi::applyDG(const struct AgcStatus *dgStatus, ControlList &ctrls)