{"id":20779,"url":"https://patchwork.libcamera.org/api/patches/20779/?format=json","web_url":"https://patchwork.libcamera.org/patch/20779/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240805135104.139932-2-chenghaoyang@google.com>","date":"2024-08-05T13:48:32","name":"[v8,1/8] libcamera: add DmaBufAllocator::exportBuffers()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"a1d4d2e1afb2bc0cf273e616fb9da0bfdbe0ec7a","submitter":{"id":117,"url":"https://patchwork.libcamera.org/api/people/117/?format=json","name":"Cheng-Hao Yang","email":"chenghaoyang@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/20779/mbox/","series":[{"id":4487,"url":"https://patchwork.libcamera.org/api/series/4487/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4487","date":"2024-08-05T13:48:31","name":"Add VirtualPipelineHandler","version":8,"mbox":"https://patchwork.libcamera.org/series/4487/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/20779/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/20779/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 51835BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  5 Aug 2024 13:51:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 553BD63398;\n\tMon,  5 Aug 2024 15:51:13 +0200 (CEST)","from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com\n\t[IPv6:2a00:1450:4864:20::22b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 654D563381\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  5 Aug 2024 15:51:07 +0200 (CEST)","by mail-lj1-x22b.google.com with SMTP id\n\t38308e7fff4ca-2ef2c56d9dcso126901161fa.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 05 Aug 2024 06:51:07 -0700 (PDT)","from chenghaoyang-germany.c.googlers.com.com\n\t(49.222.77.34.bc.googleusercontent.com. [34.77.222.49])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-428e8d6555fsm137146675e9.26.2024.08.05.06.51.05\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 05 Aug 2024 06:51:05 -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=\"IlUXxfPS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1722865866; x=1723470666;\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=R/eakiLR90Hp4UnEDHENAwykCkeQ/OvhQjrjwoGtq6g=;\n\tb=IlUXxfPS9pznodiE7HmSxVo3xner4qEPY3mZxSWePf2WDl95HluIJ68HLjJlwSVmz3\n\tj8hdtyrhtQxhOYM8Ko68DAfS/VjM8sqBqKvRBHidBcpuagjEaUp5bM7CBwBiAiP75gz9\n\tJ8PJXPwFSMeqlSwWsIH42tjlXBE/48oeee+mQ=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1722865866; x=1723470666;\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=R/eakiLR90Hp4UnEDHENAwykCkeQ/OvhQjrjwoGtq6g=;\n\tb=MposZ1d9V+cWeO+HHCxf2Fh+WsakrgGbQygZkRbK59aGhivzMWCJ79MqRf+UasP+Zu\n\tyqfjb5ocMQjWTuLrrRuJIkem/9GS3CV4BkSYIPaxmZ6DaGbOPE8uA6zc7qF+WOyqCPRl\n\tSyPXHF5Irc/nvXFxQridmC1gNtcBanOiVIf7iHID5WiQA9+J+mIZFhonCGHpRX8SekTB\n\tIM1MpY27I5THgQDQxjhSiLcnYA43wSlq25j57kB1ccjFZZOr79OfviUUiwdyOI1EciGZ\n\t9QRtak876NhdVQIT/Ibvs2N63YKb92FLikDJOuAqYZBTktRPRmhkz1t/pFVhg/NoaIyy\n\txN1A==","X-Gm-Message-State":"AOJu0YyskpPIz6V5Bij+vFMhYfw+Vhtt7srHcnnckMg9ZPMpF/J0k/Gj\n\tw1W1I5bUAvMiZgSxcGrs6IRctP3on1wxTGjDhTsfCxNZVShF+mbH0IuHAGap/WDBmYVeXdp4L9U\n\tScQ==","X-Google-Smtp-Source":"AGHT+IEe/O5coO1CJCWor1N32uTCxg9MvbPqgCyvn0c5XBngnzZ3D5+hy0JeDFj28b85Oro0kZa2EQ==","X-Received":"by 2002:a2e:8747:0:b0:2ef:22bc:6fb0 with SMTP id\n\t38308e7fff4ca-2f15ab01385mr76096561fa.34.1722865866024; \n\tMon, 05 Aug 2024 06:51:06 -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 v8 1/8] libcamera: add DmaBufAllocator::exportBuffers()","Date":"Mon,  5 Aug 2024 13:48:32 +0000","Message-ID":"<20240805135104.139932-2-chenghaoyang@google.com>","X-Mailer":"git-send-email 2.46.0.rc2.264.g509ed76dc8-goog","In-Reply-To":"<20240805135104.139932-1-chenghaoyang@google.com>","References":"<20240805135104.139932-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           | 55 +++++++++++++++++++\n 2 files changed, 67 insertions(+)","diff":"diff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h\nindex 36ec1696..3a9b56b1 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 c06eca7d..a2df1730 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@@ -243,4 +248,54 @@ 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+\tfor (auto frameSize : frameSizes) {\n+\t\tUniqueFD fd = alloc(name.c_str(), frameSize);\n+\t\tif (!fd.isValid())\n+\t\t\treturn nullptr;\n+\n+\t\tFrameBuffer::Plane plane;\n+\t\tplane.fd = SharedFD(std::move(fd));\n+\t\tplane.offset = 0;\n+\t\tplane.length = frameSize;\n+\t\tplanes.push_back(std::move(plane));\n+\t}\n+\n+\treturn std::make_unique<FrameBuffer>(planes);\n+}\n+\n } /* namespace libcamera */\n","prefixes":["v8","1/8"]}