diff --git a/webrtc/modules/audio_device/android/opensles_input.cc b/webrtc/modules/audio_device/android/opensles_input.cc index f22d8bf7ef..e68a6aa2f8 100644 --- a/webrtc/modules/audio_device/android/opensles_input.cc +++ b/webrtc/modules/audio_device/android/opensles_input.cc @@ -360,6 +360,24 @@ bool OpenSlesInput::CreateAudioRecorder() { req), false); + 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. + SLint32 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); + // Realize the recorder in synchronous mode. OPENSL_RETURN_ON_FAILURE((*sles_recorder_)->Realize(sles_recorder_, SL_BOOLEAN_FALSE), diff --git a/webrtc/modules/audio_device/android/opensles_output.cc b/webrtc/modules/audio_device/android/opensles_output.cc index 377789b237..487e284042 100644 --- a/webrtc/modules/audio_device/android/opensles_output.cc +++ b/webrtc/modules/audio_device/android/opensles_output.cc @@ -407,6 +407,24 @@ bool OpenSlesOutput::CreateAudioPlayer() { &audio_source, &audio_sink, kNumInterfaces, ids, req), false); + + SLAndroidConfigurationItf player_config; + OPENSL_RETURN_ON_FAILURE( + (*sles_player_)->GetInterface(sles_player_, + SL_IID_ANDROIDCONFIGURATION, + &player_config), + false); + + // Set audio player configuration to SL_ANDROID_STREAM_VOICE which corresponds + // to android.media.AudioManager.STREAM_VOICE_CALL. + SLint32 stream_type = SL_ANDROID_STREAM_VOICE; + OPENSL_RETURN_ON_FAILURE( + (*player_config)->SetConfiguration(player_config, + SL_ANDROID_KEY_STREAM_TYPE, + &stream_type, + sizeof(SLint32)), + false); + // Realize the player in synchronous mode. OPENSL_RETURN_ON_FAILURE((*sles_player_)->Realize(sles_player_, SL_BOOLEAN_FALSE),