[{"id":1336,"web_url":"https://patchwork.libcamera.org/comment/1336/","msgid":"<20190414202613.GN1980@bigcity.dyn.berto.se>","date":"2019-04-14T20:26:13","subject":"Re: [libcamera-devel] [PATCH v4 09/12] 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-09 21:25:45 +0200, Jacopo Mondi wrote:\n> Add to the Buffer class methods to set and retrieve a reference to the\n> Request instance this buffer is part of.\n> \n> As Buffers might outlive the Request they are associated with, the\n> reference is only temporarly valid during the buffer completion interval\n> (since when the buffer gets queued to Camera for processing, until it\n> gets marked as completed).\n\nI do not like this as the new functions are visible both to applications \nand pipeline handlers where we really should make the API fool proof.  \nLooking a head in the series I do not like how this is used neither.\n\nSomething like this might be needed depending on outcome of discussions\nlater patches in this series. The patch itself is proper and if I agreed \nthat it was needed and/or that the usage of it later I would have \nattached by tag. For now I'm withholding it pending discussion.\n\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  include/libcamera/buffer.h |  5 +++++\n>  src/libcamera/buffer.cpp   | 39 +++++++++++++++++++++++++++++++++++++-\n>  src/libcamera/request.cpp  |  4 ++++\n>  3 files changed, 47 insertions(+), 1 deletion(-)\n> \n> diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h\n> index 0c844d126a27..10c46cd57ab0 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> @@ -53,6 +54,9 @@ public:\n>  \tStatus status() const { return status_; }\n>  \tstd::vector<Plane> &planes() { return planes_; }\n>  \n> +\tvoid setRequest(Request *req) { request_ = req; }\n> +\tRequest *request() const { return request_; }\n> +\n>  private:\n>  \tfriend class BufferPool;\n>  \tfriend class PipelineHandler;\n> @@ -67,6 +71,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..68738b733ba6 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,43 @@ Buffer::Buffer()\n>   * \\return The buffer status\n>   */\n>  \n> +/**\n> + * \\fn Buffer::setRequest()\n> + * \\brief Set the request this buffer belongs to\n> + *\n> + * Buffers are associated to Streams in a Request, which is then sent to the\n> + * Camera for processing. This method stores in the Buffer a pointer to the\n> + * Request this Buffer is part of, for later retrieval through the\n> + * Buffer::request() method.\n> + *\n> + * Buffers are associated to requests at Request::prepare() time and said\n> + * association is valid until the buffer does not complete at\n> + * Request::completeBuffer() time. Before and after the buffer completion\n> + * interval (the time between when the request is queued to the Camera, and\n> + * the buffer is marked as 'complete' by pipeline handlers) the reference to\n> + * Request is set to nullptr.\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 slots\n> + * implemented in CameraData sub-classes which needs to associated a request\n> + * to the just completed buffer, before calling Request::completeBuffer().\n> + *\n> + * It is up to the caller of this function to deal with the case the buffer has\n> + * been already marked as complete, and the reference to the Request has been\n> + * invalidated and set to nullptr.\n> + *\n> + * See also Buffer::setRequest() for a more detailed explanation of the\n> + * validity interval of the Request reference contained in a Buffer.\n> + *\n> + * \\return The Request this Buffer belongs to or nullptr if the Buffer has\n> + * not been queued to the Camera for processing yet or it has completed already.\n> + * \\sa Buffer::setRequest()\n> + */\n> +\n>  /**\n>   * \\brief Mark a buffer as cancel by setting its status to BufferCancelled\n>   */\n> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\n> index 3e10c995a6fa..7d80c635fa92 100644\n> --- a/src/libcamera/request.cpp\n> +++ b/src/libcamera/request.cpp\n> @@ -130,6 +130,8 @@ int Request::prepare()\n>  {\n>  \tfor (auto const &pair : bufferMap_) {\n>  \t\tBuffer *buffer = pair.second;\n> +\n> +\t\tbuffer->setRequest(this);\n>  \t\tpending_.insert(buffer);\n>  \t}\n>  \n> @@ -166,6 +168,8 @@ bool Request::completeBuffer(Buffer *buffer)\n>  \tint ret = pending_.erase(buffer);\n>  \tASSERT(ret == 1);\n>  \n> +\tbuffer->setRequest(nullptr);\n> +\n>  \treturn empty();\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-lj1-x22f.google.com (mail-lj1-x22f.google.com\n\t[IPv6:2a00:1450:4864:20::22f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F54860DBE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 14 Apr 2019 22:26:15 +0200 (CEST)","by mail-lj1-x22f.google.com with SMTP id f18so13644206lja.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 14 Apr 2019 13:26:15 -0700 (PDT)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\to3sm9666238lfd.53.2019.04.14.13.26.13\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tSun, 14 Apr 2019 13:26:13 -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=BA41sLm8FLyB1NUP5fDMVRxSWxchwEZ9zJS90EnOwVc=;\n\tb=CSoBJ6Odhd+aONOJo2EYDqvq0DWOUYfi2ElHw9TrsOaprARN4OK88B/gM/HGXkLM1b\n\t6ke7FfK+dyvLNRY0pIRNtiVXHChaS7nnZ3WX0T9FeMEdsKWvobLxM2GZrloGQmHwLO91\n\tby4LYhZ4amjrTY64tGMZQfitMx9XkG26x8FqXo8WguSi+WJbmoayJmJl4duFLUpUM3CX\n\ttJyUXEEcYs4hNOGASchZq21N30x3gON5UBBN3K8E4wPQVEm4jfQeV+ks+vfwwa6HDuJg\n\teMFGjRAuZ473iWPXKdv79MbiRuzjR2ca7385Q8eCggQmg1jv8uLa+MS5Muvvre6Cah/2\n\t6t+A==","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=BA41sLm8FLyB1NUP5fDMVRxSWxchwEZ9zJS90EnOwVc=;\n\tb=l5LPFe+jKcBm7gh9KJa7tqpp+FK/5uj1kRlikbavZ82FN/0YbRCuStrfeIPqGVcIbb\n\tNRx3azWdn8aSvOL8VJM5Y2dQZavX6bYxzti+iY+AO7Dynrx1qSVWEQ8TYPx+uXvguDdy\n\tXCpm9Y5rtR39fRuGJr5s35HLn060LaQPvyQ7xkTeCBTMkgDR6P4r9fF6PeNO9P3sQN/+\n\toaDE5npBS3p6O74EKM2lN/sAh1MZeY84FyuTBTSYuv4Uh9EC7sBmBLeRjjN0tjHjRuRD\n\t60AyivSvBGxKzrJms9I99FwpbV85tQgaPsE2sz9Wt9y5dQR1J0O5uWn8vRUSLcDPqnQR\n\tCR2w==","X-Gm-Message-State":"APjAAAXctM26N1sH8tleTVyXquQ51fsy6clqfPj68RpbUNfWWL3lhTwl\n\tjQyaJBMuLT9EFZu7PWkR1KtHGnc75j0=","X-Google-Smtp-Source":"APXvYqw0YS8hl+FbUAj4c6VzhW+/+wwgoxxNSVf9bGGbhGwHRz9hpcZhjtVmceOeZU3jEwCEEbKPpQ==","X-Received":"by 2002:a2e:2e04:: with SMTP id u4mr27534413lju.37.1555273574850;\n\tSun, 14 Apr 2019 13:26:14 -0700 (PDT)","Date":"Sun, 14 Apr 2019 22:26:13 +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":"<20190414202613.GN1980@bigcity.dyn.berto.se>","References":"<20190409192548.20325-1-jacopo@jmondi.org>\n\t<20190409192548.20325-10-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":"<20190409192548.20325-10-jacopo@jmondi.org>","User-Agent":"Mutt/1.11.3 (2019-02-01)","Subject":"Re: [libcamera-devel] [PATCH v4 09/12] 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":"Sun, 14 Apr 2019 20:26:15 -0000"}}]