revert webrtc for f-droid
This commit is contained in:
parent
69cc5b2922
commit
69cf6d946e
1 changed files with 93 additions and 93 deletions
|
@ -17,7 +17,6 @@ import com.google.common.util.concurrent.SettableFuture;
|
|||
|
||||
import org.webrtc.AudioSource;
|
||||
import org.webrtc.AudioTrack;
|
||||
import org.webrtc.Camera1Enumerator;
|
||||
import org.webrtc.Camera2Enumerator;
|
||||
import org.webrtc.CameraEnumerationAndroid;
|
||||
import org.webrtc.CameraEnumerator;
|
||||
|
@ -45,8 +44,13 @@ import org.webrtc.voiceengine.WebRtcAudioEffects;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -59,8 +63,9 @@ public class WebRTCWrapper {
|
|||
|
||||
private static final String EXTENDED_LOGGING_TAG = WebRTCWrapper.class.getSimpleName();
|
||||
|
||||
//we should probably keep this in sync with: https://github.com/signalapp/Signal-Android/blob/master/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java#L296
|
||||
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
|
||||
//we should probably keep this in sync with: https://github.com/signalapp/Signal-Android/blob/master/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java#L296
|
||||
private static final Set<String> HARDWARE_AEC_BLACKLIST = new ImmutableSet.Builder<String>()
|
||||
.add("Pixel")
|
||||
.add("Pixel XL")
|
||||
|
@ -74,15 +79,14 @@ public class WebRTCWrapper {
|
|||
.add("Redmi Note 5")
|
||||
.add("FP2") // Fairphone FP2
|
||||
.add("MI 5")
|
||||
.add("GT-I9515") // Samsung Galaxy S4 Value Edition (jfvelte)
|
||||
.add("GT-I9515L") // Samsung Galaxy S4 Value Edition (jfvelte)
|
||||
.add("GT-I9505") // Samsung Galaxy S4 (jfltexx)
|
||||
.build();
|
||||
|
||||
private static final int CAPTURING_RESOLUTION = 1920;
|
||||
private static final int CAPTURING_MAX_FRAME_RATE = 30;
|
||||
|
||||
private final EventCallback eventCallback;
|
||||
private final AtomicBoolean readyToReceivedIceCandidates = new AtomicBoolean(false);
|
||||
private final Queue<IceCandidate> iceCandidates = new LinkedList<>();
|
||||
private final AppRTCAudioManager.AudioManagerEvents audioManagerEvents = new AppRTCAudioManager.AudioManagerEvents() {
|
||||
@Override
|
||||
public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) {
|
||||
|
@ -102,13 +106,13 @@ public class WebRTCWrapper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionChange(PeerConnection.PeerConnectionState newState) {
|
||||
public void onConnectionChange(final PeerConnection.PeerConnectionState newState) {
|
||||
eventCallback.onConnectionChange(newState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) {
|
||||
|
||||
Log.d(EXTENDED_LOGGING_TAG, "onIceConnectionChange(" + iceConnectionState + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -129,7 +133,11 @@ public class WebRTCWrapper {
|
|||
|
||||
@Override
|
||||
public void onIceCandidate(IceCandidate iceCandidate) {
|
||||
eventCallback.onIceCandidate(iceCandidate);
|
||||
if (readyToReceivedIceCandidates.get()) {
|
||||
eventCallback.onIceCandidate(iceCandidate);
|
||||
} else {
|
||||
iceCandidates.add(iceCandidate);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -140,13 +148,6 @@ public class WebRTCWrapper {
|
|||
@Override
|
||||
public void onAddStream(MediaStream mediaStream) {
|
||||
Log.d(EXTENDED_LOGGING_TAG, "onAddStream(numAudioTracks=" + mediaStream.audioTracks.size() + ",numVideoTracks=" + mediaStream.videoTracks.size() + ")");
|
||||
final List<VideoTrack> videoTracks = mediaStream.videoTracks;
|
||||
if (videoTracks.size() > 0) {
|
||||
remoteVideoTrack = videoTracks.get(0);
|
||||
Log.d(Config.LOGTAG, "remote video track enabled?=" + remoteVideoTrack.enabled());
|
||||
} else {
|
||||
Log.d(Config.LOGTAG, "no remote video tracks found");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -161,17 +162,20 @@ public class WebRTCWrapper {
|
|||
|
||||
@Override
|
||||
public void onRenegotiationNeeded() {
|
||||
|
||||
Log.d(EXTENDED_LOGGING_TAG, "onRenegotiationNeeded()");
|
||||
final PeerConnection.PeerConnectionState currentState = peerConnection == null ? null : peerConnection.connectionState();
|
||||
if (currentState != null && currentState != PeerConnection.PeerConnectionState.NEW) {
|
||||
eventCallback.onRenegotiationNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddTrack(RtpReceiver rtpReceiver, MediaStream[] mediaStreams) {
|
||||
final MediaStreamTrack track = rtpReceiver.track();
|
||||
Log.d(EXTENDED_LOGGING_TAG, "onAddTrack(kind=" + (track == null ? "null" : track.kind()) + ",numMediaStreams=" + mediaStreams.length + ")");
|
||||
if (track != null) {
|
||||
Log.d(EXTENDED_LOGGING_TAG,"onAddTrack(class="+track.getClass().getName()+")");
|
||||
if (track instanceof VideoTrack) {
|
||||
remoteVideoTrack = (VideoTrack) track;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -263,10 +267,7 @@ public class WebRTCWrapper {
|
|||
.createPeerConnectionFactory();
|
||||
|
||||
|
||||
final PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
|
||||
rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.DISABLED; //XEP-0176 doesn't support tcp
|
||||
rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
|
||||
rtcConfig.sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN;
|
||||
final PeerConnection.RTCConfiguration rtcConfig = buildConfiguration(iceServers);
|
||||
final PeerConnection peerConnection = peerConnectionFactory.createPeerConnection(rtcConfig, peerConnectionObserver);
|
||||
if (peerConnection == null) {
|
||||
throw new InitializationException("Unable to create PeerConnection");
|
||||
|
@ -300,6 +301,31 @@ public class WebRTCWrapper {
|
|||
this.peerConnection = peerConnection;
|
||||
}
|
||||
|
||||
private static PeerConnection.RTCConfiguration buildConfiguration(final List<PeerConnection.IceServer> iceServers) {
|
||||
final PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
|
||||
rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.DISABLED; //XEP-0176 doesn't support tcp
|
||||
rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
|
||||
rtcConfig.sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN;
|
||||
rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.NEGOTIATE;
|
||||
rtcConfig.enableImplicitRollback = true;
|
||||
return rtcConfig;
|
||||
}
|
||||
|
||||
void reconfigurePeerConnection(final List<PeerConnection.IceServer> iceServers) {
|
||||
requirePeerConnection().setConfiguration(buildConfiguration(iceServers));
|
||||
}
|
||||
|
||||
void restartIce() {
|
||||
executorService.execute(() -> requirePeerConnection().restartIce());
|
||||
}
|
||||
|
||||
public void setIsReadyToReceiveIceCandidates(final boolean ready) {
|
||||
readyToReceivedIceCandidates.set(ready);
|
||||
while (ready && iceCandidates.peek() != null) {
|
||||
eventCallback.onIceCandidate(iceCandidates.poll());
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void close() {
|
||||
final PeerConnection peerConnection = this.peerConnection;
|
||||
final CapturerChoice capturerChoice = this.capturerChoice;
|
||||
|
@ -414,70 +440,36 @@ public class WebRTCWrapper {
|
|||
videoTrack.setEnabled(enabled);
|
||||
}
|
||||
|
||||
ListenableFuture<SessionDescription> createOffer() {
|
||||
synchronized ListenableFuture<SessionDescription> setLocalDescription() {
|
||||
return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
|
||||
final SettableFuture<SessionDescription> future = SettableFuture.create();
|
||||
peerConnection.createOffer(new CreateSdpObserver() {
|
||||
@Override
|
||||
public void onCreateSuccess(SessionDescription sessionDescription) {
|
||||
future.set(sessionDescription);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateFailure(String s) {
|
||||
future.setException(new IllegalStateException("Unable to create offer: " + s));
|
||||
}
|
||||
}, new MediaConstraints());
|
||||
return future;
|
||||
}, MoreExecutors.directExecutor());
|
||||
}
|
||||
|
||||
ListenableFuture<SessionDescription> createAnswer() {
|
||||
return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
|
||||
final SettableFuture<SessionDescription> future = SettableFuture.create();
|
||||
peerConnection.createAnswer(new CreateSdpObserver() {
|
||||
@Override
|
||||
public void onCreateSuccess(SessionDescription sessionDescription) {
|
||||
future.set(sessionDescription);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateFailure(String s) {
|
||||
future.setException(new IllegalStateException("Unable to create answer: " + s));
|
||||
}
|
||||
}, new MediaConstraints());
|
||||
return future;
|
||||
}, MoreExecutors.directExecutor());
|
||||
}
|
||||
|
||||
ListenableFuture<Void> 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);
|
||||
}
|
||||
return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
|
||||
final SettableFuture<Void> future = SettableFuture.create();
|
||||
peerConnection.setLocalDescription(new SetSdpObserver() {
|
||||
@Override
|
||||
public void onSetSuccess() {
|
||||
future.set(null);
|
||||
final SessionDescription description = peerConnection.getLocalDescription();
|
||||
Log.d(EXTENDED_LOGGING_TAG, "set local description:");
|
||||
logDescription(description);
|
||||
future.set(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetFailure(final String s) {
|
||||
future.setException(new IllegalArgumentException("unable to set local session description: " + s));
|
||||
|
||||
public void onSetFailure(final String message) {
|
||||
future.setException(new FailureToSetDescriptionException(message));
|
||||
}
|
||||
}, sessionDescription);
|
||||
});
|
||||
return future;
|
||||
}, MoreExecutors.directExecutor());
|
||||
}
|
||||
|
||||
ListenableFuture<Void> setRemoteDescription(final SessionDescription sessionDescription) {
|
||||
Log.d(EXTENDED_LOGGING_TAG, "setting remote description:");
|
||||
private static void logDescription(final SessionDescription sessionDescription) {
|
||||
for (final String line : sessionDescription.description.split(eu.siacs.conversations.xmpp.jingle.SessionDescription.LINE_DIVIDER)) {
|
||||
Log.d(EXTENDED_LOGGING_TAG, line);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized ListenableFuture<Void> setRemoteDescription(final SessionDescription sessionDescription) {
|
||||
Log.d(EXTENDED_LOGGING_TAG, "setting remote description:");
|
||||
logDescription(sessionDescription);
|
||||
return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
|
||||
final SettableFuture<Void> future = SettableFuture.create();
|
||||
peerConnection.setRemoteDescription(new SetSdpObserver() {
|
||||
|
@ -487,9 +479,8 @@ public class WebRTCWrapper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSetFailure(String s) {
|
||||
future.setException(new IllegalArgumentException("unable to set remote session description: " + s));
|
||||
|
||||
public void onSetFailure(final String message) {
|
||||
future.setException(new FailureToSetDescriptionException(message));
|
||||
}
|
||||
}, sessionDescription);
|
||||
return future;
|
||||
|
@ -500,26 +491,26 @@ public class WebRTCWrapper {
|
|||
private ListenableFuture<PeerConnection> getPeerConnectionFuture() {
|
||||
final PeerConnection peerConnection = this.peerConnection;
|
||||
if (peerConnection == null) {
|
||||
return Futures.immediateFailedFuture(new IllegalStateException("initialize PeerConnection first"));
|
||||
return Futures.immediateFailedFuture(new PeerConnectionNotInitialized());
|
||||
} else {
|
||||
return Futures.immediateFuture(peerConnection);
|
||||
}
|
||||
}
|
||||
|
||||
private PeerConnection requirePeerConnection() {
|
||||
final PeerConnection peerConnection = this.peerConnection;
|
||||
if (peerConnection == null) {
|
||||
throw new PeerConnectionNotInitialized();
|
||||
}
|
||||
return peerConnection;
|
||||
}
|
||||
|
||||
void addIceCandidate(IceCandidate iceCandidate) {
|
||||
requirePeerConnection().addIceCandidate(iceCandidate);
|
||||
}
|
||||
|
||||
private CameraEnumerator getCameraEnumerator() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
return new Camera2Enumerator(requireContext());
|
||||
} else {
|
||||
return new Camera1Enumerator();
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<CapturerChoice> getVideoCapturer() {
|
||||
final CameraEnumerator enumerator = getCameraEnumerator();
|
||||
final CameraEnumerator enumerator = new Camera2Enumerator(requireContext());
|
||||
final Set<String> deviceNames = ImmutableSet.copyOf(enumerator.getDeviceNames());
|
||||
for (final String deviceName : deviceNames) {
|
||||
if (isFrontFacing(enumerator, deviceName)) {
|
||||
|
@ -538,10 +529,15 @@ public class WebRTCWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
public PeerConnection.PeerConnectionState getState() {
|
||||
PeerConnection.PeerConnectionState getState() {
|
||||
return requirePeerConnection().connectionState();
|
||||
}
|
||||
|
||||
public PeerConnection.SignalingState getSignalingState() {
|
||||
return requirePeerConnection().signalingState();
|
||||
}
|
||||
|
||||
|
||||
EglBase.Context getEglBaseContext() {
|
||||
return this.eglBase.getEglBaseContext();
|
||||
}
|
||||
|
@ -554,14 +550,6 @@ public class WebRTCWrapper {
|
|||
return Optional.fromNullable(this.remoteVideoTrack);
|
||||
}
|
||||
|
||||
private PeerConnection requirePeerConnection() {
|
||||
final PeerConnection peerConnection = this.peerConnection;
|
||||
if (peerConnection == null) {
|
||||
throw new PeerConnectionNotInitialized();
|
||||
}
|
||||
return peerConnection;
|
||||
}
|
||||
|
||||
private Context requireContext() {
|
||||
final Context context = this.context;
|
||||
if (context == null) {
|
||||
|
@ -574,12 +562,18 @@ public class WebRTCWrapper {
|
|||
return appRTCAudioManager;
|
||||
}
|
||||
|
||||
void execute(final Runnable command) {
|
||||
executorService.execute(command);
|
||||
}
|
||||
|
||||
public interface EventCallback {
|
||||
void onIceCandidate(IceCandidate iceCandidate);
|
||||
|
||||
void onConnectionChange(PeerConnection.PeerConnectionState newState);
|
||||
|
||||
void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices);
|
||||
|
||||
void onRenegotiationNeeded();
|
||||
}
|
||||
|
||||
private static abstract class SetSdpObserver implements SdpObserver {
|
||||
|
@ -630,6 +624,12 @@ public class WebRTCWrapper {
|
|||
|
||||
}
|
||||
|
||||
private static class FailureToSetDescriptionException extends IllegalArgumentException {
|
||||
public FailureToSetDescriptionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
private static class CapturerChoice {
|
||||
private final CameraVideoCapturer cameraVideoCapturer;
|
||||
private final CameraEnumerationAndroid.CaptureFormat captureFormat;
|
||||
|
|
Loading…
Add table
Reference in a new issue