Show a patch.

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

{
    "id": 16114,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/16114/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16114/",
    "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": "<20220530142722.57618-8-tomi.valkeinen@ideasonboard.com>",
    "date": "2022-05-30T14:27:13",
    "name": "[libcamera-devel,v4,07/16] py: Implement FrameBufferPlane",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "7f03a715421f9c5156dc135a66f4b230377195b2",
    "submitter": {
        "id": 109,
        "url": "https://patchwork.libcamera.org/api/1.1/people/109/?format=api",
        "name": "Tomi Valkeinen",
        "email": "tomi.valkeinen@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16114/mbox/",
    "series": [
        {
            "id": 3149,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3149/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3149",
            "date": "2022-05-30T14:27:06",
            "name": "More misc Python patches",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/3149/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16114/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16114/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 120B0BD161\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 30 May 2022 14:27:51 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 71BD565646;\n\tMon, 30 May 2022 16:27:50 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D1E3265642\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 May 2022 16:27:42 +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 3FCE01217;\n\tMon, 30 May 2022 16:27:42 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1653920870;\n\tbh=5EQrQnLIMh7Q1vLf6YDk88bvwFYgl0J3102xsGZzwhQ=;\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=c0Joi3Kuv7MR94qFFF0rZsMXbhkUcjrIDJ58VvE+/BTD4tCUPJcjath7eMje0Sv7m\n\tSMEOMZpnWepWK8reDEqKjue4ZbPzOeyBOKRJXa6rXD5T2V8ubRlskJOGHEnxnOdS2R\n\tf0CqcSZrn6EKtQCVZWfbzMrkF7M2TN+N3wCBFjxA3h5Mf/DOBA24jFRB5SV8g0ma8U\n\tlyzN876+kn7s/K0CJ3QTHnXnpPYxUmhGiZtdnFjuQF1PHCiw6W1FF3l0Qay5BtYpzv\n\tL06sBVfqn7eTBz+P/DUbSC85fcWqm0EVmMUU+TNtsjiuisdgUtpXGpmUrjJ1vdNcp0\n\tYemUMW74GOrgg==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1653920862;\n\tbh=5EQrQnLIMh7Q1vLf6YDk88bvwFYgl0J3102xsGZzwhQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=E96PVq2Wm6AwDo3NyyuadyhPkZW2pqIRlSPEjszHMmiPmvyd/O80m7gzwCqyL6Mn/\n\txlBS9gmjshTeqyAyInVLsIZnuFEE9rmc3O3AiTRMaXXhBVfyfNc9Pta+Cf/jdqABXn\n\tgLktR5BbCOWDfAfF6RYdUilaMZ2yZ4n56rQnUyos="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"E96PVq2W\"; 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": "Mon, 30 May 2022 17:27:13 +0300",
        "Message-Id": "<20220530142722.57618-8-tomi.valkeinen@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20220530142722.57618-1-tomi.valkeinen@ideasonboard.com>",
        "References": "<20220530142722.57618-1-tomi.valkeinen@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 07/16] 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>\nReviewed-by: Laurent Pinchart <laurent.pinchart@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..38fc382d 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 plane in fb.planes:\n+                        fds.append(plane.fd)\n                         strides.append(cfg.stride)\n-                        offsets.append(fb.offset(i))\n+                        offsets.append(plane.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..a8502d51 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 plane in fb.planes:\n+            fd = plane.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 plane.offset > buflen or plane.offset + plane.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={plane.offset}, plane length={plane.length}')\n \n-            bufinfos[fd]['maplen'] = max(bufinfos[fd]['maplen'], fb.offset(i) + fb.length(i))\n+            bufinfos[fd]['maplen'] = max(bufinfos[fd]['maplen'], plane.offset + plane.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 plane in fb.planes:\n+            fd = plane.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 = plane.offset\n+            end = plane.offset + plane.length\n \n             mv = mv[start:end]\n \n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "07/16"
    ]
}