diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/PictureResultTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/PictureResultTest.java index 950315b4..a99531a5 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/PictureResultTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/PictureResultTest.java @@ -27,12 +27,14 @@ public class PictureResultTest extends BaseTest { byte[] jpeg = new byte[]{2, 4, 1, 5, 2}; Location location = Mockito.mock(Location.class); boolean isSnapshot = true; + Facing facing = Facing.FRONT; result. format = format; result.rotation = rotation; result.size = size; result.data = jpeg; result.location = location; + result.facing = facing; //noinspection ConstantConditions result.isSnapshot = isSnapshot; @@ -43,5 +45,6 @@ public class PictureResultTest extends BaseTest { assertEquals(result.getLocation(), location); //noinspection ConstantConditions assertEquals(result.isSnapshot(), isSnapshot); + assertEquals(result.getFacing(), facing); } } diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoResultTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoResultTest.java index ec174210..503523b1 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoResultTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoResultTest.java @@ -36,6 +36,7 @@ public class VideoResultTest extends BaseTest { int videoBitRate = 300000; int audioBitRate = 30000; Audio audio = Audio.ON; + Facing facing = Facing.FRONT; result.file = file; result.rotation = rotation; @@ -50,6 +51,7 @@ public class VideoResultTest extends BaseTest { result.videoBitRate = videoBitRate; result.audioBitRate = audioBitRate; result.audio = audio; + result.facing = facing; assertEquals(result.getFile(), file); assertEquals(result.getRotation(), rotation); @@ -64,5 +66,7 @@ public class VideoResultTest extends BaseTest { assertEquals(result.getVideoBitRate(), videoBitRate); assertEquals(result.getAudioBitRate(), audioBitRate); assertEquals(result.getAudio(), audio); + assertEquals(result.getFacing(), facing); + } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java index 80dd92ba..72bc6993 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java @@ -554,6 +554,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera result.location = mLocation; result.rotation = offset(REF_SENSOR, REF_OUTPUT); result.size = getPictureSize(REF_OUTPUT); + result.facing = mFacing; mPictureRecorder = new FullPictureRecorder(result, Camera1.this, mCamera); mPictureRecorder.take(); } @@ -573,6 +574,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera PictureResult result = new PictureResult(); result.location = mLocation; result.isSnapshot = true; + result.facing = mFacing; result.size = getPreviewSize(REF_OUTPUT); // Not the real size: it will be cropped to match the view ratio result.rotation = offset(REF_SENSOR, REF_OUTPUT); // Actually it will be rotated and set to 0. AspectRatio outputRatio = flip(REF_OUTPUT, REF_VIEW) ? viewAspectRatio.inverse() : viewAspectRatio; @@ -653,6 +655,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera videoResult.isSnapshot = false; videoResult.codec = mVideoCodec; videoResult.location = mLocation; + videoResult.facing = mFacing; videoResult.rotation = offset(REF_SENSOR, REF_OUTPUT); videoResult.size = flip(REF_SENSOR, REF_OUTPUT) ? mCaptureSize.flip() : mCaptureSize; videoResult.audio = mAudio; @@ -697,6 +700,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera videoResult.isSnapshot = true; videoResult.codec = mVideoCodec; videoResult.location = mLocation; + videoResult.facing = mFacing; videoResult.videoBitRate = mVideoBitRate; videoResult.audioBitRate = mAudioBitRate; videoResult.audio = mAudio; diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/PictureResult.java b/cameraview/src/main/java/com/otaliastudios/cameraview/PictureResult.java index 82a26326..282a2980 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/PictureResult.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/PictureResult.java @@ -21,6 +21,7 @@ public class PictureResult { Location location; int rotation; Size size; + Facing facing; byte[] data; int format; @@ -67,6 +68,16 @@ public class PictureResult { return size; } + /** + * Returns the facing value with which this video was recorded. + * + * @return the Facing of this video + */ + @NonNull + public Facing getFacing() { + return facing; + } + /** * Returns the raw compressed, ready to be saved to file, * in the given format. diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java index 8dd3e7c9..11fb97dc 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java @@ -113,13 +113,24 @@ class SnapshotPictureRecorder extends PictureRecorder { Matrix.translateM(mTransform, 0, scaleTranslX, scaleTranslY, 0); Matrix.scaleM(mTransform, 0, realScaleX, realScaleY, 1); - // Apply rotation: + // Fix rotation: // TODO Not sure why we need the minus here... It makes no sense to me. LOG.w("Recording frame. Rotation:", mResult.rotation, "Actual:", -mResult.rotation); int rotation = -mResult.rotation; mResult.rotation = 0; + + // Go back to 0,0 so that rotate and flip work well. Matrix.translateM(mTransform, 0, 0.5F, 0.5F, 0); + + // Apply rotation: Matrix.rotateM(mTransform, 0, rotation, 0, 0, 1); + + // Flip horizontally for front camera: + if (mResult.facing == Facing.FRONT) { + Matrix.scaleM(mTransform, 0, -1, 1, 1); + } + + // Go back to old position. Matrix.translateM(mTransform, 0, -0.5F, -0.5F, 0); // Future note: passing scale values to the viewport? diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java b/cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java index 0c0219d8..806556b6 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java @@ -25,6 +25,7 @@ public class VideoResult { int rotation; Size size; File file; + Facing facing; VideoCodec codec; Audio audio; long maxSize; @@ -87,6 +88,16 @@ public class VideoResult { return file; } + /** + * Returns the facing value with which this video was recorded. + * + * @return the Facing of this video + */ + @NonNull + public Facing getFacing() { + return facing; + } + /** * Returns the codec that was used to encode the video frames. * diff --git a/codecov.yml b/codecov.yml index 3c22eb79..2694c73f 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,12 +1,12 @@ coverage: precision: 1 round: down - range: "40...100" + range: "30...70" status: project: default: - target: 45% + target: 40% patch: default: target: 70%