From patchwork Sun Jul 11 17:03:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12894 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3DC2FC3225 for ; Sun, 11 Jul 2021 17:04:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 60C2868521; Sun, 11 Jul 2021 19:04:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="iLHoS+Mw"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 120486851B for ; Sun, 11 Jul 2021 19:04:49 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9BA4F255 for ; Sun, 11 Jul 2021 19:04:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626023088; bh=Z7K9NPx1ABJVzh27zZgvw/0OrteuDBPTsu+nL5gx+Ds=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iLHoS+Mwk1fLbB1zR/4BOR5ugr9DkJH2hnFXfU+e5UvU4GsgvIxiwVZ3QryOr+d1B ppJTbJUzmAi/P753XXrOiHlTDh7uBN9cIirN8aoxRAWJfyhBuIvVr6YCEP+Ti/LkyQ fDiOOglorGvUlUuMNvDv2eOk3uYKlj8lk6vPao9s= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 11 Jul 2021 20:03:57 +0300 Message-Id: <20210711170359.300-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210711170359.300-1-laurent.pinchart@ideasonboard.com> References: <20210711170359.300-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/3] libcamera: base: class: Expose Extensible private data to other classes X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Despite sharing the same name, the private data class created by the Extensible design pattern and the C++ private access specifier have different goals. The latter specifies class members private to the class, while the former stores data not visible to the application. There are use cases for accessing the private data class from other classes inside libcamera. Make this possible by exposing public _d() functions in the class deriving from Extensible. This won't allow access to the private data by applications as the definition of the Private class isn't visible outside of libcamera. The _d() functions need to be defined as template functions to delay their evaluation, as the static_cast() operator in the Extensible::_d() functions needs the Private class to be fully defined. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Umang Jain Reviewed-by: Hirokazu Honda Reviewed-by: Kieran Bingham --- include/libcamera/base/class.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/libcamera/base/class.h b/include/libcamera/base/class.h index a07dac057331..8212c3d4a5ae 100644 --- a/include/libcamera/base/class.h +++ b/include/libcamera/base/class.h @@ -33,14 +33,24 @@ namespace libcamera { #define LIBCAMERA_DECLARE_PRIVATE() \ public: \ class Private; \ - friend class Private; + friend class Private; \ + template \ + const Private *_d() const \ + { \ + return Extensible::_d(); \ + } \ + template \ + Private *_d() \ + { \ + return Extensible::_d(); \ + } #define LIBCAMERA_DECLARE_PUBLIC(klass) \ friend class klass; \ using Public = klass; #define LIBCAMERA_D_PTR() \ - _d(); + _d(); #define LIBCAMERA_O_PTR() \ _o(); From patchwork Sun Jul 11 17:03:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12895 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BA18EC3224 for ; Sun, 11 Jul 2021 17:04:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B08886851B; Sun, 11 Jul 2021 19:04:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Esc1f8Nw"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 59AB46851B for ; Sun, 11 Jul 2021 19:04:49 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ED37DCC for ; Sun, 11 Jul 2021 19:04:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626023089; bh=lHGpSk5xmnEew1Bjoj550UvIH1RtL2lO8RVfAf9k17Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Esc1f8NwjbdIL/7mdCoqYjDPms/IY+5ypX2WdA6nFSXjb0RU5eiibr/8mI9OGH/4X tZ0YtPUmpYcePJGdu/ugdEYbGN6+xxqlYAnpgOyGfnwLEsh/DPhgCjjYP7Y9m1DTrY T9wEYYeEKeual684vDVh6xbDe8HuVQ4c+iJpcj3Y= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 11 Jul 2021 20:03:58 +0300 Message-Id: <20210711170359.300-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210711170359.300-1-laurent.pinchart@ideasonboard.com> References: <20210711170359.300-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/3] libcamera: Drop the LIBCAMERA_D_PTR macro in favour of the _d() function X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Now that all Extensible classes expose a _d() function that performs appropriate casts, the LIBCAMERA_D_PTR brings no real additional value. Replace it with direct calls to the _d() function. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- include/libcamera/base/class.h | 4 --- src/android/camera_buffer.h | 15 ++++------- src/android/camera_hal_config.cpp | 3 +-- src/libcamera/base/class.cpp | 17 +++--------- src/libcamera/camera.cpp | 44 ++++++++++++------------------- src/libcamera/camera_manager.cpp | 16 +++++------ 6 files changed, 34 insertions(+), 65 deletions(-) diff --git a/include/libcamera/base/class.h b/include/libcamera/base/class.h index 8212c3d4a5ae..c2e1d3534ed1 100644 --- a/include/libcamera/base/class.h +++ b/include/libcamera/base/class.h @@ -49,16 +49,12 @@ public: \ friend class klass; \ using Public = klass; -#define LIBCAMERA_D_PTR() \ - _d(); - #define LIBCAMERA_O_PTR() \ _o(); #else #define LIBCAMERA_DECLARE_PRIVATE() #define LIBCAMERA_DECLARE_PUBLIC(klass) -#define LIBCAMERA_D_PTR() #define LIBCAMERA_O_PTR() #endif diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index 2617ff6b11a1..21373fa25bf8 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -40,27 +40,22 @@ CameraBuffer::~CameraBuffer() \ } \ bool CameraBuffer::isValid() const \ { \ - const Private *const d = LIBCAMERA_D_PTR(); \ - return d->isValid(); \ + return _d()->isValid(); \ } \ unsigned int CameraBuffer::numPlanes() const \ { \ - const Private *const d = LIBCAMERA_D_PTR(); \ - return d->numPlanes(); \ + return _d()->numPlanes(); \ } \ Span CameraBuffer::plane(unsigned int plane) const \ { \ - const Private *const d = LIBCAMERA_D_PTR(); \ - return const_cast(d)->plane(plane); \ + return const_cast(_d())->plane(plane); \ } \ Span CameraBuffer::plane(unsigned int plane) \ { \ - Private *const d = LIBCAMERA_D_PTR(); \ - return d->plane(plane); \ + return _d()->plane(plane); \ } \ size_t CameraBuffer::jpegBufferSize(size_t maxJpegBufferSize) const \ { \ - const Private *const d = LIBCAMERA_D_PTR(); \ - return d->jpegBufferSize(maxJpegBufferSize); \ + return _d()->jpegBufferSize(maxJpegBufferSize); \ } #endif /* __ANDROID_CAMERA_BUFFER_H__ */ diff --git a/src/android/camera_hal_config.cpp b/src/android/camera_hal_config.cpp index d84de4fd6f90..833cf4ba98a9 100644 --- a/src/android/camera_hal_config.cpp +++ b/src/android/camera_hal_config.cpp @@ -375,8 +375,7 @@ int CameraHalConfig::parseConfigurationFile() exists_ = true; - Private *const d = LIBCAMERA_D_PTR(); - int ret = d->parseConfigFile(fh, &cameras_); + int ret = _d()->parseConfigFile(fh, &cameras_); fclose(fh); if (ret) return -EINVAL; diff --git a/src/libcamera/base/class.cpp b/src/libcamera/base/class.cpp index 165beafc243d..26b4967726d6 100644 --- a/src/libcamera/base/class.cpp +++ b/src/libcamera/base/class.cpp @@ -94,23 +94,12 @@ namespace libcamera { * name passed as the \a klass parameter. */ -/** - * \def LIBCAMERA_D_PTR() - * \brief Retrieve the private data pointer - * - * This macro can be used in any member function of a class that inherits, - * directly or indirectly, from the Extensible class, to create a local - * variable named 'd' that points to the class' private data instance. - */ - /** * \def LIBCAMERA_O_PTR() * \brief Retrieve the public instance corresponding to the private data * - * This macro is the counterpart of LIBCAMERA_D_PTR() for private data classes. - * It can be used in any member function of the private data class to create a - * local variable named 'o' that points to the public class instance - * corresponding to the private data. + * This macro is used in any member function of the private data class to access + * the public class instance corresponding to the private data. */ /** @@ -148,6 +137,8 @@ namespace libcamera { * class need to be qualified with appropriate access specifiers. The * PublicClass and Private classes always have full access to each other's * protected and private members. + * + * The PublicClass exposes its Private data pointer through the _d() function. */ /** diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 29f2d91d05d3..c8858e71d105 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -604,8 +604,7 @@ std::shared_ptr Camera::create(PipelineHandler *pipe, */ const std::string &Camera::id() const { - const Private *const d = LIBCAMERA_D_PTR(); - return d->id_; + return _d()->id_; } /** @@ -655,18 +654,16 @@ Camera::~Camera() */ void Camera::disconnect() { - Private *const d = LIBCAMERA_D_PTR(); - LOG(Camera, Debug) << "Disconnecting camera " << id(); - d->disconnect(); + _d()->disconnect(); disconnected.emit(this); } int Camera::exportFrameBuffers(Stream *stream, std::vector> *buffers) { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); int ret = d->isAccessAllowed(Private::CameraConfigured); if (ret < 0) @@ -709,7 +706,7 @@ int Camera::exportFrameBuffers(Stream *stream, */ int Camera::acquire() { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); /* * No manual locking is required as PipelineHandler::lock() is @@ -746,7 +743,7 @@ int Camera::acquire() */ int Camera::release() { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); int ret = d->isAccessAllowed(Private::CameraAvailable, Private::CameraConfigured, true); @@ -772,8 +769,7 @@ int Camera::release() */ const ControlInfoMap &Camera::controls() const { - const Private *const d = LIBCAMERA_D_PTR(); - return d->pipe_->controls(this); + return _d()->pipe_->controls(this); } /** @@ -786,8 +782,7 @@ const ControlInfoMap &Camera::controls() const */ const ControlList &Camera::properties() const { - const Private *const d = LIBCAMERA_D_PTR(); - return d->pipe_->properties(this); + return _d()->pipe_->properties(this); } /** @@ -803,8 +798,7 @@ const ControlList &Camera::properties() const */ const std::set &Camera::streams() const { - const Private *const d = LIBCAMERA_D_PTR(); - return d->streams_; + return _d()->streams_; } /** @@ -825,7 +819,7 @@ const std::set &Camera::streams() const */ std::unique_ptr Camera::generateConfiguration(const StreamRoles &roles) { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); int ret = d->isAccessAllowed(Private::CameraAvailable, Private::CameraRunning); @@ -886,7 +880,7 @@ std::unique_ptr Camera::generateConfiguration(const StreamR */ int Camera::configure(CameraConfiguration *config) { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); int ret = d->isAccessAllowed(Private::CameraAcquired, Private::CameraConfigured); @@ -958,10 +952,8 @@ int Camera::configure(CameraConfiguration *config) */ std::unique_ptr Camera::createRequest(uint64_t cookie) { - Private *const d = LIBCAMERA_D_PTR(); - - int ret = d->isAccessAllowed(Private::CameraConfigured, - Private::CameraRunning); + int ret = _d()->isAccessAllowed(Private::CameraConfigured, + Private::CameraRunning); if (ret < 0) return nullptr; @@ -992,7 +984,7 @@ std::unique_ptr Camera::createRequest(uint64_t cookie) */ int Camera::queueRequest(Request *request) { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); int ret = d->isAccessAllowed(Private::CameraRunning); if (ret < 0) @@ -1044,7 +1036,7 @@ int Camera::queueRequest(Request *request) */ int Camera::start(const ControlList *controls) { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); int ret = d->isAccessAllowed(Private::CameraConfigured); if (ret < 0) @@ -1079,7 +1071,7 @@ int Camera::start(const ControlList *controls) */ int Camera::stop() { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); /* * \todo Make calling stop() when not in 'Running' part of the state @@ -1115,11 +1107,9 @@ int Camera::stop() */ void Camera::requestComplete(Request *request) { - Private *const d = LIBCAMERA_D_PTR(); - /* Disconnected cameras are still able to complete requests. */ - if (d->isAccessAllowed(Private::CameraStopping, Private::CameraRunning, - true)) + if (_d()->isAccessAllowed(Private::CameraStopping, Private::CameraRunning, + true)) LOG(Camera, Fatal) << "Trying to complete a request when stopped"; requestCompleted.emit(request); diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index fc3bd88c737b..1c79308ad4b5 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -291,11 +291,9 @@ CameraManager::~CameraManager() */ int CameraManager::start() { - Private *const d = LIBCAMERA_D_PTR(); - LOG(Camera, Info) << "libcamera " << version_; - int ret = d->start(); + int ret = _d()->start(); if (ret) LOG(Camera, Error) << "Failed to start camera manager: " << strerror(-ret); @@ -315,7 +313,7 @@ int CameraManager::start() */ void CameraManager::stop() { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); d->exit(); d->wait(); } @@ -333,7 +331,7 @@ void CameraManager::stop() */ std::vector> CameraManager::cameras() const { - const Private *const d = LIBCAMERA_D_PTR(); + const Private *const d = _d(); MutexLocker locker(d->mutex_); @@ -353,7 +351,7 @@ std::vector> CameraManager::cameras() const */ std::shared_ptr CameraManager::get(const std::string &id) { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); MutexLocker locker(d->mutex_); @@ -383,7 +381,7 @@ std::shared_ptr CameraManager::get(const std::string &id) */ std::shared_ptr CameraManager::get(dev_t devnum) { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); MutexLocker locker(d->mutex_); @@ -439,7 +437,7 @@ std::shared_ptr CameraManager::get(dev_t devnum) void CameraManager::addCamera(std::shared_ptr camera, const std::vector &devnums) { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); ASSERT(Thread::current() == d); @@ -459,7 +457,7 @@ void CameraManager::addCamera(std::shared_ptr camera, */ void CameraManager::removeCamera(std::shared_ptr camera) { - Private *const d = LIBCAMERA_D_PTR(); + Private *const d = _d(); ASSERT(Thread::current() == d); From patchwork Sun Jul 11 17:03:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12896 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 5A3FDC3225 for ; Sun, 11 Jul 2021 17:04:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0C35868523; Sun, 11 Jul 2021 19:04:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HRBsNFnd"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A92EF6851B for ; Sun, 11 Jul 2021 19:04:49 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 49794255 for ; Sun, 11 Jul 2021 19:04:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626023089; bh=oTJ4JSdVKRE6swaW6R5yBvS4ixscrI8uHyWH0KrCG28=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HRBsNFnd0yfh9KecJQYieTSDtLTOocdlpatXji7O/tXdCJjAHJsu/k7I/SjC8RM48 jT68VrClf3FxtdjZI+3QaShExaJfPOsD2vcDC+ng9Qqig9zw9KRiBsDhqhxH5A3B3R yOvPqeNscIdW7zYvO9l3/byZKtOk8Jf4gwFAdaaI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 11 Jul 2021 20:03:59 +0300 Message-Id: <20210711170359.300-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210711170359.300-1-laurent.pinchart@ideasonboard.com> References: <20210711170359.300-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/3] libcamera: framebuffer: Make FrameBuffer class Extensible X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Implement the D-Pointer design pattern in the FrameBuffer class to allow changing internal data without affecting the public ABI. Move the request_ field and the setRequest() function to the FrameBuffer::Private class. This allows hiding the setRequest() function from the public API, removing one todo item. More fields may be moved later. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Umang Jain Reviewed-by: Kieran Bingham --- Changes since v1: - Drop extraneous semicolon - Use _d() instead of LIBCAMERA_D_PTR() --- include/libcamera/framebuffer.h | 8 +++--- include/libcamera/internal/framebuffer.h | 13 +++++++++ src/libcamera/framebuffer.cpp | 34 ++++++++++++++---------- src/libcamera/pipeline/ipu3/cio2.cpp | 3 ++- src/libcamera/pipeline/ipu3/frames.cpp | 5 ++-- src/libcamera/request.cpp | 7 ++--- 6 files changed, 46 insertions(+), 24 deletions(-) diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h index baf22a466907..28307890eac9 100644 --- a/include/libcamera/framebuffer.h +++ b/include/libcamera/framebuffer.h @@ -35,8 +35,10 @@ struct FrameMetadata { std::vector planes; }; -class FrameBuffer final +class FrameBuffer final : public Extensible { + LIBCAMERA_DECLARE_PRIVATE() + public: struct Plane { FileDescriptor fd; @@ -47,8 +49,7 @@ public: const std::vector &planes() const { return planes_; } - Request *request() const { return request_; } - void setRequest(Request *request) { request_ = request; } + Request *request() const; const FrameMetadata &metadata() const { return metadata_; } unsigned int cookie() const { return cookie_; } @@ -63,7 +64,6 @@ private: std::vector planes_; - Request *request_; FrameMetadata metadata_; unsigned int cookie_; diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h index 0c76fc62af1d..a11e895d9b88 100644 --- a/include/libcamera/internal/framebuffer.h +++ b/include/libcamera/internal/framebuffer.h @@ -47,6 +47,19 @@ public: MappedFrameBuffer(const FrameBuffer *buffer, int flags); }; +class FrameBuffer::Private : public Extensible::Private +{ + LIBCAMERA_DECLARE_PUBLIC(FrameBuffer) + +public: + Private(FrameBuffer *buffer); + + void setRequest(Request *request) { request_ = request; } + +private: + Request *request_; +}; + } /* namespace libcamera */ #endif /* __LIBCAMERA_INTERNAL_FRAMEBUFFER_H__ */ diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp index 4bde556c4013..40bf64b0a4fe 100644 --- a/src/libcamera/framebuffer.cpp +++ b/src/libcamera/framebuffer.cpp @@ -100,6 +100,21 @@ LOG_DEFINE_CATEGORY(Buffer) * \brief Array of per-plane metadata */ +FrameBuffer::Private::Private(FrameBuffer *buffer) + : Extensible::Private(buffer), request_(nullptr) +{ +} + +/** + * \fn FrameBuffer::Private::setRequest() + * \brief Set the request this buffer belongs to + * \param[in] request Request to set + * + * For buffers added to requests by applications, this method is called by + * Request::addBuffer() or Request::reuse(). For buffers internal to pipeline + * handlers, it is called by the pipeline handlers themselves. + */ + /** * \class FrameBuffer * \brief Frame buffer data and its associated dynamic metadata @@ -161,7 +176,7 @@ LOG_DEFINE_CATEGORY(Buffer) * \param[in] cookie Cookie */ FrameBuffer::FrameBuffer(const std::vector &planes, unsigned int cookie) - : planes_(planes), request_(nullptr), cookie_(cookie) + : Extensible(new Private(this)), planes_(planes), cookie_(cookie) { } @@ -172,7 +187,6 @@ FrameBuffer::FrameBuffer(const std::vector &planes, unsigned int cookie) */ /** - * \fn FrameBuffer::request() * \brief Retrieve the request this buffer belongs to * * The intended callers of this method are buffer completion handlers that @@ -185,18 +199,10 @@ FrameBuffer::FrameBuffer(const std::vector &planes, unsigned int cookie) * \return The Request the FrameBuffer belongs to, or nullptr if the buffer is * not associated with a request */ - -/** - * \fn FrameBuffer::setRequest() - * \brief Set the request this buffer belongs to - * \param[in] request Request to set - * - * For buffers added to requests by applications, this method is called by - * Request::addBuffer() or Request::reuse(). For buffers internal to pipeline - * handlers, it is called by the pipeline handlers themselves. - * - * \todo Shall be hidden from applications with a d-pointer design. - */ +Request *FrameBuffer::request() const +{ + return _d()->request_; +} /** * \fn FrameBuffer::metadata() diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 1be2cbcd5cac..1bcd580e251c 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -14,6 +14,7 @@ #include #include "libcamera/internal/camera_sensor.h" +#include "libcamera/internal/framebuffer.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/v4l2_subdevice.h" @@ -278,7 +279,7 @@ FrameBuffer *CIO2Device::queueBuffer(Request *request, FrameBuffer *rawBuffer) buffer = availableBuffers_.front(); availableBuffers_.pop(); - buffer->setRequest(request); + buffer->_d()->setRequest(request); } int ret = output_->queueBuffer(buffer); diff --git a/src/libcamera/pipeline/ipu3/frames.cpp b/src/libcamera/pipeline/ipu3/frames.cpp index ce5ccbf18e41..a4c3477cd9ef 100644 --- a/src/libcamera/pipeline/ipu3/frames.cpp +++ b/src/libcamera/pipeline/ipu3/frames.cpp @@ -10,6 +10,7 @@ #include #include +#include "libcamera/internal/framebuffer.h" #include "libcamera/internal/pipeline_handler.h" #include "libcamera/internal/v4l2_videodevice.h" @@ -56,8 +57,8 @@ IPU3Frames::Info *IPU3Frames::create(Request *request) FrameBuffer *paramBuffer = availableParamBuffers_.front(); FrameBuffer *statBuffer = availableStatBuffers_.front(); - paramBuffer->setRequest(request); - statBuffer->setRequest(request); + paramBuffer->_d()->setRequest(request); + statBuffer->_d()->setRequest(request); availableParamBuffers_.pop(); availableStatBuffers_.pop(); diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index 5faf3c71ff02..c095c9f45b09 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -18,6 +18,7 @@ #include #include "libcamera/internal/camera_controls.h" +#include "libcamera/internal/framebuffer.h" #include "libcamera/internal/tracepoints.h" /** @@ -121,7 +122,7 @@ void Request::reuse(ReuseFlag flags) if (flags & ReuseBuffers) { for (auto pair : bufferMap_) { FrameBuffer *buffer = pair.second; - buffer->setRequest(this); + buffer->_d()->setRequest(this); pending_.insert(buffer); } } else { @@ -191,7 +192,7 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer) return -EEXIST; } - buffer->setRequest(this); + buffer->_d()->setRequest(this); pending_.insert(buffer); bufferMap_[stream] = buffer; @@ -336,7 +337,7 @@ bool Request::completeBuffer(FrameBuffer *buffer) int ret = pending_.erase(buffer); ASSERT(ret == 1); - buffer->setRequest(nullptr); + buffer->_d()->setRequest(nullptr); if (buffer->metadata().status == FrameMetadata::FrameCancelled) cancelled_ = true;