AIDL 和 HIDL 音頻 HAL 比較

從 Android 14 開始,鼓勵合作夥伴和 SoC 供應商將目前的 HIDL HAL 實作替換為 AIDL HAL 實作。

為了促進從 HIDL Audio HAL 到 AIDL Audio HAL 的平滑過渡,本頁突出顯示了一些關鍵差異。此頁面還顯示了音訊 HAL 的 AIDL 和 HIDL 介面之間的對應。

AIDL 和 HIDL 音訊 HAL 實作之間的區別

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

  • AIDL Audio Core HAL中,引入了IConfig接口,以取代 HIDL HAL 中 XML 檔案中的系統範圍參數。框架從 Core HAL 而不是供應商設定檔中讀取這些參數。例如,為使用者控製而顯示的環繞聲格式清單由 Core HAL 中的IConfig.getSurroundSoundConfig方法提供。

    AIDL Audio Effects HAL中,HIDL Effects HAL 中的 XML 檔案中定義的effectProxy邏輯已移至音訊框架。音訊框架使用IFactory.queryEffects查詢系統中的所有效果實例,並使用IFactory.queryProcessing查詢所有效果處理。

  • 為了避免與音訊設備類型術語設備的使用發生混淆,HIDL Audio HAL 中的IDevice被重新命名為 AIDL Audio HAL 中的IModule

  • IPrimaryDevice在 AIDL Audio HAL 中被替換。有關當前音訊模式和螢幕旋轉的更新將傳送到每個IModule實例。與藍牙同步連接導向 (BT SCO) 和免持檔案 (HFP) 相關的參數由專用的IBluetooth介面處理。專用ITelephony介面提供特定於電話的控制。這兩個介面的實例都可以從IModule介面的主實例中檢索。有關更多信息,請參閱核心 HAL功能相關功能的比較表。

  • AIDL Audio HAL 中刪除了IDevicesFactory以避免冗餘。 HAL 模組(即IModule介面實例)現在使用其名稱作為實例名稱(例如bluetoothr_submix直接向服務管理器註冊。唯一的例外是在實例名稱default下註冊的primary模組。

AIDL 和 HIDL 音訊 HAL 映射

以下部分中的表格顯示了 HIDL 和 AIDL Audio HAL 介面之間的對應。有關目錄結構的更多信息,請參閱音頻 HAL 自述文件

核心HAL

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

HIDL API 介面和設定檔AIDL API介面
IDevicesFactoryServiceManager註冊IModule
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
IStream.start
IStream.stop
StreamDescriptor.Command.pause
.start
.start
.drain
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。

與特性相關的功能

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實例。

其他變化

其他一般變化如下:

  1. 為了提高 HAL API 的可測試性,在 AIDL 版本中,我們引入了 VTS 測試使用的偵錯選項,可透過ModuleDebug包裹使用。這些選項指示 HAL 模擬某些功能(例如,外部設備的連接),否則需要手動介入和使用外部測試設備。

  2. 當系統屬性sys.audio.restart.hal的值設定為1時,HAL 服務需要重新啟動。重啟是透過audioserver.rc實現的。實作 HAL 時,請使用audioserver.rc檔案中所列的適當的 HAL 服務名稱。在Android 14中,專門為HAL的AIDL版本添加了名稱vendor.audio-hal-aidl

效果哈爾

所有 HIDL 介面都位於android.hardware.audio.effect@NM*包中,其中NMMajor.Minor版本。所有 AIDL 介面都位於android.hardware.audio.effect包內。

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

效果工廠

HIDL API 介面
(android.hardware.audio.effect@XX)
AIDL API介面
(android.hardware.audio.effect)
IEffectsFactory.getAllDescriptors具有 null UUID 參數的IFactory.queryEffects
IEffectsFactory.getDescriptor帶有 UUID 參數的IFactory.queryEffects
IEffectsFactory.createEffect IFactory.createEffect
audio_effects.xml IFactory.queryProcessing
IFactory.queryEffects

效果介面

HIDL API 介面
(android.hardware.audio.effect@XX)
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映射到IEffect.command
IEffect.setParameter ,或
基於舊版 HIDL 指令類型的IEffect.getParameter
不適用IEffect.getState
IEffect.setParameter IEffect.setParameter
IEffect.getParameter IEffect.getParameter

效果命令

HIDL API 介面
(android.hardware.audio.effect@XX)
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在效果 AIDL HAL 中已棄用
EFFECT_CMD_SET_PARAM_COMMIT在效果 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@XX)
AIDL定義
Types.hal Flags.aidl
Parameter.aidl

特定效果定義

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