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.
This commit is contained in:
Romain Vimont 2019-06-04 21:31:46 +02:00
parent ca767ba364
commit acc4dcd520
5 changed files with 22 additions and 5 deletions

View file

@ -277,6 +277,7 @@ scrcpy(const struct scrcpy_options *options) {
.max_size = options->max_size, .max_size = options->max_size,
.bit_rate = options->bit_rate, .bit_rate = options->bit_rate,
.send_frame_meta = record, .send_frame_meta = record,
.control = options->control,
}; };
if (!server_start(&server, options->serial, &params)) { if (!server_start(&server, options->serial, &params)) {
return false; return false;

View file

@ -95,6 +95,7 @@ execute_server(struct server *server, const struct server_params *params) {
server->tunnel_forward ? "true" : "false", server->tunnel_forward ? "true" : "false",
params->crop ? params->crop : "-", params->crop ? params->crop : "-",
params->send_frame_meta ? "true" : "false", params->send_frame_meta ? "true" : "false",
params->control ? "true" : "false",
}; };
return adb_execute(server->serial, cmd, sizeof(cmd) / sizeof(cmd[0])); return adb_execute(server->serial, cmd, sizeof(cmd) / sizeof(cmd[0]));
} }

View file

@ -35,6 +35,7 @@ struct server_params {
uint16_t max_size; uint16_t max_size;
uint32_t bit_rate; uint32_t bit_rate;
bool send_frame_meta; bool send_frame_meta;
bool control;
}; };
// init default values // init default values

View file

@ -8,6 +8,7 @@ public class Options {
private boolean tunnelForward; private boolean tunnelForward;
private Rect crop; private Rect crop;
private boolean sendFrameMeta; // send PTS so that the client may record properly private boolean sendFrameMeta; // send PTS so that the client may record properly
private boolean control;
public int getMaxSize() { public int getMaxSize() {
return maxSize; return maxSize;
@ -48,4 +49,12 @@ public class Options {
public void setSendFrameMeta(boolean sendFrameMeta) { public void setSendFrameMeta(boolean sendFrameMeta) {
this.sendFrameMeta = sendFrameMeta; this.sendFrameMeta = sendFrameMeta;
} }
public boolean getControl() {
return control;
}
public void setControl(boolean control) {
this.control = control;
}
} }

View file

@ -19,11 +19,13 @@ public final class Server {
try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward)) { try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward)) {
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate()); ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate());
Controller controller = new Controller(device, connection); if (options.getControl()) {
Controller controller = new Controller(device, connection);
// asynchronous // asynchronous
startController(controller); startController(controller);
startDeviceMessageSender(controller.getSender()); startDeviceMessageSender(controller.getSender());
}
try { try {
// synchronous // synchronous
@ -65,7 +67,7 @@ public final class Server {
@SuppressWarnings("checkstyle:MagicNumber") @SuppressWarnings("checkstyle:MagicNumber")
private static Options createOptions(String... args) { private static Options createOptions(String... args) {
if (args.length != 5) { if (args.length != 6) {
throw new IllegalArgumentException("Expecting 5 parameters"); throw new IllegalArgumentException("Expecting 5 parameters");
} }
@ -87,6 +89,9 @@ public final class Server {
boolean sendFrameMeta = Boolean.parseBoolean(args[4]); boolean sendFrameMeta = Boolean.parseBoolean(args[4]);
options.setSendFrameMeta(sendFrameMeta); options.setSendFrameMeta(sendFrameMeta);
boolean control = Boolean.parseBoolean(args[5]);
options.setControl(control);
return options; return options;
} }