Commit Graph

1540 Commits (master)

Author SHA1 Message Date
Romain Vimont af57309074 Bump version to 2.4 2 months ago
Romain Vimont a720c946a6 Merge branch 'master' into release 2 months ago
Romain Vimont 8d87b91f69 Build dependencies from sources
The project has 3 build dependencies:
 - SDL
 - FFmpeg
 - libusb

For Windows, the release script downloaded pre-built build dependencies
(either from upstream, or from the scrcpy-deps repository).

Instead, download the source releases and build locally. This offers
more flexibility.

The official adb release is still downloaded and included as is in the
release archive (it is not a build dependency).

Also upgrade FFmpeg to 6.1.1 and libusb to 1.0.27.

PR #4713 <https://github.com/Genymobile/scrcpy/pull/4713>
2 months ago
inson1 125b1103e1 Happy new year 2024!
PR #4716 <https://github.com/Genymobile/scrcpy/pull/4716>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2 months ago
Romain Vimont 36189b90ea Remove spurious line 2 months ago
Romain Vimont 4dca08cfe3 Set SDL hints before creating any thread
To avoid race conditions in SDL (reported by TSAN).
2 months ago
Romain Vimont fd0f432e87 Detect missing initializations
Write invalid data in memory to easily detect missing initializations in
debug mode.
2 months ago
Romain Vimont cdf09805c0 Add missing initialization 2 months ago
Romain Vimont dd479ed176 Check options specific to SDK keyboard
Fail if an option specific to --keyboard=sdk is passed with another
keyboard input mode.

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont 5f12132c47 Do not fallback keyboard mode if AOA fails
Initially, if AOA initialization failed, default injection method was
used, in order to use the same command/shortcut when the device is
connected via USB or via TCP/IP, without changing the arguments.

Now that there are 3 keyboard modes, it seems unexpected to switch to
another specific mode if AOA fails (and it is inconsistent). If the user
explicitly requests AOA, then use AOA or fail.

Refs #2632 comment <https://github.com/Genymobile/scrcpy/pull/2632#issuecomment-945190859>
PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont 1c5ad0e813 Reassign -K and -M to UHID keyboard and mouse
The options were deprecated, but for convenience, reassign them to
aliases for --keyboard=uhid and --mouse=uhid respectively.

Their long version (--hid-keyboard and --hid-mouse) remain deprecated.

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont 6a103c809f Add UHID mouse support
Use the following command:

    scrcpy --mouse=uhid

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont 151a6225d4 Add shortcut to open keyboard settings
The keyboard settings can be opened by:

    adb shell am start -a android.settings.HARD_KEYBOARD_SETTINGS

Add a shortcut (MOD+k) for convenience if the current keyboard is HID.

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Simon Chan 87da68ee0d Handle UHID output
Use UHID output reports to synchronize CapsLock and VerrNum states.

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2 months ago
Simon Chan 840680f546 Add UHID keyboard support
Use the following command:

    scrcpy --keyboard=uhid

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2 months ago
Romain Vimont 604e59ac7b Initialize controller before keyboards
The UHID keyboard initializer will need the controller.

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont 4d2c2514fc Initialize controller in two steps
There is a dependency cycle in the initialization order:
 - keyboard depends on controller
 - controller depends on acksync
 - acksync depends on keyboard initialization

To break this cycle, bind the async instance to the controller in a
second step.

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont 107f7a83ab Extract binary to hex string conversion
PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont 2e7f6a6fc4 Rename default keyboard implementation to "sdk"
Rename {keyboard,mouse}_inject to {keyboard,mouse}_sdk.

All implementations "inject" key events and mouse events, what differs
is the mechanism. For these implementations, the Android SDK API is used
to inject events.

Note that the input mode enum variants were already renamed
(SC_KEYBOARD_INPUT_MODE_SDK and SC_MOUSE_INPUT_MODE_SDK).

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont d95276467b Extract mouse HID handling
Split the mouse implementation using AOA and the code handling HID
events, so that HID events can be reused for another protocol (UHID).

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont 91485e2863 Extract keyboard HID handling
Split the keyboard implementation using AOA and the code handling HID
events, so that HID events can be reused for another protocol (UHID).

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont f2d6203156 Extract HID events struct
An event contained several fields:
 - the accessory id
 - the HID event data
 - a field ack_to_wait specific to the AOA implementation.

Extract the HID event part to prepare the factorization of HID event
creation.

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont 2d32557fde Embed HID event data
In the implementation, an HID event is at most 8 bytes. Embed the data
in the HID event structure to avoid allocations and simplify the code.

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont ae303b8d07 Rename hid event "buffer" to "data"
This fields contains the HID event data (there is no "bufferization").

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont 29ce03e337 Rename "buffer" to "data"
The variable name is intended to match the parameter name of
libusb_control_transfer().

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont 48adae1728 Fix HID mouse documentation
The size of a mouse HID event is 4 bytes.

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Simon Chan ea98d49bae Introduce --keyboard and --mouse
Until now, there was two modes for keyboard and mouse:
 - event injection using the Android system API (default)
 - HID/AOA over USB

For this reason, the options were exposed as simple flags:
 - -K or --hid-keyboard to enable physical keyboard simulation (AOA)
 - -M or --hid-mouse to enable physical mouse simulation (AOA)

Replace them by explicit --keyboard and --mouse options, with 3 possible
values:
 - disabled
 - sdk (default)
 - aoa

This will allow to add a new mode (uhid).

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2 months ago
Romain Vimont 35add3daee Accept disabled keyboard or mouse
The input manager assumed that if a controller was present, then both a
key processor and a mouse processor were present.

Remove this assumption, to support disabling keyboard and mouse
separately. This prepares the introduction of new command line options
--keyboard and --mouse.

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont c0a1aee8ce Always pass input manager instance
Some functions in input_manager.c only have access to a sub-object (for
example the controller). For consistency, always pass the whole
input manager instance.

This will allow to add assertions when keyboard and mouse could be
disabled separately.

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
2 months ago
Romain Vimont a976417572 Fix typo in error message 2 months ago
Romain Vimont ffa238b9d3 Remove duplicate lines in libusb script 2 months ago
Romain Vimont 295102a6d9 Check device messages assumptions at runtime
Do not assume the server behaves correctly (scrcpy should not require
the device to be trusted).
2 months ago
Romain Vimont 78a7e4f293 Use sc_ prefix for device sender 2 months ago
Romain Vimont 9858eff856 Fix device message deserialization checks
If any message is incomplete, the deserialization method must return
immediately.
2 months ago
Romain Vimont 9e22f3bf1c Replace unsigned char by uint8_t for buffers
For consistency.
2 months ago
Romain Vimont a7cf4daf3b Avoid negative average buffering
The assumption that underflow and overbuffering are caused by jitter
(and that the delay between the producer and consumer will be caught up)
does not always hold.

For example, if the consumer does not consume at the expected rate (the
SDL callback is not called often enough, which is an audio output
issue), many samples will be dropped due to overbuffering, decreasing
the average buffering indefinitely.

Prevent the average buffering to become negative to limit the
consequences of an unexpected behavior.

PR #4572 <https://github.com/Genymobile/scrcpy/pull/4572>
3 months ago
Romain Vimont c12fdf900f Minimize buffer underflow on starting
If playback starts too early, insert silence until the buffer is filled
up to at least target_buffering before playing.

PR #4572 <https://github.com/Genymobile/scrcpy/pull/4572>
3 months ago
Romain Vimont 4502126e3b Use early return to avoid additional indentation
PR #4572 <https://github.com/Genymobile/scrcpy/pull/4572>
3 months ago
Romain Vimont dfa3f97a87 Fix audio player comment
PR #4572 <https://github.com/Genymobile/scrcpy/pull/4572>
3 months ago
Romain Vimont edac4b8a9a Increase buffering level smoothness
The buffering level does not change continuously: it increases abruptly
when a packet is received, and decreases abruptly when an audio block is
consumed.

To estimate the buffering level, a rolling average is used.

To make the buffering more stable, increase the smoothness of this
rolling average. This decreases the risk of enabling audio compensation
due to an estimation error.

PR #4572 <https://github.com/Genymobile/scrcpy/pull/4572>
3 months ago
Romain Vimont 44abed5c68 Improve audio compensation thresholds
Use different thresholds for enabling and disabling compensation.

Concretely, enable compensation if the difference between the average
and the target buffering levels exceeds 4 ms (instead of 1 ms). This
avoids unnecessary compensation due to small noise in buffering level
estimation.

But keep a smaller threshold (1 ms) for disabling compensation, so that
the buffering level is restored closer to the target value. This avoids
to keep the actual level close to the compensation threshold.

PR #4572 <https://github.com/Genymobile/scrcpy/pull/4572>
3 months ago
Romain Vimont cfa4f7e2f2 Replace locks by atomics in audio player
The audio output thread only reads samples from the buffer, and most of
the time, the audio receiver thread only writes samples to the buffer.
In these cases, using atomics avoids lock contention.

There are still corner cases where the audio receiver thread needs to
"read" samples (and drop them), so lock only in these cases.

PR #4572 <https://github.com/Genymobile/scrcpy/pull/4572>
3 months ago
Romain Vimont d47ecef1b5 Limit buffering time value
This avoids unreasonable values which could lead to integer overflow.

PR #4572 <https://github.com/Genymobile/scrcpy/pull/4572>
3 months ago
Romain Vimont 3333e67452 Fix memory leak on error
Fixes #4636 <https://github.com/Genymobile/scrcpy/issues/4636>
3 months ago
Romain Vimont 2ad93d1fc0 Fix scrcpy_otg() return value on error
The function now returns an enum scrcpy_exit_code, not a bool.
4 months ago
Romain Vimont d067a11478 Do not power on if no video
Power on the device on start only if video capture is enabled.

Note that it only impacts display mirroring, since control is completely
disabled if video source is camera.

Refs 110b3a16f6
4 months ago
Romain Vimont cd4056d0f3 Fix include formatting 4 months ago
Till Rathmann d2ed4510a7 Simulate tilt multitouch event by pressing Shift
PR #4529 <https://github.com/Genymobile/scrcpy/pull/4529>

Signed-off-by: Romain Vimont <rom@rom1v.com>
5 months ago
Harsh Shandilya 604dfd7c6b Fix incorrect compgen usage
PR #4532 <https://github.com/Genymobile/scrcpy/pull/4532>

Signed-off-by: Romain Vimont <rom@rom1v.com>
5 months ago
Harsh Shandilya af69689ec1 Fix bash completion syntax
PR #4532 <https://github.com/Genymobile/scrcpy/pull/4532>

Signed-off-by: Romain Vimont <rom@rom1v.com>
5 months ago