2018-01-23 23:32:29 +08:00
|
|
|
#include "scrcpy.h"
|
|
|
|
|
2018-02-01 17:46:42 +08:00
|
|
|
#include <getopt.h>
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2018-01-23 23:32:29 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <libavformat/avformat.h>
|
2019-03-28 02:37:44 +08:00
|
|
|
#define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem
|
2018-01-23 23:32:29 +08:00
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
2018-02-07 19:02:15 +08:00
|
|
|
#include "config.h"
|
2019-09-30 04:36:56 +08:00
|
|
|
#include "compat.h"
|
2018-02-13 17:10:18 +08:00
|
|
|
#include "log.h"
|
2019-02-09 22:20:07 +08:00
|
|
|
#include "recorder.h"
|
2018-01-23 23:32:29 +08:00
|
|
|
|
|
|
|
struct args {
|
2019-11-07 05:06:54 +08:00
|
|
|
struct scrcpy_options opts;
|
2019-03-03 06:52:22 +08:00
|
|
|
bool help;
|
|
|
|
bool version;
|
2018-01-23 23:32:29 +08:00
|
|
|
};
|
|
|
|
|
2018-02-01 18:44:09 +08:00
|
|
|
static void usage(const char *arg0) {
|
2019-07-31 22:11:08 +08:00
|
|
|
#ifdef __APPLE__
|
|
|
|
# define CTRL_OR_CMD "Cmd"
|
|
|
|
#else
|
|
|
|
# define CTRL_OR_CMD "Ctrl"
|
|
|
|
#endif
|
2018-02-01 18:44:09 +08:00
|
|
|
fprintf(stderr,
|
2018-02-15 01:57:29 +08:00
|
|
|
"Usage: %s [options]\n"
|
2018-02-01 18:44:09 +08:00
|
|
|
"\n"
|
|
|
|
"Options:\n"
|
|
|
|
"\n"
|
2018-02-01 23:36:50 +08:00
|
|
|
" -b, --bit-rate value\n"
|
|
|
|
" Encode the video at the given bit-rate, expressed in bits/s.\n"
|
|
|
|
" Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
|
|
|
|
" Default is %d.\n"
|
|
|
|
"\n"
|
2018-08-10 01:12:27 +08:00
|
|
|
" -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"
|
2018-09-04 21:55:20 +08:00
|
|
|
" -f, --fullscreen\n"
|
|
|
|
" Start in fullscreen.\n"
|
|
|
|
"\n"
|
2019-10-31 04:55:12 +08:00
|
|
|
" -F, --record-format format\n"
|
2019-02-09 22:20:07 +08:00
|
|
|
" Force recording format (either mp4 or mkv).\n"
|
|
|
|
"\n"
|
2018-02-01 18:44:09 +08:00
|
|
|
" -h, --help\n"
|
|
|
|
" Print this help.\n"
|
|
|
|
"\n"
|
|
|
|
" -m, --max-size value\n"
|
|
|
|
" Limit both the width and height of the video to value. The\n"
|
|
|
|
" other dimension is computed so that the device aspect-ratio\n"
|
|
|
|
" is preserved.\n"
|
|
|
|
" Default is %d%s.\n"
|
|
|
|
"\n"
|
2019-03-03 05:40:51 +08:00
|
|
|
" -n, --no-control\n"
|
|
|
|
" Disable device control (mirror the device in read-only).\n"
|
|
|
|
"\n"
|
2019-03-03 05:46:46 +08:00
|
|
|
" -N, --no-display\n"
|
|
|
|
" Do not display device (only when screen recording is\n"
|
|
|
|
" enabled).\n"
|
2019-02-02 05:53:24 +08:00
|
|
|
"\n"
|
2018-02-01 18:44:09 +08:00
|
|
|
" -p, --port port\n"
|
|
|
|
" Set the TCP port the client listens on.\n"
|
|
|
|
" Default is %d.\n"
|
|
|
|
"\n"
|
2019-07-31 07:48:32 +08:00
|
|
|
" --push-target path\n"
|
|
|
|
" Set the target directory for pushing files to the device by\n"
|
|
|
|
" drag & drop. It is passed as-is to \"adb push\".\n"
|
|
|
|
" Default is \"/sdcard/\".\n"
|
|
|
|
"\n"
|
2018-11-11 21:03:29 +08:00
|
|
|
" -r, --record file.mp4\n"
|
|
|
|
" Record screen to file.\n"
|
2019-02-09 22:20:07 +08:00
|
|
|
" The format is determined by the -F/--record-format option if\n"
|
|
|
|
" set, or by the file extension (.mp4 or .mkv).\n"
|
2018-11-11 21:03:29 +08:00
|
|
|
"\n"
|
2019-06-06 01:02:50 +08:00
|
|
|
" --render-expired-frames\n"
|
|
|
|
" By default, to minimize latency, scrcpy always renders the\n"
|
|
|
|
" last available decoded frame, and drops any previous ones.\n"
|
|
|
|
" This flag forces to render all frames, at a cost of a\n"
|
|
|
|
" possible increased latency.\n"
|
|
|
|
"\n"
|
2019-06-18 23:13:53 +08:00
|
|
|
" -s, --serial serial\n"
|
2018-02-15 01:57:29 +08:00
|
|
|
" The device serial number. Mandatory only if several devices\n"
|
|
|
|
" are connected to adb.\n"
|
|
|
|
"\n"
|
2019-06-05 06:55:46 +08:00
|
|
|
" -S, --turn-screen-off\n"
|
|
|
|
" Turn the device screen off immediately.\n"
|
|
|
|
"\n"
|
2018-03-25 21:23:00 +08:00
|
|
|
" -t, --show-touches\n"
|
|
|
|
" Enable \"show touches\" on start, disable on quit.\n"
|
|
|
|
" It only shows physical touches (not clicks from scrcpy).\n"
|
|
|
|
"\n"
|
2019-01-27 19:04:22 +08:00
|
|
|
" -T, --always-on-top\n"
|
|
|
|
" Make scrcpy window always on top (above other windows).\n"
|
|
|
|
"\n"
|
2018-02-07 19:37:53 +08:00
|
|
|
" -v, --version\n"
|
|
|
|
" Print the version of scrcpy.\n"
|
|
|
|
"\n"
|
2019-06-24 01:02:34 +08:00
|
|
|
" --window-title text\n"
|
|
|
|
" Set a custom window title.\n"
|
|
|
|
"\n"
|
2018-02-01 18:44:09 +08:00
|
|
|
"Shortcuts:\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+f\n"
|
2018-02-02 22:10:44 +08:00
|
|
|
" switch fullscreen mode\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+g\n"
|
2018-02-02 22:10:44 +08:00
|
|
|
" resize window to 1:1 (pixel-perfect)\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+x\n"
|
2018-03-13 15:32:48 +08:00
|
|
|
" Double-click on black borders\n"
|
2018-02-15 21:00:57 +08:00
|
|
|
" resize window to remove black borders\n"
|
2018-02-02 22:10:44 +08:00
|
|
|
"\n"
|
|
|
|
" Ctrl+h\n"
|
2018-03-10 07:40:55 +08:00
|
|
|
" Middle-click\n"
|
2018-02-02 22:10:44 +08:00
|
|
|
" click on HOME\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+b\n"
|
|
|
|
" " CTRL_OR_CMD "+Backspace\n"
|
2018-03-10 07:40:55 +08:00
|
|
|
" Right-click (when screen is on)\n"
|
2018-02-02 22:10:44 +08:00
|
|
|
" click on BACK\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+s\n"
|
2018-02-02 22:10:44 +08:00
|
|
|
" click on APP_SWITCH\n"
|
|
|
|
"\n"
|
2018-03-23 17:10:24 +08:00
|
|
|
" Ctrl+m\n"
|
2018-03-21 09:04:40 +08:00
|
|
|
" click on MENU\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+Up\n"
|
2018-02-02 22:10:44 +08:00
|
|
|
" click on VOLUME_UP\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+Down\n"
|
2018-02-02 22:10:44 +08:00
|
|
|
" click on VOLUME_DOWN\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+p\n"
|
2018-02-02 22:10:44 +08:00
|
|
|
" click on POWER (turn screen on/off)\n"
|
|
|
|
"\n"
|
2018-03-10 07:40:55 +08:00
|
|
|
" Right-click (when screen is off)\n"
|
2019-03-16 03:23:30 +08:00
|
|
|
" power on\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+o\n"
|
2019-03-16 03:23:30 +08:00
|
|
|
" turn device screen off (keep mirroring)\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+n\n"
|
2019-02-27 03:35:37 +08:00
|
|
|
" expand notification panel\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+Shift+n\n"
|
2019-02-27 03:35:37 +08:00
|
|
|
" collapse notification panel\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+c\n"
|
2019-05-30 21:23:01 +08:00
|
|
|
" copy device clipboard to computer\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+v\n"
|
2018-03-07 22:29:33 +08:00
|
|
|
" paste computer clipboard to device\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+Shift+v\n"
|
2019-05-31 02:25:23 +08:00
|
|
|
" copy computer clipboard to device\n"
|
|
|
|
"\n"
|
2019-07-31 22:11:08 +08:00
|
|
|
" " CTRL_OR_CMD "+i\n"
|
2018-02-15 19:24:16 +08:00
|
|
|
" enable/disable FPS counter (print frames/second in logs)\n"
|
2018-05-29 02:24:23 +08:00
|
|
|
"\n"
|
|
|
|
" Drag & drop APK file\n"
|
|
|
|
" install APK from computer\n"
|
2018-02-01 18:44:09 +08:00
|
|
|
"\n",
|
|
|
|
arg0,
|
2018-02-01 23:36:50 +08:00
|
|
|
DEFAULT_BIT_RATE,
|
2018-02-01 18:44:09 +08:00
|
|
|
DEFAULT_MAX_SIZE, DEFAULT_MAX_SIZE ? "" : " (unlimited)",
|
|
|
|
DEFAULT_LOCAL_PORT);
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static void
|
|
|
|
print_version(void) {
|
2018-11-12 21:09:11 +08:00
|
|
|
fprintf(stderr, "scrcpy %s\n\n", SCRCPY_VERSION);
|
2018-02-07 22:01:19 +08:00
|
|
|
|
|
|
|
fprintf(stderr, "dependencies:\n");
|
2019-03-03 03:09:56 +08:00
|
|
|
fprintf(stderr, " - SDL %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION,
|
|
|
|
SDL_PATCHLEVEL);
|
|
|
|
fprintf(stderr, " - libavcodec %d.%d.%d\n", LIBAVCODEC_VERSION_MAJOR,
|
|
|
|
LIBAVCODEC_VERSION_MINOR,
|
|
|
|
LIBAVCODEC_VERSION_MICRO);
|
|
|
|
fprintf(stderr, " - libavformat %d.%d.%d\n", LIBAVFORMAT_VERSION_MAJOR,
|
|
|
|
LIBAVFORMAT_VERSION_MINOR,
|
|
|
|
LIBAVFORMAT_VERSION_MICRO);
|
|
|
|
fprintf(stderr, " - libavutil %d.%d.%d\n", LIBAVUTIL_VERSION_MAJOR,
|
|
|
|
LIBAVUTIL_VERSION_MINOR,
|
|
|
|
LIBAVUTIL_VERSION_MICRO);
|
2018-02-07 22:01:19 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
static bool
|
|
|
|
parse_bit_rate(char *optarg, uint32_t *bit_rate) {
|
2018-02-15 01:53:16 +08:00
|
|
|
char *endptr;
|
|
|
|
if (*optarg == '\0') {
|
|
|
|
LOGE("Bit-rate parameter is empty");
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
long value = strtol(optarg, &endptr, 0);
|
|
|
|
int mul = 1;
|
|
|
|
if (*endptr != '\0') {
|
|
|
|
if (optarg == endptr) {
|
|
|
|
LOGE("Invalid bit-rate: %s", optarg);
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
if ((*endptr == 'M' || *endptr == 'm') && endptr[1] == '\0') {
|
|
|
|
mul = 1000000;
|
|
|
|
} else if ((*endptr == 'K' || *endptr == 'k') && endptr[1] == '\0') {
|
|
|
|
mul = 1000;
|
|
|
|
} else {
|
|
|
|
LOGE("Invalid bit-rate unit: %s", optarg);
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
}
|
2019-03-03 06:52:22 +08:00
|
|
|
if (value < 0 || ((uint32_t) -1) / mul < value) {
|
2018-02-15 01:53:16 +08:00
|
|
|
LOGE("Bitrate must be positive and less than 2^32: %s", optarg);
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
*bit_rate = (uint32_t) value * mul;
|
|
|
|
return true;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
static bool
|
|
|
|
parse_max_size(char *optarg, uint16_t *max_size) {
|
2018-02-15 01:53:16 +08:00
|
|
|
char *endptr;
|
|
|
|
if (*optarg == '\0') {
|
|
|
|
LOGE("Max size parameter is empty");
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
long value = strtol(optarg, &endptr, 0);
|
|
|
|
if (*endptr != '\0') {
|
|
|
|
LOGE("Invalid max size: %s", optarg);
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
if (value & ~0xffff) {
|
|
|
|
LOGE("Max size must be between 0 and 65535: %ld", value);
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
*max_size = (uint16_t) value;
|
|
|
|
return true;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
static bool
|
|
|
|
parse_port(char *optarg, uint16_t *port) {
|
2018-02-15 01:53:16 +08:00
|
|
|
char *endptr;
|
|
|
|
if (*optarg == '\0') {
|
|
|
|
LOGE("Invalid port parameter is empty");
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
long value = strtol(optarg, &endptr, 0);
|
|
|
|
if (*endptr != '\0') {
|
|
|
|
LOGE("Invalid port: %s", optarg);
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
if (value & ~0xffff) {
|
|
|
|
LOGE("Port out of range: %ld", value);
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
*port = (uint16_t) value;
|
|
|
|
return true;
|
2018-02-15 01:53:16 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
static bool
|
2019-02-09 22:20:07 +08:00
|
|
|
parse_record_format(const char *optarg, enum recorder_format *format) {
|
|
|
|
if (!strcmp(optarg, "mp4")) {
|
|
|
|
*format = RECORDER_FORMAT_MP4;
|
2019-03-03 06:52:22 +08:00
|
|
|
return true;
|
2019-02-09 22:20:07 +08:00
|
|
|
}
|
|
|
|
if (!strcmp(optarg, "mkv")) {
|
|
|
|
*format = RECORDER_FORMAT_MKV;
|
2019-03-03 06:52:22 +08:00
|
|
|
return true;
|
2019-02-09 22:20:07 +08:00
|
|
|
}
|
|
|
|
LOGE("Unsupported format: %s (expected mp4 or mkv)", optarg);
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2019-02-09 22:20:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static enum recorder_format
|
|
|
|
guess_record_format(const char *filename) {
|
|
|
|
size_t len = strlen(filename);
|
|
|
|
if (len < 4) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const char *ext = &filename[len - 4];
|
|
|
|
if (!strcmp(ext, ".mp4")) {
|
|
|
|
return RECORDER_FORMAT_MP4;
|
|
|
|
}
|
|
|
|
if (!strcmp(ext, ".mkv")) {
|
|
|
|
return RECORDER_FORMAT_MKV;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-06 01:02:50 +08:00
|
|
|
#define OPT_RENDER_EXPIRED_FRAMES 1000
|
2019-06-24 01:02:34 +08:00
|
|
|
#define OPT_WINDOW_TITLE 1001
|
2019-07-31 07:48:32 +08:00
|
|
|
#define OPT_PUSH_TARGET 1002
|
2019-11-07 16:58:06 +08:00
|
|
|
#define OPT_ALWAYS_ON_TOP 1003
|
|
|
|
#define OPT_CROP 1004
|
|
|
|
#define OPT_RECORD_FORMAT 1005
|
2019-06-06 01:02:50 +08:00
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
static bool
|
2019-03-03 03:09:56 +08:00
|
|
|
parse_args(struct args *args, int argc, char *argv[]) {
|
2018-02-01 17:46:42 +08:00
|
|
|
static const struct option long_options[] = {
|
2019-11-07 16:58:06 +08:00
|
|
|
{"always-on-top", no_argument, NULL, OPT_ALWAYS_ON_TOP},
|
2019-06-06 00:47:09 +08:00
|
|
|
{"bit-rate", required_argument, NULL, 'b'},
|
2019-11-07 16:58:06 +08:00
|
|
|
{"crop", required_argument, NULL, OPT_CROP},
|
2019-06-06 00:47:09 +08:00
|
|
|
{"fullscreen", no_argument, NULL, 'f'},
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"max-size", required_argument, NULL, 'm'},
|
|
|
|
{"no-control", no_argument, NULL, 'n'},
|
|
|
|
{"no-display", no_argument, NULL, 'N'},
|
|
|
|
{"port", required_argument, NULL, 'p'},
|
2019-11-07 16:48:48 +08:00
|
|
|
{"push-target", required_argument, NULL, OPT_PUSH_TARGET},
|
2019-06-06 00:47:09 +08:00
|
|
|
{"record", required_argument, NULL, 'r'},
|
2019-11-07 16:58:06 +08:00
|
|
|
{"record-format", required_argument, NULL, OPT_RECORD_FORMAT},
|
2019-06-06 01:02:50 +08:00
|
|
|
{"render-expired-frames", no_argument, NULL,
|
2019-11-07 16:48:48 +08:00
|
|
|
OPT_RENDER_EXPIRED_FRAMES},
|
2019-06-06 00:47:09 +08:00
|
|
|
{"serial", required_argument, NULL, 's'},
|
|
|
|
{"show-touches", no_argument, NULL, 't'},
|
|
|
|
{"turn-screen-off", no_argument, NULL, 'S'},
|
|
|
|
{"version", no_argument, NULL, 'v'},
|
2019-06-24 01:02:34 +08:00
|
|
|
{"window-title", required_argument, NULL,
|
2019-11-07 16:48:48 +08:00
|
|
|
OPT_WINDOW_TITLE},
|
2019-06-06 00:47:09 +08:00
|
|
|
{NULL, 0, NULL, 0 },
|
2018-02-01 17:46:42 +08:00
|
|
|
};
|
2019-11-07 05:06:54 +08:00
|
|
|
|
|
|
|
struct scrcpy_options *opts = &args->opts;
|
|
|
|
|
2018-01-23 23:32:29 +08:00
|
|
|
int c;
|
2019-06-05 06:55:46 +08:00
|
|
|
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTv", long_options,
|
2019-03-03 03:09:56 +08:00
|
|
|
NULL)) != -1) {
|
2018-01-23 23:32:29 +08:00
|
|
|
switch (c) {
|
2018-03-21 18:14:15 +08:00
|
|
|
case 'b':
|
2019-11-07 05:06:54 +08:00
|
|
|
if (!parse_bit_rate(optarg, &opts->bit_rate)) {
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-01 23:31:59 +08:00
|
|
|
}
|
2018-02-15 01:39:46 +08:00
|
|
|
break;
|
2018-08-10 01:12:27 +08:00
|
|
|
case 'c':
|
2019-11-07 16:58:06 +08:00
|
|
|
LOGW("Deprecated option -c. Use --crop instead.");
|
|
|
|
// fall through
|
|
|
|
case OPT_CROP:
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->crop = optarg;
|
2018-08-10 01:12:27 +08:00
|
|
|
break;
|
2018-09-04 21:55:20 +08:00
|
|
|
case 'f':
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->fullscreen = true;
|
2018-09-04 21:55:20 +08:00
|
|
|
break;
|
2019-02-09 22:20:07 +08:00
|
|
|
case 'F':
|
2019-11-07 16:58:06 +08:00
|
|
|
LOGW("Deprecated option -F. Use --record-format instead.");
|
|
|
|
// fall through
|
|
|
|
case OPT_RECORD_FORMAT:
|
2019-11-07 05:06:54 +08:00
|
|
|
if (!parse_record_format(optarg, &opts->record_format)) {
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2019-02-09 22:20:07 +08:00
|
|
|
}
|
|
|
|
break;
|
2018-03-21 18:14:15 +08:00
|
|
|
case 'h':
|
2019-03-03 06:52:22 +08:00
|
|
|
args->help = true;
|
2018-02-01 18:34:49 +08:00
|
|
|
break;
|
2018-03-21 18:14:15 +08:00
|
|
|
case 'm':
|
2019-11-07 05:06:54 +08:00
|
|
|
if (!parse_max_size(optarg, &opts->max_size)) {
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-01 23:31:59 +08:00
|
|
|
}
|
2018-02-01 18:34:49 +08:00
|
|
|
break;
|
2019-03-03 05:40:51 +08:00
|
|
|
case 'n':
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->control = false;
|
2019-03-03 05:40:51 +08:00
|
|
|
break;
|
2019-03-03 05:46:46 +08:00
|
|
|
case 'N':
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->display = false;
|
2019-02-02 05:53:24 +08:00
|
|
|
break;
|
2018-03-21 18:14:15 +08:00
|
|
|
case 'p':
|
2019-11-07 05:06:54 +08:00
|
|
|
if (!parse_port(optarg, &opts->port)) {
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-01 23:36:50 +08:00
|
|
|
}
|
2018-02-15 01:39:46 +08:00
|
|
|
break;
|
2018-11-11 21:03:29 +08:00
|
|
|
case 'r':
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->record_filename = optarg;
|
2018-11-11 21:03:29 +08:00
|
|
|
break;
|
2018-03-21 18:14:15 +08:00
|
|
|
case 's':
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->serial = optarg;
|
2018-02-15 01:57:29 +08:00
|
|
|
break;
|
2019-06-05 06:55:46 +08:00
|
|
|
case 'S':
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->turn_screen_off = true;
|
2019-06-05 06:55:46 +08:00
|
|
|
break;
|
2018-03-25 21:23:00 +08:00
|
|
|
case 't':
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->show_touches = true;
|
2018-03-25 21:23:00 +08:00
|
|
|
break;
|
2019-01-27 19:04:22 +08:00
|
|
|
case 'T':
|
2019-11-07 16:58:06 +08:00
|
|
|
LOGW("Deprecated option -T. Use --always-on-top instead.");
|
|
|
|
// fall through
|
|
|
|
case OPT_ALWAYS_ON_TOP:
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->always_on_top = true;
|
2019-01-27 19:04:22 +08:00
|
|
|
break;
|
2018-03-21 18:14:15 +08:00
|
|
|
case 'v':
|
2019-03-03 06:52:22 +08:00
|
|
|
args->version = true;
|
2018-02-01 23:36:50 +08:00
|
|
|
break;
|
2019-06-06 01:02:50 +08:00
|
|
|
case OPT_RENDER_EXPIRED_FRAMES:
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->render_expired_frames = true;
|
2019-06-06 01:02:50 +08:00
|
|
|
break;
|
2019-06-24 01:02:34 +08:00
|
|
|
case OPT_WINDOW_TITLE:
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->window_title = optarg;
|
2019-06-24 01:02:34 +08:00
|
|
|
break;
|
2019-07-31 07:48:32 +08:00
|
|
|
case OPT_PUSH_TARGET:
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->push_target = optarg;
|
2019-07-31 07:48:32 +08:00
|
|
|
break;
|
2018-02-01 18:34:49 +08:00
|
|
|
default:
|
|
|
|
// getopt prints the error message on stderr
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-01-23 23:32:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 05:06:54 +08:00
|
|
|
if (!opts->display && !opts->record_filename) {
|
2019-03-03 05:46:46 +08:00
|
|
|
LOGE("-N/--no-display requires screen recording (-r/--record)");
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2019-02-02 05:53:24 +08:00
|
|
|
}
|
|
|
|
|
2019-11-07 05:06:54 +08:00
|
|
|
if (!opts->display && opts->fullscreen) {
|
2019-03-03 05:46:46 +08:00
|
|
|
LOGE("-f/--fullscreen-window is incompatible with -N/--no-display");
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2019-02-02 05:53:24 +08:00
|
|
|
}
|
|
|
|
|
2018-01-23 23:32:29 +08:00
|
|
|
int index = optind;
|
|
|
|
if (index < argc) {
|
2018-02-13 17:10:18 +08:00
|
|
|
LOGE("Unexpected additional argument: %s", argv[index]);
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-01-23 23:32:29 +08:00
|
|
|
}
|
2019-02-09 22:20:07 +08:00
|
|
|
|
2019-11-07 05:06:54 +08:00
|
|
|
if (opts->record_format && !opts->record_filename) {
|
2019-02-09 22:20:07 +08:00
|
|
|
LOGE("Record format specified without recording");
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2019-02-09 22:20:07 +08:00
|
|
|
}
|
|
|
|
|
2019-11-07 05:06:54 +08:00
|
|
|
if (opts->record_filename && !opts->record_format) {
|
|
|
|
opts->record_format = guess_record_format(opts->record_filename);
|
|
|
|
if (!opts->record_format) {
|
2019-02-09 22:20:07 +08:00
|
|
|
LOGE("No format specified for \"%s\" (try with -F mkv)",
|
2019-11-07 05:06:54 +08:00
|
|
|
opts->record_filename);
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2019-02-09 22:20:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 05:06:54 +08:00
|
|
|
if (!opts->control && opts->turn_screen_off) {
|
2019-06-24 02:49:38 +08:00
|
|
|
LOGE("Could not request to turn screen off if control is disabled");
|
2019-06-20 16:59:19 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
return true;
|
2018-01-23 23:32:29 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[]) {
|
2018-03-13 17:20:09 +08:00
|
|
|
#ifdef __WINDOWS__
|
|
|
|
// disable buffering, we want logs immediately
|
|
|
|
// even line buffering (setvbuf() with mode _IOLBF) is not sufficient
|
|
|
|
setbuf(stdout, NULL);
|
|
|
|
setbuf(stderr, NULL);
|
|
|
|
#endif
|
2018-01-23 23:32:29 +08:00
|
|
|
struct args args = {
|
2019-11-07 05:06:54 +08:00
|
|
|
.opts = SCRCPY_OPTIONS_DEFAULT,
|
2019-03-03 06:52:22 +08:00
|
|
|
.help = false,
|
|
|
|
.version = false,
|
2018-01-23 23:32:29 +08:00
|
|
|
};
|
2019-11-07 05:06:54 +08:00
|
|
|
|
2018-02-15 01:44:28 +08:00
|
|
|
if (!parse_args(&args, argc, argv)) {
|
2018-01-23 23:32:29 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-02-01 18:44:09 +08:00
|
|
|
if (args.help) {
|
|
|
|
usage(argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-07 19:37:53 +08:00
|
|
|
if (args.version) {
|
2018-02-07 22:01:19 +08:00
|
|
|
print_version();
|
2018-02-07 19:37:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-31 07:55:43 +08:00
|
|
|
LOGI("scrcpy " SCRCPY_VERSION " <https://github.com/Genymobile/scrcpy>");
|
|
|
|
|
2019-02-16 22:04:32 +08:00
|
|
|
#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
|
2018-01-23 23:32:29 +08:00
|
|
|
av_register_all();
|
2018-08-10 00:18:22 +08:00
|
|
|
#endif
|
2018-01-23 23:32:29 +08:00
|
|
|
|
|
|
|
if (avformat_network_init()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-02-12 18:07:38 +08:00
|
|
|
#ifdef BUILD_DEBUG
|
2018-01-23 23:32:29 +08:00
|
|
|
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG);
|
2018-02-12 18:07:38 +08:00
|
|
|
#endif
|
2018-01-23 23:32:29 +08:00
|
|
|
|
2019-11-07 05:06:54 +08:00
|
|
|
int res = scrcpy(&args.opts) ? 0 : 1;
|
2018-01-23 23:32:29 +08:00
|
|
|
|
|
|
|
avformat_network_deinit(); // ignore failure
|
|
|
|
|
2018-09-14 20:34:59 +08:00
|
|
|
#if defined (__WINDOWS__) && ! defined (WINDOWS_NOCONSOLE)
|
|
|
|
if (res != 0) {
|
|
|
|
fprintf(stderr, "Press any key to continue...\n");
|
|
|
|
getchar();
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-23 23:32:29 +08:00
|
|
|
return res;
|
|
|
|
}
|