Show a patch.

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

{
    "id": 12000,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/12000/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/12000/",
    "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": "<20210419131715.256802-5-naush@raspberrypi.com>",
    "date": "2021-04-19T13:17:15",
    "name": "[libcamera-devel,v4,4/4] ipa: raspberrypi: Rate-limit the controller algorithms",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "b4eb011adea2eced6bc9c84d4efb846dcdc0f277",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/1.1/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/12000/mbox/",
    "series": [
        {
            "id": 1949,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1949/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1949",
            "date": "2021-04-19T13:17:11",
            "name": "ipa: raspberrypi: Rate-limit the controller algorithms",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/1949/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/12000/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/12000/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 2CE58BD812\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 19 Apr 2021 13:17:33 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C95CE68840;\n\tMon, 19 Apr 2021 15:17:32 +0200 (CEST)",
            "from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com\n\t[IPv6:2a00:1450:4864:20::32b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5C5E868830\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 19 Apr 2021 15:17:30 +0200 (CEST)",
            "by mail-wm1-x32b.google.com with SMTP id\n\tf195-20020a1c1fcc0000b029012eb88126d7so8070359wmf.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 19 Apr 2021 06:17:30 -0700 (PDT)",
            "from naush-laptop.pitowers.org\n\t([2a00:1098:3142:15:5363:8f56:4f84:754])\n\tby smtp.gmail.com with ESMTPSA id\n\tt6sm22335428wrx.38.2021.04.19.06.17.28\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 19 Apr 2021 06:17:29 -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=\"cbwyswM8\"; 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=uhakufSYimFzXE2ktJnS7KEDy6j7582V8I7AiynSico=;\n\tb=cbwyswM8jU+xVUbqNU5W0VoCEBViuubX0Tjl/HZBd+mxsEfJulIGGI1hCJenYLezLO\n\tfNaXWcC2aLScOulKV+NRnpaKXgUv+uQUIc5NAnoE0i/BEuQ0xl1mMQGVmeSmK5xb7Smv\n\to6dz5+CugVOv1TY20X25b2BqefKWbgx1y2iugXtD5SckHhZ8GtNThcPXU9IAiA0R2R+0\n\tYs8s4vULSvIsyR+8ti2VAikiNT79qwRtO4a72okWuYNVajYVs72uGteTEuyAj/kCIpyx\n\tlN8IkY1CWxOZrO1DE9NX/mP35EHXT98ei0oVLhC1NNS4t6ePG5lP+F25d6tziK+1UixE\n\tWP6g==",
        "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=uhakufSYimFzXE2ktJnS7KEDy6j7582V8I7AiynSico=;\n\tb=aJkcuEHr40waIiCUcZFr8zTvZ9qnpqQVuv6EWvzAL7jvq4aCZih1g5C2xNzX08lv7g\n\tCtTwmv8i4yjacDG4NqwxO1E9ua3mbk1WeRzQ258jc09hjsPYstJS+dfWxLQEISk6R5pF\n\tLMEakzgzGDlSn0HHim8XxGLmrs8svc4txWJZ09jJfVaHuOW7uhzeclNLNKa8UWk0nIzO\n\teoGj4ls7LUz3c2NqZkzOempBABVJkaMK9rJxuVsHkeoma0sQnYLL2UxdlwcFJAAtmF0j\n\tsiFBIgK2zZARdEA8qMWnSFp44icoksTHgJN8+AxaRKai93PSs1yotYyWVzvMQvnNSVXg\n\tRMmw==",
        "X-Gm-Message-State": "AOAM531NnVjZ9ViVI/uFStxW+koJZgJ+fcv1IwHKms6lSKQ9A/gZcSfx\n\t+c4Rpz8zuO1zlrQIMGhYxOX6PZ9np9GXag==",
        "X-Google-Smtp-Source": "ABdhPJzr32JVK95455kG6YIuSmy68FxPvP5xi3VmyRb/iOKRWFmhTIZy0w/RTS/1P1+sqex7iaaqwg==",
        "X-Received": "by 2002:a1c:80cd:: with SMTP id\n\tb196mr21733366wmd.30.1618838249707; \n\tMon, 19 Apr 2021 06:17:29 -0700 (PDT)",
        "From": "Naushir Patuck <naush@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 19 Apr 2021 14:17:15 +0100",
        "Message-Id": "<20210419131715.256802-5-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20210419131715.256802-1-naush@raspberrypi.com>",
        "References": "<20210419131715.256802-1-naush@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v4 4/4] 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. On startup, we don't rate-limit the algorithms\nuntil after the number of frames required for convergence.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/raspberrypi.cpp           | 50 +++++++++++++++++--\n .../pipeline/raspberrypi/raspberrypi.cpp      |  5 ++\n 2 files changed, 51 insertions(+), 4 deletions(-)",
    "diff": "diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex f6d1ab16a290..eac1cf8cfe44 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,32 @@ 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. Any other bits of metadata\n+\t\t * that were added in helper_->Prepare() will also be moved across.\n+\t\t * All other metadata values must remain the same as the last frame.\n+\t\t *\n+\t\t * We do this by merging the current frame's metadata into the\n+\t\t * previous frame's metadata object, and then moving the latter\n+\t\t * into the former.\n+\t\t */\n+\t\tlastMetadata.Merge(rpiMetadata_);\n+\t\trpiMetadata_ = std::move(lastMetadata);\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",
        "v4",
        "4/4"
    ]
}