From 8c2aaa06d8f62badb378e86067928b55b2640246 Mon Sep 17 00:00:00 2001 From: Al Lansley Date: Mon, 25 Mar 2024 11:28:03 +1100 Subject: [PATCH] SES-1354 - Video call self viewer not mirrored (#1397) * Fixes #874 * Removed accidentally left in line * Fixed issue - push before cleanup * Cleaned up * Removed cruft --------- Co-authored-by: = <=> Co-authored-by: AL-Session <160798022+AL-Session@users.noreply.github.com> --- .../thoughtcrime/securesms/calls/WebRtcCallActivity.kt | 4 ++++ .../org/thoughtcrime/securesms/webrtc/CallManager.kt | 10 +++++++++- .../securesms/webrtc/PeerConnectionWrapper.kt | 2 -- .../org/thoughtcrime/securesms/webrtc/video/Camera.kt | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt index b87eac12c4..198fc33372 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt @@ -334,6 +334,10 @@ class WebRtcCallActivity : PassphraseRequiredActionBarActivity() { if (isEnabled) { viewModel.localRenderer?.let { surfaceView -> surfaceView.setZOrderOnTop(true) + + // Mirror the video preview of the person making the call to prevent disorienting them + surfaceView.setMirror(true) + binding.localRenderer.addView(surfaceView) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt index 272f2c12db..ff5e481895 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt @@ -408,6 +408,10 @@ class CallManager( override fun onCameraSwitchCompleted(newCameraState: CameraState) { localCameraState = newCameraState + + // If the camera we've switched to is the front one then mirror it to match what someone + // would see when looking in the mirror rather than the left<-->right flipped version. + localRenderer?.setMirror(localCameraState.activeDirection == CameraState.Direction.FRONT) } fun onPreOffer(callId: UUID, recipient: Recipient, onSuccess: () -> Unit) { @@ -639,7 +643,11 @@ class CallManager( peerConnection?.let { connection -> connection.flipCamera() localCameraState = connection.getCameraState() - localRenderer?.setMirror(localCameraState.activeDirection == CameraState.Direction.FRONT) + + // Note: We cannot set the mirrored state of the localRenderer here because + // localCameraState.activeDirection is still PENDING (not FRONT or BACK) until the flip + // completes and we hit Camera.onCameraSwitchDone (followed by PeerConnectionWrapper.onCameraSwitchCompleted + // and CallManager.onCameraSwitchCompleted). } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/PeerConnectionWrapper.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/PeerConnectionWrapper.kt index 4835ab0dc1..f78b93d6b9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/PeerConnectionWrapper.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/PeerConnectionWrapper.kt @@ -326,8 +326,6 @@ class PeerConnectionWrapper(private val context: Context, } override fun onCameraSwitchCompleted(newCameraState: CameraState) { - // mirror rotation offset - rotationVideoSink.mirrored = newCameraState.activeDirection == CameraState.Direction.FRONT cameraEventListener.onCameraSwitchCompleted(newCameraState) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/video/Camera.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/video/Camera.kt index 421c144199..b76b168977 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/video/Camera.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/video/Camera.kt @@ -54,7 +54,7 @@ class Camera(context: Context, Log.w(TAG, "Tried to flip camera without capturer or less than 2 cameras") return } - activeDirection = PENDING + activeDirection = PENDING // Note: The activeDirection will be PENDING until `onCameraSwitchDone` capturer.switchCamera(this) }