【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.mzph.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;支持多种音…