自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
音频
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 的音频硬件抽象层 (HAL) 可将 android.media 中特定于音频的较高级别的框架 API 连接到底层音频驱动程序和硬件。本部分介绍了有关提升性能的实现说明和提示。
Android 音频架构定义了音频功能的实现方式,并指出实现中所涉及的相关源代码。
图 1. Android 音频架构
-
应用框架
-
应用框架包含应用代码,该代码使用 android.media API 与音频硬件进行交互。在内部,此代码会调用相应的 JNI 粘合类来访问与音频硬件互动的原生代码。
-
JNI
-
与 android.media 关联的 JNI 代码会调用较低级别的原生代码来访问音频硬件。JNI 位于
frameworks/base/core/jni/
和 frameworks/base/media/jni
中。
-
原生框架
-
原生框架提供相当于 android.media 软件包的原生软件包,它调用 Binder IPC 代理来访问媒体服务器的音频专属服务。
原生框架代码位于
frameworks/av/media/libmedia
中。
-
Binder IPC
-
Binder IPC 代理用于促进跨越进程边界的通信。代理位于
frameworks/av/media/libmedia
中,并以字母“I”开头。
-
媒体服务器
-
媒体服务器包含音频服务,这些音频服务是与您的 HAL 实现进行交互的实际代码。媒体服务器位于
frameworks/av/services/audioflinger
中。
-
HAL
-
HAL 定义了音频服务会调用且您必须实现才能使音频硬件正常运行的标准接口。如需了解详情,请参阅音频 HAL 接口并查看相应 HAL 版本目录的
*.hal
文件中的注释。
-
内核驱动程序
-
音频驱动程序用于同您的硬件和 HAL 实现进行交互。您可以使用高级 Linux 声音架构 (ALSA)、开放声音系统 (OSS) 或自定义驱动程序(HAL 与驱动程序无关)。
注意:如果您使用的是 ALSA,建议将 external/tinyalsa
用于驱动程序的用户部分,因为它具有兼容的许可(标准的用户模式库已获得 GPL 许可)。
-
基于 Open SL ES 的 Android 原生音频(未显示)
-
此 API 作为 Android NDK 的一部分提供,且与 android.media 位于同一架构层级。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-05。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-05。"],[],[],null,["# Audio\n\nAndroid's audio Hardware Abstraction Layer (HAL) connects the higher-level,\naudio-specific framework APIs in [android.media](http://developer.android.com/reference/android/media/package-summary.html) to the underlying audio driver and\nhardware. This section includes implementation instructions and tips for\nimproving performance.\n\n\nAndroid audio architecture defines how audio functionality is implemented and\npoints to the relevant source code involved in the implementation.\n\n\n**Figure 1.** Android audio architecture\n\n\nApplication framework\n:\n The application framework includes the app code, which uses the [android.media](http://developer.android.com/reference/android/media/package-summary.html) APIs to\n interact with audio hardware. Internally, this code calls corresponding JNI glue\n classes to access the native code that interacts with audio hardware.\n\n\nJNI\n:\n The JNI code associated with [android.media](http://developer.android.com/reference/android/media/package-summary.html) calls lower level native code to access audio\n hardware. JNI is located in `frameworks/base/core/jni/` and\n `frameworks/base/media/jni`.\n\n\nNative framework\n:\n The native framework provides a native equivalent to the [android.media](http://developer.android.com/reference/android/media/package-summary.html) package, calling\n Binder IPC proxies to access the audio-specific services of the media server.\n Native framework code is located in `frameworks/av/media/libmedia`.\n\n\nBinder IPC\n:\n Binder IPC proxies facilitate communication over process boundaries. Proxies are\n located in `frameworks/av/media/libmedia` and begin with the letter\n \"I\".\n\n\nMedia server\n:\n The media server contains audio services, which are the actual code that\n interacts with your HAL implementations. The media server is located in\n `frameworks/av/services/audioflinger`.\n\n\nHAL\n:\n The HAL defines the standard interface that audio services call into and that\n you must implement for your audio hardware to function correctly. For more details, refer to the [audio HAL\n interface](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/audio/) and comments in the `*.hal` files of the corresponding HAL version directory.\n\n\nKernel driver\n\n: The audio driver interacts with your hardware and HAL implementation. You can use Advanced Linux Sound Architecture (ALSA), Open Sound System (OSS), or a custom driver (HAL is driver-agnostic). **Note** : If you use ALSA, we recommend\n `external/tinyalsa` for the user portion of the driver because of its\n compatible licensing (the standard user-mode library is GPL-licensed).\n\n\nAndroid native audio based on Open SL ES *(not shown)*\n:\n This API is exposed as part of\n [Android NDK](https://developer.android.com/tools/sdk/ndk/index.html)\n and is at the same architecture level as\n [android.media](http://developer.android.com/reference/android/media/package-summary.html)."]]