Handle resized video stream
Accept a parameter to limit the video size. For instance, with "-m 960", the great side of the video will be scaled down to 960 (if necessary), while the other side will be scaled down so that the aspect ratio is preserved. Both dimensions must be a multiple of 8, so black bands might be added, and the mouse positions must be computed accordingly.
This commit is contained in:
@@ -9,15 +9,16 @@
|
||||
struct args {
|
||||
const char *serial;
|
||||
Uint16 port;
|
||||
Uint16 maximum_size;
|
||||
};
|
||||
|
||||
int parse_args(struct args *args, int argc, char *argv[]) {
|
||||
int c;
|
||||
while ((c = getopt(argc, argv, "p:")) != -1) {
|
||||
while ((c = getopt(argc, argv, "p:m:")) != -1) {
|
||||
switch (c) {
|
||||
case 'p': {
|
||||
char *endptr;
|
||||
long int value = strtol(optarg, &endptr, 0);
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*optarg == '\0' || *endptr != '\0') {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port: %s\n", optarg);
|
||||
return -1;
|
||||
@@ -29,6 +30,20 @@ int parse_args(struct args *args, int argc, char *argv[]) {
|
||||
args->port = (Uint16) value;
|
||||
break;
|
||||
}
|
||||
case 'm': {
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
if (value & ~0xffff) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Maximum size must be between 0 and 65535: %ld\n", value);
|
||||
return -1;
|
||||
}
|
||||
args->maximum_size = (Uint16) value;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// getopt prints the error message on stderr
|
||||
return -1;
|
||||
@@ -65,7 +80,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG);
|
||||
|
||||
res = scrcpy(args.serial, args.port) ? 0 : 1;
|
||||
res = scrcpy(args.serial, args.port, args.maximum_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) {
|
||||
SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 maximum_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) {
|
||||
}
|
||||
|
||||
// server will connect to our socket
|
||||
process_t server = start_server(serial);
|
||||
process_t server = start_server(serial, maximum_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);
|
||||
SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 maximum_size);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,13 +21,16 @@ process_t disable_tunnel(const char *serial) {
|
||||
return adb_reverse_remove(serial, SOCKET_NAME);
|
||||
}
|
||||
|
||||
process_t start_server(const char *serial) {
|
||||
process_t start_server(const char *serial, Uint16 maximum_size) {
|
||||
char maximum_size_string[6];
|
||||
sprintf(maximum_size_string, "%d", maximum_size);
|
||||
const char *const cmd[] = {
|
||||
"shell",
|
||||
"CLASSPATH=/data/local/tmp/scrcpy-server.jar",
|
||||
"app_process",
|
||||
"/system/bin",
|
||||
"com.genymobile.scrcpy.ScrCpyServer"
|
||||
"com.genymobile.scrcpy.ScrCpyServer",
|
||||
maximum_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);
|
||||
process_t start_server(const char *serial, Uint16 maximum_size);
|
||||
void stop_server(process_t server);
|
||||
|
||||
Reference in New Issue
Block a user