【Android Audio】Parameter Framework - pfw

Parameter Framework - Android AudioPolicy Engine

使用 libengineconfigurable.so 來取締默認安卓音頻引擎 libenginedefault.so,因為默認安卓音頻引擎是通過代碼來決定策略,然而 libengineconfigurable 采用讀取pfw類型的文件來實現音頻策略配置。

1. 優勢

不需要修改代碼,直接修改pfw配置文件就可以修改音頻策略

2. 啟用Parameter framework

Android U之前的版本
audio_policy_configuration.xml文件中 globalConfiguration字段增加字段: engine_library="configurable"
<globalConfiguration speaker_drc_enabled="false" engine_library="configurable" />
Android U之后的版本
使用aidl的hal,讀取config的時候檢測 audio_policy_engine_criterion_types.xmlaudio_policy_engine_criteria.xml文件存在就會啟用

hardware\interfaces\audio\aidl\default\EngineConfigXmlConverter.cpp

void EngineConfigXmlConverter::init() {
...if (getXsdcConfig()->hasCriteria() && getXsdcConfig()->hasCriterion_types()) {AudioHalEngineConfig::CapSpecificConfig capSpecificConfig;capSpecificConfig.criteriaV2 =std::make_optional<>(VALUE_OR_FATAL((convertCapCriteriaCollectionToAidl(getXsdcConfig()->getCriteria(), getXsdcConfig()->getCriterion_types()))));
...

3. 功能

當前主要是3大配置

    <InstanceDefinition><Component Name="streams" Type="Streams"/><Component Name="input_sources" Type="InputSources"/><Component Name="product_strategies" Type="ProductStrategies"/></InstanceDefinition>

3.1 輸入(input_sources)

不同的audio_source_t使用什么樣的輸入設備

<ComponentType Name="Streams" Description="associated to audio_stream_type_t definition"><Component Name="voice_call" Type="Stream" Mapping="Name:AUDIO_STREAM_VOICE_CALL"/><Component Name="system" Type="Stream" Mapping="Name:AUDIO_STREAM_SYSTEM"/><Component Name="ring" Type="Stream" Mapping="Name:AUDIO_STREAM_RING"/><Component Name="music" Type="Stream" Mapping="Name:AUDIO_STREAM_MUSIC"/><Component Name="alarm" Type="Stream" Mapping="Name:AUDIO_STREAM_ALARM"/><Component Name="notification" Type="Stream" Mapping="Name:AUDIO_STREAM_NOTIFICATION"/><Component Name="bluetooth_sco" Type="Stream" Mapping="Name:AUDIO_STREAM_BLUETOOTH_SCO"/><Component Name="enforced_audible" Type="Stream" Mapping="Name:AUDIO_STREAM_ENFORCED_AUDIBLE"Description="Sounds that cannot be muted by user and must be routed to speaker"/><Component Name="dtmf" Type="Stream" Mapping="Name:AUDIO_STREAM_DTMF"/><Component Name="tts" Type="Stream" Mapping="Name:AUDIO_STREAM_TTS"Description="Transmitted Through Speaker. Plays over speaker only, silent on other devices"/><Component Name="accessibility" Type="Stream" Mapping="Name:AUDIO_STREAM_ACCESSIBILITY"Description="For accessibility talk back prompts"/><Component Name="assistant" Type="Stream" Mapping="Name:AUDIO_STREAM_ASSISTANT"Description="used by a virtual assistant like Google Assistant, Bixby, etc."/><Component Name="rerouting" Type="Stream" Mapping="Name:AUDIO_STREAM_REROUTING"Description="For dynamic policy output mixes"/><Component Name="patch" Type="Stream" Mapping="Name:AUDIO_STREAM_PATCH"Description="For internal audio flinger tracks. Fixed volume"/>
</ComponentType>

3.2 輸出設備優先級(product_strategies)

不同的product_strategy_t使用什么樣的輸出設備

<ComponentType Name="InputSources" Description="associated to audio_source_t definition,identifier mapping must match the value of the enum"><Component Name="default" Type="InputSource" Mapping="Name:AUDIO_SOURCE_DEFAULT"/><Component Name="mic" Type="InputSource" Mapping="Name:AUDIO_SOURCE_MIC"/><Component Name="voice_uplink" Type="InputSource"Mapping="Name:AUDIO_SOURCE_VOICE_UPLINK"/><Component Name="voice_downlink" Type="InputSource"Mapping="Name:AUDIO_SOURCE_VOICE_DOWNLINK"/><Component Name="voice_call" Type="InputSource"Mapping="Name:AUDIO_SOURCE_VOICE_CALL"/><Component Name="camcorder" Type="InputSource" Mapping="Name:AUDIO_SOURCE_CAMCORDER"/><Component Name="voice_recognition" Type="InputSource"Mapping="Name:AUDIO_SOURCE_VOICE_RECOGNITION"/><Component Name="voice_communication" Type="InputSource"Mapping="Name:AUDIO_SOURCE_VOICE_COMMUNICATION"/><Component Name="remote_submix" Type="InputSource"Mapping="Name:AUDIO_SOURCE_REMOTE_SUBMIX"/><Component Name="unprocessed" Type="InputSource"Mapping="Name:AUDIO_SOURCE_UNPROCESSED"/><Component Name="voice_performance" Type="InputSource"Mapping="Name:AUDIO_SOURCE_VOICE_PERFORMANCE"/><Component Name="echo_reference" Type="InputSource"Mapping="Name:AUDIO_SOURCE_ECHO_REFERENCE"/><Component Name="fm_tuner" Type="InputSource" Mapping="Name:AUDIO_SOURCE_FM_TUNER"/><Component Name="hotword" Type="InputSource" Mapping="Name:AUDIO_SOURCE_HOTWORD"/>
</ComponentType>

3.3 音量曲線切換(streams)

不同的audio_stream_type_t使用哪個stream type的音量曲線

<ComponentType Name="ProductStrategies" Description=""><Component Name="phone" Type="ProductStrategy" Mapping="Name:STRATEGY_PHONE"/><Component Name="sonification" Type="ProductStrategy" Mapping="Name:STRATEGY_SONIFICATION"/><Component Name="enforced_audible" Type="ProductStrategy" Mapping="Name:STRATEGY_ENFORCED_AUDIBLE"/><Component Name="accessibility" Type="ProductStrategy" Mapping="Name:STRATEGY_ACCESSIBILITY"/><Component Name="sonification_respectful" Type="ProductStrategy" Mapping="Name:STRATEGY_SONIFICATION_RESPECTFUL"/><Component Name="media" Type="ProductStrategy" Mapping="Name:STRATEGY_MEDIA"/><Component Name="dtmf" Type="ProductStrategy" Mapping="Name:STRATEGY_DTMF"/><Component Name="transmitted_through_speaker" Type="ProductStrategy" Mapping="Name:STRATEGY_TRANSMITTED_THROUGH_SPEAKER"/><Component Name="assistant" Type="ProductStrategy" Mapping="Name:STRATEGY_ASSISTANT"/>
</ComponentType>

4. 配置pfw文件

4.1 supDomain

  • supDomain定義是對Strategy進行分類命名,可以任意修改
  • 可以定義多級supDomain,生成的xml中是以"."分隔
    (eg: DeviceForProductStrategy.Media)
supDomain: DeviceForProductStrategysupDomain: Mediadomain: Device1conf: ForceUseBtA2dpSpeakerAvailableOutputDevices Includes BLUETOOTH_A2DP_SPEAKERForceUseForMedia Is BT_A2DPcomponent: /Policy/policy/product_strategies/vx_1005/selected_output_devices/maskspeaker = 0spdif = 0bluetooth_a2dp_speaker = 1
...

4.2 domain

  • supDomain下面可以配置多個domain
  • 多個domain的device是共存的
  • 同一supDomain中不同的domain中不能配置相同的device
    eg:下面Assistant的Strategy中配置了2個domain(Device1、Device2),ARC可以跟其他device共存
supDomain: DeviceForProductStrategysupDomain: Assistantdomain: Device1conf: RemoteSubmixAvailableOutputDevices Includes REMOTE_SUBMIXAvailableOutputDevicesAddresses Includes 0component: /Policy/policy/product_strategies/assistant/selected_output_devices/maskspeaker = 0remote_submix = 1
...domain: Device2## these following domains consists in device(s) that can co-exist with others# e.g. ARC, SPDIF, AUX_LINE#conf: SelectedAvailableOutputDevices Includes HDMI_ARCcomponent: /Policy/policy/product_strategies/assistant/selected_output_devices/maskhdmi_arc = 1conf: NotSelectedcomponent: /Policy/policy/product_strategies/assistant/selected_output_devices/maskhdmi_arc = 0
...

4.3 config

  • 每一個domain下面的config相當于代碼中的switch-case語句。放在前面的config先被執行到。
  • 滿足config條件才會被使用,之后不再執行同一domain下的config。如果不滿足條件則進行下一個config條件檢查。
domain: Device1conf: ForceUseBtA2dpSpeakerAvailableOutputDevices Includes BLUETOOTH_A2DP_SPEAKERForceUseForMedia Is BT_A2DPcomponent: /Policy/policy/product_strategies/vx_1005/selected_output_devices/maskspeaker = 0spdif = 0hdmi = 0hdmi_arc = 0bluetooth_a2dp_speaker = 1usb_device = 0conf: UsbDeviceAvailableOutputDevices Includes USB_DEVICEcomponent: /Policy/policy/product_strategies/vx_1005/selected_output_devices/maskspeaker = 0spdif = 0hdmi = 0hdmi_arc = 0bluetooth_a2dp_speaker = 0usb_device = 1
4.3.1 criterion (準則/標準)

每個criterion 定義: pfw中所有能使用的準則類型 audio_policy_engine_criteria.xml

frameworks/av/services/audiopolicy/engineconfigurable/config/example/common/audio_policy_engine_criteria.xml

<criteria><criterion name="AvailableInputDevices" type="InputDevicesMaskType" default="none"/><criterion name="AvailableOutputDevices" type="OutputDevicesMaskType" default="none"/><criterion name="ForceUseForMedia" type="ForceUseForMediaType" default="ForceNone"/>
...
</criteria>
4.3.2 每個criterion的值:每個準則類型的值

/vendor/etc/audio_policy_engine_criteria.xmlaudio_policy_engine_criterion_typespython腳本根據audio_policy_engine_criterion_types.xml.in文件自動生成。

  • Android 16使用Google最新的capBuildPolicyCriterionTypes.py,之前安卓版本使用buildPolicyCriterionTypes.py的Python腳本。

frameworks/av/services/audiopolicy/engineconfigurable/tools/

frameworks/av/services/audiopolicy/engineconfigurable/config/example/common/audio_policy_engine_criterion_types.xml.in

<criterion_types><criterion_type name="OutputDevicesMaskType" type="inclusive"><values><value literal="EARPIECE" android_type="0x1"/><value literal="SPEAKER" android_type="0x2"/><value literal="WIRED_HEADSET" android_type="0x4"/><value literal="WIRED_HEADPHONE" android_type="0x8"/><value literal="BLUETOOTH_SCO" android_type="0x10"/><value literal="BLUETOOTH_SCO_HEADSET" android_type="0x20"/><value literal="BLUETOOTH_SCO_CARKIT" android_type="0x40"/><value literal="BLUETOOTH_A2DP" android_type="0x80"/><value literal="BLUETOOTH_A2DP_HEADPHONES" android_type="0x100"/><value literal="BLUETOOTH_A2DP_SPEAKER" android_type="0x200"/></values></criterion_type>
...<criterion_type name="ForceUseForMediaType" type="exclusive"><values><value literal="ForceNone" numerical="0"/><value literal="ForceSpeaker" numerical="1"/><value literal="ForceHeadphones" numerical="2"/><value literal="ForceBtA2dp" numerical="4"/><value literal="ForceWiredAccessory" numerical="5"/><value literal="ForceAnalogDock" numerical="8"/><value literal="ForceDigitalDock" numerical="9"/><value literal="ForceNoBtA2dp" numerical="10"/></values></criterion_type>
...

4.3.3 使用criterion

例如:配置輸出設備策略

    conf: UsbDeviceAvailableOutputDevices Includes USB_DEVICEAvailableOutputDevices Excludes WIRED_HEADPHONEANYForceUseForCommunication Is BT_SCOALLForceUseForCommunication Is SPEAKERTelephonyMode IsNot IN_CALLcomponent: /Policy/policy/product_strategies/vx_1000/selected_output_devices/mask
...usb_accessory = 0usb_device = 1usb_headset = 0speaker = 0
...

上面的config轉化為偽代碼的case:

if (AvailableOutputDevices 存在 USB_DEVICE) {if (AvailableOutputDevices 不存在 WIRED_HEADPHONE) {if (ForceUseForCommunication == BT_SCO ||(ForceUseForCommunication == SPEAKER && TelephonyMode != IN_CALL)) {return USB_DEVICE;}}
}

當前Google pfw支持3個SubSystem(Stream、InputSource、ProductStrategy)

frameworks\av\services\audiopolicy\engineconfigurable\parameter-framework\plugin\PolicySubsystem.cpp

    // Provide creators to upper layeraddSubsystemObjectFactory(new TSubsystemObjectFactory<Stream>(mStreamComponentName,(1 << MappingKeyName)));addSubsystemObjectFactory(new TSubsystemObjectFactory<InputSource>(mInputSourceComponentName,(1 << MappingKeyName)));addSubsystemObjectFactory(new TSubsystemObjectFactory<ProductStrategy>(mProductStrategyComponentName, (1 << MappingKeyName)));

分別通過下面3個函數推送到Engine中

frameworks\av\services\audiopolicy\engineconfigurable\parameter-framework\plugin\

Stream::sendToHW
Engine::setVolumeProfileForStream
InputSource::sendToHW
Engine::setDeviceForInputSource
ProductStrategy::sendToHW
Engine::setDeviceTypesForProductStrategy
Engine::setDeviceAddressForProductStrategy

/vendor/etc/parameter-framework/Structure/Policy/PolicySubsystem-CommonTypes.xml

5.1 快速debug

修改完對應的pfw文件之后
device/amlogic/common/audio路徑下mm -j,將/vendor/etc/parameter-framework/目錄替換到平臺即可

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/77005.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/77005.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/77005.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

服務器虛擬化技術深度解析:醫藥流通行業IT架構優化指南

一、服務器虛擬化的定義與原理 &#xff08;一&#xff09;技術定義&#xff1a;從物理到虛擬的資源重構 服務器虛擬化是通過軟件層&#xff08;Hypervisor&#xff09;將物理服務器的CPU、內存、存儲、網絡等硬件資源抽象為邏輯資源池&#xff0c;分割成多個相互隔離的虛擬機…

babel-runtime 如何縮小打包體積

&#x1f916; 作者簡介&#xff1a;水煮白菜王&#xff0c;一位前端勸退師 &#x1f47b; &#x1f440; 文章專欄&#xff1a; 前端專欄 &#xff0c;記錄一下平時在博客寫作中&#xff0c;總結出的一些開發技巧和知識歸納總結?。 感謝支持&#x1f495;&#x1f495;&#…

劍指Offer(數據結構與算法面試題精講)C++版——day7

劍指Offer&#xff08;數據結構與算法面試題精講&#xff09;C版——day7 題目一&#xff1a;最多刪除一個字符得到回文題目二&#xff1a;回文子字符串的個數題目三&#xff1a;刪除倒數第k個節點 題目一&#xff1a;最多刪除一個字符得到回文 這里我們可以在經典的字符串回文…

2025年常見滲透測試面試題(題目+回答)

網絡安全領域各種資源&#xff0c;學習文檔&#xff0c;以及工具分享、前沿信息分享、POC、EXP分享。不定期分享各種好玩的項目及好用的工具&#xff0c;歡迎關注。 目錄 常見面試題 一、滲透測試經歷與技術復盤 二、高頻漏洞類型與攻防體系 三、滲透工具鏈與技術特性 四、…

大數據與人工智能之大數據架構(Hadoop、Spark、Flink)

一、核心特性與架構設計 1. Hadoop&#xff1a;分布式批處理的基石 核心組件&#xff1a; HDFS&#xff1a;分布式文件系統&#xff0c;支持大規模數據存儲。MapReduce&#xff1a;基于“分而治之”的批處理模型&#xff0c;適合離線分析。 架構特點&#xff1a; 批處理主導&…

從IoT到AIoT:智能邊界的拓展與AI未來趨勢預測

文章目錄 引言&#xff1a;從連接萬物到感知萬物1. AIoT的本質&#xff1a;將智能嵌入萬物2. AIoT的推動力量與挑戰2.1 推動力量2.2 關鍵挑戰 3. 五大AIoT未來趨勢預測趨勢一&#xff1a;邊緣智能將成為主流架構趨勢二&#xff1a;AI模型將向自適應與多任務演進趨勢三&#xff…

從本地新建文件夾到拉取遠程倉庫 dev 分支的完整步驟

《從本地新建文件夾到拉取遠程倉庫 dev 分支的完整步驟》 下面為你詳細介紹從本地新建文件夾開始&#xff0c;將遠程倉庫的 dev 分支拉取到本地的具體步驟&#xff1a; 1. 創建新文件夾 在本地電腦上新建一個文件夾&#xff0c;作為存放項目代碼的目錄。你可以通過圖形界面操…

python/pytorch雜聊

Dataset 是否需要自己定義&#xff1a;如果你使用的數據集不是 PyTorch 提供的標準數據集&#xff08;如 MNIST、CIFAR-10 等&#xff09;&#xff0c;那么你需要繼承 torch.utils.data.Dataset 類并實現兩個方法&#xff1a;__len__() 和 __getitem__()。__len__() 應該返回數…

PHP 安全 E-mail

PHP 安全 E-mail 引言 隨著互聯網的普及和電子商務的發展,電子郵件成為了人們日常生活中不可或缺的通信工具。PHP作為一種廣泛使用的服務器端腳本語言,也經常被用于發送和接收電子郵件。然而,在PHP中處理電子郵件時,安全性問題不容忽視。本文將深入探討PHP安全發送電子郵…

【夜話系列】DelayQueue延遲隊列(下):實戰應用與面試精講

?? 本文是DelayQueue系列的下篇,聚焦實戰應用場景和性能優化。通過多個真實案例,帶你掌握DelayQueue在項目中的最佳實踐和性能調優技巧。 ?? 系列專欄推薦: JAVA集合專欄 【夜話集】JVM知識專欄數據庫sql理論與實戰小游戲開發文章目錄 一、DelayQueue實戰應用1.1 訂單超…

Redis(筆記)

簡介&#xff1a; 常用數據類型: 常用操作命令&#xff1a; Redis的Java客戶端&#xff1a; 操作字符串類型的數據&#xff1a; 操作Hash類型的數據&#xff1a; 操作列表類型的數據&#xff1a; 操作集合類型的數據&#xff1a; 操作有序集合類型數據&#xff1a; 通用命令…

PhotoShop學習05

1.選區基礎知識 選區&#xff0c;就是選定一些區域&#xff0c;我們對圖片的更改只在選區內生效&#xff0c;這樣可以精細調整圖片的部分而不會影響整體。它的快捷鍵是M。 我們用點擊鼠標后滑動就會出現虛線框&#xff0c;虛線框內的就是我們選定的區域。這時我們再滑動就會創…

使用Redission實現分布式鎖

分布式鎖在分布式系統中非常重要&#xff0c;主要用于解決多個進程/服務并發訪問共享資源時的數據一致性問題。在日常開發中常用于&#xff1a; 1. 防止重復操作&#xff08;冪等性控制&#xff09; 場景&#xff1a;用戶重復提交訂單、重復支付、重復點擊等。 示例&#xff1…

VScode 畫時序圖(FPGA)

1、先安裝插件&#xff1a; 2、然后就可以編寫一個.js文件&#xff0c;如下&#xff1a; {signal: [{name: clk, wave: p.......|..},{name: rstn, wave: 01......|..},{name: din_vld, wave: 0.1.0...|..},{name: din, wave: "x.x...|..", data: ["D0", …

嵌入式學習筆記——I2C

IIC協議詳解 一、IIC協議簡介二、IIC總線結構圖三、IIC通信流程詳解1. 空閑狀態 : 雙高空閑2. 起始信號&#xff08;START&#xff09;: 時高數下開始3. 停止信號&#xff08;STOP&#xff09;: 時高數上結束4. 數據傳輸格式 : 時高數穩&#xff0c;時低數變5. 應答信號 四、寫…

Apifox Helper 與 Swagger3 區別

核心定位差異 Apifox Helper 定位&#xff1a;基于 IDEA 的代碼注釋解析工具&#xff0c;與 Apifox 平臺深度集成&#xff0c;實現文檔自動生成接口管理測試協作的一體化流程。 特點&#xff1a; 通過解析 Javadoc、KDoc 等注釋生成文檔&#xff0c;代碼零侵入&#xff08;無…

單片機實現多線程的方法匯總

在單片機上實現“多線程”的方法有幾種&#xff0c;下面按照從簡單到復雜、從輕量到系統性來列出常見的方案&#xff1a; &#x1f9f5; 一、偽多線程&#xff08;最輕量&#xff09; 方法&#xff1a;主循環 狀態機 / 定時器輪詢 主循環中輪流調用各個任務的處理函數&#x…

網絡:華為數通HCIA學習:靜態路由基礎

文章目錄 前言靜態路由基礎靜態路由應用場景 靜態路由配置靜態路由在串行網絡的配置靜態路由在以太網中的配置 負載分擔配置驗證 路由備份&#xff08;浮動靜態路由&#xff09;配置驗證 缺省路由配置驗證 總結 華為HCIA 基礎實驗&#xff0d;靜態路由 & eNSP靜態路由 基礎…

[項目總結] 在線OJ刷題系統項目技術應用(下)

&#x1f338;個人主頁:https://blog.csdn.net/2301_80050796?spm1000.2115.3001.5343 &#x1f3f5;?熱門專欄: &#x1f9ca; Java基本語法(97平均質量分)https://blog.csdn.net/2301_80050796/category_12615970.html?spm1001.2014.3001.5482 &#x1f355; Collection與…

Qt音頻輸出:QAudioOutput詳解與示例

1. 簡介 QAudioOutput是Qt多媒體框架中的一個關鍵類&#xff0c;它提供了將PCM&#xff08;脈沖編碼調制&#xff09;原始音頻數據發送到音頻輸出設備的接口。作為Qt多媒體組件的一部分&#xff0c;QAudioOutput允許開發者在應用程序中實現音頻播放功能&#xff0c;支持多種音…