android / android/camera-samples

Having problem with manual focusing and digital zooming in certain condition.

Open
#447 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
5.5k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

I'm working on with high-speed camera with Google Pixel 4a smartphone. When I'm setting the manual focus and digital zoom for 720p 120fps, the code runs smoothly. However, when I try to run the same code with 1080p 120fps or 720p 240fps, the preview stops and crashes when new touch input is in or I try to start the recording.
below there is log when I tried with 720p 120fps:

2021-12-03 15:10:17.006 28833-28833/com.android.example.camera2.slowmo D/opencv: setting the focus
2021-12-03 15:10:18.639 28833-28833/com.android.example.camera2.slowmo D/btdevice: connection failed: read failed, socket might closed or timeout, read ret: -1
2021-12-03 15:10:18.641 28833-28833/com.android.example.camera2.slowmo D/BluetoothSocket: close() this: android.bluetooth.BluetoothSocket@363b88, channel: -1, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@6af921, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@5fa5146mSocket: android.net.LocalSocket@27c1f07 impl:android.net.LocalSocketImpl@6b78834 fd:java.io.FileDescriptor@3dd065d, mSocketState: INIT
2021-12-03 15:10:22.508 28833-28833/com.android.example.camera2.slowmo D/CameraFragment: Orientation changed: 180
2021-12-03 15:10:22.699 28833-28833/com.android.example.camera2.slowmo D/CameraFragment: Orientation changed: 90
2021-12-03 15:10:29.311 28833-28833/com.android.example.camera2.slowmo D/opencv: setting the zoom

but when I'm running the same code with 1080p 120fps or 720p 240fps, it turns like this
2021-12-03 15:11:22.320 29000-29000/com.android.example.camera2.slowmo D/opencv: setting the focus
2021-12-03 15:11:24.176 29000-29000/com.android.example.camera2.slowmo D/btdevice: connection failed: read failed, socket might closed or timeout, read ret: -1
2021-12-03 15:11:24.176 29000-29039/com.android.example.camera2.slowmo D/BluetoothSocket: close() this: android.bluetooth.BluetoothSocket@363b88, channel: -1, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@6af921, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@5fa5146mSocket: android.net.LocalSocket@27c1f07 impl:android.net.LocalSocketImpl@6b78834 fd:java.io.FileDescriptor@3dd065d, mSocketState: INIT
2021-12-03 15:11:25.721 29000-29037/com.android.example.camera2.slowmo E/CameraFragment: Camera 0 error: (4) Fatal (device)
java.lang.RuntimeException: Camera 0 error: (4) Fatal (device)
at com.example.android.camera2.slowmo.fragments.CameraFragment$openCamera$2$1.onError(CameraFragment.kt:1211)
at android.hardware.camera2.impl.CameraDeviceImpl.notifyError(CameraDeviceImpl.java:1748)
at android.hardware.camera2.impl.CameraDeviceImpl.$r8$lambda$KBQCqQRdhVVn7uHI9Xdha6OqnsU(Unknown Source:0)
at android.hardware.camera2.impl.CameraDeviceImpl$$ExternalSyntheticLambda0.accept(Unknown Source:8)
at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:281)
at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:204)
at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:97)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.os.HandlerThread.run(HandlerThread.java:67)

and when I start to record, the log goes like this;

2021-12-03 15:13:16.233 29208-29208/com.android.example.camera2.slowmo D/opencv: setting the focus
2021-12-03 15:13:17.165 29208-29208/com.android.example.camera2.slowmo D/InputMethodManager: showSoftInput() view=androidx.appcompat.widget.AppCompatEditText{73c9c37 VFED..CL. .F.P.... 827,238-1080,370 #7f0800bb app:id/sample_EditText aid=1073741826} flags=0 reason=SHOW_SOFT_INPUT
2021-12-03 15:13:17.370 29208-29208/com.android.example.camera2.slowmo D/InsetsController: show(ime(), fromIme=true)
2021-12-03 15:13:17.381 29208-29208/com.android.example.camera2.slowmo D/AutoFitSurfaceView: Measured dimensions set: 1240 x 1945
2021-12-03 15:13:17.391 29208-29208/com.android.example.camera2.slowmo D/AutoFitSurfaceView: Measured dimensions set: 1240 x 1945
2021-12-03 15:13:17.404 29208-29208/com.android.example.camera2.slowmo D/btdevice: connection failed: read failed, socket might closed or timeout, read ret: -1
2021-12-03 15:13:17.405 29208-29208/com.android.example.camera2.slowmo D/BluetoothSocket: close() this: android.bluetooth.BluetoothSocket@eb396b8, channel: -1, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@4b36c91, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@49f97f6mSocket: android.net.LocalSocket@684d7f7 impl:android.net.LocalSocketImpl@676664 fd:java.io.FileDescriptor@29140cd, mSocketState: INIT
2021-12-03 15:13:17.406 29208-29250/com.android.example.camera2.slowmo D/BluetoothSocket: close() this: android.bluetooth.BluetoothSocket@eb396b8, channel: -1, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@4b36c91, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@49f97f6mSocket: null, mSocketState: CLOSED
2021-12-03 15:13:18.025 29208-29208/com.android.example.camera2.slowmo D/InputMethodManager: showSoftInput() view=androidx.appcompat.widget.AppCompatEditText{73c9c37 VFED..CL. .F.P.... 827,238-1080,370 #7f0800bb app:id/sample_EditText aid=1073741826} flags=0 reason=SHOW_SOFT_INPUT
2021-12-03 15:13:18.045 29208-29208/com.android.example.camera2.slowmo D/InsetsController: show(ime(), fromIme=true)
2021-12-03 15:13:19.081 29208-29208/com.android.example.camera2.slowmo D/InputMethodManager: showSoftInput() view=androidx.appcompat.widget.AppCompatEditText{73c9c37 VFED..CL. .F.P.... 827,238-1080,370 #7f0800bb app:id/sample_EditText aid=1073741826} flags=0 reason=SHOW_SOFT_INPUT
2021-12-03 15:13:19.123 29208-29208/com.android.example.camera2.slowmo D/InsetsController: show(ime(), fromIme=true)
2021-12-03 15:13:19.488 29208-29240/com.android.example.camera2.slowmo E/CameraFragment: Camera 0 error: (4) Fatal (device)
java.lang.RuntimeException: Camera 0 error: (4) Fatal (device)
at com.example.android.camera2.slowmo.fragments.CameraFragment$openCamera$2$1.onError(CameraFragment.kt:1211)
at android.hardware.camera2.impl.CameraDeviceImpl.notifyError(CameraDeviceImpl.java:1748)
at android.hardware.camera2.impl.CameraDeviceImpl.$r8$lambda$KBQCqQRdhVVn7uHI9Xdha6OqnsU(Unknown Source:0)
at android.hardware.camera2.impl.CameraDeviceImpl$$ExternalSyntheticLambda0.accept(Unknown Source:8)
at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:281)
at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:204)
at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:97)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.os.HandlerThread.run(HandlerThread.java:67)
2021-12-03 15:13:24.300 29208-29208/com.android.example.camera2.slowmo D/AutoFitSurfaceView: Measured dimensions set: 1240 x 1945
2021-12-03 15:13:24.311 29208-29208/com.android.example.camera2.slowmo D/AutoFitSurfaceView: Measured dimensions set: 1240 x 1945
2021-12-03 15:13:36.524 29208-29208/com.android.example.camera2.slowmo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.example.camera2.slowmo, PID: 29208
android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): The camera device has encountered a serious error
at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:2350)
at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1277)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.stopRepeating(CameraCaptureSessionImpl.java:424)
at android.hardware.camera2.impl.CameraConstrainedHighSpeedCaptureSessionImpl.stopRepeating(CameraConstrainedHighSpeedCaptureSessionImpl.java:274)
at com.example.android.camera2.slowmo.fragments.CameraFragment$initializeCamera$1$7$1.invokeSuspend(CameraFragment.kt:755)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7838)
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:1003)

I have no idea why the code have problem running on different setting, while it is working fine on certain setting. It seems like the inner settings are the same, except for resolution and fps. For the information, I set the sdk on 31, build tools on 22 to implement digital zoom. Can you help me with the manual focusing and zooming? Thank you.

Contributor guide

Open the contributing guide

Research direction

Start with CameraFragment.kt at the reported onError callback around line 1211 and the high-speed session cleanup around line 755. Reproduce the 1080p/120fps and 720p/240fps cases on the Pixel 4a, compare them with 720p/120fps, and trace the camera error through the focus, zoom, recording, and session lifecycle. Done means the affected settings no longer produce the reported fatal camera crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.