[{"id":23877,"web_url":"https://patchwork.libcamera.org/comment/23877/","msgid":"<20220714150109.7nhww6gyztxpbukn@uno.localdomain>","date":"2022-07-14T15:01:09","subject":"Re: [libcamera-devel] [PATCH 3/3] libcamera: rkisp1: Control the\n\tlens from IPA","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Daniel\n\nOn Tue, Jun 28, 2022 at 11:06:56AM +0200, Daniel Semkowicz via libcamera-devel wrote:\n> Check if lens are available and have ability to control the focus.\n\nthe lens -> is\nthe lens -> has\n\n> Connect IPA setLensControls() signal to the pipeline slot that controls\n> the lens. If lens are valid, allow changing the focus from IPA by\n\nlens -> is\n\n> emitting signal to the pipeline.\n>\n> Signed-off-by: Daniel Semkowicz <dse@thaumatec.com>\n> ---\n>  include/libcamera/ipa/rkisp1.mojom       |  1 +\n>  src/ipa/rkisp1/ipa_context.h             |  4 +++\n>  src/ipa/rkisp1/rkisp1.cpp                | 36 ++++++++++++++++++++++++\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp |  1 +\n>  4 files changed, 42 insertions(+)\n>\n> diff --git a/include/libcamera/ipa/rkisp1.mojom b/include/libcamera/ipa/rkisp1.mojom\n> index e3537385..ee06a6b0 100644\n> --- a/include/libcamera/ipa/rkisp1.mojom\n> +++ b/include/libcamera/ipa/rkisp1.mojom\n> @@ -32,5 +32,6 @@ interface IPARkISP1Interface {\n>  interface IPARkISP1EventInterface {\n>  \tparamsBufferReady(uint32 frame);\n>  \tsetSensorControls(uint32 frame, libcamera.ControlList sensorControls);\n> +\tsetLensControls(libcamera.ControlList sensorControls);\n\ns/sensorControls/lensControls/\n\n>  \tmetadataReady(uint32 frame, libcamera.ControlList metadata);\n>  };\n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index f387cace..4b199048 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -41,6 +41,10 @@ struct IPASessionConfiguration {\n>  };\n>\n>  struct IPAFrameContext {\n> +\tstruct {\n> +\t\tuint32_t focus;\n> +\t} af;\n> +\n>  \tstruct {\n>  \t\tuint32_t exposure;\n>  \t\tdouble gain;\n> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\n> index 3511a054..2447f4f4 100644\n> --- a/src/ipa/rkisp1/rkisp1.cpp\n> +++ b/src/ipa/rkisp1/rkisp1.cpp\n> @@ -7,6 +7,7 @@\n>\n>  #include <algorithm>\n>  #include <math.h>\n> +#include <optional>\n>  #include <queue>\n>  #include <stdint.h>\n>  #include <string.h>\n> @@ -59,6 +60,8 @@ public:\n>  \tvoid processStatsBuffer(const uint32_t frame, const uint32_t bufferId,\n>  \t\t\t\tconst ControlList &sensorControls) override;\n>  private:\n> +\tbool validateLensControls(const ControlInfoMap &lensControls);\n> +\n>  \tvoid setControls(unsigned int frame);\n>  \tvoid prepareMetadata(unsigned int frame, unsigned int aeState);\n>\n> @@ -66,6 +69,7 @@ private:\n>  \tstd::map<unsigned int, MappedFrameBuffer> mappedBuffers_;\n>\n>  \tControlInfoMap sensorCtrls_;\n> +\tstd::optional<ControlInfoMap> lensCtrls_;\n>\n>  \t/* Camera sensor controls. */\n>  \tbool autoExposure_;\n> @@ -162,6 +166,14 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info,\n>  \t\treturn -EINVAL;\n>  \t}\n>\n> +\tauto lensControls = entityControls.find(1);\n> +\tif (lensControls != entityControls.end()) {\n\nWe shold really get rid of entityControls[] and pass paramters by\nname. Not for this patch though\n\n> +\t\tif (validateLensControls(lensControls->second))\n> +\t\t\tlensCtrls_ = lensControls->second;\n> +\t\telse\n> +\t\t\tLOG(IPARkISP1, Error) << \"Lens control validation failed.\";\n> +\t}\n> +\n>  \tautoExposure_ = true;\n>\n>  \tint32_t minExposure = itExp->second.min().get<int32_t>();\n> @@ -205,6 +217,23 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info,\n>  \treturn 0;\n>  }\n>\n> +bool IPARkISP1::validateLensControls(const ControlInfoMap &lensControls)\n\nI wonder if this is worth it, it's a single control, but I guess it\ndoesn't hurt..\n\n> +{\n> +\tstatic const uint32_t ctrls[] = {\n> +\t\tV4L2_CID_FOCUS_ABSOLUTE,\n> +\t};\n> +\n> +\tfor (auto c : ctrls) {\n> +\t\tif (lensControls.find(c) == lensControls.end()) {\n> +\t\t\tLOG(IPARkISP1, Error) << \"Unable to find lens control \"\n> +\t\t\t\t\t      << utils::hex(c);\n> +\t\t\treturn false;\n> +\t\t}\n> +\t}\n> +\n> +\treturn true;\n> +}\n> +\n>  void IPARkISP1::mapBuffers(const std::vector<IPABuffer> &buffers)\n>  {\n>  \tfor (const IPABuffer &buffer : buffers) {\n> @@ -289,6 +318,13 @@ void IPARkISP1::setControls(unsigned int frame)\n>  \tctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast<int32_t>(gain));\n>\n>  \tsetSensorControls.emit(frame, ctrls);\n> +\n> +\tif (lensCtrls_) {\n> +\t\tControlList lensCtrls(*lensCtrls_);\n> +\t\tlensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE,\n> +\t\t\t      static_cast<int32_t>(context_.frameContext.af.focus));\n> +\t\tsetLensControls.emit(lensCtrls);\n> +\t}\n>  }\n>\n>  void IPARkISP1::prepareMetadata(unsigned int frame, unsigned int aeState)\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index 363273b2..55d3e3a9 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -320,6 +320,7 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision)\n>  \t\treturn -ENOENT;\n>\n>  \tipa_->setSensorControls.connect(this, &RkISP1CameraData::setSensorControls);\n> +\tipa_->setLensControls.connect(this, &RkISP1CameraData::setLensControls);\n>  \tipa_->paramsBufferReady.connect(this, &RkISP1CameraData::paramFilled);\n>  \tipa_->metadataReady.connect(this, &RkISP1CameraData::metadataReady);\n\nNice!\n\nThanks\n   j\n\n>\n> --\n> 2.34.1\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 8FF4CBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 14 Jul 2022 15:01:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EFD2363312;\n\tThu, 14 Jul 2022 17:01:12 +0200 (CEST)","from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[IPv6:2001:4b98:dc4:8::230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A95D86330D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 14 Jul 2022 17:01:11 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id D4686240003;\n\tThu, 14 Jul 2022 15:01:10 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1657810873;\n\tbh=aVvAArEXYpVa04RNTsha4SnFCHEUDMpYZwBJ0WN6eqE=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=u8MO6JvE8TFHRKKXMZs8P1UdU9h7KScEX78+q+y5q8RUgCRhQpF006Bh+aucRzTm1\n\t5OdJfRfJlOrlqBd2p9qvNXYGIBOYlbl8JKmVCqLziedYEes3UHa+gJ3kp4s62oBXra\n\tsRxEiyB04rj1XYIlz4GeQ+430ksAbyLHCedlAehrdYL9e+hXdB5JfNhCgoEqxPJGhi\n\teIAyZzdGpqB680sJn8H9DTqTq0tDZbyn0Dcq/5BJIpM2H3oDpnobvNOQj7rKHpOaNt\n\taJgdUV7T42L5ymX6bVStHshZQffNZ1SKLBRCs1EYPR97NdT6HNlXg3NUUDvyCbC6HP\n\tVdjG00ml1Ftwg==","Date":"Thu, 14 Jul 2022 17:01:09 +0200","To":"Daniel Semkowicz <dse@thaumatec.com>","Message-ID":"<20220714150109.7nhww6gyztxpbukn@uno.localdomain>","References":"<20220628090656.19572-1-dse@thaumatec.com>\n\t<20220628090656.19572-4-dse@thaumatec.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220628090656.19572-4-dse@thaumatec.com>","Subject":"Re: [libcamera-devel] [PATCH 3/3] libcamera: rkisp1: Control the\n\tlens from IPA","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":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]