Skip to content

Commit

Permalink
android: add setUIRotation() function to support landscape
Browse files Browse the repository at this point in the history
  • Loading branch information
c-g-owen committed Oct 12, 2021
1 parent accad47 commit 2235ae2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
66 changes: 51 additions & 15 deletions android/java/com/waz/avs/VideoCapturer.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

import android.view.Gravity;
import android.view.TextureView;
import android.view.Surface;

import com.waz.call.FlowManager;

Expand Down Expand Up @@ -77,6 +78,7 @@ public class VideoCapturer implements PreviewCallback,
private float lastFtime;
private ReentrantLock lock = new ReentrantLock();
private boolean destroying = false;
private int ui_rotation = 0;

public static VideoCapturerInfo[] getCapturers() {

Expand Down Expand Up @@ -477,21 +479,7 @@ private void startCamera(SurfaceTexture surface) {
Log.w(TAG, "startCamera: failed to initCamera");
}
else {
VideoPreview vp = (VideoPreview)this.previewView;
int vrot = getViewRotation();

Log.d(TAG, "startCamera: " + vp + " rot:" + vrot +
"facing: " + cameraInfo.facing);

try {
camera.setDisplayOrientation(vrot);
}
catch (RuntimeException e){
Log.d(TAG, "startCapture: exception calling " +
"setDisplayOrientation: " +
e.getMessage());
}
vp.setVideoOrientation(vrot);
setUIRotation(Surface.ROTATION_0);

try {
if (!this.started) {
Expand Down Expand Up @@ -587,6 +575,54 @@ public int getRotation() {
return (360 - cameraInfo.orientation) % 360;
}

public void setUIRotation(int rotation) {
int degrees = 0;
int vrot = 0;
VideoPreview vp = (VideoPreview)this.previewView;

switch (rotation) {
case Surface.ROTATION_0:
degrees = 0;
break;
case Surface.ROTATION_90:
degrees = 90;
break;
case Surface.ROTATION_180:
degrees = 180;
break;
case Surface.ROTATION_270:
degrees = 270;
break;
}

this.ui_rotation = degrees;

if (cameraInfo == null) {
Log.d(TAG, "setUIRotation: " + vp + " camInfo: null");
}
else {
if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
vrot = (cameraInfo.orientation + degrees) % 360;
vrot = (360 - vrot) % 360; // compensate the mirror
}
else { // back-facing
vrot = (cameraInfo.orientation - degrees + 360) % 360;
}
Log.d(TAG, "setUIRotation: " + vp + " camrot: " + cameraInfo.orientation +
" rot:" + vrot + "facing: " + cameraInfo.facing);
}

try {
camera.setDisplayOrientation(vrot);
}
catch (RuntimeException e){
Log.d(TAG, "setUIRotation: exception calling " +
"setDisplayOrientation: " +
e.getMessage());
}
vp.setVideoOrientation(vrot);
}

private static native void handleCameraFrame(int w, int h,
byte[] data,
int rotation,
Expand Down
6 changes: 6 additions & 0 deletions android/java/com/waz/call/FlowManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ public void setVideoSendState(String convId, int state) {
}
public native void setVideoSendStateNative(String convId, int state);

public void setUIRotation(int rotation) {
if (this.videoCapturer != null) {
this.videoCapturer.setUIRotation(rotation);
}
}


private static String TAG = "FlowManager";

Expand Down

0 comments on commit 2235ae2

Please sign in to comment.