Genymobile / scrcpy

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

Some configuration errors cause `scrcpy` client to hang #5536

Open metayan opened 9 hours ago

metayan commented 9 hours ago

Environment

Client hangs in a windowless state when trying lldb -- x/app/scrcpy --new-display=1920x1080 or lldb -- x/app/scrcpy --video-source=camera on an Android 9 device. Not even ctrl-c quits it. Only KILL signal does.

Tried to fiddle with the ConfigurationException handling and to understand the termination procedure, but it's not clear enough to me to be able to fix this.

lldb -- x/app/scrcpy --new-display=1920x1080

(lldb) target create "x/app/scrcpy"
Current executable set to '/src/scm/android/scrcpy/x/app/scrcpy' (x86_64).
(lldb) settings set -- target.run-args  "--new-display=1920x1080"
(lldb) run
Process 9014 launched: '/src/scm/android/scrcpy/x/app/scrcpy' (x86_64)
scrcpy 3.0 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)  xx                      device  xx
DEBUG: Device serial: xx
DEBUG: Using SCRCPY_SERVER_PATH: x/server/scrcpy-server
x/server/scrcpy-server: 1 file pushed, 0 skipped. 319.4 MB/s (90900 bytes in 0.000s)
[server] INFO: Device: [Sony] Sony xx (Android 9)
[server] ERROR: New virtual display is not supported before Android 10
DEBUG: Interrupting socket
DEBUG: Server disconnected
DEBUG: Server terminated
[hanged here with an empty client window open, so pressed ctrl-c]
Process 9014 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x00007fff720d1746 libsystem_kernel.dylib`__semwait_signal + 10
libsystem_kernel.dylib`__semwait_signal:
->  0x7fff720d1746 <+10>: jae    0x7fff720d1750 ; <+20>
    0x7fff720d1748 <+12>: movq   %rax, %rdi
    0x7fff720d174b <+15>: jmp    0x7fff720d021d ; cerror
    0x7fff720d1750 <+20>: retq   
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x00007fff720d1746 libsystem_kernel.dylib`__semwait_signal + 10
    frame #1: 0x00007fff72054eea libsystem_c.dylib`nanosleep + 196
    frame #2: 0x0000000100902750 libSDL2-2.0.0.dylib`SDL_Delay_REAL + 83
    frame #3: 0x0000000100838352 libSDL2-2.0.0.dylib`SDL_WaitEventTimeout_REAL + 485
    frame #4: 0x000000010001e953 scrcpy`await_for_server(connected=0x00007ffeefbfef7e) at scrcpy.c:227:12
    frame #5: 0x000000010001d3ce scrcpy`scrcpy(options=0x00007ffeefbff0a8) at scrcpy.c:531:10
    frame #6: 0x0000000100003427 scrcpy`main_scrcpy(argc=2, argv=0x00007ffeefbff278) at main.c:92:52
    frame #7: 0x00000001000032f2 scrcpy`main(argc=2, argv=0x00007ffeefbff278) at main.c:111:12
    frame #8: 0x00007fff71f8dcc9 libdyld.dylib`start + 1
    frame #9: 0x00007fff71f8dcc9 libdyld.dylib`start + 1
(lldb) kill
Process 9014 exited with status = 9 (0x00000009) killed

Some ConfigurationExceptions exit nicely:

lldb -- x/app/scrcpy --video-encoder=junk
(lldb) target create "x/app/scrcpy"
Current executable set to '/src/scm/android/scrcpy/x/app/scrcpy' (x86_64).
(lldb) settings set -- target.run-args  "--video-encoder=junk"
(lldb) run
Process 9093 launched: '/src/scm/android/scrcpy/x/app/scrcpy' (x86_64)
scrcpy 3.0 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)  xx                      device  xx
DEBUG: Device serial: xx
DEBUG: Using SCRCPY_SERVER_PATH: x/server/scrcpy-server
x/server/scrcpy-server: 1 file pushed, 0 skipped. 72.0 MB/s (90900 bytes in 0.001s)
[server] INFO: Device: [Sony] Sony xx (Android 9)
[server] DEBUG: Creating encoder by name: 'junk'
[server] WARN: Audio disabled: it is not supported before Android 11
[server] DEBUG: Audio encoder stopped
[server] ERROR: Video encoder 'junk' for h264 not found
List of video encoders:
    --video-codec=h264 --video-encoder=OMX.qcom.video.encoder.avc
    --video-codec=h264 --video-encoder=OMX.google.h264.encoder
    --video-codec=h265 --video-encoder=OMX.qcom.video.encoder.hevc
[server] DEBUG: Screen streaming stopped
[server] DEBUG: Device message sender stopped
[server] DEBUG: Controller stopped
DEBUG: Server disconnected
DEBUG: Server terminated
DEBUG: Server connected
DEBUG: Starting controller thread
DEBUG: Starting receiver thread
DEBUG: Receiver stopped
DEBUG: Using SCRCPY_ICON_PATH: app/data/icon.png
INFO: Renderer: metal
DEBUG: Trilinear filtering disabled (not an OpenGL renderer)
DEBUG: Demuxer 'video': starting thread
DEBUG: Demuxer 'audio': starting thread
WARN: Device disconnected
ERROR: Demuxer 'video': stream disabled due to connection error
WARN: Demuxer 'audio': stream explicitly disabled by the device
DEBUG: quit...
DEBUG: Controller stopped
Process 9093 exited with status = 2 (0x00000002) 

Even though it's a bit weird that the Server apparently connects after disconnecting and terminating.

https://github.com/Genymobile/scrcpy/blob/da8ade/app/src/scrcpy.c#L332-L333 looks worrying. Could it be that since no stream gets created, no "stream stopped" event will ever be received?

rom1v commented 8 hours ago

Thank you for your report. I'll fix that.