From patchwork Tue Jul 25 08:55:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18886 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9AAADC32AA for ; Tue, 25 Jul 2023 08:56:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2EC92628C3; Tue, 25 Jul 2023 10:56:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1690275377; bh=w52ZtUyaSnM/AlMnx815Cq3YiwqKNeCY+/KXe/MWJ3s=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Lsj06N7WZ7jaTDPbK6hcnTVbIXiHHBxMRqaNxODTxue8E01Nm0NXSVx82LfcrO+PU CCOkHpVShqaRf0EXzNfCH1pMhhyX8e7nJONQXbhCcLTB0+WRJeoIdq4ycfwa9ppFZh OKQ8Wu/qqmwQGMUWKfKeJEyqVADJnsM1bFr7mthkzFYueMQiuuK/Yjj3MPAi5hjnid 1QvbGPj1+APKfrNxODHu8BEzVtUZ8+fTuXXUwPEpBCdd0castRV9ZN6eng/HcJAYeo PxBvWDVQjv+kW5iIVIWGmhKWNvvB2O0x/YbqH3r1ncbesT9Y45DpQ6fvIUQLgcXuWY jSy28VxrJPljA== Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EEA4C628C4 for ; Tue, 25 Jul 2023 10:56:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="n04gQI+O"; dkim-atps=neutral Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-31751d7d96eso1951497f8f.1 for ; Tue, 25 Jul 2023 01:56:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1690275370; x=1690880170; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dzH3CkVjx/MaO3z1Pv7TXEpYfMeVEJrxvRrRlFyI6JY=; b=n04gQI+ORdyM5ddgdQ/7ZLG+/Qj2MvRv1hbgrhLUrQcyuiXGGcgoyPjQqrAvPpNnHd HHmrIm8Us4RrTmiY4Eif6CVfNQ37j5EC+leJ6PjI1C+mwIcqV+GR+GRE4LECphjUCKFd UsBHZWYqa6EOuO1D+d3FtLZFtHPBkRJNn1DC1C++l1ktiSUtsBEa4DmfKbE0VhQ9Z6s3 QhIpp5iTDILUYQFHlOATEDZBpbQvFYdgjkf6NJwZcUsre5GvFf1k0eLdE508QOBk1MNV iv6FQpp7YOSW7kKge3ZL+wIzUOxoPbUSLAOegWalb3wijwd6/HwnuMIZq8W3os7lO5a2 3/Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690275370; x=1690880170; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dzH3CkVjx/MaO3z1Pv7TXEpYfMeVEJrxvRrRlFyI6JY=; b=MRDlfj6gmjWkr0T7WviAZaD9sczzX8876v3V0XVNhSrbfJIw0ghl1mum/Hal7WM9Oy yaWNDRVhvyj3HTR1uC2QRgQRFJ60r1aL/mxfqauuvFuBI8etEjPvBjOlGvsqrt2fY0OL baediVsPfkXgB2kfaQ2lDp1/sns92BLiWX5TdKu5iTpl2fd7lGii/OV2OeEw8n3Oz0oX Ew+/SKpt345LtwYl3+VKD/fePqa0wxzPghIAg75D2nAQQF1wYs+5U1GesRu0nNcRaaAz AgMzOhdEl3BhYxL5pveFVG7YGreWupytZnQ+3R2EFvt40A09JFawgCLCF06OtQNhNjoO 8LNQ== X-Gm-Message-State: ABy/qLb2Dd2HxPnRFXfpWBVUmkhwOGb1EcRtdvCE9wAL7RTS9y40Ahrq b+OeJIUfTBZhiZ0ue0gDeHT1McNg7CqkaANW+6XYzA== X-Google-Smtp-Source: APBJJlGgoolnbcpiXwFze5KxCb7yyxjvh3je4xVFwCoX2poOzSPXeuPHv1Mbn5EZC3Zg5be/0tH0sA== X-Received: by 2002:adf:e64f:0:b0:317:58a8:bb4 with SMTP id b15-20020adfe64f000000b0031758a80bb4mr4629534wrn.40.1690275370109; Tue, 25 Jul 2023 01:56:10 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id l7-20020adfe587000000b0030c4d8930b1sm1951225wrm.91.2023.07.25.01.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 01:56:09 -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 Subject: [libcamera-devel] [PATCH v2 4/4] pipeline: rpi: Simplify buffer id generation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace the buffer id generation in RPi::Stream with a simple integer counter since ids don't get recycled any more. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- .../pipeline/rpi/common/rpi_stream.cpp | 9 ++-- .../pipeline/rpi/common/rpi_stream.h | 44 ++----------------- 2 files changed, 6 insertions(+), 47 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp index e1858c731f57..d1310635c091 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp @@ -53,7 +53,7 @@ void Stream::resetBuffers() void Stream::setExportedBuffers(std::vector> *buffers) { for (auto const &buffer : *buffers) - bufferMap_.emplace(id_.get(), buffer.get()); + bufferMap_.emplace(++id_, buffer.get()); } const BufferMap &Stream::getBuffers() const @@ -78,7 +78,7 @@ unsigned int Stream::getBufferId(FrameBuffer *buffer) const void Stream::setExportedBuffer(FrameBuffer *buffer) { - bufferMap_.emplace(id_.get(), buffer); + bufferMap_.emplace(++id_, buffer); } int Stream::prepareBuffers(unsigned int count) @@ -149,9 +149,6 @@ void Stream::returnBuffer(FrameBuffer *buffer) /* Push this buffer back into the queue to be used again. */ availableBuffers_.push(buffer); - /* Allow the buffer id to be reused. */ - id_.release(getBufferId(buffer)); - /* * Do we have any Request buffers that are waiting to be queued? * If so, do it now as availableBuffers_ will not be empty. @@ -210,7 +207,7 @@ void Stream::clearBuffers() requestBuffers_ = std::queue{}; internalBuffers_.clear(); bufferMap_.clear(); - id_.reset(); + id_ = 0; } int Stream::queueToDevice(FrameBuffer *buffer) diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h index d1289c4679b9..889b499782a4 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.h +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h @@ -54,13 +54,13 @@ public: using StreamFlags = Flags; Stream() - : flags_(StreamFlag::None), id_(BufferMask::MaskID) + : flags_(StreamFlag::None), id_(0) { } Stream(const char *name, MediaEntity *dev, StreamFlags flags = StreamFlag::None) : flags_(flags), name_(name), - dev_(std::make_unique(dev)), id_(BufferMask::MaskID) + dev_(std::make_unique(dev)), id_(0) { } @@ -86,44 +86,6 @@ public: void releaseBuffers(); private: - class IdGenerator - { - public: - IdGenerator(unsigned int max) - : max_(max), id_(0) - { - } - - unsigned int get() - { - unsigned int id; - if (!recycle_.empty()) { - id = recycle_.front(); - recycle_.pop(); - } else { - id = ++id_; - ASSERT(id_ <= max_); - } - return id; - } - - void release(unsigned int id) - { - recycle_.push(id); - } - - void reset() - { - id_ = 0; - recycle_ = {}; - } - - private: - unsigned int max_; - unsigned int id_; - std::queue recycle_; - }; - void clearBuffers(); int queueToDevice(FrameBuffer *buffer); @@ -136,7 +98,7 @@ private: std::unique_ptr dev_; /* Tracks a unique id key for the bufferMap_ */ - IdGenerator id_; + unsigned int id_; /* All frame buffers associated with this device stream. */ BufferMap bufferMap_;