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,16 +910,18 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
}
private void disableMicrophone(View view) {
JingleRtpConnection rtpConnection = requireRtpConnection();
rtpConnection.setMicrophoneEnabled(false);
final JingleRtpConnection rtpConnection = requireRtpConnection();
if (rtpConnection.setMicrophoneEnabled(false)) {
updateInCallButtonConfiguration();
}
}
private void enableMicrophone(View view) {
JingleRtpConnection rtpConnection = requireRtpConnection();
rtpConnection.setMicrophoneEnabled(true);
final JingleRtpConnection rtpConnection = requireRtpConnection();
if (rtpConnection.setMicrophoneEnabled(true)) {
updateInCallButtonConfiguration();
}
}
private void switchToEarpiece(View view) {
requireRtpConnection().getAudioManager().setDefaultAudioDevice(AppRTCAudioManager.AudioDevice.EARPIECE);

View File

@ -1085,8 +1085,8 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
return webRTCWrapper.isMicrophoneEnabled();
}
public void setMicrophoneEnabled(final boolean enabled) {
webRTCWrapper.setMicrophoneEnabled(enabled);
public boolean setMicrophoneEnabled(final boolean enabled) {
return webRTCWrapper.setMicrophoneEnabled(enabled);
}
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;
if (audioTrack == null) {
throw new IllegalStateException("Local audio track does not exist (yet)");
}
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() {