{"id":16097,"url":"https://patchwork.libcamera.org/api/patches/16097/?format=json","web_url":"https://patchwork.libcamera.org/patch/16097/","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-27-tomi.valkeinen@ideasonboard.com>","date":"2022-05-27T14:44:43","name":"[libcamera-devel,v3,26/30] py: cam: cam_qt: mmap the fbs only once","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"1822c7e45b3ea4a12c2363810b59bee2d9c4d82a","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/16097/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/16097/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16097/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 D15D1C326D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 May 2022 14:45:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CA24E65652;\n\tFri, 27 May 2022 16:45:39 +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 026326565E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 May 2022 16:45:18 +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 652AE4CDA;\n\tFri, 27 May 2022 16:45:17 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1653662739;\n\tbh=Okl+wkWXIhIj8TacF37C+99ssAxg9vTV88RCzBhwMzM=;\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=YC/Tt6sXq//S5o8f5jsJfCuYgXzJNj0oXJe5dgRYnTmjb0PBNNiNjwy68yBSmeaNS\n\tmhRrOFwTIMYSokEsMFyooygxPhOeglChBAGeEYG+duZBoUOAa2kEc4K5leJ0u8Veex\n\tddiVNLR1YfV31cddPx/HndzsGkR+Zeuq004CO4BD3I8P9ydKOEVE3zWa4Vk6kuFvRY\n\tmVNOzozkPzogPue0xWLtFzig3+6s026AEUdccap8ksgrGuEEDpCz+44GfglhSQYi2e\n\tw4aqi/1nwrBno+yApE9nTtt5ycdklydhX48i0MdrhisbGVeYT1NFyiS9Iz5Z2stXya\n\tcCNq+grj8rI0A==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1653662717;\n\tbh=Okl+wkWXIhIj8TacF37C+99ssAxg9vTV88RCzBhwMzM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=rjPiDnjnXp7x8EKv4ozDUH1L2TYMCYmejQhVg2VwQogIh+11m+XH3MUxXeydFSN1u\n\txNUT3fXNiB87A36DQJhSWRoizi3f71bMUlNlkA9ykAaUze2mDgSHUSP2pqbTAhrjN1\n\tOiW0M2paJAbhnYTDZxvH8jfucxqQdH6OlToaysvY="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"rjPiDnjn\"; 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:43 +0300","Message-Id":"<20220527144447.94891-27-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 26/30] py: cam: cam_qt: mmap the fbs\n\tonly once","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":"Instead of doing an mmap and munmap every time a Request is complete,\nmmap all the buffers once at the start of the program.\n\nSigned-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n---\n src/py/cam/cam_qt.py | 39 +++++++++++++++++++++++++--------------\n 1 file changed, 25 insertions(+), 14 deletions(-)","diff":"diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py\nindex b6412bdf..c1723b44 100644\n--- a/src/py/cam/cam_qt.py\n+++ b/src/py/cam/cam_qt.py\n@@ -52,6 +52,16 @@ class QtRenderer:\n \n         self.windows = windows\n \n+        buf_mmap_map = {}\n+\n+        for ctx in self.contexts:\n+            for stream in ctx.streams:\n+                for buf in ctx.allocator.buffers(stream):\n+                    mfb = libcamera.utils.MappedFrameBuffer(buf).mmap()\n+                    buf_mmap_map[buf] = mfb\n+\n+        self.buf_mmap_map = buf_mmap_map\n+\n     def run(self):\n         camnotif = QtCore.QSocketNotifier(self.cm.event_fd, QtCore.QSocketNotifier.Read)\n         camnotif.activated.connect(lambda _: self.readcam())\n@@ -81,7 +91,9 @@ class QtRenderer:\n         for stream, fb in buffers.items():\n             wnd = next(wnd for wnd in self.windows if wnd.stream == stream)\n \n-            wnd.handle_request(stream, fb)\n+            mfb = self.buf_mmap_map[fb]\n+\n+            wnd.handle_request(stream, mfb)\n \n         self.state.request_processed(ctx, req)\n \n@@ -145,26 +157,25 @@ class MainWindow(QtWidgets.QWidget):\n \n         controlsLayout.addStretch()\n \n-    def buf_to_qpixmap(self, stream, fb):\n-        with libcamera.utils.MappedFrameBuffer(fb) as mfb:\n-            cfg = stream.configuration\n+    def buf_to_qpixmap(self, stream, mfb):\n+        cfg = stream.configuration\n \n-            if cfg.pixel_format == libcam.formats.MJPEG:\n-                pix = QtGui.QPixmap(cfg.size.width, cfg.size.height)\n-                pix.loadFromData(mfb.planes[0])\n-            else:\n-                rgb = mfb_to_rgb(mfb, cfg)\n-                if rgb is None:\n-                    raise Exception('Format not supported: ' + cfg.pixel_format)\n+        if cfg.pixel_format == libcam.formats.MJPEG:\n+            pix = QtGui.QPixmap(cfg.size.width, cfg.size.height)\n+            pix.loadFromData(mfb.planes[0])\n+        else:\n+            rgb = mfb_to_rgb(mfb, cfg)\n+            if rgb is None:\n+                raise Exception('Format not supported: ' + cfg.pixel_format)\n \n-                pix = rgb_to_pix(rgb)\n+            pix = rgb_to_pix(rgb)\n \n         return pix\n \n-    def handle_request(self, stream, fb):\n+    def handle_request(self, stream, mfb):\n         ctx = self.ctx\n \n-        pix = self.buf_to_qpixmap(stream, fb)\n+        pix = self.buf_to_qpixmap(stream, mfb)\n         self.label.setPixmap(pix)\n \n         self.frameLabel.setText('Queued: {}\\nDone: {}\\nFps: {:.2f}'\n","prefixes":["libcamera-devel","v3","26/30"]}