Skip to content

Commit 7ddfc43

Browse files
authored
android: Allow for skipping checking the audio playstate if needed (#129)
Pausing/stopping the audio track can lead to a race condition against the AudioTrackThread due to this assert. Normally this is fine since directly pausing/stopping isn't possible, but user is using reflection to workaround another audio issue (muted participants still have a sending audio stream which keeps the audio alive, affecting global sound if in the background). Not a full fix, as would like to manually control the audio track directly (needs a bigger fix to handle proper synchronization before allowing public access), but this will work through reflection (user takes responsibility for usage).
1 parent a5b6625 commit 7ddfc43

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sdk/android/src/java/org/webrtc/audio/WebRtcAudioTrack.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class WebRtcAudioTrack {
8080
private final @Nullable AudioTrackStateCallback stateCallback;
8181
private final @Nullable PlaybackSamplesReadyCallback audioSamplesReadyCallback;
8282

83+
private boolean checkPlayState = true;
84+
8385
/**
8486
* Audio thread which keeps calling AudioTrack.write() to stream audio.
8587
* Data is periodically acquired from the native WebRTC layer using the
@@ -99,7 +101,10 @@ public AudioTrackThread(String name) {
99101
public void run() {
100102
Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO);
101103
Logging.d(TAG, "AudioTrackThread" + WebRtcAudioUtils.getThreadInfo());
102-
assertTrue(audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING);
104+
105+
if (checkPlayState) {
106+
assertTrue(audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING);
107+
}
103108

104109
// Audio playout has started and the client is informed about it.
105110
doAudioTrackStateCallback(AUDIO_TRACK_START);

0 commit comments

Comments
 (0)