[{"id":27620,"web_url":"https://patchwork.libcamera.org/comment/27620/","msgid":"<r4sicdykcgk4i7ibqkglvqi7f422vb5i73w76r3dbgfawmxtud@qkjalxunmgby>","date":"2023-07-27T09:34:35","subject":"Re: [libcamera-devel] [PATCH v2 4/4] pipeline: rpi: Simplify buffer\n\tid generation","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Naush\n\nOn Tue, Jul 25, 2023 at 09:55:40AM +0100, Naushir Patuck via libcamera-devel wrote:\n> Replace the buffer id generation in RPi::Stream with a simple integer\n> counter since ids don't get recycled any more.\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n\nLooks good!\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nThanks\n  j\n\n> ---\n>  .../pipeline/rpi/common/rpi_stream.cpp        |  9 ++--\n>  .../pipeline/rpi/common/rpi_stream.h          | 44 ++-----------------\n>  2 files changed, 6 insertions(+), 47 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> index e1858c731f57..d1310635c091 100644\n> --- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> @@ -53,7 +53,7 @@ void Stream::resetBuffers()\n>  void Stream::setExportedBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n>  {\n>  \tfor (auto const &buffer : *buffers)\n> -\t\tbufferMap_.emplace(id_.get(), buffer.get());\n> +\t\tbufferMap_.emplace(++id_, buffer.get());\n>  }\n>\n>  const BufferMap &Stream::getBuffers() const\n> @@ -78,7 +78,7 @@ unsigned int Stream::getBufferId(FrameBuffer *buffer) const\n>\n>  void Stream::setExportedBuffer(FrameBuffer *buffer)\n>  {\n> -\tbufferMap_.emplace(id_.get(), buffer);\n> +\tbufferMap_.emplace(++id_, buffer);\n>  }\n>\n>  int Stream::prepareBuffers(unsigned int count)\n> @@ -149,9 +149,6 @@ void Stream::returnBuffer(FrameBuffer *buffer)\n>  \t/* Push this buffer back into the queue to be used again. */\n>  \tavailableBuffers_.push(buffer);\n>\n> -\t/* Allow the buffer id to be reused. */\n> -\tid_.release(getBufferId(buffer));\n> -\n>  \t/*\n>  \t * Do we have any Request buffers that are waiting to be queued?\n>  \t * If so, do it now as availableBuffers_ will not be empty.\n> @@ -210,7 +207,7 @@ void Stream::clearBuffers()\n>  \trequestBuffers_ = std::queue<FrameBuffer *>{};\n>  \tinternalBuffers_.clear();\n>  \tbufferMap_.clear();\n> -\tid_.reset();\n> +\tid_ = 0;\n>  }\n>\n>  int Stream::queueToDevice(FrameBuffer *buffer)\n> diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h\n> index d1289c4679b9..889b499782a4 100644\n> --- a/src/libcamera/pipeline/rpi/common/rpi_stream.h\n> +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h\n> @@ -54,13 +54,13 @@ public:\n>  \tusing StreamFlags = Flags<StreamFlag>;\n>\n>  \tStream()\n> -\t\t: flags_(StreamFlag::None), id_(BufferMask::MaskID)\n> +\t\t: flags_(StreamFlag::None), id_(0)\n>  \t{\n>  \t}\n>\n>  \tStream(const char *name, MediaEntity *dev, StreamFlags flags = StreamFlag::None)\n>  \t\t: flags_(flags), name_(name),\n> -\t\t  dev_(std::make_unique<V4L2VideoDevice>(dev)), id_(BufferMask::MaskID)\n> +\t\t  dev_(std::make_unique<V4L2VideoDevice>(dev)), id_(0)\n>  \t{\n>  \t}\n>\n> @@ -86,44 +86,6 @@ public:\n>  \tvoid releaseBuffers();\n>\n>  private:\n> -\tclass IdGenerator\n> -\t{\n> -\tpublic:\n> -\t\tIdGenerator(unsigned int max)\n> -\t\t\t: max_(max), id_(0)\n> -\t\t{\n> -\t\t}\n> -\n> -\t\tunsigned int get()\n> -\t\t{\n> -\t\t\tunsigned int id;\n> -\t\t\tif (!recycle_.empty()) {\n> -\t\t\t\tid = recycle_.front();\n> -\t\t\t\trecycle_.pop();\n> -\t\t\t} else {\n> -\t\t\t\tid = ++id_;\n> -\t\t\t\tASSERT(id_ <= max_);\n> -\t\t\t}\n> -\t\t\treturn id;\n> -\t\t}\n> -\n> -\t\tvoid release(unsigned int id)\n> -\t\t{\n> -\t\t\trecycle_.push(id);\n> -\t\t}\n> -\n> -\t\tvoid reset()\n> -\t\t{\n> -\t\t\tid_ = 0;\n> -\t\t\trecycle_ = {};\n> -\t\t}\n> -\n> -\tprivate:\n> -\t\tunsigned int max_;\n> -\t\tunsigned int id_;\n> -\t\tstd::queue<unsigned int> recycle_;\n> -\t};\n> -\n>  \tvoid clearBuffers();\n>  \tint queueToDevice(FrameBuffer *buffer);\n>\n> @@ -136,7 +98,7 @@ private:\n>  \tstd::unique_ptr<V4L2VideoDevice> dev_;\n>\n>  \t/* Tracks a unique id key for the bufferMap_ */\n> -\tIdGenerator id_;\n> +\tunsigned int id_;\n>\n>  \t/* All frame buffers associated with this device stream. */\n>  \tBufferMap bufferMap_;\n> --\n> 2.34.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 40477BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 27 Jul 2023 09:34:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E9876628C1;\n\tThu, 27 Jul 2023 11:34:44 +0200 (CEST)","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 3F183628BC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Jul 2023 11:34:43 +0200 (CEST)","from ideasonboard.com (mob-5-91-19-250.net.vodafone.it\n\t[5.91.19.250])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2E0CC4A9;\n\tThu, 27 Jul 2023 11:33:42 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1690450484;\n\tbh=ng/TOfDO2DX7jjdDY0MZWOIYzJqysxuWYMnekx7ntOc=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=EtC7BoD1Ic7CyfYVPHGw/BcMw6pudqKTGXjKwYnJ2GcCNpoVhttUa8HzV0ybCkObD\n\tGRzJwpsL+zA1x9nohCw81GIHORrN5qJzC3NYcx56StUWqHMNEW/NZS+ekr/a8XV5OR\n\tn/0nNR+03VixRLMfR0VbkkGMUi1Vfyvkbn+LRUkCSwta/B1MbW8E+w4Z9DGWUDBtqf\n\t8KfrCwYvDK4Kyg3eHwq9Ssau5CTqcJFa6uUHlVsjoXXeAM2oZzIeFkfwqZyEslWdfZ\n\t6KaK2HGEtx3BiJLgKn9ZtUB7riBHBLiiz/hMLE7gEFA+meOUKVOlfdN9VGFiP9nAky\n\t4l4tl5JulyOAA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1690450423;\n\tbh=ng/TOfDO2DX7jjdDY0MZWOIYzJqysxuWYMnekx7ntOc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=oDuWrP0jsf71BBNIJGAC+pDsWUi2R32doeA2RmiMXXfdVIl+p56SkEPleH5+WBCbH\n\taOBa626Ye6IvJJMbrtc9YGqaNS+FYROqzbLU0nUCimbSn8ufOpBI+1l+QAGViSScs0\n\t7RbaMDQG0yUsh25XbNQzlj1TwpEj8iGYTwTJbZZI="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"oDuWrP0j\"; dkim-atps=neutral","Date":"Thu, 27 Jul 2023 11:34:35 +0200","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<r4sicdykcgk4i7ibqkglvqi7f422vb5i73w76r3dbgfawmxtud@qkjalxunmgby>","References":"<20230725085540.24863-1-naush@raspberrypi.com>\n\t<20230725085540.24863-5-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230725085540.24863-5-naush@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v2 4/4] pipeline: rpi: Simplify buffer\n\tid generation","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27728,"web_url":"https://patchwork.libcamera.org/comment/27728/","msgid":"<169382233522.277971.13237256071364819047@ping.linuxembedded.co.uk>","date":"2023-09-04T10:12:15","subject":"Re: [libcamera-devel] [PATCH v2 4/4] pipeline: rpi: Simplify buffer\n\tid generation","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck via libcamera-devel (2023-07-25 09:55:40)\n> Replace the buffer id generation in RPi::Stream with a simple integer\n> counter since ids don't get recycled any more.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  .../pipeline/rpi/common/rpi_stream.cpp        |  9 ++--\n>  .../pipeline/rpi/common/rpi_stream.h          | 44 ++-----------------\n\nDiffstat looks like a win!\n\nThere are no bugs in code that doesn't exist, right? ;-)\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n>  2 files changed, 6 insertions(+), 47 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> index e1858c731f57..d1310635c091 100644\n> --- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> @@ -53,7 +53,7 @@ void Stream::resetBuffers()\n>  void Stream::setExportedBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n>  {\n>         for (auto const &buffer : *buffers)\n> -               bufferMap_.emplace(id_.get(), buffer.get());\n> +               bufferMap_.emplace(++id_, buffer.get());\n>  }\n>  \n>  const BufferMap &Stream::getBuffers() const\n> @@ -78,7 +78,7 @@ unsigned int Stream::getBufferId(FrameBuffer *buffer) const\n>  \n>  void Stream::setExportedBuffer(FrameBuffer *buffer)\n>  {\n> -       bufferMap_.emplace(id_.get(), buffer);\n> +       bufferMap_.emplace(++id_, buffer);\n>  }\n>  \n>  int Stream::prepareBuffers(unsigned int count)\n> @@ -149,9 +149,6 @@ void Stream::returnBuffer(FrameBuffer *buffer)\n>         /* Push this buffer back into the queue to be used again. */\n>         availableBuffers_.push(buffer);\n>  \n> -       /* Allow the buffer id to be reused. */\n> -       id_.release(getBufferId(buffer));\n> -\n>         /*\n>          * Do we have any Request buffers that are waiting to be queued?\n>          * If so, do it now as availableBuffers_ will not be empty.\n> @@ -210,7 +207,7 @@ void Stream::clearBuffers()\n>         requestBuffers_ = std::queue<FrameBuffer *>{};\n>         internalBuffers_.clear();\n>         bufferMap_.clear();\n> -       id_.reset();\n> +       id_ = 0;\n>  }\n>  \n>  int Stream::queueToDevice(FrameBuffer *buffer)\n> diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h\n> index d1289c4679b9..889b499782a4 100644\n> --- a/src/libcamera/pipeline/rpi/common/rpi_stream.h\n> +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h\n> @@ -54,13 +54,13 @@ public:\n>         using StreamFlags = Flags<StreamFlag>;\n>  \n>         Stream()\n> -               : flags_(StreamFlag::None), id_(BufferMask::MaskID)\n> +               : flags_(StreamFlag::None), id_(0)\n>         {\n>         }\n>  \n>         Stream(const char *name, MediaEntity *dev, StreamFlags flags = StreamFlag::None)\n>                 : flags_(flags), name_(name),\n> -                 dev_(std::make_unique<V4L2VideoDevice>(dev)), id_(BufferMask::MaskID)\n> +                 dev_(std::make_unique<V4L2VideoDevice>(dev)), id_(0)\n>         {\n>         }\n>  \n> @@ -86,44 +86,6 @@ public:\n>         void releaseBuffers();\n>  \n>  private:\n> -       class IdGenerator\n> -       {\n> -       public:\n> -               IdGenerator(unsigned int max)\n> -                       : max_(max), id_(0)\n> -               {\n> -               }\n> -\n> -               unsigned int get()\n> -               {\n> -                       unsigned int id;\n> -                       if (!recycle_.empty()) {\n> -                               id = recycle_.front();\n> -                               recycle_.pop();\n> -                       } else {\n> -                               id = ++id_;\n> -                               ASSERT(id_ <= max_);\n> -                       }\n> -                       return id;\n> -               }\n> -\n> -               void release(unsigned int id)\n> -               {\n> -                       recycle_.push(id);\n> -               }\n> -\n> -               void reset()\n> -               {\n> -                       id_ = 0;\n> -                       recycle_ = {};\n> -               }\n> -\n> -       private:\n> -               unsigned int max_;\n> -               unsigned int id_;\n> -               std::queue<unsigned int> recycle_;\n> -       };\n> -\n>         void clearBuffers();\n>         int queueToDevice(FrameBuffer *buffer);\n>  \n> @@ -136,7 +98,7 @@ private:\n>         std::unique_ptr<V4L2VideoDevice> dev_;\n>  \n>         /* Tracks a unique id key for the bufferMap_ */\n> -       IdGenerator id_;\n> +       unsigned int id_;\n>  \n>         /* All frame buffers associated with this device stream. */\n>         BufferMap bufferMap_;\n> -- \n> 2.34.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 44D12BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  4 Sep 2023 10:12:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 442B3628EB;\n\tMon,  4 Sep 2023 12:12:20 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A2E0628D7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  4 Sep 2023 12:12:19 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net\n\t[82.37.23.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2FE15CCE;\n\tMon,  4 Sep 2023 12:10:53 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1693822340;\n\tbh=huYWlrWBCP9akmfs6ShFZW0I4NZYRas9FP57EKUqEk4=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=pIVKOiEi+KlYYzXvMKE5NNEobVcedhd9BunBWw/F08v1vkRO1xSKuYHi126Duw704\n\tJvhgtPfBU1KucSool7ob7oxgRZjcpfr/y0bWV214r4msGay+xPBUD0wvhKGBV5BUW2\n\tKjP6vH2bkhSvMDJD7CD3n0EgZhS6M6ZXlPYKlRU4VNYjmXYUJGBdHAvPUVXNEuYF1W\n\tmuwNeZMxNikxxCXYlYCmwxCXJf2SvapczjowFWCd/FWbOfIQHOYu92PcKm8GMqiklQ\n\tXCBMeFMZvwkZUVgXc8C0kQ+N29D0TjZjLAJ5ydaJ5O1wY5CW02FNrGyyIKmGKZ3CNw\n\twQ2T+EI6GaiAg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1693822253;\n\tbh=huYWlrWBCP9akmfs6ShFZW0I4NZYRas9FP57EKUqEk4=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=u6D/DPpY6rCV7abcRHwsExSIlg9rmQkMsBcrC3TJ6HNot0Ve1bE+kNsqb3xaKgWn5\n\tIo0yGSxBDXI5fVvO8kT+cGA0iAz/vOMwvv8y/Ealo5JH0PzNGgWDYsm2fgVpSRfSuY\n\tsM3qh/HLLGyJpSYv1bT6WipQdBFADxdq8UbsR8oE="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"u6D/DPpY\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20230725085540.24863-5-naush@raspberrypi.com>","References":"<20230725085540.24863-1-naush@raspberrypi.com>\n\t<20230725085540.24863-5-naush@raspberrypi.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 04 Sep 2023 11:12:15 +0100","Message-ID":"<169382233522.277971.13237256071364819047@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v2 4/4] pipeline: rpi: Simplify buffer\n\tid generation","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]