Revert "Add support of AudioRecord.Builder in the ADM for Android"

This reverts commit 24b945d60526f8074d0db1329ba20e9b49602794.

Reason for revert: Caused http://b/140707892

Original change's description:
> Add support of AudioRecord.Builder in the ADM for Android
> 
> Use the latest builder class for AudioRecord instead of the old
> constructor. AudioTrack has been updated for a while now.
> 
> Bug: webrtc:10942
> Change-Id: Ia68b12e5aaf1525cfa630650fbaaa02d70ada15f
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/151305
> Reviewed-by: Alex Glaznev <glaznev@webrtc.org>
> Commit-Queue: Henrik Andreassson <henrika@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#29072}

TBR=henrika@webrtc.org,glaznev@webrtc.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: webrtc:10942
Change-Id: Idbc487cf8d42e76f6a3435be6fef6634aa0cd62b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/152526
Reviewed-by: Daixiang Mou <dmou@webrtc.org>
Commit-Queue: Daixiang Mou <dmou@webrtc.org>
Commit-Queue: Hari Molabanti <harimb@google.com>
Cr-Commit-Position: refs/heads/master@{#29159}
This commit is contained in:
Hari Molabanti
2019-09-11 18:03:23 +00:00
committed by Commit Bot
parent 7e2441234b
commit a1727db1ac

View File

@ -10,7 +10,6 @@
package org.webrtc.audio; package org.webrtc.audio;
import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.media.AudioFormat; import android.media.AudioFormat;
import android.media.AudioManager; import android.media.AudioManager;
@ -252,22 +251,15 @@ class WebRtcAudioRecord {
int bufferSizeInBytes = Math.max(BUFFER_SIZE_FACTOR * minBufferSize, byteBuffer.capacity()); int bufferSizeInBytes = Math.max(BUFFER_SIZE_FACTOR * minBufferSize, byteBuffer.capacity());
Logging.d(TAG, "bufferSizeInBytes: " + bufferSizeInBytes); Logging.d(TAG, "bufferSizeInBytes: " + bufferSizeInBytes);
try { try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { audioRecord =
// Use the AudioRecord.Builder class on Android M (23) and above. new AudioRecord(audioSource, sampleRate, channelConfig, audioFormat, bufferSizeInBytes);
audioRecord = createAudioRecordOnMOrHigher(
audioSource, sampleRate, channelConfig, audioFormat, bufferSizeInBytes);
} else {
// Use the old AudioRecord constructor for API levels below 23.
audioRecord = createAudioRecordOnLowerThanM(
audioSource, sampleRate, channelConfig, audioFormat, bufferSizeInBytes);
}
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
reportWebRtcAudioRecordInitError("AudioRecord build error: " + e.getMessage()); reportWebRtcAudioRecordInitError("AudioRecord ctor error: " + e.getMessage());
releaseAudioResources(); releaseAudioResources();
return -1; return -1;
} }
if (audioRecord == null || audioRecord.getState() != AudioRecord.STATE_INITIALIZED) { if (audioRecord == null || audioRecord.getState() != AudioRecord.STATE_INITIALIZED) {
reportWebRtcAudioRecordInitError("Creation or initialization of audio recorder failed."); reportWebRtcAudioRecordInitError("Failed to create a new AudioRecord instance");
releaseAudioResources(); releaseAudioResources();
return -1; return -1;
} }
@ -291,7 +283,7 @@ class WebRtcAudioRecord {
} }
if (audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) { if (audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
reportWebRtcAudioRecordStartError(AudioRecordStartErrorCode.AUDIO_RECORD_START_STATE_MISMATCH, reportWebRtcAudioRecordStartError(AudioRecordStartErrorCode.AUDIO_RECORD_START_STATE_MISMATCH,
"AudioRecord.startRecording failed - incorrect state: " "AudioRecord.startRecording failed - incorrect state :"
+ audioRecord.getRecordingState()); + audioRecord.getRecordingState());
return false; return false;
} }
@ -315,27 +307,6 @@ class WebRtcAudioRecord {
return true; return true;
} }
@TargetApi(Build.VERSION_CODES.M)
private static AudioRecord createAudioRecordOnMOrHigher(
int audioSource, int sampleRate, int channelConfig, int audioFormat, int bufferSizeInBytes) {
Logging.d(TAG, "createAudioRecordOnMOrHigher");
return new AudioRecord.Builder()
.setAudioSource(audioSource)
.setAudioFormat(new AudioFormat.Builder()
.setEncoding(audioFormat)
.setSampleRate(sampleRate)
.setChannelMask(channelConfig)
.build())
.setBufferSizeInBytes(bufferSizeInBytes)
.build();
}
private static AudioRecord createAudioRecordOnLowerThanM(
int audioSource, int sampleRate, int channelConfig, int audioFormat, int bufferSizeInBytes) {
Logging.d(TAG, "createAudioRecordOnLowerThanM");
return new AudioRecord(audioSource, sampleRate, channelConfig, audioFormat, bufferSizeInBytes);
}
private void logMainParameters() { private void logMainParameters() {
Logging.d(TAG, Logging.d(TAG,
"AudioRecord: " "AudioRecord: "