Fix tests and rebase process

v2
Mattia Iavarone 6 years ago
parent fcf41c8d2c
commit 74878d7ef0
  1. 9
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/IntegrationTest.java
  2. 42
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  3. 4
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  4. 13
      cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java
  5. 3
      cameraview/src/main/java/com/otaliastudios/cameraview/PictureResult.java

@ -39,7 +39,7 @@ import static org.mockito.Mockito.mock;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@MediumTest @MediumTest
@Ignore // @Ignore
public class IntegrationTest extends BaseTest { public class IntegrationTest extends BaseTest {
@Rule @Rule
@ -401,7 +401,7 @@ public class IntegrationTest extends BaseTest {
// as documented. This works locally though. // as documented. This works locally though.
camera.setMode(Mode.VIDEO); camera.setMode(Mode.VIDEO);
waitForOpen(true); waitForOpen(true);
camera.takeVideo(null, 4000); camera.takeVideo(new File(context().getFilesDir(), "video.mp4"), 4000);
waitForVideoEnd(true); waitForVideoEnd(true);
} }
@ -589,10 +589,9 @@ public class IntegrationTest extends BaseTest {
public void testFrameProcessing_afterVideo() throws Exception { public void testFrameProcessing_afterVideo() throws Exception {
FrameProcessor processor = mock(FrameProcessor.class); FrameProcessor processor = mock(FrameProcessor.class);
camera.addFrameProcessor(processor); camera.addFrameProcessor(processor);
camera.setSessionType(SessionType.VIDEO); camera.setMode(Mode.VIDEO);
waitForOpen(true); waitForOpen(true);
camera.takeVideo(new File(context().getFilesDir(), "video.mp4"), 4000);
camera.startCapturingVideo(null, 2000);
waitForVideoEnd(true); waitForVideoEnd(true);
assert30Frames(processor); assert30Frames(processor);

@ -661,7 +661,8 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
onVideoResult(null); onVideoResult(null);
return; return;
} }
mVideoRecorder = new FullVideoRecorder(videoResult, Camera1.this, mCamera, mCameraId); mVideoRecorder = new FullVideoRecorder(videoResult, Camera1.this,
Camera1.this, mCamera, mCameraId);
mVideoRecorder.start(); 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. // Zoom and simpler stuff.

@ -1330,7 +1330,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param durationMillis recording max duration * @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(); final int old = getVideoMaxDuration();
addCameraListener(new CameraListener() { addCameraListener(new CameraListener() {
@Override @Override
@ -1365,7 +1365,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param durationMillis recording max duration * @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(); final int old = getVideoMaxDuration();
addCameraListener(new CameraListener() { addCameraListener(new CameraListener() {
@Override @Override

@ -16,9 +16,14 @@ class FullVideoRecorder extends VideoRecorder {
private MediaRecorder mMediaRecorder; private MediaRecorder mMediaRecorder;
private CamcorderProfile mProfile; 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); super(stub, listener);
mCamera = camera;
mController = controller;
mMediaRecorder = new MediaRecorder(); mMediaRecorder = new MediaRecorder();
mMediaRecorder.setCamera(camera); mMediaRecorder.setCamera(camera);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
@ -115,9 +120,15 @@ class FullVideoRecorder extends VideoRecorder {
LOG.w("stop:", "Error while closing media recorder. Swallowing", e); LOG.w("stop:", "Error while closing media recorder. Swallowing", e);
} }
mMediaRecorder.release(); mMediaRecorder.release();
if (mController != null) {
// Restore frame processing.
mCamera.setPreviewCallbackWithBuffer(mController);
}
} }
mProfile = null; mProfile = null;
mMediaRecorder = null; mMediaRecorder = null;
mCamera = null;
mController = null;
dispatchResult(); dispatchResult();
} }
} }

@ -1,5 +1,6 @@
package com.otaliastudios.cameraview; package com.otaliastudios.cameraview;
import android.graphics.BitmapFactory;
import android.location.Location; import android.location.Location;
import java.io.File; import java.io.File;
@ -97,7 +98,7 @@ public class PictureResult {
* @param callback a callback to be notified of image decoding * @param callback a callback to be notified of image decoding
*/ */
public void toBitmap(int maxWidth, int maxHeight, @NonNull BitmapCallback callback) { 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);
} }
/** /**

Loading…
Cancel
Save