Android 音频源码分析——aduio_policy_configuration.xml

Posted VNanyesheshou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 音频源码分析——aduio_policy_configuration.xml相关的知识,希望对你有一定的参考价值。

aduio_policy_configuration.xml内容分为三大模块:

  1. 全局配置;
  2. modules模块;
  3. volume section;

1. globalConfiguration

<globalConfiguration speaker_drc_enabled="true"/>

speaker_drc_enabled值为ture时:在DEVICE_CATEGORY_SPEAKER路径上使用DRC增强柔和声音的设备,用于相应地调整音量曲线。

2. modules模块

modules下面包含module列表,每个音频硬件模块都对应一个module。模块包括:primary、A2DP、USB、remote_submix、hearing_aid。

这里以primary为例:

每个module都将包含两个用于音频HAL的必需标记:“ halVersion”和“ name”。

<module name="primary" halVersion="3.0">

attachedDevices: 永久连接的设备,也就是内置的设备

<attachedDevices>
    <item>Speaker</item> <!-- 扬声器 -->
    <item>Built-In Mic</item> <!-- 内置麦克 -->
    <item>Built-In Back Mic</item><!-- 内置后侧麦克 -->
</attachedDevices>

defaultOutputDevice:默认的输出设备(不适用任何规则时默认设备)

devicePorts:可以通过此模块访问的所有输入和输出设备的设备描述符的列表。包含内置设备和外接设备。

<devicePorts>
    <!-- Output devices declaration, i.e. Sink DEVICE PORT -->
    //听筒配置
    <devicePort tagName="Earpiece" type="AUDIO_DEVICE_OUT_EARPIECE" role="sink">
       <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                samplingRates="48000" channelMasks="AUDIO_CHANNEL_IN_MONO"/>
    </devicePort>
    //扬声器配置
    <devicePort tagName="Speaker" role="sink" type="AUDIO_DEVICE_OUT_SPEAKER" address="">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
        <gains>
            <gain name="gain_1" mode="AUDIO_GAIN_MODE_JOINT"
                  minValueMB="-8400"
                  maxValueMB="4000"
                  defaultValueMB="0"
                  stepValueMB="100"/>
        </gains>
    </devicePort>
    //有线耳机
    <devicePort tagName="Wired Headset" type="AUDIO_DEVICE_OUT_WIRED_HEADSET" role="sink">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
    </devicePort>
    //无线耳机
    <devicePort tagName="Wired Headphones" type="AUDIO_DEVICE_OUT_WIRED_HEADPHONE" role="sink">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
    </devicePort>
    <devicePort tagName="BT SCO" type="AUDIO_DEVICE_OUT_BLUETOOTH_SCO" role="sink">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="8000,16000" channelMasks="AUDIO_CHANNEL_OUT_MONO"/>
    </devicePort>
    <devicePort tagName="BT SCO Headset" type="AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET" role="sink">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="8000,16000" channelMasks="AUDIO_CHANNEL_OUT_MONO"/>
    </devicePort>
    <devicePort tagName="BT SCO Car Kit" type="AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT" role="sink">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="8000,16000" channelMasks="AUDIO_CHANNEL_OUT_MONO"/>
    </devicePort>
    <devicePort tagName="Telephony Tx" type="AUDIO_DEVICE_OUT_TELEPHONY_TX" role="sink">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="8000,16000" channelMasks="AUDIO_CHANNEL_OUT_MONO"/>
    </devicePort>

    <devicePort tagName="Built-In Mic" type="AUDIO_DEVICE_IN_BUILTIN_MIC" role="source">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000"
                 channelMasks="AUDIO_CHANNEL_IN_MONO,AUDIO_CHANNEL_IN_STEREO,AUDIO_CHANNEL_IN_FRONT_BACK"/>
    </devicePort>
    <devicePort tagName="Built-In Back Mic" type="AUDIO_DEVICE_IN_BACK_MIC" role="source">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000"
                 channelMasks="AUDIO_CHANNEL_IN_MONO,AUDIO_CHANNEL_IN_STEREO,AUDIO_CHANNEL_IN_FRONT_BACK"/>
    </devicePort>
    <devicePort tagName="Wired Headset Mic" type="AUDIO_DEVICE_IN_WIRED_HEADSET" role="source">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000"
                 channelMasks="AUDIO_CHANNEL_IN_MONO,AUDIO_CHANNEL_IN_STEREO,AUDIO_CHANNEL_IN_FRONT_BACK"/>
    </devicePort>
    <devicePort tagName="BT SCO Headset Mic" type="AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET" role="source">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="8000,16000" channelMasks="AUDIO_CHANNEL_IN_MONO"/>
    </devicePort>
    <devicePort tagName="Telephony Rx" type="AUDIO_DEVICE_IN_TELEPHONY_RX" role="source">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="8000,16000" channelMasks="AUDIO_CHANNEL_IN_MONO"/>
    </devicePort>
</devicePorts>

mixPorts:音频HAL公开的所有输出和输入流列表。

输出流:primary output、deep_buffer、compressed_offload、voice_tx

输入流:primary input、voice_rx

<mixPorts>
    <mixPort name="primary output" role="source" flags="AUDIO_OUTPUT_FLAG_PRIMARY">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
    </mixPort>
    <mixPort name="deep_buffer" role="source"
            flags="AUDIO_OUTPUT_FLAG_DEEP_BUFFER">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
    </mixPort>
    <mixPort name="compressed_offload" role="source"
             flags="AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_NON_BLOCKING">
        <profile name="" format="AUDIO_FORMAT_MP3"
                 samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000"
                 channelMasks="AUDIO_CHANNEL_OUT_STEREO,AUDIO_CHANNEL_OUT_MONO"/>
        <profile name="" format="AUDIO_FORMAT_AAC"
                 samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000"
                 channelMasks="AUDIO_CHANNEL_OUT_STEREO,AUDIO_CHANNEL_OUT_MONO"/>
        <profile name="" format="AUDIO_FORMAT_AAC_LC"
                 samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000"
                 channelMasks="AUDIO_CHANNEL_OUT_STEREO,AUDIO_CHANNEL_OUT_MONO"/>
    </mixPort>
    <mixPort name="voice_tx" role="source">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="8000,16000" channelMasks="AUDIO_CHANNEL_OUT_MONO"/>
    </mixPort>
    <mixPort name="primary input" role="sink">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000"
                 channelMasks="AUDIO_CHANNEL_IN_MONO,AUDIO_CHANNEL_IN_STEREO,AUDIO_CHANNEL_IN_FRONT_BACK"/>
    </mixPort>
    <mixPort name="voice_rx" role="sink">
        <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                 samplingRates="8000,16000" channelMasks="AUDIO_CHANNEL_IN_MONO"/>
    </mixPort>
</mixPorts>

routes:表示输入和输出设备之间,流和设备之间可能的连接的列表。

<routes>
    <route type="mix" sink="Earpiece"
           sources="primary output,deep_buffer,BT SCO Headset Mic"/>
    <route type="mix" sink="Speaker"
           sources="primary output,deep_buffer,compressed_offload,BT SCO Headset Mic,Telephony Rx"/>
    <route type="mix" sink="Wired Headset"
           sources="primary output,deep_buffer,compressed_offload,BT SCO Headset Mic,Telephony Rx"/>
    <route type="mix" sink="Wired Headphones"
           sources="primary output,deep_buffer,compressed_offload,BT SCO Headset Mic,Telephony Rx"/>
    <route type="mix" sink="primary input"
           sources="Built-In Mic,Built-In Back Mic,Wired Headset Mic,BT SCO Headset Mic"/>
    <route type="mix" sink="Telephony Tx"
           sources="Built-In Mic,Built-In Back Mic,Wired Headset Mic,BT SCO Headset Mic, voice_tx"/>
    <route type="mix" sink="voice_rx"
           sources="Telephony Rx"/>
</routes>

route

  • type: mux表示来源都是互斥的,mix表示是可以混合的;
  • sink:此通路中的接收器;
  • sources:可以连接到该接收器的所有来源;

其他module对应配置

<!-- A2dp Audio HAL -->
<xi:include href="a2dp_audio_policy_configuration.xml"/>

<!-- Usb Audio HAL -->
<xi:include href="usb_audio_policy_configuration.xml"/>

<!-- Remote Submix Audio HAL -->
<xi:include href="r_submix_audio_policy_configuration.xml"/>

<!-- Hearing aid Audio HAL -->
<xi:include href="hearing_aid_audio_policy_configuration.xml"/>

3. volume section

<!-- Volume section -->

<xi:include href="audio_policy_volumes.xml"/>
<xi:include href="default_volume_tables.xml"/>

<!-- End of Volume section -->

audio_policy_volumes 定义了给定场景和设备类别的体积曲线。它包含此曲线的点列表,表示从0到100的给定体积指数的衰减(以Millibel为单位)。

default_volume_tables 包含所有设备类别的完整默认音量表。

以上是关于Android 音频源码分析——aduio_policy_configuration.xml的主要内容,如果未能解决你的问题,请参考以下文章

Android 音频源码分析——AudioTrack设备选择

Android 音频源码分析——AudioTrack设备选择

Android 音频源码分析——audioserver启动

Android 音频源码分析——音频设备切换(插入耳机)

Android 音频源码分析——音频设备切换(插入耳机)

Android 音频源码分析——音频设备切换(插入耳机)