Commit Graph

494 Commits (9e78b765da01843b4986f93179b0c92701269062)

Author SHA1 Message Date
Yu-Chen Lin fcf225049d Use consistent variable names
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>
5 years ago
Romain Vimont 6537c2ef01 Add clipboard logs
Synchronizing local and device clipboards in invisible. Add INFO logs
on success.
5 years ago
Romain Vimont 9712cb8123 Do not minimize on focus loss
The default behavior seems annoying.

Fixes <https://github.com/Genymobile/scrcpy/issues/554>
5 years ago
Romain Vimont 28980bbc90 Rename "event" to "message"
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.
5 years ago
Yu-Chen Lin 2a8a3e6ed5 Correct return value type in handle_event
handle_event return the type enum event_result not bool

Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
5 years ago
Romain Vimont c13a24389c Implement computer-to-device clipboard copy
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>
5 years ago
Romain Vimont 63c078ee6c Implement device-to-computer clipboard copy
On Ctrl+C:
 - the client sends a GET_CLIPBOARD command to the device;
 - the device retrieve its current clipboard text and sends it in a
   GET_CLIPBOARD device event;
 - the client sets this text as the system clipboard text, so that it
   can be pasted in another application.

Fixes <https://github.com/Genymobile/scrcpy/issues/145>
5 years ago
Romain Vimont 6112095e75 Add device event receiver
Create a separate component to handle device events, managed by the
controller.
5 years ago
Romain Vimont f9d2d99166 Add GET_CLIPBOARD device event
Add the first device event, used to forward the device clipboard to the
computer.
5 years ago
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.
5 years ago
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.
5 years ago
Romain Vimont 6ec2ddd2d1 Truncate UTF-8 properly
This will avoid to produce invalid UTF-8 results (although unlikely).
5 years ago
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.
5 years ago
Romain Vimont 3aa5426cad Add unit tests for control events serialization
Add missing tests for serialization and deserialization of control
events.
5 years ago
Romain Vimont 63207d9cd5 Fix wrong comment in unit test 5 years ago
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.
5 years ago
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.
5 years ago
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.
5 years ago
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.
5 years ago
Romain Vimont 0dee9b04b2 Use net_recv() to read only one byte
Partial read is impossible for 1 byte, so net_recv_all() is useless.
5 years ago
Romain Vimont 8fc58bde75 Simplify server_connect_to()
Only use 2 branches, using either forward or remote tunnel.
5 years ago
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.
5 years ago
Romain Vimont 6edb1294f0 Add missing return 0 in unit test 5 years ago
Romain Vimont 073181b294 Use cbuf for file handler request queue
Replace the file_handler_request_queue implementation by cbuf.
5 years ago
Romain Vimont 241a3dcba5 Use cbuf for control event queue
Replace the control_event_queue implementation by cbuf.
5 years ago
Romain Vimont b38292cd69 Add generic circular buffer
Add a circular buffer implementation, to factorize multiple specific
queues implementation.
5 years ago
Romain Vimont 7475550ae8 Add buffer_read16be()
Add a function to read 16 bits in big-endian to a uint16_t.
5 years ago
Romain Vimont 7fc8793d5b Make buffer util functions accept const buffers
So that they can be used both on const and non-const input buffers.
5 years ago
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.
5 years ago
Romain Vimont 507b0bcccf Fix memory leak on error
The variable condition was not destroyed on strdup() failure.
5 years ago
Romain Vimont e1afd9f8b0 Fix event ownership comment 5 years ago
Romain Vimont b08dada6c1 Prefix control event constants by namespace
This will avoid conflicts with future device events.
5 years ago
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
5 years ago
Romain Vimont befe455e44 Remove unused includes
The struct control_event does not use mutexes, and net.h does not need
SDL_platform.h.
5 years ago
Romain Vimont d2504f974c Fix indentation
Previous refactorings broke indentation.
5 years ago
Romain Vimont 0fbab42f8c Format meson.build for readability 5 years ago
Romain Vimont 08f506b24f Replace SDL_bool by bool in tests
Commit dfed1b250e replaced SDL types by
standard types in sources, but tests were not updated.
5 years ago
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.
5 years ago
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>.
5 years ago
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.
5 years ago
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.
5 years ago
Romain Vimont b3bd5f1b80 Remove useless casts to (void *) 5 years ago
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>
5 years ago
Romain Vimont 2dc1a59471 Check surface returned for icon
SDL_CreateRGBSurfaceFrom() may return NULL, causing a segfault.

<https://github.com/Genymobile/scrcpy/issues/539>
5 years ago
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>.
5 years ago
Romain Vimont eeb8e8420f Use size_t for command length
The size of an array should have type size_t.
5 years ago
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>
5 years ago
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>
5 years ago
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>
5 years ago
Romain Vimont e2ef39fae5 Fix overflow in test
The serialized text is not nul-terminated (its size is explicitely
provided), but the input text in the event is a nul-terminated string.

The test was failing with ASAN enabled.
5 years ago
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.
5 years ago
Romain Vimont a7b3901c31 Add more consts
Some decoder and recorder functions must not write to AVCodec and
AVPacket.
5 years ago
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.
5 years ago
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.
5 years ago
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).
5 years ago
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.
5 years ago
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
5 years ago
Romain Vimont 8655ba7197 Add option to mirror in read-only
Add an option to disable device control: -n/--no-control.
5 years ago
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.
5 years ago
Romain Vimont db6644f1f9 Add missing no_window initialization
Initialize the field no_window in "struct args"
5 years ago
Romain Vimont 36191b7eec Avoid unnecessary call if display is disabled
If --no-window is passed, there is no need to register an event watcher.
5 years ago
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.
5 years ago
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.)
5 years ago
Romain Vimont b2fe005498 Replace uint64_t by Uint64 for consistency
The field pts is declared Uint64 in struct frame_meta.
5 years ago
Romain Vimont 89812e4eee Implement the --no-window flag
Disable decoder, screen (display), file_handler and controller when
--no-window is requested.

<https://github.com/Genymobile/scrcpy/pull/418>
5 years ago
CapsLock 421a1141e2 Add a new option: -n/--no-window
This option will allow scrcpy to record the stream without display.

Signed-off-by: Romain Vimont <rom@rom1v.com>
5 years ago
Romain Vimont e6e011baaf Add stream layer
The decoder initially read from the socket, decoded the video and sent
the decoded frames to the screen:

              +---------+      +----------+
  socket ---> | decoder | ---> |  screen  |
              +---------+      +----------+

The design was simple, but the decoder had several responsabilities.

Then we added the recording feature, so we added a recorder, which
reused the packets received from the socket managed by the decoder:

                                    +----------+
                               ---> |  screen  |
              +---------+     /     +----------+
  socket ---> | decoder | ----
              +---------+     \     +----------+
                               ---> | recorder |
                                    +----------+

This lack of separation of concerns now have concrete implications: we
could not (properly) disable the decoder/display to only record the
video.

Therefore, split the decoder to extract the stream:

                                    +----------+      +----------+
                               ---> | decoder  | ---> |  screen  |
              +---------+     /     +----------+      +----------+
  socket ---> | stream  | ----
              +---------+     \     +----------+
                               ---> | recorder |
                                    +----------+

This will allow to record the stream without decoding the video.
5 years ago
Romain Vimont e7b7b083aa Store the recording request in a local bool
This avoids to test explicitly whether options->record_filename is NULL.
5 years ago
Romain Vimont 8aeb5c0e3c Fix cleanup order
The order of cleanup was not the reverse as the initialization order. As
a consequence, recorder_destroy() could theoretically be called even if
recorder_init() failed.
5 years ago
Romain Vimont bcd4090d51 Fix recording with old decoding/encoding API
The deprecated avcodec_decode_video2() should always the whole packet,
so there is no need to loop (cf doc/examples/demuxing_decoding.c in
FFmpeg).

This hack changed the packet size and data pointer. This broke recording
which used the same packet.
5 years ago
Romain Vimont 84270e2d18 Rename "stop" to "interrupt"
The purpose of video_buffer_stop() is to interrupt any blocking call, so
rename it to video_buffer_interrupt().
5 years ago
Romain Vimont fff87095d9 Rename "frames" to "video_buffer"
It better describes the purpose of the structure.
5 years ago
Romain Vimont aacb09a3d6 Remove unused mutex field in decoder 5 years ago
Romain Vimont 7d10ec2b5a Add shortcut to expand/collapse notification panel
Use Ctrl+n to expand, Ctrl+Shift+n to collapse.

Fixes <https://github.com/Genymobile/scrcpy/issues/392>
5 years ago
Romain Vimont 1c1fe5ec53 Use "always on top" only for SDL >= 2.0.5
The flag SDL_WINDOW_ALWAYS_ON_TOP is available since SDL 2.0.5.

Do not use it if SDL is older, to fix compilation failure.

Fixes <https://github.com/Genymobile/scrcpy/issues/432>
5 years ago
Romain Vimont 751600a7f9 Move all compat ifdefs definitions to compat.h
This allows to give a proper name to features requirements.
5 years ago
Romain Vimont f5f4e6b1c5 Allocate extradata with av_malloc()
The extradata buffer is owned by libav, so it must be allocated with
av_malloc(), not SDL_malloc().

This fixes a crash on Windows during avformat_free_context().
5 years ago
Romain Vimont 6c40dbd27d Regroup Windows-ifdefs in command.h 5 years ago
Romain Vimont 477c0a2cab Create process with wide chars on Windows
Windows does not support UTF-8, so pushing a file with non-ASCII
characters failed.

Convert the UTF-8 command line to a wide characters string and call
CreateProcessW().

Fixes <https://github.com/Genymobile/scrcpy/issues/422>
5 years ago
Romain Vimont c0b65b14df Merge branch 'master' into dev 5 years ago
Romain Vimont b23cacfc1a Add recording logs
Log when recording is started and stopped.
5 years ago
Romain Vimont 0ed2373952 Support recording to MKV
Implement recording to Matroska files.

The format to use is determined by the option -F/--record-format if set,
or by the file extension (".mp4" or ".mkv").
5 years ago
Romain Vimont 1aaad6ba35 Rescale packet timestamp to container time base
Some containers force their own time base. For example, matroska
overwrite time_base to (AVRational) {1, 1000}.

Therefore, rescale our packet timestamps to the output stream time base.

Suggested-by: Steve Lhomme <robux4@ycbcr.xyz>
5 years ago
Romain Vimont c8f0805b89 Write header file with correct extradata
When recording, the header must be written with extradata set to the
content of the very first packet.

Suggested-by: Steve Lhomme <robux4@ycbcr.xyz>

Fixes <https://github.com/Genymobile/scrcpy/issues/351>
Fixes <https://github.com/Genymobile/scrcpy/issues/416>
5 years ago
Romain Vimont ee3cba57a8 Forward FFmpeg logs
FFmpeg logs can be useful to understand the cause of issues.
5 years ago
Romain Vimont c11905b860 Add log verbose macro
This was the only log priority missing.
5 years ago
Romain Vimont 1a5ba59504 Fix memory leak on close
The buffer associated to the AVIOContext must be freed.
5 years ago
Yu-Chen Lin eca82e09c3 app: add always_on_top
It is very convenient when I play mobile game and watch video at the
same time.

Tested on Linux mint Cinnamon as well as Windows 10.

Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
5 years ago
Yu-Chen Lin 4d30fa93ba tests: fix test_control_event_serialize
commit fefb9816a changed the protocol, fix the related testing case.

Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
5 years ago
Romain Vimont 7764a836f1 Fix incorrect comment
Comment had not been updated along with the code.
6 years ago
Romain Vimont d71e036f3a Do not disable screensaver
Keep screensaver enabled while scrcpy is running.

Fixes <https://github.com/Genymobile/scrcpy/issues/380>.
6 years ago
Yu-Chen Lin c5ec1a194c input_manager: don't ignore double click event when clicking inside device
Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
6 years ago
Romain Vimont 39c5e71605 Make the server unlink itself
To clean up the device, the client executed "adb shell rm" once the
server was guaranteed to be started (after the connection succeeded).

This implied to track whether the installation state, and failed if an
additional tunnel was used in "forward" mode:
<https://github.com/Genymobile/scrcpy/issues/386#issuecomment-453936034>

Instead, make the server unlink itself on start.
6 years ago
Romain Vimont fefb9816a9 Handle mouse events outside device screen
Mouse events position were unsigned (so negative values could not be
handled properly).

To avoid issues with negative values, mouse events outside the device
screen were ignored (commit a7fe9ad779).

But as a consequence, drag&drop were "broken" if the "drop" occurred
outside the device screen.

Instead, use signed 32-bits to store the position, and forward events
outside the device screen.

Fixes <https://github.com/Genymobile/scrcpy/issues/357>.
6 years ago
Romain Vimont 7830859c21 Merge branch 'master' into dev 6 years ago
Romain Vimont a7fe9ad779 Ignore mouse events outside device screen
Never create a "struct point" with a position possibly outside the
device screen (i.e. in the black borders area), and do not transmit such
events.

This fixes an assertion failure on mouse wheel events outside the device
screen area.
6 years ago
Romain Vimont 1e22ebcac2 Always use non-empty arguments
The client passes parameters to the server via "adb shell" arguments.

Use "-" instead of "" when no crop is specified to avoid empty
arguments, which are not handled the same way on all devices.

Fixed <https://github.com/Genymobile/scrcpy/issues/337>.
6 years ago
Romain Vimont 2876463d39 Fix read_packet() return value on error or EOF
Fix warning on error or EOF:

> Invalid return value 0 for stream protocol

See <http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=a606f27f4c610708fa96e35eed7b7537d3d8f712>.

Fixes <https://github.com/Genymobile/scrcpy/issues/333>.
6 years ago
Romain Vimont 6dc6ec05d5 Configure version at meson project level
Make meson aware of the project version, so that it does not print:

    Project version: undefined
6 years ago
Pierre Gordon a17f1116ce Bump version to 1.5
Signed-off-by: Romain Vimont <rom@rom1v.com>
6 years ago
Romain Vimont 22ff03f2f7 Do not queue invalid PTS
Configuration packets produced by MediaCodec have no valid PTS, and do
not produce frame. Do not queue their (invalid) PTS not to break the
matching between frames and their PTS.
6 years ago
Romain Vimont 60afb46c8d Store queue of PTS for pending frames
Several frames may be read by read_packet() before they are consumed
(returned by av_read_frame()), so we need to store the PTS of frames in
order, so that the right PTS is assigned to the right frame.
6 years ago
Romain Vimont 345f8858d3 Send frame meta only if recording is enabled
The client needs the PTS for each frame only if recording is enabled.
Otherwise, the PTS are not necessary, and the protocol is more
straighforward.
6 years ago
Romain Vimont 22bf0c19d6 Rename --output-file to --record
To record the screen to a local file:

    scrcpy --record file.mp4
6 years ago
Romain Vimont 70579dc709 Wrap receiver state into separate struct
For readability, wrap the state of the receiver in a separate struct
receiver_state.
6 years ago
Romain Vimont e562837c0b Avoid partial header reads
Use net_recv_all() to avoid partial reads for the "meta" header (this
would break the whole stream).
6 years ago
Romain Vimont ebe998cf78 Move buffer reader functions to buffer_util.h 6 years ago
Romain Vimont b98eb7d0fa Support AVStream.codec for old FFmpeg versions
AVStream.codec has been deprecated in favor of AVStream.codecpar.

Due to the FFmpeg/Libav split, this happened in two separate versions:
 - 57.33.100 for FFmpeg
 - 57.5.0 for Libav
6 years ago
yuchenlin e361b49b4a recorder: use av_oformat_next to support older FFmpeg
Signed-off-by: yuchenlin <npes87184@gmail.com>
6 years ago
Romain Vimont d0e090e1f9 Reenable custom SDL signal handlers
This partially reverts commit f00c6c5b13.

On Ctrl+C, we need to execute cleanup code. For instance, if recording
is enabled, we need to write MP4 file trailer on exit.

Custom SDL signal handlers were disabled because it leaded to process
hanging on Ctrl+C during network calls on initialization, but now it
seems to work correctly, the network calls return immediately on signal.
6 years ago
Romain Vimont 475912a39c Do not transmit MediaCodec flags
Since PTS handling has been fixed, the recorder do not associate a PTS
to a wrong frame anymore, so PTS of "configuration packets" (which never
produce a frame), are never read by the recorder. Therefore, there is no
need to ignore them explicitly, so we can remove the MediaCodec flags
completely.
6 years ago
Romain Vimont 27e8a9a79d Assign PTS to the right frame
The PTS was read from the socket and set as the current one even before
the frame was consumed, so it could be assigned to the previous frame
"in advance".

Store the PTS for the current frame and the last PTS read from the
packet header of the next frame in separate fields.

As a side-effect, this fixes the warning on quit:

> Application provided invalid, non monotonically increasing dts to
> muxer in stream 0: 17164020 >= 17164020
6 years ago
Romain Vimont 61db575861 Decode and push frame before recording
Handle display before recording, to reduce latency.
6 years ago
Romain Vimont 2cd99e7205 Only set valid PTS/DTS
When the PTS is valid, set both PTS and DTS to avoid FFmpeg warnings.

Since configuration packets have no PTS, do not record these packets.
6 years ago
Romain Vimont 27686e9361 Add recorder
Implement recording in a separate "class".
6 years ago
Ivan Gorinov d706c5df39 Enable video output file, with pts set by server 6 years ago
Romain Vimont cb3cf801c8 Extract bit operations to buffer_util.h
Move util functions to a reusable separate header.
6 years ago
Romain Vimont 9160d465ec Add feature test macro to declare kill()
Avoid the following warning on some systems:

> warning: implicit declaration of function 'kill'
> [-Wimplicit-function-declaration]
6 years ago
Romain Vimont 5c739874a4 Fix memory leak on error
On decode error, unref the packet.
6 years ago
Romain Vimont d061c30965 Replace Ctrl by Meta for volume shortcuts on MacOS
Ctrl+UP and Ctrl+DOWN are already used by the window manager on MacOS.

Use Cmd key instead (like on VLC).
6 years ago
Romain Vimont 5bf1261364 Refactor to support Meta in shortcuts
Move the Ctrl and Meta key down checks to each shortcut individually, so
that we can add a shortcut involving Meta.
6 years ago
yuchenlin 96056e3213 input_manager: fix potential memory leak on text
Fix potential memory leak when controller_push_event failed.

Signed-off-by: yuchenlin <npes87184@gmail.com>
6 years ago
Romain Vimont 0b92b93358 Capture Alt and Meta keys
Alt and Meta keys should not be forwarded to the device. For now, they
are not used for shortcuts, but they could be.
6 years ago
Romain Vimont c20245630e Factorize Windows command building
Extract command line building to a separate method.
6 years ago
Romain Vimont 8875955921 Support paths containing spaces on Windows
Quote the arguments of "adb push" to support paths which contain spaces
on Windows.

Fixes <https://github.com/Genymobile/scrcpy/issues/288>.
6 years ago
Romain Vimont ff4430b2a3 Declare fun(void) functions with no parameters
This is not C++.
6 years ago
Romain Vimont 24d107d017 Bump version to 1.4 6 years ago
Romain Vimont 411aa4fcfd Handle alpha and space chars as raw events
To handle special chars, text is handled as text input instead of key
events. However, this breaks the separation of DOWN and UP key events.

As a compromise, send letters and space as key events, to preserve
original DOWN/UP events, but send other text input events as text, to be
able to send "special" characters.

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

Suggested-by: pete1414
Suggested-by: King-Slide <kingslide@gmail.com>
6 years ago
yuchenlin 140b1ef6a5 prevent closing console right after process error in windows
Signed-off-by: yuchenlin <npes87184@gmail.com>
6 years ago
Romain Vimont eca99d5af7 Fix header guard name 6 years ago
yuchenlin 27bed948d4 Use specific error for missing binary on Windows
Signed-off-by: yuchenlin <npes87184@gmail.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
6 years ago
Philipp Sandhaus af9808cf02 Add option to start in fullscreen
Signed-off-by: Romain Vimont <rom@rom1v.com>
6 years ago
Romain Vimont 55d33ddd5f Do not handle system-specific values in command.c
The common command.c handled process errors from system-specific int
values (errno).

Rather, expose a new enum process_result to handle error cause in a
generic way.
6 years ago
yuchenlin 6d2d803003 Notify adb missing
There are many user who encounters missing adb.
To stop things happens again, we check it and show
sexy response to user.

Signed-off-by: yuchenlin <npes87184@gmail.com>
6 years ago
Romain Vimont 89e0203682 Add missing include for lock_util.h
lock_util.c did not include lock_util.h. This was catched by the gcc
option -Wmissing-prototypes.
6 years ago
Romain Vimont 536b31829a Separate multi-words filenames by '_'
Rename foobar.ext to foo_bar.ext.

<https://github.com/Genymobile/scrcpy/pull/226#discussion_r209454865>
6 years ago
Romain Vimont 6581f9feb9 Make request_queue functions static
These functions are local to file_handler.c.
6 years ago
Romain Vimont 359685b1db Simplify SDL_assert() calls
SDL_assert() already prevents "unused variable" warnings.
6 years ago
Romain Vimont 4527be4cde Add missing include config.h
When config.h is not included, BUILD_DEBUG is not set.
6 years ago
npes87184 66f45f9dae Support drag&drop a file to transfer it to device
Signed-off-by: npes87184 <npes87184@gmail.com>
6 years ago
npes87184 aa97eed24b installer -> file_handler
Signed-off-by: npes87184 <npes87184@gmail.com>
6 years ago
Romain Vimont 2daeb1fd5f Reset current installer process
The current_process field was never reset after an installation is
complete. As a consequence, installer_stop() attempted to terminate it,
leading to a warning, at best.
6 years ago
Grief cde0b3d248 Return non-zero value on connection loss
Make scrscpy to return 0 exit code only in case when the user closes its
app, otherwise, i.e. in case of connection loss, return 1.
6 years ago
Romain Vimont 6fa209fa82 Remove AINPUT_SOURCE_ANY value
In the Android input header file, an enum has a value taking more than
31 bits, leading to the following warning:

    ISO C restricts enumerator values to range of ‘int’

Since we don't use it, remove it.
6 years ago
Romain Vimont b37c0f6cd6 Replace Uint32 by int to fix warnings in tinyxpm 6 years ago
npes87184 a3ab92226d Destroy mutex if strdup failed
Signed-off-by: npes87184 <npes87184@gmail.com>
6 years ago
npes87184 f8ef4f1cf7 remove redundant semicolon
Signed-off-by: npes87184 <npes87184@gmail.com>
6 years ago
Romain Vimont 7e42358a7b Bump version to 1.3 6 years ago
Romain Vimont caa9e30004 Add crop feature
Add an option to crop the screen on the server. This allows to mirror
only part of the device screen.
6 years ago
Romain Vimont 8793c104ee Increase "adb forward" connection attempts
5 seconds might not be sufficient:
<https://github.com/Genymobile/scrcpy/issues/213>

Increase to 10 seconds (it does not harm).
6 years ago
Romain Vimont fca806e095 Do not call deprecated av_register_all()
av_register_all() is deprecated in FFmpeg since this commit:
<http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=0694d8702421e7aff1340038559c438b61bb30dd>

It is now useless to call it:
<https://ffmpeg.org/pipermail/ffmpeg-devel/2018-February/225051.html>

Fixes <https://github.com/Genymobile/scrcpy/issues/203>.
6 years ago
Romain Vimont 49b2e63d13 Forward repeated volume events
Send repeated events when holding volume up/down shortcuts.
6 years ago
Romain Vimont c12c64ed41 Send separate DOWN/UP key events
Shortcuts generated instant DOWN/UP key events. Instead, generate DOWN
event on Ctrl+key down and UP event on Ctrl+key up.

Fixes <https://github.com/Genymobile/scrcpy/issues/166>.
6 years ago
Romain Vimont 2f66acd75d Improve English comment
Replace "implying" by "involving" (both "impliquant" in French).
6 years ago
Romain Vimont 1846d2f078 Prevent killing unexpected process
A missing initialization (fixed by the previous commit) leaded to kill
unexpected process.

In order to prevent consequences of similar errors in the future, never
call kill() with a non-positive PID.

See <https://github.com/Genymobile/scrcpy/issues/182>.
6 years ago
Romain Vimont 1a0139321b Fix missing installer initialization
The current_process field of struct installer was not initialized.
Since the installer instance is static, its default value was 0.

The call to installer_stop() then called kill(0, SIGTERM) (on Linux),
which sent SIGTERM to every process in the process group. In particular,
the scrcpy process was killed.

As a consequence, the last cleanup steps, like disabling "show touches",
were not executed.

Fixes <https://github.com/Genymobile/scrcpy/issues/183>.
6 years ago
Romain Vimont f705a73149 Use a meson option to crossbuild for Windows
Meson decided to crossbuild for Windows as soon as
meson.is_cross_build() returned true. This made non-Windows crossbuilds
fail.

Instead, add an explicit option "crossbuild_windows".

Fixes <https://github.com/Genymobile/scrcpy/issues/165>.
6 years ago
Romain Vimont 8106bb8215 Bump version to 1.2 6 years ago
Romain Vimont a63dd47f2d Make CreateProcess() flags depend on "noconsole"
On Windows, display the output of external commands (adb) when a console
is available.
6 years ago
Romain Vimont aedc2c2da9 Also build "noconsole" binary for Windows
On Windows, an application is either console or gui, it cannot be both.

Scrcpy should be both: it outputs important information to console, but
we still want to be able to ignore the console and launch it without a
visible cmd.exe window.

Therefore, build two binaries:
 - scrcpy.exe
 - scrcpy-noconsole.exe
6 years ago
Romain Vimont 106b87a4d2 Add cross-compilation scripts for Windows
Build the Windows binary from mingw on Linux, using the official
prebuilt binaries for ffmpeg, SDL2 and adb.

MSYS2 and all its packaged dll are not necessary anymore.
6 years ago
Romain Vimont 6274cc3767 Document APK drag & drop
Add the drag & drop shortcut for installing an APK file to the README
and the help.
6 years ago
Romain Vimont 9c6f9b24f9 Quote apk path on Windows
Windows will parse the string, so the local name must be quoted.
6 years ago
Adonis Najimi e2a2973990 Drag and drop to install apk files from computer
<https://github.com/Genymobile/scrcpy/pull/133>
6 years ago
Romain Vimont 41419a2e77 Fix net_send_all() warning
If len is not positive, w could be returned uninitialized.
6 years ago
Romain Vimont e3d0a59c80 Fix proc_show_touches warning
In practice, proc_show_touches may not be used uninitialized, since it
checks the flag options->show_touches, but the compiler can't know that,
so initialize it to avoid the warning.
6 years ago
Romain Vimont bb3a7f05ac Release controller lock while processing events
Once the controller took a control event, release the mutex before
processing it, so that the main thread is not blocked to push a new
event.
6 years ago
Romain Vimont ec02823045 Fix leak on server start error
Fail on SDL_strdup() failure, and free the duplicated serial on further
error.
6 years ago
Romain Vimont 435a7fe314 Add missing includes
Include string.h and stdio.h explicitly.
6 years ago
Romain Vimont 78da66f126 Merge branch 'master' into dev 6 years ago
Romain Vimont 9aa88b6fc3 Map numpad ENTER key
Forward numpad ENTER key to the device.

Fixes <https://github.com/Genymobile/scrcpy/issues/117>.
6 years ago
Romain Vimont 0871bca9c7 Avoid pointer arithmetic on "void *"
Fix the following warning (with -Wpedantic enabled):

    pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
6 years ago
Romain Vimont b2b5404883 Use const pointers when possible
Sending data only require to read the input buffer, so declare it const.
6 years ago
Romain Vimont 1bddb80b5f Change volume shortcuts
I could not make Ctrl+'+' and Ctrl+'-' work for every keyboard on every
platform.

Instead, use Ctrl+UP and Ctrl+DOWN (like in VLC) to change the volume.

Fixes <https://github.com/Genymobile/scrcpy/issues/103>.
6 years ago
Romain Vimont 71f50fb697 Merge branch 'master' into dev 6 years ago
Romain Vimont 82efff34e8 Factorize texture creation
SDL_CreateTexture() is called both during initialization and on frame
size change.

To avoid inconsistent changes to arguments value, factorize them to a
single function create_texture().
6 years ago
Romain Vimont 860006e082 Forward double-click events
Double-clicks were not sent to the device anymore since the
"double-click on black borders" feature.

When a double click occurs inside the device screen, send the event to
the device normally.

Fixes <https://github.com/Genymobile/scrcpy/issues/97>.
6 years ago
Romain Vimont 57eaf05289 Improve startup time when show_touches is enabled
Enabling "show touches" involves the execution of an adb command, which
takes some time.

In order to parallelize, execute the command as soon as possible, but
reap the process only once everything is initialized.
6 years ago
Romain Vimont dd2a5c1ecf Disable "show touches" once window is closed
If --show-touches is set, then the option must be disabled on quit.

Since it executes an adb command, it takes some time, so close the
window beforehand so that the close window button does not seem
unresponsive.
6 years ago
Romain Vimont 66ec252893 Add an option to enable "show touches"
Add -t/--show-touches option to show physical touches while scrcpy is
running.

See <https://github.com/Genymobile/scrcpy/issues/96>.
6 years ago
Romain Vimont b13d25b9f4 Group scrcpy options into a struct
The scrcpy() function accepts as many parameters as there are options.

To simplify, group all options in a separate struct.
6 years ago
Romain Vimont b449c09442 Merge branch 'master' into dev 6 years ago
Romain Vimont 35298bb0c6 Process the last video frame
On H.264 stream EOF, the eof_reached flag is set, but av_read_frame()
still provides a frame, so check the flag only afterwards.

As a side-effect, it also fixes a memory leak (the very last packet was
not unref).
6 years ago
Romain Vimont 73c332e3e4 Unref last packet on exit 6 years ago
Romain Vimont 29b5c5b8f4 Merge branch 'arich/addShake' into dev (#85)
Add support for CTRL+S to send hardware "shake" to device
6 years ago
Romain Vimont 88ee6bc928 Swap MENU and APP_SWITCH shortcuts
Ctrl+s was mapped to MENU, while Ctrl+m was mapped to APP_SWITCH.

To avoid confusion, swap the shortcuts:
 - Ctrl+m like _M_enu
 - Ctrl+s like _S_witch
6 years ago
Romain Vimont 35e9a64c34 Rename "shake" to "menu"
The action sends AKEYCODE_MENU, so just name it "menu".

See <https://github.com/Genymobile/scrcpy/pull/85>.
6 years ago
Andy Rich 301c52b603 Add support for CTRL+S to send hardware "shake" to device w/readme 6 years ago
Romain Vimont f00c6c5b13 Disable custom SDL signal handlers
Request SDL not to replace the SIGINT and SIGTERM handlers, so that the
process is immediately terminated on Ctrl+C.

This avoids process hanging on Ctrl+C during network calls on
initialization.

Some of them accepted a timeout, but it was not used since
commit 9b056f5091 anymore.
6 years ago
Romain Vimont 3b3803da0d Remove useless blocks in switch/case
Remove unnecessary additional blocks.
6 years ago
Romain Vimont f5cf6c1b2c Include source root directory
All headers and sources are in src/. To avoid using relative includes
from subdirectories ("../../"), include the source root directory.
6 years ago
Romain Vimont c65cb36d3b Increase the number of connection attempts
In "adb forward" mode, it may take a while before the server socket is
listening, so increase the number of connection attempts.

See <https://github.com/Genymobile/scrcpy/issues/5#issuecomment-373718551>.
6 years ago
Romain Vimont 821ec9843c Fix win32 build
The types size_t and ssize_t are defined on Windows (in MSYS2), so there
is no need to typedef SIZE_T and SSIZE_T.

Exit code is "unsigned long" both on Windows 32 and 64 bits.

See <https://github.com/Genymobile/scrcpy/issues/46#issuecomment-373603596>.
6 years ago
Romain Vimont f16bd88802 Remove useless cast
For consistency with mouse button events handling, directly assign from
Sint32 to Uint16.
6 years ago
Romain Vimont f3e8834a3c Fix warning message
Mouse "wheel button" is meaningless :)
6 years ago
Romain Vimont 080df5eb5d Fix switch/case code style
For readability and consistency, indent case statatements, and remove
unnecessary additional blocks.
6 years ago
Romain Vimont d744837f13 Bump version to 1.1 6 years ago
Romain Vimont f7bc0bd5b5 Merge branch 'dev' into release 6 years ago
Romain Vimont 8a3c6a3ae7 Remove useless argument
Do not pass any data to the event watcher, it is unused.
6 years ago
Romain Vimont 0b1e59186f Workaround continuous resizing on Windows/MacOS
On Windows and MacOS, resizing blocks the event loop, so resizing events
are not triggered:
 - <https://bugzilla.libsdl.org/show_bug.cgi?id=2077>
 - <https://stackoverflow.com/a/40693139/1987178>

As a workaround, register an event watcher to render the screen from
another thread.

Since the whole event loop is blocked during resizing, the screen
content is not refreshed (on Windows and MacOS) until resizing ends.
6 years ago