Find a file
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.
2018-02-16 00:56:58 +01:00
app Replace SDL_net by custom implementation 2018-02-16 00:56:58 +01:00
config Apply Genymobile rules for Android projects 2018-02-07 20:58:18 +01:00
gradle/wrapper Convert server to an Android project 2018-01-30 12:01:36 +01:00
scripts Refactor build system 2018-02-14 09:23:14 +01:00
server Accept prebuilt server 2018-02-14 16:28:21 +01:00
.gitignore Convert server to an Android project 2018-01-30 12:01:36 +01:00
build.gradle Convert server to an Android project 2018-01-30 12:01:36 +01:00
gradle.properties Convert server to an Android project 2018-01-30 12:01:36 +01:00
gradlew Convert server to an Android project 2018-01-30 12:01:36 +01:00
gradlew.bat Convert server to an Android project 2018-01-30 12:01:36 +01:00
Makefile Replace meson subprojects by subdir 2018-02-14 14:03:56 +01:00
meson.build Require Meson 0.37 2018-02-14 14:03:56 +01:00
meson_options.txt Add description for meson options 2018-02-15 11:28:19 +01:00
README.md Parse XPM without SDL_image 2018-02-05 19:24:33 +01:00
run Add run script 2018-02-14 18:31:42 +01:00
settings.gradle Convert server to an Android project 2018-01-30 12:01:36 +01:00

ScrCpy

This project displays screens of Android devices plugged on USB in live.

Run

Runtime requirements

This projects requires FFmpeg, LibSDL2 and LibSDL2-net.

Linux

Install the packages from your package manager. For example, on Debian:

sudo apt install ffmpeg libsdl2-2.0.0 libsdl2-net-2.0.0

Windows

From MSYS2:

pacman -S mingw-w64-x86_64-SDL2
pacman -S mingw-w64-x86_64-SDL2_net
pacman -S mingw-w64-x86_64-ffmpeg

MacOS

TODO

Build

The project is divided into two parts:

  • the server, running on the device (in server/);
  • the client, running on the computer (in app/).

The server is a raw Java project requiring Android SDK. It not an Android project: the target file is a .jar, and a main() method is executed with shell rights.

The client is a C project using SDL and FFmpeg, built with Meson/Ninja.

The root directory contains a Makefile to build both parts.

Build requirements

Install the Android SDK, the JDK 8 (openjdk-8-jdk), and the packages described below.

Linux

sudo apt install make gcc openjdk-8-jdk pkg-config meson zip \
                 libavcodec-dev libavformat-dev libavutil-dev \
                 libsdl2-dev libsdl2-net-dev

Windows

Install these packages:

pacman -S mingw-w64-x86_64-make
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-pkg-config
pacman -S mingw-w64-x86_64-meson
pacman -S zip

Java 8 is not available in MSYS2, so install it manually and make it available from the PATH:

export PATH="$JAVA_HOME/bin:$PATH"

Build

Make sure your ANDROID_HOME variable is set to your Android SDK directory:

export ANDROID_HOME=~/android/sdk

From the project root directory, execute:

make build

To run the build:

make run

It is also pass arguments to scrcpy via make:

make run ARGS="-p 1234"

The purpose of this command is to execute scrcpy during the development.

Test

To execute unit tests:

make test

The server-side tests require JUnit 4:

sudo apt install junit4

Generate a release

From the project root directory, execute:

make release

This will generate the application in dist/scrcpy/.

Run

Plug a device, and from dist/scrcpy/, execute:

./scrcpy

If several devices are listed in adb devices, you must specify the serial:

./scrcpy 0123456789abcdef

To change the default port (useful to launch several scrcpy simultaneously):

./scrcpy -p 1234

Other options are available, check scrcpy --help.