Show a patch.

GET /api/1.1/patches/17382/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 17382,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/17382/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17382/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20220920062351.3697066-1-paul.elder@ideasonboard.com>",
    "date": "2022-09-20T06:23:51",
    "name": "[libcamera-devel,v2] ipa: rkisp1: Add support for manual gain and exposure",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "426e9172bddd199326911c74cdeb8fc572d27e63",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/17382/mbox/",
    "series": [
        {
            "id": 3493,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3493/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3493",
            "date": "2022-09-20T06:23:51",
            "name": "[libcamera-devel,v2] ipa: rkisp1: Add support for manual gain and exposure",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/3493/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17382/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17382/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 B013DC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 20 Sep 2022 06:24:06 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E8C54621A4;\n\tTue, 20 Sep 2022 08:24:05 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1A52F600AA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 20 Sep 2022 08:24:04 +0200 (CEST)",
            "from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp\n\t[175.177.42.159])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9FF636BE;\n\tTue, 20 Sep 2022 08:24:02 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1663655046;\n\tbh=IbrVApm5i/n+U3b4W3dR0xZFkWNY31EASgDT7PfKtqk=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=epOapROMuwuA2pCZlphkXo5f2R5+V0cI+Hqi9QhbX00XnbpBwDIaLP5bOq6dZuj4q\n\tllFnUJ5uJlJP+6jBLGIyGTiqmV/+YKBOQgiC8nq98yDiO8kIe8Hwy4RSuawNG/ICMO\n\tQKyI7jF43MmA5N3qCM3EnLAtWG7WQ5T2Lk/jiin+RpwBm1V/MaAUmT+M2tlxaMu51v\n\tXzI6yQhllXqJNptaZFT83mZ6TCmgU1WYBGkM8BXh0Zm9152T2MmAKn8blQpif/swxw\n\tx4llSs1IZJQUjNnPMaq8sCc4IzDRpJ18u5K28XKmk5QEOeoRWMMMOGDkxgj7VLDbzj\n\tsEZ5sYvwKQgAw==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1663655043;\n\tbh=IbrVApm5i/n+U3b4W3dR0xZFkWNY31EASgDT7PfKtqk=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=IM2blyA3Ln9wxZBuvf81X9E23pGNPoS83a56dWSTDRZdUEWOAUgAJBfDjGj5kmvX3\n\twhqR4Qj4epsYGK8iTFhawDh7fbn8zGNpOkfeYm4Kf3Ygwmi8X0R+N4/4OokDmc7DYT\n\tQ2kXCFu+tRU4r+DeSvs4z8J5qZ5Pf3O9y2U5/KPk="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"IM2blyA3\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 20 Sep 2022 15:23:51 +0900",
        "Message-Id": "<20220920062351.3697066-1-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.30.2",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2] ipa: rkisp1: Add support for manual\n\tgain and exposure",
        "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": "Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Paul Elder <paul.elder@ideasonboard.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Add support for manual gain and exposure in the rkisp1 IPA.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nThis patch depends on v4 of the series: \"ipa: Frame context queue, IPU3\n& RkISP consolidation, and RkISP1 improvements\"\n\nChanges in v2:\n- set the min and max values of ExposureTime and AnalogueGain properly\n  - to that end, plumb the sensorControls through the pipeline handler's\n    loadIPA() and the IPA's init()\n---\n include/libcamera/ipa/rkisp1.mojom       |  2 +-\n src/ipa/rkisp1/algorithms/agc.cpp        | 59 +++++++++++++++++++++---\n src/ipa/rkisp1/algorithms/agc.h          |  4 ++\n src/ipa/rkisp1/ipa_context.h             | 13 +++++-\n src/ipa/rkisp1/rkisp1.cpp                | 17 +++++++\n src/libcamera/pipeline/rkisp1/rkisp1.cpp |  9 ++--\n 6 files changed, 91 insertions(+), 13 deletions(-)",
    "diff": "diff --git a/include/libcamera/ipa/rkisp1.mojom b/include/libcamera/ipa/rkisp1.mojom\nindex eaf3955e..b526450d 100644\n--- a/include/libcamera/ipa/rkisp1.mojom\n+++ b/include/libcamera/ipa/rkisp1.mojom\n@@ -10,7 +10,7 @@ import \"include/libcamera/ipa/core.mojom\";\n \n interface IPARkISP1Interface {\n \tinit(libcamera.IPASettings settings,\n-\t     uint32 hwRevision)\n+\t     uint32 hwRevision, libcamera.ControlInfoMap sensorControls)\n \t\t=> (int32 ret, libcamera.ControlInfoMap ipaControls);\n \tstart() => (int32 ret);\n \tstop();\ndiff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\nindex bc764142..d26b35ed 100644\n--- a/src/ipa/rkisp1/algorithms/agc.cpp\n+++ b/src/ipa/rkisp1/algorithms/agc.cpp\n@@ -14,6 +14,7 @@\n #include <libcamera/base/log.h>\n #include <libcamera/base/utils.h>\n \n+#include <libcamera/control_ids.h>\n #include <libcamera/ipa/core_ipa_interface.h>\n \n #include \"libipa/histogram.h\"\n@@ -73,8 +74,11 @@ Agc::Agc()\n int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n {\n \t/* Configure the default exposure and gain. */\n-\tcontext.activeState.agc.gain = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);\n-\tcontext.activeState.agc.exposure = 10ms / context.configuration.sensor.lineDuration;\n+\tcontext.activeState.agc.automatic.gain = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);\n+\tcontext.activeState.agc.automatic.exposure = 10ms / context.configuration.sensor.lineDuration;\n+\tcontext.activeState.agc.manual.gain = context.activeState.agc.automatic.gain;\n+\tcontext.activeState.agc.manual.exposure = context.activeState.agc.automatic.exposure;\n+\tcontext.activeState.agc.autoEnabled = true;\n \n \t/*\n \t * According to the RkISP1 documentation:\n@@ -221,8 +225,8 @@ void Agc::computeExposure(IPAContext &context, RkISP1FrameContext &frameContext,\n \t\t\t      << stepGain;\n \n \t/* Update the estimated exposure and gain. */\n-\tactiveState.agc.exposure = shutterTime / configuration.sensor.lineDuration;\n-\tactiveState.agc.gain = stepGain;\n+\tactiveState.agc.automatic.exposure = shutterTime / configuration.sensor.lineDuration;\n+\tactiveState.agc.automatic.gain = stepGain;\n }\n \n /**\n@@ -331,8 +335,10 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n void Agc::prepare(IPAContext &context, const uint32_t frame,\n \t\t  RkISP1FrameContext &frameContext, rkisp1_params_cfg *params)\n {\n-\tframeContext.agc.exposure = context.activeState.agc.exposure;\n-\tframeContext.agc.gain = context.activeState.agc.gain;\n+\tif (frameContext.agc.autoEnabled) {\n+\t\tframeContext.agc.exposure = context.activeState.agc.automatic.exposure;\n+\t\tframeContext.agc.gain = context.activeState.agc.automatic.gain;\n+\t}\n \n \tif (frame > 0)\n \t\treturn;\n@@ -365,6 +371,47 @@ void Agc::prepare(IPAContext &context, const uint32_t frame,\n \tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_HST;\n }\n \n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::queueRequest\n+ */\n+void Agc::queueRequest(IPAContext &context,\n+\t\t       [[maybe_unused]] const uint32_t frame,\n+\t\t       RkISP1FrameContext &frameContext,\n+\t\t       const ControlList &controls)\n+{\n+\tauto &agc = context.activeState.agc;\n+\n+\tconst auto &agcEnable = controls.get(controls::AeEnable);\n+\tif (agcEnable && *agcEnable != agc.autoEnabled) {\n+\t\tagc.autoEnabled = *agcEnable;\n+\n+\t\tLOG(RkISP1Agc, Debug)\n+\t\t\t<< (*agcEnable ? \"Enabling\" : \"Disabling\") << \" AGC\";\n+\t}\n+\n+\tconst auto &exposure = controls.get(controls::ExposureTime);\n+\tif (exposure && !agc.autoEnabled) {\n+\t\tagc.manual.exposure = *exposure;\n+\n+\t\tLOG(RkISP1Agc, Debug)\n+\t\t\t<< \"Set exposure to: \" << agc.manual.exposure;\n+\t}\n+\n+\tconst auto &gain = controls.get(controls::AnalogueGain);\n+\tif (gain && !agc.autoEnabled) {\n+\t\tagc.manual.gain = *gain;\n+\n+\t\tLOG(RkISP1Agc, Debug) << \"Set gain to: \" << agc.manual.gain;\n+\t}\n+\n+\tframeContext.agc.autoEnabled = agc.autoEnabled;\n+\n+\tif (!frameContext.agc.autoEnabled) {\n+\t\tframeContext.agc.exposure = agc.manual.exposure;\n+\t\tframeContext.agc.gain = agc.manual.gain;\n+\t}\n+}\n+\n REGISTER_IPA_ALGORITHM(Agc, \"Agc\")\n \n } /* namespace ipa::rkisp1::algorithms */\ndiff --git a/src/ipa/rkisp1/algorithms/agc.h b/src/ipa/rkisp1/algorithms/agc.h\nindex d6c6fb13..e624f101 100644\n--- a/src/ipa/rkisp1/algorithms/agc.h\n+++ b/src/ipa/rkisp1/algorithms/agc.h\n@@ -32,6 +32,10 @@ public:\n \tvoid process(IPAContext &context, const uint32_t frame,\n \t\t     RkISP1FrameContext &frameContext,\n \t\t     const rkisp1_stat_buffer *stats) override;\n+\tvoid queueRequest(IPAContext &context,\n+\t\t\t  const uint32_t frame,\n+\t\t\t  RkISP1FrameContext &frameContext,\n+\t\t\t  const ControlList &controls) override;\n \n private:\n \tvoid computeExposure(IPAContext &Context, RkISP1FrameContext &frameContext,\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex d0bc9090..df72ec87 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -50,8 +50,16 @@ struct IPASessionConfiguration {\n \n struct IPAActiveState {\n \tstruct {\n-\t\tuint32_t exposure;\n-\t\tdouble gain;\n+\t\tstruct {\n+\t\t\tuint32_t exposure;\n+\t\t\tdouble gain;\n+\t\t} manual;\n+\t\tstruct {\n+\t\t\tuint32_t exposure;\n+\t\t\tdouble gain;\n+\t\t} automatic;\n+\n+\t\tbool autoEnabled;\n \t} agc;\n \n \tstruct {\n@@ -92,6 +100,7 @@ struct RkISP1FrameContext : public FrameContext {\n \tstruct {\n \t\tuint32_t exposure;\n \t\tdouble gain;\n+\t\tbool autoEnabled;\n \t} agc;\n \n \tstruct {\ndiff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\nindex 75370ac8..5be045a0 100644\n--- a/src/ipa/rkisp1/rkisp1.cpp\n+++ b/src/ipa/rkisp1/rkisp1.cpp\n@@ -49,6 +49,7 @@ public:\n \tIPARkISP1();\n \n \tint init(const IPASettings &settings, unsigned int hwRevision,\n+\t\t const ControlInfoMap &sensorControls,\n \t\t ControlInfoMap *ipaControls) override;\n \tint start() override;\n \tvoid stop() override;\n@@ -116,6 +117,7 @@ std::string IPARkISP1::logPrefix() const\n }\n \n int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision,\n+\t\t    const ControlInfoMap &sensorControls,\n \t\t    ControlInfoMap *ipaControls)\n {\n \t/* \\todo Add support for other revisions */\n@@ -183,6 +185,21 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision,\n \n \t/* Return the controls handled by the IPA. */\n \tControlInfoMap::Map ctrlMap = rkisp1Controls;\n+\n+\tauto exposureTimeInfo = sensorControls.find(V4L2_CID_EXPOSURE);\n+\tif (exposureTimeInfo != sensorControls.end()) {\n+\t\tctrlMap.emplace(&controls::ExposureTime,\n+\t\t\t\tControlInfo(exposureTimeInfo->second.min(),\n+\t\t\t\t\t    exposureTimeInfo->second.max()));\n+\t}\n+\n+\tauto analogueGainInfo = sensorControls.find(V4L2_CID_ANALOGUE_GAIN);\n+\tif (analogueGainInfo != sensorControls.end()) {\n+\t\tctrlMap.emplace(&controls::AnalogueGain,\n+\t\t\t\tControlInfo(static_cast<float>(analogueGainInfo->second.min().get<int32_t>()),\n+\t\t\t\t\t    static_cast<float>(analogueGainInfo->second.max().get<int32_t>())));\n+\t}\n+\n \t*ipaControls = ControlInfoMap(std::move(ctrlMap), controls::controls);\n \n \treturn 0;\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 25fbf9f1..3b9f77e8 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -89,7 +89,7 @@ public:\n \t}\n \n \tPipelineHandlerRkISP1 *pipe();\n-\tint loadIPA(unsigned int hwRevision);\n+\tint loadIPA(unsigned int hwRevision, const ControlInfoMap &sensorControls);\n \n \tStream mainPathStream_;\n \tStream selfPathStream_;\n@@ -317,7 +317,8 @@ PipelineHandlerRkISP1 *RkISP1CameraData::pipe()\n \treturn static_cast<PipelineHandlerRkISP1 *>(Camera::Private::pipe());\n }\n \n-int RkISP1CameraData::loadIPA(unsigned int hwRevision)\n+int RkISP1CameraData::loadIPA(unsigned int hwRevision,\n+\t\t\t      const ControlInfoMap &sensorControls)\n {\n \tipa_ = IPAManager::createIPA<ipa::rkisp1::IPAProxyRkISP1>(pipe(), 1, 1);\n \tif (!ipa_)\n@@ -346,7 +347,7 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision)\n \t}\n \n \tint ret = ipa_->init({ ipaTuningFile, sensor_->model() }, hwRevision,\n-\t\t\t     &controlInfo_);\n+\t\t\t     sensorControls, &controlInfo_);\n \tif (ret < 0) {\n \t\tLOG(RkISP1, Error) << \"IPA initialization failure\";\n \t\treturn ret;\n@@ -1019,7 +1020,7 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n \tisp_->frameStart.connect(data->delayedCtrls_.get(),\n \t\t\t\t &DelayedControls::applyControls);\n \n-\tret = data->loadIPA(media_->hwRevision());\n+\tret = data->loadIPA(media_->hwRevision(), data->sensor_->controls());\n \tif (ret)\n \t\treturn ret;\n \n",
    "prefixes": [
        "libcamera-devel",
        "v2"
    ]
}