From dcb16378c84ca3592a36664320fa05b3b99e59d9 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Tue, 1 Dec 2020 14:53:34 -0400 Subject: [PATCH] Display PiP in Group Calls even if local video is disabled. --- .../webrtc/CallParticipantView.java | 15 ++++++++++++- .../webrtc/CallParticipantsState.java | 6 +++++- .../components/webrtc/WebRtcCallView.java | 21 +++++-------------- .../securesms/service/WebRtcCallService.java | 1 - app/src/main/res/layout/webrtc_call_view.xml | 3 ++- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java index df838bf4f3..0c907f60f3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java @@ -16,7 +16,6 @@ import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.components.AvatarImageView; import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto; import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto; -import org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto; import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto; import org.thoughtcrime.securesms.events.CallParticipant; import org.thoughtcrime.securesms.mms.GlideApp; @@ -24,6 +23,7 @@ import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientId; import org.thoughtcrime.securesms.util.AvatarUtil; import org.thoughtcrime.securesms.util.ViewUtil; +import org.webrtc.RendererCommon; import java.util.Objects; @@ -70,6 +70,14 @@ public class CallParticipantView extends ConstraintLayout { useLargeAvatar(); } + void setMirror(boolean mirror) { + renderer.setMirror(mirror); + } + + void setScalingType(@NonNull RendererCommon.ScalingType scalingType) { + renderer.setScalingType(scalingType); + } + void setCallParticipant(@NonNull CallParticipant participant) { boolean participantChanged = recipientId == null || !recipientId.equals(participant.getRecipient().getId()); recipientId = participant.getRecipient().getId(); @@ -137,6 +145,11 @@ public class CallParticipantView extends ConstraintLayout { } private static final class FallbackPhotoProvider extends Recipient.FallbackPhotoProvider { + @Override + public @NonNull FallbackContactPhoto getPhotoForLocalNumber() { + return super.getPhotoForRecipientWithoutName(); + } + @Override public @NonNull FallbackContactPhoto getPhotoForRecipientWithoutName() { ResourceContactPhoto photo = new ResourceContactPhoto(R.drawable.ic_profile_outline_120); diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsState.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsState.java index 245d061bc4..a72e0b57a2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsState.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsState.java @@ -167,6 +167,7 @@ public final class CallParticipantsState { WebRtcLocalRenderState localRenderState = determineLocalRenderMode(webRtcViewModel.getLocalParticipant(), oldState.isInPipMode, newShowVideoForOutgoing, + webRtcViewModel.getGroupState().isNotIdle(), webRtcViewModel.getState(), webRtcViewModel.getRemoteParticipants().size(), oldState.isViewingFocusedParticipant); @@ -191,6 +192,7 @@ public final class CallParticipantsState { WebRtcLocalRenderState localRenderState = determineLocalRenderMode(oldState.localParticipant, isInPip, oldState.showVideoForOutgoing, + oldState.getGroupCallState().isNotIdle(), oldState.callState, oldState.getAllRemoteParticipants().size(), oldState.isViewingFocusedParticipant); @@ -214,6 +216,7 @@ public final class CallParticipantsState { WebRtcLocalRenderState localRenderState = determineLocalRenderMode(oldState.localParticipant, oldState.isInPipMode, oldState.showVideoForOutgoing, + oldState.getGroupCallState().isNotIdle(), oldState.callState, oldState.getAllRemoteParticipants().size(), selectedPage == SelectedPage.FOCUSED); @@ -232,11 +235,12 @@ public final class CallParticipantsState { private static @NonNull WebRtcLocalRenderState determineLocalRenderMode(@NonNull CallParticipant localParticipant, boolean isInPip, boolean showVideoForOutgoing, + boolean isNonIdleGroupCall, @NonNull WebRtcViewModel.State callState, int numberOfRemoteParticipants, boolean isViewingFocusedParticipant) { - boolean displayLocal = !isInPip && localParticipant.isVideoEnabled(); + boolean displayLocal = isNonIdleGroupCall || (!isInPip && localParticipant.isVideoEnabled()); WebRtcLocalRenderState localRenderState = WebRtcLocalRenderState.GONE; if (displayLocal || showVideoForOutgoing) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java index faeb50f485..12ce675977 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java @@ -69,7 +69,7 @@ public class WebRtcCallView extends FrameLayout { private AccessibleToggleButton videoToggle; private AccessibleToggleButton micToggle; private ViewGroup smallLocalRenderFrame; - private TextureViewRenderer smallLocalRender; + private CallParticipantView smallLocalRender; private View largeLocalRenderFrame; private TextureViewRenderer largeLocalRender; private View largeLocalRenderNoVideo; @@ -287,38 +287,33 @@ public class WebRtcCallView extends FrameLayout { largeLocalRender.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL); if (localCallParticipant.getVideoSink().getEglBase() != null) { - smallLocalRender.init(localCallParticipant.getVideoSink().getEglBase()); largeLocalRender.init(localCallParticipant.getVideoSink().getEglBase()); } + smallLocalRender.setCallParticipant(localCallParticipant); + smallLocalRender.setRenderInPip(true); + videoToggle.setChecked(localCallParticipant.isVideoEnabled(), false); + switch (state) { case GONE: largeLocalRender.attachBroadcastVideoSink(null); largeLocalRenderFrame.setVisibility(View.GONE); - smallLocalRender.attachBroadcastVideoSink(null); smallLocalRenderFrame.setVisibility(View.GONE); - videoToggle.setChecked(false, false); break; case SMALL_RECTANGLE: smallLocalRenderFrame.setVisibility(View.VISIBLE); - smallLocalRender.attachBroadcastVideoSink(localCallParticipant.getVideoSink()); animatePipToLargeRectangle(); largeLocalRender.attachBroadcastVideoSink(null); largeLocalRenderFrame.setVisibility(View.GONE); - - videoToggle.setChecked(true, false); break; case SMALLER_RECTANGLE: smallLocalRenderFrame.setVisibility(View.VISIBLE); - smallLocalRender.attachBroadcastVideoSink(localCallParticipant.getVideoSink()); animatePipToSmallRectangle(); largeLocalRender.attachBroadcastVideoSink(null); largeLocalRenderFrame.setVisibility(View.GONE); - - videoToggle.setChecked(true, false); break; case LARGE: largeLocalRender.attachBroadcastVideoSink(localCallParticipant.getVideoSink()); @@ -327,10 +322,7 @@ public class WebRtcCallView extends FrameLayout { largeLocalRenderNoVideo.setVisibility(View.GONE); largeLocalRenderNoVideoAvatar.setVisibility(View.GONE); - smallLocalRender.attachBroadcastVideoSink(null); smallLocalRenderFrame.setVisibility(View.GONE); - - videoToggle.setChecked(true, false); break; case LARGE_NO_VIDEO: largeLocalRender.attachBroadcastVideoSink(null); @@ -345,10 +337,7 @@ public class WebRtcCallView extends FrameLayout { .diskCacheStrategy(DiskCacheStrategy.ALL) .into(largeLocalRenderNoVideoAvatar); - smallLocalRender.attachBroadcastVideoSink(null); smallLocalRenderFrame.setVisibility(View.GONE); - - videoToggle.setChecked(false, false); break; } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.java b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.java index f9ea2b04c5..b6b9d5b99a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.java @@ -57,7 +57,6 @@ import org.thoughtcrime.securesms.util.FutureTaskListener; import org.thoughtcrime.securesms.util.ListenableFutureTask; import org.thoughtcrime.securesms.util.TelephonyUtil; import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.concurrent.SignalExecutors; import org.thoughtcrime.securesms.webrtc.CallNotificationBuilder; import org.thoughtcrime.securesms.webrtc.UncaughtExceptionHandlerManager; diff --git a/app/src/main/res/layout/webrtc_call_view.xml b/app/src/main/res/layout/webrtc_call_view.xml index 311cd7188c..9552f21933 100644 --- a/app/src/main/res/layout/webrtc_call_view.xml +++ b/app/src/main/res/layout/webrtc_call_view.xml @@ -103,8 +103,9 @@ tools:background="@color/red" tools:visibility="visible"> -