android 4.4.2 两路录音会导致系统anr,进而崩溃

先写解法,此方法只支持一路录音,超过一路,应用调用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

https://blog.csdn.net/u012169524/article/details/52938241

https://www.jianshu.com/p/f40157091db3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值