{"id":1685,"url":"https://patchwork.libcamera.org/api/patches/1685/?format=json","web_url":"https://patchwork.libcamera.org/patch/1685/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190713172351.25452-5-laurent.pinchart@ideasonboard.com>","date":"2019-07-13T17:23:39","name":"[libcamera-devel,v2,04/16] libcamera: request: Add cookie to make request tracking easier","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"c2cc9a648e22cc83e0368944eba004d91edd7db3","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1685/mbox/","series":[{"id":430,"url":"https://patchwork.libcamera.org/api/series/430/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=430","date":"2019-07-13T17:23:35","name":"Add support for external buffers","version":2,"mbox":"https://patchwork.libcamera.org/series/430/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1685/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1685/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 32BBD61760\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 13 Jul 2019 19:24:31 +0200 (CEST)","from pendragon.ideasonboard.com (softbank126209254147.bbtec.net\n\t[126.209.254.147])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 15218443\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 13 Jul 2019 19:24:29 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1563038670;\n\tbh=v+B5QVuTUkUMF8r2djLCIK6Dhh8rF/ynuBhdrwfO7gE=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=DhJ4d8F6/8/4YXcYwVe2dDdjLeMP5CDaGLGj3IHqMItK2WouTta7g+m2FE6m0Kkou\n\tgDbc3VlIC8bvDdEBuDJmeVOtCdMWDbbAzqiuza48YufsKcoOP0HfNhLUoY4r97ag7r\n\txZbDVzjr696Hp0GQeGDzt950++9Eg2l0/7wwobxw=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 04/16] libcamera: request: Add cookie\n\tto make request tracking easier","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sat, 13 Jul 2019 17:24:31 -0000"},"content":"Applications often have to map requests queued to a camera to external\nresources. To make this easy, add a 64-bit integer cookie to the Request\nclass that is set when the request is created and can be retrieved at\nany time, especially in the request completion handler. The cookie is\ncompletely transparent for libcamera and is never modified.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/camera.h  |  3 ++-\n include/libcamera/request.h |  5 ++++-\n src/libcamera/camera.cpp    | 10 ++++++++--\n src/libcamera/request.cpp   | 18 ++++++++++++++++--\n 4 files changed, 30 insertions(+), 6 deletions(-)","diff":"diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\nindex 6d693d9a6c7a..21fac550f412 100644\n--- a/include/libcamera/camera.h\n+++ b/include/libcamera/camera.h\n@@ -10,6 +10,7 @@\n #include <map>\n #include <memory>\n #include <set>\n+#include <stdint.h>\n #include <string>\n \n #include <libcamera/controls.h>\n@@ -93,7 +94,7 @@ public:\n \tint allocateBuffers();\n \tint freeBuffers();\n \n-\tRequest *createRequest();\n+\tRequest *createRequest(uint64_t cookie = 0);\n \tint queueRequest(Request *request);\n \n \tint start();\ndiff --git a/include/libcamera/request.h b/include/libcamera/request.h\nindex a93468d7c8b7..dd165bc21c03 100644\n--- a/include/libcamera/request.h\n+++ b/include/libcamera/request.h\n@@ -8,6 +8,7 @@\n #define __LIBCAMERA_REQUEST_H__\n \n #include <map>\n+#include <stdint.h>\n #include <unordered_set>\n \n #include <libcamera/controls.h>\n@@ -29,7 +30,7 @@ public:\n \t\tRequestCancelled,\n \t};\n \n-\texplicit Request(Camera *camera);\n+\tRequest(Camera *camera, uint64_t cookie = 0);\n \tRequest(const Request &) = delete;\n \tRequest &operator=(const Request &) = delete;\n \n@@ -38,6 +39,7 @@ public:\n \tint setBuffers(const std::map<Stream *, Buffer *> &streamMap);\n \tBuffer *findBuffer(Stream *stream) const;\n \n+\tuint64_t cookie() const { return cookie_; }\n \tStatus status() const { return status_; }\n \n \tbool hasPendingBuffers() const { return !pending_.empty(); }\n@@ -56,6 +58,7 @@ private:\n \tstd::map<Stream *, Buffer *> bufferMap_;\n \tstd::unordered_set<Buffer *> pending_;\n \n+\tuint64_t cookie_;\n \tStatus status_;\n };\n \ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 810cb1295f34..1f307654ab01 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -754,10 +754,16 @@ int Camera::freeBuffers()\n \n /**\n  * \\brief Create a request object for the camera\n+ * \\param[in] cookie Opaque cookie for application use\n  *\n  * This method creates an empty request for the application to fill with\n  * buffers and paramaters, and queue for capture.\n  *\n+ * The \\a cookie is stored in the request and is accessible through the\n+ * Request::cookie() method at any time. It is typically used by applications\n+ * to map the request to an external resource in the request completion\n+ * handler, and is completely opaque to libcamera.\n+ *\n  * The ownership of the returned request is passed to the caller, which is\n  * responsible for either queueing the request or deleting it.\n  *\n@@ -766,12 +772,12 @@ int Camera::freeBuffers()\n  *\n  * \\return A pointer to the newly created request, or nullptr on error\n  */\n-Request *Camera::createRequest()\n+Request *Camera::createRequest(uint64_t cookie)\n {\n \tif (disconnected_ || !stateBetween(CameraPrepared, CameraRunning))\n \t\treturn nullptr;\n \n-\treturn new Request(this);\n+\treturn new Request(this, cookie);\n }\n \n /**\ndiff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\nindex f0b5985814bd..8cf41a43a80e 100644\n--- a/src/libcamera/request.cpp\n+++ b/src/libcamera/request.cpp\n@@ -46,9 +46,17 @@ LOG_DEFINE_CATEGORY(Request)\n /**\n  * \\brief Create a capture request for a camera\n  * \\param[in] camera The camera that creates the request\n+ * \\param[in] cookie Opaque cookie for application use\n+ *\n+ * The \\a cookie is stored in the request and is accessible through the\n+ * cookie() method at any time. It is typically used by applications to map the\n+ * request to an external resource in the request completion handler, and is\n+ * completely opaque to libcamera.\n+ *\n  */\n-Request::Request(Camera *camera)\n-\t: camera_(camera), controls_(camera), status_(RequestPending)\n+Request::Request(Camera *camera, uint64_t cookie)\n+\t: camera_(camera), controls_(camera), cookie_(cookie),\n+\t  status_(RequestPending)\n {\n }\n \n@@ -119,6 +127,12 @@ Buffer *Request::findBuffer(Stream *stream) const\n \treturn it->second;\n }\n \n+/**\n+ * \\fn Request::cookie()\n+ * \\brief Retrieve the cookie set when the request was created\n+ * \\return The request cookie\n+ */\n+\n /**\n  * \\fn Request::status()\n  * \\brief Retrieve the request completion status\n","prefixes":["libcamera-devel","v2","04/16"]}