Skip to content

Commit

Permalink
Fix: Cannot process multiple parallel takePicture. Need to wait for…
Browse files Browse the repository at this point in the history
… on request to finish first. (google#97)

Prev to this change, Samsung Galaxy S4 crashes in demo app due to this error:
```
[CAM-BACK]-ERR(virtual android::status_t android::ExynosCameraHWImpl::takePicture()):capture already in progress
java.lang.RuntimeException: takePicture failed
  at android.hardware.Camera.native_takePicture(Native Method)
  at android.hardware.Camera.takePicture(Camera.java:1338)
  at com.google.android.cameraview.Camera1.takePictureInternal(Unknown Source)
  at com.google.android.cameraview.Camera1$2.onAutoFocus(Unknown Source)
```
  • Loading branch information
lytefast authored and yaraki committed Mar 13, 2017
1 parent 07a9806 commit ab3b778
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions library/src/main/api14/com/google/android/cameraview/Camera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.atomic.AtomicBoolean;


@SuppressWarnings("deprecation")
class Camera1 extends CameraViewImpl {
Expand All @@ -45,6 +47,8 @@ class Camera1 extends CameraViewImpl {

private int mCameraId;

private final AtomicBoolean isPictureCaptureInProgress = new AtomicBoolean(false);

Camera mCamera;

private Camera.Parameters mCameraParameters;
Expand Down Expand Up @@ -227,14 +231,17 @@ public void onAutoFocus(boolean success, Camera camera) {
}

void takePictureInternal() {
mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
mCallback.onPictureTaken(data);
camera.cancelAutoFocus();
camera.startPreview();
}
});
if (!isPictureCaptureInProgress.getAndSet(true)) {
mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
isPictureCaptureInProgress.set(false);
mCallback.onPictureTaken(data);
camera.cancelAutoFocus();
camera.startPreview();
}
});
}
}

@Override
Expand Down

0 comments on commit ab3b778

Please sign in to comment.