ImageCapture takePicture onCaptureSuccess never called - OnePlus 8

827 views
Skip to first unread message

Marvin Effing

unread,
Jan 24, 2022, 5:27:13 AM1/24/22
to Android CameraX Discussion Group
We are encountering a bug that is very device specific, namely it occurs only on OnePlus 8 device and no other type. When calling to take a picture with the image capture use case "imageCapture.takePicture" is called but the subsequent "onCaptureSuccess(...)` or `onError(...)" is never called. So it appears that it remains stuck trying to take a picture on a hardware level, but the resulting image capture is never returned for callback handling.

The logcat suggests this too:

2022-01-24 10:59:59.898 15627-15849/<app-under-test> D/ImageCapture: issueTakePicture
2022-01-24 10:59:59.899 15627-15710/<app-under-test> D/Camera2CameraImpl: {Camera@1dac21d[id=0]} Use case ImageCapture:androidx.camera.core.ImageCapture-21e8d004-8e93-4ab1-aa0a-c92d2f4be691 ACTIVE
2022-01-24 10:59:59.899 15627-15710/<app-under-test> D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.Preview-9ceffccc-743d-4821-bd28-b48e8a4cb5bd267903828] for camera: 0
2022-01-24 10:59:59.900 15627-15710/<app-under-test> D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.Preview-9ceffccc-743d-4821-bd28-b48e8a4cb5bd267903828] for camera: 0
2022-01-24 10:59:59.900 15627-15710/<app-under-test> D/Camera2CameraImpl: {Camera@1dac21d[id=0]} Use cases [ImageCapture:androidx.camera.core.ImageCapture-21e8d004-8e93-4ab1-aa0a-c92d2f4be691] now ATTACHED
2022-01-24 10:59:59.900 15627-15710/<app-under-test> D/UseCaseAttachState: All use case: [androidx.camera.core.ImageCapture-21e8d004-8e93-4ab1-aa0a-c92d2f4be691132436577, androidx.camera.core.Preview-9ceffccc-743d-4821-bd28-b48e8a4cb5bd267903828] for camera: 0
2022-01-24 10:59:59.900 15627-15710/<app-under-test> D/Camera2CameraImpl: mMeteringRepeating is ATTACHED, SessionConfig Surfaces: 2, CaptureConfig Surfaces: 1
2022-01-24 10:59:59.900 15627-15710/<app-under-test> D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.ImageCapture-21e8d004-8e93-4ab1-aa0a-c92d2f4be691132436577, androidx.camera.core.Preview-9ceffccc-743d-4821-bd28-b48e8a4cb5bd267903828] for camera: 0
2022-01-24 10:59:59.901 15627-15710/<app-under-test> D/Camera2CameraImpl: {Camera@1dac21d[id=0]} Resetting Capture Session
2022-01-24 10:59:59.901 15627-15710/<app-under-test> D/Camera2CameraImpl: {Camera@1dac21d[id=0]} Releasing session in state OPENED
2022-01-24 10:59:59.901 15627-15710/<app-under-test> D/UseCaseAttachState: All use case: [androidx.camera.core.ImageCapture-21e8d004-8e93-4ab1-aa0a-c92d2f4be691132436577, androidx.camera.core.Preview-9ceffccc-743d-4821-bd28-b48e8a4cb5bd267903828] for camera: 0
2022-01-24 10:59:59.902 15627-15710/<app-under-test> D/Camera2CameraImpl: {Camera@1dac21d[id=0]} Use case ImageCapture:androidx.camera.core.ImageCapture-21e8d004-8e93-4ab1-aa0a-c92d2f4be691 ACTIVE
2022-01-24 10:59:59.902 15627-15710/<app-under-test> D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.ImageCapture-21e8d004-8e93-4ab1-aa0a-c92d2f4be691132436577, androidx.camera.core.Preview-9ceffccc-743d-4821-bd28-b48e8a4cb5bd267903828] for camera: 0
2022-01-24 10:59:59.903 15627-15710/<app-under-test> D/CaptureSession: onSessionFinished()
2022-01-24 10:59:59.903 15627-15710/<app-under-test> D/Camera2CameraImpl: {Camera@1dac21d[id=0]} Issue capture request
2022-01-24 10:59:59.903 15627-15710/<app-under-test> D/Camera2CameraImpl: {Camera@1dac21d[id=0]} Unable to configure camera cancelled
2022-01-24 10:59:59.903 15627-15710/<app-under-test> D/SyncCaptureSessionBase: [androidx.camera.camera2.internal.SynchronizedCaptureSessionBaseImpl@56ae22f] getSurface...done
2022-01-24 10:59:59.903 15627-15710/<app-under-test> D/CaptureSession: Opening capture session.
2022-01-24 10:59:59.904 15627-15710/<app-under-test> D/DeferrableSurface: New surface in use[total_surfaces=3, used_surfaces=3](androidx.camera.core.impl.ImmediateSurface@aa6ba47}
2022-01-24 10:59:59.904 15627-15710/<app-under-test> D/DeferrableSurface: use count+1, useCount=1 androidx.camera.core.impl.ImmediateSurface@aa6ba47
2022-01-24 10:59:59.904 15627-15710/<app-under-test> D/DeferrableSurface: use count+1, useCount=2 androidx.camera.core.SurfaceRequest$2@acc53e
2022-01-24 11:00:00.228 15627-15710/<app-under-test> D/DeferrableSurface: use count-1,  useCount=1 closed=false androidx.camera.core.SurfaceRequest$2@acc53e
2022-01-24 11:00:00.228 15627-15710/<app-under-test> D/DeferrableSurface: use count-1,  useCount=0 closed=true androidx.camera.core.impl.ImmediateSurface@14b24b5
2022-01-24 11:00:00.228 15627-15710/<app-under-test> D/DeferrableSurface: Surface no longer in use[total_surfaces=3, used_surfaces=2](androidx.camera.core.impl.ImmediateSurface@14b24b5}
2022-01-24 11:00:00.228 15627-15710/<app-under-test> D/DeferrableSurface: Surface terminated[total_surfaces=2, used_surfaces=2](androidx.camera.core.impl.ImmediateSurface@14b24b5}
2022-01-24 11:00:00.228 15627-15710/<app-under-test> D/CaptureSession: Attempting to send capture request onConfigured
2022-01-24 11:00:00.228 15627-15710/<app-under-test> D/CaptureSession: Issuing request for session.
2022-01-24 11:00:00.230 15627-15710/<app-under-test> D/CaptureSession: Issuing capture request.
2022-01-24 11:00:00.231 15627-15710/<app-under-test> D/CaptureSession: CameraCaptureSession.onConfigured() mState=OPENED
2022-01-24 11:00:00.232 15627-15710/<app-under-test> D/CaptureSession: CameraCaptureSession.onReady() OPENED
2022-01-24 11:00:00.232 15627-15709/<app-under-test> D/CaptureSession: CameraCaptureSession.onReady() OPENED

As you can read "CaptureSession: Issuing capture request." is being issued all the time, but without result. I also noticed that waiting sufficiently long ~10 seconds we get the error message in logcat "Receive capture error on unknown request ID 3", which seems to point to some hardware problem implementation of camera2.

Pressing the back button cancels the image capture takePicture, and `onError(...)` from the ImageCapture.OnImageCaptureCallback is called with Error:

Type error: IMAGE_CAPTURE_ERROR
Image capture request cannot be completed, camera is closed.
Camera is closed.

However, the camera is open, a preview is shown, image analysis is working, torch is working, etc.

This is only occurring on OP8 devices. Please help!

Marvin Effing

unread,
Jan 24, 2022, 5:31:35 AM1/24/22
to Android CameraX Discussion Group, Marvin Effing
The takePicture method:

public synchronized void takePicture(@NonNull PictureCallback pictureCallback) {
if (camera != null && cameraExecutor != null) {
this.pictureCallback = pictureCallback;

handler.post(() -> {
startImageCapture(cameraSelector);

imageCapture.takePicture( <<<---- not going further than here
Executors.newSingleThreadExecutor(),
new ImageCapture.OnImageCapturedCallback() {
@Override
public void onCaptureSuccess(@NonNull ImageProxy image) { <<<<----- never called
synchronized (cameraLock) {
int width, height;
final byte[] data = imageToByteArray(image);

width = image.getWidth();
height = image.getHeight();
int rotation = image.getImageInfo().getRotationDegrees();
image.close();

callOnPictureTakenCallback(data, width, height, rotation);

Log.d(TAG, "takePicture took: " + (System.currentTimeMillis() - begin) + " ms");
}
}

@Override
public void onError(@NonNull ImageCaptureException exception) { <<<<----- only called when on back pressed
String message = "";
switch (exception.getImageCaptureError()) {
case ImageCapture.ERROR_UNKNOWN:
message = "An unknown error occurred.\n";
break;
case ImageCapture.ERROR_CAPTURE_FAILED:
message = "Capture request failed.\n";
break;
case ImageCapture.ERROR_INVALID_CAMERA:
message = "ImageCapture use case not bound to a valid camera.\n";
break;
case ImageCapture.ERROR_CAMERA_CLOSED:
message = "Image capture request cannot be completed, camera is closed.\n";
break;
case ImageCapture.ERROR_FILE_IO:
message = "Error while attempting to read or write a file.\n";
break;
}

message += exception.getMessage();
pictureCallback.onPictureTakenError(Error.IMAGE_CAPTURE_ERROR, message);
}
}
});
});
}
}

Scott Nien

unread,
Jan 24, 2022, 9:41:12 AM1/24/22
to Marvin Effing, Android CameraX Discussion Group
Hi Marvin, 
Thanks for letting us know.  
I am wondering,  Is it 100% reproducible or did it just happen once or twice ?  


--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/73377fe4-346e-4436-8afd-b7ca5a53fe0dn%40android.com.

Marvin Effing

unread,
Jan 26, 2022, 7:49:10 AM1/26/22
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, Marvin Effing
Hi Scott,

Thanks for replying.
The issue has been resolved in the meantime. It was 100% reproducible, but was not caused by the specific phone type.

Scott Nien

unread,
Jan 26, 2022, 11:00:49 AM1/26/22
to Marvin Effing, Android CameraX Discussion Group
Thanks for the update.   Glad to hear that was resolved. 
Reply all
Reply to author
Forward
0 new messages