Show a patch.

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

{
    "id": 21725,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/21725/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21725/",
    "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": "<20241022074544.3790451-2-chenghaoyang@chromium.org>",
    "date": "2024-10-22T07:43:37",
    "name": "[v16,1/7] libcamera: add DmaBufAllocator::exportBuffers()",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "ed60f2d0706996035f0d068f760645e99d473c70",
    "submitter": {
        "id": 117,
        "url": "https://patchwork.libcamera.org/api/1.1/people/117/?format=api",
        "name": "Cheng-Hao Yang",
        "email": "chenghaoyang@chromium.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21725/mbox/",
    "series": [
        {
            "id": 4733,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4733/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4733",
            "date": "2024-10-22T07:43:36",
            "name": "Add VirtualPipelineHandler",
            "version": 16,
            "mbox": "https://patchwork.libcamera.org/series/4733/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21725/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21725/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 E2EC1C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 22 Oct 2024 07:45:59 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A1B0265398;\n\tTue, 22 Oct 2024 09:45:59 +0200 (CEST)",
            "from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com\n\t[IPv6:2607:f8b0:4864:20::32f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 357DA65395\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 22 Oct 2024 09:45:53 +0200 (CEST)",
            "by mail-ot1-x32f.google.com with SMTP id\n\t46e09a7af769-718119fc061so2087376a34.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 22 Oct 2024 00:45:52 -0700 (PDT)",
            "from chenghaoyang-low.c.googlers.com.com\n\t(27.247.221.35.bc.googleusercontent.com. [35.221.247.27])\n\tby smtp.gmail.com with ESMTPSA id\n\td2e1a72fcca58-71ec13d75aesm4091024b3a.124.2024.10.22.00.45.49\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 22 Oct 2024 00:45:50 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"oJpwRUvA\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1729583151; x=1730187951;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=6BE58G+d8eNOduzGj/+av0/CduK1GmcHJNUUTiaSAbo=;\n\tb=oJpwRUvACEnQkWmTTzyg+HAHkcT6adkyHkVV2tf5BkIlNOuxHLG/jX53EOLFGcDDEl\n\tvpwHdCLLQFdV3olA6KzfcJ0nHAyzo358/JrNMkdeHqNffh4t8r1oj2316zDZtFW17aBi\n\tl+dv7v0reoAP1ezqqbWgNaC09A4Jmu+QsKhlg=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1729583151; x=1730187951;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=6BE58G+d8eNOduzGj/+av0/CduK1GmcHJNUUTiaSAbo=;\n\tb=S+YWRNNSAz6+a+hRqwdP24djitD3p0rKh34MpoTv97xauhnW8c6osqUOy4hR8DvGpt\n\tCH1a5HvBi5NmX+MfX8SchRykYSLi2IwkXY+SoiMRAyJ6PEXUjb5i5K1daYWPajr3BGCK\n\tTiS5x/EiHTfIdRYhuVXSCHdafd0eSGEb6A3r9daZh5iUu5bQUZkHdeKOxfYeK5ULqY9K\n\tdDK1BC5USHRtXbNgL8uaCg3cU62SaIldZHRCrFAWmnmO0CKIUNr0HPFSQ+5UsZ+HayfM\n\tXetXzCadL1/iQZPFDfM5UfC9pwGdtVNq++Uu1HyILXBipVNIHH5HHo7kOeg0nkMQll7z\n\tmPpw==",
        "X-Gm-Message-State": "AOJu0YwIndAScSpGgBS/VXx5cnpXFtJrYRydVKy4Ka+55SGzAOzszCtJ\n\tIMUgcybJna8q9es26IDK7i2/6i4QhPlqdJt6b9KyaBhTybI2TL5UkBD9vS/xO5jR2u5M3n6OBsk\n\t=",
        "X-Google-Smtp-Source": "AGHT+IF6jedLDpIgT3SLOGuRrzIqiwLQkCRaSn/RXU0/KGlGt9EhvH8PGIpbRont1s3z6hpXQnxxpg==",
        "X-Received": "by 2002:a05:6870:c113:b0:287:cb2:c0e with SMTP id\n\t586e51a60fabf-2892c2dee9amr12691295fac.12.1729583150783; \n\tTue, 22 Oct 2024 00:45:50 -0700 (PDT)",
        "From": "Harvey Yang <chenghaoyang@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Harvey Yang <chenghaoyang@chromium.org>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "Subject": "[PATCH v16 1/7] libcamera: add DmaBufAllocator::exportBuffers()",
        "Date": "Tue, 22 Oct 2024 07:43:37 +0000",
        "Message-ID": "<20241022074544.3790451-2-chenghaoyang@chromium.org>",
        "X-Mailer": "git-send-email 2.47.0.105.g07ac214952-goog",
        "In-Reply-To": "<20241022074544.3790451-1-chenghaoyang@chromium.org>",
        "References": "<20241022074544.3790451-1-chenghaoyang@chromium.org>",
        "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": "Add a helper function exportBuffers in DmaBufAllocator to make it easier\nto use.\n\nIt'll be used in Virtual Pipeline Handler and SoftwareIsp.\n\nSigned-off-by: Harvey Yang <chenghaoyang@chromium.org>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n .../libcamera/internal/dma_buf_allocator.h    | 13 +++++\n src/libcamera/dma_buf_allocator.cpp           | 57 +++++++++++++++++++\n 2 files changed, 70 insertions(+)",
    "diff": "diff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h\nindex d2a0a0d19..9211d4837 100644\n--- a/include/libcamera/internal/dma_buf_allocator.h\n+++ b/include/libcamera/internal/dma_buf_allocator.h\n@@ -7,11 +7,17 @@\n \n #pragma once\n \n+#include <memory>\n+#include <string>\n+#include <vector>\n+\n #include <libcamera/base/flags.h>\n #include <libcamera/base/unique_fd.h>\n \n namespace libcamera {\n \n+class FrameBuffer;\n+\n class DmaBufAllocator\n {\n public:\n@@ -28,7 +34,14 @@ public:\n \tbool isValid() const { return providerHandle_.isValid(); }\n \tUniqueFD alloc(const char *name, std::size_t size);\n \n+\tint exportBuffers(unsigned int count,\n+\t\t\t  const std::vector<unsigned int> &planeSizes,\n+\t\t\t  std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n+\n private:\n+\tstd::unique_ptr<FrameBuffer> createBuffer(\n+\t\tstd::string name, const std::vector<unsigned int> &planeSizes);\n+\n \tUniqueFD allocFromHeap(const char *name, std::size_t size);\n \tUniqueFD allocFromUDmaBuf(const char *name, std::size_t size);\n \tUniqueFD providerHandle_;\ndiff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp\nindex be6efb89f..262eb53a0 100644\n--- a/src/libcamera/dma_buf_allocator.cpp\n+++ b/src/libcamera/dma_buf_allocator.cpp\n@@ -22,6 +22,9 @@\n \n #include <libcamera/base/log.h>\n #include <libcamera/base/memfd.h>\n+#include <libcamera/base/shared_fd.h>\n+\n+#include <libcamera/framebuffer.h>\n \n /**\n  * \\file dma_buf_allocator.cpp\n@@ -205,4 +208,58 @@ UniqueFD DmaBufAllocator::alloc(const char *name, std::size_t size)\n \t\treturn allocFromHeap(name, size);\n }\n \n+/**\n+ * \\brief Allocate and export buffers from the DmaBufAllocator\n+ * \\param[in] count The number of requested FrameBuffers\n+ * \\param[in] planeSizes The sizes of planes in each FrameBuffer\n+ * \\param[out] buffers Array of buffers successfully allocated\n+ *\n+ * Planes in a FrameBuffer are allocated with a single dma buf.\n+ * \\todo Add the option to allocate each plane with a dma buf respectively.\n+ *\n+ * \\return The number of allocated buffers on success or a negative error code\n+ * otherwise\n+ */\n+int DmaBufAllocator::exportBuffers(unsigned int count,\n+\t\t\t\t   const std::vector<unsigned int> &planeSizes,\n+\t\t\t\t   std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n+{\n+\tfor (unsigned int i = 0; i < count; ++i) {\n+\t\tstd::unique_ptr<FrameBuffer> buffer =\n+\t\t\tcreateBuffer(\"frame-\" + std::to_string(i), planeSizes);\n+\t\tif (!buffer) {\n+\t\t\tLOG(DmaBufAllocator, Error) << \"Unable to create buffer\";\n+\n+\t\t\tbuffers->clear();\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tbuffers->push_back(std::move(buffer));\n+\t}\n+\n+\treturn count;\n+}\n+\n+std::unique_ptr<FrameBuffer>\n+DmaBufAllocator::createBuffer(std::string name,\n+\t\t\t      const std::vector<unsigned int> &planeSizes)\n+{\n+\tstd::vector<FrameBuffer::Plane> planes;\n+\n+\tunsigned int frameSize = 0, offset = 0;\n+\tfor (auto planeSize : planeSizes)\n+\t\tframeSize += planeSize;\n+\n+\tSharedFD fd(alloc(name.c_str(), frameSize));\n+\tif (!fd.isValid())\n+\t\treturn nullptr;\n+\n+\tfor (auto planeSize : planeSizes) {\n+\t\tplanes.emplace_back(FrameBuffer::Plane{ fd, offset, planeSize });\n+\t\toffset += planeSize;\n+\t}\n+\n+\treturn std::make_unique<FrameBuffer>(planes);\n+}\n+\n } /* namespace libcamera */\n",
    "prefixes": [
        "v16",
        "1/7"
    ]
}