Android Audio - 支持多个CODEC同时录音

Android Audio - 支持多个CODEC同时录音

Android6.0 修改方法

源码路径: sdk\frameworks\av\services\audiopolicy\managerdefault\AudioPolicyManager.cpp
在 status_t AudioPolicyManager::startInput() 代码片中, 注释掉以下代码即可

#ifndef ANDROID6_0_SUPPORT_MULIT_CODEC_RECORDING
	// Modify Tower 20190429, support multi codec recording
    // virtual input devices are compatible with other input devices
    if (!is_virtual_input_device(inputDesc->mDevice)) {
        // for a non-virtual input device, check if there is another (non-virtual) active input
        audio_io_handle_t activeInput = mInputs.getActiveInput();
        if (activeInput != 0 && activeInput != input) {
            // If the already active input uses AUDIO_SOURCE_HOTWORD then it is closed,
            // otherwise the active input continues and the new input cannot be started.
            sp<AudioInputDescriptor> activeDesc = mInputs.valueFor(activeInput);
            if ((activeDesc->mInputSource == AUDIO_SOURCE_HOTWORD) &&
                    !activeDesc->hasPreemptedSession(session)) {
                ALOGW("startInput(%d) preempting low-priority input %d", input, activeInput);
                audio_session_t activeSession = activeDesc->mSessions.itemAt(0);
                SortedVector<audio_session_t> sessions = activeDesc->getPreemptedSessions();
                sessions.add(activeSession);
                inputDesc->setPreemptedSessions(sessions);
                stopInput(activeInput, activeSession);
                releaseInput(activeInput, activeSession);
            } else {
                ALOGE("startInput(%d) failed: other input %d already started", input, activeInput);
                return INVALID_OPERATION;
            }
        }

        // Do not allow capture if an active voice call is using a software patch and
        // the call TX source device is on the same HW module.
        // FIXME: would be better to refine to only inputs whose profile connects to the
        // call TX device but this information is not in the audio patch
        if (mCallTxPatch != 0 &&
            inputDesc->getModuleHandle() == mCallTxPatch->mPatch.sources[0].ext.device.hw_module) {
            return INVALID_OPERATION;
        }
    }
#endif

说明

其实就是 AudioPolicyManager 类成员 mInputs[] 里面获取是否已经有 RecordThread 线程打开(mRefCount > 0)时. 原先Android 是不支持多个声卡同时录音的. 本身 Android 音频框架里面就只有一个 RecordThread 线程. 通过以上代码片注释. 使得Android 不得不重新创建一个新的 RecordThread 和数据缓冲池. 达到多声卡同时录音的目的.

[补充]:

有问题可以邮件沟通 iFinelio Tower <308662170@qq.com>

  • 0
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值