From d462b8304827a55205e0e54c9a78361fa5107ce9 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Sat, 23 Feb 2019 15:52:41 +0100 Subject: [PATCH] v2.0.0-beta03 (#392) * Fix #377 and update dependencies * Fix #384 * Fix unbindFromSurface bug * Bump version to v2.0.0-beta03 * Update build.gradle --- README.md | 2 +- cameraview/build.gradle | 2 +- .../com/otaliastudios/cameraview/EglCore.java | 19 ++---------- .../com/otaliastudios/cameraview/Camera1.java | 29 ++++++++++++++----- .../cameraview/CameraController.java | 2 +- .../otaliastudios/cameraview/CameraView.java | 1 - demo/build.gradle | 4 +-- demo/src/main/AndroidManifest.xml | 4 +-- docs/_posts/2018-12-20-changelog.md | 9 +++++- docs/_posts/2018-12-20-install.md | 2 +- 10 files changed, 39 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 566d0e9c9..01f3ac6b1 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-beta02' +compile 'com.otaliastudios:cameraview:2.0.0-beta03' ``` - Fast & reliable diff --git a/cameraview/build.gradle b/cameraview/build.gradle index aa0d58193..07e871c79 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-beta02' +version = '2.0.0-beta03' group = 'com.otaliastudios' //region android dependencies diff --git a/cameraview/src/main/gles/com/otaliastudios/cameraview/EglCore.java b/cameraview/src/main/gles/com/otaliastudios/cameraview/EglCore.java index 2483978dc..62f1f6d97 100644 --- a/cameraview/src/main/gles/com/otaliastudios/cameraview/EglCore.java +++ b/cameraview/src/main/gles/com/otaliastudios/cameraview/EglCore.java @@ -137,7 +137,7 @@ public EglCore(EGLContext sharedContext, int flags) { int[] values = new int[1]; EGL14.eglQueryContext(mEGLDisplay, mEGLContext, EGL14.EGL_CONTEXT_CLIENT_VERSION, values, 0); - Log.d(TAG, "EGLContext created, client version " + values[0]); + // Log.d(TAG, "EGLContext created, client version " + values[0]); } /** @@ -273,7 +273,7 @@ public EGLSurface createOffscreenSurface(int width, int height) { public void makeCurrent(EGLSurface eglSurface) { if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) { // called makeCurrent() before create? - Log.d(TAG, "NOTE: makeCurrent w/o display"); + // Log.d(TAG, "NOTE: makeCurrent w/o display"); } if (!EGL14.eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext)) { throw new RuntimeException("eglMakeCurrent failed"); @@ -351,21 +351,6 @@ public int getGlVersion() { return mGlVersion; } - /** - * Writes the current display, context, and surface to the log. - */ - public static void logCurrent(String msg) { - EGLDisplay display; - EGLContext context; - EGLSurface surface; - - display = EGL14.eglGetCurrentDisplay(); - context = EGL14.eglGetCurrentContext(); - surface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW); - Log.i(TAG, "Current EGL (" + msg + "): display=" + display + ", context=" + context + - ", surface=" + surface); - } - /** * Checks for EGL errors. Throws an exception if an error has been raised. */ diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java index 72bc6993e..7c6f9b52d 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java @@ -66,7 +66,10 @@ public void run() { }); } - // Preview surface is now available. If camera is open, set up. + /** + * Preview surface is now available. If camera is open, set up. + * At this point we are sure that mPreview is not null. + */ @Override public void onSurfaceAvailable() { LOG.i("onSurfaceAvailable:", "Size is", mPreview.getOutputSurfaceSize()); @@ -80,8 +83,11 @@ public void run() { }); } - // Preview surface did change its size. Compute a new preview size. - // This requires stopping and restarting the preview. + /** + * Preview surface did change its size. Compute a new preview size. + * This requires stopping and restarting the preview. + * At this point we are sure that mPreview is not null. + */ @Override public void onSurfaceChanged() { LOG.i("onSurfaceChanged, size is", mPreview.getOutputSurfaceSize()); @@ -119,8 +125,11 @@ private boolean shouldBindToSurface() { return isCameraAvailable() && mPreview != null && mPreview.hasSurface() && !mIsBound; } - // The act of binding an "open" camera to a "ready" preview. - // These can happen at different times but we want to end up here. + /** + * The act of binding an "open" camera to a "ready" preview. + * These can happen at different times but we want to end up here. + * At this point we are sure that mPreview is not null. + */ @WorkerThread private void bindToSurface() { LOG.i("bindToSurface:", "Started"); @@ -275,7 +284,7 @@ void onStop() { } if (mCamera != null) { stopPreview(); - unbindFromSurface(); + if (mIsBound) unbindFromSurface(); destroyCamera(); } mCameraOptions = null; @@ -440,8 +449,12 @@ private boolean applyPlaySounds(boolean oldPlaySound) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(mCameraId, info); if (info.canDisableShutterSound) { - mCamera.enableShutterSound(mPlaySounds); - return true; + try { + // this method is documented to throw on some occasions. #377 + return mCamera.enableShutterSound(mPlaySounds); + } catch (RuntimeException exception) { + return false; + } } } if (mPlaySounds) { diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java index d60637877..cfedbb9c5 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java @@ -91,7 +91,7 @@ abstract class CameraController implements mFrameManager = new FrameManager(2, this); } - void setPreview(CameraPreview cameraPreview) { + void setPreview(@NonNull CameraPreview cameraPreview) { mPreview = cameraPreview; mPreview.setSurfaceCallback(this); } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java index f7c979fff..7f2f62136 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java @@ -602,7 +602,6 @@ public void setLifecycleOwner(@NonNull LifecycleOwner owner) { public void open() { if (!isEnabled()) return; if (mCameraPreview != null) mCameraPreview.onResume(); - if (checkPermissions(getAudio())) { // Update display orientation for current CameraController mOrientationHelper.enable(getContext()); diff --git a/demo/build.gradle b/demo/build.gradle index 51bcb2f12..be25003a4 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -23,6 +23,6 @@ android { dependencies { implementation project(':cameraview') - implementation 'androidx.appcompat:appcompat:1.1.0-alpha01' - implementation 'com.google.android.material:material:1.1.0-alpha02' + implementation 'androidx.appcompat:appcompat:1.1.0-alpha02' + implementation 'com.google.android.material:material:1.1.0-alpha03' } diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml index 91853314d..15d6c9eaf 100644 --- a/demo/src/main/AndroidManifest.xml +++ b/demo/src/main/AndroidManifest.xml @@ -15,9 +15,9 @@ + android:screenOrientation="portrait" + android:hardwareAccelerated="true"> diff --git a/docs/_posts/2018-12-20-changelog.md b/docs/_posts/2018-12-20-changelog.md index 41a4495ad..1a924184f 100644 --- a/docs/_posts/2018-12-20-changelog.md +++ b/docs/_posts/2018-12-20-changelog.md @@ -8,6 +8,11 @@ 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-beta03 + +- Fixed a few bugs ([#392][392]) +- Important fixes to video snapshot recording ([#374][374]) + ### v2.0.0-beta02 - Fixed important bugs ([#356][356]) @@ -19,4 +24,6 @@ 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). [356]: https://github.com/natario1/CameraView/pull/356 -[360]: https://github.com/natario1/CameraView/pull/360 \ No newline at end of file +[360]: https://github.com/natario1/CameraView/pull/360 +[374]: https://github.com/natario1/CameraView/pull/374 +[392]: https://github.com/natario1/CameraView/pull/392 \ 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 0683c4cc8..917a56e9f 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-beta02' +api 'com.otaliastudios:cameraview:2.0.0-beta03' ``` No other configuration steps are needed. \ No newline at end of file