Show a patch.

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

{
    "id": 20232,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20232/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20232/",
    "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": "<20240607080330.2667994-4-paul.elder@ideasonboard.com>",
    "date": "2024-06-07T08:03:30",
    "name": "[v5,3/3] ipa: rkisp1: agc: Plumb mode-selection and frame duration controls",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "1e5e477b94445df32dc77220e1dd598343e17f3b",
    "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/20232/mbox/",
    "series": [
        {
            "id": 4372,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4372/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4372",
            "date": "2024-06-07T08:03:27",
            "name": "ipa: rkisp1: Improve AGC (plumbing)",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/4372/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20232/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20232/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 E3CA7C31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  7 Jun 2024 08:03:59 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 96E2565457;\n\tFri,  7 Jun 2024 10:03:59 +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 B723465466\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  7 Jun 2024 10:03:54 +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 08834230;\n\tFri,  7 Jun 2024 10:03:43 +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=\"lE3FGCf/\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1717747425;\n\tbh=K88SLHj5KqZrGi+HAnvr38dED/UcHR68nNVkJs/rubA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=lE3FGCf/O4q0Ze3tuH4wypVilgD49iFN9CP4Pb3r+ykQ24b6HKSMi0ZZGzLPf/UpL\n\tQeMbqDMTGBv3dsFJZY9c+rOhFdscq+BGFvnV5AzbRtLvOCrULaRkwohK8xSiCegi/u\n\th4Wc+gkNTXqgKYh60oOBp0OqAONiy7zzVpiaAhnI=",
        "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 v5 3/3] ipa: rkisp1: agc: Plumb mode-selection and frame\n\tduration controls",
        "Date": "Fri,  7 Jun 2024 17:03:30 +0900",
        "Message-Id": "<20240607080330.2667994-4-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.39.2",
        "In-Reply-To": "<20240607080330.2667994-1-paul.elder@ideasonboard.com>",
        "References": "<20240607080330.2667994-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---\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     | 55 ++++++++++++++++++++++++---\n src/ipa/rkisp1/algorithms/algorithm.h |  2 +\n src/ipa/rkisp1/ipa_context.h          | 10 ++++-\n src/ipa/rkisp1/rkisp1.cpp             | 10 +++++\n 4 files changed, 70 insertions(+), 7 deletions(-)",
    "diff": "diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\nindex e9f1f2095..c6d03c3b2 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@@ -48,6 +50,7 @@ int Agc::parseMeteringModes(IPAContext &context, const YamlObject &tuningData,\n \t\treturn -EINVAL;\n \t}\n \n+\tstd::vector<ControlValue> availableMeteringModes;\n \tfor (const auto &[key, value] : yamlMeteringModes.asDict()) {\n \t\tif (controls::AeMeteringModeNameValueMap.find(key) ==\n \t\t    controls::AeMeteringModeNameValueMap.end()) {\n@@ -66,17 +69,23 @@ int Agc::parseMeteringModes(IPAContext &context, const YamlObject &tuningData,\n \t\t\t\t<< \"Matched metering matrix mode \"\n \t\t\t\t<< key << \", version \" << version;\n \n-\t\t\tmeteringModes_[controls::AeMeteringModeNameValueMap.at(key)] = weights;\n+\t\t\tint32_t control = controls::AeMeteringModeNameValueMap.at(key);\n+\t\t\tmeteringModes_[control] = weights;\n+\t\t\tavailableMeteringModes.push_back(control);\n \t\t}\n \t}\n \n-\tif (meteringModes_.empty()) {\n+\tif (availableMeteringModes.empty()) {\n \t\tint32_t meteringModeId = controls::AeMeteringModeNameValueMap.at(\"MeteringMatrix\");\n \t\tstd::vector<uint8_t> weights(context.hw->numHistogramWeights, 1);\n \n \t\tmeteringModes_[meteringModeId] = weights;\n+\t\tavailableMeteringModes.push_back(meteringModeId);\n \t}\n \n+\tAlgorithm::controls_[&controls::AeMeteringMode] =\n+\t\tControlInfo(availableMeteringModes);\n+\n \treturn 0;\n }\n \n@@ -137,6 +146,8 @@ int Agc::init(IPAContext &context, const YamlObject &tuningData)\n \n \tcontext.ctrlMap.merge(controls());\n \n+\tAlgorithm::controls_.merge(ControlInfoMap::Map(controls()));\n+\n \treturn 0;\n }\n \n@@ -159,6 +170,7 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n \n \tcontext.activeState.agc.constraintMode = constraintModes().begin()->first;\n \tcontext.activeState.agc.exposureMode = exposureModeHelpers().begin()->first;\n+\tcontext.activeState.agc.meteringMode = meteringModes_.begin()->first;\n \n \t/*\n \t * Define the measurement window for AGC as a centered rectangle\n@@ -169,7 +181,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@@ -223,6 +234,26 @@ 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\tagc.meteringMode = *meteringMode;\n+\tframeContext.agc.meteringMode = agc.meteringMode;\n+\n+\tconst auto &exposureMode = controls.get(controls::AeExposureMode);\n+\tif (exposureMode)\n+\t\tagc.exposureMode = *exposureMode;\n+\tframeContext.agc.exposureMode = agc.exposureMode;\n+\n+\tconst auto &constraintMode = controls.get(controls::AeConstraintMode);\n+\tif (constraintMode)\n+\t\tagc.constraintMode = *constraintMode;\n+\tframeContext.agc.constraintMode = agc.constraintMode;\n+\n+\tconst auto &frameDurationLimits = controls.get(controls::FrameDurationLimits);\n+\tif (frameDurationLimits)\n+\t\tagc.maxShutterSpeed = std::chrono::milliseconds((*frameDurationLimits).back());\n+\tframeContext.agc.maxShutterSpeed = agc.maxShutterSpeed;\n }\n \n /**\n@@ -261,8 +292,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 \tstd::stringstream str;\n@@ -289,6 +319,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@@ -296,6 +327,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@@ -370,6 +405,16 @@ 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+\tif (!maxShutterSpeed)\n+\t\tmaxShutterSpeed = std::max(context.configuration.sensor.maxShutterSpeed,\n+\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/algorithms/algorithm.h b/src/ipa/rkisp1/algorithms/algorithm.h\nindex 715cfcd82..93a4b548c 100644\n--- a/src/ipa/rkisp1/algorithms/algorithm.h\n+++ b/src/ipa/rkisp1/algorithms/algorithm.h\n@@ -25,6 +25,8 @@ public:\n \n \tbool disabled_;\n \tbool supportsRaw_;\n+\n+\tControlInfoMap::Map controls_;\n };\n \n } /* namespace ipa::rkisp1 */\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex bd02a7a24..1cad512e1 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -68,8 +68,10 @@ struct IPAActiveState {\n \t\t} automatic;\n \n \t\tbool autoEnabled;\n-\t\tuint32_t constraintMode;\n-\t\tuint32_t exposureMode;\n+\t\tint32_t constraintMode;\n+\t\tint32_t exposureMode;\n+\t\tint32_t meteringMode;\n+\t\tutils::Duration maxShutterSpeed;\n \t} agc;\n \n \tstruct {\n@@ -111,6 +113,10 @@ struct IPAFrameContext : public FrameContext {\n \t\tuint32_t exposure;\n \t\tdouble gain;\n \t\tbool autoEnabled;\n+\t\tint32_t exposureMode;\n+\t\tint32_t constraintMode;\n+\t\tint32_t meteringMode;\n+\t\tutils::Duration maxShutterSpeed;\n \t} agc;\n \n \tstruct {\ndiff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\nindex 6687c91e7..12b3aedd2 100644\n--- a/src/ipa/rkisp1/rkisp1.cpp\n+++ b/src/ipa/rkisp1/rkisp1.cpp\n@@ -80,6 +80,7 @@ private:\n \tstd::map<unsigned int, MappedFrameBuffer> mappedBuffers_;\n \n \tControlInfoMap sensorControls_;\n+\tControlInfoMap::Map algoControls_;\n \n \t/* Interface to the Camera Helper */\n \tstd::unique_ptr<CameraSensorHelper> camHelper_;\n@@ -193,6 +194,14 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision,\n \tif (ret)\n \t\treturn ret;\n \n+\tfor (auto const &a : algorithms()) {\n+\t\tAlgorithm *algo = static_cast<Algorithm *>(a.get());\n+\n+\t\t/* \\todo Avoid merging duplicate controls */\n+\t\tif (!algo->controls_.empty())\n+\t\t\talgoControls_.merge(ControlInfoMap::Map(algo->controls_));\n+\t}\n+\n \t/* Initialize controls. */\n \tupdateControls(sensorInfo, sensorControls, ipaControls);\n \n@@ -377,6 +386,7 @@ void IPARkISP1::updateControls(const IPACameraSensorInfo &sensorInfo,\n \t\t\t       ControlInfoMap *ipaControls)\n {\n \tControlInfoMap::Map ctrlMap = rkisp1Controls;\n+\tctrlMap.merge(algoControls_);\n \n \t/*\n \t * Compute exposure time limits from the V4L2_CID_EXPOSURE control\n",
    "prefixes": [
        "v5",
        "3/3"
    ]
}