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);