fetch local description on its own executor

This commit is contained in:
Daniel Gultsch 2023-10-02 11:03:08 +02:00
parent 0dca7f8a5a
commit 09993b8319
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
2 changed files with 33 additions and 29 deletions

View file

@ -2354,7 +2354,7 @@ public class JingleRtpConnection extends AbstractJingleConnection
private void restartIce() { private void restartIce() {
this.stateHistory.clear(); this.stateHistory.clear();
this.webRTCWrapper.restartIce(); this.webRTCWrapper.restartIceAsync();
} }
@Override @Override

View file

@ -14,6 +14,10 @@ import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture; import com.google.common.util.concurrent.SettableFuture;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.services.AppRTCAudioManager;
import eu.siacs.conversations.services.XmppConnectionService;
import org.webrtc.AudioSource; import org.webrtc.AudioSource;
import org.webrtc.AudioTrack; import org.webrtc.AudioTrack;
import org.webrtc.CandidatePairChangeEvent; import org.webrtc.CandidatePairChangeEvent;
@ -38,7 +42,6 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.Queue;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -46,16 +49,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.services.AppRTCAudioManager;
import eu.siacs.conversations.services.XmppConnectionService;
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
public class WebRTCWrapper { public class WebRTCWrapper {
private static final String EXTENDED_LOGGING_TAG = WebRTCWrapper.class.getSimpleName(); private static final String EXTENDED_LOGGING_TAG = WebRTCWrapper.class.getSimpleName();
private final ExecutorService executorService = Executors.newSingleThreadExecutor(); private final ExecutorService executorService = Executors.newSingleThreadExecutor();
private final ExecutorService localDescriptionExecutorService =
Executors.newSingleThreadExecutor();
private static final Set<String> HARDWARE_AEC_BLACKLIST = private static final Set<String> HARDWARE_AEC_BLACKLIST =
new ImmutableSet.Builder<String>() new ImmutableSet.Builder<String>()
@ -260,7 +261,8 @@ public class WebRTCWrapper {
Preconditions.checkNotNull(media); Preconditions.checkNotNull(media);
Preconditions.checkArgument( Preconditions.checkArgument(
media.size() > 0, "media can not be empty when initializing peer connection"); media.size() > 0, "media can not be empty when initializing peer connection");
final boolean setUseHardwareAcousticEchoCanceler = !HARDWARE_AEC_BLACKLIST.contains(Build.MODEL); final boolean setUseHardwareAcousticEchoCanceler =
!HARDWARE_AEC_BLACKLIST.contains(Build.MODEL);
Log.d( Log.d(
Config.LOGTAG, Config.LOGTAG,
String.format( String.format(
@ -412,21 +414,20 @@ public class WebRTCWrapper {
requirePeerConnection().setConfiguration(buildConfiguration(iceServers)); requirePeerConnection().setConfiguration(buildConfiguration(iceServers));
} }
void restartIce() { void restartIceAsync() {
executorService.execute( this.execute(this::restartIce);
() -> { }
private void restartIce() {
final PeerConnection peerConnection; final PeerConnection peerConnection;
try { try {
peerConnection = requirePeerConnection(); peerConnection = requirePeerConnection();
} catch (final PeerConnectionNotInitialized e) { } catch (final PeerConnectionNotInitialized e) {
Log.w( Log.w(EXTENDED_LOGGING_TAG, "PeerConnection vanished before we could execute restart");
EXTENDED_LOGGING_TAG,
"PeerConnection vanished before we could execute restart");
return; return;
} }
setIsReadyToReceiveIceCandidates(false); setIsReadyToReceiveIceCandidates(false);
peerConnection.restartIce(); peerConnection.restartIce();
});
} }
public void setIsReadyToReceiveIceCandidates(final boolean ready) { public void setIsReadyToReceiveIceCandidates(final boolean ready) {
@ -587,12 +588,15 @@ public class WebRTCWrapper {
} }
private ListenableFuture<SessionDescription> getLocalDescriptionFuture() { private ListenableFuture<SessionDescription> getLocalDescriptionFuture() {
return Futures.submit(() -> { return Futures.submit(
final SessionDescription description = requirePeerConnection().getLocalDescription(); () -> {
final SessionDescription description =
requirePeerConnection().getLocalDescription();
Log.d(EXTENDED_LOGGING_TAG, "local description:"); Log.d(EXTENDED_LOGGING_TAG, "local description:");
logDescription(description); logDescription(description);
return description; return description;
},executorService); },
localDescriptionExecutorService);
} }
public static void logDescription(final SessionDescription sessionDescription) { public static void logDescription(final SessionDescription sessionDescription) {
@ -703,7 +707,7 @@ public class WebRTCWrapper {
} }
void execute(final Runnable command) { void execute(final Runnable command) {
executorService.execute(command); this.executorService.execute(command);
} }
public void switchSpeakerPhonePreference(AppRTCAudioManager.SpeakerPhonePreference preference) { public void switchSpeakerPhonePreference(AppRTCAudioManager.SpeakerPhonePreference preference) {