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