From patchwork Wed Mar 24 15:01:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11697 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com 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 14635C32E5 for ; Wed, 24 Mar 2021 15:01:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C88B968D72; Wed, 24 Mar 2021 16:01:36 +0100 (CET) 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="jQLWb1EQ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 27BC5602E3 for ; Wed, 24 Mar 2021 16:01:32 +0100 (CET) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B2E37A52; Wed, 24 Mar 2021 16:01:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1616598091; bh=EGb+GuXa1N2wwQFIP+D+xlmADU9XJ/ajKKA/y4GqIJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jQLWb1EQtstcKaYpnjHhWsamSXa9hoCFpBynuih8v18CS/3h98j8KBJIJG4ZRfD3q A9iMlcYAOk2hkEvR7XpF1wFloB22DssIY3D7qb9xVomZN2c6Y2qZv9mrtmraonljpp hxJOYur+xICTsEtnNLcPF9t9XyHXt/FKAoyHsOXw= From: Kieran Bingham To: libcamera devel Date: Wed, 24 Mar 2021 15:01:22 +0000 Message-Id: <20210324150125.1318325-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210324150125.1318325-1-kieran.bingham@ideasonboard.com> References: <20210324150125.1318325-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/6] libcamera: buffer: Initialise status 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" Buffers queued to a pipeline handler may not be yet queued to a device when the request is cancelled. This can lead to the FrameMetadata having never been explicitly set by an underlying V4L2 device. The status field on this is used to check the state of the buffer to determine if it was correctly filled, or if it was cancelled. In the event that the buffer is not used, it must be marked as Cancelled as the metadata associated with that frame will not be valid. Initialise the FrameMetadata to FrameCancelled to prevent uninitialised access. Furthermore, re-initialise the metadata to this state when the buffers are re-used, or added to a Request to ensure that they are in the correct state in the event that they do not get used at all. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Laurent Pinchart --- v3: - Initialise as FrameCancelled - Re-initialise to FrameCancelled when buffers are re-used - Do not re-order the enum include/libcamera/buffer.h | 2 +- src/libcamera/request.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h index 302fe3d3e86b..f6673e2f6eda 100644 --- a/include/libcamera/buffer.h +++ b/include/libcamera/buffer.h @@ -28,7 +28,7 @@ struct FrameMetadata { unsigned int bytesused; }; - Status status; + Status status = FrameCancelled; unsigned int sequence; uint64_t timestamp; std::vector planes; diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index 0071667e4a2c..9ea6ed09446b 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -118,8 +118,12 @@ void Request::reuse(ReuseFlag flags) pending_.clear(); if (flags & ReuseBuffers) { for (auto pair : bufferMap_) { - pair.second->request_ = this; - pending_.insert(pair.second); + FrameBuffer *buffer = pair.second; + + buffer->metadata_.status = FrameMetadata::Status::FrameCancelled; + buffer->request_ = this; + + pending_.insert(buffer); } } else { bufferMap_.clear(); @@ -188,6 +192,7 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer) } buffer->request_ = this; + buffer->metadata_.status = FrameMetadata::Status::FrameCancelled; pending_.insert(buffer); bufferMap_[stream] = buffer;