Fix camerapreview tests

pull/360/head
Mattia Iavarone 6 years ago
parent 217d197fe8
commit caff00455f
  1. 8
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraPreviewTest.java
  2. 10
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/GLCameraPreviewTest.java
  3. 10
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/SurfaceCameraPreviewTest.java
  4. 10
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/TextureCameraPreviewTest.java
  5. 3
      cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java
  6. 4
      cameraview/src/main/views/com/otaliastudios/cameraview/GLCameraPreview.java

@ -149,8 +149,12 @@ public abstract class CameraPreviewTest extends BaseTest {
private float getViewAspectRatioWithScale() { private float getViewAspectRatioWithScale() {
Size size = preview.getOutputSurfaceSize(); Size size = preview.getOutputSurfaceSize();
int newWidth = (int) (((float) size.getWidth()) * preview.getView().getScaleX()); int newWidth = (int) (((float) size.getWidth()) * getCropScaleX());
int newHeight = (int) (((float) size.getHeight()) * preview.getView().getScaleY()); int newHeight = (int) (((float) size.getHeight()) * getCropScaleY());
return AspectRatio.of(newWidth, newHeight).toFloat(); return AspectRatio.of(newWidth, newHeight).toFloat();
} }
abstract protected float getCropScaleX();
abstract protected float getCropScaleY();
} }

@ -16,4 +16,14 @@ public class GLCameraPreviewTest extends CameraPreviewTest {
protected CameraPreview createPreview(Context context, ViewGroup parent, CameraPreview.SurfaceCallback callback) { protected CameraPreview createPreview(Context context, ViewGroup parent, CameraPreview.SurfaceCallback callback) {
return new GLCameraPreview(context, parent, 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;
}
} }

@ -16,4 +16,14 @@ public class SurfaceCameraPreviewTest extends CameraPreviewTest {
protected CameraPreview createPreview(Context context, ViewGroup parent, CameraPreview.SurfaceCallback callback) { protected CameraPreview createPreview(Context context, ViewGroup parent, CameraPreview.SurfaceCallback callback) {
return new SurfaceCameraPreview(context, parent, callback); return new SurfaceCameraPreview(context, parent, callback);
} }
@Override
protected float getCropScaleX() {
return 1F;
}
@Override
protected float getCropScaleY() {
return 1F;
}
} }

@ -40,4 +40,14 @@ public class TextureCameraPreviewTest extends CameraPreviewTest {
private boolean isHardwareAccelerated() { private boolean isHardwareAccelerated() {
return preview.getView().isHardwareAccelerated(); return preview.getView().isHardwareAccelerated();
} }
@Override
protected float getCropScaleX() {
return preview.getView().getScaleX();
}
@Override
protected float getCropScaleY() {
return preview.getView().getScaleY();
}
} }

@ -24,6 +24,9 @@ class MediaRecorderVideoRecorder extends VideoRecorder {
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mProfile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH); mProfile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
// TODO: should get a profile of a quality compatible with the chosen size. // 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... // Camera2 constructor here...

@ -192,8 +192,8 @@ class GLCameraPreview extends CameraPreview<GLSurfaceView, SurfaceTexture> imple
return true; return true;
} }
private float mScaleX = 1F; /* for tests */ float mScaleX = 1F;
private float mScaleY = 1F; /* for tests */ float mScaleY = 1F;
/** /**
* To crop in GL, we could actually use view.setScaleX and setScaleY, but only from Android N onward. * To crop in GL, we could actually use view.setScaleX and setScaleY, but only from Android N onward.

Loading…
Cancel
Save