自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
音訊
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
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 實作互動。您可以使用 Advanced Linux Sound Architecture (ALSA)、Open Sound System (OSS) 或自訂驅動程式 (HAL 是驅動程式無關的)。
注意:如果您使用 ALSA,建議您將 external/tinyalsa
用於驅動程式的使用者部分,因為其相容的授權 (標準使用者模式程式庫為 GPL 授權)。
-
以 OpenSL ES 為基礎的 Android 原生音訊 (未顯示)
-
這個 API 會在 Android NDK 中公開,且與 android.media 位於相同的架構層級。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],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)."]]