diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-01-19 21:42:09 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-01-23 22:36:30 +0200 |
commit | a4be7bb5ff4d4dce1fdc942a103f6360dad91f11 (patch) | |
tree | e5c218cb52d0224604745037cd20eaa3cf9734a5 /src/libcamera/framebuffer_allocator.cpp | |
parent | a0295fdaf854bb10c387255f10677d9b6f1554dc (diff) |
libcamera: camera: Move private data members to private implementation
Use the d-pointer idiom ([1], [2]) to hide the private data members from
the Camera class interface. This will ease maintaining ABI
compatibility, and prepares for the implementation of the Camera class
threading model.
The FrameBufferAllocator class accesses the Camera private data members
directly. In order to hide them, this pattern is replaced with new
private member functions in the Camera class, and the
FrameBufferAllocator is updated accordingly.
[1] https://wiki.qt.io/D-Pointer
[2] https://en.cppreference.com/w/cpp/language/pimpl
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/libcamera/framebuffer_allocator.cpp')
-rw-r--r-- | src/libcamera/framebuffer_allocator.cpp | 43 |
1 files changed, 11 insertions, 32 deletions
diff --git a/src/libcamera/framebuffer_allocator.cpp b/src/libcamera/framebuffer_allocator.cpp index c772b516..4ced10cd 100644 --- a/src/libcamera/framebuffer_allocator.cpp +++ b/src/libcamera/framebuffer_allocator.cpp @@ -89,7 +89,7 @@ FrameBufferAllocator::~FrameBufferAllocator() { for (auto &value : buffers_) { Stream *stream = value.first; - camera_->pipe_->freeFrameBuffers(camera_.get(), stream); + camera_->freeFrameBuffers(stream); } buffers_.clear(); @@ -117,32 +117,17 @@ FrameBufferAllocator::~FrameBufferAllocator() */ int FrameBufferAllocator::allocate(Stream *stream) { - if (camera_->state_ != Camera::CameraConfigured) { - LOG(Allocator, Error) - << "Camera must be in the configured state to allocate buffers"; - return -EACCES; - } - - if (camera_->streams().find(stream) == camera_->streams().end()) { - LOG(Allocator, Error) - << "Stream does not belong to " << camera_->name(); - return -EINVAL; - } - - if (camera_->activeStreams_.find(stream) == camera_->activeStreams_.end()) { - LOG(Allocator, Error) - << "Stream is not part of " << camera_->name() - << " active configuration"; - return -EINVAL; - } - if (buffers_.count(stream)) { LOG(Allocator, Error) << "Buffers already allocated for stream"; return -EBUSY; } - return camera_->pipe_->exportFrameBuffers(camera_.get(), stream, - &buffers_[stream]); + int ret = camera_->exportFrameBuffers(stream, &buffers_[stream]); + if (ret == -EINVAL) + LOG(Allocator, Error) + << "Stream is not part of " << camera_->name() + << " active configuration"; + return ret; } /** @@ -159,22 +144,16 @@ int FrameBufferAllocator::allocate(Stream *stream) */ int FrameBufferAllocator::free(Stream *stream) { - if (camera_->state_ != Camera::CameraConfigured) { - LOG(Allocator, Error) - << "Camera must be in the configured state to free buffers"; - return -EACCES; - } - auto iter = buffers_.find(stream); if (iter == buffers_.end()) return -EINVAL; - std::vector<std::unique_ptr<FrameBuffer>> &buffers = iter->second; + int ret = camera_->freeFrameBuffers(stream); + if (ret < 0) + return ret; + std::vector<std::unique_ptr<FrameBuffer>> &buffers = iter->second; buffers.clear(); - - camera_->pipe_->freeFrameBuffers(camera_.get(), stream); - buffers_.erase(iter); return 0; |