Patch Detail
Show a patch.
GET /api/1.1/patches/18923/?format=api
{ "id": 18923, "url": "https://patchwork.libcamera.org/api/1.1/patches/18923/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18923/", "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": "<20230802065449.2904457-4-chenghaoyang@chromium.org>", "date": "2023-08-02T06:51:45", "name": "[libcamera-devel,v7,3/3] libcamera: Add exportFrameBuffers in HeapAllocator", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "72b970f96db849b34e26b76f2ac2061ce931f035", "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/18923/mbox/", "series": [ { "id": 4000, "url": "https://patchwork.libcamera.org/api/1.1/series/4000/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4000", "date": "2023-08-02T06:51:42", "name": "Add HeapAllocator", "version": 7, "mbox": "https://patchwork.libcamera.org/series/4000/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18923/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18923/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 69EF7C32B0\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 2 Aug 2023 06:55:06 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F0EE0627EC;\n\tWed, 2 Aug 2023 08:55:05 +0200 (CEST)", "from mail-pf1-x433.google.com (mail-pf1-x433.google.com\n\t[IPv6:2607:f8b0:4864:20::433])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AB20F627E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 2 Aug 2023 08:55:02 +0200 (CEST)", "by mail-pf1-x433.google.com with SMTP id\n\td2e1a72fcca58-686f0d66652so6121602b3a.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 01 Aug 2023 23:55:02 -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\td14-20020aa7868e000000b0065980654baasm9142154pfo.130.2023.08.01.23.54.59\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 01 Aug 2023 23:55:00 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1690959306;\n\tbh=EUpSCqw8ZvFk90XGcTGbyKhD5FT1P8Mlb4eRm3H2xTk=;\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=dri8xwThQ5K0iEYrcGK2FC8ue2A/hZp6UvFjwBT7rZEd3RVOzXuLCqqwO3JIlI5t+\n\tGwhOjY9w+krNgI7UygM6OqF8IYwvGx62FBaF9HgfsnD8TF1fLWt0TEV3n1ijHkMjcY\n\t7/bdKuV/pK4p/NxmIU88u0UE4dP1Zmj1QRXTugQPGMt8SbCSUNuRc4XNa5mRh1HIkL\n\t3ogwakj125NRS38vbjW0tCjQy3Y6J74+3vgvN1szhA3yDP5uDxujp1NSKwGIR+QX8m\n\tKz+G5DwT/HaBRApC42Zs65JA8sM2xRYhBaqaAYcFw6MVpUPZZxkb2zzvvrxIFic7Na\n\tr+Mn0Maz/VR9Q==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1690959301; x=1691564101;\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=SR8gv5LwHmrnA+J0vzfvBFITtJUKF6RbopGQzNfWe00=;\n\tb=HPoVEsPm2QMjL2WA1bDtnATwF9JX5MvNS3MO1tRficDZRqVFiKtwg+nPbG9C6XcVje\n\ttv+0NqCvHHAb3SPU/fIGlX6lkfOmqhi5YOf7rg8rS+BIb+mZLQEKYt7SJRYmX0ZJIWbP\n\tmbhqfS8TzZeYLw6oStcZirwtuV80iAPg/VK6E=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"HPoVEsPm\"; \n\tdkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1690959301; x=1691564101;\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=SR8gv5LwHmrnA+J0vzfvBFITtJUKF6RbopGQzNfWe00=;\n\tb=dfDin6EqlcJISn0vmho+jzGPUeluLzregCSRh998kWgn+eg4RoJpKYc2deGG/8P1UP\n\tuvZfVDHsA1UATr7w+UtzMh9n0KatAnJSJ6rvih8hcqlLI5yZW1pr13HZ68j5Ve1Cymy9\n\tNczNt8kk4WOROaIf/1AHds81DqCxYmRiqJRDzY2dshWm405w2sAkgrbtNvoNw1XyjOeC\n\tdlDWBHC4JuYaLP8IduKTvEMjyC1vE5q9vXSfptiAIV8JKgu/wfPSeqg/RNHm93jevI8X\n\tVmPptB9VRk+w4SOE93bB1kP2fYkNAy00zKfyxJCvP+ulphAYRvTKv/qKotoAlkrsUPtP\n\tHlTQ==", "X-Gm-Message-State": "ABy/qLYyNMNmOmC5IhAq+HiWnSeKFXZLb5ppFT0pYiib3ZrJwAaQh24+\n\tTlMdLyrYeRLHzaS8aqO+Hbtv+FH+/W8lfslKPMU=", "X-Google-Smtp-Source": "APBJJlHBsefdblBYvxLdcESSOQ719nUlWQC9SiI7nSQIHHojOT2Sb8AuVMyUI2u/CeSK7d/Pn+X8ng==", "X-Received": "by 2002:a05:6a21:6d95:b0:134:4f86:7966 with SMTP id\n\twl21-20020a056a216d9500b001344f867966mr19325429pzb.9.1690959300640; \n\tTue, 01 Aug 2023 23:55:00 -0700 (PDT)", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 2 Aug 2023 06:51:45 +0000", "Message-ID": "<20230802065449.2904457-4-chenghaoyang@chromium.org>", "X-Mailer": "git-send-email 2.41.0.585.gd2178a4bd4-goog", "In-Reply-To": "<20230802065449.2904457-1-chenghaoyang@chromium.org>", "References": "<20230802065449.2904457-1-chenghaoyang@chromium.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v7 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": "Harvey Yang <chenghaoyang@chromium.org>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Add 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 | 10 ++++\n src/libcamera/heap_allocator.cpp | 60 ++++++++++++++++++++-\n 2 files changed, 69 insertions(+), 1 deletion(-)", "diff": "diff --git a/include/libcamera/internal/heap_allocator.h b/include/libcamera/internal/heap_allocator.h\nindex 6620fa23..064696d5 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+struct StreamConfiguration;\n \n class HeapAllocator\n {\n@@ -25,7 +29,13 @@ public:\n \tbool isValid() const;\n \tUniqueFD alloc(const char *name, std::size_t size);\n \n+\tint exportFrameBuffers(\n+\t\tconst StreamConfiguration &config,\n+\t\tstd::vector<std::unique_ptr<FrameBuffer>> *buffers);\n+\n private:\n+\tstd::unique_ptr<FrameBuffer> createBuffer(const StreamConfiguration &config);\n+\n \tstd::unique_ptr<Heap> heap_;\n };\n \ndiff --git a/src/libcamera/heap_allocator.cpp b/src/libcamera/heap_allocator.cpp\nindex 1caa1469..a1dba155 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 /**\n * \\file libcamera/internal/heap_allocator.h\n * \\brief Internal heap buffer allocator support\n@@ -291,7 +297,59 @@ UniqueFD HeapAllocator::alloc(const char *name, std::size_t size)\n \t\treturn {};\n \t}\n \n-\treturn heap_->alloc(name, size);\n+\tstd::size_t pageSize = getpagesize();\n+\t/* Allocation size needs to be a direct multiple of pageSize. */\n+\tstd::size_t numPage = (size + pageSize - 1) / pageSize;\n+\n+\treturn heap_->alloc(name, numPage * pageSize);\n+}\n+\n+int HeapAllocator::exportFrameBuffers(\n+\tconst StreamConfiguration &config,\n+\tstd::vector<std::unique_ptr<FrameBuffer>> *buffers)\n+{\n+\tunsigned int count = config.bufferCount;\n+\n+\tfor (unsigned i = 0; i < count; ++i) {\n+\t\tstd::unique_ptr<FrameBuffer> buffer = createBuffer(config);\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(\n+\tconst StreamConfiguration &config)\n+{\n+\tstd::vector<FrameBuffer::Plane> planes;\n+\n+\tauto info = PixelFormatInfo::info(config.pixelFormat);\n+\tfor (size_t i = 0; i < info.planes.size(); ++i) {\n+\t\tunsigned int planeSize = info.planeSize(config.size, i);\n+\t\tif (planeSize == 0)\n+\t\t\tcontinue;\n+\n+\t\tUniqueFD fd = alloc(\"FrameBuffer\", planeSize);\n+\t\tif (!fd.isValid())\n+\t\t\treturn nullptr;\n+\n+\t\tSharedFD sharedFd(std::move(fd));\n+\n+\t\tFrameBuffer::Plane plane;\n+\t\tplane.fd = sharedFd;\n+\t\tplane.offset = 0;\n+\t\tplane.length = planeSize;\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": [ "libcamera-devel", "v7", "3/3" ] }