Skip to content
Snippets Groups Projects
Commit d55ad960 authored by Leo Ma's avatar Leo Ma
Browse files

Fix video upside down


For some Android SDK versions (maybe Android M+) the camera preview rotation
will show upside down constract to the older ones. So we need to adjust
the preview rotation on dynamic orientation change as well as camera
face switch.

Signed-off-by: default avatarLeo Ma <begeekmyfriend@gmail.com>
parent 74bfa104
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -238,11 +238,6 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
mPublisher.setPreviewRotation(90);
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
mPublisher.setPreviewRotation(0);
}
mPublisher.stopEncode();
mPublisher.stopRecord();
btnRecord.setText("record");
Loading
Loading
package net.ossrs.yasea;
 
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.ImageFormat;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.os.Build;
import android.util.AttributeSet;
 
import com.seu.magicfilter.base.gpuimage.GPUImageFilter;
Loading
Loading
@@ -45,6 +47,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
private ByteBuffer mGLPreviewBuffer;
private int mCamId = -1;
private int mPreviewRotation = 90;
private int mPreviewOrientation = Configuration.ORIENTATION_PORTRAIT;
 
private Thread worker;
private final Object writeLock = new Object();
Loading
Loading
@@ -172,7 +175,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
}
 
private void deleteTextures() {
if(mOESTextureId != OpenGLUtils.NO_TEXTURE){
if (mOESTextureId != OpenGLUtils.NO_TEXTURE) {
queueEvent(new Runnable() {
@Override
public void run() {
Loading
Loading
@@ -183,12 +186,28 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
}
}
 
public void setPreviewRotation(int rotation) {
mPreviewRotation = rotation;
}
public void setCameraId(int id) {
mCamId = id;
setPreviewOrientation(mPreviewOrientation);
}
public void setPreviewOrientation(int orientation) {
mPreviewOrientation = orientation;
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(mCamId, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
mPreviewRotation = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? 270 : 90;
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
mPreviewRotation = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? 180 : 0;
}
} else if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
mPreviewRotation = 90;
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
mPreviewRotation = 0;
}
}
}
 
public int getCameraId() {
Loading
Loading
@@ -293,8 +312,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
Camera.getCameraInfo(i, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
backCamId = i;
}
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
} else if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
frontCamId = i;
break;
}
Loading
Loading
Loading
Loading
@@ -31,7 +31,7 @@ public class SrsEncoder {
public static int vLandscapeHeight = 720;
public static int vOutWidth = 720; // Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK
public static int vOutHeight = 1280; // Since Y component is quadruple size as U and V component, the stride must be set as 32x
public static int vBitrate = 500 * 1000; // 500kbps
public static int vBitrate = 1200 * 1000; // 1200kbps
public static final int VFPS = 24;
public static final int VGOP = 48;
public static final int ASAMPLERATE = 44100;
Loading
Loading
@@ -98,7 +98,7 @@ public class SrsEncoder {
// Since Y component is quadruple size as U and V component, the stride must be set as 32x
if (!useSoftEncoder && vOutWidth % 32 != 0 || vOutHeight % 32 != 0) {
if (vmci.getName().contains("MTK")) {
throw new AssertionError("MTK encoding revolution stride must be 32x");
//throw new AssertionError("MTK encoding revolution stride must be 32x");
}
}
Loading
Loading
Loading
Loading
@@ -187,13 +187,10 @@ public class SrsPublisher {
}
public void setScreenOrientation(int orientation) {
mCameraView.setPreviewOrientation(orientation);
mEncoder.setScreenOrientation(orientation);
}
public void setPreviewRotation(int rotation) {
mCameraView.setPreviewRotation(rotation);
}
public void setVideoHDMode() {
mEncoder.setVideoHDMode();
}
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment