From 0ce09885034fd831e2eaa92b871c5717311014d9 Mon Sep 17 00:00:00 2001 From: henrika Date: Mon, 20 Nov 2017 12:32:55 +0100 Subject: [PATCH] Expose audio record source setting in WebRtcAudioRecord. Landing https://webrtc-review.googlesource.com/c/src/+/23881 on behalf of stevengatto@ TBR=glaznev Bug: webrtc:8545 Change-Id: I4358b93d2f4d934c497c4d3ee7e86e1fbc7a5fae Reviewed-on: https://webrtc-review.googlesource.com/24460 Reviewed-by: Henrik Andreassson Commit-Queue: Henrik Andreassson Cr-Commit-Position: refs/heads/master@{#20788} --- .../webrtc/voiceengine/WebRtcAudioRecord.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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) {