RK3576 android14 usb_audio_policy_configuration.xml解析
一,简介
usb_audio_policy_configuration.xml文件用于配置 USB 音频策略 的 XML 文件,属于 USB Audio HAL(Hardware Abstraction Layer) 的一部分。它的作用是定义 USB 音频设备的输入输出行为、支持的格式、采样率、通道数,以及音频路由规则。
源码位置:frameworks/av/services/audiopolicy/config/usb_audio_policy_configuration.xml
系统位置(adb 下可直接修改文件验证):/vendor/etc/audio/usb_audio_policy_configuration.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (C) 2015 The Android Open Source ProjectLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
-->
<!-- USB Audio HAL Audio Policy Configuration file --><module name="usb" halVersion="2.0"><mixPorts><mixPort name="usb_accessory output" role="source"><profile name="" format="AUDIO_FORMAT_PCM_16_BIT"samplingRates="44100" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/></mixPort><mixPort name="usb_device output" role="source"/><mixPort name="usb_device input" role="sink"/></mixPorts><devicePorts><devicePort tagName="USB Host Out" type="AUDIO_DEVICE_OUT_USB_ACCESSORY" role="sink"><profile name="" format="AUDIO_FORMAT_PCM_16_BIT"samplingRates="44100" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/></devicePort><devicePort tagName="USB Device Out" type="AUDIO_DEVICE_OUT_USB_DEVICE" role="sink"/><devicePort tagName="USB Headset Out" type="AUDIO_DEVICE_OUT_USB_HEADSET" role="sink"/><devicePort tagName="USB Device In" type="AUDIO_DEVICE_IN_USB_DEVICE" role="source"/><devicePort tagName="USB Headset In" type="AUDIO_DEVICE_IN_USB_HEADSET" role="source"/></devicePorts><routes><route type="mix" sink="USB Host Out"sources="usb_accessory output"/><route type="mix" sink="USB Device Out"sources="usb_device output"/><route type="mix" sink="USB Headset Out"sources="usb_device output"/><route type="mix" sink="usb_device input"sources="USB Device In,USB Headset In"/></routes>
</module>
二,文件结构解析
1. module 标签
<module name="usb" halVersion="2.0">
表示这是一个 USB 音频模块的配置。halVersion="2.0"
表示使用的是 USB Audio HAL 2.0 版本。
2. mixPorts 标签
定义系统内部用于播放或录制的逻辑音频流(虚拟端口)。
<mixPort name="usb_accessory output" role="source"><profile name="" format="AUDIO_FORMAT_PCM_16_BIT"samplingRates="44100" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
</mixPort>
role="source"
:表示这是一个输出源(播放),profile 定义了支持的音频格式:16-bit PCM、44.1kHz、立体声。
<mixPort name="usb_device output" role="source"/>
<mixPort name="usb_device input" role="sink"/>
usb_device output
:用于 USB 设备输出(播放);
usb_device input
:用于 USB 设备输入(录制),role="sink"
表示接收音频数据。
3. devicePorts 标签
定义系统中可识别的物理 USB 音频设备类型及其能力。
<devicePort tagName="USB Host Out" type="AUDIO_DEVICE_OUT_USB_ACCESSORY" role="sink"><profile name="" format="AUDIO_FORMAT_PCM_16_BIT"samplingRates="44100" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
</devicePort>
type="AUDIO_DEVICE_OUT_USB_ACCESSORY"
:表示这是一个 USB 主机模式下的输出设备。
role="sink"
:表示这是一个接收音频的设备(如扬声器),同样支持 16-bit PCM、44.1kHz、立体声。
4. routes 标签
定义音频数据如何在 mixPort
和 devicePort
之间流动。
<route type="mix" sink="USB Host Out" sources="usb_accessory output"/>
表示将逻辑输出流 usb_accessory output
路由到物理设备 USB Host Out
。
<route type="mix" sink="USB Device Out" sources="usb_device output"/>
<route type="mix" sink="USB Headset Out" sources="usb_device output"/>
将 usb_device output
输出流分别路由到 USB Device Out 和 USB Headset Out
。
<route type="mix" sink="usb_device input" sources="USB Device In,USB Headset In"/>
将两个物理输入设备(USB Device In 和 USB Headset In)的音频数据路由到逻辑输入流 usb_device input
。
三,实例修改
- 问题现象:
主板接入客户USB接口阵列麦克风,可以录音的同时但是也会识别到耳机(右上角有耳机图标),会导致喇叭无声音输出。 - 问题原因:
USB麦克风通常是一个复合设备(Composite Device),它可能同时包含音频输入(麦克风) 和音频输出(耳机) 两个接口(Interface)。 - 解决方法:
修改音频策略配置文件: usb_audio_policy_configuration.xml
注释掉了两条路由规则:
sink="USB Device Out"
sink="USB Headset Out"<!--<route type="mix" sink="USB Device Out"sources="usb_device output"/><route type="mix" sink="USB Headset Out"sources="usb_device output"/>-->
这两条规则原本将系统内部的 usb_device output 音频流路由到物理的USB输出设备。注释后,系统无法将播放音频发送到USB设备的输出接口。所有输入相关的配置(usb_device input, USB Device In, USB Headset In)和路由均保持原样,确保USB麦克风的录音功能正常。