From 8b66d5b5758c1ed9f32d119eb98c25ca88fad51e Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Sat, 25 May 2019 12:15:46 -0300 Subject: [PATCH] Quick fixes & bump version (#471) * Fix #460 * Fix #419 * Fix #443 * Bump version * Fix #425 * Fix test --- README.md | 2 +- cameraview/build.gradle | 2 +- .../cameraview/VideoRecorderTest.java | 2 +- .../com/otaliastudios/cameraview/Camera1.java | 8 ++++---- .../com/otaliastudios/cameraview/CameraView.java | 2 +- .../cameraview/FullVideoRecorder.java | 9 +++++++-- .../cameraview/SnapshotPictureRecorder.java | 7 +++++-- .../cameraview/SnapshotVideoRecorder.java | 7 ++++++- .../otaliastudios/cameraview/VideoRecorder.java | 6 ++++-- docs/_posts/2018-12-20-changelog.md | 15 ++++++++++++++- docs/_posts/2018-12-20-install.md | 2 +- 11 files changed, 45 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ac834d92..5362cea1 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ CameraView is a well documented, high-level library that makes capturing picture addressing most of the common issues and needs, and still leaving you with flexibility where needed. ```groovy -compile 'com.otaliastudios:cameraview:2.0.0-beta04' +compile 'com.otaliastudios:cameraview:2.0.0-beta05' ``` - Fast & reliable diff --git a/cameraview/build.gradle b/cameraview/build.gradle index be1a5062..739cfd01 100644 --- a/cameraview/build.gradle +++ b/cameraview/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' // Required by bintray -version = '2.0.0-beta04' +version = '2.0.0-beta05' group = 'com.otaliastudios' //region android dependencies diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoRecorderTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoRecorderTest.java index 2399f215..32de8692 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoRecorderTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoRecorderTest.java @@ -28,7 +28,7 @@ public class VideoRecorderTest extends BaseTest { }; recorder.start(); recorder.stop(); - Mockito.verify(listener, Mockito.times(1)).onVideoResult(result); + Mockito.verify(listener, Mockito.times(1)).onVideoResult(result, null); assertNull(recorder.mListener); assertNull(recorder.mResult); } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java index 1d54cde2..1d25a8c8 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java @@ -336,7 +336,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera return; } - LOG.e("Error inside the onError callback.", error); + LOG.e("Internal Camera1 error.", error); Exception runtime = new RuntimeException(CameraLogger.lastMessage); int reason; switch (error) { @@ -646,13 +646,13 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera // Video recording stuff. @Override - public void onVideoResult(@Nullable VideoResult result) { + public void onVideoResult(@Nullable VideoResult result, @Nullable Exception exception) { mVideoRecorder = null; if (result != null) { mCameraCallbacks.dispatchOnVideoTaken(result); } else { // Something went wrong, lock the camera again. - mCameraCallbacks.dispatchError(new CameraException(CameraException.REASON_VIDEO_FAILED)); + mCameraCallbacks.dispatchError(new CameraException(exception, CameraException.REASON_VIDEO_FAILED)); mCamera.lock(); } } @@ -689,7 +689,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera } catch (Exception e) { // If this failed, we are unlikely able to record the video. // Dispatch an error. - onVideoResult(null); + onVideoResult(null, e); return; } mVideoRecorder = new FullVideoRecorder(videoResult, Camera1.this, diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java index 35317995..eaf74e88 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java @@ -104,7 +104,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { Facing facing = Facing.fromValue(a.getInteger(R.styleable.CameraView_cameraFacing, Facing.DEFAULT(context).value())); Flash flash = Flash.fromValue(a.getInteger(R.styleable.CameraView_cameraFlash, Flash.DEFAULT.value())); Grid grid = Grid.fromValue(a.getInteger(R.styleable.CameraView_cameraGrid, Grid.DEFAULT.value())); - int gridColor = a.getColor(R.styleable.CameraView_cameraGrid, GridLinesLayout.DEFAULT_COLOR); + int gridColor = a.getColor(R.styleable.CameraView_cameraGridColor, GridLinesLayout.DEFAULT_COLOR); WhiteBalance whiteBalance = WhiteBalance.fromValue(a.getInteger(R.styleable.CameraView_cameraWhiteBalance, WhiteBalance.DEFAULT.value())); Mode mode = Mode.fromValue(a.getInteger(R.styleable.CameraView_cameraMode, Mode.DEFAULT.value())); Hdr hdr = Hdr.fromValue(a.getInteger(R.styleable.CameraView_cameraHdr, Hdr.DEFAULT.value())); diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java index 65359b34..4d26287d 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java @@ -104,7 +104,9 @@ class FullVideoRecorder extends VideoRecorder { mMediaRecorder.prepare(); mMediaRecorder.start(); } catch (Exception e) { + LOG.w("stop:", "Error while starting media recorder.", e); mResult = null; + mError = e; stop(); } } @@ -115,9 +117,12 @@ class FullVideoRecorder extends VideoRecorder { try { mMediaRecorder.stop(); } catch (Exception e) { - // This can happen if stopVideo() is called right after takeVideo(). We don't care. + LOG.w("stop:", "Error while closing media recorder.", e); + // This can happen if stopVideo() is called right after takeVideo() (in which case we don't care) + // Or when prepare()/start() have failed for some reason and we are not allowed to call stop. + // Make sure we don't override the error if one exists already. mResult = null; - LOG.w("stop:", "Error while closing media recorder. Swallowing", e); + if (mError == null) mError = e; } mMediaRecorder.release(); if (mController != null) { diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java index 444d5a70..bf197bd8 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java @@ -1,6 +1,7 @@ package com.otaliastudios.cameraview; import android.annotation.SuppressLint; +import android.annotation.TargetApi; import android.graphics.Bitmap; import android.graphics.ImageFormat; import android.graphics.Rect; @@ -10,6 +11,8 @@ import android.hardware.Camera; import android.opengl.EGL14; import android.opengl.EGLContext; import android.opengl.Matrix; +import android.os.Build; + import androidx.annotation.NonNull; import java.io.ByteArrayOutputStream; @@ -42,14 +45,14 @@ class SnapshotPictureRecorder extends PictureRecorder { @Override void take() { - if (mPreview instanceof GlCameraPreview) { + if (mPreview instanceof GlCameraPreview && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { takeGl((GlCameraPreview) mPreview); } else { takeLegacy(); } } - @SuppressLint("NewApi") + @TargetApi(Build.VERSION_CODES.KITKAT) private void takeGl(@NonNull final GlCameraPreview preview) { preview.addRendererFrameCallback(new GlCameraPreview.RendererFrameCallback() { diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotVideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotVideoRecorder.java index e707dec9..bf54ab14 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotVideoRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotVideoRecorder.java @@ -124,7 +124,9 @@ class SnapshotVideoRecorder extends VideoRecorder implements GlCameraPreview.Ren // If something failed, undo the result, since this is the mechanism // to notify Camera1 about this. if (e != null) { + LOG.e("Error onEncoderStop", e); mResult = null; + mError = e; } else { if (stopReason == MediaEncoderEngine.STOP_BY_MAX_DURATION) { mResult.endReason = VideoResult.REASON_MAX_DURATION_REACHED; @@ -132,11 +134,14 @@ class SnapshotVideoRecorder extends VideoRecorder implements GlCameraPreview.Ren mResult.endReason = VideoResult.REASON_MAX_SIZE_REACHED; } } - mEncoderEngine = null; + // Cleanup + mCurrentState = STATE_NOT_RECORDING; + mDesiredState = STATE_NOT_RECORDING; if (mPreview != null) { mPreview.removeRendererFrameCallback(SnapshotVideoRecorder.this); mPreview = null; } + mEncoderEngine = null; dispatchResult(); } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/VideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/VideoRecorder.java index 22d512b0..afd176c4 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/VideoRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/VideoRecorder.java @@ -12,6 +12,7 @@ abstract class VideoRecorder { /* tests */ VideoResult mResult; /* tests */ VideoResultListener mListener; + protected Exception mError; VideoRecorder(@NonNull VideoResult stub, @Nullable VideoResultListener listener) { mResult = stub; @@ -25,14 +26,15 @@ abstract class VideoRecorder { @SuppressWarnings("WeakerAccess") protected void dispatchResult() { if (mListener != null) { - mListener.onVideoResult(mResult); + mListener.onVideoResult(mResult, mError); mListener = null; mResult = null; + mError = null; } } interface VideoResultListener { - void onVideoResult(@Nullable VideoResult result); + void onVideoResult(@Nullable VideoResult result, @Nullable Exception exception); } } diff --git a/docs/_posts/2018-12-20-changelog.md b/docs/_posts/2018-12-20-changelog.md index 79fa8b22..b5523ccc 100644 --- a/docs/_posts/2018-12-20-changelog.md +++ b/docs/_posts/2018-12-20-changelog.md @@ -8,6 +8,13 @@ order: 3 New versions are released through GitHub, so the reference page is the [GitHub Releases](https://github.com/natario1/CameraView/releases) page. +### v2.0.0-beta05 + +- Fixed `FrameProcessor` freeze and release behavior, was broken ([#431][431]) +- New: new api `setAutoFocusResetDelay` to control the delay to reset the focus after autofocus was performed, thanks to [@cneuwirt][cneuwirt] ([#435][435]) +- Faster camera preview on layout changes ([#403][403]) +- A few bug fixes ([#471][471]) + ### v2.0.0-beta04 - Renames setPreviewSize to setPreviewStreamSize (previewSize suggests it is related to the view size but it's not) ([#393][393]) @@ -28,8 +35,14 @@ New versions are released through GitHub, so the reference page is the [GitHub R This is the first beta release. For changes with respect to v1, please take a look at the [migration guide](../extra/v1-migration-guide.html). +[cneuwirt]: https://github.com/cneuwirt + [356]: https://github.com/natario1/CameraView/pull/356 [360]: https://github.com/natario1/CameraView/pull/360 [374]: https://github.com/natario1/CameraView/pull/374 [392]: https://github.com/natario1/CameraView/pull/392 -[393]: https://github.com/natario1/CameraView/pull/393 \ No newline at end of file +[393]: https://github.com/natario1/CameraView/pull/393 +[471]: https://github.com/natario1/CameraView/pull/471 +[431]: https://github.com/natario1/CameraView/pull/431 +[403]: https://github.com/natario1/CameraView/pull/403 +[435]: https://github.com/natario1/CameraView/pull/435 \ No newline at end of file diff --git a/docs/_posts/2018-12-20-install.md b/docs/_posts/2018-12-20-install.md index be6bf81d..ab84bb9a 100644 --- a/docs/_posts/2018-12-20-install.md +++ b/docs/_posts/2018-12-20-install.md @@ -24,7 +24,7 @@ allprojects { Then simply download the latest version: ```groovy -api 'com.otaliastudios:cameraview:2.0.0-beta04' +api 'com.otaliastudios:cameraview:2.0.0-beta05' ``` No other configuration steps are needed. \ No newline at end of file