[libcamera-devel] [PATCH 9/9] libcamera: pipeline: raspberrypi: Move RPiStream methods to a cpp file
Naushir Patuck
naush at raspberrypi.com
Mon Jul 13 10:47:28 CEST 2020
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 <naush at raspberrypi.com>
---
.../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<FrameBuffer> &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<FrameBuffer *>{};
+ requeueBuffers_ = std::queue<FrameBuffer *>{};
+ 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<FrameBuffer> &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<FrameBuffer *>{};
- requeueBuffers_ = std::queue<FrameBuffer *>{};
- internalBuffers_.clear();
- bufferList_.clear();
- }
+ void clearBuffers();
/*
* Indicates that this stream is active externally, i.e. the buffers
--
2.25.1
More information about the libcamera-devel
mailing list