[libcamera-devel,v4,08/31] libcamera: ipu3: Implement camera start/stop

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

Commit Message

Jacopo Mondi March 20, 2019, 4:30 p.m. UTC
Start and stop video devices in the pipeline.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/pipeline/ipu3/ipu3.cpp | 54 ++++++++++++++++++++++++----
 1 file changed, 48 insertions(+), 6 deletions(-)

Comments

Laurent Pinchart March 21, 2019, 9:58 a.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Wed, Mar 20, 2019 at 05:30:32PM +0100, Jacopo Mondi wrote:
> Start and stop video devices in the pipeline.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  src/libcamera/pipeline/ipu3/ipu3.cpp | 54 ++++++++++++++++++++++++----
>  1 file changed, 48 insertions(+), 6 deletions(-)
> 
> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> index 2975c218f6c9..994c95692dd4 100644
> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> @@ -334,12 +334,52 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera, Stream *stream)
>  int PipelineHandlerIPU3::start(Camera *camera)
>  {
>  	IPU3CameraData *data = cameraData(camera);
> -	V4L2Device *cio2 = data->cio2.output;
>  	int ret;
>  
> -	ret = cio2->streamOn();
> +	/*
> +	 * Enqueue all available buffers to the CIO2 unit to start frame
> +	 * capture. Start ImgU video devices and queue buffers to the output
> +	 * ones at queueRequest() time.

"Start the ImgU video devices, buffers will be queued to the ImgU output
and viewfinder when requests will be queued." ?

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +	 */
> +	for (Buffer &buffer : data->cio2.pool.buffers()) {
> +		ret = data->cio2.output->queueBuffer(&buffer);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	ret = data->cio2.output->streamOn();
>  	if (ret) {
> -		LOG(IPU3, Info) << "Failed to start camera " << camera->name();
> +		LOG(IPU3, Error) << "Failed to start CIO2";
> +		stop(camera);
> +		return ret;
> +	}
> +
> +	/* Start the ImgU video devices. */
> +	ret = data->imgu->output->streamOn();
> +	if (ret) {
> +		LOG(IPU3, Error) << "Failed to start ImgU output";
> +		stop(camera);
> +		return ret;
> +	}
> +
> +	ret = data->imgu->viewfinder->streamOn();
> +	if (ret) {
> +		LOG(IPU3, Error) << "Failed to start ImgU viewfinder";
> +		stop(camera);
> +		return ret;
> +	}
> +
> +	ret = data->imgu->stat->streamOn();
> +	if (ret) {
> +		LOG(IPU3, Error) << "Failed to start ImgU stat";
> +		stop(camera);
> +		return ret;
> +	}
> +
> +	ret = data->imgu->input->streamOn();
> +	if (ret) {
> +		LOG(IPU3, Error) << "Failed to start ImgU input";
> +		stop(camera);
>  		return ret;
>  	}
>  
> @@ -349,10 +389,12 @@ int PipelineHandlerIPU3::start(Camera *camera)
>  void PipelineHandlerIPU3::stop(Camera *camera)
>  {
>  	IPU3CameraData *data = cameraData(camera);
> -	V4L2Device *cio2 = data->cio2.output;
>  
> -	if (cio2->streamOff())
> -		LOG(IPU3, Info) << "Failed to stop camera " << camera->name();
> +	data->cio2.output->streamOff();
> +	data->imgu->output->streamOff();
> +	data->imgu->viewfinder->streamOff();
> +	data->imgu->stat->streamOff();
> +	data->imgu->input->streamOff();
>  
>  	PipelineHandler::stop(camera);
>  }

Patch

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index 2975c218f6c9..994c95692dd4 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -334,12 +334,52 @@  int PipelineHandlerIPU3::freeBuffers(Camera *camera, Stream *stream)
 int PipelineHandlerIPU3::start(Camera *camera)
 {
 	IPU3CameraData *data = cameraData(camera);
-	V4L2Device *cio2 = data->cio2.output;
 	int ret;
 
-	ret = cio2->streamOn();
+	/*
+	 * Enqueue all available buffers to the CIO2 unit to start frame
+	 * capture. Start ImgU video devices and queue buffers to the output
+	 * ones at queueRequest() time.
+	 */
+	for (Buffer &buffer : data->cio2.pool.buffers()) {
+		ret = data->cio2.output->queueBuffer(&buffer);
+		if (ret)
+			return ret;
+	}
+
+	ret = data->cio2.output->streamOn();
 	if (ret) {
-		LOG(IPU3, Info) << "Failed to start camera " << camera->name();
+		LOG(IPU3, Error) << "Failed to start CIO2";
+		stop(camera);
+		return ret;
+	}
+
+	/* Start the ImgU video devices. */
+	ret = data->imgu->output->streamOn();
+	if (ret) {
+		LOG(IPU3, Error) << "Failed to start ImgU output";
+		stop(camera);
+		return ret;
+	}
+
+	ret = data->imgu->viewfinder->streamOn();
+	if (ret) {
+		LOG(IPU3, Error) << "Failed to start ImgU viewfinder";
+		stop(camera);
+		return ret;
+	}
+
+	ret = data->imgu->stat->streamOn();
+	if (ret) {
+		LOG(IPU3, Error) << "Failed to start ImgU stat";
+		stop(camera);
+		return ret;
+	}
+
+	ret = data->imgu->input->streamOn();
+	if (ret) {
+		LOG(IPU3, Error) << "Failed to start ImgU input";
+		stop(camera);
 		return ret;
 	}
 
@@ -349,10 +389,12 @@  int PipelineHandlerIPU3::start(Camera *camera)
 void PipelineHandlerIPU3::stop(Camera *camera)
 {
 	IPU3CameraData *data = cameraData(camera);
-	V4L2Device *cio2 = data->cio2.output;
 
-	if (cio2->streamOff())
-		LOG(IPU3, Info) << "Failed to stop camera " << camera->name();
+	data->cio2.output->streamOff();
+	data->imgu->output->streamOff();
+	data->imgu->viewfinder->streamOff();
+	data->imgu->stat->streamOff();
+	data->imgu->input->streamOff();
 
 	PipelineHandler::stop(camera);
 }