From 333f509e5354408095505b4a1dcd3da104492892 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 29 Apr 2020 09:10:15 +0200 Subject: [PATCH] =?UTF-8?q?synchronize=20public=20WebRTCWrapper=20methods?= =?UTF-8?q?=20so=20closes=20don=E2=80=99t=20race?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xmpp/jingle/WebRTCWrapper.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java index ffbd8cf70..bb5c1ea24 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java @@ -158,7 +158,7 @@ public class WebRTCWrapper { private EglBase eglBase = null; private CapturerChoice capturerChoice; - public WebRTCWrapper(final EventCallback eventCallback) { + WebRTCWrapper(final EventCallback eventCallback) { this.eventCallback = eventCallback; } @@ -175,7 +175,7 @@ public class WebRTCWrapper { }); } - public void initializePeerConnection(final Set media, final List iceServers) throws InitializationException { + synchronized void initializePeerConnection(final Set media, final List iceServers) throws InitializationException { Preconditions.checkState(this.eglBase != null); Preconditions.checkNotNull(media); Preconditions.checkArgument(media.size() > 0, "media can not be empty when initializing peer connection"); @@ -224,7 +224,7 @@ public class WebRTCWrapper { this.peerConnection = peerConnection; } - public void close() { + synchronized void close() { final PeerConnection peerConnection = this.peerConnection; final CapturerChoice capturerChoice = this.capturerChoice; final AppRTCAudioManager audioManager = this.appRTCAudioManager; @@ -259,7 +259,7 @@ public class WebRTCWrapper { } } - void verifyClosed() { + synchronized void verifyClosed() { if (this.peerConnection != null || this.eglBase != null || this.localVideoTrack != null @@ -286,7 +286,7 @@ public class WebRTCWrapper { audioTrack.setEnabled(enabled); } - public boolean isVideoEnabled() { + boolean isVideoEnabled() { final VideoTrack videoTrack = this.localVideoTrack; if (videoTrack == null) { throw new IllegalStateException("Local video track does not exist"); @@ -294,7 +294,7 @@ public class WebRTCWrapper { return videoTrack.enabled(); } - public void setVideoEnabled(final boolean enabled) { + void setVideoEnabled(final boolean enabled) { final VideoTrack videoTrack = this.localVideoTrack; if (videoTrack == null) { throw new IllegalStateException("Local video track does not exist"); @@ -302,7 +302,7 @@ public class WebRTCWrapper { videoTrack.setEnabled(enabled); } - public ListenableFuture createOffer() { + ListenableFuture createOffer() { return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> { final SettableFuture future = SettableFuture.create(); peerConnection.createOffer(new CreateSdpObserver() { @@ -313,7 +313,6 @@ public class WebRTCWrapper { @Override public void onCreateFailure(String s) { - Log.d(Config.LOGTAG, "create failure" + s); future.setException(new IllegalStateException("Unable to create offer: " + s)); } }, new MediaConstraints()); @@ -321,7 +320,7 @@ public class WebRTCWrapper { }, MoreExecutors.directExecutor()); } - public ListenableFuture createAnswer() { + ListenableFuture createAnswer() { return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> { final SettableFuture future = SettableFuture.create(); peerConnection.createAnswer(new CreateSdpObserver() { @@ -339,7 +338,7 @@ public class WebRTCWrapper { }, MoreExecutors.directExecutor()); } - public ListenableFuture setLocalDescription(final SessionDescription sessionDescription) { + ListenableFuture setLocalDescription(final SessionDescription sessionDescription) { Log.d(EXTENDED_LOGGING_TAG, "setting local description:"); for (final String line : sessionDescription.description.split(eu.siacs.conversations.xmpp.jingle.SessionDescription.LINE_DIVIDER)) { Log.d(EXTENDED_LOGGING_TAG, line); @@ -363,7 +362,7 @@ public class WebRTCWrapper { }, MoreExecutors.directExecutor()); } - public ListenableFuture setRemoteDescription(final SessionDescription sessionDescription) { + ListenableFuture setRemoteDescription(final SessionDescription sessionDescription) { Log.d(EXTENDED_LOGGING_TAG, "setting remote description:"); for (final String line : sessionDescription.description.split(eu.siacs.conversations.xmpp.jingle.SessionDescription.LINE_DIVIDER)) { Log.d(EXTENDED_LOGGING_TAG, line); @@ -396,7 +395,7 @@ public class WebRTCWrapper { } } - public void addIceCandidate(IceCandidate iceCandidate) { + void addIceCandidate(IceCandidate iceCandidate) { requirePeerConnection().addIceCandidate(iceCandidate); } @@ -447,11 +446,11 @@ public class WebRTCWrapper { return this.eglBase.getEglBaseContext(); } - public Optional getLocalVideoTrack() { + Optional getLocalVideoTrack() { return Optional.fromNullable(this.localVideoTrack); } - public Optional getRemoteVideoTrack() { + Optional getRemoteVideoTrack() { return Optional.fromNullable(this.remoteVideoTrack); } @@ -471,7 +470,7 @@ public class WebRTCWrapper { return context; } - public AppRTCAudioManager getAudioManager() { + AppRTCAudioManager getAudioManager() { return appRTCAudioManager; } @@ -512,7 +511,7 @@ public class WebRTCWrapper { } } - public static class InitializationException extends Exception { + static class InitializationException extends Exception { private InitializationException(String message) { super(message); @@ -523,12 +522,12 @@ public class WebRTCWrapper { private final CameraVideoCapturer cameraVideoCapturer; private final CameraEnumerationAndroid.CaptureFormat captureFormat; - public CapturerChoice(CameraVideoCapturer cameraVideoCapturer, CameraEnumerationAndroid.CaptureFormat captureFormat) { + CapturerChoice(CameraVideoCapturer cameraVideoCapturer, CameraEnumerationAndroid.CaptureFormat captureFormat) { this.cameraVideoCapturer = cameraVideoCapturer; this.captureFormat = captureFormat; } - public int getFrameRate() { + int getFrameRate() { return Math.max(captureFormat.framerate.min, Math.min(CAPTURING_MAX_FRAME_RATE, captureFormat.framerate.max)); } }