Skip to content

Commit

Permalink
Disable server controller if --no-control
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rom1v committed Jun 4, 2019
1 parent ca767ba commit acc4dcd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params)) {
return false;
Expand Down
1 change: 1 addition & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
Expand Down
1 change: 1 addition & 0 deletions app/src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct server_params {
uint16_t max_size;
uint32_t bit_rate;
bool send_frame_meta;
bool control;
};

// init default values
Expand Down
9 changes: 9 additions & 0 deletions server/src/main/java/com/genymobile/scrcpy/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,4 +49,12 @@ public boolean getSendFrameMeta() {
public void setSendFrameMeta(boolean sendFrameMeta) {
this.sendFrameMeta = sendFrameMeta;
}

public boolean getControl() {
return control;
}

public void setControl(boolean control) {
this.control = control;
}
}
15 changes: 10 additions & 5 deletions server/src/main/java/com/genymobile/scrcpy/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ private static void scrcpy(Options options) throws IOException {
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
Expand Down Expand Up @@ -65,7 +67,7 @@ public void run() {

@SuppressWarnings("checkstyle:MagicNumber")
private static Options createOptions(String... args) {
if (args.length != 5) {
if (args.length != 6) {
throw new IllegalArgumentException("Expecting 5 parameters");
}

Expand All @@ -87,6 +89,9 @@ private static Options createOptions(String... args) {
boolean sendFrameMeta = Boolean.parseBoolean(args[4]);
options.setSendFrameMeta(sendFrameMeta);

boolean control = Boolean.parseBoolean(args[5]);
options.setControl(control);

return options;
}

Expand Down

0 comments on commit acc4dcd

Please sign in to comment.