Skip to content

Commit

Permalink
Configure server verbosity from the client
Browse files Browse the repository at this point in the history
Send the requested log level from the client.

This paves the way to configure it via a command-line argument.
  • Loading branch information
rom1v committed May 24, 2020
1 parent 56bff2f commit 3df63c5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
5 changes: 5 additions & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ execute_server(struct server *server, const struct server_params *params) {
"/", // unused
"com.genymobile.scrcpy.Server",
SCRCPY_VERSION,
#ifndef NDEBUG
"debug",
#else
"info",
#endif
max_size_string,
bit_rate_string,
max_fps_string,
Expand Down
13 changes: 12 additions & 1 deletion server/src/main/java/com/genymobile/scrcpy/Ln.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,23 @@ enum Level {
DEBUG, INFO, WARN, ERROR
}

private static final Level THRESHOLD = BuildConfig.DEBUG ? Level.DEBUG : Level.INFO;
private static Level THRESHOLD;

private Ln() {
// not instantiable
}

/**
* Initialize the log level.
* <p>
* Must be called before starting any new thread.
*
* @param level the log level
*/
public static void initLogLevel(Level level) {
THRESHOLD = level;
}

public static boolean isEnabled(Level level) {
return level.ordinal() >= THRESHOLD.ordinal();
}
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 @@ -3,6 +3,7 @@
import android.graphics.Rect;

public class Options {
private Ln.Level logLevel;
private int maxSize;
private int bitRate;
private int maxFps;
Expand All @@ -16,6 +17,14 @@ public class Options {
private boolean stayAwake;
private String codecOptions;

public Ln.Level getLogLevel() {
return logLevel;
}

public void setLogLevel(Ln.Level logLevel) {
this.logLevel = logLevel;
}

public int getMaxSize() {
return maxSize;
}
Expand Down
32 changes: 19 additions & 13 deletions server/src/main/java/com/genymobile/scrcpy/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,48 +119,51 @@ private static Options createOptions(String... args) {
"The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")");
}

final int expectedParameters = 13;
final int expectedParameters = 14;
if (args.length != expectedParameters) {
throw new IllegalArgumentException("Expecting " + expectedParameters + " parameters");
}

Options options = new Options();

int maxSize = Integer.parseInt(args[1]) & ~7; // multiple of 8
Ln.Level level = Ln.Level.valueOf(args[1].toUpperCase());
options.setLogLevel(level);

int maxSize = Integer.parseInt(args[2]) & ~7; // multiple of 8
options.setMaxSize(maxSize);

int bitRate = Integer.parseInt(args[2]);
int bitRate = Integer.parseInt(args[3]);
options.setBitRate(bitRate);

int maxFps = Integer.parseInt(args[3]);
int maxFps = Integer.parseInt(args[4]);
options.setMaxFps(maxFps);

int lockedVideoOrientation = Integer.parseInt(args[4]);
int lockedVideoOrientation = Integer.parseInt(args[5]);
options.setLockedVideoOrientation(lockedVideoOrientation);

// use "adb forward" instead of "adb tunnel"? (so the server must listen)
boolean tunnelForward = Boolean.parseBoolean(args[5]);
boolean tunnelForward = Boolean.parseBoolean(args[6]);
options.setTunnelForward(tunnelForward);

Rect crop = parseCrop(args[6]);
Rect crop = parseCrop(args[7]);
options.setCrop(crop);

boolean sendFrameMeta = Boolean.parseBoolean(args[7]);
boolean sendFrameMeta = Boolean.parseBoolean(args[8]);
options.setSendFrameMeta(sendFrameMeta);

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

int displayId = Integer.parseInt(args[9]);
int displayId = Integer.parseInt(args[10]);
options.setDisplayId(displayId);

boolean showTouches = Boolean.parseBoolean(args[10]);
boolean showTouches = Boolean.parseBoolean(args[11]);
options.setShowTouches(showTouches);

boolean stayAwake = Boolean.parseBoolean(args[11]);
boolean stayAwake = Boolean.parseBoolean(args[12]);
options.setStayAwake(stayAwake);

String codecOptions = args[12];
String codecOptions = args[13];
options.setCodecOptions(codecOptions);

return options;
Expand Down Expand Up @@ -215,6 +218,9 @@ public void uncaughtException(Thread t, Throwable e) {
});

Options options = createOptions(args);

Ln.initLogLevel(options.getLogLevel());

scrcpy(options);
}
}

0 comments on commit 3df63c5

Please sign in to comment.