Show a patch.

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

{
    "id": 11965,
    "url": "https://patchwork.libcamera.org/api/patches/11965/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/11965/",
    "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": "<20210416103141.1483745-4-naush@raspberrypi.com>",
    "date": "2021-04-16T10:31:41",
    "name": "[libcamera-devel,v2,3/3] ipa: raspberrypi: Rate-limit the controller algorithms",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "3bef22d86f84c7adf0058d1603b8a42236251414",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/11965/mbox/",
    "series": [
        {
            "id": 1939,
            "url": "https://patchwork.libcamera.org/api/series/1939/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1939",
            "date": "2021-04-16T10:31:38",
            "name": "ipa: raspberrypi: Rate-limit the controller algorithms",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/1939/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/11965/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/11965/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 42216BD235\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 16 Apr 2021 10:31:59 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A2C3D68813;\n\tFri, 16 Apr 2021 12:31:58 +0200 (CEST)",
            "from mail-wr1-x435.google.com (mail-wr1-x435.google.com\n\t[IPv6:2a00:1450:4864:20::435])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 73F386880A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Apr 2021 12:31:56 +0200 (CEST)",
            "by mail-wr1-x435.google.com with SMTP id h4so17145604wrt.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Apr 2021 03:31:56 -0700 (PDT)",
            "from naush-laptop.pitowers.org\n\t([2a00:1098:3142:15:4af5:8d45:b5d1:889d])\n\tby smtp.gmail.com with ESMTPSA id\n\td133sm8234500wmf.9.2021.04.16.03.31.55\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 16 Apr 2021 03:31:55 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"jKp3YlC3\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=ISdsVA4HeIRxKBQupjIswGfDjzyE6VkT7Xub0Q0Fgvc=;\n\tb=jKp3YlC3NXSg3G9D/N5Mhmk72aBJb9jphmg/EPwcfkDtgll1crVTjTfGcx87fiBxT5\n\tnqk4qbtLVYgTQSQDHQ/ZJr8kzQeqGAbab845L2do4ZVaqATKaVRo1DpLwFnV01WZgGMj\n\tjYL8kBr7SPx+u/MvZFbdsctHZNvLaakv4AfQ13rCYaXTphmPGzqZXvsaJacTAtazgqEo\n\t+Th7TxHKt3zOmEeOPxy1zHWGUgMyrgaQfZ3sCGiyCe2y9VhwAQerqnxfZsoXfdsNLUhE\n\tCmJGAnKbki6C4qAcsNJw5/vIApKEW1arDIgrpnxhDPpKnR1LoUOgCQL66aSghEC4nwF5\n\tvUZQ==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=ISdsVA4HeIRxKBQupjIswGfDjzyE6VkT7Xub0Q0Fgvc=;\n\tb=Xxleeag4Lo6kK/NX2QU5flbdt52n8Y3rDZSuKMPf/CuSOPCeW7vKaA31z/EV2WYxUY\n\t3kzp81XMJ69YTxDFDGuVZJqXcplw274qr9+YTGeZ0sVBgN8TKhx9vWZjTK+stTCrTA15\n\taQYxiYbtX51oE4oLqNSA8jDUFB+0kq4WmFLchidULcla6dEnLAmmsH61IGRmNM71TvLt\n\toBZ9eZf2GOy9HjCL17NsULrUEQ0EYvn/jq82CVjznNxJfqs6OtNz2MlAqGJjAgBUS7Sc\n\t4ogL/X83iBWlT/aojoFRL8qI1L6K6/gnic2APkPumVoV9SzqX2RLIFR9ZtSIQvZUQceH\n\tZsCw==",
        "X-Gm-Message-State": "AOAM530+heRPvFpVptKAt+Zzx4sUNiApfMnm28YVddVrQBBIo5IrkBb+\n\tiNd8VUE9amSLWq6hgU85d6wV6iZAV0whlw==",
        "X-Google-Smtp-Source": "ABdhPJywUbXGhlWe7HznCIOaaCTZ+trOcMCxFhEzUI/ZCybc9c42WbMrHdTVxWovdkxIJmpTdliazQ==",
        "X-Received": "by 2002:adf:df0a:: with SMTP id\n\ty10mr8514604wrl.246.1618569115827; \n\tFri, 16 Apr 2021 03:31:55 -0700 (PDT)",
        "From": "Naushir Patuck <naush@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 16 Apr 2021 11:31:41 +0100",
        "Message-Id": "<20210416103141.1483745-4-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20210416103141.1483745-1-naush@raspberrypi.com>",
        "References": "<20210416103141.1483745-1-naush@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v2 3/3] ipa: raspberrypi: Rate-limit the\n\tcontroller algorithms",
        "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>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The controller algorithms currently run on every frame provided to the\nIPA by the pipeline handler. This may be undesirable for very fast fps\noperating modes where it could significantly increase the computation\ncycles (per unit time) without providing any significant changes to the\nIQ parameters. The added latencies could also cause dropped frames.\n\nPass the FrameBuffer timestamp to the IPA through the controls. This\ntimestamp will be used to rate-limit the controller algorithms to run\nwith a minimum inter-frame time given by a compile time constant,\ncurrently set to 16.66ms.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/ipa/raspberrypi/raspberrypi.cpp           | 48 +++++++++++++++++--\n .../pipeline/raspberrypi/raspberrypi.cpp      |  5 ++\n 2 files changed, 49 insertions(+), 4 deletions(-)",
    "diff": "diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex f6d1ab16a290..e96b169ca612 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -61,6 +61,14 @@ constexpr unsigned int DefaultExposureTime = 20000;\n constexpr double defaultMinFrameDuration = 1e6 / 30.0;\n constexpr double defaultMaxFrameDuration = 1e6 / 0.01;\n \n+/*\n+ * Determine the minimum allowable inter-frame duration (in us) to run the\n+ * controller algorithms. If the pipeline handler provider frames at a rate\n+ * higher than this, we rate-limit the controller prepare() and process() calls\n+ * to lower than or equal to this rate.\n+ */\n+constexpr double controllerMinFrameDuration = 1e6 / 60.0;\n+\n LOG_DEFINE_CATEGORY(IPARPI)\n \n class IPARPi : public ipa::RPi::IPARPiInterface\n@@ -68,7 +76,7 @@ class IPARPi : public ipa::RPi::IPARPiInterface\n public:\n \tIPARPi()\n \t\t: controller_(), frameCount_(0), checkCount_(0), mistrustCount_(0),\n-\t\t  lsTable_(nullptr), firstStart_(true)\n+\t\t  lastRunTimestamp_(0), lsTable_(nullptr), firstStart_(true)\n \t{\n \t}\n \n@@ -146,6 +154,12 @@ private:\n \t/* Number of frames that need to be dropped on startup. */\n \tunsigned int dropFrameCount_;\n \n+\t/* Frame timestamp for the last run of the controller. */\n+\tuint64_t lastRunTimestamp_;\n+\n+\t/* Do we run a Controller::process() for this frame? */\n+\tbool processPending_;\n+\n \t/* LS table allocation passed in from the pipeline handler. */\n \tFileDescriptor lsTableHandle_;\n \tvoid *lsTable_;\n@@ -262,6 +276,7 @@ void IPARPi::start(const ControlList &controls, ipa::RPi::StartConfig *startConf\n \tstartConfig->dropFrameCount = dropFrameCount_;\n \n \tfirstStart_ = false;\n+\tlastRunTimestamp_ = 0;\n }\n \n void IPARPi::setMode(const CameraSensorInfo &sensorInfo)\n@@ -406,7 +421,7 @@ void IPARPi::signalStatReady(uint32_t bufferId)\n {\n \tif (++checkCount_ != frameCount_) /* assert here? */\n \t\tLOG(IPARPI, Error) << \"WARNING: Prepare/Process mismatch!!!\";\n-\tif (frameCount_ > mistrustCount_)\n+\tif (processPending_ && frameCount_ > mistrustCount_)\n \t\tprocessStats(bufferId);\n \n \treportMetadata();\n@@ -894,10 +909,11 @@ void IPARPi::returnEmbeddedBuffer(unsigned int bufferId)\n \n void IPARPi::prepareISP(const ipa::RPi::ISPConfig &data)\n {\n+\tint64_t frameTimestamp = data.controls.get(controls::draft::SensorTimestamp);\n+\tRPiController::Metadata lastMetadata;\n \tSpan<uint8_t> embeddedBuffer;\n \n-\trpiMetadata_.Clear();\n-\n+\tlastMetadata = std::move(rpiMetadata_);\n \tfillDeviceStatus(data.controls);\n \n \tif (data.embeddedBufferPresent) {\n@@ -920,6 +936,30 @@ void IPARPi::prepareISP(const ipa::RPi::ISPConfig &data)\n \tif (data.embeddedBufferPresent)\n \t\treturnEmbeddedBuffer(data.embeddedBufferId);\n \n+\tif (lastRunTimestamp_ && frameCount_ > dropFrameCount_ &&\n+\t    frameTimestamp - lastRunTimestamp_ < controllerMinFrameDuration * 1e3) {\n+\t\t/*\n+\t\t * Ensure we update the controller metadata with the new frame's\n+\t\t * exposure/gain values so that the correct values are returned\n+\t\t * out in libcamera metadata later on. All other metadata values\n+\t\t * must remain the same as the last frame.\n+\t\t */\n+\t\tDeviceStatus currentDeviceStatus;\n+\n+\t\trpiMetadata_.Get<DeviceStatus>(\"device.status\", currentDeviceStatus);\n+\t\trpiMetadata_ = std::move(lastMetadata);\n+\t\trpiMetadata_.Set(\"device.status\", currentDeviceStatus);\n+\t\tprocessPending_ = false;\n+\t\tLOG(IPARPI, Debug) << \"Rate-limiting the controller! inter-frame duration: \"\n+\t\t\t\t   << frameTimestamp - lastRunTimestamp_\n+\t\t\t\t   << \", min duration \"\n+\t\t\t\t   << controllerMinFrameDuration * 1e3;\n+\t\treturn;\n+\t}\n+\n+\tlastRunTimestamp_ = frameTimestamp;\n+\tprocessPending_ = true;\n+\n \tControlList ctrls(ispCtrls_);\n \n \tcontroller_.Prepare(&rpiMetadata_);\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 2a917455500f..9cf9c8c6cebd 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -1414,6 +1414,11 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n \t\t * DelayedControl and queue them along with the frame buffer.\n \t\t */\n \t\tControlList ctrl = delayedCtrls_->get(buffer->metadata().sequence);\n+\t\t/*\n+\t\t * Add the frame timestamp to the ControlList for the IPA to use\n+\t\t * as it does not receive the FrameBuffer object.\n+\t\t */\n+\t\tctrl.set(controls::draft::SensorTimestamp, buffer->metadata().timestamp);\n \t\tbayerQueue_.push({ buffer, std::move(ctrl) });\n \t} else {\n \t\tembeddedQueue_.push(buffer);\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "3/3"
    ]
}