summaryrefslogtreecommitdiff
path: root/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2020-09-18 10:42:31 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-09-21 13:10:48 +0200
commite1784ca88359827824f3b5a1efc60c15c9783564 (patch)
treeac680b6b822bfbb0b86fd0133bf3d2b41b5697d5 /src/libcamera/pipeline/raspberrypi/rpi_stream.cpp
parentf22ffc0ebec40e718325922edc3422bf0c487390 (diff)
pipeline: raspberrypi: Use an unordered_map for the stream buffer list
By using a map container, we can easily insert/remove buffers from the buffer list. This will be required to track buffers allocated externally and passed to the pipeline handler through a Request. Replace the buffer index tracking with an id generated internally by the stream object. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/libcamera/pipeline/raspberrypi/rpi_stream.cpp')
-rw-r--r--src/libcamera/pipeline/raspberrypi/rpi_stream.cpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp
index 80170d64..aee0aa2d 100644
--- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp
+++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp
@@ -44,26 +44,28 @@ bool RPiStream::isExternal() const
void RPiStream::setExportedBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers)
{
- std::transform(buffers->begin(), buffers->end(), std::back_inserter(bufferList_),
- [](std::unique_ptr<FrameBuffer> &b) { return b.get(); });
+ for (auto const &buffer : *buffers)
+ bufferMap_.emplace(id_.get(), buffer.get());
}
-const std::vector<FrameBuffer *> &RPiStream::getBuffers() const
+const BufferMap &RPiStream::getBuffers() const
{
- return bufferList_;
+ return bufferMap_;
}
-int RPiStream::getBufferIndex(FrameBuffer *buffer) const
+int RPiStream::getBufferId(FrameBuffer *buffer) const
{
if (importOnly_)
return -1;
- /* Find the buffer in the list, and return the index position. */
- auto it = std::find(bufferList_.begin(), bufferList_.end(), buffer);
- if (it != bufferList_.end())
- return std::distance(bufferList_.begin(), it);
+ /* Find the buffer in the map, and return the buffer id. */
+ auto it = std::find_if(bufferMap_.begin(), bufferMap_.end(),
+ [&buffer](auto const &p) { return p.second == buffer; });
- return -1;
+ if (it == bufferMap_.end())
+ return -1;
+
+ return it->first;
}
int RPiStream::prepareBuffers(unsigned int count)
@@ -86,7 +88,7 @@ int RPiStream::prepareBuffers(unsigned int count)
}
/* We must import all internal/external exported buffers. */
- count = bufferList_.size();
+ count = bufferMap_.size();
}
return dev_->importBuffers(count);
@@ -139,6 +141,9 @@ void RPiStream::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.
@@ -196,12 +201,13 @@ void RPiStream::clearBuffers()
availableBuffers_ = std::queue<FrameBuffer *>{};
requestBuffers_ = std::queue<FrameBuffer *>{};
internalBuffers_.clear();
- bufferList_.clear();
+ bufferMap_.clear();
+ id_.reset();
}
int RPiStream::queueToDevice(FrameBuffer *buffer)
{
- LOG(RPISTREAM, Debug) << "Queuing buffer " << getBufferIndex(buffer)
+ LOG(RPISTREAM, Debug) << "Queuing buffer " << getBufferId(buffer)
<< " for " << name_;
int ret = dev_->queueBuffer(buffer);