【问题标题】:How does being in a call affect Android Audio routing?通话中对 Android 音频路由有何影响?
【发布时间】:2021-03-29 09:31:09
【问题描述】:

我正在将 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,96000,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,96000,192000,384000,768000"
                             channelMasks="AUDIO_CHANNEL_OUT_STEREO,AUDIO_CHANNEL_OUT_QUAD,AUDIO_CHANNEL_OUT_5POINT1,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,44100,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,esai 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/RxattachedDevicesdevicePortsvoice_tx/rxmixPortsTelephony Txvoice_rxroutes)。 p>

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, dialPadVisible: false, offHook: true, horizontal: false, uiShowing: false, audioRoute: EARPIECE
03-29 10:09:36.910  4425  4425 I Dialer  : ProximitySensor.updateProximitySensorMode - screenOnImmediately: false, dialPadVisible: false, offHook: true, horizontal: 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, route: WIRED_HEADSET, supportedRouteMask: WIRED_HEADSET, SPEAKER, activeBluetoothDevice: [null], 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, dialPadVisible: false, offHook: true, horizontal: false, uiShowing: true, audioRoute: WIRED_HEADSET
03-29 10:09:37.296  4425  4425 I Dialer  : InCallFragment.setAudioState - audioState: [AudioState isMuted: false, route: WIRED_HEADSET, supportedRouteMask: WIRED_HEADSET, SPEAKER, activeBluetoothDevice: [null], supportedBluetoothDevices: []]
<ANSWER>
<HUP>
03-29 10:09:59.189  3737  4093 I Telecom : InCallController: Calling onAudioStateChanged, audioState: [AudioState isMuted: false, route: WIRED_HEADSET, supportedRouteMask: WIRED_HEADSET, SPEAKER, activeBluetoothDevice: [null], supportedBluetoothDevices: []] -> [AudioState isMuted: false, route: WIRED_HEADSET, supportedRouteMask: WIRED_HEADSET, SPEAKER, activeBluetoothDevice: [null], supportedBluetoothDevices: []]: CSW.sDc->CARSM.pM_UPDATE_SYSTEM_AUDIO_ROUTE@AO0
03-29 10:09:59.243  4425  4425 I Dialer  : ProximitySensor.updateProximitySensorMode - screenOnImmediately: true, dialPadVisible: false, offHook: false, horizontal: false, uiShowing: 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(), headphone 0 ,headset 0 ,speaker 0, earpiece 1,
03-29 10:10:00.615  3504  5123 I audio_hw_primary: start_output_stream_primary... 0xeb651000, device 2, address , mode 0
03-29 10:10:00.615  3504  5123 I audio_hw_primary: select_output_device(), headphone 0 ,headset 0 ,speaker 0, earpiece 1,
03-29 10:10:00.618  3504  5123 I audio_hw_primary: get_card_for_device adev: 0xeb62d000, device: 2, flag: 0, 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, dialPadVisible: false, offHook: false, horizontal: false, uiShowing: false, 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

【问题讨论】:

  • 您是否尝试过像this example 那样向/从您的新设备端口添加路由?
  • 我相信我已经添加了&lt;route type="mix" sink="Telephony Tx" sources="voice_tx"/&gt;&lt;route type="mix" sink="voice_rx" sources="Telephony Rx"/&gt;。你建议我把sources="Built-In Mic...加到&lt;route type="mix" sink="Telephony Tx"吗?
  • 如果您查看我链接到的示例,它会将Telephony Rx 添加为大多数接收器的源,并将Telephony Tx 添加为所有麦克风的接收器。自从我使用 Android 平台音频以来已经有好几年了,当时以不同的方式处理路由,所以我不知道这是否是正确的做法,但可能值得一试。
  • @Michael 如果你把你的评论变成一个答案,我会奖励赏金来拯救它去浪费,

标签: android audio android-source


【解决方案1】:

查看this example 时,它也有Telephony TxTelephony Rx 端口,与您的配置相比,一个不同之处在于它还定义了从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,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="Telephony Tx" 
       sources="Built-In Mic,Built-In Back Mic,Wired Headset Mic,BT SCO Headset Mic"/>

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-10
      • 1970-01-01
      • 2013-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-08
      相关资源
      最近更新 更多