2018-01-22 18:22:31 +08:00
|
|
|
#include "command.h"
|
|
|
|
|
|
|
|
#include <SDL2/SDL_log.h>
|
|
|
|
#include <errno.h>
|
2018-02-01 23:36:50 +08:00
|
|
|
#include <stdint.h>
|
2018-01-22 18:22:31 +08:00
|
|
|
|
2018-01-23 22:46:34 +08:00
|
|
|
#define SOCKET_NAME "scrcpy"
|
|
|
|
|
|
|
|
process_t push_server(const char *serial) {
|
2018-02-02 16:31:44 +08:00
|
|
|
const char *server_path = getenv("SCRCPY_SERVER_JAR");
|
|
|
|
if (!server_path) {
|
|
|
|
server_path = "scrcpy-server.jar";
|
2018-01-23 22:46:34 +08:00
|
|
|
}
|
2018-02-02 16:31:44 +08:00
|
|
|
return adb_push(serial, server_path, "/data/local/tmp/scrcpy-server.jar");
|
2018-01-23 22:46:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
process_t enable_tunnel(const char *serial, Uint16 local_port) {
|
|
|
|
return adb_reverse(serial, SOCKET_NAME, local_port);
|
|
|
|
}
|
|
|
|
|
|
|
|
process_t disable_tunnel(const char *serial) {
|
|
|
|
return adb_reverse_remove(serial, SOCKET_NAME);
|
|
|
|
}
|
|
|
|
|
2018-02-01 23:36:50 +08:00
|
|
|
process_t start_server(const char *serial, Uint16 max_size, Uint32 bit_rate) {
|
2018-02-01 19:18:06 +08:00
|
|
|
char max_size_string[6];
|
2018-02-01 23:36:50 +08:00
|
|
|
char bit_rate_string[11];
|
|
|
|
sprintf(max_size_string, "%"PRIu16, max_size);
|
|
|
|
sprintf(bit_rate_string, "%"PRIu32, bit_rate);
|
2018-01-22 18:22:31 +08:00
|
|
|
const char *const cmd[] = {
|
|
|
|
"shell",
|
2018-02-02 16:31:44 +08:00
|
|
|
"CLASSPATH=/data/local/tmp/scrcpy-server.jar",
|
2018-01-22 18:22:31 +08:00
|
|
|
"app_process",
|
2018-01-30 00:06:44 +08:00
|
|
|
"/", // unused
|
2018-01-29 22:40:33 +08:00
|
|
|
"com.genymobile.scrcpy.ScrCpyServer",
|
2018-02-01 19:18:06 +08:00
|
|
|
max_size_string,
|
2018-02-01 23:36:50 +08:00
|
|
|
bit_rate_string,
|
2018-01-22 18:22:31 +08:00
|
|
|
};
|
|
|
|
return adb_execute(serial, cmd, sizeof(cmd) / sizeof(cmd[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
void stop_server(process_t server) {
|
|
|
|
if (!cmd_terminate(server)) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Could not terminate server: %s", strerror(errno));
|
|
|
|
}
|
|
|
|
}
|