{"id":15181,"url":"https://patchwork.libcamera.org/api/patches/15181/?format=json","web_url":"https://patchwork.libcamera.org/patch/15181/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20211221043610.2512334-4-paul.elder@ideasonboard.com>","date":"2021-12-21T04:36:05","name":"[libcamera-devel,v3,3/8] libcamera: pipeline: raspberrypi: Support the new AE controls","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"d523991e7e1674320df688cf7dc908c1605ecfcd","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":{"id":17,"url":"https://patchwork.libcamera.org/api/users/17/?format=json","username":"epaul","first_name":"Paul","last_name":"Elder","email":"paul.elder@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/15181/mbox/","series":[{"id":2849,"url":"https://patchwork.libcamera.org/api/series/2849/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2849","date":"2021-12-21T04:36:02","name":"The Great AE Changes","version":3,"mbox":"https://patchwork.libcamera.org/series/2849/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15181/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15181/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 E2C18C3258\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 21 Dec 2021 04:36:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5B71B608FD;\n\tTue, 21 Dec 2021 05:36:26 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CCF94608E8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 21 Dec 2021 05:36:22 +0100 (CET)","from pyrite.mediacom.info (unknown\n\t[IPv6:2604:2d80:ad90:fb00:96fd:8874:873:6c16])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0B8D2881;\n\tTue, 21 Dec 2021 05:36:21 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"pjmfHhYy\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1640061382;\n\tbh=xeuyaNCaNS1VCUnxH5qrJU+44XXUrBA/zwpl1s4vbto=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=pjmfHhYyEGo4t7xMK3N6kS1ZluiEtQNreteTu9HssvSE2jZITFrWNUSbDieJGadYn\n\toG4EXVc02QsYZxZuDDSeFLRfOBb8RX56ZDjI3GbMdRjbN7YRPMAP8kbcQCqJWReeSD\n\t07cfBs6oO54rT/Nl5GKDWeLpZMAWIuOG1L6mwj9k=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 20 Dec 2021 22:36:05 -0600","Message-Id":"<20211221043610.2512334-4-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20211221043610.2512334-1-paul.elder@ideasonboard.com>","References":"<20211221043610.2512334-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 3/8] libcamera: pipeline: raspberrypi:\n\tSupport the new AE controls","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add support for the new AE controls in the raspberrypi pipeline handler,\nand in the IPA.\n\nBug: https://bugs.libcamera.org/show_bug.cgi?id=42\nBug: https://bugs.libcamera.org/show_bug.cgi?id=43\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nChanges in v3:\n- s/Exposure/Shutter/\n- move the new Pause/Resume functions to AgcAlgorithm\n  - update callers as appropriate\n- make the original Pause/Resume functions call the new ones\n\nChanges in v2:\n- fix the rebase error where some uvc stuff was in rasberrypi\n- i haven't yet taken in the comments to move the new Pause/Resume\n  functions\n\nInitial versoin:\nThis is very hacky. I wasn't sure what the best way was to plumb it into\nthe raspberrypi IPA as it was a bit hairy...\n---\n include/libcamera/ipa/raspberrypi.h           |  3 +-\n .../raspberrypi/controller/agc_algorithm.hpp  |  4 ++\n src/ipa/raspberrypi/controller/rpi/agc.cpp    | 22 +++++++++-\n src/ipa/raspberrypi/controller/rpi/agc.hpp    |  5 +++\n src/ipa/raspberrypi/raspberrypi.cpp           | 42 +++++++++++++++----\n 5 files changed, 66 insertions(+), 10 deletions(-)","diff":"diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h\nindex 7f705e49..672b85a5 100644\n--- a/include/libcamera/ipa/raspberrypi.h\n+++ b/include/libcamera/ipa/raspberrypi.h\n@@ -28,8 +28,9 @@ namespace RPi {\n  * unsupported control is encountered.\n  */\n static const ControlInfoMap Controls({\n-\t\t{ &controls::AeEnable, ControlInfo(false, true) },\n+\t\t{ &controls::ExposureTimeMode, ControlInfo(controls::ExposureTimeModeValues) },\n \t\t{ &controls::ExposureTime, ControlInfo(0, 999999) },\n+\t\t{ &controls::AnalogueGainMode, ControlInfo(controls::AnalogueGainModeValues) },\n \t\t{ &controls::AnalogueGain, ControlInfo(1.0f, 32.0f) },\n \t\t{ &controls::AeMeteringMode, ControlInfo(controls::AeMeteringModeValues) },\n \t\t{ &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) },\ndiff --git a/src/ipa/raspberrypi/controller/agc_algorithm.hpp b/src/ipa/raspberrypi/controller/agc_algorithm.hpp\nindex 61595ea2..538cfa88 100644\n--- a/src/ipa/raspberrypi/controller/agc_algorithm.hpp\n+++ b/src/ipa/raspberrypi/controller/agc_algorithm.hpp\n@@ -27,6 +27,10 @@ public:\n \tvirtual void SetExposureMode(std::string const &exposure_mode_name) = 0;\n \tvirtual void\n \tSetConstraintMode(std::string const &contraint_mode_name) = 0;\n+\tvirtual void PauseShutter();\n+\tvirtual void PauseGain();\n+\tvirtual void ResumeShutter();\n+\tvirtual void ResumeGain();\n };\n \n } // namespace RPiController\ndiff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\nindex f6a9cb0a..14d6e024 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n@@ -210,14 +210,34 @@ bool Agc::IsPaused() const\n }\n \n void Agc::Pause()\n+{\n+\tPauseShutter();\n+\tPauseGain();\n+}\n+\n+void Agc::Resume()\n+{\n+\tResumeShutter();\n+\tResumeGain();\n+}\n+\n+void Agc::PauseShutter()\n {\n \tfixed_shutter_ = status_.shutter_time;\n+}\n+\n+void Agc::PauseGain()\n+{\n \tfixed_analogue_gain_ = status_.analogue_gain;\n }\n \n-void Agc::Resume()\n+void Agc::ResumeShutter()\n {\n \tfixed_shutter_ = 0s;\n+}\n+\n+void Agc::ResumeGain()\n+{\n \tfixed_analogue_gain_ = 0;\n }\n \ndiff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp\nindex c100d312..af4c72ff 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.hpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp\n@@ -90,6 +90,11 @@ public:\n \tvoid Prepare(Metadata *image_metadata) override;\n \tvoid Process(StatisticsPtr &stats, Metadata *image_metadata) override;\n \n+\tvoid PauseShutter() override;\n+\tvoid PauseGain() override;\n+\tvoid ResumeShutter() override;\n+\tvoid ResumeGain() override;\n+\n private:\n \tvoid updateLockStatus(DeviceStatus const &device_status);\n \tAgcConfig config_;\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 0ed41385..9bea16e7 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -53,6 +53,8 @@\n #include \"sharpen_algorithm.hpp\"\n #include \"sharpen_status.h\"\n \n+#include \"controller/rpi/agc.hpp\"\n+\n namespace libcamera {\n \n using namespace std::literals::chrono_literals;\n@@ -483,7 +485,10 @@ void IPARPi::reportMetadata()\n \n \tAgcStatus *agcStatus = rpiMetadata_.GetLocked<AgcStatus>(\"agc.status\");\n \tif (agcStatus) {\n-\t\tlibcameraMetadata_.set(controls::AeLocked, agcStatus->locked);\n+\t\tlibcameraMetadata_.set(controls::AeState,\n+\t\t\t\t       agcStatus->locked ?\n+\t\t\t\t       controls::AeStateConverged :\n+\t\t\t\t       controls::AeStateSearching);\n \t\tlibcameraMetadata_.set(controls::DigitalGain, agcStatus->digital_gain);\n \t}\n \n@@ -628,20 +633,22 @@ void IPARPi::queueRequest(const ControlList &controls)\n \t\t\t\t  << \" = \" << ctrl.second.toString();\n \n \t\tswitch (ctrl.first) {\n-\t\tcase controls::AE_ENABLE: {\n-\t\t\tRPiController::Algorithm *agc = controller_.GetAlgorithm(\"agc\");\n+\t\tcase controls::EXPOSURE_TIME_MODE: {\n+\t\t\tRPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(\n+\t\t\t\tcontroller_.GetAlgorithm(\"agc\"));\n \t\t\tif (!agc) {\n \t\t\t\tLOG(IPARPI, Warning)\n-\t\t\t\t\t<< \"Could not set AE_ENABLE - no AGC algorithm\";\n+\t\t\t\t\t<< \"Could not set EXPOSURE_TIME_MODE - no AGC algorithm\";\n \t\t\t\tbreak;\n \t\t\t}\n \n-\t\t\tif (ctrl.second.get<bool>() == false)\n-\t\t\t\tagc->Pause();\n+\t\t\tif (ctrl.second.get<int32_t>() == controls::ExposureTimeModeDisabled)\n+\t\t\t\tagc->PauseShutter();\n \t\t\telse\n-\t\t\t\tagc->Resume();\n+\t\t\t\tagc->ResumeShutter();\n \n-\t\t\tlibcameraMetadata_.set(controls::AeEnable, ctrl.second.get<bool>());\n+\t\t\tlibcameraMetadata_.set(controls::ExposureTimeMode,\n+\t\t\t\t\t       ctrl.second.get<int32_t>());\n \t\t\tbreak;\n \t\t}\n \n@@ -661,6 +668,25 @@ void IPARPi::queueRequest(const ControlList &controls)\n \t\t\tbreak;\n \t\t}\n \n+\t\tcase controls::ANALOGUE_GAIN_MODE: {\n+\t\t\tRPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(\n+\t\t\t\tcontroller_.GetAlgorithm(\"agc\"));\n+\t\t\tif (!agc) {\n+\t\t\t\tLOG(IPARPI, Warning)\n+\t\t\t\t\t<< \"Could not set ANALOGUE_GAIN_MODE - no AGC algorithm\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tif (ctrl.second.get<int32_t>() == controls::AnalogueGainModeDisabled)\n+\t\t\t\tagc->PauseGain();\n+\t\t\telse\n+\t\t\t\tagc->ResumeGain();\n+\n+\t\t\tlibcameraMetadata_.set(controls::AnalogueGainMode,\n+\t\t\t\t\t       ctrl.second.get<int32_t>());\n+\t\t\tbreak;\n+\t\t}\n+\n \t\tcase controls::ANALOGUE_GAIN: {\n \t\t\tRPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(\n \t\t\t\tcontroller_.GetAlgorithm(\"agc\"));\n","prefixes":["libcamera-devel","v3","3/8"]}