Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 1 | page.title=Audio |
| 2 | @jd:body |
| 3 | |
| 4 | <!-- |
Heidi von Markham | 1e7b8b7 | 2015-03-09 10:13:48 -0700 | [diff] [blame] | 5 | Copyright 2015 The Android Open Source Project |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 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 | --> |
Heidi von Markham | 1e7b8b7 | 2015-03-09 10:13:48 -0700 | [diff] [blame] | 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 | |
Heidi von Markham | b493fb6 | 2015-03-25 12:35:11 -0700 | [diff] [blame] | 28 | <img style="float: right; margin: 0px 15px 15px 15px;" src="images/ape_fwk_hal_audio.png" alt="Android Audio HAL icon"/> |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 29 | <p> |
Glenn Kasten | ff257d4 | 2014-11-10 16:29:03 -0800 | [diff] [blame] | 30 | Android's audio Hardware Abstraction Layer (HAL) connects the higher-level, audio-specific |
Heidi von Markham | 1e7b8b7 | 2015-03-09 10:13:48 -0700 | [diff] [blame] | 31 | framework APIs in <a href="http://developer.android.com/reference/android/media/package-summary.html">android.media</a> to the underlying audio driver and hardware. This section includes implementation instructions and tips for improving performance.</p> |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 32 | </p> |
Heidi von Markham | 1e7b8b7 | 2015-03-09 10:13:48 -0700 | [diff] [blame] | 33 | <h2 id="Architecture">Audio Architecture</h2> |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 34 | <p> |
| 35 | The following figure and list describe how audio functionality is implemented and the relevant |
| 36 | source code that is involved in the implementation: |
| 37 | </p> |
Heidi von Markham | 1e7b8b7 | 2015-03-09 10:13:48 -0700 | [diff] [blame] | 38 | <img src="images/ape_fwk_audio.png" alt="Audio architecture" id="figure1" /> |
Clay Murphy | 1b77cc2 | 2014-12-17 18:20:06 -0800 | [diff] [blame] | 39 | <p class="img-caption"> |
| 40 | <strong>Figure 1.</strong> Android audio architecture |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 41 | </p> |
| 42 | <dl> |
| 43 | <dt> |
| 44 | Application framework |
| 45 | </dt> |
| 46 | <dd> |
| 47 | At the application framework level is the app code, which utilizes the |
| 48 | <a href="http://developer.android.com/reference/android/media/package-summary.html">android.media</a> |
| 49 | APIs to interact with the audio hardware. Internally, this code calls corresponding JNI glue |
Clay Murphy | c28f237 | 2013-09-25 16:13:40 -0700 | [diff] [blame] | 50 | classes to access the native code that interacts with the audio hardware. |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 51 | </dd> |
| 52 | <dt> |
| 53 | JNI |
| 54 | </dt> |
| 55 | <dd> |
| 56 | The JNI code associated with <a href="http://developer.android.com/reference/android/media/package-summary.html">android.media</a> is located in the |
| 57 | <code>frameworks/base/core/jni/</code> and <code>frameworks/base/media/jni</code> directories. |
| 58 | This code calls the lower level native code to obtain access to the audio hardware. |
| 59 | </dd> |
| 60 | <dt> |
| 61 | Native framework |
| 62 | </dt> |
| 63 | <dd> |
| 64 | The native framework is defined in <code>frameworks/av/media/libmedia</code> and provides a |
| 65 | native equivalent to the <a href="http://developer.android.com/reference/android/media/package-summary.html">android.media</a> package. The native framework calls the Binder |
| 66 | IPC proxies to obtain access to audio-specific services of the media server. |
| 67 | </dd> |
| 68 | <dt> |
| 69 | Binder IPC |
| 70 | </dt> |
| 71 | <dd> |
| 72 | The Binder IPC proxies facilitate communication over process boundaries. They are located in |
| 73 | the <code>frameworks/av/media/libmedia</code> directory and begin with the letter "I". |
| 74 | </dd> |
| 75 | <dt> |
| 76 | Media Server |
| 77 | </dt> |
| 78 | <dd> |
| 79 | The audio services in the media server, located in |
| 80 | <code>frameworks/av/services/audioflinger</code>, is the actual code that interacts with your |
| 81 | HAL implementations. |
| 82 | </dd> |
| 83 | <dt> |
| 84 | HAL |
| 85 | </dt> |
| 86 | <dd> |
Clay Murphy | c28f237 | 2013-09-25 16:13:40 -0700 | [diff] [blame] | 87 | The HAL defines the standard interface that audio services call into |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 88 | and that you must implement to have your audio hardware function correctly. The audio HAL |
Clay Murphy | c28f237 | 2013-09-25 16:13:40 -0700 | [diff] [blame] | 89 | interfaces are located in |
| 90 | <code>hardware/libhardware/include/hardware</code>. See <a |
Glenn Kasten | ff257d4 | 2014-11-10 16:29:03 -0800 | [diff] [blame] | 91 | href="{@docRoot}devices/halref/audio_8h_source.html"><hardware/audio.h></a> for additional details. |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 92 | </dd> |
| 93 | <dt> |
| 94 | Kernel Driver |
| 95 | </dt> |
| 96 | <dd> |
| 97 | The audio driver interacts with the hardware and your implementation of the HAL. You can choose |
| 98 | to use ALSA, OSS, or a custom driver of your own at this level. The HAL is driver-agnostic. |
| 99 | <p> |
| 100 | <strong>Note:</strong> If you do choose ALSA, we recommend using <code>external/tinyalsa</code> |
| 101 | for the user portion of the driver because of its compatible licensing (The standard user-mode |
| 102 | library is GPL licensed). |
| 103 | </p> |
| 104 | </dd> |
| 105 | </dl> |
Glenn Kasten | ff257d4 | 2014-11-10 16:29:03 -0800 | [diff] [blame] | 106 | <p> |
| 107 | Not shown: Android native audio based on OpenSL ES. |
| 108 | This API is exposed as part of |
| 109 | <a href="https://developer.android.com/tools/sdk/ndk/index.html">Android NDK</a>, |
| 110 | and is at the same architecture level as |
| 111 | <a href="http://developer.android.com/reference/android/media/package-summary.html">android.media</a>. |
Heidi von Markham | 1e7b8b7 | 2015-03-09 10:13:48 -0700 | [diff] [blame] | 112 | </p> |