1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Audio Inputs and Outputs</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API"><link rel="up" href="common.html" title="Chapter&#160;1.&#160;Common API Elements"><link rel="prev" href="video.html" title="Video Inputs and Outputs"><link rel="next" href="tuner.html" title="Tuners and Modulators"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Audio Inputs and Outputs</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="video.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;1.&#160;Common API Elements</th><td width="20%" align="right">&#160;<a accesskey="n" href="tuner.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="audio"></a>Audio Inputs and Outputs</h2></div></div></div><p>Audio inputs and outputs are physical connectors of a
2device. Video capture devices have inputs, output devices have
3outputs, zero or more each. Radio devices have no audio inputs or
4outputs. They have exactly one tuner which in fact
5<span class="emphasis"><em>is</em></span> an audio source, but this API associates
6tuners with video inputs or outputs only, and radio devices have
7none of these.<a href="#ftn.idp1096816628" class="footnote" name="idp1096816628"><sup class="footnote">[4]</sup></a> A connector on a TV card to loop back the received
8audio signal to a sound card is not considered an audio output.</p><p>Audio and video inputs and outputs are associated. Selecting
9a video source also selects an audio source. This is most evident when
10the video and audio source is a tuner. Further audio connectors can
11combine with more than one video input or output. Assumed two
12composite video inputs and two audio inputs exist, there may be up to
13four valid combinations. The relation of video and audio connectors
14is defined in the <em class="structfield"><code>audioset</code></em> field of the
15respective struct&#160;<a class="link" href="vidioc-enuminput.html#v4l2-input" title="Table&#160;A.39.&#160;struct v4l2_input">v4l2_input</a> or struct&#160;<a class="link" href="vidioc-enumoutput.html#v4l2-output" title="Table&#160;A.43.&#160;struct v4l2_output">v4l2_output</a>, where each bit represents
16the index number, starting at zero, of one audio input or output.</p><p>To learn about the number and attributes of the
17available inputs and outputs applications can enumerate them with the
18<a class="link" href="vidioc-enumaudio.html" title="ioctl VIDIOC_ENUMAUDIO"><code class="constant">VIDIOC_ENUMAUDIO</code></a> and <a class="link" href="vidioc-enumaudioout.html" title="ioctl VIDIOC_ENUMAUDOUT"><code class="constant">VIDIOC_ENUMAUDOUT</code></a> ioctl, respectively. The
19struct&#160;<a class="link" href="vidioc-g-audio.html#v4l2-audio" title="Table&#160;A.51.&#160;struct v4l2_audio">v4l2_audio</a> returned by the <code class="constant">VIDIOC_ENUMAUDIO</code> ioctl
20also contains signal status information applicable when the current
21audio input is queried.</p><p>The <a class="link" href="vidioc-g-audio.html" title="ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO"><code class="constant">VIDIOC_G_AUDIO</code></a> and <a class="link" href="vidioc-g-audioout.html" title="ioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT"><code class="constant">VIDIOC_G_AUDOUT</code></a> ioctls report
22the current audio input and output, respectively. Note that, unlike
23<a class="link" href="vidioc-g-input.html" title="ioctl VIDIOC_G_INPUT, VIDIOC_S_INPUT"><code class="constant">VIDIOC_G_INPUT</code></a> and <a class="link" href="vidioc-g-output.html" title="ioctl VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT"><code class="constant">VIDIOC_G_OUTPUT</code></a> these ioctls return a structure
24as <code class="constant">VIDIOC_ENUMAUDIO</code> and
25<code class="constant">VIDIOC_ENUMAUDOUT</code> do, not just an index.</p><p>To select an audio input and change its properties
26applications call the <a class="link" href="vidioc-g-audio.html" title="ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO"><code class="constant">VIDIOC_S_AUDIO</code></a> ioctl. To select an audio
27output (which presently has no changeable properties) applications
28call the <a class="link" href="vidioc-g-audioout.html" title="ioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT"><code class="constant">VIDIOC_S_AUDOUT</code></a> ioctl.</p><p>Drivers must implement all audio input ioctls when the device
29has multiple selectable audio inputs, all audio output ioctls when the
30device has multiple selectable audio outputs. When the device has any
31audio inputs or outputs the driver must set the <code class="constant">V4L2_CAP_AUDIO</code>
32flag in the struct&#160;<a class="link" href="vidioc-querycap.html#v4l2-capability" title="Table&#160;A.93.&#160;struct v4l2_capability">v4l2_capability</a> returned by the <a class="link" href="vidioc-querycap.html" title="ioctl VIDIOC_QUERYCAP"><code class="constant">VIDIOC_QUERYCAP</code></a> ioctl.</p><div class="example"><a name="idp1096830292"></a><p class="title"><b>Example&#160;1.3.&#160;Information about the current audio input</b></p><div class="example-contents"><pre class="programlisting">
33struct&#160;<a class="link" href="vidioc-g-audio.html#v4l2-audio" title="Table&#160;A.51.&#160;struct v4l2_audio">v4l2_audio</a> audio;
34
35memset(&amp;audio, 0, sizeof(audio));
36
37if (-1 == ioctl(fd, <a class="link" href="vidioc-g-audio.html" title="ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO"><code class="constant">VIDIOC_G_AUDIO</code></a>, &amp;audio)) {
38	perror("VIDIOC_G_AUDIO");
39	exit(EXIT_FAILURE);
40}
41
42printf("Current input: %s\n", audio.name);
43      </pre></div></div><br class="example-break"><div class="example"><a name="idp1096832188"></a><p class="title"><b>Example&#160;1.4.&#160;Switching to the first audio input</b></p><div class="example-contents"><pre class="programlisting">
44struct&#160;<a class="link" href="vidioc-g-audio.html#v4l2-audio" title="Table&#160;A.51.&#160;struct v4l2_audio">v4l2_audio</a> audio;
45
46memset(&amp;audio, 0, sizeof(audio)); /* clear audio.mode, audio.reserved */
47
48audio.index = 0;
49
50if (-1 == ioctl(fd, <a class="link" href="vidioc-g-audio.html" title="ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO"><code class="constant">VIDIOC_S_AUDIO</code></a>, &amp;audio)) {
51	perror("VIDIOC_S_AUDIO");
52	exit(EXIT_FAILURE);
53}
54      </pre></div></div><br class="example-break"><div class="footnotes"><br><hr style="width:100; text-align:left;margin-left: 0"><div id="ftn.idp1096816628" class="footnote"><p><a href="#idp1096816628" class="para"><sup class="para">[4] </sup></a>Actually struct&#160;<a class="link" href="vidioc-g-audio.html#v4l2-audio" title="Table&#160;A.51.&#160;struct v4l2_audio">v4l2_audio</a> ought to have a
55<em class="structfield"><code>tuner</code></em> field like struct&#160;<a class="link" href="vidioc-enuminput.html#v4l2-input" title="Table&#160;A.39.&#160;struct v4l2_input">v4l2_input</a>, not only
56making the API more consistent but also permitting radio devices with
57multiple tuners.</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="video.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="common.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="tuner.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Video Inputs and Outputs&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Tuners and Modulators</td></tr></table></div></body></html>
58