@@ -49,6 +49,17 @@ public:
const CameraControlValidator *validator() const { return validator_.get(); }
+#ifndef __DOXYGEN__
+ struct FrameBufferPoolDeleter {
+ std::vector<FrameBuffer *> *pool = nullptr;
+ void operator()(FrameBuffer *buffer) const;
+ };
+#endif
+
+ using PooledFrameBuffer = std::unique_ptr<FrameBuffer, FrameBufferPoolDeleter>;
+
+ [[nodiscard]] PooledFrameBuffer acquireBuffer(const Stream *stream);
+
private:
enum State {
CameraAvailable,
@@ -754,6 +754,42 @@ Camera::Private::PendingFence::PendingFence(const Stream *s, FrameBuffer *b)
buffer(b)
{
}
+
+/**
+ * \typedef Camera::Private::PooledFrameBuffer
+ * \brief An std::unique_ptr for automatically returning the FrameBuffer to the pool to simplify error handling.
+ */
+
+#ifndef __DOXYGEN__
+void Camera::Private::FrameBufferPoolDeleter::operator()(FrameBuffer *buffer) const
+{
+ pool->push_back(buffer);
+}
+#endif
+
+/**
+ * \brief Acquire a buffer for a stream
+ * \param[in] stream The stream
+ *
+ * \return A buffer or an empty handle if not available
+ */
+Camera::Private::PooledFrameBuffer
+Camera::Private::acquireBuffer(const Stream *stream)
+{
+ auto it = streamData_.find(stream);
+ if (it == streamData_.end() || !it->second.active || it->second.buffers.empty())
+ return {};
+
+ FrameBuffer *buffer = it->second.buffers.back();
+ buffer->_d()->stream_ = stream;
+
+ LOG(Camera, Debug)
+ << "Camera:" << LIBCAMERA_O_PTR() << " acquired buffer:"
+ << buffer << " for stream:" << stream;
+
+ it->second.buffers.pop_back();
+ return { buffer, { &it->second.buffers } };
+}
#endif /* __DOXYGEN_PUBLIC__ */
/**
Add an internal function for pipeeline handlers that can be used to retrieve a buffer from the pool of a specific stream. Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> --- include/libcamera/internal/camera.h | 11 +++++++++ src/libcamera/camera.cpp | 36 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)