From patchwork Tue Dec 8 20:44:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10618 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 BA8E6BDB21 for ; Tue, 8 Dec 2020 20:44:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 84EE267E6F; Tue, 8 Dec 2020 21:44:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Z3cgVBkH"; dkim-atps=neutral Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A918367F0B for ; Tue, 8 Dec 2020 21:44:50 +0100 (CET) Received: by mail-ed1-x52f.google.com with SMTP id q16so18975754edv.10 for ; Tue, 08 Dec 2020 12:44:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XdEmnit+rjT7DnH9yrl+C0JlXKdX3fb/QjsepWpG/tE=; b=Z3cgVBkHSUy9aY0kQDP+aifbzn7/IY8H8WpGujdVK69QZb7GaOZPqkN2lBwzinTGep MTc5VOsBpWLfutTqdwGlzGgqpOcbx99AB78ftQSHY8h2vAq65AZLBnuueXCD5IdJYppT PGNfM+F6qryNsW9d9TXkXQ5HDk2Nf/r6lsgFE/r5YMLJf4/AePxN84U3b9GXV8zpzUaY DsNZWJQfN+wzNTXOyrKplLX0hyH4bdlsIGoo8QJw/M6YDw0W2b/WyqzVz52kqQ9NpSmE rAHRyHWqdSUwUrUtCJuxLQj/JzXq6sxHUSsVvNRVriOOzRcN/N2OPIyyKVwJMHmJElD7 TuuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XdEmnit+rjT7DnH9yrl+C0JlXKdX3fb/QjsepWpG/tE=; b=mpAJT1bdT/3pElL27N60PE2YZmnWcjA8JSa4P+V6+AoUMGT3CXSjh8YsbXqCz1taoq B6bDQiAd5DvTCpchYwwC+ftX5OiO8qfTkJe5mqJamvWCCoAyqCliqxuBtaX+gwRJSDPq e1xRnNeW5aTU4UclPTb+Q2xFhXjt1IRSqJYRChDFr+79l8nq7nZIKLOyZyslgsqmx+Gl cNIbvu0lk2GZw26CWS4B7H7Hutd8hVbKACrkTfXhbhIH+pxCjUpUcHRl/CRNHBNzmr+a eppPd9wRfirLL4oNPoh/IeAMGN2voLMd10IhWS49ZUESEuP70xp1e3/iMiekJJx49Mvn gKeA== X-Gm-Message-State: AOAM5307Q4R6ESZkdtKkbAv0HE67G/+2iEqPQeRngUfRCjA9XEVW1swl kDRLodeIbWeW+u849Q8mDyXu+qw9cyV+tvXK X-Google-Smtp-Source: ABdhPJxJz/mT7ygHLT715uCKSlIAFp1G3ZmFKxLqUujpXs/hObqexjFLAGo/wpWwwmEYec8I/UQfNQ== X-Received: by 2002:a50:875b:: with SMTP id 27mr26588440edv.24.1607460290050; Tue, 08 Dec 2020 12:44:50 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id be6sm18441471edb.29.2020.12.08.12.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 12:44:49 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Dec 2020 20:44:41 +0000 Message-Id: <20201208204441.9356-7-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201208204441.9356-1-david.plowman@raspberrypi.com> References: <20201208204441.9356-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 6/6] src: ipa: raspberrypi: Move initial frame drop decision to AGC/AWB 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Previously the CamHelper was returning the number of frames to drop (on account of AGC/AWB converging). This wasn't really appropriate, it's better for the algorithms to do it as they know how many frames they might need. The CamHelper::HideFramesStartup method should now just be returning the number of frames to hide because they're bad/invalid in some way, not worrying about the AGC/AWB. For many sensors, the correct value for this is zero. But the ov5647 needs updating as it must return 2. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/cam_helper.cpp | 6 ++--- src/ipa/raspberrypi/cam_helper_ov5647.cpp | 10 ++++++++ src/ipa/raspberrypi/raspberrypi.cpp | 28 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index c8ac3232..6efa0d7f 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -82,10 +82,10 @@ bool CamHelper::SensorEmbeddedDataPresent() const unsigned int CamHelper::HideFramesStartup() const { /* - * By default, hide 6 frames completely at start-up while AGC etc. sort - * themselves out (converge). + * The number of frames when a camera first starts that shouldn't be + * displayed as they are invalid in some way. */ - return 6; + return 0; } unsigned int CamHelper::HideFramesModeSwitch() const diff --git a/src/ipa/raspberrypi/cam_helper_ov5647.cpp b/src/ipa/raspberrypi/cam_helper_ov5647.cpp index dc5d8275..0b841cd1 100644 --- a/src/ipa/raspberrypi/cam_helper_ov5647.cpp +++ b/src/ipa/raspberrypi/cam_helper_ov5647.cpp @@ -19,6 +19,7 @@ public: uint32_t GainCode(double gain) const override; double Gain(uint32_t gain_code) const override; void GetDelays(int &exposure_delay, int &gain_delay) const override; + unsigned int HideFramesStartup() const override; unsigned int HideFramesModeSwitch() const override; unsigned int MistrustFramesStartup() const override; unsigned int MistrustFramesModeSwitch() const override; @@ -54,6 +55,15 @@ void CamHelperOv5647::GetDelays(int &exposure_delay, int &gain_delay) const gain_delay = 2; } +unsigned int CamHelperOv5647::HideFramesStartup() const +{ + /* + * On startup, we get a couple of under-exposed frames which + * we don't want shown. + */ + return 2; +} + unsigned int CamHelperOv5647::HideFramesModeSwitch() const { /* diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index ba63480e..8dd796ed 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -194,6 +194,34 @@ int IPARPi::start(const IPAOperationData &data, IPAOperationData *result) if (firstStart_) { dropFrame = helper_->HideFramesStartup(); mistrustCount_ = helper_->MistrustFramesStartup(); + + /* + * Query the AGC/AWB for how many frames they may take to + * converge sufficiently. Where these numbers are non-zero + * we must allow for the frames with bad statistics + * (mistrustCount_) that they won't see. But if zero (i.e. + * no convergence necessary), no frames need to be dropped. + */ + unsigned int agcConvergenceFrames = 0; + RPiController::AgcAlgorithm *agc = dynamic_cast( + controller_.GetAlgorithm("agc")); + if (agc) { + agcConvergenceFrames = agc->GetConvergenceFrames(); + if (agcConvergenceFrames) + agcConvergenceFrames += mistrustCount_; + } + + unsigned int awbConvergenceFrames = 0; + RPiController::AwbAlgorithm *awb = dynamic_cast( + controller_.GetAlgorithm("awb")); + if (awb) { + awbConvergenceFrames = awb->GetConvergenceFrames(); + if (awbConvergenceFrames) + awbConvergenceFrames += mistrustCount_; + } + + dropFrame = std::max({ dropFrame, agcConvergenceFrames, awbConvergenceFrames }); + LOG(IPARPI, Debug) << "Drop " << dropFrame << " frames on startup"; } else { dropFrame = helper_->HideFramesModeSwitch(); mistrustCount_ = helper_->MistrustFramesModeSwitch();