diff options
author | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2019-10-27 22:10:25 +0100 |
---|---|---|
committer | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2020-01-12 16:10:37 +0100 |
commit | eb4030f6c07174a520be1ebd73628e9ae4789569 (patch) | |
tree | 2c919e7216c3649d5339b2953f62e98da9dee2f7 /src/libcamera/camera.cpp | |
parent | e9e6135d97d0afd3191e59578a71d51db14d6ad4 (diff) |
libcamera: allocator: Add FrameBufferAllocator to help applications allocate buffers
The FrameBuffer interface is based on the idea that all buffers are
allocated externally to libcamera and are only used by it. This is meant
to create a simpler API centered around usage of buffers, regardless of
where they come from.
Linux however lacks a centralized allocator at the moment, and not all
users of libcamera are expected to use another device that could provide
suitable buffers for the camera. This patch thus adds a helper class to
allocate buffers internally in libcamera, in a way that matches the
needs of the FrameBuffer-based API.
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera/camera.cpp')
-rw-r--r-- | src/libcamera/camera.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 5d294b10..20340167 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -9,6 +9,7 @@ #include <iomanip> +#include <libcamera/framebuffer_allocator.h> #include <libcamera/request.h> #include <libcamera/stream.h> @@ -405,7 +406,7 @@ const std::string &Camera::name() const Camera::Camera(PipelineHandler *pipe, const std::string &name) : pipe_(pipe->shared_from_this()), name_(name), disconnected_(false), - state_(CameraAvailable) + state_(CameraAvailable), allocator_(nullptr) { } @@ -541,6 +542,16 @@ int Camera::release() if (!stateBetween(CameraAvailable, CameraConfigured)) return -EBUSY; + if (allocator_) { + /* + * \todo Try to find a better API that would make this error + * impossible. + */ + LOG(Camera, Error) + << "Buffers must be freed before the camera can be reconfigured"; + return -EBUSY; + } + pipe_->unlock(); state_ = CameraAvailable; @@ -649,6 +660,12 @@ int Camera::configure(CameraConfiguration *config) if (!stateBetween(CameraAcquired, CameraConfigured)) return -EACCES; + if (allocator_ && allocator_->allocated()) { + LOG(Camera, Error) + << "Allocator must be deleted before camera can be reconfigured"; + return -EBUSY; + } + if (config->validate() != CameraConfiguration::Valid) { LOG(Camera, Error) << "Can't configure camera with invalid configuration"; |