From patchwork Fri May 27 14:44:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 16097 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id D15D1C326D for ; Fri, 27 May 2022 14:45:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CA24E65652; Fri, 27 May 2022 16:45:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653662739; bh=Okl+wkWXIhIj8TacF37C+99ssAxg9vTV88RCzBhwMzM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=YC/Tt6sXq//S5o8f5jsJfCuYgXzJNj0oXJe5dgRYnTmjb0PBNNiNjwy68yBSmeaNS mhRrOFwTIMYSokEsMFyooygxPhOeglChBAGeEYG+duZBoUOAa2kEc4K5leJ0u8Veex ddiVNLR1YfV31cddPx/HndzsGkR+Zeuq004CO4BD3I8P9ydKOEVE3zWa4Vk6kuFvRY mVNOzozkPzogPue0xWLtFzig3+6s026AEUdccap8ksgrGuEEDpCz+44GfglhSQYi2e w4aqi/1nwrBno+yApE9nTtt5ycdklydhX48i0MdrhisbGVeYT1NFyiS9Iz5Z2stXya cCNq+grj8rI0A== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 026326565E for ; Fri, 27 May 2022 16:45:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rjPiDnjn"; dkim-atps=neutral Received: from deskari.lan (91-156-85-209.elisa-laajakaista.fi [91.156.85.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 652AE4CDA; Fri, 27 May 2022 16:45:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653662717; bh=Okl+wkWXIhIj8TacF37C+99ssAxg9vTV88RCzBhwMzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rjPiDnjnXp7x8EKv4ozDUH1L2TYMCYmejQhVg2VwQogIh+11m+XH3MUxXeydFSN1u xNUT3fXNiB87A36DQJhSWRoizi3f71bMUlNlkA9ykAaUze2mDgSHUSP2pqbTAhrjN1 OiW0M2paJAbhnYTDZxvH8jfucxqQdH6OlToaysvY= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi 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 Subject: [libcamera-devel] [PATCH v3 26/30] py: cam: cam_qt: mmap the fbs only once X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tomi Valkeinen via libcamera-devel From: Tomi Valkeinen Reply-To: Tomi Valkeinen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Instead of doing an mmap and munmap every time a Request is complete, mmap all the buffers once at the start of the program. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- src/py/cam/cam_qt.py | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py index b6412bdf..c1723b44 100644 --- a/src/py/cam/cam_qt.py +++ b/src/py/cam/cam_qt.py @@ -52,6 +52,16 @@ class QtRenderer: self.windows = windows + buf_mmap_map = {} + + for ctx in self.contexts: + for stream in ctx.streams: + for buf in ctx.allocator.buffers(stream): + mfb = libcamera.utils.MappedFrameBuffer(buf).mmap() + buf_mmap_map[buf] = mfb + + self.buf_mmap_map = buf_mmap_map + def run(self): camnotif = QtCore.QSocketNotifier(self.cm.event_fd, QtCore.QSocketNotifier.Read) camnotif.activated.connect(lambda _: self.readcam()) @@ -81,7 +91,9 @@ class QtRenderer: for stream, fb in buffers.items(): wnd = next(wnd for wnd in self.windows if wnd.stream == stream) - wnd.handle_request(stream, fb) + mfb = self.buf_mmap_map[fb] + + wnd.handle_request(stream, mfb) self.state.request_processed(ctx, req) @@ -145,26 +157,25 @@ class MainWindow(QtWidgets.QWidget): controlsLayout.addStretch() - def buf_to_qpixmap(self, stream, fb): - with libcamera.utils.MappedFrameBuffer(fb) as mfb: - cfg = stream.configuration + def buf_to_qpixmap(self, stream, mfb): + cfg = stream.configuration - if cfg.pixel_format == libcam.formats.MJPEG: - pix = QtGui.QPixmap(cfg.size.width, cfg.size.height) - pix.loadFromData(mfb.planes[0]) - else: - rgb = mfb_to_rgb(mfb, cfg) - if rgb is None: - raise Exception('Format not supported: ' + cfg.pixel_format) + if cfg.pixel_format == libcam.formats.MJPEG: + pix = QtGui.QPixmap(cfg.size.width, cfg.size.height) + pix.loadFromData(mfb.planes[0]) + else: + rgb = mfb_to_rgb(mfb, cfg) + if rgb is None: + raise Exception('Format not supported: ' + cfg.pixel_format) - pix = rgb_to_pix(rgb) + pix = rgb_to_pix(rgb) return pix - def handle_request(self, stream, fb): + def handle_request(self, stream, mfb): ctx = self.ctx - pix = self.buf_to_qpixmap(stream, fb) + pix = self.buf_to_qpixmap(stream, mfb) self.label.setPixmap(pix) self.frameLabel.setText('Queued: {}\nDone: {}\nFps: {:.2f}'