[libcamera-devel,v4,22/31] RFC: libcamera: pipeline_handlers: Add postFreeBuffers

Message ID 20190320163055.22056-23-jacopo@jmondi.org
State Superseded
Headers show
Series
  • libcamera: ipu3: Add ImgU support + multiple streams
Related show

Commit Message

Jacopo Mondi March 20, 2019, 4:30 p.m. UTC
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 <jacopo@jmondi.org>
---
 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(-)

Patch

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<Stream *> &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
  */