From patchwork Fri Jul 21 09:37:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18861 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 7CEF8BDC71 for ; Fri, 21 Jul 2023 09:38:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2F9CF628BD; Fri, 21 Jul 2023 11:38:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1689932285; bh=3CbGSLrQmTwZnhFjxxJdZwHpkN2gVzhIXN1IK7P3A70=; 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=pDhgGCCgY97rBf2PWOgADBx+KeqyWfImWae2C+slnvBO2hiNxvNKzRB9cWwKGMSET DsE6gHE7pppZoPpj+H5lDd6MKa8rihmRNBpJlrC6k+TTADILI1DdtGZsDPf/toucFN 68CEXyW08ArQF2D2QklURletiM3bV4GOlwpta1+nX2Nca9Pcpks81HGjnY2aq32Sio HMbpsMCVRVmN3OCvGd/HDbkWYLTPSmB22+e+idIv3uKUPi/ItohA7vzllYAPpTe6Ix lF7qTxKACgqNUmiWE3psWV4nA6pNEUB1YTZKi+yZKVoJhGZgJzMZ1Y4m51ncIhG/7u yse+0R8/AAiJQ== Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5868B628C4 for ; Fri, 21 Jul 2023 11:38:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="mqRKKbGB"; dkim-atps=neutral Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3141fa31c2bso1280390f8f.2 for ; Fri, 21 Jul 2023 02:38:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1689932280; x=1690537080; 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=DXvCa+21v7+8EeLNesmlzeQop9M4JkysDUnJt+FZOOI=; b=mqRKKbGB4v543xessxaFNytREX8e9lWKGA1XiDFMuG8atuH+2AMxmIS+5uiU0Pv0ef bhRkH5oGfmoDICP0sSyv5toGZ3BYXjWpp2CYoQTFlp/wyviSUP4RjGkMyHYGLxDKcaeF yHc/BcKX3CT1clgJfbvrsA2BYDsDQWvxfaS8qWwFq54Ho624+q9TCZ2lvZgDfW8ITiy/ vYKS6etFlPEPtFlLNXyEyjWEvHRvTuFX1GCFmiGficp2KEMIrVEykaXze92NRZ7gRZYm /Y/hoaLl0yeseQskIUOw3jFsjGKptzcsWNyUSjbp/EnNvz+s5BxPSmTDy4G1eVwIwdyY r5WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689932280; x=1690537080; 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=DXvCa+21v7+8EeLNesmlzeQop9M4JkysDUnJt+FZOOI=; b=eiyWIb5shejm41in3N3nafIqs+F5ShwgU3LmmjJv5vKXQdFY+GzHHOEM8GVzPb47Jo wdprtQhkMXnPJ330eVQB/2eKkcXdLN7zZdonaepWFoukoQvCM6sheY0iSR7M15Encl1s DHwk4wL4LGTGXELUSqDAaU6CeaQLbyAK8RIG46LvCN5VhT4YlqBgfD0iNu7Sf/4ig0lL 8i6dBwVJuwTPnfkMP6/90cGA4VjfiitihuVYerc7JaB1OSrXzJa3gu43aaZgIoQ4zZVb euc3gR9FYhoRTBj7MwrKNSkgbMhiPtl+uLr32SAksm3sluDIHeLRuJxaRps/xHsRroaj Ioyg== X-Gm-Message-State: ABy/qLaNULKyRnFPzQypkvtcgeT2GtX3q/fq/xI5k9lNliDEuGT2epYb fZ9eD37bzp4CP7xIJUk0VBB7KpEQweDzgM1yubWANA== X-Google-Smtp-Source: APBJJlElhkt/xCcR8mbw9LEJE6ILFrT0G1U1Bt1jN1UmjrWq7EWnunvPFo0ozCy6ikNXWLFuYBCpxQ== X-Received: by 2002:a5d:4b42:0:b0:315:ade6:a52d with SMTP id w2-20020a5d4b42000000b00315ade6a52dmr944574wrs.19.1689932279768; Fri, 21 Jul 2023 02:37:59 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id n12-20020a5d6b8c000000b003143c6e09ccsm3674663wrx.16.2023.07.21.02.37.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 02:37:59 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 21 Jul 2023 10:37:59 +0100 Message-Id: <20230721093759.27700-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230721093759.27700-1-naush@raspberrypi.com> References: <20230721093759.27700-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 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 --- .../pipeline/rpi/common/rpi_stream.cpp | 9 ++-- .../pipeline/rpi/common/rpi_stream.h | 42 +------------------ 2 files changed, 5 insertions(+), 46 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp index e24531e171c8..d32163d3fc0f 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..cc5d3f4afad4 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.h +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h @@ -60,7 +60,7 @@ public: 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_;