Romain Vimont
6112095e75
Add device event receiver
...
Create a separate component to handle device events, managed by the
controller.
2019-05-30 22:46:52 +02:00
Romain Vimont
f9d2d99166
Add GET_CLIPBOARD device event
...
Add the first device event, used to forward the device clipboard to the
computer.
2019-05-30 22:36:22 +02:00
Romain Vimont
ec71a3f66a
Use two sockets for video and control
...
The socket used the device-to-computer direction to stream the video and
the computer-to-device direction to send control events.
Some features, like copy-paste from device to computer, require to send
non-video data from the device to the computer.
To make them possible, use two sockets:
- one for streaming the video from the device to the client;
- one for control/events in both directions.
2019-05-30 22:35:41 +02:00
Romain Vimont
69360c7407
Extract control event string serialization
...
A string is serialized as a length (2 bytes) followed by the string data
(non nul-terminated).
For now, it is used only once, but we will need to serialize strings in
other events.
2019-05-30 22:35:04 +02:00
Romain Vimont
6ec2ddd2d1
Truncate UTF-8 properly
...
This will avoid to produce invalid UTF-8 results (although unlikely).
2019-05-30 22:34:59 +02:00
Romain Vimont
0a7fe7ad57
Add helpers to truncate UTF-8 at code points
...
This will help to avoid truncating a UTF-8 string in the middle of a
code point, producing an invalid UTF-8 result.
2019-05-30 22:30:18 +02:00
Romain Vimont
63909fd10d
Merge commands with other control events
...
Several commands were grouped under the same event type "command", with
a separate field to indicate the actual command.
Move these commands at the same level as other control events. It will
allow to implement commands with arguments.
2019-05-30 22:30:18 +02:00
Romain Vimont
3b4366e5bf
Stop stream immediately on quit
...
If the stream is stopped, av_read_frame() will be woken up and yield a
corrupted packet. Do not try to decode or record it.
2019-05-30 22:30:18 +02:00
Romain Vimont
47f1003200
Close server socket before killing process
...
The sockets may be closed and shutdown on server_stop(). This will
interrupt the stream and controller threads more quickly and gracefully.
2019-05-30 22:30:18 +02:00
Romain Vimont
bfb86ca2c2
Simplify cleanup
...
The cleanup is not linear: for example, the server must be stopped and
its sockets must be shutdown after the stream and controller are stopped
(so that they don't continue processing garbage), but before they are
joined, to avoid a deadlock if they are blocked on a socket read.
Simplify the spaghetti-cleanup by keeping trace of initialization at
runtime.
2019-05-30 22:30:18 +02:00
Romain Vimont
0dee9b04b2
Use net_recv() to read only one byte
...
Partial read is impossible for 1 byte, so net_recv_all() is useless.
2019-05-30 22:30:18 +02:00
Romain Vimont
8fc58bde75
Simplify server_connect_to()
...
Only use 2 branches, using either forward or remote tunnel.
2019-05-30 22:30:18 +02:00
Romain Vimont
5a431cdf9b
Make server_connect_to() return a bool
...
The resulting socket is accessible from the server instance, there is no
need to return it.
This paves the way to use several sockets in parallel.
2019-05-30 22:30:18 +02:00
Romain Vimont
073181b294
Use cbuf for file handler request queue
...
Replace the file_handler_request_queue implementation by cbuf.
2019-05-30 22:30:18 +02:00
Romain Vimont
241a3dcba5
Use cbuf for control event queue
...
Replace the control_event_queue implementation by cbuf.
2019-05-30 22:30:18 +02:00
Romain Vimont
b38292cd69
Add generic circular buffer
...
Add a circular buffer implementation, to factorize multiple specific
queues implementation.
2019-05-30 22:30:18 +02:00
Romain Vimont
7475550ae8
Add buffer_read16be()
...
Add a function to read 16 bits in big-endian to a uint16_t.
2019-05-30 22:30:18 +02:00
Romain Vimont
7fc8793d5b
Make buffer util functions accept const buffers
...
So that they can be used both on const and non-const input buffers.
2019-05-30 22:30:18 +02:00
Romain Vimont
bf5e54b2e9
Make control_event_serialize() return size_t
...
control_event_serialize() returns the number of bytes written, so the
type should be size_t.
2019-05-30 22:30:18 +02:00
Romain Vimont
507b0bcccf
Fix memory leak on error
...
The variable condition was not destroyed on strdup() failure.
2019-05-30 22:30:18 +02:00
Romain Vimont
e1afd9f8b0
Fix event ownership comment
2019-05-30 22:30:18 +02:00
Romain Vimont
b08dada6c1
Prefix control event constants by namespace
...
This will avoid conflicts with future device events.
2019-05-30 22:30:18 +02:00
Romain Vimont
999c964689
Make macro expansion-safe
...
Use parentheses to avoid unexpected results.
For example, make:
2 * SERIALIZED_EVENT_MAX_SIZE
expand to:
2 * (3 + TEXT_MAX_LENGTH)
instead of:
2 * 3 + TEXT_MAX_LENGTH
2019-05-30 22:30:18 +02:00
Romain Vimont
befe455e44
Remove unused includes
...
The struct control_event does not use mutexes, and net.h does not need
SDL_platform.h.
2019-05-30 22:30:18 +02:00
Romain Vimont
d2504f974c
Fix indentation
...
Previous refactorings broke indentation.
2019-05-30 22:30:18 +02:00
Romain Vimont
3bc1c51b91
Always use SDL_malloc() and SDL_free()
...
To avoid mixing SDL_malloc()/SDL_strdup() with free(), or malloc() with
SDL_free(), always use the SDL version.
2019-05-30 22:30:08 +02:00
Romain Vimont
5d473efeb5
Bind Home key to MOVE_HOME
...
On pressing Home key on the computer, move the cursor to the beginning
of the line instead of going back to the home screen.
<https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_HOME >
<https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_MOVE_HOME >
Fixes (part of) <https://github.com/Genymobile/scrcpy/issues/555 >.
2019-05-27 10:24:47 +02:00
Romain Vimont
a41dd6c79f
Make owned filename a pointer-to-non-const
...
The file handler owns the filename string, so it needs to free it.
Therefore, it should not be a pointer-to-const.
2019-05-24 17:25:31 +02:00
Romain Vimont
c3779d8513
Make owned serial a pointer-to-non-const
...
The file handler owns the serial, so it needs to free it. Therefore, it
should not be a pointer-to-const.
2019-05-24 17:24:17 +02:00
Romain Vimont
b3bd5f1b80
Remove useless casts to (void *)
2019-05-24 17:23:21 +02:00
Romain Vimont
3133d5d1c7
Continue on icon loading failure
...
If loading the icon from xpm fails, launch scrcpy without window icon.
<https://github.com/Genymobile/scrcpy/issues/539 >
2019-05-23 20:58:08 +02:00
Romain Vimont
2dc1a59471
Check surface returned for icon
...
SDL_CreateRGBSurfaceFrom() may return NULL, causing a segfault.
<https://github.com/Genymobile/scrcpy/issues/539 >
2019-05-20 09:44:45 +02:00
Romain Vimont
e443518ed9
Print adb command on error
...
When the execution of an adb command fails, print the command. This will
help to understand what went wrong.
See <https://github.com/Genymobile/scrcpy/issues/530 >.
2019-05-12 15:16:13 +02:00
Romain Vimont
eeb8e8420f
Use size_t for command length
...
The size of an array should have type size_t.
2019-05-12 14:31:18 +02:00
Sebastian Krzyszkowiak
b941854c73
Disable X11 compositor bypass
...
Compositor bypass is meant for fullscreen games consuming lots of GPU
resources. For a light app that will usually be windowed, this only
causes unnecessary compositor suspends, especially visible (and
annoying) with complying window manager like KWin.
Signed-off-by: Romain Vimont <rom@rom1v.com>
2019-05-05 17:35:00 +02:00
Sebastian Krzyszkowiak
068253a3a2
Fix mouse focus clickthrough
...
Mouse focus clickthrough didn't work due to compat.h header not being
included in scrcpy.c.
Signed-off-by: Romain Vimont <rom@rom1v.com>
2019-05-05 17:28:25 +02:00
Gerdal
ffa8c66979
Fix link error on Windows Subsystem for Linux
...
Build failed on WSL because of lack of reference to WinMain@16 during
linking.
Fixes <https://github.com/Genymobile/scrcpy/issues/316 >
Signed-off-by: Romain Vimont <rom@rom1v.com>
2019-03-31 20:07:07 +02:00
Romain Vimont
50dac2eaee
Log "new texture" at INFO level
...
The "initial texture" is logged at INFO level. For consistency, log "new
texture" at the same level.
2019-03-07 20:18:03 +01:00
Romain Vimont
a7b3901c31
Add more consts
...
Some decoder and recorder functions must not write to AVCodec and
AVPacket.
2019-03-03 12:02:41 +01:00
Romain Vimont
f7efafd846
Explicitly pass control flag to input manager
...
Replace the "global" control flag in the input_manager by a function
parameter to make explicit that the behavior depends whether
--no-control has been set.
2019-03-03 11:05:26 +01:00
Romain Vimont
6baed8a06f
Do not init SDL video subsystem if no display
...
The SDL video subsystem is not necessary if we don't display the video.
Move the sdl_init_and_configure() function from screen.c to scrcpy.c,
because it is not only related to the screen display.
2019-03-03 01:41:35 +01:00
Romain Vimont
8595862005
Use explicit output parameter for skipped frame
...
The function video_buffer_offer_decoded_frame() returned a bool to
indicate whether the previous frame had been consumed.
This was confusing, because we could expect the returned bool report
whether the action succeeded.
Make the semantic explicit by using an output parameter.
Also revert the flag (report if the frame has been skipped instead of
consumed) to avoid confusion for the first frame (the previous is
neither skipped nor consumed because there is no previous frame).
2019-03-03 00:35:20 +01:00
Romain Vimont
9ef345fdd0
Make owned serial a pointer-to-non-const
...
The server owns the serial, so it needs to free it. Therefore, it should
not be a pointer-to-const.
2019-03-03 00:01:16 +01:00
Romain Vimont
dfed1b250e
Replace SDL types by C99 standard types
...
Scrcpy is a C11 project. Use the C99 standard types instead of the
SDL-specific types:
SDL_bool -> bool
SintXX -> intXX_t
UintXX -> uintXX_t
2019-03-02 23:55:23 +01:00
Romain Vimont
8655ba7197
Add option to mirror in read-only
...
Add an option to disable device control: -n/--no-control.
2019-03-02 23:10:21 +01:00
Romain Vimont
163cd36ccc
Rename -n/--no-window to -N/--no-display
...
The description of scrcpy is "Display and control your Android device".
We want an option to disable display, another one to disable control.
For naming consistency, name it --no-display.
Also change the shortname to -N, so that we can use -n for --no-control
later.
2019-03-02 22:46:46 +01:00
Romain Vimont
db6644f1f9
Add missing no_window initialization
...
Initialize the field no_window in "struct args"
2019-03-02 22:42:28 +01:00
Romain Vimont
36191b7eec
Avoid unnecessary call if display is disabled
...
If --no-window is passed, there is no need to register an event watcher.
2019-03-02 21:51:07 +01:00
Romain Vimont
33ccb1368f
Extract event processing out of event_loop()
...
To avoid too many levels of nested blocks, move the event handling logic
in a separate function.
2019-03-02 21:51:07 +01:00
Romain Vimont
aeda583a2c
Update code style
...
Limit source code to 80 chars, and declare functions return type and
modifiers on a separate line.
This allows to avoid very long lines, and all function names are
aligned.
(We do this on VLC, and I like it.)
2019-03-02 20:28:46 +01:00