do not mirror back camera. fixes #3693

This commit is contained in:
Daniel Gultsch 2020-05-03 11:08:11 +02:00
parent 5a5f887229
commit e70b6eec98
3 changed files with 26 additions and 10 deletions

View File

@ -639,14 +639,14 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
}
private void switchCamera(final View view) {
Futures.addCallback(requireRtpConnection().switchCamera(), new FutureCallback<Void>() {
Futures.addCallback(requireRtpConnection().switchCamera(), new FutureCallback<Boolean>() {
@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);

View File

@ -1043,7 +1043,11 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
return webRTCWrapper.isCameraSwitchable();
}
public ListenableFuture<Void> switchCamera() {
public boolean isFrontCamera() {
return webRTCWrapper.isFrontCamera();
}
public ListenableFuture<Boolean> switchCamera() {
return webRTCWrapper.switchCamera();
}

View File

@ -277,16 +277,22 @@ public class WebRTCWrapper {
return capturerChoice != null && capturerChoice.availableCameras.size() > 1;
}
ListenableFuture<Void> switchCamera() {
boolean isFrontCamera() {
final CapturerChoice capturerChoice = this.capturerChoice;
return capturerChoice == null || capturerChoice.isFrontCamera;
}
ListenableFuture<Boolean> switchCamera() {
final CapturerChoice capturerChoice = this.capturerChoice;
if (capturerChoice == null) {
return Futures.immediateFailedFuture(new IllegalStateException("CameraCapturer has not been initialized"));
}
final SettableFuture<Void> future = SettableFuture.create();
final SettableFuture<Boolean> 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<String> 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<String> availableCameras;
private boolean isFrontCamera = false;
CapturerChoice(CameraVideoCapturer cameraVideoCapturer, CameraEnumerationAndroid.CaptureFormat captureFormat, Set<String> cameras) {
this.cameraVideoCapturer = cameraVideoCapturer;