Fixes WebRtcAudioTrack crash while stopping

TBR=henrika@webrtc.org

Bug: webrtc:11248
Change-Id: I5b829b5193d2accdfbf1e06c5317a5cd441c48c3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/163990
Commit-Queue: Alex Narest <alexnarest@google.com>
Commit-Queue: Alex Narest <alexnarest@webrtc.org>
Reviewed-by: Alex Narest <alexnarest@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30133}
This commit is contained in:
Alex Narest
2020-01-02 15:35:23 +01:00
committed by Commit Bot
parent a688d11d96
commit d2fb5f510f

View File

@ -142,20 +142,6 @@ class WebRtcAudioTrack {
// counting number of written frames and subtracting the result from
// audioTrack.getPlaybackHeadPosition().
}
// Stops playing the audio data. Since the instance was created in
// MODE_STREAM mode, audio will stop playing after the last buffer that
// was written has been played.
if (audioTrack != null) {
Logging.d(TAG, "Calling AudioTrack.stop...");
try {
audioTrack.stop();
Logging.d(TAG, "AudioTrack.stop is done.");
doAudioTrackStateCallback(AUDIO_TRACK_STOP);
} catch (IllegalStateException e) {
Logging.e(TAG, "AudioTrack.stop failed: " + e.getMessage());
}
}
}
private int writeBytes(AudioTrack audioTrack, ByteBuffer byteBuffer, int sizeInBytes) {
@ -320,6 +306,16 @@ class WebRtcAudioTrack {
}
Logging.d(TAG, "AudioTrackThread has now been stopped.");
audioThread = null;
if (audioTrack != null) {
Logging.d(TAG, "Calling AudioTrack.stop...");
try {
audioTrack.stop();
Logging.d(TAG, "AudioTrack.stop is done.");
doAudioTrackStateCallback(AUDIO_TRACK_STOP);
} catch (IllegalStateException e) {
Logging.e(TAG, "AudioTrack.stop failed: " + e.getMessage());
}
}
releaseAudioResources();
return true;
}