This should fix video preview size and ratio

This commit is contained in:
Sylvain Berfini 2018-01-02 15:40:36 +01:00
parent cebd6f7721
commit 4c1521625e
9 changed files with 38 additions and 124 deletions

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.linphone.mediastream.video.display.GL2JNIView
android:visibility="visible"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/videoSurface" />
<SurfaceView
android:id="@+id/videoCaptureSurface"
android:layout_width="145dp"
android:layout_height="120dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:visibility="visible"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/videoSurface" />
<SurfaceView
android:id="@+id/videoCaptureSurface"
android:layout_width="145dp"
android:layout_height="120dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.linphone.mediastream.video.display.GL2JNIView
android:visibility="visible"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/videoSurface" />
<SurfaceView
android:id="@+id/videoCaptureSurface"
android:layout_width="218dp"
android:layout_height="160dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:visibility="visible"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/videoSurface" />
<SurfaceView
android:id="@+id/videoCaptureSurface"
android:layout_width="218dp"
android:layout_height="160dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.linphone.mediastream.video.display.GL2JNIView
android:visibility="visible"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/videoSurface" />
<SurfaceView
android:id="@+id/videoCaptureSurface"
android:layout_width="290dp"
android:layout_height="240dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:visibility="visible"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/videoSurface" />
<SurfaceView
android:id="@+id/videoCaptureSurface"
android:layout_width="290dp"
android:layout_height="240dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>

View file

@ -12,8 +12,8 @@
<SurfaceView <SurfaceView
android:id="@+id/videoCaptureSurface" android:id="@+id/videoCaptureSurface"
android:layout_width="120dp" android:layout_width="wrap_content"
android:layout_height="145dp" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" /> android:layout_alignParentRight="true" />

View file

@ -12,8 +12,8 @@
<SurfaceView <SurfaceView
android:id="@+id/videoCaptureSurface" android:id="@+id/videoCaptureSurface"
android:layout_width="120dp" android:layout_width="wrap_content"
android:layout_height="145dp" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" /> android:layout_alignParentRight="true" />

View file

@ -23,12 +23,16 @@ import org.linphone.compatibility.Compatibility;
import org.linphone.compatibility.CompatibilityScaleGestureDetector; import org.linphone.compatibility.CompatibilityScaleGestureDetector;
import org.linphone.compatibility.CompatibilityScaleGestureListener; import org.linphone.compatibility.CompatibilityScaleGestureListener;
import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCore;
import org.linphone.core.VideoSize;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import org.linphone.mediastream.video.AndroidVideoWindowImpl; import org.linphone.mediastream.video.AndroidVideoWindowImpl;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import android.app.Fragment; import android.app.Fragment;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener; import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener; import android.view.GestureDetector.OnGestureListener;
@ -82,6 +86,7 @@ public class CallVideoFragment extends Fragment implements OnGestureListener, On
public void onVideoPreviewSurfaceReady(AndroidVideoWindowImpl vw, SurfaceView surface) { public void onVideoPreviewSurfaceReady(AndroidVideoWindowImpl vw, SurfaceView surface) {
mCaptureView = surface; mCaptureView = surface;
LinphoneManager.getLc().setPreviewWindow(mCaptureView); LinphoneManager.getLc().setPreviewWindow(mCaptureView);
resizePreview();
} }
public void onVideoPreviewSurfaceDestroyed(AndroidVideoWindowImpl vw) { public void onVideoPreviewSurfaceDestroyed(AndroidVideoWindowImpl vw) {
@ -139,6 +144,33 @@ public class CallVideoFragment extends Fragment implements OnGestureListener, On
} }
} }
private void resizePreview() {
LinphoneCore lc = LinphoneManager.getLc();
if (lc.getCallsNb() > 0) {
LinphoneCall call = lc.getCurrentCall();
if (call == null) {
call = lc.getCalls()[0];
}
if (call == null) return;
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
int screenHeight = metrics.heightPixels;
int maxHeight = screenHeight / 4; // Let's take at most 1/4 of the screen for the camera preview
VideoSize videoSize = call.getCurrentParams().getSentVideoSize(); // It already takes care of rotation
int width = videoSize.width;
int height = videoSize.height;
Log.d("Video height is " + height + ", width is " + width);
width = width * maxHeight / height;
height = maxHeight;
mCaptureView.getHolder().setFixedSize(width, height);
Log.d("Video preview size set to " + width + "x" + height);
}
}
private void fixZOrder(SurfaceView video, SurfaceView preview) { private void fixZOrder(SurfaceView video, SurfaceView preview) {
video.setZOrderOnTop(false); video.setZOrderOnTop(false);
preview.setZOrderOnTop(true); preview.setZOrderOnTop(true);
@ -177,6 +209,8 @@ public class CallVideoFragment extends Fragment implements OnGestureListener, On
mGestureDetector = new GestureDetector(inCallActivity, this); mGestureDetector = new GestureDetector(inCallActivity, this);
mScaleDetector = Compatibility.getScaleGestureDetector(inCallActivity, this); mScaleDetector = Compatibility.getScaleGestureDetector(inCallActivity, this);
resizePreview();
} }
@Override @Override