1page.title=Audio 2@jd:body 3 4<!-- 5 Copyright 2015 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 20<div id="qv-wrapper"> 21 <div id="qv"> 22 <h2>In this document</h2> 23 <ol id="auto-toc"> 24 </ol> 25 </div> 26</div> 27 28<img style="float: right; margin: 0px 15px 15px 15px;" 29src="images/ape_fwk_hal_audio.png" alt="Android Audio HAL icon"/> 30 31<p> 32Android's audio Hardware Abstraction Layer (HAL) connects the higher-level, 33audio-specific framework APIs in <a href="http://developer.android.com/reference/android/media/package-summary.html">android.media</a> to the underlying audio driver and 34hardware. This section includes implementation instructions and tips for 35improving performance. 36</p> 37 38<h2 id="Architecture">Audio Architecture</h2> 39<p> 40Android audio architecture defines how audio functionality is implemented and 41points to the relevant source code involved in the implementation. 42</p> 43 44<img src="images/ape_fwk_audio.png" alt="Audio architecture" id="figure1" /> 45 46<p class="img-caption"> 47<strong>Figure 1.</strong> Android audio architecture 48</p> 49 50<dl> 51 52<dt> 53Application framework 54</dt> 55<dd> 56The application framework includes the app code, which uses the <a href="http://developer.android.com/reference/android/media/package-summary.html">android.media</a> APIs to 57interact with audio hardware. Internally, this code calls corresponding JNI glue 58classes to access the native code that interacts with audio hardware. 59</dd> 60 61<dt> 62JNI 63</dt> 64<dd> 65The JNI code associated with <a href="http://developer.android.com/reference/android/media/package-summary.html">android.media</a> calls lower level native code to access audio 66hardware. JNI is located in <code>frameworks/base/core/jni/</code> and 67<code>frameworks/base/media/jni</code>. 68</dd> 69 70<dt> 71Native framework 72</dt> 73<dd> 74The native framework provides a native equivalent to the <a href="http://developer.android.com/reference/android/media/package-summary.html">android.media</a> package, calling 75Binder IPC proxies to access the audio-specific services of the media server. 76Native framework code is located in <code>frameworks/av/media/libmedia</code>. 77</dd> 78 79<dt> 80Binder IPC 81</dt> 82<dd> 83Binder IPC proxies facilitate communication over process boundaries. Proxies are 84located in <code>frameworks/av/media/libmedia</code> and begin with the letter 85"I". 86</dd> 87 88<dt> 89Media server 90</dt> 91<dd> 92The media server contains audio services, which are the actual code that 93interacts with your HAL implementations. The media server is located in 94<code>frameworks/av/services/audioflinger</code>. 95</dd> 96 97<dt> 98HAL 99</dt> 100<dd> 101The HAL defines the standard interface that audio services call into and that 102you must implement for your audio hardware to function correctly. The audio HAL 103interfaces are located in <code>hardware/libhardware/include/hardware</code>. 104For details, see <a 105href="{@docRoot}devices/halref/audio_8h_source.html">hardware/audio.h</a>. 106</dd> 107 108<dt> 109Kernel driver 110</dt> 111<dd> 112The audio driver interacts with your hardware and HAL implementation. You can 113use Advanced Linux Sound Architecture (ALSA), Open Sound System (OSS), or a 114custom driver (HAL is driver-agnostic). 115<p class="note"><strong>Note</strong>: If you use ALSA, we recommend 116<code>external/tinyalsa</code> for the user portion of the driver because of its 117compatible licensing (the standard user-mode library is GPL-licensed).</p> 118</dd> 119 120<dt> 121Android native audio based on Open SL ES <em>(not shown)</em> 122</dt> 123<dd> 124This API is exposed as part of 125<a href="https://developer.android.com/tools/sdk/ndk/index.html">Android NDK</a> 126and is at the same architecture level as 127<a href="http://developer.android.com/reference/android/media/package-summary.html">android.media</a>. 128</dd> 129 130</dl>