{"id":10497,"url":"https://patchwork.libcamera.org/api/1.1/patches/10497/?format=json","web_url":"https://patchwork.libcamera.org/patch/10497/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20201125113640.20246-3-david.plowman@raspberrypi.com>","date":"2020-11-25T11:36:39","name":"[libcamera-devel,2/3] src: ipa: raspberrypi: Improve behaviour when AE disabled","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"27391b6cc9b32e5a9af090a7dc4ad6f3a3d55b00","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/1.1/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/10497/mbox/","series":[{"id":1481,"url":"https://patchwork.libcamera.org/api/1.1/series/1481/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1481","date":"2020-11-25T11:36:37","name":"Raspberry Pi AGC improvements","version":1,"mbox":"https://patchwork.libcamera.org/series/1481/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10497/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10497/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 285EEBE08A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 25 Nov 2020 11:36:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E908963407;\n\tWed, 25 Nov 2020 12:36:49 +0100 (CET)","from mail-wm1-x343.google.com (mail-wm1-x343.google.com\n\t[IPv6:2a00:1450:4864:20::343])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C202963407\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Nov 2020 12:36:48 +0100 (CET)","by mail-wm1-x343.google.com with SMTP id h21so1845720wmb.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Nov 2020 03:36:48 -0800 (PST)","from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tb14sm4232371wrq.47.2020.11.25.03.36.44\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 25 Nov 2020 03:36:44 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"Iq2JkBZ9\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=8JNci13+JNowdRzOWljkat5DoWfHKcSt76kigmtYf1I=;\n\tb=Iq2JkBZ9cLnNzpoT90BIWfEvQ8ph2GLT77sbU1+5SuHZouUkkZayfRPIzE4ewkh5bR\n\tRQLe1yz+PS3HVgDuUJkARoKcr5qVBKjqFzc0HOlXXJqWbJaJn+YacNLHU+6HFqs2gBod\n\t7AS0pcFkCtJFekqY44bjuLdI2OcFT6hZyXoQIcPjcwuU4F87YwK1XTtm/5JxEWK/XBW1\n\t2nksHrLv6BaWmBw3qswLVFC7krMi5ZeLZsGL+qH5ZBV4aMyjDodKyopFzcVjEUruQv+W\n\t9jOrnVdlO4r0Hw/Zs+EQ7HXSDtrB0Ohb4XvwTONrpjyOt6CgZASjplImqLBK/u3cfgat\n\tjD5w==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=8JNci13+JNowdRzOWljkat5DoWfHKcSt76kigmtYf1I=;\n\tb=FpbuAPudnfFfpnLvqUcYJpojsmNSFmn06Nv0pyTJg8hQZiLjdMtroj2r8Flz52h/0E\n\tZY6IvWeBz4rRNZMC/nwHgAZKCUN8Je7sUO9t9qcgbDCQf2LA/zotTp2PUa8G9VLwe72m\n\tg+Y9vYP2RYFmvyefpglFCoNjHeGh/VMl2KKEHc8Xuq/0hTgCwUACalUcSdQh0t1P4Xtb\n\t+e1rqBr3oZmeAsksiQ03/vkbIcUjepGwT45GXn2FWMvIzkU/H+KTi64EbA/xs3qrTxug\n\tFNePtUdlVQo7xcUpqEbMpNDljvV0HbAiWfobW5OUISz3b88SuzvsFxdH2UJGQ+qkhi+M\n\tL21A==","X-Gm-Message-State":"AOAM5337MYZdarWJAI2QGV/xA4r77r53WWoHsCKm1K/qN52cy1l+iSRV\n\twDW7BlpOCNjFjVHZVCNbAqLpB2J3+7Uv5Li2","X-Google-Smtp-Source":"ABdhPJzgW3YnFdVCbI8748rPfLX1rBt0tBmiM8I9cLEydgCqr0BBpEf5PuKqZ6bytsd5+59ANQV5FA==","X-Received":"by 2002:a1c:6a16:: with SMTP id f22mr3484527wmc.86.1606304205143;\n\tWed, 25 Nov 2020 03:36:45 -0800 (PST)","From":"David Plowman <david.plowman@raspberrypi.com>","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\n\tbehaviour when AE disabled","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"AE/AGC \"disabled\" is now implemented by leaving it running but fixing\nthe exposure/gain to the last values we requested. This behaves better\nwhen, for example, a fixed shutter or gain is then specified - the\nother value remains fixed and doesn't start floating again.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/raspberrypi.cpp | 48 ++++++++++++++++++-----------\n 1 file changed, 30 insertions(+), 18 deletions(-)","diff":"diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 9853a343..30516665 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -67,7 +67,8 @@ public:\n \tIPARPi()\n \t\t: lastMode_({}), controller_(), controllerInit_(false),\n \t\t  frameCount_(0), checkCount_(0), mistrustCount_(0),\n-\t\t  lsTable_(nullptr)\n+\t\t  lsTable_(nullptr),\n+\t\t  lastShutter_(0), lastGain_(0)\n \t{\n \t}\n \n@@ -145,6 +146,10 @@ private:\n \t/* LS table allocation passed in from the pipeline handler. */\n \tFileDescriptor lsTableHandle_;\n \tvoid *lsTable_;\n+\n+\t/* For enabling/disabling the AEC/AGC algorithm. */\n+\tuint32_t lastShutter_;\n+\tfloat lastGain_;\n };\n \n int IPARPi::init(const IPASettings &settings)\n@@ -493,12 +498,22 @@ void IPARPi::queueRequest(const ControlList &controls)\n \n \t\tswitch (ctrl.first) {\n \t\tcase controls::AE_ENABLE: {\n-\t\t\tRPiController::Algorithm *agc = controller_.GetAlgorithm(\"agc\");\n+\t\t\tRPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(\n+\t\t\t\tcontroller_.GetAlgorithm(\"agc\"));\n \t\t\tASSERT(agc);\n-\t\t\tif (ctrl.second.get<bool>() == false)\n-\t\t\t\tagc->Pause();\n-\t\t\telse\n-\t\t\t\tagc->Resume();\n+\n+\t\t\t/*\n+\t\t\t * We always run the AGC even if it's \"disabled\".\n+\t\t\t * Both exposure and gain are \"fixed\" to the last\n+\t\t\t * values it produced.\n+\t\t\t */\n+\t\t\tif (ctrl.second.get<bool>() == false) {\n+\t\t\t\tagc->SetFixedShutter(lastShutter_);\n+\t\t\t\tagc->SetFixedAnalogueGain(lastGain_);\n+\t\t\t} else {\n+\t\t\t\tagc->SetFixedShutter(0);\n+\t\t\t\tagc->SetFixedAnalogueGain(0);\n+\t\t\t}\n \n \t\t\tlibcameraMetadata_.set(controls::AeEnable, ctrl.second.get<bool>());\n \t\t\tbreak;\n@@ -510,13 +525,10 @@ void IPARPi::queueRequest(const ControlList &controls)\n \t\t\tASSERT(agc);\n \n \t\t\t/* This expects units of micro-seconds. */\n-\t\t\tagc->SetFixedShutter(ctrl.second.get<int32_t>());\n+\t\t\tint32_t shutter = ctrl.second.get<int32_t>();\n+\t\t\tagc->SetFixedShutter(shutter);\n \n-\t\t\t/* For the manual values to take effect, AGC must be unpaused. */\n-\t\t\tif (agc->IsPaused())\n-\t\t\t\tagc->Resume();\n-\n-\t\t\tlibcameraMetadata_.set(controls::ExposureTime, ctrl.second.get<int32_t>());\n+\t\t\tlibcameraMetadata_.set(controls::ExposureTime, shutter);\n \t\t\tbreak;\n \t\t}\n \n@@ -524,14 +536,11 @@ void IPARPi::queueRequest(const ControlList &controls)\n \t\t\tRPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(\n \t\t\t\tcontroller_.GetAlgorithm(\"agc\"));\n \t\t\tASSERT(agc);\n-\t\t\tagc->SetFixedAnalogueGain(ctrl.second.get<float>());\n \n-\t\t\t/* For the manual values to take effect, AGC must be unpaused. */\n-\t\t\tif (agc->IsPaused())\n-\t\t\t\tagc->Resume();\n+\t\t\tfloat gain = ctrl.second.get<float>();\n+\t\t\tagc->SetFixedAnalogueGain(gain);\n \n-\t\t\tlibcameraMetadata_.set(controls::AnalogueGain,\n-\t\t\t\t\t       ctrl.second.get<float>());\n+\t\t\tlibcameraMetadata_.set(controls::AnalogueGain, gain);\n \t\t\tbreak;\n \t\t}\n \n@@ -861,6 +870,9 @@ void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)\n \n void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls)\n {\n+\tlastShutter_ = agcStatus->shutter_time;\n+\tlastGain_ = agcStatus->analogue_gain;\n+\n \tint32_t gainCode = helper_->GainCode(agcStatus->analogue_gain);\n \tint32_t exposureLines = helper_->ExposureLines(agcStatus->shutter_time);\n \n","prefixes":["libcamera-devel","2/3"]}