From patchwork Tue Apr 20 13:07:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 12016 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 A740DBDB16 for ; Tue, 20 Apr 2021 13:07:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5A4056885B; Tue, 20 Apr 2021 15:07:53 +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="GB/kSRZB"; dkim-atps=neutral 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 27C8868848 for ; Tue, 20 Apr 2021 15:07:48 +0200 (CEST) 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 AB8C21172; Tue, 20 Apr 2021 15:07:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1618924067; bh=wMRpuy1H/rF5bzYMG+ti3c5ayvGN5Ca88P/T1NxiRI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GB/kSRZBS9/qfhQPYau4mPI0//U5QZoxOGz1x4jaAErEMdZTktVYqB+1KRZHI6yH0 lgPLWNDaHVzOK8PJ4I7nHSpd5eJc0MXGw/FlVOjBqOCvc0Uoe+qTvdkYiZ2/tzFYdH +3j3t+SJC0CYqLFDDxFcw2W9sw7fTWCFEoxsfFOc= From: Kieran Bingham To: libcamera devel Date: Tue, 20 Apr 2021 14:07:41 +0100 Message-Id: <20210420130741.236848-7-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> References: <20210420130741.236848-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 6/6] libcamera: request: Make it extensible 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" Provide an extensible private object for the Request class. This allows us to make modifications to the private API and storage of requests without affecting the public API or ABI. The D pointer is obtained in all Request functions implemented in the request.cpp file along with an assertion that the D pointer was valid to provide extra validation checking that the Request has not been deleted, while in use as it is 'owned' by the application. Signed-off-by: Kieran Bingham Reviewed-by: Jean-Michel Hautbois --- The assertions added in findBuffer, complete() and completeBuffer() allow us to ensure that the Request is still valid while asynchronous actions occur on the Request internally in libcamera, and provide (almost) equivalent functionality as the Request Canary previously proposed. The additions in reuse() and addBuffer() are called from applications, so the assertions may be less helpful there, but I've added them for consistency. include/libcamera/request.h | 4 +++- src/libcamera/request.cpp | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/include/libcamera/request.h b/include/libcamera/request.h index 4cf5ff3f7d3b..909a1aebc2d2 100644 --- a/include/libcamera/request.h +++ b/include/libcamera/request.h @@ -24,8 +24,10 @@ class CameraControlValidator; class FrameBuffer; class Stream; -class Request +class Request : public Extensible { + LIBCAMERA_DECLARE_PRIVATE(Request) + public: enum Status { RequestPending, diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index ce2dd7b17f10..977bfac4fce6 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -28,6 +28,19 @@ namespace libcamera { LOG_DEFINE_CATEGORY(Request) +class Request::Private : public Extensible::Private +{ + LIBCAMERA_DECLARE_PUBLIC(Request) + +public: + Private(Request *request); +}; + +Request::Private::Private(Request *request) + : Extensible::Private(request) +{ +} + /** * \enum Request::Status * Request completion status @@ -73,8 +86,8 @@ LOG_DEFINE_CATEGORY(Request) * */ Request::Request(Camera *camera, uint64_t cookie) - : camera_(camera), sequence_(0), cookie_(cookie), - status_(RequestPending), cancelled_(false) + : Extensible(new Private(this)), camera_(camera), sequence_(0), + cookie_(cookie), status_(RequestPending), cancelled_(false) { /** * \todo Should the Camera expose a validator instance, to avoid @@ -114,6 +127,9 @@ Request::~Request() */ void Request::reuse(ReuseFlag flags) { + Private *const d = LIBCAMERA_D_PTR(); + ASSERT(d); + LIBCAMERA_TRACEPOINT(request_reuse, this); pending_.clear(); @@ -179,6 +195,9 @@ void Request::reuse(ReuseFlag flags) */ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer) { + Private *const d = LIBCAMERA_D_PTR(); + ASSERT(d); + if (!stream) { LOG(Request, Error) << "Invalid stream reference"; return -EINVAL; @@ -214,6 +233,9 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer) */ FrameBuffer *Request::findBuffer(const Stream *stream) const { + const Private *const d = LIBCAMERA_D_PTR(); + ASSERT(d); + const auto it = bufferMap_.find(stream); if (it == bufferMap_.end()) return nullptr; @@ -282,6 +304,8 @@ FrameBuffer *Request::findBuffer(const Stream *stream) const */ void Request::complete() { + Private *const d = LIBCAMERA_D_PTR(); + ASSERT(d); ASSERT(status_ == RequestPending); ASSERT(!hasPendingBuffers()); @@ -307,6 +331,9 @@ void Request::complete() */ bool Request::completeBuffer(FrameBuffer *buffer) { + Private *const d = LIBCAMERA_D_PTR(); + ASSERT(d); + LIBCAMERA_TRACEPOINT(request_complete_buffer, this, buffer); int ret = pending_.erase(buffer); @@ -330,6 +357,9 @@ bool Request::completeBuffer(FrameBuffer *buffer) */ std::string Request::toString() const { + const Private *const d = LIBCAMERA_D_PTR(); + ASSERT(d); + std::stringstream ss; /* Pending, Completed, Cancelled(X). */