Skip to contentSkip to conversation

vb2: regression fix for vbi capture & poll

RFC PATCH In review Hans Verkuil 2 participants 3 messages Sep 16, 2014 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 vb2: regression fix for vbi capture & poll

(My proposal to fix this. Note that it is untested, I plan to do that this evening)

Commit 9241650d62f7 broke vbi capture applications that expect POLLERR to be returned if STREAMON wasn't called.

Rather than checking whether buffers were queued AND vb2 was not yet streaming, just check whether streaming is in progress and return POLLERR if not.

This change makes it impossible to poll in one thread and call STREAMON in another, but doing that breaks existing applications and is also not according to the spec. So be it.

drivers/media/v4l2-core/videobuf2-core.c +3 -3
index 7e6aff6..0452fb2 100644
@@ -2583,10 +2583,10 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
 	}
 
 	/*
-	 * There is nothing to wait for if no buffer has been queued and the
-	 * queue isn't streaming, or if the error flag is set.
+	 * There is nothing to wait for if the queue isn't streaming, or if
+	 * the error flag is set.
 	 */
-	if ((list_empty(&q->queued_list) && !vb2_is_streaming(q)) || q->error)
+	if (!vb2_is_streaming(q) || q->error)
 		return res | POLLERR;
 
 	/*
#1 lore raw

Em Tue, 16 Sep 2014 11:28:16 +0200
Hans Verkuil <[email protected]> escreveu:

Quoted 21 lines

(My proposal to fix this. Note that it is untested, I plan to do that this evening)

Commit 9241650d62f7 broke vbi capture applications that expect POLLERR to be returned if STREAMON wasn't called.

Rather than checking whether buffers were queued AND vb2 was not yet streaming, just check whether streaming is in progress and return POLLERR if not.

This change makes it impossible to poll in one thread and call STREAMON in another, but doing that breaks existing applications and is also not according to the spec. So be it.

drivers/media/v4l2-core/videobuf2-core.c +0 -0
index 7e6aff6..0452fb2 100644
@@ -2583,10 +2583,10 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
 	}

drivers/media/v4l2-core/videobuf2-core.c unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait) · line 2590

Quoted 10 lines
drivers/media/v4l2-core/videobuf2-core.c +3 -3
 
 	/*
-	 * There is nothing to wait for if no buffer has been queued and the
-	 * queue isn't streaming, or if the error flag is set.
+	 * There is nothing to wait for if the queue isn't streaming, or if
+	 * the error flag is set.
 	 */
-	if ((list_empty(&q->queued_list) && !vb2_is_streaming(q)) || q->error)
+	if (!vb2_is_streaming(q) || q->error)
 		return res | POLLERR;

This makes the code even more different than what VB1 does. I suspect that this will likely cause even more regressions.

The following (untested) patch seems to be what matches best what VB1 does, and are likely to cause less harm, but needs test of course.

drivers/media/v4l2-core/videobuf2-core.c +3 -0
index 5b808e25fc09..0d86526cbcb0 100644
@@ -2586,6 +2586,9 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
 	 * There is nothing to wait for if no buffer has been queued and the
 	 * queue isn't streaming, or if the error flag is set.
 	 */
+	if (!vb2_is_streaming(q))
+		vb2_internal_streamon(q, q->type);
+
 	if ((list_empty(&q->queued_list) && !vb2_is_streaming(q)) || q->error)
 		return res | POLLERR;
 
#2 lore raw
Quoted 46 lines · Mauro Carvalho Chehab

Em Tue, 16 Sep 2014 11:28:16 +0200
Hans Verkuil <[email protected]> escreveu:

Quoted 21 lines

(My proposal to fix this. Note that it is untested, I plan to do that this evening)

Commit 9241650d62f7 broke vbi capture applications that expect POLLERR to be returned if STREAMON wasn't called.

Rather than checking whether buffers were queued AND vb2 was not yet streaming, just check whether streaming is in progress and return POLLERR if not.

This change makes it impossible to poll in one thread and call STREAMON in another, but doing that breaks existing applications and is also not according to the spec. So be it.

drivers/media/v4l2-core/videobuf2-core.c +0 -0
index 7e6aff6..0452fb2 100644
@@ -2583,10 +2583,10 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
 	}

drivers/media/v4l2-core/videobuf2-core.c unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait) · line 2590

Quoted 10 lines
drivers/media/v4l2-core/videobuf2-core.c +3 -3
 
 	/*
-	 * There is nothing to wait for if no buffer has been queued and the
-	 * queue isn't streaming, or if the error flag is set.
+	 * There is nothing to wait for if the queue isn't streaming, or if
+	 * the error flag is set.
 	 */
-	if ((list_empty(&q->queued_list) && !vb2_is_streaming(q)) || q->error)
+	if (!vb2_is_streaming(q) || q->error)
 		return res | POLLERR;

This makes the code even more different than what VB1 does. I suspect that this will likely cause even more regressions.

The following (untested) patch seems to be what matches best what VB1 does, and are likely to cause less harm, but needs test of course.

drivers/media/v4l2-core/videobuf2-core.c +0 -0
index 5b808e25fc09..0d86526cbcb0 100644

drivers/media/v4l2-core/videobuf2-core.c unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait) · line 2591

Quoted 6 lines
drivers/media/v4l2-core/videobuf2-core.c +3 -0
@@ -2586,6 +2586,9 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
 	 * There is nothing to wait for if no buffer has been queued and the
 	 * queue isn't streaming, or if the error flag is set.
 	 */
+	if (!vb2_is_streaming(q))
+		vb2_internal_streamon(q, q->type);
+

As mentioned in my previous email, this is certainly not what vb1 does. VB1 returns POLLERR and does not start streaming, that's what I saw when debugging this yesterday. The automatic streaming when poll is called is valid only if REQBUFS was never called since it assumes read() mode.

Regards,

Hans

Quoted 8 lines
drivers/media/v4l2-core/videobuf2-core.c +0 -1
 	if ((list_empty(&q->queued_list) && !vb2_is_streaming(q)) || q->error)
 		return res | POLLERR;
 
--

To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html