2020-08-26 15:03:09 +08:00
|
|
|
.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
|
2018-08-30 22:15:26 +08:00
|
|
|
|
2016-06-30 21:18:56 +08:00
|
|
|
.. _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
|
2016-07-13 02:15:23 +08:00
|
|
|
these. [#f1]_ A connector on a TV card to loop back the received audio
|
2016-06-30 21:18:56 +08:00
|
|
|
signal to a sound card is not considered an audio output.
|
|
|
|
|
|
|
|
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
|
2016-08-30 04:37:59 +08:00
|
|
|
:c:type:`v4l2_input` or struct
|
|
|
|
:c:type:`v4l2_output`, where each bit represents the index
|
2016-06-30 21:18:56 +08:00
|
|
|
number, starting at zero, of one audio input or output.
|
|
|
|
|
|
|
|
To learn about the number and attributes of the available inputs and
|
|
|
|
outputs applications can enumerate them with the
|
2016-07-02 00:58:44 +08:00
|
|
|
:ref:`VIDIOC_ENUMAUDIO` and
|
2016-07-07 22:05:38 +08:00
|
|
|
:ref:`VIDIOC_ENUMAUDOUT <VIDIOC_ENUMAUDOUT>` ioctl, respectively.
|
2016-08-30 04:37:59 +08:00
|
|
|
The struct :c:type:`v4l2_audio` returned by the
|
2016-07-02 00:58:44 +08:00
|
|
|
:ref:`VIDIOC_ENUMAUDIO` ioctl also contains signal
|
2018-10-26 20:18:33 +08:00
|
|
|
status information applicable when the current audio input is queried.
|
2016-06-30 21:18:56 +08:00
|
|
|
|
2016-07-03 21:02:29 +08:00
|
|
|
The :ref:`VIDIOC_G_AUDIO <VIDIOC_G_AUDIO>` and
|
2016-07-07 22:05:38 +08:00
|
|
|
:ref:`VIDIOC_G_AUDOUT <VIDIOC_G_AUDOUT>` ioctls report the current
|
2016-07-10 22:57:43 +08:00
|
|
|
audio input and output, respectively.
|
|
|
|
|
2016-08-16 04:49:50 +08:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
Note that, unlike :ref:`VIDIOC_G_INPUT <VIDIOC_G_INPUT>` and
|
2016-07-10 22:57:43 +08:00
|
|
|
: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.
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
To select an audio input and change its properties applications call the
|
2016-07-02 00:42:29 +08:00
|
|
|
:ref:`VIDIOC_S_AUDIO <VIDIOC_G_AUDIO>` ioctl. To select an audio
|
2016-06-30 21:18:56 +08:00
|
|
|
output (which presently has no changeable properties) applications call
|
2016-07-07 22:05:38 +08:00
|
|
|
the :ref:`VIDIOC_S_AUDOUT <VIDIOC_G_AUDOUT>` ioctl.
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
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
|
2016-08-30 04:37:59 +08:00
|
|
|
in the struct :c:type:`v4l2_capability` returned by
|
2016-07-02 00:58:44 +08:00
|
|
|
the :ref:`VIDIOC_QUERYCAP` ioctl.
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
|
2016-07-10 19:22:19 +08:00
|
|
|
Example: Information about the current audio input
|
|
|
|
==================================================
|
|
|
|
|
2016-06-30 21:18:56 +08:00
|
|
|
.. code-block:: c
|
|
|
|
|
|
|
|
struct v4l2_audio audio;
|
|
|
|
|
|
|
|
memset(&audio, 0, sizeof(audio));
|
|
|
|
|
|
|
|
if (-1 == ioctl(fd, VIDIOC_G_AUDIO, &audio)) {
|
2016-07-05 03:25:48 +08:00
|
|
|
perror("VIDIOC_G_AUDIO");
|
|
|
|
exit(EXIT_FAILURE);
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Current input: %s\\n", audio.name);
|
|
|
|
|
|
|
|
|
2016-07-10 19:22:19 +08:00
|
|
|
Example: Switching to the first audio input
|
|
|
|
===========================================
|
|
|
|
|
2016-06-30 21:18:56 +08:00
|
|
|
.. 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)) {
|
2016-07-05 03:25:48 +08:00
|
|
|
perror("VIDIOC_S_AUDIO");
|
|
|
|
exit(EXIT_FAILURE);
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
2016-07-13 02:15:23 +08:00
|
|
|
.. [#f1]
|
2016-08-30 04:37:59 +08:00
|
|
|
Actually struct :c:type:`v4l2_audio` ought to have a
|
|
|
|
``tuner`` field like struct :c:type:`v4l2_input`, not
|
2016-06-30 21:18:56 +08:00
|
|
|
only making the API more consistent but also permitting radio devices
|
|
|
|
with multiple tuners.
|