{"id":18199,"url":"https://patchwork.libcamera.org/api/1.1/patches/18199/?format=json","web_url":"https://patchwork.libcamera.org/patch/18199/","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":"<20230126134559.3323-3-david.plowman@raspberrypi.com>","date":"2023-01-26T13:45:59","name":"[libcamera-devel,v2,2/2] ipa: raspberrypi: Handle AEC/AGC flicker controls","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"a16095e0c063f58b44b6c89ff02ad3089fc9c4cb","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/18199/mbox/","series":[{"id":3727,"url":"https://patchwork.libcamera.org/api/1.1/series/3727/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3727","date":"2023-01-26T13:45:57","name":"Add flicker avoidance controls","version":2,"mbox":"https://patchwork.libcamera.org/series/3727/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18199/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18199/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 672D3BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Jan 2023 13:46:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 96104625EB;\n\tThu, 26 Jan 2023 14:46:08 +0100 (CET)","from mail-wr1-x433.google.com (mail-wr1-x433.google.com\n\t[IPv6:2a00:1450:4864:20::433])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B79D461EFB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Jan 2023 14:46:05 +0100 (CET)","by mail-wr1-x433.google.com with SMTP id m14so1362446wrg.13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Jan 2023 05:46:05 -0800 (PST)","from pi4-davidp.pitowers.org\n\t([2a00:1098:3142:14:e4a2:3070:eea4:e434])\n\tby smtp.gmail.com with ESMTPSA id\n\tm2-20020a056000180200b002bfb5618ee7sm1370567wrh.91.2023.01.26.05.46.04\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 26 Jan 2023 05:46:04 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1674740768;\n\tbh=uC9Wltj2m2gSKP/fun7dbaUcLSWVuEKVtB40k/yyRfA=;\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=QVhPzCZMmaGVpf5Dff7+j6DqJwxLsaIfgbqzZW3nz7um2vJMLwLbIPqwb+Pph/CIj\n\tLs9YuYtc4jKClreeXHSk6U6wAmm1Op6nBzyS7u9tQb0CvZ+qrWIIOAofNdXQfL8F8D\n\t2wh6dOhCwAR4kLlX3HTGBpJ4Pcy/Tdj3dy3sW6uK5ZVgNAhJf8Hsf7s96hiDUQgqH6\n\tPBKWkgD12lDTyfEnZ8C9gALLBxTgBC/g7SEvdZUg3a8Wrc/fhqP5WDPzH0s2WX+rW2\n\tgLLddp+TPvbXAz7HQTMR8x8p+/2ElYd2WeVYrLeR9c4/RSms+AvVWy2o5aoFn/bI4J\n\tZI4wFSAu9qF2Q==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\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=T0St15xM0OQiiLGtya1glBR/W5nvGUy3/1PW9Rvrxyk=;\n\tb=kvXQgABF03g1ka1Re+FW+WDBHyVgz9AAqLR9W9QnKRNlnEj6c8UbaiI2tFIJrx4IoB\n\tT6ljccde4N2OXrzDxNBldYVmeUBZOieJTGDAMj5DB6AbnkA6fhSB/JRn2RDqvGHqEEDu\n\tX0SGSZ9geAOXhHC+tgGNeTpCLvOnKjYj4jFphqpE02YMhm866PHy+zC/aT9O39UvlA4T\n\t7xM0T9VVyZEmhujJtUdDMVcY/W0CwTq/MF0qr/7kwImTw0cYRUQPUfqCDFjV0x9TUuyT\n\tJAKfo+cHIvY/3tx3toLFNezkW6LOaaDTPME/1Au21VP2+mGpcgGY6MDAjVg3WTxV1Ond\n\t09MA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"kvXQgABF\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\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=T0St15xM0OQiiLGtya1glBR/W5nvGUy3/1PW9Rvrxyk=;\n\tb=7ewfJy4gfoFcJUiGEq7gb4ejTidQj+YMvuGLaLqQbXvo9b9VBh+KO54/OKeMrGk75W\n\tyF1flSHxpjRZDfC472/p3qU+kR1T+L2upp5Ng8nF95I1p3KZxIfvetpaPMqI2q16c5/C\n\t9axDTpNdxxu7LYIdhditJNHFEpVhnkwNgOA6lLDySMzK/BfFOBK3HmAF6NeILgq2MeVr\n\ttICfjhE9Hk4WlnssBYA0QM7GjcwQhv4P9AzweXNruNafupGIHswQHFaXIgqMd5pgdTu+\n\tM2iV5YIsjQgHQtgCmkl2l55b+S0VhOzso94tRSZBhSnbmBnUu/WiKceJGtxhZjiyyBID\n\tKuRQ==","X-Gm-Message-State":"AO0yUKXYEEA0ZI/Ct7jE6LWVA4MCs6Q//rJ5UNp8Qc1raKkB0lZsSzaw\n\tnJN+ZdGY2xcLztlJj1QHArNq4IL8tnOVVLhY","X-Google-Smtp-Source":"AK7set9py7eNzR4hklTGPP1A2bLEOQbKfG34afTnz8wW3OVbvNiEOHfskMMgFaCJ2LefvmvKqnuhXQ==","X-Received":"by 2002:a5d:4c41:0:b0:2bf:b3c5:cf54 with SMTP id\n\tn1-20020a5d4c41000000b002bfb3c5cf54mr7218345wrt.60.1674740765165; \n\tThu, 26 Jan 2023 05:46:05 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 26 Jan 2023 13:45:59 +0000","Message-Id":"<20230126134559.3323-3-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.30.2","In-Reply-To":"<20230126134559.3323-1-david.plowman@raspberrypi.com>","References":"<20230126134559.3323-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 2/2] ipa: raspberrypi: 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. The\n\"Auto\" mode is currently unsupported.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/raspberrypi.cpp | 80 +++++++++++++++++++++++++++++\n 1 file changed, 80 insertions(+)","diff":"diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 5f7397e2..477d72ba 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -86,6 +86,8 @@ static 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::AeFlickerPeriod, ControlInfo(0, 1000000) },\n \t{ &controls::AwbEnable, ControlInfo(false, true) },\n \t{ &controls::ColourGains, ControlInfo(0.0f, 32.0f) },\n \t{ &controls::AwbMode, ControlInfo(controls::AwbModeValues) },\n@@ -218,6 +220,12 @@ private:\n \n \t/* Maximum gain code for the sensor. */\n \tuint32_t maxSensorGainCode_;\n+\n+\t/* The current state of flicker avoidance. */\n+\tstruct FlickerState {\n+\t\tint32_t mode;\n+\t\tDuration period;\n+\t} flickerState_;\n };\n \n int IPARPi::init(const IPASettings &settings, bool lensPresent, IPAInitResult *result)\n@@ -946,6 +954,78 @@ void IPARPi::queueRequest(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 AE_FLICKER_MODE - 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::FlickerFreq50Hz: {\n+\t\t\t\tagc->setFlickerPeriod(10000 * 1.0us);\n+\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tcase controls::FlickerFreq60Hz: {\n+\t\t\t\tagc->setFlickerPeriod(8333.333 * 1.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_.period);\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_PERIOD: {\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_FLICKER_PERIOD - no AGC algorithm\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tuint32_t period = ctrl.second.get<int32_t>();\n+\t\t\tflickerState_.period = period * 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_.period);\n+\n+\t\t\tbreak;\n+\t\t}\n+\n \t\tcase controls::AWB_ENABLE: {\n \t\t\tRPiController::AwbAlgorithm *awb = dynamic_cast<RPiController::AwbAlgorithm *>(\n \t\t\t\tcontroller_.getAlgorithm(\"awb\"));\n","prefixes":["libcamera-devel","v2","2/2"]}