From patchwork Wed Mar 20 16:30:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 768 Return-Path: Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AD56A611B4 for ; Wed, 20 Mar 2019 17:30:41 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 4171320000D; Wed, 20 Mar 2019 16:30:41 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Mar 2019 17:30:46 +0100 Message-Id: <20190320163055.22056-23-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190320163055.22056-1-jacopo@jmondi.org> References: <20190320163055.22056-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 22/31] RFC: libcamera: pipeline_handlers: Add postFreeBuffers X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Mar 2019 16:30:41 -0000 Add a postFreeBuffers virtual method to the PipelineHandler base class and call if after performing per-stream memory release. Implement the method in the IPU3 pipeline handler to perform memory release on the CIO2 unit and ImgU input and stat video nodes. Signed-off-by: Jacopo Mondi --- src/libcamera/camera.cpp | 2 + src/libcamera/include/pipeline_handler.h | 4 ++ src/libcamera/pipeline/ipu3/ipu3.cpp | 48 +++++++++++++++--------- src/libcamera/pipeline_handler.cpp | 19 +++++++++- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 8020dff8f8ea..cf618ec567fc 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -514,6 +514,8 @@ int Camera::freeBuffers() pipe_->freeBuffers(this, stream); } + pipe_->postFreeBuffers(this); + state_ = CameraConfigured; return 0; diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h index 7ce5b67cc7fc..d3066550f1b7 100644 --- a/src/libcamera/include/pipeline_handler.h +++ b/src/libcamera/include/pipeline_handler.h @@ -64,6 +64,10 @@ public: } virtual int allocateBuffers(Camera *camera, Stream *stream) = 0; virtual int freeBuffers(Camera *camera, Stream *stream) = 0; + virtual int postFreeBuffers(Camera *camera) + { + return 0; + } virtual int start(Camera *camera) = 0; virtual void stop(Camera *camera); diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 5f323888d84f..ac2b14156d4f 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -109,6 +109,7 @@ public: const std::set &activeStreams) override; int allocateBuffers(Camera *camera, Stream *stream) override; int freeBuffers(Camera *camera, Stream *stream) override; + int postFreeBuffers(Camera *camera) override; int start(Camera *camera) override; void stop(Camera *camera) override; @@ -543,26 +544,8 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera, Stream *stream) IPU3CameraData *data = cameraData(camera); V4L2Device *viewfinder = data->imgu->viewfinder; V4L2Device *output = data->imgu->output; - V4L2Device *input = data->imgu->input; - V4L2Device *cio2 = data->cio2.output; - V4L2Device *stat = data->imgu->stat; int ret; - if (data->cio2.pool.count()) { - ret = input->releaseBuffers(); - if (ret) - LOG(IPU3, Error) << "Failed to release ImgU input memory"; - - ret = cio2->releaseBuffers(); - if (ret) - LOG(IPU3, Error) << "Failed to release CIO2 memory"; - - ret = stat->releaseBuffers(); - if (ret) - LOG(IPU3, Error) << "Failed to release ImgU stat memory"; - - } - if (isOutput(data, stream)) { ret = output->releaseBuffers(); if (ret) @@ -594,6 +577,35 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera, Stream *stream) return 0; } +int PipelineHandlerIPU3::postFreeBuffers(Camera *camera) +{ + IPU3CameraData *data = cameraData(camera); + V4L2Device *input = data->imgu->input; + V4L2Device *cio2 = data->cio2.output; + V4L2Device *stat = data->imgu->stat; + int retval = 0; + + int ret = input->releaseBuffers(); + if (ret) { + retval |= ret; + LOG(IPU3, Error) << "Failed to release ImgU input memory"; + } + + ret = cio2->releaseBuffers(); + if (ret) { + retval |= ret; + LOG(IPU3, Error) << "Failed to release CIO2 memory"; + } + + ret = stat->releaseBuffers(); + if (ret) { + retval |= ret; + LOG(IPU3, Error) << "Failed to release ImgU stat memory"; + } + + return retval; +} + int PipelineHandlerIPU3::start(Camera *camera) { IPU3CameraData *data = cameraData(camera); diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 1f556ed789b6..d0dee64b9844 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -231,7 +231,24 @@ PipelineHandler::~PipelineHandler() * After a capture session has been stopped all buffers associated with the * stream shall be freed. * - * The intended caller of this method is the Camera class. + * The intended caller of this method is the Camera class which calls it + * once per each active stream. + * + * \return 0 on success or a negative error code otherwise + */ + +/** + * \fn PipelineHandler::postFreeBuffers() + * \brief Perform post-memory release operations. Optional for pipeline + * handlers to implement + * \param[in] camera The camera to release memory on + * + * If any clean up operation is required this virtual method provides an entry + * point for pipeline handlers to do so. + * + * The intended caller of this method is the Camera class, which call it once + * after performing per-stream memory release by calling + * PipelineHandler::freeBuffers() on each active stream. * * \return 0 on success or a negative error code otherwise */