Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
112.93k stars 10.78k forks source link

Scrcpy 3.0 is not detecting some cameras in Android 12. #5539

Open xM0DI opened 11 hours ago

xM0DI commented 11 hours ago

Environment

Describe the bug

When using scrcpy --video-source=camera --camera-id=0, it gives error. same happens with id=2 (back). Above command is working for other ids like 1 and 3 (front camera) etc. This is only happening in device running android 12. I have tested same command on Android 14 and it works as intended.

scrcpy 3.0 <https://github.com/Genymobile/scrcpy>
INFO: Camera video source: control disabled
INFO: Camera video source: microphone audio source selected
INFO: ADB device found:
INFO:     -->   (usb)  RZ8N814HZNZ                     device  SM_M315F
D:\Downloads\scrcpy-win64-v3.0\scrcpy-server: 1 file pushed, 0 skipped. 69.5 MB/s (90224 bytes in 0.001s)
[server] INFO: Device: [samsung] samsung SM-M315F (Android 12)
[server] INFO: Using camera '0'
INFO: Renderer: direct3d
INFO: Texture: 4624x3472
[server] ERROR: Video encoding error
Wjava.io.IOException: android.hardware.camera2.CameraAccessException: The camera device is currently in the error state; no further calls to it will succeed.
A       at com.genymobile.scrcpy.video.CameraCapture.start(CameraCapture.java:270)
        at com.genymobile.scrcpy.video.SurfaceEncoder.streamCapture(SurfaceEncoder.java:95)
        at com.genymobile.scrcpy.video.SurfaceEncoder.lambda$start$0$com-genymobile-scrcpy-video-SurfaceEncoder(SurfaceEncoder.java:292)
        at com.genymobile.scrcpy.video.SurfaceEncoder$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
        at java.lang.Thread.run(Thread.java:1012)
Caused by: android.hardware.camera2.CameraAccessException: The camera device is currently in the error state; no further calls to it will succeed.
        at com.genymobile.scrcpy.video.CameraCapture$2.onConfigureFailed(CameraCapture.java:370)
        at android.hardware.camera2.impl.CallbackProxies$SessionStateCallbackProxy.lambda$onConfigureFailed$1$CallbackProxies$SessionStateCallbackProxy(CallbackProxies.java:64)
        at android.hardware.camera2.impl.CallbackProxies$SessionStateCallbackProxy$$ExternalSyntheticLambda3.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.os.HandlerThread.run(HandlerThread.java:67)
RN: Device disconnected
rom1v commented 11 hours ago

Is the camera app working on that device?

Try rebooting your device.

xM0DI commented 9 hours ago

Yes I am able to use camera app on device. Tried reboot also but it didn't work. This is working in Scrcpy 2.7.

rom1v commented 6 hours ago

If you know how to build, could you find the culprit commit with git bisect?

Does it work with a lower resolution -m 1024? (even if it works, there's a bug, it should not fail without it but retry automatically)

xM0DI commented 5 hours ago

Yes it works with -m1024, more over if we specifically provide size (which we get using list sizes) it works. So I am guessing it is not retrying smaller resolution as it used to do in 2.7.

scrcpy-win64-v2.7
[server] INFO: Device: [samsung] samsung SM-M315F (Android 12)
[server] INFO: Using camera '0'
INFO: Renderer: direct3d
INFO: Texture: 4624x3468
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: Retrying with -m2560...
[server] INFO: Retrying...
[server] WARN: Camera capture failed: frame 10
INFO: Texture: 2336x1080
rom1v commented 5 hours ago

On a tablet where the encoder cannot support the camera resolution, it fails and retry:

INFO: Texture: 3264x2448
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: 
[server] INFO: Retrying with -m2560...
[server] ERROR: Encoding error: android.media.MediaCodec$CodecException: 
[server] INFO: Retrying with -m1920...

So it behaves differently on your device.

Do you know how to build and use git bisect to find which change introduce the problem on your device?

rom1v commented 4 hours ago

Another simpler test: I disabled retry on v2.7, so I will get the stack trace which triggers the retry.

Please replace this file in scrcpy 2.7: