[libcamera-devel] [PATCH 14/30] cam: Move event loop exit from CameraSession to CamApp

Kieran Bingham kieran.bingham at ideasonboard.com
Mon Jul 12 17:17:00 CEST 2021


On 07/07/2021 03:19, Laurent Pinchart wrote:
> MAke exiting the event loop the responsibility of the application, not

/MAke/Make/

> the camera session, to prepare for support of multiple camera sessions.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> ---
>  src/cam/camera_session.cpp | 2 +-
>  src/cam/camera_session.h   | 4 ++++
>  src/cam/main.cpp           | 7 +++++++
>  3 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp
> index b26c7974056d..16c1c66a285a 100644
> --- a/src/cam/camera_session.cpp
> +++ b/src/cam/camera_session.cpp
> @@ -232,7 +232,7 @@ void CameraSession::processRequest(Request *request)
>  
>  	captureCount_++;
>  	if (captureLimit_ && captureCount_ >= captureLimit_) {
> -		EventLoop::instance()->exit(0);
> +		captureDone.emit();
>  		return;
>  	}
>  
> diff --git a/src/cam/camera_session.h b/src/cam/camera_session.h
> index 270ba3e929e7..2728d7607db2 100644
> --- a/src/cam/camera_session.h
> +++ b/src/cam/camera_session.h
> @@ -11,6 +11,8 @@
>  #include <stdint.h>
>  #include <vector>
>  
> +#include <libcamera/base/signal.h>
> +
>  #include <libcamera/camera.h>
>  #include <libcamera/framebuffer.h>
>  #include <libcamera/framebuffer_allocator.h>
> @@ -28,6 +30,8 @@ public:
>  
>  	int run(const OptionsParser::Options &options);
>  
> +	libcamera::Signal<> captureDone;
> +
>  private:
>  	int capture(libcamera::FrameBufferAllocator *allocator);
>  
> diff --git a/src/cam/main.cpp b/src/cam/main.cpp
> index 90435206d386..a567a7cc7653 100644
> --- a/src/cam/main.cpp
> +++ b/src/cam/main.cpp
> @@ -38,6 +38,7 @@ public:
>  private:
>  	void cameraAdded(std::shared_ptr<Camera> cam);
>  	void cameraRemoved(std::shared_ptr<Camera> cam);
> +	void captureDone();
>  	int parseOptions(int argc, char *argv[]);
>  	int prepareConfig();
>  	int listControls();
> @@ -330,6 +331,11 @@ void CamApp::cameraRemoved(std::shared_ptr<Camera> cam)
>  	std::cout << "Camera Removed: " << cam->id() << std::endl;
>  }
>  
> +void CamApp::captureDone()
> +{
> +	EventLoop::instance()->exit(0);

Ok - this makes more sense than the previous patch ;-)

I'm curious that now any CaptureSession can signal application to close
- so perhaps we'll see that change in the next patches...

Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>

> +}
> +
>  int CamApp::run()
>  {
>  	int ret;
> @@ -364,6 +370,7 @@ int CamApp::run()
>  
>  	if (options_.isSet(OptCapture)) {
>  		CameraSession session(camera_, config_.get());
> +		session.captureDone.connect(this, &CamApp::captureDone);
>  		return session.run(options_);
>  	}
>  
> 


More information about the libcamera-devel mailing list