From patchwork Mon May 30 14:27:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 16117 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 87ED7C3274 for ; Mon, 30 May 2022 14:27:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E82E165645; Mon, 30 May 2022 16:27:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653920872; bh=n+W+jX0Fs4ev88/WDptxjT/u3x5ep0kwU/KdgsI3Z4w=; 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=B47wvHVEUC25FmY6oiuctty3PDy2IsxW/XtZ1Yvvz2oe0V5NVXu9P5QNh7aljnuU4 2pSTmVJl18NbXoDah5Qa1UTeCFW+vpGlCpwh969MKsNEErVkDfeKBt9cpMTFPIGuaM 07gPhiuUQ+pLMCl1dWndHGpu90iAWkITHHdB+X27MVJMjiImDT1+eYYtdb1TK0ZJa/ +Ediv6374K+4kIts8m88ohAQaWOwiOr7EViSui04ebX1EKkITLkhsmVODfSfTYzn26 jfMX5hLlEQj7y/JUW9wEQrGS5vfBUtFFAcMKv7x3+LSF4LEkth40+PGDo7+3b7HBYm CdQOaobFQ/nlQ== 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 6841165647 for ; Mon, 30 May 2022 16:27:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="WlFi6YWq"; 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 CC021110E; Mon, 30 May 2022 16:27:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653920864; bh=n+W+jX0Fs4ev88/WDptxjT/u3x5ep0kwU/KdgsI3Z4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WlFi6YWq8VkpYZMmY5s4KIftdrNBW+1c5n+c1LO6igBRMwy1DeYjsTKRnrRFCs+el XkNz0172pLjMWcMDo5AJtC/J1Z9YZ6NAy0MV224pN0w4N1ertWIUSAInVBT+DPoc3f lCs7yDe6viHlHRf0RtUXQi6ghQm38l/ZTdrvXexQ= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Mon, 30 May 2022 17:27:16 +0300 Message-Id: <20220530142722.57618-11-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 Subject: [libcamera-devel] [PATCH v4 10/16] 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}'