← Documents Documentation/userspace-api/media/v4l/func-poll.rst GitHub 원문 ↗

Linux 6.18.37 · Userspace API / Media / V4L

V4L2 poll()

Capture·output buffer, read/write와 V4L2 event의 poll 준비 상태를 설명합니다.

Source pathDocumentation/userspace-api/media/v4l/func-poll.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

func-poll.rst:1-113

`poll()`은 capture와 output buffer 준비, read/write 가능 상태와 V4L2 event를 각각 revents flag로 보고하며 POLLPRI-only 대기는 streaming을 시작하지 않습니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

이벤트 대기 선언

1-30

`v4l2-poll`은 file descriptor에서 event가 발생할 때까지 기다리는 synchronous I/O 함수입니다. `<sys/poll.h>`를 포함하고 `int poll(struct pollfd *ufds, unsigned int nfds, int timeout)`을 호출합니다.

`poll()` 핵심 입력
항목설명
`ufds`감시할 descriptor와 요청 event를 담은 `pollfd` 배열입니다.
`nfds``ufds` 배열의 원소 수입니다.
`timeout`최대 대기 시간입니다.

일반 POSIX `poll()` 계약에 따라 descriptor 배열과 timeout을 전달합니다.

.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. c:namespace:: V4L

.. _func-poll:

***********
V4L2 poll()
***********

Name
====

v4l2-poll - Wait for some event on a file descriptor

Synopsis
========

.. code-block:: c

    #include <sys/poll.h>

.. c:function:: int poll( struct pollfd *ufds, unsigned int nfds, int timeout )

Arguments
=========


Description
===========

Streaming, read/write와 event 준비 상태

31-89

Application은 `poll()`로 capture data가 준비되거나 output 장치가 data를 받을 수 있을 때까지 실행을 멈출 수 있습니다. Streaming I/O에서는 capture buffer가 채워져 `VIDIOC_DQBUF`로 꺼낼 수 있거나 output 장치가 `VIDIOC_QBUF`로 새 buffer를 받을 수 있을 때까지 기다립니다. Capture outgoing queue에 buffer가 이미 있거나 display incoming queue가 가득 차지 않았으면 즉시 반환합니다.

`pollfd.revents` 의미
항목설명
`POLLIN | POLLRDNORM`Capture data 또는 dequeuable buffer가 준비됐습니다.
`POLLOUT | POLLWRNORM`Output 장치가 새 buffer나 write data를 받을 수 있습니다.
`POLLPRI``VIDIOC_DQEVENT`로 읽을 V4L2 event가 발생했습니다.
`POLLERR`Capture streaming을 시작하지 않았거나 시작했지만 capture buffer를 queue하지 않은 상태입니다.

Capture, output, 우선 event와 잘못된 streaming 상태를 구분합니다.

성공하면 `revents`가 0이 아닌 descriptor 수, timeout이면 0, 실패하면 -1과 `errno`를 반환합니다. `VIDIOC_STREAMON`을 호출하지 않았으면 성공 반환과 함께 `POLLERR`가 설정됩니다. Capture에서 STREAMON 후 QBUF가 없을 때도 POLLERR입니다. Output의 같은 상황에서는 새 buffer를 받을 수 있으므로 `POLLOUT | POLLWRNORM`이 설정됩니다.

Read I/O가 협상됐고 아직 capture하지 않는 driver라면 `poll()`이 capture를 시작합니다. 실패하면 POLLERR이고, 성공하면 data를 읽을 수 있을 때까지 기다립니다. Continuous capture 장치는 data가 이미 있으면 즉시 반환할 수 있습니다. Write I/O가 협상됐고 아직 streaming하지 않으면 `poll()`이 streaming을 시작하고 non-blocking `write()`가 가능할 때까지 기다립니다.

Application이 `events`에 `POLLPRI`만 설정해 V4L2 event에만 관심을 표시하면 `poll()`은 아직 멈춘 streaming을 시작하지 않습니다. 따라서 buffer와 무관하게 event만 기다릴 수 있습니다. Read, write 또는 streaming I/O를 구현하는 모든 driver는 `poll()`도 지원해야 합니다.

Streaming `poll()`
`events`가 POLLPRI만인지 확인Buffer event 요청이면 필요한 capture/streaming 시작Capture queue 또는 output capacity 대기Event 발생 시 `revents` 설정Descriptor 수, 0 timeout 또는 -1 반환

요청 event에 따라 capture 시작 여부와 반환 flag가 달라집니다.

With the :c:func:`poll()` function applications can suspend execution
until the driver has captured data or is ready to accept data for
output.

When streaming I/O has been negotiated this function waits until a
buffer has been filled by the capture device and can be dequeued with
the :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. For output devices this
function waits until the device is ready to accept a new buffer to be
queued up with the :ref:`VIDIOC_QBUF <VIDIOC_QBUF>` ioctl for
display. When buffers are already in the outgoing queue of the driver
(capture) or the incoming queue isn't full (display) the function
returns immediately.

On success :c:func:`poll()` returns the number of file descriptors
that have been selected (that is, file descriptors for which the
``revents`` field of the respective ``struct pollfd`` structure
is non-zero). Capture devices set the ``POLLIN`` and ``POLLRDNORM``
flags in the ``revents`` field, output devices the ``POLLOUT`` and
``POLLWRNORM`` flags. When the function timed out it returns a value of
zero, on failure it returns -1 and the ``errno`` variable is set
appropriately. When the application did not call
:ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` the :c:func:`poll()`
function succeeds, but sets the ``POLLERR`` flag in the ``revents``
field. When the application has called
:ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` for a capture device but
hasn't yet called :ref:`VIDIOC_QBUF <VIDIOC_QBUF>`, the
:c:func:`poll()` function succeeds and sets the ``POLLERR`` flag in
the ``revents`` field. For output devices this same situation will cause
:c:func:`poll()` to succeed as well, but it sets the ``POLLOUT`` and
``POLLWRNORM`` flags in the ``revents`` field.

If an event occurred (see :ref:`VIDIOC_DQEVENT`)
then ``POLLPRI`` will be set in the ``revents`` field and
:c:func:`poll()` will return.

When use of the :c:func:`read()` function has been negotiated and the
driver does not capture yet, the :c:func:`poll()` function starts
capturing. When that fails it returns a ``POLLERR`` as above. Otherwise
it waits until data has been captured and can be read. When the driver
captures continuously (as opposed to, for example, still images) the
function may return immediately.

When use of the :c:func:`write()` function has been negotiated and the
driver does not stream yet, the :c:func:`poll()` function starts
streaming. When that fails it returns a ``POLLERR`` as above. Otherwise
it waits until the driver is ready for a non-blocking
:c:func:`write()` call.

If the caller is only interested in events (just ``POLLPRI`` is set in
the ``events`` field), then :c:func:`poll()` will *not* start
streaming if the driver does not stream yet. This makes it possible to
just poll for events and not for buffers.

All drivers implementing the :c:func:`read()` or :c:func:`write()`
function or streaming I/O must also support the :c:func:`poll()`
function.

For more details see the :c:func:`poll()` manual page.

반환값과 오류

90-113

성공 시 non-zero `revents`를 가진 structure 수를 반환하고 timeout이면 0입니다. 오류 시 -1과 `errno`를 반환합니다.

`poll()` 오류
항목설명
`EBADF``ufds` 원소 하나 이상이 유효하지 않은 descriptor입니다.
`EBUSY`Driver가 여러 read/write stream을 지원하지 않고 장치가 이미 사용 중입니다.
`EFAULT``ufds`가 접근할 수 없는 memory 영역을 참조합니다.
`EINTR`Signal이 호출을 중단했습니다.
`EINVAL``nfds`가 `RLIMIT_NOFILE`을 넘었습니다. `getrlimit()`로 한도를 확인합니다.

Descriptor 배열과 system limit 관련 실패를 분류합니다.

Return Value
============

On success, :c:func:`poll()` returns the number structures which have
non-zero ``revents`` fields, or zero if the call timed out. On error -1
is returned, and the ``errno`` variable is set appropriately:

EBADF
    One or more of the ``ufds`` members specify an invalid file
    descriptor.

EBUSY
    The driver does not support multiple read or write streams and the
    device is already in use.

EFAULT
    ``ufds`` references an inaccessible memory area.

EINTR
    The call was interrupted by a signal.

EINVAL
    The ``nfds`` value exceeds the ``RLIMIT_NOFILE`` value. Use
    ``getrlimit()`` to obtain this value.