Heidi von Markham | d0333d6 | 2016-07-08 12:05:46 -0700 | [diff] [blame] | 1 | page.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 |
| 28 | describing your audio topology.</p> |
| 29 | |
| 30 | <p>Previous Android releases required using the |
| 31 | <code>device/<company>/<device>/audio/audio_policy.conf</code> |
| 32 | to declare the audio devices present on your product (you can see an example of |
| 33 | this file for the Galaxy Nexus audio hardware in |
| 34 | <code>device/samsung/tuna/audio/audio_policy.conf</code>). However, .conf is a |
| 35 | simple proprietary format that is too limited to describe complex topologies for |
| 36 | applications such as televisions and automobiles.</p> |
| 37 | |
| 38 | <p>Android 7.0 deprecates the <code>audio_policy.conf</code> and adds support |
| 39 | for defining audio topology using an XML file format that is more |
| 40 | human-readable, has a wide range of editing and parsing tools, and is flexible |
| 41 | enough 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 |
| 45 | the 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 |
| 50 | of output an input stream profiles, devices usable for playback and capture, and |
| 51 | audio 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 |
| 56 | and enable a different set of sampling rates/channel masks for each audio |
| 57 | format.</li> |
| 58 | <li>Explicit definitions of all possible connections between devices and |
| 59 | streams. Previously, an implicit rule made it possible to interconnect all |
| 60 | devices attached to the same HAL module, preventing the audio policy from |
| 61 | controlling connections requested with audio patch APIs. In the XML format, the |
| 62 | topology description now defines connection limitations.</li> |
| 63 | <li>Support for <em>includes</em> avoids repeating standard A2DP, USB, or |
| 64 | reroute submit definitions.</li> |
| 65 | <li>Customizable volume curves. Previously, volume tables were hardcoded. In the |
| 66 | XML 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> |
| 71 | shows 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 |
| 77 | XML 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 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
| 91 | <audioPolicyConfiguration version="1.0" xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 92 | <globalConfiguration speaker_drc_enabled="true"/> |
| 93 | <modules> |
| 94 | <module name="primary" halVersion="3.0"> |
| 95 | <attachedDevices> |
| 96 | <item>Speaker</item> |
| 97 | <item>Earpiece</item> |
| 98 | <item>Built-In Mic</item> |
| 99 | </attachedDevices> |
| 100 | <defaultOutputDevice>Speaker</defaultOutputDevice> |
| 101 | <mixPorts> |
| 102 | <mixPort name="primary output" role="source" flags="AUDIO_OUTPUT_FLAG_PRIMARY"> |
| 103 | <profile name="" format="AUDIO_FORMAT_PCM_16_BIT" |
| 104 | samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/> |
| 105 | </mixPort> |
| 106 | <mixPort name="primary input" role="sink"> |
| 107 | <profile name="" format="AUDIO_FORMAT_PCM_16_BIT" |
| 108 | samplingRates="8000,16000,48000" |
| 109 | channelMasks="AUDIO_CHANNEL_IN_MONO"/> |
| 110 | </mixPort> |
| 111 | </mixPorts> |
| 112 | <devicePorts> |
| 113 | <devicePort tagName="Earpiece" type="AUDIO_DEVICE_OUT_EARPIECE" role="sink"> |
| 114 | <profile name="" format="AUDIO_FORMAT_PCM_16_BIT" |
| 115 | samplingRates="48000" channelMasks="AUDIO_CHANNEL_IN_MONO"/> |
| 116 | </devicePort> |
| 117 | <devicePort tagName="Speaker" role="sink" type="AUDIO_DEVICE_OUT_SPEAKER" address=""> |
| 118 | <profile name="" format="AUDIO_FORMAT_PCM_16_BIT" |
| 119 | samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/> |
| 120 | </devicePort> |
| 121 | <devicePort tagName="Wired Headset" type="AUDIO_DEVICE_OUT_WIRED_HEADSET" role="sink"> |
| 122 | <profile name="" format="AUDIO_FORMAT_PCM_16_BIT" |
| 123 | samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/> |
| 124 | </devicePort> |
| 125 | <devicePort tagName="Built-In Mic" type="AUDIO_DEVICE_IN_BUILTIN_MIC" role="source"> |
| 126 | <profile name="" format="AUDIO_FORMAT_PCM_16_BIT" |
| 127 | samplingRates="8000,16000,48000" |
| 128 | channelMasks="AUDIO_CHANNEL_IN_MONO"/> |
| 129 | </devicePort> |
| 130 | <devicePort tagName="Wired Headset Mic" type="AUDIO_DEVICE_IN_WIRED_HEADSET" role="source"> |
| 131 | <profile name="" format="AUDIO_FORMAT_PCM_16_BIT" |
| 132 | samplingRates="8000,16000,48000" |
| 133 | channelMasks="AUDIO_CHANNEL_IN_MONO"/> |
| 134 | </devicePort> |
| 135 | </devicePorts> |
| 136 | <routes> |
| 137 | <route type="mix" sink="Earpiece" sources="primary output"/> |
| 138 | <route type="mix" sink="Speaker" sources="primary output"/> |
| 139 | <route type="mix" sink="Wired Headset" sources="primary output"/> |
| 140 | <route type="mix" sink="primary input" sources="Built-In Mic,Wired Headset Mic"/> |
| 141 | </routes> |
| 142 | </module> |
| 143 | <xi:include href="a2dp_audio_policy_configuration.xml"/> |
| 144 | </modules> |
| 145 | |
| 146 | <xi:include href="audio_policy_volumes.xml"/> |
| 147 | <xi:include href="default_volume_tables.xml"/> |
| 148 | </audioPolicyConfiguration> |
| 149 | </pre></div></div> |
| 150 | </p> |
| 151 | |
| 152 | <p>The top level structure contains modules that correspond to each audio HAL |
| 153 | hardware module, where each module has a list of mix ports, device ports, and |
| 154 | routes:</p> |
| 155 | <ul> |
| 156 | <li><strong>Mix ports</strong> describe the possible config profiles for streams |
| 157 | that 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 |
| 159 | their type (and optionally address and audio properties, if relevant).</li> |
| 160 | <li><strong>Routes</strong> (new) is now separated from the mix port descriptor, |
| 161 | enabling 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 |
| 165 | form a UI index to a volume in dB. A separate include file provides default |
| 166 | curves, but each curve for a given use case and device category can be |
| 167 | overwritten.</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 | <?xml version="1.0" encoding="UTF-8"?> |
| 180 | <volumes> |
| 181 | <reference name="FULL_SCALE_VOLUME_CURVE"> |
| 182 | <point>0,0</point> |
| 183 | <point>100,0</point> |
| 184 | </reference> |
| 185 | <reference name="SILENT_VOLUME_CURVE"> |
| 186 | <point>0,-9600</point> |
| 187 | <point>100,-9600</point> |
| 188 | </reference> |
| 189 | <reference name="DEFAULT_VOLUME_CURVE"> |
| 190 | <point>1,-4950</point> |
| 191 | <point>33,-3350</point> |
| 192 | <point>66,-1700</point> |
| 193 | <point>100,0</point> |
| 194 | </reference> |
| 195 | </volumes> |
| 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 | <?xml version="1.0" encoding="UTF-8"?> |
| 209 | <volumes> |
| 210 | <volume stream="AUDIO_STREAM_VOICE_CALL" deviceCategory="DEVICE_CATEGORY_HEADSET" ref="DEFAULT_VOLUME_CURVE"/> |
| 211 | <volume stream="AUDIO_STREAM_VOICE_CALL" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="DEFAULT_VOLUME_CURVE"/> |
| 212 | <volume stream="AUDIO_STREAM_VOICE_CALL" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="DEFAULT_VOLUME_CURVE"/> |
| 213 | <volume stream="AUDIO_STREAM_VOICE_CALL" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA" ref="DEFAULT_VOLUME_CURVE"/> |
| 214 | |
| 215 | <volume stream="AUDIO_STREAM_SYSTEM" deviceCategory="DEVICE_CATEGORY_HEADSET" ref="DEFAULT_VOLUME_CURVE"/> |
| 216 | <volume stream="AUDIO_STREAM_SYSTEM" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="DEFAULT_VOLUME_CURVE"/> |
| 217 | <volume stream="AUDIO_STREAM_SYSTEM" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="DEFAULT_VOLUME_CURVE"/> |
| 218 | <volume stream="AUDIO_STREAM_SYSTEM" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA" ref="DEFAULT_VOLUME_CURVE"/> |
| 219 | |
| 220 | <volume stream="AUDIO_STREAM_RING" deviceCategory="DEVICE_CATEGORY_HEADSET" ref="DEFAULT_VOLUME_CURVE"/> |
| 221 | <volume stream="AUDIO_STREAM_RING" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="DEFAULT_VOLUME_CURVE"/> |
| 222 | <volume stream="AUDIO_STREAM_RING" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="DEFAULT_VOLUME_CURVE"/> |
| 223 | <volume stream="AUDIO_STREAM_RING" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA"ref="DEFAULT_VOLUME_CURVE"/> |
| 224 | |
| 225 | <volume stream="AUDIO_STREAM_MUSIC" deviceCategory="DEVICE_CATEGORY_HEADSET" ref="DEFAULT_VOLUME_CURVE"/> |
| 226 | <volume stream="AUDIO_STREAM_MUSIC" deviceCategory="DEVICE_CATEGORY_SPEAKER"> |
| 227 | <point>1,-5500</point> |
| 228 | <point>20,-4300</point> |
| 229 | <point>86,-1200</point> |
| 230 | <point>100,0</point> |
| 231 | </volume> |
| 232 | <volume stream="AUDIO_STREAM_MUSIC" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="DEFAULT_VOLUME_CURVE"/> |
| 233 | <volume stream="AUDIO_STREAM_MUSIC" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA" ref="DEFAULT_VOLUME_CURVE"/> |
| 234 | |
| 235 | <volume stream="AUDIO_STREAM_ALARM" deviceCategory="DEVICE_CATEGORY_HEADSET" ref="DEFAULT_VOLUME_CURVE"/> |
| 236 | <volume stream="AUDIO_STREAM_ALARM" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="DEFAULT_VOLUME_CURVE"/> |
| 237 | <volume stream="AUDIO_STREAM_ALARM" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="DEFAULT_VOLUME_CURVE"/> |
| 238 | <volume stream="AUDIO_STREAM_ALARM" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA" ref="DEFAULT_VOLUME_CURVE"/> |
| 239 | |
| 240 | <volume stream="AUDIO_STREAM_NOTIFICATION" deviceCategory="DEVICE_CATEGORY_HEADSET" ref="DEFAULT_VOLUME_CURVE"/> |
| 241 | <volume stream="AUDIO_STREAM_NOTIFICATION" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="DEFAULT_VOLUME_CURVE"/> |
| 242 | <volume stream="AUDIO_STREAM_NOTIFICATION" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="DEFAULT_VOLUME_CURVE"/> |
| 243 | <volume stream="AUDIO_STREAM_NOTIFICATION" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA" ref="DEFAULT_VOLUME_CURVE"/> |
| 244 | |
| 245 | <volume stream="AUDIO_STREAM_BLUETOOTH_SCO" deviceCategory="DEVICE_CATEGORY_HEADSET" ref="DEFAULT_VOLUME_CURVE"/> |
| 246 | <volume stream="AUDIO_STREAM_BLUETOOTH_SCO" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="DEFAULT_VOLUME_CURVE"/> |
| 247 | <volume stream="AUDIO_STREAM_BLUETOOTH_SCO" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="DEFAULT_VOLUME_CURVE"/> |
| 248 | <volume stream="AUDIO_STREAM_BLUETOOTH_SCO" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA" ref="DEFAULT_VOLUME_CURVE"/> |
| 249 | |
| 250 | <volume stream="AUDIO_STREAM_ENFORCED_AUDIBLE" deviceCategory="DEVICE_CATEGORY_HEADSET" ref="DEFAULT_VOLUME_CURVE"/> |
| 251 | <volume stream="AUDIO_STREAM_ENFORCED_AUDIBLE" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="DEFAULT_VOLUME_CURVE"/> |
| 252 | <volume stream="AUDIO_STREAM_ENFORCED_AUDIBLE" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="DEFAULT_VOLUME_CURVE"/> |
| 253 | <volume stream="AUDIO_STREAM_ENFORCED_AUDIBLE" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA" ref="DEFAULT_VOLUME_CURVE"/> |
| 254 | |
| 255 | <volume stream="AUDIO_STREAM_DTMF" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="DEFAULT_VOLUME_CURVE"/> |
| 256 | <volume stream="AUDIO_STREAM_DTMF" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="DEFAULT_VOLUME_CURVE"/> |
| 257 | <volume stream="AUDIO_STREAM_DTMF" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="DEFAULT_VOLUME_CURVE"/> |
| 258 | <volume stream="AUDIO_STREAM_DTMF" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA" ref="DEFAULT_VOLUME_CURVE"/> |
| 259 | |
| 260 | <volume stream="AUDIO_STREAM_TTS" deviceCategory="DEVICE_CATEGORY_HEADSET" ref="SILENT_VOLUME_CURVE"/> |
| 261 | <volume stream="AUDIO_STREAM_TTS" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="FULL_SCALE_VOLUME_CURVE"/> |
| 262 | <volume stream="AUDIO_STREAM_TTS" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="SILENT_VOLUME_CURVE"/> |
| 263 | <volume stream="AUDIO_STREAM_TTS" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA" ref="SILENT_VOLUME_CURVE"/> |
| 264 | |
| 265 | <volume stream="AUDIO_STREAM_ACCESSIBILITY" deviceCategory="DEVICE_CATEGORY_HEADSET" ref="DEFAULT_VOLUME_CURVE"/> |
| 266 | <volume stream="AUDIO_STREAM_ACCESSIBILITY" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="DEFAULT_VOLUME_CURVE"/> |
| 267 | <volume stream="AUDIO_STREAM_ACCESSIBILITY" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="DEFAULT_VOLUME_CURVE"/> |
| 268 | <volume stream="AUDIO_STREAM_ACCESSIBILITY" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA" ref="DEFAULT_VOLUME_CURVE"/> |
| 269 | |
| 270 | <volume stream="AUDIO_STREAM_REROUTING" deviceCategory="DEVICE_CATEGORY_HEADSET" ref="FULL_SCALE_VOLUME_CURVE"/> |
| 271 | <volume stream="AUDIO_STREAM_REROUTING" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="FULL_SCALE_VOLUME_CURVE"/> |
| 272 | <volume stream="AUDIO_STREAM_REROUTING" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="FULL_SCALE_VOLUME_CURVE"/> |
| 273 | <volume stream="AUDIO_STREAM_REROUTING" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA" ref="FULL_SCALE_VOLUME_CURVE"/> |
| 274 | |
| 275 | <volume stream="AUDIO_STREAM_PATCH" deviceCategory="DEVICE_CATEGORY_HEADSET" ref="FULL_SCALE_VOLUME_CURVE"/> |
| 276 | <volume stream="AUDIO_STREAM_PATCH" deviceCategory="DEVICE_CATEGORY_SPEAKER" ref="FULL_SCALE_VOLUME_CURVE"/> |
| 277 | <volume stream="AUDIO_STREAM_PATCH" deviceCategory="DEVICE_CATEGORY_EARPIECE" ref="FULL_SCALE_VOLUME_CURVE"/> |
| 278 | <volume stream="AUDIO_STREAM_PATCH" deviceCategory="DEVICE_CATEGORY_EXT_MEDIA" ref="FULL_SCALE_VOLUME_CURVE"/> |
| 279 | </volumes> |
| 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 |
| 284 | configuration information located in other XML files. All included files must |
| 285 | follow 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) |
| 291 | audio HAL modules configuration information to all audio policy configuration |
| 292 | files (which is prone to errors). A standard audio policy configuration xml file |
| 293 | is 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 |
| 302 | to make it more maintainable and to highlight what is configurable. The new |
| 303 | organization of <code>frameworks/av/services/audiopolicy</code> includes the |
| 304 | following 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 |
| 315 | applications. Similar to <code>AudioPolicyManager.cpp</code> with engine |
| 316 | functionality 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 |
| 322 | profiles, audio device descriptors, audio patches, audio port, etc.). Previously |
| 323 | defined 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 |
| 329 | a given use case. It implements a standard interface with the generic part, such |
| 330 | as to get the appropriate device for a given playback or capture use case, or to |
| 331 | set connected devices or external state (i.e. a call state of forced usage) that |
| 332 | can 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). |
| 340 | Configuration is based on the parameter framework and where the policy is |
| 341 | defined 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 |
| 347 | implementations. This is the default and includes hard coded rules that |
| 348 | correspond 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 |
| 354 | interface 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 |
| 361 | maintain while also supporting an audio policy defined entirely by configuration |
| 362 | files. The reorganization and audio policy design is based on Intel's parameter |
| 363 | framework, 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 |
| 369 | parameters.</li> |
| 370 | <li>Define (in XML or in a domain-specific language) conditions/rules upon which |
| 371 | a 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 |
| 375 | details, refer to Intel documentation on the |
| 376 | <a href="https://github.com/01org/parameter-framework">parameter-framework</a> |
| 377 | and |
| 378 | <a href="http://01org.github.io/parameter-framework/hosting/Android_M_Configurable_Audio_Policy.pdf">Android |
| 379 | Configurable 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 |
| 383 | top of the audio patch/audio port infrastructure and allows application |
| 384 | developers to indicate a preference for a specific device output or input for |
| 385 | connected audio records or tracks.</p> |
| 386 | <p>In Android 7.0, the Enumeration and Selection API is verified by CTS tests |
| 387 | and is extended to include routing for native C/C++ (OpenSL ES) audio streams. |
| 388 | The routing of native streams continues to be done in Java, with the addition of |
| 389 | an <code>AudioRouting</code> interface that supersedes, combines, and deprecates |
| 390 | the 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 |
| 395 | configuration interfaces</a> and <code>OpenSLES_AndroidConfiguration.h</code>. |
| 396 | For 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 |
| 403 | output the audio stream directly to the audio hardware (this bypasses the |
| 404 | AudioFlinger mixer so it doesn't get downmixed to two channels.) The audio HAL |
| 405 | must expose whether an output stream profile supports multichannel audio |
| 406 | capabilities. If the HAL exposes its capabilities, the default policy manager |
| 407 | allows 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 |
| 411 | audio policy configuration file to describe the multichannel output for your |
| 412 | product. The following example from a Galaxy Nexus shows a <em>dynamic</em> |
| 413 | channel mask, which means the audio policy manager queries the actual channel |
| 414 | masks supported by the HDMI sink after connection.</p> |
| 415 | |
| 416 | <pre> |
| 417 | audio_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 |
| 438 | content to stereo automatically when sent to an audio device that does not |
| 439 | support 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 |
| 444 | declared for your product. For details, see |
| 445 | <a href="{@docRoot}devices/media/index.html#expose">Exposing Codecs to the |
| 446 | Framework</a>.</p> |