[{"id":2246,"web_url":"https://patchwork.libcamera.org/comment/2246/","msgid":"<20190714070711.GA31102@wyvern>","date":"2019-07-14T07:07:11","subject":"Re: [libcamera-devel] [PATCH v2 04/16] libcamera: request: Add\n\tcookie to make request tracking easier","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your patch.\n\nOn 2019-07-13 20:23:39 +0300, Laurent Pinchart wrote:\n> Applications often have to map requests queued to a camera to external\n> resources. To make this easy, add a 64-bit integer cookie to the Request\n> class that is set when the request is created and can be retrieved at\n> any time, especially in the request completion handler. The cookie is\n> completely transparent for libcamera and is never modified.\n> \n> Signed-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(-)\n> \n> diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\n> index 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();\n> diff --git a/include/libcamera/request.h b/include/libcamera/request.h\n> index 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\nI think this should be const uint64_t, with this fixed.\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n>  \tStatus status_;\n>  };\n>  \n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 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>  /**\n> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\n> index 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> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-pl1-x644.google.com (mail-pl1-x644.google.com\n\t[IPv6:2607:f8b0:4864:20::644])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DE8DD60E3F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 14 Jul 2019 09:07:16 +0200 (CEST)","by mail-pl1-x644.google.com with SMTP id t14so6735360plr.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 14 Jul 2019 00:07:16 -0700 (PDT)","from localhost (softbank126159224182.bbtec.net. [126.159.224.182])\n\tby smtp.gmail.com with ESMTPSA id\n\tb24sm12514749pfd.98.2019.07.14.00.07.13\n\t(version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256);\n\tSun, 14 Jul 2019 00:07:14 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=rVl252SCkOb+n3PTJfIWbyaLTzd1gBzutQizpx8/WOg=;\n\tb=FoXAuRuVzyDKDjjl+GbdjoyM9COpGzUs5xhxxetv2NN6aTQ+ZtnO+twIJTsIXtSP8O\n\ttMxvEPb/yE1iEvsDXGn02tP/x9lFa6T5PIFs3Mm3NUETqIMRti8DT+Q0w634ySLigXvo\n\tMXoume6glf9a+cDDbA7MJKnzq9xFMDNN70zCeWhmt6DLtoZ3tCDOXl4h2Ita1eHDQSoY\n\tIbk2g+nZUpSkuWCj8T3FTLaL7F97X1PylXRZIQdzHdFK18z4cTdDfjKmHhZTEISdSqrf\n\tGwa7ZrXyCq/CVsBNP8B6gxTXvve2vB30WjnGMiXJZjqd2rEB+3R3OQYjnPVZH7ZAwe23\n\tSjbQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=rVl252SCkOb+n3PTJfIWbyaLTzd1gBzutQizpx8/WOg=;\n\tb=Iha3u0fs8xFjyoKealNLXilCNcDbnCg0tbNXxExVfXRWAUnANAr53MieFTIFX3C4uG\n\tCG76I7SY81pweMqY8MNSd9y5NWvtROa7nxwWDgtOvAMqOQpuhkcizRV7csnFz3IpkJrO\n\tFaveBKwzMw/49mvXlylP2ZxDj0N6eq05TF7Rmabrw/QFOhWD/L8sz4p5ym2hUkM4b1HY\n\tre7+SaMhwWzLFHUMGZME+T1sKx9Kp6zyR9t+P5XTvt8sg0axlt6nCnH6FF7cJ5jfpvxv\n\ty3Y+R7CpU8TAcnQtji4clbluJ1td9C5EukE4Cam9PzMHHTsMoJR0uhaxl2sxepl3Pqdi\n\tx8JA==","X-Gm-Message-State":"APjAAAWRbYdD9qmwkO4uKugxYhQExAmb9oWPGAPl2e6aTwoU7VN7ZHAW\n\tCkibhhdmOnuXxfwfgrvvFQg=","X-Google-Smtp-Source":"APXvYqwNeXTdWwaUqFO9TR6SGsm7iSf24vtXGioACs8XZyF2E7rQ6lT4746WwHrR/dJfq+yar34lFg==","X-Received":"by 2002:a17:902:846:: with SMTP id\n\t64mr21479822plk.265.1563088035157; \n\tSun, 14 Jul 2019 00:07:15 -0700 (PDT)","Date":"Sun, 14 Jul 2019 16:07:11 +0900","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190714070711.GA31102@wyvern>","References":"<20190713172351.25452-1-laurent.pinchart@ideasonboard.com>\n\t<20190713172351.25452-5-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190713172351.25452-5-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH v2 04/16] libcamera: request: Add\n\tcookie to 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":"Sun, 14 Jul 2019 07:07:17 -0000"}}]