pull/530/head
Mattia Iavarone 6 years ago
parent a553955a84
commit 13387dc89b
  1. 4
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/video/VideoRecorderTest.java
  2. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java
  3. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java
  4. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java
  5. 10
      cameraview/src/main/java/com/otaliastudios/cameraview/video/FullVideoRecorder.java
  6. 12
      cameraview/src/main/java/com/otaliastudios/cameraview/video/SnapshotVideoRecorder.java
  7. 9
      cameraview/src/main/java/com/otaliastudios/cameraview/video/VideoRecorder.java

@ -29,7 +29,7 @@ public class VideoRecorderTest extends BaseTest {
} }
@Override @Override
protected void onStop() { protected void onStop(boolean isCameraShutdown) {
dispatchVideoRecordingEnd(); dispatchVideoRecordingEnd();
dispatchResult(); dispatchResult();
} }
@ -37,7 +37,7 @@ public class VideoRecorderTest extends BaseTest {
recorder.start(result); recorder.start(result);
Mockito.verify(listener,Mockito.times(1) ) Mockito.verify(listener,Mockito.times(1) )
.onVideoRecordingStart(); .onVideoRecordingStart();
recorder.stop(); recorder.stop(false);
Mockito.verify(listener, Mockito.times(1)) Mockito.verify(listener, Mockito.times(1))
.onVideoRecordingEnd(); .onVideoRecordingEnd();
Mockito.verify(listener, Mockito.times(1)) Mockito.verify(listener, Mockito.times(1))

@ -231,7 +231,7 @@ public class Camera1Engine extends CameraEngine implements
@Override @Override
protected Task<Void> onStopPreview() { protected Task<Void> onStopPreview() {
if (mVideoRecorder != null) { if (mVideoRecorder != null) {
mVideoRecorder.stop(); mVideoRecorder.stop(true);
mVideoRecorder = null; mVideoRecorder = null;
} }
mPictureRecorder = null; mPictureRecorder = null;

@ -535,7 +535,7 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
if (mVideoRecorder != null) { if (mVideoRecorder != null) {
// This should synchronously call onVideoResult that will reset the repeating builder // This should synchronously call onVideoResult that will reset the repeating builder
// to the PREVIEW template. This is very important. // to the PREVIEW template. This is very important.
mVideoRecorder.stop(); mVideoRecorder.stop(true);
mVideoRecorder = null; mVideoRecorder = null;
} }
mPictureRecorder = null; mPictureRecorder = null;

@ -1189,7 +1189,7 @@ public abstract class CameraEngine implements
public void run() { public void run() {
LOG.i("stopVideo", "executing.", "isTakingVideo?", isTakingVideo()); LOG.i("stopVideo", "executing.", "isTakingVideo?", isTakingVideo());
if (mVideoRecorder != null) { if (mVideoRecorder != null) {
mVideoRecorder.stop(); mVideoRecorder.stop(false);
mVideoRecorder = null; mVideoRecorder = null;
} }
} }

@ -103,11 +103,11 @@ public abstract class FullVideoRecorder extends VideoRecorder {
switch (what) { switch (what) {
case MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED: case MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED:
mResult.endReason = VideoResult.REASON_MAX_DURATION_REACHED; mResult.endReason = VideoResult.REASON_MAX_DURATION_REACHED;
stop(); stop(false);
break; break;
case MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED: case MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED:
mResult.endReason = VideoResult.REASON_MAX_SIZE_REACHED; mResult.endReason = VideoResult.REASON_MAX_SIZE_REACHED;
stop(); stop(false);
break; break;
} }
} }
@ -130,7 +130,7 @@ public abstract class FullVideoRecorder extends VideoRecorder {
protected void onStart() { protected void onStart() {
if (!prepareMediaRecorder(mResult)) { if (!prepareMediaRecorder(mResult)) {
mResult = null; mResult = null;
stop(); stop(false);
return; return;
} }
@ -141,12 +141,12 @@ public abstract class FullVideoRecorder extends VideoRecorder {
LOG.w("start:", "Error while starting media recorder.", e); LOG.w("start:", "Error while starting media recorder.", e);
mResult = null; mResult = null;
mError = e; mError = e;
stop(); stop(false);
} }
} }
@Override @Override
protected void onStop() { protected void onStop(boolean isCameraShutdown) {
if (mMediaRecorder != null) { if (mMediaRecorder != null) {
dispatchVideoRecordingEnd(); dispatchVideoRecordingEnd();
try { try {

@ -78,8 +78,16 @@ public class SnapshotVideoRecorder extends VideoRecorder implements RendererFram
} }
@Override @Override
protected void onStop() { protected void onStop(boolean isCameraShutdown) {
mDesiredState = STATE_NOT_RECORDING; if (isCameraShutdown) {
// The renderer callback might never be called. From my tests, it's not.
LOG.i("Stopping the encoder engine from isCameraShutdown.");
mDesiredState = STATE_NOT_RECORDING;
mCurrentState = STATE_NOT_RECORDING;
mEncoderEngine.stop();
} else {
mDesiredState = STATE_NOT_RECORDING;
}
} }
@RendererThread @RendererThread

@ -64,9 +64,10 @@ public abstract class VideoRecorder {
/** /**
* Stops recording. * Stops recording.
* @param isCameraShutdown whether this is a full shutdown, camera is being closed
*/ */
public final void stop() { public final void stop(boolean isCameraShutdown) {
onStop(); onStop(isCameraShutdown);
} }
/** /**
@ -79,13 +80,12 @@ public abstract class VideoRecorder {
protected abstract void onStart(); protected abstract void onStart();
protected abstract void onStop(); protected abstract void onStop(boolean isCameraShutdown);
/** /**
* Subclasses can call this to notify that the result was obtained, * Subclasses can call this to notify that the result was obtained,
* either with some error (null result) or with the actual stub, filled. * either with some error (null result) or with the actual stub, filled.
*/ */
@SuppressWarnings("WeakerAccess")
@CallSuper @CallSuper
protected void dispatchResult() { protected void dispatchResult() {
mIsRecording = false; mIsRecording = false;
@ -112,6 +112,7 @@ public abstract class VideoRecorder {
* Subclasses can call this to notify that the video recording has ended, * Subclasses can call this to notify that the video recording has ended,
* although the video result might still be processed. * although the video result might still be processed.
*/ */
@SuppressWarnings("WeakerAccess")
@CallSuper @CallSuper
protected void dispatchVideoRecordingEnd() { protected void dispatchVideoRecordingEnd() {
if (mListener != null) { if (mListener != null) {

Loading…
Cancel
Save