moonlight-stream / moonlight-android

GameStream client for Android
GNU General Public License v3.0
3.86k stars 614 forks source link

[Issue]: Inputs freeze intermittently with a Bluetooth controller connected to the phone while streaming (sunshine host) #1395

Open RadarNyan opened 1 month ago

RadarNyan commented 1 month ago

Describe the bug

Input (phone touchscreen & Xbox controller connected to the phone via Bluetooth) would freeze randomly during streaming, but video/audio are not affected.

Steps to reproduce

  1. Start streaming with a Bluetooth controller connected to my phone, this would NOT create a virtual controller until I any button on the controller is pressed.
  2. Play a video on the PC as a reference for video/audio streaming status.
  3. Move the cursor by using the touch screen constantly, then press any button on the controller. As soon as I press the button, a "device connect" sound can be heard, as now the virtual game pad is connected and all inputs are frozen. Not even the touch screen would move the cursor anymore, while video/audio are not affected at all. I can move the mouse on the PC, so it's not Windows being frozen.
  4. Wait for a few seconds until the cursor can be moved again by the touchscreen, and then the controller will work with no issue as well.
  5. However, during the streaming, input would freeze randomly and then recover after a few seconds, which is very annoying.
  6. I have tried to repeat the above procedure on another laptop (running moonlight-qt) but can't reproduce the issue, which makes me think this might be an Android-specific issue.
  7. I do not have this "game controller freezes touchscreen" issue with any controller test app I can find, so it's unlikely to be a hardware problem of the phone.

Affected games

All.

Other Moonlight clients

PC

Moonlight adjusted settings

No

Moonlight adjusted settings (please complete the following information)

N/A

Moonlight default settings

Yes

Gamepad-related connection issue

No

Gamepad-related input issue

No

Gamepad-related streaming issue

Yes

Android version

Android 12

Device model

POCO X4 GT (Dimensity 8100)

Server PC OS version

Windows 10 21H2

Server PC GeForce Experience version

N/A

Server PC Nvidia GPU driver version

N/A

Server PC antivirus and firewall software

Windows defaults

Screenshots

No response

Relevant log output

Screenshot_2024-07-18-16-05-46-544-edit_com f0x1d logfox

Inputs freeze at the first log (about audio) and resumes at the last (so about 10 seconds.)

Additional context

I managed to find an OTG connector and connected the Xbox controller to the phone via USB, but I failed to reproduce the issue, so it's Bluetooth-specific.

I've tried to play the same games with the Steam Link app, and despite the horrible performance and messy steam input mapping system, I haven't experienced any freezing, so this can't be caused by "hardware limitation due to the antenna wiring" as mentioned in the moonlight-streaming troubleshooting page.

RadarNyan commented 1 month ago

image

I've been trying to track this down but do not have enough knowledge of Android development to make anything out of it. All I've found is that this problem is caused by some slow binder calls which block the ControllerHandler thread.

ClassicOldSong commented 1 month ago

You can try my fork that may have solved the issue: ClassicOldSong/moonlight-android/releases

Uncheck Enable battery status report for gamepad in the settings.

ClassicOldSong commented 1 month ago

Dupe https://github.com/moonlight-stream/moonlight-android/issues/1389

RadarNyan commented 1 month ago

You can try my fork that may have solved the issue: ClassicOldSong/moonlight-android/releases

Uncheck Enable battery status report for gamepad in the settings.

I just installed your fork and unchecked the option, but the problem persists. All inputs still hang for 10 seconds with the same slow binder log.

RadarNyan commented 1 month ago

Thanks, @ClassicOldSong ! I managed to produce a duct tape fix by commenting out

private final HandlerThread backgroundHandlerThread;
private final Handler backgroundThreadHandler;

And every error lines caused by commenting out the above two lines in ControllerHandler.java, now the problem is gone.

ClassicOldSong commented 1 month ago

There was a typo in my commit, that option was not actually set... Just pushed a new release, you can try again...

The AI generated string didn't match the actual key of the checkbox...

RadarNyan commented 1 month ago

There was a typo in my commit, that option was not actually set... Just pushed a new release, you can try again...

The AI generated string didn't match the actual key of the checkbox...

Yup, the new upload works.