audio.rst 3.5 KB

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