[2/4] libcamera: converter_v4l2_m2m: Support crop selection
diff mbox series

Message ID 20240519081539.29832-3-umang.jain@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: rkisp1: Plumb i.MX8MP DW100 dewarper
Related show

Commit Message

Umang Jain May 19, 2024, 8:15 a.m. UTC
Add a helper to set selection rectangle on the video node
to support cropping and scaling capabilites.

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

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 1126050c..acc6424c 100644
--- a/include/libcamera/internal/converter/converter_v4l2_m2m.h
+++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h
@@ -29,6 +29,7 @@  class MediaDevice;
 class Size;
 class SizeRange;
 struct StreamConfiguration;
+class Rectangle;
 class V4L2M2MDevice;
 
 class V4L2M2MConverter : public Converter
@@ -56,6 +57,8 @@  public:
 	int queueBuffers(FrameBuffer *input,
 			 const std::map<unsigned int, FrameBuffer *> &outputs);
 
+	int setSelection(unsigned int output, unsigned int target, Rectangle *rect);
+
 private:
 	class Stream : protected Loggable
 	{
@@ -74,6 +77,8 @@  private:
 
 		int queueBuffers(FrameBuffer *input, FrameBuffer *output);
 
+		int setSelection(unsigned int target, Rectangle *rect);
+
 	protected:
 		std::string logPrefix() const override;
 
diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp
index d8929fc5..2d3ee257 100644
--- a/src/libcamera/converter/converter_v4l2_m2m.cpp
+++ b/src/libcamera/converter/converter_v4l2_m2m.cpp
@@ -155,6 +155,15 @@  int V4L2M2MConverter::Stream::queueBuffers(FrameBuffer *input, FrameBuffer *outp
 	return 0;
 }
 
+int V4L2M2MConverter::Stream::setSelection(unsigned int target, Rectangle *rect)
+{
+	int ret = m2m_->output()->setSelection(target, rect);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 std::string V4L2M2MConverter::Stream::logPrefix() const
 {
 	return "stream" + std::to_string(index_);
@@ -370,6 +379,23 @@  int V4L2M2MConverter::exportBuffers(unsigned int output, unsigned int count,
 	return streams_[output].exportBuffers(count, buffers);
 }
 
+/**
+ * \brief Set a selection rectangle \a rect for \a target
+ * \param[in] output Index of the output stream
+ * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags
+ * \param[inout] rect The selection rectangle to be applied
+ *
+ * \return 0 on success or a negative error code otherwise
+ */
+int V4L2M2MConverter::setSelection(unsigned int output, unsigned int target,
+				   Rectangle *rect)
+{
+	if (output >= streams_.size())
+		return -EINVAL;
+
+	return streams_[output].setSelection(target, rect);
+}
+
 /**
  * \copydoc libcamera::Converter::start
  */