USB MIC从识别到选择的流程framework层记录

Android9.0 USB MIC从识别到选择的流程framework层记录

使用的平台是RK3399,Android9.0

主要修改应用:

通过相关系统打印得知,当Usb MIC插入系统时,会触发
UsbAlsaManager.java里面的
void usbDeviceAdded(String deviceAddress, UsbDevice usbDevice,UsbDescriptorParser parser)

void usbDeviceAdded(String deviceAddress, UsbDevice usbDevice,
            UsbDescriptorParser parser) {
        if (DEBUG) {
            Slog.d(TAG, "usbDeviceAdded(): " + usbDevice.getManufacturerName()
                    + " nm:" + usbDevice.getProductName());
        }

        // Scan the Alsa File Space
        mCardsParser.scan(); //对Alsa的声卡文件扫描解析

        // Find the ALSA spec for this device address//查找此设备地址的ALSA规范
        AlsaCardsParser.AlsaCardRecord cardRec =
                mCardsParser.findCardNumFor(deviceAddress);
        if (cardRec == null) {
            return;
        }
		//通过解析判断USB 声卡设备是否有输入输出等标记
		//可以通过在此获取USB 声卡的pid以及vid对声卡进行划分判断优先级
		//***" PID: "+usbDevice.getProductId()+" VID: "+usbDevice.getVendorId())***
        // Add it to the devices list
        boolean hasInput = parser.hasInput();
        boolean hasOutput = parser.hasOutput();
        if (DEBUG) {
            Slog.d(TAG, "hasInput: " + hasInput + " hasOutput:" + hasOutput);
        }
        if (hasInput || hasOutput) {
            boolean isInputHeadset = parser.isInputHeadset();
            boolean isOutputHeadset = parser.isOutputHeadset();

            if (mAudioService == null) {
                Slog.e(TAG, "no AudioService");
                return;
            }
			//新建声卡设备对象
            UsbAlsaDevice alsaDevice =
                    new UsbAlsaDevice(mAudioService, cardRec.getCardNum(), 0 /*device*/,
                                      deviceAddress, hasOutput, hasInput,
                                      isInputHeadset, isOutputHeadset);
            if (alsaDevice != null) {
                alsaDevice.setDeviceNameAndDescription(
                          cardRec.getCardName(), cardRec.getCardDescription());
                  //加入到声卡设备的集合列表中
                mAlsaDevices.add(0, alsaDevice);
                //选择声卡设备
                selectAlsaDevice(alsaDevice);
            }
        }

        ..........

        if (DEBUG) {
            Slog.d(TAG, "deviceAdded() - done");
        }
    }

最后通过selectAlsaDevice(alsaDevice)进行对USB声卡的选择

/**
     * Select the AlsaDevice to be used for AudioService.
     * AlsaDevice.start() notifies AudioService of it's connected state.
     *
     * @param alsaDevice The selected UsbAlsaDevice for system USB audio.
     */
    private synchronized void selectAlsaDevice(UsbAlsaDevice alsaDevice) {
        if (DEBUG) {
            Slog.d(TAG, "selectAlsaDevice " + alsaDevice);
        }

        if (mSelectedDevice != null) {
            deselectAlsaDevice();
        }

        // FIXME Does not yet handle the case where the setting is changed
        // after device connection.  Ideally we should handle the settings change
        // in SettingsObserver. Here we should log that a USB device is connected
        // and disconnected with its address (card , device) and force the
        // connection or disconnection when the setting changes.
        int isDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 0);
        if (isDisabled != 0) {
            return;
        }
		//最终调用到alsaDevice.start
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值