From patchwork Mon Sep 6 22:56:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13683 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 7DFC4BE175 for ; Mon, 6 Sep 2021 22:57:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A349869176; Tue, 7 Sep 2021 00:57:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VhmXhv56"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 659A86917B for ; Tue, 7 Sep 2021 00:57:05 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F190A891; Tue, 7 Sep 2021 00:57:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630969025; bh=FQRh8jtBYRQJEcnoB04QAkbbvLALlkPZpcwtBAk8UnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VhmXhv56SkWQwQhQ8L2VrvH8gFlpoONpUX/PQN/qCUC4M/q6Da2LvuaQVwxPpOECE RTqs9HHRHox1wrzjPKJujFYrUpmY69y1rujiBvoiXq8AHzDDrKEx0qVUc06rHQMknI SRwq1427i2m522/6d6zAwl0r1kn4iQff5+XyHcUk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Sep 2021 01:56:22 +0300 Message-Id: <20210906225636.14683-16-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210906225420.13275-1-laurent.pinchart@ideasonboard.com> References: <20210906225420.13275-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 16/30] libcamera: framebuffer: Allocate metadata planes at construction time 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 metadata planes are allocated by V4L2VideoDevice when dequeuing a buffer. This causes the metadata planes to only be allocated after a buffer gets dequeued, and doesn't provide any strong guarantee that their number matches the number of FrameBuffer planes. The lack of this invariant makes the FrameBuffer class fragile. As a first step towards fixing this, allocate the metadata planes when the FrameBuffer is constructed. The FrameMetadata API should be further improved by preventing a change in the number of planes. Signed-off-by: Laurent Pinchart Reviewed-by: Jean-Michel Hautbois Reviewed-by: Hirokazu Honda --- Changes since v1: - Return buffer with state set to FrameError on error --- src/libcamera/framebuffer.cpp | 2 ++ src/libcamera/v4l2_videodevice.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp index e71c2ffae034..e4f8419a9063 100644 --- a/src/libcamera/framebuffer.cpp +++ b/src/libcamera/framebuffer.cpp @@ -210,6 +210,8 @@ FrameBuffer::FrameBuffer(const std::vector &planes, unsigned int cookie) : Extensible(std::make_unique()), planes_(planes), cookie_(cookie) { + metadata_.planes.resize(planes_.size()); + unsigned int offset = 0; bool isContiguous = true; ino_t inode = 0; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 281f3f13fc9c..81209e485c24 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1675,7 +1675,6 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() unsigned int numV4l2Planes = multiPlanar ? buf.length : 1; FrameMetadata &metadata = buffer->metadata_; - metadata.planes.clear(); if (numV4l2Planes != buffer->planes().size()) { /* @@ -1705,8 +1704,9 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() return buffer; } - metadata.planes.push_back({ std::min(plane.length, bytesused) }); - bytesused -= metadata.planes.back().bytesused; + metadata.planes[i].bytesused = + std::min(plane.length, bytesused); + bytesused -= metadata.planes[i].bytesused; } } else if (multiPlanar) { /* @@ -1715,9 +1715,9 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() * V4L2 buffer is guaranteed to be equal at this point. */ for (unsigned int i = 0; i < numV4l2Planes; ++i) - metadata.planes.push_back({ planes[i].bytesused }); + metadata.planes[i].bytesused = planes[i].bytesused; } else { - metadata.planes.push_back({ buf.bytesused }); + metadata.planes[0].bytesused = buf.bytesused; } return buffer;