Add crop feature
Add an option to crop the screen on the server. This allows to mirror only part of the device screen.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
struct args {
|
||||
const char *serial;
|
||||
const char *crop;
|
||||
SDL_bool help;
|
||||
SDL_bool version;
|
||||
SDL_bool show_touches;
|
||||
@@ -29,6 +30,12 @@ static void usage(const char *arg0) {
|
||||
" Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
|
||||
" Default is %d.\n"
|
||||
"\n"
|
||||
" -c, --crop width:height:x:y\n"
|
||||
" Crop the device screen on the server.\n"
|
||||
" The values are expressed in the device natural orientation\n"
|
||||
" (typically, portrait for a phone, landscape for a tablet).\n"
|
||||
" Any --max-size value is computed on the cropped size.\n"
|
||||
"\n"
|
||||
" -h, --help\n"
|
||||
" Print this help.\n"
|
||||
"\n"
|
||||
@@ -192,6 +199,7 @@ static SDL_bool parse_port(char *optarg, Uint16 *port) {
|
||||
static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
|
||||
static const struct option long_options[] = {
|
||||
{"bit-rate", required_argument, NULL, 'b'},
|
||||
{"crop", required_argument, NULL, 'c'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"max-size", required_argument, NULL, 'm'},
|
||||
{"port", required_argument, NULL, 'p'},
|
||||
@@ -201,13 +209,16 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
|
||||
{NULL, 0, NULL, 0 },
|
||||
};
|
||||
int c;
|
||||
while ((c = getopt_long(argc, argv, "b:hm:p:s:tv", long_options, NULL)) != -1) {
|
||||
while ((c = getopt_long(argc, argv, "b:c:hm:p:s:tv", long_options, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'b':
|
||||
if (!parse_bit_rate(optarg, &args->bit_rate)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
args->crop = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
args->help = SDL_TRUE;
|
||||
break;
|
||||
@@ -253,6 +264,7 @@ int main(int argc, char *argv[]) {
|
||||
#endif
|
||||
struct args args = {
|
||||
.serial = NULL,
|
||||
.crop = NULL,
|
||||
.help = SDL_FALSE,
|
||||
.version = SDL_FALSE,
|
||||
.show_touches = SDL_FALSE,
|
||||
@@ -288,6 +300,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
struct scrcpy_options options = {
|
||||
.serial = args.serial,
|
||||
.crop = args.crop,
|
||||
.port = args.port,
|
||||
.max_size = args.max_size,
|
||||
.bit_rate = args.bit_rate,
|
||||
|
||||
@@ -126,7 +126,7 @@ static void wait_show_touches(process_t process) {
|
||||
|
||||
SDL_bool scrcpy(const struct scrcpy_options *options) {
|
||||
if (!server_start(&server, options->serial, options->port,
|
||||
options->max_size, options->bit_rate)) {
|
||||
options->max_size, options->bit_rate, options->crop)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
struct scrcpy_options {
|
||||
const char *serial;
|
||||
const char *crop;
|
||||
Uint16 port;
|
||||
Uint16 max_size;
|
||||
Uint32 bit_rate;
|
||||
|
||||
@@ -77,7 +77,8 @@ static SDL_bool disable_tunnel(struct server *server) {
|
||||
}
|
||||
|
||||
static process_t execute_server(const char *serial,
|
||||
Uint16 max_size, Uint32 bit_rate, SDL_bool tunnel_forward) {
|
||||
Uint16 max_size, Uint32 bit_rate,
|
||||
const char *crop, SDL_bool tunnel_forward) {
|
||||
char max_size_string[6];
|
||||
char bit_rate_string[11];
|
||||
sprintf(max_size_string, "%"PRIu16, max_size);
|
||||
@@ -91,6 +92,7 @@ static process_t execute_server(const char *serial,
|
||||
max_size_string,
|
||||
bit_rate_string,
|
||||
tunnel_forward ? "true" : "false",
|
||||
crop ? crop : "",
|
||||
};
|
||||
return adb_execute(serial, cmd, sizeof(cmd) / sizeof(cmd[0]));
|
||||
}
|
||||
@@ -147,7 +149,7 @@ void server_init(struct server *server) {
|
||||
}
|
||||
|
||||
SDL_bool server_start(struct server *server, const char *serial, Uint16 local_port,
|
||||
Uint16 max_size, Uint32 bit_rate) {
|
||||
Uint16 max_size, Uint32 bit_rate, const char *crop) {
|
||||
server->local_port = local_port;
|
||||
|
||||
if (serial) {
|
||||
@@ -188,7 +190,8 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po
|
||||
}
|
||||
|
||||
// server will connect to our server socket
|
||||
server->process = execute_server(serial, max_size, bit_rate, server->tunnel_forward);
|
||||
server->process = execute_server(serial, max_size, bit_rate, crop,
|
||||
server->tunnel_forward);
|
||||
if (server->process == PROCESS_NONE) {
|
||||
if (!server->tunnel_forward) {
|
||||
close_socket(&server->server_socket);
|
||||
|
||||
@@ -31,7 +31,7 @@ void server_init(struct server *server);
|
||||
|
||||
// push, enable tunnel et start the server
|
||||
SDL_bool server_start(struct server *server, const char *serial, Uint16 local_port,
|
||||
Uint16 max_size, Uint32 bit_rate);
|
||||
Uint16 max_size, Uint32 bit_rate, const char *crop);
|
||||
|
||||
// block until the communication with the server is established
|
||||
socket_t server_connect_to(struct server *server);
|
||||
|
||||
Reference in New Issue
Block a user