Bug 1134991 - Failure to set up voice communication mode in OpenSLES should not be fatal. r=jesup, a=lizzard
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Fri, 20 Feb 2015 19:13:13 +0100
changeset 280720 6267d292aab3b6464d1ddd08d52416a397f0c4d8
parent 280719 9a4542438b40afd3d2066afe919fbd49b3354ff2
child 280721 108b0d3dc2fea25c07d7105baee6cac01fc969fd
push id113
push userryanvm@gmail.com
push dateThu, 05 Nov 2015 16:09:15 +0000
reviewersjesup, lizzard
bugs1134991
milestone38.0a2
Bug 1134991 - Failure to set up voice communication mode in OpenSLES should not be fatal. r=jesup, a=lizzard
media/webrtc/trunk/webrtc/modules/audio_device/android/opensles_input.cc
media/webrtc/trunk/webrtc/modules/audio_device/android/opensles_input.h
--- a/media/webrtc/trunk/webrtc/modules/audio_device/android/opensles_input.cc
+++ b/media/webrtc/trunk/webrtc/modules/audio_device/android/opensles_input.cc
@@ -391,16 +391,33 @@ bool OpenSlesInput::EnqueueAllBuffers() 
   // |fifo_|.
   while (fifo_->size() != 0) {
     // Clear the fifo.
     fifo_->Pop();
   }
   return true;
 }
 
+void OpenSlesInput::SetupVoiceMode() {
+  SLAndroidConfigurationItf configItf;
+  SLresult res = (*sles_recorder_)->GetInterface(sles_recorder_, SL_IID_ANDROIDCONFIGURATION_,
+                                                 (void*)&configItf);
+  WEBRTC_TRACE(kTraceError, kTraceAudioDevice, id_, "OpenSL GetInterface: %d", res);
+
+  if (res == SL_RESULT_SUCCESS) {
+    SLuint32 voiceMode = SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION;
+    SLuint32 voiceSize = sizeof(voiceMode);
+
+    res = (*configItf)->SetConfiguration(configItf,
+                                         SL_ANDROID_KEY_RECORDING_PRESET,
+                                         &voiceMode, voiceSize);
+    WEBRTC_TRACE(kTraceError, kTraceAudioDevice, id_, "OpenSL Set Voice mode res: %d", res);
+  }
+}
+
 #if defined(WEBRTC_GONK) && defined(WEBRTC_HARDWARE_AEC_NS)
 bool OpenSlesInput::CheckPlatformAEC() {
   effect_descriptor_t fxDesc;
   uint32_t numFx;
 
   if (android::AudioEffect::queryNumberEffects(&numFx) != android::NO_ERROR) {
     return false;
   }
@@ -514,26 +531,17 @@ bool OpenSlesInput::CreateAudioRecorder(
 
   SLAndroidConfigurationItf recorder_config;
   OPENSL_RETURN_ON_FAILURE(
       (*sles_recorder_)->GetInterface(sles_recorder_,
                                       SL_IID_ANDROIDCONFIGURATION_,
                                       &recorder_config),
       false);
 
-  // Set audio recorder configuration to
-  // SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION which ensures that we
-  // use the main microphone tuned for audio communications.
-  SLuint32 stream_type = SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION;
-  OPENSL_RETURN_ON_FAILURE(
-      (*recorder_config)->SetConfiguration(recorder_config,
-                                           SL_ANDROID_KEY_RECORDING_PRESET,
-                                           &stream_type,
-                                           sizeof(SLint32)),
-      false);
+  SetupVoiceMode();
 
   // Realize the recorder in synchronous mode.
   OPENSL_RETURN_ON_FAILURE((*sles_recorder_)->Realize(sles_recorder_,
                                                       SL_BOOLEAN_FALSE),
                            false);
 
 #if defined(WEBRTC_GONK) && defined(WEBRTC_HARDWARE_AEC_NS)
   SetupAECAndNS();
--- a/media/webrtc/trunk/webrtc/modules/audio_device/android/opensles_input.h
+++ b/media/webrtc/trunk/webrtc/modules/audio_device/android/opensles_input.h
@@ -142,19 +142,19 @@ class OpenSlesInput {
   void CalculateNumFifoBuffersNeeded();
   void AllocateBuffers();
   int TotalBuffersUsed() const;
   bool EnqueueAllBuffers();
   // This function also configures the audio recorder, e.g. sample rate to use
   // etc, so it should be called when starting recording.
   bool CreateAudioRecorder();
   void DestroyAudioRecorder();
+  void SetupVoiceMode();
 #if defined(WEBRTC_GONK) && defined(WEBRTC_HARDWARE_AEC_NS)
   void SetupAECAndNS();
-  void SetupVoiceMode();
   bool CheckPlatformAEC();
 #endif
 
   // When overrun happens there will be more frames received from OpenSL than
   // the desired number of buffers. It is possible to expand the number of
   // buffers as you go but that would greatly increase the complexity of this
   // code. HandleOverrun gracefully handles the scenario by restarting playout,
   // throwing away all pending audio data. This will sound like a click. This