From c3d0da097cd5040c6108d099f0291b3e138db0cb Mon Sep 17 00:00:00 2001 From: henrika Date: Fri, 22 Sep 2017 13:16:31 +0200 Subject: [PATCH] Avoids crash in AudioTrack when audio starts in background mode TBR=noahric Bug: NONE Change-Id: Ie528b36cc03d53b15fbfd56a386309a8c3adce73 Reviewed-on: https://webrtc-review.googlesource.com/2681 Commit-Queue: Henrik Andreassson Reviewed-by: Henrik Andreassson Cr-Commit-Position: refs/heads/master@{#19927} --- .../src/org/webrtc/voiceengine/WebRtcAudioTrack.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java b/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java index ab55567b3c..148632b29b 100644 --- a/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java +++ b/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java @@ -120,12 +120,19 @@ public class WebRtcAudioTrack { // This priming will avoid an immediate underrun, but is not required. // TODO(henrika): initial tests have shown that priming is not required. audioTrack.play(); - assertTrue(audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING); } catch (IllegalStateException e) { reportWebRtcAudioTrackStartError("AudioTrack.play failed: " + e.getMessage()); releaseAudioResources(); return; } + // We have seen reports that AudioTrack.play() can sometimes start in a + // paued mode (e.g. when application is in background mode). + // TODO(henrika): consider calling reportWebRtcAudioTrackStartError() + // and release audio resources here as well. For now, let the thread start + // and hope that the audio session can be restored later. + if (audioTrack.getPlayState() != AudioTrack.PLAYSTATE_PLAYING) { + Logging.w(TAG, "AudioTrack failed to enter playing state."); + } // Fixed size in bytes of each 10ms block of audio data that we ask for // using callbacks to the native WebRTC client.