From patchwork Fri Aug 15 11:33:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 24131 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 857D7BEFBE for ; Fri, 15 Aug 2025 11:34:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E7C806925E; Fri, 15 Aug 2025 13:34:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Ef4jFpon"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DE45861443 for ; Fri, 15 Aug 2025 13:34:21 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id E1287605; Fri, 15 Aug 2025 13:33:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1755257607; bh=yRAxsrQ6ipP0IxLlpZKKaiJQ3ujWO9s1cmAAiPwGlHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ef4jFponHfCvA9TDD0+VJYHW1YKB/qIZ5xas87iWkHQicXo3Zb0RMHCpzMnmTZRZm tEivEKNIosLkt5rgthOQ4RU28mCS6U7N5WkC3BFz8ksqDlTcGR87Cg+VLHbfN5qkYY kz05fbWhhjx0amyHTImgQ9yj1Nz/NsNf2Ho3JPsc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Daniel_R=C3=A1kos?= Subject: [PATCH v2 1/8] libcamera: v4l2_videodevice: Avoid repeated calls to FrameBuffer::planes() Date: Fri, 15 Aug 2025 14:33:53 +0300 Message-ID: <20250815113400.20623-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.49.1 In-Reply-To: <20250815113400.20623-1-laurent.pinchart@ideasonboard.com> References: <20250815113400.20623-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The V4L2VideoDevice::dequeueBuffer() calls buffer->planes() multiple times. Store the planes array in a local variable to make this more efficient. Signed-off-by: Laurent Pinchart Reviewed-by: Barnabás Pőcze --- src/libcamera/v4l2_videodevice.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 5b3530b4e542..ba1889a939cb 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1909,9 +1909,10 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() } metadata.sequence -= firstFrame_.value(); + const std::vector &framebufferPlanes = buffer->planes(); unsigned int numV4l2Planes = multiPlanar ? buf.length : 1; - if (numV4l2Planes != buffer->planes().size()) { + if (numV4l2Planes != framebufferPlanes.size()) { /* * If we have a multi-planar buffer with a V4L2 * single-planar format, split the V4L2 buffer across @@ -1921,7 +1922,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() if (numV4l2Planes != 1) { LOG(V4L2, Error) << "Invalid number of planes (" << numV4l2Planes - << " != " << buffer->planes().size() << ")"; + << " != " << framebufferPlanes.size() << ")"; metadata.status = FrameMetadata::FrameError; return buffer; @@ -1938,12 +1939,12 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() : buf.bytesused; unsigned int remaining = bytesused; - for (auto [i, plane] : utils::enumerate(buffer->planes())) { + for (auto [i, plane] : utils::enumerate(framebufferPlanes)) { if (!remaining) { LOG(V4L2, Error) << "Dequeued buffer (" << bytesused << " bytes) too small for plane lengths " - << utils::join(buffer->planes(), "/", + << utils::join(framebufferPlanes, "/", [](const FrameBuffer::Plane &p) { return p.length; });