Added local video preview to TextureOverlay so we can still send video while app is in background

This commit is contained in:
Sylvain Berfini 2019-02-20 10:42:09 +01:00
parent cb1429c7be
commit d507484453
2 changed files with 39 additions and 7 deletions

View file

@ -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");
}
}

View file

@ -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() {