Android 14 透過持續監控聲音劑量測量並向使用者發出有關有害暴露程度的警告,在音訊框架和音訊 HAL 中提供對聲音劑量的支援。
聲音劑量是一段時間內聲壓級的測量值。透過監測聲音劑量,我們可以幫助保護使用者免受過度或長時間接觸聲音的破壞性影響,從而在便攜式 Android 設備上使用耳機時提供更好的聽力保護,並最大限度地減少聽力受損的機會。
安全收聽設備的新標準符合IEC62368-1第三版(需要登入)和EN50332-3 (僅限訂戶存取)中聽力保護的監管要求,其中引入了聲音劑量的概念。
聲音劑量功能使 OEM 能夠遵循新的聽力安全法規。為了支援聲音劑量,原始設備製造商必須遵守所有客製化和認證的介面規範和規定。客製化的 OEM 實作可以繞過或修改聲音劑量的 AOSP 預設實作。但是,強烈建議使用 AOSP 實作。
聲劑量計算
IEC62368-1 第 3 版和 EN50332-3 中的標準透過計算計算的聲音劑量 (CSD) 提高了測量聲音暴露的準確性。 CSD 是透過對一段時間內的瞬時暴露水準 (MEL) 進行積分來計算的。累積 CSD 值的 7 天連續滾動視窗保留用於聲音劑量計算。
根據 IEC62368-1 第 3 版第 10.6.3.2 節,如果 CSD 值達到 100% 限值,系統會在每次增加 100% 時向使用者發出有關聲級的警報。如果使用者不確認警告,音量將降低至 IEC62368-1 表 39 中預先定義的輻射能源 1 類 (RS1) 值。
如 IEC62368-1 第 3 版第 10.6.3.3 節所述,每次 MEL 值超過 IEC62368 表 39 的輻射能源 2 類 (RS2) 值時,除了聲音劑量警告之外,系統還必須啟動基於暴露的警告- 1。
為了符合這些法規的認證並使 CSD 值更具相關性,系統必須使用使用者感知的準確輸出值(例如媒體播放輸出)。對於 CSD 計算來說,使用接近使用者所承受的實際聲壓級的值非常重要。
建築學
根據捕捉幀的位置,感測器的硬體特性和效果可能會影響渲染幀的功率等級。為了進行精確的輸出聲壓級測量,我們擴展了 HAL,以直接從底層硬體獲取 MEL 值,並考慮數位訊號處理器 (DSP) 或揚聲器屬性(例如阻抗、靈敏度、和頻率響應。
如果 HAL 無法提供 MEL 值,作為後備機制,音訊框架將分析並計算 CSD。音訊框架中的計算是基於 HAL 報告的渲染輸出資訊以及發送到音訊 DSP 的幀。
聲音劑量引入了兩個組件SoundDoseHelper
和SoundDoseManager,
如圖1所示:
圖 1.聲音劑量特徵的架構組件。
聲音劑量助手
SoundDoseHelper
類別位於systemserver
進程中,是所有相關聲音劑量資料的主要收集點。 AudioService
類別管理SoundDoseHelper
類別。
SoundDoseHelper
類別負責以下任務:
- 處理新劑量信息
- 持續聲音劑量值
- 在
audioserver
崩潰時恢復狀態 - 觸發系統 UI 通知
- 降低音量
聲音劑量管理器
SoundDoseManager
類別位於audioserver
進程中,並且是AudioFlinger
類別的一部分,它從 HAL 收集聲音劑量數據,或從發送到 HAL 的幀在內部計算該數據(作為後備)。 SoundDoseManager
類別將聲音劑量資料傳送到SoundDoseHelper
類別。
MelProcessor 和 MelAggregator
如果 HAL 無法提供 MEL 值,則使用libaudioutils
中的MelProcessor
和MelAggregator
實用程式進行內部聲音劑量計算。
在MelProcessor
類別中,主要計算是透過呼叫MelProcessor::process(const void* buffer, size_t bytes)
在帶有音訊樣本的緩衝區上執行的。如果需要,OEM 可以在其 HAL 實作中使用MelProcessor
。
MelAggregator
類別從不同音訊連接埠接收 MEL 值,並以 7 天的滾動視窗計算 CSD 值。 MelAggregator::aggregateAndAddNewMelRecord_l(MelRecord mel)
方法執行邏輯。結果將發送到SoundDoseManager
類,以便與AudioService
進行通訊。
執行
從 Android 14 開始,HIDL 介面擴充已被棄用,因此用於檢索計算的 MEL 值並發出暴露警告的新 HAL 介面(名為ISoundDose
)被定義為AIDL Audio HAL的一部分。然而,對於需要更多時間來整合 AIDL Audio HAL 的實施者,我們有一個獨立的聲音劑量 AIDL HAL ,它提供了ISoundDoseFactory
介面。這將在未來被棄用。
以下程式碼範例顯示了聲音劑量支援的 HAL 方法:
/**
* This interface provides functions related to sound exposure control required for compliance to
* EN/IEC 62368-1 3rd edition. Implementing this interface is mandatory for devices for which
* compliance to this standard is mandated and implementing audio offload decoding or other direct
* playback paths where volume control happens below the audio HAL.
*/
@VintfStability
interface ISoundDose {
/**
* Max value in dBA used for momentary exposure warnings as defined by IEC62368-1
* 3rd edition. This value represents the default RS2 upper bound.
*/
const int DEFAULT_MAX_RS2 = 100;
/** Min value of the RS2 threshold in dBA as defined by IEC62368-1 3rd edition. */
const int MIN_RS2 = 80;
/**
* Sets the RS2 upper bound used for momentary exposure warnings. Default value is
* DEFAULT_MAX_RS2 as specified in IEC62368-1 3rd edition.
*
* @param rs2ValueDbA custom RS2 upper bound to use
* @throws EX_ILLEGAL_ARGUMENT if rs2ValueDbA is greater than DEFAULT_MAX_RS2 or lower
* than MIN_RS2
*/
void setOutputRs2UpperBound(float rs2ValueDbA);
/**
* Gets the RS2 upper bound used for momentary exposure warnings.
*
* @return the RS2 upper bound in dBA
*/
float getOutputRs2UpperBound();
/**
* Registers the HAL callback for sound dose computation. If sound dose is supported
* the MEL values and exposure notifications will be received through this callback
* only. The internal framework MEL computation will be disabled.
* It is not possible to unregister the callback. The HAL is responsible to provide
* the MEL values throughout its lifecycle.
*
* @param callback to use when new updates are available for sound dose
*/
void registerSoundDoseCallback(in IHalSoundDoseCallback callback);
@VintfStability
oneway interface IHalSoundDoseCallback {
/**
* Called whenever the current MEL value exceeds the set RS2 upper bound.
*
* @param currentDbA the current MEL value which exceeds the RS2 upper bound
* @param audioDevice the audio device where the MEL exposure warning was recorded
*/
void onMomentaryExposureWarning(float currentDbA, in AudioDevice audioDevice);
@VintfStability
parcelable MelRecord {
/**
* Array of continuously recorded MEL values >= MIN_RS2 (1 per second).
* First value in the array was recorded at 'timestamp'.
*/
float[] melValues;
/**
* Corresponds to the time in seconds, as reported by CLOCK_MONOTONIC, when
* the first MEL entry in melValues was recorded. The timestamp values have
* to be consistent throughout all audio ports, equal timestamp values will
* be aggregated.
*/
long timestamp;
}
/**
* Provides a MelRecord containing continuous MEL values sorted by timestamp.
* Note that all the MEL values originate from the audio device specified by audioDevice.
* In case values from multiple devices need to be reported, the caller should execute
* this callback once for every device.
*
* @param melRecord contains the MEL values used for CSD
* @param audioDevice the audio device where the MEL values were recorded
*/
void onNewMelValues(in MelRecord melRecord, in AudioDevice audioDevice);
}
}
新的 HAL 介面實現回調,通知框架有關瞬時暴露的信息,並在輸出等級超過 RS1 時提供 MEL 值。實作這些介面後,框架將它們用於 CSD 報告。如果沒有此回調實現, AudioFlinger
上的回退實現將用於計算 CSD 值的估計。
聲音劑量獨立 AIDL 支持
在 OEM 能夠將聲音劑量整合到 AIDL 音訊 HAL 之前,他們可以使用獨立的 AIDL API ISoundDoseFactory
作為解決方法。 ISoundDoseFactory
使用ISoundDose
介面,如以下程式碼範例所示:
@VintfStability
interface ISoundDoseFactory {
/**
* Retrieve the sound dose interface for a given audio HAL module name.
*
* If a device must comply to IEC62368-1 3rd edition audio safety requirements and is
* implementing audio offload decoding or other direct playback paths where volume control
* happens below the audio HAL, it must return an instance of the ISoundDose interface.
* The same instance must be returned during the lifetime of the HAL module.
* If the HAL module does not support sound dose, null must be returned, without throwing
* any errors.
*
* @param module for which we trigger sound dose updates.
* @return An instance of the ISoundDose interface implementation.
* @throws EX_ILLEGAL_STATE If there was an error creating an instance.
*/
@nullable ISoundDose getSoundDose(in @utf8InCpp String module);
}
聲音劑量 AIDL 音頻 HAL 支持
透過擴展IModule
接口,聲音劑量接口作為 AIDL Audio HAL 的一部分得到長期支持,如以下程式碼範例所示:
@VintfStability
interface IModule {
…
/**
* Retrieve the sound dose interface.
*
* If a device must comply to IEC62368-1 3rd edition audio safety requirements and is
* implementing audio offload decoding or other direct playback paths where volume control
* happens below the audio HAL, it must return an instance of the ISoundDose interface.
* The same instance must be returned during the lifetime of the HAL module.
* If the HAL module does not support sound dose, null must be returned, without throwing
* any errors.
*
* @return An instance of the ISoundDose interface implementation.
* @throws EX_ILLEGAL_STATE If there was an error creating an instance.
*/
@nullable ISoundDose getSoundDose();
}
此功能是 IEC62368-1 第 3 版和 EN50332-3 中描述的新法規的實現,因此沒有面向外部的 API。
OEM 可以透過實施新的 HAL 介面並向音訊框架提供準確的 CSD MEL 資料(建議)或提供自訂聲音劑量實施來認證其裝置。
啟用聲音劑量的計算
預設情況下,AOSP 支援聽力安全邏輯,確保通過現有 EN50332-2 和 IEC62368-1 10.6.5 標準進行認證。
在Android 14中,預設會停用聲音劑量的計算。
從 Android 14-QPR1 開始,請使用以下指南啟用聲音劑量的計算。
如果您所在的國家/地區強制執行聲音劑量法規,請檢查
config.xml
中的config_safe_media_volume_enabled
是否設為true
。為了符合 EN50332-3 和 IEC62368-1 10.6.3,供應商必須將
config.xml
中的config_safe_sound_dosage_enabled
標誌覆寫為true
。對於支援卸載解碼且未實現聲音劑量 HAL 介面的設備,config_safe_sound_dosage_enabled
不得設為true
。在這種情況下,將config_safe_sound_dosage_enabled
設為true
可能會導致 CSD 值不準確以及安全聽力標準的認證問題。
以下決策圖描述了根據國家/地區限制和標誌值確定是否計算 CSD 或舊版聽力安全等級(在 Android 14 之前實現)的邏輯。
圖2.啟用聲音劑量的計算(此邏輯在Android 14-QPR1中添加)。
驗證
在實現聲音劑量的 HAL 介面時,OEM 必須針對 IModule AIDL Audio HAL 實現的VtsHalAudioCoreTargetTest
定義的 VTS 測試案例進行驗證,或針對獨立聲音劑量 AIDL HAL 實現的VtsHalSoundDoseFactoryTargetTest
定義的 VTS 測試案例進行驗證。