[RFC,5/6] libcamera: converter_v4l2_m2m: Add helper to apply controls
diff mbox series

Message ID 20240712052920.33396-6-umang.jain@ideasonboard.com
State Not Applicable
Headers show
Series
  • converter_dw100: Add vertex map support
Related show

Commit Message

Umang Jain July 12, 2024, 5:29 a.m. UTC
Add applyControls() helper to apply controls for a stream.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 .../internal/converter/converter_v4l2_m2m.h    |  5 +++++
 src/libcamera/converter/converter_v4l2_m2m.cpp | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+)

Comments

Jacopo Mondi July 24, 2024, 1:30 p.m. UTC | #1
Hi Umang

On Fri, Jul 12, 2024 at 10:59:19AM GMT, Umang Jain wrote:
> Add applyControls() helper to apply controls for a stream.

This assumes controls are applied on the capture queue. Isn't there a
use case for applying controls to the output queue ?

>
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>  .../internal/converter/converter_v4l2_m2m.h    |  5 +++++
>  src/libcamera/converter/converter_v4l2_m2m.cpp | 18 ++++++++++++++++++
>  2 files changed, 23 insertions(+)
>
> diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h
> index f61beef8..9d3d62d6 100644
> --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h
> +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h
> @@ -24,6 +24,7 @@
>
>  namespace libcamera {
>
> +class ControlList;
>  class FrameBuffer;
>  class MediaDevice;
>  class Size;
> @@ -61,6 +62,8 @@ public:
>  	int setCrop(const Stream *stream, Rectangle *rect);
>  	std::pair<Rectangle, Rectangle> getCropBounds(const Stream *stream);
>
> +	int applyControls(const Stream *stream, ControlList &ctrls);
> +
>  protected:
>  	class Mapping
>  	{
> @@ -97,6 +100,8 @@ private:
>  		int start();
>  		void stop();
>
> +		int applyControls(ControlList &ctrls);
> +
>  		int queueBuffers(FrameBuffer *input, FrameBuffer *output);
>
>  		int setSelection(unsigned int target, Rectangle *rect);
> diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp
> index 9752a23e..9ff5102a 100644
> --- a/src/libcamera/converter/converter_v4l2_m2m.cpp
> +++ b/src/libcamera/converter/converter_v4l2_m2m.cpp
> @@ -15,6 +15,7 @@
>  #include <libcamera/base/signal.h>
>  #include <libcamera/base/utils.h>
>
> +#include <libcamera/controls.h>
>  #include <libcamera/framebuffer.h>
>  #include <libcamera/geometry.h>
>  #include <libcamera/stream.h>
> @@ -186,6 +187,11 @@ void V4L2M2MConverter::V4L2M2MStream::captureBufferReady(FrameBuffer *buffer)
>  	converter_->outputBufferReady.emit(buffer);
>  }
>
> +int V4L2M2MConverter::V4L2M2MStream::applyControls(ControlList &ctrls)
> +{
> +	return m2m_->capture()->setControls(&ctrls);
> +};
> +
>  /* -----------------------------------------------------------------------------
>   * V4L2M2MConverter
>   */
> @@ -532,6 +538,18 @@ int V4L2M2MConverter::queueBuffers(FrameBuffer *input,
>  	return 0;
>  }
>
> +/**
> + * libcamera::Converter::applyControls
> + */
> +int V4L2M2MConverter::applyControls(const Stream *stream, ControlList &ctrls)
> +{
> +	auto iter = streams_.find(stream);
> +	if (iter == streams_.end())
> +		return -EINVAL;
> +
> +	return iter->second->applyControls(ctrls);
> +}
> +
>  /*
>   * \todo: This should be extended to include Feature::Flag to denote
>   * what each converter supports feature-wise.
> --
> 2.45.0
>
Laurent Pinchart Aug. 2, 2024, 10:49 p.m. UTC | #2
On Wed, Jul 24, 2024 at 03:30:22PM +0200, Jacopo Mondi wrote:
> On Fri, Jul 12, 2024 at 10:59:19AM GMT, Umang Jain wrote:
> > Add applyControls() helper to apply controls for a stream.
> 
> This assumes controls are applied on the capture queue. Isn't there a
> use case for applying controls to the output queue ?

Controls are applied on a video device, not a queue, it won't make a
difference.

> > Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> > ---
> >  .../internal/converter/converter_v4l2_m2m.h    |  5 +++++
> >  src/libcamera/converter/converter_v4l2_m2m.cpp | 18 ++++++++++++++++++
> >  2 files changed, 23 insertions(+)
> >
> > diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h
> > index f61beef8..9d3d62d6 100644
> > --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h
> > +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h
> > @@ -24,6 +24,7 @@
> >
> >  namespace libcamera {
> >
> > +class ControlList;
> >  class FrameBuffer;
> >  class MediaDevice;
> >  class Size;
> > @@ -61,6 +62,8 @@ public:
> >  	int setCrop(const Stream *stream, Rectangle *rect);
> >  	std::pair<Rectangle, Rectangle> getCropBounds(const Stream *stream);
> >
> > +	int applyControls(const Stream *stream, ControlList &ctrls);

Unless I'm mistaken, the M2M framework doesn't support per-file handle
controls, so you can't have per-stream controls.

> > +
> >  protected:
> >  	class Mapping
> >  	{
> > @@ -97,6 +100,8 @@ private:
> >  		int start();
> >  		void stop();
> >
> > +		int applyControls(ControlList &ctrls);
> > +
> >  		int queueBuffers(FrameBuffer *input, FrameBuffer *output);
> >
> >  		int setSelection(unsigned int target, Rectangle *rect);
> > diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp
> > index 9752a23e..9ff5102a 100644
> > --- a/src/libcamera/converter/converter_v4l2_m2m.cpp
> > +++ b/src/libcamera/converter/converter_v4l2_m2m.cpp
> > @@ -15,6 +15,7 @@
> >  #include <libcamera/base/signal.h>
> >  #include <libcamera/base/utils.h>
> >
> > +#include <libcamera/controls.h>
> >  #include <libcamera/framebuffer.h>
> >  #include <libcamera/geometry.h>
> >  #include <libcamera/stream.h>
> > @@ -186,6 +187,11 @@ void V4L2M2MConverter::V4L2M2MStream::captureBufferReady(FrameBuffer *buffer)
> >  	converter_->outputBufferReady.emit(buffer);
> >  }
> >
> > +int V4L2M2MConverter::V4L2M2MStream::applyControls(ControlList &ctrls)
> > +{
> > +	return m2m_->capture()->setControls(&ctrls);
> > +};
> > +
> >  /* -----------------------------------------------------------------------------
> >   * V4L2M2MConverter
> >   */
> > @@ -532,6 +538,18 @@ int V4L2M2MConverter::queueBuffers(FrameBuffer *input,
> >  	return 0;
> >  }
> >
> > +/**
> > + * libcamera::Converter::applyControls
> > + */
> > +int V4L2M2MConverter::applyControls(const Stream *stream, ControlList &ctrls)
> > +{
> > +	auto iter = streams_.find(stream);
> > +	if (iter == streams_.end())
> > +		return -EINVAL;
> > +
> > +	return iter->second->applyControls(ctrls);
> > +}
> > +
> >  /*
> >   * \todo: This should be extended to include Feature::Flag to denote
> >   * what each converter supports feature-wise.

Patch
diff mbox series

diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h
index f61beef8..9d3d62d6 100644
--- a/include/libcamera/internal/converter/converter_v4l2_m2m.h
+++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h
@@ -24,6 +24,7 @@ 
 
 namespace libcamera {
 
+class ControlList;
 class FrameBuffer;
 class MediaDevice;
 class Size;
@@ -61,6 +62,8 @@  public:
 	int setCrop(const Stream *stream, Rectangle *rect);
 	std::pair<Rectangle, Rectangle> getCropBounds(const Stream *stream);
 
+	int applyControls(const Stream *stream, ControlList &ctrls);
+
 protected:
 	class Mapping
 	{
@@ -97,6 +100,8 @@  private:
 		int start();
 		void stop();
 
+		int applyControls(ControlList &ctrls);
+
 		int queueBuffers(FrameBuffer *input, FrameBuffer *output);
 
 		int setSelection(unsigned int target, Rectangle *rect);
diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp
index 9752a23e..9ff5102a 100644
--- a/src/libcamera/converter/converter_v4l2_m2m.cpp
+++ b/src/libcamera/converter/converter_v4l2_m2m.cpp
@@ -15,6 +15,7 @@ 
 #include <libcamera/base/signal.h>
 #include <libcamera/base/utils.h>
 
+#include <libcamera/controls.h>
 #include <libcamera/framebuffer.h>
 #include <libcamera/geometry.h>
 #include <libcamera/stream.h>
@@ -186,6 +187,11 @@  void V4L2M2MConverter::V4L2M2MStream::captureBufferReady(FrameBuffer *buffer)
 	converter_->outputBufferReady.emit(buffer);
 }
 
+int V4L2M2MConverter::V4L2M2MStream::applyControls(ControlList &ctrls)
+{
+	return m2m_->capture()->setControls(&ctrls);
+};
+
 /* -----------------------------------------------------------------------------
  * V4L2M2MConverter
  */
@@ -532,6 +538,18 @@  int V4L2M2MConverter::queueBuffers(FrameBuffer *input,
 	return 0;
 }
 
+/**
+ * libcamera::Converter::applyControls
+ */
+int V4L2M2MConverter::applyControls(const Stream *stream, ControlList &ctrls)
+{
+	auto iter = streams_.find(stream);
+	if (iter == streams_.end())
+		return -EINVAL;
+
+	return iter->second->applyControls(ctrls);
+}
+
 /*
  * \todo: This should be extended to include Feature::Flag to denote
  * what each converter supports feature-wise.