From patchwork Wed Nov 25 11:36:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10495 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 39AF7BE08A for ; Wed, 25 Nov 2020 11:36:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 127C56340E; Wed, 25 Nov 2020 12:36:46 +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="GUygUYkn"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BED31633E5 for ; Wed, 25 Nov 2020 12:36:44 +0100 (CET) Received: by mail-wm1-x333.google.com with SMTP id p22so1709580wmg.3 for ; Wed, 25 Nov 2020 03:36:44 -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=1xhsu7HrWSngEnUv4/MVRgNPdbfcwpnU4q9jZTtkWVE=; b=GUygUYkngH3ght4L5X4deW+lpzQMRwfcEUG3UBwc4CrFHysYYWU2MqHNJ8BmDO/YeN 5Yc6xgF4ppy9Zj3HaKb94RCpOUDquoaw63SqRi9izQfcPDScCvDUZ/Ecx2rnE69lIlE6 BoRvhf/tXh6BFOeKaFOwvPrYsezPARCzrd8LbhbeIRXBl2rXuYSJbXaAfK3aDxad58pb S645xz3kxcaTt0Y44+Q2LG6pYIsU6PDWqtRcMHcgek4kz3re4+fl213EGePMc1lxaYYk rNev9JzD79qVJZiDT0nKPkup+6QZZFZya7S6KSpkdq0E5naDsQGFQq4phgagxk3ZMbU0 Z6sA== 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=1xhsu7HrWSngEnUv4/MVRgNPdbfcwpnU4q9jZTtkWVE=; b=GDs8wDBP5yPITCLqaZi7VbVfa5MuXOBn5pFY3aVcN93rQsBofpzOC3yD7TvNYm42J/ xxqwI9+JbrvEkELeWRIEyeGmIGO64THAUuCqtO+8xBrjlovVGAqZb+0oV+muXKF7J2VT U7DUGkEGRaFqHYPlohpCp76WbL7mq9+IgSLhoM8QjbuFwxdGm1GIQU0jQvR4H2vXTSN4 yQzA2ftjMt22FSrk3d+zcgeczMGziCCmDLe9MlJ7nUHGYyo9Hcgt28JE/78KFMpY+7CR QwuZFHhu1ayDjCX8q8f8LasmiI/nagcoPfqqYi9NoVcc3xM2+btSRh3NEGxEN0anwZy9 A00g== X-Gm-Message-State: AOAM532Y2I2iJsud2PDFGL2PUrOHfNwv5mbe8GAYZBMJ89v78Ix/tq2C n5B9QhBWdZiaLDJN8xPlsHwEs141/jJyTgDo X-Google-Smtp-Source: ABdhPJweoT2od3sUHar8wPqOc+Yfv9xhUVIO2Ia3pLWwIm8KfN5mxiZOa/K4jbxLYbxrkDEgLKufWQ== X-Received: by 2002:a1c:2b05:: with SMTP id r5mr3350705wmr.179.1606304204270; Wed, 25 Nov 2020 03:36:44 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id b14sm4232371wrq.47.2020.11.25.03.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 03:36:43 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 25 Nov 2020 11:36:38 +0000 Message-Id: <20201125113640.20246-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201125113640.20246-1-david.plowman@raspberrypi.com> References: <20201125113640.20246-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] src: ipa: raspberrypi: Avoid AGC filtering when both gain and shutter specified 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" When both gain and shutter have been directly specified, do not filter slowly towards those target values, but adopt them immediately. This should match user expectations better. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/rpi/agc.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index 4c56bdc9..30a1c1c1 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -588,7 +588,12 @@ bool Agc::applyDigitalGain(double gain, double target_Y) void Agc::filterExposure(bool desaturate) { - double speed = frame_count_ <= config_.startup_frames ? 1.0 : config_.speed; + double speed = config_.speed; + // AGC adapts instantly if both shutter and gain are directly specified + // or we're in the startup phase. + if ((status_.fixed_shutter && status_.fixed_analogue_gain) || + frame_count_ <= config_.startup_frames) + speed = 1.0; if (filtered_.total_exposure == 0.0) { filtered_.total_exposure = target_.total_exposure; filtered_.total_exposure_no_dg = target_.total_exposure_no_dg; From patchwork Wed Nov 25 11:36:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10497 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 285EEBE08A for ; Wed, 25 Nov 2020 11:36:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E908963407; Wed, 25 Nov 2020 12:36:49 +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="Iq2JkBZ9"; dkim-atps=neutral Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C202963407 for ; Wed, 25 Nov 2020 12:36:48 +0100 (CET) Received: by mail-wm1-x343.google.com with SMTP id h21so1845720wmb.2 for ; Wed, 25 Nov 2020 03:36:48 -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=8JNci13+JNowdRzOWljkat5DoWfHKcSt76kigmtYf1I=; b=Iq2JkBZ9cLnNzpoT90BIWfEvQ8ph2GLT77sbU1+5SuHZouUkkZayfRPIzE4ewkh5bR RQLe1yz+PS3HVgDuUJkARoKcr5qVBKjqFzc0HOlXXJqWbJaJn+YacNLHU+6HFqs2gBod 7AS0pcFkCtJFekqY44bjuLdI2OcFT6hZyXoQIcPjcwuU4F87YwK1XTtm/5JxEWK/XBW1 2nksHrLv6BaWmBw3qswLVFC7krMi5ZeLZsGL+qH5ZBV4aMyjDodKyopFzcVjEUruQv+W 9jOrnVdlO4r0Hw/Zs+EQ7HXSDtrB0Ohb4XvwTONrpjyOt6CgZASjplImqLBK/u3cfgat jD5w== 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=8JNci13+JNowdRzOWljkat5DoWfHKcSt76kigmtYf1I=; b=FpbuAPudnfFfpnLvqUcYJpojsmNSFmn06Nv0pyTJg8hQZiLjdMtroj2r8Flz52h/0E ZY6IvWeBz4rRNZMC/nwHgAZKCUN8Je7sUO9t9qcgbDCQf2LA/zotTp2PUa8G9VLwe72m g+Y9vYP2RYFmvyefpglFCoNjHeGh/VMl2KKEHc8Xuq/0hTgCwUACalUcSdQh0t1P4Xtb +e1rqBr3oZmeAsksiQ03/vkbIcUjepGwT45GXn2FWMvIzkU/H+KTi64EbA/xs3qrTxug FNePtUdlVQo7xcUpqEbMpNDljvV0HbAiWfobW5OUISz3b88SuzvsFxdH2UJGQ+qkhi+M L21A== X-Gm-Message-State: AOAM5337MYZdarWJAI2QGV/xA4r77r53WWoHsCKm1K/qN52cy1l+iSRV wDW7BlpOCNjFjVHZVCNbAqLpB2J3+7Uv5Li2 X-Google-Smtp-Source: ABdhPJzgW3YnFdVCbI8748rPfLX1rBt0tBmiM8I9cLEydgCqr0BBpEf5PuKqZ6bytsd5+59ANQV5FA== X-Received: by 2002:a1c:6a16:: with SMTP id f22mr3484527wmc.86.1606304205143; Wed, 25 Nov 2020 03:36:45 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id b14sm4232371wrq.47.2020.11.25.03.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 03:36:44 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 25 Nov 2020 11:36:39 +0000 Message-Id: <20201125113640.20246-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201125113640.20246-1-david.plowman@raspberrypi.com> References: <20201125113640.20246-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] src: ipa: raspberrypi: Improve behaviour when AE disabled 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" AE/AGC "disabled" is now implemented by leaving it running but fixing the exposure/gain to the last values we requested. This behaves better when, for example, a fixed shutter or gain is then specified - the other value remains fixed and doesn't start floating again. Signed-off-by: David Plowman --- src/ipa/raspberrypi/raspberrypi.cpp | 48 ++++++++++++++++++----------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 9853a343..30516665 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -67,7 +67,8 @@ public: IPARPi() : lastMode_({}), controller_(), controllerInit_(false), frameCount_(0), checkCount_(0), mistrustCount_(0), - lsTable_(nullptr) + lsTable_(nullptr), + lastShutter_(0), lastGain_(0) { } @@ -145,6 +146,10 @@ private: /* LS table allocation passed in from the pipeline handler. */ FileDescriptor lsTableHandle_; void *lsTable_; + + /* For enabling/disabling the AEC/AGC algorithm. */ + uint32_t lastShutter_; + float lastGain_; }; int IPARPi::init(const IPASettings &settings) @@ -493,12 +498,22 @@ void IPARPi::queueRequest(const ControlList &controls) switch (ctrl.first) { case controls::AE_ENABLE: { - RPiController::Algorithm *agc = controller_.GetAlgorithm("agc"); + RPiController::AgcAlgorithm *agc = dynamic_cast( + controller_.GetAlgorithm("agc")); ASSERT(agc); - if (ctrl.second.get() == false) - agc->Pause(); - else - agc->Resume(); + + /* + * We always run the AGC even if it's "disabled". + * Both exposure and gain are "fixed" to the last + * values it produced. + */ + if (ctrl.second.get() == false) { + agc->SetFixedShutter(lastShutter_); + agc->SetFixedAnalogueGain(lastGain_); + } else { + agc->SetFixedShutter(0); + agc->SetFixedAnalogueGain(0); + } libcameraMetadata_.set(controls::AeEnable, ctrl.second.get()); break; @@ -510,13 +525,10 @@ void IPARPi::queueRequest(const ControlList &controls) ASSERT(agc); /* This expects units of micro-seconds. */ - agc->SetFixedShutter(ctrl.second.get()); + int32_t shutter = ctrl.second.get(); + agc->SetFixedShutter(shutter); - /* For the manual values to take effect, AGC must be unpaused. */ - if (agc->IsPaused()) - agc->Resume(); - - libcameraMetadata_.set(controls::ExposureTime, ctrl.second.get()); + libcameraMetadata_.set(controls::ExposureTime, shutter); break; } @@ -524,14 +536,11 @@ void IPARPi::queueRequest(const ControlList &controls) RPiController::AgcAlgorithm *agc = dynamic_cast( controller_.GetAlgorithm("agc")); ASSERT(agc); - agc->SetFixedAnalogueGain(ctrl.second.get()); - /* For the manual values to take effect, AGC must be unpaused. */ - if (agc->IsPaused()) - agc->Resume(); + float gain = ctrl.second.get(); + agc->SetFixedAnalogueGain(gain); - libcameraMetadata_.set(controls::AnalogueGain, - ctrl.second.get()); + libcameraMetadata_.set(controls::AnalogueGain, gain); break; } @@ -861,6 +870,9 @@ void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls) void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) { + lastShutter_ = agcStatus->shutter_time; + lastGain_ = agcStatus->analogue_gain; + int32_t gainCode = helper_->GainCode(agcStatus->analogue_gain); int32_t exposureLines = helper_->ExposureLines(agcStatus->shutter_time); From patchwork Wed Nov 25 11:36:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10496 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 A2402BE08A for ; Wed, 25 Nov 2020 11:36:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 71AA463411; Wed, 25 Nov 2020 12:36:48 +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="pZDBDZMO"; dkim-atps=neutral Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8ACDF6340A for ; Wed, 25 Nov 2020 12:36:46 +0100 (CET) Received: by mail-wr1-x42f.google.com with SMTP id g14so1555333wrm.13 for ; Wed, 25 Nov 2020 03:36:46 -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=CE6uEHlIE9O8XYmvvI4ab7mE8mycSjsTt8W0hUgGoYk=; b=pZDBDZMOy3g8HM0Xy4I8mFRiNHhvwkW4TkLTVKXmLANKvvXL/nwk3j52SHAc2CW3mz VT0M28r+cGm/ZAFrkeF7mWIHljaNuNwHZFKXIkS1Ew+3G7LcytfJWkNa8lzAQWKpU6qv +eOBSGeJR7RinridiwjUNzvhwNHA5KhRvcSVixIvw7iv4QjpPMkOLfws2A7qTVnb132J 6OdhwQ3GFYZWHt0RxVqlMwf8PYAtTFowIoXkh3C+FP6cR4HtGRZmcmh1AFid0y6QxQHU 7LHJ/fUA+nbPWUkM1iSXM+Z0RJ0VIqvEIqiybQGFNFQ89d+iYz7qoA6wxhop4KMssPUL 3tTA== 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=CE6uEHlIE9O8XYmvvI4ab7mE8mycSjsTt8W0hUgGoYk=; b=KK65O21R9ormomJq6Ja+GJvBZ+/EKx8PZqrAJH6sTSF+a51m2CVVDKBMw77NIOKy0Q SLyr4cirEJCSpGF4TXocpAzLlZvuD+AHKJiDiWfmcpwMxuHgSBbyaxVhz6p6VpV9ASiy +jwGsu0YJqY0ac1lSjNhm0xiHK4S/a2ktQNCCwJ18qb+JZzpDWQ4TTjb9LylYjY0mkhB PIAQ0iUiSQkd0cIYOKKeFEGymJqpdUSV6t4nkEzP5WLqrVXJ+x58xUDCHCYHDyitr7Yi F74mfUk6XAdTkiwi6kHgADr4mPKDE1RTqhjwKmOqTyIxp+fuZhVeqPCPUtxcgkq5izPO nkAA== X-Gm-Message-State: AOAM530FkFaQglXh/7T15tOIPajQWSNn9wcVBY+zlf45A2ZcXxV2006p TFoFEC90JW0OCYNXZSi9dJfMKBkfGhhVxdIW X-Google-Smtp-Source: ABdhPJyzpwId8Om6RMRyva/4Z8sRQXxY/rehZmKDkhpDeAILC6XLUkQ+p0pZYfDqXUTccgFGcQDh+Q== X-Received: by 2002:adf:f98a:: with SMTP id f10mr3663644wrr.154.1606304205971; Wed, 25 Nov 2020 03:36:45 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id b14sm4232371wrq.47.2020.11.25.03.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 03:36:45 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 25 Nov 2020 11:36:40 +0000 Message-Id: <20201125113640.20246-4-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201125113640.20246-1-david.plowman@raspberrypi.com> References: <20201125113640.20246-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] src: ipa: raspberrypi: Fix initial AGC oscillation for imx219 sensor 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" The exposure times in the exposure modes were causing AGC oscillations because the algorithm was demanding long unachievable exposure times but, without working sensor metadata, thought it was getting them when actually it was not. We fix it by making the exposure profile request only achievable exposure times, as we do for the ov5647 tuning. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/data/imx219.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ipa/raspberrypi/data/imx219.json b/src/ipa/raspberrypi/data/imx219.json index b03a7beb..212f8b9a 100644 --- a/src/ipa/raspberrypi/data/imx219.json +++ b/src/ipa/raspberrypi/data/imx219.json @@ -133,7 +133,7 @@ { "shutter": [ - 100, 10000, 30000, 60000, 120000 + 100, 10000, 30000, 30000, 30000 ], "gain": [ @@ -144,7 +144,7 @@ { "shutter": [ - 100, 5000, 10000, 20000, 120000 + 100, 5000, 10000, 20000, 30000 ], "gain": [