当前位置:   article > 正文

【Android Audio】4、音频设备管理 【基于Android Q 】_listaudioports

listaudioports

4、音频设备管理 【基于Android Q 】

在这里插入图片描述

audio policy xml里面有2种角色:source和sink,每种角色又分为devicePorts和mixPorts。

type为AUDIO_PORT_TYPE_DEVICE
devicePorts(source):为实际的硬件输入设备,对应安卓的role为AUDIO_PORT_ROLE_SOURCE ;
devicePorts(sink):为实际的硬件输出设备,对应安卓的role为AUDIO_PORT_ROLE_SINK ;

type为AUDIO_PORT_TYPE_MIX
mixPorts(source):为AudioFlinger中的播放(AudioTrack)的线程,对应安卓的role为AUDIO_PORT_ROLE_SOURCE,mOutputs;
mixPorts(sink):为AudioFlinger中的录音(AudioRecord)的线程,对应安卓的role为AUDIO_PORT_ROLE_SINK,mInputs

routes:定义devicePort和mixPorts的路由策略

通过该接口AudioSystem.listAudioPorts可获取到当前所有的端口

status_t AudioPolicyManager::listAudioPorts(audio_port_role_t role,
                                            audio_port_type_t type,
                                            unsigned int *num_ports,
                                            struct audio_port *ports,
                                            unsigned int *generation)
{
   
...
    if (type == AUDIO_PORT_TYPE_NONE || type == AUDIO_PORT_TYPE_DEVICE) {
   
        // do not report devices with type AUDIO_DEVICE_IN_STUB or AUDIO_DEVICE_OUT_STUB
        // as they are used by stub HALs by convention
        if (role == AUDIO_PORT_ROLE_SINK || role == AUDIO_PORT_ROLE_NONE) {
   
            for (const auto& dev : mAvailableOutputDevices) {
   
                if (dev->type() == AUDIO_DEVICE_OUT_STUB) {
   
                    continue;
                }
                if (portsWritten < portsMax) {
   
                    dev->toAudioPort(&ports[portsWritten++]);
                    ALOGD("[%s:%d] output device role:%d, name:%s, type:%#x", __func__, __LINE__,
                        ports[portsWritten-1].role, ports[portsWritten-1].name, ports[portsWritten-1].ext.device.type);
                }
                (*num_ports)++;
            }
        }
        if (role == AUDIO_PORT_ROLE_SOURCE || role == AUDIO_PORT_ROLE_NONE) {
   
            for (const auto& dev : mAvailableInputDevices) {
   
                if (dev->type() == AUDIO_DEVICE_IN_STUB) {
   
                    continue;
                }
                if (portsWritten < portsMax) {
   
                    dev->toAudioPort(&ports[portsWritten++]);
                    ALOGD("[%s:%d] input device role:%d, name:%s, type:%#x", __func__, __LINE__,
                        ports[portsWritten-1].role, ports[portsWritten-1].name, ports[portsWritten-1].ext.device.type);
                }
                (
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/875978?site
推荐阅读
相关标签
  

闽ICP备14008679号