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

Linux 6.18.37 · Userspace API / Media / V4L

V4L2 write()

V4L2 output write의 시작 동작, data 부족 policy와 오류를 설명합니다.

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

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

1. 요약·해설

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

요약·해설

func-write.rst:1-81

`write()`는 첫 payload로 hardware output을 시작하며 data 공급이 늦으면 video·raw VBI·VPS·WSS는 반복하고 Teletext·Closed Caption은 blank line으로 대체합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2 .. c:namespace:: V4L
3
4 .. _func-write:
5
6 ************
7 V4L2 write()
8 ************
9
10 Name
11 ====
12
13 v4l2-write - Write to a V4L2 device
14
15 Synopsis
16 ========
17
18 .. code-block:: c
19
20 #include <unistd.h>
21
22 .. c:function:: ssize_t write( int fd, void *buf, size_t count )
23
24 Arguments
25 =========
26
27 ``fd``
28 File descriptor returned by :c:func:`open()`.
29
30 ``buf``
31 Buffer with data to be written
32
33 ``count``
34 Number of bytes at the buffer
35
36 Description
37 ===========
38
39 :c:func:`write()` writes up to ``count`` bytes to the device
40 referenced by the file descriptor ``fd`` from the buffer starting at
41 ``buf``. When the hardware outputs are not active yet, this function
42 enables them. When ``count`` is zero, :c:func:`write()` returns 0
43 without any other effect.
44
45 When the application does not provide more data in time, the previous
46 video frame, raw VBI image, sliced VPS or WSS data is displayed again.
47 Sliced Teletext or Closed Caption data is not repeated, the driver
48 inserts a blank line instead.
49
50 Return Value
51 ============
52
53 On success, the number of bytes written are returned. Zero indicates
54 nothing was written. On error, -1 is returned, and the ``errno``
55 variable is set appropriately. In this case the next write will start at
56 the beginning of a new frame. Possible error codes are:
57
58 EAGAIN
59 Non-blocking I/O has been selected using the
60 :ref:`O_NONBLOCK <func-open>` flag and no buffer space was
61 available to write the data immediately.
62
63 EBADF
64 ``fd`` is not a valid file descriptor or is not open for writing.
65
66 EBUSY
67 The driver does not support multiple write streams and the device is
68 already in use.
69
70 EFAULT
71 ``buf`` references an inaccessible memory area.
72
73 EINTR
74 The call was interrupted by a signal before any data was written.
75
76 EIO
77 I/O error. This indicates some hardware problem.
78
79 EINVAL
80 The :c:func:`write()` function is not supported by this driver,
81 not on this device, or generally not on this type of device.
82

3. 한국어 전문 번역

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

출력 쓰기 선언과 인자

1-35

`v4l2-write`는 V4L2 output 장치에 data를 씁니다. `<unistd.h>`를 포함하고 `ssize_t write(int fd, void *buf, size_t count)`를 호출합니다.

`write()` 인자
항목설명
`fd``open()`이 반환한 file descriptor입니다.
`buf`장치에 쓸 data가 들어 있는 buffer입니다.
`count`Buffer에 들어 있는 byte 수입니다.

출력 장치 descriptor, source buffer와 byte 수를 전달합니다.

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

.. _func-write:

************
V4L2 write()
************

Name
====

v4l2-write - Write to a V4L2 device

Synopsis
========

.. code-block:: c

    #include <unistd.h>

.. c:function:: ssize_t write( int fd, void *buf, size_t count )

Arguments
=========

``fd``
    File descriptor returned by :c:func:`open()`.

``buf``
     Buffer with data to be written

``count``
    Number of bytes at the buffer

출력 시작과 data 부족 처리

36-49

`write()`는 `buf`에서 최대 `count` byte를 `fd`가 가리키는 장치에 씁니다. Hardware output이 아직 활성화되지 않았다면 이 호출이 출력을 시작합니다. `count == 0`이면 다른 효과 없이 0을 반환합니다.

Application이 제때 다음 data를 제공하지 않으면 이전 video frame, raw VBI image, sliced VPS 또는 WSS data를 다시 표시합니다. Sliced Teletext와 Closed Caption data는 반복하지 않고 driver가 그 자리에 blank line을 삽입합니다.

출력 starvation 동작
항목설명
Video frame이전 frame을 다시 표시합니다.
Raw VBI image이전 image를 다시 표시합니다.
Sliced VPS / WSS이전 data를 다시 표시합니다.
Sliced Teletext반복하지 않고 blank line을 삽입합니다.
Closed Caption반복하지 않고 blank line을 삽입합니다.

Data 종류에 따라 이전 payload를 반복할지 blank line으로 대체할지가 달라집니다.

`write()` 출력 흐름
Output 장치를 `O_RDWR`로 open`write(fd, buf, count)` 호출비활성 hardware output 시작다음 payload를 제시간에 공급지연 시 repeat 또는 blank-line policy 적용

첫 data가 output을 활성화하고 이후 공급 지연은 payload 종류별 policy로 처리됩니다.

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

:c:func:`write()` writes up to ``count`` bytes to the device
referenced by the file descriptor ``fd`` from the buffer starting at
``buf``. When the hardware outputs are not active yet, this function
enables them. When ``count`` is zero, :c:func:`write()` returns 0
without any other effect.

When the application does not provide more data in time, the previous
video frame, raw VBI image, sliced VPS or WSS data is displayed again.
Sliced Teletext or Closed Caption data is not repeated, the driver
inserts a blank line instead.

반환값, frame 경계와 오류

50-81

성공하면 실제로 쓴 byte 수를 반환하며 0은 아무 data도 쓰지 않았음을 뜻합니다. 실패하면 -1과 적절한 `errno`를 반환하고, 다음 `write()`는 새 frame의 시작부터 기록합니다.

`write()` 오류
항목설명
`EAGAIN``O_NONBLOCK`을 사용했고 즉시 쓸 buffer 공간이 없습니다.
`EBADF``fd`가 유효하지 않거나 write로 열리지 않았습니다.
`EBUSY`Driver가 multiple write stream을 지원하지 않고 장치가 이미 사용 중입니다.
`EFAULT``buf`가 접근할 수 없는 memory를 참조합니다.
`EINTR`Data를 하나도 쓰기 전에 signal이 호출을 중단했습니다.
`EIO`Hardware 문제가 발생했습니다.
`EINVAL`해당 driver, device 또는 device 종류가 `write()`를 지원하지 않습니다.

Buffer 공간, descriptor, stream 점유, memory와 hardware 문제를 구분합니다.

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

On success, the number of bytes written are returned. Zero indicates
nothing was written. On error, -1 is returned, and the ``errno``
variable is set appropriately. In this case the next write will start at
the beginning of a new frame. Possible error codes are:

EAGAIN
    Non-blocking I/O has been selected using the
    :ref:`O_NONBLOCK <func-open>` flag and no buffer space was
    available to write the data immediately.

EBADF
    ``fd`` is not a valid file descriptor or is not open for writing.

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

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

EINTR
    The call was interrupted by a signal before any data was written.

EIO
    I/O error. This indicates some hardware problem.

EINVAL
    The :c:func:`write()` function is not supported by this driver,
    not on this device, or generally not on this type of device.