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

Linux 6.18.37 · Userspace API / Media / V4L

Audio input과 output

V4L2 audio connector의 video 연계, audioset bitmask, 열거·조회·선택 ioctl과 driver capability를 정의합니다.

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

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

1. 요약·해설

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

요약·해설

audio.rst:1-97

V4L2에서 audio connector는 video input/output과 `audioset` bitmask로 연결됩니다. Application은 enumerate/get/set ioctl로 connector를 다루고, driver는 connector 수와 존재 여부에 맞춰 ioctl 및 `V4L2_CAP_AUDIO`를 제공해야 합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2
3 .. _audio:
4
5 ************************
6 Audio Inputs and Outputs
7 ************************
8
9 Audio inputs and outputs are physical connectors of a device. Video
10 capture devices have inputs, output devices have outputs, zero or more
11 each. Radio devices have no audio inputs or outputs. They have exactly
12 one tuner which in fact *is* an audio source, but this API associates
13 tuners with video inputs or outputs only, and radio devices have none of
14 these. [#f1]_ A connector on a TV card to loop back the received audio
15 signal to a sound card is not considered an audio output.
16
17 Audio and video inputs and outputs are associated. Selecting a video
18 source also selects an audio source. This is most evident when the video
19 and audio source is a tuner. Further audio connectors can combine with
20 more than one video input or output. Assumed two composite video inputs
21 and two audio inputs exist, there may be up to four valid combinations.
22 The relation of video and audio connectors is defined in the
23 ``audioset`` field of the respective struct
24 :c:type:`v4l2_input` or struct
25 :c:type:`v4l2_output`, where each bit represents the index
26 number, starting at zero, of one audio input or output.
27
28 To learn about the number and attributes of the available inputs and
29 outputs applications can enumerate them with the
30 :ref:`VIDIOC_ENUMAUDIO` and
31 :ref:`VIDIOC_ENUMAUDOUT <VIDIOC_ENUMAUDOUT>` ioctl, respectively.
32 The struct :c:type:`v4l2_audio` returned by the
33 :ref:`VIDIOC_ENUMAUDIO` ioctl also contains signal
34 status information applicable when the current audio input is queried.
35
36 The :ref:`VIDIOC_G_AUDIO <VIDIOC_G_AUDIO>` and
37 :ref:`VIDIOC_G_AUDOUT <VIDIOC_G_AUDOUT>` ioctls report the current
38 audio input and output, respectively.
39
40 .. note::
41
42 Note that, unlike :ref:`VIDIOC_G_INPUT <VIDIOC_G_INPUT>` and
43 :ref:`VIDIOC_G_OUTPUT <VIDIOC_G_OUTPUT>` these ioctls return a
44 structure as :ref:`VIDIOC_ENUMAUDIO` and
45 :ref:`VIDIOC_ENUMAUDOUT <VIDIOC_ENUMAUDOUT>` do, not just an index.
46
47 To select an audio input and change its properties applications call the
48 :ref:`VIDIOC_S_AUDIO <VIDIOC_G_AUDIO>` ioctl. To select an audio
49 output (which presently has no changeable properties) applications call
50 the :ref:`VIDIOC_S_AUDOUT <VIDIOC_G_AUDOUT>` ioctl.
51
52 Drivers must implement all audio input ioctls when the device has
53 multiple selectable audio inputs, all audio output ioctls when the
54 device has multiple selectable audio outputs. When the device has any
55 audio inputs or outputs the driver must set the ``V4L2_CAP_AUDIO`` flag
56 in the struct :c:type:`v4l2_capability` returned by
57 the :ref:`VIDIOC_QUERYCAP` ioctl.
58
59
60 Example: Information about the current audio input
61 ==================================================
62
63 .. code-block:: c
64
65 struct v4l2_audio audio;
66
67 memset(&audio, 0, sizeof(audio));
68
69 if (-1 == ioctl(fd, VIDIOC_G_AUDIO, &audio)) {
70 perror("VIDIOC_G_AUDIO");
71 exit(EXIT_FAILURE);
72 }
73
74 printf("Current input: %s\\n", audio.name);
75
76
77 Example: Switching to the first audio input
78 ===========================================
79
80 .. code-block:: c
81
82 struct v4l2_audio audio;
83
84 memset(&audio, 0, sizeof(audio)); /* clear audio.mode, audio.reserved */
85
86 audio.index = 0;
87
88 if (-1 == ioctl(fd, VIDIOC_S_AUDIO, &audio)) {
89 perror("VIDIOC_S_AUDIO");
90 exit(EXIT_FAILURE);
91 }
92
93 .. [#f1]
94 Actually struct :c:type:`v4l2_audio` ought to have a
95 ``tuner`` field like struct :c:type:`v4l2_input`, not
96 only making the API more consistent but also permitting radio devices
97 with multiple tuners.
98

3. 한국어 전문 번역

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

물리 audio connector

1-16

Audio input과 output은 device의 물리 connector입니다. Video capture device는 input을, output device는 output을 가지며 각각 0개 이상일 수 있습니다.

Radio device에는 audio input이나 output이 없습니다. 정확히 하나의 tuner가 있고 실제로 audio source이지만, 이 API는 tuner를 video input 또는 output에만 연결하며 radio device에는 둘 다 없기 때문입니다.

TV card에서 수신 audio signal을 sound card로 loop back하는 connector는 audio output으로 간주하지 않습니다.

Device별 audio connector 해석
항목설명
Video capture device0개 이상의 audio input
Video output device0개 이상의 audio output
Radio deviceAudio source인 tuner 1개, API audio input/output은 없음
TV card loopback connectorAudio output으로 간주하지 않음

API가 물리 connector와 tuner를 분류하는 방식입니다.

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

.. _audio:

************************
Audio Inputs and Outputs
************************

Audio inputs and outputs are physical connectors of a device. Video
capture devices have inputs, output devices have outputs, zero or more
each. Radio devices have no audio inputs or outputs. They have exactly
one tuner which in fact *is* an audio source, but this API associates
tuners with video inputs or outputs only, and radio devices have none of
these. [#f1]_ A connector on a TV card to loop back the received audio
signal to a sound card is not considered an audio output.

Video와 audio connector의 연결

17-27

Audio input/output은 video input/output과 연결됩니다. Video source를 선택하면 audio source도 함께 선택되며, video와 audio source가 tuner일 때 이 관계가 가장 분명합니다.

하나의 audio connector가 둘 이상의 video input 또는 output과 조합될 수도 있습니다. Composite video input 2개와 audio input 2개가 있다면 유효한 조합은 최대 4개입니다.

Video와 audio connector의 관계는 각각의 `struct v4l2_input` 또는 `struct v4l2_output`에 있는 `audioset` field로 정의됩니다. 각 bit는 0부터 시작하는 audio input 또는 output index 하나를 나타냅니다.

audioset bitmask
항목설명
bit 0Audio input/output index 0
bit 1Audio input/output index 1
...각 추가 bit가 같은 번호의 audio connector index를 나타냄

각 video connector가 조합할 수 있는 audio connector index를 bit로 표현합니다.

Audio and video inputs and outputs are associated. Selecting a video
source also selects an audio source. This is most evident when the video
and audio source is a tuner. Further audio connectors can combine with
more than one video input or output. Assumed two composite video inputs
and two audio inputs exist, there may be up to four valid combinations.
The relation of video and audio connectors is defined in the
``audioset`` field of the respective struct
:c:type:`v4l2_input` or struct
:c:type:`v4l2_output`, where each bit represents the index
number, starting at zero, of one audio input or output.

Audio connector 열거와 현재 선택 조회

28-39

Application은 `VIDIOC_ENUMAUDIO`와 `VIDIOC_ENUMAUDOUT` ioctl로 사용 가능한 audio input과 output의 수 및 속성을 각각 열거할 수 있습니다.

`VIDIOC_ENUMAUDIO`가 반환하는 `struct v4l2_audio`에는 현재 audio input을 조회할 때 적용되는 signal status 정보도 포함됩니다.

`VIDIOC_G_AUDIO`와 `VIDIOC_G_AUDOUT` ioctl은 현재 audio input과 output을 각각 보고합니다.

Audio 조회 ioctl
항목설명
VIDIOC_ENUMAUDIOAudio input 열거, struct v4l2_audio 반환
VIDIOC_ENUMAUDOUTAudio output 열거
VIDIOC_G_AUDIO현재 audio input 조회
VIDIOC_G_AUDOUT현재 audio output 조회

Input과 output의 열거 및 현재 선택 조회를 구분합니다.

To learn about the number and attributes of the available inputs and
outputs applications can enumerate them with the
:ref:`VIDIOC_ENUMAUDIO` and
:ref:`VIDIOC_ENUMAUDOUT <VIDIOC_ENUMAUDOUT>` ioctl, respectively.
The struct :c:type:`v4l2_audio` returned by the
:ref:`VIDIOC_ENUMAUDIO` ioctl also contains signal
status information applicable when the current audio input is queried.

The :ref:`VIDIOC_G_AUDIO <VIDIOC_G_AUDIO>` and
:ref:`VIDIOC_G_AUDOUT <VIDIOC_G_AUDOUT>` ioctls report the current
audio input and output, respectively.

구조체 반환과 audio connector 선택

40-50

`VIDIOC_G_INPUT` 및 `VIDIOC_G_OUTPUT`과 달리 `VIDIOC_G_AUDIO`와 `VIDIOC_G_AUDOUT`은 index 하나가 아니라 `VIDIOC_ENUMAUDIO` 및 `VIDIOC_ENUMAUDOUT`과 같은 구조체를 반환합니다.

Audio input을 선택하고 속성을 변경하려면 `VIDIOC_S_AUDIO`를 호출합니다. 현재 변경 가능한 속성이 없는 audio output을 선택하려면 `VIDIOC_S_AUDOUT`을 호출합니다.

Audio 선택 ioctl
항목설명
VIDIOC_S_AUDIOAudio input 선택 및 속성 변경
VIDIOC_S_AUDOUTAudio output 선택, 현재 변경 가능한 속성 없음

Input은 선택과 속성 변경을, output은 현재 선택을 설정합니다.

.. note::

   Note that, unlike :ref:`VIDIOC_G_INPUT <VIDIOC_G_INPUT>` and
   :ref:`VIDIOC_G_OUTPUT <VIDIOC_G_OUTPUT>` these ioctls return a
   structure as :ref:`VIDIOC_ENUMAUDIO` and
   :ref:`VIDIOC_ENUMAUDOUT <VIDIOC_ENUMAUDOUT>` do, not just an index.

To select an audio input and change its properties applications call the
:ref:`VIDIOC_S_AUDIO <VIDIOC_G_AUDIO>` ioctl. To select an audio
output (which presently has no changeable properties) applications call
the :ref:`VIDIOC_S_AUDOUT <VIDIOC_G_AUDOUT>` ioctl.

Driver 구현 및 capability 요구사항

51-58

Device에 선택 가능한 audio input이 여러 개 있으면 driver는 모든 audio input ioctl을 구현해야 합니다. 선택 가능한 audio output이 여러 개 있으면 모든 audio output ioctl을 구현해야 합니다.

Device에 audio input 또는 output이 하나라도 있으면 `VIDIOC_QUERYCAP`이 반환하는 `struct v4l2_capability`에 `V4L2_CAP_AUDIO` flag를 설정해야 합니다.


Drivers must implement all audio input ioctls when the device has
multiple selectable audio inputs, all audio output ioctls when the
device has multiple selectable audio outputs. When the device has any
audio inputs or outputs the driver must set the ``V4L2_CAP_AUDIO`` flag
in the struct :c:type:`v4l2_capability` returned by
the :ref:`VIDIOC_QUERYCAP` ioctl.

현재 audio input 정보 예제

59-75

다음 C code는 `struct v4l2_audio`를 0으로 초기화하고 `VIDIOC_G_AUDIO`로 현재 input을 조회한 뒤 이름을 출력합니다.

struct v4l2_audio audio;

memset(&audio, 0, sizeof(audio));

if (-1 == ioctl(fd, VIDIOC_G_AUDIO, &audio)) {
	perror("VIDIOC_G_AUDIO");
	exit(EXIT_FAILURE);
}

printf("Current input: %s\n", audio.name);

Example: Information about the current audio input
==================================================

.. code-block:: c

    struct v4l2_audio audio;

    memset(&audio, 0, sizeof(audio));

    if (-1 == ioctl(fd, VIDIOC_G_AUDIO, &audio)) {
	perror("VIDIOC_G_AUDIO");
	exit(EXIT_FAILURE);
    }

    printf("Current input: %s\\n", audio.name);

첫 번째 audio input으로 전환하는 예제

76-92

다음 C code는 구조체를 초기화해 `audio.mode`와 `audio.reserved`도 지우고 `audio.index = 0`으로 설정한 뒤 `VIDIOC_S_AUDIO`를 호출합니다.

struct v4l2_audio audio;

memset(&audio, 0, sizeof(audio)); /* clear audio.mode, audio.reserved */

audio.index = 0;

if (-1 == ioctl(fd, VIDIOC_S_AUDIO, &audio)) {
	perror("VIDIOC_S_AUDIO");
	exit(EXIT_FAILURE);
}

Example: Switching to the first audio input
===========================================

.. code-block:: c

    struct v4l2_audio audio;

    memset(&audio, 0, sizeof(audio)); /* clear audio.mode, audio.reserved */

    audio.index = 0;

    if (-1 == ioctl(fd, VIDIOC_S_AUDIO, &audio)) {
	perror("VIDIOC_S_AUDIO");
	exit(EXIT_FAILURE);
    }

Radio tuner 표현에 관한 API 주석

93-97

실제로는 `struct v4l2_audio`에도 `struct v4l2_input`처럼 `tuner` field가 있어야 합니다. 그러면 API가 더 일관될 뿐 아니라 tuner가 여러 개인 radio device도 표현할 수 있습니다.

.. [#f1]
   Actually struct :c:type:`v4l2_audio` ought to have a
   ``tuner`` field like struct :c:type:`v4l2_input`, not
   only making the API more consistent but also permitting radio devices
   with multiple tuners.