[{"id":1440,"web_url":"https://patchwork.libcamera.org/comment/1440/","msgid":"<20190417153944.GO28515@bigcity.dyn.berto.se>","date":"2019-04-17T15:39:44","subject":"Re: [libcamera-devel] [PATCH v7 8/8] libcamera: buffer: Store\n\tRequest reference in Buffer","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your work.\n\nOn 2019-04-17 15:58:58 +0200, Jacopo Mondi wrote:\n> Add to the Buffer class methods to set and retrieve a reference to the\n> Request instance the buffer is part of.\n> \n> As buffers might outlive the Request they are associated with, the\n> reference is only temporary valid during the buffer completion interval\n> (from when the buffer gets queued to Camera for processing, until it\n> gets marked as completed).\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  include/libcamera/buffer.h |  6 ++++++\n>  src/libcamera/buffer.cpp   | 25 ++++++++++++++++++++++++-\n>  src/libcamera/request.cpp  |  3 +++\n>  3 files changed, 33 insertions(+), 1 deletion(-)\n> \n> diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h\n> index 0c844d126a27..8f9b42e39339 100644\n> --- a/include/libcamera/buffer.h\n> +++ b/include/libcamera/buffer.h\n> @@ -13,6 +13,7 @@\n>  namespace libcamera {\n>  \n>  class BufferPool;\n> +class Request;\n>  \n>  class Plane final\n>  {\n> @@ -52,14 +53,18 @@ public:\n>  \tunsigned int sequence() const { return sequence_; }\n>  \tStatus status() const { return status_; }\n>  \tstd::vector<Plane> &planes() { return planes_; }\n> +\tRequest *request() const { return request_; }\n>  \n>  private:\n>  \tfriend class BufferPool;\n>  \tfriend class PipelineHandler;\n> +\tfriend class Request;\n>  \tfriend class V4L2Device;\n>  \n>  \tvoid cancel();\n>  \n> +\tvoid setRequest(Request *request) { request_ = request; }\n> +\n>  \tunsigned int index_;\n>  \tunsigned int bytesused_;\n>  \tuint64_t timestamp_;\n> @@ -67,6 +72,7 @@ private:\n>  \tStatus status_;\n>  \n>  \tstd::vector<Plane> planes_;\n> +\tRequest *request_;\n>  };\n>  \n>  class BufferPool final\n> diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp\n> index e2d1cf04411e..8261ca41d62e 100644\n> --- a/src/libcamera/buffer.cpp\n> +++ b/src/libcamera/buffer.cpp\n> @@ -196,7 +196,7 @@ void *Plane::mem()\n>   */\n>  \n>  Buffer::Buffer()\n> -\t: index_(-1)\n> +\t: index_(-1), request_(nullptr)\n>  {\n>  }\n>  \n> @@ -248,6 +248,22 @@ Buffer::Buffer()\n>   * \\return The buffer status\n>   */\n>  \n> +/**\n> + * \\fn Buffer::request()\n> + * \\brief Retrieve the request this buffer belongs to\n> + *\n> + * The intended callers of this method are buffer completion handlers that\n> + * needs to associate a buffer to the request it belongs to.\n> + *\n> + * A Buffer is associated to a request by Request::prepare() and the\n> + * association is valid until the buffer completes. The returned request\n> + * pointer is valid only during that interval.\n> + *\n> + * \\return The Request the Buffer belongs to, or nullptr if the buffer is\n> + * either completed or not associated with a request\n> + * \\sa Buffer::setRequest()\n> + */\n> +\n>  /**\n>   * \\brief Mark a buffer as cancel by setting its status to BufferCancelled\n>   */\n> @@ -259,6 +275,13 @@ void Buffer::cancel()\n>  \tstatus_ = BufferCancelled;\n>  }\n>  \n> +/**\n> + * \\fn Buffer::setRequest()\n> + * \\brief Set the request this buffer belongs to\n> + *\n> + * The intended callers are Request::prepare() and Request::completeBuffer().\n> + */\n> +\n>  /**\n>   * \\class BufferPool\n>   * \\brief A pool of buffers\n> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\n> index b215366baa7c..290175f876b4 100644\n> --- a/src/libcamera/request.cpp\n> +++ b/src/libcamera/request.cpp\n> @@ -141,6 +141,7 @@ int Request::prepare()\n>  \n>  \tfor (auto const &pair : bufferMap_) {\n>  \t\tBuffer *buffer = pair.second;\n> +\t\tbuffer->setRequest(this);\n>  \t\tpending_.insert(buffer);\n>  \t}\n>  \n> @@ -177,6 +178,8 @@ bool Request::completeBuffer(Buffer *buffer)\n>  \tint ret = pending_.erase(buffer);\n>  \tASSERT(ret == 1);\n>  \n> +\tbuffer->setRequest(nullptr);\n> +\n>  \treturn !hasPendingBuffers();\n>  }\n>  \n> -- \n> 2.21.0\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-lf1-x12b.google.com (mail-lf1-x12b.google.com\n\t[IPv6:2a00:1450:4864:20::12b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C7E0460DBF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Apr 2019 17:39:46 +0200 (CEST)","by mail-lf1-x12b.google.com with SMTP id h5so16308626lfm.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Apr 2019 08:39:46 -0700 (PDT)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tr6sm2637543lfp.28.2019.04.17.08.39.45\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tWed, 17 Apr 2019 08:39:45 -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=1RCW5R/LzPEqt7bb1TVapAAAhyoJJSMi8g0e9r9nVaQ=;\n\tb=RnKyyY7q8k2kaTXoHCUVhEwWB+4wMM/6I//I4McFhqLXFkXH18RLu2dpnGHvwmss8t\n\t+XWsOz71cQAQFFM3gzh5ecni/c2QeF+fW9WX/Zme6FzebrFoOAAJXC/1r7WqtQRwD67s\n\texfSAcJtqV4/A+i/qd0ApGu4bbZXXy99ncJCqQjP8bvWKOgW/QhubWAFu30bbg/xDpj2\n\tQaZ/7bvrPwCpAhRXxwqrfY53xusCoJ/sYoE82fAZnx3h5k3QkoGsK/NLiCV7dmdZzK8Y\n\tV+bPjbMHy3vX3mNKQcFEQKdbttLCdMIGDR2r7TjNoc+K/iYqIgTlBMFxTuWkcKXex1B3\n\tPtvw==","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=1RCW5R/LzPEqt7bb1TVapAAAhyoJJSMi8g0e9r9nVaQ=;\n\tb=FujnD4zz7+lNKpXeTRolBo2Zs3MBAszr9ulunfxRccI4AWYH0eu+VhKfDBBosXXqQp\n\tAT7nP1AEw4nIiwFUgaTWeWKpuo2zN4VCzcJhhbt1NlukDvMW7efAJFoXbxlhw00AwA6W\n\tUkrHhzNqGNL27/rpXMMK1IxJvWwHqw3WE56pv24YAnXeGJAlj0Az00zTTshy5sv7fLV0\n\trRaPLm3pe1rWE5BV1B3q0CxHrI2YWqeC2gyzZsmwnE3DylAbrTsTvrRewW9YuBtZDHXL\n\tVlILEo7uqEhlx6AoGTlbejV7J229tHPbuZXphgq1CRGriqvRvJW70Zexi4TUqpiJERR+\n\toVgQ==","X-Gm-Message-State":"APjAAAU7S5YElajJrLmTzcgoMUHgKqz+ja6oNxecjKxwirk6fKDSaelF\n\tCO+9qmaDmtuEYoQD0L6I7CbvXw==","X-Google-Smtp-Source":"APXvYqzcpY99uxQngwBQIZLQXCLnbunMMhdrIag5npFv4zHaZhKPGHvurTyLjiatZeJ3i6AOOBCSrw==","X-Received":"by 2002:ac2:4119:: with SMTP id\n\tb25mr29593181lfi.72.1555515586122; \n\tWed, 17 Apr 2019 08:39:46 -0700 (PDT)","Date":"Wed, 17 Apr 2019 17:39:44 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190417153944.GO28515@bigcity.dyn.berto.se>","References":"<20190417135858.23914-1-jacopo@jmondi.org>\n\t<20190417135858.23914-9-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190417135858.23914-9-jacopo@jmondi.org>","User-Agent":"Mutt/1.11.3 (2019-02-01)","Subject":"Re: [libcamera-devel] [PATCH v7 8/8] libcamera: buffer: Store\n\tRequest reference in Buffer","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":"Wed, 17 Apr 2019 15:39:47 -0000"}},{"id":1449,"web_url":"https://patchwork.libcamera.org/comment/1449/","msgid":"<20190418130535.GP4806@pendragon.ideasonboard.com>","date":"2019-04-18T13:05:35","subject":"Re: [libcamera-devel] [PATCH v7 8/8] libcamera: buffer: Store\n\tRequest reference in Buffer","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, Apr 17, 2019 at 03:58:58PM +0200, Jacopo Mondi wrote:\n> Add to the Buffer class methods to set and retrieve a reference to the\n> Request instance the buffer is part of.\n> \n> As buffers might outlive the Request they are associated with, the\n\ns/might //\n\n> reference is only temporary valid during the buffer completion interval\n> (from when the buffer gets queued to Camera for processing, until it\n> gets marked as completed).\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  include/libcamera/buffer.h |  6 ++++++\n>  src/libcamera/buffer.cpp   | 25 ++++++++++++++++++++++++-\n>  src/libcamera/request.cpp  |  3 +++\n>  3 files changed, 33 insertions(+), 1 deletion(-)\n> \n> diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h\n> index 0c844d126a27..8f9b42e39339 100644\n> --- a/include/libcamera/buffer.h\n> +++ b/include/libcamera/buffer.h\n> @@ -13,6 +13,7 @@\n>  namespace libcamera {\n>  \n>  class BufferPool;\n> +class Request;\n>  \n>  class Plane final\n>  {\n> @@ -52,14 +53,18 @@ public:\n>  \tunsigned int sequence() const { return sequence_; }\n>  \tStatus status() const { return status_; }\n>  \tstd::vector<Plane> &planes() { return planes_; }\n> +\tRequest *request() const { return request_; }\n>  \n>  private:\n>  \tfriend class BufferPool;\n>  \tfriend class PipelineHandler;\n> +\tfriend class Request;\n>  \tfriend class V4L2Device;\n>  \n>  \tvoid cancel();\n>  \n> +\tvoid setRequest(Request *request) { request_ = request; }\n> +\n>  \tunsigned int index_;\n>  \tunsigned int bytesused_;\n>  \tuint64_t timestamp_;\n> @@ -67,6 +72,7 @@ private:\n>  \tStatus status_;\n>  \n>  \tstd::vector<Plane> planes_;\n> +\tRequest *request_;\n>  };\n>  \n>  class BufferPool final\n> diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp\n> index e2d1cf04411e..8261ca41d62e 100644\n> --- a/src/libcamera/buffer.cpp\n> +++ b/src/libcamera/buffer.cpp\n> @@ -196,7 +196,7 @@ void *Plane::mem()\n>   */\n>  \n>  Buffer::Buffer()\n> -\t: index_(-1)\n> +\t: index_(-1), request_(nullptr)\n>  {\n>  }\n>  \n> @@ -248,6 +248,22 @@ Buffer::Buffer()\n>   * \\return The buffer status\n>   */\n>  \n> +/**\n> + * \\fn Buffer::request()\n> + * \\brief Retrieve the request this buffer belongs to\n> + *\n> + * The intended callers of this method are buffer completion handlers that\n> + * needs to associate a buffer to the request it belongs to.\n\ns/needs/need/\n\nWith this fixed,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> + *\n> + * A Buffer is associated to a request by Request::prepare() and the\n> + * association is valid until the buffer completes. The returned request\n> + * pointer is valid only during that interval.\n> + *\n> + * \\return The Request the Buffer belongs to, or nullptr if the buffer is\n> + * either completed or not associated with a request\n> + * \\sa Buffer::setRequest()\n> + */\n> +\n>  /**\n>   * \\brief Mark a buffer as cancel by setting its status to BufferCancelled\n>   */\n> @@ -259,6 +275,13 @@ void Buffer::cancel()\n>  \tstatus_ = BufferCancelled;\n>  }\n>  \n> +/**\n> + * \\fn Buffer::setRequest()\n> + * \\brief Set the request this buffer belongs to\n> + *\n> + * The intended callers are Request::prepare() and Request::completeBuffer().\n> + */\n> +\n>  /**\n>   * \\class BufferPool\n>   * \\brief A pool of buffers\n> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\n> index b215366baa7c..290175f876b4 100644\n> --- a/src/libcamera/request.cpp\n> +++ b/src/libcamera/request.cpp\n> @@ -141,6 +141,7 @@ int Request::prepare()\n>  \n>  \tfor (auto const &pair : bufferMap_) {\n>  \t\tBuffer *buffer = pair.second;\n> +\t\tbuffer->setRequest(this);\n>  \t\tpending_.insert(buffer);\n>  \t}\n>  \n> @@ -177,6 +178,8 @@ bool Request::completeBuffer(Buffer *buffer)\n>  \tint ret = pending_.erase(buffer);\n>  \tASSERT(ret == 1);\n>  \n> +\tbuffer->setRequest(nullptr);\n> +\n>  \treturn !hasPendingBuffers();\n>  }\n>","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8757F60DC0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Apr 2019 15:05:44 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C0D59333;\n\tThu, 18 Apr 2019 15:05:43 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1555592744;\n\tbh=7A8ekQ9W5pRz5nrfSngH7aUSC5i8mgqv2kOGmX0/woo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ttDCJrYg7AS6JvR4VaOcHQLqtQrHvuFFknhCV6gesXAUCpDkgZGXqALSV3au1XgBN\n\tm7hie3+5TboDVJHYcwRyHOrfdiyVZBEybzXNNXIbI1c4RYxmM2k40VvJHE1DPoHkXG\n\tdbmO0k87Hp7U3TGTrz9Iuf78PQYFSk2trjEM6LB0=","Date":"Thu, 18 Apr 2019 16:05:35 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190418130535.GP4806@pendragon.ideasonboard.com>","References":"<20190417135858.23914-1-jacopo@jmondi.org>\n\t<20190417135858.23914-9-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190417135858.23914-9-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v7 8/8] libcamera: buffer: Store\n\tRequest reference in Buffer","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":"Thu, 18 Apr 2019 13:05:44 -0000"}}]