Rename maximum_size to max_size
The long option is --max-size, so for consistency, adapt the code accordingly.
This commit is contained in:
parent
213b721ff9
commit
ee93f3f23a
8 changed files with 30 additions and 28 deletions
|
@ -6,11 +6,12 @@
|
|||
#include <SDL2/SDL.h>
|
||||
|
||||
#define DEFAULT_LOCAL_PORT 27183
|
||||
#define DEFAULT_MAX_SIZE 0
|
||||
|
||||
struct args {
|
||||
const char *serial;
|
||||
Uint16 port;
|
||||
Uint16 maximum_size;
|
||||
Uint16 max_size;
|
||||
};
|
||||
|
||||
static int parse_args(struct args *args, int argc, char *argv[]) {
|
||||
|
@ -40,14 +41,14 @@ static int parse_args(struct args *args, int argc, char *argv[]) {
|
|||
char *endptr;
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*optarg == '\0' || *endptr != '\0') {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid maximum size: %s\n", optarg);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid max size: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
if (value & ~0xffff) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Maximum size must be between 0 and 65535: %ld\n", value);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Max size must be between 0 and 65535: %ld\n", value);
|
||||
return -1;
|
||||
}
|
||||
args->maximum_size = (Uint16) value;
|
||||
args->max_size = (Uint16) value;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -72,6 +73,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
struct args args = {
|
||||
.serial = NULL,
|
||||
.max_size = DEFAULT_MAX_SIZE,
|
||||
.port = DEFAULT_LOCAL_PORT,
|
||||
};
|
||||
if (parse_args(&args, argc, argv)) {
|
||||
|
@ -86,7 +88,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG);
|
||||
|
||||
res = scrcpy(args.serial, args.port, args.maximum_size) ? 0 : 1;
|
||||
res = scrcpy(args.serial, args.port, args.max_size) ? 0 : 1;
|
||||
|
||||
avformat_network_deinit(); // ignore failure
|
||||
|
||||
|
|
|
@ -382,7 +382,7 @@ void event_loop(void) {
|
|||
}
|
||||
}
|
||||
|
||||
SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 maximum_size) {
|
||||
SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size) {
|
||||
SDL_bool ret = 0;
|
||||
|
||||
process_t push_proc = push_server(serial);
|
||||
|
@ -402,7 +402,7 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 maximum_size) {
|
|||
}
|
||||
|
||||
// server will connect to our socket
|
||||
process_t server = start_server(serial, maximum_size);
|
||||
process_t server = start_server(serial, max_size);
|
||||
if (server == PROCESS_NONE) {
|
||||
ret = SDL_FALSE;
|
||||
SDLNet_TCP_Close(server_socket);
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
|
||||
SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 maximum_size);
|
||||
SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,16 +21,16 @@ process_t disable_tunnel(const char *serial) {
|
|||
return adb_reverse_remove(serial, SOCKET_NAME);
|
||||
}
|
||||
|
||||
process_t start_server(const char *serial, Uint16 maximum_size) {
|
||||
char maximum_size_string[6];
|
||||
sprintf(maximum_size_string, "%d", maximum_size);
|
||||
process_t start_server(const char *serial, Uint16 max_size) {
|
||||
char max_size_string[6];
|
||||
sprintf(max_size_string, "%d", max_size);
|
||||
const char *const cmd[] = {
|
||||
"shell",
|
||||
"CLASSPATH=/data/local/tmp/scrcpy.apk",
|
||||
"app_process",
|
||||
"/", // unused
|
||||
"com.genymobile.scrcpy.ScrCpyServer",
|
||||
maximum_size_string,
|
||||
max_size_string,
|
||||
};
|
||||
return adb_execute(serial, cmd, sizeof(cmd) / sizeof(cmd[0]));
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@ process_t push_server(const char *serial);
|
|||
process_t enable_tunnel(const char *serial, Uint16 local_port);
|
||||
process_t disable_tunnel(const char *serial);
|
||||
|
||||
process_t start_server(const char *serial, Uint16 maximum_size);
|
||||
process_t start_server(const char *serial, Uint16 max_size);
|
||||
void stop_server(process_t server);
|
||||
|
|
|
@ -20,7 +20,7 @@ public final class Device {
|
|||
private RotationListener rotationListener;
|
||||
|
||||
public Device(Options options) {
|
||||
screenInfo = computeScreenInfo(options.getMaximumSize());
|
||||
screenInfo = computeScreenInfo(options.getMaxSize());
|
||||
registerRotationWatcher(new IRotationWatcher.Stub() {
|
||||
@Override
|
||||
public void onRotationChanged(int rotation) throws RemoteException {
|
||||
|
@ -40,10 +40,10 @@ public final class Device {
|
|||
return screenInfo;
|
||||
}
|
||||
|
||||
private ScreenInfo computeScreenInfo(int maximumSize) {
|
||||
private ScreenInfo computeScreenInfo(int maxSize) {
|
||||
// Compute the video size and the padding of the content inside this video.
|
||||
// Principle:
|
||||
// - scale down the great side of the screen to maximumSize (if necessary);
|
||||
// - scale down the great side of the screen to maxSize (if necessary);
|
||||
// - scale down the other side so that the aspect ratio is preserved;
|
||||
// - round this value to the nearest multiple of 8 (H.264 only accepts multiples of 8)
|
||||
DisplayInfo displayInfo = serviceManager.getDisplayManager().getDisplayInfo();
|
||||
|
@ -51,16 +51,16 @@ public final class Device {
|
|||
Size deviceSize = displayInfo.getSize();
|
||||
int w = deviceSize.getWidth();
|
||||
int h = deviceSize.getHeight();
|
||||
if (maximumSize > 0) {
|
||||
assert maximumSize % 8 == 0;
|
||||
if (maxSize > 0) {
|
||||
assert maxSize % 8 == 0;
|
||||
boolean portrait = h > w;
|
||||
int major = portrait ? h : w;
|
||||
int minor = portrait ? w : h;
|
||||
if (major > maximumSize) {
|
||||
int minorExact = minor * maximumSize / major;
|
||||
if (major > maxSize) {
|
||||
int minorExact = minor * maxSize / major;
|
||||
// +4 to round the value to the nearest multiple of 8
|
||||
minor = (minorExact + 4) & ~7;
|
||||
major = maximumSize;
|
||||
major = maxSize;
|
||||
}
|
||||
w = portrait ? minor : major;
|
||||
h = portrait ? major : minor;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package com.genymobile.scrcpy;
|
||||
|
||||
public class Options {
|
||||
private int maximumSize;
|
||||
private int maxSize;
|
||||
|
||||
public int getMaximumSize() {
|
||||
return maximumSize;
|
||||
public int getMaxSize() {
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
public void setMaximumSize(int maximumSize) {
|
||||
this.maximumSize = maximumSize;
|
||||
public void setMaxSize(int maxSize) {
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ public class ScrCpyServer {
|
|||
private static Options createOptions(String... args) {
|
||||
Options options = new Options();
|
||||
if (args.length > 0) {
|
||||
int maximumSize = Integer.parseInt(args[0]) & ~7; // multiple of 8
|
||||
options.setMaximumSize(maximumSize);
|
||||
int maxSize = Integer.parseInt(args[0]) & ~7; // multiple of 8
|
||||
options.setMaxSize(maxSize);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue