Show a patch.

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

{
    "id": 20968,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20968/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20968/",
    "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": "<20240820172202.526547-2-chenghaoyang@google.com>",
    "date": "2024-08-20T16:23:32",
    "name": "[v9,1/8] libcamera: add DmaBufAllocator::exportBuffers()",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "93b6205e2413e6b77c555fe8e4cd3f7d9e9b9919",
    "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/20968/mbox/",
    "series": [
        {
            "id": 4529,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4529/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4529",
            "date": "2024-08-20T16:23:31",
            "name": "Add VirtualPipelineHandler",
            "version": 9,
            "mbox": "https://patchwork.libcamera.org/series/4529/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20968/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20968/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 A7EA4C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 20 Aug 2024 17:22:22 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 42961633DA;\n\tTue, 20 Aug 2024 19:22:22 +0200 (CEST)",
            "from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com\n\t[IPv6:2a00:1450:4864:20::32a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2B322633B9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 20 Aug 2024 19:22:16 +0200 (CEST)",
            "by mail-wm1-x32a.google.com with SMTP id\n\t5b1f17b1804b1-4280bbdad3dso45736665e9.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 20 Aug 2024 10:22:16 -0700 (PDT)",
            "from chenghaoyang-germany.c.googlers.com.com\n\t(161.126.77.34.bc.googleusercontent.com. [34.77.126.161])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-42ab6e90db5sm30328575e9.0.2024.08.20.10.22.13\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 20 Aug 2024 10:22:14 -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=\"QTiHx+sT\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1724174535; x=1724779335;\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=xhJ1TpNfniDD0lgMah61wWiI0vruYwsEg3JQnpBROMs=;\n\tb=QTiHx+sTibzYudyenUtC3JettTDUhA1a3S3/EwHWVYKRRjoBYEQZj6i2tRVLy6TrB1\n\tWhJfPivYbCVOnxLTgXFHtk68N5toyVdlAV8hSRmCGiVsnrYvTBcEAfA1riU9Pu7pmpYY\n\tfsfEjBaD6yAatQ9Vf8Q111wjQ192k/U6qT7ZE=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1724174535; x=1724779335;\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=xhJ1TpNfniDD0lgMah61wWiI0vruYwsEg3JQnpBROMs=;\n\tb=Lh4jJXbBA3i9wSO6BGuLEvHFvvx5sK66Tku5+a2bPE1+9c1z8VGqngDIkVN7SlvlA4\n\t6hO//39El/655Hpc/bodbnzNOJWo8q3imjoFknzMD3bgDW4pJI4vxWBkfGPc18E3rLf2\n\thLseF7d+gSnP86eSm5gZVQREzX4eLe+HdZM80D9cD41xKd60GWbLvFwK7Lmgs8ioWngC\n\toapTkCzV1txTxfVZYo/R0M5hrGq1DSmbJlP6ZkLxCwhNoUpTJGXB3fUOkJ5YmSyNb5jm\n\tlmZP+hJJEaVa0tDXKrGq1SnUcpnVYt26QX75wbnOpMbOc8zJUqVlnzLoe/9cxtAVnPk3\n\t6Bxw==",
        "X-Gm-Message-State": "AOJu0YzDa14XT8yKmgflvR/shGnJnP9C6lQGljPgEEaTqYVAQI9yA/lN\n\tlye26F33vDTnFeFsvL/y+8M2Hp86V1jJIrmNyMOEYcp0FKzePI7Tp/upHO8MStPaDWHkQwiOuid\n\tjfO3rMGY=",
        "X-Google-Smtp-Source": "AGHT+IGonbZmSHTbLGIz2b10s+Wy5//AT3oBumPhjOlHMWUOu2bR1D+cxyqvSPJ2aozdV1BBzkyD6g==",
        "X-Received": "by 2002:a05:600c:46ce:b0:426:593c:935d with SMTP id\n\t5b1f17b1804b1-42abd21f59fmr493395e9.5.1724174534668; \n\tTue, 20 Aug 2024 10:22:14 -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 v9 1/8] libcamera: add DmaBufAllocator::exportBuffers()",
        "Date": "Tue, 20 Aug 2024 16:23:32 +0000",
        "Message-ID": "<20240820172202.526547-2-chenghaoyang@google.com>",
        "X-Mailer": "git-send-email 2.46.0.184.g6999bdac58-goog",
        "In-Reply-To": "<20240820172202.526547-1-chenghaoyang@google.com>",
        "References": "<20240820172202.526547-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    | 12 ++++\n src/libcamera/dma_buf_allocator.cpp           | 64 ++++++++++++++++++-\n 2 files changed, 74 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h\nindex 36ec1696b..3a9b56b1c 100644\n--- a/include/libcamera/internal/dma_buf_allocator.h\n+++ b/include/libcamera/internal/dma_buf_allocator.h\n@@ -8,12 +8,16 @@\n #pragma once\n \n #include <stddef.h>\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+struct StreamConfiguration;\n+\n class DmaBufAllocator\n {\n public:\n@@ -30,7 +34,15 @@ public:\n \tbool isValid() const { return providerHandle_.isValid(); }\n \tUniqueFD alloc(const char *name, std::size_t size);\n \n+\tint exportBuffers(\n+\t\tstd::size_t count,\n+\t\tstd::vector<std::size_t> frameSize,\n+\t\tstd::vector<std::unique_ptr<FrameBuffer>> *buffers);\n+\n private:\n+\tstd::unique_ptr<FrameBuffer> createBuffer(\n+\t\tstd::string name, std::vector<std::size_t> 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 c06eca7d0..2d88b8b2b 100644\n--- a/src/libcamera/dma_buf_allocator.cpp\n+++ b/src/libcamera/dma_buf_allocator.cpp\n@@ -23,6 +23,11 @@\n \n #include <libcamera/base/log.h>\n \n+#include <libcamera/framebuffer.h>\n+#include <libcamera/stream.h>\n+\n+#include \"libcamera/internal/formats.h\"\n+\n /**\n  * \\file dma_buf_allocator.cpp\n  * \\brief dma-buf allocator\n@@ -130,8 +135,8 @@ DmaBufAllocator::~DmaBufAllocator() = default;\n /* uClibc doesn't provide the file sealing API. */\n #ifndef __DOXYGEN__\n #if not HAVE_FILE_SEALS\n-#define F_ADD_SEALS\t\t1033\n-#define F_SEAL_SHRINK\t\t0x0002\n+#define F_ADD_SEALS 1033\n+#define F_SEAL_SHRINK 0x0002\n #endif\n #endif\n \n@@ -243,4 +248,59 @@ 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 for \\a stream from the DmaBufAllocator\n+ * \\param[in] count The number of FrameBuffers required\n+ * \\param[in] frameSizes The sizes of planes in the 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(\n+\tstd::size_t count,\n+\tstd::vector<std::size_t> frameSizes,\n+\tstd::vector<std::unique_ptr<FrameBuffer>> *buffers)\n+{\n+\tfor (unsigned 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> DmaBufAllocator::createBuffer(\n+\tstd::string name, std::vector<std::size_t> frameSizes)\n+{\n+\tstd::vector<FrameBuffer::Plane> planes;\n+\n+\tstd::size_t 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\tFrameBuffer::Plane plane;\n+\t\tplane.fd = fd;\n+\t\tplane.offset = offset;\n+\t\tplane.length = frameSize;\n+\t\tplanes.push_back(std::move(plane));\n+\t\toffset += plane.length;\n+\t}\n+\n+\treturn std::make_unique<FrameBuffer>(planes);\n+}\n+\n } /* namespace libcamera */\n",
    "prefixes": [
        "v9",
        "1/8"
    ]
}