media: vivid: use vb2_queue_change_type
authorTomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Mon, 12 Apr 2021 11:02:11 +0000 (13:02 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 8 Jun 2021 10:06:55 +0000 (12:06 +0200)
Use the new vb2_queue_change_type() function in .vidioc_reqbufs and
.vidioc_create_bufs instead of changing the queue type manually in
vidioc_s_fmt_vbi_cap() and vidioc_s_fmt_sliced_vbi_cap().

This allows for a more consistent behavior, as .vidioc_reqbufs and
.vidioc_create_bufs are when the queue will become "busy".

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/test-drivers/vivid/vivid-core.c
drivers/media/test-drivers/vivid/vivid-vbi-cap.c

index ca0ebf6..d2bd265 100644 (file)
@@ -656,6 +656,46 @@ static const struct v4l2_file_operations vivid_radio_fops = {
        .unlocked_ioctl = video_ioctl2,
 };
 
+static int vidioc_reqbufs(struct file *file, void *priv,
+                         struct v4l2_requestbuffers *p)
+{
+       struct video_device *vdev = video_devdata(file);
+       int r;
+
+       /*
+        * Sliced and raw VBI capture share the same queue so we must
+        * change the type.
+        */
+       if (p->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE ||
+           p->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
+               r = vb2_queue_change_type(vdev->queue, p->type);
+               if (r)
+                       return r;
+       }
+
+       return vb2_ioctl_reqbufs(file, priv, p);
+}
+
+static int vidioc_create_bufs(struct file *file, void *priv,
+                             struct v4l2_create_buffers *p)
+{
+       struct video_device *vdev = video_devdata(file);
+       int r;
+
+       /*
+        * Sliced and raw VBI capture share the same queue so we must
+        * change the type.
+        */
+       if (p->format.type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE ||
+           p->format.type == V4L2_BUF_TYPE_VBI_CAPTURE) {
+               r = vb2_queue_change_type(vdev->queue, p->format.type);
+               if (r)
+                       return r;
+       }
+
+       return vb2_ioctl_create_bufs(file, priv, p);
+}
+
 static const struct v4l2_ioctl_ops vivid_ioctl_ops = {
        .vidioc_querycap                = vidioc_querycap,
 
@@ -717,8 +757,8 @@ static const struct v4l2_ioctl_ops vivid_ioctl_ops = {
        .vidioc_g_fbuf                  = vidioc_g_fbuf,
        .vidioc_s_fbuf                  = vidioc_s_fbuf,
 
-       .vidioc_reqbufs                 = vb2_ioctl_reqbufs,
-       .vidioc_create_bufs             = vb2_ioctl_create_bufs,
+       .vidioc_reqbufs                 = vidioc_reqbufs,
+       .vidioc_create_bufs             = vidioc_create_bufs,
        .vidioc_prepare_buf             = vb2_ioctl_prepare_buf,
        .vidioc_querybuf                = vb2_ioctl_querybuf,
        .vidioc_qbuf                    = vb2_ioctl_qbuf,
index 387df4f..b65b02e 100644 (file)
@@ -257,7 +257,6 @@ int vidioc_s_fmt_vbi_cap(struct file *file, void *priv,
                return ret;
        if (f->type != V4L2_BUF_TYPE_VBI_CAPTURE && vb2_is_busy(&dev->vb_vbi_cap_q))
                return -EBUSY;
-       dev->vbi_cap_dev.queue->type = V4L2_BUF_TYPE_VBI_CAPTURE;
        return 0;
 }
 
@@ -324,7 +323,6 @@ int vidioc_s_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format
        if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE && vb2_is_busy(&dev->vb_vbi_cap_q))
                return -EBUSY;
        dev->service_set_cap = vbi->service_set;
-       dev->vbi_cap_dev.queue->type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
        return 0;
 }