From patchwork Mon Jul 13 08:47:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 8759 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 B12BEBDB1C for ; Mon, 13 Jul 2020 08:48:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7F45A605B4; Mon, 13 Jul 2020 10:48:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="i6Rw1VbW"; dkim-atps=neutral Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 57D60605B4 for ; Mon, 13 Jul 2020 10:48:07 +0200 (CEST) Received: by mail-wm1-x32a.google.com with SMTP id q15so12483576wmj.2 for ; Mon, 13 Jul 2020 01:48:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=by0PDKAUD7j60C7WR+Teh6crYrQuh/f0Gxq6tC3Qaks=; b=i6Rw1VbWKAjivS5YZ3X240LGgVOdr8qknqaJ3goISljbo+liLMSV7eN5SeaJeG6nwa qaizeHjdlOMM54RpZnTGHE/fk2dh6FJhEkqXcWga4FUg2AzSuKUVodju4Y5v7F183giW TSBGd80naUzkWOvXz5Cy0OilKa8qNZDDWBuo85GfD2Z1QoodykV6VFsH2RYeG3417SRD 2SvrE129hqDuWFay2xe2yzUEvGPmxfuCn5p+UGcrGo/wcuJTQRJY9AQXDGVK4yJhyqWJ InJyvrkx4kAYZF4jJrokYYpbXg4LzekM0CSGu2+vEvt0SKJe5y/UYk1xaGJ0RrjpLqyj BcOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=by0PDKAUD7j60C7WR+Teh6crYrQuh/f0Gxq6tC3Qaks=; b=q5CQj8M9/q8KeGP58TkBuObNC0QMY80iP+Pq2rIrkePdDmB2TFsmtoJn9s8mvQyCEQ JMaQM6Zehn6k4AnTOUb0gZsGHbKEzSxFAMeSCgPaIDMuG9lQEuYs8Cy30D8wSpkpkYJ8 0t9nwR9MDC4eMrfiTBjP4jnTwYyavdQMYHm/truF59/BC27NxBCdqqX1JU11/xW7yR+P NATTugnwpSm2ATdTFNyoQbounVlxU4sUC2s5YY8d/KB2jn6uaZY7jQMzfCSzKYNkfKEI HgQaVs4R9CXBKN0gRgiZcPSC7oQDt2ehgEbp8jH6IR7tTE7Lew8Z+RTrWAPfDMlgyfdb eesQ== X-Gm-Message-State: AOAM531MN4GnAs/dnPLResNshwsPDrqQ7bRP5l3L0gZyaA6opN4EFJEw /yXH7CSeEgAnWz7mw2xzGPzcaLc39wQ= X-Google-Smtp-Source: ABdhPJz6M6n2CqznAgrr0LbViX/Lw4t5cOgo+P5aTw5QvBvN0aGqT8nSJim2Yupf9nfIuQAbeIx/uQ== X-Received: by 2002:a1c:bc54:: with SMTP id m81mr17599599wmf.22.1594630086451; Mon, 13 Jul 2020 01:48:06 -0700 (PDT) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id g14sm23203357wrm.93.2020.07.13.01.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 01:48:05 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Jul 2020 09:47:28 +0100 Message-Id: <20200713084727.232422-10-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200713084727.232422-1-naush@raspberrypi.com> References: <20200713084727.232422-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 9/9] libcamera: pipeline: raspberrypi: Move RPiStream methods to a cpp file 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Some of the RPiStream methods have grown considerably in code size. Move those functions into a cpp file to stop inlining. No other functional changes in this commit. Signed-off-by: Naushir Patuck Reviewed-by: Niklas Söderlund --- .../pipeline/raspberrypi/meson.build | 1 + .../pipeline/raspberrypi/rpi_stream.cpp | 167 ++++++++++++++++++ .../pipeline/raspberrypi/rpi_stream.h | 155 +--------------- 3 files changed, 174 insertions(+), 149 deletions(-) create mode 100644 src/libcamera/pipeline/raspberrypi/rpi_stream.cpp diff --git a/src/libcamera/pipeline/raspberrypi/meson.build b/src/libcamera/pipeline/raspberrypi/meson.build index dcfe07c5..4cdfd8e1 100644 --- a/src/libcamera/pipeline/raspberrypi/meson.build +++ b/src/libcamera/pipeline/raspberrypi/meson.build @@ -3,4 +3,5 @@ libcamera_sources += files([ 'raspberrypi.cpp', 'staggered_ctrl.cpp', + 'rpi_stream.cpp' ]) diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp new file mode 100644 index 00000000..4eaa0686 --- /dev/null +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp @@ -0,0 +1,167 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Raspberry Pi (Trading) Ltd. + * + * rpi_stream.cpp - Raspberry Pi device stream abstraction class. + */ + +#include "rpi_stream.h" + +namespace libcamera { + +LOG_DEFINE_CATEGORY(RPISTREAM) + +namespace RPi { + +int RPiStream::prepareBuffers(unsigned int count) +{ + int ret; + + if (!importOnly_) { + if (count) { + /* Export some frame buffers for internal use. */ + ret = dev_->exportBuffers(count, &internalBuffers_); + if (ret < 0) + return ret; + + /* Add these exported buffers to the internal/external buffer list. */ + std::transform(internalBuffers_.begin(), internalBuffers_.end(), + std::back_inserter(bufferList_), + [](std::unique_ptr &b) { return b.get(); }); + + /* Add these buffers to the queue of internal usable buffers. */ + for (auto const &buffer : internalBuffers_) + availableBuffers_.push(buffer.get()); + } + + /* We must import all internal/external exported buffers. */ + count = bufferList_.size(); + } + + return dev_->importBuffers(count); +} + +int RPiStream::queueAllBuffers() +{ + int ret; + + if (external_) + return 0; + + while (!availableBuffers_.empty()) { + ret = queueBuffer(availableBuffers_.front()); + if (ret < 0) + return ret; + + availableBuffers_.pop(); + } + + return 0; +} + +int RPiStream::queueBuffer(FrameBuffer *buffer) +{ + /* + * A nullptr buffer implies an external stream, but no external + * buffer has been supplied. So, pick one from the availableBuffers_ + * queue. + */ + if (!buffer) { + if (availableBuffers_.empty()) { + LOG(RPISTREAM, Warning) << "No buffers available for " + << name_; + /* + * Note that we need to requeue an internal buffer as soon + * as one becomes available. + */ + requeueBuffers_.push(nullptr); + return -ENOMEM; + } + + buffer = availableBuffers_.front(); + availableBuffers_.pop(); + } + + if (requeueBuffers_.empty()) { + /* + * No earlier requests are pending to be queued, so we can + * go ahead and queue the buffer into the device. + */ + LOG(RPISTREAM, Debug) << "Queuing buffer " << buffer->cookie() + << " for " << name_; + + int ret = dev_->queueBuffer(buffer); + if (ret) + LOG(RPISTREAM, Error) << "Failed to queue buffer for " + << name_; + return ret; + } else { + /* + * There are earlier buffers to be queued, so this buffer must + * go on the waiting list. + */ + requeueBuffers_.push(buffer); + return 0; + } +} + +void RPiStream::returnBuffer(FrameBuffer *buffer) +{ + /* Push this buffer back into the queue to be used again. */ + availableBuffers_.push(buffer); + + /* + * Do we have any buffers that are waiting to be queued? + * If so, do it now as availableBuffers_ will not be empty. + */ + while (!requeueBuffers_.empty()) { + FrameBuffer *buffer = requeueBuffers_.front(); + requeueBuffers_.pop(); + + if (!buffer && !availableBuffers_.empty()) { + /* + * We want to queue an internal buffer, and at + * least one is available. + */ + buffer = availableBuffers_.front(); + availableBuffers_.pop(); + } else if (!buffer && !availableBuffers_.empty()) { + /* + * We want to queue an internal buffer, but none + * are available. + */ + break; + } + + LOG(RPISTREAM, Debug) << "Queuing buffer " << buffer->cookie() + << " for " << name_ << " from returnBuffer"; + + int ret = dev_->queueBuffer(buffer); + if (ret) + LOG(RPISTREAM, Error) << "Failed to queue buffer for " + << name_ << " from returnBuffer"; + } +} + +bool RPiStream::findFrameBuffer(FrameBuffer *buffer) const +{ + if (importOnly_) + return false; + + if (std::find(bufferList_.begin(), bufferList_.end(), buffer) != bufferList_.end()) + return true; + + return false; +} + +void RPiStream::clearBuffers() +{ + availableBuffers_ = std::queue{}; + requeueBuffers_ = std::queue{}; + internalBuffers_.clear(); + bufferList_.clear(); +} + +} /* namespace RPi */ + +} /* namespace libcamera */ diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.h b/src/libcamera/pipeline/raspberrypi/rpi_stream.h index 3309edfb..dbbff70b 100644 --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.h +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.h @@ -16,8 +16,6 @@ namespace libcamera { -LOG_DEFINE_CATEGORY(RPISTREAM) - namespace RPi { /* @@ -82,155 +80,14 @@ public: clearBuffers(); } - int prepareBuffers(unsigned int count) - { - int ret; - - if (!importOnly_) { - if (count) { - /* Export some frame buffers for internal use. */ - ret = dev_->exportBuffers(count, &internalBuffers_); - if (ret < 0) - return ret; - - /* Add these exported buffers to the internal/external buffer list. */ - std::transform(internalBuffers_.begin(), internalBuffers_.end(), - std::back_inserter(bufferList_), - [](std::unique_ptr &b) { return b.get(); }); - - /* Add these buffers to the queue of internal usable buffers. */ - for (auto const &buffer : internalBuffers_) - availableBuffers_.push(buffer.get()); - } - - /* We must import all internal/external exported buffers. */ - count = bufferList_.size(); - } - - return dev_->importBuffers(count); - } - - int queueAllBuffers() - { - int ret; - - if (external_) - return 0; - - while (!availableBuffers_.empty()) { - ret = queueBuffer(availableBuffers_.front()); - if (ret < 0) - return ret; - - availableBuffers_.pop(); - } - - return 0; - } - - int queueBuffer(FrameBuffer *buffer) - { - /* - * A nullptr buffer implies an external stream, but no external - * buffer has been supplied. So, pick one from the availableBuffers_ - * queue. - */ - if (!buffer) { - if (availableBuffers_.empty()) { - LOG(RPISTREAM, Warning) << "No buffers available for " - << name_; - /* - * Note that we need to requeue an internal buffer as soon - * as one becomes available. - */ - requeueBuffers_.push(nullptr); - return -ENOMEM; - } - - buffer = availableBuffers_.front(); - availableBuffers_.pop(); - } - - if (requeueBuffers_.empty()) { - /* - * No earlier requests are pending to be queued, so we can - * go ahead and queue the buffer into the device. - */ - LOG(RPISTREAM, Debug) << "Queuing buffer " << buffer->cookie() - << " for " << name_; - - int ret = dev_->queueBuffer(buffer); - if (ret) - LOG(RPISTREAM, Error) << "Failed to queue buffer for " - << name_; - return ret; - } else { - /* - * There are earlier buffers to be queued, so this buffer - * must go on the waiting list. - */ - requeueBuffers_.push(buffer); - return 0; - } - } - - void returnBuffer(FrameBuffer *buffer) - { - /* Push this buffer back into the queue to be used again. */ - availableBuffers_.push(buffer); - - /* - * Do we have any buffers that are waiting to be queued? - * If so, do it now as availableBuffers_ will not be empty. - */ - while (!requeueBuffers_.empty()) { - FrameBuffer *buffer = requeueBuffers_.front(); - requeueBuffers_.pop(); - - if (!buffer && !availableBuffers_.empty()) { - /* - * We want to queue an internal buffer, and at - * least one is available. - */ - buffer = availableBuffers_.front(); - availableBuffers_.pop(); - } else if (!buffer && !availableBuffers_.empty()) { - /* - * We want to queue an internal buffer, but none - * are available. - */ - break; - } - - LOG(RPISTREAM, Debug) << "Queuing buffer " << buffer->cookie() - << " for " << name_ << " from returnBuffer"; - - int ret = dev_->queueBuffer(buffer); - if (ret) - LOG(RPISTREAM, Error) << "Failed to queue buffer for " - << name_ << " from returnBuffer"; - } - } - - bool findFrameBuffer(FrameBuffer *buffer) const - { - if (importOnly_) - return false; - - if (std::find(bufferList_.begin(), bufferList_.end(), buffer) != bufferList_.end()) - return true; - - return false; - } + int prepareBuffers(unsigned int count); + int queueAllBuffers(); + int queueBuffer(FrameBuffer *buffer); + void returnBuffer(FrameBuffer *buffer); + bool findFrameBuffer(FrameBuffer *buffer) const; private: - void clearBuffers() - { - availableBuffers_ = std::queue{}; - requeueBuffers_ = std::queue{}; - internalBuffers_.clear(); - bufferList_.clear(); - } + void clearBuffers(); /* * Indicates that this stream is active externally, i.e. the buffers