Show a patch.

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

{
    "id": 20311,
    "url": "https://patchwork.libcamera.org/api/patches/20311/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20311/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20240614074214.3600996-3-paul.elder@ideasonboard.com>",
    "date": "2024-06-14T07:42:14",
    "name": "[v6,2/2] ipa: rkisp1: agc: Plumb mode-selection and frame duration controls",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "0291a4e67453eeb10dea4acf7dfd97d684d62b7a",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20311/mbox/",
    "series": [
        {
            "id": 4392,
            "url": "https://patchwork.libcamera.org/api/series/4392/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4392",
            "date": "2024-06-14T07:42:12",
            "name": "ipa: rkisp1: Improve AGC (plumbing)",
            "version": 6,
            "mbox": "https://patchwork.libcamera.org/series/4392/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20311/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20311/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 9DA51C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 14 Jun 2024 07:42:34 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5D78565489;\n\tFri, 14 Jun 2024 09:42:34 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 076126548D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 14 Jun 2024 09:42:32 +0200 (CEST)",
            "from neptunite.hamster-moth.ts.net\n\t(h175-177-049-156.catv02.itscom.jp [175.177.49.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 56ACF10C4;\n\tFri, 14 Jun 2024 09:42:14 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"vC2gMbNx\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1718350937;\n\tbh=+oRxh4XOdw5+JqwcGsdMmvKdL/4hppRKFcsHT22TKVE=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=vC2gMbNxNkI3kEW+QCqlxJEW89T+5/5VCGBc143jdaUWFA4Tn7ub71DekzW+ge86N\n\tt44d0f+f6P2aHFhTsm1W4hceU41avT5/yjlEPfOVF0D1IAsmYi30RxiYXvRlXWPMbN\n\tajMW1kSibB5WoFcFXCAsPfo3a3INyWzDdVPldpXs=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Paul Elder <paul.elder@ideasonboard.com>,\n\tStefan Klug <stefan.klug@ideasonboard.com>",
        "Subject": "[PATCH v6 2/2] ipa: rkisp1: agc: Plumb mode-selection and frame\n\tduration controls",
        "Date": "Fri, 14 Jun 2024 16:42:14 +0900",
        "Message-Id": "<20240614074214.3600996-3-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.39.2",
        "In-Reply-To": "<20240614074214.3600996-1-paul.elder@ideasonboard.com>",
        "References": "<20240614074214.3600996-1-paul.elder@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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": "Plumb controls for setting metering mode, exposure mode, constraint\nmode, and frame duration limits. Also report them as available controls,\nas well as in metadata.\n\nWhile at it, add the missing #include for tuple, as a std::tie is used.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\nChanges in v6:\n- remove the extra Algorithm::controls_\n- remove the intermediate variable for accumulating the metering modes\n- only update parameters when they are changed\n- change the types of the control modes in the IPA cotext from ints to\n  enums\n  - add the appropriate casts when used\n- initialize maxShutterSpeed at configure time to avoid the awkward\n  extra check to ensure that it isn't zero\n  - add a todo that FrameDurationLimits should be initialized in agc and\n    not in the IPA\n\nNo change in v5\n\nNo change in v4\n\nChanges in v3:\n- prevent maxShutterSpeed (for setLimits) from choosing 0 shutter speed\n  if one of the inputs std::min() is not set (this fixes an assertion\n  failure in the exposure mode helper)\n\nChanges in v2:\n- add #include <tuple>\n- don't overwrite metering/exposure/constraint mode controls to default\n  if no control is supplied, and retain the old value instead (same for\n  frame duration limits)\n---\n src/ipa/rkisp1/algorithms/agc.cpp | 76 ++++++++++++++++++++++++++++---\n src/ipa/rkisp1/ipa_context.h      | 12 ++++-\n 2 files changed, 79 insertions(+), 9 deletions(-)",
    "diff": "diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\nindex 5a9c6be118d9..8702145187c7 100644\n--- a/src/ipa/rkisp1/algorithms/agc.cpp\n+++ b/src/ipa/rkisp1/algorithms/agc.cpp\n@@ -10,6 +10,8 @@\n #include <algorithm>\n #include <chrono>\n #include <cmath>\n+#include <tuple>\n+#include <vector>\n \n #include <libcamera/base/log.h>\n #include <libcamera/base/utils.h>\n@@ -74,6 +76,13 @@ int Agc::parseMeteringModes(IPAContext &context, const YamlObject &tuningData)\n \t\tmeteringModes_[meteringModeId] = weights;\n \t}\n \n+\tstd::vector<ControlValue> meteringModes;\n+\tstd::vector<int> meteringModeKeys = utils::map_keys(meteringModes_);\n+\tstd::transform(meteringModeKeys.begin(), meteringModeKeys.end(),\n+\t\t       std::back_inserter(meteringModes),\n+\t\t       [](int x) { return ControlValue(x); });\n+\tcontext.ctrlMap[&controls::AeMeteringMode] = ControlInfo(meteringModes);\n+\n \treturn 0;\n }\n \n@@ -167,8 +176,19 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n \tcontext.activeState.agc.manual.exposure = context.activeState.agc.automatic.exposure;\n \tcontext.activeState.agc.autoEnabled = !context.configuration.raw;\n \n-\tcontext.activeState.agc.constraintMode = constraintModes().begin()->first;\n-\tcontext.activeState.agc.exposureMode = exposureModeHelpers().begin()->first;\n+\tcontext.activeState.agc.constraintMode =\n+\t\tstatic_cast<controls::AeConstraintModeEnum>(constraintModes().begin()->first);\n+\tcontext.activeState.agc.exposureMode =\n+\t\tstatic_cast<controls::AeExposureModeEnum>(exposureModeHelpers().begin()->first);\n+\tcontext.activeState.agc.meteringMode =\n+\t\tstatic_cast<controls::AeMeteringModeEnum>(meteringModes_.begin()->first);\n+\n+\t/*\n+\t * \\todo This should probably come from FrameDurationLimits instead,\n+\t * except it's computed in the IPA and not here so we'd have to\n+\t * recompute it.\n+\t */\n+\tcontext.activeState.agc.maxShutterSpeed = context.configuration.sensor.maxShutterSpeed;\n \n \t/*\n \t * Define the measurement window for AGC as a centered rectangle\n@@ -179,7 +199,6 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n \tcontext.configuration.agc.measureWindow.h_size = 3 * configInfo.outputSize.width / 4;\n \tcontext.configuration.agc.measureWindow.v_size = 3 * configInfo.outputSize.height / 4;\n \n-\t/* \\todo Run this again when FrameDurationLimits is passed in */\n \tsetLimits(context.configuration.sensor.minShutterSpeed,\n \t\t  context.configuration.sensor.maxShutterSpeed,\n \t\t  context.configuration.sensor.minAnalogueGain,\n@@ -233,6 +252,39 @@ void Agc::queueRequest(IPAContext &context,\n \t\tframeContext.agc.exposure = agc.manual.exposure;\n \t\tframeContext.agc.gain = agc.manual.gain;\n \t}\n+\n+\tconst auto &meteringMode = controls.get(controls::AeMeteringMode);\n+\tif (meteringMode) {\n+\t\tframeContext.agc.update = agc.meteringMode != *meteringMode;\n+\t\tagc.meteringMode =\n+\t\t\tstatic_cast<controls::AeMeteringModeEnum>(*meteringMode);\n+\t}\n+\tframeContext.agc.meteringMode = agc.meteringMode;\n+\n+\tconst auto &exposureMode = controls.get(controls::AeExposureMode);\n+\tif (exposureMode) {\n+\t\tframeContext.agc.update = agc.exposureMode != *exposureMode;\n+\t\tagc.exposureMode =\n+\t\t\tstatic_cast<controls::AeExposureModeEnum>(*exposureMode);\n+\t}\n+\tframeContext.agc.exposureMode = agc.exposureMode;\n+\n+\tconst auto &constraintMode = controls.get(controls::AeConstraintMode);\n+\tif (constraintMode) {\n+\t\tframeContext.agc.update = agc.constraintMode != *constraintMode;\n+\t\tagc.constraintMode =\n+\t\t\tstatic_cast<controls::AeConstraintModeEnum>(*constraintMode);\n+\t}\n+\tframeContext.agc.constraintMode = agc.constraintMode;\n+\n+\tconst auto &frameDurationLimits = controls.get(controls::FrameDurationLimits);\n+\tif (frameDurationLimits) {\n+\t\tutils::Duration maxShutterSpeed =\n+\t\t\tstd::chrono::milliseconds((*frameDurationLimits).back());\n+\t\tframeContext.agc.update = agc.maxShutterSpeed != maxShutterSpeed;\n+\t\tagc.maxShutterSpeed = maxShutterSpeed;\n+\t}\n+\tframeContext.agc.maxShutterSpeed = agc.maxShutterSpeed;\n }\n \n /**\n@@ -246,8 +298,7 @@ void Agc::prepare(IPAContext &context, const uint32_t frame,\n \t\tframeContext.agc.gain = context.activeState.agc.automatic.gain;\n \t}\n \n-\t/* \\todo Remove this when we can set the below with controls */\n-\tif (frame > 0)\n+\tif (frame > 0 && !frameContext.agc.update)\n \t\treturn;\n \n \t/* Configure the measurement window. */\n@@ -271,8 +322,7 @@ void Agc::prepare(IPAContext &context, const uint32_t frame,\n \t\tparams->meas.hst_config.hist_weight,\n \t\tcontext.hw->numHistogramWeights\n \t};\n-\t/* \\todo Get this from control */\n-\tstd::vector<uint8_t> &modeWeights = meteringModes_.at(controls::MeteringMatrix);\n+\tstd::vector<uint8_t> &modeWeights = meteringModes_.at(frameContext.agc.meteringMode);\n \tstd::copy(modeWeights.begin(), modeWeights.end(), weights.begin());\n \n \tstruct rkisp1_cif_isp_window window = params->meas.hst_config.meas_window;\n@@ -295,6 +345,7 @@ void Agc::fillMetadata(IPAContext &context, IPAFrameContext &frameContext,\n \t\t\t\t     * frameContext.sensor.exposure;\n \tmetadata.set(controls::AnalogueGain, frameContext.sensor.gain);\n \tmetadata.set(controls::ExposureTime, exposureTime.get<std::micro>());\n+\tmetadata.set(controls::AeEnable, frameContext.agc.autoEnabled);\n \n \t/* \\todo Use VBlank value calculated from each frame exposure. */\n \tuint32_t vTotal = context.configuration.sensor.size.height\n@@ -302,6 +353,10 @@ void Agc::fillMetadata(IPAContext &context, IPAFrameContext &frameContext,\n \tutils::Duration frameDuration = context.configuration.sensor.lineDuration\n \t\t\t\t      * vTotal;\n \tmetadata.set(controls::FrameDuration, frameDuration.get<std::micro>());\n+\n+\tmetadata.set(controls::AeMeteringMode, frameContext.agc.meteringMode);\n+\tmetadata.set(controls::AeExposureMode, frameContext.agc.exposureMode);\n+\tmetadata.set(controls::AeConstraintMode, frameContext.agc.constraintMode);\n }\n \n /**\n@@ -376,6 +431,13 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \t\t       [](uint32_t x) { return x >> 4; });\n \texpMeans_ = { params->ae.exp_mean, context.hw->numAeCells };\n \n+\tutils::Duration maxShutterSpeed = std::min(context.configuration.sensor.maxShutterSpeed,\n+\t\t\t\t\t\t   frameContext.agc.maxShutterSpeed);\n+\tsetLimits(context.configuration.sensor.minShutterSpeed,\n+\t\t  maxShutterSpeed,\n+\t\t  context.configuration.sensor.minAnalogueGain,\n+\t\t  context.configuration.sensor.maxAnalogueGain);\n+\n \t/*\n \t * The Agc algorithm needs to know the effective exposure value that was\n \t * applied to the sensor when the statistics were collected.\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex 2a994d81ae41..6022480d4fd2 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -12,6 +12,7 @@\n \n #include <libcamera/base/utils.h>\n \n+#include <libcamera/control_ids.h>\n #include <libcamera/controls.h>\n #include <libcamera/geometry.h>\n \n@@ -68,8 +69,10 @@ struct IPAActiveState {\n \t\t} automatic;\n \n \t\tbool autoEnabled;\n-\t\tuint32_t constraintMode;\n-\t\tuint32_t exposureMode;\n+\t\tcontrols::AeConstraintModeEnum constraintMode;\n+\t\tcontrols::AeExposureModeEnum exposureMode;\n+\t\tcontrols::AeMeteringModeEnum meteringMode;\n+\t\tutils::Duration maxShutterSpeed;\n \t} agc;\n \n \tstruct {\n@@ -115,6 +118,11 @@ struct IPAFrameContext : public FrameContext {\n \t\tuint32_t exposure;\n \t\tdouble gain;\n \t\tbool autoEnabled;\n+\t\tcontrols::AeConstraintModeEnum constraintMode;\n+\t\tcontrols::AeExposureModeEnum exposureMode;\n+\t\tcontrols::AeMeteringModeEnum meteringMode;\n+\t\tutils::Duration maxShutterSpeed;\n+\t\tbool update;\n \t} agc;\n \n \tstruct {\n",
    "prefixes": [
        "v6",
        "2/2"
    ]
}