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

Message ID 20190228200410.3022-9-jacopo@jmondi.org
State Superseded
Headers show
Series
  • libcamera: ipu3: ImgU support
Related show

Commit Message

Jacopo Mondi Feb. 28, 2019, 8:04 p.m. UTC
Start and stop all video devices in the pipeline.

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

Comments

Laurent Pinchart March 2, 2019, 10:59 p.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Thu, Feb 28, 2019 at 09:04:08PM +0100, Jacopo Mondi wrote:
> Start and stop all video devices in the pipeline.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  src/libcamera/pipeline/ipu3/ipu3.cpp | 57 ++++++++++++++++++++++++----
>  1 file changed, 49 insertions(+), 8 deletions(-)
> 
> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> index 8ce661e27f62..b9bc992879f5 100644
> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> @@ -146,6 +146,8 @@ private:
>  	void registerCameras();
>  
>  	int releaseBuffers(V4L2Device *dev);
> +	int startDevice(V4L2Device *dev);
> +	int stopDevice(V4L2Device *dev);
>  
>  	ImguDevice imgu0_;
>  	ImguDevice imgu1_;
> @@ -410,14 +412,27 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera, Stream *stream)
>  int PipelineHandlerIPU3::start(const Camera *camera)
>  {
>  	IPU3CameraData *data = cameraData(camera);
> -	V4L2Device *cio2 = data->cio2.output;
>  	int ret;
>  
> -	ret = cio2->streamOn();
> -	if (ret) {
> -		LOG(IPU3, Info) << "Failed to start camera " << camera->name();
> +	ret = startDevice(data->imgu->output);
> +	if (ret)
> +		return ret;
> +
> +	ret = startDevice(data->imgu->viewfinder);
> +	if (ret)
> +		return ret;
> +
> +	ret = startDevice(data->imgu->stat);
> +	if (ret)
> +		return ret;
> +
> +	ret = startDevice(data->imgu->input);
> +	if (ret)
> +		return ret;
> +
> +	ret = startDevice(data->cio2.output);
> +	if (ret)
>  		return ret;
> -	}

Don't you need to clean up and stop the nodes that have been started ?
calling stop() might be all you need.

>  
>  	return 0;
>  }
> @@ -425,10 +440,12 @@ int PipelineHandlerIPU3::start(const Camera *camera)
>  void PipelineHandlerIPU3::stop(const Camera *camera)
>  {
>  	IPU3CameraData *data = cameraData(camera);
> -	V4L2Device *cio2 = data->cio2.output;
>  
> -	if (cio2->streamOff())
> -		LOG(IPU3, Info) << "Failed to stop camera " << camera->name();
> +	stopDevice(data->imgu->output);
> +	stopDevice(data->imgu->viewfinder);
> +	stopDevice(data->imgu->stat);
> +	stopDevice(data->imgu->input);
> +	stopDevice(data->cio2.output);

How about accummulating errors and printing one message at the end with
the number of nodes that failed to stop (if any) ?

>  }
>  
>  int PipelineHandlerIPU3::queueRequest(const Camera *camera, Request *request)
> @@ -934,6 +951,30 @@ int PipelineHandlerIPU3::releaseBuffers(V4L2Device *dev)
>  	return 0;
>  }
>  
> +int PipelineHandlerIPU3::startDevice(V4L2Device *dev)
> +{
> +	int ret = dev->streamOn();
> +	if (ret) {
> +		LOG(IPU3, Info)
> +			<< "Failed to start video device:" << dev->deviceNode();
> +		return ret;

The error message is already printed by the V4L2Device class, lets drop
these two methods.

> +	}
> +
> +	return 0;
> +}
> +
> +int PipelineHandlerIPU3::stopDevice(V4L2Device *dev)
> +{
> +	int ret = dev->streamOff();
> +	if (ret) {
> +		LOG(IPU3, Info)
> +			<< "Failed to stop video device:" << dev->deviceNode();
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
>  REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3);
>  
>  } /* namespace libcamera */
Jacopo Mondi March 9, 2019, 9 p.m. UTC | #2
Hi Laurent,

On Sun, Mar 03, 2019 at 12:59:35AM +0200, Laurent Pinchart wrote:
> Hi Jacopo,
>
> Thank you for the patch.
>
> On Thu, Feb 28, 2019 at 09:04:08PM +0100, Jacopo Mondi wrote:
> > Start and stop all video devices in the pipeline.
> >
> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> > ---
> >  src/libcamera/pipeline/ipu3/ipu3.cpp | 57 ++++++++++++++++++++++++----
> >  1 file changed, 49 insertions(+), 8 deletions(-)
> >
> > diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > index 8ce661e27f62..b9bc992879f5 100644
> > --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> > +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > @@ -146,6 +146,8 @@ private:
> >  	void registerCameras();
> >
> >  	int releaseBuffers(V4L2Device *dev);
> > +	int startDevice(V4L2Device *dev);
> > +	int stopDevice(V4L2Device *dev);
> >
> >  	ImguDevice imgu0_;
> >  	ImguDevice imgu1_;
> > @@ -410,14 +412,27 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera, Stream *stream)
> >  int PipelineHandlerIPU3::start(const Camera *camera)
> >  {
> >  	IPU3CameraData *data = cameraData(camera);
> > -	V4L2Device *cio2 = data->cio2.output;
> >  	int ret;
> >
> > -	ret = cio2->streamOn();
> > -	if (ret) {
> > -		LOG(IPU3, Info) << "Failed to start camera " << camera->name();
> > +	ret = startDevice(data->imgu->output);
> > +	if (ret)
> > +		return ret;
> > +
> > +	ret = startDevice(data->imgu->viewfinder);
> > +	if (ret)
> > +		return ret;
> > +
> > +	ret = startDevice(data->imgu->stat);
> > +	if (ret)
> > +		return ret;
> > +
> > +	ret = startDevice(data->imgu->input);
> > +	if (ret)
> > +		return ret;
> > +
> > +	ret = startDevice(data->cio2.output);
> > +	if (ret)
> >  		return ret;
> > -	}
>
> Don't you need to clean up and stop the nodes that have been started ?
> calling stop() might be all you need.
>
> >
> >  	return 0;
> >  }
> > @@ -425,10 +440,12 @@ int PipelineHandlerIPU3::start(const Camera *camera)
> >  void PipelineHandlerIPU3::stop(const Camera *camera)
> >  {
> >  	IPU3CameraData *data = cameraData(camera);
> > -	V4L2Device *cio2 = data->cio2.output;
> >
> > -	if (cio2->streamOff())
> > -		LOG(IPU3, Info) << "Failed to stop camera " << camera->name();
> > +	stopDevice(data->imgu->output);
> > +	stopDevice(data->imgu->viewfinder);
> > +	stopDevice(data->imgu->stat);
> > +	stopDevice(data->imgu->input);
> > +	stopDevice(data->cio2.output);
>
> How about accummulating errors and printing one message at the end with
> the number of nodes that failed to stop (if any) ?
>
> >  }
> >
> >  int PipelineHandlerIPU3::queueRequest(const Camera *camera, Request *request)
> > @@ -934,6 +951,30 @@ int PipelineHandlerIPU3::releaseBuffers(V4L2Device *dev)
> >  	return 0;
> >  }
> >
> > +int PipelineHandlerIPU3::startDevice(V4L2Device *dev)
> > +{
> > +	int ret = dev->streamOn();
> > +	if (ret) {
> > +		LOG(IPU3, Info)
> > +			<< "Failed to start video device:" << dev->deviceNode();
> > +		return ret;
>
> The error message is already printed by the V4L2Device class, lets drop
> these two methods.
>

Will fix all in v2.

Thanks
  j

> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +int PipelineHandlerIPU3::stopDevice(V4L2Device *dev)
> > +{
> > +	int ret = dev->streamOff();
> > +	if (ret) {
> > +		LOG(IPU3, Info)
> > +			<< "Failed to stop video device:" << dev->deviceNode();
> > +		return ret;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> >  REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3);
> >
> >  } /* namespace libcamera */
>
> --
> Regards,
>
> Laurent Pinchart

Patch

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index 8ce661e27f62..b9bc992879f5 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -146,6 +146,8 @@  private:
 	void registerCameras();
 
 	int releaseBuffers(V4L2Device *dev);
+	int startDevice(V4L2Device *dev);
+	int stopDevice(V4L2Device *dev);
 
 	ImguDevice imgu0_;
 	ImguDevice imgu1_;
@@ -410,14 +412,27 @@  int PipelineHandlerIPU3::freeBuffers(Camera *camera, Stream *stream)
 int PipelineHandlerIPU3::start(const Camera *camera)
 {
 	IPU3CameraData *data = cameraData(camera);
-	V4L2Device *cio2 = data->cio2.output;
 	int ret;
 
-	ret = cio2->streamOn();
-	if (ret) {
-		LOG(IPU3, Info) << "Failed to start camera " << camera->name();
+	ret = startDevice(data->imgu->output);
+	if (ret)
+		return ret;
+
+	ret = startDevice(data->imgu->viewfinder);
+	if (ret)
+		return ret;
+
+	ret = startDevice(data->imgu->stat);
+	if (ret)
+		return ret;
+
+	ret = startDevice(data->imgu->input);
+	if (ret)
+		return ret;
+
+	ret = startDevice(data->cio2.output);
+	if (ret)
 		return ret;
-	}
 
 	return 0;
 }
@@ -425,10 +440,12 @@  int PipelineHandlerIPU3::start(const Camera *camera)
 void PipelineHandlerIPU3::stop(const Camera *camera)
 {
 	IPU3CameraData *data = cameraData(camera);
-	V4L2Device *cio2 = data->cio2.output;
 
-	if (cio2->streamOff())
-		LOG(IPU3, Info) << "Failed to stop camera " << camera->name();
+	stopDevice(data->imgu->output);
+	stopDevice(data->imgu->viewfinder);
+	stopDevice(data->imgu->stat);
+	stopDevice(data->imgu->input);
+	stopDevice(data->cio2.output);
 }
 
 int PipelineHandlerIPU3::queueRequest(const Camera *camera, Request *request)
@@ -934,6 +951,30 @@  int PipelineHandlerIPU3::releaseBuffers(V4L2Device *dev)
 	return 0;
 }
 
+int PipelineHandlerIPU3::startDevice(V4L2Device *dev)
+{
+	int ret = dev->streamOn();
+	if (ret) {
+		LOG(IPU3, Info)
+			<< "Failed to start video device:" << dev->deviceNode();
+		return ret;
+	}
+
+	return 0;
+}
+
+int PipelineHandlerIPU3::stopDevice(V4L2Device *dev)
+{
+	int ret = dev->streamOff();
+	if (ret) {
+		LOG(IPU3, Info)
+			<< "Failed to stop video device:" << dev->deviceNode();
+		return ret;
+	}
+
+	return 0;
+}
+
 REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3);
 
 } /* namespace libcamera */