Compare commits

...

13 Commits

Author SHA1 Message Date
Avinash Sonawane
4078ccb882 Replace raw number by its name
PR #4373 <https://github.com/Genymobile/scrcpy/pull/4373>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-10-25 09:26:17 +02:00
Avinash Sonawane
0ab96c4ca6 Replace sprintf() with asprintf()
Pre-computing the maximum target size is too fragile, the
micro-optimization does not worth it.

PR #4373 <https://github.com/Genymobile/scrcpy/pull/4373>

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-10-25 09:22:01 +02:00
Avinash Sonawane
bc8913e12b Use char * for pointer arithmetic
PR #4374 <https://github.com/Genymobile/scrcpy/pull/4374>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-10-24 23:12:36 +02:00
Romain Vimont
3c2013de10 Enable missing-prototypes warning
Warn if a global function is defined without a previous prototype
declaration. It is not enabled by default at warning_level=2.
2023-10-24 23:06:57 +02:00
Avinash Sonawane
8cef8bac94 Declare local functions as static
PR #4374 <https://github.com/Genymobile/scrcpy/pull/4374>

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-10-24 23:06:57 +02:00
Avinash Sonawane
0bbe8a7007 Wrap macros in do-while(0)
To fix the warnings of stray `;`.

PR #4374 <https://github.com/Genymobile/scrcpy/pull/4374>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-10-24 22:58:33 +02:00
Romain Vimont
9fdb882509 Fix --pause-on-exit parsing
The function incorrectly returned `false` instead of a valid (and
expected) enum value.
2023-10-24 22:53:41 +02:00
Romain Vimont
8e7b041f35 Add missing voids for empty parameter list 2023-10-23 21:50:40 +02:00
Avinash Sonawane
9ade389069 Make sc_usb_devices_destroy() static
It is only called from the implementation file.

PR #4371 <https://github.com/Genymobile/scrcpy/pull/4371>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-10-23 15:39:19 +02:00
Avinash Sonawane
90ba885547 Remove redundant ;
PR #4371 <https://github.com/Genymobile/scrcpy/pull/4371>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-10-23 15:09:26 +02:00
Avinash Sonawane
7adf98e9d4 Use void for empty function parameter list
PR #4371 <https://github.com/Genymobile/scrcpy/pull/4371>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-10-23 15:07:24 +02:00
Romain Vimont
1c864a88eb Use --pause-on-exit from launchers
The terminal opened by scrcpy-console (.bat or .desktop) must not close
if scrcpy terminates with an error, so that error messages can be read.

Refs #3817 <https://github.com/Genymobile/scrcpy/pull/3817>
Refs #3822 <https://github.com/Genymobile/scrcpy/pull/3822>
PR #4130 <https://github.com/Genymobile/scrcpy/pull/4130>
2023-10-11 09:43:44 +02:00
Romain Vimont
1650b7c058 Add --pause-on-exit
Add an option to make scrcpy pause on exit.

Three behaviors are possible:
 - always pause on exit:
    --pause-on-exit
    --pause-on-exit=true
 - never pause on exit:
    (no option)
    --pause-on-exit=false
 - pause when scrcpy returns with an error (a non-zero exit code):
    --pause-on-exit=if-error

This is useful to prevent the terminal window from automatically
closing, so that error messages can be read.

Refs #3817 <https://github.com/Genymobile/scrcpy/pull/3817>
Refs #3822 <https://github.com/Genymobile/scrcpy/pull/3822>
PR #4130 <https://github.com/Genymobile/scrcpy/pull/4130>
2023-10-11 09:43:44 +02:00
23 changed files with 202 additions and 49 deletions

View File

@@ -44,6 +44,8 @@ _scrcpy() {
--no-video-playback --no-video-playback
--otg --otg
-p --port= -p --port=
--pause-on-exit
--pause-on-exit=
--power-off-on-close --power-off-on-close
--prefer-text --prefer-text
--print-fps --print-fps
@@ -97,6 +99,10 @@ _scrcpy() {
COMPREPLY=($(compgen -W 'unlocked initial 0 1 2 3' -- "$cur")) COMPREPLY=($(compgen -W 'unlocked initial 0 1 2 3' -- "$cur"))
return return
;; ;;
--pause-on-exit)
COMPREPLY=($(compgen -W 'true false if-error' -- "$cur"))
return
;;
-r|--record) -r|--record)
COMPREPLY=($(compgen -f -- "$cur")) COMPREPLY=($(compgen -f -- "$cur"))
return return

View File

@@ -1,4 +1,2 @@
@echo off @echo off
scrcpy.exe %* scrcpy.exe --pause-on-exit=if-error %*
:: if the exit code is >= 1, then pause
if errorlevel 1 pause

View File

@@ -5,7 +5,7 @@ Comment=Display and control your Android device
# For some users, the PATH or ADB environment variables are set from the shell # For some users, the PATH or ADB environment variables are set from the shell
# startup file, like .bashrc or .zshrc… Run an interactive shell to get # startup file, like .bashrc or .zshrc… Run an interactive shell to get
# environment correctly initialized. # environment correctly initialized.
Exec=/bin/bash --norc --noprofile -i -c "\"\\$SHELL\" -i -c scrcpy || read -p 'Press Enter to quit...'" Exec=/bin/sh -c "\"\\$SHELL\" -i -c scrcpy --pause-on-exit=if-error"
Icon=scrcpy Icon=scrcpy
Terminal=true Terminal=true
Type=Application Type=Application

View File

@@ -50,6 +50,7 @@ arguments=(
'--no-video-playback[Disable video playback]' '--no-video-playback[Disable video playback]'
'--otg[Run in OTG mode \(simulating physical keyboard and mouse\)]' '--otg[Run in OTG mode \(simulating physical keyboard and mouse\)]'
{-p,--port=}'[\[port\[\:port\]\] Set the TCP port \(range\) used by the client to listen]' {-p,--port=}'[\[port\[\:port\]\] Set the TCP port \(range\) used by the client to listen]'
'--pause-on-exit=[Make scrcpy pause before exiting]:mode:(true false if-error)'
'--power-off-on-close[Turn the device screen off when closing scrcpy]' '--power-off-on-close[Turn the device screen off when closing scrcpy]'
'--prefer-text[Inject alpha characters and space as text events instead of key events]' '--prefer-text[Inject alpha characters and space as text events instead of key events]'
'--print-fps[Start FPS counter, to print frame logs to the console]' '--print-fps[Start FPS counter, to print frame logs to the console]'

View File

@@ -267,6 +267,16 @@ Set the TCP port (range) used by the client to listen.
Default is 27183:27199. Default is 27183:27199.
.TP
\fB\-\-pause\-on\-exit\fR[=\fImode\fR]
Configure pause on exit. Possible values are "true" (always pause on exit), "false" (never pause on exit) and "if-error" (pause only if an error occured).
This is useful to prevent the terminal window from automatically closing, so that error messages can be read.
Default is "false".
Passing the option without argument is equivalent to passing "true".
.TP .TP
.B \-\-power\-off\-on\-close .B \-\-power\-off\-on\-close
Turn the device screen off when closing scrcpy. Turn the device screen off when closing scrcpy.

View File

@@ -70,7 +70,7 @@ argv_to_string(const char *const *argv, char *buf, size_t bufsize) {
} }
static void static void
show_adb_installation_msg() { show_adb_installation_msg(void) {
#ifndef __WINDOWS__ #ifndef __WINDOWS__
static const struct { static const struct {
const char *binary; const char *binary;
@@ -216,30 +216,44 @@ sc_adb_kill_server(struct sc_intr *intr, unsigned flags) {
bool bool
sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port, sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
const char *device_socket_name, unsigned flags) { const char *device_socket_name, unsigned flags) {
char local[4 + 5 + 1]; // tcp:PORT char *local;
char remote[108 + 14 + 1]; // localabstract:NAME if (asprintf(&local, "tcp:%" PRIu16, local_port) == -1) {
sprintf(local, "tcp:%" PRIu16, local_port); LOG_OOM();
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name); return false;
}
char *remote;
if (asprintf(&remote, "localabstract:%s", device_socket_name) == -1) {
LOG_OOM();
free(local);
return false;
}
assert(serial); assert(serial);
const char *const argv[] = const char *const argv[] =
SC_ADB_COMMAND("-s", serial, "forward", local, remote); SC_ADB_COMMAND("-s", serial, "forward", local, remote);
sc_pid pid = sc_adb_execute(argv, flags); sc_pid pid = sc_adb_execute(argv, flags);
free(remote);
free(local);
return process_check_success_intr(intr, pid, "adb forward", flags); return process_check_success_intr(intr, pid, "adb forward", flags);
} }
bool bool
sc_adb_forward_remove(struct sc_intr *intr, const char *serial, sc_adb_forward_remove(struct sc_intr *intr, const char *serial,
uint16_t local_port, unsigned flags) { uint16_t local_port, unsigned flags) {
char local[4 + 5 + 1]; // tcp:PORT char *local;
sprintf(local, "tcp:%" PRIu16, local_port); if (asprintf(&local, "tcp:%" PRIu16, local_port) == -1) {
LOG_OOM();
return false;
}
assert(serial); assert(serial);
const char *const argv[] = const char *const argv[] =
SC_ADB_COMMAND("-s", serial, "forward", "--remove", local); SC_ADB_COMMAND("-s", serial, "forward", "--remove", local);
sc_pid pid = sc_adb_execute(argv, flags); sc_pid pid = sc_adb_execute(argv, flags);
free(local);
return process_check_success_intr(intr, pid, "adb forward --remove", flags); return process_check_success_intr(intr, pid, "adb forward --remove", flags);
} }
@@ -247,29 +261,45 @@ bool
sc_adb_reverse(struct sc_intr *intr, const char *serial, sc_adb_reverse(struct sc_intr *intr, const char *serial,
const char *device_socket_name, uint16_t local_port, const char *device_socket_name, uint16_t local_port,
unsigned flags) { unsigned flags) {
char local[4 + 5 + 1]; // tcp:PORT
char remote[108 + 14 + 1]; // localabstract:NAME
sprintf(local, "tcp:%" PRIu16, local_port);
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name);
assert(serial); assert(serial);
char *local;
if (asprintf(&local, "tcp:%" PRIu16, local_port) == -1) {
LOG_OOM();
return false;
}
char *remote;
if (asprintf(&remote, "localabstract:%s", device_socket_name) == -1) {
LOG_OOM();
free(local);
return false;
}
const char *const argv[] = const char *const argv[] =
SC_ADB_COMMAND("-s", serial, "reverse", remote, local); SC_ADB_COMMAND("-s", serial, "reverse", remote, local);
sc_pid pid = sc_adb_execute(argv, flags); sc_pid pid = sc_adb_execute(argv, flags);
free(remote);
free(local);
return process_check_success_intr(intr, pid, "adb reverse", flags); return process_check_success_intr(intr, pid, "adb reverse", flags);
} }
bool bool
sc_adb_reverse_remove(struct sc_intr *intr, const char *serial, sc_adb_reverse_remove(struct sc_intr *intr, const char *serial,
const char *device_socket_name, unsigned flags) { const char *device_socket_name, unsigned flags) {
char remote[108 + 14 + 1]; // localabstract:NAME char *remote;
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name); if (asprintf(&remote, "localabstract:%s", device_socket_name) == -1) {
LOG_OOM();
return false;
}
assert(serial); assert(serial);
const char *const argv[] = const char *const argv[] =
SC_ADB_COMMAND("-s", serial, "reverse", "--remove", remote); SC_ADB_COMMAND("-s", serial, "reverse", "--remove", remote);
sc_pid pid = sc_adb_execute(argv, flags); sc_pid pid = sc_adb_execute(argv, flags);
free(remote);
return process_check_success_intr(intr, pid, "adb reverse --remove", flags); return process_check_success_intr(intr, pid, "adb reverse --remove", flags);
} }
@@ -332,14 +362,18 @@ sc_adb_install(struct sc_intr *intr, const char *serial, const char *local,
bool bool
sc_adb_tcpip(struct sc_intr *intr, const char *serial, uint16_t port, sc_adb_tcpip(struct sc_intr *intr, const char *serial, uint16_t port,
unsigned flags) { unsigned flags) {
char port_string[5 + 1]; char *port_string;
sprintf(port_string, "%" PRIu16, port); if (asprintf(&port_string, "%" PRIu16, port) == -1) {
LOG_OOM();
return false;
}
assert(serial); assert(serial);
const char *const argv[] = const char *const argv[] =
SC_ADB_COMMAND("-s", serial, "tcpip", port_string); SC_ADB_COMMAND("-s", serial, "tcpip", port_string);
sc_pid pid = sc_adb_execute(argv, flags); sc_pid pid = sc_adb_execute(argv, flags);
free(port_string);
return process_check_success_intr(intr, pid, "adb tcpip", flags); return process_check_success_intr(intr, pid, "adb tcpip", flags);
} }

View File

@@ -7,7 +7,7 @@
#include "util/log.h" #include "util/log.h"
#include "util/str.h" #include "util/str.h"
bool static bool
sc_adb_parse_device(char *line, struct sc_adb_device *device) { sc_adb_parse_device(char *line, struct sc_adb_device *device) {
// One device line looks like: // One device line looks like:
// "0123456789abcdef device usb:2-1 product:MyProduct model:MyModel " // "0123456789abcdef device usb:2-1 product:MyProduct model:MyModel "

View File

@@ -79,6 +79,7 @@ enum {
OPT_AUDIO_SOURCE, OPT_AUDIO_SOURCE,
OPT_KILL_ADB_ON_CLOSE, OPT_KILL_ADB_ON_CLOSE,
OPT_TIME_LIMIT, OPT_TIME_LIMIT,
OPT_PAUSE_ON_EXIT,
}; };
struct sc_option { struct sc_option {
@@ -463,6 +464,20 @@ static const struct sc_option options[] = {
"Default is " STR(DEFAULT_LOCAL_PORT_RANGE_FIRST) ":" "Default is " STR(DEFAULT_LOCAL_PORT_RANGE_FIRST) ":"
STR(DEFAULT_LOCAL_PORT_RANGE_LAST) ".", STR(DEFAULT_LOCAL_PORT_RANGE_LAST) ".",
}, },
{
.longopt_id = OPT_PAUSE_ON_EXIT,
.longopt = "pause-on-exit",
.argdesc = "mode",
.optional_arg = true,
.text = "Configure pause on exit. Possible values are \"true\" (always "
"pause on exit), \"false\" (never pause on exit) and "
"\"if-error\" (pause only if an error occured).\n"
"This is useful to prevent the terminal window from "
"automatically closing, so that error messages can be read.\n"
"Default is \"false\".\n"
"Passing the option without argument is equivalent to passing "
"\"true\".",
},
{ {
.longopt_id = OPT_POWER_OFF_ON_CLOSE, .longopt_id = OPT_POWER_OFF_ON_CLOSE,
.longopt = "power-off-on-close", .longopt = "power-off-on-close",
@@ -1070,7 +1085,7 @@ print_shortcut(const struct sc_shortcut *shortcut, unsigned cols) {
while (shortcut->shortcuts[i]) { while (shortcut->shortcuts[i]) {
printf(" %s\n", shortcut->shortcuts[i]); printf(" %s\n", shortcut->shortcuts[i]);
++i; ++i;
}; }
char *text = sc_str_wrap_lines(shortcut->text, cols, 8); char *text = sc_str_wrap_lines(shortcut->text, cols, 8);
if (!text) { if (!text) {
@@ -1637,6 +1652,29 @@ parse_time_limit(const char *s, sc_tick *tick) {
return true; return true;
} }
static bool
parse_pause_on_exit(const char *s, enum sc_pause_on_exit *pause_on_exit) {
if (!s || !strcmp(s, "true")) {
*pause_on_exit = SC_PAUSE_ON_EXIT_TRUE;
return true;
}
if (!strcmp(s, "false")) {
*pause_on_exit = SC_PAUSE_ON_EXIT_FALSE;
return true;
}
if (!strcmp(s, "if-error")) {
*pause_on_exit = SC_PAUSE_ON_EXIT_IF_ERROR;
return true;
}
LOGE("Unsupported pause on exit mode: %s "
"(expected true, false or if-error)", optarg);
return false;
}
static bool static bool
parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[], parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
const char *optstring, const struct option *longopts) { const char *optstring, const struct option *longopts) {
@@ -1977,6 +2015,11 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
return false; return false;
} }
break; break;
case OPT_PAUSE_ON_EXIT:
if (!parse_pause_on_exit(optarg, &args->pause_on_exit)) {
return false;
}
break;
default: default:
// getopt prints the error message on stderr // getopt prints the error message on stderr
return false; return false;
@@ -2190,6 +2233,37 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
return true; return true;
} }
static enum sc_pause_on_exit
sc_get_pause_on_exit(int argc, char *argv[]) {
// Read arguments backwards so that the last --pause-on-exit is considered
// (same behavior as getopt())
for (int i = argc - 1; i >= 1; --i) {
const char *arg = argv[i];
// Starts with "--pause-on-exit"
if (!strncmp("--pause-on-exit", arg, 15)) {
if (arg[15] == '\0') {
// No argument
return SC_PAUSE_ON_EXIT_TRUE;
}
if (arg[15] != '=') {
// Invalid parameter, ignore
return SC_PAUSE_ON_EXIT_FALSE;
}
const char *value = &arg[16];
if (!strcmp(value, "true")) {
return SC_PAUSE_ON_EXIT_TRUE;
}
if (!strcmp(value, "if-error")) {
return SC_PAUSE_ON_EXIT_IF_ERROR;
}
// Set to false, inclusing when the value is invalid
return SC_PAUSE_ON_EXIT_FALSE;
}
}
return SC_PAUSE_ON_EXIT_FALSE;
}
bool bool
scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) { scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
struct sc_getopt_adapter adapter; struct sc_getopt_adapter adapter;
@@ -2203,5 +2277,11 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
sc_getopt_adapter_destroy(&adapter); sc_getopt_adapter_destroy(&adapter);
if (!ret && args->pause_on_exit == SC_PAUSE_ON_EXIT_FALSE) {
// Check if "--pause-on-exit" is present in the arguments list, because
// it must be taken into account even if command line parsing failed
args->pause_on_exit = sc_get_pause_on_exit(argc, argv);
}
return ret; return ret;
} }

View File

@@ -7,10 +7,17 @@
#include "options.h" #include "options.h"
enum sc_pause_on_exit {
SC_PAUSE_ON_EXIT_TRUE,
SC_PAUSE_ON_EXIT_FALSE,
SC_PAUSE_ON_EXIT_IF_ERROR,
};
struct scrcpy_cli_args { struct scrcpy_cli_args {
struct scrcpy_options opts; struct scrcpy_options opts;
bool help; bool help;
bool version; bool version;
enum sc_pause_on_exit pause_on_exit;
}; };
void void

View File

@@ -271,7 +271,7 @@ error:
} }
SDL_Surface * SDL_Surface *
scrcpy_icon_load() { scrcpy_icon_load(void) {
char *icon_path = get_icon_path(); char *icon_path = get_icon_path();
if (!icon_path) { if (!icon_path) {
return NULL; return NULL;

View File

@@ -23,7 +23,7 @@
#include "util/str.h" #include "util/str.h"
#endif #endif
int static int
main_scrcpy(int argc, char *argv[]) { main_scrcpy(int argc, char *argv[]) {
#ifdef _WIN32 #ifdef _WIN32
// disable buffering, we want logs immediately // disable buffering, we want logs immediately
@@ -39,26 +39,32 @@ main_scrcpy(int argc, char *argv[]) {
.opts = scrcpy_options_default, .opts = scrcpy_options_default,
.help = false, .help = false,
.version = false, .version = false,
.pause_on_exit = SC_PAUSE_ON_EXIT_FALSE,
}; };
#ifndef NDEBUG #ifndef NDEBUG
args.opts.log_level = SC_LOG_LEVEL_DEBUG; args.opts.log_level = SC_LOG_LEVEL_DEBUG;
#endif #endif
enum scrcpy_exit_code ret;
if (!scrcpy_parse_args(&args, argc, argv)) { if (!scrcpy_parse_args(&args, argc, argv)) {
return SCRCPY_EXIT_FAILURE; ret = SCRCPY_EXIT_FAILURE;
goto end;
} }
sc_set_log_level(args.opts.log_level); sc_set_log_level(args.opts.log_level);
if (args.help) { if (args.help) {
scrcpy_print_usage(argv[0]); scrcpy_print_usage(argv[0]);
return SCRCPY_EXIT_SUCCESS; ret = SCRCPY_EXIT_SUCCESS;
goto end;
} }
if (args.version) { if (args.version) {
scrcpy_print_version(); scrcpy_print_version();
return SCRCPY_EXIT_SUCCESS; ret = SCRCPY_EXIT_SUCCESS;
goto end;
} }
#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL #ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
@@ -72,18 +78,26 @@ main_scrcpy(int argc, char *argv[]) {
#endif #endif
if (!net_init()) { if (!net_init()) {
return SCRCPY_EXIT_FAILURE; ret = SCRCPY_EXIT_FAILURE;
goto end;
} }
sc_log_configure(); sc_log_configure();
#ifdef HAVE_USB #ifdef HAVE_USB
enum scrcpy_exit_code ret = args.opts.otg ? scrcpy_otg(&args.opts) ret = args.opts.otg ? scrcpy_otg(&args.opts) : scrcpy(&args.opts);
: scrcpy(&args.opts);
#else #else
enum scrcpy_exit_code ret = scrcpy(&args.opts); ret = scrcpy(&args.opts);
#endif #endif
end:
if (args.pause_on_exit == SC_PAUSE_ON_EXIT_TRUE ||
(args.pause_on_exit == SC_PAUSE_ON_EXIT_IF_ERROR &&
ret != SCRCPY_EXIT_SUCCESS)) {
printf("Press Enter to continue...\n");
getchar();
}
return ret; return ret;
} }

View File

@@ -90,7 +90,7 @@ push_event(uint32_t type, const char *name) {
#define PUSH_EVENT(TYPE) push_event(TYPE, # TYPE) #define PUSH_EVENT(TYPE) push_event(TYPE, # TYPE)
#ifdef _WIN32 #ifdef _WIN32
BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) { static BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) {
if (ctrl_type == CTRL_C_EVENT) { if (ctrl_type == CTRL_C_EVENT) {
PUSH_EVENT(SDL_QUIT); PUSH_EVENT(SDL_QUIT);
return TRUE; return TRUE;
@@ -297,7 +297,7 @@ sc_timeout_on_timeout(struct sc_timeout *timeout, void *userdata) {
// Generate a scrcpy id to differentiate multiple running scrcpy instances // Generate a scrcpy id to differentiate multiple running scrcpy instances
static uint32_t static uint32_t
scrcpy_generate_scid() { scrcpy_generate_scid(void) {
struct sc_rand rand; struct sc_rand rand;
sc_rand_init(&rand); sc_rand_init(&rand);
// Only use 31 bits to avoid issues with signed values on the Java-side // Only use 31 bits to avoid issues with signed values on the Java-side

View File

@@ -86,14 +86,15 @@ sc_server_params_copy(struct sc_server_params *dst,
// The params reference user-allocated memory, so we must copy them to // The params reference user-allocated memory, so we must copy them to
// handle them from another thread // handle them from another thread
#define COPY(FIELD) \ #define COPY(FIELD) do { \
dst->FIELD = NULL; \ dst->FIELD = NULL; \
if (src->FIELD) { \ if (src->FIELD) { \
dst->FIELD = strdup(src->FIELD); \ dst->FIELD = strdup(src->FIELD); \
if (!dst->FIELD) { \ if (!dst->FIELD) { \
goto error; \ goto error; \
} \ } \
} } \
} while(0)
COPY(req_serial); COPY(req_serial);
COPY(crop); COPY(crop);
@@ -215,13 +216,13 @@ execute_server(struct sc_server *server,
cmd[count++] = SCRCPY_VERSION; cmd[count++] = SCRCPY_VERSION;
unsigned dyn_idx = count; // from there, the strings are allocated unsigned dyn_idx = count; // from there, the strings are allocated
#define ADD_PARAM(fmt, ...) { \ #define ADD_PARAM(fmt, ...) do { \
char *p; \ char *p; \
if (asprintf(&p, fmt, ## __VA_ARGS__) == -1) { \ if (asprintf(&p, fmt, ## __VA_ARGS__) == -1) { \
goto end; \ goto end; \
} \ } \
cmd[count++] = p; \ cmd[count++] = p; \
} } while(0)
ADD_PARAM("scid=%08x", params->scid); ADD_PARAM("scid=%08x", params->scid);
ADD_PARAM("log_level=%s", log_level_to_server_string(params->log_level)); ADD_PARAM("log_level=%s", log_level_to_server_string(params->log_level));

View File

@@ -27,7 +27,7 @@
// keyboard support, though OS could support more keys via modifying the report // keyboard support, though OS could support more keys via modifying the report
// desc. 6 should be enough for scrcpy. // desc. 6 should be enough for scrcpy.
#define HID_KEYBOARD_MAX_KEYS 6 #define HID_KEYBOARD_MAX_KEYS 6
#define HID_KEYBOARD_EVENT_SIZE (2 + HID_KEYBOARD_MAX_KEYS) #define HID_KEYBOARD_EVENT_SIZE (HID_KEYBOARD_INDEX_KEYS + HID_KEYBOARD_MAX_KEYS)
#define HID_RESERVED 0x00 #define HID_RESERVED 0x00
#define HID_ERROR_ROLL_OVER 0x01 #define HID_ERROR_ROLL_OVER 0x01

View File

@@ -93,7 +93,7 @@ sc_usb_device_move(struct sc_usb_device *dst, struct sc_usb_device *src) {
src->product = NULL; src->product = NULL;
} }
void static void
sc_usb_devices_destroy(struct sc_vec_usb_devices *usb_devices) { sc_usb_devices_destroy(struct sc_vec_usb_devices *usb_devices) {
for (size_t i = 0; i < usb_devices->size; ++i) { for (size_t i = 0; i < usb_devices->size; ++i) {
sc_usb_device_destroy(&usb_devices->data[i]); sc_usb_device_destroy(&usb_devices->data[i]);

View File

@@ -147,7 +147,7 @@ sc_sdl_log_print(void *userdata, int category, SDL_LogPriority priority,
} }
void void
sc_log_configure() { sc_log_configure(void) {
SDL_LogSetOutputFunction(sc_sdl_log_print, NULL); SDL_LogSetOutputFunction(sc_sdl_log_print, NULL);
// Redirect FFmpeg logs to SDL logs // Redirect FFmpeg logs to SDL logs
av_log_set_callback(sc_av_log_callback); av_log_set_callback(sc_av_log_callback);

View File

@@ -36,6 +36,6 @@ sc_log_windows_error(const char *prefix, int error);
#endif #endif
void void
sc_log_configure(); sc_log_configure(void);
#endif #endif

View File

@@ -190,10 +190,10 @@ sc_vecdeque_reallocdata_(void *ptr, size_t newcap, size_t item_size,
size_t right_len = MIN(size, oldcap - oldorigin); size_t right_len = MIN(size, oldcap - oldorigin);
assert(right_len); assert(right_len);
memcpy(newptr, ptr + (oldorigin * item_size), right_len * item_size); memcpy(newptr, (char *) ptr + (oldorigin * item_size), right_len * item_size);
if (size > right_len) { if (size > right_len) {
memcpy(newptr + (right_len * item_size), ptr, memcpy((char *) newptr + (right_len * item_size), ptr,
(size - right_len) * item_size); (size - right_len) * item_size);
} }

View File

@@ -5,7 +5,7 @@
#include "util/bytebuf.h" #include "util/bytebuf.h"
void test_bytebuf_simple(void) { static void test_bytebuf_simple(void) {
struct sc_bytebuf buf; struct sc_bytebuf buf;
uint8_t data[20]; uint8_t data[20];
@@ -34,7 +34,7 @@ void test_bytebuf_simple(void) {
sc_bytebuf_destroy(&buf); sc_bytebuf_destroy(&buf);
} }
void test_bytebuf_boundaries(void) { static void test_bytebuf_boundaries(void) {
struct sc_bytebuf buf; struct sc_bytebuf buf;
uint8_t data[20]; uint8_t data[20];
@@ -71,7 +71,7 @@ void test_bytebuf_boundaries(void) {
sc_bytebuf_destroy(&buf); sc_bytebuf_destroy(&buf);
} }
void test_bytebuf_two_steps_write(void) { static void test_bytebuf_two_steps_write(void) {
struct sc_bytebuf buf; struct sc_bytebuf buf;
uint8_t data[20]; uint8_t data[20];

View File

@@ -358,7 +358,7 @@ static void test_index_of_column(void) {
assert(sc_str_index_of_column(" a bc d", 1, " ") == 2); assert(sc_str_index_of_column(" a bc d", 1, " ") == 2);
} }
static void test_remove_trailing_cr() { static void test_remove_trailing_cr(void) {
char s[] = "abc\r"; char s[] = "abc\r";
sc_str_remove_trailing_cr(s, sizeof(s) - 1); sc_str_remove_trailing_cr(s, sizeof(s) - 1);
assert(!strcmp(s, "abc")); assert(!strcmp(s, "abc"));

View File

@@ -102,7 +102,7 @@ static void test_vecdeque_reserve(void) {
sc_vecdeque_destroy(&vdq); sc_vecdeque_destroy(&vdq);
} }
static void test_vecdeque_grow() { static void test_vecdeque_grow(void) {
struct SC_VECDEQUE(int) vdq = SC_VECDEQUE_INITIALIZER; struct SC_VECDEQUE(int) vdq = SC_VECDEQUE_INITIALIZER;
bool ok = sc_vecdeque_reserve(&vdq, 20); bool ok = sc_vecdeque_reserve(&vdq, 20);
@@ -142,7 +142,7 @@ static void test_vecdeque_grow() {
sc_vecdeque_destroy(&vdq); sc_vecdeque_destroy(&vdq);
} }
static void test_vecdeque_push_hole() { static void test_vecdeque_push_hole(void) {
struct SC_VECDEQUE(int) vdq = SC_VECDEQUE_INITIALIZER; struct SC_VECDEQUE(int) vdq = SC_VECDEQUE_INITIALIZER;
bool ok = sc_vecdeque_reserve(&vdq, 20); bool ok = sc_vecdeque_reserve(&vdq, 20);

View File

@@ -187,7 +187,7 @@ static void test_vector_index_of(void) {
sc_vector_destroy(&vec); sc_vector_destroy(&vec);
} }
static void test_vector_grow() { static void test_vector_grow(void) {
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER; struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
bool ok; bool ok;

View File

@@ -7,6 +7,8 @@ project('scrcpy', 'c',
'b_ndebug=if-release', 'b_ndebug=if-release',
]) ])
add_project_arguments('-Wmissing-prototypes', language: 'c')
if get_option('compile_app') if get_option('compile_app')
subdir('app') subdir('app')
endif endif