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

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

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

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

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

@ -78,8 +78,16 @@ public class SnapshotVideoRecorder extends VideoRecorder implements RendererFram
}
@Override
protected void onStop() {
mDesiredState = STATE_NOT_RECORDING;
protected void onStop(boolean isCameraShutdown) {
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

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

Loading…
Cancel
Save