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

Fix preview rotation bug


Signed-off-by: default avatarLeo Ma <begeekmyfriend@gmail.com>
parent 76ea43d4
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -25,6 +25,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
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')
}
Loading
Loading
@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
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
// in the individual module build.gradle files
Loading
Loading
Loading
Loading
@@ -28,6 +28,6 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
Loading
Loading
@@ -26,6 +26,7 @@ public class SrsCameraView extends SurfaceView implements SurfaceHolder.Callback
private int mPreviewWidth;
private int mPreviewHeight;
private boolean mIsEncoding;
private boolean mIsTorchOn = false;
public interface PreviewCallback {
void onGetYuvFrame(byte[] data);
Loading
Loading
@@ -48,17 +49,19 @@ public class SrsCameraView extends SurfaceView implements SurfaceHolder.Callback
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.N ? 270 : 90;
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
mPreviewRotation = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? 180 : 0;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
mPreviewRotation = info.orientation % 360;
mPreviewRotation = (360 - mPreviewRotation) % 360; // compensate the mirror
} else {
mPreviewRotation = (info.orientation + 360) % 360;
}
} else if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
mPreviewRotation = 90;
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
mPreviewRotation = 0;
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
mPreviewRotation = (info.orientation + 90) % 360;
mPreviewRotation = (360 - mPreviewRotation) % 360; // compensate the mirror
} else {
mPreviewRotation = (info.orientation + 270) % 360;
}
}
}
Loading
Loading
@@ -128,7 +131,9 @@ public class SrsCameraView extends SurfaceView implements SurfaceHolder.Callback
List<String> supportedFlashModes = params.getSupportedFlashModes();
if (supportedFlashModes != null && !supportedFlashModes.isEmpty()) {
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 {
params.setFlashMode(supportedFlashModes.get(0));
}
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