From a4be7bb5ff4d4dce1fdc942a103f6360dad91f11 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 19 Jan 2020 21:42:09 +0200 Subject: libcamera: camera: Move private data members to private implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Niklas Söderlund --- src/libcamera/framebuffer_allocator.cpp | 43 +++++++++------------------------ 1 file changed, 11 insertions(+), 32 deletions(-) (limited to 'src/libcamera/framebuffer_allocator.cpp') 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> &buffers = iter->second; + int ret = camera_->freeFrameBuffers(stream); + if (ret < 0) + return ret; + std::vector> &buffers = iter->second; buffers.clear(); - - camera_->pipe_->freeFrameBuffers(camera_.get(), stream); - buffers_.erase(iter); return 0; -- cgit v1.2.1