Skip to content

Commit

Permalink
Rebase and Merge with Master - From v1.2 to v1.3
Browse files Browse the repository at this point in the history
- Fix missing initialization that leaded to kill the whole process
- group on quit (Genymobile#182, Genymobile#183)
- Support holding Ctrl+Key shortcuts (Genymobile#166)
- Forward repeated volume events
- Increase "adb forward" connections attempts to 10 seconds (Genymobile#213)
- Add crop feature
  • Loading branch information
LeonardoManzella committed Aug 15, 2018
1 parent 4302912 commit 84f9467
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 58 deletions.
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# scrcpy (v1.2)
# scrcpy (v1.3)

This application provides display and control of Android devices connected on
USB (or [over TCP/IP][article-tcpip]). It does not require any _root_ access.
Expand Down Expand Up @@ -79,13 +79,13 @@ Two [AUR] packages have been created by users:
For Windows, for simplicity, prebuilt archives with all the dependencies
(including `adb`) are available:

- [`scrcpy-win32-v1.2.zip`][direct-win32].
_(SHA-256: a1fe1de67ec75dcf970ca5d97a04c26ff0f2d61871f2ef51b6f2f0bf666966b2)_
- [`scrcpy-win64-v1.2.zip`][direct-win64].
_(SHA-256: 35ae3bcee51771e7c51b8a8be87aef2295c9f267606a7cf83ebb0a4d583ef536)_
- [`scrcpy-win32-v1.3.zip`][direct-win32].
_(SHA-256: 51a2990e631ed469a7a86ff38107d517a91d313fb3f8327eb7bc71dde40870b5)_
- [`scrcpy-win64-v1.3.zip`][direct-win64].
_(SHA-256: 0768a80d3d600d0bbcd220ca150ae88a3a58d1fe85c308a8c61f44480b711e43)_

[direct-win32]: https://github.com/Genymobile/scrcpy/releases/download/v1.2/scrcpy-win32-v1.2.zip
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.2/scrcpy-win64-v1.2.zip
[direct-win32]: https://github.com/Genymobile/scrcpy/releases/download/v1.3/scrcpy-win32-v1.3.zip
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.3/scrcpy-win64-v1.3.zip

Instead, you may want to build it manually.

Expand Down Expand Up @@ -247,10 +247,10 @@ Since the server binary, that will be pushed to the Android device, does not
depend on your system and architecture, you may want to use the prebuilt binary
instead:

- [`scrcpy-server-v1.2.jar`][direct-scrcpy-server].
_(SHA-256: cb39654ed2fda3d30ddff292806950ccc5c394375ea12b974f790c7f38f61f60)_
- [`scrcpy-server-v1.3.jar`][direct-scrcpy-server].
_(SHA-256: 0f9a5a217f33f0ed7a1498ceb3c0cccf31c53533893aa952e674c1571d2740c1)_

[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.2/scrcpy-server-v1.2.jar
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.3/scrcpy-server-v1.3.jar

In that case, the build does not require Java or the Android SDK.

Expand Down Expand Up @@ -294,6 +294,12 @@ screen is smaller, or cannot decode such a high definition):
scrcpy -m 1024
```

The device screen may be cropped to mirror only part of the screen:

```bash
scrcpy -c 1224:1440:0:0 # 1224x1440 at offset (0,0)
```

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

```bash
Expand Down
2 changes: 1 addition & 1 deletion app/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ conf = configuration_data()
conf.set('BUILD_DEBUG', get_option('buildtype') == 'debug')

# the version, updated on release
conf.set_quoted('SCRCPY_VERSION', '1.2')
conf.set_quoted('SCRCPY_VERSION', '1.3')

# the prefix used during configuration (meson --prefix=PREFIX)
conf.set_quoted('PREFIX', get_option('prefix'))
Expand Down
3 changes: 0 additions & 3 deletions app/src/android/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,6 @@ enum android_input_source {
AINPUT_SOURCE_JOYSTICK = 0x01000000 | AINPUT_SOURCE_CLASS_JOYSTICK,
/** rotary encoder */
AINPUT_SOURCE_ROTARY_ENCODER = 0x00400000 | AINPUT_SOURCE_CLASS_NONE,

/** any */
AINPUT_SOURCE_ANY = 0xffffff00,
};

/**
Expand Down
2 changes: 1 addition & 1 deletion app/src/inputmanager.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void input_manager_process_mouse_button(struct input_manager *input_manager,
}
// otherwise, send the click event to the device
}
};
}
struct control_event control_event;
if (mouse_button_from_sdl_to_android(event, input_manager->screen->frame_size, &control_event)) {
if (!controller_push_event(input_manager->controller, &control_event)) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/installer.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ SDL_bool installer_init(struct installer *installer, const char *serial) {
installer->serial = SDL_strdup(serial);
if (!installer->serial) {
LOGW("Cannot strdup serial");
SDL_DestroyMutex(installer->mutex);
return SDL_FALSE;
}
} else {
Expand Down Expand Up @@ -117,6 +118,7 @@ static int run_installer(void *data) {

for (;;) {
mutex_lock(installer->mutex);
installer->current_process = PROCESS_NONE;
while (!installer->stopped && apk_queue_is_empty(&installer->queue)) {
cond_wait(installer->event_cond, installer->mutex);
}
Expand Down
17 changes: 16 additions & 1 deletion app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

struct args {
const char *serial;
const char *crop;
SDL_bool help;
SDL_bool version;
SDL_bool show_touches;
Expand All @@ -29,6 +30,12 @@ static void usage(const char *arg0) {
" Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
" Default is %d.\n"
"\n"
" -c, --crop width:height:x:y\n"
" Crop the device screen on the server.\n"
" The values are expressed in the device natural orientation\n"
" (typically, portrait for a phone, landscape for a tablet).\n"
" Any --max-size value is computed on the cropped size.\n"
"\n"
" -h, --help\n"
" Print this help.\n"
"\n"
Expand Down Expand Up @@ -192,6 +199,7 @@ static SDL_bool parse_port(char *optarg, Uint16 *port) {
static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
static const struct option long_options[] = {
{"bit-rate", required_argument, NULL, 'b'},
{"crop", required_argument, NULL, 'c'},
{"help", no_argument, NULL, 'h'},
{"max-size", required_argument, NULL, 'm'},
{"port", required_argument, NULL, 'p'},
Expand All @@ -201,13 +209,16 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
{NULL, 0, NULL, 0 },
};
int c;
while ((c = getopt_long(argc, argv, "b:hm:p:s:tv", long_options, NULL)) != -1) {
while ((c = getopt_long(argc, argv, "b:c:hm:p:s:tv", long_options, NULL)) != -1) {
switch (c) {
case 'b':
if (!parse_bit_rate(optarg, &args->bit_rate)) {
return SDL_FALSE;
}
break;
case 'c':
args->crop = optarg;
break;
case 'h':
args->help = SDL_TRUE;
break;
Expand Down Expand Up @@ -253,6 +264,7 @@ int main(int argc, char *argv[]) {
#endif
struct args args = {
.serial = NULL,
.crop = NULL,
.help = SDL_FALSE,
.version = SDL_FALSE,
.show_touches = SDL_FALSE,
Expand All @@ -274,7 +286,9 @@ int main(int argc, char *argv[]) {
return 0;
}

#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
av_register_all();
#endif

if (avformat_network_init()) {
return 1;
Expand All @@ -286,6 +300,7 @@ int main(int argc, char *argv[]) {

struct scrcpy_options options = {
.serial = args.serial,
.crop = args.crop,
.port = args.port,
.max_size = args.max_size,
.bit_rate = args.bit_rate,
Expand Down
13 changes: 7 additions & 6 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int event_watcher(void *data, SDL_Event *event) {
}
#endif

static void event_loop(void) {
static SDL_bool event_loop(void) {
#ifdef CONTINUOUS_RESIZING_WORKAROUND
SDL_AddEventWatch(event_watcher, NULL);
#endif
Expand All @@ -65,18 +65,18 @@ static void event_loop(void) {
switch (event.type) {
case EVENT_DECODER_STOPPED:
LOGD("Video decoder stopped");
return;
return SDL_FALSE;
case SDL_QUIT:
LOGD("User requested to quit");
return;
return SDL_TRUE;
case EVENT_NEW_FRAME:
if (!screen.has_frame) {
screen.has_frame = SDL_TRUE;
// this is the very first frame, show the window
screen_show_window(&screen);
}
if (!screen_update_frame(&screen, &frames)) {
return;
return SDL_FALSE;
}
break;
case SDL_WINDOWEVENT:
Expand Down Expand Up @@ -109,6 +109,7 @@ static void event_loop(void) {
break;
}
}
return SDL_FALSE;
}

static process_t set_show_touches_enabled(const char *serial, SDL_bool enabled) {
Expand All @@ -126,7 +127,7 @@ static void wait_show_touches(process_t process) {

SDL_bool scrcpy(const struct scrcpy_options *options) {
if (!server_start(&server, options->serial, options->port,
options->max_size, options->bit_rate)) {
options->max_size, options->bit_rate, options->crop)) {
return SDL_FALSE;
}

Expand Down Expand Up @@ -210,7 +211,7 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
show_touches_waited = SDL_TRUE;
}

event_loop();
ret = event_loop();
LOGD("quit...");

screen_destroy(&screen);
Expand Down
1 change: 1 addition & 0 deletions app/src/scrcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

struct scrcpy_options {
const char *serial;
const char *crop;
Uint16 port;
Uint16 max_size;
Uint32 bit_rate;
Expand Down
11 changes: 7 additions & 4 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ static SDL_bool disable_tunnel(struct server *server) {
}

static process_t execute_server(const char *serial,
Uint16 max_size, Uint32 bit_rate, SDL_bool tunnel_forward) {
Uint16 max_size, Uint32 bit_rate,
const char *crop, SDL_bool tunnel_forward) {
char max_size_string[6];
char bit_rate_string[11];
sprintf(max_size_string, "%"PRIu16, max_size);
Expand All @@ -91,6 +92,7 @@ static process_t execute_server(const char *serial,
max_size_string,
bit_rate_string,
tunnel_forward ? "true" : "false",
crop ? crop : "",
};
return adb_execute(serial, cmd, sizeof(cmd) / sizeof(cmd[0]));
}
Expand Down Expand Up @@ -147,7 +149,7 @@ void server_init(struct server *server) {
}

SDL_bool server_start(struct server *server, const char *serial, Uint16 local_port,
Uint16 max_size, Uint32 bit_rate) {
Uint16 max_size, Uint32 bit_rate, const char *crop) {
server->local_port = local_port;

if (serial) {
Expand Down Expand Up @@ -188,7 +190,8 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po
}

// server will connect to our server socket
server->process = execute_server(serial, max_size, bit_rate, server->tunnel_forward);
server->process = execute_server(serial, max_size, bit_rate, crop,
server->tunnel_forward);
if (server->process == PROCESS_NONE) {
if (!server->tunnel_forward) {
close_socket(&server->server_socket);
Expand All @@ -207,7 +210,7 @@ socket_t server_connect_to(struct server *server) {
if (!server->tunnel_forward) {
server->device_socket = net_accept(server->server_socket);
} else {
Uint32 attempts = 50;
Uint32 attempts = 100;
Uint32 delay = 100; // ms
server->device_socket = connect_to_server(server->local_port, attempts, delay);
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void server_init(struct server *server);

// push, enable tunnel et start the server
SDL_bool server_start(struct server *server, const char *serial, Uint16 local_port,
Uint16 max_size, Uint32 bit_rate);
Uint16 max_size, Uint32 bit_rate, const char *crop);

// block until the communication with the server is established
socket_t server_connect_to(struct server *server);
Expand Down
14 changes: 7 additions & 7 deletions app/src/tinyxpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ SDL_Surface *read_xpm(char *xpm[]) {
// *** No error handling, assume the XPM source is valid ***
// (it's in our source repo)
// Assertions are only checked in debug
Uint32 width = strtol(xpm[0], &endptr, 10);
Uint32 height = strtol(endptr + 1, &endptr, 10);
Uint32 colors = strtol(endptr + 1, &endptr, 10);
Uint32 chars = strtol(endptr + 1, &endptr, 10);
int width = strtol(xpm[0], &endptr, 10);
int height = strtol(endptr + 1, &endptr, 10);
int colors = strtol(endptr + 1, &endptr, 10);
int chars = strtol(endptr + 1, &endptr, 10);

// sanity checks
SDL_assert(width < 256);
SDL_assert(height < 256);
SDL_assert(colors < 256);
SDL_assert(0 <= width && width < 256);
SDL_assert(0 <= height && height < 256);
SDL_assert(0 <= colors && colors < 256);
SDL_assert(chars == 1); // this implementation does not support more

// init index
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('scrcpy', 'c', meson_version: '>= 0.37', default_options : 'c_std=c99')
project('scrcpy', 'c', meson_version: '>= 0.37', default_options : 'c_std=c11')

if get_option('build_app')
subdir('app')
Expand Down
4 changes: 2 additions & 2 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.genymobile.scrcpy"
minSdkVersion 21
targetSdkVersion 27
versionCode 3
versionName "1.2"
versionCode 4
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Loading

0 comments on commit 84f9467

Please sign in to comment.