From e70b6eec98069a67da47686972056050df87049b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 3 May 2020 11:08:11 +0200 Subject: [PATCH] do not mirror back camera. fixes #3693 --- .../conversations/ui/RtpSessionActivity.java | 10 +++++----- .../xmpp/jingle/JingleRtpConnection.java | 6 +++++- .../xmpp/jingle/WebRTCWrapper.java | 20 +++++++++++++++---- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index 33c7913e7..e7f4d9e92 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -639,14 +639,14 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe } private void switchCamera(final View view) { - Futures.addCallback(requireRtpConnection().switchCamera(), new FutureCallback() { + Futures.addCallback(requireRtpConnection().switchCamera(), new FutureCallback() { @Override - public void onSuccess(@NullableDecl Void result) { - + public void onSuccess(@NullableDecl Boolean isFrontCamera) { + binding.localVideo.setMirror(isFrontCamera); } @Override - public void onFailure(final Throwable throwable) { + public void onFailure(@NonNull final Throwable throwable) { Log.d(Config.LOGTAG,"could not switch camera", Throwables.getRootCause(throwable)); Toast.makeText(RtpSessionActivity.this, R.string.could_not_switch_camera, Toast.LENGTH_LONG).show(); } @@ -715,7 +715,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe ensureSurfaceViewRendererIsSetup(binding.localVideo); //paint local view over remote view binding.localVideo.setZOrderMediaOverlay(true); - binding.localVideo.setMirror(true); + binding.localVideo.setMirror(requireRtpConnection().isFrontCamera()); localVideoTrack.get().addSink(binding.localVideo); } else { binding.localVideo.setVisibility(View.GONE); diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index 9aeac835b..5a8c7d6d2 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -1043,7 +1043,11 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web return webRTCWrapper.isCameraSwitchable(); } - public ListenableFuture switchCamera() { + public boolean isFrontCamera() { + return webRTCWrapper.isFrontCamera(); + } + + public ListenableFuture switchCamera() { return webRTCWrapper.switchCamera(); } 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 844ef9db8..78d033996 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java @@ -277,16 +277,22 @@ public class WebRTCWrapper { return capturerChoice != null && capturerChoice.availableCameras.size() > 1; } - ListenableFuture switchCamera() { + boolean isFrontCamera() { + final CapturerChoice capturerChoice = this.capturerChoice; + return capturerChoice == null || capturerChoice.isFrontCamera; + } + + ListenableFuture switchCamera() { final CapturerChoice capturerChoice = this.capturerChoice; if (capturerChoice == null) { return Futures.immediateFailedFuture(new IllegalStateException("CameraCapturer has not been initialized")); } - final SettableFuture future = SettableFuture.create(); + final SettableFuture future = SettableFuture.create(); capturerChoice.cameraVideoCapturer.switchCamera(new CameraVideoCapturer.CameraSwitchHandler() { @Override public void onCameraSwitchDone(boolean isFrontCamera) { - future.set(null); + capturerChoice.isFrontCamera = isFrontCamera; + future.set(isFrontCamera); } @Override @@ -438,7 +444,12 @@ public class WebRTCWrapper { final Set deviceNames = ImmutableSet.copyOf(enumerator.getDeviceNames()); for (final String deviceName : deviceNames) { if (enumerator.isFrontFacing(deviceName)) { - return Optional.fromNullable(of(enumerator, deviceName, deviceNames)); + final CapturerChoice capturerChoice = of(enumerator, deviceName, deviceNames); + if (capturerChoice == null) { + return Optional.absent(); + } + capturerChoice.isFrontCamera = true; + return Optional.of(capturerChoice); } } if (deviceNames.size() == 0) { @@ -548,6 +559,7 @@ public class WebRTCWrapper { private final CameraVideoCapturer cameraVideoCapturer; private final CameraEnumerationAndroid.CaptureFormat captureFormat; private final Set availableCameras; + private boolean isFrontCamera = false; CapturerChoice(CameraVideoCapturer cameraVideoCapturer, CameraEnumerationAndroid.CaptureFormat captureFormat, Set cameras) { this.cameraVideoCapturer = cameraVideoCapturer;