Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java

Issue 3007673002: Now uses builder class for AudioRecord objects from SDK 23 (Closed)
Patch Set: nit Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 66c1483851ba38ec9da98c64e54cb136a4c3b04e..729ff37622834875197e3c7ac950c2a32eb75862 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
@@ -215,8 +215,16 @@ 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,
- AudioFormat.ENCODING_PCM_16BIT, bufferSizeInBytes);
+ if (WebRtcAudioUtils.runningOnMarshmallowOrHigher()) {
+ // Use AudioRecord.Builder to create the AudioRecord instance if we are on API level 23 or
+ // higher.
+ audioRecord = createAudioRecordOnMarshmallowOrHigher(
+ sampleRate, channelConfig, bufferSizeInBytes);
+ } else {
+ // Use default constructor for API levels below 23.
+ audioRecord = new AudioRecord(AudioSource.VOICE_COMMUNICATION, sampleRate,
+ channelConfig, AudioFormat.ENCODING_PCM_16BIT, bufferSizeInBytes);
+ }
} catch (IllegalArgumentException e) {
reportWebRtcAudioRecordInitError("AudioRecord ctor error: " + e.getMessage());
releaseAudioResources();
@@ -305,6 +313,22 @@ public class WebRtcAudioRecord {
}
}
+ // Creates an AudioRecord instance using AudioRecord.Builder which was added in API level 23.
+ @TargetApi(23)
+ private AudioRecord createAudioRecordOnMarshmallowOrHigher(
+ int sampleRateInHz, int channelConfig, int bufferSizeInBytes) {
+ Logging.d(TAG, "createAudioRecordOnMarshmallowOrHigher");
+ return new AudioRecord.Builder()
+ .setAudioSource(AudioSource.VOICE_COMMUNICATION)
+ .setAudioFormat(new AudioFormat.Builder()
+ .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
+ .setSampleRate(sampleRateInHz)
+ .setChannelMask(channelConfig)
+ .build())
+ .setBufferSizeInBytes(bufferSizeInBytes)
+ .build();
+ }
+
// Helper method which throws an exception when an assertion has failed.
private static void assertTrue(boolean condition) {
if (!condition) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698