Skip to content

Commit

Permalink
android: Allow for skipping checking the audio playstate if needed (#129
Browse files Browse the repository at this point in the history
)

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).
  • Loading branch information
davidliu authored Jul 9, 2024
1 parent a5b6625 commit 7ddfc43
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sdk/android/src/java/org/webrtc/audio/WebRtcAudioTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class WebRtcAudioTrack {
private final @Nullable AudioTrackStateCallback stateCallback;
private final @Nullable PlaybackSamplesReadyCallback audioSamplesReadyCallback;

private boolean checkPlayState = true;

/**
* Audio thread which keeps calling AudioTrack.write() to stream audio.
* Data is periodically acquired from the native WebRTC layer using the
Expand All @@ -99,7 +101,10 @@ public AudioTrackThread(String name) {
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO);
Logging.d(TAG, "AudioTrackThread" + WebRtcAudioUtils.getThreadInfo());
assertTrue(audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING);

if (checkPlayState) {
assertTrue(audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING);
}

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

0 comments on commit 7ddfc43

Please sign in to comment.