From patchwork Sat Jul 13 17:23:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1685 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 32BBD61760 for ; Sat, 13 Jul 2019 19:24:31 +0200 (CEST) Received: from pendragon.ideasonboard.com (softbank126209254147.bbtec.net [126.209.254.147]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 15218443 for ; Sat, 13 Jul 2019 19:24:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1563038670; bh=v+B5QVuTUkUMF8r2djLCIK6Dhh8rF/ynuBhdrwfO7gE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DhJ4d8F6/8/4YXcYwVe2dDdjLeMP5CDaGLGj3IHqMItK2WouTta7g+m2FE6m0Kkou gDbc3VlIC8bvDdEBuDJmeVOtCdMWDbbAzqiuza48YufsKcoOP0HfNhLUoY4r97ag7r xZbDVzjr696Hp0GQeGDzt950++9Eg2l0/7wwobxw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 13 Jul 2019 20:23:39 +0300 Message-Id: <20190713172351.25452-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190713172351.25452-1-laurent.pinchart@ideasonboard.com> References: <20190713172351.25452-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/16] libcamera: request: Add cookie to make request tracking easier X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Jul 2019 17:24:31 -0000 Applications often have to map requests queued to a camera to external resources. To make this easy, add a 64-bit integer cookie to the Request class that is set when the request is created and can be retrieved at any time, especially in the request completion handler. The cookie is completely transparent for libcamera and is never modified. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/camera.h | 3 ++- include/libcamera/request.h | 5 ++++- src/libcamera/camera.cpp | 10 ++++++++-- src/libcamera/request.cpp | 18 ++++++++++++++++-- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 6d693d9a6c7a..21fac550f412 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -93,7 +94,7 @@ public: int allocateBuffers(); int freeBuffers(); - Request *createRequest(); + Request *createRequest(uint64_t cookie = 0); int queueRequest(Request *request); int start(); diff --git a/include/libcamera/request.h b/include/libcamera/request.h index a93468d7c8b7..dd165bc21c03 100644 --- a/include/libcamera/request.h +++ b/include/libcamera/request.h @@ -8,6 +8,7 @@ #define __LIBCAMERA_REQUEST_H__ #include +#include #include #include @@ -29,7 +30,7 @@ public: RequestCancelled, }; - explicit Request(Camera *camera); + Request(Camera *camera, uint64_t cookie = 0); Request(const Request &) = delete; Request &operator=(const Request &) = delete; @@ -38,6 +39,7 @@ public: int setBuffers(const std::map &streamMap); Buffer *findBuffer(Stream *stream) const; + uint64_t cookie() const { return cookie_; } Status status() const { return status_; } bool hasPendingBuffers() const { return !pending_.empty(); } @@ -56,6 +58,7 @@ private: std::map bufferMap_; std::unordered_set pending_; + uint64_t cookie_; Status status_; }; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 810cb1295f34..1f307654ab01 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -754,10 +754,16 @@ int Camera::freeBuffers() /** * \brief Create a request object for the camera + * \param[in] cookie Opaque cookie for application use * * This method creates an empty request for the application to fill with * buffers and paramaters, and queue for capture. * + * The \a cookie is stored in the request and is accessible through the + * Request::cookie() method at any time. It is typically used by applications + * to map the request to an external resource in the request completion + * handler, and is completely opaque to libcamera. + * * The ownership of the returned request is passed to the caller, which is * responsible for either queueing the request or deleting it. * @@ -766,12 +772,12 @@ int Camera::freeBuffers() * * \return A pointer to the newly created request, or nullptr on error */ -Request *Camera::createRequest() +Request *Camera::createRequest(uint64_t cookie) { if (disconnected_ || !stateBetween(CameraPrepared, CameraRunning)) return nullptr; - return new Request(this); + return new Request(this, cookie); } /** diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index f0b5985814bd..8cf41a43a80e 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -46,9 +46,17 @@ LOG_DEFINE_CATEGORY(Request) /** * \brief Create a capture request for a camera * \param[in] camera The camera that creates the request + * \param[in] cookie Opaque cookie for application use + * + * The \a cookie is stored in the request and is accessible through the + * cookie() method at any time. It is typically used by applications to map the + * request to an external resource in the request completion handler, and is + * completely opaque to libcamera. + * */ -Request::Request(Camera *camera) - : camera_(camera), controls_(camera), status_(RequestPending) +Request::Request(Camera *camera, uint64_t cookie) + : camera_(camera), controls_(camera), cookie_(cookie), + status_(RequestPending) { } @@ -119,6 +127,12 @@ Buffer *Request::findBuffer(Stream *stream) const return it->second; } +/** + * \fn Request::cookie() + * \brief Retrieve the cookie set when the request was created + * \return The request cookie + */ + /** * \fn Request::status() * \brief Retrieve the request completion status