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).
2021-11-24 21:31:12 +01:00
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.
2021-11-24 21:23:20 +01:00
Romain Vimont
2eb881c5f1
Allocate and format server command args
...
This simplifies formatting.
2021-11-24 21:10:18 +01:00
Romain Vimont
2c3099e2de
Parse codec options early
...
For consistency with other options, parse the codec options on the
server before storing them in the Options instance.
2021-11-24 21:06:02 +01:00
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.
2021-11-24 21:01:25 +01:00
Romain Vimont
d5f6697f3a
Add (v)asprintf compatibility functions
...
In case they are not available on the platform.
2021-11-24 19:55:00 +01:00
Romain Vimont
d6c0054545
Move check_functions in meson script
...
Move the variable to the place it is actually used.
2021-11-24 19:38:33 +01:00
Romain Vimont
6f487a2892
Add missing includes in compat implementation
...
These includes are necessary for the strdup() compat implementation.
2021-11-24 19:37:33 +01:00
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 .
2021-11-24 19:36:33 +01:00
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 >
2021-11-24 09:44:39 +01:00
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 >
2021-11-24 09:41:21 +01:00
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 >
2021-11-23 21:15:05 +01:00
Romain Vimont
41abe021e2
Make the device acknowledge device clipboard
...
If the client provided a sequence number on SET_CLIPBOARD request, make
the device send back an acknowledgement once the clipboard is set.
PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814 >
2021-11-23 21:15:05 +01:00
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 >
2021-11-23 21:15:05 +01:00
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 >
2021-11-23 21:15:05 +01:00
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 >
2021-11-23 21:15:05 +01:00
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 >
2021-11-23 21:15:05 +01:00
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 >
2021-11-23 21:15:05 +01:00
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 >
2021-11-23 21:14:49 +01:00
Romain Vimont
0427a981e5
Use UINT64_C macro for uint64_t constant in tests
...
A long constant might not be sufficient.
2021-11-21 22:57:33 +01:00
Romain Vimont
44721ed982
Document remote ADB server in README
...
Refs #2807 <https://github.com/Genymobile/scrcpy/pull/2807 >
2021-11-21 22:37:52 +01:00
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 >
2021-11-21 22:37:52 +01:00
Romain Vimont and RipleyTom
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 >
2021-11-21 00:20:11 +01:00
Romain Vimont
226f3b2c91
Add missing include config.h
2021-11-21 00:13:25 +01:00
Romain Vimont
2d6a96776c
Improve SSH tunnel documentation in README
2021-11-19 21:03:29 +01:00
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.
2021-11-19 09:45:02 +01:00
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
2021-11-19 08:18:13 +01:00
Romain Vimont
4cfc1cd70a
Assert that long options are correctly set
2021-11-19 08:06:23 +01:00
Romain Vimont
2fc80eae2d
Simplify adb_tunnel
...
With the new adb functions, the static adb_tunnel functions become
unnecessary.
2021-11-19 07:25:03 +01:00
Romain Vimont
3fdbd994e0
Privatize low-level adb functions
...
Only expose the interruptible user-friendly API.
2021-11-19 07:25:03 +01:00
Romain Vimont
ce225f019a
Use new user-friendly adb API
...
Replace the adb_exec_*() calls by the new adb functions to simplify.
2021-11-18 22:11:19 +01:00
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.
2021-11-18 22:08:15 +01:00
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.
2021-11-18 21:47:17 +01:00
Romain Vimont
84334cf7db
Use sc_intr in file_handler
...
Replace manual interruption handling by the recent sc_intr mechanism.
2021-11-18 21:33:25 +01:00
Romain Vimont
0ba2686e1d
Simplify file_handler
...
Call the target functions directly.
2021-11-18 19:46:47 +01:00
Romain Vimont
55648d4d64
Improve file_handler readability
...
Use local variables as short name aliases.
2021-11-18 19:46:40 +01:00
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.
2021-11-18 19:43:10 +01:00
Romain Vimont
0426ae885c
Make "adb get-serialno" interruptible
...
All process executions must be interruptible, so that Ctrl+c reacts
immediately.
2021-11-18 19:41:41 +01:00
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.
2021-11-18 19:39:11 +01:00
Romain Vimont
cb65531533
Simplify sc_str_truncate()
...
Use strcspn() to get the prefix length directly.
2021-11-18 19:37:53 +01:00
Romain Vimont
9619ade706
Generalize string trunctation util function
...
Add an additional argument to let the client pass the possible end
chars.
2021-11-18 18:48:16 +01:00
Romain Vimont
f2781a8b6d
Expose util function to truncate first line
...
Move the local implementation from adb functions to the string util
functions.
2021-11-18 18:48:16 +01:00
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.
2021-11-18 18:48:11 +01:00
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.
2021-11-18 18:32:15 +01:00
Romain Vimont
632bd5697b
Add missing error handling
...
If "adb get-serialno" fails, attempting to read from the uninitialized
pipe is incorrect.
2021-11-18 18:32:15 +01:00
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.
2021-11-18 18:31:36 +01:00
Romain Vimont
ee93d2aac1
Configure init and cleanup asynchronously
...
Accessing the settings (like --show-touches) on start should not delay
screen mirroring.
PR #2802 <https://github.com/Genymobile/scrcpy/pull/2802 >
2021-11-18 08:37:32 +01:00
Romain Vimont
c29a0bf675
Do not quit on cleanup configuration failure
...
Cleanup is used for some options like --show-touches to restore the
state on exit.
If the configuration fails, do not crash the whole process. Just log an
error.
PR #2802 <https://github.com/Genymobile/scrcpy/pull/2802 >
2021-11-18 08:37:28 +01:00
Romain Vimont
411bb0d18e
Move init and cleanup to a separate method
...
PR #2802 <https://github.com/Genymobile/scrcpy/pull/2802 >
2021-11-18 08:37:26 +01:00
Romain Vimont
cc0902b13c
Read/write settings via command on Android >= 12
...
Before Android 8, executing the "settings" command from a shell was
very slow (~1 second), because it spawned a new app_process to execute
Java code. Therefore, to access settings without performance issues,
scrcpy used private APIs to read from and write to settings.
However, since Android 12, this is not possible anymore, due to
permissions changes.
To make it work again, execute the "settings" command on Android 12 (or
on previous version if the other method failed). This method is faster
than before Android 8 (~100ms).
Fixes #2671 <https://github.com/Genymobile/scrcpy/issues/2671 >
Fixes #2788 <https://github.com/Genymobile/scrcpy/issues/2788 >
PR #2802 <https://github.com/Genymobile/scrcpy/pull/2802 >
2021-11-18 08:37:22 +01:00
Romain Vimont
48b572c272
Add throwable parameter to Log.w()
...
When an exception occurs, we might want to log a warning instead of an
error.
PR #2802 <https://github.com/Genymobile/scrcpy/pull/2802 >
2021-11-18 08:37:18 +01:00
Romain Vimont
94feae71f2
Report settings errors via Exceptions
...
Settings read/write errors were silently ignored. Report them via a
SettingsException so that the caller can handle them.
This allows to log a proper error message, and will also allow to
fallback to a different settings method in case of failure.
PR #2802 <https://github.com/Genymobile/scrcpy/pull/2802 >
2021-11-18 08:37:02 +01:00
Romain Vimont
67170437f1
Wrap settings management into a Settings class
...
Until now, the code that needed to read/write the Android settings had
to explicitly open and close a ContentProvider.
Wrap these details into a Settings class.
This paves the way to provide an alternative implementation of settings
read/write for Android >= 12.
PR #2802 <https://github.com/Genymobile/scrcpy/pull/2802 >
2021-11-18 08:36:48 +01:00
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 >
2021-11-15 10:13:30 +01:00
Romain Vimont
9cb8766220
Factorize resource release after CreateProcess()
...
Free the wide characters string in all cases before checking for errors.
2021-11-15 07:49:01 +01:00
Romain Vimont
fd4ec784e0
Remove useless assignments on error
...
Leave the output parameter untouched on error.
2021-11-14 22:53:49 +01:00
Romain Vimont
52cebe1597
Fix Windows sc_pipe function names
...
The implementation name was incorrect (it was harmless, because they are
not used on Windows).
2021-11-14 22:41:38 +01:00
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.
2021-11-14 15:40:59 +01:00
Romain Vimont
739ff9dce0
Fix compilation errors with old SDL versions
...
SDL_PixelFormatEnum has been introduced in SDL 2.0.10:
<https://github.com/libsdl-org/SDL/commit/cc6a8ac87e41d0df68075081dbf5cd2ba46f8fd4 >
SDL_PIXELFORMAT_BGR444 has been introduced in SDL 2.0.12:
<https://github.com/libsdl-org/SDL/commit/a1c11854f28b7186a744df412aa6273862459c31 >
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 >
2021-11-14 15:37:30 +01:00
Romain Vimont
65b023ac6d
Update links to v1.20
2021-11-14 01:51:32 +01:00
Romain Vimont
a045e28df8
Bump version to 1.20
2021-11-14 01:25:24 +01:00
Romain Vimont
52138fd921
Update script to build without gradle to SDK 31
...
Build tools 31.x.x do not ship dx anymore. Use d8 instead.
Refs 8bf28e9f53
2021-11-14 01:25:24 +01:00
Romain Vimont
1bb0df5da1
Extract ANDROID_JAR path in build script
...
This will allow to reuse it.
2021-11-14 01:25:24 +01:00
Romain Vimont
562ec6e9b3
Merge branch 'master' into dev
2021-11-14 01:25:00 +01:00
Romain Vimont
1be5daf999
Fix word order in README
2021-11-14 01:23:06 +01:00
Romain Vimont
57387fa707
Mention crash on Android 12 on old scrcpy in FAQ
2021-11-14 01:23:06 +01:00
Romain Vimont
4e811a4a68
Adapt icon in README
...
Use SVG format, align to the right, and reduce its size.
2021-11-14 01:23:06 +01:00
Romain Vimont
99a4a48477
Replace "connected on" to "connected via"
...
I'm not sure "connected on USB" is correct.
2021-11-14 01:23:06 +01:00
Romain Vimont
1d97d77032
Improve scrcpy presentation in README
2021-11-14 01:23:06 +01:00
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).
2021-11-14 01:23:06 +01:00
Romain Vimont
c1a34881d7
Use sc_ prefix for server
2021-11-14 01:23:05 +01:00
Romain Vimont
057c7a4df4
Move str_util to str
...
Simplify naming.
2021-11-14 01:22:22 +01:00
Romain Vimont
979ce64dc0
Improve string util API
...
Use prefixed names and improve documentation.
2021-11-14 01:22:22 +01:00
Romain Vimont
9a0bd545d5
Rename SC_INVALID_SOCKET to SC_SOCKET_NONE
...
For consistency with SC_PROCESS_NONE.
2021-11-14 01:22:22 +01:00
Romain Vimont
c4d008b96a
Extract adb tunnel to a separate component
...
This simplifies the server code.
2021-11-14 01:22:22 +01:00
Romain Vimont
0d45c29d13
Move IPV4_LOCALHOST to net.h
...
This constant will be used from several files.
2021-11-14 01:22:22 +01:00
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.
2021-11-14 01:22:22 +01:00
Romain Vimont
f488cbd7e7
Make server interruptible
...
Use an interruptor to immediately wake up blocking calls on
server_stop().
2021-11-14 01:22:20 +01:00
Romain Vimont
40340509d9
Add interruptor utilities
...
Expose wrapper functions for interrupting blocking calls, for process
and sockets.
2021-11-13 22:54:18 +01:00
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).
2021-11-13 22:53:07 +01:00
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.
2021-11-13 10:19:52 +01:00
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.
2021-11-13 10:17:51 +01:00
Romain Vimont
a54dc8212f
Reorder server functions
...
This will avoid forward declarations in future commits.
2021-11-13 10:16:35 +01:00
Romain Vimont
882e4cff5f
Copy server params
...
This is a preliminary step necessary to move the server to a separate
thread.
2021-11-13 10:05:20 +01:00
Romain Vimont
9fa4d1cd4a
Reorder server and server_params
...
This will allow to define a server_params field in server.
2021-11-13 10:05:20 +01:00
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.
2021-11-13 10:05:20 +01:00
Romain Vimont
ed19901db1
Set video and control sockets only on success
...
Store the video and control sockets only if server_connect_to() returns
successfully.
2021-11-13 10:05:01 +01:00
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).
2021-11-13 10:03:03 +01:00
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.
2021-11-13 10:02:23 +01:00
Romain Vimont
aa011832c1
Improve process API
...
Prefix symbols and constants names and improve documentation.
2021-11-12 22:44:37 +01:00
Romain Vimont
7e93abcf6d
Factorize common impl of process_execute()
...
Both implementations are the same. Move them to the common process.c.
2021-11-12 22:44:37 +01:00
Romain Vimont
e80e6631e4
Remove duplicate function declaration
...
The function process_terminate() was declared twice.
2021-11-12 22:44:37 +01:00
Romain Vimont
fcc04f967b
Improve file API
...
Prefix symbols and constants names and improve documentation.
2021-11-12 22:44:37 +01:00
Romain Vimont
d4c262301f
Move functions from process to file
...
Move filesystem-related functions from process.[ch] to file.[ch].
2021-11-12 22:44:37 +01:00
Romain Vimont
be55e250ca
Make screen_render() static
...
It is only used from screen.c.
2021-11-12 22:44:22 +01:00
Romain Vimont
c548f017bf
Upgrade junit to 4.13.1
2021-11-12 22:44:18 +01:00
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.
2021-11-11 15:22:39 +01:00
Romain Vimont
38332f683c
Add util function to get terminal size
2021-11-11 15:22:39 +01:00
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.
2021-11-11 14:59:34 +01:00
Romain Vimont
74ab0a4df8
Structure shortcuts help
2021-11-11 14:59:34 +01:00