Show a patch.

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

{
    "id": 11172,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/11172/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/11172/",
    "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": "<20210204232613.494121-11-niklas.soderlund@ragnatech.se>",
    "date": "2021-02-04T23:26:12",
    "name": "[libcamera-devel,v4,10/11] libcamera: ipu3: Add helper for parameter and statistic buffers",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "ab83de50319389ddb80e94b4116a5b4303cd9e97",
    "submitter": {
        "id": 5,
        "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api",
        "name": "Niklas Söderlund",
        "email": "niklas.soderlund@ragnatech.se"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/11172/mbox/",
    "series": [
        {
            "id": 1656,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1656/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1656",
            "date": "2021-02-04T23:26:02",
            "name": "libcamera: ipu3: Attach to an skeleton IPA",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/1656/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/11172/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/11172/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 8A7E8BD162\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Feb 2021 23:27:18 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 651F3614A7;\n\tFri,  5 Feb 2021 00:27:18 +0100 (CET)",
            "from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3A8EA614B3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Feb 2021 00:27:16 +0100 (CET)",
            "from bismarck.berto.se (p4fca2458.dip0.t-ipconnect.de\n\t[79.202.36.88])\n\tby bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid 83a07858-6740-11eb-b73f-0050569116f7;\n\tFri, 05 Feb 2021 00:27:15 +0100 (CET)"
        ],
        "X-Halon-ID": "83a07858-6740-11eb-b73f-0050569116f7",
        "Authorized-sender": "niklas.soderlund@fsdn.se",
        "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  5 Feb 2021 00:26:12 +0100",
        "Message-Id": "<20210204232613.494121-11-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.30.0",
        "In-Reply-To": "<20210204232613.494121-1-niklas.soderlund@ragnatech.se>",
        "References": "<20210204232613.494121-1-niklas.soderlund@ragnatech.se>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v4 10/11] libcamera: ipu3: Add helper for\n\tparameter and statistic buffers",
        "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=\"utf-8\"",
        "Content-Transfer-Encoding": "base64",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Add a helper class to aid in associating a parameter and statistic\nbuffer with each request queued to the pipeline. The helper helps with\ntracking the state of the extra buffers and in completing the request\nonce all extra processing is done.\n\nThis change only adds the helper more work is needed to integrate it\nwith the pipeline and an IPA.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n* Changes since v1\n- Move mapping of buffers to IPA to the pipeline handler and a separate\n  patch.\n- Move all pipeline interactions out of helper.\n\n* Changes since v2\n- Add todo to remove dynamic memory allocation.\n- Remove unused find(Request *request).\n\n* Changes since v3\n- s/IPU3Frames::Info/Info/ for tryComplete() in header file.\n- Add a remove() interface to reduce code duplication when removing an\n  entry that is should be removed rather then completed. For example in\n  error paths.\n- Add LOG(Error) prints if the info structure can't be find().\n---\n src/libcamera/pipeline/ipu3/frames.cpp  | 136 ++++++++++++++++++++++++\n src/libcamera/pipeline/ipu3/frames.h    |  62 +++++++++++\n src/libcamera/pipeline/ipu3/meson.build |   1 +\n 3 files changed, 199 insertions(+)\n create mode 100644 src/libcamera/pipeline/ipu3/frames.cpp\n create mode 100644 src/libcamera/pipeline/ipu3/frames.h",
    "diff": "diff --git a/src/libcamera/pipeline/ipu3/frames.cpp b/src/libcamera/pipeline/ipu3/frames.cpp\nnew file mode 100644\nindex 0000000000000000..37932dc779a5a112\n--- /dev/null\n+++ b/src/libcamera/pipeline/ipu3/frames.cpp\n@@ -0,0 +1,136 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * frames.cpp - Intel IPU3 Frames helper\n+ */\n+\n+#include \"frames.h\"\n+\n+#include <libcamera/buffer.h>\n+#include <libcamera/request.h>\n+\n+#include \"libcamera/internal/pipeline_handler.h\"\n+#include \"libcamera/internal/v4l2_videodevice.h\"\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(IPU3)\n+\n+IPU3Frames::IPU3Frames()\n+\t: nextId_(0)\n+{\n+}\n+\n+void IPU3Frames::init(const std::vector<std::unique_ptr<FrameBuffer>> &paramBuffers,\n+\t\t      const std::vector<std::unique_ptr<FrameBuffer>> &statBuffers)\n+{\n+\tfor (const std::unique_ptr<FrameBuffer> &buffer : paramBuffers)\n+\t\tavailableParamBuffers_.push(buffer.get());\n+\n+\tfor (const std::unique_ptr<FrameBuffer> &buffer : statBuffers)\n+\t\tavailableStatBuffers_.push(buffer.get());\n+\n+\tnextId_ = 0;\n+\tframeInfo_.clear();\n+}\n+\n+void IPU3Frames::clear()\n+{\n+\tavailableParamBuffers_ = {};\n+\tavailableStatBuffers_ = {};\n+}\n+\n+IPU3Frames::Info *IPU3Frames::create(Request *request)\n+{\n+\tunsigned int id = nextId_++;\n+\n+\tif (availableParamBuffers_.empty()) {\n+\t\tLOG(IPU3, Error) << \"Parameters buffer underrun\";\n+\t\treturn nullptr;\n+\t}\n+\tFrameBuffer *paramBuffer = availableParamBuffers_.front();\n+\n+\tif (availableStatBuffers_.empty()) {\n+\t\tLOG(IPU3, Error) << \"Statisitc buffer underrun\";\n+\t\treturn nullptr;\n+\t}\n+\tFrameBuffer *statBuffer = availableStatBuffers_.front();\n+\n+\tavailableParamBuffers_.pop();\n+\tavailableStatBuffers_.pop();\n+\n+\t/* \\todo Remove the dynamic allocation of Info */\n+\tstd::unique_ptr<Info> info = std::make_unique<Info>();\n+\n+\tinfo->id = id;\n+\tinfo->request = request;\n+\tinfo->rawBuffer = nullptr;\n+\tinfo->paramBuffer = paramBuffer;\n+\tinfo->statBuffer = statBuffer;\n+\tinfo->paramDequeued = false;\n+\tinfo->metadataProcessed = false;\n+\n+\tframeInfo_[id] = std::move(info);\n+\n+\treturn frameInfo_[id].get();\n+}\n+\n+void IPU3Frames::remove(IPU3Frames::Info *info)\n+{\n+\t/* Return params and stat buffer for reuse. */\n+\tavailableParamBuffers_.push(info->paramBuffer);\n+\tavailableStatBuffers_.push(info->statBuffer);\n+\n+\t/* Delete the extended frame information. */\n+\tframeInfo_.erase(info->id);\n+}\n+\n+bool IPU3Frames::tryComplete(IPU3Frames::Info *info)\n+{\n+\tRequest *request = info->request;\n+\n+\tif (request->hasPendingBuffers())\n+\t\treturn false;\n+\n+\tif (!info->metadataProcessed)\n+\t\treturn false;\n+\n+\tif (!info->paramDequeued)\n+\t\treturn false;\n+\n+\tremove(info);\n+\n+\treturn true;\n+}\n+\n+IPU3Frames::Info *IPU3Frames::find(unsigned int id)\n+{\n+\tconst auto &itInfo = frameInfo_.find(id);\n+\n+\tif (itInfo != frameInfo_.end())\n+\t\treturn itInfo->second.get();\n+\n+\tLOG(IPU3, Error) << \"Can't find tracking informaton for frame \" << id;\n+\treturn nullptr;\n+}\n+\n+IPU3Frames::Info *IPU3Frames::find(FrameBuffer *buffer)\n+{\n+\tfor (auto const &itInfo : frameInfo_) {\n+\t\tInfo *info = itInfo.second.get();\n+\n+\t\tfor (auto const itBuffers : info->request->buffers())\n+\t\t\tif (itBuffers.second == buffer)\n+\t\t\t\treturn info;\n+\n+\t\tif (info->rawBuffer == buffer || info->paramBuffer == buffer ||\n+\t\t    info->statBuffer == buffer)\n+\t\t\treturn info;\n+\t}\n+\n+\tLOG(IPU3, Error) << \"Can't find tracking informaton from buffer\";\n+\treturn nullptr;\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/pipeline/ipu3/frames.h b/src/libcamera/pipeline/ipu3/frames.h\nnew file mode 100644\nindex 0000000000000000..106e5c15cc7aea9b\n--- /dev/null\n+++ b/src/libcamera/pipeline/ipu3/frames.h\n@@ -0,0 +1,62 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * frames.h - Intel IPU3 Frames helper\n+ */\n+#ifndef __LIBCAMERA_PIPELINE_IPU3_FRAMES_H__\n+#define __LIBCAMERA_PIPELINE_IPU3_FRAMES_H__\n+\n+#include <map>\n+#include <memory>\n+#include <queue>\n+#include <vector>\n+\n+namespace libcamera {\n+\n+class FrameBuffer;\n+class IPAProxy;\n+class PipelineHandler;\n+class Request;\n+class V4L2VideoDevice;\n+struct IPABuffer;\n+\n+class IPU3Frames\n+{\n+public:\n+\tstruct Info {\n+\t\tunsigned int id;\n+\t\tRequest *request;\n+\n+\t\tFrameBuffer *rawBuffer;\n+\t\tFrameBuffer *paramBuffer;\n+\t\tFrameBuffer *statBuffer;\n+\n+\t\tbool paramDequeued;\n+\t\tbool metadataProcessed;\n+\t};\n+\n+\tIPU3Frames();\n+\n+\tvoid init(const std::vector<std::unique_ptr<FrameBuffer>> &paramBuffers,\n+\t\t  const std::vector<std::unique_ptr<FrameBuffer>> &statBuffers);\n+\tvoid clear();\n+\n+\tInfo *create(Request *request);\n+\tvoid remove(Info *info);\n+\tbool tryComplete(Info *info);\n+\n+\tInfo *find(unsigned int id);\n+\tInfo *find(FrameBuffer *buffer);\n+\n+private:\n+\tstd::queue<FrameBuffer *> availableParamBuffers_;\n+\tstd::queue<FrameBuffer *> availableStatBuffers_;\n+\n+\tunsigned int nextId_;\n+\tstd::map<unsigned int, std::unique_ptr<Info>> frameInfo_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_PIPELINE_IPU3_FRAMES_H__ */\ndiff --git a/src/libcamera/pipeline/ipu3/meson.build b/src/libcamera/pipeline/ipu3/meson.build\nindex d60e07ae6ccac2bc..a1b0b31ac5bcf864 100644\n--- a/src/libcamera/pipeline/ipu3/meson.build\n+++ b/src/libcamera/pipeline/ipu3/meson.build\n@@ -2,6 +2,7 @@\n \n libcamera_sources += files([\n     'cio2.cpp',\n+    'frames.cpp',\n     'imgu.cpp',\n     'ipu3.cpp',\n ])\n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "10/11"
    ]
}