Commit Graph

143 Commits (ca9e1a05148d46793de0118a8cbcef62877df534)

Author SHA1 Message Date
Romain Vimont 6adc97198b Provide device info directly on server connection
This avoids to retrieve them in a separate step.
3 years ago
Marco Martinelli d39161f753 Add support for v4l2loopback
It allows to send the video stream to /dev/videoN, so that it can be
captured (like a webcam) by any v4l2-capable tool.

PR #2232 <https://github.com/Genymobile/scrcpy/pull/2232>
PR #2233 <https://github.com/Genymobile/scrcpy/pull/2233>
PR #2268 <https://github.com/Genymobile/scrcpy/pull/2268>

Co-authored-by: Romain Vimont <rom@rom1v.com>
3 years ago
Romain Vimont 9826c5c4a4 Remove HiDPI compilation flag
Always enable HiDPI support, there is no reason to expose a compilation
flag.
3 years ago
Romain Vimont b16b65a715 Simplify default values
It makes sense to extract default values for bitrate and port range
(which are arbitrary and might be changed in the future).

However, the default values for "max size" and "lock video orientation"
are naturally unlimited/unlocked, and will never be changed. Extracting
these options just added complexity for no benefit, so hardcode them.
3 years ago
Romain Vimont 9cd1a7380d Enable NDEBUG via Meson built-in option 3 years ago
Romain Vimont f6320c7e31 Wrap SDL thread functions into scrcpy-specific API
The goal is to expose a consistent API for system tools, and paves the
way to make the "core" independant of SDL in the future.
3 years ago
Romain Vimont c0dde0fade Provide strdup() compat
Make strdup() available on all platforms.
3 years ago
Romain Vimont 8dbb1676b7 Factorize meson compiler variable initialization 3 years ago
Romain Vimont cc6f5020d8 Move conditional src files in meson.build
Declare all the source files (including the platform-specific ones) at
the beginning.
3 years ago
Romain Vimont 4bd9da4c93 Split command into process and adb
The process API provides the system-specific implementation, the adb API
uses it to expose adb commands.
3 years ago
Romain Vimont a46733906a Replace noconsole binary by a wrapper script
This simplifies the build system.

Refs <https://github.com/Genymobile/scrcpy/issues/1975#issuecomment-745314161>
4 years ago
Romain Vimont 1b76d9fd78 Customize shortcut modifier
Add --shortcut-mod, and use Alt as default modifier.

This paves the way to forward the Ctrl key to the device.
4 years ago
Romain Vimont 08c0c64af6 Rename test names from "event" to "msg"
The meson test names had not been changed when "event" had been renamed
to "message".

Ref: 28980bbc90
4 years ago
Romain Vimont bea7658807 Enable trilinear filtering for OpenGL
Improve downscaling quality if mipmapping is available.

Suggested-by: Giumo Clanjor (哆啦比猫/兰威举) <cjxgm2@gmail.com>

Fixes #40 <https://github.com/Genymobile/scrcpy/issues/40>
Ref: <https://github.com/Genymobile/scrcpy/issues/40#issuecomment-591917787>
4 years ago
Romain Vimont 902b99174d Fix server debugger for Android >= 9
Add a compilation flag to select the debugger method to use:
 - old: Android < 9
 - new: Android >= 9

See <https://github.com/Genymobile/scrcpy/issues/1187#issuecomment-599075661>
4 years ago
George Stamoulis 1982bc439b Add option to lock video orientation
PR #1151 <https://github.com/Genymobile/scrcpy/pull/1151>

Signed-off-by: Romain Vimont <rom@rom1v.com>
4 years ago
Romain Vimont dc7fcf3c7a Accept port range
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>
4 years ago
Romain Vimont db6252e52b Simplify net.c
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.
5 years ago
Romain Vimont e4cebc8d4c Do not build tests in release mode
Assertions would not be executed.

And as a side effect, it causes "unused variable" warnings.
5 years ago
Romain Vimont ba1b36758e Define SDL_MAIN_HANDLED in all tests
Each test defines its own main() function. If this flag is not set, then
SDL redefines it to SDL_main(), causing compilation failures.
5 years ago
Romain Vimont ad92a192b5 Fix meson.build codestyle 5 years ago
Romain Vimont 929bf48c7e Add tests for command-line parsing 5 years ago
Romain Vimont d950383b72 Move command-line parsing to a separate file 5 years ago
Yu-Chen Lin b2bf25c52c Add test_buffer_util
Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
5 years ago
Romain Vimont b5ebb234dd Replace BUILD_DEBUG by NDEBUG
Use the "standard" NDEBUG definition, which is used by assert().
5 years ago
Romain Vimont dfd0707a29 Move utilities to util/ 5 years ago
Romain Vimont 18f2e33a8b Fix noconsole.exe
The linker flag "-mwindows" has no effect on my current MinGW.

Instead, passing "-Wl,--subsystem,windows" works.

Fixes <https://github.com/Genymobile/scrcpy/issues/691>
5 years ago
Romain Vimont 683f7ca848 Document how to attach a debugger to the server 5 years ago
Romain Vimont 0415672a75 Merge branch 'master' into dev 5 years ago
yangfl 4696878a97 Add manpage for scrcpy 5 years ago
Romain Vimont 3da95b52bd Rename scrcpy-server.jar to scrcpy-server
The server name ending with .jar has several drawbacks:
 - meson requires the jar executable to attempt to modify it:
     <https://github.com/Genymobile/scrcpy/issues/404#issuecomment-456065923>
     <https://github.com/mesonbuild/meson/issues/4844>
 - meson warns during "ninja install"
     <https://github.com/Genymobile/scrcpy/issues/458>
 - some users try to execute it on the computer as a java executable

Removing the extension solves all these problems.
5 years ago
Romain Vimont 9463850c24 Rename "convert.h" to "event_converter.h"
The filename gave no hint about what was converted.
5 years ago
Romain Vimont 53b6ee2cf4 Add generic intrusive FIFO queue
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.
5 years ago
Romain Vimont 2755bfc255 Improve portable builds
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.
5 years ago
Romain Vimont eb34098add Simplify portable build configuration
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.
5 years ago
Romain Vimont b777760bca Simplify scrcpy-server path configuration
The full path of scrcpy-server.jar was partially configured from
meson.build then concatenated by C code.

Instead, directly write the path in C.
5 years ago
Romain Vimont 5d11339259 Inline lock_util functions
They are just tiny wrappers.
5 years ago
Romain Vimont ebccb9f6cc Add runtime option to render expired frames
Replace the compilation flag SKIP_FRAMES by a runtime flag to force
rendering of expired frames. By default, the expired frames are skipped.
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
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 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 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 0fbab42f8c Format meson.build for readability 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 fff87095d9 Rename "frames" to "video_buffer"
It better describes the purpose of the structure.
5 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 27686e9361 Add recorder
Implement recording in a separate "class".
6 years ago
Romain Vimont 24d107d017 Bump version to 1.4 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
npes87184 aa97eed24b installer -> file_handler
Signed-off-by: npes87184 <npes87184@gmail.com>
6 years ago
Romain Vimont 7e42358a7b Bump version to 1.3 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
Adonis Najimi e2a2973990 Drag and drop to install apk files from computer
<https://github.com/Genymobile/scrcpy/pull/133>
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 d744837f13 Bump version to 1.1 6 years ago
Romain Vimont c2ac6fe7bd Upgrade version to 1.0 6 years ago
Romain Vimont fffeedffda Expose High DPI support configuration flag
The High DPI support is enabled by default, so that the renderer use the
full definition of High DPI screens.

However, there are still mouse coordinates problems on some MacOS having
High DPI support (but not all), so expose a way to disable it.
6 years ago
Romain Vimont e3f5d3b49b Double the default bitrate
Set the default video bitrate to 8Mbps. This greatly increase quality on
fast motion, without negative side effects.
6 years ago
Romain Vimont 089378926b Rename SCRCPY_SERVER_JAR to SCRCPY_SERVER_PATH
The server is currently a JAR, but it may ba an APK or a DEX, so the
variable name should not contain the type.

Rename the environment variable, the Meson options and the C
definitions.
6 years ago
Romain Vimont 9b056f5091 Replace SDL_net by custom implementation
SDL_net is not very suitable for scrcpy.

For example, SDLNet_TCP_Accept() is non-blocking, so we have to wrap it
by calling many SDL_Net-specific functions to make it blocking.

But above all, SDLNet_TCP_Open() is a server socket only when no IP is
provided; otherwise, it's a client socket. Therefore, it is not possible
to create a server socket bound to localhost, so it accepts connections
from anywhere.

This is a problem for scrcpy, because on start, the application listens
for nearly 1 second until it accepts the first connection, supposedly
from the device. If someone on the local network manages to connect to
the server socket first, then they can stream arbitrary H.264 video.
This may be troublesome, for example during a public presentation ;-)

Provide our own simplified API (net.h) instead, implemented for the
different platforms.
6 years ago
Romain Vimont 000ced9ba8 Refactor screencontrol to inputmanager
The "screen control" handled user input, which happened to be only
used to control the screen.

The controller and screen were passed to every function. Instead, group
them in a struct input_manager.

The purpose is to add a new shortcut to enable/disable FPS counter. This
feature is not related to "screen control", and will require access to
the "frames" instance.
6 years ago
Romain Vimont 42882702d7 Expose skip_frames as a build option
It can be initially configured by:

    meson builddir -Dskip_frames=false

Or on an existing builddir by:

    mesonconf builddir -Dskip_frames=false
6 years ago
Romain Vimont 38e6682875 Add FPS counter
Remove frame counter from scrcpy.c and add a new FPS counter, logging as
INFO the measured frame rate every second (on new frame).
6 years ago
Romain Vimont 0efa9305eb Require Meson 0.37
Older versions of Meson are too limited, and it's simple to install a
newer version ("pip3 install meson").
6 years ago
Romain Vimont c2127d0819 Replace meson subprojects by subdir
Since Meson 0.44, subproject_dir may not be '.' anymore. This implies we
must move app/ and server/ to a subprojects/ directory, which requires
to also change some gradle files.

Instead, just use subdir(), with options to disable building of the app
or the server.
6 years ago
Romain Vimont ff94462d8a Refactor build system
The client was built with Meson, the server with Gradle, and were run by
a Makefile.

Add a Meson script for the server (which delegates to Gradle), and a
parent script to build and install both the client and the server to the
system, typically with:

    meson --buildtype release build
    cd build
    ninja
    sudo ninja install

In addition, use a separate Makefile to build a "portable" version of
the application (where the client expects the server to be in the
current directory). Typically:

    make release-portable
    cd dist/scrcpy
    ./scrcpy

This is especially useful for Windows builds, which are not "installed".
6 years ago
Romain Vimont 396df8a9d8 Provide config.h.in for old meson versions
The current meson version is able to generate a config.h from a
configuration data object without any template.

However, older versions of meson require a template, so provide it for
compatibility.
6 years ago
Romain Vimont d45ef1a295 Do not use too recent set_quoted()
Old versions of meson do not support set_quoted(). Replace the call by
the old-fashioned manual quotation.
6 years ago
Romain Vimont 4dbc450d01 Enable debug logs only for debug builds
In release mode, use the default log priorities.
6 years ago
Romain Vimont e8dfb723af Move control-related code to screencontrol.c
Move the code handling user input from scrcpy.c to a separate file,
screencontrol.c.
6 years ago
Romain Vimont 3b06e7d500 Move device-related code to device.c
Move the code to read the initial device info from scrcpy.c to a
separate file, device.c.
6 years ago
Romain Vimont 6c578b5caa Move screen-related code to screen.c
The file scrcpy.c contains too many different things in addition to the
main logic, so move the screen code to a separate file, screen.c.
6 years ago
Romain Vimont ffae15e36a Rename control to controller
The struct decoder is defined in decoder.h.

For naming consistency, define the struct controller in controller.h.
6 years ago
Romain Vimont 9f6464acff Expose application version
Expose scrcpy version via -v or --version.
6 years ago
Romain Vimont 8d30d40b79 Make SKIP_FRAMES a compilation flag
The skip_frames flag was a non-configurable runtime flag. Since it is
not exposed to the user, there is no need for a (possible) runtime cost.

For testing purpose, we still want it to be configurable, so make it a
compilation flag.
6 years ago
Romain Vimont 53ff1aa410 Use meson to configure default values
Make meson generate config.h with configured values.
6 years ago
Romain Vimont 71c2bfdd22 Parse XPM without SDL_image
We encounter some problems with SDL2_image on MSYS2 (Windows), so
implement our own XPM parsing which does not depend on SDL_image.

The input XPM is considered safe (it's in our source repo), so do not
check XPM format errors. This implies that read_xpm() is not safe to
call on any unsafe input.

Although less straightforward, use SDL_CreateRGBSurfaceFrom() instead of
SDL_CreateRGBSurfaceWithFormatFrom() because it is available with SDL
versions older than 2.0.5.
6 years ago
Romain Vimont 52c89c7afb Add window icon
Add a bugdroid icon loaded from an XPM.
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 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).
7 years ago
Romain Vimont f75c404a26 Add tests for strutil
Test our custom string handling functions.
7 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.
7 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.
7 years ago
Romain Vimont d5b349f670 Do not inline lockutil functions
This duplicates chars in the final binary.
7 years ago
Romain Vimont 54d9148a36 Initial commit
Start a new clean history from here.
7 years ago