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>