先写解法,此方法只支持一路录音,超过一路,应用调用AudioRecord和MediaRecord将会失败
diff --git a/frameworks/av/services/audioflinger/AudioFlinger.cpp b/frameworks/av/services/audioflinger/AudioFlinger.cpp
index 3132e54..f89ba26 100644
--- a/frameworks/av/services/audioflinger/AudioFlinger.cpp
+++ b/frameworks/av/services/audioflinger/AudioFlinger.cpp
@@ -1691,6 +1691,13 @@ audio_io_handle_t AudioFlinger::openInput(audio_module_handle_t module,
Mutex::Autolock _l(mLock);
+// shanaibing add start, only support one recording
+ if (mRecordThreads.size() > 0) {
+ ALOGE("openinput unsupport multi record");
+ return 0;
+ }
+// shanaibing add end
+
inHwDev = findSuitableHwDev_l(module, *pDevices);
if (inHwDev == NULL)
return 0;
1.针对AudioRecord,在AudioRecorder中native_setup返回错误,导致应用层面new AudioRecorder失败
208 public AudioRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat,
209 int bufferSizeInBytes)
210 throws IllegalArgumentException {
...
227 int initResult = native_setup( new WeakReference<AudioRecord>(this),
228 mRecordSource, mSampleRate, mChannelMask, mAudioFormat, mNativeBufferSizeInBytes,
229 session);
230 if (initResult != SUCCESS) {
231 loge("Error code "+initResult+" when initializing native AudioRecord object.");
232 return; // with mState == STATE_UNINITIALIZED
233 }
234
...
238 }
2.针对MediaRecord,相对复杂一些,从android_media_MediaRecorder.cpp中的mr->start看起
347 static void
348 android_media_MediaRecorder_start(JNIEnv *env, jobject thiz)
349 {
350 ALOGV("start");
351 sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
352 process_media_recorder_call(env, mr->start(), "java/lang/RuntimeException", "start failed.");
353 }
直到StagefrightRecorder.cpp中startMPEG4Recording函数中获取输入源失败,
745 status_t StagefrightRecorder::start() {
...
757 switch (mOutputFormat) {
758 case OUTPUT_FORMAT_DEFAULT:
759 case OUTPUT_FORMAT_THREE_GPP:
760 case OUTPUT_FORMAT_MPEG_4:
761 status = startMPEG4Recording();
762 break;
...
return status;
803 }
最终导致process_media_recorder_call抛出异常,从而应用层面调用start方法失败
参考:
https://blog.csdn.net/omnispace/article/details/52955556
https://www.cnblogs.com/qiengo/p/4220386.html
https://blog.csdn.net/cuitianxiang/article/details/46989773