[5/9] libcamera: v4l2_subdevice: Add bind context
diff mbox series

Message ID 20250725-multicontext-v1-5-ea558291e101@ideasonboard.com
State New
Headers show
Series
  • libcamera: Support for multi-context operations
Related show

Commit Message

Jacopo Mondi July 25, 2025, 10:33 a.m. UTC
Add a function to the V4L2Subdevice class that allows to
bind a subdevice to a media device context using the
VIDIOC_SUBDEV_BIND_CONTEXT ioctl.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 include/libcamera/internal/v4l2_subdevice.h |  2 ++
 src/libcamera/v4l2_subdevice.cpp            | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)

Comments

Isaac Scott July 25, 2025, 10:37 a.m. UTC | #1
Hi Jacopo,

On Fri, 2025-07-25 at 12:33 +0200, Jacopo Mondi wrote:
> Add a function to the V4L2Subdevice class that allows to
> bind a subdevice to a media device context using the
> VIDIOC_SUBDEV_BIND_CONTEXT ioctl.
> 
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
>  include/libcamera/internal/v4l2_subdevice.h |  2 ++
>  src/libcamera/v4l2_subdevice.cpp            | 18 ++++++++++++++++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/include/libcamera/internal/v4l2_subdevice.h
> b/include/libcamera/internal/v4l2_subdevice.h
> index
> fa2a4a21eefbb792c69fa6357934d607a009d11a..f65a587c3034df014390863319a
> 350c8fbd4ed5a 100644
> --- a/include/libcamera/internal/v4l2_subdevice.h
> +++ b/include/libcamera/internal/v4l2_subdevice.h
> @@ -140,6 +140,8 @@ public:
>  		return formats({ pad, 0 });
>  	}
>  
> +	int bindContext(unsigned int context);
> +

Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>

>  	int getFormat(const Stream &stream, V4L2SubdeviceFormat
> *format,
>  		      Whence whence = ActiveFormat);
>  	int getFormat(unsigned int pad, V4L2SubdeviceFormat *format,
> diff --git a/src/libcamera/v4l2_subdevice.cpp
> b/src/libcamera/v4l2_subdevice.cpp
> index
> ce6b0d38cbf1a598e6dc73de8cb36ba245ed73f9..9038783bd2975b6b2063a5d6089
> 0e2de82c4aa0d 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -1351,6 +1351,24 @@ std::optional<ColorSpace>
> V4L2Subdevice::toColorSpace(const v4l2_mbus_framefmt &
>  	return V4L2Device::toColorSpace(format, colourEncoding);
>  }
>  
> +/**
> + * \brief Bind a subdevice to a media device context
> + * \param[in] context The file descriptor that identifies the media
> device
> + * context
> + * \return 0 on success or a negative error code otherwise
> + */
> +int V4L2Subdevice::bindContext(unsigned int context)
> +{
> +	struct v4l2_subdev_bind_context c = {};
> +	c.context_fd = context;
> +
> +	int ret = ioctl(VIDIOC_SUBDEV_BIND_CONTEXT, &c);
> +	if (ret)
> +		LOG(V4L2, Error) << "Unable to bind context: " <<
> strerror(-ret);
> +
> +	return ret;
> +}
> +
>  /**
>   * \brief Retrieve the image format set on one of the V4L2 subdevice
> streams
>   * \param[in] stream The stream the format is to be retrieved from

Patch
diff mbox series

diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h
index fa2a4a21eefbb792c69fa6357934d607a009d11a..f65a587c3034df014390863319a350c8fbd4ed5a 100644
--- a/include/libcamera/internal/v4l2_subdevice.h
+++ b/include/libcamera/internal/v4l2_subdevice.h
@@ -140,6 +140,8 @@  public:
 		return formats({ pad, 0 });
 	}
 
+	int bindContext(unsigned int context);
+
 	int getFormat(const Stream &stream, V4L2SubdeviceFormat *format,
 		      Whence whence = ActiveFormat);
 	int getFormat(unsigned int pad, V4L2SubdeviceFormat *format,
diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
index ce6b0d38cbf1a598e6dc73de8cb36ba245ed73f9..9038783bd2975b6b2063a5d60890e2de82c4aa0d 100644
--- a/src/libcamera/v4l2_subdevice.cpp
+++ b/src/libcamera/v4l2_subdevice.cpp
@@ -1351,6 +1351,24 @@  std::optional<ColorSpace> V4L2Subdevice::toColorSpace(const v4l2_mbus_framefmt &
 	return V4L2Device::toColorSpace(format, colourEncoding);
 }
 
+/**
+ * \brief Bind a subdevice to a media device context
+ * \param[in] context The file descriptor that identifies the media device
+ * context
+ * \return 0 on success or a negative error code otherwise
+ */
+int V4L2Subdevice::bindContext(unsigned int context)
+{
+	struct v4l2_subdev_bind_context c = {};
+	c.context_fd = context;
+
+	int ret = ioctl(VIDIOC_SUBDEV_BIND_CONTEXT, &c);
+	if (ret)
+		LOG(V4L2, Error) << "Unable to bind context: " << strerror(-ret);
+
+	return ret;
+}
+
 /**
  * \brief Retrieve the image format set on one of the V4L2 subdevice streams
  * \param[in] stream The stream the format is to be retrieved from