|
|
@ -86,32 +86,32 @@ public class Camera2Helper { |
|
|
|
start(); |
|
|
|
start(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private int getCameraOri(int rotation, String cameraId) { |
|
|
|
private int getCameraOrientation(int rotation, String cameraId) { |
|
|
|
int degrees = rotation * 90; |
|
|
|
int degree = rotation * 90; |
|
|
|
switch (rotation) { |
|
|
|
switch (rotation) { |
|
|
|
case Surface.ROTATION_0: |
|
|
|
case Surface.ROTATION_0: |
|
|
|
degrees = 0; |
|
|
|
degree = 0; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Surface.ROTATION_90: |
|
|
|
case Surface.ROTATION_90: |
|
|
|
degrees = 90; |
|
|
|
degree = 90; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Surface.ROTATION_180: |
|
|
|
case Surface.ROTATION_180: |
|
|
|
degrees = 180; |
|
|
|
degree = 180; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Surface.ROTATION_270: |
|
|
|
case Surface.ROTATION_270: |
|
|
|
degrees = 270; |
|
|
|
degree = 270; |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
int result; |
|
|
|
int result; |
|
|
|
if (CAMERA_ID_FRONT.equals(cameraId)) { |
|
|
|
if (CAMERA_ID_FRONT.equals(cameraId)) { |
|
|
|
result = (mSensorOrientation + degrees) % 360; |
|
|
|
result = (mSensorOrientation + degree) % 360; |
|
|
|
result = (360 - result) % 360; |
|
|
|
result = (360 - result) % 360; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
result = (mSensorOrientation - degrees + 360) % 360; |
|
|
|
result = (mSensorOrientation - degree + 360) % 360; |
|
|
|
} |
|
|
|
} |
|
|
|
Log.i(TAG, "getCameraOri: " + rotation + " " + result + " " + mSensorOrientation); |
|
|
|
Log.i(TAG, "getCameraOrientation, result=" + result); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -120,19 +120,19 @@ public class Camera2Helper { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) { |
|
|
|
public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) { |
|
|
|
Log.i(TAG, "onSurfaceTextureAvailable: "); |
|
|
|
Log.i(TAG, "onSurfaceTextureAvailable..."); |
|
|
|
openCamera(); |
|
|
|
openCamera(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { |
|
|
|
public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { |
|
|
|
Log.i(TAG, "onSurfaceTextureSizeChanged: "); |
|
|
|
Log.i(TAG, "onSurfaceTextureSizeChanged, width=" + width + "--height=" + height); |
|
|
|
configureTransform(width, height); |
|
|
|
configureTransform(width, height); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) { |
|
|
|
public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) { |
|
|
|
Log.i(TAG, "onSurfaceTextureDestroyed: "); |
|
|
|
Log.i(TAG, "onSurfaceTextureDestroyed..."); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -151,7 +151,7 @@ public class Camera2Helper { |
|
|
|
mCameraDevice = cameraDevice; |
|
|
|
mCameraDevice = cameraDevice; |
|
|
|
createCameraPreviewSession(); |
|
|
|
createCameraPreviewSession(); |
|
|
|
if (camera2Listener != null) { |
|
|
|
if (camera2Listener != null) { |
|
|
|
camera2Listener.onCameraOpened(mPreviewSize, getCameraOri(rotation, mCameraId)); |
|
|
|
camera2Listener.onCameraOpened(mPreviewSize, getCameraOrientation(rotation, mCameraId)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -179,6 +179,7 @@ public class Camera2Helper { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private final CameraCaptureSession.StateCallback mCaptureStateCallback = new CameraCaptureSession.StateCallback() { |
|
|
|
private final CameraCaptureSession.StateCallback mCaptureStateCallback = new CameraCaptureSession.StateCallback() { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -286,7 +287,7 @@ public class Camera2Helper { |
|
|
|
context = null; |
|
|
|
context = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setUpCameraOutputs(CameraManager cameraManager) { |
|
|
|
private void setUpCameraOutput(CameraManager cameraManager) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (configCameraParams(cameraManager, specificCameraId)) { |
|
|
|
if (configCameraParams(cameraManager, specificCameraId)) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -330,7 +331,7 @@ public class Camera2Helper { |
|
|
|
|
|
|
|
|
|
|
|
private void openCamera() { |
|
|
|
private void openCamera() { |
|
|
|
CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); |
|
|
|
CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); |
|
|
|
setUpCameraOutputs(cameraManager); |
|
|
|
setUpCameraOutput(cameraManager); |
|
|
|
configureTransform(mTextureView.getWidth(), mTextureView.getHeight()); |
|
|
|
configureTransform(mTextureView.getWidth(), mTextureView.getHeight()); |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { |
|
|
|
if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { |
|
|
@ -463,7 +464,6 @@ public class Camera2Helper { |
|
|
|
} else if (Surface.ROTATION_180 == rotation) { |
|
|
|
} else if (Surface.ROTATION_180 == rotation) { |
|
|
|
matrix.postRotate(180, centerX, centerY); |
|
|
|
matrix.postRotate(180, centerX, centerY); |
|
|
|
} |
|
|
|
} |
|
|
|
Log.i(TAG, "configureTransform: " + getCameraOri(rotation, mCameraId) + " " + rotation * 90); |
|
|
|
|
|
|
|
mTextureView.setTransform(matrix); |
|
|
|
mTextureView.setTransform(matrix); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|