[libcamera-devel,5/5] cam: Use script parser to set controls
diff mbox series

Message ID 20220518171921.244168-6-jacopo@jmondi.org
State Accepted
Headers show
Series
  • cam: Add support for capture scripts
Related show

Commit Message

Jacopo Mondi May 18, 2022, 5:19 p.m. UTC
Add to the CameraSession class a script parser instance, created
conditionally to the OptCaptureScript option.

If the script parser has been created, use it at queueRequest time to
retrieve the list of controls that has to be associated with a Request,
and populate Request::controls() with it before queueing it to the
Camera.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/cam/camera_session.cpp | 10 ++++++++++
 src/cam/camera_session.h   |  3 +++
 2 files changed, 13 insertions(+)

Comments

Laurent Pinchart May 20, 2022, 10:26 a.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Wed, May 18, 2022 at 07:19:21PM +0200, Jacopo Mondi via libcamera-devel wrote:
> Add to the CameraSession class a script parser instance, created
> conditionally to the OptCaptureScript option.
> 
> If the script parser has been created, use it at queueRequest time to
> retrieve the list of controls that has to be associated with a Request,
> and populate Request::controls() with it before queueing it to the
> Camera.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  src/cam/camera_session.cpp | 10 ++++++++++
>  src/cam/camera_session.h   |  3 +++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp
> index a1b447235009..74c2acd79499 100644
> --- a/src/cam/camera_session.cpp
> +++ b/src/cam/camera_session.cpp
> @@ -94,6 +94,13 @@ CameraSession::CameraSession(CameraManager *cm,
>  	}
>  #endif
>  
> +	if (options_.isSet(OptCaptureScript)) {
> +		script_ = std::make_unique<CaptureScript>(camera_,
> +					  options_[OptCaptureScript].toString());
> +		if (!script_->valid())

An error message would be nice here.

> +			return;
> +	}
> +
>  	switch (config->validate()) {
>  	case CameraConfiguration::Valid:
>  		break;
> @@ -327,6 +334,9 @@ int CameraSession::startCapture()
>  
>  int CameraSession::queueRequest(Request *request)
>  {
> +	if (script_)
> +		request->controls() = script_->frameControls(queueCount_);
> +
>  	queueCount_++;
>  
>  	return camera_->queueRequest(request);
> diff --git a/src/cam/camera_session.h b/src/cam/camera_session.h
> index bf966bd15ab0..2cca92df0079 100644
> --- a/src/cam/camera_session.h
> +++ b/src/cam/camera_session.h
> @@ -21,6 +21,7 @@
>  #include <libcamera/request.h>
>  #include <libcamera/stream.h>
>  
> +#include "capture_script.h"

You can forward-declare the class in this header and move the include to
the .cpp file.

>  #include "options.h"
>  
>  class FrameSink;
> @@ -60,6 +61,8 @@ private:
>  	std::shared_ptr<libcamera::Camera> camera_;
>  	std::unique_ptr<libcamera::CameraConfiguration> config_;
>  
> +	std::unique_ptr<CaptureScript> script_;
> +
>  	std::map<const libcamera::Stream *, std::string> streamNames_;
>  	std::unique_ptr<FrameSink> sink_;
>  	unsigned int cameraIndex_;

Patch
diff mbox series

diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp
index a1b447235009..74c2acd79499 100644
--- a/src/cam/camera_session.cpp
+++ b/src/cam/camera_session.cpp
@@ -94,6 +94,13 @@  CameraSession::CameraSession(CameraManager *cm,
 	}
 #endif
 
+	if (options_.isSet(OptCaptureScript)) {
+		script_ = std::make_unique<CaptureScript>(camera_,
+					  options_[OptCaptureScript].toString());
+		if (!script_->valid())
+			return;
+	}
+
 	switch (config->validate()) {
 	case CameraConfiguration::Valid:
 		break;
@@ -327,6 +334,9 @@  int CameraSession::startCapture()
 
 int CameraSession::queueRequest(Request *request)
 {
+	if (script_)
+		request->controls() = script_->frameControls(queueCount_);
+
 	queueCount_++;
 
 	return camera_->queueRequest(request);
diff --git a/src/cam/camera_session.h b/src/cam/camera_session.h
index bf966bd15ab0..2cca92df0079 100644
--- a/src/cam/camera_session.h
+++ b/src/cam/camera_session.h
@@ -21,6 +21,7 @@ 
 #include <libcamera/request.h>
 #include <libcamera/stream.h>
 
+#include "capture_script.h"
 #include "options.h"
 
 class FrameSink;
@@ -60,6 +61,8 @@  private:
 	std::shared_ptr<libcamera::Camera> camera_;
 	std::unique_ptr<libcamera::CameraConfiguration> config_;
 
+	std::unique_ptr<CaptureScript> script_;
+
 	std::map<const libcamera::Stream *, std::string> streamNames_;
 	std::unique_ptr<FrameSink> sink_;
 	unsigned int cameraIndex_;