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