Show a patch.

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

{
    "id": 14209,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/14209/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/14209/",
    "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": "<20211020154607.180161-3-jeanmichel.hautbois@ideasonboard.com>",
    "date": "2021-10-20T15:45:56",
    "name": "[libcamera-devel,v2,02/13] ipa: ipu3: set frameContext before controls",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "c3aaf76cca815db9a493d8a7153af87c7cd0f8c3",
    "submitter": {
        "id": 75,
        "url": "https://patchwork.libcamera.org/api/1.1/people/75/?format=api",
        "name": "Jean-Michel Hautbois",
        "email": "jeanmichel.hautbois@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/14209/mbox/",
    "series": [
        {
            "id": 2645,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2645/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2645",
            "date": "2021-10-20T15:45:54",
            "name": "ipa: ipu3: Fix AGC bugs",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/2645/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/14209/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/14209/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 E95FFBDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 20 Oct 2021 15:46:20 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 87F1868F6B;\n\tWed, 20 Oct 2021 17:46:17 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A44FA68F58\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Oct 2021 17:46:13 +0200 (CEST)",
            "from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:ce4b:1c5f:7302:b899])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 564224A0;\n\tWed, 20 Oct 2021 17:46:13 +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=\"i15+H9ND\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1634744773;\n\tbh=L5ufunWOH5Fu6bhjrBtMchLEPZGadrcBMb+m+59/cVY=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=i15+H9NDowTkGfHyOb164vSrMGXSShaW4luze1HknyG2fkIZSbgwDuX1GKiFIUD+r\n\tz/dV/kLLKloLQMld5C9s2R9j5Pk0HC0fxdaNxZkLanEz/mgNEPdOhcZLjO8GwE+x2w\n\twX0PPSVIpSNd3QXCWjUAB9dSndc02Na0oTfKQuxo=",
        "From": "Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 20 Oct 2021 17:45:56 +0200",
        "Message-Id": "<20211020154607.180161-3-jeanmichel.hautbois@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<20211020154607.180161-1-jeanmichel.hautbois@ideasonboard.com>",
        "References": "<20211020154607.180161-1-jeanmichel.hautbois@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 02/13] ipa: ipu3: set frameContext\n\tbefore 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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The AGC frame context needs to be initialised correctly for the first\niteration.\n\nSet the gain and exposure appropriately to the current values known to\nthe IPA.\n\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/ipu3/algorithms/agc.cpp |  8 ++++-\n src/ipa/ipu3/ipa_context.h      |  9 +++++\n src/ipa/ipu3/ipu3.cpp           | 64 +++++++++++++++++++++++++++++----\n 3 files changed, 73 insertions(+), 8 deletions(-)",
    "diff": "diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex 970ec424..a001e349 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -60,7 +60,13 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n \n \tlineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n \t\t      / configInfo.sensorInfo.pixelRate;\n-\tmaxExposureTime_ = kMaxExposure * lineDuration_;\n+\tmaxExposureTime_ = context.configuration.agc.maxShutterSpeed;\n+\n+\t/* Configure the default exposure and gain */\n+\tcontext.frameContext.agc.gain =\n+\t\tcontext.configuration.agc.minAnalogueGain;\n+\tcontext.frameContext.agc.exposure =\n+\t\tcontext.configuration.agc.minShutterSpeed / lineDuration_;\n \n \treturn 0;\n }\ndiff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\nindex 5bab684c..847c03fe 100644\n--- a/src/ipa/ipu3/ipa_context.h\n+++ b/src/ipa/ipu3/ipa_context.h\n@@ -10,6 +10,8 @@\n \n #include <linux/intel-ipu3.h>\n \n+#include <libcamera/base/utils.h>\n+\n #include <libcamera/geometry.h>\n \n namespace libcamera {\n@@ -22,6 +24,13 @@ struct IPASessionConfiguration {\n \t\tSize bdsOutputSize;\n \t\tuint32_t stride;\n \t} grid;\n+\n+\tstruct {\n+\t\tutils::Duration minShutterSpeed;\n+\t\tutils::Duration maxShutterSpeed;\n+\t\tdouble minAnalogueGain;\n+\t\tdouble maxAnalogueGain;\n+\t} agc;\n };\n \n struct IPAFrameContext {\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 388f1902..36ca83f5 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -97,6 +97,23 @@\n  * \\brief Number of cells on one line including the ImgU padding\n  */\n \n+/**\n+ * \\struct IPASessionConfiguration::agc\n+ * \\brief AGC parameters configuration of the IPA\n+ *\n+ * \\var IPASessionConfiguration::agc::minShutterSpeed\n+ * \\brief Minimum shutter speed supported with the configured sensor\n+ *\n+ * \\var IPASessionConfiguration::grid::maxShutterSpeed\n+ * \\brief Maximum shutter speed supported with the configured sensor\n+ *\n+ * \\var IPASessionConfiguration::grid::minAnalogueGain\n+ * \\brief Minimum analogue gain supported with the configured sensor\n+ *\n+ * \\var IPASessionConfiguration::grid::maxAnalogueGain\n+ * \\brief Maximum analogue gain supported with the configured sensor\n+ */\n+\n /**\n  * \\struct IPAFrameContext::agc\n  * \\brief Context for the Automatic Gain Control algorithm\n@@ -158,6 +175,8 @@ namespace libcamera {\n \n LOG_DEFINE_CATEGORY(IPAIPU3)\n \n+using namespace std::literals::chrono_literals;\n+\n namespace ipa::ipu3 {\n \n class IPAIPU3 : public IPAIPU3Interface\n@@ -182,6 +201,8 @@ private:\n \tvoid updateControls(const IPACameraSensorInfo &sensorInfo,\n \t\t\t    const ControlInfoMap &sensorControls,\n \t\t\t    ControlInfoMap *ipaControls);\n+\tvoid updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,\n+\t\t\t\t\tconst ControlInfoMap &sensorControls);\n \tvoid processControls(unsigned int frame, const ControlList &controls);\n \tvoid fillParams(unsigned int frame, ipu3_uapi_params *params);\n \tvoid parseStatistics(unsigned int frame,\n@@ -216,6 +237,36 @@ private:\n \tstruct IPAContext context_;\n };\n \n+/*\n+ * Compute IPASessionConfiguration using the sensor information and the sensor\n+ * v4l2 controls.\n+ */\n+void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,\n+\t\t\t\t\t const ControlInfoMap &sensorControls)\n+{\n+\tconst ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;\n+\tint32_t minExposure = v4l2Exposure.min().get<int32_t>();\n+\tint32_t maxExposure = v4l2Exposure.max().get<int32_t>();\n+\n+\tutils::Duration lineDuration = sensorInfo.lineLength * 1.0s\n+\t\t\t\t     / sensorInfo.pixelRate;\n+\n+\tconst ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second;\n+\tint32_t minGain = v4l2Gain.min().get<int32_t>();\n+\tint32_t maxGain = v4l2Gain.max().get<int32_t>();\n+\n+\t/*\n+\t * When the AGC computes the new exposure values for a frame, it needs\n+\t * to know the limits for shutter speed and analogue gain.\n+\t * As it depends on the sensor, update it with the controls.\n+\t *\n+\t * \\todo take VBLANK into account for maximum shutter speed\n+\t */\n+\tcontext_.configuration.agc.minShutterSpeed = minExposure * lineDuration;\n+\tcontext_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration;\n+\tcontext_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);\n+\tcontext_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);\n+}\n \n /*\n  * Compute camera controls using the sensor information and the sensor\n@@ -436,15 +487,18 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n \n \tcalculateBdsGrid(configInfo.bdsOutputSize);\n \n+\t/* Update the camera controls using the new sensor settings. */\n+\tupdateControls(sensorInfo_, ctrls_, ipaControls);\n+\n+\t/* Update the IPASessionConfiguration using the sensor settings */\n+\tupdateSessionConfiguration(sensorInfo_, ctrls_);\n+\n \tfor (auto const &algo : algorithms_) {\n \t\tint ret = algo->configure(context_, configInfo);\n \t\tif (ret)\n \t\t\treturn ret;\n \t}\n \n-\t/* Update the camera controls using the new sensor settings. */\n-\tupdateControls(sensorInfo_, ctrls_, ipaControls);\n-\n \treturn 0;\n }\n \n@@ -543,10 +597,6 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n {\n \tControlList ctrls(controls::controls);\n \n-\t/* \\todo These fields should not be written by the IPAIPU3 layer */\n-\tcontext_.frameContext.agc.gain = camHelper_->gain(gain_);\n-\tcontext_.frameContext.agc.exposure = exposure_;\n-\n \tfor (auto const &algo : algorithms_)\n \t\talgo->process(context_, stats);\n \n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "02/13"
    ]
}