ignore race condition when toggling fixes #3822

This commit is contained in:
Daniel Gultsch 2020-07-09 19:14:28 +02:00
parent 9ab0fbe48c
commit 6a6c9fb3bf
3 changed files with 19 additions and 10 deletions

View file

@ -910,15 +910,17 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
} }
private void disableMicrophone(View view) { private void disableMicrophone(View view) {
JingleRtpConnection rtpConnection = requireRtpConnection(); final JingleRtpConnection rtpConnection = requireRtpConnection();
rtpConnection.setMicrophoneEnabled(false); if (rtpConnection.setMicrophoneEnabled(false)) {
updateInCallButtonConfiguration(); updateInCallButtonConfiguration();
}
} }
private void enableMicrophone(View view) { private void enableMicrophone(View view) {
JingleRtpConnection rtpConnection = requireRtpConnection(); final JingleRtpConnection rtpConnection = requireRtpConnection();
rtpConnection.setMicrophoneEnabled(true); if (rtpConnection.setMicrophoneEnabled(true)) {
updateInCallButtonConfiguration(); updateInCallButtonConfiguration();
}
} }
private void switchToEarpiece(View view) { private void switchToEarpiece(View view) {

View file

@ -1085,8 +1085,8 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
return webRTCWrapper.isMicrophoneEnabled(); return webRTCWrapper.isMicrophoneEnabled();
} }
public void setMicrophoneEnabled(final boolean enabled) { public boolean setMicrophoneEnabled(final boolean enabled) {
webRTCWrapper.setMicrophoneEnabled(enabled); return webRTCWrapper.setMicrophoneEnabled(enabled);
} }
public boolean isVideoEnabled() { public boolean isVideoEnabled() {

View file

@ -370,12 +370,19 @@ public class WebRTCWrapper {
} }
} }
void setMicrophoneEnabled(final boolean enabled) { boolean setMicrophoneEnabled(final boolean enabled) {
final AudioTrack audioTrack = this.localAudioTrack; final AudioTrack audioTrack = this.localAudioTrack;
if (audioTrack == null) { if (audioTrack == null) {
throw new IllegalStateException("Local audio track does not exist (yet)"); throw new IllegalStateException("Local audio track does not exist (yet)");
} }
audioTrack.setEnabled(enabled); try {
audioTrack.setEnabled(enabled);
return true;
} catch (final IllegalStateException e) {
Log.d(Config.LOGTAG, "unable to toggle microphone", e);
//ignoring race condition in case MediaStreamTrack has been disposed
return false;
}
} }
boolean isVideoEnabled() { boolean isVideoEnabled() {