Refactor onVideoTaken, introducing VideoResult

pull/360/head
Mattia Iavarone 7 years ago
parent bd7a4d3cc9
commit 29c32090eb
  1. 1
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewCallbacksTest.java
  2. 13
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  3. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  4. 6
      cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java

@ -216,7 +216,6 @@ public class CameraViewCallbacksTest extends BaseTest {
verify(listener, times(1)).onCameraError(error); verify(listener, times(1)).onCameraError(error);
} }
@Test
public void testProcessFrame() { public void testProcessFrame() {
Frame mock = mock(Frame.class); Frame mock = mock(Frame.class);
completeTask().when(processor).process(mock); completeTask().when(processor).process(mock);

@ -616,6 +616,15 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
// ----------------- // -----------------
// Video recording stuff. // Video recording stuff.
@Override
public void onVideoResult(@Nullable VideoResult result) {
if (result != null) {
mCameraCallbacks.dispatchOnVideoTaken(result);
} else {
// Something went wrong, lock the camera again.
mCamera.lock();
}
}
@Override @Override
void takeVideo(@NonNull final File videoFile) { void takeVideo(@NonNull final File videoFile) {
@ -672,10 +681,6 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
// Something went wrong, lock the camera again. // Something went wrong, lock the camera again.
mCamera.lock(); mCamera.lock();
} }
if (mCamera != null) {
// This is needed to restore FrameProcessor. No re-allocation needed though.
mCamera.setPreviewCallbackWithBuffer(this);
}
} }
@WorkerThread @WorkerThread

@ -57,8 +57,6 @@ abstract class CameraController implements
protected FrameManager mFrameManager; protected FrameManager mFrameManager;
protected SizeSelector mPictureSizeSelector; protected SizeSelector mPictureSizeSelector;
protected SizeSelector mVideoSizeSelector; protected SizeSelector mVideoSizeSelector;
// protected MediaRecorder mMediaRecorder;
// protected VideoResult mVideoResult;
protected VideoRecorder mVideoRecorder; protected VideoRecorder mVideoRecorder;
protected long mVideoMaxSize; protected long mVideoMaxSize;
protected int mVideoMaxDuration; protected int mVideoMaxDuration;

@ -35,7 +35,11 @@ class MediaRecorderVideoRecorder extends VideoRecorder {
mMediaRecorder.setOutputFormat(mProfile.fileFormat); mMediaRecorder.setOutputFormat(mProfile.fileFormat);
mMediaRecorder.setVideoFrameRate(mProfile.videoFrameRate); mMediaRecorder.setVideoFrameRate(mProfile.videoFrameRate);
mMediaRecorder.setVideoSize(size.getWidth(), size.getHeight()); mMediaRecorder.setVideoSize(size.getWidth(), size.getHeight());
mMediaRecorder.setVideoEncoder(new Mapper1().map(mResult.getCodec())); if (mResult.getCodec() == VideoCodec.DEFAULT) {
mMediaRecorder.setVideoEncoder(mProfile.videoCodec);
} else {
mMediaRecorder.setVideoEncoder(new Mapper1().map(mResult.getCodec()));
}
mMediaRecorder.setVideoEncodingBitRate(mProfile.videoBitRate); mMediaRecorder.setVideoEncodingBitRate(mProfile.videoBitRate);
if (mResult.getAudio() == Audio.ON) { if (mResult.getAudio() == Audio.ON) {
mMediaRecorder.setAudioChannels(mProfile.audioChannels); mMediaRecorder.setAudioChannels(mProfile.audioChannels);

Loading…
Cancel
Save