From d507484453a12ec998220044eb9afb3f8eb56f48 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 20 Feb 2019 10:42:09 +0100 Subject: [PATCH] Added local video preview to TextureOverlay so we can still send video while app is in background --- .../org/linphone/call/CallVideoFragment.java | 11 +++--- .../views/LinphoneTextureViewOverlay.java | 35 +++++++++++++++++-- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/linphone/call/CallVideoFragment.java b/app/src/main/java/org/linphone/call/CallVideoFragment.java index b9c8e857a..2554ebf33 100644 --- a/app/src/main/java/org/linphone/call/CallVideoFragment.java +++ b/app/src/main/java/org/linphone/call/CallVideoFragment.java @@ -149,18 +149,19 @@ public class CallVideoFragment extends Fragment call.getCurrentParams() .getSentVideoDefinition(); // It already takes care of rotation if (videoSize.getWidth() == 0 || videoSize.getHeight() == 0) { - Log.w("Couldn't get sent video definition, using default video definition"); + Log.w( + "[Video Fragment] Couldn't get sent video definition, using default video definition"); videoSize = lc.getPreferredVideoDefinition(); } int width = videoSize.getWidth(); int height = videoSize.getHeight(); - Log.d("Video height is " + height + ", width is " + width); + Log.d("[Video Fragment] Video height is " + height + ", width is " + width); width = width * maxHeight / height; height = maxHeight; if (mCaptureView == null) { - Log.e("mCaptureView is null !"); + Log.e("[Video Fragment] mCaptureView is null !"); return; } @@ -170,7 +171,7 @@ public class CallVideoFragment extends Fragment 1); // Clears the rule, as there is no removeRule until API 17. newLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 1); mCaptureView.setLayoutParams(newLp); - Log.d("Video preview size set to " + width + "x" + height); + Log.d("[Video Fragment] Video preview size set to " + width + "x" + height); } } @@ -194,7 +195,7 @@ public class CallVideoFragment extends Fragment CallManager.getInstance().updateCall(); } catch (ArithmeticException ae) { - Log.e("Cannot swtich camera : no camera"); + Log.e("[Video Fragment] Cannot swtich camera : no camera"); } } diff --git a/app/src/main/java/org/linphone/views/LinphoneTextureViewOverlay.java b/app/src/main/java/org/linphone/views/LinphoneTextureViewOverlay.java index dc9ecb2ed..fac0de589 100644 --- a/app/src/main/java/org/linphone/views/LinphoneTextureViewOverlay.java +++ b/app/src/main/java/org/linphone/views/LinphoneTextureViewOverlay.java @@ -29,20 +29,25 @@ import android.view.Gravity; import android.view.MotionEvent; import android.view.TextureView; import android.view.View; +import android.view.ViewGroup; import android.view.WindowManager; +import android.widget.RelativeLayout; import org.linphone.LinphoneActivity; import org.linphone.LinphoneManager; import org.linphone.LinphoneService; import org.linphone.core.Call; import org.linphone.core.CallParams; +import org.linphone.core.Core; +import org.linphone.core.VideoDefinition; import org.linphone.mediastream.Version; -public class LinphoneTextureViewOverlay extends TextureView implements LinphoneOverlay { +public class LinphoneTextureViewOverlay extends RelativeLayout implements LinphoneOverlay { private final WindowManager mWindowManager; private final WindowManager.LayoutParams mParams; private final DisplayMetrics mMetrics; private float mX, mY, mTouchX, mTouchY; private boolean mDragEnabled; + private TextureView mRemoteVideo, mLocalPreview; public LinphoneTextureViewOverlay(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); @@ -70,7 +75,33 @@ public class LinphoneTextureViewOverlay extends TextureView implements LinphoneO CallParams callParams = call.getCurrentParams(); mParams.width = callParams.getReceivedVideoDefinition().getWidth(); mParams.height = callParams.getReceivedVideoDefinition().getHeight(); - LinphoneManager.getLc().setNativeVideoWindowId(this); + + mRemoteVideo = new TextureView(context); + addView(mRemoteVideo); + mLocalPreview = new TextureView(context); + addView(mLocalPreview); + + RelativeLayout.LayoutParams remoteVideoParams = + new RelativeLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + mRemoteVideo.setLayoutParams(remoteVideoParams); + + VideoDefinition videoSize = call.getCurrentParams().getSentVideoDefinition(); + int localPreviewWidth = videoSize.getWidth(); + int localPreviewHeight = videoSize.getHeight(); + int localPreviewMaxHeight = mParams.height / 4; + localPreviewWidth = localPreviewWidth * localPreviewMaxHeight / localPreviewHeight; + localPreviewHeight = localPreviewMaxHeight; + + RelativeLayout.LayoutParams localPreviewParams = + new RelativeLayout.LayoutParams(localPreviewWidth, localPreviewHeight); + localPreviewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, TRUE); + localPreviewParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, TRUE); + mLocalPreview.setLayoutParams(localPreviewParams); + + Core lc = LinphoneManager.getLc(); + lc.setNativeVideoWindowId(mRemoteVideo); + lc.setNativePreviewWindowId(mLocalPreview); setOnClickListener( new OnClickListener() {