{"id":18821,"url":"https://patchwork.libcamera.org/api/patches/18821/?format=json","web_url":"https://patchwork.libcamera.org/patch/18821/","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":"<20230713151218.26045-3-david.plowman@raspberrypi.com>","date":"2023-07-13T15:12:18","name":"[libcamera-devel,v4,2/2] ipa: rpi: common: Handle AEC/AGC flicker controls","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"b20deb9e1e19531ed78ff7f84ab1bfc01f1ddfd5","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18821/mbox/","series":[{"id":3970,"url":"https://patchwork.libcamera.org/api/series/3970/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3970","date":"2023-07-13T15:12:16","name":"Add flicker avoidance controls","version":4,"mbox":"https://patchwork.libcamera.org/series/3970/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18821/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18821/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 4F7DFBEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Jul 2023 15:12:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C302A628BE;\n\tThu, 13 Jul 2023 17:12:24 +0200 (CEST)","from mail-wm1-x334.google.com (mail-wm1-x334.google.com\n\t[IPv6:2a00:1450:4864:20::334])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 95715628BC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jul 2023 17:12:22 +0200 (CEST)","by mail-wm1-x334.google.com with SMTP id\n\t5b1f17b1804b1-3fbc0609cd6so7664805e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jul 2023 08:12:22 -0700 (PDT)","from pi4-davidp.pitowers.org\n\t([2a00:1098:3142:14:2bce:64d6:1a5c:49a2])\n\tby smtp.gmail.com with ESMTPSA id\n\tf11-20020a7bc8cb000000b003fa98908014sm18771086wml.8.2023.07.13.08.12.21\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 13 Jul 2023 08:12:21 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1689261144;\n\tbh=LjLquS0H3O5FIw/g+yfCCv2S++a1b3mowkz+YB+h3wQ=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=Ad8Z4/y2woG90VWP/RMwdvsILAd0dpzJRZc0SuDqAFoEzcb4YWIJESMCNT3mB6PRo\n\t5/5twXa7O4sZvGLmMH6hqeaYdDYDYTVNOzVe1273RP/j8vsPbMbtpFRgD22Zj/CkQd\n\tLVncmELj/JU44ZlvXi3UBgDke2tJ05C5qNVtn8Iiu4NNK54FMoktPfYYT8sH0Gufkw\n\t49EtwZp/Iqn6y0tJSxo5u0uBT1pP0BAroArVW6Dxd1g+d5S4moikfIg8NvSdW5bfnp\n\tJKi+Z+hSMo6aayVBq4J01xkRUkThZ8KmL57wLv8os5G8VS5lEiYXe25kkfPE3V6DCz\n\tZUJ1xYj4GwSNg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1689261142; x=1691853142;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=XzmlYLkxgEHn2L3BZQy6j1gfEvkwbGXBFfztjzabUdo=;\n\tb=cb45i4zsSCLy64uMXMHGrK3LJhPwHVNFQFeTO+yX3wAD9n+Abik+Hz/O01WG352doy\n\tHTeGDWMFe2clNY2osHFiDsUykbKZzzBTJKE2Yiqgyh/Tj0q8tXD9IMG0Q8Woz7Q/sGNs\n\taX0ArMvkwOazpTxlqDu5H6B5+L+8U1UN7BovhFy6luIdqxtatxbBPJ808JEiKmZShV+u\n\tNXmkvJ3tairMKV5TTFIWlfy/9Rjk05UGLm7TDtEJPLcJ0ZIhPToYukQmJb+UYLo9CUuf\n\tWHjojL2yvKb0iVPk/ZlnAks/ygUU3L+PPiQmIicpjDzhX2WE5SILByWxjPzl0rqS3FZ4\n\tgT7A=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"cb45i4zs\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1689261142; x=1691853142;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=XzmlYLkxgEHn2L3BZQy6j1gfEvkwbGXBFfztjzabUdo=;\n\tb=BL+wj/f2+NfU1KR3UEFrK+NpBjZ19SG9rudX5X10ro2gsZNBpIC59yEd8gwYJWXuk0\n\tJ+dOtNy6YXyo06jz6GR80WzfHbHLIHJZSY1jjIUZl1iFk4B0Bxsgnrf6fYdZYbVMDI8A\n\tUPaULkLnSoqdfLMI1lDVjcgzjeoLJeNe9pP7DfIfUiGUDlaOSeC3GoJ5XhYSrkWNfkKL\n\tL/o+FqfQ/Kyabey01b4FMrPaewjbJUJrUzOLcvTYsvLpPO8blxBIf/0irad/2QAsQx8o\n\tE0gsB7BF5GPg6qLTukeysyPKSsEAK6m5jpMdV8SIHk3QD+zZMpQM98Wh/pn3U6VAb3Uf\n\tBgDw==","X-Gm-Message-State":"ABy/qLYc4iH5Z8ZD9MNN7g8Xpm0IXENZ9TFsGHJeJKGPb7fEt594EJnw\n\tl7w454v2hOMhN/C2+MXZ2WH68b2CXSScLw2oc5E=","X-Google-Smtp-Source":"APBJJlHNdIJR5nVKtVOIZRTZCiWDiwZ2lg2Cl0IoY8FltDwhmWMIa33i/blVZgqTH4EzPKue6CQTkw==","X-Received":"by 2002:a1c:4b11:0:b0:3fa:962e:e8f4 with SMTP id\n\ty17-20020a1c4b11000000b003fa962ee8f4mr1595101wma.26.1689261142058; \n\tThu, 13 Jul 2023 08:12:22 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 13 Jul 2023 16:12:18 +0100","Message-Id":"<20230713151218.26045-3-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.30.2","In-Reply-To":"<20230713151218.26045-1-david.plowman@raspberrypi.com>","References":"<20230713151218.26045-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 2/2] ipa: rpi: common: Handle AEC/AGC\n\tflicker 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>","From":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"We handle the flicker modes by passing the correct period to the\nAEC/AGC algorithm which already contains the necessary code.\n\nThe \"Auto\" mode, as well as reporting the detected flicker period via\nthe \"AeFlickerDetected\" metadata, are unsupported for now.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/rpi/common/ipa_base.cpp | 64 ++++++++++++++++++++++++++++++++-\n src/ipa/rpi/common/ipa_base.h   |  6 ++++\n 2 files changed, 69 insertions(+), 1 deletion(-)","diff":"diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp\nindex f40f2e71..81d65ea5 100644\n--- a/src/ipa/rpi/common/ipa_base.cpp\n+++ b/src/ipa/rpi/common/ipa_base.cpp\n@@ -61,6 +61,8 @@ const ControlInfoMap::Map ipaControls{\n \t{ &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) },\n \t{ &controls::AeExposureMode, ControlInfo(controls::AeExposureModeValues) },\n \t{ &controls::ExposureValue, ControlInfo(-8.0f, 8.0f, 0.0f) },\n+\t{ &controls::AeFlickerMode, ControlInfo(controls::AeFlickerModeValues) },\n+\t{ &controls::AeFlickerCustom, ControlInfo(100, 1000000) },\n \t{ &controls::Brightness, ControlInfo(-1.0f, 1.0f, 0.0f) },\n \t{ &controls::Contrast, ControlInfo(0.0f, 32.0f, 1.0f) },\n \t{ &controls::Sharpness, ControlInfo(0.0f, 16.0f, 1.0f) },\n@@ -97,7 +99,7 @@ namespace ipa::RPi {\n \n IpaBase::IpaBase()\n \t: controller_(), frameCount_(0), mistrustCount_(0), lastRunTimestamp_(0),\n-\t  firstStart_(true)\n+\t  firstStart_(true), flickerState_({ 0, 0s })\n {\n }\n \n@@ -812,6 +814,66 @@ void IpaBase::applyControls(const ControlList &controls)\n \t\t\tbreak;\n \t\t}\n \n+\t\tcase controls::AE_FLICKER_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 AeFlickerMode - no AGC algorithm\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tint32_t mode = ctrl.second.get<int32_t>();\n+\t\t\tbool modeValid = true;\n+\n+\t\t\tswitch (mode) {\n+\t\t\tcase controls::FlickerOff: {\n+\t\t\t\tagc->setFlickerPeriod(0us);\n+\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tcase controls::FlickerCustom: {\n+\t\t\t\tagc->setFlickerPeriod(flickerState_.customPeriod);\n+\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tdefault:\n+\t\t\t\tLOG(IPARPI, Error) << \"Flicker mode \" << mode << \" is not supported\";\n+\t\t\t\tmodeValid = false;\n+\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tif (modeValid)\n+\t\t\t\tflickerState_.mode = mode;\n+\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase controls::AE_FLICKER_CUSTOM: {\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 AeFlickerCustom - no AGC algorithm\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tuint32_t customPeriod = ctrl.second.get<int32_t>();\n+\t\t\tflickerState_.customPeriod = customPeriod * 1.0us;\n+\n+\t\t\t/*\n+\t\t\t * We note that it makes no difference if the mode gets set to \"custom\"\n+\t\t\t * first, and the period updated after, or vice versa.\n+\t\t\t */\n+\t\t\tif (flickerState_.mode == controls::FlickerCustom)\n+\t\t\t\tagc->setFlickerPeriod(flickerState_.customPeriod);\n+\n+\t\t\tbreak;\n+\t\t}\n+\n \t\tcase controls::AWB_ENABLE: {\n \t\t\t/* Silently ignore this control for a mono sensor. */\n \t\t\tif (monoSensor_)\ndiff --git a/src/ipa/rpi/common/ipa_base.h b/src/ipa/rpi/common/ipa_base.h\nindex 39d00760..22823176 100644\n--- a/src/ipa/rpi/common/ipa_base.h\n+++ b/src/ipa/rpi/common/ipa_base.h\n@@ -116,6 +116,12 @@ private:\n \t/* Frame duration (1/fps) limits. */\n \tutils::Duration minFrameDuration_;\n \tutils::Duration maxFrameDuration_;\n+\n+\t/* The current state of flicker avoidance. */\n+\tstruct FlickerState {\n+\t\tint32_t mode;\n+\t\tutils::Duration customPeriod;\n+\t} flickerState_;\n };\n \n } /* namespace ipa::RPi */\n","prefixes":["libcamera-devel","v4","2/2"]}