diff options
author | Naushir Patuck <naush@raspberrypi.com> | 2020-09-18 10:42:31 +0100 |
---|---|---|
committer | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2020-09-21 13:10:48 +0200 |
commit | e1784ca88359827824f3b5a1efc60c15c9783564 (patch) | |
tree | ac680b6b822bfbb0b86fd0133bf3d2b41b5697d5 /src/libcamera/pipeline/raspberrypi/rpi_stream.h | |
parent | f22ffc0ebec40e718325922edc3422bf0c487390 (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.h')
-rw-r--r-- | src/libcamera/pipeline/raspberrypi/rpi_stream.h | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.h b/src/libcamera/pipeline/raspberrypi/rpi_stream.h index 959e9147..df986367 100644 --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.h +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.h @@ -9,8 +9,10 @@ #include <queue> #include <string> +#include <unordered_map> #include <vector> +#include <libcamera/ipa/raspberrypi.h> #include <libcamera/stream.h> #include "libcamera/internal/v4l2_videodevice.h" @@ -19,6 +21,8 @@ namespace libcamera { namespace RPi { +using BufferMap = std::unordered_map<unsigned int, FrameBuffer *>; + /* * Device stream abstraction for either an internal or external stream. * Used for both Unicam and the ISP. @@ -27,12 +31,13 @@ class RPiStream : public Stream { public: RPiStream() + : id_(RPiIpaMask::ID) { } RPiStream(const char *name, MediaEntity *dev, bool importOnly = false) : external_(false), importOnly_(importOnly), name_(name), - dev_(std::make_unique<V4L2VideoDevice>(dev)) + dev_(std::make_unique<V4L2VideoDevice>(dev)), id_(RPiIpaMask::ID) { } @@ -45,8 +50,8 @@ public: bool isExternal() const; void setExportedBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers); - const std::vector<FrameBuffer *> &getBuffers() const; - int getBufferIndex(FrameBuffer *buffer) const; + const BufferMap &getBuffers() const; + int getBufferId(FrameBuffer *buffer) const; int prepareBuffers(unsigned int count); int queueBuffer(FrameBuffer *buffer); @@ -56,6 +61,44 @@ public: void releaseBuffers(); private: + class IdGenerator + { + public: + IdGenerator(int max) + : max_(max), id_(0) + { + } + + int get() + { + int id; + if (!recycle_.empty()) { + id = recycle_.front(); + recycle_.pop(); + } else { + id = id_++; + ASSERT(id_ <= max_); + } + return id; + } + + void release(int id) + { + recycle_.push(id); + } + + void reset() + { + id_ = 0; + recycle_ = {}; + } + + private: + int max_; + int id_; + std::queue<int> recycle_; + }; + void clearBuffers(); int queueToDevice(FrameBuffer *buffer); @@ -74,8 +117,11 @@ private: /* The actual device stream. */ std::unique_ptr<V4L2VideoDevice> dev_; + /* Tracks a unique id key for the bufferMap_ */ + IdGenerator id_; + /* All frame buffers associated with this device stream. */ - std::vector<FrameBuffer *> bufferList_; + BufferMap bufferMap_; /* * List of frame buffers that we can use if none have been provided by |