diff --git a/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java b/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java index ba93ea1fb2..71c7df18fc 100644 --- a/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java +++ b/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java @@ -47,6 +47,9 @@ public class WebRtcAudioRecord { // but the wait times out afther this amount of time. private static final long AUDIO_RECORD_THREAD_JOIN_TIMEOUT_MS = 2000; + private static final int DEFAULT_AUDIO_SOURCE = getDefaultAudioSource(); + private static int audioSource = DEFAULT_AUDIO_SOURCE; + private final long nativeAudioRecord; private WebRtcAudioEffects effects = null; @@ -205,7 +208,7 @@ public class WebRtcAudioRecord { int bufferSizeInBytes = Math.max(BUFFER_SIZE_FACTOR * minBufferSize, byteBuffer.capacity()); Logging.d(TAG, "bufferSizeInBytes: " + bufferSizeInBytes); try { - audioRecord = new AudioRecord(AudioSource.VOICE_COMMUNICATION, sampleRate, channelConfig, + audioRecord = new AudioRecord(audioSource, sampleRate, channelConfig, AudioFormat.ENCODING_PCM_16BIT, bufferSizeInBytes); } catch (IllegalArgumentException e) { reportWebRtcAudioRecordInitError("AudioRecord ctor error: " + e.getMessage()); @@ -294,6 +297,17 @@ public class WebRtcAudioRecord { private native void nativeDataIsRecorded(int bytes, long nativeAudioRecord); + @SuppressWarnings("NoSynchronizedMethodCheck") + public static synchronized void setAudioSource(int source) { + Logging.w(TAG, "Audio source is changed from: " + audioSource + + " to " + source); + audioSource = source; + } + + private static int getDefaultAudioSource() { + return AudioSource.VOICE_COMMUNICATION; + } + // Sets all recorded samples to zero if |mute| is true, i.e., ensures that // the microphone is muted. public static void setMicrophoneMute(boolean mute) {