{"id":18645,"url":"https://patchwork.libcamera.org/api/1.1/patches/18645/?format=json","web_url":"https://patchwork.libcamera.org/patch/18645/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20230522083546.2465448-4-chenghaoyang@google.com>","date":"2023-05-22T08:35:08","name":"[libcamera-devel,v6,3/3] libcamera: Add exportFrameBuffers in HeapAllocator","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"14e87b4112fa22c116066ac69dbe7e6b3881d224","submitter":{"id":117,"url":"https://patchwork.libcamera.org/api/1.1/people/117/?format=json","name":"Cheng-Hao Yang","email":"chenghaoyang@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18645/mbox/","series":[{"id":3883,"url":"https://patchwork.libcamera.org/api/1.1/series/3883/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3883","date":"2023-05-22T08:35:05","name":"Add HeapAllocator","version":6,"mbox":"https://patchwork.libcamera.org/series/3883/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18645/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18645/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 1E4DDC31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 22 May 2023 08:36:01 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E0F8E62865;\n\tMon, 22 May 2023 10:36:00 +0200 (CEST)","from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com\n\t[IPv6:2607:f8b0:4864:20::62c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 55FDE627DC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 May 2023 10:35:56 +0200 (CEST)","by mail-pl1-x62c.google.com with SMTP id\n\td9443c01a7336-1ae875bf125so18966145ad.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 May 2023 01:35:56 -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\th1-20020a170902f54100b001a980a23804sm4321253plf.4.2023.05.22.01.35.53\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 22 May 2023 01:35:54 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1684744560;\n\tbh=0MRzzNK7YdDOow/alZSUpvn6S0XNOZGqFTYfaZmht7Q=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=ceph6V0j3ZB5Uj5NN/DWQkJdOKXSkoY8CrCz2GmycpOTT2J5IV9OgkSI+NBWh9AUH\n\tJt0S7VqPWeYrcb3a0uNnlBzQULE82aoQWpHMc9IpeINfBcSE+8jNk4QNNMS+i/OjgU\n\tWCGhNaLHHTDiK1OuXZimEmsQCJ7HJrjO33XVzKX7SGO6yYMpIyUwWXW8lYQYUg53C4\n\tuUAJNk5l6lEUyDZWXUM4O6Cmb/8KRFZpOKlV5aQAR7EZBRysrssdgJkHy47EJIW+g3\n\tR1jCEXNkJQpQldn2sYJ/uBICPPlW5UIQNfc/H1+2h6gNrm8smOxIgUl2ekZoAvn/IY\n\tdRNnVWpeUWsHw==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1684744555; x=1687336555;\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=+HAMbjUgljEg+SmXq+kpb1omhD43ul+/Dp5+qYCcWhE=;\n\tb=Ujkpgv9TlHTrh0RLXWBZ/g+AFH5Cx3g9BE0qnPS743yMJLadkzW9ldq7HG6URAImqD\n\t1Gn1cHfS8Tc7uEC5P8IxlcYYPE7DPXicSBON/aIFdgQG8tzzOYbNyxaJ85VS3RdGay6R\n\tHTm4tTG09D43Mjn+Y9Zvu8H0JS35GJbbZV5K8="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"Ujkpgv9T\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1684744555; x=1687336555;\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=+HAMbjUgljEg+SmXq+kpb1omhD43ul+/Dp5+qYCcWhE=;\n\tb=PbAfys0MhIot66qcjl4i9AAF7OwYN3T83biyIcy9zVOd5QDLvADSpJgcy9GwsI9v/k\n\tKrrMvwuKJNlM1R/11dAj7OtdlXhTXDMfuklIuCX0waXQ+jflrffDSyXWQMhvQH5FTYQp\n\tW3ONBKkNkdnPuHkcHRxU0Ka4RXDPne12cXlFRZROi2BuMqJ34tTmBFRusVJcN5PO2rff\n\trZlokqDIM0eNdsTXeeV6vV7wsDIawGiRzgTg6DnCsMCaiTazbV8/yv/FsMctpeE3PhkD\n\tODX0pveUn2mmq/Hay7OivGEl10yWoZtKkF3JPirMIwNvdAYolR/qmXMnX+GX+O5xsr64\n\thh3w==","X-Gm-Message-State":"AC+VfDwcKQ9h5oBMWRT5K1mZu581ZnlKy4+1jLTgJ5hp7siN3+lKuxvc\n\tBCF5YEVJfJv63QBvmEXjArtAXeFXyhqhKsTPNCg=","X-Google-Smtp-Source":"ACHHUZ7aNPY/xYWoAJ2jN6H6QWE0J1AAZS8YAu4J7MeSaGOoNpQE37e1JqaKWYH7bjUiOeGR6PBO4Q==","X-Received":"by 2002:a17:902:e889:b0:1ac:753a:7933 with SMTP id\n\tw9-20020a170902e88900b001ac753a7933mr11982573plg.39.1684744554666; \n\tMon, 22 May 2023 01:35:54 -0700 (PDT)","X-Google-Original-From":"Harvey Yang <chenghaoyang@google.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 22 May 2023 08:35:08 +0000","Message-ID":"<20230522083546.2465448-4-chenghaoyang@google.com>","X-Mailer":"git-send-email 2.40.1.698.g37aff9b760-goog","In-Reply-To":"<20230522083546.2465448-1-chenghaoyang@google.com>","References":"<20230522083546.2465448-1-chenghaoyang@google.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v6 3/3] libcamera: Add exportFrameBuffers\n\tin HeapAllocator","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>","From":"Harvey Yang via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Harvey Yang <chenghaoyang@chromium.org>","Cc":"Cheng-Hao Yang <chenghaoyang@chromium.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Cheng-Hao Yang <chenghaoyang@chromium.org>\n\nAdd a helper function exportFrameBuffers in HeapAllocator to make it\neasier to use.\n\nSigned-off-by: Harvey Yang <chenghaoyang@chromium.org>\n---\n include/libcamera/internal/heap_allocator.h |  9 +++\n src/libcamera/heap_allocator.cpp            | 62 +++++++++++++++++++++\n 2 files changed, 71 insertions(+)","diff":"diff --git a/include/libcamera/internal/heap_allocator.h b/include/libcamera/internal/heap_allocator.h\nindex 92d4488a..92beaaa4 100644\n--- a/include/libcamera/internal/heap_allocator.h\n+++ b/include/libcamera/internal/heap_allocator.h\n@@ -9,12 +9,16 @@\n #pragma once\n \n #include <stddef.h>\n+#include <vector>\n \n #include <libcamera/base/unique_fd.h>\n \n namespace libcamera {\n \n+class Camera;\n+class FrameBuffer;\n class Heap;\n+class Stream;\n \n class HeapAllocator\n {\n@@ -24,7 +28,12 @@ public:\n \tbool isValid() const;\n \tUniqueFD alloc(const char *name, std::size_t size);\n \n+\tint exportFrameBuffers(Camera *camera, Stream *stream,\n+\t\t\t       std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n+\n private:\n+\tstd::unique_ptr<FrameBuffer> createBuffer(Stream *stream);\n+\n \tstd::unique_ptr<Heap> heap_;\n };\n \ndiff --git a/src/libcamera/heap_allocator.cpp b/src/libcamera/heap_allocator.cpp\nindex 8f99f590..e99cdbe5 100644\n--- a/src/libcamera/heap_allocator.cpp\n+++ b/src/libcamera/heap_allocator.cpp\n@@ -22,6 +22,12 @@\n \n #include <libcamera/base/log.h>\n \n+#include <libcamera/camera.h>\n+#include <libcamera/framebuffer.h>\n+#include <libcamera/stream.h>\n+\n+#include \"libcamera/internal/formats.h\"\n+\n namespace libcamera {\n \n /*\n@@ -227,4 +233,60 @@ UniqueFD HeapAllocator::alloc(const char *name, std::size_t size)\n \treturn heap_->alloc(name, size);\n }\n \n+int HeapAllocator::exportFrameBuffers([[maybe_unused]] Camera *camera, Stream *stream,\n+\t\t\t\t      std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n+{\n+\tunsigned int count = stream->configuration().bufferCount;\n+\n+\t/** \\todo Support multiplanar allocations */\n+\n+\tfor (unsigned i = 0; i < count; ++i) {\n+\t\tstd::unique_ptr<FrameBuffer> buffer = createBuffer(stream);\n+\t\tif (!buffer) {\n+\t\t\tLOG(HeapAllocator, 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> HeapAllocator::createBuffer(Stream *stream)\n+{\n+\tstd::vector<FrameBuffer::Plane> planes;\n+\n+\tunsigned int frameSize = stream->configuration().frameSize;\n+\tint pageSize = getpagesize();\n+\t/** Allocation size need to be a direct multiple of |pageSize|. */\n+\tunsigned int numPage = (frameSize + pageSize - 1) / pageSize;\n+\n+\tUniqueFD fd = alloc(\"FrameBuffer\", numPage * pageSize);\n+\tif (!fd.isValid())\n+\t\treturn nullptr;\n+\n+\tauto info = PixelFormatInfo::info(stream->configuration().pixelFormat);\n+\tSharedFD shared_fd(std::move(fd));\n+\tunsigned int offset = 0;\n+\tfor (size_t i = 0; i < info.planes.size(); ++i) {\n+\t\tunsigned int planeSize = info.planeSize(stream->configuration().size, i);\n+\t\tif (planeSize == 0)\n+\t\t\tcontinue;\n+\n+\t\t/** \\todo We don't support allocating buffers with a dedicated fd per plane */\n+\t\tFrameBuffer::Plane plane;\n+\t\tplane.fd = shared_fd;\n+\t\tplane.offset = offset;\n+\t\tplane.length = planeSize;\n+\t\tplanes.push_back(std::move(plane));\n+\n+\t\toffset += planeSize;\n+\t}\n+\n+\treturn std::make_unique<FrameBuffer>(planes);\n+}\n+\n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v6","3/3"]}