rename old "pip*"-stuff to "selfVideo*"

improve design-logic for pip-mode and normal mode when switched back from pip

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2021-10-20 20:24:26 +02:00
parent 914b10bf20
commit 3ba599be98
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
3 changed files with 63 additions and 48 deletions

View file

@ -148,7 +148,7 @@ class MagicCallActivity : BaseActivity() {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig) super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
isInPipMode = isInPictureInPictureMode isInPipMode = isInPictureInPictureMode
var callController = router?.getControllerWithTag("CallController") as CallController val callController = router?.getControllerWithTag("CallController") as CallController
if (isInPictureInPictureMode) { if (isInPictureInPictureMode) {
callController.updateUiForPipMode() callController.updateUiForPipMode()
} else { } else {

View file

@ -180,8 +180,12 @@ public class CallController extends BaseController {
@BindView(R.id.callControlEnableSpeaker) @BindView(R.id.callControlEnableSpeaker)
SimpleDraweeView callControlEnableSpeaker; SimpleDraweeView callControlEnableSpeaker;
@BindView(R.id.pip_video_view) @BindView(R.id.selfVideoRenderer)
SurfaceViewRenderer pipVideoView; SurfaceViewRenderer selfVideoRenderer;
@BindView(R.id.selfVideoViewWrapper)
FrameLayout selfVideoViewWrapper;
@BindView(R.id.controllerCallLayout) @BindView(R.id.controllerCallLayout)
RelativeLayout controllerCallLayout; RelativeLayout controllerCallLayout;
@BindView(R.id.gridview) @BindView(R.id.gridview)
@ -205,8 +209,7 @@ public class CallController extends BaseController {
@BindView(R.id.callConversationNameTextView) @BindView(R.id.callConversationNameTextView)
TextView callConversationNameTextView; TextView callConversationNameTextView;
@BindView(R.id.selfVideoView)
FrameLayout selfVideoView;
@BindView(R.id.callStateRelativeLayoutView) @BindView(R.id.callStateRelativeLayoutView)
RelativeLayout callStateView; RelativeLayout callStateView;
@ -371,8 +374,9 @@ public class CallController extends BaseController {
callControls.setZ(100.0f); callControls.setZ(100.0f);
basicInitialization(); basicInitialization();
participantDisplayItems = new HashMap<>();
initViews(); initViews();
initPipView(); updateSelfVideoViewPosition();
if (!isConnectionEstablished()){ if (!isConnectionEstablished()){
initiateCall(); initiateCall();
} }
@ -475,37 +479,37 @@ public class CallController extends BaseController {
}); });
} }
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
private void initViews() { private void initViews() {
participantDisplayItems = new HashMap<>();
callControls.setVisibility(View.VISIBLE);
callInfosLinearLayout.setVisibility(View.VISIBLE);
selfVideoViewWrapper.setVisibility(View.VISIBLE);
if (isVoiceOnlyCall) { if (isVoiceOnlyCall) {
callControlEnableSpeaker.setVisibility(View.VISIBLE); callControlEnableSpeaker.setVisibility(View.VISIBLE);
cameraSwitchButton.setVisibility(View.GONE); cameraSwitchButton.setVisibility(View.GONE);
cameraControlButton.setVisibility(View.GONE); cameraControlButton.setVisibility(View.GONE);
pipVideoView.setVisibility(View.GONE); selfVideoRenderer.setVisibility(View.GONE);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT); ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, R.id.callInfosLinearLayout); params.addRule(RelativeLayout.BELOW, R.id.callInfosLinearLayout);
int callControlsHeight = int callControlsHeight = Math.round(getApplicationContext().getResources().getDimension(R.dimen.call_controls_height));
Math.round(getApplicationContext().getResources().getDimension(R.dimen.call_controls_height));
params.setMargins(0,0,0, callControlsHeight); params.setMargins(0,0,0, callControlsHeight);
gridView.setLayoutParams(params); gridView.setLayoutParams(params);
} else { } else {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(0,0,0, 0);
gridView.setLayoutParams(params);
callControlEnableSpeaker.setVisibility(View.GONE); callControlEnableSpeaker.setVisibility(View.GONE);
if (cameraEnumerator.getDeviceNames().length < 2) { if (cameraEnumerator.getDeviceNames().length < 2) {
cameraSwitchButton.setVisibility(View.GONE); cameraSwitchButton.setVisibility(View.GONE);
} }
initSelfVideoView();
pipVideoView.init(rootEglBase.getEglBaseContext(), null);
pipVideoView.setZOrderMediaOverlay(true);
// disabled because it causes some devices to crash
pipVideoView.setEnableHardwareScaler(false);
pipVideoView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
pipVideoView.setOnTouchListener(new SelfVideoTouchListener());
} }
gridView.setOnTouchListener(new View.OnTouchListener() { gridView.setOnTouchListener(new View.OnTouchListener() {
@ -521,6 +525,21 @@ public class CallController extends BaseController {
initGridAdapter(); initGridAdapter();
} }
@SuppressLint("ClickableViewAccessibility")
private void initSelfVideoView() {
try{
selfVideoRenderer.init(rootEglBase.getEglBaseContext(), null);
} catch(IllegalStateException e) {
Log.d(TAG, "selfVideoRenderer already initialized", e);
}
selfVideoRenderer.setZOrderMediaOverlay(true);
// disabled because it causes some devices to crash
selfVideoRenderer.setEnableHardwareScaler(false);
selfVideoRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
selfVideoRenderer.setOnTouchListener(new SelfVideoTouchListener());
}
private void initGridAdapter() { private void initGridAdapter() {
if (conversationView != null) { if (conversationView != null) {
GridView gridView = conversationView.findViewById(R.id.gridview); GridView gridView = conversationView.findViewById(R.id.gridview);
@ -704,7 +723,7 @@ public class CallController extends BaseController {
localVideoTrack = peerConnectionFactory.createVideoTrack("NCv0", videoSource); localVideoTrack = peerConnectionFactory.createVideoTrack("NCv0", videoSource);
localMediaStream.addTrack(localVideoTrack); localMediaStream.addTrack(localVideoTrack);
localVideoTrack.setEnabled(false); localVideoTrack.setEnabled(false);
localVideoTrack.addSink(pipVideoView); localVideoTrack.addSink(selfVideoRenderer);
} }
private void microphoneInitialization() { private void microphoneInitialization() {
@ -725,7 +744,7 @@ public class CallController extends BaseController {
Logging.d(TAG, "Creating front facing camera capturer."); Logging.d(TAG, "Creating front facing camera capturer.");
VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null); VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null);
if (videoCapturer != null) { if (videoCapturer != null) {
pipVideoView.setMirror(true); selfVideoRenderer.setMirror(true);
return videoCapturer; return videoCapturer;
} }
} }
@ -740,7 +759,7 @@ public class CallController extends BaseController {
VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null); VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null);
if (videoCapturer != null) { if (videoCapturer != null) {
pipVideoView.setMirror(false); selfVideoRenderer.setMirror(false);
return videoCapturer; return videoCapturer;
} }
} }
@ -894,7 +913,7 @@ public class CallController extends BaseController {
cameraVideoCapturer.switchCamera(new CameraVideoCapturer.CameraSwitchHandler() { cameraVideoCapturer.switchCamera(new CameraVideoCapturer.CameraSwitchHandler() {
@Override @Override
public void onCameraSwitchDone(boolean currentCameraIsFront) { public void onCameraSwitchDone(boolean currentCameraIsFront) {
pipVideoView.setMirror(currentCameraIsFront); selfVideoRenderer.setMirror(currentCameraIsFront);
} }
@Override @Override
@ -928,9 +947,9 @@ public class CallController extends BaseController {
localMediaStream.videoTracks.get(0).setEnabled(enable); localMediaStream.videoTracks.get(0).setEnabled(enable);
} }
if (enable) { if (enable) {
pipVideoView.setVisibility(View.VISIBLE); selfVideoRenderer.setVisibility(View.VISIBLE);
} else { } else {
pipVideoView.setVisibility(View.INVISIBLE); selfVideoRenderer.setVisibility(View.INVISIBLE);
} }
} else { } else {
message = "audioOff"; message = "audioOff";
@ -1545,8 +1564,8 @@ public class CallController extends BaseController {
videoCapturer = null; videoCapturer = null;
} }
if (pipVideoView != null) { if (selfVideoRenderer != null) {
pipVideoView.release(); selfVideoRenderer.release();
} }
if (audioSource != null) { if (audioSource != null) {
@ -1879,11 +1898,11 @@ public class CallController extends BaseController {
public void onMessageEvent(ConfigurationChangeEvent configurationChangeEvent) { public void onMessageEvent(ConfigurationChangeEvent configurationChangeEvent) {
powerManagerUtils.setOrientation(Objects.requireNonNull(getResources()).getConfiguration().orientation); powerManagerUtils.setOrientation(Objects.requireNonNull(getResources()).getConfiguration().orientation);
initGridAdapter(); initGridAdapter();
initPipView(); updateSelfVideoViewPosition();
} }
private void initPipView() { private void updateSelfVideoViewPosition() {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) pipVideoView.getLayoutParams(); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) selfVideoRenderer.getLayoutParams();
DisplayMetrics displayMetrics = getApplicationContext().getResources().getDisplayMetrics(); DisplayMetrics displayMetrics = getApplicationContext().getResources().getDisplayMetrics();
int screenWidthPx = displayMetrics.widthPixels; int screenWidthPx = displayMetrics.widthPixels;
@ -1908,11 +1927,11 @@ public class CallController extends BaseController {
layoutParams.width = (int) getResources().getDimension(R.dimen.large_preview_dimension); layoutParams.width = (int) getResources().getDimension(R.dimen.large_preview_dimension);
newXafterRotate = (float) (screenWidthDp - getResources().getDimension(R.dimen.large_preview_dimension) * 0.5); newXafterRotate = (float) (screenWidthDp - getResources().getDimension(R.dimen.large_preview_dimension) * 0.5);
} }
pipVideoView.setLayoutParams(layoutParams); selfVideoRenderer.setLayoutParams(layoutParams);
int newXafterRotatePx = (int) DisplayUtils.convertDpToPixel(newXafterRotate, getApplicationContext()); int newXafterRotatePx = (int) DisplayUtils.convertDpToPixel(newXafterRotate, getApplicationContext());
selfVideoView.setY(newYafterRotate); selfVideoViewWrapper.setY(newYafterRotate);
selfVideoView.setX(newXafterRotatePx); selfVideoViewWrapper.setX(newXafterRotatePx);
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
@ -2368,22 +2387,18 @@ public class CallController extends BaseController {
callControls.setVisibility(View.GONE); callControls.setVisibility(View.GONE);
callInfosLinearLayout.setVisibility(View.GONE); callInfosLinearLayout.setVisibility(View.GONE);
selfVideoView.setVisibility(View.GONE); selfVideoViewWrapper.setVisibility(View.GONE);
callStateView.setVisibility(View.GONE); callStateView.setVisibility(View.GONE);
selfVideoRenderer.release();
} }
public void updateUiForNormalMode(){ public void updateUiForNormalMode(){
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, initViews(); // --> IllegalStateException: pip_video_viewAlready initialized
ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, R.id.callInfosLinearLayout);
int callControlsHeight =
Math.round(getApplicationContext().getResources().getDimension(R.dimen.call_controls_height));
params.setMargins(0,0,0, callControlsHeight);
gridView.setLayoutParams(params);
callControls.setVisibility(View.VISIBLE); callControls.setVisibility(View.VISIBLE);
callInfosLinearLayout.setVisibility(View.VISIBLE); callInfosLinearLayout.setVisibility(View.VISIBLE);
selfVideoView.setVisibility(View.VISIBLE); selfVideoViewWrapper.setVisibility(View.VISIBLE);
} }
private String getDescriptionForCallType() { private String getDescriptionForCallType() {
@ -2489,10 +2504,10 @@ public class CallController extends BaseController {
long duration = event.getEventTime() - event.getDownTime(); long duration = event.getEventTime() - event.getDownTime();
if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
float newY = event.getRawY() - selfVideoView.getHeight() / (float) 2; float newY = event.getRawY() - selfVideoViewWrapper.getHeight() / (float) 2;
float newX = event.getRawX() - selfVideoView.getWidth() / (float) 2; float newX = event.getRawX() - selfVideoViewWrapper.getWidth() / (float) 2;
selfVideoView.setY(newY); selfVideoViewWrapper.setY(newY);
selfVideoView.setX(newX); selfVideoViewWrapper.setX(newX);
} else if (event.getActionMasked() == MotionEvent.ACTION_UP && duration < 100) { } else if (event.getActionMasked() == MotionEvent.ACTION_UP && duration < 100) {
switchCamera(); switchCamera();
} }

View file

@ -55,12 +55,12 @@
android:stretchMode="columnWidth" /> android:stretchMode="columnWidth" />
<FrameLayout <FrameLayout
android:id="@+id/selfVideoView" android:id="@+id/selfVideoViewWrapper"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<org.webrtc.SurfaceViewRenderer <org.webrtc.SurfaceViewRenderer
android:id="@+id/pip_video_view" android:id="@+id/selfVideoRenderer"
android:layout_width="@dimen/large_preview_dimension" android:layout_width="@dimen/large_preview_dimension"
android:layout_height="150dp" android:layout_height="150dp"
android:layout_gravity="center" android:layout_gravity="center"