AIDL 和 HIDL Audio HAL 比較

從 Android 14 開始,我們鼓勵合作夥伴和 SoC 供應商以 AIDL HAL 實作項目取代目前的 HIDL HAL 實作項目。

為方便從 HIDL Audio HAL 順利轉換至 AIDL Audio HAL,本頁面將重點說明兩者之間的主要差異。本頁面也會顯示 Audio HAL 的 AIDL 和 HIDL 介面之間的對應關係。

AIDL 和 HIDL 音訊 HAL 實作方式的差異

HIDL 結構和 AIDL 結構的主要差異如下:

  • AIDL Audio Core HAL 中,導入了 IConfig 介面,取代 HIDL HAL 中 XML 檔案的系統範圍參數。架構會從 Core HAL 讀取這些參數,而不是從供應商設定檔讀取。舉例來說,使用者控制項顯示的環繞音效格式清單,是由 Core HAL 中的 IConfig.getSurroundSoundConfig 方法提供。

    AIDL 音效 HAL 中,HIDL 音效 HAL 的 XML 檔案中定義的 effectProxy 邏輯會移至音訊架構。音訊架構會使用 IFactory.queryEffects 查詢系統中的所有效果執行個體,並使用 IFactory.queryProcessing 查詢所有效果處理程序。

  • 為避免與音訊裝置類型使用的「裝置」一詞混淆,HIDL Audio HAL 中的 IDevice 會在 AIDL Audio HAL 中重新命名為 IModule

  • AIDL Audio HAL 會取代 IPrimaryDevice。架構會將目前的音訊模式和螢幕旋轉更新傳送至每個 IModule 執行個體。專屬 IBluetooth 介面會處理與藍牙同步連線導向 (BT SCO) 和免持聽筒設定檔 (HFP) 相關的參數。專屬 ITelephony 介面提供電話專用控制項。您可以從 IModule 介面的主要執行個體擷取這兩個介面的執行個體。詳情請參閱「核心 HAL」和「功能相關功能」的比較表。

  • AIDL Audio HAL 中已移除 IDevicesFactory,以免造成多餘的程式碼。HAL 模組 (即 IModule 介面執行個體) 現在會使用模組執行個體名稱 (例如 bluetoothr_submix) 直接向服務管理員註冊。唯一的例外是 primary 模組,該模組會以執行個體名稱 default 註冊。

AIDL 和 HIDL 音訊 HAL 對應

以下各節的表格顯示 HIDL 和 AIDL Audio HAL 介面之間的對應關係。如要進一步瞭解目錄結構,請參閱音訊 HAL

核心 HAL

所有 HIDL 介面都位於 android.hardware.audio@N.M 套件中,其中 N.M 表示 Major.Minor 版本。所有 AIDL 介面都位於 android.hardware.audio.core 套件中。

HIDL API 介面和設定檔 AIDL API 介面
IDevicesFactory 已註冊 IModule (註冊商:ServiceManager)。
IDevice IModule
IPrimaryDevice ITelephony
IBluetooth
IStream
IStreamIn
IStreamOut
StreamDescriptor
IStreamIn
IStreamCommon
IStreamOut
audio_policy_configuration.xml
audio_policy_engine_configuration.xml
IConfig
IModule
可設定的音訊政策檔案 針對 Android 14 使用 HIDL 實作項目。

音訊連接埠、動態設定檔、路徑和修補程式

在這個表格中,XML 檔案的元素會以角括號標示。

HIDL API 介面方法和設定檔元素 AIDL API 介面方法
<attachedDevices>
<defaultOutputDevice>
<mixPorts>
<devicePorts>
IModule.getAudioPorts
IDevice.getAudioPort
IDevice.setConnectedState
IModule.getAudioPort
IModule.connectExternalDevice
IModule.disconnectExternalDevice
IStream.getSupportedProfiles IModule.connectExternalDevice
<routes> IModule.getAudioRoutes
IDevice.createAudioPatch
IDevice.updateAudioPatch
IDevice.releaseAudioPatch
IStream.getDevices
IStream.setDevices
裝置規格IDevice.openInputStream
IDevice.openOutputStream
IModule.setAudioPatch
IModule.setAudioPortConfig
IModule.resetAudioPatch

音訊連接埠設定和串流

HIDL API 介面方法 AIDL API 介面方法
IStream.getAudioProperties
IStream.setAudioProperties
IStreamIn.getAudioSource
IModule.getAudioPortConfigs
IModule.setAudioPortConfig
IDevice.openInputStream
IDevice.openOutputStream
IStreamIn.prepareForReading
IStreamOut.prepareForWriting
IStream.createMmapBuffer
IModule.openInputStream
IModule.openOutputStream
IStream.close IStreamCommon.close
IStreamIn.updateSinkMetadata
IStreamOut.updateSourceMetadata
IStreamIn.updateMetadata
IStreamOut.updateMetadata
IStream.standby StreamDescriptor.Command.standby
IStream.pause
IStream.resume
StreamDescriptor.Command.pause
.start
IStream.start
IStream.stop
(MMAP 串流)
StreamDescriptor.Command.start.burst
.pause (輸入) 和/或 .flush (輸出)
IStreamOut.drain
IStreamOut.flush
StreamDescriptor.Command.drain
.flush
IStreamOut.setCallback
IStreamOut.clearCallback
IModule.openOutputStream
IStreamCommon.close
IStreamOut.getPresentationPositionIStreamIn.getCapturePosition
IStreamOut.getLatency
IStream.getMmapPosition
IStreamIn.getInputFramesLost
StreamDescriptor.Reply.observable
StreamDescriptor.Reply.latencyMs
StreamDescriptor.Reply.hardware
StreamDescriptor.Reply.xrunFrames
IDevice.getInputBufferSize
IStreamOut.getLatency
IStream.getBufferSize
IStream.getFrameSize
IStream.getFrameCount
IModule.setAudioPatch、名義延遲和最小緩衝區大小是 HAL 傳回的 AudioPatch 結構體一部分。以影格為單位的實際緩衝區大小,與以位元組為單位的影格大小,都屬於 StreamDescriptor 結構。將這兩個數字相乘,即可計算緩衝區大小 (以位元組為單位)。

音效連接

HIDL API 介面方法 AIDL API 介面方法
IDevice.addDeviceEffect
IDevice.removeDeviceEffect
IModule.addDeviceEffect
IModule.removeDeviceEffect
IStream.addEffect
IStream.removeEffect
IStreamCommon.addEffect
IStreamCommon.removeEffect

系統設定

先前在音訊政策 XML 設定檔 (即 audio_policy_configuration.xmlaudio_policy_engine_configuration.xml) 中定義的全系統設定,現在必須透過 IConfig 提供。不過,為方便轉換至 AIDL,供應商仍可選擇使用先前用於設定全系統設定的 XML 檔案。IConfig 的參考實作包含必要的程式碼,可使用 AIDL 資料型別表示 XML 檔案中的資訊,方便從 XML 轉換為 AIDL。

HIDL 設定檔元素 AIDL API 介面方法
<globalConfiguration>
<speaker_drc_enabled>1

<call_screen_mode_supported>
<engine_library>
分為兩種不同的方法:
ITelephony.getSupportedAudioModes
IConfig.getEngineConfig
<volumes>,或
<volumeGroups><ProductStrategies>
IConfig.getEngineConfig
<surroundSound> IConfig.getSurroundSoundConfig

  1. speaker_drc_enabled 會從設定檔中移除,因為系統不會使用這個設定項目。所有裝置都必須啟用 DRC。 <ahref="#fnref1" rev="footnote"> </ahref="#fnref1">

功能相關功能

HIDL API 介面方法 AIDL API 介面
IDevice.setMasterVolume
IDevice.getMasterVolume
IDevice.setMicMute
IDevice.getMicMute
IDevice.setMasterMute
IDevice.getMasterMute
IModule.\*
IPrimaryDevice.getTtyMode
IPrimaryDevice.setTtyMode
IPrimaryDevice.getHacEnabled
IPrimaryDevice.setHacEnabled
IPrimaryDevice.setVoiceVolume
ITelephony.TelecomConfig.\*
IPrimaryDevice.setBtScoHeadsetDebugName
IPrimaryDevice.getBtScoNrecEnabled
IPrimaryDevice.setBtScoNrecEnabled
IPrimaryDevice.getBtScoWidebandEnabled
IPrimaryDevice.setBtScoWidebandEnabled,
IPrimaryDevice.getBtHfpEnabled
IPrimaryDevice.setBtHfpEnabled
IPrimaryDevice.setBtHfpSampleRate
IPrimaryDevice.setBtHfpVolume
IBluetooth.ScoConfig.\*
IBluetooth.HfpConfig.\*
IPrimaryDevice.setMode
IPrimaryDevice.updateRotation
ITelephony.switchAudioMode
IModule.updateAudioMode
IModule.updateScreenRotation
IDevice.setScreenState
IDevice.getMicrophones
IModule.updateScreenState
IModule.getMicrophones
IDevice.getHwAvSync
IStream.setHwAvSync
IModule.generateHwAvSyncId
IStreamCommon.updateHwAvSyncId
IStreamIn.setGain
IStreamIn.setMicrophoneDirection
IStreamIn.setMicrophoneFieldDimension
IStreamIn.setHwGain
IStreamIn.setMicrophoneDirection
IStreamIn.setMicrophoneFieldDimension
IStreamOut.getDualMonoMode
IStreamOut.setDualMonoMode
IStreamOut.getPlaybackRateParameters
IStreamOut.setPlaybackRateParameters
IStreamOut.selectPresentation
IStreamOut.getAudioDescriptionMixLevel
IStreamOut.setAudioDescriptionMixLevel
IStreamOut.setLatencyMode
IStreamOut.getRecommendedLatencyModes
IStreamOut.\*
IStreamOut.setEventCallback
IStreamOut.setLatencyModeCallback
IModule.openOutputStream (回呼會合併至 IStreamOutEventCallback)
IDevice.get/setParameters
IStream.get/setParameters
IModule.get/setVendorParameters
IStreamCommon.get/setVendorParameters

舊版方法

HIDL API 介面方法 留言
IDevice.initCheck
IDevice.close
HAL 模組會在成功初始化時,透過 ServiceManager 發布自身。此時即視為永久狀態,無法關閉。
IDevice.supportsAudioPatches
IStreamOut.supportsPauseAndResume
IStreamOut.supportsDrain
必須支援修補程式、暫停、繼續和排空。
IStreamOut.getRenderPosition
IStreamOut.getNextWriteTimestamp
已過時。

供應商額外資訊

在 HIDL API 中,供應商擴充功能是使用 IDeviceIStream 介面的 getParameterssetParameters 方法實作。這些方法接受任意字串。在 AIDL API 中,有對應的方法 (例如 getVendorParameterssetVendorParameters),這些方法會透過 ParcelableHolders 內的封裝,採用任意 Parcelable 執行個體。

其他變更

其他一般異動如下:

  • 為提升 HAL API 的可測試性,我們在 AIDL 版本中導入 VTS 測試使用的偵錯選項,這些選項可透過 ModuleDebug 可封送物件取得。這些選項會指示 HAL 模擬特定功能 (例如連線至外部裝置),否則需要手動介入並使用外部測試設備。

  • 當架構或 VTS 測試將 sys.audio.restart.hal 系統屬性設為 1 時,HAL 服務必須重新啟動。audioserver.rc 檔案會處理重新啟動作業。實作 HAL 時,請使用 audioserver.rc 檔案中列出的適當 HAL 服務名稱。在 Android 14 中,系統會專為 HAL 的 AIDL 版本新增名稱 vendor.audio-hal-aidl

Effects HAL

所有 HIDL 介面都位於 android.hardware.audio.effect@N.M* 套件中,其中 N.MMajor.Minor 版本。所有 AIDL 介面都位於 android.hardware.audio.effect 套件中。

HIDL API 介面和設定檔 AIDL API 介面
IEffectsFactory IFactory
IEffect IEffect
audio_effects.xml IEffect

特效工廠

HIDL API 介面
(android.hardware.audio.effect@X.X)
AIDL API 介面
(android.hardware.audio.effect)
IEffectsFactory.getAllDescriptors IFactory.queryEffects,並提供空值 UUID 參數
IEffectsFactory.getDescriptor IFactory.queryEffects (含 UUID 參數)
IEffectsFactory.createEffect IFactory.createEffect
audio_effects.xml IFactory.queryProcessing
IFactory.queryEffects

效果介面

HIDL API 介面
(android.hardware.audio.effect@X.X)
AIDL API 介面
(android.hardware.audio.effect)
IEffect.init IEffect.open
IEffect.setConfig IEffect.setParameter
IEffect.enable IEffect.command(CommandId::START)
IEffect.disable IEffect.command(CommandId::STOP)
IEffect.reset IEffect.command(CommandId::RESET)
IEffect.getDescriptor IEffect.getDescriptor
IEffect.command 根據舊版 HIDL 指令類型,對應至 IEffect.command
IEffect.setParameter
IEffect.getParameter
IEffect.getState
IEffect.setParameter IEffect.setParameter
IEffect.getParameter IEffect.getParameter

效果指令

HIDL API 介面
(android.hardware.audio.effect@X.X)
AIDL API 介面
(android.hardware.audio.effect)
EFFECT_CMD_INIT IEffect.open
EFFECT_CMD_RESET CommandId.RESET
EFFECT_CMD_ENABLE IEffect.command(CommandId::START)
EFFECT_CMD_DISABLE IEffect.command(CommandId::STOP)
EFFECT_CMD_SET_PARAM_DEFERRED 已在 Effects AIDL HAL 中淘汰
EFFECT_CMD_SET_PARAM_COMMIT 已在 Effects AIDL HAL 中淘汰
EFFECT_CMD_SET_CONFIG
EFFECT_CMD_SET_PARAM
EFFECT_CMD_SET_DEVICE
EFFECT_CMD_SET_VOLUME
EFFECT_CMD_SET_AUDIO_MODE
EFFECT_CMD_SET_CONFIG_REVERSE
EFFECT_CMD_SET_INPUT_DEVICE
EFFECT_CMD_SET_FEATURE_CONFIG
EFFECT_CMD_SET_AUDIO_SOURCE
IEffect.setParameter
EFFECT_CMD_GET_PARAM
EFFECT_CMD_GET_CONFIG
EFFECT_CMD_GET_CONFIG_REVERSE
EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS
EFFECT_CMD_GET_FEATURE_CONFIG
VISUALIZER_CMD_MEASURE
EFFECT_CMD_FIRST_PROPRIETARY
(與 VISUALIZER_CMD_CAPTURE 相同)
IEffect.getParameter
EFFECT_CMD_OFFLOAD 已淘汰。
在 AIDL 中,卸載和非卸載模式切換作業會在架構中處理。
EFFECT_CMD_DUMP 由內建的繫結器交易 AIBinder_dump 處理。

定義常見效果參數

HIDL 定義
(android.hardware.audio.effect@X.X)
AIDL 定義
Types.hal Flags.aidl
Parameter.aidl

特定效果定義

HIDL API 介面
(android.hardware.audio.effect@X.X)
AIDL API 介面
(android.hardware.audio.effect)
I$EffectType$.hal $EffectType$.aidl