Revert "Now uses AudioRecord.Builder on Android again."

This reverts commit e7a5567954e43d1560e07770155c6ed66c6b9df2.

Reason for revert: Causes crashes when no permissions are granted - b/71056584

TBR=henrika@webrtc.org

Original change's description:
> Now uses AudioRecord.Builder on Android again.
>
> I tried to land the same change by reverting https://webrtc-review.googlesource.com/c/src/+/34443
> but the revert failed and I therefore land it manually here instead.
>
> TBR=glaznev@webrtc.org
>
> Bug: b/32742417
> Change-Id: Ied8ed3e7c7d67c51f781e39cbea952a2303278d9
> Reviewed-on: https://webrtc-review.googlesource.com/34442
> Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
> Commit-Queue: Henrik Andreassson <henrika@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#21351}

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

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

Bug: b/32742417
Change-Id: I8fd27d4b8c7d5a04f24477fc0ddffae89f01d566
Reviewed-on: https://webrtc-review.googlesource.com/36463
Commit-Queue: Alex Glaznev <glaznev@webrtc.org>
Reviewed-by: Alex Glaznev <glaznev@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21456}
This commit is contained in:
Alex Glaznev 2017-12-27 23:48:48 +00:00 committed by Commit Bot
parent 16b2a3633d
commit 9e17217736

View File

@ -201,16 +201,8 @@ public class WebRtcAudioRecord {
int bufferSizeInBytes = Math.max(BUFFER_SIZE_FACTOR * minBufferSize, byteBuffer.capacity());
Logging.d(TAG, "bufferSizeInBytes: " + bufferSizeInBytes);
try {
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, sampleRate, channelConfig,
AudioFormat.ENCODING_PCM_16BIT, bufferSizeInBytes);
}
audioRecord = new AudioRecord(audioSource, sampleRate, channelConfig,
AudioFormat.ENCODING_PCM_16BIT, bufferSizeInBytes);
} catch (IllegalArgumentException e) {
reportWebRtcAudioRecordInitError("AudioRecord ctor error: " + e.getMessage());
releaseAudioResources();
@ -284,22 +276,6 @@ public class WebRtcAudioRecord {
}
}
// Creates an AudioRecord instance using AudioRecord.Builder.
@TargetApi(23)
private AudioRecord createAudioRecordOnMarshmallowOrHigher(
int sampleRateInHz, int channelConfig, int bufferSizeInBytes) {
Logging.d(TAG, "createAudioRecordOnMarshmallowOrHigher");
return new AudioRecord.Builder()
.setAudioSource(audioSource)
.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) {