From a2731f50b16f93b158df0e9d5500acdd773c7670 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Thu, 3 Jan 2019 18:42:00 +0100 Subject: [PATCH] Fix tests and rebase process --- .../cameraview/IntegrationTest.java | 9 ++-- .../com/otaliastudios/cameraview/Camera1.java | 42 +------------------ .../otaliastudios/cameraview/CameraView.java | 4 +- .../cameraview/FullVideoRecorder.java | 13 +++++- .../cameraview/PictureResult.java | 3 +- 5 files changed, 22 insertions(+), 49 deletions(-) diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/IntegrationTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/IntegrationTest.java index 15025fde..63fa4b83 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/IntegrationTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/IntegrationTest.java @@ -39,7 +39,7 @@ import static org.mockito.Mockito.mock; */ @RunWith(AndroidJUnit4.class) @MediumTest -@Ignore +// @Ignore public class IntegrationTest extends BaseTest { @Rule @@ -401,7 +401,7 @@ public class IntegrationTest extends BaseTest { // as documented. This works locally though. camera.setMode(Mode.VIDEO); waitForOpen(true); - camera.takeVideo(null, 4000); + camera.takeVideo(new File(context().getFilesDir(), "video.mp4"), 4000); waitForVideoEnd(true); } @@ -589,10 +589,9 @@ public class IntegrationTest extends BaseTest { public void testFrameProcessing_afterVideo() throws Exception { FrameProcessor processor = mock(FrameProcessor.class); camera.addFrameProcessor(processor); - camera.setSessionType(SessionType.VIDEO); + camera.setMode(Mode.VIDEO); waitForOpen(true); - - camera.startCapturingVideo(null, 2000); + camera.takeVideo(new File(context().getFilesDir(), "video.mp4"), 4000); waitForVideoEnd(true); assert30Frames(processor); diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java index e17ecdf9..3e34236b 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java @@ -661,7 +661,8 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera onVideoResult(null); return; } - mVideoRecorder = new FullVideoRecorder(videoResult, Camera1.this, mCamera, mCameraId); + mVideoRecorder = new FullVideoRecorder(videoResult, Camera1.this, + Camera1.this, mCamera, mCameraId); mVideoRecorder.start(); } }); @@ -763,45 +764,6 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera }); } - @Override - public void onVideoResult(@Nullable VideoResult result) { - if (result != null) { - mCameraCallbacks.dispatchOnVideoTaken(result); - } else { - // Something went wrong, lock the camera again. - mCamera.lock(); - } - } - - @WorkerThread - private void initMediaRecorder() { - mMediaRecorder = new MediaRecorder(); - mCamera.unlock(); - mMediaRecorder.setCamera(mCamera); - - mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); - if (mAudio == Audio.ON) { - // Must be called before setOutputFormat. - mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); - } - CamcorderProfile profile = getCamcorderProfile(); - mMediaRecorder.setOutputFormat(profile.fileFormat); - mMediaRecorder.setVideoFrameRate(profile.videoFrameRate); - mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight); - if (mVideoCodec == VideoCodec.DEFAULT) { - mMediaRecorder.setVideoEncoder(profile.videoCodec); - } else { - mMediaRecorder.setVideoEncoder(mMapper.map(mVideoCodec)); - } - mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate); - if (mAudio == Audio.ON) { - mMediaRecorder.setAudioChannels(profile.audioChannels); - mMediaRecorder.setAudioSamplingRate(profile.audioSampleRate); - mMediaRecorder.setAudioEncoder(profile.audioCodec); - mMediaRecorder.setAudioEncodingBitRate(profile.audioBitRate); - } - } - // ----------------- // Zoom and simpler stuff. diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java index 2b7f52e5..de0c5d24 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java @@ -1330,7 +1330,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { * @param durationMillis recording max duration * */ - public void takeVideo(@Nullable File file, int durationMillis) { + public void takeVideo(@NonNull File file, int durationMillis) { final int old = getVideoMaxDuration(); addCameraListener(new CameraListener() { @Override @@ -1365,7 +1365,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { * @param durationMillis recording max duration * */ - public void takeVideoSnapshot(@Nullable File file, int durationMillis) { + public void takeVideoSnapshot(@NonNull File file, int durationMillis) { final int old = getVideoMaxDuration(); addCameraListener(new CameraListener() { @Override diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java index 086a8a53..65359b34 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java @@ -16,9 +16,14 @@ class FullVideoRecorder extends VideoRecorder { private MediaRecorder mMediaRecorder; private CamcorderProfile mProfile; + private Camera1 mController; + private Camera mCamera; - FullVideoRecorder(@NonNull VideoResult stub, @Nullable VideoResultListener listener, @NonNull Camera camera, int cameraId) { + FullVideoRecorder(@NonNull VideoResult stub, @Nullable VideoResultListener listener, + @NonNull Camera1 controller, @NonNull Camera camera, int cameraId) { super(stub, listener); + mCamera = camera; + mController = controller; mMediaRecorder = new MediaRecorder(); mMediaRecorder.setCamera(camera); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); @@ -115,9 +120,15 @@ class FullVideoRecorder extends VideoRecorder { LOG.w("stop:", "Error while closing media recorder. Swallowing", e); } mMediaRecorder.release(); + if (mController != null) { + // Restore frame processing. + mCamera.setPreviewCallbackWithBuffer(mController); + } } mProfile = null; mMediaRecorder = null; + mCamera = null; + mController = null; dispatchResult(); } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/PictureResult.java b/cameraview/src/main/java/com/otaliastudios/cameraview/PictureResult.java index a28b68b1..82a26326 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/PictureResult.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/PictureResult.java @@ -1,5 +1,6 @@ package com.otaliastudios.cameraview; +import android.graphics.BitmapFactory; import android.location.Location; import java.io.File; @@ -97,7 +98,7 @@ public class PictureResult { * @param callback a callback to be notified of image decoding */ public void toBitmap(int maxWidth, int maxHeight, @NonNull BitmapCallback callback) { - CameraUtils.decodeBitmap(getData(), maxWidth, maxHeight, rotation, callback); + CameraUtils.decodeBitmap(getData(), maxWidth, maxHeight, new BitmapFactory.Options(), rotation, callback); } /**