| Index: webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java
|
| diff --git a/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java b/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java
|
| index 3bda070eac1069a291c15fd4d85d92fb01d09faa..c3665442b06260557cf94c8e5cd2724926773da7 100644
|
| --- a/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java
|
| +++ b/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java
|
| @@ -170,8 +170,9 @@ public class WebRtcAudioRecord {
|
| // Get the minimum buffer size required for the successful creation of
|
| // an AudioRecord object, in byte units.
|
| // Note that this size doesn't guarantee a smooth recording under load.
|
| - int minBufferSize = AudioRecord.getMinBufferSize(
|
| - sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
|
| + final int channelConfig = channelCountToConfiguration(channels);
|
| + int minBufferSize =
|
| + AudioRecord.getMinBufferSize(sampleRate, channelConfig, AudioFormat.ENCODING_PCM_16BIT);
|
| if (minBufferSize == AudioRecord.ERROR || minBufferSize == AudioRecord.ERROR_BAD_VALUE) {
|
| Logging.e(TAG, "AudioRecord.getMinBufferSize failed: " + minBufferSize);
|
| return -1;
|
| @@ -184,8 +185,8 @@ 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,
|
| - AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSizeInBytes);
|
| + audioRecord = new AudioRecord(AudioSource.VOICE_COMMUNICATION, sampleRate, channelConfig,
|
| + AudioFormat.ENCODING_PCM_16BIT, bufferSizeInBytes);
|
| } catch (IllegalArgumentException e) {
|
| Logging.e(TAG, e.getMessage());
|
| return -1;
|
| @@ -246,7 +247,7 @@ public class WebRtcAudioRecord {
|
| // created instance uses the parameters that we asked for.
|
| private boolean areParametersValid(int sampleRate, int channels) {
|
| return (audioRecord.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT
|
| - && audioRecord.getChannelConfiguration() == AudioFormat.CHANNEL_IN_MONO
|
| + && audioRecord.getChannelConfiguration() == channelCountToConfiguration(channels)
|
| && audioRecord.getAudioSource() == AudioSource.VOICE_COMMUNICATION
|
| && audioRecord.getSampleRate() == sampleRate && audioRecord.getChannelCount() == channels);
|
| }
|
| @@ -273,6 +274,10 @@ public class WebRtcAudioRecord {
|
| }
|
| }
|
|
|
| + private int channelCountToConfiguration(int channels) {
|
| + return (channels == 1 ? AudioFormat.CHANNEL_IN_MONO : AudioFormat.CHANNEL_IN_STEREO);
|
| + }
|
| +
|
| private native void nativeCacheDirectBufferAddress(ByteBuffer byteBuffer, long nativeAudioRecord);
|
|
|
| private native void nativeDataIsRecorded(int bytes, long nativeAudioRecord);
|
|
|