Skip to content

Commit 8b66d5b

Browse files
authored
Quick fixes & bump version (#471)
* Fix #460 * Fix #419 * Fix #443 * Bump version * Fix #425 * Fix test
1 parent b9620b7 commit 8b66d5b

File tree

11 files changed

+45
-17
lines changed

11 files changed

+45
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ CameraView is a well documented, high-level library that makes capturing picture
2222
addressing most of the common issues and needs, and still leaving you with flexibility where needed.
2323

2424
```groovy
25-
compile 'com.otaliastudios:cameraview:2.0.0-beta04'
25+
compile 'com.otaliastudios:cameraview:2.0.0-beta05'
2626
```
2727

2828
- Fast & reliable

cameraview/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'com.github.dcendents.android-maven'
33
apply plugin: 'com.jfrog.bintray'
44

55
// Required by bintray
6-
version = '2.0.0-beta04'
6+
version = '2.0.0-beta05'
77
group = 'com.otaliastudios'
88

99
//region android dependencies

cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoRecorderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void stop() {
2828
};
2929
recorder.start();
3030
recorder.stop();
31-
Mockito.verify(listener, Mockito.times(1)).onVideoResult(result);
31+
Mockito.verify(listener, Mockito.times(1)).onVideoResult(result, null);
3232
assertNull(recorder.mListener);
3333
assertNull(recorder.mResult);
3434
}

cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public void onError(int error, Camera camera) {
336336
return;
337337
}
338338

339-
LOG.e("Error inside the onError callback.", error);
339+
LOG.e("Internal Camera1 error.", error);
340340
Exception runtime = new RuntimeException(CameraLogger.lastMessage);
341341
int reason;
342342
switch (error) {
@@ -646,13 +646,13 @@ private boolean isCameraAvailable() {
646646
// Video recording stuff.
647647

648648
@Override
649-
public void onVideoResult(@Nullable VideoResult result) {
649+
public void onVideoResult(@Nullable VideoResult result, @Nullable Exception exception) {
650650
mVideoRecorder = null;
651651
if (result != null) {
652652
mCameraCallbacks.dispatchOnVideoTaken(result);
653653
} else {
654654
// Something went wrong, lock the camera again.
655-
mCameraCallbacks.dispatchError(new CameraException(CameraException.REASON_VIDEO_FAILED));
655+
mCameraCallbacks.dispatchError(new CameraException(exception, CameraException.REASON_VIDEO_FAILED));
656656
mCamera.lock();
657657
}
658658
}
@@ -689,7 +689,7 @@ public void run() {
689689
} catch (Exception e) {
690690
// If this failed, we are unlikely able to record the video.
691691
// Dispatch an error.
692-
onVideoResult(null);
692+
onVideoResult(null, e);
693693
return;
694694
}
695695
mVideoRecorder = new FullVideoRecorder(videoResult, Camera1.this,

cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private void init(@NonNull Context context, @Nullable AttributeSet attrs) {
104104
Facing facing = Facing.fromValue(a.getInteger(R.styleable.CameraView_cameraFacing, Facing.DEFAULT(context).value()));
105105
Flash flash = Flash.fromValue(a.getInteger(R.styleable.CameraView_cameraFlash, Flash.DEFAULT.value()));
106106
Grid grid = Grid.fromValue(a.getInteger(R.styleable.CameraView_cameraGrid, Grid.DEFAULT.value()));
107-
int gridColor = a.getColor(R.styleable.CameraView_cameraGrid, GridLinesLayout.DEFAULT_COLOR);
107+
int gridColor = a.getColor(R.styleable.CameraView_cameraGridColor, GridLinesLayout.DEFAULT_COLOR);
108108
WhiteBalance whiteBalance = WhiteBalance.fromValue(a.getInteger(R.styleable.CameraView_cameraWhiteBalance, WhiteBalance.DEFAULT.value()));
109109
Mode mode = Mode.fromValue(a.getInteger(R.styleable.CameraView_cameraMode, Mode.DEFAULT.value()));
110110
Hdr hdr = Hdr.fromValue(a.getInteger(R.styleable.CameraView_cameraHdr, Hdr.DEFAULT.value()));

cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public void onInfo(MediaRecorder mediaRecorder, int what, int extra) {
104104
mMediaRecorder.prepare();
105105
mMediaRecorder.start();
106106
} catch (Exception e) {
107+
LOG.w("stop:", "Error while starting media recorder.", e);
107108
mResult = null;
109+
mError = e;
108110
stop();
109111
}
110112
}
@@ -115,9 +117,12 @@ void stop() {
115117
try {
116118
mMediaRecorder.stop();
117119
} catch (Exception e) {
118-
// This can happen if stopVideo() is called right after takeVideo(). We don't care.
120+
LOG.w("stop:", "Error while closing media recorder.", e);
121+
// This can happen if stopVideo() is called right after takeVideo() (in which case we don't care)
122+
// Or when prepare()/start() have failed for some reason and we are not allowed to call stop.
123+
// Make sure we don't override the error if one exists already.
119124
mResult = null;
120-
LOG.w("stop:", "Error while closing media recorder. Swallowing", e);
125+
if (mError == null) mError = e;
121126
}
122127
mMediaRecorder.release();
123128
if (mController != null) {

cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.otaliastudios.cameraview;
22

33
import android.annotation.SuppressLint;
4+
import android.annotation.TargetApi;
45
import android.graphics.Bitmap;
56
import android.graphics.ImageFormat;
67
import android.graphics.Rect;
@@ -10,6 +11,8 @@
1011
import android.opengl.EGL14;
1112
import android.opengl.EGLContext;
1213
import android.opengl.Matrix;
14+
import android.os.Build;
15+
1316
import androidx.annotation.NonNull;
1417

1518
import java.io.ByteArrayOutputStream;
@@ -42,14 +45,14 @@ class SnapshotPictureRecorder extends PictureRecorder {
4245

4346
@Override
4447
void take() {
45-
if (mPreview instanceof GlCameraPreview) {
48+
if (mPreview instanceof GlCameraPreview && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
4649
takeGl((GlCameraPreview) mPreview);
4750
} else {
4851
takeLegacy();
4952
}
5053
}
5154

52-
@SuppressLint("NewApi")
55+
@TargetApi(Build.VERSION_CODES.KITKAT)
5356
private void takeGl(@NonNull final GlCameraPreview preview) {
5457
preview.addRendererFrameCallback(new GlCameraPreview.RendererFrameCallback() {
5558

cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotVideoRecorder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,24 @@ public void onEncoderStop(int stopReason, @Nullable Exception e) {
124124
// If something failed, undo the result, since this is the mechanism
125125
// to notify Camera1 about this.
126126
if (e != null) {
127+
LOG.e("Error onEncoderStop", e);
127128
mResult = null;
129+
mError = e;
128130
} else {
129131
if (stopReason == MediaEncoderEngine.STOP_BY_MAX_DURATION) {
130132
mResult.endReason = VideoResult.REASON_MAX_DURATION_REACHED;
131133
} else if (stopReason == MediaEncoderEngine.STOP_BY_MAX_SIZE) {
132134
mResult.endReason = VideoResult.REASON_MAX_SIZE_REACHED;
133135
}
134136
}
135-
mEncoderEngine = null;
137+
// Cleanup
138+
mCurrentState = STATE_NOT_RECORDING;
139+
mDesiredState = STATE_NOT_RECORDING;
136140
if (mPreview != null) {
137141
mPreview.removeRendererFrameCallback(SnapshotVideoRecorder.this);
138142
mPreview = null;
139143
}
144+
mEncoderEngine = null;
140145
dispatchResult();
141146
}
142147
}

cameraview/src/main/java/com/otaliastudios/cameraview/VideoRecorder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ abstract class VideoRecorder {
1212

1313
/* tests */ VideoResult mResult;
1414
/* tests */ VideoResultListener mListener;
15+
protected Exception mError;
1516

1617
VideoRecorder(@NonNull VideoResult stub, @Nullable VideoResultListener listener) {
1718
mResult = stub;
@@ -25,14 +26,15 @@ abstract class VideoRecorder {
2526
@SuppressWarnings("WeakerAccess")
2627
protected void dispatchResult() {
2728
if (mListener != null) {
28-
mListener.onVideoResult(mResult);
29+
mListener.onVideoResult(mResult, mError);
2930
mListener = null;
3031
mResult = null;
32+
mError = null;
3133
}
3234
}
3335

3436

3537
interface VideoResultListener {
36-
void onVideoResult(@Nullable VideoResult result);
38+
void onVideoResult(@Nullable VideoResult result, @Nullable Exception exception);
3739
}
3840
}

docs/_posts/2018-12-20-changelog.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ order: 3
88

99
New versions are released through GitHub, so the reference page is the [GitHub Releases](https://github.com/natario1/CameraView/releases) page.
1010

11+
### v2.0.0-beta05
12+
13+
- Fixed `FrameProcessor` freeze and release behavior, was broken ([#431][431])
14+
- New: new api `setAutoFocusResetDelay` to control the delay to reset the focus after autofocus was performed, thanks to [@cneuwirt][cneuwirt] ([#435][435])
15+
- Faster camera preview on layout changes ([#403][403])
16+
- A few bug fixes ([#471][471])
17+
1118
### v2.0.0-beta04
1219

1320
- 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
2835

2936
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).
3037

38+
[cneuwirt]: https://github.com/cneuwirt
39+
3140
[356]: https://github.com/natario1/CameraView/pull/356
3241
[360]: https://github.com/natario1/CameraView/pull/360
3342
[374]: https://github.com/natario1/CameraView/pull/374
3443
[392]: https://github.com/natario1/CameraView/pull/392
35-
[393]: https://github.com/natario1/CameraView/pull/393
44+
[393]: https://github.com/natario1/CameraView/pull/393
45+
[471]: https://github.com/natario1/CameraView/pull/471
46+
[431]: https://github.com/natario1/CameraView/pull/431
47+
[403]: https://github.com/natario1/CameraView/pull/403
48+
[435]: https://github.com/natario1/CameraView/pull/435

0 commit comments

Comments
 (0)