Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High polling rate makes mouse(HID) movement sluggish #3088

Open
2 tasks done
nothingshiru opened this issue Mar 6, 2022 · 22 comments
Open
2 tasks done

High polling rate makes mouse(HID) movement sluggish #3088

nothingshiru opened this issue Mar 6, 2022 · 22 comments

Comments

@nothingshiru
Copy link

nothingshiru commented Mar 6, 2022

  • I have read the FAQ.
  • I have searched in existing issues.

Environment

  • OS: Windows 10
  • scrcpy version: 1.23
  • installation method: Windows release
  • device model: Huawei Matepad 10.4
  • Android version: 10

Describe the bug
The polling rate of my mouse can be set to 125hz, 500hz, 1000hz in driver. When it is set to 500hz or 1000hz, mouse(HID) movement is sluggish.

@nothingshiru nothingshiru changed the title High polling rate makes mouse(HID) sluggish High polling rate makes mouse(HID) movement sluggish Mar 6, 2022
@rom1v
Copy link
Collaborator

rom1v commented Mar 7, 2022

Any relevant logs in the console output?

@nothingshiru
Copy link
Author

nothingshiru commented Mar 7, 2022

Sorry. I'm not a programmer so that I might not understand you well. Where can I find the console output?

@rom1v
Copy link
Collaborator

rom1v commented Mar 7, 2022

Double-click on open_a_terminal_here.bat, type scrcpy -KM (K for HID keyboard, M for HID mouse) and press Enter. Some logs will be printed to this terminal while scrcpy is running.

@nothingshiru
Copy link
Author

scrcpy -KM doesn't work. scrcpy --otg works.

And here is the log.

D:\Program Files\scrcpy-win64-v1.23>scrcpy -KM -s TFMNU20429107644
scrcpy 1.23 <https://github.com/Genymobile/scrcpy>
ERROR: On Windows, it is not possible to open a USB device already open by another process (like adb).
ERROR: Therefore, -K/--hid-keyboard and -M/--hid-mouse may only work in OTG mode (--otg).

D:\Program Files\scrcpy-win64-v1.23>scrcpy --otg -s TFMNU20429107644
scrcpy 1.23 <https://github.com/Genymobile/scrcpy>
INFO: Killing adb daemon (if any)...
INFO: USB device: TFMNU20429107644 (12d1:107e) HUAWEI BAH3-W09
WARN: On this platform, libusb does not have hotplug capability; device disconnection will not be detected properly
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event
WARN: Could request HID event

@nothingshiru
Copy link
Author

nothingshiru commented Mar 7, 2022

When the polling rate is set to 125hz, I don't see the WARN: Could request HID event

D:\Program Files\scrcpy-win64-v1.23>scrcpy --otg -s TFMNU20429107644
scrcpy 1.23 <https://github.com/Genymobile/scrcpy>
INFO: Killing adb daemon (if any)...
INFO: USB device: TFMNU20429107644 (12d1:107e) HUAWEI BAH3-W09
WARN: On this platform, libusb does not have hotplug capability; device disconnection will not be detected properly

@rom1v
Copy link
Collaborator

rom1v commented Mar 7, 2022

OK, that's what I suspected.

Scrcpy enqueues at most a fixed number of events (currently 64), because if there are too many events not consumed, we want to discard them (to avoid forwarding them with a high delay).

With a high polling rate, this limit might be too low, let's try to increase to 512:

diff --git a/app/src/usb/aoa_hid.h b/app/src/usb/aoa_hid.h
index d785a0e9..d1a95643 100644
--- a/app/src/usb/aoa_hid.h
+++ b/app/src/usb/aoa_hid.h
@@ -27,7 +27,7 @@ sc_hid_event_init(struct sc_hid_event *hid_event, uint16_t accessory_id,
 void
 sc_hid_event_destroy(struct sc_hid_event *hid_event);
 
-struct sc_hid_event_queue CBUF(struct sc_hid_event, 64);
+struct sc_hid_event_queue CBUF(struct sc_hid_event, 512);
 
 struct sc_aoa {
     struct sc_usb *usb;

Here is a binary to replace in your v1.23 release:

  • scrcpy.exe sha256:0801c7a6b84be4e08a9a26d09ab12e5a66fe6fdeb66a6514886cd2e077fd6083

Please check if there are still warnings in the console (if you mouse the mouse for a while). If not, please check that there is no noticeable delay between your mouse motion and the cursor motion.

If there are still warnings, then the events could not be consumed/forwarded at the same rate as they are received. That would require event resampling/merging to accommodate the issue.

@nothingshiru
Copy link
Author

I replaced the file.
There are still warnings in the console and the delay is much worse than before.

@rom1v
Copy link
Collaborator

rom1v commented Mar 7, 2022

OK, thank you.

So an event resampling/merging mechanism will be necessary. It's not trivial and requires some work.

Unfortunately, I could not reproduce on my machine with my mouse (AFAIK I could not configure the polling rate).

@nothingshiru
Copy link
Author

This is quite important as the polling rate of a gaming mouse is normally set to at least 500hz by default. I'm now ok with 125hz though. I will wait patiently.

@rom1v
Copy link
Collaborator

rom1v commented Mar 7, 2022

Does it work with another Android device?

@nothingshiru
Copy link
Author

There are still warnings in the console and the delay is much worse than before.

I tested it on my phone. Still the same.

  • device model: Honor V10
  • Android version: 10

@rom1v
Copy link
Collaborator

rom1v commented Mar 7, 2022

OK.

And does it work correctly if you connect your mouse directly to the Android device?

@rom1v
Copy link
Collaborator

rom1v commented Mar 7, 2022

Also, do you reproduce the problem if you use the default mouse injection method instead of HID? (Since mouse motion events are not forwarded when nl mouse buttons are pressed, press the left button and move the mouse.)

@nothingshiru
Copy link
Author

nothingshiru commented Mar 7, 2022

And does it work correctly if you connect your mouse directly to the Android device?

I connect my mouse directly to my Android devices via OTG cable. It works correctly.

Also, do you reproduce the problem if you use the default mouse injection method instead of HID? (Since mouse motion events are not forwarded when nl mouse buttons are pressed, press the left button and move the mouse.)

Sorry. I don't quite understand this. What is "default mouse injecton method"?

@rom1v
Copy link
Collaborator

rom1v commented Mar 7, 2022

Sorry. I don't quite understand this. What is "default mouse injecton method"?

Without --otg.

@nothingshiru
Copy link
Author

nothingshiru commented Mar 7, 2022

Do you mean mirroring screen of Android device and controling it on pc screen? In this case, I don't see delay.

@rom1v
Copy link
Collaborator

rom1v commented Mar 7, 2022

Do you mean mirroring screen of Android device and controling it on pc screen?

Yes. In that case, when you move the mouse with left button pressed, are there any warnings in the console?

@nothingshiru
Copy link
Author

No, there is no any warnings in the console.

@DymondZ
Copy link

DymondZ commented Aug 24, 2022

I have the same issue on v1.24 (latest right now) using a Razer DeathAdder Essential which only can be set to 500 or 1000 Hz polling rate. I tested both
Using 500 Hz, very tiny movements dont trigger the message and seem to result in a good latency. Moving a fraction more or faster and such triggering the message do result in a very noticable input lag. 1000 Hz does increase the input lag even more I would say you can feel it.

I cut the end of the Terminal output because its repeating:

PS C:\Programs\scrcpy-win64-v1.24> .\scrcpy.exe --otg
scrcpy 1.24 <https://github.com/Genymobile/scrcpy>
INFO: Killing adb daemon (if any)...
INFO: USB device: 227d5ca9 (18d1:4ee7) Xiaomi Redmi Note 10 Pro
WARN: On this platform, libusb does not have hotplug capability; device disconnection will not be detected properly
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)
WARN: Could not request HID event (mouse motion)

I know its asking a bit lot but the DeathAdder Essential is a very cheap gaming mouse by now. I bought it for 28€ 2 years ago not on discount. Cheapest price new I found 22€ just now. Maybe you could consider it for supporting mice that dont go under 500 Hz. I would even use 125 Hz as a workaround if it was available for me.
And heck I would even do 10€ via PayPal or send you mine if needed.

@iliqiliev
Copy link

Everything described above applies to my 1000Hz mouse on Linux if that is any help

@Tryanks
Copy link

Tryanks commented May 8, 2023

When I tried using AOAv2 to forward HID events in my own program, I noticed that each usb.Control command took longer than 1ms, sometimes up to 2ms. I think that's why the high polling rate mouse lags, because it reports faster than AOAv2 can consume.

@Tryanks
Copy link

Tryanks commented May 8, 2023

For sending HID events, it is possible to combine multiple HID event data into one send. after AOAv2 receives the data and reports it to the kernel, the system splits and processes the received HID events one by one. this approach keeps the 1000Hz polling data intact and reduces the data interaction frequency to 125Hz. but it introduces a latency of about 8ms. But I think this is enough to solve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants