This commit is contained in:
parent
62324f8898
commit
f7fb3e361d
@ -499,6 +499,11 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
int getCameraOrientation() {
|
||||
return mCameraInfo.orientation;
|
||||
}
|
||||
|
||||
@Override
|
||||
void setDisplayOrientation(int displayOrientation) {
|
||||
if (mDisplayOrientation == displayOrientation) {
|
||||
|
||||
@ -231,6 +231,8 @@ class Camera2 extends CameraViewImpl implements MediaRecorder.OnInfoListener, Me
|
||||
|
||||
private int mFlash;
|
||||
|
||||
private int mCameraOrientation;
|
||||
|
||||
private int mDisplayOrientation;
|
||||
|
||||
private int mDeviceOrientation;
|
||||
@ -614,6 +616,11 @@ class Camera2 extends CameraViewImpl implements MediaRecorder.OnInfoListener, Me
|
||||
return mIsScanning;
|
||||
}
|
||||
|
||||
@Override
|
||||
int getCameraOrientation() {
|
||||
return mCameraOrientation;
|
||||
}
|
||||
|
||||
@Override
|
||||
void setDisplayOrientation(int displayOrientation) {
|
||||
mDisplayOrientation = displayOrientation;
|
||||
@ -687,8 +694,8 @@ class Camera2 extends CameraViewImpl implements MediaRecorder.OnInfoListener, Me
|
||||
|
||||
/**
|
||||
* <p>Collects some information from {@link #mCameraCharacteristics}.</p>
|
||||
* <p>This rewrites {@link #mPreviewSizes}, {@link #mPictureSizes}, and optionally,
|
||||
* {@link #mAspectRatio}.</p>
|
||||
* <p>This rewrites {@link #mPreviewSizes}, {@link #mPictureSizes},
|
||||
* {@link #mCameraOrientation}, and optionally, {@link #mAspectRatio}.</p>
|
||||
*/
|
||||
private void collectCameraInfo() {
|
||||
StreamConfigurationMap map = mCameraCharacteristics.get(
|
||||
@ -718,6 +725,8 @@ class Camera2 extends CameraViewImpl implements MediaRecorder.OnInfoListener, Me
|
||||
if (!mPreviewSizes.ratios().contains(mAspectRatio)) {
|
||||
mAspectRatio = mPreviewSizes.ratios().iterator().next();
|
||||
}
|
||||
|
||||
mCameraOrientation = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
|
||||
}
|
||||
|
||||
protected void collectPictureSizes(SizeMap sizes, StreamConfigurationMap map) {
|
||||
|
||||
@ -473,6 +473,15 @@ public class CameraView extends FrameLayout {
|
||||
return mImpl.getFlash();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the camera orientation relative to the devices native orientation.
|
||||
*
|
||||
* @return The orientation of the camera.
|
||||
*/
|
||||
public int getCameraOrientation() {
|
||||
return mImpl.getCameraOrientation();
|
||||
}
|
||||
|
||||
public void setFocusDepth(float value) {
|
||||
mImpl.setFocusDepth(value);
|
||||
}
|
||||
|
||||
@ -83,6 +83,8 @@ abstract class CameraViewImpl {
|
||||
|
||||
abstract void stopRecording();
|
||||
|
||||
abstract int getCameraOrientation();
|
||||
|
||||
abstract void setDisplayOrientation(int displayOrientation);
|
||||
|
||||
abstract void setDeviceOrientation(int deviceOrientation);
|
||||
|
||||
@ -121,7 +121,7 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
|
||||
|
||||
@Override
|
||||
public void onFramePreview(CameraView cameraView, byte[] data, int width, int height, int rotation) {
|
||||
int correctRotation = RNCameraViewHelper.getCorrectCameraRotation(rotation, getFacing());
|
||||
int correctRotation = RNCameraViewHelper.getCorrectCameraRotation(rotation, getFacing(), getCameraOrientation());
|
||||
boolean willCallBarCodeTask = mShouldScanBarCodes && !barCodeScannerTaskLock && cameraView instanceof BarCodeScannerAsyncTaskDelegate;
|
||||
boolean willCallFaceTask = mShouldDetectFaces && !faceDetectorTaskLock && cameraView instanceof FaceDetectorAsyncTaskDelegate;
|
||||
boolean willCallGoogleBarcodeTask = mShouldGoogleDetectBarcodes && !googleBarcodeDetectorTaskLock && cameraView instanceof BarcodeDetectorAsyncTaskDelegate;
|
||||
|
||||
@ -275,13 +275,19 @@ public class RNCameraViewHelper {
|
||||
|
||||
// Utilities
|
||||
|
||||
public static int getCorrectCameraRotation(int rotation, int facing) {
|
||||
public static int getCorrectCameraRotation(int rotation, int facing, int cameraOrientation) {
|
||||
if (facing == CameraView.FACING_FRONT) {
|
||||
return (rotation - 90 + 360) % 360;
|
||||
return (360 - (cameraOrientation + rotation) % 360) % 360;
|
||||
} else {
|
||||
return (-rotation + 90 + 360) % 360;
|
||||
final int landscapeFlip = rotationIsLandscape(rotation) ? 180 : 0;
|
||||
return (cameraOrientation - rotation + landscapeFlip) % 360;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean rotationIsLandscape(int rotation) {
|
||||
return (rotation == Constants.LANDSCAPE_90 ||
|
||||
rotation == Constants.LANDSCAPE_270);
|
||||
}
|
||||
|
||||
private static int getCamcorderProfileQualityFromCameraModuleConstant(int quality) {
|
||||
switch (quality) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user