From acc4dcd520f960a3e5d8fb431ceb0cbc3e7825e4 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 4 Jun 2019 21:31:46 +0200 Subject: [PATCH] Disable server controller if --no-control If --no-control is disabled, there is no need for a controller. It also avoids to power on the device on start if control is disabled. --- app/src/scrcpy.c | 1 + app/src/server.c | 1 + app/src/server.h | 1 + .../main/java/com/genymobile/scrcpy/Options.java | 9 +++++++++ .../main/java/com/genymobile/scrcpy/Server.java | 15 ++++++++++----- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index c7b78fee..e85577a4 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -277,6 +277,7 @@ scrcpy(const struct scrcpy_options *options) { .max_size = options->max_size, .bit_rate = options->bit_rate, .send_frame_meta = record, + .control = options->control, }; if (!server_start(&server, options->serial, ¶ms)) { return false; diff --git a/app/src/server.c b/app/src/server.c index 5b586b93..6c12ba99 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -95,6 +95,7 @@ execute_server(struct server *server, const struct server_params *params) { server->tunnel_forward ? "true" : "false", params->crop ? params->crop : "-", params->send_frame_meta ? "true" : "false", + params->control ? "true" : "false", }; return adb_execute(server->serial, cmd, sizeof(cmd) / sizeof(cmd[0])); } diff --git a/app/src/server.h b/app/src/server.h index de0d14b8..74a6cac8 100644 --- a/app/src/server.h +++ b/app/src/server.h @@ -35,6 +35,7 @@ struct server_params { uint16_t max_size; uint32_t bit_rate; bool send_frame_meta; + bool control; }; // init default values diff --git a/server/src/main/java/com/genymobile/scrcpy/Options.java b/server/src/main/java/com/genymobile/scrcpy/Options.java index 851c7ed6..af6b2ee1 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Options.java +++ b/server/src/main/java/com/genymobile/scrcpy/Options.java @@ -8,6 +8,7 @@ public class Options { private boolean tunnelForward; private Rect crop; private boolean sendFrameMeta; // send PTS so that the client may record properly + private boolean control; public int getMaxSize() { return maxSize; @@ -48,4 +49,12 @@ public class Options { public void setSendFrameMeta(boolean sendFrameMeta) { this.sendFrameMeta = sendFrameMeta; } + + public boolean getControl() { + return control; + } + + public void setControl(boolean control) { + this.control = control; + } } diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index 76028fbe..1e4d10d6 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -19,11 +19,13 @@ public final class Server { try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward)) { ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate()); - Controller controller = new Controller(device, connection); + if (options.getControl()) { + Controller controller = new Controller(device, connection); - // asynchronous - startController(controller); - startDeviceMessageSender(controller.getSender()); + // asynchronous + startController(controller); + startDeviceMessageSender(controller.getSender()); + } try { // synchronous @@ -65,7 +67,7 @@ public final class Server { @SuppressWarnings("checkstyle:MagicNumber") private static Options createOptions(String... args) { - if (args.length != 5) { + if (args.length != 6) { throw new IllegalArgumentException("Expecting 5 parameters"); } @@ -87,6 +89,9 @@ public final class Server { boolean sendFrameMeta = Boolean.parseBoolean(args[4]); options.setSendFrameMeta(sendFrameMeta); + boolean control = Boolean.parseBoolean(args[5]); + options.setControl(control); + return options; }