This should fix video preview size and ratio

This commit is contained in:
Sylvain Berfini 2018-01-02 15:40:36 +01:00
parent f480b23bc4
commit e25120a2ff
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
android:id="@+id/videoCaptureSurface"
android:layout_width="120dp"
android:layout_height="145dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />

View file

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

View file

@ -28,11 +28,15 @@ import org.linphone.compatibility.Compatibility;
import org.linphone.compatibility.CompatibilityScaleGestureDetector;
import org.linphone.compatibility.CompatibilityScaleGestureListener;
import org.linphone.core.Call;
import org.linphone.core.Core;
import org.linphone.core.VideoDefinition;
import org.linphone.mediastream.Log;
import org.linphone.mediastream.video.AndroidVideoWindowImpl;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
@ -86,6 +90,7 @@ public class CallVideoFragment extends Fragment implements OnGestureListener, On
public void onVideoPreviewSurfaceReady(AndroidVideoWindowImpl vw, SurfaceView surface) {
mCaptureView = surface;
LinphoneManager.getLc().setNativePreviewWindowId(mCaptureView);
resizePreview();
}
public void onVideoPreviewSurfaceDestroyed(AndroidVideoWindowImpl vw) {
@ -143,6 +148,33 @@ public class CallVideoFragment extends Fragment implements OnGestureListener, On
}
}
private void resizePreview() {
Core lc = LinphoneManager.getLc();
if (lc.getCallsNb() > 0) {
Call 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
VideoDefinition videoSize = call.getCurrentParams().getSentVideoDefinition(); // It already takes care of rotation
int width = videoSize.getWidth();
int height = videoSize.getHeight();
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) {
video.setZOrderOnTop(false);
preview.setZOrderOnTop(true);
@ -189,6 +221,8 @@ public class CallVideoFragment extends Fragment implements OnGestureListener, On
mGestureDetector = new GestureDetector(inCallActivity, this);
mScaleDetector = Compatibility.getScaleGestureDetector(inCallActivity, this);
resizePreview();
}
@Override