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

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

Issue 2574053003: Improves release of allocated audio resources on Android (Closed)
Patch Set: restored one error check Created 4 years 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 | « webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java ('k') | 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/WebRtcAudioTrack.java
diff --git a/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java b/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java
index 5ea647a44bcfeb7d0040061c109f5bddf8387817..7c3a672576ebdce5e81af009139e64c342209870 100644
--- a/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java
+++ b/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java
@@ -77,6 +77,7 @@ public class WebRtcAudioTrack {
assertTrue(audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING);
} catch (IllegalStateException e) {
Logging.e(TAG, "AudioTrack.play failed: " + e.getMessage());
+ releaseAudioResources();
return;
}
@@ -202,14 +203,16 @@ public class WebRtcAudioTrack {
AudioFormat.ENCODING_PCM_16BIT, minBufferSizeInBytes, AudioTrack.MODE_STREAM);
} catch (IllegalArgumentException e) {
Logging.d(TAG, e.getMessage());
+ releaseAudioResources();
return false;
}
// It can happen that an AudioTrack is created but it was not successfully
// initialized upon creation. Seems to be the case e.g. when the maximum
// number of globally available audio tracks is exceeded.
- if (audioTrack.getState() != AudioTrack.STATE_INITIALIZED) {
+ if (audioTrack == null || audioTrack.getState() != AudioTrack.STATE_INITIALIZED) {
Logging.e(TAG, "Initialization of audio track failed.");
+ releaseAudioResources();
return false;
}
logMainParameters();
@@ -222,7 +225,7 @@ public class WebRtcAudioTrack {
assertTrue(audioTrack != null);
assertTrue(audioThread == null);
if (audioTrack.getState() != AudioTrack.STATE_INITIALIZED) {
- Logging.e(TAG, "Audio track is not successfully initialized.");
+ Logging.e(TAG, "AudioTrack instance is not successfully initialized.");
return false;
}
audioThread = new AudioTrackThread("AudioTrackJavaThread");
@@ -236,10 +239,7 @@ public class WebRtcAudioTrack {
logUnderrunCount();
audioThread.joinThread();
audioThread = null;
- if (audioTrack != null) {
- audioTrack.release();
- audioTrack = null;
- }
+ releaseAudioResources();
return true;
}
@@ -330,4 +330,12 @@ public class WebRtcAudioTrack {
Logging.w(TAG, "setSpeakerMute(" + mute + ")");
speakerMute = mute;
}
+
+ // Releases the native AudioTrack resources.
+ private void releaseAudioResources() {
+ if (audioTrack != null) {
+ audioTrack.release();
+ audioTrack = null;
+ }
+ }
}
« no previous file with comments | « webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698