Skip to contentSkip to conversation

au0828 vb2 conversion

PATCH Superseded Shuah Khan 3 participants 13 messages Dec 18, 2014 – Jan 22, 2015 Media (V4L/DVB)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Shuah Khan

author
#0 lore raw

v2 cover au0828 vb2 conversion

This patch series includes patch v2 of the au0828 vb2 conversion, removing video and vbi buffer timeout handling, and a patch to not set fmt.pix.priv.

The following work is in progress and will be as separate patches:
- removing users and using v4l2_fh_is_singular_file() instead.
- Changing dynamic allocation of video device structs to static which will reduce the overhead to allocate at register time and deallocating at unregister.

Shuah Khan (3):
media: au0828 - convert to use videobuf2
media: au0828 change to not zero out fmt.pix.priv
media: au0828 remove video and vbi buffer timeout work-around

 drivers/media/usb/au0828/Kconfig        |   2 +-
 drivers/media/usb/au0828/au0828-cards.c |   2 +-
 drivers/media/usb/au0828/au0828-vbi.c   | 122 ++--
 drivers/media/usb/au0828/au0828-video.c | 994 +++++++++++---------------------
 drivers/media/usb/au0828/au0828.h       |  64 +-
 5 files changed, 414 insertions(+), 770 deletions(-)
Signature · 1 line
2.1.0
author
#1 lore raw

PATCH v2 1/3 media: au0828 - convert to use videobuf2

Convert au0828 to use videobuf2. Tested with NTSC. Tested video and vbi devices with xawtv, tvtime, and vlc. Ran v4l2-compliance to ensure there are no new regressions in video and vbi now has 3 fewer failures.

video before:
test VIDIOC_G_FMT: FAIL 3 failures
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

Video after:
test VIDIOC_G_FMT: FAIL 3 failures
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

vbi before:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: FAIL test VIDIOC_EXPBUF: FAIL
test USERPTR: FAIL
Total: 72, Succeeded: 66, Failed: 6, Warnings: 0

vbi after:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK (Not Supported) test USERPTR: OK
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

---
 drivers/media/usb/au0828/Kconfig        |   2 +-
 drivers/media/usb/au0828/au0828-cards.c |   2 +-
 drivers/media/usb/au0828/au0828-vbi.c   | 122 ++--
 drivers/media/usb/au0828/au0828-video.c | 949 +++++++++++++-------------------
 drivers/media/usb/au0828/au0828.h       |  61 +-
 5 files changed, 444 insertions(+), 692 deletions(-)
drivers/media/usb/au0828/Kconfig +1 -1
index 1d410ac..78b797e 100644
@@ -4,7 +4,7 @@ config VIDEO_AU0828
 	depends on I2C && INPUT && DVB_CORE && USB
 	select I2C_ALGOBIT
 	select VIDEO_TVEEPROM
-	select VIDEOBUF_VMALLOC
+	select VIDEOBUF2_VMALLOC
 	select DVB_AU8522_DTV if MEDIA_SUBDRV_AUTOSELECT
 	select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT
 	select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT
drivers/media/usb/au0828/au0828-cards.c +1 -1
index 9eb77ac..ae2e563 100644
@@ -39,7 +39,7 @@ static void hvr950q_cs5340_audio(void *priv, int enable)
 struct au0828_board au0828_boards[] = {
 	[AU0828_BOARD_UNKNOWN] = {
 		.name	= "Unknown board",
-		.tuner_type = UNSET,
+		.tuner_type = -1U,
 		.tuner_addr = ADDR_UNSET,
 	},
 	[AU0828_BOARD_HAUPPAUGE_HVR850] = {
drivers/media/usb/au0828/au0828-vbi.c +39 -83

150 lines not on this page · raw message

drivers/media/usb/au0828/au0828-video.c +371 -578

1,423 lines not on this page · raw message

drivers/media/usb/au0828/au0828.h +32 -29

124 lines not on this page · raw message

Signature · 1 line
2.1.0
author
#10 lore raw

PATCH v2 3/3 media: au0828 remove video and vbi buffer timeout work-around

In reply to Shuah Khan

au0828 does video and vbi buffer timeout handling to prevent applications such as tvtime from hanging by ensuring that the video frames continue to be delivered even when the ITU-656 input isn't receiving any data. This work-around is complex as it introduces set and clear tier code paths in start/stop streaming, and close interfaces. After the vb2 conversion, the timeout handling is introducing instability as well as feeding too many blank green screens, resulting in degraded video quality. Without this timeout handling, both xawtv, and tvtime are working well with good quality video.

---
 drivers/media/usb/au0828/au0828-video.c | 103 +-------------------------------
 drivers/media/usb/au0828/au0828.h       |   5 --
 2 files changed, 1 insertion(+), 107 deletions(-)
drivers/media/usb/au0828/au0828-video.c +1 -102
index ef49b2e..3bdf132 100644
@@ -593,15 +593,6 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
 					outp = NULL;
 				else
 					outp = vb2_plane_vaddr(&buf->vb, 0);
-
-				/* As long as isoc traffic is arriving, keep
-				   resetting the timer */
-				if (dev->vid_timeout_running)
-					mod_timer(&dev->vid_timeout,
-						  jiffies + (HZ / 10));
-				if (dev->vbi_timeout_running)
-					mod_timer(&dev->vbi_timeout,
-						  jiffies + (HZ / 10));
 			}
 
 			if (buf != NULL) {
@@ -804,15 +795,9 @@ int au0828_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
 			return rc;
 		}
 
-		if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+		if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
 			v4l2_device_call_all(&dev->v4l2_dev, 0, video,
 						s_stream, 1);
-			dev->vid_timeout_running = 1;
-			mod_timer(&dev->vid_timeout, jiffies + (HZ / 10));
-		} else if (vq->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
-			dev->vbi_timeout_running = 1;
-			mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10));
-		}
 	}
 	dev->streaming_users++;
 	return rc;
@@ -851,9 +836,6 @@ static void au0828_stop_streaming(struct vb2_queue *vq)
 		(AUVI_INPUT(i).audio_setup)(dev, 0);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
-
-	dev->vid_timeout_running = 0;
-	del_timer_sync(&dev->vid_timeout);
 }
 
 void au0828_stop_vbi_streaming(struct vb2_queue *vq)
@@ -882,9 +864,6 @@ void au0828_stop_vbi_streaming(struct vb2_queue *vq)
 		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
-
-	dev->vbi_timeout_running = 0;
-	del_timer_sync(&dev->vbi_timeout);
 }
 
 static struct vb2_ops au0828_video_qops = {
@@ -917,56 +896,6 @@ void au0828_analog_unregister(struct au0828_dev *dev)
 	mutex_unlock(&au0828_sysfs_lock);
 }
 
-/* This function ensures that video frames continue to be delivered even if
-   the ITU-656 input isn't receiving any data (thereby preventing applications
-   such as tvtime from hanging) */
-static void au0828_vid_buffer_timeout(unsigned long data)
-{
-	struct au0828_dev *dev = (struct au0828_dev *) data;
-	struct au0828_dmaqueue *dma_q = &dev->vidq;
-	struct au0828_buffer *buf;
-	unsigned char *vid_data;
-	unsigned long flags = 0;
-
-	spin_lock_irqsave(&dev->slock, flags);
-
-	buf = dev->isoc_ctl.buf;
-	if (buf != NULL) {
-		vid_data = vb2_plane_vaddr(&buf->vb, 0);
-		memset(vid_data, 0x00, buf->length); /* Blank green frame */
-		buffer_filled(dev, dma_q, buf);
-	}
-	get_next_buf(dma_q, &buf);
-
-	if (dev->vid_timeout_running == 1)
-		mod_timer(&dev->vid_timeout, jiffies + (HZ / 10));
-
-	spin_unlock_irqrestore(&dev->slock, flags);
-}
-
-static void au0828_vbi_buffer_timeout(unsigned long data)
-{
-	struct au0828_dev *dev = (struct au0828_dev *) data;
-	struct au0828_dmaqueue *dma_q = &dev->vbiq;
-	struct au0828_buffer *buf;
-	unsigned char *vbi_data;
-	unsigned long flags = 0;
-
-	spin_lock_irqsave(&dev->slock, flags);
-
-	buf = dev->isoc_ctl.vbi_buf;
-	if (buf != NULL) {
-		vbi_data = vb2_plane_vaddr(&buf->vb, 0);
-		memset(vbi_data, 0x00, buf->length);
-		vbi_buffer_filled(dev, dma_q, buf);
-	}
-	vbi_get_next_buf(dma_q, &buf);
-
-	if (dev->vbi_timeout_running == 1)
-		mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10));
-	spin_unlock_irqrestore(&dev->slock, flags);
-}
-
 static int au0828_v4l2_open(struct file *filp)
 {
 	struct video_device *vdev = video_devdata(filp);
@@ -1016,7 +945,6 @@ static int au0828_v4l2_close(struct file *filp)
 {
 	int ret;
 	struct au0828_dev *dev = video_drvdata(filp);
-	struct video_device *vdev = video_devdata(filp);
 
 	dprintk(1,
 		"%s called std_set %d dev_state %d stream users %d users %d\n",
@@ -1024,17 +952,6 @@ static int au0828_v4l2_close(struct file *filp)
 		dev->streaming_users, dev->users);
 
 	mutex_lock(&dev->lock);
-	if (vdev->vfl_type == VFL_TYPE_GRABBER && dev->vid_timeout_running) {
-		/* Cancel timeout thread in case they didn't call streamoff */
-		dev->vid_timeout_running = 0;
-		del_timer_sync(&dev->vid_timeout);
-	} else if (vdev->vfl_type == VFL_TYPE_VBI &&
-			dev->vbi_timeout_running) {
-		/* Cancel timeout thread in case they didn't call streamoff */
-		dev->vbi_timeout_running = 0;
-		del_timer_sync(&dev->vbi_timeout);
-	}
-
 	if (dev->dev_state == DEV_DISCONNECTED)
 		goto end;
 
@@ -1626,11 +1543,6 @@ void au0828_v4l2_suspend(struct au0828_dev *dev)
 			}
 		}
 	}
-
-	if (dev->vid_timeout_running)
-		del_timer_sync(&dev->vid_timeout);
-	if (dev->vbi_timeout_running)
-		del_timer_sync(&dev->vbi_timeout);
 }
 
 void au0828_v4l2_resume(struct au0828_dev *dev)
@@ -1644,11 +1556,6 @@ void au0828_v4l2_resume(struct au0828_dev *dev)
 		au0828_init_tuner(dev);
 	}
 
-	if (dev->vid_timeout_running)
-		mod_timer(&dev->vid_timeout, jiffies + (HZ / 10));
-	if (dev->vbi_timeout_running)
-		mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10));
-
 	/* If we were doing ac97 instead of i2s, it would go here...*/
 	au0828_i2s_init(dev);
 
@@ -1817,14 +1724,6 @@ int au0828_analog_register(struct au0828_dev *dev,
 	INIT_LIST_HEAD(&dev->vidq.active);
 	INIT_LIST_HEAD(&dev->vbiq.active);
 
-	dev->vid_timeout.function = au0828_vid_buffer_timeout;
-	dev->vid_timeout.data = (unsigned long) dev;
-	init_timer(&dev->vid_timeout);
-
-	dev->vbi_timeout.function = au0828_vbi_buffer_timeout;
-	dev->vbi_timeout.data = (unsigned long) dev;
-	init_timer(&dev->vbi_timeout);
-
 	dev->width = NTSC_STD_W;
 	dev->height = NTSC_STD_H;
 	dev->field_size = dev->width * dev->height;
drivers/media/usb/au0828/au0828.h +0 -5
index eb15187..9dac92e 100644
@@ -221,11 +221,6 @@ struct au0828_dev {
 	unsigned int frame_count;
 	unsigned int vbi_frame_count;
 
-	struct timer_list vid_timeout;
-	int vid_timeout_running;
-	struct timer_list vbi_timeout;
-	int vbi_timeout_running;
-
 	int users;
 	int streaming_users;
 
Signature · 1 line
2.1.0
author
#5 lore raw

PATCH v2 2/3 media: au0828 change to not zero out fmt.pix.priv

In reply to Shuah Khan

There is no need to zero out fmt.pix.priv in vidioc_g_fmt_vid_cap() vidioc_try_fmt_vid_cap(), and vidioc_s_fmt_vid_cap(). Remove it.

---
 drivers/media/usb/au0828/au0828-video.c | 2 --
 1 file changed, 2 deletions(-)
drivers/media/usb/au0828/au0828-video.c +0 -2
index 3011ca8..ef49b2e 100644
@@ -1104,7 +1104,6 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
 	format->fmt.pix.sizeimage = width * height * 2;
 	format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
 	format->fmt.pix.field = V4L2_FIELD_INTERLACED;
-	format->fmt.pix.priv = 0;
 
 	if (cmd == VIDIOC_TRY_FMT)
 		return 0;
@@ -1189,7 +1188,6 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
 	f->fmt.pix.sizeimage = dev->frame_size;
 	f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; /* NTSC/PAL */
 	f->fmt.pix.field = V4L2_FIELD_INTERLACED;
-	f->fmt.pix.priv = 0;
 	return 0;
 }
 
Signature · 1 line
2.1.0
Acked-by on v2 2/3
#6 lore raw

Re: [PATCH v2 2/3] media: au0828 change to not zero out fmt.pix.priv

My first code review of the new year, so let's start with a simple one to avoid taxing my brain cells (that are still in vacation mode) too much...

Quoted 4 lines · Shuah Khan

There is no need to zero out fmt.pix.priv in vidioc_g_fmt_vid_cap() vidioc_try_fmt_vid_cap(), and vidioc_s_fmt_vid_cap(). Remove it.

Happy New Year!

Hans

Quoted 25 lines
---
 drivers/media/usb/au0828/au0828-video.c | 2 --
 1 file changed, 2 deletions(-)
drivers/media/usb/au0828/au0828-video.c +0 -2
index 3011ca8..ef49b2e 100644
@@ -1104,7 +1104,6 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
 	format->fmt.pix.sizeimage = width * height * 2;
 	format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
 	format->fmt.pix.field = V4L2_FIELD_INTERLACED;
-	format->fmt.pix.priv = 0;
 
 	if (cmd == VIDIOC_TRY_FMT)
 		return 0;
@@ -1189,7 +1188,6 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
 	f->fmt.pix.sizeimage = dev->frame_size;
 	f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; /* NTSC/PAL */
 	f->fmt.pix.field = V4L2_FIELD_INTERLACED;
-	f->fmt.pix.priv = 0;
 	return 0;
 }
 
#11 lore raw

Re: [PATCH v2 3/3] media: au0828 remove video and vbi buffer timeout work-around

In reply to Shuah Khan
Quoted 8 lines · Shuah Khan

au0828 does video and vbi buffer timeout handling to prevent applications such as tvtime from hanging by ensuring that the video frames continue to be delivered even when the ITU-656 input isn't receiving any data. This work-around is complex as it introduces set and clear tier code paths in start/stop streaming, and close interfaces. After the vb2 conversion, the timeout handling is introducing instability as well as feeding too many blank green screens, resulting in degraded video quality.

Why would this result in degraded video quality? And which instability exactly?

Quoted 2 lines

Without this timeout handling, both xawtv, and tvtime are working well with good quality video.

Erm, tvtime without the recent 'tvtime: don't block indefinitely waiting for frames' patch will not work well with au0828 without the timeout code if there is no valid video data.

This should at minimum be mentioned in the commit log.

Especially if this fixes other issues as you mentioned in the log I am all for it. But others will probably object to this.

Regards,

Hans

Quoted 203 lines
---
 drivers/media/usb/au0828/au0828-video.c | 103 +-------------------------------
 drivers/media/usb/au0828/au0828.h       |   5 --
 2 files changed, 1 insertion(+), 107 deletions(-)
drivers/media/usb/au0828/au0828-video.c +1 -102
index ef49b2e..3bdf132 100644
@@ -593,15 +593,6 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
 					outp = NULL;
 				else
 					outp = vb2_plane_vaddr(&buf->vb, 0);
-
-				/* As long as isoc traffic is arriving, keep
-				   resetting the timer */
-				if (dev->vid_timeout_running)
-					mod_timer(&dev->vid_timeout,
-						  jiffies + (HZ / 10));
-				if (dev->vbi_timeout_running)
-					mod_timer(&dev->vbi_timeout,
-						  jiffies + (HZ / 10));
 			}
 
 			if (buf != NULL) {
@@ -804,15 +795,9 @@ int au0828_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
 			return rc;
 		}
 
-		if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+		if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
 			v4l2_device_call_all(&dev->v4l2_dev, 0, video,
 						s_stream, 1);
-			dev->vid_timeout_running = 1;
-			mod_timer(&dev->vid_timeout, jiffies + (HZ / 10));
-		} else if (vq->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
-			dev->vbi_timeout_running = 1;
-			mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10));
-		}
 	}
 	dev->streaming_users++;
 	return rc;
@@ -851,9 +836,6 @@ static void au0828_stop_streaming(struct vb2_queue *vq)
 		(AUVI_INPUT(i).audio_setup)(dev, 0);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
-
-	dev->vid_timeout_running = 0;
-	del_timer_sync(&dev->vid_timeout);
 }
 
 void au0828_stop_vbi_streaming(struct vb2_queue *vq)
@@ -882,9 +864,6 @@ void au0828_stop_vbi_streaming(struct vb2_queue *vq)
 		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
-
-	dev->vbi_timeout_running = 0;
-	del_timer_sync(&dev->vbi_timeout);
 }
 
 static struct vb2_ops au0828_video_qops = {
@@ -917,56 +896,6 @@ void au0828_analog_unregister(struct au0828_dev *dev)
 	mutex_unlock(&au0828_sysfs_lock);
 }
 
-/* This function ensures that video frames continue to be delivered even if
-   the ITU-656 input isn't receiving any data (thereby preventing applications
-   such as tvtime from hanging) */
-static void au0828_vid_buffer_timeout(unsigned long data)
-{
-	struct au0828_dev *dev = (struct au0828_dev *) data;
-	struct au0828_dmaqueue *dma_q = &dev->vidq;
-	struct au0828_buffer *buf;
-	unsigned char *vid_data;
-	unsigned long flags = 0;
-
-	spin_lock_irqsave(&dev->slock, flags);
-
-	buf = dev->isoc_ctl.buf;
-	if (buf != NULL) {
-		vid_data = vb2_plane_vaddr(&buf->vb, 0);
-		memset(vid_data, 0x00, buf->length); /* Blank green frame */
-		buffer_filled(dev, dma_q, buf);
-	}
-	get_next_buf(dma_q, &buf);
-
-	if (dev->vid_timeout_running == 1)
-		mod_timer(&dev->vid_timeout, jiffies + (HZ / 10));
-
-	spin_unlock_irqrestore(&dev->slock, flags);
-}
-
-static void au0828_vbi_buffer_timeout(unsigned long data)
-{
-	struct au0828_dev *dev = (struct au0828_dev *) data;
-	struct au0828_dmaqueue *dma_q = &dev->vbiq;
-	struct au0828_buffer *buf;
-	unsigned char *vbi_data;
-	unsigned long flags = 0;
-
-	spin_lock_irqsave(&dev->slock, flags);
-
-	buf = dev->isoc_ctl.vbi_buf;
-	if (buf != NULL) {
-		vbi_data = vb2_plane_vaddr(&buf->vb, 0);
-		memset(vbi_data, 0x00, buf->length);
-		vbi_buffer_filled(dev, dma_q, buf);
-	}
-	vbi_get_next_buf(dma_q, &buf);
-
-	if (dev->vbi_timeout_running == 1)
-		mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10));
-	spin_unlock_irqrestore(&dev->slock, flags);
-}
-
 static int au0828_v4l2_open(struct file *filp)
 {
 	struct video_device *vdev = video_devdata(filp);
@@ -1016,7 +945,6 @@ static int au0828_v4l2_close(struct file *filp)
 {
 	int ret;
 	struct au0828_dev *dev = video_drvdata(filp);
-	struct video_device *vdev = video_devdata(filp);
 
 	dprintk(1,
 		"%s called std_set %d dev_state %d stream users %d users %d\n",
@@ -1024,17 +952,6 @@ static int au0828_v4l2_close(struct file *filp)
 		dev->streaming_users, dev->users);
 
 	mutex_lock(&dev->lock);
-	if (vdev->vfl_type == VFL_TYPE_GRABBER && dev->vid_timeout_running) {
-		/* Cancel timeout thread in case they didn't call streamoff */
-		dev->vid_timeout_running = 0;
-		del_timer_sync(&dev->vid_timeout);
-	} else if (vdev->vfl_type == VFL_TYPE_VBI &&
-			dev->vbi_timeout_running) {
-		/* Cancel timeout thread in case they didn't call streamoff */
-		dev->vbi_timeout_running = 0;
-		del_timer_sync(&dev->vbi_timeout);
-	}
-
 	if (dev->dev_state == DEV_DISCONNECTED)
 		goto end;
 
@@ -1626,11 +1543,6 @@ void au0828_v4l2_suspend(struct au0828_dev *dev)
 			}
 		}
 	}
-
-	if (dev->vid_timeout_running)
-		del_timer_sync(&dev->vid_timeout);
-	if (dev->vbi_timeout_running)
-		del_timer_sync(&dev->vbi_timeout);
 }
 
 void au0828_v4l2_resume(struct au0828_dev *dev)
@@ -1644,11 +1556,6 @@ void au0828_v4l2_resume(struct au0828_dev *dev)
 		au0828_init_tuner(dev);
 	}
 
-	if (dev->vid_timeout_running)
-		mod_timer(&dev->vid_timeout, jiffies + (HZ / 10));
-	if (dev->vbi_timeout_running)
-		mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10));
-
 	/* If we were doing ac97 instead of i2s, it would go here...*/
 	au0828_i2s_init(dev);
 
@@ -1817,14 +1724,6 @@ int au0828_analog_register(struct au0828_dev *dev,
 	INIT_LIST_HEAD(&dev->vidq.active);
 	INIT_LIST_HEAD(&dev->vbiq.active);
 
-	dev->vid_timeout.function = au0828_vid_buffer_timeout;
-	dev->vid_timeout.data = (unsigned long) dev;
-	init_timer(&dev->vid_timeout);
-
-	dev->vbi_timeout.function = au0828_vbi_buffer_timeout;
-	dev->vbi_timeout.data = (unsigned long) dev;
-	init_timer(&dev->vbi_timeout);
-
 	dev->width = NTSC_STD_W;
 	dev->height = NTSC_STD_H;
 	dev->field_size = dev->width * dev->height;
drivers/media/usb/au0828/au0828.h +0 -5
index eb15187..9dac92e 100644
@@ -221,11 +221,6 @@ struct au0828_dev {
 	unsigned int frame_count;
 	unsigned int vbi_frame_count;
 
-	struct timer_list vid_timeout;
-	int vid_timeout_running;
-	struct timer_list vbi_timeout;
-	int vbi_timeout_running;
-
 	int users;
 	int streaming_users;
 
#2 lore raw

Re: [PATCH v2 1/3] media: au0828 - convert to use videobuf2

In reply to Shuah Khan
Quoted 53 lines · Shuah Khan

Convert au0828 to use videobuf2. Tested with NTSC. Tested video and vbi devices with xawtv, tvtime, and vlc. Ran v4l2-compliance to ensure there are no new regressions in video and vbi now has 3 fewer failures.

video before:
test VIDIOC_G_FMT: FAIL 3 failures
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

Video after:
test VIDIOC_G_FMT: FAIL 3 failures
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

vbi before:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: FAIL test VIDIOC_EXPBUF: FAIL
test USERPTR: FAIL
Total: 72, Succeeded: 66, Failed: 6, Warnings: 0

vbi after:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK (Not Supported) test USERPTR: OK
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

---
 drivers/media/usb/au0828/Kconfig        |   2 +-
 drivers/media/usb/au0828/au0828-cards.c |   2 +-
 drivers/media/usb/au0828/au0828-vbi.c   | 122 ++--
 drivers/media/usb/au0828/au0828-video.c | 949 +++++++++++++-------------------
 drivers/media/usb/au0828/au0828.h       |  61 +-
 5 files changed, 444 insertions(+), 692 deletions(-)
drivers/media/usb/au0828/Kconfig +1 -1
index 1d410ac..78b797e 100644
@@ -4,7 +4,7 @@ config VIDEO_AU0828
 	depends on I2C && INPUT && DVB_CORE && USB
 	select I2C_ALGOBIT
 	select VIDEO_TVEEPROM
-	select VIDEOBUF_VMALLOC
+	select VIDEOBUF2_VMALLOC
 	select DVB_AU8522_DTV if MEDIA_SUBDRV_AUTOSELECT
 	select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT
 	select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT
drivers/media/usb/au0828/au0828-cards.c +0 -0
index 9eb77ac..ae2e563 100644

drivers/media/usb/au0828/au0828-cards.c static void hvr950q_cs5340_audio(void *priv, int enable) · line 45

Quoted 8 lines
drivers/media/usb/au0828/au0828-cards.c +1 -1
@@ -39,7 +39,7 @@ static void hvr950q_cs5340_audio(void *priv, int enable)
 struct au0828_board au0828_boards[] = {
 	[AU0828_BOARD_UNKNOWN] = {
 		.name	= "Unknown board",
-		.tuner_type = UNSET,
+		.tuner_type = -1U,
 		.tuner_addr = ADDR_UNSET,
 	},
 	[AU0828_BOARD_HAUPPAUGE_HVR850] = {

I would split off this au0828-cards.c change into a separate patch. It has nothing to do with the vb2 conversion.

Regards,

Hans

#4 lore raw

Re: [PATCH v2 1/3] media: au0828 - convert to use videobuf2

In reply to Shuah Khan

Hi Shuah,

Looks good! I do have a few small comments, see below.

Quoted 90 lines · Shuah Khan

Convert au0828 to use videobuf2. Tested with NTSC. Tested video and vbi devices with xawtv, tvtime, and vlc. Ran v4l2-compliance to ensure there are no new regressions in video and vbi now has 3 fewer failures.

video before:
test VIDIOC_G_FMT: FAIL 3 failures
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

Video after:
test VIDIOC_G_FMT: FAIL 3 failures
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

vbi before:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: FAIL test VIDIOC_EXPBUF: FAIL
test USERPTR: FAIL
Total: 72, Succeeded: 66, Failed: 6, Warnings: 0

vbi after:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK (Not Supported) test USERPTR: OK
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

---
 drivers/media/usb/au0828/Kconfig        |   2 +-
 drivers/media/usb/au0828/au0828-cards.c |   2 +-
 drivers/media/usb/au0828/au0828-vbi.c   | 122 ++--
 drivers/media/usb/au0828/au0828-video.c | 949 +++++++++++++-------------------
 drivers/media/usb/au0828/au0828.h       |  61 +-
 5 files changed, 444 insertions(+), 692 deletions(-)
drivers/media/usb/au0828/au0828-video.c +14 -14
index 5f337b1..3011ca8 100644
+void au0828_analog_unregister(struct au0828_dev *dev)
 {
-	switch (fh->type) {
-	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-		return AU0828_RESOURCE_VIDEO;
-	case V4L2_BUF_TYPE_VBI_CAPTURE:
-		return AU0828_RESOURCE_VBI;
-	default:
-		BUG();
-		return 0;
-	}
+	dprintk(1, "au0828_analog_unregister called\n");
+	mutex_lock(&au0828_sysfs_lock);
+
+	if (dev->vdev)
+		video_unregister_device(dev->vdev);
+	if (dev->vbi_dev)
+		video_unregister_device(dev->vbi_dev);
+
+	mutex_unlock(&au0828_sysfs_lock);
 }
 
 /* This function ensures that video frames continue to be delivered even if
@@ -951,8 +932,8 @@ static void au0828_vid_buffer_timeout(unsigned long data)
 
 	buf = dev->isoc_ctl.buf;
 	if (buf != NULL) {
-		vid_data = videobuf_to_vmalloc(&buf->vb);
-		memset(vid_data, 0x00, buf->vb.size); /* Blank green frame */
+		vid_data = vb2_plane_vaddr(&buf->vb, 0);
+		memset(vid_data, 0x00, buf->length); /* Blank green frame */
 		buffer_filled(dev, dma_q, buf);
 	}
 	get_next_buf(dma_q, &buf);
@@ -975,8 +956,8 @@ static void au0828_vbi_buffer_timeout(unsigned long data)
 
 	buf = dev->isoc_ctl.vbi_buf;
 	if (buf != NULL) {
-		vbi_data = videobuf_to_vmalloc(&buf->vb);
-		memset(vbi_data, 0x00, buf->vb.size);
+		vbi_data = vb2_plane_vaddr(&buf->vb, 0);
+		memset(vbi_data, 0x00, buf->length);
 		vbi_buffer_filled(dev, dma_q, buf);
 	}
 	vbi_get_next_buf(dma_q, &buf);
@@ -986,14 +967,12 @@ static void au0828_vbi_buffer_timeout(unsigned long data)
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
 
-
 static int au0828_v4l2_open(struct file *filp)

drivers/media/usb/au0828/au0828-video.c static void au0828_vbi_buffer_timeout(unsigned long data) · line 978

Quoted 10 lines
drivers/media/usb/au0828/au0828-video.c +1 -2
 {
-	int ret = 0;
 	struct video_device *vdev = video_devdata(filp);
 	struct au0828_dev *dev = video_drvdata(filp);
-	struct au0828_fh *fh;
 	int type;
+	int ret = 0;
 
 	switch (vdev->vfl_type) {
 	case VFL_TYPE_GRABBER:

This switch can be removed.

Quoted 5 lines
drivers/media/usb/au0828/au0828-video.c +0 -1
@@ -1957,17 +1693,23 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
 	.vidioc_g_audio             = vidioc_g_audio,
 	.vidioc_s_audio             = vidioc_s_audio,
 	.vidioc_cropcap             = vidioc_cropcap,
-	.vidioc_reqbufs             = vidioc_reqbufs,

drivers/media/usb/au0828/au0828-video.c static const struct v4l2_ioctl_ops video_ioctl_ops = { · line 1702

Quoted 10 lines
drivers/media/usb/au0828/au0828-video.c +7 -3
-	.vidioc_querybuf            = vidioc_querybuf,
-	.vidioc_qbuf                = vidioc_qbuf,
-	.vidioc_dqbuf               = vidioc_dqbuf,
+
+	.vidioc_reqbufs             = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs         = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf         = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf            = vb2_ioctl_querybuf,
+	.vidioc_qbuf                = vb2_ioctl_qbuf,
+	.vidioc_dqbuf               = vb2_ioctl_dqbuf,

Add vidioc_expbuf as well. That is now supported by videobuf2-vmalloc.

Quoted 32 lines
drivers/media/usb/au0828/au0828-video.c +18 -2
+
 	.vidioc_s_std               = vidioc_s_std,
 	.vidioc_g_std               = vidioc_g_std,
 	.vidioc_enum_input          = vidioc_enum_input,
 	.vidioc_g_input             = vidioc_g_input,
 	.vidioc_s_input             = vidioc_s_input,
-	.vidioc_streamon            = vidioc_streamon,
-	.vidioc_streamoff           = vidioc_streamoff,
+
+	.vidioc_streamon            = vb2_ioctl_streamon,
+	.vidioc_streamoff           = vb2_ioctl_streamoff,
+
 	.vidioc_g_tuner             = vidioc_g_tuner,
 	.vidioc_s_tuner             = vidioc_s_tuner,
 	.vidioc_g_frequency         = vidioc_g_frequency,
@@ -1988,6 +1730,42 @@ static const struct video_device au0828_video_template = {
 	.tvnorms                    = V4L2_STD_NTSC_M | V4L2_STD_PAL_M,
 };
 
+static int au0828_vb2_setup(struct au0828_dev *dev)
+{
+	int rc;
+	struct vb2_queue *q;
+
+	/* Setup Videobuf2 for Video capture */
+	q = &dev->vb_vidq;
+	q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
+	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+	q->drv_priv = dev;
+	q->buf_struct_size = sizeof(struct au0828_buffer);
+	q->ops = &au0828_video_qops;

drivers/media/usb/au0828/au0828-video.c static const struct video_device au0828_video_template = { · line 1755

Quoted 10 lines
drivers/media/usb/au0828/au0828-video.c +10 -0
+	q->mem_ops = &vb2_vmalloc_memops;
+
+	rc = vb2_queue_init(q);
+	if (rc < 0)
+		return rc;
+
+	/* Setup Videobuf2 for VBI capture */
+	q = &dev->vb_vbiq;
+	q->type = V4L2_BUF_TYPE_VBI_CAPTURE;
+	q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR;

Add VB2_DMABUF here as well.

Admittedly, nobody will use it, but it comes for free, so why not?

Quoted 62 lines
drivers/media/usb/au0828/au0828-video.c +29 -2
+	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+	q->drv_priv = dev;
+	q->buf_struct_size = sizeof(struct au0828_buffer);
+	q->ops = &au0828_vbi_qops;
+	q->mem_ops = &vb2_vmalloc_memops;
+
+	rc = vb2_queue_init(q);
+	if (rc < 0)
+		return rc;
+
+	return 0;
+}
+
 /**************************************************************************/
 
 int au0828_analog_register(struct au0828_dev *dev,
@@ -2039,9 +1817,7 @@ int au0828_analog_register(struct au0828_dev *dev,
 
 	/* init video dma queues */
 	INIT_LIST_HEAD(&dev->vidq.active);
-	INIT_LIST_HEAD(&dev->vidq.queued);
 	INIT_LIST_HEAD(&dev->vbiq.active);
-	INIT_LIST_HEAD(&dev->vbiq.queued);
 
 	dev->vid_timeout.function = au0828_vid_buffer_timeout;
 	dev->vid_timeout.data = (unsigned long) dev;
@@ -2078,18 +1854,34 @@ int au0828_analog_register(struct au0828_dev *dev,
 		goto err_vdev;
 	}
 
+	mutex_init(&dev->vb_queue_lock);
+	mutex_init(&dev->vb_vbi_queue_lock);
+
 	/* Fill the video capture device struct */
 	*dev->vdev = au0828_video_template;
 	dev->vdev->v4l2_dev = &dev->v4l2_dev;
 	dev->vdev->lock = &dev->lock;
+	dev->vdev->queue = &dev->vb_vidq;
+	dev->vdev->queue->lock = &dev->vb_queue_lock;
 	strcpy(dev->vdev->name, "au0828a video");
 
 	/* Setup the VBI device */
 	*dev->vbi_dev = au0828_video_template;
 	dev->vbi_dev->v4l2_dev = &dev->v4l2_dev;
 	dev->vbi_dev->lock = &dev->lock;
+	dev->vbi_dev->queue = &dev->vb_vbiq;
+	dev->vbi_dev->queue->lock = &dev->vb_vbi_queue_lock;
 	strcpy(dev->vbi_dev->name, "au0828a vbi");
 
+	/* initialize videobuf2 stuff */
+	retval = au0828_vb2_setup(dev);
+	if (retval != 0) {
+		dprintk(1, "unable to setup videobuf2 queues (error = %d).\n",
+			retval);
+		ret = -ENODEV;
+		goto err_vbi_dev;
+	}
+
 	/* Register the v4l2 device */
 	video_set_drvdata(dev->vdev, dev);
 	retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1);

drivers/media/usb/au0828/au0828-video.c int au0828_analog_register(struct au0828_dev *dev, · line 1905

Quoted 4 lines
drivers/media/usb/au0828/au0828-video.c +1 -0
@@ -2110,6 +1902,7 @@ int au0828_analog_register(struct au0828_dev *dev,
 		goto err_vbi_dev;
 	}
 
+

This spurious line can be removed.

drivers/media/usb/au0828/au0828-video.c int au0828_analog_register(struct au0828_dev *dev, · line 1908

Quoted 3 lines
drivers/media/usb/au0828/au0828-video.c +0 -0
 	dprintk(1, "%s completed!\n", __func__);
 
 	return 0;

Regards,

Hans

author
#3 lore raw

Re: [PATCH v2 1/3] media: au0828 - convert to use videobuf2

In reply to Hans Verkuil
Quoted 57 lines · Hans Verkuil
Quoted 56 lines · Shuah Khan

Convert au0828 to use videobuf2. Tested with NTSC. Tested video and vbi devices with xawtv, tvtime, and vlc. Ran v4l2-compliance to ensure there are no new regressions in video and vbi now has 3 fewer failures.

video before:
test VIDIOC_G_FMT: FAIL 3 failures
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

Video after:
test VIDIOC_G_FMT: FAIL 3 failures
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

vbi before:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: FAIL test VIDIOC_EXPBUF: FAIL
test USERPTR: FAIL
Total: 72, Succeeded: 66, Failed: 6, Warnings: 0

vbi after:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK (Not Supported) test USERPTR: OK
Total: 72, Succeeded: 69, Failed: 3, Warnings: 0

---
 drivers/media/usb/au0828/Kconfig        |   2 +-
 drivers/media/usb/au0828/au0828-cards.c |   2 +-
 drivers/media/usb/au0828/au0828-vbi.c   | 122 ++--
 drivers/media/usb/au0828/au0828-video.c | 949 +++++++++++++-------------------
 drivers/media/usb/au0828/au0828.h       |  61 +-
 5 files changed, 444 insertions(+), 692 deletions(-)
drivers/media/usb/au0828/Kconfig +1 -1
index 1d410ac..78b797e 100644
@@ -4,7 +4,7 @@ config VIDEO_AU0828
 	depends on I2C && INPUT && DVB_CORE && USB
 	select I2C_ALGOBIT
 	select VIDEO_TVEEPROM
-	select VIDEOBUF_VMALLOC
+	select VIDEOBUF2_VMALLOC
 	select DVB_AU8522_DTV if MEDIA_SUBDRV_AUTOSELECT
 	select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT
 	select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT
drivers/media/usb/au0828/au0828-cards.c +0 -0
index 9eb77ac..ae2e563 100644
@@ -39,7 +39,7 @@ static void hvr950q_cs5340_audio(void *priv, int enable)
 struct au0828_board au0828_boards[] = {
 	[AU0828_BOARD_UNKNOWN] = {
 		.name	= "Unknown board",
Quoted 9 lines

drivers/media/usb/au0828/au0828-cards.c static void hvr950q_cs5340_audio(void *priv, int enable) · line 45

Quoted 5 lines
drivers/media/usb/au0828/au0828-cards.c +1 -1
-		.tuner_type = UNSET,
+		.tuner_type = -1U,
 		.tuner_addr = ADDR_UNSET,
 	},
 	[AU0828_BOARD_HAUPPAUGE_HVR850] = {

I would split off this au0828-cards.c change into a separate patch. It has nothing to do with the vb2 conversion.

I will split this patch and add it to the series.

-- Shuah

Signature · 5 lines
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
[email protected] | (970) 217-8978
author
#12 lore raw

Re: [PATCH v2 3/3] media: au0828 remove video and vbi buffer timeout work-around

In reply to Hans Verkuil
Quoted 10 lines · Hans Verkuil
Quoted 8 lines · Shuah Khan

au0828 does video and vbi buffer timeout handling to prevent applications such as tvtime from hanging by ensuring that the video frames continue to be delivered even when the ITU-656 input isn't receiving any data. This work-around is complex as it introduces set and clear tier code paths in start/stop streaming, and close interfaces. After the vb2 conversion, the timeout handling is introducing instability as well as feeding too many blank green screens, resulting in degraded video quality.

Quoted 2 lines

Why would this result in degraded video quality? And which instability exactly?

What I noticed was that I was seeing a few too many green screens and I had to re-tune xawtv when the timeout code is in place. My thinking was that this timeout handling could be introducing blank green frames when there is no need. However, I can't reproduce the problem on 3.19-rc4 base which is what I am using to test the changes to the patch series. Hence, I am not positive if the timeout code indeed was doing anything bad.

Quoted 3 lines
Quoted 3 lines

Without this timeout handling, both xawtv, and tvtime are working well with good quality video.

I am seeing tvtime hangs.

Quoted 6 lines

Erm, tvtime without the recent 'tvtime: don't block indefinitely waiting for frames' patch will not work well with au0828 without the timeout code if there is no valid video data.

This should at minimum be mentioned in the commit log.

I will resend the patch with the updated commit log knowing full well that it might not be accepted.

I do have to re-cut the patch after the changes to address your comments on the vb2 conversion patch. It applies, with fuzz, so I decided to re-cut the patch.

thanks,
-- Shuah

Signature · 5 lines
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
[email protected] | (970) 217-8978
author
#7 lore raw

Re: [PATCH v2 2/3] media: au0828 change to not zero out fmt.pix.priv

In reply to Hans Verkuil
Quoted 11 lines · Hans Verkuil

My first code review of the new year, so let's start with a simple one to avoid taxing my brain cells (that are still in vacation mode) too much...

Quoted 4 lines · Shuah Khan

There is no need to zero out fmt.pix.priv in vidioc_g_fmt_vid_cap() vidioc_try_fmt_vid_cap(), and vidioc_s_fmt_vid_cap(). Remove it.

Thanks.

-- Shuah

Signature · 5 lines
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
[email protected] | (970) 217-8978
author
#8 lore raw

Re: [PATCH v2 2/3] media: au0828 change to not zero out fmt.pix.priv

In reply to Hans Verkuil
Quoted 4 lines · Hans Verkuil

My first code review of the new year, so let's start with a simple one to avoid taxing my brain cells (that are still in vacation mode) too much...

On 12/18/2014 05:20 PM, Shuah Khan wrote:

Quoted 8 lines
Quoted 4 lines

There is no need to zero out fmt.pix.priv in vidioc_g_fmt_vid_cap() vidioc_try_fmt_vid_cap(), and vidioc_s_fmt_vid_cap(). Remove it.

Happy New Year!

Hans,

Thanks. Just FYI, I dropped this patch from the patch v3 series since it has been Acked. Please note that that this version is what needs to be pulled in.

thanks,
-- Shuah

Signature · 5 lines
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
[email protected] | (970) 217-8978
Acked-by on v2 2/3
#9 lore raw

Re: [PATCH v2 2/3] media: au0828 change to not zero out fmt.pix.priv

In reply to Shuah Khan

Hi Shuah,

Thanks for the patch.

Quoted 4 lines · Shuah Khan

There is no need to zero out fmt.pix.priv in vidioc_g_fmt_vid_cap() vidioc_try_fmt_vid_cap(), and vidioc_s_fmt_vid_cap(). Remove it.

Regards,
--Prabhakar Lad

Quoted 27 lines
---
 drivers/media/usb/au0828/au0828-video.c | 2 --
 1 file changed, 2 deletions(-)
drivers/media/usb/au0828/au0828-video.c +0 -3
index 3011ca8..ef49b2e 100644
@@ -1104,7 +1104,6 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
        format->fmt.pix.sizeimage = width * height * 2;
        format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
        format->fmt.pix.field = V4L2_FIELD_INTERLACED;
-       format->fmt.pix.priv = 0;
 
        if (cmd == VIDIOC_TRY_FMT)
                return 0;
@@ -1189,7 +1188,6 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
        f->fmt.pix.sizeimage = dev->frame_size;
        f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; /* NTSC/PAL */
        f->fmt.pix.field = V4L2_FIELD_INTERLACED;
-       f->fmt.pix.priv = 0;
        return 0;
 }
 
--

2.1.0