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>
This commit is contained in:
committed by
Niklas Söderlund
parent
f22ffc0ebe
commit
e1784ca883
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user