xref: /openbmc/linux/Documentation/userspace-api/media/v4l/audio.rst (revision cbecf716ca618fd44feda6bd9a64a8179d031fc5)
1*059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
254f38fcaSMauro Carvalho Chehab
354f38fcaSMauro Carvalho Chehab.. _audio:
454f38fcaSMauro Carvalho Chehab
554f38fcaSMauro Carvalho Chehab************************
654f38fcaSMauro Carvalho ChehabAudio Inputs and Outputs
754f38fcaSMauro Carvalho Chehab************************
854f38fcaSMauro Carvalho Chehab
954f38fcaSMauro Carvalho ChehabAudio inputs and outputs are physical connectors of a device. Video
1054f38fcaSMauro Carvalho Chehabcapture devices have inputs, output devices have outputs, zero or more
1154f38fcaSMauro Carvalho Chehabeach. Radio devices have no audio inputs or outputs. They have exactly
1254f38fcaSMauro Carvalho Chehabone tuner which in fact *is* an audio source, but this API associates
1354f38fcaSMauro Carvalho Chehabtuners with video inputs or outputs only, and radio devices have none of
1454f38fcaSMauro Carvalho Chehabthese. [#f1]_ A connector on a TV card to loop back the received audio
1554f38fcaSMauro Carvalho Chehabsignal to a sound card is not considered an audio output.
1654f38fcaSMauro Carvalho Chehab
1754f38fcaSMauro Carvalho ChehabAudio and video inputs and outputs are associated. Selecting a video
1854f38fcaSMauro Carvalho Chehabsource also selects an audio source. This is most evident when the video
1954f38fcaSMauro Carvalho Chehaband audio source is a tuner. Further audio connectors can combine with
2054f38fcaSMauro Carvalho Chehabmore than one video input or output. Assumed two composite video inputs
2154f38fcaSMauro Carvalho Chehaband two audio inputs exist, there may be up to four valid combinations.
2254f38fcaSMauro Carvalho ChehabThe relation of video and audio connectors is defined in the
2354f38fcaSMauro Carvalho Chehab``audioset`` field of the respective struct
2454f38fcaSMauro Carvalho Chehab:c:type:`v4l2_input` or struct
2554f38fcaSMauro Carvalho Chehab:c:type:`v4l2_output`, where each bit represents the index
2654f38fcaSMauro Carvalho Chehabnumber, starting at zero, of one audio input or output.
2754f38fcaSMauro Carvalho Chehab
2854f38fcaSMauro Carvalho ChehabTo learn about the number and attributes of the available inputs and
2954f38fcaSMauro Carvalho Chehaboutputs applications can enumerate them with the
3054f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_ENUMAUDIO` and
3154f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_ENUMAUDOUT <VIDIOC_ENUMAUDOUT>` ioctl, respectively.
3254f38fcaSMauro Carvalho ChehabThe struct :c:type:`v4l2_audio` returned by the
3354f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_ENUMAUDIO` ioctl also contains signal
3454f38fcaSMauro Carvalho Chehabstatus information applicable when the current audio input is queried.
3554f38fcaSMauro Carvalho Chehab
3654f38fcaSMauro Carvalho ChehabThe :ref:`VIDIOC_G_AUDIO <VIDIOC_G_AUDIO>` and
3754f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_G_AUDOUT <VIDIOC_G_AUDOUT>` ioctls report the current
3854f38fcaSMauro Carvalho Chehabaudio input and output, respectively.
3954f38fcaSMauro Carvalho Chehab
4054f38fcaSMauro Carvalho Chehab.. note::
4154f38fcaSMauro Carvalho Chehab
4254f38fcaSMauro Carvalho Chehab   Note that, unlike :ref:`VIDIOC_G_INPUT <VIDIOC_G_INPUT>` and
4354f38fcaSMauro Carvalho Chehab   :ref:`VIDIOC_G_OUTPUT <VIDIOC_G_OUTPUT>` these ioctls return a
4454f38fcaSMauro Carvalho Chehab   structure as :ref:`VIDIOC_ENUMAUDIO` and
4554f38fcaSMauro Carvalho Chehab   :ref:`VIDIOC_ENUMAUDOUT <VIDIOC_ENUMAUDOUT>` do, not just an index.
4654f38fcaSMauro Carvalho Chehab
4754f38fcaSMauro Carvalho ChehabTo select an audio input and change its properties applications call the
4854f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_S_AUDIO <VIDIOC_G_AUDIO>` ioctl. To select an audio
4954f38fcaSMauro Carvalho Chehaboutput (which presently has no changeable properties) applications call
5054f38fcaSMauro Carvalho Chehabthe :ref:`VIDIOC_S_AUDOUT <VIDIOC_G_AUDOUT>` ioctl.
5154f38fcaSMauro Carvalho Chehab
5254f38fcaSMauro Carvalho ChehabDrivers must implement all audio input ioctls when the device has
5354f38fcaSMauro Carvalho Chehabmultiple selectable audio inputs, all audio output ioctls when the
5454f38fcaSMauro Carvalho Chehabdevice has multiple selectable audio outputs. When the device has any
5554f38fcaSMauro Carvalho Chehabaudio inputs or outputs the driver must set the ``V4L2_CAP_AUDIO`` flag
5654f38fcaSMauro Carvalho Chehabin the struct :c:type:`v4l2_capability` returned by
5754f38fcaSMauro Carvalho Chehabthe :ref:`VIDIOC_QUERYCAP` ioctl.
5854f38fcaSMauro Carvalho Chehab
5954f38fcaSMauro Carvalho Chehab
6054f38fcaSMauro Carvalho ChehabExample: Information about the current audio input
6154f38fcaSMauro Carvalho Chehab==================================================
6254f38fcaSMauro Carvalho Chehab
6354f38fcaSMauro Carvalho Chehab.. code-block:: c
6454f38fcaSMauro Carvalho Chehab
6554f38fcaSMauro Carvalho Chehab    struct v4l2_audio audio;
6654f38fcaSMauro Carvalho Chehab
6754f38fcaSMauro Carvalho Chehab    memset(&audio, 0, sizeof(audio));
6854f38fcaSMauro Carvalho Chehab
6954f38fcaSMauro Carvalho Chehab    if (-1 == ioctl(fd, VIDIOC_G_AUDIO, &audio)) {
7054f38fcaSMauro Carvalho Chehab	perror("VIDIOC_G_AUDIO");
7154f38fcaSMauro Carvalho Chehab	exit(EXIT_FAILURE);
7254f38fcaSMauro Carvalho Chehab    }
7354f38fcaSMauro Carvalho Chehab
7454f38fcaSMauro Carvalho Chehab    printf("Current input: %s\\n", audio.name);
7554f38fcaSMauro Carvalho Chehab
7654f38fcaSMauro Carvalho Chehab
7754f38fcaSMauro Carvalho ChehabExample: Switching to the first audio input
7854f38fcaSMauro Carvalho Chehab===========================================
7954f38fcaSMauro Carvalho Chehab
8054f38fcaSMauro Carvalho Chehab.. code-block:: c
8154f38fcaSMauro Carvalho Chehab
8254f38fcaSMauro Carvalho Chehab    struct v4l2_audio audio;
8354f38fcaSMauro Carvalho Chehab
8454f38fcaSMauro Carvalho Chehab    memset(&audio, 0, sizeof(audio)); /* clear audio.mode, audio.reserved */
8554f38fcaSMauro Carvalho Chehab
8654f38fcaSMauro Carvalho Chehab    audio.index = 0;
8754f38fcaSMauro Carvalho Chehab
8854f38fcaSMauro Carvalho Chehab    if (-1 == ioctl(fd, VIDIOC_S_AUDIO, &audio)) {
8954f38fcaSMauro Carvalho Chehab	perror("VIDIOC_S_AUDIO");
9054f38fcaSMauro Carvalho Chehab	exit(EXIT_FAILURE);
9154f38fcaSMauro Carvalho Chehab    }
9254f38fcaSMauro Carvalho Chehab
9354f38fcaSMauro Carvalho Chehab.. [#f1]
9454f38fcaSMauro Carvalho Chehab   Actually struct :c:type:`v4l2_audio` ought to have a
9554f38fcaSMauro Carvalho Chehab   ``tuner`` field like struct :c:type:`v4l2_input`, not
9654f38fcaSMauro Carvalho Chehab   only making the API more consistent but also permitting radio devices
9754f38fcaSMauro Carvalho Chehab   with multiple tuners.
98