Commit 95213ceb authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] videobuf2-core: also test for pending events

Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Acked-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Acked-by: default avatarPawel Osciak <pawel@osciak.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 0e17e9a9
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <media/v4l2-dev.h>
#include <media/v4l2-fh.h>
#include <media/v4l2-event.h>
#include <media/videobuf2-core.h> #include <media/videobuf2-core.h>
static int debug; static int debug;
...@@ -1642,15 +1645,28 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q); ...@@ -1642,15 +1645,28 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q);
* For OUTPUT queues, if a buffer is ready to be dequeued, the file descriptor * For OUTPUT queues, if a buffer is ready to be dequeued, the file descriptor
* will be reported as available for writing. * will be reported as available for writing.
* *
* If the driver uses struct v4l2_fh, then vb2_poll() will also check for any
* pending events.
*
* The return values from this function are intended to be directly returned * The return values from this function are intended to be directly returned
* from poll handler in driver. * from poll handler in driver.
*/ */
unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait) unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
{ {
struct video_device *vfd = video_devdata(file);
unsigned long req_events = poll_requested_events(wait); unsigned long req_events = poll_requested_events(wait);
unsigned long flags;
unsigned int ret;
struct vb2_buffer *vb = NULL; struct vb2_buffer *vb = NULL;
unsigned int res = 0;
unsigned long flags;
if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
struct v4l2_fh *fh = file->private_data;
if (v4l2_event_pending(fh))
res = POLLPRI;
else if (req_events & POLLPRI)
poll_wait(file, &fh->wait, wait);
}
/* /*
* Start file I/O emulator only if streaming API has not been used yet. * Start file I/O emulator only if streaming API has not been used yet.
...@@ -1658,19 +1674,17 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait) ...@@ -1658,19 +1674,17 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
if (q->num_buffers == 0 && q->fileio == NULL) { if (q->num_buffers == 0 && q->fileio == NULL) {
if (!V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_READ) && if (!V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_READ) &&
(req_events & (POLLIN | POLLRDNORM))) { (req_events & (POLLIN | POLLRDNORM))) {
ret = __vb2_init_fileio(q, 1); if (__vb2_init_fileio(q, 1))
if (ret) return res | POLLERR;
return POLLERR;
} }
if (V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_WRITE) && if (V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_WRITE) &&
(req_events & (POLLOUT | POLLWRNORM))) { (req_events & (POLLOUT | POLLWRNORM))) {
ret = __vb2_init_fileio(q, 0); if (__vb2_init_fileio(q, 0))
if (ret) return res | POLLERR;
return POLLERR;
/* /*
* Write to OUTPUT queue can be done immediately. * Write to OUTPUT queue can be done immediately.
*/ */
return POLLOUT | POLLWRNORM; return res | POLLOUT | POLLWRNORM;
} }
} }
...@@ -1678,7 +1692,7 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait) ...@@ -1678,7 +1692,7 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
* There is nothing to wait for if no buffers have already been queued. * There is nothing to wait for if no buffers have already been queued.
*/ */
if (list_empty(&q->queued_list)) if (list_empty(&q->queued_list))
return POLLERR; return res | POLLERR;
poll_wait(file, &q->done_wq, wait); poll_wait(file, &q->done_wq, wait);
...@@ -1693,10 +1707,11 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait) ...@@ -1693,10 +1707,11 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
if (vb && (vb->state == VB2_BUF_STATE_DONE if (vb && (vb->state == VB2_BUF_STATE_DONE
|| vb->state == VB2_BUF_STATE_ERROR)) { || vb->state == VB2_BUF_STATE_ERROR)) {
return (V4L2_TYPE_IS_OUTPUT(q->type)) ? POLLOUT | POLLWRNORM : return (V4L2_TYPE_IS_OUTPUT(q->type)) ?
POLLIN | POLLRDNORM; res | POLLOUT | POLLWRNORM :
res | POLLIN | POLLRDNORM;
} }
return 0; return res;
} }
EXPORT_SYMBOL_GPL(vb2_poll); EXPORT_SYMBOL_GPL(vb2_poll);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment