Commit Graph

2408 Commits (master)
 

Author SHA1 Message Date
Romain Vimont 2172c53b7b Force the server target filename
The server path may be customized using SCRCPY_APK. If its basename is
different from "scrcpy.apk", it will be pushed with a different name,
so the execution would fail.

Therefore, force the push target filename.
6 years ago
Romain Vimont ca44585f96 Do not send simple mouse move events
Moving the mouse without any button pressed has no effect on Android.
Therefore, do not even send these very frequent events.
6 years ago
Romain Vimont 79b28eb68f Enable mouse focus clickthrough
Consider a click to gain focus as a click on the device.
6 years ago
Romain Vimont 6b546a87ab Add bit-rate command-line option
Add a command-line option (-b/--bit-rate) to customize the video
bit-rate.
6 years ago
Romain Vimont 7fe7bbf58c Check empty string before strtol()
There is no need to call strtol() if the input string is empty.
6 years ago
Romain Vimont 3bc63708b4 Remove useless newlines in SDL_Log*
Trailing new line is not necessary in SDL_Log* methods.
6 years ago
Romain Vimont 2683fa20ed Add debug log for shortcuts
Add a debug log for every succeeded shortcut action.
6 years ago
Romain Vimont 274e1ac9ec Fix rotation bug in fullscreen mode on X11
On rotation, scrcpy resize the window to match the new rotation.
However, in fullscreen mode, setting the window size does not change the
windowed size on X11, so the behavior is incorrect.

To avoid the problem, apply the resize only after fullscreen is
disabled.
6 years ago
Romain Vimont 35a111d56e Add --help
Provide command-line help, with -h/--help option.
6 years ago
Romain Vimont ee93f3f23a Rename maximum_size to max_size
The long option is --max-size, so for consistency, adapt the code
accordingly.
6 years ago
Romain Vimont 213b721ff9 Use long command-line options
In addition to the short form (e.g. "-p"), add the long form ("--port").
6 years ago
Romain Vimont 60b2f2ca64 Indent switch blocks content
For readability, indent "case" in switch blocks.

Replace:

    switch (x) {
    case 1:
        // ...
    case 2:
        // ...
    case 3: { // a local scope block
        int i = 42;
        // ...
    }
    }

By:

    switch (x) {
        case 1:
            // ...
        case 2:
            // ...
        case 3: { // a local scope block
            int i = 42;
            // ...
        }
    }
6 years ago
Romain Vimont 628f88ab89 Use ADB environment variable
Use the ADB environment variable to provide a custom adb path.
6 years ago
Romain Vimont 865ebb3862 Encode video using MediaCodec API
Replace screenrecord execution by manual screen encoding using the
MediaCodec API.

The "screenrecord" solution had several drawbacks:
 - screenrecord output is buffered, so tiny frames may not be accessible
   immediately;
 - it did not output a frame until the surface changed, leading to a
   black screen on start;
 - it is limited to 3 minutes recording, so it needed to be restarted;
 - screenrecord added black borders in the video when the requested
   dimensions did not preserve aspect-ratio exactly (sometimes
   unavoidable since video dimensions must be multiple of 8);
 - rotation handling was hacky (killing the process and starting a new
   one).

Handling the encoding manually allows to solve all these problems.
6 years ago
Romain Vimont 7ed334915e Register uncaught exception handler
Never miss an exception by using an uncaught exception handler.
6 years ago
Romain Vimont 8c4a454d68 Extract argument parsing
Move argument parsing to a separate method.
6 years ago
Romain Vimont 73831a0837 Use the Point class from the framework
Replace our custom Point class by android.graphics.Point.
6 years ago
Romain Vimont b67907e24e Convert server to an Android project
To simplify the device server-side build, use gradle to create an APK,
even if we use it as a simple jar, by running its main() method.
6 years ago
Romain Vimont 89f6a3cfe7 Handle resized video stream
Accept a parameter to limit the video size.

For instance, with "-m 960", the great side of the video will be scaled
down to 960 (if necessary), while the other side will be scaled down so
that the aspect ratio is preserved. Both dimensions must be a multiple
of 8, so black bands might be added, and the mouse positions must be
computed accordingly.
6 years ago
Romain Vimont 2c4ea6869e Do not use device as a singleton
The device instance should be able to store a state (e.g. the maximum
size requested by the user), so it should not be a singleton.
6 years ago
Romain Vimont 879941355d Swap position/point names
A point is a 2D vector. A position represent a point relative to the
screen size.
6 years ago
Romain Vimont f70359f14f Inject mouse events as touchscreen
As a mouse, some clicks on close prositions are sometimes not generated
on some devices.
6 years ago
Romain Vimont 1930c81062 Add toString() methods to java point classes
Useful for debugging.
6 years ago
Romain Vimont dca53ff931 Add missing source files in server Makefile
All classes were still built, but make was not able to detect changes on
missing files.
6 years ago
Romain Vimont 2aa15db210 Add shortcut to resize to ratio 1:1
Make Ctrl+g resize the window to the size of the video (pixel-perfect).
6 years ago
Romain Vimont ab2c3de9f5 Capture all Ctrl events
For consistency, capture all Ctrl events (not only those we react to).
6 years ago
Romain Vimont 2c35220618 Rename screen -> scrcpy -> main
Rename scrcpy.c to main.c (this file handles the command line parsing),
and screen.c to scrcpy.c (it exposes the entry point scrcpy()).
6 years ago
Romain Vimont 8984c1a7c4 Scale mouse events
The video screen size on the client may differ from the real device
screen size (e.g. the video stream may be scaled down). As a
consequence, mouse events must be scaled to match the real device
coordinates.

For this purpose, make the client send the video screen size along with
the absolute pointer location, and the server scale the location to
match the real device size before injecting mouse events.
6 years ago
Romain Vimont 11a60e5767 Keep screen info in cache
Currently, we only use screen information (width, height, rotation)
once at initialization, to send the device size to the client.

To be able to scale mouse events, make it accessible in memory. For this
purpose, replace the "static" DeviceUtil to a singleton Device, and
update it on every screen rotation.
6 years ago
Romain Vimont d7b00a9bab Move server-related functions to server.c
In addition to the functions to start/stop the server, move the
functions to push the jar and enable/disable the "adb reverse" tunnel.
6 years ago
Romain Vimont 3078894d1f Add debug log on new screenrecord execution
To easily notice problems with screenrecord execution, log every new
instance started.
6 years ago
Romain Vimont 7d67696b7e Extract server-related functions
To lighten screen.c, move start_server() and stop_server() to a separate
file.
6 years ago
Romain Vimont 52af91f6b0 Add unit tests for control event serialization
Test serialization of the 4 types of events (keycode, text, mouse,
scroll).
6 years ago
Romain Vimont 90c69d2c79 Use pointers-to-const where relevant
Explicitly declare const a function parameter intended to be read-only.
6 years ago
Romain Vimont 53cd59605a Ignore keycodes generating unwanted events
Ctrl, Alt, Shift and Meta should not be transmitted to the Android
device: they may generate unwanted events. For instance, resizing the
window using Alt+click will generate an Alt event which may open a menu
on the device.

All keycodes that generate a text input must also be excluded, to avoid
the text input to be written twice.
6 years ago
Romain Vimont 66b7a99db6 Fix includes windows-specific source
The header strutil.h is two levels above sys/win/command.c, and
SDL_log.h was missing.
6 years ago
Romain Vimont fbf2d34006 Add unit testing instructions in README 6 years ago
Romain Vimont f75c404a26 Add tests for strutil
Test our custom string handling functions.
6 years ago
Romain Vimont cabb102a04 Implement keyboard/mouse control
To control the device from the computer:
 - retrieve mouse and keyboard SDL events;
 - convert them to Android events;
 - serialize them;
 - send them on the same socket used by the video stream (but in the
 opposite direction);
 - deserialize the events on the Android side;
 - inject them using the InputManager.
6 years ago
Romain Vimont 6605ab8e23 Log to android logger and stdout/stderr 6 years ago
Romain Vimont 95591d2938 Move platform specific to sys/
Move unix/ and win/ to sys/, so that we can use android/ for android
headers without confusion.
6 years ago
Romain Vimont a919944372 Use _exit() instead of exit() in child process
exit() should not be called from within a child process, since it would
call functions registered with atexit(), and flush stdio streams. Use
_exit() instead.
6 years ago
Romain Vimont 07b3918129 Do not call SDL_Quit()
It may crash in i965_dri.so when calling SDL_Quit (probably a driver
bug). To avoid a segmentation fault, do not call SDL_Quit().
7 years ago
Romain Vimont a005df7b37 Always destroy in reverse order
For consistency and safety, always destroy objects in reverse order they
were initialized.
7 years ago
Romain Vimont de106747b6 Improve main() error handling
Parse the command-line arguments first, and do not ignore avformat
network init failure. At the end, deinit the avformat network.
7 years ago
Romain Vimont bb8afa9324 Fix comment about data sent over the socket
We now send the device name in addition to the screen dimensions on the
socket. Update the comment accordingly.
7 years ago
Romain Vimont d972a88c1a Optimize includes
Only include SDL_stdinc.h for SDL_bool, not the whole SDL.h.
7 years ago
Romain Vimont d5b349f670 Do not inline lockutil functions
This duplicates chars in the final binary.
7 years ago
Romain Vimont a9b276aa67 Remove useless forward declarations
The required headers are included anyway.
7 years ago
Romain Vimont b9c9466d65 Handle condition variable failure
Add condition variables function wrappers to handle unexpected failure.
7 years ago