Accept a range of ports to listen to, so that it does not fail if
another instance of scrcpy is currently starting.
The range can be passed via the command line:
scrcpy -p 27183:27186
scrcpy -p 27183 # implicitly 27183:27183, as before
The default is 27183:27199.
Closes#951 <https://github.com/Genymobile/scrcpy/issues/951>
Start the server socket in enable_tunnel() directly.
For the caller point of view, enabling the tunnel opens a port (either
the server socket locally or the "adb forward" process).
The platform-specific code for net.c was implemented in sys/*/net.c.
But the differences are quite limited, so use ifdef-blocks in the single
net.c instead.
The file 'E:\安安\scrcpy-win64-v1.12.1-1-g31bd950\scrcpy-server'
exists, however, it will show msg as follow:
INFO: scrcpy 1.12.1 <https://github.com/Genymobile/scrcpy>
stat: No such file or directory
ERROR: 'E:\安安\scrcpy-win64-v1.12.1-1-g31bd950\scrcpy-server' does
not exist or is not a regular file
Press any key to continue...
This patch fixes it.
Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
The function get_server_path() sometimes returned an owned string,
sometimes a non-owned string.
Always return an allocated (owned) string, and free it after usage.
A proper solution could be to use "long long" instead (guaranteed to be
at least 64 bits), but it adds its own problems (e.g. "%lld" is not
supported as a printf format on all platforms).
In practice, we don't need such high values, so keep it simple.
Fixes#995 <https://github.com/Genymobile/scrcpy/issues/995>
If SCRCPY_SERVER_PATH points to a directory, then a directory will be
pushed to /data/local/tmp/scrcpy-server.jar.
When executing it, app_process will just abort and leave the directory
on the device, causing scrcpy to always fail.
To avoid the problem, check that the server is a regular file before
pushing it.
Closes#956 <https://github.com/Genymobile/scrcpy/issues/956>
> Movements down (scroll backward) generate negative y values and up
> (scroll forward) generate positive y values.
> If direction is SDL_MOUSEWHEEL_FLIPPED the values in x and y will be
> opposite. Multiply by -1 to change them back.
<https://wiki.libsdl.org/SDL_MouseWheelEvent#Remarks>
The x and y values already take the scrolling configuration into
account. Reversing the values when the direction is flipped cancels the
scrolling configuration.
Therefore, just ignore the direction field.
Fixes <https://github.com/Genymobile/scrcpy/issues/966>
Commit 3da95b52bd renamed
'scrcpy-server.jar' to 'scrcpy-server' to avoid issues on the client
side.
However, removing the extension may cause issues with app_process, so
restore the extension only on the device side.
Fixes <https://github.com/Genymobile/scrcpy/issues/944>
Send client version as first parameter and check it at server start.
Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
Expose an option to configure how key/text events are forwarded to the
Android device.
Enabling the option avoids issues when combining multiple keys to enter
special characters, but breaks the expected behavior of alpha keys in
games (typically WASD).
Fixes <https://github.com/Genymobile/scrcpy/issues/650>
Mouse events coordinates depend on the screen size and location, so the
converter need to access the screen.
The fact that it needs the position or the size is an internal detail,
so pass a pointer to the whole screen structure.
Now, get_window_size() returns the current window size (fullscreen or
not), while get_windowed_window_size() always returned the windowed size
(the size when fullscreen is disabled).
Headers seem to be a bit different in Apple land and you need to include
stddef.h explicitly to the NULL declaration.
This also makes the code a bit more correct, as stddef.h is the header
in the C standard that defines NULL
(https://en.cppreference.com/w/cpp/header/cstddef).
We need several FIFO queues (a queue of packets, a queue of messages,
etc.).
Some of them are implemented using cbuf, a generic circular buffer. But
for recording, we need to store the packets in an unbounded queue until
they are written, so the queue was implemented manually.
Create a generic implementation (using macros) to avoid reimplementing
it every time.
The record file was written from the stream thread. As a consequence,
any blocking I/O to write the file delayed the decoder.
For maximum performance even when recording is enabled, send
(refcounted) packets to a separate recording thread.
To packetize the H.264 raw stream, av_parser_parse2() (called by
av_read_frame()) knows that it has received a full frame only after it
has received some data for the next frame. As a consequence, the client
always waited until the next frame before sending the current frame to
the decoder!
On the device side, we know packets boundaries. To reduce latency,
make the device always transmit the "frame meta" to packetize the stream
manually (it was already implemented to send PTS, but only enabled on
recording).
On the client side, replace av_read_frame() by manual packetizing and
parsing.
<https://stackoverflow.com/questions/50682518/replacing-av-read-frame-to-reduce-delay>
<https://trac.ffmpeg.org/ticket/3354>
If --no-control is set, then the controller is not initialized (both in
the client and the server), so it is not possible to control the device
to turn its screen off.
See <https://github.com/Genymobile/scrcpy/issues/608>.
In portable builds, scrcpy-server.jar was supposed to be present in the
current directory, so in practice it worked only if scrcpy was launched
from its own directory.
Instead, find the absolute path of the executable and build a suitable
path to use scrcpy-server.jar from the same directory.
There was already utf8_to_wide_char(), used to correctly execute
commands on Windows.
Add the reverse converter: utf8_from_wide_char(). We will need it to
build the scrcpy-server path based on the executable directory.
To create a portable build (with scrcpy-server.jar accessible from the
scrcpy directory), replace OVERRIDE_SERVER_PATH by a simple compilation
flag: PORTABLE.
This paves the way to use more complex rules to determine the path of
scrcpy-server.jar in portable builds.
On socket disconnection, on Linux, recv() returns -1 and errno is set.
But on Windows, errno is 0.
In that case, AVERROR(errno) == 0, leading to the warning:
> Invalid return value 0 for stream protocol
To avoid the problem, if errno is 0, return AVERROR_EOF.
Ref: commit 2876463d39
The FPS counter was called only on new frames, so it could not print
values regularly, especially when there are very few FPS (when the
device surface does not change).
To the extreme, it was never able to display 0 fps.
Add a separate thread to print framerate every second.
Only keep "turn device screen off" and POWER button.
After we turn the device screen off (with Ctrl+o), turning it back on
does not always work, and leaves the device in a weird state, where even
the power button may not be sufficient:
<https://github.com/Genymobile/scrcpy/issues/175#issuecomment-497946596>
This is not an acceptable behavior, so disable the shortcut to turn the
physical device screen on. We can use the POWER button (or Ctrl+p)
instead.
The condition "event->type == SDL_KEYDOWN" and the variable
input_manager->controller are used many times. Replace them by local
variables to reduce verbosity.
Add two shortcuts:
- Ctrl+o to turn the device screen off while mirroring
- Ctrl+Shift+o to turn it back on
On power on (either via the POWER key or BACK while screen is off), both
the device screen and the mirror are turned on.
<https://github.com/Genymobile/scrcpy/issues/175>
Use the same variable name in functions declaration and definition.
Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
After the recent refactorings, a "control event" is not necessarily an
"event" (it may be a "command"). Similarly, the unique "device event"
used to send the device clipboard content is more a "reponse" to the
request from the client than an "event".
Rename both to "message", and rename the message types to better
describe their intent.
It was already possible to _paste_ (with Ctrl+v) the content of the
computer clipboard on the device. Technically, it injects a sequence of
events to generate the text.
Add a new feature (Ctrl+Shift+v) to copy to the device clipboard
instead, without injecting the content. Contrary to events injection,
this preserves the UTF-8 content exactly, so the text is not broken by
special characters.
<https://github.com/Genymobile/scrcpy/issues/413>