diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/video/SnapshotVideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/video/SnapshotVideoRecorder.java index 8031dad0..34d7f5da 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/video/SnapshotVideoRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/video/SnapshotVideoRecorder.java @@ -183,26 +183,17 @@ public class SnapshotVideoRecorder extends VideoRecorder implements RendererFram } if (mEncoderEngine != null) { - // can happen on teardown + // Can happen on teardown. At least it used to. + // NOTE: If this still happens, I would say we can still crash on mOverlaySurface + // calls above. We might have to add some synchronization. mEncoderEngine.notify(TextureMediaEncoder.FRAME_EVENT, frame); } } if (mCurrentState == STATE_RECORDING && mDesiredState == STATE_NOT_RECORDING) { LOG.i("Stopping the encoder engine."); - mCurrentState = STATE_NOT_RECORDING; // before nulling encoderEngine! + mCurrentState = STATE_NOT_RECORDING; mEncoderEngine.stop(); - mEncoderEngine = null; - mPreview.removeRendererFrameCallback(SnapshotVideoRecorder.this); - mPreview = null; - if (mOverlaySurfaceTexture != null) { - mOverlaySurfaceTexture.release(); - mOverlaySurfaceTexture = null; - } - if (mOverlaySurface != null) { - mOverlaySurface.release(); - mOverlaySurface = null; - } } } @@ -241,6 +232,15 @@ public class SnapshotVideoRecorder extends VideoRecorder implements RendererFram mCurrentState = STATE_NOT_RECORDING; mDesiredState = STATE_NOT_RECORDING; mPreview.removeRendererFrameCallback(SnapshotVideoRecorder.this); + mPreview = null; + if (mOverlaySurfaceTexture != null) { + mOverlaySurfaceTexture.release(); + mOverlaySurfaceTexture = null; + } + if (mOverlaySurface != null) { + mOverlaySurface.release(); + mOverlaySurface = null; + } mEncoderEngine = null; dispatchResult(); } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/AudioMediaEncoder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/AudioMediaEncoder.java index 070eb82f..62a060f1 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/AudioMediaEncoder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/AudioMediaEncoder.java @@ -28,7 +28,7 @@ public class AudioMediaEncoder extends MediaEncoder { private static final String TAG = AudioMediaEncoder.class.getSimpleName(); private static final CameraLogger LOG = CameraLogger.create(TAG); - private static final boolean PERFORMANCE_DEBUG = true; + private static final boolean PERFORMANCE_DEBUG = false; private static final boolean PERFORMANCE_FILL_GAPS = true; private boolean mRequestStop = false; diff --git a/demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java b/demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java index 7fdcfb89..6af85d2f 100644 --- a/demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java +++ b/demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java @@ -44,7 +44,7 @@ import java.util.List; public class CameraActivity extends AppCompatActivity implements View.OnClickListener, OptionView.Callback { private final static CameraLogger LOG = CameraLogger.create("DemoApp"); - private final static boolean USE_FRAME_PROCESSOR = true; + private final static boolean USE_FRAME_PROCESSOR = false; private final static boolean DECODE_BITMAP = true; private CameraView camera;