* [PATCH] media: videobuf2-v4l2.c: add vb2_queue_change_type() helper
@ 2021-04-12 8:12 Tomi Valkeinen
2021-04-12 8:43 ` Hans Verkuil
0 siblings, 1 reply; 2+ messages in thread
From: Tomi Valkeinen @ 2021-04-12 8:12 UTC (permalink / raw)
To: Tomasz Figa, Marek Szyprowski, Mauro Carvalho Chehab,
Hans Verkuil, linux-media, Laurent Pinchart
Cc: Tomi Valkeinen
On some platforms a video device can capture either video data or
metadata. The driver can implement vidioc functions for both video and
metadata, and use a single vb2_queue for the buffers. However, vb2_queue
requires choosing a single buffer type, which conflicts with the idea of
capturing either video or metadata.
The buffer type of vb2_queue can be changed, but it's not obvious how
this should be done in the drivers. To help this, add a new helper
function vb2_queue_change_type() which ensures the correct checks and
documents how it can be used.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
drivers/media/common/videobuf2/videobuf2-v4l2.c | 14 ++++++++++++++
include/media/videobuf2-v4l2.h | 15 +++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index 7e96f67c60ba..2988bb38ceb1 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -939,6 +939,20 @@ void vb2_queue_release(struct vb2_queue *q)
}
EXPORT_SYMBOL_GPL(vb2_queue_release);
+int vb2_queue_change_type(struct vb2_queue *q, unsigned int type)
+{
+ if (type == q->type)
+ return 0;
+
+ if (vb2_is_busy(q))
+ return -EBUSY;
+
+ q->type = type;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(vb2_queue_change_type);
+
__poll_t vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
{
struct video_device *vfd = video_devdata(file);
diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
index c203047eb834..3e604c1b5e1b 100644
--- a/include/media/videobuf2-v4l2.h
+++ b/include/media/videobuf2-v4l2.h
@@ -261,6 +261,21 @@ int __must_check vb2_queue_init_name(struct vb2_queue *q, const char *name);
*/
void vb2_queue_release(struct vb2_queue *q);
+/**
+ * vb2_queue_change_type() - change the type of an inactive vb2_queue
+ * @q: pointer to &struct vb2_queue with videobuf2 queue.
+ *
+ * This function changes the type of the vb2_queue. This is only possible
+ * if the queue is not busy (i.e. no buffers have been queued).
+ *
+ * vb2_queue_change_type() can be used to support multiple buffer types using
+ * the same queue. The driver can implement v4l2_ioctl_ops.vidioc_reqbufs and
+ * v4l2_ioctl_ops.vidioc_create_bufs functions and call vb2_queue_change_type()
+ * before calling vb2_ioctl_reqbufs() or vb2_ioctl_create_bufs(), and thus
+ * "lock" the buffer type until the buffers have been released.
+ */
+int vb2_queue_change_type(struct vb2_queue *q, unsigned int type);
+
/**
* vb2_poll() - implements poll userspace operation
* @q: pointer to &struct vb2_queue with videobuf2 queue.
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] media: videobuf2-v4l2.c: add vb2_queue_change_type() helper
2021-04-12 8:12 [PATCH] media: videobuf2-v4l2.c: add vb2_queue_change_type() helper Tomi Valkeinen
@ 2021-04-12 8:43 ` Hans Verkuil
0 siblings, 0 replies; 2+ messages in thread
From: Hans Verkuil @ 2021-04-12 8:43 UTC (permalink / raw)
To: Tomi Valkeinen, Tomasz Figa, Marek Szyprowski,
Mauro Carvalho Chehab, linux-media, Laurent Pinchart
Hi Tomi,
On 12/04/2021 10:12, Tomi Valkeinen wrote:
> On some platforms a video device can capture either video data or
> metadata. The driver can implement vidioc functions for both video and
> metadata, and use a single vb2_queue for the buffers. However, vb2_queue
> requires choosing a single buffer type, which conflicts with the idea of
> capturing either video or metadata.
>
> The buffer type of vb2_queue can be changed, but it's not obvious how
> this should be done in the drivers. To help this, add a new helper
> function vb2_queue_change_type() which ensures the correct checks and
> documents how it can be used.
>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
> drivers/media/common/videobuf2/videobuf2-v4l2.c | 14 ++++++++++++++
> include/media/videobuf2-v4l2.h | 15 +++++++++++++++
> 2 files changed, 29 insertions(+)
>
> diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
> index 7e96f67c60ba..2988bb38ceb1 100644
> --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
> +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
> @@ -939,6 +939,20 @@ void vb2_queue_release(struct vb2_queue *q)
> }
> EXPORT_SYMBOL_GPL(vb2_queue_release);
>
> +int vb2_queue_change_type(struct vb2_queue *q, unsigned int type)
> +{
> + if (type == q->type)
> + return 0;
> +
> + if (vb2_is_busy(q))
> + return -EBUSY;
> +
> + q->type = type;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(vb2_queue_change_type);
> +
> __poll_t vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
> {
> struct video_device *vfd = video_devdata(file);
> diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
> index c203047eb834..3e604c1b5e1b 100644
> --- a/include/media/videobuf2-v4l2.h
> +++ b/include/media/videobuf2-v4l2.h
> @@ -261,6 +261,21 @@ int __must_check vb2_queue_init_name(struct vb2_queue *q, const char *name);
> */
> void vb2_queue_release(struct vb2_queue *q);
>
> +/**
> + * vb2_queue_change_type() - change the type of an inactive vb2_queue
> + * @q: pointer to &struct vb2_queue with videobuf2 queue.
> + *
> + * This function changes the type of the vb2_queue. This is only possible
> + * if the queue is not busy (i.e. no buffers have been queued).
queued -> allocated
> + *
> + * vb2_queue_change_type() can be used to support multiple buffer types using
> + * the same queue. The driver can implement v4l2_ioctl_ops.vidioc_reqbufs and
> + * v4l2_ioctl_ops.vidioc_create_bufs functions and call vb2_queue_change_type()
> + * before calling vb2_ioctl_reqbufs() or vb2_ioctl_create_bufs(), and thus
> + * "lock" the buffer type until the buffers have been released.
> + */
> +int vb2_queue_change_type(struct vb2_queue *q, unsigned int type);
> +
> /**
> * vb2_poll() - implements poll userspace operation
> * @q: pointer to &struct vb2_queue with videobuf2 queue.
>
Can you also update vivid to use this function? That would also be a good test.
Check with v4l2-compliance as well. It is not impossible that some changes
have to be made to v4l2-compliance, ping me on irc if that's the case.
Regards,
Hans
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-12 8:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 8:12 [PATCH] media: videobuf2-v4l2.c: add vb2_queue_change_type() helper Tomi Valkeinen
2021-04-12 8:43 ` Hans Verkuil
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.