{"id":18886,"url":"https://patchwork.libcamera.org/api/1.1/patches/18886/?format=json","web_url":"https://patchwork.libcamera.org/patch/18886/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20230725085540.24863-5-naush@raspberrypi.com>","date":"2023-07-25T08:55:40","name":"[libcamera-devel,v2,4/4] pipeline: rpi: Simplify buffer id generation","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"a520b44d50b82cf792fae5114be7f1e60160b476","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18886/mbox/","series":[{"id":3984,"url":"https://patchwork.libcamera.org/api/1.1/series/3984/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3984","date":"2023-07-25T08:55:36","name":"Raspberry Pi: External buffer handling","version":2,"mbox":"https://patchwork.libcamera.org/series/3984/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18886/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18886/checks/","tags":{},"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 9AAADC32AA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 25 Jul 2023 08:56:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2EC92628C3;\n\tTue, 25 Jul 2023 10:56:17 +0200 (CEST)","from mail-wr1-x431.google.com (mail-wr1-x431.google.com\n\t[IPv6:2a00:1450:4864:20::431])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EEA4C628C4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Jul 2023 10:56:10 +0200 (CEST)","by mail-wr1-x431.google.com with SMTP id\n\tffacd0b85a97d-31751d7d96eso1951497f8f.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Jul 2023 01:56:10 -0700 (PDT)","from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tl7-20020adfe587000000b0030c4d8930b1sm1951225wrm.91.2023.07.25.01.56.09\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 25 Jul 2023 01:56:09 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1690275377;\n\tbh=w52ZtUyaSnM/AlMnx815Cq3YiwqKNeCY+/KXe/MWJ3s=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=Lsj06N7WZ7jaTDPbK6hcnTVbIXiHHBxMRqaNxODTxue8E01Nm0NXSVx82LfcrO+PU\n\tCCOkHpVShqaRf0EXzNfCH1pMhhyX8e7nJONQXbhCcLTB0+WRJeoIdq4ycfwa9ppFZh\n\tOKQ8Wu/qqmwQGMUWKfKeJEyqVADJnsM1bFr7mthkzFYueMQiuuK/Yjj3MPAi5hjnid\n\t1QvbGPj1+APKfrNxODHu8BEzVtUZ8+fTuXXUwPEpBCdd0castRV9ZN6eng/HcJAYeo\n\tPxBvWDVQjv+kW5iIVIWGmhKWNvvB2O0x/YbqH3r1ncbesT9Y45DpQ6fvIUQLgcXuWY\n\tjSy28VxrJPljA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1690275370; x=1690880170;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=dzH3CkVjx/MaO3z1Pv7TXEpYfMeVEJrxvRrRlFyI6JY=;\n\tb=n04gQI+ORdyM5ddgdQ/7ZLG+/Qj2MvRv1hbgrhLUrQcyuiXGGcgoyPjQqrAvPpNnHd\n\tHHmrIm8Us4RrTmiY4Eif6CVfNQ37j5EC+leJ6PjI1C+mwIcqV+GR+GRE4LECphjUCKFd\n\tUsBHZWYqa6EOuO1D+d3FtLZFtHPBkRJNn1DC1C++l1ktiSUtsBEa4DmfKbE0VhQ9Z6s3\n\tQhIpp5iTDILUYQFHlOATEDZBpbQvFYdgjkf6NJwZcUsre5GvFf1k0eLdE508QOBk1MNV\n\tiv6FQpp7YOSW7kKge3ZL+wIzUOxoPbUSLAOegWalb3wijwd6/HwnuMIZq8W3os7lO5a2\n\t3/Wg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"n04gQI+O\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1690275370; x=1690880170;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=dzH3CkVjx/MaO3z1Pv7TXEpYfMeVEJrxvRrRlFyI6JY=;\n\tb=MRDlfj6gmjWkr0T7WviAZaD9sczzX8876v3V0XVNhSrbfJIw0ghl1mum/Hal7WM9Oy\n\tyaWNDRVhvyj3HTR1uC2QRgQRFJ60r1aL/mxfqauuvFuBI8etEjPvBjOlGvsqrt2fY0OL\n\tbaediVsPfkXgB2kfaQ2lDp1/sns92BLiWX5TdKu5iTpl2fd7lGii/OV2OeEw8n3Oz0oX\n\tEw+/SKpt345LtwYl3+VKD/fePqa0wxzPghIAg75D2nAQQF1wYs+5U1GesRu0nNcRaaAz\n\tAgMzOhdEl3BhYxL5pveFVG7YGreWupytZnQ+3R2EFvt40A09JFawgCLCF06OtQNhNjoO\n\t8LNQ==","X-Gm-Message-State":"ABy/qLb2Dd2HxPnRFXfpWBVUmkhwOGb1EcRtdvCE9wAL7RTS9y40Ahrq\n\tb+OeJIUfTBZhiZ0ue0gDeHT1McNg7CqkaANW+6XYzA==","X-Google-Smtp-Source":"APBJJlGgoolnbcpiXwFze5KxCb7yyxjvh3je4xVFwCoX2poOzSPXeuPHv1Mbn5EZC3Zg5be/0tH0sA==","X-Received":"by 2002:adf:e64f:0:b0:317:58a8:bb4 with SMTP id\n\tb15-20020adfe64f000000b0031758a80bb4mr4629534wrn.40.1690275370109; \n\tTue, 25 Jul 2023 01:56:10 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 25 Jul 2023 09:55:40 +0100","Message-Id":"<20230725085540.24863-5-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20230725085540.24863-1-naush@raspberrypi.com>","References":"<20230725085540.24863-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 4/4] pipeline: rpi: Simplify buffer id\n\tgeneration","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":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Replace the buffer id generation in RPi::Stream with a simple integer\ncounter since ids don't get recycled any more.\n\nSigned-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 2 files changed, 6 insertions(+), 47 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\nindex 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)\ndiff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h\nindex 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","prefixes":["libcamera-devel","v2","4/4"]}