Fix preview rotation bug

Signed-off-by: Leo Ma <begeekmyfriend@gmail.com>
camera2
Leo Ma 8 years ago
parent 6d92307149
commit 5e039d6539

@ -25,6 +25,6 @@ android {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.2.0' compile 'com.android.support:appcompat-v7:25.3.1'
compile project(path: ':library') compile project(path: ':library')
} }

@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.3.0' classpath 'com.android.tools.build:gradle:2.3.1'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

@ -38,6 +38,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
private int mPreviewWidth; private int mPreviewWidth;
private int mPreviewHeight; private int mPreviewHeight;
private boolean mIsEncoding; private boolean mIsEncoding;
private boolean mIsTorchOn = false;
private float mInputAspectRatio; private float mInputAspectRatio;
private float mOutputAspectRatio; private float mOutputAspectRatio;
private float[] mProjectionMatrix = new float[16]; private float[] mProjectionMatrix = new float[16];
@ -199,17 +200,19 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
mPreviewOrientation = orientation; mPreviewOrientation = orientation;
Camera.CameraInfo info = new Camera.CameraInfo(); Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(mCamId, info); Camera.getCameraInfo(mCamId, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { if (orientation == Configuration.ORIENTATION_PORTRAIT) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) { if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
mPreviewRotation = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? 270 : 90; mPreviewRotation = info.orientation % 360;
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { mPreviewRotation = (360 - mPreviewRotation) % 360; // compensate the mirror
mPreviewRotation = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? 180 : 0; } else { // back-facing
mPreviewRotation = (info.orientation + 360) % 360;
} }
} else if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) { if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
mPreviewRotation = 90; mPreviewRotation = (info.orientation + 90) % 360;
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { mPreviewRotation = (360 - mPreviewRotation) % 360; // compensate the mirror
mPreviewRotation = 0; } else { // back-facing
mPreviewRotation = (info.orientation + 270) % 360;
} }
} }
} }
@ -293,7 +296,9 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
List<String> supportedFlashModes = params.getSupportedFlashModes(); List<String> supportedFlashModes = params.getSupportedFlashModes();
if (supportedFlashModes != null && !supportedFlashModes.isEmpty()) { if (supportedFlashModes != null && !supportedFlashModes.isEmpty()) {
if (supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)) { if (supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)) {
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); if (mIsTorchOn) {
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
}
} else { } else {
params.setFlashMode(supportedFlashModes.get(0)); params.setFlashMode(supportedFlashModes.get(0));
} }

@ -97,7 +97,7 @@ public class SrsEncoder {
// Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK // Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK
// Since Y component is quadruple size as U and V component, the stride must be set as 32x // 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 (!useSoftEncoder && vOutWidth % 32 != 0 || vOutHeight % 32 != 0) {
if (vmci.getName().contains("MTK")) { 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");
} }
@ -284,7 +284,7 @@ public class SrsEncoder {
// Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK // Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK
// Since Y component is quadruple size as U and V component, the stride must be set as 32x // 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 (!useSoftEncoder && vOutWidth % 32 != 0 || vOutHeight % 32 != 0) {
if (vmci.getName().contains("MTK")) { 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…
Cancel
Save