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

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

Issue 1323243012: Avoids crashes in Java-based InitRecording() (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Feedback from magjed@ Created 5 years, 3 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 f81bab3e93b3e4676e9c8959e3e310b7a3199002..990c3d46b17f5886697bf39c16fe344df8944b92 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
@@ -145,6 +145,10 @@ class WebRtcAudioRecord {
Loge("RECORD_AUDIO permission is missing");
return -1;
}
+ if (audioRecord != null) {
+ Loge("InitRecording() called twice without StopRecording()");
+ return -1;
+ }
final int bytesPerFrame = channels * (BITS_PER_SAMPLE / 8);
final int framesPerBuffer = sampleRate / BUFFERS_PER_SECOND;
byteBuffer = ByteBuffer.allocateDirect(bytesPerFrame * framesPerBuffer);
@@ -164,11 +168,6 @@ class WebRtcAudioRecord {
AudioFormat.ENCODING_PCM_16BIT);
Logd("AudioRecord.getMinBufferSize: " + minBufferSize);
- if (aec != null) {
- aec.release();
- aec = null;
- }
- assertTrue(audioRecord == null);
int bufferSizeInBytes = Math.max(byteBuffer.capacity(), minBufferSize);
Logd("bufferSizeInBytes: " + bufferSizeInBytes);
@@ -180,10 +179,14 @@ class WebRtcAudioRecord {
bufferSizeInBytes);
} catch (IllegalArgumentException e) {
- Logd(e.getMessage());
+ Loge(e.getMessage());
+ return -1;
+ }
+ if (audioRecord == null ||
+ audioRecord.getState() != AudioRecord.STATE_INITIALIZED) {
+ Loge("Failed to create a new AudioRecord instance");
return -1;
}
- assertTrue(audioRecord.getState() == AudioRecord.STATE_INITIALIZED);
Logd("AudioRecord " +
"session ID: " + audioRecord.getAudioSessionId() + ", " +
« 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