[{"id":16272,"web_url":"https://patchwork.libcamera.org/comment/16272/","msgid":"<CAEmqJPpbCfdfN8j2V_PhUQh-b0nTpTXEc+KiuZvAbsLE0o3axw@mail.gmail.com>","date":"2021-04-14T10:32:19","subject":"Re: [libcamera-devel] [PATCH v3 3/3] ipa: raspberrypi: Update\n\tsensor's RED/BLUE balance controls when present","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi David,\n\nOn Wed, 14 Apr 2021 at 11:30, David Plowman <david.plowman@raspberrypi.com>\nwrote:\n\n> If the sensor exposes V4L2_CID_RED_BALANCE and V4L2_CID_BLUE_BALANCE\n> controls, assume it wants to be told the colour gains.\n>\n> We want these to be applied as soon as possible so we add a new\n> setSensorControls signal to the IPA which passes these back to the\n> pipeline handler without using the DelayedControls mechanism.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n\n>  include/libcamera/ipa/raspberrypi.mojom            |  1 +\n>  src/ipa/raspberrypi/raspberrypi.cpp                | 13 +++++++++++++\n>  src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 10 ++++++++++\n>  3 files changed, 24 insertions(+)\n>\n> diff --git a/include/libcamera/ipa/raspberrypi.mojom\n> b/include/libcamera/ipa/raspberrypi.mojom\n> index f38c2261..ebaf0a04 100644\n> --- a/include/libcamera/ipa/raspberrypi.mojom\n> +++ b/include/libcamera/ipa/raspberrypi.mojom\n> @@ -117,6 +117,7 @@ interface IPARPiEventInterface {\n>         statsMetadataComplete(uint32 bufferId, ControlList controls);\n>         runIsp(uint32 bufferId);\n>         embeddedComplete(uint32 bufferId);\n> +       setSensorControls(ControlList controls);\n>         setIspControls(ControlList controls);\n>         setDelayedControls(ControlList controls);\n>  };\n> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp\n> b/src/ipa/raspberrypi/raspberrypi.cpp\n> index dad6395f..f95896d2 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -1036,6 +1036,19 @@ void IPARPi::processStats(unsigned int bufferId)\n>\n>                 setDelayedControls.emit(ctrls);\n>         }\n> +\n> +       struct AwbStatus awbStatus;\n> +       if (rpiMetadata_.Get(\"awb.status\", awbStatus) == 0 &&\n> +           sensorCtrls_.find(V4L2_CID_RED_BALANCE) != sensorCtrls_.end()\n> &&\n> +           sensorCtrls_.find(V4L2_CID_BLUE_BALANCE) !=\n> sensorCtrls_.end()) {\n> +               ControlList ctrls(sensorCtrls_);\n> +               ctrls.set(V4L2_CID_RED_BALANCE,\n> +\n>  static_cast<int32_t>(helper_->ColourGainCode(awbStatus.gain_r)));\n> +               ctrls.set(V4L2_CID_BLUE_BALANCE,\n> +\n>  static_cast<int32_t>(helper_->ColourGainCode(awbStatus.gain_b)));\n> +\n> +               setSensorControls.emit(ctrls);\n> +       }\n>  }\n>\n>  void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList\n> &ctrls)\n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index f22e286e..8dae4912 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -152,6 +152,7 @@ public:\n>         void statsMetadataComplete(uint32_t bufferId, const ControlList\n> &controls);\n>         void runIsp(uint32_t bufferId);\n>         void embeddedComplete(uint32_t bufferId);\n> +       void setSensorControls(const ControlList &controls);\n>         void setIspControls(const ControlList &controls);\n>         void setDelayedControls(const ControlList &controls);\n>\n> @@ -1219,6 +1220,7 @@ int RPiCameraData::loadIPA(ipa::RPi::SensorConfig\n> *sensorConfig)\n>         ipa_->statsMetadataComplete.connect(this,\n> &RPiCameraData::statsMetadataComplete);\n>         ipa_->runIsp.connect(this, &RPiCameraData::runIsp);\n>         ipa_->embeddedComplete.connect(this,\n> &RPiCameraData::embeddedComplete);\n> +       ipa_->setSensorControls.connect(this,\n> &RPiCameraData::setSensorControls);\n>         ipa_->setIspControls.connect(this, &RPiCameraData::setIspControls);\n>         ipa_->setDelayedControls.connect(this,\n> &RPiCameraData::setDelayedControls);\n>\n> @@ -1361,6 +1363,14 @@ void RPiCameraData::embeddedComplete(uint32_t\n> bufferId)\n>         handleState();\n>  }\n>\n> +void RPiCameraData::setSensorControls(const ControlList &controls)\n> +{\n> +       ControlList ctrls = controls;\n> +\n> +       unicam_[Unicam::Image].dev()->setControls(&ctrls);\n> +       handleState();\n> +}\n> +\n>  void RPiCameraData::setIspControls(const ControlList &controls)\n>  {\n>         ControlList ctrls = controls;\n> --\n> 2.20.1\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel\n>","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 9B8AABD224\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 14 Apr 2021 10:32:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 03DCD68817;\n\tWed, 14 Apr 2021 12:32:38 +0200 (CEST)","from mail-lf1-x135.google.com (mail-lf1-x135.google.com\n\t[IPv6:2a00:1450:4864:20::135])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 17B3F68803\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Apr 2021 12:32:36 +0200 (CEST)","by mail-lf1-x135.google.com with SMTP id z13so15313486lfd.9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Apr 2021 03:32:36 -0700 (PDT)"],"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=\"HFDcvV1U\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=VEDoPw8jSLcQLMqWfv5Fh0PDm91iEkTX76sWFUJ/Big=;\n\tb=HFDcvV1UkAh4WC4BLdHr3m32quqrDxLdi2hEAl3vWNz+O+dQfyhoFnfPkTjQWj6nYi\n\tYqIxLwvb6BbB1lIiVLfHp3XFLO1SArxVLoZ2CQhWOAQeZ2p/+LDLib9clGPcKGvfXPPE\n\tYsAZOmO7IEJ5/R84/cI88XX76dKkBKTCP9HCu+cOqcWmDdZGZwd6gAeA/ULLhkgH9T7i\n\t1NonVUUbcoTrcv4fqUHfyVv6TLzbVQL7921emWssmukEmDvrx3VQDvKQvas7uX5sjxPj\n\tyKMFTIzOBcunX/ZKuH/u92FBnHDcAT8Igc915aLrxcBmacackGZ/6DShdEcMVBShJsgk\n\t1Oug==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=VEDoPw8jSLcQLMqWfv5Fh0PDm91iEkTX76sWFUJ/Big=;\n\tb=QYbHaNcgH3mfiufCQDhVOJgTgKZ87iOI4CW7o5199nIC6PQG/+RBLMmkMxbPiHTe5r\n\tjRQ4OW9DROIgRbXC9HCwlV+itdo4RFuTVc4ak+rr4KeekTDLVJY2WppKMHEcBBURX89v\n\tbKsnHDKkVYR7wcVRm019sTv9bZKK0pFBf1VomZoIN0TVoY+BA5cKcufzXaOK8jUC4PgF\n\tj5GaQZwQd/W/Mdt8fag40Q3YbWJmWXIGB14R5duIGDUDwWYq1TYsq9K4x8lChrdnC2gz\n\tNFz5WnbmTg6SQA8BfR3216wIsYpAkCvb6SZ9UPXCMK3XoNSKO179lBXmsB4K+GbJTy8k\n\twaIw==","X-Gm-Message-State":"AOAM530nxfIpX8CpldNt2Uq8tuiJuPuyqSDCv840e27ka8Hid2qWewep\n\tG7w1d86e3u2CS9L+kVY3RyNZ/aGoJO0KFmIia7kKow==","X-Google-Smtp-Source":"ABdhPJx04zX3sh7JY4zXWVvW7C1r3xb4rXYyuEjUJAGCCOI1IPaU+lO/v198XCzJh0Yu7jRDCE6BVL0Hu7U0eJBA7DI=","X-Received":"by 2002:a05:6512:3f87:: with SMTP id\n\tx7mr4539638lfa.617.1618396355575; \n\tWed, 14 Apr 2021 03:32:35 -0700 (PDT)","MIME-Version":"1.0","References":"<20210414102955.9503-1-david.plowman@raspberrypi.com>\n\t<20210414102955.9503-4-david.plowman@raspberrypi.com>","In-Reply-To":"<20210414102955.9503-4-david.plowman@raspberrypi.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Wed, 14 Apr 2021 11:32:19 +0100","Message-ID":"<CAEmqJPpbCfdfN8j2V_PhUQh-b0nTpTXEc+KiuZvAbsLE0o3axw@mail.gmail.com>","To":"David Plowman <david.plowman@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v3 3/3] ipa: raspberrypi: Update\n\tsensor's RED/BLUE balance controls when present","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"multipart/mixed;\n\tboundary=\"===============1343114664937785508==\"","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":16327,"web_url":"https://patchwork.libcamera.org/comment/16327/","msgid":"<YHoKNne4Y6lv5QO2@pendragon.ideasonboard.com>","date":"2021-04-16T22:05:42","subject":"Re: [libcamera-devel] [PATCH v3 3/3] ipa: raspberrypi: Update\n\tsensor's RED/BLUE balance controls when present","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi David,\n\nThank you for the patch.\n\nOn Wed, Apr 14, 2021 at 11:29:55AM +0100, David Plowman wrote:\n> If the sensor exposes V4L2_CID_RED_BALANCE and V4L2_CID_BLUE_BALANCE\n> controls, assume it wants to be told the colour gains.\n> \n> We want these to be applied as soon as possible so we add a new\n> setSensorControls signal to the IPA which passes these back to the\n> pipeline handler without using the DelayedControls mechanism.\n> \n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  include/libcamera/ipa/raspberrypi.mojom            |  1 +\n>  src/ipa/raspberrypi/raspberrypi.cpp                | 13 +++++++++++++\n>  src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 10 ++++++++++\n>  3 files changed, 24 insertions(+)\n> \n> diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom\n> index f38c2261..ebaf0a04 100644\n> --- a/include/libcamera/ipa/raspberrypi.mojom\n> +++ b/include/libcamera/ipa/raspberrypi.mojom\n> @@ -117,6 +117,7 @@ interface IPARPiEventInterface {\n>  \tstatsMetadataComplete(uint32 bufferId, ControlList controls);\n>  \trunIsp(uint32 bufferId);\n>  \tembeddedComplete(uint32 bufferId);\n> +\tsetSensorControls(ControlList controls);\n>  \tsetIspControls(ControlList controls);\n>  \tsetDelayedControls(ControlList controls);\n>  };\n> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n> index dad6395f..f95896d2 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -1036,6 +1036,19 @@ void IPARPi::processStats(unsigned int bufferId)\n>  \n>  \t\tsetDelayedControls.emit(ctrls);\n>  \t}\n> +\n> +\tstruct AwbStatus awbStatus;\n> +\tif (rpiMetadata_.Get(\"awb.status\", awbStatus) == 0 &&\n> +\t    sensorCtrls_.find(V4L2_CID_RED_BALANCE) != sensorCtrls_.end() &&\n> +\t    sensorCtrls_.find(V4L2_CID_BLUE_BALANCE) != sensorCtrls_.end()) {\n> +\t\tControlList ctrls(sensorCtrls_);\n> +\t\tctrls.set(V4L2_CID_RED_BALANCE,\n> +\t\t\t  static_cast<int32_t>(helper_->ColourGainCode(awbStatus.gain_r)));\n> +\t\tctrls.set(V4L2_CID_BLUE_BALANCE,\n> +\t\t\t  static_cast<int32_t>(helper_->ColourGainCode(awbStatus.gain_b)));\n> +\n> +\t\tsetSensorControls.emit(ctrls);\n> +\t}\n>  }\n\nGiven that this series doesn't make use of this feature, it's hard to\nreview the patch. What bothers me is usage of V4L2_CID_RED_BALANCE and\nV4L2_CID_BLUE_BALANCE. Those two controls haven't been designed for\ncamera sensors, and while a few drivers in the mainline kernel implement\nthem, it's most likely an abuse. Sensors that provide per-colour gains\ntypically have one gain for each Bayer component. We need new V4L2\ncontrols for this.\n\n>  \n>  void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)\n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index f22e286e..8dae4912 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -152,6 +152,7 @@ public:\n>  \tvoid statsMetadataComplete(uint32_t bufferId, const ControlList &controls);\n>  \tvoid runIsp(uint32_t bufferId);\n>  \tvoid embeddedComplete(uint32_t bufferId);\n> +\tvoid setSensorControls(const ControlList &controls);\n>  \tvoid setIspControls(const ControlList &controls);\n>  \tvoid setDelayedControls(const ControlList &controls);\n>  \n> @@ -1219,6 +1220,7 @@ int RPiCameraData::loadIPA(ipa::RPi::SensorConfig *sensorConfig)\n>  \tipa_->statsMetadataComplete.connect(this, &RPiCameraData::statsMetadataComplete);\n>  \tipa_->runIsp.connect(this, &RPiCameraData::runIsp);\n>  \tipa_->embeddedComplete.connect(this, &RPiCameraData::embeddedComplete);\n> +\tipa_->setSensorControls.connect(this, &RPiCameraData::setSensorControls);\n>  \tipa_->setIspControls.connect(this, &RPiCameraData::setIspControls);\n>  \tipa_->setDelayedControls.connect(this, &RPiCameraData::setDelayedControls);\n>  \n> @@ -1361,6 +1363,14 @@ void RPiCameraData::embeddedComplete(uint32_t bufferId)\n>  \thandleState();\n>  }\n>  \n> +void RPiCameraData::setSensorControls(const ControlList &controls)\n> +{\n> +\tControlList ctrls = controls;\n> +\n> +\tunicam_[Unicam::Image].dev()->setControls(&ctrls);\n> +\thandleState();\n> +}\n> +\n>  void RPiCameraData::setIspControls(const ControlList &controls)\n>  {\n>  \tControlList ctrls = controls;","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 686A3BD237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 16 Apr 2021 22:05:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A8C4568812;\n\tSat, 17 Apr 2021 00:05:47 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 64165687F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 17 Apr 2021 00:05:45 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C237651E;\n\tSat, 17 Apr 2021 00:05:44 +0200 (CEST)"],"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=\"IwUCV2el\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1618610745;\n\tbh=Opl3/J+H+SgqnAJubMp85+AXQMC7CCxXDR/AKz+xfcU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=IwUCV2elazsYc0Dk0CwQkt0WZ3CAUsq01kIyoPDlm6ZRIJAT1Vy30KoMHnekbKZhb\n\th/YrfNglBb5euJHqjC1a80/TtcKLRed/G3wd3bHGW2oCAfMH4J2nWWAxBsO0aaj/IG\n\tqAQcVwFBMNkMdJLOGbpCZxTxKFdyjlCa0wGNYJ4k=","Date":"Sat, 17 Apr 2021 01:05:42 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"David Plowman <david.plowman@raspberrypi.com>","Message-ID":"<YHoKNne4Y6lv5QO2@pendragon.ideasonboard.com>","References":"<20210414102955.9503-1-david.plowman@raspberrypi.com>\n\t<20210414102955.9503-4-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210414102955.9503-4-david.plowman@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v3 3/3] ipa: raspberrypi: Update\n\tsensor's RED/BLUE balance controls when present","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>","Cc":"libcamera-devel@lists.libcamera.org","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>"}}]