Merge remote-tracking branch 'mmc-uh/next'
[deliverable/linux.git] / Documentation / media / uapi / v4l / func-poll.rst
CommitLineData
5377d91f
MH
1.. -*- coding: utf-8; mode: rst -*-
2
3.. _func-poll:
4
5***********
6V4L2 poll()
7***********
8
15e7d615 9Name
586027ce 10====
5377d91f 11
586027ce 12v4l2-poll - Wait for some event on a file descriptor
5377d91f 13
15e7d615
MCC
14
15Synopsis
5377d91f
MH
16========
17
18.. code-block:: c
19
20 #include <sys/poll.h>
21
22
1b81f010 23.. c:function:: int poll( struct pollfd *ufds, unsigned int nfds, int timeout )
e9de2d89 24 :name: v4l2-poll
586027ce 25
15e7d615 26Arguments
586027ce
MCC
27=========
28
29
30
15e7d615 31Description
5377d91f
MH
32===========
33
760c7010 34With the :ref:`poll() <func-poll>` function applications can suspend execution
5377d91f
MH
35until the driver has captured data or is ready to accept data for
36output.
37
38When streaming I/O has been negotiated this function waits until a
39buffer has been filled by the capture device and can be dequeued with
af4a4d0d 40the :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. For output devices this
5377d91f 41function waits until the device is ready to accept a new buffer to be
7347081e 42queued up with the :ref:`VIDIOC_QBUF` ioctl for
5377d91f
MH
43display. When buffers are already in the outgoing queue of the driver
44(capture) or the incoming queue isn't full (display) the function
45returns immediately.
46
760c7010 47On success :ref:`poll() <func-poll>` returns the number of file descriptors
5377d91f 48that have been selected (that is, file descriptors for which the
acf309a2 49``revents`` field of the respective :c:func:`struct pollfd` structure
5377d91f
MH
50is non-zero). Capture devices set the ``POLLIN`` and ``POLLRDNORM``
51flags in the ``revents`` field, output devices the ``POLLOUT`` and
52``POLLWRNORM`` flags. When the function timed out it returns a value of
53zero, on failure it returns -1 and the ``errno`` variable is set
54appropriately. When the application did not call
760c7010 55:ref:`VIDIOC_STREAMON` the :ref:`poll() <func-poll>`
5377d91f
MH
56function succeeds, but sets the ``POLLERR`` flag in the ``revents``
57field. When the application has called
7347081e
MCC
58:ref:`VIDIOC_STREAMON` for a capture device but
59hasn't yet called :ref:`VIDIOC_QBUF`, the
760c7010 60:ref:`poll() <func-poll>` function succeeds and sets the ``POLLERR`` flag in
5377d91f 61the ``revents`` field. For output devices this same situation will cause
760c7010 62:ref:`poll() <func-poll>` to succeed as well, but it sets the ``POLLOUT`` and
5377d91f
MH
63``POLLWRNORM`` flags in the ``revents`` field.
64
7347081e 65If an event occurred (see :ref:`VIDIOC_DQEVENT`)
5377d91f 66then ``POLLPRI`` will be set in the ``revents`` field and
760c7010 67:ref:`poll() <func-poll>` will return.
5377d91f 68
760c7010
MCC
69When use of the :ref:`read() <func-read>` function has been negotiated and the
70driver does not capture yet, the :ref:`poll() <func-poll>` function starts
5377d91f
MH
71capturing. When that fails it returns a ``POLLERR`` as above. Otherwise
72it waits until data has been captured and can be read. When the driver
73captures continuously (as opposed to, for example, still images) the
74function may return immediately.
75
760c7010
MCC
76When use of the :ref:`write() <func-write>` function has been negotiated and the
77driver does not stream yet, the :ref:`poll() <func-poll>` function starts
5377d91f
MH
78streaming. When that fails it returns a ``POLLERR`` as above. Otherwise
79it waits until the driver is ready for a non-blocking
760c7010 80:ref:`write() <func-write>` call.
5377d91f
MH
81
82If the caller is only interested in events (just ``POLLPRI`` is set in
760c7010 83the ``events`` field), then :ref:`poll() <func-poll>` will *not* start
5377d91f
MH
84streaming if the driver does not stream yet. This makes it possible to
85just poll for events and not for buffers.
86
760c7010
MCC
87All drivers implementing the :ref:`read() <func-read>` or :ref:`write() <func-write>`
88function or streaming I/O must also support the :ref:`poll() <func-poll>`
5377d91f
MH
89function.
90
760c7010 91For more details see the :ref:`poll() <func-poll>` manual page.
5377d91f
MH
92
93
15e7d615 94Return Value
5377d91f
MH
95============
96
760c7010 97On success, :ref:`poll() <func-poll>` returns the number structures which have
5377d91f
MH
98non-zero ``revents`` fields, or zero if the call timed out. On error -1
99is returned, and the ``errno`` variable is set appropriately:
100
101EBADF
102 One or more of the ``ufds`` members specify an invalid file
103 descriptor.
104
105EBUSY
106 The driver does not support multiple read or write streams and the
107 device is already in use.
108
109EFAULT
110 ``ufds`` references an inaccessible memory area.
111
112EINTR
113 The call was interrupted by a signal.
114
115EINVAL
116 The ``nfds`` argument is greater than ``OPEN_MAX``.
This page took 0.051073 seconds and 5 git commands to generate.