Compare commits

..

2 Commits

Author SHA1 Message Date
Romain Vimont
185802fbe2 longlong 2019-12-10 09:22:30 +01:00
Romain Vimont
78f566bd6d Move platorm-specific defines to common.h
They could be useful anywhere.
2019-12-10 09:11:09 +01:00
15 changed files with 95 additions and 133 deletions

View File

@@ -233,10 +233,10 @@ You can then [run](README.md#run) _scrcpy_.
## Prebuilt server
- [`scrcpy-server-v1.12.1`][direct-scrcpy-server]
_(SHA-256: 63e569c8a1d0c1df31d48c4214871c479a601782945fed50c1e61167d78266ea)_
- [`scrcpy-server-v1.12`][direct-scrcpy-server]
_(SHA-256: b6595262c230e9773fdb817257abcc8c6e6e00f15b1c32b6a850ccfd8176dc10)_
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.12.1/scrcpy-server-v1.12.1
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.12/scrcpy-server-v1.12
Download the prebuilt server somewhere, and specify its path during the Meson
configuration:

View File

@@ -1,4 +1,4 @@
# scrcpy (v1.12.1)
# scrcpy (v1.12)
This application provides display and control of Android devices connected on
USB (or [over TCP/IP][article-tcpip]). It does not require any _root_ access.
@@ -62,13 +62,13 @@ For Gentoo, an [Ebuild] is available: [`scrcpy/`][ebuild-link].
For Windows, for simplicity, prebuilt archives with all the dependencies
(including `adb`) are available:
- [`scrcpy-win32-v1.12.1.zip`][direct-win32]
_(SHA-256: 0f4b3b063536b50a2df05dc42c760f9cc0093a9a26dbdf02d8232c74dab43480)_
- [`scrcpy-win64-v1.12.1.zip`][direct-win64]
_(SHA-256: 57d34b6d16cfd9fe169bc37c4df58ebd256d05c1ea3febc63d9cb0a027ab47c9)_
- [`scrcpy-win32-v1.12.zip`][direct-win32]
_(SHA-256: b2c8c4a3899c037cf448a2102906775114826ba646ce1b847826925103fa801d)_
- [`scrcpy-win64-v1.12.zip`][direct-win64]
_(SHA-256: 7d47983b426f7287de0230b88975dc17c1d9c343fa61a93ff2af78b6e9ef5c8c)_
[direct-win32]: https://github.com/Genymobile/scrcpy/releases/download/v1.12.1/scrcpy-win32-v1.12.1.zip
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.12.1/scrcpy-win64-v1.12.1.zip
[direct-win32]: https://github.com/Genymobile/scrcpy/releases/download/v1.12/scrcpy-win32-v1.12.zip
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.12/scrcpy-win64-v1.12.zip
You can also [build the app manually][BUILD].

View File

@@ -2,6 +2,7 @@
#include <getopt.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include "config.h"
@@ -197,9 +198,9 @@ scrcpy_print_usage(const char *arg0) {
}
static bool
parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
long max, const char *name) {
long value;
parse_integer_arg(const char *s, long long *out, bool accept_suffix,
long long min, long long max, const char *name) {
long long value;
bool ok;
if (accept_suffix) {
ok = parse_integer_with_suffix(s, &value);
@@ -212,8 +213,8 @@ parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
}
if (value < min || value > max) {
LOGE("Could not parse %s: value (%ld) out-of-range (%ld; %ld)",
name, value, min, max);
LOGE("Could not parse %s: value (%" PRIlld ") out-of-range (%"
PRIlld "; %" PRIlld ")", name, value, min, max);
return false;
}
@@ -223,10 +224,8 @@ parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
static bool
parse_bit_rate(const char *s, uint32_t *bit_rate) {
long value;
// long may be 32 bits (it is the case on mingw), so do not use more than
// 31 bits (long is signed)
bool ok = parse_integer_arg(s, &value, true, 0, 0x7FFFFFFF, "bit-rate");
long long value;
bool ok = parse_integer_arg(s, &value, true, 0, 0xFFFFFFFFLL, "bit-rate");
if (!ok) {
return false;
}
@@ -237,7 +236,7 @@ parse_bit_rate(const char *s, uint32_t *bit_rate) {
static bool
parse_max_size(const char *s, uint16_t *max_size) {
long value;
long long value;
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF, "max size");
if (!ok) {
return false;
@@ -249,7 +248,7 @@ parse_max_size(const char *s, uint16_t *max_size) {
static bool
parse_max_fps(const char *s, uint16_t *max_fps) {
long value;
long long value;
bool ok = parse_integer_arg(s, &value, false, 0, 1000, "max fps");
if (!ok) {
return false;
@@ -261,7 +260,7 @@ parse_max_fps(const char *s, uint16_t *max_fps) {
static bool
parse_window_position(const char *s, int16_t *position) {
long value;
long long value;
bool ok = parse_integer_arg(s, &value, false, -1, 0x7FFF,
"window position");
if (!ok) {
@@ -274,7 +273,7 @@ parse_window_position(const char *s, int16_t *position) {
static bool
parse_window_dimension(const char *s, uint16_t *dimension) {
long value;
long long value;
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF,
"window dimension");
if (!ok) {
@@ -287,7 +286,7 @@ parse_window_dimension(const char *s, uint16_t *dimension) {
static bool
parse_port(const char *s, uint16_t *port) {
long value;
long long value;
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF, "port");
if (!ok) {
return false;

View File

@@ -4,6 +4,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "config.h"
#include "common.h"
@@ -202,3 +205,14 @@ process_check_success(process_t proc, const char *name) {
}
return true;
}
bool
is_regular_file(const char *path) {
struct stat path_stat;
int r = stat(path, &path_stat);
if (r) {
perror("stat");
return false;
}
return S_ISREG(path_stat.st_mode);
}

View File

@@ -4,38 +4,8 @@
#include <stdbool.h>
#include <inttypes.h>
#ifdef _WIN32
// not needed here, but winsock2.h must never be included AFTER windows.h
# include <winsock2.h>
# include <windows.h>
# define PATH_SEPARATOR '\\'
# define PRIexitcode "lu"
// <https://stackoverflow.com/a/44383330/1987178>
# ifdef _WIN64
# define PRIsizet PRIu64
# else
# define PRIsizet PRIu32
# endif
# define PROCESS_NONE NULL
# define NO_EXIT_CODE -1u // max value as unsigned
typedef HANDLE process_t;
typedef DWORD exit_code_t;
#else
# include <sys/types.h>
# define PATH_SEPARATOR '/'
# define PRIsizet "zu"
# define PRIexitcode "d"
# define PROCESS_NONE -1
# define NO_EXIT_CODE -1
typedef pid_t process_t;
typedef int exit_code_t;
#endif
#include "config.h"
#include "common.h"
enum process_result {
PROCESS_SUCCESS,

View File

@@ -5,6 +5,44 @@
#include "config.h"
#ifdef _WIN32
// not needed here, but winsock2.h must never be included AFTER windows.h
# include <winsock2.h>
# include <windows.h>
# define PATH_SEPARATOR '\\'
# define PRIexitcode "lu"
// <https://stackoverflow.com/a/44383330/1987178>
# ifdef _WIN64
# define PRIsizet PRIu64
# else
# define PRIsizet PRIu32
# endif
# define PROCESS_NONE NULL
# define NO_EXIT_CODE -1u // max value as unsigned
typedef HANDLE process_t;
typedef DWORD exit_code_t;
#else
# include <sys/types.h>
# define PATH_SEPARATOR '/'
# define PRIsizet "zu"
# define PRIexitcode "d"
# define PROCESS_NONE -1
# define NO_EXIT_CODE -1
typedef pid_t process_t;
typedef int exit_code_t;
#endif
// in MinGW, "%ll" is not supported as printf format for long long
# ifdef __MINGW32__
# define PRIlld "I64d"
# else
# define PRIlld "lld"
# endif
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
#define MIN(X,Y) (X) < (Y) ? (X) : (Y)
#define MAX(X,Y) (X) > (Y) ? (X) : (Y)

View File

@@ -6,13 +6,11 @@
#include <libgen.h>
#include <stdio.h>
#include <SDL2/SDL_timer.h>
#include <SDL2/SDL_platform.h>
#include "config.h"
#include "command.h"
#include "util/log.h"
#include "util/net.h"
#include "util/str_util.h"
#define SOCKET_NAME "scrcpy"
#define SERVER_FILENAME "scrcpy-server"
@@ -20,39 +18,20 @@
#define DEFAULT_SERVER_PATH PREFIX "/share/scrcpy/" SERVER_FILENAME
#define DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
static char *
static const char *
get_server_path(void) {
#ifdef __WINDOWS__
const wchar_t *server_path_env = _wgetenv(L"SCRCPY_SERVER_PATH");
#else
const char *server_path_env = getenv("SCRCPY_SERVER_PATH");
#endif
if (server_path_env) {
LOGD("Using SCRCPY_SERVER_PATH: %s", server_path_env);
// if the envvar is set, use it
#ifdef __WINDOWS__
char *server_path = utf8_from_wide_char(server_path_env);
#else
char *server_path = SDL_strdup(server_path_env);
#endif
if (!server_path) {
LOGE("Could not allocate memory");
return NULL;
}
LOGD("Using SCRCPY_SERVER_PATH: %s", server_path);
return server_path;
return server_path_env;
}
#ifndef PORTABLE
LOGD("Using server: " DEFAULT_SERVER_PATH);
char *server_path = SDL_strdup(DEFAULT_SERVER_PATH);
if (!server_path) {
LOGE("Could not allocate memory");
return NULL;
}
// the absolute path is hardcoded
return server_path;
return DEFAULT_SERVER_PATH;
#else
// use scrcpy-server in the same directory as the executable
char *executable_path = get_executable_path();
if (!executable_path) {
@@ -88,17 +67,12 @@ get_server_path(void) {
static bool
push_server(const char *serial) {
char *server_path = get_server_path();
if (!server_path) {
return false;
}
const char *server_path = get_server_path();
if (!is_regular_file(server_path)) {
LOGE("'%s' does not exist or is not a regular file\n", server_path);
SDL_free(server_path);
return false;
}
process_t process = adb_push(serial, server_path, DEVICE_SERVER_PATH);
SDL_free(server_path);
return process_check_success(process, "adb push");
}

View File

@@ -15,7 +15,6 @@
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -128,14 +127,3 @@ get_executable_path(void) {
return NULL;
#endif
}
bool
is_regular_file(const char *path) {
struct stat path_stat;
if (stat(path, &path_stat)) {
perror("stat");
return false;
}
return S_ISREG(path_stat.st_mode);
}

View File

@@ -4,8 +4,6 @@
#include "util/log.h"
#include "util/str_util.h"
#include <sys/stat.h>
static int
build_cmd(char *cmd, size_t len, const char *const argv[]) {
// Windows command-line parsing is WTF:
@@ -92,22 +90,3 @@ get_executable_path(void) {
buf[len] = '\0';
return utf8_from_wide_char(buf);
}
bool
is_regular_file(const char *path) {
wchar_t *wide_path = utf8_to_wide_char(path);
if (!wide_path) {
LOGC("Could not allocate wide char string");
return false;
}
struct _stat path_stat;
int r = _wstat(wide_path, &path_stat);
SDL_free(wide_path);
if (r) {
perror("stat");
return false;
}
return S_ISREG(path_stat.st_mode);
}

View File

@@ -63,13 +63,13 @@ strquote(const char *src) {
}
bool
parse_integer(const char *s, long *out) {
parse_integer(const char *s, long long *out) {
char *endptr;
if (*s == '\0') {
return false;
}
errno = 0;
long value = strtol(s, &endptr, 0);
long long value = strtol(s, &endptr, 0);
if (errno == ERANGE) {
return false;
}
@@ -82,13 +82,13 @@ parse_integer(const char *s, long *out) {
}
bool
parse_integer_with_suffix(const char *s, long *out) {
parse_integer_with_suffix(const char *s, long long *out) {
char *endptr;
if (*s == '\0') {
return false;
}
errno = 0;
long value = strtol(s, &endptr, 0);
long long value = strtoll(s, &endptr, 0);
if (errno == ERANGE) {
return false;
}
@@ -106,8 +106,8 @@ parse_integer_with_suffix(const char *s, long *out) {
}
}
if ((value < 0 && LONG_MIN / mul > value) ||
(value > 0 && LONG_MAX / mul < value)) {
if ((value < 0 && LLONG_MIN / mul > value) ||
(value > 0 && LLONG_MAX / mul < value)) {
return false;
}

View File

@@ -29,14 +29,14 @@ strquote(const char *src);
// parse s as an integer into value
// returns true if the conversion succeeded, false otherwise
bool
parse_integer(const char *s, long *out);
parse_integer(const char *s, long long *out);
// parse s as an integer into value
// like parse_integer(), but accept 'k'/'K' (x1000) and 'm'/'M' (x1000000) as
// suffix
// returns true if the conversion succeeded, false otherwise
bool
parse_integer_with_suffix(const char *s, long *out);
parse_integer_with_suffix(const char *s, long long *out);
// return the index to truncate a UTF-8 string at a valid position
size_t

View File

@@ -171,7 +171,7 @@ static void test_utf8_truncate(void) {
}
static void test_parse_integer(void) {
long value;
long long value;
bool ok = parse_integer("1234", &value);
assert(ok);
assert(value == 1234);
@@ -188,7 +188,7 @@ static void test_parse_integer(void) {
}
static void test_parse_integer_with_suffix(void) {
long value;
long long value;
bool ok = parse_integer_with_suffix("1234", &value);
assert(ok);
assert(value == 1234);

View File

@@ -1,5 +1,5 @@
project('scrcpy', 'c',
version: '1.12.1',
version: '1.12',
meson_version: '>= 0.37',
default_options: [
'c_std=c11',

View File

@@ -6,8 +6,8 @@ android {
applicationId "com.genymobile.scrcpy"
minSdkVersion 21
targetSdkVersion 29
versionCode 14
versionName "1.12.1"
versionCode 13
versionName "1.12"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {

View File

@@ -12,7 +12,7 @@
set -e
SCRCPY_DEBUG=false
SCRCPY_VERSION_NAME=1.12.1
SCRCPY_VERSION_NAME=1.12
PLATFORM=${ANDROID_PLATFORM:-29}
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-29.0.2}