TomerPacific / MediumArticles

A repository that contains code associated with various Medium articles I have written
https://tomerpacific.github.io/MediumArticles/
76 stars 80 forks source link

Camera2API sample crashes due to incorrectly configured I/O surface #1

Closed paulfreeman closed 2 years ago

paulfreeman commented 2 years ago

I found your article to be a useful overview and your sample code a good stripped down sample for experimentation. Thank you for the clear description of the API.

However there seems to be a problem with the ImageReader. As it is, providing it to createCaptureSession is causing a crash on line 244

cameraDevice.createCaptureSession(listOf(previewSurface, imageReader.surface), captureStateCallback, null)

The following error is logged

W/CameraDevice-JV-0: Stream configuration failed due to: endConfigure:593: Camera 0: Unsupported set of inputs/outputs provided

changing this by removing the imageReader.surface causes the preview to display

cameraDevice.createCaptureSession(listOf(previewSurface), captureStateCallback, null)

With this latter change selecting 'takePhoto' will crash for a similar reason.

TomerPacific commented 2 years ago

@paulfreeman , thanks for brining this to my attention. I'll definitely check it out and work out a solution.

TomerPacific commented 2 years ago

@paulfreeman - tried to reproduce the crash you saw, but did not see it happening.

Care to share some more details on how you managed to get it?

The device you used and it's API level.

TomerPacific commented 2 years ago

Closing issue due to inactivity.

cyrildavidt commented 7 months ago

The same was happening with me while started the session recording

Process: com.tomerpacific.camera2api, PID: 10012 java.lang.IllegalArgumentException: CaptureRequest contains unconfigured Input/Output Surface! at android.hardware.camera2.CaptureRequest.convertSurfaceToStreamId(CaptureRequest.java:765) at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:1268) at android.hardware.camera2.impl.CameraDeviceImpl.capture(CameraDeviceImpl.java:1105) at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:189) at com.tomerpacific.camera2api.MainActivity.takePhoto(MainActivity.kt:177) at com.tomerpacific.camera2api.MainActivity.onCreate$lambda-2$lambda-1(MainActivity.kt:72) at com.tomerpacific.camera2api.MainActivity.$r8$lambda$5SYaZ2RZ9y5DG99ZvHbub8_t9LE(Unknown Source:0) at com.tomerpacific.camera2api.MainActivity$$ExternalSyntheticLambda0.onClick(Unknown Source:2) at android.view.View.performClick(View.java:7537) at android.view.View.performClickInternal(View.java:7514) at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0) at android.view.View$PerformClick.run(View.java:29555) at android.os.Handler.handleCallback(Handler.java:984) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loopOnce(Looper.java:238) at android.os.Looper.loop(Looper.java:357) at android.app.ActivityThread.main(ActivityThread.java:8194) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:957)