Show a patch.

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

{
    "id": 21193,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/21193/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21193/",
    "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": "<20240907143110.2210711-2-chenghaoyang@google.com>",
    "date": "2024-09-07T14:28:26",
    "name": "[v11,1/7] libcamera: add DmaBufAllocator::exportBuffers()",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "a015ca9be87f2ccd9a3161a4792f9e1910117964",
    "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/21193/mbox/",
    "series": [
        {
            "id": 4567,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4567/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4567",
            "date": "2024-09-07T14:28:25",
            "name": "Add VirtualPipelineHandler",
            "version": 11,
            "mbox": "https://patchwork.libcamera.org/series/4567/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21193/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21193/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 E5216C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  7 Sep 2024 14:31:24 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A5750634FC;\n\tSat,  7 Sep 2024 16:31:21 +0200 (CEST)",
            "from mail-pf1-x432.google.com (mail-pf1-x432.google.com\n\t[IPv6:2607:f8b0:4864:20::432])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D0CD6633CC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  7 Sep 2024 16:31:19 +0200 (CEST)",
            "by mail-pf1-x432.google.com with SMTP id\n\td2e1a72fcca58-717911ef035so2308952b3a.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 07 Sep 2024 07:31:19 -0700 (PDT)",
            "from chenghaoyang-low.c.googlers.com.com\n\t(0.223.81.34.bc.googleusercontent.com. [34.81.223.0])\n\tby smtp.gmail.com with ESMTPSA id\n\td9443c01a7336-20710e33974sm9208935ad.104.2024.09.07.07.31.16\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSat, 07 Sep 2024 07:31:17 -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=\"W3J/zO67\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1725719478; x=1726324278;\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=ykxXuMf7wvHOxfLwxRKz/cbPcfwSaWd3G7r3fOBmhAA=;\n\tb=W3J/zO67tqrCQoAEYhPy5HpcQz0B4ixaExqVfE5Hy1GJXPxFQ64tPBqUYo3B1QmRHH\n\tloF3IAPaEOvs3F9yh93gJQcfNkZQtd1R5oi8WioWtbQZARiv+qoXYeI06rCVTxgxjttA\n\tnUFabilcuB+YHKg6ernbSRAXdJ55oEwSzsF2M=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1725719478; x=1726324278;\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=ykxXuMf7wvHOxfLwxRKz/cbPcfwSaWd3G7r3fOBmhAA=;\n\tb=UrlV3BSUazrMztNhS/HH4LYn+cpbZQCM97OJ1tRZdM6Q4uSoIriJpQHNdyVgaCBsAt\n\tf2BYzSNQFdphNssqxR7XBE2jcrfOWlxaDNVxtqEYce0Y9CIpxIXXk7g1AgG/FreYAXwe\n\t0YUBMmsRhCxdJHPArI561SFh6MOopqk+5uu7njEovBoCKf2g4ZIN7k8MzmgkPzzWPzGD\n\tS0tUQFFlomGYumu4Az4xprAt7O8MGDrG14Zyss9afQllmwOVYzmNnT69rl0I4RKwu1j9\n\t7PgeqHriB5QraoFrou5jZWf6TvSiK/vJEPy0ba+MXd0aOnUzcVUcPh2PvA9beIlYK2Oz\n\tc5Gw==",
        "X-Gm-Message-State": "AOJu0YzBIboVGfG0MooWgI7aUMG/lCl0oRC8eo4rsPiNrec54JlqGxJ7\n\tGxGtDHC0JIhM57BI5e2Fn16usooWHvNnPOysuv27+iIe89skTJbY+WtefZUXs6Ki8N+oMMjKmQ4\n\t=",
        "X-Google-Smtp-Source": "AGHT+IE5tiwhrTyqS7fO21GJvUh3PV83d3SDENceuMWT3pehASWDmyAU6VSpSoz6sBHVP5UJ3Z2oPQ==",
        "X-Received": "by 2002:a05:6a20:e687:b0:1cf:126c:49fb with SMTP id\n\tadf61e73a8af0-1cf1d20c5c7mr5996722637.43.1725719477713; \n\tSat, 07 Sep 2024 07:31:17 -0700 (PDT)",
        "From": "Harvey Yang <chenghaoyang@chromium.org>",
        "X-Google-Original-From": "Harvey Yang <chenghaoyang@google.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Harvey Yang <chenghaoyang@google.com>,\n\tHarvey Yang <chenghaoyang@chromium.org>",
        "Subject": "[PATCH v11 1/7] libcamera: add DmaBufAllocator::exportBuffers()",
        "Date": "Sat,  7 Sep 2024 14:28:26 +0000",
        "Message-ID": "<20240907143110.2210711-2-chenghaoyang@google.com>",
        "X-Mailer": "git-send-email 2.46.0.469.g59c65b2a67-goog",
        "In-Reply-To": "<20240907143110.2210711-1-chenghaoyang@google.com>",
        "References": "<20240907143110.2210711-1-chenghaoyang@google.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": "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>\n---\n .../libcamera/internal/dma_buf_allocator.h    | 13 +++++\n src/libcamera/dma_buf_allocator.cpp           | 55 +++++++++++++++++++\n 2 files changed, 68 insertions(+)",
    "diff": "diff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h\nindex d2a0a0d1..66d3b419 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> &frameSize,\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> &frameSizes);\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 be6efb89..d2ac175f 100644\n--- a/src/libcamera/dma_buf_allocator.cpp\n+++ b/src/libcamera/dma_buf_allocator.cpp\n@@ -23,6 +23,10 @@\n #include <libcamera/base/log.h>\n #include <libcamera/base/memfd.h>\n \n+#include <libcamera/framebuffer.h>\n+\n+#include \"libcamera/internal/formats.h\"\n+\n /**\n  * \\file dma_buf_allocator.cpp\n  * \\brief dma-buf allocator\n@@ -205,4 +209,55 @@ 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] frameSizes The sizes of planes in each FrameBuffer\n+ * \\param[out] buffers Array of buffers successfully allocated\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> &frameSizes,\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), frameSizes);\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> &frameSizes)\n+{\n+\tstd::vector<FrameBuffer::Plane> planes;\n+\n+\tunsigned int bufferSize = 0, offset = 0;\n+\tfor (auto frameSize : frameSizes)\n+\t\tbufferSize += frameSize;\n+\n+\tSharedFD fd(alloc(name.c_str(), bufferSize));\n+\tif (!fd.isValid())\n+\t\treturn nullptr;\n+\n+\tfor (auto frameSize : frameSizes) {\n+\t\tplanes.emplace_back(FrameBuffer::Plane{ fd, offset, frameSize });\n+\t\toffset += frameSize;\n+\t}\n+\n+\treturn std::make_unique<FrameBuffer>(planes);\n+}\n+\n } /* namespace libcamera */\n",
    "prefixes": [
        "v11",
        "1/7"
    ]
}