From caff00455f94acb25034601cd59dddfaf0f04b61 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Sat, 15 Sep 2018 12:48:32 -0300 Subject: [PATCH] Fix camerapreview tests --- .../otaliastudios/cameraview/CameraPreviewTest.java | 8 ++++++-- .../otaliastudios/cameraview/GLCameraPreviewTest.java | 10 ++++++++++ .../cameraview/SurfaceCameraPreviewTest.java | 10 ++++++++++ .../cameraview/TextureCameraPreviewTest.java | 10 ++++++++++ .../cameraview/MediaRecorderVideoRecorder.java | 3 +++ .../com/otaliastudios/cameraview/GLCameraPreview.java | 4 ++-- 6 files changed, 41 insertions(+), 4 deletions(-) diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraPreviewTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraPreviewTest.java index 8b56d56a..f9b483f9 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraPreviewTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraPreviewTest.java @@ -149,8 +149,12 @@ public abstract class CameraPreviewTest extends BaseTest { private float getViewAspectRatioWithScale() { Size size = preview.getOutputSurfaceSize(); - int newWidth = (int) (((float) size.getWidth()) * preview.getView().getScaleX()); - int newHeight = (int) (((float) size.getHeight()) * preview.getView().getScaleY()); + int newWidth = (int) (((float) size.getWidth()) * getCropScaleX()); + int newHeight = (int) (((float) size.getHeight()) * getCropScaleY()); return AspectRatio.of(newWidth, newHeight).toFloat(); } + + abstract protected float getCropScaleX(); + + abstract protected float getCropScaleY(); } diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/GLCameraPreviewTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/GLCameraPreviewTest.java index e766f856..24590c96 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/GLCameraPreviewTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/GLCameraPreviewTest.java @@ -16,4 +16,14 @@ public class GLCameraPreviewTest extends CameraPreviewTest { protected CameraPreview createPreview(Context context, ViewGroup parent, CameraPreview.SurfaceCallback callback) { return new GLCameraPreview(context, parent, callback); } + + @Override + protected float getCropScaleY() { + return 1F / ((GLCameraPreview) preview).mScaleY; + } + + @Override + protected float getCropScaleX() { + return 1F / ((GLCameraPreview) preview).mScaleX; + } } diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/SurfaceCameraPreviewTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/SurfaceCameraPreviewTest.java index 14a7e849..bbf024d1 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/SurfaceCameraPreviewTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/SurfaceCameraPreviewTest.java @@ -16,4 +16,14 @@ public class SurfaceCameraPreviewTest extends CameraPreviewTest { protected CameraPreview createPreview(Context context, ViewGroup parent, CameraPreview.SurfaceCallback callback) { return new SurfaceCameraPreview(context, parent, callback); } + + @Override + protected float getCropScaleX() { + return 1F; + } + + @Override + protected float getCropScaleY() { + return 1F; + } } diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/TextureCameraPreviewTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/TextureCameraPreviewTest.java index a050101c..866a851b 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/TextureCameraPreviewTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/TextureCameraPreviewTest.java @@ -40,4 +40,14 @@ public class TextureCameraPreviewTest extends CameraPreviewTest { private boolean isHardwareAccelerated() { return preview.getView().isHardwareAccelerated(); } + + @Override + protected float getCropScaleX() { + return preview.getView().getScaleX(); + } + + @Override + protected float getCropScaleY() { + return preview.getView().getScaleY(); + } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java index fbf27b7e..1d228e0d 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java @@ -24,6 +24,9 @@ class MediaRecorderVideoRecorder extends VideoRecorder { mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mProfile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH); // TODO: should get a profile of a quality compatible with the chosen size. + // Might do this by inspecting mResult.getSize(). However, it is not super important. + // We are only bound to respect the video size passed by the VideoSizeSelector, and + // we are doing that below. } // Camera2 constructor here... diff --git a/cameraview/src/main/views/com/otaliastudios/cameraview/GLCameraPreview.java b/cameraview/src/main/views/com/otaliastudios/cameraview/GLCameraPreview.java index 84500289..bf9245e5 100644 --- a/cameraview/src/main/views/com/otaliastudios/cameraview/GLCameraPreview.java +++ b/cameraview/src/main/views/com/otaliastudios/cameraview/GLCameraPreview.java @@ -192,8 +192,8 @@ class GLCameraPreview extends CameraPreview imple return true; } - private float mScaleX = 1F; - private float mScaleY = 1F; + /* for tests */ float mScaleX = 1F; + /* for tests */ float mScaleY = 1F; /** * To crop in GL, we could actually use view.setScaleX and setScaleY, but only from Android N onward.