Mauro Carvalho Chehab | 82559ac | 2018-08-30 10:15:26 -0400 | [diff] [blame] | 1 | .. 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 Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 10 | .. _audio: |
| 11 | |
| 12 | ************************ |
| 13 | Audio Inputs and Outputs |
| 14 | ************************ |
| 15 | |
| 16 | Audio inputs and outputs are physical connectors of a device. Video |
| 17 | capture devices have inputs, output devices have outputs, zero or more |
| 18 | each. Radio devices have no audio inputs or outputs. They have exactly |
| 19 | one tuner which in fact *is* an audio source, but this API associates |
| 20 | tuners with video inputs or outputs only, and radio devices have none of |
Mauro Carvalho Chehab | 4855307 | 2016-07-12 15:15:23 -0300 | [diff] [blame] | 21 | these. [#f1]_ A connector on a TV card to loop back the received audio |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 22 | signal to a sound card is not considered an audio output. |
| 23 | |
| 24 | Audio and video inputs and outputs are associated. Selecting a video |
| 25 | source also selects an audio source. This is most evident when the video |
| 26 | and audio source is a tuner. Further audio connectors can combine with |
| 27 | more than one video input or output. Assumed two composite video inputs |
| 28 | and two audio inputs exist, there may be up to four valid combinations. |
| 29 | The relation of video and audio connectors is defined in the |
| 30 | ``audioset`` field of the respective struct |
Mauro Carvalho Chehab | e8be7e9 | 2016-08-29 17:37:59 -0300 | [diff] [blame] | 31 | :c:type:`v4l2_input` or struct |
| 32 | :c:type:`v4l2_output`, where each bit represents the index |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 33 | number, starting at zero, of one audio input or output. |
| 34 | |
| 35 | To learn about the number and attributes of the available inputs and |
| 36 | outputs applications can enumerate them with the |
Mauro Carvalho Chehab | 7347081 | 2016-07-01 13:58:44 -0300 | [diff] [blame] | 37 | :ref:`VIDIOC_ENUMAUDIO` and |
Mauro Carvalho Chehab | 9f97b30 | 2016-07-07 11:05:38 -0300 | [diff] [blame] | 38 | :ref:`VIDIOC_ENUMAUDOUT <VIDIOC_ENUMAUDOUT>` ioctl, respectively. |
Mauro Carvalho Chehab | e8be7e9 | 2016-08-29 17:37:59 -0300 | [diff] [blame] | 39 | The struct :c:type:`v4l2_audio` returned by the |
Mauro Carvalho Chehab | 7347081 | 2016-07-01 13:58:44 -0300 | [diff] [blame] | 40 | :ref:`VIDIOC_ENUMAUDIO` ioctl also contains signal |
Sean Young | 2e9a2ec | 2018-10-26 08:18:33 -0400 | [diff] [blame] | 41 | status information applicable when the current audio input is queried. |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 42 | |
Mauro Carvalho Chehab | 4e03cb7 | 2016-07-03 10:02:29 -0300 | [diff] [blame] | 43 | The :ref:`VIDIOC_G_AUDIO <VIDIOC_G_AUDIO>` and |
Mauro Carvalho Chehab | 9f97b30 | 2016-07-07 11:05:38 -0300 | [diff] [blame] | 44 | :ref:`VIDIOC_G_AUDOUT <VIDIOC_G_AUDOUT>` ioctls report the current |
Mauro Carvalho Chehab | 706f8a9 | 2016-07-10 11:57:43 -0300 | [diff] [blame] | 45 | audio input and output, respectively. |
| 46 | |
Mauro Carvalho Chehab | b6b6e67 | 2016-08-15 17:49:50 -0300 | [diff] [blame] | 47 | .. note:: |
| 48 | |
| 49 | Note that, unlike :ref:`VIDIOC_G_INPUT <VIDIOC_G_INPUT>` and |
Mauro Carvalho Chehab | 706f8a9 | 2016-07-10 11:57:43 -0300 | [diff] [blame] | 50 | :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 Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 53 | |
| 54 | To select an audio input and change its properties applications call the |
Mauro Carvalho Chehab | af4a4d0 | 2016-07-01 13:42:29 -0300 | [diff] [blame] | 55 | :ref:`VIDIOC_S_AUDIO <VIDIOC_G_AUDIO>` ioctl. To select an audio |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 56 | output (which presently has no changeable properties) applications call |
Mauro Carvalho Chehab | 9f97b30 | 2016-07-07 11:05:38 -0300 | [diff] [blame] | 57 | the :ref:`VIDIOC_S_AUDOUT <VIDIOC_G_AUDOUT>` ioctl. |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 58 | |
| 59 | Drivers must implement all audio input ioctls when the device has |
| 60 | multiple selectable audio inputs, all audio output ioctls when the |
| 61 | device has multiple selectable audio outputs. When the device has any |
| 62 | audio inputs or outputs the driver must set the ``V4L2_CAP_AUDIO`` flag |
Mauro Carvalho Chehab | e8be7e9 | 2016-08-29 17:37:59 -0300 | [diff] [blame] | 63 | in the struct :c:type:`v4l2_capability` returned by |
Mauro Carvalho Chehab | 7347081 | 2016-07-01 13:58:44 -0300 | [diff] [blame] | 64 | the :ref:`VIDIOC_QUERYCAP` ioctl. |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 65 | |
| 66 | |
Mauro Carvalho Chehab | 282f02c | 2016-07-10 08:22:19 -0300 | [diff] [blame] | 67 | Example: Information about the current audio input |
| 68 | ================================================== |
| 69 | |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 70 | .. 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 Chehab | 0579e6e | 2016-07-04 16:25:48 -0300 | [diff] [blame] | 77 | perror("VIDIOC_G_AUDIO"); |
| 78 | exit(EXIT_FAILURE); |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | printf("Current input: %s\\n", audio.name); |
| 82 | |
| 83 | |
Mauro Carvalho Chehab | 282f02c | 2016-07-10 08:22:19 -0300 | [diff] [blame] | 84 | Example: Switching to the first audio input |
| 85 | =========================================== |
| 86 | |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 87 | .. code-block:: c |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 88 | |
| 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 Chehab | 0579e6e | 2016-07-04 16:25:48 -0300 | [diff] [blame] | 96 | perror("VIDIOC_S_AUDIO"); |
| 97 | exit(EXIT_FAILURE); |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 98 | } |
| 99 | |
Mauro Carvalho Chehab | 4855307 | 2016-07-12 15:15:23 -0300 | [diff] [blame] | 100 | .. [#f1] |
Mauro Carvalho Chehab | e8be7e9 | 2016-08-29 17:37:59 -0300 | [diff] [blame] | 101 | Actually struct :c:type:`v4l2_audio` ought to have a |
| 102 | ``tuner`` field like struct :c:type:`v4l2_input`, not |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 103 | only making the API more consistent but also permitting radio devices |
| 104 | with multiple tuners. |