Commit 58d75f4b1ce26324b4d809b18f94819843a98731
Committed by
Mauro Carvalho Chehab
1 parent
50394e7369
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
[media] vb2: fix VBI/poll regression
The recent conversion of saa7134 to vb2 unconvered a poll() bug that broke the teletext applications alevt and mtt. These applications expect that calling poll() without having called VIDIOC_STREAMON will cause poll() to return POLLERR. That did not happen in vb2. This patch fixes that behavior. It also fixes what should happen when poll() is called when STREAMON is called but no buffers have been queued. In that case poll() will also return POLLERR, but only for capture queues since output queues will always return POLLOUT anyway in that situation. This brings the vb2 behavior in line with the old videobuf behavior. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Showing 2 changed files with 18 additions and 3 deletions Side-by-side Diff
drivers/media/v4l2-core/videobuf2-core.c
... | ... | @@ -971,6 +971,7 @@ |
971 | 971 | * to the userspace. |
972 | 972 | */ |
973 | 973 | req->count = allocated_buffers; |
974 | + q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type); | |
974 | 975 | |
975 | 976 | return 0; |
976 | 977 | } |
... | ... | @@ -1018,6 +1019,7 @@ |
1018 | 1019 | memset(q->plane_sizes, 0, sizeof(q->plane_sizes)); |
1019 | 1020 | memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx)); |
1020 | 1021 | q->memory = create->memory; |
1022 | + q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type); | |
1021 | 1023 | } |
1022 | 1024 | |
1023 | 1025 | num_buffers = min(create->count, VIDEO_MAX_FRAME - q->num_buffers); |
... | ... | @@ -1821,6 +1823,7 @@ |
1821 | 1823 | */ |
1822 | 1824 | list_add_tail(&vb->queued_entry, &q->queued_list); |
1823 | 1825 | q->queued_count++; |
1826 | + q->waiting_for_buffers = false; | |
1824 | 1827 | vb->state = VB2_BUF_STATE_QUEUED; |
1825 | 1828 | if (V4L2_TYPE_IS_OUTPUT(q->type)) { |
1826 | 1829 | /* |
... | ... | @@ -2287,6 +2290,7 @@ |
2287 | 2290 | * their normal dequeued state. |
2288 | 2291 | */ |
2289 | 2292 | __vb2_queue_cancel(q); |
2293 | + q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type); | |
2290 | 2294 | |
2291 | 2295 | dprintk(3, "successful\n"); |
2292 | 2296 | return 0; |
2293 | 2297 | |
... | ... | @@ -2605,10 +2609,17 @@ |
2605 | 2609 | } |
2606 | 2610 | |
2607 | 2611 | /* |
2608 | - * There is nothing to wait for if no buffer has been queued and the | |
2609 | - * queue isn't streaming, or if the error flag is set. | |
2612 | + * There is nothing to wait for if the queue isn't streaming, or if the | |
2613 | + * error flag is set. | |
2610 | 2614 | */ |
2611 | - if ((list_empty(&q->queued_list) && !vb2_is_streaming(q)) || q->error) | |
2615 | + if (!vb2_is_streaming(q) || q->error) | |
2616 | + return res | POLLERR; | |
2617 | + /* | |
2618 | + * For compatibility with vb1: if QBUF hasn't been called yet, then | |
2619 | + * return POLLERR as well. This only affects capture queues, output | |
2620 | + * queues will always initialize waiting_for_buffers to false. | |
2621 | + */ | |
2622 | + if (q->waiting_for_buffers) | |
2612 | 2623 | return res | POLLERR; |
2613 | 2624 | |
2614 | 2625 | /* |
include/media/videobuf2-core.h
... | ... | @@ -380,6 +380,9 @@ |
380 | 380 | * @start_streaming_called: start_streaming() was called successfully and we |
381 | 381 | * started streaming. |
382 | 382 | * @error: a fatal error occurred on the queue |
383 | + * @waiting_for_buffers: used in poll() to check if vb2 is still waiting for | |
384 | + * buffers. Only set for capture queues if qbuf has not yet been | |
385 | + * called since poll() needs to return POLLERR in that situation. | |
383 | 386 | * @fileio: file io emulator internal data, used only if emulator is active |
384 | 387 | * @threadio: thread io internal data, used only if thread is active |
385 | 388 | */ |
... | ... | @@ -417,6 +420,7 @@ |
417 | 420 | unsigned int streaming:1; |
418 | 421 | unsigned int start_streaming_called:1; |
419 | 422 | unsigned int error:1; |
423 | + unsigned int waiting_for_buffers:1; | |
420 | 424 | |
421 | 425 | struct vb2_fileio_data *fileio; |
422 | 426 | struct vb2_threadio_data *threadio; |