[{"id":21908,"web_url":"https://patchwork.libcamera.org/comment/21908/","msgid":"<Ycz1Ek76rsMdhsGG@pendragon.ideasonboard.com>","date":"2021-12-29T23:53:54","subject":"Re: [libcamera-devel] [PATCH 3/3] ipa: raspberrypi: Update sensor's\n\tV4L2_CID_NOTIFY_GAINS control 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 Thu, Dec 23, 2021 at 08:01:10AM +0000, David Plowman wrote:\n> If the sensor exposes the V4L2_CID_NOTIFY_GAINS controls, assume it\n> 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> ---\n>  include/libcamera/ipa/raspberrypi.mojom       |  1 +\n>  src/ipa/raspberrypi/raspberrypi.cpp           | 22 +++++++++++++++++++\n>  .../pipeline/raspberrypi/raspberrypi.cpp      | 10 +++++++++\n>  3 files changed, 33 insertions(+)\n> \n> diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom\n> index acd3cafe..e7647724 100644\n> --- a/include/libcamera/ipa/raspberrypi.mojom\n> +++ b/include/libcamera/ipa/raspberrypi.mojom\n> @@ -123,6 +123,7 @@ interface IPARPiEventInterface {\n>  \tstatsMetadataComplete(uint32 bufferId, libcamera.ControlList controls);\n>  \trunIsp(uint32 bufferId);\n>  \tembeddedComplete(uint32 bufferId);\n> +\tsetSensorControls(libcamera.ControlList controls);\n>  \tsetIspControls(libcamera.ControlList controls);\n>  \tsetDelayedControls(libcamera.ControlList controls);\n>  };\n> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n> index 0ed41385..8c20c066 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -1061,6 +1061,28 @@ void IPARPi::processStats(unsigned int bufferId)\n>  \n>  \t\tsetDelayedControls.emit(ctrls);\n>  \t}\n> +\n> +\tauto itCtrl = sensorCtrls_.find(V4L2_CID_NOTIFY_GAINS);\n> +\tif (itCtrl != sensorCtrls_.end()) {\n> +\t\tstruct AwbStatus awbStatus;\n> +\t\tif (rpiMetadata_.Get(\"awb.status\", awbStatus) == 0) {\n> +\t\t\t/*\n> +\t\t\t * This control is a linear gain value where the default is\n> +\t\t\t * defined to correspond to a gain of 1. The order of the gains\n> +\t\t\t * is always B, Gb, Gr, R.\n> +\t\t\t */\n> +\t\t\tint unity = itCtrl->second.def().get<int32_t>();\n> +\t\t\tControlList ctrls(sensorCtrls_);\n> +\t\t\tint32_t gains[4] = { static_cast<int32_t>(awbStatus.gain_b * unity),\n> +\t\t\t\t\t     unity, unity,\n> +\t\t\t\t\t     static_cast<int32_t>(awbStatus.gain_r * unity) };\n> +\t\t\tControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(gains),\n> +\t\t\t\t\t\t\t    sizeof(gains) });\n> +\t\t\tctrls.set(V4L2_CID_NOTIFY_GAINS, c);\n> +\n> +\t\t\tsetSensorControls.emit(ctrls);\n\nCould we avoid adding another operation by setting V4L2_CID_NOTIFY_GAINS\nin the pipeline handler, when receiving the request metadata in\nRPiCameraData::statsMetadataComplete() ?\n\n> +\t\t}\n> +\t}\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 b5c687da..59d3bbd8 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -196,6 +196,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>  \tvoid setSensorControls(ControlList &controls);\n> @@ -1405,6 +1406,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> @@ -1524,6 +1526,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> +\tsensor_->setControls(&ctrls);\n> +\thandleState();\n\nDo we need to call handleState() here ?\n\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 C2FA7BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 29 Dec 2021 23:53:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EBFB360905;\n\tThu, 30 Dec 2021 00:53:58 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DAF5860868\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Dec 2021 00:53:56 +0100 (CET)","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 4842A2A5;\n\tThu, 30 Dec 2021 00:53:56 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"f29XMfNG\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1640822036;\n\tbh=i/XOky0u58XNHqiTbXyKAkVF2IAssQ0m+RQi5xdeKc4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=f29XMfNGDdeljQDhmR1xkZFANVouFYk/q9oPm0FdE0SAQj1iI20BbrLO5JVbsvxMV\n\t6CGvUeHB3Ih+xgO+86kQmrrLqSDGiRc25XkveWM7xhtf0AieTbKzM/OeyF6DxFt+vx\n\txbS8CvTjbBp9vqlGFigwy5fhDg1vUDUtGBCG9Ang=","Date":"Thu, 30 Dec 2021 01:53:54 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"David Plowman <david.plowman@raspberrypi.com>","Message-ID":"<Ycz1Ek76rsMdhsGG@pendragon.ideasonboard.com>","References":"<20211223080110.9766-1-david.plowman@raspberrypi.com>\n\t<20211223080110.9766-4-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211223080110.9766-4-david.plowman@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH 3/3] ipa: raspberrypi: Update sensor's\n\tV4L2_CID_NOTIFY_GAINS control 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","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":21912,"web_url":"https://patchwork.libcamera.org/comment/21912/","msgid":"<CAHW6GY+dos3E-mqbvgwUURZMFrAnqa8TQZHf_tM00LjkXAMKEA@mail.gmail.com>","date":"2021-12-30T11:21:52","subject":"Re: [libcamera-devel] [PATCH 3/3] ipa: raspberrypi: Update sensor's\n\tV4L2_CID_NOTIFY_GAINS control when present","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Laurent\n\nThanks for the comments.\n\nOn Wed, 29 Dec 2021 at 23:53, Laurent Pinchart\n<laurent.pinchart@ideasonboard.com> wrote:\n>\n> Hi David,\n>\n> Thank you for the patch.\n>\n> On Thu, Dec 23, 2021 at 08:01:10AM +0000, David Plowman wrote:\n> > If the sensor exposes the V4L2_CID_NOTIFY_GAINS controls, assume it\n> > 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> > ---\n> >  include/libcamera/ipa/raspberrypi.mojom       |  1 +\n> >  src/ipa/raspberrypi/raspberrypi.cpp           | 22 +++++++++++++++++++\n> >  .../pipeline/raspberrypi/raspberrypi.cpp      | 10 +++++++++\n> >  3 files changed, 33 insertions(+)\n> >\n> > diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom\n> > index acd3cafe..e7647724 100644\n> > --- a/include/libcamera/ipa/raspberrypi.mojom\n> > +++ b/include/libcamera/ipa/raspberrypi.mojom\n> > @@ -123,6 +123,7 @@ interface IPARPiEventInterface {\n> >       statsMetadataComplete(uint32 bufferId, libcamera.ControlList controls);\n> >       runIsp(uint32 bufferId);\n> >       embeddedComplete(uint32 bufferId);\n> > +     setSensorControls(libcamera.ControlList controls);\n> >       setIspControls(libcamera.ControlList controls);\n> >       setDelayedControls(libcamera.ControlList controls);\n> >  };\n> > diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n> > index 0ed41385..8c20c066 100644\n> > --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> > +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> > @@ -1061,6 +1061,28 @@ void IPARPi::processStats(unsigned int bufferId)\n> >\n> >               setDelayedControls.emit(ctrls);\n> >       }\n> > +\n> > +     auto itCtrl = sensorCtrls_.find(V4L2_CID_NOTIFY_GAINS);\n> > +     if (itCtrl != sensorCtrls_.end()) {\n> > +             struct AwbStatus awbStatus;\n> > +             if (rpiMetadata_.Get(\"awb.status\", awbStatus) == 0) {\n> > +                     /*\n> > +                      * This control is a linear gain value where the default is\n> > +                      * defined to correspond to a gain of 1. The order of the gains\n> > +                      * is always B, Gb, Gr, R.\n> > +                      */\n> > +                     int unity = itCtrl->second.def().get<int32_t>();\n> > +                     ControlList ctrls(sensorCtrls_);\n> > +                     int32_t gains[4] = { static_cast<int32_t>(awbStatus.gain_b * unity),\n> > +                                          unity, unity,\n> > +                                          static_cast<int32_t>(awbStatus.gain_r * unity) };\n> > +                     ControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(gains),\n> > +                                                         sizeof(gains) });\n> > +                     ctrls.set(V4L2_CID_NOTIFY_GAINS, c);\n> > +\n> > +                     setSensorControls.emit(ctrls);\n>\n> Could we avoid adding another operation by setting V4L2_CID_NOTIFY_GAINS\n> in the pipeline handler, when receiving the request metadata in\n> RPiCameraData::statsMetadataComplete() ?\n\nThat's an interesting thought. Let me check with Naush once he's back,\nbut I guess we could \"intercept\" the colour gain values there and\nupdate those controls in much the same way.\n\n>\n> > +             }\n> > +     }\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 b5c687da..59d3bbd8 100644\n> > --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > @@ -196,6 +196,7 @@ public:\n> >       void statsMetadataComplete(uint32_t bufferId, const ControlList &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> >       void setSensorControls(ControlList &controls);\n> > @@ -1405,6 +1406,7 @@ int RPiCameraData::loadIPA(ipa::RPi::SensorConfig *sensorConfig)\n> >       ipa_->statsMetadataComplete.connect(this, &RPiCameraData::statsMetadataComplete);\n> >       ipa_->runIsp.connect(this, &RPiCameraData::runIsp);\n> >       ipa_->embeddedComplete.connect(this, &RPiCameraData::embeddedComplete);\n> > +     ipa_->setSensorControls.connect(this, &RPiCameraData::setSensorControls);\n> >       ipa_->setIspControls.connect(this, &RPiCameraData::setIspControls);\n> >       ipa_->setDelayedControls.connect(this, &RPiCameraData::setDelayedControls);\n> >\n> > @@ -1524,6 +1526,14 @@ void RPiCameraData::embeddedComplete(uint32_t bufferId)\n> >       handleState();\n> >  }\n> >\n> > +void RPiCameraData::setSensorControls(const ControlList &controls)\n> > +{\n> > +     ControlList ctrls = controls;\n> > +\n> > +     sensor_->setControls(&ctrls);\n> > +     handleState();\n>\n> Do we need to call handleState() here ?\n\nProbably not! But maybe this disappears altogether...\n\nThanks!\nDavid\n\n>\n> > +}\n> > +\n> >  void RPiCameraData::setIspControls(const ControlList &controls)\n> >  {\n> >       ControlList ctrls = controls;\n>\n> --\n> Regards,\n>\n> Laurent Pinchart","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 47627BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 30 Dec 2021 11:22:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5F332608EB;\n\tThu, 30 Dec 2021 12:22:06 +0100 (CET)","from mail-wr1-x435.google.com (mail-wr1-x435.google.com\n\t[IPv6:2a00:1450:4864:20::435])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 005B060115\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Dec 2021 12:22:04 +0100 (CET)","by mail-wr1-x435.google.com with SMTP id d9so49903313wrb.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Dec 2021 03:22:04 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"llp2Mw9H\"; 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=swYCY7SenwP/YUpkga0sfhDHsDWRjoLQwbEEWGF8LAw=;\n\tb=llp2Mw9HpQ9OBfftq1R7C6V3VANGUjcwlJ3RcWp5N5U1Gs7UXGATXC31k4vej3omz2\n\tFXxEp5vxLY10XdMNjM6fhKk1dKQLEZZXeyHlOwZ6i6NK580DAGZhfUZGFbo6iNmFrMFG\n\tshU1XCQPbxVgIIjXrtCA83SI2fVquyq+rtIBYlRNHQA+eoowdQHEQ8wUXalb5pHpyi6Q\n\t6u5tbIxJYInhr2/E6bJUhsuCYCsvz2Co7FRCKTzYX1sVoG6hehoLTdvYzaSDj+LJEUyp\n\tDd9wLVk7y0hQir3CvF8ZXZ2ob6eY7jpr66M/5Kg/srbAwpD2TF5eEEoVJKwcQZfFKgo+\n\thcrA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=swYCY7SenwP/YUpkga0sfhDHsDWRjoLQwbEEWGF8LAw=;\n\tb=OHsxN8WFOllbvaABq7u1pR/FDkChPz6McAOGRsTmTPhdXv7YHHt9rEH9LRDzk2T052\n\to0byQw2UsfiChQ+8IcS7iVt9GyckFaZWX2t+lYWslBG1y8ZlEM1w05sckidB5IQsiQ/h\n\tPbFCocW6BW5DCcy2D4SQqikxzTzeUkOoZ+wNorF2GeIP3jVLdXMZlC+XPE02ChCG02gQ\n\t6t/GCkyDn4GfX9Fcj89e8zIpiw8qr/2ElTn0gayGXjpUpaRMw6wbeKMqDLa4B0y5sP9A\n\txqmG1Bv9ax5qKhH6jmvP6aaMe1KbJh6yzmk9E6Irit8jBpGgZxVpw876YWcw+cSMxtOX\n\taaTQ==","X-Gm-Message-State":"AOAM532pymxdTT5ge0+MA7LV1teZF88NXGpM2EWAipncSb04EeyQrXDf\n\tGXD4S/TpsD1mXk4YgL6ED8p2+AYGpD5OicX9vz8JTA==","X-Google-Smtp-Source":"ABdhPJy4JUcMh5w6DEDPmYEqo3l1byMIAdffcWxFNUsZIdnALN1dUp+QgETw+AOxnAWrAhH1U4mWcRQ4OpofOboAYbU=","X-Received":"by 2002:a5d:6442:: with SMTP id\n\td2mr24409760wrw.334.1640863324514; \n\tThu, 30 Dec 2021 03:22:04 -0800 (PST)","MIME-Version":"1.0","References":"<20211223080110.9766-1-david.plowman@raspberrypi.com>\n\t<20211223080110.9766-4-david.plowman@raspberrypi.com>\n\t<Ycz1Ek76rsMdhsGG@pendragon.ideasonboard.com>","In-Reply-To":"<Ycz1Ek76rsMdhsGG@pendragon.ideasonboard.com>","From":"David Plowman <david.plowman@raspberrypi.com>","Date":"Thu, 30 Dec 2021 11:21:52 +0000","Message-ID":"<CAHW6GY+dos3E-mqbvgwUURZMFrAnqa8TQZHf_tM00LjkXAMKEA@mail.gmail.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH 3/3] ipa: raspberrypi: Update sensor's\n\tV4L2_CID_NOTIFY_GAINS control 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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]