1page.title=Configuring Audio Policies
2@jd:body
3
4<!--
5    Copyright 2016 The Android Open Source Project
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18-->
19<div id="qv-wrapper">
20  <div id="qv">
21    <h2>In this document</h2>
22    <ol id="auto-toc">
23    </ol>
24  </div>
25</div>
26
27<p>Android 7.0 introduces a new audio policy configuration file format (XML) for
28describing your audio topology.</p>
29
30<p>Previous Android releases required using the
31<code>device/&lt;company&gt;/&lt;device&gt;/audio/audio_policy.conf</code>
32to declare the audio devices present on your product (you can see an example of
33this file for the Galaxy Nexus audio hardware in
34<code>device/samsung/tuna/audio/audio_policy.conf</code>). However, .conf is a
35simple proprietary format that is too limited to describe complex topologies for
36applications such as televisions and automobiles.</p>
37
38<p>Android 7.0 deprecates the <code>audio_policy.conf</code> and adds support
39for defining audio topology using an XML file format that is more
40human-readable, has a wide range of editing and parsing tools, and is flexible
41enough to describe complex audio topologies.</p>
42
43<p class="note".<strong>Note:</strong> Android 7.0 preserves support for using
44<code>audio_policy.conf</code>; this legacy format is used by default. To use
45the XML file format, include the build option <code>USE_XML_AUDIO_POLICY_CONF
46:= 1</code> in device makefile.</p>
47
48<h2 id=xml_advantages>Advantages of the XML format</h2>
49<p>As in the .conf file, the new XML file enables defining the number and types
50of output an input stream profiles, devices usable for playback and capture, and
51audio attributes. In addition, the XML format offers the following enhancements:
52</p>
53
54<ul>
55<li>Audio profiles are now structured similar to HDMI Simple Audio Descriptors
56and enable a different set of sampling rates/channel masks for each audio
57format.</li>
58<li>Explicit definitions of all possible connections between devices and
59streams. Previously, an implicit rule made it possible to interconnect all
60devices attached to the same HAL module, preventing the audio policy from
61controlling connections requested with audio patch APIs. In the XML format, the
62topology description now defines connection limitations.</li>
63<li>Support for <em>includes</em> avoids repeating standard A2DP, USB, or
64reroute submit definitions.</li>
65<li>Customizable volume curves. Previously, volume tables were hardcoded. In the
66XML format, volume tables are described and can be customized.</li>
67</ul>
68
69<p>The template at
70<code>frameworks/av/services/audiopolicy/config/audio_policy_configuration.xml</code>
71shows many of these features in use.</p>
72
73<h2 id=xml_file_format>File format and location</h2>
74<p>The new audio policy configuration file is
75<code>audio_policy_configuration.xml</code> and is located in
76<code>/system/etc</code>. To view a simple audio policy configuration in the new
77XML file format, view the example below.</p>
78
79<p>
80<div class="toggle-content closed">
81  <p><a href="#" onclick="return toggleContent(this)">
82    <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" />
83    <strong><span class="toggle-content-text">Show audio policy example</span>
84    <span class="toggle-content-text" style="display:none;">Hide audio policy
85    example</span></strong>
86  </a></p>
87
88  <div class="toggle-content-toggleme">
89<pre class="prettyprint">
90&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
91&lt;audioPolicyConfiguration version=&quot;1.0&quot; xmlns:xi=&quot;http://www.w3.org/2001/XInclude&quot;&gt;
92    &lt;globalConfiguration speaker_drc_enabled=&quot;true&quot;/&gt;
93    &lt;modules&gt;
94        &lt;module name=&quot;primary&quot; halVersion=&quot;3.0&quot;&gt;
95            &lt;attachedDevices&gt;
96                &lt;item&gt;Speaker&lt;/item&gt;
97                &lt;item&gt;Earpiece&lt;/item&gt;
98                &lt;item&gt;Built-In Mic&lt;/item&gt;
99            &lt;/attachedDevices&gt;
100            &lt;defaultOutputDevice&gt;Speaker&lt;/defaultOutputDevice&gt;
101            &lt;mixPorts&gt;
102                &lt;mixPort name=&quot;primary output&quot; role=&quot;source&quot; flags=&quot;AUDIO_OUTPUT_FLAG_PRIMARY&quot;&gt;
103                    &lt;profile name=&quot;&quot; format=&quot;AUDIO_FORMAT_PCM_16_BIT&quot;
104                             samplingRates=&quot;48000&quot; channelMasks=&quot;AUDIO_CHANNEL_OUT_STEREO&quot;/&gt;
105                &lt;/mixPort&gt;
106                &lt;mixPort name=&quot;primary input&quot; role=&quot;sink&quot;&gt;
107                    &lt;profile name=&quot;&quot; format=&quot;AUDIO_FORMAT_PCM_16_BIT&quot;
108                             samplingRates=&quot;8000,16000,48000&quot;
109                             channelMasks=&quot;AUDIO_CHANNEL_IN_MONO&quot;/&gt;
110                &lt;/mixPort&gt;
111            &lt;/mixPorts&gt;
112            &lt;devicePorts&gt;
113                &lt;devicePort tagName=&quot;Earpiece&quot; type=&quot;AUDIO_DEVICE_OUT_EARPIECE&quot; role=&quot;sink&quot;&gt;
114                   &lt;profile name=&quot;&quot; format=&quot;AUDIO_FORMAT_PCM_16_BIT&quot;
115                            samplingRates=&quot;48000&quot; channelMasks=&quot;AUDIO_CHANNEL_IN_MONO&quot;/&gt;
116                &lt;/devicePort&gt;
117                &lt;devicePort tagName=&quot;Speaker&quot; role=&quot;sink&quot; type=&quot;AUDIO_DEVICE_OUT_SPEAKER&quot; address=&quot;&quot;&gt;
118                    &lt;profile name=&quot;&quot; format=&quot;AUDIO_FORMAT_PCM_16_BIT&quot;
119                             samplingRates=&quot;48000&quot; channelMasks=&quot;AUDIO_CHANNEL_OUT_STEREO&quot;/&gt;
120                &lt;/devicePort&gt;
121                &lt;devicePort tagName=&quot;Wired Headset&quot; type=&quot;AUDIO_DEVICE_OUT_WIRED_HEADSET&quot; role=&quot;sink&quot;&gt;
122                    &lt;profile name=&quot;&quot; format=&quot;AUDIO_FORMAT_PCM_16_BIT&quot;
123                             samplingRates=&quot;48000&quot; channelMasks=&quot;AUDIO_CHANNEL_OUT_STEREO&quot;/&gt;
124                &lt;/devicePort&gt;
125                &lt;devicePort tagName=&quot;Built-In Mic&quot; type=&quot;AUDIO_DEVICE_IN_BUILTIN_MIC&quot; role=&quot;source&quot;&gt;
126                    &lt;profile name=&quot;&quot; format=&quot;AUDIO_FORMAT_PCM_16_BIT&quot;
127                             samplingRates=&quot;8000,16000,48000&quot;
128                             channelMasks=&quot;AUDIO_CHANNEL_IN_MONO&quot;/&gt;
129                &lt;/devicePort&gt;
130                &lt;devicePort tagName=&quot;Wired Headset Mic&quot; type=&quot;AUDIO_DEVICE_IN_WIRED_HEADSET&quot; role=&quot;source&quot;&gt;
131                    &lt;profile name=&quot;&quot; format=&quot;AUDIO_FORMAT_PCM_16_BIT&quot;
132                             samplingRates=&quot;8000,16000,48000&quot;
133                             channelMasks=&quot;AUDIO_CHANNEL_IN_MONO&quot;/&gt;
134                &lt;/devicePort&gt;
135            &lt;/devicePorts&gt;
136            &lt;routes&gt;
137                &lt;route type=&quot;mix&quot; sink=&quot;Earpiece&quot; sources=&quot;primary output&quot;/&gt;
138                &lt;route type=&quot;mix&quot; sink=&quot;Speaker&quot; sources=&quot;primary output&quot;/&gt;
139                &lt;route type=&quot;mix&quot; sink=&quot;Wired Headset&quot; sources=&quot;primary output&quot;/&gt;
140                &lt;route type=&quot;mix&quot; sink=&quot;primary input&quot; sources=&quot;Built-In Mic,Wired Headset Mic&quot;/&gt;
141            &lt;/routes&gt;
142        &lt;/module&gt;
143        &lt;xi:include href=&quot;a2dp_audio_policy_configuration.xml&quot;/&gt;
144    &lt;/modules&gt;
145
146    &lt;xi:include href=&quot;audio_policy_volumes.xml&quot;/&gt;
147    &lt;xi:include href=&quot;default_volume_tables.xml&quot;/&gt;
148&lt;/audioPolicyConfiguration&gt;
149</pre></div></div>
150</p>
151
152<p>The top level structure contains modules that correspond to each audio HAL
153hardware module, where each module has a list of mix ports, device ports, and
154routes:</p>
155<ul>
156<li><strong>Mix ports</strong> describe the possible config profiles for streams
157that can be opened at the audio HAL for playback and capture.</li>
158<li><strong>Device ports</strong> describe the devices that can be attached with
159their type (and optionally address and audio properties, if relevant).</li>
160<li><strong>Routes</strong> (new) is now separated from the mix port descriptor,
161enabling description of routes from device to device or stream to device.</li>
162</ul>
163
164<p>Volume tables are simple lists of points defining the curve used to translate
165form a UI index to a volume in dB. A separate include file provides default
166curves, but each curve for a given use case and device category can be
167overwritten.</p>
168
169<div class="toggle-content closed">
170  <p><a href="#" onclick="return toggleContent(this)">
171    <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" />
172    <strong><span class="toggle-content-text">Show volume table example</span>
173    <span class="toggle-content-text" style="display:none;">Hide volume table
174    example</span></strong>
175  </a></p>
176
177  <div class="toggle-content-toggleme">
178<p><pre>
179&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
180&lt;volumes&gt;
181    &lt;reference name=&quot;FULL_SCALE_VOLUME_CURVE&quot;&gt;
182        &lt;point&gt;0,0&lt;/point&gt;
183        &lt;point&gt;100,0&lt;/point&gt;
184    &lt;/reference&gt;
185    &lt;reference name=&quot;SILENT_VOLUME_CURVE&quot;&gt;
186        &lt;point&gt;0,-9600&lt;/point&gt;
187        &lt;point&gt;100,-9600&lt;/point&gt;
188    &lt;/reference&gt;
189    &lt;reference name=&quot;DEFAULT_VOLUME_CURVE&quot;&gt;
190        &lt;point&gt;1,-4950&lt;/point&gt;
191        &lt;point&gt;33,-3350&lt;/point&gt;
192        &lt;point&gt;66,-1700&lt;/point&gt;
193        &lt;point&gt;100,0&lt;/point&gt;
194    &lt;/reference&gt;
195&lt;/volumes&gt;
196</pre></p></div></div>
197
198<div class="toggle-content closed">
199  <p><a href="#" onclick="return toggleContent(this)">
200    <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" />
201    <strong><span class="toggle-content-text">Show volumes example</span>
202    <span class="toggle-content-text" style="display:none;">Hide volumes
203    example</span></strong>
204  </a></p>
205
206  <div class="toggle-content-toggleme">
207<p><pre>
208&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
209&lt;volumes&gt;
210    &lt;volume stream=&quot;AUDIO_STREAM_VOICE_CALL&quot; deviceCategory=&quot;DEVICE_CATEGORY_HEADSET&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
211    &lt;volume stream=&quot;AUDIO_STREAM_VOICE_CALL&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
212    &lt;volume stream=&quot;AUDIO_STREAM_VOICE_CALL&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
213    &lt;volume stream=&quot;AUDIO_STREAM_VOICE_CALL&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
214
215    &lt;volume stream=&quot;AUDIO_STREAM_SYSTEM&quot; deviceCategory=&quot;DEVICE_CATEGORY_HEADSET&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
216    &lt;volume stream=&quot;AUDIO_STREAM_SYSTEM&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
217    &lt;volume stream=&quot;AUDIO_STREAM_SYSTEM&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
218    &lt;volume stream=&quot;AUDIO_STREAM_SYSTEM&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
219
220    &lt;volume stream=&quot;AUDIO_STREAM_RING&quot; deviceCategory=&quot;DEVICE_CATEGORY_HEADSET&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
221    &lt;volume stream=&quot;AUDIO_STREAM_RING&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
222    &lt;volume stream=&quot;AUDIO_STREAM_RING&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
223    &lt;volume stream=&quot;AUDIO_STREAM_RING&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot;ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
224
225    &lt;volume stream=&quot;AUDIO_STREAM_MUSIC&quot; deviceCategory=&quot;DEVICE_CATEGORY_HEADSET&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
226    &lt;volume stream=&quot;AUDIO_STREAM_MUSIC&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot;&gt;
227        &lt;point&gt;1,-5500&lt;/point&gt;
228        &lt;point&gt;20,-4300&lt;/point&gt;
229        &lt;point&gt;86,-1200&lt;/point&gt;
230        &lt;point&gt;100,0&lt;/point&gt;
231    &lt;/volume&gt;
232    &lt;volume stream=&quot;AUDIO_STREAM_MUSIC&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
233    &lt;volume stream=&quot;AUDIO_STREAM_MUSIC&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
234
235    &lt;volume stream=&quot;AUDIO_STREAM_ALARM&quot; deviceCategory=&quot;DEVICE_CATEGORY_HEADSET&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
236    &lt;volume stream=&quot;AUDIO_STREAM_ALARM&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
237    &lt;volume stream=&quot;AUDIO_STREAM_ALARM&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
238    &lt;volume stream=&quot;AUDIO_STREAM_ALARM&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
239
240    &lt;volume stream=&quot;AUDIO_STREAM_NOTIFICATION&quot; deviceCategory=&quot;DEVICE_CATEGORY_HEADSET&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
241    &lt;volume stream=&quot;AUDIO_STREAM_NOTIFICATION&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
242    &lt;volume stream=&quot;AUDIO_STREAM_NOTIFICATION&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
243    &lt;volume stream=&quot;AUDIO_STREAM_NOTIFICATION&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
244
245    &lt;volume stream=&quot;AUDIO_STREAM_BLUETOOTH_SCO&quot; deviceCategory=&quot;DEVICE_CATEGORY_HEADSET&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
246    &lt;volume stream=&quot;AUDIO_STREAM_BLUETOOTH_SCO&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
247    &lt;volume stream=&quot;AUDIO_STREAM_BLUETOOTH_SCO&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
248    &lt;volume stream=&quot;AUDIO_STREAM_BLUETOOTH_SCO&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
249
250    &lt;volume stream=&quot;AUDIO_STREAM_ENFORCED_AUDIBLE&quot; deviceCategory=&quot;DEVICE_CATEGORY_HEADSET&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
251    &lt;volume stream=&quot;AUDIO_STREAM_ENFORCED_AUDIBLE&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
252    &lt;volume stream=&quot;AUDIO_STREAM_ENFORCED_AUDIBLE&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
253    &lt;volume stream=&quot;AUDIO_STREAM_ENFORCED_AUDIBLE&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
254
255    &lt;volume stream=&quot;AUDIO_STREAM_DTMF&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
256    &lt;volume stream=&quot;AUDIO_STREAM_DTMF&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
257    &lt;volume stream=&quot;AUDIO_STREAM_DTMF&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
258    &lt;volume stream=&quot;AUDIO_STREAM_DTMF&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
259
260    &lt;volume stream=&quot;AUDIO_STREAM_TTS&quot; deviceCategory=&quot;DEVICE_CATEGORY_HEADSET&quot; ref=&quot;SILENT_VOLUME_CURVE&quot;/&gt;
261    &lt;volume stream=&quot;AUDIO_STREAM_TTS&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;FULL_SCALE_VOLUME_CURVE&quot;/&gt;
262    &lt;volume stream=&quot;AUDIO_STREAM_TTS&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;SILENT_VOLUME_CURVE&quot;/&gt;
263    &lt;volume stream=&quot;AUDIO_STREAM_TTS&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot; ref=&quot;SILENT_VOLUME_CURVE&quot;/&gt;
264
265    &lt;volume stream=&quot;AUDIO_STREAM_ACCESSIBILITY&quot; deviceCategory=&quot;DEVICE_CATEGORY_HEADSET&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
266    &lt;volume stream=&quot;AUDIO_STREAM_ACCESSIBILITY&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
267    &lt;volume stream=&quot;AUDIO_STREAM_ACCESSIBILITY&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
268    &lt;volume stream=&quot;AUDIO_STREAM_ACCESSIBILITY&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot; ref=&quot;DEFAULT_VOLUME_CURVE&quot;/&gt;
269
270    &lt;volume stream=&quot;AUDIO_STREAM_REROUTING&quot; deviceCategory=&quot;DEVICE_CATEGORY_HEADSET&quot; ref=&quot;FULL_SCALE_VOLUME_CURVE&quot;/&gt;
271    &lt;volume stream=&quot;AUDIO_STREAM_REROUTING&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;FULL_SCALE_VOLUME_CURVE&quot;/&gt;
272    &lt;volume stream=&quot;AUDIO_STREAM_REROUTING&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;FULL_SCALE_VOLUME_CURVE&quot;/&gt;
273    &lt;volume stream=&quot;AUDIO_STREAM_REROUTING&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot; ref=&quot;FULL_SCALE_VOLUME_CURVE&quot;/&gt;
274
275    &lt;volume stream=&quot;AUDIO_STREAM_PATCH&quot; deviceCategory=&quot;DEVICE_CATEGORY_HEADSET&quot; ref=&quot;FULL_SCALE_VOLUME_CURVE&quot;/&gt;
276    &lt;volume stream=&quot;AUDIO_STREAM_PATCH&quot; deviceCategory=&quot;DEVICE_CATEGORY_SPEAKER&quot; ref=&quot;FULL_SCALE_VOLUME_CURVE&quot;/&gt;
277    &lt;volume stream=&quot;AUDIO_STREAM_PATCH&quot; deviceCategory=&quot;DEVICE_CATEGORY_EARPIECE&quot; ref=&quot;FULL_SCALE_VOLUME_CURVE&quot;/&gt;
278    &lt;volume stream=&quot;AUDIO_STREAM_PATCH&quot; deviceCategory=&quot;DEVICE_CATEGORY_EXT_MEDIA&quot; ref=&quot;FULL_SCALE_VOLUME_CURVE&quot;/&gt;
279&lt;/volumes&gt;
280</pre></p></div></div>
281
282<h2 id=file_inclusions>File inclusions</h2>
283<p>The XML Inclusions (XInclude) method can be used to include audio policy
284configuration information located in other  XML files. All included files must
285follow the structure described above with the following restrictions:</p>
286<ul>
287<li>Files can contain only top-level elements.</li>
288<li>Files cannot contain Xinclude elements.</li>
289</ul>
290<p>Use includes to avoid copying standard Android Open Source Project (AOSP)
291audio HAL modules configuration information to all audio policy configuration
292files (which is prone to errors). A standard audio policy configuration xml file
293is provided for the following audio HALs:</p>
294<ul>
295<li><strong>A2DP:</strong> <code>a2dp_audio_policy_configuration.xml</code></li>
296<li><strong>Reroute submix:</strong> <code>rsubmix_audio_policy_configuration.xml</code></li>
297<li><strong>USB:</strong> <code>usb_audio_policy_configuration.xml</code></li>
298</ul>
299
300<h2 id=code_reorg>Audio policy code reorganization</h2>
301<p>Android 7.0 splits <code>AudioPolicyManager.cpp</code> into several modules
302to make it more maintainable and to highlight what is configurable. The new
303organization of <code>frameworks/av/services/audiopolicy</code> includes the
304following modules:</p>
305
306<table>
307<tr>
308<th>Module</th>
309<th>Description</th>
310</tr>
311
312<tr>
313<td><code>/managerdefault</code></td>
314<td>Includes the generic interfaces and behavior implementation common to all
315applications. Similar to <code>AudioPolicyManager.cpp</code> with engine
316functionality and common concepts abstracted away.</td>
317</tr>
318
319<tr>
320<td><code>/common</code></td>
321<td>Defines base classes (e.g data structures for input output audio stream
322profiles, audio device descriptors, audio patches, audio port, etc.). Previously
323defined inside <code>AudioPolicyManager.cpp</code>.</td>
324</tr>
325
326<tr>
327<td><code>/engine</code></td>
328<td><p>Implements the rules that define which device and volumes should be used for
329a given use case. It implements a standard interface with the generic part, such
330as to get the appropriate device for a given playback or capture use case, or to
331set connected devices or external state (i.e. a call state of forced usage) that
332can alter the routing decision.</p>
333<p>Available in two versions, customized and default; use build option
334<code>USE_CONFIGURABLE_AUDIO_POLICY</code> to select.</p></td>
335</tr>
336
337<tr>
338<td><code>/engineconfigurable</code></td>
339<td>Policy engine implementation that relies on parameter framework (see below).
340Configuration is based on the parameter framework and where the policy is
341defined by XML files.</td>
342</tr>
343
344<tr>
345<td><code>/enginedefault</code></td>
346<td>Policy engine implementation based on previous Android Audio Policy Manager
347implementations. This is the default and includes hard coded rules that
348correspond to current Nexus and AOSP implementations.</td>
349</tr>
350
351<tr>
352<td><code>/service</code></td>
353<td>Includes binder interfaces, threading and locking implementation with
354interface to the rest of the framework.</td>
355</tr>
356
357</table>
358
359<h2 id=policy_config>Configuration using parameter-framework</h2>
360<p>Android 7.0 reorganizes audio policy code to make it easier to understand and
361maintain while also supporting an audio policy defined entirely by configuration
362files. The reorganization and audio policy design is based on Intel's parameter
363framework, a plugin-based and rule-based framework for handling parameters.</p>
364
365<p>Using the new configurable audio policy enables vendors OEMs to:</p>
366<ul>
367<li>Describe a system's structure and its parameters in XML.</li>
368<li>Write (in C++) or reuse a backend (plugin) for accessing described
369parameters.</li>
370<li>Define (in XML or in a domain-specific language) conditions/rules upon which
371a given parameter must take a given value.</li>
372</ul>
373
374<p>AOSP includes an example of an audio policy configuration file that uses the parameter-framework at: <code>Frameworks/av/services/audiopolicy/engineconfigurable/parameter-framework/example/Settings/PolicyConfigurableDomains.xml</code>. For
375details, refer to Intel documentation on the
376<a href="https://github.com/01org/parameter-framework">parameter-framework</a>
377and
378<a href="http://01org.github.io/parameter-framework/hosting/Android_M_Configurable_Audio_Policy.pdf">Android
379Configurable Audio Policy</a>.</p>
380
381<h2 id=policy_routing_apis>Audio policy routing APIs</h2>
382<p>Android 6.0 introduced a public Enumeration and Selection API that sits on
383top of the audio patch/audio port infrastructure and allows application
384developers to indicate a preference for a specific device output or input for
385connected audio records or tracks.</p>
386<p>In Android 7.0, the Enumeration and Selection API is verified by CTS tests
387and is extended to include routing for native C/C++ (OpenSL ES) audio streams.
388The routing of native streams continues to be done in Java, with the addition of
389an <code>AudioRouting</code> interface that supersedes, combines, and deprecates
390the explicit routing methods that were specific to <code>AudioTrack</code> and
391<code>AudioRecord</code> classes.</p>
392
393<p>For details on the Enumeration and Selection API, refer to
394<a href="https://developer.android.com/ndk/guides/audio/opensl-for-android.html?hl=fi#configuration-interface">Android
395configuration interfaces</a> and <code>OpenSLES_AndroidConfiguration.h</code>.
396For details on audio routing, refer to
397<a href="https://developer.android.com/reference/android/media/AudioRouting.html">AudioRouting</a>.
398</p>
399
400<h2 id=multichannel>Multi-channel support</h2>
401
402<p>If your hardware and driver supports multichannel audio via HDMI, you can
403output the audio stream  directly to the audio hardware (this bypasses the
404AudioFlinger mixer so it doesn't get downmixed to two channels.) The audio HAL
405must expose whether an output stream profile supports multichannel audio
406capabilities. If the HAL exposes its capabilities, the default policy manager
407allows multichannel playback over HDMI. For implementation details, see
408<code>device/samsung/tuna/audio/audio_hw.c</code>.</p>
409
410<p>To specify that your product contains a multichannel audio output, edit the
411audio policy configuration file to describe the multichannel output for your
412product. The following example from a Galaxy Nexus shows a <em>dynamic</em>
413channel mask, which means the audio policy manager queries the actual channel
414masks supported by the HDMI sink after connection.</p>
415
416<pre>
417audio_hw_modules {
418  primary {
419    outputs {
420        ...
421        hdmi {
422          sampling_rates 44100|48000
423          channel_masks dynamic
424          formats AUDIO_FORMAT_PCM_16_BIT
425          devices AUDIO_DEVICE_OUT_AUX_DIGITAL
426          flags AUDIO_OUTPUT_FLAG_DIRECT
427        }
428        ...
429    }
430    ...
431  }
432  ...
433}
434</pre>
435
436<p>You can also specify a static channel mask such as
437<code>AUDIO_CHANNEL_OUT_5POINT1</code>. AudioFlinger's mixer downmixes the
438content to stereo automatically when sent to an audio device that does not
439support multichannel audio.</p>
440
441<h2 id=codecs>Media codecs</h2>
442
443<p>Ensure the audio codecs your hardware and drivers support are properly
444declared for your product. For details, see
445<a href="{@docRoot}devices/media/index.html#expose">Exposing Codecs to the
446Framework</a>.</p>
447