通话对 Android 音频路由有何影响?

问题描述

我正在将 AOSP (Android 10) 移植到新设备。音频正在工作。通话音频不起作用。

我的 audio_policy_configuration.xml 目前是:

<audioPolicyConfiguration version="1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
    <globalConfiguration speaker_drc_enabled="true"/>

    <modules>
        <module name="primary" halVersion="2.0">
            <attachedDevices>
                <item>Speaker</item>    
                <item>Built-In Mic</item>

                <item>Telephony Rx</item>
                <item>Telephony Tx</item>
            </attachedDevices>
            <defaultOutputDevice>Speaker</defaultOutputDevice>
            <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="hdmi output" role="source" flags="AUdio_OUTPUT_FLAG_DIRECT">
                    <profile name="" format="AUdio_FORMAT_PCM_16_BIT"
                             samplingRates="32000,44100,48000,88200,96000,176400,192000" channelMasks="AUdio_CHANNEL_NONE"/>
                </mixPort>
                <mixPort name="esai output" role="source" flags="AUdio_OUTPUT_FLAG_DIRECT|AUdio_OUTPUT_FLAG_HW_AV_SYNC">
                    <profile name="" format="AUdio_FORMAT_PCM_16_BIT"
                             samplingRates="48000,192000,384000,768000"
                             channelMasks="AUdio_CHANNEL_OUT_STEREO,AUdio_CHANNEL_OUT_QUAD,AUdio_CHANNEL_OUT_5POINT1,AUdio_CHANNEL_OUT_7POINT1"/>
                    <profile name="" format="AUdio_FORMAT_PCM_FLOAT"
                             samplingRates="48000,AUdio_CHANNEL_OUT_7POINT1"/>
                </mixPort>
                <mixPort name="dsd output" role="source" flags="AUdio_OUTPUT_FLAG_DIRECT|AUdio_OUTPUT_FLAG_COMPRESS_OFFLOAD">
                    <profile name="" format="AUdio_FORMAT_DSD"
                             samplingRates="2822400,5644800,11289600,22579200" channelMasks="AUdio_CHANNEL_OUT_STEREO"/>
                </mixPort>
                <mixPort name="primary input" role="sink">
                    <profile name="" format="AUdio_FORMAT_PCM_16_BIT"
                             samplingRates="8000,11025,16000,22050,24000,32000,48000"
                             channelMasks="AUdio_CHANNEL_IN_MONO,AUdio_CHANNEL_IN_STEREO"/>
                </mixPort>

                <mixPort name="voice_tx" role="source">
                    <profile name="" format="AUdio_FORMAT_PCM_16_BIT"
                             samplingRates="16000" channelMasks="AUdio_CHANNEL_OUT_MONO,AUdio_CHANNEL_OUT_STEREO"/>
                </mixPort>
                <mixPort name="voice_rx" role="sink">
                    <profile name="" format="AUdio_FORMAT_PCM_16_BIT"
                             samplingRates="16000" channelMasks="AUdio_CHANNEL_IN_MONO,AUdio_CHANNEL_IN_STEREO"/>
                </mixPort>
            </mixPorts>
            <devicePorts>
                <devicePort tagName="Speaker" type="AUdio_DEVICE_OUT_SPEAKER" role="sink" >
                </devicePort>
                <devicePort tagName="Wired Headphones" type="AUdio_DEVICE_OUT_WIRED_HEADPHONE" role="sink">
                </devicePort>
                <devicePort tagName="HDMI Out" type="AUdio_DEVICE_OUT_AUX_DIGITAL" role="sink">
                </devicePort>
                <devicePort tagName="Line-Out" type="AUdio_DEVICE_OUT_LINE" role="sink">
                </devicePort>
                <devicePort tagName="Built-In Mic" type="AUdio_DEVICE_IN_BUILTIN_MIC" role="source">
                </devicePort>
                <devicePort tagName="Line-In" type="AUdio_DEVICE_IN_AUX_DIGITAL" role="source">
                </devicePort>

                <devicePort tagName="Telephony Rx" type="AUdio_DEVICE_IN_TELEPHONY_RX" role="source">
                </devicePort>
                <devicePort tagName="Telephony Tx" type="AUdio_DEVICE_OUT_TELEPHONY_TX" role="sink">
                </devicePort>
            </devicePorts>
            <routes>
                <route type="mix" sink="Speaker"
                       sources="primary output"/>
                <route type="mix" sink="Wired Headphones"
                       sources="dsd output,esai output,primary output"/>
                <route type="mix" sink="HDMI Out"
                       sources="hdmi output,primary output"/>
                <route type="mix" sink="Line-Out"
                       sources="dsd output,primary output"/>
                <route type="mix" sink="primary input"
                       sources="Built-In Mic,Line-In"/>

                <route type="mix" sink="Telephony Tx"
                       sources="voice_tx"/>
                <route type="mix" sink="voice_rx"
                       sources="Telephony Rx"/>       
            </routes>
        </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"/>

    </modules>

    <!-- Volume section -->
    <xi:include href="audio_policy_volumes.xml"/>
    <xi:include href="default_volume_tables.xml"/>

</audioPolicyConfiguration>

(我添加Telephone Tx/Rx attachedDevicesdevicePortsvoice_tx/rx mixPortsTelephony Txvoice_rx routes。)

logcat | grep audio输出是:

<DIAL>
03-29 10:09:36.495  3504  3661 I audio_hw_primary: adev_set_mode mode 2
03-29 10:09:36.495  3504  3661 W audio_hw_primary: Entering IN_CALL state,in_call=0
03-29 10:09:36.495  3504  3661 W audio_hw_primary: no standby
03-29 10:09:36.495  3504  3661 I audio_hw_primary: select_output_device(),headphone 0,headset 0,speaker 0,earpiece 1,03-29 10:09:36.591  3504  3661 D audio_hw_primary: out_set_parameters: enter: kvpairs: routing=2
03-29 10:09:36.591  3504  3661 D audio_hw_primary: out_set_parameters: exit: code(0)
03-29 10:09:36.594  3504  3661 D audio_hw_primary: out_set_parameters: enter: kvpairs: routing=2
03-29 10:09:36.594  3504  3661 D audio_hw_primary: out_set_parameters: exit: code(0)
03-29 10:09:36.643  4425  4425 I Dialer  : ProximitySensor.updateProximitySensorMode - screenOnImmediately: false,dialPadVisible: false,offHook: false,horizontal: false,uiShowing: false,audioRoute: EARPIECE
03-29 10:09:36.908  4425  4425 I Dialer  : ProximitySensor.updateProximitySensorMode - screenOnImmediately: false,offHook: true,audioRoute: EARPIECE
03-29 10:09:36.910  4425  4425 I Dialer  : ProximitySensor.updateProximitySensorMode - screenOnImmediately: false,uiShowing: true,audioRoute: EARPIECE
03-29 10:09:37.054  3737  4093 I Telecom : InCallController: Calling onAudioStateChanged,audioState: [AudioState isMuted: false,route: WIRED_HEADSET,supportedRouteMask: WIRED_HEADSET,SPEAKER,activeBluetoothDevice: [null],supportedBluetoothDevices: []] -> [AudioState isMuted: false,supportedBluetoothDevices: []]: (...->CS.crCo->H.CS.crCo->H.CS.crCo.pICR)->CSW.hCCC->CARSM.pM_UPDATE_SYstem_AUdio_ROUTE@E-E-AGA
03-29 10:09:37.246  4425  4425 I Dialer  : ProximitySensor.updateProximitySensorMode - screenOnImmediately: true,audioRoute: WIRED_HEADSET
03-29 10:09:37.296  4425  4425 I Dialer  : InCallFragment.setAudioState - audioState: [AudioState isMuted: false,supportedBluetoothDevices: []]
<ANSWER>
<HUP>
03-29 10:09:59.189  3737  4093 I Telecom : InCallController: Calling onAudioStateChanged,supportedBluetoothDevices: []]: CSW.sDc->CARSM.pM_UPDATE_SYstem_AUdio_ROUTE@AO0
03-29 10:09:59.243  4425  4425 I Dialer  : ProximitySensor.updateProximitySensorMode - screenOnImmediately: true,audioRoute: WIRED_HEADSET
03-29 10:09:59.343  3504  5123 I audio_hw_primary: start_output_stream_primary... 0xeb651000,device 2,address,mode 2
03-29 10:09:59.343  3504  5123 I audio_hw_primary: get_card_for_device adev: 0xeb62d000,device: 2,flag: 0,card_index: 0xeb651158
03-29 10:09:59.353  3504  5123 W audio_hw_primary: card 0,port 0 device 0x2
03-29 10:09:59.353  3504  5123 W audio_hw_primary: rate 48000,channel 2 period_size 0xc0
03-29 10:10:00.607  3737  4094 I Telecom : CallAudioModeStateMachine: Abandoning audio focus: Now UNFOCUSED: CSW.sDc->ICTP.r->ICTP.cUTP->CAMSM.pM_3002@AO0
03-29 10:10:00.608  3504  3661 I audio_hw_primary: adev_set_mode mode 0
03-29 10:10:00.608  3504  3661 W audio_hw_primary: Leaving IN_CALL state,in_call=1,mode=0
03-29 10:10:00.609  3504  3661 W audio_hw_primary: do_out_standby... 0xeb651000
03-29 10:10:00.609  3504  3661 I audio_hw_primary: select_output_device(),03-29 10:10:00.615  3504  5123 I audio_hw_primary: start_output_stream_primary... 0xeb651000,mode 0
03-29 10:10:00.615  3504  5123 I audio_hw_primary: select_output_device(),03-29 10:10:00.618  3504  5123 I audio_hw_primary: get_card_for_device adev: 0xeb62d000,card_index: 0xeb651158
03-29 10:10:00.623  3504  5123 W audio_hw_primary: card 0,port 0 device 0x2
03-29 10:10:00.623  3504  5123 W audio_hw_primary: rate 48000,channel 2 period_size 0xc0
03-29 10:10:01.776  4425  4425 I Dialer  : ProximitySensor.updateProximitySensorMode - screenOnImmediately: true,audioRoute: WIRED_HEADSET
03-29 10:10:03.607  3504  3661 W audio_hw_primary: do_out_standby... 0xeb651000
^C

在这里看不到任何错误

我也看不到任何迹象表明正在使用新路由。 (通话中还没有音频。)

如何让 Android 注意到对 audio_policy_configuration.xml添加并使其使用在通话期间路由的 Telephony Txvoice_rx

解决方法

查看同时具有 Telephony TxTelephony Rx 端口的 this example 时,与您的配置相比的一个不同之处在于它还定义了从 Telephony Rx 到大多数接收器的路由,以及从所有麦克风到 Telephony Tx

<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,Telephony Rx"/>
<route type="mix" sink="Wired Headphones"
       sources="primary output,Telephony Rx"/>
<route type="mix" sink="Telephony Tx" 
       sources="Built-In Mic,Built-In Back Mic,Wired Headset Mic,BT SCO Headset Mic"/>

为了使路由正常工作,这可能是您的配置中缺少的一部分。

出于某种原因,Telephony Rx 未添加为 Earpiece 接收器的源。我不知道这是为什么。也许是疏忽(?)。

,

如果您使用的是 Agora Android Video SDK,那么您可以使用 setDefaultAudioRoutetoSpeakerphone 方法