From patchwork Tue Mar 7 10:30:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18347 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 CA8D0C3262 for ; Tue, 7 Mar 2023 10:30:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 193DD626C2; Tue, 7 Mar 2023 11:30:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678185022; bh=p4NX4NT6AUG8DZqOr71i/qWbOUcv1IEEHvyDAOhZ0kA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=KByPWuoyqr0CNdsOQznUURdiwC6h9O4S0dE1MkPbxwrT9+Q1DCFeF8aJPDv23eAcX ED7/ONKINIeHUKbF74/LzmsnM00wUMbV28/vbsmEygvGkDxYGmYJ47jMgD9QFZIM0Q EJWTKG/cN++Et+fuvjXlsoVAGYJIdUVATYSn87RZoE1Oux6bTBkBQGfLeR1k2bo/eR 2w5j46UhbEqYHwPafz2fxkpAktiJib9YEqsnyIAYC4S0a7spwfPP+KsjmM3n7GuPIx HijZGcyM35C7FWyX50zLqSj+eksF0LR82Ah+FRaPAtEg6oCtxQH9s9I6//Xit0CMAk NZh4IoxnRETjA== Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 168DA6266A for ; Tue, 7 Mar 2023 11:30:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="AkzSOT96"; dkim-atps=neutral Received: by mail-wr1-x434.google.com with SMTP id e13so11571925wro.10 for ; Tue, 07 Mar 2023 02:30:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1678185019; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3gAHJm9NpiQ1zfRhg6VO2npvj+v9NiZ4ZFdagsdSiow=; b=AkzSOT96rKWukUYg3zPM0BQ+M8cNo+rXXEJvFx7XGajh+1a1JJi0ZMExN3J/L8t7xI /UXdMP1GySR72QN/HCuVri3emMQ1wJ30az1XR449fLBiBHTObtMe0vWaVaHiBqLbzvFj p8GMX96YnAr5Jmd+TzGI1qY805rwaXhL3ANxbtQHDue83zFV8hUArC2u3kw5OcqO61ON 54t3IueRoqp66SsDMml9jbQKsKgEsKSouqoXdt7XBPoI6TanTRlUjXDl8ChSAOb4wLPA aW/6TcoYbdnX6oc+UUe9uvFe/IbM9+KGQTsxHbs3Wep8aGT765EfOgAvB8c03WnDlYv/ HVqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678185019; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3gAHJm9NpiQ1zfRhg6VO2npvj+v9NiZ4ZFdagsdSiow=; b=V545Sz2cWfz/kMUbV2xz2RrHzK39RdoIWnT1idaqbmFNRBycZcp30vne43Zw1D+wh/ 9O5gOkaqBg4ItCqKQESmSnVPSRgM38bDj8jiCmfml/9A1BKedPVY18oF1sQehiAHG2e3 2MPT7RhFzz2fpkIM1syEOclLvl222c4LnIR27ICUnhPJtb8+kxuLWgeTXazRibn7MXer /zZVdYsV3qvDntWvK51G+A67zMCa/bEzHJ+p34IXLyPboeJ6WZ/OfrR3vKYnuHQwbvfN FRsq0Si9XgNxpnQMM1vDPIbIIeOiewkE7/yNz0BzTVc6a+jbRQOAT3kgehR4zpeXoMDY CduQ== X-Gm-Message-State: AO0yUKVZySZYwGQgdaMKaJP+fFa27RGJPhl5HvuMnRZW64EC3RQVz/Iw XbDsfePIPxwxM+QpDT1sVF1ShD2qY7h9R0aMDFE7kw== X-Google-Smtp-Source: AK7set87XyUyvkxCES5pFuLDcwv2Ft+fgoFZBvwDzfTPA56BBe96wXfzk0udQ53wAeZStTEchX8yaA== X-Received: by 2002:a5d:558e:0:b0:2c9:e5f0:bd4f with SMTP id i14-20020a5d558e000000b002c9e5f0bd4fmr9082931wrv.18.1678185019472; Tue, 07 Mar 2023 02:30:19 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id r1-20020a056000014100b002c5534db60bsm12523621wrx.71.2023.03.07.02.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 02:30:19 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Mar 2023 10:30:21 +0000 Message-Id: <20230307103023.3932-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307103023.3932-1-naush@raspberrypi.com> References: <20230307103023.3932-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/3] pipeline: ipa: raspberrypi: Change Unicam timeout handling 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: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add an explicit helper function setCameraTimeout() in the pipeline handler to set the Unicam timeout value. This function is signalled from the IPA to set up an appropriate timeout. This replaces the maxSensorFrameLengthMs value parameter returned back from IPARPi::start(). Adjust the timeout to be 5x the maximum frame duration reported by the IPA. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/ipa/raspberrypi.mojom | 2 +- src/ipa/raspberrypi/raspberrypi.cpp | 2 +- .../pipeline/raspberrypi/raspberrypi.cpp | 24 ++++++++++++------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index 8e78f167f179..80e0126618c8 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -49,7 +49,6 @@ struct IPAConfigResult { struct StartConfig { libcamera.ControlList controls; int32 dropFrameCount; - uint32 maxSensorFrameLengthMs; }; interface IPARPiInterface { @@ -132,4 +131,5 @@ interface IPARPiEventInterface { setIspControls(libcamera.ControlList controls); setDelayedControls(libcamera.ControlList controls, uint32 delayContext); setLensControls(libcamera.ControlList controls); + setCameraTimeout(uint32 maxFrameLengthMs); }; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 9b08ae4ca622..f6826bf27fe1 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -341,7 +341,7 @@ void IPARPi::start(const ControlList &controls, StartConfig *startConfig) startConfig->dropFrameCount = dropFrameCount_; const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.maxLineLength; - startConfig->maxSensorFrameLengthMs = maxSensorFrameDuration.get(); + setCameraTimeout.emit(maxSensorFrameDuration.get()); firstStart_ = false; lastRunTimestamp_ = 0; diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 841209548350..3d04842a2440 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -212,6 +212,7 @@ public: void setIspControls(const ControlList &controls); void setDelayedControls(const ControlList &controls, uint32_t delayContext); void setLensControls(const ControlList &controls); + void setCameraTimeout(uint32_t maxExposureTimeMs); void setSensorControls(ControlList &controls); void unicamTimeout(); @@ -1166,14 +1167,6 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) } } - /* - * Set the dequeue timeout to the larger of 2x the maximum possible - * frame duration or 1 second. - */ - utils::Duration timeout = - std::max(1s, 2 * startConfig.maxSensorFrameLengthMs * 1ms); - data->unicam_[Unicam::Image].dev()->setDequeueTimeout(timeout); - return 0; } @@ -1645,6 +1638,7 @@ int RPiCameraData::loadIPA(ipa::RPi::IPAInitResult *result) ipa_->setIspControls.connect(this, &RPiCameraData::setIspControls); ipa_->setDelayedControls.connect(this, &RPiCameraData::setDelayedControls); ipa_->setLensControls.connect(this, &RPiCameraData::setLensControls); + ipa_->setCameraTimeout.connect(this, &RPiCameraData::setCameraTimeout); /* * The configuration (tuning file) is made from the sensor name unless @@ -1957,6 +1951,20 @@ void RPiCameraData::setLensControls(const ControlList &controls) } } +void RPiCameraData::setCameraTimeout(uint32_t maxFrameLengthMs) +{ + /* + * Set the dequeue timeout to the larger of 5x the maximum reported + * frame length advertised by the IPA over a number of frames. Allow + * a minimum timeout value of 1s. + */ + utils::Duration timeout = + std::max(1s, 5 * maxFrameLengthMs * 1ms); + + LOG(RPI, Debug) << "Setting Unicam timeout to " << timeout; + unicam_[Unicam::Image].dev()->setDequeueTimeout(timeout); +} + void RPiCameraData::setSensorControls(ControlList &controls) { /* From patchwork Tue Mar 7 10:30:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18348 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 9BD65BDE17 for ; Tue, 7 Mar 2023 10:30:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B3A51626BD; Tue, 7 Mar 2023 11:30:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678185022; bh=uHukBppQ9A5OsTHDeu/tfXJdWD3XkC4RKes4mVrlEV4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=q4gvgt+6S6j+q2Xc1LaTnEr7VrijStqCSherdLGcTlLTdpBKFJORWskvDF9g6+zDs WIoK6EdDHgz2yuDAXILHeno5FEtjI1+/QuB8fbuzQwDV/y98c8xTtYSRrKWmav9KEf sun9FJ4jrjqVwHjog1ehu4KZs86GYT5gaFNrrjmwMUxXB2u3Sws0eLSA1U4RtMAEAv G3yuZfcpOk33BEVoKa6RiUXHnFdv1h0J5j+3z7pmT+T2HMdnjxNgnPotOumrUN0brj 4vpmLC/lEj2IDROhyOjAhcxFPQ2pY8Gm+u2XxpNAkV2+Y4smDkYSp9R/xap62jGAER diDOdRGfE5i5w== Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E4A93626B0 for ; Tue, 7 Mar 2023 11:30:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Oc9fJCg9"; dkim-atps=neutral Received: by mail-wr1-x430.google.com with SMTP id f11so11593612wrv.8 for ; Tue, 07 Mar 2023 02:30:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1678185020; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PhGw19Z6wfbl/Zl2QWmnDP+EBngZ5SCr/PEqqFZIILA=; b=Oc9fJCg9ZPDZuSAhHHHpSNC+hvh+yNyQQy1zfBqZUszNQR3QYNKZ+TFN3Jnv4AhiJr ZaPy5gp4WH4nzrOQrNPdZvV2UPyFTiZp1jPOAiBua2vBg3eHqPROehoxWuufO2u2B1Gs vkPNLsHdIbF0dMyCgEVU1r+t7J5sVUhDiGLCAmL7dTr3J+b8fwPrmZmJNM97X6P4l20P d6lDvPV5Ii/9Z1+8TOIVjKs2Ypb2Xg0eFsTvEckNY8VWPcOGsyb3BvaPh6Qcf++bwqcU NRo/Lw8O9T5LbqYSfU/4Z//EfToZu7/I6yzWXfmLtG2/cYEdS+wktmwwdhTqncH+DVAd j0bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678185020; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PhGw19Z6wfbl/Zl2QWmnDP+EBngZ5SCr/PEqqFZIILA=; b=NVfHT94pXL9ucif2yJ36fomWBmefgXlMGRLgmwhuFNyeiaNKpHyt1V5/IYUzAVS4kK alp+keYzRrDzz2ESyxb4FqeUCQqDUQZByRzhVVlIwII3hX41vFLCbe1Yildxl24S6RtO r7tK139W7FjmJdzMThVENupYpOnmtb43eDBZkHR3FF92aD6O8hMEBTamgPhQkY0QamiX /jzAP6UJN+sx+3n6lEO8p2tvg3VK86piXlTwoYJBhXZ/9hk5lkLiRIzSamRHTwOlXjm5 hGjUyev5TZjUu6ZmluLMzhce15JGt2n+Wo7L901+Fr3quvyhgrJXUpIMhf3gAQewqoJ0 4RpA== X-Gm-Message-State: AO0yUKXfWX+BL5x8Pd+bx82ZadO43xIl8rLvUduWCdWumJ0I7RojtIVc wcZhKaCEy76SIkNoKBPqi/mp54ercaco0+XtSSsYQw== X-Google-Smtp-Source: AK7set/tHWL+WysTpjUHHOQMyfFO1+L4GzQra+l0iQCdm1By4sMfTPofrg85+xjRLrb73df3wZ+E+A== X-Received: by 2002:adf:ec04:0:b0:2c7:d56:777b with SMTP id x4-20020adfec04000000b002c70d56777bmr9192339wrn.64.1678185020210; Tue, 07 Mar 2023 02:30:20 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id r1-20020a056000014100b002c5534db60bsm12523621wrx.71.2023.03.07.02.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 02:30:19 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Mar 2023 10:30:22 +0000 Message-Id: <20230307103023.3932-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307103023.3932-1-naush@raspberrypi.com> References: <20230307103023.3932-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/3] ipa: raspberrypi: Better heuristics for calculating Unicam timeout 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: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi 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 Reviewed-by: Jacopo Mondi --- src/ipa/raspberrypi/raspberrypi.cpp | 45 +++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index f6826bf27fe1..1375795568e2 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; @@ -121,7 +125,8 @@ class IPARPi : public IPARPiInterface public: IPARPi() : controller_(), frameCount_(0), checkCount_(0), mistrustCount_(0), - lastRunTimestamp_(0), lsTable_(nullptr), firstStart_(true) + lastRunTimestamp_(0), lsTable_(nullptr), firstStart_(true), + lastTimeout_(0s) { } @@ -155,6 +160,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 +226,10 @@ private: /* Maximum gain code for the sensor. */ uint32_t maxSensorGainCode_; + + /* Track the frame length times over FrameLengthsQueueSize frames. */ + std::deque frameLengths_; + Duration lastTimeout_; }; int IPARPi::init(const IPASettings &settings, bool lensPresent, IPAInitResult *result) @@ -284,6 +294,11 @@ void IPARPi::start(const ControlList &controls, StartConfig *startConfig) controller_.switchMode(mode_, &metadata); + /* Reset the frame lengths queue state. */ + lastTimeout_ = 0s; + frameLengths_.clear(); + frameLengths_.resize(FrameLengthsQueueSize, 0s); + /* SwitchMode may supply updated exposure/gain values to use. */ AgcStatus agcStatus; agcStatus.shutterTime = 0.0s; @@ -294,6 +309,7 @@ void IPARPi::start(const ControlList &controls, StartConfig *startConfig) ControlList ctrls(sensorCtrls_); applyAGC(&agcStatus, ctrls); startConfig->controls = std::move(ctrls); + setCameraTimeoutValue(); } /* @@ -340,8 +356,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,6 +1448,22 @@ 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 pipeline handler. Only signal if it has changed + * from the last set value. + */ + auto max = std::max_element(frameLengths_.begin(), frameLengths_.end()); + + if (*max != lastTimeout_) { + setCameraTimeout.emit(max->get()); + lastTimeout_ = *max; } } @@ -1522,6 +1552,15 @@ 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. + */ + frameLengths_.pop_front(); + frameLengths_.push_back(helper_->exposure(vblank + mode_.height, + helper_->hblankToLineLength(hblank))); } void IPARPi::applyDG(const struct AgcStatus *dgStatus, ControlList &ctrls) From patchwork Tue Mar 7 10:30:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18349 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 222EBC329C for ; Tue, 7 Mar 2023 10:30:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 26EFD626C9; Tue, 7 Mar 2023 11:30:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678185024; bh=lGYbbxoqtpGGSf8cC/frHzgSz4mi2oydf29mWnS4u/s=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=mzNDEKDAktkrNkXfVlaT4VNytGQuv079FI9ze9atp/swXtIAJuQSJ5LYlRbPU/7Q+ mxp53dBy0KZTXl89jKVH38O535vNBV/7573A0EFO7QvKt8FmsZRJbbCqnDD0Gi1BjX G3WfHKC2aY8R4hZtiUS+JBxe18lAM5P5QUzg6bW5CCV8mCchF/muUaUeoCMbZGmnh1 SMw5xrseZTqMdLEqnb7oTUdGAvI+JwG1uFkZs3AH3crqKB36K6RvVIilBpCVfL5/1m MV7XmjbtQKRRVATs+5IwQlE4joEjik7MYOjwQFSaiTAuFNTvvYK/pCAJSscrw+J5it SEJY487H1MxOQ== Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A4F77626B0 for ; Tue, 7 Mar 2023 11:30:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="RpjGoED6"; dkim-atps=neutral Received: by mail-wr1-x434.google.com with SMTP id e13so11572012wro.10 for ; Tue, 07 Mar 2023 02:30:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1678185021; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hf459/AQVIscT2N7Fl1SGWffRnnAiMEDRDiXUOvhwZQ=; b=RpjGoED6Z2R5cMy6MmTrUBs+dBXru/YHq7FiGyradTXMaq+MjoScdkFftSW71GGL5O 4kZxmMDPEsf4NBbc1BqM+MvbL3AniKHh3vEOT7YzzJcz6L+O0uOv0ykBtVMe7jAhFgBC D/ZXWH1mV1dsZrbrwzLVPEs7DK+EMKbSR9HZdVFXtQG8BcMdaZORZsnQOV2A6/bU5waa fxCx5o33AROD5wYheQBOKTkBAowYT1Bx99KjXfnRF+Gm9/fClADuKVlnd+rgML2jUPJ5 dJKvZs4OI38nw2RJagejSGBnSDuojOd/jO5DWlpnCsNSk7Xnlo5V1IU/R9KjO/rAGt9f 9GuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678185021; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hf459/AQVIscT2N7Fl1SGWffRnnAiMEDRDiXUOvhwZQ=; b=B02xWH6mLSDQZDGS4tmwTqKTbt/Z5bLWKUIMdLXWw37b/aOAuogaqGAri6CMxOcoyJ cq0N72+HeziP++RcRdkQVfQQLEJtDlUDktk0EyXUFpmjGefeUOPPBDafTBfb1cj6P3PR PT1+swTy8H3ssLvdt9Z7d13H0W76z25wjoPZLPqwCj2DpYxbMqhCca3UabyEXtl0GHvG fI1R8aMIGmfrgz1sCfHX9n280k67NGd3NX3IYqvShb5EUO4oXVXNuV6lOOHCdYWEAtRQ 5f7qchWit2NmGnTsQxNwZWkATqi1s1O7n1UL09yuSVCHXV3l7BLiKwWp1yI7xCtZD7lZ HiXw== X-Gm-Message-State: AO0yUKU0jY8oVWSSIM0JFvGILiXtHCJ0OG19AJsdG5mTVpacKZcMPVy6 zCmGW7TL+v0t1kZUPo/USopY5MY5BPLShWoiw6bMGQ== X-Google-Smtp-Source: AK7set/CrvW9fikQXhI0yhCk1XSp3F7Tkyt8l7v1GaPu72mxGmtHHex5yTYwhGU86bs/8Lv+mFCXQw== X-Received: by 2002:a05:6000:c4:b0:2c7:5247:e496 with SMTP id q4-20020a05600000c400b002c75247e496mr7801252wrx.60.1678185021068; Tue, 07 Mar 2023 02:30:21 -0800 (PST) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id r1-20020a056000014100b002c5534db60bsm12523621wrx.71.2023.03.07.02.30.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 02:30:20 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Mar 2023 10:30:23 +0000 Message-Id: <20230307103023.3932-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307103023.3932-1-naush@raspberrypi.com> References: <20230307103023.3932-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/3] pipeline: raspberrypi: Add a Unicam timeout override config options 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: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a new parameter to the pipeline handler config file named "unicam_timeout_value_ms" to allow users to override the automatically computed Unicam timeout value. This value is given in milliseconds, and setting a value of 0 (the default value) disables the override. An example use of this parameter would be if an application configured a RAW stream, and provides buffers for the stream on every request. If the application holds off on sending requests for a particular reason (e.g. a timelapse use case), then we will possibly hit the watchdog timeout as it is only a small multiple of the frame length. This override allows an application to select a larger value with the knowledge that it may space requests longer than the calculated timeout value. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- .../pipeline/raspberrypi/data/example.yaml | 11 ++++++++++- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/data/example.yaml b/src/libcamera/pipeline/raspberrypi/data/example.yaml index ad5f2344384f..c90f518f8849 100644 --- a/src/libcamera/pipeline/raspberrypi/data/example.yaml +++ b/src/libcamera/pipeline/raspberrypi/data/example.yaml @@ -32,6 +32,15 @@ # Override any request from the IPA to drop a number of startup # frames. # - # "disable_startup_frame_drops": false + # "disable_startup_frame_drops": false, + + # Custom timeout value (in ms) for Unicam to use. This overrides + # the value computed by the pipeline handler based on frame + # durations. + # + # Set this value to 0 to use the pipeline handler computed + # timeout value. + # + # "unicam_timeout_value_ms": 0, } } diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 3d04842a2440..58bab6b6e0d5 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -319,6 +319,11 @@ public: * frames. */ bool disableStartupFrameDrops; + /* + * Override the Unicam timeout value calculated by the IPA based + * on frame durations. + */ + unsigned int unicamTimeoutValue; }; Config config_; @@ -1715,6 +1720,7 @@ int RPiCameraData::loadPipelineConfiguration() .minUnicamBuffers = 2, .minTotalUnicamBuffers = 4, .disableStartupFrameDrops = false, + .unicamTimeoutValue = 0, }; char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RPI_CONFIG_FILE"); @@ -1750,6 +1756,14 @@ int RPiCameraData::loadPipelineConfiguration() phConfig["min_total_unicam_buffers"].get(config_.minTotalUnicamBuffers); config_.disableStartupFrameDrops = phConfig["disable_startup_frame_drops"].get(config_.disableStartupFrameDrops); + config_.unicamTimeoutValue = + phConfig["unicam_timeout_value_ms"].get(config_.unicamTimeoutValue); + + if (config_.unicamTimeoutValue) { + /* Disable the IPA signal to control timeout and set the user requested value. */ + ipa_->setCameraTimeout.disconnect(); + unicam_[Unicam::Image].dev()->setDequeueTimeout(config_.unicamTimeoutValue * 1ms); + } if (config_.minTotalUnicamBuffers < config_.minUnicamBuffers) { LOG(RPI, Error) << "Invalid configuration: min_total_unicam_buffers must be >= min_unicam_buffers";