Commit Graph

1540 Commits (master)

Author SHA1 Message Date
Romain Vimont 9db42341e4 Pass screen instance to mouse capture functions
Using the screen instance or not in these functions is an implementation
detail. Further changes will require the screen instance.

Refs 7848a387c8
PR #3031 <https://github.com/Genymobile/scrcpy/pull/3031>
2 years ago
Romain Vimont 82a99f69ec Remove "linux-only" mentions for HID/OTG features
HID/OTG features are not limited to Linux anymore.

PR #3031 <https://github.com/Genymobile/scrcpy/pull/3031>
2 years ago
Romain Vimont 33202491e1 Build on macOS with libusb support
Fixes #2774 <https://github.com/Genymobile/scrcpy/issues/2774>
PR #3031 <https://github.com/Genymobile/scrcpy/pull/3031>
2 years ago
Romain Vimont b4fd882ece Fix typo 2 years ago
Romain Vimont c4ab65eb79 Remove useless '\n' in log 2 years ago
Romain Vimont 6edf50d447 Remove fprintf() in tests
It was committed by mistake.
2 years ago
Romain Vimont 4b018be789 Add --print-fps to enable FPS counter on start
The FPS counter could be enabled/disabled via MOD+i.

Add a command line option to enable it on start. This is consistent with
other features like --turn-screen-off or --fullscreen.

Fixes #468 <https://github.com/Genymobile/scrcpy/issues/468>
PR #3030 <https://github.com/Genymobile/scrcpy/pull/3030>
2 years ago
Romain Vimont fa93c8a91b Move FPS counter start/stop logs
This will allow to print the same logs for every start/stop call.

PR #3030 <https://github.com/Genymobile/scrcpy/pull/3030>
2 years ago
Romain Vimont 03705b828b Use sc_prefix for fps counter 2 years ago
Romain Vimont 85edba20e7 Enforce deadline reached on timeout
The value of sc_tick_now() has microsecond precision, but
sc_cond_timedwait() has only millisecond precision.

To guarantee that sc_tick_now() >= deadline when sc_cond_timedwait()
returns due to timeout, round up to the next millisecond.

This avoids to call a non-blocking sc_cond_timedwait() in a loop for no
reason until a target deadline during up to 1 millisecond.

Refs 682a691173
2 years ago
Romain Vimont 2a872c3865 Fix fps_counter tick type
The type uint32_t is not sufficient to store the result of
sc_tick_now().

As a consequence, the FPS counter entered a live loop and caused a lock
starvation (deadlock in practice).

Refs ec871dd3f5
Refs 682a691173
2 years ago
Romain Vimont ccbe370cc5 Add --no-cleanup option
It might be useful not to cleanup on exit, for example to leave the
screen turned off, or keep the server binary on the device (via the
server option "cleanup=false").

Fixes #1764 <https://github.com/Genymobile/scrcpy/issues/1764>
PR #3020 <https://github.com/Genymobile/scrcpy/pull/3020>
2 years ago
Romain Vimont bb991f829c Fix order of options
In alphabetic order, "no-clipboard-autosync" is before
"no-downsize-on-error".
2 years ago
Romain Vimont ca9e1a0514 Add compilation flag for USB features
This allows to disable HID/OTG features on Linux to build without
libusb.
2 years ago
Romain Vimont cc27771dd1 Add compilation flag for V4L2 feature
This allows to disable V4L2 support on Linux to build without
libavdevice.
2 years ago
Romain Vimont d0ab8c0e7b Fix double adb tunnel closing
On error, close the adb tunnel only if it has not already been closed
beforehand.
2 years ago
Romain Vimont 5c62f3419d Rename buffer util functions with sc_ prefix 2 years ago
Romain Vimont 044acc2259 Rename HEADER_SIZE to SC_PACKET_HEADER_SIZE
Prefix the constant for consistency.
2 years ago
Romain Vimont 6fc388f369 Remove unused BUFSIZE 2 years ago
Romain Vimont 1c02b58412 Remove sc_demuxer_parse()
Now that the key frame flag is known, parsing the packet is useless.
2 years ago
Romain Vimont 67068e4e3d Pass key frame flag from the device
MediaCodec indicates when a packet is a key frame. Transmit it to the
client.
2 years ago
Romain Vimont e3c2398aa2 Store packet flags in PTS most significant bits
A special PTS value was used to encode a config packet.

To prepare for adding more flags, use the most significant bits of the
PTS field to store flags.
2 years ago
Romain Vimont 29c163959c Indent ifdef for clarity
Make it explicit that the ifdef is an inner block.
2 years ago
Romain Vimont 4a95c08d56 Improve error message for unsupported usb hotplug 2 years ago
Romain Vimont 7848a387c8 Do not duplicate relative mouse mode state
The relative mouse mode is tracked by SDL, and accessible via
SDL_GetRelativeMouseMode().

This is more robust in case SDL changes the relative mouse mode on its
own.
2 years ago
Romain Vimont 43ae418752 Fix USB device leak on connection error
If sc_usb_connect() failed, then the sc_usb_device was never destroyed.

The assignment was mistakenly removed by commit
61969aeb80.
2 years ago
Romain Vimont 8d583d36e2 Move prebuilt-deps/ to app/
The prebuilt dependencies are specific to the client app (not the
server).

This also avoids to reference the parent directory (../) from
app/meson.build.
2 years ago
Romain Vimont f86df817f9 Print libusb version on --version 2 years ago
Romain Vimont 9a546ef1af Print both compiled and linked versions of libs
On --version, print both the version scrcpy had been compiled against,
and the version linked at runtime.
2 years ago
Romain Vimont 9477594f80 Move version handling to a separate file
This will avoid to include all dependencies headers from main.c.
2 years ago
Romain Vimont 29828aa330 Log device opening errors during listing
Without this log, the user would have no way to know that a USB device
is rejected because it could not be opened (typically due to
insufficient permissions).
2 years ago
Romain Vimont 582161607e Add option to select USB or TCP/IP devices
If several devices are connected (as listed by `adb devices`), it was
necessary to provide the explicit serial via -s/--serial.

If only one device is connected via USB (respectively, via TCP/IP), it
might be convenient to select it automatically. For this purpose, two
new options are introduced:
 - -d/--select-usb: select the single device connected over USB
 - -e/--select-tcpip: select the single device connected over TCP/IP

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 146f65d7b2 Introduce adb device selector
Currently, a device is selected either from a specific serial, or if it
is the only one connected.

In order to support selecting the only device connected via USB or via
TCP/IP separately, introduce a new selection structure.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 5ed13ef477 Execute adb start-server
This does nothing if the adb daemon is already started, but allows to
print any output/errors to the console.

Otherwise, the daemon starting would occur during `adb devices`, which
does not output to the console because the result is parsed.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 9c545e8c29 Remove sc_adb_get_serialno()
The device serial is now retrieved from `adb devices -l`, `adb
get-serialno` is not called anymore.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 0a619dc9ef Allow selecting a device from IP without port
Since the previous commit, if a serial is given via -s/--serial (either
a real USB serial or an IP:port), a device is selected if its serial
matches exactly.

In addition, if the user pass an IP without a port, then select any
device with this IP, regardless of the port (so that "192.168.1.1"
matches any "192.168.1.1:port"). This is also the default behavior of
adb.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 4692d13179 Expose simple API to select a single adb device
Select an adb device from the output of `adb device -l`.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 02d46b2262 Expose function to test if a serial is TCP/IP
In practice, it just tests if the serial contains a ':', which is
sufficient to distinguish ip:port from a real USB serial.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 4389de1c23 Add adb devices parser
Add a parser of `adb device -l` output, to extract a list of devices
with their serial, state and model.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 85ff70fc95 Refactor device configuration
Depending on the parameters passed to scrcpy, either the initial device
serial is necessary or not. Reorganize to simplify the logic.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 700503df6c List and select USB devices separately
List all USB devices in a first step, then select the matching one(s).

This allows to report a user-friendly log message containing the list of
devices, with the matching one(s) highlighted.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 61969aeb80 Expose simple API to select a single USB device
The caller just wants a single device. Handle all cases and error
messages internally.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont b88c4aa75e Add move-function for sc_usb_device
Add a function to "move" a sc_usb_device into another instance.

This will avoid unnecessary copies.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 8c50342fb2 Move SC_PRIsizet to compat.h
Define the printf format macro for size_t in compat.h so that it can be
used from anywhere.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 0eadf95a3e Rename function to destroy a list of USB devices
Rename from "usb_device_" to "usb_devices_".

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 6df2205cf3 Add generic LOG() macro with level parameter
One log macro was provided for each log level (LOGV(), LOGD(), LOGI(),
LOGW(), LOGE()).

Add a generic macro LOG(LEVEL, ...) accepting a log level as parameter,
so that it is possible to write logging wrappers.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2 years ago
Romain Vimont 61b6324ee9 Remove LOGC()
It is not clear when to use LOGC() rather than LOGE(). Always use
LOGE().

Moreover, enum sc_log_level has no "critical" log level.
2 years ago
Romain Vimont f20137d2ac Improve USB device open log
For consistency with "List USB devices", log "Open USB device".
2 years ago
Romain Vimont b60809a4da Inline USB device opening
Such a separate function was useless.
2 years ago
Romain Vimont b0e04aa327 Remove log_libusb_error()
This helper did not help a lot, and prevented the client to choose the
log level and the prefix error message.
2 years ago
Romain Vimont 137d2c9791 Remove confusing sc_str_truncate()
This util function was error-prone:
 - it accepted a buffer as parameter (not necessarily a NUL-terminated
   string) and its length (including the NUL char, if any);
 - it wrote '\0' over the last character of the buffer, so the last
   character was lost if the buffer was not a NUL-terminated string, and
   even worse, it caused undefined behavior if the length was empty;
 - it returned the length of the resulting NUL-terminated string,
   which was inconsistent with the input buffer length.

In addition, it was not necessarily optimal:
 - it wrote '\0' twice;
 - it required to know the buffer length, that is the input string
   length + 1, in advance.

Remove this function, and let the client use strcspn() manually.
2 years ago
Romain Vimont 6d41c53b61 Fix adb connect parsing
The function assumed that the raw output of "adb connect" was a
NUL-terminated string, but it is not the case.

It this output did not end with a space or a new line character, then
sc_str_truncate() would write '\0' over the last character. Even worse,
if the output was empty, then sc_str_truncate() would write
out-of-bounds.

Avoid the error-prone sc_str_truncate() util function.
2 years ago
Romain Vimont 8d540e83c7 Fix adb get-serialno parsing
The function assumed that the raw output of "adb get-serialno" was a
NUL-terminated string, but it is not the case.

It this output did not end with a space or a new line character, then
sc_str_truncate() would write '\0' over the last character. Even worse,
if the output was empty, then sc_str_truncate() would write
out-of-bounds.

Avoid the error-prone sc_str_truncate() util function.
2 years ago
Romain Vimont 2ea12f73db Fix adb getprop parsing
The function assumed that the raw output of "adb getprop" was a
NUL-terminated string, but it is not the case.

It this output did not end with a space or a new line character, then
sc_str_truncate() would write '\0' over the last character. Even worse,
if the output was empty, then sc_str_truncate() would write
out-of-bounds.

Avoid the error-prone sc_str_truncate() util function.
2 years ago
Romain Vimont 5d6bd8f9cd Fix adb device ip parsing
The parser assumed that its input was a NUL-terminated string, but it
was not the case: it is just the raw output of "adb devices ip route".

In practice, it was harmless, since the output always ended with '\n'
(which was replaced by '\0' on truncation), but it was incorrect
nonetheless.

Always write a '\0' at the end of the buffer, and explicitly parse as a
NUL-terminated string. For that purpose, avoid the error-prone
sc_str_truncate() util function.
2 years ago
Romain Vimont 5b3ae2cb2f Store actual serial in sc_server
Before starting the server, the actual device serial (possibly its
ip:port if it's over TCP/IP) must be known.

A serial might be requested via -s/--serial (stored in the
sc_server_params), but the actual serial may change afterwards:
 - if none is provided, then it is retrieved with "adb get-serialno";
 - if --tcpip is requested, then the final serial will be the target
   ip:port.

The requested serial was overwritten by the actual serial in the
sc_server_params struct, which was a bit hacky.

Instead, store a separate serial field in sc_server (and rename the one
from sc_server_params to "req_serial" to avoid confusion).
2 years ago
Romain Vimont 08f16a9dde Simplify switch to TCPIP function
Do not use an output parameter to return the value. Instead, return the
actual ip:port string on success or NULL on error.
2 years ago
Romain Vimont 386cf7d7ac Build adb argv statically
Now that providing a serial is mandatory for adb commands where it is
relevant, the whole argv array may be built statically, without
allocations at runtime.
2 years ago
Romain Vimont 5e2bfccab4 Expose adb executable path publicly
This will allow the caller to build the argv array directly.
2 years ago
Romain Vimont ba30ca5c1e Rename adb_command to adb_executable
Semantically, a "command" refers to the whole command line argv (adb and
its arguments).
2 years ago
Romain Vimont 028e7afe32 Assert non-NULL serial
If no serial is passed, then the command would work if there is exactly
one device connected, but will fail with multiple devices.

To avoid such cases, ensure that a serial is always provided.
2 years ago
Romain Vimont 6ca9825c0f Assert "adb disconnect" is called with an argument
Calling "adb disconnect" without argument would disconnect every TCP/IP
device. We must make sure scrcpy never does that.
2 years ago
Romain Vimont f807131c0a Remove useless undef
The #define was removed in 1c71bd16be.
2 years ago
Romain Vimont 21106bd70a Remove screensaver log
If --disable-screensaver is passed, then screensaver is disabled,
otherwise it is enabled. No need for a log.
2 years ago
Romain Vimont bd3c93ae3d Remove platform-tools installation suggestion
On Windows, adb is provided in the release archive. Most missing adb
issues come from users setting the ADB environment variable to an
incorrect value (on all platforms).

Suggesting to install platform-tools to solve the problem will just make
things worse (there will be one more adb in yet another location).
2 years ago
Romain Vimont 9e3902f30c Use sc_ prefix for adb 2 years ago
Romain Vimont 7810ca61b0 Move ADB code to adb/ 2 years ago
Romain Vimont c460243ce2 Simplify demuxer
Call the same push_packet_to_sinks() in all cases, and make
sc_demuxer_parse() return void.
2 years ago
Romain Vimont 7dec225ceb Rename stream to sc_demuxer
For consistency with recorder and decoder, name the component which
demuxes a "demuxer".

And add the missing sc_ prefix.
2 years ago
Romain Vimont 4ee62abe1d Use sc_ prefix for recorder 2 years ago
Romain Vimont 0080d0b0ff Use sc_ prefix for decoder 2 years ago
CennoxX 0bf7e4ddc4 Add missing spaces in help
PR #2994 <https://github.com/Genymobile/scrcpy/pull/2994>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2 years ago
Romain Vimont f02f2135cd Fix include for standard library header 2 years ago
Romain Vimont 9b4360b6b8 Add warning in function documentation
The function parsing "ip route" output modifies the input buffer to
tokenize in place. This must be mentioned in the function documentation.
2 years ago
Romain Vimont c8d0f5cdeb Fix sc_str_truncate() documentation
The function was initially implemented to truncate lines, but was later
generalized to accept custom delimiters. The whole documentation has not
been updated accordingly.

Refs 9619ade706
2 years ago
Romain Vimont 22d9f0faf4 Fix comment typo 2 years ago
Romain Vimont 64a09513ae Bump version to 1.22 2 years ago
Romain Vimont 38cdcdda50 Improve prebuilt system
This aims to fix two issues with the previous implementation:
 1. the whole content of downloaded archives were extracted, while only
    few files are necessary;
 2. the archives were extracted in the prebuild-deps/ directory as is.

As a consequence of (2), the actual directory name relied on the root
directory of the archive. For adb, this root directory was always
"platform-tools", so when bumping the adb version, the target directory
already existed and the dependency was not upgraded (the old one had to
be removed manually).

Expose common function to download a file and check its checksum, but
let the custom script for each dependency extract only the needed files
and reorganize the content if necessary.
2 years ago
Romain Vimont b8d7f36ba3 Fix SC_EXIT_CODE_NONE value
The exit code on windows is stored in a DWORD, an unsigned long:
<https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/262627d8-3418-4627-9218-4ffe110850b2>

Use the max value of this type for SC_EXIT_CODE_NONE.
2 years ago
Romain Vimont 80bec70852 Add helper to log Windows system errors
It will help to log errors returned by GetLastError() or
WSAGetLastError():
 - <https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror>
 - <https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsagetlasterror>
 - <https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes#system-error-codes>

Always log the errors in English to be able to read them in bug reports.
2 years ago
Romain Vimont 5508c635cb Enable mouse focus clickthrough in OTG mode
A single click on the window must both give focus and capture the mouse.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont ea68a003a2 Make HID keyboard and mouse optional in OTG mode
Allow to only enable HID keyboard or HID mouse:

    scrcpy --otg -K   # keyboard only
    scrcpy --otg -M   # mouse only
    scrcpy --otg -KM  # keyboard and mouse
    scrcpy --otg      # keyboard and mouse

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont 91418c79ab Add OTG mode
Add an option --otg to run scrcpy with only physical keyboard and mouse
simulation (HID over AOA), without mirroring and without requiring adb.

To avoid adding complexity into the scrcpy initialization and screen
implementation, OTG mode is implemented totally separately, with a
separate window.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont 36aaf70279 Move input event helpers
Input events helpers to convert from SDL events to scrcpy events were
implemented in input_manager. To reuse them for OTG mode, move them to
input_events.h.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont 1a03206e36 Detect USB device disconnection
The device disconnection is detected when the video socket closes.

In order to introduce an OTG mode (HID events) without mirroring (and
without server), we must be able to detect USB device disconnection.

This feature will only be used in OTG mode.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont 37987b822e Make acksync optional for AOA initialization
Acksync is used to delay HID events until some request (in practice,
device clipboard synchronization) is acknowledged by the device.

This mechanism will not be necessary for OTG mode.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont 8fc9dca8cb Make serial optional to find USB devices
If no serial is provided, then list all available USB devices (which can
be open and having a serial).

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont 1c17f57c10 Find a list of devices instead of a single one
Several devices may match the requested serial, but above all, this
paves the way to list all devices (when no serial is provided).

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont d8b37fe189 Wrap libusb_device
Introduce a structure to wrap a libusb_device and expose its descriptor
data read during discovery.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont 0ee9e2ff51 Expose function to find a USB device
The device was automatically found by sc_usb_connect(). Instead, expose
a function to find a device from a serial, and let the caller connect to
the device found (if any).

This will allow to list all devices first, then select one device to
connect to.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont 1ab3692f3d Add util function to read USB descriptor string
Use it from accept_device() to simplify (at the cost an additional
allocation for each serial, but it is not important).

It will also be useful in other functions in further commits.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont bbef426a4b Split USB initialization and connection
This will allow to execute other USB calls (retrieving the device list
for example) before connecting to the selected device.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont 2114f48185 Find device with USB context
An explicit context was used everywhere except for listing the devices.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont b779eca8d3 Remove libusb_device field
It is possible to retrieve the device instance from the handle via
libusb_get_device(), so we don't need to reference the device one more
time.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont adda47b0f7 Move sc_usb out of sc_aoa
This will allow to initialize a USB device separately and pass it to
sc_aoa.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont 48e3ff284f Make serial mandatory for sc_usb
In practice, it is already mandatory.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont 1d6f9952ee Extract USB handling from AOA
The AOA code handled both USB initialization and AOA commands/events.
Extract USB-related code to a separate file and structure.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont d48d191262 Rename HAVE_AOA_HID to HAVE_USB
The condition actually determines whether scrcpy can use libusb or not.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont 2762f5d183 Move AOA/HID code to usb/
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2 years ago
Romain Vimont c996a6d462 Fix socket close race condition
The server needs to interrupt the sockets on stop, but it must not close
them while other threads may attempt to read from or write to them.

In particular, the video_socket is read by the stream thread, and the
control_socket is written by the controller and read by receiver.

Therefore, close the socket only on sc_server_destroy(), which is called
after all other threads are joined.

Reported by TSAN on close:

    WARNING: ThreadSanitizer: data race (pid=3287612)
      Write of size 8 at 0x7ba000000080 by thread T1:
        #0 close ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:1690 (libtsan.so.0+0x359d8)
        #1 net_close ../app/src/util/net.c:280 (scrcpy+0x23643)
        #2 run_server ../app/src/server.c:772 (scrcpy+0x20047)
        #3 <null> <null> (libSDL2-2.0.so.0+0x905a0)

      Previous read of size 8 at 0x7ba000000080 by thread T16:
        #0 recv ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:6603 (libtsan.so.0+0x4f4a6)
        #1 net_recv_all ../app/src/util/net.c:228 (scrcpy+0x234a9)
        #2 stream_recv_packet ../app/src/stream.c:33 (scrcpy+0x2045c)
        #3 run_stream ../app/src/stream.c:228 (scrcpy+0x21169)
        #4 <null> <null> (libSDL2-2.0.so.0+0x905a0)

Refs ddb9396743
2 years ago
Romain Vimont 8ea6fb1f0f Print version on stdout
Refs b25404ee4b
2 years ago
Romain Vimont b546c33eff Do not print scrcpy version twice on --version
Refs 6da6d905c2
2 years ago
Romain Vimont 4817cadd09 Fix code style
Align function parameters.
2 years ago
Romain Vimont 02b5e87802 Slightly reduce lock usage
Locking the frame_buffer mutex to reference the input frame into the
tmp_frame is unnecessary.

This also fixes the missing unlock on error.
2 years ago
Romain Vimont 8e4d3beb01 Fix return value on adb commands error 2 years ago
Romain Vimont 9d2e00697e Use sc_ prefix for control_msg enums
Refs afa4a1b728
2 years ago
Romain Vimont f289d206ea Disable more actions if --no-control
If control is disabled, then do not enable "show touches" or
automatically power off the device on close.
2 years ago
Romain Vimont ca516f4318 Refactor if-block in cli
Several tests must be performed if opts->control is false.
2 years ago
Romain Vimont 5d6076bffd Move misplaced break statements
With ifdefs, the resulting code could contain both a return statement
and a break.
2 years ago
Romain Vimont e0bce1725b Fix header guard prefix 2 years ago
Romain Vimont 063d103dd6 Capture mouse on start for --hid-mouse
If relative mode is enabled, capture the mouse immediately.
2 years ago
Romain Vimont 4bf9c057fe Extract relative mode check to an inline function
This will allow to reuse the condition in another function.
2 years ago
Romain Vimont 17c97820b2 Never forward capture keys
In relative mode, Alt and Super are "capture keys". Never forward them
to the input manager, to avoid inconsistencies between UP and DOWN
events.
2 years ago
Romain Vimont 8c7f0ed5ea Fix warning message
Make the message consistent for HID keyboard and HID mouse.
2 years ago
Romain Vimont ac038f276e Add missing break statement
This was harmless because this is the last "case" of the switch, but for
consistency, add the missing break.
2 years ago
Romain Vimont 1f65b1bf87 Remove inline hint
There is no reason to request inlining here.
2 years ago
Romain Vimont d41a46dc95 Handle libusb_get_device_descriptor() error
The function libusb_get_device_descriptor() might return an error.
Handle it.
2 years ago
Romain Vimont 308a1f8192 Simplify error handling in sc_aoa_init()
Use goto to avoid many repetitions.
2 years ago
Romain Vimont 241a587e61 Fix missing HID mouse destructor call
The destructor unregisters the HID mouse, so it was not reported as a
leak, but it must still be called.
2 years ago
Romain Vimont 7e35bfe382 Refactor if-blocks
Group all conditions requiring a controller in a single if-block.
2 years ago
Romain Vimont 855819bbd8 Remove redundant control boolean
The controller is NULL if and only if control is disabled, so an
additional control boolean is redundant.
2 years ago
Romain Vimont 557daf280e Pass NULL controller if control is disabled
If --no-control is requested, then the controller instance is not
initialized. However, its reference was still passed to screen and
input_manager.

Instead, pass NULL if no controller is available.
2 years ago
Romain Vimont 0b8e926330 Do not process finger events if no control
If --no-control is passed, then im->mp is NULL, so processing touches
would crash.
2 years ago
Romain Vimont 0ec3361bc9 Fix crash on --no-control
Relative mouse mode assumed that a mouse processor was always available,
but this is not the case if --no-control is passed.
2 years ago
Romain Vimont 81ff7ebd06 Simplify event loop
Merge single event handling with the event loop function.
2 years ago
Romain Vimont 1ffe312369 Handle file drop from input_manager
A file is pushed (or an apk is installed) to the device on file drop.
This behavior is specific to the screen and its input_manager.
2 years ago
Romain Vimont ebef027c4f Do not return status for event handling
It is never read. Simplify.
2 years ago
Romain Vimont 8e4e7d42f1 Fix leak on file pusher error
If a file_push request fails, the allocated filename must be freed.
2 years ago
Romain Vimont b066dc0bbf Rename file_handler to sc_file_pusher
Rename handler to pusher ("handler" is too generic), and add sc_ prefix.
2 years ago
Romain Vimont 3a0ba7d0a4 Disable downsizing on error if V4L2 is enabled
V4L2 device is created with the initial device size, it does not support
resizing.

PR #2947 <https://github.com/Genymobile/scrcpy/pull/2947>
2 years ago
Romain Vimont 75c5dc6859 Position and size the window on first frame
The optimal initial size was computed from the expected dimensions, sent
immediately by the server before encoding any video frame.

However, the actual frame size may be different, for example when the
device encoder does not support the requested size.

To always handle this case properly, position and size the window only
once the first frame size is known.

PR #2947 <https://github.com/Genymobile/scrcpy/pull/2947>
2 years ago
Romain Vimont fa30f9806a Move "show window" call on first frame
Show the window only after the actual frame size is known (and if no
error has occurred).

This will allow to properly position and size the window when the size
of the first frame is different from the size initially announced by the
server.

PR #2947 <https://github.com/Genymobile/scrcpy/pull/2947>
2 years ago
Romain Vimont 4fb61ac83d Fix screen comments
The position fields accept SC_WINDOW_POSITION_UNDEFINED, not the size
fields.

PR #2947 <https://github.com/Genymobile/scrcpy/pull/2947>
2 years ago
Romain Vimont 15bf27afdd Make auto-downsize on error optional
Add --no-downsize-on-error option to disable attempts to use a lower
definition on MediaCodec error.

PR #2947 <https://github.com/Genymobile/scrcpy/pull/2947>
2 years ago
Romain Vimont b3ff1f6b3b Upgrade FFmpeg (5.0) for Windows 64-bit
Use FFmpeg win64 binaries from gyan.dev (referenced from ffmpeg.org):

 - https://www.gyan.dev/ffmpeg/builds/
 - https://ffmpeg.org/download.html#build-windows

Keep the old FFmpeg prebuilt binaries (4.3.1) for win32 builds.

Fixes #1753 <https://github.com/Genymobile/scrcpy/issues/1753>
Refs #1838 <https://github.com/Genymobile/scrcpy/pull/1838>
Refs #2583 <https://github.com/Genymobile/scrcpy/pull/2583>
PR #2952 <https://github.com/Genymobile/scrcpy/pull/2952>

Co-authored-by: Yu-Chen Lin <npes87184@gmail.com>
Co-authored-by: nkh0472 <nkh0472@hotmail.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2 years ago
Romain Vimont a2495c5ef1 Use symlink to simplify Windows ffmpeg dependency
The FFmpeg dependency is downloaded from two separate zipfiles.

Symlink include/ to expose everything from a single directory, to
simplify the meson script.

PR #2952 <https://github.com/Genymobile/scrcpy/pull/2952>
2 years ago
Bernhard Rosenkränzer 5e8fa56e7a Fix build with ffmpeg 5.0
PR #2948 <https://github.com/Genymobile/scrcpy/pull/2948>

Signed-off-by: Bernhard Rosenkränzer <bero@lindev.ch>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2 years ago
Romain Vimont 1c71bd16be Use constant string for known booleans
Boolean options explicitly passed to the server are statically known.
2 years ago
Romain Vimont afa4a1b728 Use sc_ prefix for control_msg 2 years ago
Romain Vimont 3a4d5c7f18 Use sc_ prefix for controller 2 years ago
Romain Vimont 5f7ddff8ae Use sc_ prefix for input_manager 2 years ago
Romain Vimont 2a0c2e5e99 Use sc_ prefix for screen 2 years ago
Romain Vimont a6644e831b Fix code style
Limit to 80 chars.
2 years ago
Romain Vimont 75655194fb Do not pass scrcpy_options to keyboard inject
The components should be configurable independently of the global
scrcpy_options instance: their configuration could be provided
separately, like it is the case for example for some screen parameters.

For consistency, keyboard injection should not depend on scrcpy_options.
2 years ago
Romain Vimont cba84f6999 Add support for HID mouse 3 years ago
Romain Vimont ed2e45ee29 Refactor AOA/HID keyboard initialization
This paves the way to add support for HID mouse initialization.
3 years ago
Romain Vimont aee1b39790 Add CLAMP() macro 3 years ago
Romain Vimont 17d01b5bf7 Add UI/UX support for relative mouse mode
In relative mouse mode, the mouse pointer must be "captured" from the
computer.

Toggle (disable/enable) relative mouse mode using any of the hardcoded
capture keys:
 - left-Alt
 - left-Super
 - right-Super

These capture keys do not conflict with shortcuts, since a shortcut is
always a combination of the MOD key and some other key, while the
capture key triggers an action only if it is pressed and released alone.

The relative mouse mode is also automatically enabled on any click in
the window, and automatically disabled on focus lost (it is possible to
lose focus even without the mouse).
3 years ago
Romain Vimont 40fca82b60 Forward all motion events to mouse processors
The decision to not send motion events when no click is pressed is
specific to Android mouse injection. Other mouse processors (e.g. for
HID mouse) will need to receive all events.
3 years ago
Romain Vimont 643293752d Provide relative mouse motion vector in event
This will allow the mouse processor to handle relative motion easily.
3 years ago
Romain Vimont b5855e5deb Add relative mode flag to mouse processors
The default mouse injection works in absolute mode: it forwards clicks
at a specific position on screen.

To support HID mouse, add a flag to indicate that the mouse processor
works in relative mode: it forwards mouse motion vectors, without any
absolute reference to the screen.
3 years ago
Romain Vimont 924375487e Pass buttons state in scroll events
A scroll event might be produced when a mouse button is pressed (for
example when scrolling while selecting a text). For consistency, pass
the actual buttons state (instead of 0).

In practice, it seems that this use case does not work properly with
Android event injection, but it will work with HID mouse.
3 years ago
Romain Vimont 7121a0dc53 Destroy acksync immediately on error
If AOA or HID keyboard may not be initialized for some reason, acksync
is useless.
3 years ago
Romain Vimont f04812fc71 Remove duplicate boolean
The AOA initialization state is already tracked by aoa_hid_initialized.
3 years ago
Romain Vimont 5ce1ccde85 Reorder controller and HID initialization
This allows to merge two "#ifdef HAVE_AOA_HID" blocks to simplify.
3 years ago
Romain Vimont 6102a0b5bb Move input_manager into screen
The input_manager is strongly tied to the screen, it could not work
independently of the specific screen implementation.

To implement a user-friendly HID mouse behavior, some SDL events
will need to be handled both by the screen and by the input manager. For
example, a click must typically be handled by the input_manager so that
it is forwarded to the device, but in HID mouse mode, the first click
should be handled by the screen to capture the mouse (enable relative
mouse mode).

Make the input_manager a descendant of the screen, so that the screen
decides what to do on SDL events.

Concretely, replace this structure hierarchy:

     +- struct scrcpy
        +- struct input_manager
        +- struct screen

by this one:

     +- struct scrcpy
        +- struct screen
           +- struct input_manager
3 years ago
Romain Vimont 2b34e1224e Use separate struct for input manager params
This avoids to directly pass the options instance (which contains more
data than strictly necessary), and limit the number of parameters for
the init function.
3 years ago
Romain Vimont a9d23400cd Remove unused enum value requiring SDL 2.0.18
Refs b8fed50639
Fixes #2924 <https://github.com/Genymobile/scrcpy/issues/2924>
3 years ago
Romain Vimont cca3c953da Enable virtual finger only on left click
The pinch-to-zoom feature must only be enabled with Ctrl+left_click.
3 years ago
Romain Vimont 57f1655d4b Make some mouse processors ops optional
Do not force all mouse processors to implement scroll events or touch
events.
3 years ago
Romain Vimont bc674721dc Make process_text() optional
Not all key processors support text injection (HID keyboard does not
support it).

Instead of providing a dummy op function, set it to NULL and check on
the caller side before calling it.
3 years ago
Romain Vimont 63e29b1782 Apply buttons mask if not --forward-all-clicks
If --forward-all-clicks is not set, then only left clicks are forwarded.
For consistency, also mask the buttons state in other events.
3 years ago
Romain Vimont 3c15cbdaf8 Reorder mouse processor ops
Group the mouse events callbacks before the touch event callback.
3 years ago
Romain Vimont 96e0e89740 Simplify mouse injection implementation
The static functions are now so simple that they become unnecessary: the
control message may be initialized directly instead.
3 years ago
Romain Vimont a1f2f5fbd3 Make some event conversions infallible
When the implementation handles all possible input values, it may never
fail.
3 years ago
Romain Vimont 9460bdd87b Use scrcpy input events for mouse processors
Pass scrcpy input events instead of SDL input events to mouse
processors.

These events represent exactly what mouse processors need, abstracted
from any visual orientation and scaling applied on the SDL window.

This makes the mouse processors independent of the "screen" instance,
and the implementation source code independent of the SDL API.
3 years ago
Romain Vimont b4b638e8fe Use scrcpy input events for key processors
Pass scrcpy input events instead of SDL input events to key processors.

This makes the source code of key processors independent of the SDL API.
3 years ago
Romain Vimont e4396e34c2 Use common sc_action in input manager
Now that the scrcpy input events API exposes a sc_action enum, use the
same from the input manager.
3 years ago
Romain Vimont b8fed50639 Add intermediate input events layer
This aims to make the key/mouse processors independent of the "screen",
by processing scrcpy-specific input events instead of SDL events.

In particular, these scrcpy events are not impacted by any UI window
scaling or rotation (contrary to SDL events).
3 years ago
Romain Vimont d540c72e7c Rename SC_MOD_* to SC_SHORTCUT_MOD_*
This will avoid conflicts with new SC_MOD_* constants.
3 years ago
Romain Vimont cd5891fee6 Remove actions bitset
The input manager exposed functions taking an "actions" parameter,
containing a bitmask-OR of ACTION_UP and ACTION_DOWN.

But they are never called with both actions simultaneously anymore, so
simplify.

Refs 964b6d2243
Refs d0739911a3
3 years ago
Romain Vimont 26ee7ce566 Expose V4L2 option on all platforms
This allows to report a meaningful error message if an unsupported
feature is used on an incompatible platform. This is consistent with the
behavior of -K/--hid-keyboard.
3 years ago
Romain Vimont ba28d817fb Fail on unsupported HID option
If the feature is not supported on the platform, fail during command
line parsing instead of using a fallback.
3 years ago
Romain Vimont 37124e1452 Avoid unused function warning
If HAVE_SOCK_CLOEXEC is not defined, then sc_raw_socket_close() is never
used. Add an #ifndef block to remove the warning.
3 years ago
Romain Vimont 6b9f397733 Happy new year 2022! 3 years ago
Romain Vimont 1fbc590b26 Fix memory leaks in tests
Tests were failing when run with ASAN enabled.
3 years ago
Romain Vimont 826ddf1a6e Document HID keyboard events 3 years ago
Romain Vimont 6261bb0b5a Ignore display bounds on resize-to-fit
The "resize to fit" feature (MOD+w or double-click on black borders)
computed the "optimal size" using the same function computing the
initial window size on start.

However, on "resize to fit", only the black borders must be removed (the
content size must be preserved), so the display bounds must not be
considered.
3 years ago
Romain Vimont 2f091beeaa Simplify sc_size assignment
Assign the whole struct instead of each field separately.
3 years ago
Romain Vimont ad11c5babb Set DPI awareness for Windows
Add a windows manifest to set the DPI awareness by default:
<https://docs.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process>

Refs #40 <https://github.com/Genymobile/scrcpy/issues/40>
Fixes #2865 <https://github.com/Genymobile/scrcpy/issues/2865>
3 years ago
Romain Vimont feb250a973 Fix typos reported by codespell 3 years ago
Chih-Hsuan Yen d049671908 Fix adb server hang
Since commit 0426708544, the server is run
in a dedicated thread. For SDL, many signals, including SIGINT and
SIGTERM, are masked for new threads. As a result, if the adb server is
not already running, adb commands invoked by scrcpy will start an adb
server that ignores those signals and cannot be terminated at system
shutdown.

Fixes #2873 <https://github.com/Genymobile/scrcpy/issues/2873>
PR #2870 <https://github.com/Genymobile/scrcpy/pull/2870>

Signed-off-by: Romain Vimont <rom@rom1v.com>
3 years ago
Romain Vimont 0685c491cd Improve crossbuild configuration
Use meson native features to detect crossbuild, and remove the
user-provided option crossbuild_windows.
3 years ago
Romain Vimont 29570ee819 Add metadata to scrcpy.exe for Windows
Refs <https://stackoverflow.com/a/708382/1987178>
3 years ago
Romain Vimont cfcbc2ac21 Add icon to scrcpy.exe
The icon will be associated to scrcpy.exe in the Windows explorer.

The .ico was created using imagemagick:

    convert icon.png icon.ico

It is included as a binary for simplicity.

Refs #2815 <https://github.com/Genymobile/scrcpy/issues/2815>
3 years ago
Romain Vimont 2cb4e04209 Update copyright date to 2021 in manpage
December, it's time to update to 2021!
3 years ago
Romain Vimont 878ffffc36 Update environment variables section in manpage
Use the same content as the section printed with --help.
3 years ago
Romain Vimont f0361fc8b3 Add environment variables in help
Print the list of environment variables used by scrcpy in --help.
3 years ago
Romain Vimont b5d4ec61fc Move newline generation in help
If we removed the shortcuts intro, we would not need the additional '\n'
of the section title, so it should be printed along with the shortcuts
intro.
3 years ago
Romain Vimont 3ada5c51bc Rename scrcpy threads
Prefix the name of threads by "scrcpy-". This improves readability in
the output of `top -H` for example.

Limit the thread names to 16 bytes, because it is limited on some
platforms.
3 years ago
Romain Vimont 09c55b0f93 Set "low delay" decoder flag
I don't really know the concrete benefits, but scrcpy definitely wants
low delay decoding.

Suggested-by: François Cartegnie <fcvlcdev@free.fr>
3 years ago
Romain Vimont 682a691173 Use timers with microsecond precision
SDL only provides millisecond precision. Use system timers to get a
better precision.
3 years ago
Romain Vimont ddb9396743 Interrupt and close sockets on server stop
The sockets were never interrupted or closed by the client since recent
changes to run the server from a dedicated thread (see commit
0426708544).

As a side effect, the server could never terminate properly (it was
waiting on socket blocking calls), so it was always killed by the client
after the WATCHDOG_DELAY.

Interrupt the sockets on stop to give the servera chance to terminate
property, then close them.
3 years ago
Romain Vimont cabcbc2b15 Do not create control socket if no control
If --no-control is enabled, then it is not necessary to create a second
communication socket between the client and the server.

This also facilitates the use of the server alone (without the client)
to receive only the raw video stream.
3 years ago
Romain Vimont 80fe12a95f Require libavcodec >= 57.37
In ffmpeg/doc/APIchanges:

> 2016-04-21 - 7fc329e - lavc 57.37.100 - avcodec.h
>   Add a new audio/video encoding and decoding API with decoupled input
>   and output -- avcodec_send_packet(), avcodec_receive_frame(),
>   avcodec_send_frame() and avcodec_receive_packet().

Refs de9b79ec2d

Refs #2862 <https://github.com/Genymobile/scrcpy/issues/2862>
3 years ago
Romain Vimont 099c546580 Require libavformat >= 57.33
In ffmpeg/doc/APIchanges:

> 2016-04-11 - 6f69f7a / 9200514 - lavf 57.33.100 / 57.5.0 - avformat.h
>   Add AVStream.codecpar, deprecate AVStream.codec.

Refs 5d9e96dc4e

Refs #2862 <https://github.com/Genymobile/scrcpy/issues/2862>
3 years ago
Romain Vimont dca2c5f94f Require SDL >= 2.0.5
Icon loading uses SDL_CreateRGBSurfaceWithFormatFrom(), available since
SDL 2.0.5 (in 2016).

Refs #2862 <https://github.com/Genymobile/scrcpy/issues/2862>
3 years ago
Romain Vimont 90cf956f57 Remove spurious ';' 3 years ago
Romain Vimont 36c8778d2d Add missing comma
Thank you clang:

    ../app/src/control_msg.c:45:5: warning: suspicious concatenation of
    string literals in an array initialization; did you mean to separate
    the elements with a comma? [-Wstring-concatenation]
        "hover-exit",
        ^
3 years ago
Romain Vimont ae90ef22db Add a unit test for clipboard text length
This would have catched the possible memcpy() overflow fixed by the
previous commit.

Refs #2859 <https://github.com/Genymobile/scrcpy/pull/2859>
3 years ago
Yu-Chen Lin d80bc25eba Fix overflow in memcpy
In function ‘memcpy’,
    inlined from ‘control_msg_serialize.constprop’ at ../app/src/control_msg.c:77:5,
    inlined from ‘run_controller’ at ../app/src/controller.c:69:12:
        /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34:10:
        warning: ‘__builtin___memcpy_chk’ writing 262138 bytes into a region
        of size 262130 overflows the destination [-Wstringop-overflow=]
   return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));

Refs 901d837165
PR #2859 <https://github.com/Genymobile/scrcpy/pull/2859>

Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
3 years ago
Yu-Chen Lin daa06abd34 Fix comment in control message serialization
Refs 245999aec4

Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
3 years ago
Romain Vimont 94702a4309 Fix memset() size in tests
The memset() size was 1 byte too long. It was harmless because the last
'a' was overwritten by '\0`.
3 years ago
Romain Vimont 65fbec9643 Mention SCRCPY_ICON_PATH env var in manpage 3 years ago
Romain Vimont 64a04b8d4a Fix process execution on Windows 7
According to this bug report on Firefox:
<https://bugzilla.mozilla.org/show_bug.cgi?id=1460995>

> CreateProcess fails with ERROR_NO_SYSTEM_RESOURCES on Windows 7. It
> looks like the reason why is because PROC_THREAD_ATTRIBUTE_HANDLE_LIST
> doesn't like console handles.

To avoid the problem, do not pass console handles to
PROC_THREAD_ATTRIBUTE_HANDLE_LIST.

Refs #2783 <https://github.com/Genymobile/scrcpy/pull/2783>
Refs f801d8b312
Fixes #2838 <https://github.com/Genymobile/scrcpy/issues/2838>
PR #2840 <https://github.com/Genymobile/scrcpy/pull/2840>
3 years ago
Romain Vimont 86c91e183d Log CreateProcessW() error code on Windows
Refs #2838 <https://github.com/Genymobile/scrcpy/issues/2838>
3 years ago
Romain Vimont e2b3968c66 Always synchronize clipboard on explicit COPY/CUT
If --no-clipboard-autosync is enabled, the automatic clipboard
synchronization performed whenever the device clipboard changes is
disabled.

But on explicit COPY and CUT scrcpy shortcuts (MOD+c and MOD+x), the
clipboard should still be synchronized, so that it remains possible to
copy-paste from the device to the computer.

This is consistent with the behavior of MOD+v, which pastes the computer
clipboard to the device.

Refs #2228 <https://github.com/Genymobile/scrcpy/issues/2228>
Refs #2817 <https://github.com/Genymobile/scrcpy/pull/2817>
PR #2834 <https://github.com/Genymobile/scrcpy/pull/2834>
3 years ago
Romain Vimont cbe73b0bc3 Fix set_clipboard message log
If paste is disabled on set_clipboard, then the PASTE key is not
injected, but COPY is unrelated.

PR #2834 <https://github.com/Genymobile/scrcpy/pull/2834>
3 years ago
Romain Vimont bd56d81f72 Add --raw-key-events
This option allows to inject all input keys as key events, and ignore
text events.

Fixes #2816 <https://github.com/Genymobile/scrcpy/issues/2816>
PR #2831 <https://github.com/Genymobile/scrcpy/pull/2831>
3 years ago
Romain Vimont 5e918ac0c3 Use enum for key injection mode
There was only two key injection modes:
 - the default one
 - the mode with --prefer-text enabled

To prepare the addition of another mode (--raw-key-events), use an enum
instead of a bool.

PR #2831 <https://github.com/Genymobile/scrcpy/pull/2831>
3 years ago
Romain Vimont 0c0f62e4ab Use static maps to convert input events
This improves readability (hopefully).

PR #2831 <https://github.com/Genymobile/scrcpy/pull/2831>
3 years ago
Romain Vimont c96505200a Fix code style in keyboard_inject 3 years ago
Romain Vimont 82a053015d Improve HID keyboard documentation
Explain how to configure the keyboard layout.
3 years ago
Romain Vimont 19858e6aeb Add --tcpip feature
Expose an option to automatically configure and reconnect the device
over TCP/IP, to simplify wireless connection without using adb
explicitly.

There are two variants:
 - If a destination address is provided, then scrcpy connects to this
   address before starting. The device must listen on the given TCP port
   (default is 5555).
 - If no destination address is provided, then scrcpy attempts to find
   the IP address of the current device (typically connected over USB),
   enables TCP/IP mode, then connects to this address before starting.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
3 years ago
Romain Vimont 3b310f8317 Extract interruptible sleep for server
This improves readability, and makes the function reusable.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
3 years ago
Romain Vimont 800ba33ff4 Add function to read an adb property
This will allow to read the property "service.adb.tcp.port" to know if
the TCP/IP mode is enabled on the device, and which listening port is
used.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
3 years ago
Romain Vimont 8543d842ea Add function to switch device to TCP/IP mode
Expose a function to execute "adb tcpip <port>".

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
3 years ago
Romain Vimont f609b406c9 Add function to find the device IP address
Parse the result of "adb shell ip route" to find the device IP address.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
3 years ago
Romain Vimont b7e631791c Add util function to remove trailing '\r'
Depending on the platform and adb versions, the lines output by adb
could end with "\r\r\n". This util function helps to remove all trailing
'\r'.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
3 years ago
Romain Vimont b52f87a892 Add util function to locate a column in a string
This will help to parse the result of "adb shell ip route" to find the
device IP address.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
3 years ago
Romain Vimont 3bf6fd2894 Workaround "adb connect" error detection
"adb connect" always returns successfully (with exit code 0), even in
case of failure.

As a workaround, capture its output and check if it starts with
"connected".

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
3 years ago
Romain Vimont bfce22414f Add adb connect and disconnect
PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
3 years ago
Romain Vimont e6e6f865a0 Add adb flag to disable execution error logs
In addition to disable stdout and stderr of the child process, add a
flag to disable the error log printed by scrcpy if the command failed.

This will we useful for commands which are expected to fail in some
cases (like "adb disconnect" if the device is not connected).

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
3 years ago
Romain Vimont e3d4aa8c5d Use flags for adb commands
Explicitly indicate, for each adb call, if stdout and stderr must be
inherited.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
3 years ago
Romain Vimont f801d8b312 Expose flags for process execution
Let the caller decide if stdout and stderr must be inherited on process
creation, i.e. if stdout and stderr of the child process should be
printed in the scrcpy console.

This allows to get output and errors for specific adb commands depending
on the context.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
3 years ago
Romain Vimont b9b8b6aab8 Simplify Windows process inheritance configuration
Merge if-blocks together.
3 years ago
Romain Vimont 3e54773c48 Remove intermediate static functions from adb.c
They can easily be inlined into the public functions.
3 years ago
Romain Vimont b90c89766b Set CLOEXEC flag on sockets
If SOCK_CLOEXEC exists, then set the flag on socket creation.

Otherwise, use fcntl() (or SetHandleInformation() on Windows) to set the
flag afterwards.

This avoids the sockets to be inherited in child processes.

Refs #2783 <https://github.com/Genymobile/scrcpy/pull/2783>
3 years ago
Romain Vimont 904f0ae61e Check process success locally for adb commands
Remove sc_process_check_success() from the process API, it is too
specific.
3 years ago
Romain Vimont 680d2cc940 Extract command argv building
This simplifies adb_execute_p().
3 years ago
Romain Vimont 8ed3328055 Use unsigned for connection attempts count
There is no reason to use an explicit uint32_t.
3 years ago
Romain Vimont d31725f077 Reorder cli sanity checks
Check unexpected additional arguments before other sanity checks.
3 years ago
Romain Vimont b0eb1a55d6 Fix adb get-serialno error handling
If pipe read fails, return.
3 years ago
Romain Vimont 3653fb6b15 Add OutOfMemory log helper
Add a special LOG_OOM() function to log all OutOfMemory errors (i.e.
allocations returning NULL).
3 years ago
Romain Vimont 92a458e846 Remove unreachable return statements 3 years ago
Romain Vimont 73e0311d14 Add missing return on file_handler failure
Mistake introduced by 84334cf7db.
3 years ago
Romain Vimont 007f616302 Add missing includes
Include these headers explicitly instead of relying on transitivity.
3 years ago
Romain Vimont 7b29f5fd2d Do not pass default values to the server
By default, only pass the version and the bit rate (the default bitrate
is a client compilation option).
3 years ago
Romain Vimont 04e5537f8c Pass server parameters as key=value pairs
The options values to configure the server were identified by their
command-line argument index. Now that there are a lot of arguments, many
of them being booleans, it became unreadable and error-prone.

Identify the arguments by a key string instead, and make them optional.

This will also simplify running the server manually for debugging.
3 years ago
Romain Vimont 2eb881c5f1 Allocate and format server command args
This simplifies formatting.
3 years ago
Romain Vimont 5434ea543c Remove local "serial" variable
In execute_server(), the serial is used only once. Moreover, it can be
retrieved from the `params` argument directly.
3 years ago
Romain Vimont d5f6697f3a Add (v)asprintf compatibility functions
In case they are not available on the platform.
3 years ago
Romain Vimont d6c0054545 Move check_functions in meson script
Move the variable to the place it is actually used.
3 years ago
Romain Vimont 6f487a2892 Add missing includes in compat implementation
These includes are necessary for the strdup() compat implementation.
3 years ago
Romain Vimont dc0ac01e00 Define common feature test macros for all systems
_POSIX_C_SOURCE, _XOPEN_SOURCE and _GNU_SOURCE are also used on Windows.

Fix regression introduced by ba547e3895.
3 years ago
Romain Vimont 6abff46c9f Add option to disable clipboard autosync
By default, scrcpy automatically synchronizes the computer clipboard to
the device clipboard before injecting Ctrl+v, and the device clipboard
to the computer clipboard whenever it changes.

This new option --no-clipboard-autosync disables this automatic
synchronization.

Fixes #2228 <https://github.com/Genymobile/scrcpy/issues/2228>
PR #2817 <https://github.com/Genymobile/scrcpy/pull/2817>
3 years ago
Romain Vimont 5d17bcf1bc Wait SET_CLIPBOARD ack before Ctrl+v via HID
To allow seamless copy-paste, on Ctrl+v, a SET_CLIPBOARD request is
performed before injecting Ctrl+v.

But when HID keyboard is enabled, the Ctrl+v injection is not sent on
the same channel as the clipboard request, so they are not serialized,
and may occur in any order. If Ctrl+v happens to be injected before the
new clipboard content is set, then the old content is pasted instead,
which is incorrect.

To minimize the probability of occurrence of the wrong order, a delay of
2 milliseconds was added before injecting Ctrl+v. Then 5ms. But even
with 5ms, the wrong behavior sometimes happens.

To handle it properly, add an acknowledgement mechanism, so that Ctrl+v
is injected over AOA only after the SET_CLIPBOARD request has been
performed and acknowledged by the server.

Refs e4163321f0
Refs 45b0f8123a

PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
3 years ago
Romain Vimont 2d5525eac1 Move PRIu64 Windows workaround to compat.h
So that we can use it from several files.

PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
3 years ago
Romain Vimont 2a0730ee9b Add device clipboard set acknowledgement
Add a device message type so that the device could send acknowledgements
for SET_CLIPBOARD requests.

PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
3 years ago
Romain Vimont 901d837165 Add sequence number to set_clipboard request
This will allow the client to request an acknowledgement.

PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
3 years ago
Romain Vimont aba1fc03c3 Add acksync helper to wait for acks
This will allow to send requests with sequence numbers to the server
and wait for acknowledgements.

PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
3 years ago
Romain Vimont 5b3856c3b6 Explicitly indicate when device clipboard is set
Pass the information that device clipboard has been set to the key
processor. This avoids the keyprocessor to "guess", and paves the way to
implement a proper acknowledgement mechanism.

PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
3 years ago
Romain Vimont 854de9659a Do not inject Ctrl+v if clipboard sync failed
This prevents to paste the current Android clipboard, which would be
unexpected.

PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
3 years ago
Romain Vimont ea8028332c Synchronize computer-to-device empty clipboard
Set the device clipboard to empty string if necessary. Otherwise, the
current device clipboard will be pasted on Ctrl+v.

PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
3 years ago
Romain Vimont 0427a981e5 Use UINT64_C macro for uint64_t constant in tests
A long constant might not be sufficient.
3 years ago
Romain Vimont 68eaee5bb0 Force adb forward if tunnel host/port is provided
Tunnel host and port are only meaningful in "adb forward" mode.

They indicate where the client must connect to communicate with the
server. In "adb reverse" mode, the client _listens_, it does not
_connect_.

Refs #2807 <https://github.com/Genymobile/scrcpy/pull/2807>
3 years ago
RipleyTom 7bdbde7363 Add options to configure tunnel host and port
In "adb forward" mode, by default, scrcpy connects to localhost:PORT,
where PORT is the local port passed to "adb forward". This assumes that
the tunnel is established on the local host with a local adb server
(which is the common case).

For advanced usage, add --tunnel-host and --tunnel-port to force the
connection to a different destination.

Fixes #2801 <https://github.com/Genymobile/scrcpy/issues/2801>
PR #2807 <https://github.com/Genymobile/scrcpy/pull/2807>

Signed-off-by: Romain Vimont <rom@rom1v.com>
3 years ago
RipleyTom 52e5181c84 Add function to parse IPv4 addresses
PR #2807 <https://github.com/Genymobile/scrcpy/pull/2807>

Signed-off-by: Romain Vimont <rom@rom1v.com>
3 years ago
Romain Vimont ba547e3895 Configure feature test macros in meson
Refs #2807 <https://github.com/Genymobile/scrcpy/pull/2807>

Co-authored-by: RipleyTom <RipleyTom@users.noreply.github.com>
3 years ago
Romain Vimont 226f3b2c91 Add missing include config.h 3 years ago
Romain Vimont 6da6d905c2 Print scrcpy header first
Inconditionnally print the scrcpy version first, without using LOGI().

The log level is configured only after parsing the command line
parameters (it may be changed via -V), and command line parsing logs
should not appear before the scrcpy version.
3 years ago
Romain Vimont b25404ee4b Print help to stdout
The output of -h/--help was printed on stderr, although it is not an
error.

Printing on stdout allows to pipe the result directly:

    scrcpy --help | less

Instead of (in bash):

    scrcpy --help |& less
3 years ago
Romain Vimont 4cfc1cd70a Assert that long options are correctly set 3 years ago
Romain Vimont 2fc80eae2d Simplify adb_tunnel
With the new adb functions, the static adb_tunnel functions become
unnecessary.
3 years ago
Romain Vimont 3fdbd994e0 Privatize low-level adb functions
Only expose the interruptible user-friendly API.
3 years ago
Romain Vimont ce225f019a Use new user-friendly adb API
Replace the adb_exec_*() calls by the new adb functions to simplify.
3 years ago
Romain Vimont b7559744a7 Expose new user-friendly adb functions
Expose interruptible adb functions which return the expected result
directly, without exposing the process (sc_pid) to the caller.
3 years ago
Romain Vimont afb5a5e80f Rename adb functions to adb_exec_*
This paves the way to replace them by more user-friendly functions that
will call them internally.
3 years ago
Romain Vimont 84334cf7db Use sc_intr in file_handler
Replace manual interruption handling by the recent sc_intr mechanism.
3 years ago
Romain Vimont 0ba2686e1d Simplify file_handler
Call the target functions directly.
3 years ago
Romain Vimont 55648d4d64 Improve file_handler readability
Use local variables as short name aliases.
3 years ago
Romain Vimont 13fd693b50 Simplify adb_execute_p()
Only pass the stdout pipe as parameter, scrcpy never writes to stdin or
reads from stderr of an adb process.
3 years ago
Romain Vimont 0426ae885c Make "adb get-serialno" interruptible
All process executions must be interruptible, so that Ctrl+c reacts
immediately.
3 years ago
Romain Vimont ea454e9cee Add interruptible function to read from pipe
This will avoid to block Ctrl+c if the process the pipe is read from
takes too much time.
3 years ago
Romain Vimont cb65531533 Simplify sc_str_truncate()
Use strcspn() to get the prefix length directly.
3 years ago
Romain Vimont 9619ade706 Generalize string trunctation util function
Add an additional argument to let the client pass the possible end
chars.
3 years ago
Romain Vimont f2781a8b6d Expose util function to truncate first line
Move the local implementation from adb functions to the string util
functions.
3 years ago
Romain Vimont 443cb14d6e Assume non-NULL serial in file_handler
The previous commit guarantees to always initialize the serial, so the
file_handle may assume it is never NULL.
3 years ago
Romain Vimont b30c3a429f Always retrieve device serial
This allows to execute all adb commands with the specific -s parameter,
even if it is not provided by the user.

In practice, calling adb without -s works if there is exactly one device
connected. But some adb commands (for example "adb push" on drag & drop)
could be executed after another device is connected, so the actual
device serial must be known.
3 years ago
Romain Vimont 632bd5697b Add missing error handling
If "adb get-serialno" fails, attempting to read from the uninitialized
pipe is incorrect.
3 years ago
Romain Vimont de50846905 Close process on check success
The interruptible version of the function to check process success
(sc_process_check_success_intr()) did not accept a close parameter to
avoid a race condition. But as the result, the processes were not closed
at all.

Add a close parameter, and close the process separately to avoid the
race condition.
3 years ago
Romain Vimont 9cb14b5166 Inherit only specific handles on Windows
To be able to communicate with a child process via stdin, stdout and
stderr, the CreateProcess() parameter bInheritHandles must be set to
TRUE. But this causes *all* handles to be inherited, including sockets.

As a result, the server socket was inherited by the process running adb
to execute the server on the device, so it could not be closed properly,
causing other scrcpy instances to fail.

To fix the issue, use an extended API to explicitly set the HANDLEs to
inherit:
 - <https://stackoverflow.com/a/28185363/1987178>
 - <https://devblogs.microsoft.com/oldnewthing/20111216-00/?p=8873>

Fixes #2779 <https://github.com/Genymobile/scrcpy/issues/2779>
PR #2783 <https://github.com/Genymobile/scrcpy/pull/2783>
3 years ago
Romain Vimont 9cb8766220 Factorize resource release after CreateProcess()
Free the wide characters string in all cases before checking for errors.
3 years ago
Romain Vimont fd4ec784e0 Remove useless assignments on error
Leave the output parameter untouched on error.
3 years ago
Romain Vimont 52cebe1597 Fix Windows sc_pipe function names
The implementation name was incorrect (it was harmless, because they are
not used on Windows).
3 years ago
Romain Vimont 6a27062f48 Stop connection attempts if interrupted
If the interruptor is interrupted, every network call will fail, but the
retry-on-error mechanism must also be stopped.
3 years ago
Romain Vimont 739ff9dce0 Fix compilation errors with old SDL versions
SDL_PixelFormatEnum has been introduced in SDL 2.0.10:
<cc6a8ac87e>

SDL_PIXELFORMAT_BGR444 has been introduced in SDL 2.0.12:
<a1c11854f2>

Fixes #2777 <https://github.com/Genymobile/scrcpy/issues/2777>
PR #2781 <https://github.com/Genymobile/scrcpy/pull/2781>

Reviewed-by: Yu-Chen Lin <npes87184@gmail.com>
3 years ago
Romain Vimont 45b0f8123a Increase delay to inject HID on Ctrl+v
2 milliseconds turn out to be insufficient sometimes. It seems that 5
milliseconds is enough (and still not noticeable).
3 years ago
Romain Vimont c1a34881d7 Use sc_ prefix for server 3 years ago
Romain Vimont 057c7a4df4 Move str_util to str
Simplify naming.
3 years ago
Romain Vimont 979ce64dc0 Improve string util API
Use prefixed names and improve documentation.
3 years ago
Romain Vimont 9a0bd545d5 Rename SC_INVALID_SOCKET to SC_SOCKET_NONE
For consistency with SC_PROCESS_NONE.
3 years ago
Romain Vimont c4d008b96a Extract adb tunnel to a separate component
This simplifies the server code.
3 years ago
Romain Vimont 0d45c29d13 Move IPV4_LOCALHOST to net.h
This constant will be used from several files.
3 years ago
Romain Vimont 37c840a4c8 Interrupt on process terminated
Interrupt any blocking call on process terminated, like on
server_stop().

This allows to interrupt any blocking accept() with correct
synchronization without additional complexity.
3 years ago
Romain Vimont f488cbd7e7 Make server interruptible
Use an interruptor to immediately wake up blocking calls on
server_stop().
3 years ago
Romain Vimont 40340509d9 Add interruptor utilities
Expose wrapper functions for interrupting blocking calls, for process
and sockets.
3 years ago
Romain Vimont e0896142db Introduce interruptor tool
An interruptor instance will help to wake up a blocking call from
another thread (typically to terminate immediately on Ctrl+C).
3 years ago
Romain Vimont 0426708544 Run the server from a dedicated thread
Define server callbacks, start the server asynchronously and listen to
connection events to initialize scrcpy properly.

It will help to simplify the server code, and allows to run the UI event
loop while the server is connecting. In particular, this will allow to
receive SIGINT/Ctrl+C events during connection to interrupt immediately.
3 years ago
Romain Vimont 5b9c88693e Wait using a condition variable in server
Currently, server_stop() is called from the same thread as
server_connect_to(), so interruption may never happen.

This is a step to prepare executing the server from a dedicated thread.
3 years ago
Romain Vimont a54dc8212f Reorder server functions
This will avoid forward declarations in future commits.
3 years ago
Romain Vimont 882e4cff5f Copy server params
This is a preliminary step necessary to move the server to a separate
thread.
3 years ago
Romain Vimont 9fa4d1cd4a Reorder server and server_params
This will allow to define a server_params field in server.
3 years ago
Romain Vimont 0bfa75a48b Split socket creation and connect/listen
This will allow to assign the socket to a variable before connecting or
listening, so that it can be interrupted from another thread.
3 years ago
Romain Vimont ed19901db1 Set video and control sockets only on success
Store the video and control sockets only if server_connect_to() returns
successfully.
3 years ago
Romain Vimont e69356c550 Initialize tunnel_enabled flag internally
Set the flag from the inner methods, to avoid bypassing the assignment
by mistake (on error for example).
3 years ago
Romain Vimont 03de9224fc Introduce process observer
Add a tool to easily observe process termination.

This allows to move this complexity out of the server code.
3 years ago
Romain Vimont aa011832c1 Improve process API
Prefix symbols and constants names and improve documentation.
3 years ago
Romain Vimont 7e93abcf6d Factorize common impl of process_execute()
Both implementations are the same. Move them to the common process.c.
3 years ago
Romain Vimont e80e6631e4 Remove duplicate function declaration
The function process_terminate() was declared twice.
3 years ago
Romain Vimont fcc04f967b Improve file API
Prefix symbols and constants names and improve documentation.
3 years ago
Romain Vimont d4c262301f Move functions from process to file
Move filesystem-related functions from process.[ch] to file.[ch].
3 years ago
Romain Vimont be55e250ca Make screen_render() static
It is only used from screen.c.
3 years ago
Romain Vimont 7a733328bc Adapt help to terminal size
If the error stream is a terminal, and we can retrieve the terminal
size, wrap the help content according to the terminal width.
3 years ago
Romain Vimont 38332f683c Add util function to get terminal size 3 years ago
Romain Vimont 3f51a2ab43 Generate getopt params from option structures
Use the option descriptions to generate the optstring and longopts
parameters for the getopt_long() command.

That way, the options are completely described in a single place.
3 years ago
Romain Vimont 74ab0a4df8 Structure shortcuts help 3 years ago
Romain Vimont f59e9e3cb0 Structure command line options help
It will allow to correctly print the help for the current terminal size
(even if for now it is hardcoded to 80 columns).
3 years ago
Romain Vimont 9ec3406568 Add line wrapper
Add a tool to wrap lines at words boundaries (spaces) to fit in a
specified number of columns, left-indented by a specified number of
spaces.
3 years ago
Romain Vimont 6dba1922c1 Add string buffer util
This will help to build strings incrementally.
3 years ago
Romain Vimont 570a003c39 Remove deprecated -T option
The short option -T is deprecated since v1.11. Only the long version
(--always-on-top) remains.
3 years ago
Romain Vimont b62df7ee91 Remove deprecated -c option
The short option -c is deprecated since v1.11. Only the long version
(--crop) remains.
3 years ago
Romain Vimont 30d40f4e78 Document --power-off-on-close
The option was not documented.

Refs #824 <https://github.com/Genymobile/scrcpy/pull/824>
3 years ago
Romain Vimont f489f7fcad Mention drag & drop for non-APK files in help 3 years ago
Romain Vimont f65c3fde69 Fix typos in help 3 years ago
Romain Vimont 48fcfa96ab Add missing include "common.h" 3 years ago
Romain Vimont 676fa73d2c Wrap device name and size in a struct
As a benefit, this avoids to take care of the device name length on the
caller side.
3 years ago
Romain Vimont 58ea238fb2 Remove unnecessary variable
Test directly if a record filename is provided, without an intermediate
boolean variable.
3 years ago
Romain Vimont 13c4aa1a3b Disable synthetic mouse events from touch events
Touch events with id SDL_TOUCH_MOUSEID are ignored anyway, but it is
better not to generate them in the first place.
3 years ago
Romain Vimont caf594c90e Split SDL initialization
Initialize SDL_INIT_EVENTS first (very quick) and SDL_INIT_VIDEO after
the server (quite long).
3 years ago
Romain Vimont 688477ff65 Move SDL initialization
Inline SDL initialization in scrcpy(). This will allow to split
minimal initialization and video initialization.
3 years ago
Romain Vimont ac539e1312 Set SDL hints before initialization
In theory, some SDL hints should be initialized before calling
SDL_Init().
3 years ago
Romain Vimont a57c7d3a2b Extract SDL hints
Set all SDL hints in a separate function.
3 years ago
Romain Vimont d2d18466d4 Factorize SDL event push
Add a macro and inline function to call SDL_PushEvent() and log on error
(without actually handling the error, because there is nothing we could
do).
3 years ago
Romain Vimont dae091e3ab Handle SDL_PushEvent() errors
Pushing an event to the main thread may fail. If this happens, log an
error, and try to recover when possible.
3 years ago
Romain Vimont 4c4381de4c Use sc_ prefix for size, position and point 3 years ago
Romain Vimont 06131ef634 Fix typo in clock comments 3 years ago
Romain Vimont 34eb10ea0b Define v4l2 option field only if HAVE_V4L2 3 years ago
Romain Vimont 27fa23846d Define default options as const struct
This is more readable than a macro, and we could ifdef some fields.
3 years ago
Romain Vimont e4d5c1ce36 Move scrcpy option structs to options.h
This will allow to define symbols in options.c without all the
dependencies of scrcpy.c.
3 years ago
Romain Vimont ac23bec144 Expose socket interruption
On Linux, socket functions are unblocked by shutdown(), but on Windows
they are unblocked by closesocket().

Expose net_interrupt() and net_close() to abstract these differences:
 - net_interrupt() calls shutdown() on Linux and closesocket() on
   Windows (if not already called);
 - net_close() calls close() on Linux and closesocket() on Windows (if
   not already called).

This simplifies the server code, and prevents a data race on close
(reported by TSAN) on Linux (but does not fix it on Windows):

    WARNING: ThreadSanitizer: data race (pid=836124)
      Write of size 8 at 0x7ba0000000d0 by main thread:
        #0 close ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:1690 (libtsan.so.0+0x359d8)
        #1 net_close ../app/src/util/net.c:211 (scrcpy+0x1c76b)
        #2 close_socket ../app/src/server.c:330 (scrcpy+0x19442)
        #3 server_stop ../app/src/server.c:522 (scrcpy+0x19e33)
        #4 scrcpy ../app/src/scrcpy.c:532 (scrcpy+0x156fc)
        #5 main ../app/src/main.c:92 (scrcpy+0x622a)

      Previous read of size 8 at 0x7ba0000000d0 by thread T6:
        #0 recv ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:6603 (libtsan.so.0+0x4f4a6)
        #1 net_recv ../app/src/util/net.c:167 (scrcpy+0x1c5a7)
        #2 run_receiver ../app/src/receiver.c:76 (scrcpy+0x12819)
        #3 <null> <null> (libSDL2-2.0.so.0+0x84f40)
3 years ago
Romain Vimont e5ea13770b Add socket wrapper
This paves the way to store an additional "closed" flag on Windows
to interrupt and close properly.
3 years ago
Romain Vimont 3eac212af1 Use net_send() from net_send_all()
This will make net_send_all() continue to work even if net_send()
behavior is changed.
3 years ago
Romain Vimont 3adff37c2d Use sc_ prefix for sockets
Rename:
 - socket_t to sc_socket
 - INVALID_SOCKET to SC_INVALID_SOCKET
3 years ago
Romain Vimont eb6afe7669 Move net_init() and net_cleanup() upwards
These two functions are global, define them at the top of the
implementation file. This is consistent with the header file.
3 years ago
Romain Vimont e4163321f0 Delay HID events on Ctrl+v
When Ctrl+v is pressed, a control is sent to the device to set the
device clipboard before injecting Ctrl+v.

With the InputManager method, it is guaranteed that the device
synchronization is executed before handling Ctrl+v, since the commands
are executed on the device in sequence.

However, HID are injected from the computer, so there is no such
guarantee. As a consequence, on Android, Ctrl+v triggers a paste with
the old clipboard content.

To workaround the issue, wait a bit (2 milliseconds) from the AOA
thread before injecting the event, to leave enough time for the
clipboard to be set before injecting Ctrl+v.
3 years ago
Romain Vimont c96874b257 Synchronize HID keyboard state on first event
When an AOA HID keyboard is registered, CAPSLOCK and NUMLOCK are both
disabled, regardless of the state of the computer keyboard.

To synchronize the state, on first key event, inject CAPSLOCK and/or
NUMLOCK if necessary.
3 years ago
Romain Vimont 511356710d Retrieve device serial for AOA
The serial is necessary to find the correct Android device for AOA.

If it is not explicitly provided by the user via -s, then execute "adb
getserialno" to retrieve it.
3 years ago
Romain Vimont d55015e4cf Expose function to get the device serial
Expose adb_get_serialno() to retrieve the device serial via the command
"adb getserialno".
3 years ago
Romain Vimont 0681480809 Add read_pipe_all()
Add a convenience function to read from a pipe until all requested data
has been read.
3 years ago
Romain Vimont 96b18dabaa Expose adb execution with redirection
Expose the redirection feature to the adb API.
3 years ago
Romain Vimont eaf4afaad9 Add command execution with redirection
Expose command execution with pipes to stdin, stdout and stderr.

This will allow to read the result of adb commands.
3 years ago
Alynx Zhou 207082977a Add support for USB HID keyboard over AOAv2
This provides a better input experience, by simulating a physical
keyboard. It converts SDL keyboard events to proper HID events, and send
them over AOAv2.

This is a rewriting and bugfix of the origin code from @amosbird:
<https://github.com/Genymobile/scrcpy/issues/279#issuecomment-453819354>

The feature is enabled the command line option -K or --hid-keyboard,
and is only available on Linux, over USB.

Refs <https://source.android.com/devices/accessories/aoa2#hid-support>
Refs <https://www.usb.org/sites/default/files/hid1_11.pdf>

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

Signed-off-by: Romain Vimont <rom@rom1v.com>
3 years ago
Romain Vimont f7d1efdf1d Extract mouse processor trait
Mainly for consistency with the keyboard processor trait.

This could allow to provide alternative mouse processors.
3 years ago
Romain Vimont bcf5a9750f Extract keyboard processor trait
This will allow to provide alternative key processors.
3 years ago
Romain Vimont 056d36ce4a Fix trait header guards 3 years ago
Romain Vimont 1e340caf76 Remove legacy scrcpy icon
Remove the old icon in XPM format and the code to load it.
3 years ago
Romain Vimont 6004f0b6b0 Use a new scrcpy icon
Use the new icon designed by @varlesh:
<https://github.com/Genymobile/scrcpy/pull/1987#issuecomment-949684080>

Load it from a PNG file (SDL only supports bitmap icons).
3 years ago
Romain Vimont 12ed2f2402 Add support for palette icon formats
To support more icon formats.
3 years ago
Romain Vimont 0e4564da03 Add icon loader
Add helper to load icons from image files via FFmpeg.
3 years ago
Romain Vimont 156d958e77 Move common instruction out of ifdef
Both ifdef-branches return server_path.
3 years ago
Romain Vimont 7229e3cce0 Extract util function to build a local file path
Finding a local file in the scrcpy directory may be useful for files
other than scrcpy-server in the future.
3 years ago
Romain Vimont a7e41b0f85 Fix code style 3 years ago
zhongkaizhu 46d3e35c30 Fix "Could not find v4l2 muxer"
The AVOutputFormat name is a comma-separated list. In theory, possible
names for V4L2 are:

    - "video4linux2,v4l2"
    - "v4l2,video4linux2"
    - "v4l2"
    - "video4linux2"

To find the muxer in all cases, we must request exactly one muxer name
at a time.

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

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
3 years ago
Romain Vimont 07d75eb336 Simplify net_send_all()
There is no need to declare the variable before the loop.
3 years ago
Romain Vimont 31131039bb Add missing includes
Refs #2616 <https://github.com/Genymobile/scrcpy/issues/2616>
3 years ago
Romain Vimont 1d1c9f36f4 Retrieve correct error messages on Windows
For sockets functions, Windows does not store error codes in errno, so
perror() does not print any error. Use WSAGetLastError() instead.

Refs #2624 <https://github.com/Genymobile/scrcpy/issues/2624>
3 years ago
Romain Vimont 4d6dd9d281 Compute scrcpy directory manually
The function dirname() does not work correctly everywhere with non-ASCII
characters.

Fixes #2619 <https://github.com/Genymobile/scrcpy/issues/2619>
3 years ago
a1346054 b5e98db635 Fix typo in manpage
PR #2606 <https://github.com/Genymobile/scrcpy/pull/2606>

Signed-off-by: Romain Vimont <rom@rom1v.com>
3 years ago
Romain Vimont 3761f56c28 Declare callbacks static
It was a typo, "static" was missing.
3 years ago
Romain Vimont f78608ab29 Fix type for assignment
The functions net_send_all() and net_recv_all() return ssize_t, not int.
3 years ago
Romain Vimont 6f03022646 Fix net_send_all()
On partial writes, the final result was the number of bytes written by
the last send() rather than the total.
3 years ago
Romain Vimont daf90d33d5 Fix code style
Make the code fit into 80 columns.
3 years ago
Romain Vimont 0ae10f2b39 Improve slope estimation on start
The first frames are typically received and decoded with more delay than
the others, causing a wrong slope estimation on start.

To compensate, assume an initial slope of 1, then progressively use the
estimated slope.
3 years ago
Romain Vimont 4c4d02295c Add buffering debugging tools
Output buffering and clock logs by disabling a compilation flag.
3 years ago
Romain Vimont 2f03141e9f Add clock tests
The clock rolling sum is not trivial. Test it.
3 years ago
Romain Vimont 3397720330 Add buffering command line options
Add --display-buffer and --v4l2-buffer options to configure buffering
time.
3 years ago
Romain Vimont 79278961b9 Implement buffering
To minimize latency (at the cost of jitter), scrcpy always displays a
frame as soon as it available, without waiting.

However, when recording (--record), it still writes the captured
timestamps to the output file, so that the recorded file can be played
correctly without jitter.

Some real-time use cases might benefit from adding a small latency to
compensate for jitter too. For example, few tens of seconds of latency
for live-streaming are not important, but jitter is noticeable.

Therefore, implement a buffering mechanism (disabled by default) to add
a configurable latency delay.

PR #2417 <https://github.com/Genymobile/scrcpy/issues/2417>
3 years ago
Romain Vimont 408a301201 Notify new frames via callbacks
Currently, a frame is available to the consumer as soon as it is pushed
by the producer (which can detect if the previous frame is skipped).

Notify the new frames (and frame skipped) via callbacks instead.

This paves the way to add (optional) buffering, which will introduce a
delay between the time when the frame is produced and the time it is
available to be consumed.
3 years ago
Romain Vimont 4d8bcfc68a Extract current video_buffer to frame_buffer
The current video buffer only stores one pending frame.

In order to add a new buffering feature, move this part to a separate
"frame buffer". Keep the video_buffer, which currently delegates all its
calls to the frame_buffer.
3 years ago
Romain Vimont 336248df08 Rename video_buffer to sc_video_buffer
Add a scrcpy-specific prefix.
3 years ago
Romain Vimont 28bce48d47 Relax v4l2_sink lock constraints
To fix a data race, commit 5caeab5f6d
called video_buffer_push() and video_buffer_consume() under the
v4l2_sink lock.

Instead, use the previous_skipped indication (initialized with video
buffer locked) to lock only for protecting the has_frame flag.

This enables the possibility for the video_buffer to notify new frames
via callbacks without lock inversion issues.
3 years ago
Romain Vimont 32e692d5d2 Replace delay by deadline in timedwait()
The function sc_cond_timedwait() accepted a parameter representing the
max duration to wait, because it internally uses SDL_CondWaitTimeout().

Instead, accept a deadline, to be consistent with
pthread_cond_timedwait().
3 years ago
Romain Vimont ec871dd3f5 Wrap tick API
This avoids to use the SDL timer API directly, and will allow to handle
generic ticks (possibly negative).
3 years ago
Romain Vimont 5524f378c8 Add missing error log
Log video buffer initialization failure in v4l2_sink.
3 years ago
Romain Vimont 4ed3aa3604 Move include fps_counter
The fps_counter is not used from video_buffer.
3 years ago
Romain Vimont 40cea1f677 Remove obsolete comment
Commit 2a94a2b119 removed video_buffer
callbacks, the comment is now meaningless.
3 years ago
Romain Vimont 099cba07f0 Rename queue to sc_queue
Add a scrcpy-specific prefix.
3 years ago
Romain Vimont af8a21ed7c Fix manpage formatting 3 years ago
Romain Vimont 5938e862a1 Fix --lock-video-orientation syntax in help
Commit f76fe2c0d4 fixed README and tests.

Fix command line help and manpage.
3 years ago
Romain Vimont e9096e3e34 Remove unnecessary calls to av_packet_unref()
av_packet_free() already calls av_packet_unref().
3 years ago
Romain Vimont 5caeab5f6d Fix v4l2 data race
The v4l2_sink implementation directly read the internal video_buffer
field "pending_frame_consumed", which is protected by the internal
video_buffer mutex. But this mutex was not locked, so reads were racy.

Lock using the v4l2_sink mutex in addition, and use a separate field to
avoid depending on the video_buffer internal data.
3 years ago
Romain Vimont 33fbdc86c7 Initialize fields before starting a thread
To avoid data races.

Reported by TSAN.
3 years ago
Romain Vimont f33d37976c Fix assertion race condition in debug mode
Commit 21d206f360 added mutex assertions.

However, the "locker" variable to trace the locker thread id was read
and written by several threads without any protection, so it was racy.

Reported by TSAN.
3 years ago
Romain Vimont 7dca5078e7 Initialize controller even if there is no display
The options --no-display and --no-control are independent.

The controller was not initialized when no display was requested,
because it was assumed that no control could occur without display. But
that's not true (anymore): for example, it is possible to pass
--turn-screen-off.

Fixes #2426 <https://github.com/Genymobile/scrcpy/issues/2426>
3 years ago
Wirtos_new a9d9cbf8b5 Replace VLA by dynamic allocation
And increase the command buffer size.

Refs #1358 <https://github.com/Genymobile/scrcpy/issues/1358#issuecomment-862989748>
PR #2405 <https://github.com/Genymobile/scrcpy/pull/2405>

Signed-off-by: Romain Vimont <rom@rom1v.com>
3 years ago
Wirtos_new fda32928c1 Rename cmd to argv
This is more explicit.

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

Signed-off-by: Romain Vimont <rom@rom1v.com>
3 years ago
Romain Vimont 710e80aa0d Return build_cmd() success via a boolean
For consistency with other functions in the codebase.
3 years ago
Romain Vimont 77e96d745b Suggest --record-format instead of -F on error
The short option -F has been deprecated by
ff061b4f30. On error, suggest the long
option --record-format instead.
3 years ago
Romain Vimont 1c95043478 Attempt to log message only in verbose mode
If the log level is not verbose, there is no need to attempt to log
control messages at all.
3 years ago
Romain Vimont 488991116b Expose function to get the current log level
This will allow to avoid unnecessary processing for creating logs which
will be discarded anyway.
3 years ago
Romain Vimont 5c95d18beb Move log level conversion to log API 3 years ago
Romain Vimont 1039f9b531 Workaround PRIu64 on Windows
On Windows, PRIu64 is defined to "llu", which is not supported:

    error: unknown conversion type character 'l' in format
3 years ago
Marti Raudsepp 19ca02cd8f Log control messages in verbose mode
PR #2371 <https://github.com/Genymobile/scrcpy/pull/2371>

Signed-off-by: Romain Vimont <rom@rom1v.com>
3 years ago
Marti Raudsepp 937fa704a6 Add --verbosity=verbose log level
PR #2371 <https://github.com/Genymobile/scrcpy/pull/2371>

Signed-off-by: Romain Vimont <rom@rom1v.com>
3 years ago
Romain Vimont 7db0189f23 Forward mouse motion only on main clicks
Mouse motion events were forwarded as soon as any mouse button was
pressed.

Instead, only consider left-click (and also middle-click and right-click
if --forward-all-clicks is enabled).
3 years ago
Romain Vimont 8b90e1d3f4 Remove extra ';' in #define 3 years ago
Romain Vimont df017160ed Replace strcpy() by memcpy()
It was safe to call strcpy() since the input length was checked, but
then it is more straightforward to call memcpy() directly.
3 years ago
Romain Vimont a1f2094787 Push to /sdcard/Download/ by default
Change the default push target from /sdcard/ to /sdcard/Download/.

Pushing to the root of /sdcard/ is not very convenient, many apps do not
expose its content directly.

It can still be changed by --push-target.

PR #2384 <https://github.com/Genymobile/scrcpy/pull/2384>
3 years ago
Romain Vimont 9b89b7ab72 Center the window on resize-to-fit
When removing the black borders (by double-clicking on them, or by
pressing MOD+w), the window is resized to fit the device screen, but its
top-left position was left unchanged.

Instead, move the window so that the new window area is at the center of
the old window area.

Refs #2387 <https://github.com/Genymobile/scrcpy/issues/2387>
3 years ago
Romain Vimont 7343b233e4 Render screen on window restored
It should not be necessary, since screen_render() is called just after
on SDL_WINDOWEVENT_EXPOSED, but in practice the window content might not
be correctly displayed on restored if a rotation occurred while
minimized.

Note that calling screen_render() twice in a row on
SDL_WINDOWEVENT_EXPOSED also "fixes" the issue.
3 years ago
Romain Vimont cd2894570d Allocate AVPacket for v4l2_sink
From FFmpeg/doc/APIchanges:

    2021-03-17 - f7db77bd87 - lavc 58.133.100 - codec.h
      Deprecated av_init_packet(). Once removed, sizeof(AVPacket) will
      no longer be a part of the public ABI.

Refs #2302 <https://github.com/Genymobile/scrcpy/issues/2302>
3 years ago
Romain Vimont 4af317d40d Allocate AVPacket for recorder
From FFmpeg/doc/APIchanges:

    2021-03-17 - f7db77bd87 - lavc 58.133.100 - codec.h
      Deprecated av_init_packet(). Once removed, sizeof(AVPacket) will
      no longer be a part of the public ABI.

Refs #2302 <https://github.com/Genymobile/scrcpy/issues/2302>
3 years ago
Romain Vimont 318b6a572e Allocate AVPacket for local stream packet
From FFmpeg/doc/APIchanges:

    2021-03-17 - f7db77bd87 - lavc 58.133.100 - codec.h
      Deprecated av_init_packet(). Once removed, sizeof(AVPacket) will
      no longer be a part of the public ABI.

Refs #2302 <https://github.com/Genymobile/scrcpy/issues/2302>
3 years ago
Romain Vimont e8b053ad2f Allocate AVPacket for stream->pending
From FFmpeg/doc/APIchanges:

    2021-03-17 - f7db77bd87 - lavc 58.133.100 - codec.h
      Deprecated av_init_packet(). Once removed, sizeof(AVPacket) will
      no longer be a part of the public ABI.

Remove the has_pending boolean, which can be replaced by:

    stream->pending != NULL

Refs #2302 <https://github.com/Genymobile/scrcpy/issues/2302>
3 years ago
Romain Vimont af228706f1 Fix compatibility with old FFmpeg
V4L2 sink used a "url" field format AVFormatContext which has been
introduced in lavf 58.7.100.

Fixes #2382 <https://github.com/Genymobile/scrcpy/issues/2382>

Refs <ea3672b7d6>
Refs <fa8308d3d4>
3 years ago
Romain Vimont f76fe2c0d4 Fix --lock-video-orientation syntax
The argument for option --lock-video-orientation has been made optional
by 5af9d0ee0f.

With getopt_long(), contrary to mandatory arguments, optional arguments
must be given with a '=':

    --lock-video-orientation 2   # wrong, parse error
    --lock-video-orientation=2   # correct
3 years ago
Romain Vimont 506f918fb7 Group components into struct scrcpy
This avoids to refer to many structs globally.
3 years ago
Romain Vimont 6fd7e89da1 Explicitly initialize decoder sink_count
The zero-initialization relied on the fact that the decoder instance is
static.
3 years ago
Romain Vimont 4c31911df2 Pass serial within struct server_params
This was the only option passed separately.
3 years ago
Romain Vimont 6adc97198b Provide device info directly on server connection
This avoids to retrieve them in a separate step.
3 years ago
Romain Vimont 6a2cd089a1 Initialize input manager dynamically
The input manager was partially initialized statically, but a call to
input_manager_init() was needed anyway, so initialize all the fields
from the "constructor".

This is consistent with the initialization of the other structs.
3 years ago
Romain Vimont dcee7c0f7f Factorize screen_init() error management 3 years ago
Romain Vimont e604e8a752 Move fps_counter to screen
The FPS counter specifically count frames from the screen video buffer,
so it is specific to the screen.
3 years ago
Romain Vimont f19c455110 Fix leak on error
Destroy video buffer if screen window creation failed.
3 years ago
Romain Vimont 83116fc199 Notify end-of-stream via callback
Do not send a SDL event directly, to make stream independent of SDL.
3 years ago
Romain Vimont 1e64f0f931 Use ARRAY_LEN() macro 3 years ago
Romain Vimont f062dfd30b Merge branch 'master' into dev 3 years ago
Romain Vimont 1b9dcce23c Fix double-free on error
On error, server->serial was freed twice: immediately and in
server_destroy().

Refs #2292 <https://github.com/Genymobile/scrcpy/issues/2292#issuecomment-831424820>
3 years ago
Romain Vimont ae6ec7a194 Unref decoder AVFrame immediately
The frame can be unref immediately after it is pushed to the frame
sinks.

It was not really a memory leak because the frame was unref every time
by avcodec_receive_frame() (and freed on close), but a reference was
unnecessarily kept for too long.
3 years ago
Romain Vimont 84f17fdeab Fix v4l2 AVPacket memory leak on error
Unref v4l2 AVPacket even if writing failed.
3 years ago
Romain Vimont 1cde68a1fa Fix v4l2 AVFrame memory leak
Unref frame immediately once encoded.

Fixes #2279 <https://github.com/Genymobile/scrcpy/pull/2279>
3 years ago
Romain Vimont 45e7280148 Rename --v4l2_sink to --v4l2-sink
This was a rebase issue, the previous version in #2268 was correct.

Refs #2268 <https://github.com/Genymobile/scrcpy/pull/2268>
3 years ago
Marco Martinelli d39161f753 Add support for v4l2loopback
It allows to send the video stream to /dev/videoN, so that it can be
captured (like a webcam) by any v4l2-capable tool.

PR #2232 <https://github.com/Genymobile/scrcpy/pull/2232>
PR #2233 <https://github.com/Genymobile/scrcpy/pull/2233>
PR #2268 <https://github.com/Genymobile/scrcpy/pull/2268>

Co-authored-by: Romain Vimont <rom@rom1v.com>
3 years ago
Romain Vimont 5af9d0ee0f Make --lock-video-orientation argument optional
If the option is set without argument, lock the initial device
orientation (as if the value "initial" was passed).
3 years ago
Romain Vimont fd0dc6c0cd Add --lock-video-orientation=initial
Add a new mode to the --lock-video-orientation option, to lock the
initial orientation of the device.

This avoids to pass an explicit value (0, 1, 2 or 3) and think about
which is the right one.
3 years ago
Romain Vimont 151bc16644 Use strlist_contains() to find a muxer
The AVOutputFormat name is a string list: it contains names separated by
',' (possibly only one).
3 years ago
Romain Vimont ffc00210e9 Add strlist_contains()
Add a function to know if a string list, using some separator, contains
a specific string.
3 years ago
Romain Vimont 243854a408 Fix recorder comment 3 years ago
Romain Vimont 8b90dc61b9 Handle EAGAIN on send_packet in decoder
EAGAIN was only handled on receive_frame.

In practice, it should not be necessary, since one packet always
contains one frame. But just in case.
3 years ago
Romain Vimont 2a5dfc1c17 Handle errors using gotos in recorder_open()
There are many initializations in recorder_open(). Handle RAII-like
deinitialization using gotos.
3 years ago
Romain Vimont e3fccc5a5e Initialize recorder fields on open
Only initialize ops and parameters copy from recorder_init(). It was
inconsistent to initialize some fields from _init() and some others from
_open().
3 years ago
Romain Vimont 0541f1bff2 Hide the window immediately on close
The screen may not be destroyed immediately on close to avoid undefined
behavior, because it may still receive events from the decoder.

But the visual window must still be closed immediately.
3 years ago
Romain Vimont 0272e6dc77 Assert screen closed on destroy
The destruction order is important, but tricky, because the screen is
open/close by the decoder, but destroyed by scrcpy.c on the main thread.

Add assertions to guarantee that the screen is not destroyed before
being closed.
3 years ago
Romain Vimont 2a94a2b119 Remove video_buffer callbacks
Now that screen is both the owner and the listener of the video buffer,
execute the code directly without callbacks.
3 years ago
Romain Vimont e91acdb0c4 Move video_buffer to screen
The video buffer is now an internal detail of the screen component.

Since the screen is plugged to the decoder via the frame sink trait, the
decoder does not access to the video buffer anymore.
3 years ago
Romain Vimont 6f5ad21f57 Make decoder push frames to sinks
Now that screen implements the packet sink trait, make decoder push
packets to the sinks without depending on the concrete sink types.
3 years ago
Romain Vimont 08b3086ffc Expose screen as frame sink
Make screen implement the frame sink trait.

This will allow the decoder to push frames without depending on the
concrete sink type.
3 years ago
Romain Vimont deab7da761 Add frame sink trait
This trait will allow to abstract the concrete sink types from the frame
producer (decoder.c).
3 years ago
Romain Vimont f7a1b67d66 Make stream push packets to sinks
Now that decoder and recorder implement the packet sink trait, make
stream push packets to the sinks without depending on the concrete sink
types.
3 years ago