{"id":16092,"url":"https://patchwork.libcamera.org/api/patches/16092/?format=json","web_url":"https://patchwork.libcamera.org/patch/16092/","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":"<20220527144447.94891-24-tomi.valkeinen@ideasonboard.com>","date":"2022-05-27T14:44:40","name":"[libcamera-devel,v3,23/30] py: Implement FrameBufferPlane","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"c57c440df314c586963cfb3cfc6f575f05597d78","submitter":{"id":109,"url":"https://patchwork.libcamera.org/api/people/109/?format=json","name":"Tomi Valkeinen","email":"tomi.valkeinen@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16092/mbox/","series":[{"id":3146,"url":"https://patchwork.libcamera.org/api/series/3146/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3146","date":"2022-05-27T14:44:17","name":"More misc Python patches","version":3,"mbox":"https://patchwork.libcamera.org/series/3146/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16092/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16092/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 23A3DC3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 May 2022 14:45:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B2DBB6563D;\n\tFri, 27 May 2022 16:45:34 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 676526565A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 May 2022 16:45:16 +0200 (CEST)","from deskari.lan (91-156-85-209.elisa-laajakaista.fi\n\t[91.156.85.209])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D02FBFD1;\n\tFri, 27 May 2022 16:45:15 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1653662734;\n\tbh=dXzV8DfLo7pNLIj8LFBrLz4vdQqYZJkEXG2sBTSVd2U=;\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:\n\tFrom;\n\tb=mE0OM7xgpcDbRShdC6acqDSKlGeu8nxhQVn4N8PmvBi8ZuWH3onJSGiKcyHwce/7X\n\tH2iEKVjPqm5d6OA+MvS1NVn9zNzRWpvWK4jpjh0v2Pa2yh1GYjdYQs9Pm12YKN+GEM\n\tl65GCbV7PrFMz9VaBqWtWbADNUFLkaSBo4u1gtB5csMNtrb6UQmGJSaXjAKtWffNwA\n\t/3O74jHUuZZIYhwMRIYlMYiRoN1cd3FeIN9fceuR/VBstnlSzAQCau3IfYLzZL8i0/\n\tQHwNrGOgK5xO5sjPJ9fAwRyCUmpwEifQC5vPy2AFdopg0jIzpa+FtV0CQxJ62rFRTv\n\tuVQbpcE83L1pg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1653662716;\n\tbh=dXzV8DfLo7pNLIj8LFBrLz4vdQqYZJkEXG2sBTSVd2U=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=gx4KA2MyzHiX4t4n4/njxfJseTH6cxkw6xv29sVc2C0tzAbkEYF99rMhMwfLqksKf\n\tBKkvlh30W8WhPEMh8d0TFsTTjJopIQdYrvxDyyIMQb0/E1rh6K5Xp7CTTGaXFC+EiF\n\t9J5m/0JIQ8zxYjtYrnYbeJLeT4maMDJFXHJ3/rzo="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"gx4KA2My\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org,\n\tDavid Plowman <david.plowman@raspberrypi.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tJacopo Mondi <jacopo@jmondi.org>","Date":"Fri, 27 May 2022 17:44:40 +0300","Message-Id":"<20220527144447.94891-24-tomi.valkeinen@ideasonboard.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20220527144447.94891-1-tomi.valkeinen@ideasonboard.com>","References":"<20220527144447.94891-1-tomi.valkeinen@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 23/30] py: Implement FrameBufferPlane","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":"Tomi Valkeinen via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Implement FrameBufferPlane class and adjust the methods and uses\naccordingly.\n\nNote that we don't expose the fd as a SharedFD, but as an int.\n\nSigned-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n---\n src/py/cam/cam_kms.py                       |  6 +--\n src/py/cam/cam_qtgl.py                      |  2 +-\n src/py/libcamera/py_main.cpp                | 45 +++++++++++----------\n src/py/libcamera/utils/MappedFrameBuffer.py | 18 ++++-----\n 4 files changed, 36 insertions(+), 35 deletions(-)","diff":"diff --git a/src/py/cam/cam_kms.py b/src/py/cam/cam_kms.py\nindex 49b00211..3d1e8c27 100644\n--- a/src/py/cam/cam_kms.py\n+++ b/src/py/cam/cam_kms.py\n@@ -131,10 +131,10 @@ class KMSRenderer:\n                     fds = []\n                     strides = []\n                     offsets = []\n-                    for i in range(fb.num_planes):\n-                        fds.append(fb.fd(i))\n+                    for p in fb.planes:\n+                        fds.append(p.fd)\n                         strides.append(cfg.stride)\n-                        offsets.append(fb.offset(i))\n+                        offsets.append(p.offset)\n \n                     drmfb = pykms.DmabufFramebuffer(self.card, w, h, fmt,\n                                                     fds, strides, offsets)\ndiff --git a/src/py/cam/cam_qtgl.py b/src/py/cam/cam_qtgl.py\nindex 4b43f51d..6cfbd347 100644\n--- a/src/py/cam/cam_qtgl.py\n+++ b/src/py/cam/cam_qtgl.py\n@@ -269,7 +269,7 @@ class MainWindow(QtWidgets.QWidget):\n             EGL_WIDTH, w,\n             EGL_HEIGHT, h,\n             EGL_LINUX_DRM_FOURCC_EXT, fmt,\n-            EGL_DMA_BUF_PLANE0_FD_EXT, fb.fd(0),\n+            EGL_DMA_BUF_PLANE0_FD_EXT, fb.planes[0].fd,\n             EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,\n             EGL_DMA_BUF_PLANE0_PITCH_EXT, cfg.stride,\n             EGL_NONE,\ndiff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp\nindex 52f70811..fcf009f0 100644\n--- a/src/py/libcamera/py_main.cpp\n+++ b/src/py/libcamera/py_main.cpp\n@@ -155,6 +155,7 @@ PYBIND11_MODULE(_libcamera, m)\n \tauto pyStreamFormats = py::class_<StreamFormats>(m, \"StreamFormats\");\n \tauto pyFrameBufferAllocator = py::class_<FrameBufferAllocator>(m, \"FrameBufferAllocator\");\n \tauto pyFrameBuffer = py::class_<FrameBuffer>(m, \"FrameBuffer\");\n+\tauto pyFrameBufferPlane = py::class_<FrameBuffer::Plane>(pyFrameBuffer, \"Plane\");\n \tauto pyStream = py::class_<Stream>(m, \"Stream\");\n \tauto pyControlId = py::class_<ControlId>(m, \"ControlId\");\n \tauto pyControlInfo = py::class_<ControlInfo>(m, \"ControlInfo\");\n@@ -408,31 +409,31 @@ PYBIND11_MODULE(_libcamera, m)\n \t\t});\n \n \tpyFrameBuffer\n-\t\t/* \\todo implement FrameBuffer::Plane properly */\n-\t\t.def(py::init([](std::vector<std::tuple<int, unsigned int>> planes, unsigned int cookie) {\n-\t\t\tstd::vector<FrameBuffer::Plane> v;\n-\t\t\tfor (const auto &t : planes)\n-\t\t\t\tv.push_back({ SharedFD(std::get<0>(t)), FrameBuffer::Plane::kInvalidOffset, std::get<1>(t) });\n-\t\t\treturn new FrameBuffer(v, cookie);\n-\t\t}))\n+\t\t.def(py::init<std::vector<FrameBuffer::Plane>, unsigned int>(),\n+\t\t     py::arg(\"planes\"), py::arg(\"cookie\") = 0)\n \t\t.def_property_readonly(\"metadata\", &FrameBuffer::metadata, py::return_value_policy::reference_internal)\n-\t\t.def_property_readonly(\"num_planes\", [](const FrameBuffer &self) {\n-\t\t\treturn self.planes().size();\n-\t\t})\n-\t\t.def(\"length\", [](FrameBuffer &self, uint32_t idx) {\n-\t\t\tconst FrameBuffer::Plane &plane = self.planes()[idx];\n-\t\t\treturn plane.length;\n-\t\t})\n-\t\t.def(\"fd\", [](FrameBuffer &self, uint32_t idx) {\n-\t\t\tconst FrameBuffer::Plane &plane = self.planes()[idx];\n-\t\t\treturn plane.fd.get();\n-\t\t})\n-\t\t.def(\"offset\", [](FrameBuffer &self, uint32_t idx) {\n-\t\t\tconst FrameBuffer::Plane &plane = self.planes()[idx];\n-\t\t\treturn plane.offset;\n-\t\t})\n+\t\t.def_property_readonly(\"planes\", &FrameBuffer::planes)\n \t\t.def_property(\"cookie\", &FrameBuffer::cookie, &FrameBuffer::setCookie);\n \n+\tpyFrameBufferPlane\n+\t\t.def(py::init())\n+\t\t.def(py::init([](int fd, unsigned int offset, unsigned int length) {\n+\t\t\tauto p = FrameBuffer::Plane();\n+\t\t\tp.fd = SharedFD(fd);\n+\t\t\tp.offset = offset;\n+\t\t\tp.length = length;\n+\t\t\treturn p;\n+\t\t}), py::arg(\"fd\"), py::arg(\"offset\"), py::arg(\"length\"))\n+\t\t.def_property(\"fd\",\n+\t\t\t[](const FrameBuffer::Plane &self) {\n+\t\t\t\treturn self.fd.get();\n+\t\t\t},\n+\t\t\t[](FrameBuffer::Plane &self, int fd) {\n+\t\t\t\tself.fd = SharedFD(fd);\n+\t\t\t})\n+\t\t.def_readwrite(\"offset\", &FrameBuffer::Plane::offset)\n+\t\t.def_readwrite(\"length\", &FrameBuffer::Plane::length);\n+\n \tpyStream\n \t\t.def_property_readonly(\"configuration\", &Stream::configuration);\n \ndiff --git a/src/py/libcamera/utils/MappedFrameBuffer.py b/src/py/libcamera/utils/MappedFrameBuffer.py\nindex fc2726b6..69315e76 100644\n--- a/src/py/libcamera/utils/MappedFrameBuffer.py\n+++ b/src/py/libcamera/utils/MappedFrameBuffer.py\n@@ -21,8 +21,8 @@ class MappedFrameBuffer:\n \n         bufinfos = {}\n \n-        for i in range(fb.num_planes):\n-            fd = fb.fd(i)\n+        for p in fb.planes:\n+            fd = p.fd\n \n             if fd not in bufinfos:\n                 buflen = os.lseek(fd, 0, os.SEEK_END)\n@@ -30,11 +30,11 @@ class MappedFrameBuffer:\n             else:\n                 buflen = bufinfos[fd]['buflen']\n \n-            if fb.offset(i) > buflen or fb.offset(i) + fb.length(i) > buflen:\n+            if p.offset > buflen or p.offset + p.length > buflen:\n                 raise RuntimeError(f'plane is out of buffer: buffer length={buflen}, ' +\n-                                   f'plane offset={fb.offset(i)}, plane length={fb.length(i)}')\n+                                   f'plane offset={p.offset}, plane length={p.length}')\n \n-            bufinfos[fd]['maplen'] = max(bufinfos[fd]['maplen'], fb.offset(i) + fb.length(i))\n+            bufinfos[fd]['maplen'] = max(bufinfos[fd]['maplen'], p.offset + p.length)\n \n         # mmap the buffers\n \n@@ -51,14 +51,14 @@ class MappedFrameBuffer:\n \n         planes = []\n \n-        for i in range(fb.num_planes):\n-            fd = fb.fd(i)\n+        for p in fb.planes:\n+            fd = p.fd\n             info = bufinfos[fd]\n \n             mv = memoryview(info['map'])\n \n-            start = fb.offset(i)\n-            end = fb.offset(i) + fb.length(i)\n+            start = p.offset\n+            end = p.offset + p.length\n \n             mv = mv[start:end]\n \n","prefixes":["libcamera-devel","v3","23/30"]}