blob: 4c7fdbc8a860571abd575f4e44273a287cbbfea0 [file] [log] [blame]
Mauro Carvalho Chehab82559ac2018-08-30 10:15:26 -04001.. Permission is granted to copy, distribute and/or modify this
2.. document under the terms of the GNU Free Documentation License,
3.. Version 1.1 or any later version published by the Free Software
4.. Foundation, with no Invariant Sections, no Front-Cover Texts
5.. and no Back-Cover Texts. A copy of the license is included at
6.. Documentation/media/uapi/fdl-appendix.rst.
7..
8.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
9
Markus Heiser5377d912016-06-30 15:18:56 +020010.. _audio:
11
12************************
13Audio Inputs and Outputs
14************************
15
16Audio inputs and outputs are physical connectors of a device. Video
17capture devices have inputs, output devices have outputs, zero or more
18each. Radio devices have no audio inputs or outputs. They have exactly
19one tuner which in fact *is* an audio source, but this API associates
20tuners with video inputs or outputs only, and radio devices have none of
Mauro Carvalho Chehab48553072016-07-12 15:15:23 -030021these. [#f1]_ A connector on a TV card to loop back the received audio
Markus Heiser5377d912016-06-30 15:18:56 +020022signal to a sound card is not considered an audio output.
23
24Audio and video inputs and outputs are associated. Selecting a video
25source also selects an audio source. This is most evident when the video
26and audio source is a tuner. Further audio connectors can combine with
27more than one video input or output. Assumed two composite video inputs
28and two audio inputs exist, there may be up to four valid combinations.
29The relation of video and audio connectors is defined in the
30``audioset`` field of the respective struct
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -030031:c:type:`v4l2_input` or struct
32:c:type:`v4l2_output`, where each bit represents the index
Markus Heiser5377d912016-06-30 15:18:56 +020033number, starting at zero, of one audio input or output.
34
35To learn about the number and attributes of the available inputs and
36outputs applications can enumerate them with the
Mauro Carvalho Chehab73470812016-07-01 13:58:44 -030037:ref:`VIDIOC_ENUMAUDIO` and
Mauro Carvalho Chehab9f97b302016-07-07 11:05:38 -030038:ref:`VIDIOC_ENUMAUDOUT <VIDIOC_ENUMAUDOUT>` ioctl, respectively.
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -030039The struct :c:type:`v4l2_audio` returned by the
Mauro Carvalho Chehab73470812016-07-01 13:58:44 -030040:ref:`VIDIOC_ENUMAUDIO` ioctl also contains signal
Sean Young2e9a2ec2018-10-26 08:18:33 -040041status information applicable when the current audio input is queried.
Markus Heiser5377d912016-06-30 15:18:56 +020042
Mauro Carvalho Chehab4e03cb72016-07-03 10:02:29 -030043The :ref:`VIDIOC_G_AUDIO <VIDIOC_G_AUDIO>` and
Mauro Carvalho Chehab9f97b302016-07-07 11:05:38 -030044:ref:`VIDIOC_G_AUDOUT <VIDIOC_G_AUDOUT>` ioctls report the current
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -030045audio input and output, respectively.
46
Mauro Carvalho Chehabb6b6e672016-08-15 17:49:50 -030047.. note::
48
49 Note that, unlike :ref:`VIDIOC_G_INPUT <VIDIOC_G_INPUT>` and
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -030050 :ref:`VIDIOC_G_OUTPUT <VIDIOC_G_OUTPUT>` these ioctls return a
51 structure as :ref:`VIDIOC_ENUMAUDIO` and
52 :ref:`VIDIOC_ENUMAUDOUT <VIDIOC_ENUMAUDOUT>` do, not just an index.
Markus Heiser5377d912016-06-30 15:18:56 +020053
54To select an audio input and change its properties applications call the
Mauro Carvalho Chehabaf4a4d02016-07-01 13:42:29 -030055:ref:`VIDIOC_S_AUDIO <VIDIOC_G_AUDIO>` ioctl. To select an audio
Markus Heiser5377d912016-06-30 15:18:56 +020056output (which presently has no changeable properties) applications call
Mauro Carvalho Chehab9f97b302016-07-07 11:05:38 -030057the :ref:`VIDIOC_S_AUDOUT <VIDIOC_G_AUDOUT>` ioctl.
Markus Heiser5377d912016-06-30 15:18:56 +020058
59Drivers must implement all audio input ioctls when the device has
60multiple selectable audio inputs, all audio output ioctls when the
61device has multiple selectable audio outputs. When the device has any
62audio inputs or outputs the driver must set the ``V4L2_CAP_AUDIO`` flag
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -030063in the struct :c:type:`v4l2_capability` returned by
Mauro Carvalho Chehab73470812016-07-01 13:58:44 -030064the :ref:`VIDIOC_QUERYCAP` ioctl.
Markus Heiser5377d912016-06-30 15:18:56 +020065
66
Mauro Carvalho Chehab282f02c2016-07-10 08:22:19 -030067Example: Information about the current audio input
68==================================================
69
Markus Heiser5377d912016-06-30 15:18:56 +020070.. code-block:: c
71
72 struct v4l2_audio audio;
73
74 memset(&audio, 0, sizeof(audio));
75
76 if (-1 == ioctl(fd, VIDIOC_G_AUDIO, &audio)) {
Mauro Carvalho Chehab0579e6e2016-07-04 16:25:48 -030077 perror("VIDIOC_G_AUDIO");
78 exit(EXIT_FAILURE);
Markus Heiser5377d912016-06-30 15:18:56 +020079 }
80
81 printf("Current input: %s\\n", audio.name);
82
83
Mauro Carvalho Chehab282f02c2016-07-10 08:22:19 -030084Example: Switching to the first audio input
85===========================================
86
Markus Heiser5377d912016-06-30 15:18:56 +020087.. code-block:: c
Markus Heiser5377d912016-06-30 15:18:56 +020088
89 struct v4l2_audio audio;
90
91 memset(&audio, 0, sizeof(audio)); /* clear audio.mode, audio.reserved */
92
93 audio.index = 0;
94
95 if (-1 == ioctl(fd, VIDIOC_S_AUDIO, &audio)) {
Mauro Carvalho Chehab0579e6e2016-07-04 16:25:48 -030096 perror("VIDIOC_S_AUDIO");
97 exit(EXIT_FAILURE);
Markus Heiser5377d912016-06-30 15:18:56 +020098 }
99
Mauro Carvalho Chehab48553072016-07-12 15:15:23 -0300100.. [#f1]
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -0300101 Actually struct :c:type:`v4l2_audio` ought to have a
102 ``tuner`` field like struct :c:type:`v4l2_input`, not
Markus Heiser5377d912016-06-30 15:18:56 +0200103 only making the API more consistent but also permitting radio devices
104 with multiple tuners.