Compare commits
56 Commits
swscale
...
mouse_butt
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75ce0b5c3f | ||
|
|
5c65f3c170 | ||
|
|
f0f96fbc3d | ||
|
|
edee69d637 | ||
|
|
8ef4c044fa | ||
|
|
c23c38f99d | ||
|
|
65c4f487b3 | ||
|
|
c6d7f5ee96 | ||
|
|
28f6cbaea6 | ||
|
|
08fc6694e1 | ||
|
|
d0983db592 | ||
|
|
fb7870500a | ||
|
|
33006561c7 | ||
|
|
a09733d175 | ||
|
|
6231f683af | ||
|
|
9826c5c4a4 | ||
|
|
1d615a0d51 | ||
|
|
fb0bcaebc2 | ||
|
|
dd453ad041 | ||
|
|
0308ef43f2 | ||
|
|
40febf4a91 | ||
|
|
429fdef04f | ||
|
|
d1789f082a | ||
|
|
eb7e1070cf | ||
|
|
386f017ba9 | ||
|
|
cc48b24324 | ||
|
|
597c54f049 | ||
|
|
955da3b578 | ||
|
|
cb9c42bdcb | ||
|
|
fb9f9848bd | ||
|
|
c50b958ee4 | ||
|
|
441d3fb119 | ||
|
|
cb197ee3a2 | ||
|
|
218636dc10 | ||
|
|
b16b65a715 | ||
|
|
a3aa5ac95e | ||
|
|
0207e3df33 | ||
|
|
9cd1a7380d | ||
|
|
24b637b972 | ||
|
|
76a3d9805b | ||
|
|
50b4a730e3 | ||
|
|
ea2369f568 | ||
|
|
0538e9645b | ||
|
|
626094ad13 | ||
|
|
a566635c43 | ||
|
|
862948b132 | ||
|
|
c0c4ba7009 | ||
|
|
c53bd4d8b6 | ||
|
|
54f5c42d7b | ||
|
|
21d206f360 | ||
|
|
d2689fc168 | ||
|
|
f6320c7e31 | ||
|
|
30e619d37f | ||
|
|
c0dde0fade | ||
|
|
ace438e52a | ||
|
|
8e83f3e8af |
@@ -11,7 +11,6 @@ src = [
|
|||||||
'src/event_converter.c',
|
'src/event_converter.c',
|
||||||
'src/file_handler.c',
|
'src/file_handler.c',
|
||||||
'src/fps_counter.c',
|
'src/fps_counter.c',
|
||||||
'src/frame_texture.c',
|
|
||||||
'src/input_manager.c',
|
'src/input_manager.c',
|
||||||
'src/opengl.c',
|
'src/opengl.c',
|
||||||
'src/receiver.c',
|
'src/receiver.c',
|
||||||
@@ -47,7 +46,6 @@ if not get_option('crossbuild_windows')
|
|||||||
dependency('libavformat'),
|
dependency('libavformat'),
|
||||||
dependency('libavcodec'),
|
dependency('libavcodec'),
|
||||||
dependency('libavutil'),
|
dependency('libavutil'),
|
||||||
dependency('libswscale'),
|
|
||||||
dependency('sdl2'),
|
dependency('sdl2'),
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -101,9 +99,6 @@ foreach f : check_functions
|
|||||||
endif
|
endif
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
# expose the build type
|
|
||||||
conf.set('NDEBUG', get_option('buildtype') != 'debug')
|
|
||||||
|
|
||||||
# the version, updated on release
|
# the version, updated on release
|
||||||
conf.set_quoted('SCRCPY_VERSION', meson.project_version())
|
conf.set_quoted('SCRCPY_VERSION', meson.project_version())
|
||||||
|
|
||||||
@@ -119,23 +114,10 @@ conf.set('PORTABLE', get_option('portable'))
|
|||||||
conf.set('DEFAULT_LOCAL_PORT_RANGE_FIRST', '27183')
|
conf.set('DEFAULT_LOCAL_PORT_RANGE_FIRST', '27183')
|
||||||
conf.set('DEFAULT_LOCAL_PORT_RANGE_LAST', '27199')
|
conf.set('DEFAULT_LOCAL_PORT_RANGE_LAST', '27199')
|
||||||
|
|
||||||
# the default max video size for both dimensions, in pixels
|
|
||||||
# overridden by option --max-size
|
|
||||||
conf.set('DEFAULT_MAX_SIZE', '0') # 0: unlimited
|
|
||||||
|
|
||||||
# the default video orientation
|
|
||||||
# natural device orientation is 0 and each increment adds 90 degrees
|
|
||||||
# counterclockwise
|
|
||||||
# overridden by option --lock-video-orientation
|
|
||||||
conf.set('DEFAULT_LOCK_VIDEO_ORIENTATION', '-1') # -1: unlocked
|
|
||||||
|
|
||||||
# the default video bitrate, in bits/second
|
# the default video bitrate, in bits/second
|
||||||
# overridden by option --bit-rate
|
# overridden by option --bit-rate
|
||||||
conf.set('DEFAULT_BIT_RATE', '8000000') # 8Mbps
|
conf.set('DEFAULT_BIT_RATE', '8000000') # 8Mbps
|
||||||
|
|
||||||
# enable High DPI support
|
|
||||||
conf.set('HIDPI_SUPPORT', get_option('hidpi_support'))
|
|
||||||
|
|
||||||
# run a server debugger and wait for a client to be attached
|
# run a server debugger and wait for a client to be attached
|
||||||
conf.set('SERVER_DEBUGGER', get_option('server_debugger'))
|
conf.set('SERVER_DEBUGGER', get_option('server_debugger'))
|
||||||
|
|
||||||
|
|||||||
15
app/scrcpy.1
15
app/scrcpy.1
@@ -167,13 +167,6 @@ Set the initial display rotation. Possibles values are 0, 1, 2 and 3. Each incre
|
|||||||
.BI "\-s, \-\-serial " number
|
.BI "\-s, \-\-serial " number
|
||||||
The device serial number. Mandatory only if several devices are connected to adb.
|
The device serial number. Mandatory only if several devices are connected to adb.
|
||||||
|
|
||||||
.TP
|
|
||||||
.BI "\-\-scale\-filter filter
|
|
||||||
Supported filters are "none" and "trilinear".
|
|
||||||
|
|
||||||
Trilinear filtering is only available if the renderer is OpenGL 3.0+ or OpenGL
|
|
||||||
ES 2.0+.
|
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-shortcut\-mod " key[+...]][,...]
|
.BI "\-\-shortcut\-mod " key[+...]][,...]
|
||||||
Specify the modifiers to use for scrcpy shortcuts. Possible keys are "lctrl", "rctrl", "lalt", "ralt", "lsuper" and "rsuper".
|
Specify the modifiers to use for scrcpy shortcuts. Possible keys are "lctrl", "rctrl", "lalt", "ralt", "lsuper" and "rsuper".
|
||||||
@@ -194,16 +187,16 @@ Enable "show touches" on start, restore the initial value on exit.
|
|||||||
|
|
||||||
It only shows physical touches (not clicks from scrcpy).
|
It only shows physical touches (not clicks from scrcpy).
|
||||||
|
|
||||||
.TP
|
|
||||||
.B \-v, \-\-version
|
|
||||||
Print the version of scrcpy.
|
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-V, \-\-verbosity " value
|
.BI "\-V, \-\-verbosity " value
|
||||||
Set the log level ("debug", "info", "warn" or "error").
|
Set the log level ("debug", "info", "warn" or "error").
|
||||||
|
|
||||||
Default is "info" for release builds, "debug" for debug builds.
|
Default is "info" for release builds, "debug" for debug builds.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B \-v, \-\-version
|
||||||
|
Print the version of scrcpy.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-w, \-\-stay-awake
|
.B \-w, \-\-stay-awake
|
||||||
Keep the device on while scrcpy is running, when the device is plugged in.
|
Keep the device on while scrcpy is running, when the device is plugged in.
|
||||||
|
|||||||
106
app/src/cli.c
106
app/src/cli.c
@@ -10,6 +10,9 @@
|
|||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "util/str_util.h"
|
#include "util/str_util.h"
|
||||||
|
|
||||||
|
#define STR_IMPL_(x) #x
|
||||||
|
#define STR(x) STR_IMPL_(x)
|
||||||
|
|
||||||
void
|
void
|
||||||
scrcpy_print_usage(const char *arg0) {
|
scrcpy_print_usage(const char *arg0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@@ -23,7 +26,7 @@ scrcpy_print_usage(const char *arg0) {
|
|||||||
" -b, --bit-rate value\n"
|
" -b, --bit-rate value\n"
|
||||||
" Encode the video at the given bit-rate, expressed in bits/s.\n"
|
" Encode the video at the given bit-rate, expressed in bits/s.\n"
|
||||||
" Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
|
" Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
|
||||||
" Default is %d.\n"
|
" Default is " STR(DEFAULT_BIT_RATE) ".\n"
|
||||||
"\n"
|
"\n"
|
||||||
" --codec-options key[:type]=value[,...]\n"
|
" --codec-options key[:type]=value[,...]\n"
|
||||||
" Set a list of comma-separated key:type=value options for the\n"
|
" Set a list of comma-separated key:type=value options for the\n"
|
||||||
@@ -81,7 +84,7 @@ scrcpy_print_usage(const char *arg0) {
|
|||||||
" Possible values are -1 (unlocked), 0, 1, 2 and 3.\n"
|
" Possible values are -1 (unlocked), 0, 1, 2 and 3.\n"
|
||||||
" Natural device orientation is 0, and each increment adds a\n"
|
" Natural device orientation is 0, and each increment adds a\n"
|
||||||
" 90 degrees rotation counterclockwise.\n"
|
" 90 degrees rotation counterclockwise.\n"
|
||||||
" Default is %d%s.\n"
|
" Default is -1 (unlocked).\n"
|
||||||
"\n"
|
"\n"
|
||||||
" --max-fps value\n"
|
" --max-fps value\n"
|
||||||
" Limit the frame rate of screen capture (officially supported\n"
|
" Limit the frame rate of screen capture (officially supported\n"
|
||||||
@@ -91,7 +94,7 @@ scrcpy_print_usage(const char *arg0) {
|
|||||||
" Limit both the width and height of the video to value. The\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"
|
" other dimension is computed so that the device aspect-ratio\n"
|
||||||
" is preserved.\n"
|
" is preserved.\n"
|
||||||
" Default is %d%s.\n"
|
" Default is 0 (unlimited).\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -n, --no-control\n"
|
" -n, --no-control\n"
|
||||||
" Disable device control (mirror the device in read-only).\n"
|
" Disable device control (mirror the device in read-only).\n"
|
||||||
@@ -103,9 +106,15 @@ scrcpy_print_usage(const char *arg0) {
|
|||||||
" --no-key-repeat\n"
|
" --no-key-repeat\n"
|
||||||
" Do not forward repeated key events when a key is held down.\n"
|
" Do not forward repeated key events when a key is held down.\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
" --no-mipmaps\n"
|
||||||
|
" If the renderer is OpenGL 3.0+ or OpenGL ES 2.0+, then\n"
|
||||||
|
" mipmaps are automatically generated to improve downscaling\n"
|
||||||
|
" quality. This option disables the generation of mipmaps.\n"
|
||||||
|
"\n"
|
||||||
" -p, --port port[:port]\n"
|
" -p, --port port[:port]\n"
|
||||||
" Set the TCP port (range) used by the client to listen.\n"
|
" Set the TCP port (range) used by the client to listen.\n"
|
||||||
" Default is %d:%d.\n"
|
" Default is " STR(DEFAULT_LOCAL_PORT_RANGE_FIRST) ":"
|
||||||
|
STR(DEFAULT_LOCAL_PORT_RANGE_LAST) ".\n"
|
||||||
"\n"
|
"\n"
|
||||||
" --prefer-text\n"
|
" --prefer-text\n"
|
||||||
" Inject alpha characters and space as text events instead of\n"
|
" Inject alpha characters and space as text events instead of\n"
|
||||||
@@ -149,11 +158,6 @@ scrcpy_print_usage(const char *arg0) {
|
|||||||
" The device serial number. Mandatory only if several devices\n"
|
" The device serial number. Mandatory only if several devices\n"
|
||||||
" are connected to adb.\n"
|
" are connected to adb.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" --scale-filter filter\n"
|
|
||||||
" Supported filters are \"none\" and \"trilinear\".\n"
|
|
||||||
" Trilinear filtering is only available if the renderer is\n"
|
|
||||||
" OpenGL 3.0+ or OpenGL ES 2.0+.\n"
|
|
||||||
"\n"
|
|
||||||
" --shortcut-mod key[+...]][,...]\n"
|
" --shortcut-mod key[+...]][,...]\n"
|
||||||
" Specify the modifiers to use for scrcpy shortcuts.\n"
|
" Specify the modifiers to use for scrcpy shortcuts.\n"
|
||||||
" Possible keys are \"lctrl\", \"rctrl\", \"lalt\", \"ralt\",\n"
|
" Possible keys are \"lctrl\", \"rctrl\", \"lalt\", \"ralt\",\n"
|
||||||
@@ -175,9 +179,6 @@ scrcpy_print_usage(const char *arg0) {
|
|||||||
" on exit.\n"
|
" on exit.\n"
|
||||||
" It only shows physical touches (not clicks from scrcpy).\n"
|
" It only shows physical touches (not clicks from scrcpy).\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -v, --version\n"
|
|
||||||
" Print the version of scrcpy.\n"
|
|
||||||
"\n"
|
|
||||||
" -V, --verbosity value\n"
|
" -V, --verbosity value\n"
|
||||||
" Set the log level (debug, info, warn or error).\n"
|
" Set the log level (debug, info, warn or error).\n"
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
@@ -185,6 +186,9 @@ scrcpy_print_usage(const char *arg0) {
|
|||||||
#else
|
#else
|
||||||
" Default is info.\n"
|
" Default is info.\n"
|
||||||
#endif
|
#endif
|
||||||
|
"\n"
|
||||||
|
" -v, --version\n"
|
||||||
|
" Print the version of scrcpy.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -w, --stay-awake\n"
|
" -w, --stay-awake\n"
|
||||||
" Keep the device on while scrcpy is running, when the device\n"
|
" Keep the device on while scrcpy is running, when the device\n"
|
||||||
@@ -297,12 +301,7 @@ scrcpy_print_usage(const char *arg0) {
|
|||||||
"\n"
|
"\n"
|
||||||
" Drag & drop APK file\n"
|
" Drag & drop APK file\n"
|
||||||
" Install APK from computer\n"
|
" Install APK from computer\n"
|
||||||
"\n",
|
"\n", arg0);
|
||||||
arg0,
|
|
||||||
DEFAULT_BIT_RATE,
|
|
||||||
DEFAULT_LOCK_VIDEO_ORIENTATION, DEFAULT_LOCK_VIDEO_ORIENTATION >= 0 ? "" : " (unlocked)",
|
|
||||||
DEFAULT_MAX_SIZE, DEFAULT_MAX_SIZE ? "" : " (unlimited)",
|
|
||||||
DEFAULT_LOCAL_PORT_RANGE_FIRST, DEFAULT_LOCAL_PORT_RANGE_LAST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@@ -641,62 +640,6 @@ guess_record_format(const char *filename) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
|
||||||
parse_scale_filter(const char *optarg, enum sc_scale_filter *filter) {
|
|
||||||
// TODO store in a map and loop over the entries instead
|
|
||||||
if (!strcmp(optarg, "none")) {
|
|
||||||
*filter = SC_SCALE_FILTER_NONE;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "trilinear")) {
|
|
||||||
*filter = SC_SCALE_FILTER_TRILINEAR;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "bilinear")) {
|
|
||||||
*filter = SC_SCALE_FILTER_BILINEAR;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "bicubic")) {
|
|
||||||
*filter = SC_SCALE_FILTER_BICUBIC;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "x")) {
|
|
||||||
*filter = SC_SCALE_FILTER_X;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "point")) {
|
|
||||||
*filter = SC_SCALE_FILTER_POINT;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "area")) {
|
|
||||||
*filter = SC_SCALE_FILTER_AREA;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "bicublin")) {
|
|
||||||
*filter = SC_SCALE_FILTER_BICUBLIN;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "gauss")) {
|
|
||||||
*filter = SC_SCALE_FILTER_GAUSS;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "sinc")) {
|
|
||||||
*filter = SC_SCALE_FILTER_SINC;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "lanczos")) {
|
|
||||||
*filter = SC_SCALE_FILTER_LANCZOS;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "spline")) {
|
|
||||||
*filter = SC_SCALE_FILTER_SPLINE;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
LOGE("Unsupported scale filter: %s "
|
|
||||||
"(expected one of [TODO])", optarg);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define OPT_RENDER_EXPIRED_FRAMES 1000
|
#define OPT_RENDER_EXPIRED_FRAMES 1000
|
||||||
#define OPT_WINDOW_TITLE 1001
|
#define OPT_WINDOW_TITLE 1001
|
||||||
#define OPT_PUSH_TARGET 1002
|
#define OPT_PUSH_TARGET 1002
|
||||||
@@ -723,7 +666,7 @@ parse_scale_filter(const char *optarg, enum sc_scale_filter *filter) {
|
|||||||
#define OPT_FORWARD_ALL_CLICKS 1023
|
#define OPT_FORWARD_ALL_CLICKS 1023
|
||||||
#define OPT_LEGACY_PASTE 1024
|
#define OPT_LEGACY_PASTE 1024
|
||||||
#define OPT_ENCODER_NAME 1025
|
#define OPT_ENCODER_NAME 1025
|
||||||
#define OPT_SCALE_FILTER 1026
|
#define OPT_POWER_OFF_ON_CLOSE 1026
|
||||||
|
|
||||||
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[]) {
|
||||||
@@ -760,7 +703,6 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
{"render-expired-frames", no_argument, NULL,
|
{"render-expired-frames", no_argument, NULL,
|
||||||
OPT_RENDER_EXPIRED_FRAMES},
|
OPT_RENDER_EXPIRED_FRAMES},
|
||||||
{"rotation", required_argument, NULL, OPT_ROTATION},
|
{"rotation", required_argument, NULL, OPT_ROTATION},
|
||||||
{"scale-filter", required_argument, NULL, OPT_SCALE_FILTER},
|
|
||||||
{"serial", required_argument, NULL, 's'},
|
{"serial", required_argument, NULL, 's'},
|
||||||
{"shortcut-mod", required_argument, NULL, OPT_SHORTCUT_MOD},
|
{"shortcut-mod", required_argument, NULL, OPT_SHORTCUT_MOD},
|
||||||
{"show-touches", no_argument, NULL, 't'},
|
{"show-touches", no_argument, NULL, 't'},
|
||||||
@@ -775,6 +717,8 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
{"window-height", required_argument, NULL, OPT_WINDOW_HEIGHT},
|
{"window-height", required_argument, NULL, OPT_WINDOW_HEIGHT},
|
||||||
{"window-borderless", no_argument, NULL,
|
{"window-borderless", no_argument, NULL,
|
||||||
OPT_WINDOW_BORDERLESS},
|
OPT_WINDOW_BORDERLESS},
|
||||||
|
{"power-off-on-close", no_argument, NULL,
|
||||||
|
OPT_POWER_OFF_ON_CLOSE},
|
||||||
{NULL, 0, NULL, 0 },
|
{NULL, 0, NULL, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -915,9 +859,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
opts->render_driver = optarg;
|
opts->render_driver = optarg;
|
||||||
break;
|
break;
|
||||||
case OPT_NO_MIPMAPS:
|
case OPT_NO_MIPMAPS:
|
||||||
LOGW("Deprecated option --no-mipmaps. "
|
opts->mipmaps = false;
|
||||||
"Use --scale-filter=none instead.");
|
|
||||||
opts->scale_filter = SC_SCALE_FILTER_NONE;
|
|
||||||
break;
|
break;
|
||||||
case OPT_NO_KEY_REPEAT:
|
case OPT_NO_KEY_REPEAT:
|
||||||
opts->forward_key_repeat = false;
|
opts->forward_key_repeat = false;
|
||||||
@@ -945,10 +887,8 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
case OPT_LEGACY_PASTE:
|
case OPT_LEGACY_PASTE:
|
||||||
opts->legacy_paste = true;
|
opts->legacy_paste = true;
|
||||||
break;
|
break;
|
||||||
case OPT_SCALE_FILTER:
|
case OPT_POWER_OFF_ON_CLOSE:
|
||||||
if (!parse_scale_filter(optarg, &opts->scale_filter)) {
|
opts->power_off_on_close = true;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// getopt prints the error message on stderr
|
// getopt prints the error message on stderr
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
# define SCRCPY_SDL_HAS_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR
|
# define SCRCPY_SDL_HAS_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_STRDUP
|
#ifndef HAVE_STRDUP
|
||||||
char *strdup(const char *s);
|
char *strdup(const char *s);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
|||||||
buffer_write32be(&buf[17],
|
buffer_write32be(&buf[17],
|
||||||
(uint32_t) msg->inject_scroll_event.vscroll);
|
(uint32_t) msg->inject_scroll_event.vscroll);
|
||||||
return 21;
|
return 21;
|
||||||
|
case CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON:
|
||||||
|
buf[1] = msg->inject_keycode.action;
|
||||||
|
return 2;
|
||||||
case CONTROL_MSG_TYPE_SET_CLIPBOARD: {
|
case CONTROL_MSG_TYPE_SET_CLIPBOARD: {
|
||||||
buf[1] = !!msg->set_clipboard.paste;
|
buf[1] = !!msg->set_clipboard.paste;
|
||||||
size_t len = write_string(msg->set_clipboard.text,
|
size_t len = write_string(msg->set_clipboard.text,
|
||||||
@@ -77,7 +80,6 @@ control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
|||||||
case CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE:
|
case CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE:
|
||||||
buf[1] = msg->set_screen_power_mode.mode;
|
buf[1] = msg->set_screen_power_mode.mode;
|
||||||
return 2;
|
return 2;
|
||||||
case CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON:
|
|
||||||
case CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL:
|
case CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||||
case CONTROL_MSG_TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
case CONTROL_MSG_TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||||
case CONTROL_MSG_TYPE_GET_CLIPBOARD:
|
case CONTROL_MSG_TYPE_GET_CLIPBOARD:
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ struct control_msg {
|
|||||||
int32_t hscroll;
|
int32_t hscroll;
|
||||||
int32_t vscroll;
|
int32_t vscroll;
|
||||||
} inject_scroll_event;
|
} inject_scroll_event;
|
||||||
|
struct {
|
||||||
|
enum android_keyevent_action action; // action for the BACK key
|
||||||
|
// screen may only be turned on on ACTION_DOWN
|
||||||
|
} back_or_screen_on;
|
||||||
struct {
|
struct {
|
||||||
char *text; // owned, to be freed by free()
|
char *text; // owned, to be freed by free()
|
||||||
bool paste;
|
bool paste;
|
||||||
|
|||||||
@@ -1,32 +1,11 @@
|
|||||||
#include "decoder.h"
|
#include "decoder.h"
|
||||||
|
|
||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
#include <libavutil/time.h>
|
|
||||||
#include <SDL2/SDL_events.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
#include "recorder.h"
|
|
||||||
#include "video_buffer.h"
|
#include "video_buffer.h"
|
||||||
#include "util/buffer_util.h"
|
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
|
|
||||||
// set the decoded frame as ready for rendering, and notify
|
|
||||||
static void
|
|
||||||
push_frame(struct decoder *decoder) {
|
|
||||||
bool previous_frame_skipped;
|
|
||||||
video_buffer_offer_decoded_frame(decoder->video_buffer,
|
|
||||||
&previous_frame_skipped);
|
|
||||||
if (previous_frame_skipped) {
|
|
||||||
// the previous EVENT_NEW_FRAME will consume this frame
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static SDL_Event new_frame_event = {
|
|
||||||
.type = EVENT_NEW_FRAME,
|
|
||||||
};
|
|
||||||
SDL_PushEvent(&new_frame_event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
decoder_init(struct decoder *decoder, struct video_buffer *vb) {
|
decoder_init(struct decoder *decoder, struct video_buffer *vb) {
|
||||||
decoder->video_buffer = vb;
|
decoder->video_buffer = vb;
|
||||||
@@ -66,10 +45,10 @@ decoder_push(struct decoder *decoder, const AVPacket *packet) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ret = avcodec_receive_frame(decoder->codec_ctx,
|
ret = avcodec_receive_frame(decoder->codec_ctx,
|
||||||
decoder->video_buffer->decoding_frame);
|
decoder->video_buffer->producer_frame);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
// a frame was received
|
// a frame was received
|
||||||
push_frame(decoder);
|
video_buffer_producer_offer_frame(decoder->video_buffer);
|
||||||
} else if (ret != AVERROR(EAGAIN)) {
|
} else if (ret != AVERROR(EAGAIN)) {
|
||||||
LOGE("Could not receive video frame: %d", ret);
|
LOGE("Could not receive video frame: %d", ret);
|
||||||
return false;
|
return false;
|
||||||
@@ -77,7 +56,7 @@ decoder_push(struct decoder *decoder, const AVPacket *packet) {
|
|||||||
#else
|
#else
|
||||||
int got_picture;
|
int got_picture;
|
||||||
int len = avcodec_decode_video2(decoder->codec_ctx,
|
int len = avcodec_decode_video2(decoder->codec_ctx,
|
||||||
decoder->video_buffer->decoding_frame,
|
decoder->video_buffer->producer_frame,
|
||||||
&got_picture,
|
&got_picture,
|
||||||
packet);
|
packet);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
@@ -85,7 +64,7 @@ decoder_push(struct decoder *decoder, const AVPacket *packet) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (got_picture) {
|
if (got_picture) {
|
||||||
push_frame(decoder);
|
video_buffer_producer_offer_frame(decoder->video_buffer);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ struct video_buffer;
|
|||||||
|
|
||||||
struct decoder {
|
struct decoder {
|
||||||
struct video_buffer *video_buffer;
|
struct video_buffer *video_buffer;
|
||||||
|
|
||||||
AVCodecContext *codec_ctx;
|
AVCodecContext *codec_ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
#define EVENT_NEW_SESSION SDL_USEREVENT
|
#define EVENT_NEW_FRAME SDL_USEREVENT
|
||||||
#define EVENT_NEW_FRAME (SDL_USEREVENT + 1)
|
#define EVENT_STREAM_STOPPED (SDL_USEREVENT + 1)
|
||||||
#define EVENT_STREAM_STOPPED (SDL_USEREVENT + 2)
|
|
||||||
|
|||||||
@@ -1,247 +0,0 @@
|
|||||||
#include "frame_texture.h"
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <libavutil/imgutils.h>
|
|
||||||
#include <libswscale/swscale.h>
|
|
||||||
|
|
||||||
#include "util/log.h"
|
|
||||||
|
|
||||||
static inline bool
|
|
||||||
is_swscale_enabled(enum sc_scale_filter scale_filter) {
|
|
||||||
return scale_filter != SC_SCALE_FILTER_NONE
|
|
||||||
&& scale_filter != SC_SCALE_FILTER_TRILINEAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SDL_Texture *
|
|
||||||
create_texture(struct sc_frame_texture *ftex, struct size size) {
|
|
||||||
SDL_Renderer *renderer = ftex->renderer;
|
|
||||||
SDL_PixelFormatEnum fmt = is_swscale_enabled(ftex->scale_filter)
|
|
||||||
? SDL_PIXELFORMAT_RGB24
|
|
||||||
: SDL_PIXELFORMAT_YV12;
|
|
||||||
SDL_Texture *texture = SDL_CreateTexture(renderer, fmt,
|
|
||||||
SDL_TEXTUREACCESS_STREAMING,
|
|
||||||
size.width, size.height);
|
|
||||||
if (!texture) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ftex->scale_filter == SC_SCALE_FILTER_TRILINEAR) {
|
|
||||||
struct sc_opengl *gl = &ftex->gl;
|
|
||||||
|
|
||||||
SDL_GL_BindTexture(texture, NULL, NULL);
|
|
||||||
|
|
||||||
// Enable trilinear filtering for downscaling
|
|
||||||
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
|
||||||
GL_LINEAR_MIPMAP_LINEAR);
|
|
||||||
gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -1.f);
|
|
||||||
|
|
||||||
SDL_GL_UnbindTexture(texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
sc_frame_texture_init(struct sc_frame_texture *ftex, SDL_Renderer *renderer,
|
|
||||||
enum sc_scale_filter scale_filter,
|
|
||||||
struct size initial_size) {
|
|
||||||
SDL_RendererInfo renderer_info;
|
|
||||||
int r = SDL_GetRendererInfo(renderer, &renderer_info);
|
|
||||||
const char *renderer_name = r ? NULL : renderer_info.name;
|
|
||||||
LOGI("Renderer: %s", renderer_name ? renderer_name : "(unknown)");
|
|
||||||
|
|
||||||
ftex->scale_filter = scale_filter;
|
|
||||||
|
|
||||||
// starts with "opengl"
|
|
||||||
bool use_opengl = renderer_name && !strncmp(renderer_name, "opengl", 6);
|
|
||||||
if (use_opengl) {
|
|
||||||
struct sc_opengl *gl = &ftex->gl;
|
|
||||||
sc_opengl_init(gl);
|
|
||||||
|
|
||||||
LOGI("OpenGL version: %s", gl->version);
|
|
||||||
|
|
||||||
if (scale_filter == SC_SCALE_FILTER_TRILINEAR) {
|
|
||||||
bool supports_mipmaps =
|
|
||||||
sc_opengl_version_at_least(gl, 3, 0, /* OpenGL 3.0+ */
|
|
||||||
2, 0 /* OpenGL ES 2.0+ */);
|
|
||||||
if (!supports_mipmaps) {
|
|
||||||
LOGW("Trilinear filtering disabled "
|
|
||||||
"(OpenGL 3.0+ or ES 2.0+ required)");
|
|
||||||
ftex->scale_filter = SC_SCALE_FILTER_NONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (scale_filter == SC_SCALE_FILTER_TRILINEAR) {
|
|
||||||
LOGD("Trilinear filtering disabled (not an OpenGL renderer)");
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGD("Scale filter: %s\n", sc_scale_filter_name(ftex->scale_filter));
|
|
||||||
|
|
||||||
LOGI("Initial texture: %" PRIu16 "x%" PRIu16, initial_size.width,
|
|
||||||
initial_size.height);
|
|
||||||
ftex->renderer = renderer;
|
|
||||||
ftex->texture = create_texture(ftex, initial_size);
|
|
||||||
if (!ftex->texture) {
|
|
||||||
LOGC("Could not create texture: %s", SDL_GetError());
|
|
||||||
SDL_DestroyRenderer(ftex->renderer);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ftex->texture_size = initial_size;
|
|
||||||
ftex->decoded_frame = NULL;
|
|
||||||
memset(ftex->data, 0, sizeof(ftex->data));
|
|
||||||
memset(ftex->linesize, 0, sizeof(ftex->linesize));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sc_frame_texture_destroy(struct sc_frame_texture *ftex) {
|
|
||||||
if (ftex->texture) {
|
|
||||||
SDL_DestroyTexture(ftex->texture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
to_sws_filter(enum sc_scale_filter scale_filter) {
|
|
||||||
switch (scale_filter) {
|
|
||||||
case SC_SCALE_FILTER_BILINEAR: return SWS_BILINEAR;
|
|
||||||
case SC_SCALE_FILTER_BICUBIC: return SWS_BICUBIC;
|
|
||||||
case SC_SCALE_FILTER_X: return SWS_X;
|
|
||||||
case SC_SCALE_FILTER_POINT: return SWS_POINT;
|
|
||||||
case SC_SCALE_FILTER_AREA: return SWS_AREA;
|
|
||||||
case SC_SCALE_FILTER_BICUBLIN: return SWS_BICUBLIN;
|
|
||||||
case SC_SCALE_FILTER_GAUSS: return SWS_GAUSS;
|
|
||||||
case SC_SCALE_FILTER_SINC: return SWS_SINC;
|
|
||||||
case SC_SCALE_FILTER_LANCZOS: return SWS_LANCZOS;
|
|
||||||
case SC_SCALE_FILTER_SPLINE: return SWS_SPLINE;
|
|
||||||
default: assert(!"unsupported filter");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
screen_generate_resized_frame(struct sc_frame_texture *ftex,
|
|
||||||
struct size target_size) {
|
|
||||||
assert(is_swscale_enabled(ftex->scale_filter));
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
if (ftex->data[0]) {
|
|
||||||
av_freep(&ftex->data[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret = av_image_alloc(ftex->data, ftex->linesize, target_size.width,
|
|
||||||
target_size.height, AV_PIX_FMT_RGB24, 16);
|
|
||||||
if (ret < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const AVFrame *input = ftex->decoded_frame;
|
|
||||||
assert(input);
|
|
||||||
|
|
||||||
int flags = to_sws_filter(ftex->scale_filter);
|
|
||||||
struct SwsContext *ctx =
|
|
||||||
sws_getContext(input->width, input->height, AV_PIX_FMT_YUV420P,
|
|
||||||
target_size.width, target_size.height, AV_PIX_FMT_RGB24,
|
|
||||||
flags, NULL, NULL, NULL);
|
|
||||||
if (!ctx) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
sws_scale(ctx, (const uint8_t *const *) input->data, input->linesize, 0,
|
|
||||||
input->height, ftex->data, ftex->linesize);
|
|
||||||
sws_freeContext(ctx);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
sc_frame_texture_update_direct(struct sc_frame_texture *ftex,
|
|
||||||
const AVFrame *frame) {
|
|
||||||
struct size frame_size = {frame->width, frame->height};
|
|
||||||
if (ftex->texture_size.width != frame_size.width
|
|
||||||
|| ftex->texture_size.height != frame_size.height) {
|
|
||||||
// Frame dimensions changed, destroy texture
|
|
||||||
SDL_DestroyTexture(ftex->texture);
|
|
||||||
|
|
||||||
LOGI("New texture: %" PRIu16 "x%" PRIu16, frame_size.width,
|
|
||||||
frame_size.height);
|
|
||||||
ftex->texture = create_texture(ftex, frame_size);
|
|
||||||
if (!ftex->texture) {
|
|
||||||
LOGC("Could not create texture: %s", SDL_GetError());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ftex->texture_size = frame_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_UpdateYUVTexture(ftex->texture, NULL,
|
|
||||||
frame->data[0], frame->linesize[0],
|
|
||||||
frame->data[1], frame->linesize[1],
|
|
||||||
frame->data[2], frame->linesize[2]);
|
|
||||||
|
|
||||||
if (ftex->scale_filter == SC_SCALE_FILTER_TRILINEAR) {
|
|
||||||
SDL_GL_BindTexture(ftex->texture, NULL, NULL);
|
|
||||||
ftex->gl.GenerateMipmap(GL_TEXTURE_2D);
|
|
||||||
SDL_GL_UnbindTexture(ftex->texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
sc_frame_texture_update_swscale(struct sc_frame_texture *ftex,
|
|
||||||
const AVFrame *frame, struct size target_size) {
|
|
||||||
if (ftex->texture_size.width != target_size.width
|
|
||||||
|| ftex->texture_size.height != target_size.height) {
|
|
||||||
// Frame dimensions changed, destroy texture
|
|
||||||
SDL_DestroyTexture(ftex->texture);
|
|
||||||
|
|
||||||
ftex->texture = create_texture(ftex, target_size);
|
|
||||||
if (!ftex->texture) {
|
|
||||||
LOGC("Could not create texture: %s", SDL_GetError());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ftex->texture_size = target_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The frame is valid until the next call to
|
|
||||||
// video_buffer_take_rendering_frame()
|
|
||||||
ftex->decoded_frame = frame;
|
|
||||||
|
|
||||||
bool ok = screen_generate_resized_frame(ftex, target_size);
|
|
||||||
if (!ok) {
|
|
||||||
LOGE("Failed to resize frame\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_UpdateTexture(ftex->texture, NULL, ftex->data[0], ftex->linesize[0]);
|
|
||||||
|
|
||||||
if (ftex->scale_filter == SC_SCALE_FILTER_TRILINEAR) {
|
|
||||||
SDL_GL_BindTexture(ftex->texture, NULL, NULL);
|
|
||||||
ftex->gl.GenerateMipmap(GL_TEXTURE_2D);
|
|
||||||
SDL_GL_UnbindTexture(ftex->texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
sc_frame_texture_update(struct sc_frame_texture *ftex, const AVFrame *frame,
|
|
||||||
struct size target_size) {
|
|
||||||
if (is_swscale_enabled(ftex->scale_filter)) {
|
|
||||||
return sc_frame_texture_update_swscale(ftex, frame, target_size);
|
|
||||||
}
|
|
||||||
return sc_frame_texture_update_direct(ftex, frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
sc_frame_texture_resize(struct sc_frame_texture *ftex,
|
|
||||||
struct size target_size) {
|
|
||||||
if (is_swscale_enabled(ftex->scale_filter)) {
|
|
||||||
return sc_frame_texture_update_swscale(ftex, ftex->decoded_frame,
|
|
||||||
target_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nothing to do
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
#ifndef SC_FRAME_TEXTURE_H
|
|
||||||
#define SC_FRAME_TEXTURE_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <libavformat/avformat.h>
|
|
||||||
|
|
||||||
#include "coords.h"
|
|
||||||
#include "opengl.h"
|
|
||||||
#include "scrcpy.h"
|
|
||||||
|
|
||||||
struct sc_frame_texture {
|
|
||||||
SDL_Renderer *renderer; // owned by struct screen
|
|
||||||
|
|
||||||
enum sc_scale_filter scale_filter;
|
|
||||||
struct sc_opengl gl;
|
|
||||||
|
|
||||||
SDL_Texture *texture;
|
|
||||||
struct size texture_size;
|
|
||||||
|
|
||||||
// For swscaling
|
|
||||||
const AVFrame *decoded_frame; // owned by the video_buffer
|
|
||||||
uint8_t *data[4];
|
|
||||||
int linesize[4];
|
|
||||||
};
|
|
||||||
|
|
||||||
bool
|
|
||||||
sc_frame_texture_init(struct sc_frame_texture *ftex, SDL_Renderer *renderer,
|
|
||||||
enum sc_scale_filter scale_filter,
|
|
||||||
struct size initial_size);
|
|
||||||
|
|
||||||
void
|
|
||||||
sc_frame_texture_destroy(struct sc_frame_texture *ftex);
|
|
||||||
|
|
||||||
bool
|
|
||||||
sc_frame_texture_update(struct sc_frame_texture *ftex, const AVFrame *frame,
|
|
||||||
struct size target_size);
|
|
||||||
|
|
||||||
bool
|
|
||||||
sc_frame_texture_resize(struct sc_frame_texture *ftex, struct size target_size);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -146,13 +146,25 @@ action_cut(struct controller *controller, int actions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// turn the screen on if it was off, press BACK otherwise
|
// turn the screen on if it was off, press BACK otherwise
|
||||||
|
// If the screen is off, it is turned on only on ACTION_DOWN
|
||||||
static void
|
static void
|
||||||
press_back_or_turn_screen_on(struct controller *controller) {
|
press_back_or_turn_screen_on(struct controller *controller, int actions) {
|
||||||
struct control_msg msg;
|
struct control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON;
|
msg.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON;
|
||||||
|
|
||||||
if (!controller_push_msg(controller, &msg)) {
|
if (actions & ACTION_DOWN) {
|
||||||
LOGW("Could not request 'press back or turn screen on'");
|
msg.back_or_screen_on.action = AKEY_EVENT_ACTION_DOWN;
|
||||||
|
if (!controller_push_msg(controller, &msg)) {
|
||||||
|
LOGW("Could not request 'press back or turn screen on'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actions & ACTION_UP) {
|
||||||
|
msg.back_or_screen_on.action = AKEY_EVENT_ACTION_UP;
|
||||||
|
if (!controller_push_msg(controller, &msg)) {
|
||||||
|
LOGW("Could not request 'press back or turn screen on'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +298,7 @@ rotate_client_right(struct screen *screen) {
|
|||||||
screen_set_rotation(screen, new_rotation);
|
screen_set_rotation(screen, new_rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
input_manager_process_text_input(struct input_manager *im,
|
input_manager_process_text_input(struct input_manager *im,
|
||||||
const SDL_TextInputEvent *event) {
|
const SDL_TextInputEvent *event) {
|
||||||
if (is_shortcut_mod(im, SDL_GetModState())) {
|
if (is_shortcut_mod(im, SDL_GetModState())) {
|
||||||
@@ -366,7 +378,7 @@ convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
input_manager_process_key(struct input_manager *im,
|
input_manager_process_key(struct input_manager *im,
|
||||||
const SDL_KeyboardEvent *event) {
|
const SDL_KeyboardEvent *event) {
|
||||||
// control: indicates the state of the command-line option --no-control
|
// control: indicates the state of the command-line option --no-control
|
||||||
@@ -480,9 +492,7 @@ input_manager_process_key(struct input_manager *im,
|
|||||||
return;
|
return;
|
||||||
case SDLK_i:
|
case SDLK_i:
|
||||||
if (!shift && !repeat && down) {
|
if (!shift && !repeat && down) {
|
||||||
struct fps_counter *fps_counter =
|
switch_fps_counter_state(im->fps_counter);
|
||||||
im->video_buffer->fps_counter;
|
|
||||||
switch_fps_counter_state(fps_counter);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_n:
|
case SDLK_n:
|
||||||
@@ -551,7 +561,7 @@ convert_mouse_motion(const SDL_MouseMotionEvent *from, struct screen *screen,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
input_manager_process_mouse_motion(struct input_manager *im,
|
input_manager_process_mouse_motion(struct input_manager *im,
|
||||||
const SDL_MouseMotionEvent *event) {
|
const SDL_MouseMotionEvent *event) {
|
||||||
if (!event->state) {
|
if (!event->state) {
|
||||||
@@ -605,7 +615,7 @@ convert_touch(const SDL_TouchFingerEvent *from, struct screen *screen,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
input_manager_process_touch(struct input_manager *im,
|
input_manager_process_touch(struct input_manager *im,
|
||||||
const SDL_TouchFingerEvent *event) {
|
const SDL_TouchFingerEvent *event) {
|
||||||
struct control_msg msg;
|
struct control_msg msg;
|
||||||
@@ -637,7 +647,7 @@ convert_mouse_button(const SDL_MouseButtonEvent *from, struct screen *screen,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
input_manager_process_mouse_button(struct input_manager *im,
|
input_manager_process_mouse_button(struct input_manager *im,
|
||||||
const SDL_MouseButtonEvent *event) {
|
const SDL_MouseButtonEvent *event) {
|
||||||
bool control = im->control;
|
bool control = im->control;
|
||||||
@@ -648,13 +658,15 @@ input_manager_process_mouse_button(struct input_manager *im,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool down = event->type == SDL_MOUSEBUTTONDOWN;
|
bool down = event->type == SDL_MOUSEBUTTONDOWN;
|
||||||
if (!im->forward_all_clicks && down) {
|
if (!im->forward_all_clicks) {
|
||||||
|
int action = down ? ACTION_DOWN : ACTION_UP;
|
||||||
|
|
||||||
if (control && event->button == SDL_BUTTON_RIGHT) {
|
if (control && event->button == SDL_BUTTON_RIGHT) {
|
||||||
press_back_or_turn_screen_on(im->controller);
|
press_back_or_turn_screen_on(im->controller, action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (control && event->button == SDL_BUTTON_MIDDLE) {
|
if (control && event->button == SDL_BUTTON_MIDDLE) {
|
||||||
action_home(im->controller, ACTION_DOWN | ACTION_UP);
|
action_home(im->controller, action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -667,7 +679,9 @@ input_manager_process_mouse_button(struct input_manager *im,
|
|||||||
bool outside = x < r->x || x >= r->x + r->w
|
bool outside = x < r->x || x >= r->x + r->w
|
||||||
|| y < r->y || y >= r->y + r->h;
|
|| y < r->y || y >= r->y + r->h;
|
||||||
if (outside) {
|
if (outside) {
|
||||||
screen_resize_to_fit(im->screen);
|
if (down) {
|
||||||
|
screen_resize_to_fit(im->screen);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -736,7 +750,7 @@ convert_mouse_wheel(const SDL_MouseWheelEvent *from, struct screen *screen,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
input_manager_process_mouse_wheel(struct input_manager *im,
|
input_manager_process_mouse_wheel(struct input_manager *im,
|
||||||
const SDL_MouseWheelEvent *event) {
|
const SDL_MouseWheelEvent *event) {
|
||||||
struct control_msg msg;
|
struct control_msg msg;
|
||||||
@@ -746,3 +760,46 @@ input_manager_process_mouse_wheel(struct input_manager *im,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
input_manager_handle_event(struct input_manager *im, SDL_Event *event) {
|
||||||
|
switch (event->type) {
|
||||||
|
case SDL_TEXTINPUT:
|
||||||
|
if (!im->control) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
input_manager_process_text_input(im, &event->text);
|
||||||
|
return true;
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
case SDL_KEYUP:
|
||||||
|
// some key events do not interact with the device, so process the
|
||||||
|
// event even if control is disabled
|
||||||
|
input_manager_process_key(im, &event->key);
|
||||||
|
return true;
|
||||||
|
case SDL_MOUSEMOTION:
|
||||||
|
if (!im->control) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
input_manager_process_mouse_motion(im, &event->motion);
|
||||||
|
return true;
|
||||||
|
case SDL_MOUSEWHEEL:
|
||||||
|
if (!im->control) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
input_manager_process_mouse_wheel(im, &event->wheel);
|
||||||
|
return true;
|
||||||
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
// some mouse events do not interact with the device, so process
|
||||||
|
// the event even if control is disabled
|
||||||
|
input_manager_process_mouse_button(im, &event->button);
|
||||||
|
return true;
|
||||||
|
case SDL_FINGERMOTION:
|
||||||
|
case SDL_FINGERDOWN:
|
||||||
|
case SDL_FINGERUP:
|
||||||
|
input_manager_process_touch(im, &event->tfinger);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,11 +11,10 @@
|
|||||||
#include "fps_counter.h"
|
#include "fps_counter.h"
|
||||||
#include "scrcpy.h"
|
#include "scrcpy.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "video_buffer.h"
|
|
||||||
|
|
||||||
struct input_manager {
|
struct input_manager {
|
||||||
struct controller *controller;
|
struct controller *controller;
|
||||||
struct video_buffer *video_buffer;
|
struct fps_counter *fps_counter;
|
||||||
struct screen *screen;
|
struct screen *screen;
|
||||||
|
|
||||||
// SDL reports repeated events as a boolean, but Android expects the actual
|
// SDL reports repeated events as a boolean, but Android expects the actual
|
||||||
@@ -40,28 +39,7 @@ void
|
|||||||
input_manager_init(struct input_manager *im,
|
input_manager_init(struct input_manager *im,
|
||||||
const struct scrcpy_options *options);
|
const struct scrcpy_options *options);
|
||||||
|
|
||||||
void
|
bool
|
||||||
input_manager_process_text_input(struct input_manager *im,
|
input_manager_handle_event(struct input_manager *im, SDL_Event *event);
|
||||||
const SDL_TextInputEvent *event);
|
|
||||||
|
|
||||||
void
|
|
||||||
input_manager_process_key(struct input_manager *im,
|
|
||||||
const SDL_KeyboardEvent *event);
|
|
||||||
|
|
||||||
void
|
|
||||||
input_manager_process_mouse_motion(struct input_manager *im,
|
|
||||||
const SDL_MouseMotionEvent *event);
|
|
||||||
|
|
||||||
void
|
|
||||||
input_manager_process_touch(struct input_manager *im,
|
|
||||||
const SDL_TouchFingerEvent *event);
|
|
||||||
|
|
||||||
void
|
|
||||||
input_manager_process_mouse_button(struct input_manager *im,
|
|
||||||
const SDL_MouseButtonEvent *event);
|
|
||||||
|
|
||||||
void
|
|
||||||
input_manager_process_mouse_wheel(struct input_manager *im,
|
|
||||||
const SDL_MouseWheelEvent *event);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ recorder_rescale_packet(struct recorder *recorder, AVPacket *packet) {
|
|||||||
av_packet_rescale_ts(packet, SCRCPY_TIME_BASE, ostream->time_base);
|
av_packet_rescale_ts(packet, SCRCPY_TIME_BASE, ostream->time_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
static bool
|
||||||
recorder_write(struct recorder *recorder, AVPacket *packet) {
|
recorder_write(struct recorder *recorder, AVPacket *packet) {
|
||||||
if (!recorder->header_written) {
|
if (!recorder->header_written) {
|
||||||
if (packet->pts != AV_NOPTS_VALUE) {
|
if (packet->pts != AV_NOPTS_VALUE) {
|
||||||
|
|||||||
170
app/src/scrcpy.c
170
app/src/scrcpy.c
@@ -29,28 +29,8 @@
|
|||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "util/net.h"
|
#include "util/net.h"
|
||||||
|
|
||||||
static const char *sc_scale_filter_names[SC_SCALE_FILTER__COUNT] = {
|
|
||||||
[SC_SCALE_FILTER_NONE] = "none",
|
|
||||||
[SC_SCALE_FILTER_TRILINEAR] = "trilinear",
|
|
||||||
[SC_SCALE_FILTER_BILINEAR] = "bilinear",
|
|
||||||
[SC_SCALE_FILTER_BICUBIC] = "bicubic",
|
|
||||||
[SC_SCALE_FILTER_X] = "x",
|
|
||||||
[SC_SCALE_FILTER_POINT] = "point",
|
|
||||||
[SC_SCALE_FILTER_AREA] = "area",
|
|
||||||
[SC_SCALE_FILTER_BICUBLIN] = "bicublin",
|
|
||||||
[SC_SCALE_FILTER_GAUSS] = "gauss",
|
|
||||||
[SC_SCALE_FILTER_SINC] = "sinc",
|
|
||||||
[SC_SCALE_FILTER_LANCZOS] = "lanczos",
|
|
||||||
[SC_SCALE_FILTER_SPLINE] = "spline",
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *
|
|
||||||
sc_scale_filter_name(enum sc_scale_filter scale_filter) {
|
|
||||||
return sc_scale_filter_names[scale_filter];
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct server server;
|
static struct server server;
|
||||||
static struct screen screen = SCREEN_INITIALIZER;
|
static struct screen screen;
|
||||||
static struct fps_counter fps_counter;
|
static struct fps_counter fps_counter;
|
||||||
static struct video_buffer video_buffer;
|
static struct video_buffer video_buffer;
|
||||||
static struct stream stream;
|
static struct stream stream;
|
||||||
@@ -61,7 +41,7 @@ static struct file_handler file_handler;
|
|||||||
|
|
||||||
static struct input_manager input_manager = {
|
static struct input_manager input_manager = {
|
||||||
.controller = &controller,
|
.controller = &controller,
|
||||||
.video_buffer = &video_buffer,
|
.fps_counter = &fps_counter,
|
||||||
.screen = &screen,
|
.screen = &screen,
|
||||||
.repeat = 0,
|
.repeat = 0,
|
||||||
|
|
||||||
@@ -148,30 +128,6 @@ sdl_init_and_configure(bool display, const char *render_driver,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__WINDOWS__)
|
|
||||||
# define CONTINUOUS_RESIZING_WORKAROUND
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
|
||||||
// On Windows and MacOS, resizing blocks the event loop, so resizing events are
|
|
||||||
// not triggered. As a workaround, handle them in an event handler.
|
|
||||||
//
|
|
||||||
// <https://bugzilla.libsdl.org/show_bug.cgi?id=2077>
|
|
||||||
// <https://stackoverflow.com/a/40693139/1987178>
|
|
||||||
static int
|
|
||||||
event_watcher(void *data, SDL_Event *event) {
|
|
||||||
(void) data;
|
|
||||||
if (event->type == SDL_WINDOWEVENT
|
|
||||||
&& event->window.event == SDL_WINDOWEVENT_RESIZED) {
|
|
||||||
// In practice, it seems to always be called from the same thread in
|
|
||||||
// that specific case. Anyway, it's just a workaround.
|
|
||||||
screen_render(&screen, true);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
is_apk(const char *file) {
|
is_apk(const char *file) {
|
||||||
const char *ext = strrchr(file, '.');
|
const char *ext = strrchr(file, '.');
|
||||||
@@ -193,56 +149,6 @@ handle_event(SDL_Event *event, const struct scrcpy_options *options) {
|
|||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
LOGD("User requested to quit");
|
LOGD("User requested to quit");
|
||||||
return EVENT_RESULT_STOPPED_BY_USER;
|
return EVENT_RESULT_STOPPED_BY_USER;
|
||||||
case EVENT_NEW_FRAME:
|
|
||||||
if (!screen.has_frame) {
|
|
||||||
screen.has_frame = true;
|
|
||||||
// this is the very first frame, show the window
|
|
||||||
screen_show_window(&screen);
|
|
||||||
}
|
|
||||||
if (!screen_update_frame(&screen, &video_buffer)) {
|
|
||||||
return EVENT_RESULT_CONTINUE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_WINDOWEVENT:
|
|
||||||
if (screen.has_frame) {
|
|
||||||
screen_handle_window_event(&screen, &event->window);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_TEXTINPUT:
|
|
||||||
if (!options->control) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
input_manager_process_text_input(&input_manager, &event->text);
|
|
||||||
break;
|
|
||||||
case SDL_KEYDOWN:
|
|
||||||
case SDL_KEYUP:
|
|
||||||
// some key events do not interact with the device, so process the
|
|
||||||
// event even if control is disabled
|
|
||||||
input_manager_process_key(&input_manager, &event->key);
|
|
||||||
break;
|
|
||||||
case SDL_MOUSEMOTION:
|
|
||||||
if (!options->control) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
input_manager_process_mouse_motion(&input_manager, &event->motion);
|
|
||||||
break;
|
|
||||||
case SDL_MOUSEWHEEL:
|
|
||||||
if (!options->control) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
input_manager_process_mouse_wheel(&input_manager, &event->wheel);
|
|
||||||
break;
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
// some mouse events do not interact with the device, so process
|
|
||||||
// the event even if control is disabled
|
|
||||||
input_manager_process_mouse_button(&input_manager, &event->button);
|
|
||||||
break;
|
|
||||||
case SDL_FINGERMOTION:
|
|
||||||
case SDL_FINGERDOWN:
|
|
||||||
case SDL_FINGERUP:
|
|
||||||
input_manager_process_touch(&input_manager, &event->tfinger);
|
|
||||||
break;
|
|
||||||
case SDL_DROPFILE: {
|
case SDL_DROPFILE: {
|
||||||
if (!options->control) {
|
if (!options->control) {
|
||||||
break;
|
break;
|
||||||
@@ -261,19 +167,24 @@ handle_event(SDL_Event *event, const struct scrcpy_options *options) {
|
|||||||
action = ACTION_PUSH_FILE;
|
action = ACTION_PUSH_FILE;
|
||||||
}
|
}
|
||||||
file_handler_request(&file_handler, action, file);
|
file_handler_request(&file_handler, action, file);
|
||||||
break;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool consumed = screen_handle_event(&screen, event);
|
||||||
|
if (consumed) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
consumed = input_manager_handle_event(&input_manager, event);
|
||||||
|
(void) consumed;
|
||||||
|
|
||||||
|
end:
|
||||||
return EVENT_RESULT_CONTINUE;
|
return EVENT_RESULT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
event_loop(const struct scrcpy_options *options) {
|
event_loop(const struct scrcpy_options *options) {
|
||||||
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
|
||||||
if (options->display) {
|
|
||||||
SDL_AddEventWatch(event_watcher, NULL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_WaitEvent(&event)) {
|
while (SDL_WaitEvent(&event)) {
|
||||||
enum event_result result = handle_event(&event, options);
|
enum event_result result = handle_event(&event, options);
|
||||||
@@ -342,6 +253,7 @@ scrcpy(const struct scrcpy_options *options) {
|
|||||||
bool stream_started = false;
|
bool stream_started = false;
|
||||||
bool controller_initialized = false;
|
bool controller_initialized = false;
|
||||||
bool controller_started = false;
|
bool controller_started = false;
|
||||||
|
bool screen_initialized = false;
|
||||||
|
|
||||||
bool record = !!options->record_filename;
|
bool record = !!options->record_filename;
|
||||||
struct server_params params = {
|
struct server_params params = {
|
||||||
@@ -359,6 +271,7 @@ scrcpy(const struct scrcpy_options *options) {
|
|||||||
.codec_options = options->codec_options,
|
.codec_options = options->codec_options,
|
||||||
.encoder_name = options->encoder_name,
|
.encoder_name = options->encoder_name,
|
||||||
.force_adb_forward = options->force_adb_forward,
|
.force_adb_forward = options->force_adb_forward,
|
||||||
|
.power_off_on_close = options->power_off_on_close,
|
||||||
};
|
};
|
||||||
if (!server_start(&server, options->serial, ¶ms)) {
|
if (!server_start(&server, options->serial, ¶ms)) {
|
||||||
goto end;
|
goto end;
|
||||||
@@ -392,8 +305,7 @@ scrcpy(const struct scrcpy_options *options) {
|
|||||||
}
|
}
|
||||||
fps_counter_initialized = true;
|
fps_counter_initialized = true;
|
||||||
|
|
||||||
if (!video_buffer_init(&video_buffer, &fps_counter,
|
if (!video_buffer_init(&video_buffer, options->render_expired_frames)) {
|
||||||
options->render_expired_frames)) {
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
video_buffer_initialized = true;
|
video_buffer_initialized = true;
|
||||||
@@ -426,13 +338,6 @@ scrcpy(const struct scrcpy_options *options) {
|
|||||||
|
|
||||||
stream_init(&stream, server.video_socket, dec, rec);
|
stream_init(&stream, server.video_socket, dec, rec);
|
||||||
|
|
||||||
// now we consumed the header values, the socket receives the video stream
|
|
||||||
// start the stream
|
|
||||||
if (!stream_start(&stream)) {
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
stream_started = true;
|
|
||||||
|
|
||||||
if (options->display) {
|
if (options->display) {
|
||||||
if (options->control) {
|
if (options->control) {
|
||||||
if (!controller_init(&controller, server.control_socket)) {
|
if (!controller_init(&controller, server.control_socket)) {
|
||||||
@@ -449,14 +354,25 @@ scrcpy(const struct scrcpy_options *options) {
|
|||||||
const char *window_title =
|
const char *window_title =
|
||||||
options->window_title ? options->window_title : device_name;
|
options->window_title ? options->window_title : device_name;
|
||||||
|
|
||||||
if (!screen_init_rendering(&screen, window_title, frame_size,
|
struct screen_params screen_params = {
|
||||||
options->always_on_top, options->window_x,
|
.window_title = window_title,
|
||||||
options->window_y, options->window_width,
|
.frame_size = frame_size,
|
||||||
options->window_height,
|
.always_on_top = options->always_on_top,
|
||||||
options->window_borderless,
|
.window_x = options->window_x,
|
||||||
options->rotation, options->scale_filter)) {
|
.window_y = options->window_y,
|
||||||
|
.window_width = options->window_width,
|
||||||
|
.window_height = options->window_height,
|
||||||
|
.window_borderless = options->window_borderless,
|
||||||
|
.rotation = options->rotation,
|
||||||
|
.mipmaps = options->mipmaps,
|
||||||
|
.fullscreen = options->fullscreen,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!screen_init(&screen, &video_buffer, &fps_counter,
|
||||||
|
&screen_params)) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
screen_initialized = true;
|
||||||
|
|
||||||
if (options->turn_screen_off) {
|
if (options->turn_screen_off) {
|
||||||
struct control_msg msg;
|
struct control_msg msg;
|
||||||
@@ -467,19 +383,20 @@ scrcpy(const struct scrcpy_options *options) {
|
|||||||
LOGW("Could not request 'set screen power mode'");
|
LOGW("Could not request 'set screen power mode'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->fullscreen) {
|
|
||||||
screen_switch_fullscreen(&screen);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// now we consumed the header values, the socket receives the video stream
|
||||||
|
// start the stream
|
||||||
|
if (!stream_start(&stream)) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
stream_started = true;
|
||||||
|
|
||||||
input_manager_init(&input_manager, options);
|
input_manager_init(&input_manager, options);
|
||||||
|
|
||||||
ret = event_loop(options);
|
ret = event_loop(options);
|
||||||
LOGD("quit...");
|
LOGD("quit...");
|
||||||
|
|
||||||
screen_destroy(&screen);
|
|
||||||
|
|
||||||
end:
|
end:
|
||||||
// stop stream and controller so that they don't continue once their socket
|
// stop stream and controller so that they don't continue once their socket
|
||||||
// is shutdown
|
// is shutdown
|
||||||
@@ -506,6 +423,13 @@ end:
|
|||||||
if (stream_started) {
|
if (stream_started) {
|
||||||
stream_join(&stream);
|
stream_join(&stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destroy the screen only after the stream is guaranteed to be finished,
|
||||||
|
// because otherwise the screen could receive new frames after destruction
|
||||||
|
if (screen_initialized) {
|
||||||
|
screen_destroy(&screen);
|
||||||
|
}
|
||||||
|
|
||||||
if (controller_started) {
|
if (controller_started) {
|
||||||
controller_join(&controller);
|
controller_join(&controller);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,25 +41,6 @@ struct sc_port_range {
|
|||||||
uint16_t last;
|
uint16_t last;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum sc_scale_filter {
|
|
||||||
SC_SCALE_FILTER_NONE,
|
|
||||||
SC_SCALE_FILTER_TRILINEAR, // mipmaps
|
|
||||||
SC_SCALE_FILTER_BILINEAR,
|
|
||||||
SC_SCALE_FILTER_BICUBIC,
|
|
||||||
SC_SCALE_FILTER_X,
|
|
||||||
SC_SCALE_FILTER_POINT,
|
|
||||||
SC_SCALE_FILTER_AREA,
|
|
||||||
SC_SCALE_FILTER_BICUBLIN,
|
|
||||||
SC_SCALE_FILTER_GAUSS,
|
|
||||||
SC_SCALE_FILTER_SINC,
|
|
||||||
SC_SCALE_FILTER_LANCZOS,
|
|
||||||
SC_SCALE_FILTER_SPLINE,
|
|
||||||
SC_SCALE_FILTER__COUNT,
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *
|
|
||||||
sc_scale_filter_name(enum sc_scale_filter scale_filter);
|
|
||||||
|
|
||||||
#define SC_WINDOW_POSITION_UNDEFINED (-0x8000)
|
#define SC_WINDOW_POSITION_UNDEFINED (-0x8000)
|
||||||
|
|
||||||
struct scrcpy_options {
|
struct scrcpy_options {
|
||||||
@@ -75,7 +56,6 @@ struct scrcpy_options {
|
|||||||
enum sc_record_format record_format;
|
enum sc_record_format record_format;
|
||||||
struct sc_port_range port_range;
|
struct sc_port_range port_range;
|
||||||
struct sc_shortcut_mods shortcut_mods;
|
struct sc_shortcut_mods shortcut_mods;
|
||||||
enum sc_scale_filter scale_filter;
|
|
||||||
uint16_t max_size;
|
uint16_t max_size;
|
||||||
uint32_t bit_rate;
|
uint32_t bit_rate;
|
||||||
uint16_t max_fps;
|
uint16_t max_fps;
|
||||||
@@ -95,12 +75,14 @@ struct scrcpy_options {
|
|||||||
bool render_expired_frames;
|
bool render_expired_frames;
|
||||||
bool prefer_text;
|
bool prefer_text;
|
||||||
bool window_borderless;
|
bool window_borderless;
|
||||||
|
bool mipmaps;
|
||||||
bool stay_awake;
|
bool stay_awake;
|
||||||
bool force_adb_forward;
|
bool force_adb_forward;
|
||||||
bool disable_screensaver;
|
bool disable_screensaver;
|
||||||
bool forward_key_repeat;
|
bool forward_key_repeat;
|
||||||
bool forward_all_clicks;
|
bool forward_all_clicks;
|
||||||
bool legacy_paste;
|
bool legacy_paste;
|
||||||
|
bool power_off_on_close;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SCRCPY_OPTIONS_DEFAULT { \
|
#define SCRCPY_OPTIONS_DEFAULT { \
|
||||||
@@ -122,11 +104,10 @@ struct scrcpy_options {
|
|||||||
.data = {SC_MOD_LALT, SC_MOD_LSUPER}, \
|
.data = {SC_MOD_LALT, SC_MOD_LSUPER}, \
|
||||||
.count = 2, \
|
.count = 2, \
|
||||||
}, \
|
}, \
|
||||||
.scale_filter = SC_SCALE_FILTER_TRILINEAR, \
|
.max_size = 0, \
|
||||||
.max_size = DEFAULT_MAX_SIZE, \
|
|
||||||
.bit_rate = DEFAULT_BIT_RATE, \
|
.bit_rate = DEFAULT_BIT_RATE, \
|
||||||
.max_fps = 0, \
|
.max_fps = 0, \
|
||||||
.lock_video_orientation = DEFAULT_LOCK_VIDEO_ORIENTATION, \
|
.lock_video_orientation = -1, \
|
||||||
.rotation = 0, \
|
.rotation = 0, \
|
||||||
.window_x = SC_WINDOW_POSITION_UNDEFINED, \
|
.window_x = SC_WINDOW_POSITION_UNDEFINED, \
|
||||||
.window_y = SC_WINDOW_POSITION_UNDEFINED, \
|
.window_y = SC_WINDOW_POSITION_UNDEFINED, \
|
||||||
@@ -142,12 +123,14 @@ struct scrcpy_options {
|
|||||||
.render_expired_frames = false, \
|
.render_expired_frames = false, \
|
||||||
.prefer_text = false, \
|
.prefer_text = false, \
|
||||||
.window_borderless = false, \
|
.window_borderless = false, \
|
||||||
|
.mipmaps = true, \
|
||||||
.stay_awake = false, \
|
.stay_awake = false, \
|
||||||
.force_adb_forward = false, \
|
.force_adb_forward = false, \
|
||||||
.disable_screensaver = false, \
|
.disable_screensaver = false, \
|
||||||
.forward_key_repeat = true, \
|
.forward_key_repeat = true, \
|
||||||
.forward_all_clicks = false, \
|
.forward_all_clicks = false, \
|
||||||
.legacy_paste = false, \
|
.legacy_paste = false, \
|
||||||
|
.power_off_on_close = false, \
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
323
app/src/screen.c
323
app/src/screen.c
@@ -4,7 +4,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
#include "events.h"
|
||||||
#include "icon.xpm"
|
#include "icon.xpm"
|
||||||
|
#include "scrcpy.h"
|
||||||
#include "tiny_xpm.h"
|
#include "tiny_xpm.h"
|
||||||
#include "video_buffer.h"
|
#include "video_buffer.h"
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
@@ -189,32 +191,111 @@ screen_update_content_rect(struct screen *screen) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
screen_init(struct screen *screen) {
|
on_frame_available(struct video_buffer *vb, void *userdata) {
|
||||||
*screen = (struct screen) SCREEN_INITIALIZER;
|
(void) vb;
|
||||||
|
(void) userdata;
|
||||||
|
|
||||||
|
static SDL_Event new_frame_event = {
|
||||||
|
.type = EVENT_NEW_FRAME,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Post the event on the UI thread
|
||||||
|
SDL_PushEvent(&new_frame_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
static void
|
||||||
screen_init_rendering(struct screen *screen, const char *window_title,
|
on_frame_skipped(struct video_buffer *vb, void *userdata) {
|
||||||
struct size frame_size, bool always_on_top,
|
(void) vb;
|
||||||
int16_t window_x, int16_t window_y, uint16_t window_width,
|
|
||||||
uint16_t window_height, bool window_borderless,
|
struct screen *screen = userdata;
|
||||||
uint8_t rotation, enum sc_scale_filter scale_filter) {
|
fps_counter_add_skipped_frame(screen->fps_counter);
|
||||||
screen->frame_size = frame_size;
|
}
|
||||||
screen->rotation = rotation;
|
|
||||||
if (rotation) {
|
static inline SDL_Texture *
|
||||||
LOGI("Initial display rotation set to %u", rotation);
|
create_texture(struct screen *screen) {
|
||||||
|
SDL_Renderer *renderer = screen->renderer;
|
||||||
|
struct size size = screen->frame_size;
|
||||||
|
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12,
|
||||||
|
SDL_TEXTUREACCESS_STREAMING,
|
||||||
|
size.width, size.height);
|
||||||
|
if (!texture) {
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
struct size content_size = get_rotated_size(frame_size, screen->rotation);
|
|
||||||
|
if (screen->mipmaps) {
|
||||||
|
struct sc_opengl *gl = &screen->gl;
|
||||||
|
|
||||||
|
SDL_GL_BindTexture(texture, NULL, NULL);
|
||||||
|
|
||||||
|
// Enable trilinear filtering for downscaling
|
||||||
|
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||||
|
GL_LINEAR_MIPMAP_LINEAR);
|
||||||
|
gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -1.f);
|
||||||
|
|
||||||
|
SDL_GL_UnbindTexture(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(__APPLE__) || defined(__WINDOWS__)
|
||||||
|
# define CONTINUOUS_RESIZING_WORKAROUND
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
||||||
|
// On Windows and MacOS, resizing blocks the event loop, so resizing events are
|
||||||
|
// not triggered. As a workaround, handle them in an event handler.
|
||||||
|
//
|
||||||
|
// <https://bugzilla.libsdl.org/show_bug.cgi?id=2077>
|
||||||
|
// <https://stackoverflow.com/a/40693139/1987178>
|
||||||
|
static int
|
||||||
|
event_watcher(void *data, SDL_Event *event) {
|
||||||
|
struct screen *screen = data;
|
||||||
|
if (event->type == SDL_WINDOWEVENT
|
||||||
|
&& event->window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||||
|
// In practice, it seems to always be called from the same thread in
|
||||||
|
// that specific case. Anyway, it's just a workaround.
|
||||||
|
screen_render(screen, true);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool
|
||||||
|
screen_init(struct screen *screen, struct video_buffer *vb,
|
||||||
|
struct fps_counter *fps_counter,
|
||||||
|
const struct screen_params *params) {
|
||||||
|
screen->vb = vb;
|
||||||
|
screen->fps_counter = fps_counter;
|
||||||
|
|
||||||
|
screen->resize_pending = false;
|
||||||
|
screen->has_frame = false;
|
||||||
|
screen->fullscreen = false;
|
||||||
|
screen->maximized = false;
|
||||||
|
|
||||||
|
static const struct video_buffer_callbacks cbs = {
|
||||||
|
.on_frame_available = on_frame_available,
|
||||||
|
.on_frame_skipped = on_frame_skipped,
|
||||||
|
};
|
||||||
|
video_buffer_set_consumer_callbacks(vb, &cbs, screen);
|
||||||
|
|
||||||
|
screen->frame_size = params->frame_size;
|
||||||
|
screen->rotation = params->rotation;
|
||||||
|
if (screen->rotation) {
|
||||||
|
LOGI("Initial display rotation set to %u", screen->rotation);
|
||||||
|
}
|
||||||
|
struct size content_size =
|
||||||
|
get_rotated_size(screen->frame_size, screen->rotation);
|
||||||
screen->content_size = content_size;
|
screen->content_size = content_size;
|
||||||
|
|
||||||
struct size window_size =
|
struct size window_size = get_initial_optimal_size(content_size,
|
||||||
get_initial_optimal_size(content_size, window_width, window_height);
|
params->window_width,
|
||||||
uint32_t window_flags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE;
|
params->window_height);
|
||||||
#ifdef HIDPI_SUPPORT
|
uint32_t window_flags = SDL_WINDOW_HIDDEN
|
||||||
window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
| SDL_WINDOW_RESIZABLE
|
||||||
#endif
|
| SDL_WINDOW_ALLOW_HIGHDPI;
|
||||||
if (always_on_top) {
|
if (params->always_on_top) {
|
||||||
#ifdef SCRCPY_SDL_HAS_WINDOW_ALWAYS_ON_TOP
|
#ifdef SCRCPY_SDL_HAS_WINDOW_ALWAYS_ON_TOP
|
||||||
window_flags |= SDL_WINDOW_ALWAYS_ON_TOP;
|
window_flags |= SDL_WINDOW_ALWAYS_ON_TOP;
|
||||||
#else
|
#else
|
||||||
@@ -222,15 +303,15 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
|||||||
"(compile with SDL >= 2.0.5 to enable it)");
|
"(compile with SDL >= 2.0.5 to enable it)");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (window_borderless) {
|
if (params->window_borderless) {
|
||||||
window_flags |= SDL_WINDOW_BORDERLESS;
|
window_flags |= SDL_WINDOW_BORDERLESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = window_x != SC_WINDOW_POSITION_UNDEFINED
|
int x = params->window_x != SC_WINDOW_POSITION_UNDEFINED
|
||||||
? window_x : (int) SDL_WINDOWPOS_UNDEFINED;
|
? params->window_x : (int) SDL_WINDOWPOS_UNDEFINED;
|
||||||
int y = window_y != SC_WINDOW_POSITION_UNDEFINED
|
int y = params->window_y != SC_WINDOW_POSITION_UNDEFINED
|
||||||
? window_y : (int) SDL_WINDOWPOS_UNDEFINED;
|
? params->window_y : (int) SDL_WINDOWPOS_UNDEFINED;
|
||||||
screen->window = SDL_CreateWindow(window_title, x, y,
|
screen->window = SDL_CreateWindow(params->window_title, x, y,
|
||||||
window_size.width, window_size.height,
|
window_size.width, window_size.height,
|
||||||
window_flags);
|
window_flags);
|
||||||
if (!screen->window) {
|
if (!screen->window) {
|
||||||
@@ -246,13 +327,37 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok = sc_frame_texture_init(&screen->ftex, screen->renderer,
|
SDL_RendererInfo renderer_info;
|
||||||
scale_filter, frame_size);
|
int r = SDL_GetRendererInfo(screen->renderer, &renderer_info);
|
||||||
if (!ok) {
|
const char *renderer_name = r ? NULL : renderer_info.name;
|
||||||
LOGC("Could not init frame texture");
|
LOGI("Renderer: %s", renderer_name ? renderer_name : "(unknown)");
|
||||||
SDL_DestroyRenderer(screen->renderer);
|
|
||||||
SDL_DestroyWindow(screen->window);
|
screen->mipmaps = false;
|
||||||
return false;
|
|
||||||
|
// starts with "opengl"
|
||||||
|
bool use_opengl = renderer_name && !strncmp(renderer_name, "opengl", 6);
|
||||||
|
if (use_opengl) {
|
||||||
|
struct sc_opengl *gl = &screen->gl;
|
||||||
|
sc_opengl_init(gl);
|
||||||
|
|
||||||
|
LOGI("OpenGL version: %s", gl->version);
|
||||||
|
|
||||||
|
if (params->mipmaps) {
|
||||||
|
bool supports_mipmaps =
|
||||||
|
sc_opengl_version_at_least(gl, 3, 0, /* OpenGL 3.0+ */
|
||||||
|
2, 0 /* OpenGL ES 2.0+ */);
|
||||||
|
if (supports_mipmaps) {
|
||||||
|
LOGI("Trilinear filtering enabled");
|
||||||
|
screen->mipmaps = true;
|
||||||
|
} else {
|
||||||
|
LOGW("Trilinear filtering disabled "
|
||||||
|
"(OpenGL 3.0+ or ES 2.0+ required)");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGI("Trilinear filtering disabled");
|
||||||
|
}
|
||||||
|
} else if (params->mipmaps) {
|
||||||
|
LOGD("Trilinear filtering disabled (not an OpenGL renderer)");
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface *icon = read_xpm(icon_xpm);
|
SDL_Surface *icon = read_xpm(icon_xpm);
|
||||||
@@ -263,6 +368,16 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
|||||||
LOGW("Could not load icon");
|
LOGW("Could not load icon");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGI("Initial texture: %" PRIu16 "x%" PRIu16, params->frame_size.width,
|
||||||
|
params->frame_size.height);
|
||||||
|
screen->texture = create_texture(screen);
|
||||||
|
if (!screen->texture) {
|
||||||
|
LOGC("Could not create texture: %s", SDL_GetError());
|
||||||
|
SDL_DestroyRenderer(screen->renderer);
|
||||||
|
SDL_DestroyWindow(screen->window);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Reset the window size to trigger a SIZE_CHANGED event, to workaround
|
// Reset the window size to trigger a SIZE_CHANGED event, to workaround
|
||||||
// HiDPI issues with some SDL renderers when several displays having
|
// HiDPI issues with some SDL renderers when several displays having
|
||||||
// different HiDPI scaling are connected
|
// different HiDPI scaling are connected
|
||||||
@@ -270,17 +385,25 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
|||||||
|
|
||||||
screen_update_content_rect(screen);
|
screen_update_content_rect(screen);
|
||||||
|
|
||||||
|
if (params->fullscreen) {
|
||||||
|
screen_switch_fullscreen(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
||||||
|
SDL_AddEventWatch(event_watcher, screen);
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
screen_show_window(struct screen *screen) {
|
screen_show_window(struct screen *screen) {
|
||||||
SDL_ShowWindow(screen->window);
|
SDL_ShowWindow(screen->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
screen_destroy(struct screen *screen) {
|
screen_destroy(struct screen *screen) {
|
||||||
sc_frame_texture_destroy(&screen->ftex);
|
SDL_DestroyTexture(screen->texture);
|
||||||
SDL_DestroyRenderer(screen->renderer);
|
SDL_DestroyRenderer(screen->renderer);
|
||||||
SDL_DestroyWindow(screen->window);
|
SDL_DestroyWindow(screen->window);
|
||||||
}
|
}
|
||||||
@@ -343,10 +466,13 @@ screen_set_rotation(struct screen *screen, unsigned rotation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// recreate the texture and resize the window if the frame size has changed
|
// recreate the texture and resize the window if the frame size has changed
|
||||||
static void
|
static bool
|
||||||
prepare_for_frame(struct screen *screen, struct size new_frame_size) {
|
prepare_for_frame(struct screen *screen, struct size new_frame_size) {
|
||||||
if (screen->frame_size.width != new_frame_size.width
|
if (screen->frame_size.width != new_frame_size.width
|
||||||
|| screen->frame_size.height != new_frame_size.height) {
|
|| screen->frame_size.height != new_frame_size.height) {
|
||||||
|
// frame dimension changed, destroy texture
|
||||||
|
SDL_DestroyTexture(screen->texture);
|
||||||
|
|
||||||
screen->frame_size = new_frame_size;
|
screen->frame_size = new_frame_size;
|
||||||
|
|
||||||
struct size new_content_size =
|
struct size new_content_size =
|
||||||
@@ -354,20 +480,45 @@ prepare_for_frame(struct screen *screen, struct size new_frame_size) {
|
|||||||
set_content_size(screen, new_content_size);
|
set_content_size(screen, new_content_size);
|
||||||
|
|
||||||
screen_update_content_rect(screen);
|
screen_update_content_rect(screen);
|
||||||
|
|
||||||
|
LOGI("New texture: %" PRIu16 "x%" PRIu16,
|
||||||
|
screen->frame_size.width, screen->frame_size.height);
|
||||||
|
screen->texture = create_texture(screen);
|
||||||
|
if (!screen->texture) {
|
||||||
|
LOGC("Could not create texture: %s", SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write the frame into the texture
|
||||||
|
static void
|
||||||
|
update_texture(struct screen *screen, const AVFrame *frame) {
|
||||||
|
SDL_UpdateYUVTexture(screen->texture, NULL,
|
||||||
|
frame->data[0], frame->linesize[0],
|
||||||
|
frame->data[1], frame->linesize[1],
|
||||||
|
frame->data[2], frame->linesize[2]);
|
||||||
|
|
||||||
|
if (screen->mipmaps) {
|
||||||
|
SDL_GL_BindTexture(screen->texture, NULL, NULL);
|
||||||
|
screen->gl.GenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
SDL_GL_UnbindTexture(screen->texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
static bool
|
||||||
screen_update_frame(struct screen *screen, struct video_buffer *vb) {
|
screen_update_frame(struct screen *screen) {
|
||||||
const AVFrame *frame = video_buffer_take_rendering_frame(vb);
|
const AVFrame *frame = video_buffer_consumer_take_frame(screen->vb);
|
||||||
struct size new_frame_size = {frame->width, frame->height};
|
|
||||||
prepare_for_frame(screen, new_frame_size);
|
|
||||||
|
|
||||||
struct size rect_size = {screen->rect.w, screen->rect.h};
|
fps_counter_add_rendered_frame(screen->fps_counter);
|
||||||
bool ok = sc_frame_texture_update(&screen->ftex, frame, rect_size);
|
|
||||||
if (!ok) {
|
struct size new_frame_size = {frame->width, frame->height};
|
||||||
|
if (!prepare_for_frame(screen, new_frame_size)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
update_texture(screen, frame);
|
||||||
|
|
||||||
screen_render(screen, false);
|
screen_render(screen, false);
|
||||||
return true;
|
return true;
|
||||||
@@ -377,18 +528,11 @@ void
|
|||||||
screen_render(struct screen *screen, bool update_content_rect) {
|
screen_render(struct screen *screen, bool update_content_rect) {
|
||||||
if (update_content_rect) {
|
if (update_content_rect) {
|
||||||
screen_update_content_rect(screen);
|
screen_update_content_rect(screen);
|
||||||
struct size rect_size = {screen->rect.w, screen->rect.h};
|
|
||||||
if (!sc_frame_texture_resize(&screen->ftex, rect_size)) {
|
|
||||||
// FIXME return error
|
|
||||||
LOGC("oops");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sc_frame_texture *ftex = &screen->ftex;
|
SDL_RenderClear(screen->renderer);
|
||||||
SDL_RenderClear(ftex->renderer);
|
|
||||||
if (screen->rotation == 0) {
|
if (screen->rotation == 0) {
|
||||||
SDL_RenderCopy(screen->renderer, ftex->texture, NULL,
|
SDL_RenderCopy(screen->renderer, screen->texture, NULL, &screen->rect);
|
||||||
&screen->rect);
|
|
||||||
} else {
|
} else {
|
||||||
// rotation in RenderCopyEx() is clockwise, while screen->rotation is
|
// rotation in RenderCopyEx() is clockwise, while screen->rotation is
|
||||||
// counterclockwise (to be consistent with --lock-video-orientation)
|
// counterclockwise (to be consistent with --lock-video-orientation)
|
||||||
@@ -408,10 +552,10 @@ screen_render(struct screen *screen, bool update_content_rect) {
|
|||||||
dstrect = &screen->rect;
|
dstrect = &screen->rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RenderCopyEx(screen->renderer, ftex->texture, NULL, dstrect,
|
SDL_RenderCopyEx(screen->renderer, screen->texture, NULL, dstrect,
|
||||||
angle, NULL, 0);
|
angle, NULL, 0);
|
||||||
}
|
}
|
||||||
SDL_RenderPresent(ftex->renderer);
|
SDL_RenderPresent(screen->renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -461,31 +605,52 @@ screen_resize_to_pixel_perfect(struct screen *screen) {
|
|||||||
content_size.height);
|
content_size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
screen_handle_window_event(struct screen *screen,
|
screen_handle_event(struct screen *screen, SDL_Event *event) {
|
||||||
const SDL_WindowEvent *event) {
|
switch (event->type) {
|
||||||
switch (event->event) {
|
case EVENT_NEW_FRAME:
|
||||||
case SDL_WINDOWEVENT_EXPOSED:
|
if (!screen->has_frame) {
|
||||||
screen_render(screen, true);
|
screen->has_frame = true;
|
||||||
break;
|
// this is the very first frame, show the window
|
||||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
screen_show_window(screen);
|
||||||
screen_render(screen, true);
|
|
||||||
break;
|
|
||||||
case SDL_WINDOWEVENT_MAXIMIZED:
|
|
||||||
screen->maximized = true;
|
|
||||||
break;
|
|
||||||
case SDL_WINDOWEVENT_RESTORED:
|
|
||||||
if (screen->fullscreen) {
|
|
||||||
// On Windows, in maximized+fullscreen, disabling fullscreen
|
|
||||||
// mode unexpectedly triggers the "restored" then "maximized"
|
|
||||||
// events, leaving the window in a weird state (maximized
|
|
||||||
// according to the events, but not maximized visually).
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
screen->maximized = false;
|
bool ok = screen_update_frame(screen);
|
||||||
apply_pending_resize(screen);
|
if (!ok) {
|
||||||
break;
|
LOGW("Frame update failed\n");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case SDL_WINDOWEVENT:
|
||||||
|
if (!screen->has_frame) {
|
||||||
|
// Do nothing
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch (event->window.event) {
|
||||||
|
case SDL_WINDOWEVENT_EXPOSED:
|
||||||
|
screen_render(screen, true);
|
||||||
|
break;
|
||||||
|
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||||
|
screen_render(screen, true);
|
||||||
|
break;
|
||||||
|
case SDL_WINDOWEVENT_MAXIMIZED:
|
||||||
|
screen->maximized = true;
|
||||||
|
break;
|
||||||
|
case SDL_WINDOWEVENT_RESTORED:
|
||||||
|
if (screen->fullscreen) {
|
||||||
|
// On Windows, in maximized+fullscreen, disabling
|
||||||
|
// fullscreen mode unexpectedly triggers the "restored"
|
||||||
|
// then "maximized" events, leaving the window in a
|
||||||
|
// weird state (maximized according to the events, but
|
||||||
|
// not maximized visually).
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
screen->maximized = false;
|
||||||
|
apply_pending_resize(screen);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct point
|
struct point
|
||||||
|
|||||||
@@ -8,17 +8,18 @@
|
|||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
|
|
||||||
#include "coords.h"
|
#include "coords.h"
|
||||||
#include "frame_texture.h"
|
|
||||||
#include "opengl.h"
|
#include "opengl.h"
|
||||||
#include "scrcpy.h"
|
|
||||||
|
|
||||||
struct video_buffer;
|
struct video_buffer;
|
||||||
|
|
||||||
struct screen {
|
struct screen {
|
||||||
|
struct video_buffer *vb;
|
||||||
|
struct fps_counter *fps_counter;
|
||||||
|
|
||||||
SDL_Window *window;
|
SDL_Window *window;
|
||||||
SDL_Renderer *renderer;
|
SDL_Renderer *renderer;
|
||||||
struct sc_frame_texture ftex;
|
SDL_Texture *texture;
|
||||||
|
struct sc_opengl gl;
|
||||||
struct size frame_size;
|
struct size frame_size;
|
||||||
struct size content_size; // rotated frame_size
|
struct size content_size; // rotated frame_size
|
||||||
|
|
||||||
@@ -34,64 +35,37 @@ struct screen {
|
|||||||
bool has_frame;
|
bool has_frame;
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
bool maximized;
|
bool maximized;
|
||||||
bool no_window;
|
bool mipmaps;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SCREEN_INITIALIZER { \
|
struct screen_params {
|
||||||
.window = NULL, \
|
const char *window_title;
|
||||||
.renderer = NULL, \
|
struct size frame_size;
|
||||||
.ftex = {0}, \
|
bool always_on_top;
|
||||||
.frame_size = { \
|
|
||||||
.width = 0, \
|
|
||||||
.height = 0, \
|
|
||||||
}, \
|
|
||||||
.content_size = { \
|
|
||||||
.width = 0, \
|
|
||||||
.height = 0, \
|
|
||||||
}, \
|
|
||||||
.resize_pending = false, \
|
|
||||||
.windowed_content_size = { \
|
|
||||||
.width = 0, \
|
|
||||||
.height = 0, \
|
|
||||||
}, \
|
|
||||||
.rotation = 0, \
|
|
||||||
.rect = { \
|
|
||||||
.x = 0, \
|
|
||||||
.y = 0, \
|
|
||||||
.w = 0, \
|
|
||||||
.h = 0, \
|
|
||||||
}, \
|
|
||||||
.has_frame = false, \
|
|
||||||
.fullscreen = false, \
|
|
||||||
.maximized = false, \
|
|
||||||
.no_window = false, \
|
|
||||||
}
|
|
||||||
|
|
||||||
// initialize default values
|
int16_t window_x;
|
||||||
void
|
int16_t window_y;
|
||||||
screen_init(struct screen *screen);
|
uint16_t window_width; // accepts SC_WINDOW_POSITION_UNDEFINED
|
||||||
|
uint16_t window_height; // accepts SC_WINDOW_POSITION_UNDEFINED
|
||||||
|
|
||||||
|
bool window_borderless;
|
||||||
|
|
||||||
|
uint8_t rotation;
|
||||||
|
bool mipmaps;
|
||||||
|
|
||||||
|
bool fullscreen;
|
||||||
|
};
|
||||||
|
|
||||||
// initialize screen, create window, renderer and texture (window is hidden)
|
// initialize screen, create window, renderer and texture (window is hidden)
|
||||||
// window_x and window_y accept SC_WINDOW_POSITION_UNDEFINED
|
|
||||||
bool
|
bool
|
||||||
screen_init_rendering(struct screen *screen, const char *window_title,
|
screen_init(struct screen *screen, struct video_buffer *vb,
|
||||||
struct size frame_size, bool always_on_top,
|
struct fps_counter *fps_counter,
|
||||||
int16_t window_x, int16_t window_y, uint16_t window_width,
|
const struct screen_params *params);
|
||||||
uint16_t window_height, bool window_borderless,
|
|
||||||
uint8_t rotation, enum sc_scale_filter scale_filter);
|
|
||||||
|
|
||||||
// show the window
|
|
||||||
void
|
|
||||||
screen_show_window(struct screen *screen);
|
|
||||||
|
|
||||||
// destroy window, renderer and texture (if any)
|
// destroy window, renderer and texture (if any)
|
||||||
void
|
void
|
||||||
screen_destroy(struct screen *screen);
|
screen_destroy(struct screen *screen);
|
||||||
|
|
||||||
// resize if necessary and write the rendered frame into the texture
|
|
||||||
bool
|
|
||||||
screen_update_frame(struct screen *screen, struct video_buffer *vb);
|
|
||||||
|
|
||||||
// render the texture to the renderer
|
// render the texture to the renderer
|
||||||
//
|
//
|
||||||
// Set the update_content_rect flag if the window or content size may have
|
// Set the update_content_rect flag if the window or content size may have
|
||||||
@@ -115,9 +89,9 @@ screen_resize_to_pixel_perfect(struct screen *screen);
|
|||||||
void
|
void
|
||||||
screen_set_rotation(struct screen *screen, unsigned rotation);
|
screen_set_rotation(struct screen *screen, unsigned rotation);
|
||||||
|
|
||||||
// react to window events
|
// react to SDL events
|
||||||
void
|
bool
|
||||||
screen_handle_window_event(struct screen *screen, const SDL_WindowEvent *event);
|
screen_handle_event(struct screen *screen, SDL_Event *event);
|
||||||
|
|
||||||
// convert point from window coordinates to frame coordinates
|
// convert point from window coordinates to frame coordinates
|
||||||
// x and y are expressed in pixels
|
// x and y are expressed in pixels
|
||||||
|
|||||||
@@ -293,6 +293,7 @@ execute_server(struct server *server, const struct server_params *params) {
|
|||||||
params->stay_awake ? "true" : "false",
|
params->stay_awake ? "true" : "false",
|
||||||
params->codec_options ? params->codec_options : "-",
|
params->codec_options ? params->codec_options : "-",
|
||||||
params->encoder_name ? params->encoder_name : "-",
|
params->encoder_name ? params->encoder_name : "-",
|
||||||
|
params->power_off_on_close ? "true" : "false",
|
||||||
};
|
};
|
||||||
#ifdef SERVER_DEBUGGER
|
#ifdef SERVER_DEBUGGER
|
||||||
LOGI("Server debugger waiting for a client on device port "
|
LOGI("Server debugger waiting for a client on device port "
|
||||||
@@ -375,8 +376,6 @@ server_init(struct server *server) {
|
|||||||
server->video_socket = INVALID_SOCKET;
|
server->video_socket = INVALID_SOCKET;
|
||||||
server->control_socket = INVALID_SOCKET;
|
server->control_socket = INVALID_SOCKET;
|
||||||
|
|
||||||
server->port_range.first = 0;
|
|
||||||
server->port_range.last = 0;
|
|
||||||
server->local_port = 0;
|
server->local_port = 0;
|
||||||
|
|
||||||
server->tunnel_enabled = false;
|
server->tunnel_enabled = false;
|
||||||
@@ -410,8 +409,6 @@ run_wait_server(void *data) {
|
|||||||
bool
|
bool
|
||||||
server_start(struct server *server, const char *serial,
|
server_start(struct server *server, const char *serial,
|
||||||
const struct server_params *params) {
|
const struct server_params *params) {
|
||||||
server->port_range = params->port_range;
|
|
||||||
|
|
||||||
if (serial) {
|
if (serial) {
|
||||||
server->serial = strdup(serial);
|
server->serial = strdup(serial);
|
||||||
if (!server->serial) {
|
if (!server->serial) {
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ struct server {
|
|||||||
socket_t server_socket; // only used if !tunnel_forward
|
socket_t server_socket; // only used if !tunnel_forward
|
||||||
socket_t video_socket;
|
socket_t video_socket;
|
||||||
socket_t control_socket;
|
socket_t control_socket;
|
||||||
struct sc_port_range port_range;
|
|
||||||
uint16_t local_port; // selected from port_range
|
uint16_t local_port; // selected from port_range
|
||||||
bool tunnel_enabled;
|
bool tunnel_enabled;
|
||||||
bool tunnel_forward; // use "adb forward" instead of "adb reverse"
|
bool tunnel_forward; // use "adb forward" instead of "adb reverse"
|
||||||
@@ -47,6 +46,7 @@ struct server_params {
|
|||||||
bool show_touches;
|
bool show_touches;
|
||||||
bool stay_awake;
|
bool stay_awake;
|
||||||
bool force_adb_forward;
|
bool force_adb_forward;
|
||||||
|
bool power_off_on_close;
|
||||||
};
|
};
|
||||||
|
|
||||||
// init default values
|
// init default values
|
||||||
|
|||||||
@@ -11,8 +11,6 @@
|
|||||||
#include "util/net.h"
|
#include "util/net.h"
|
||||||
#include "util/thread.h"
|
#include "util/thread.h"
|
||||||
|
|
||||||
struct video_buffer;
|
|
||||||
|
|
||||||
struct stream {
|
struct stream {
|
||||||
socket_t socket;
|
socket_t socket;
|
||||||
sc_thread thread;
|
sc_thread thread;
|
||||||
|
|||||||
@@ -7,12 +7,9 @@
|
|||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
|
|
||||||
bool
|
bool
|
||||||
video_buffer_init(struct video_buffer *vb, struct fps_counter *fps_counter,
|
video_buffer_init(struct video_buffer *vb, bool wait_consumer) {
|
||||||
bool render_expired_frames) {
|
vb->producer_frame = av_frame_alloc();
|
||||||
vb->fps_counter = fps_counter;
|
if (!vb->producer_frame) {
|
||||||
|
|
||||||
vb->decoding_frame = av_frame_alloc();
|
|
||||||
if (!vb->decoding_frame) {
|
|
||||||
goto error_0;
|
goto error_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,8 +18,8 @@ video_buffer_init(struct video_buffer *vb, struct fps_counter *fps_counter,
|
|||||||
goto error_1;
|
goto error_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
vb->rendering_frame = av_frame_alloc();
|
vb->consumer_frame = av_frame_alloc();
|
||||||
if (!vb->rendering_frame) {
|
if (!vb->consumer_frame) {
|
||||||
goto error_2;
|
goto error_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,105 +28,116 @@ video_buffer_init(struct video_buffer *vb, struct fps_counter *fps_counter,
|
|||||||
goto error_3;
|
goto error_3;
|
||||||
}
|
}
|
||||||
|
|
||||||
vb->render_expired_frames = render_expired_frames;
|
vb->wait_consumer = wait_consumer;
|
||||||
if (render_expired_frames) {
|
if (wait_consumer) {
|
||||||
ok = sc_cond_init(&vb->pending_frame_consumed_cond);
|
ok = sc_cond_init(&vb->pending_frame_consumed_cond);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
sc_mutex_destroy(&vb->mutex);
|
sc_mutex_destroy(&vb->mutex);
|
||||||
goto error_2;
|
goto error_2;
|
||||||
}
|
}
|
||||||
// interrupted is not used if expired frames are not rendered
|
// interrupted is not used if wait_consumer is disabled since offering
|
||||||
// since offering a frame will never block
|
// a frame will never block
|
||||||
vb->interrupted = false;
|
vb->interrupted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// there is initially no rendering frame, so consider it has already been
|
// there is initially no frame, so consider it has already been consumed
|
||||||
// consumed
|
|
||||||
vb->pending_frame_consumed = true;
|
vb->pending_frame_consumed = true;
|
||||||
|
|
||||||
|
// The callbacks must be set by the consumer via
|
||||||
|
// video_buffer_set_consumer_callbacks()
|
||||||
|
vb->cbs = NULL;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error_3:
|
error_3:
|
||||||
av_frame_free(&vb->rendering_frame);
|
av_frame_free(&vb->consumer_frame);
|
||||||
error_2:
|
error_2:
|
||||||
av_frame_free(&vb->pending_frame);
|
av_frame_free(&vb->pending_frame);
|
||||||
error_1:
|
error_1:
|
||||||
av_frame_free(&vb->decoding_frame);
|
av_frame_free(&vb->producer_frame);
|
||||||
error_0:
|
error_0:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
video_buffer_destroy(struct video_buffer *vb) {
|
video_buffer_destroy(struct video_buffer *vb) {
|
||||||
if (vb->render_expired_frames) {
|
if (vb->wait_consumer) {
|
||||||
sc_cond_destroy(&vb->pending_frame_consumed_cond);
|
sc_cond_destroy(&vb->pending_frame_consumed_cond);
|
||||||
}
|
}
|
||||||
sc_mutex_destroy(&vb->mutex);
|
sc_mutex_destroy(&vb->mutex);
|
||||||
av_frame_free(&vb->rendering_frame);
|
av_frame_free(&vb->consumer_frame);
|
||||||
av_frame_free(&vb->pending_frame);
|
av_frame_free(&vb->pending_frame);
|
||||||
av_frame_free(&vb->decoding_frame);
|
av_frame_free(&vb->producer_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static inline void
|
||||||
video_buffer_swap_decoding_frame(struct video_buffer *vb) {
|
swap_frames(AVFrame **lhs, AVFrame **rhs) {
|
||||||
sc_mutex_assert(&vb->mutex);
|
AVFrame *tmp = *lhs;
|
||||||
AVFrame *tmp = vb->decoding_frame;
|
*lhs = *rhs;
|
||||||
vb->decoding_frame = vb->pending_frame;
|
*rhs = tmp;
|
||||||
vb->pending_frame = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
video_buffer_swap_rendering_frame(struct video_buffer *vb) {
|
|
||||||
sc_mutex_assert(&vb->mutex);
|
|
||||||
AVFrame *tmp = vb->rendering_frame;
|
|
||||||
vb->rendering_frame = vb->pending_frame;
|
|
||||||
vb->pending_frame = tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
video_buffer_offer_decoded_frame(struct video_buffer *vb,
|
video_buffer_set_consumer_callbacks(struct video_buffer *vb,
|
||||||
bool *previous_frame_skipped) {
|
const struct video_buffer_callbacks *cbs,
|
||||||
|
void *cbs_userdata) {
|
||||||
|
assert(!vb->cbs); // must be set only once
|
||||||
|
assert(cbs);
|
||||||
|
assert(cbs->on_frame_available);
|
||||||
|
vb->cbs = cbs;
|
||||||
|
vb->cbs_userdata = cbs_userdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
video_buffer_producer_offer_frame(struct video_buffer *vb) {
|
||||||
|
assert(vb->cbs);
|
||||||
|
|
||||||
sc_mutex_lock(&vb->mutex);
|
sc_mutex_lock(&vb->mutex);
|
||||||
if (vb->render_expired_frames) {
|
if (vb->wait_consumer) {
|
||||||
// wait for the current (expired) frame to be consumed
|
// wait for the current (expired) frame to be consumed
|
||||||
while (!vb->pending_frame_consumed && !vb->interrupted) {
|
while (!vb->pending_frame_consumed && !vb->interrupted) {
|
||||||
sc_cond_wait(&vb->pending_frame_consumed_cond, &vb->mutex);
|
sc_cond_wait(&vb->pending_frame_consumed_cond, &vb->mutex);
|
||||||
}
|
}
|
||||||
} else if (!vb->pending_frame_consumed) {
|
|
||||||
fps_counter_add_skipped_frame(vb->fps_counter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
video_buffer_swap_decoding_frame(vb);
|
av_frame_unref(vb->pending_frame);
|
||||||
|
swap_frames(&vb->producer_frame, &vb->pending_frame);
|
||||||
|
|
||||||
*previous_frame_skipped = !vb->pending_frame_consumed;
|
bool skipped = !vb->pending_frame_consumed;
|
||||||
vb->pending_frame_consumed = false;
|
vb->pending_frame_consumed = false;
|
||||||
|
|
||||||
sc_mutex_unlock(&vb->mutex);
|
sc_mutex_unlock(&vb->mutex);
|
||||||
|
|
||||||
|
if (skipped) {
|
||||||
|
if (vb->cbs->on_frame_skipped)
|
||||||
|
vb->cbs->on_frame_skipped(vb, vb->cbs_userdata);
|
||||||
|
} else {
|
||||||
|
vb->cbs->on_frame_available(vb, vb->cbs_userdata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const AVFrame *
|
const AVFrame *
|
||||||
video_buffer_take_rendering_frame(struct video_buffer *vb) {
|
video_buffer_consumer_take_frame(struct video_buffer *vb) {
|
||||||
sc_mutex_lock(&vb->mutex);
|
sc_mutex_lock(&vb->mutex);
|
||||||
assert(!vb->pending_frame_consumed);
|
assert(!vb->pending_frame_consumed);
|
||||||
vb->pending_frame_consumed = true;
|
vb->pending_frame_consumed = true;
|
||||||
|
|
||||||
fps_counter_add_rendered_frame(vb->fps_counter);
|
swap_frames(&vb->consumer_frame, &vb->pending_frame);
|
||||||
|
av_frame_unref(vb->pending_frame);
|
||||||
|
|
||||||
video_buffer_swap_rendering_frame(vb);
|
if (vb->wait_consumer) {
|
||||||
|
|
||||||
if (vb->render_expired_frames) {
|
|
||||||
// unblock video_buffer_offer_decoded_frame()
|
// unblock video_buffer_offer_decoded_frame()
|
||||||
sc_cond_signal(&vb->pending_frame_consumed_cond);
|
sc_cond_signal(&vb->pending_frame_consumed_cond);
|
||||||
}
|
}
|
||||||
sc_mutex_unlock(&vb->mutex);
|
sc_mutex_unlock(&vb->mutex);
|
||||||
|
|
||||||
// rendering_frame is only written from this thread, no need to lock
|
// consumer_frame is only written from this thread, no need to lock
|
||||||
return vb->rendering_frame;
|
return vb->consumer_frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
video_buffer_interrupt(struct video_buffer *vb) {
|
video_buffer_interrupt(struct video_buffer *vb) {
|
||||||
if (vb->render_expired_frames) {
|
if (vb->wait_consumer) {
|
||||||
sc_mutex_lock(&vb->mutex);
|
sc_mutex_lock(&vb->mutex);
|
||||||
vb->interrupted = true;
|
vb->interrupted = true;
|
||||||
sc_mutex_unlock(&vb->mutex);
|
sc_mutex_unlock(&vb->mutex);
|
||||||
|
|||||||
@@ -13,53 +13,67 @@ typedef struct AVFrame AVFrame;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* There are 3 frames in memory:
|
* There are 3 frames in memory:
|
||||||
* - one frame is held by the decoder (decoding_frame)
|
* - one frame is held by the producer (producer_frame)
|
||||||
* - one frame is held by the renderer (rendering_frame)
|
* - one frame is held by the consumer (consumer_frame)
|
||||||
* - one frame is shared between the decoder and the renderer (pending_frame)
|
* - one frame is shared between the producer and the consumer (pending_frame)
|
||||||
*
|
*
|
||||||
* The decoder decodes a packet into the decoding_frame (it may takes time).
|
* The producer generates a frame into the producer_frame (it may takes time).
|
||||||
*
|
*
|
||||||
* Once the frame is decoded, it calls video_buffer_offer_decoded_frame(),
|
* Once the frame is produced, it calls video_buffer_producer_offer_frame(),
|
||||||
* which swaps the decoding and pending frames.
|
* which swaps the producer and pending frames.
|
||||||
*
|
*
|
||||||
* When the renderer is notified that a new frame is available, it calls
|
* When the consumer is notified that a new frame is available, it calls
|
||||||
* video_buffer_take_rendering_frame() to retrieve it, which swaps the pending
|
* video_buffer_consumer_take_frame() to retrieve it, which swaps the pending
|
||||||
* and rendering frames. The frame is valid until the next call, without
|
* and consumer frames. The frame is valid until the next call, without
|
||||||
* blocking the decoder.
|
* blocking the producer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct video_buffer {
|
struct video_buffer {
|
||||||
AVFrame *decoding_frame;
|
AVFrame *producer_frame;
|
||||||
AVFrame *pending_frame;
|
AVFrame *pending_frame;
|
||||||
AVFrame *rendering_frame;
|
AVFrame *consumer_frame;
|
||||||
|
|
||||||
sc_mutex mutex;
|
sc_mutex mutex;
|
||||||
bool render_expired_frames;
|
bool wait_consumer; // never overwrite a pending frame if it is not consumed
|
||||||
bool interrupted;
|
bool interrupted;
|
||||||
|
|
||||||
sc_cond pending_frame_consumed_cond;
|
sc_cond pending_frame_consumed_cond;
|
||||||
bool pending_frame_consumed;
|
bool pending_frame_consumed;
|
||||||
|
|
||||||
struct fps_counter *fps_counter;
|
const struct video_buffer_callbacks *cbs;
|
||||||
|
void *cbs_userdata;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct video_buffer_callbacks {
|
||||||
|
// Called when a new frame can be consumed by
|
||||||
|
// video_buffer_consumer_take_frame(vb)
|
||||||
|
// This callback is mandatory (it must not be NULL).
|
||||||
|
void (*on_frame_available)(struct video_buffer *vb, void *userdata);
|
||||||
|
|
||||||
|
// Called when a pending frame has been overwritten by the producer
|
||||||
|
// This callback is optional (it may be NULL).
|
||||||
|
void (*on_frame_skipped)(struct video_buffer *vb, void *userdata);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
video_buffer_init(struct video_buffer *vb, struct fps_counter *fps_counter,
|
video_buffer_init(struct video_buffer *vb, bool wait_consumer);
|
||||||
bool render_expired_frames);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
video_buffer_destroy(struct video_buffer *vb);
|
video_buffer_destroy(struct video_buffer *vb);
|
||||||
|
|
||||||
// set the decoded frame as ready for rendering
|
|
||||||
// the output flag is set to report whether the previous frame has been skipped
|
|
||||||
void
|
void
|
||||||
video_buffer_offer_decoded_frame(struct video_buffer *vb,
|
video_buffer_set_consumer_callbacks(struct video_buffer *vb,
|
||||||
bool *previous_frame_skipped);
|
const struct video_buffer_callbacks *cbs,
|
||||||
|
void *cbs_userdata);
|
||||||
|
|
||||||
// mark the rendering frame as consumed and return it
|
// set the producer frame as ready for consuming
|
||||||
|
void
|
||||||
|
video_buffer_producer_offer_frame(struct video_buffer *vb);
|
||||||
|
|
||||||
|
// mark the consumer frame as consumed and return it
|
||||||
// the frame is valid until the next call to this function
|
// the frame is valid until the next call to this function
|
||||||
const AVFrame *
|
const AVFrame *
|
||||||
video_buffer_take_rendering_frame(struct video_buffer *vb);
|
video_buffer_consumer_take_frame(struct video_buffer *vb);
|
||||||
|
|
||||||
// wake up and avoid any blocking call
|
// wake up and avoid any blocking call
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -146,14 +146,18 @@ static void test_serialize_inject_scroll_event(void) {
|
|||||||
static void test_serialize_back_or_screen_on(void) {
|
static void test_serialize_back_or_screen_on(void) {
|
||||||
struct control_msg msg = {
|
struct control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
||||||
|
.back_or_screen_on = {
|
||||||
|
.action = AKEY_EVENT_ACTION_UP,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = control_msg_serialize(&msg, buf);
|
size_t size = control_msg_serialize(&msg, buf);
|
||||||
assert(size == 1);
|
assert(size == 2);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
||||||
|
0x01, // AKEY_EVENT_ACTION_UP
|
||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
[binaries]
|
[binaries]
|
||||||
name = 'mingw'
|
name = 'mingw'
|
||||||
c = '/usr/bin/i686-w64-mingw32-gcc'
|
c = 'i686-w64-mingw32-gcc'
|
||||||
cpp = '/usr/bin/i686-w64-mingw32-g++'
|
cpp = 'i686-w64-mingw32-g++'
|
||||||
ar = '/usr/bin/i686-w64-mingw32-ar'
|
ar = 'i686-w64-mingw32-ar'
|
||||||
strip = '/usr/bin/i686-w64-mingw32-strip'
|
strip = 'i686-w64-mingw32-strip'
|
||||||
pkgconfig = '/usr/bin/i686-w64-mingw32-pkg-config'
|
pkgconfig = 'i686-w64-mingw32-pkg-config'
|
||||||
|
|
||||||
[host_machine]
|
[host_machine]
|
||||||
system = 'windows'
|
system = 'windows'
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
[binaries]
|
[binaries]
|
||||||
name = 'mingw'
|
name = 'mingw'
|
||||||
c = '/usr/bin/x86_64-w64-mingw32-gcc'
|
c = 'x86_64-w64-mingw32-gcc'
|
||||||
cpp = '/usr/bin/x86_64-w64-mingw32-g++'
|
cpp = 'x86_64-w64-mingw32-g++'
|
||||||
ar = '/usr/bin/x86_64-w64-mingw32-ar'
|
ar = 'x86_64-w64-mingw32-ar'
|
||||||
strip = '/usr/bin/x86_64-w64-mingw32-strip'
|
strip = 'x86_64-w64-mingw32-strip'
|
||||||
pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config'
|
pkgconfig = 'x86_64-w64-mingw32-pkg-config'
|
||||||
|
|
||||||
[host_machine]
|
[host_machine]
|
||||||
system = 'windows'
|
system = 'windows'
|
||||||
|
|||||||
@@ -1 +1,7 @@
|
|||||||
CreateObject("Wscript.Shell").Run "cmd /c scrcpy.exe", 0, false
|
strCommand = "cmd /c scrcpy.exe"
|
||||||
|
|
||||||
|
For Each Arg In WScript.Arguments
|
||||||
|
strCommand = strCommand & " """ & replace(Arg, """", """""""""") & """"
|
||||||
|
Next
|
||||||
|
|
||||||
|
CreateObject("Wscript.Shell").Run strCommand, 0, false
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ project('scrcpy', 'c',
|
|||||||
default_options: [
|
default_options: [
|
||||||
'c_std=c11',
|
'c_std=c11',
|
||||||
'warning_level=2',
|
'warning_level=2',
|
||||||
|
'b_ndebug=if-release',
|
||||||
])
|
])
|
||||||
|
|
||||||
if get_option('compile_app')
|
if get_option('compile_app')
|
||||||
|
|||||||
@@ -3,6 +3,5 @@ option('compile_server', type: 'boolean', value: true, description: 'Build the s
|
|||||||
option('crossbuild_windows', type: 'boolean', value: false, description: 'Build for Windows from Linux')
|
option('crossbuild_windows', type: 'boolean', value: false, description: 'Build for Windows from Linux')
|
||||||
option('prebuilt_server', type: 'string', description: 'Path of the prebuilt server')
|
option('prebuilt_server', type: 'string', description: 'Path of the prebuilt server')
|
||||||
option('portable', type: 'boolean', value: false, description: 'Use scrcpy-server from the same directory as the scrcpy executable')
|
option('portable', type: 'boolean', value: false, description: 'Use scrcpy-server from the same directory as the scrcpy executable')
|
||||||
option('hidpi_support', type: 'boolean', value: true, description: 'Enable High DPI support')
|
|
||||||
option('server_debugger', type: 'boolean', value: false, description: 'Run a server debugger and wait for a client to be attached')
|
option('server_debugger', type: 'boolean', value: false, description: 'Run a server debugger and wait for a client to be attached')
|
||||||
option('server_debugger_method', type: 'combo', choices: ['old', 'new'], value: 'new', description: 'Select the debugger method (Android < 9: "old", Android >= 9: "new")')
|
option('server_debugger_method', type: 'combo', choices: ['old', 'new'], value: 'new', description: 'Select the debugger method (Android < 9: "old", Android >= 9: "new")')
|
||||||
|
|||||||
@@ -19,19 +19,21 @@ public final class CleanUp {
|
|||||||
// not instantiable
|
// not instantiable
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void configure(boolean disableShowTouches, int restoreStayOn, boolean restoreNormalPowerMode) throws IOException {
|
public static void configure(boolean disableShowTouches, int restoreStayOn, boolean restoreNormalPowerMode, boolean powerOffScreen, int displayId)
|
||||||
boolean needProcess = disableShowTouches || restoreStayOn != -1 || restoreNormalPowerMode;
|
throws IOException {
|
||||||
|
boolean needProcess = disableShowTouches || restoreStayOn != -1 || restoreNormalPowerMode || powerOffScreen;
|
||||||
if (needProcess) {
|
if (needProcess) {
|
||||||
startProcess(disableShowTouches, restoreStayOn, restoreNormalPowerMode);
|
startProcess(disableShowTouches, restoreStayOn, restoreNormalPowerMode, powerOffScreen, displayId);
|
||||||
} else {
|
} else {
|
||||||
// There is no additional clean up to do when scrcpy dies
|
// There is no additional clean up to do when scrcpy dies
|
||||||
unlinkSelf();
|
unlinkSelf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void startProcess(boolean disableShowTouches, int restoreStayOn, boolean restoreNormalPowerMode) throws IOException {
|
private static void startProcess(boolean disableShowTouches, int restoreStayOn, boolean restoreNormalPowerMode, boolean powerOffScreen,
|
||||||
|
int displayId) throws IOException {
|
||||||
String[] cmd = {"app_process", "/", CleanUp.class.getName(), String.valueOf(disableShowTouches), String.valueOf(
|
String[] cmd = {"app_process", "/", CleanUp.class.getName(), String.valueOf(disableShowTouches), String.valueOf(
|
||||||
restoreStayOn), String.valueOf(restoreNormalPowerMode)};
|
restoreStayOn), String.valueOf(restoreNormalPowerMode), String.valueOf(powerOffScreen), String.valueOf(displayId)};
|
||||||
|
|
||||||
ProcessBuilder builder = new ProcessBuilder(cmd);
|
ProcessBuilder builder = new ProcessBuilder(cmd);
|
||||||
builder.environment().put("CLASSPATH", SERVER_PATH);
|
builder.environment().put("CLASSPATH", SERVER_PATH);
|
||||||
@@ -61,6 +63,8 @@ public final class CleanUp {
|
|||||||
boolean disableShowTouches = Boolean.parseBoolean(args[0]);
|
boolean disableShowTouches = Boolean.parseBoolean(args[0]);
|
||||||
int restoreStayOn = Integer.parseInt(args[1]);
|
int restoreStayOn = Integer.parseInt(args[1]);
|
||||||
boolean restoreNormalPowerMode = Boolean.parseBoolean(args[2]);
|
boolean restoreNormalPowerMode = Boolean.parseBoolean(args[2]);
|
||||||
|
boolean powerOffScreen = Boolean.parseBoolean(args[3]);
|
||||||
|
int displayId = Integer.parseInt(args[4]);
|
||||||
|
|
||||||
if (disableShowTouches || restoreStayOn != -1) {
|
if (disableShowTouches || restoreStayOn != -1) {
|
||||||
ServiceManager serviceManager = new ServiceManager();
|
ServiceManager serviceManager = new ServiceManager();
|
||||||
@@ -76,9 +80,12 @@ public final class CleanUp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (restoreNormalPowerMode) {
|
if (Device.isScreenOn()) {
|
||||||
Ln.i("Restoring normal power mode");
|
if (powerOffScreen) {
|
||||||
if (Device.isScreenOn()) {
|
Ln.i("Power off screen");
|
||||||
|
Device.powerOffScreen(displayId);
|
||||||
|
} else if (restoreNormalPowerMode) {
|
||||||
|
Ln.i("Restoring normal power mode");
|
||||||
Device.setScreenPowerMode(Device.POWER_MODE_NORMAL);
|
Device.setScreenPowerMode(Device.POWER_MODE_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,13 @@ public final class ControlMessage {
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ControlMessage createBackOrScreenOn(int action) {
|
||||||
|
ControlMessage msg = new ControlMessage();
|
||||||
|
msg.type = TYPE_BACK_OR_SCREEN_ON;
|
||||||
|
msg.action = action;
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
public static ControlMessage createSetClipboard(String text, boolean paste) {
|
public static ControlMessage createSetClipboard(String text, boolean paste) {
|
||||||
ControlMessage msg = new ControlMessage();
|
ControlMessage msg = new ControlMessage();
|
||||||
msg.type = TYPE_SET_CLIPBOARD;
|
msg.type = TYPE_SET_CLIPBOARD;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public class ControlMessageReader {
|
|||||||
static final int INJECT_KEYCODE_PAYLOAD_LENGTH = 13;
|
static final int INJECT_KEYCODE_PAYLOAD_LENGTH = 13;
|
||||||
static final int INJECT_TOUCH_EVENT_PAYLOAD_LENGTH = 27;
|
static final int INJECT_TOUCH_EVENT_PAYLOAD_LENGTH = 27;
|
||||||
static final int INJECT_SCROLL_EVENT_PAYLOAD_LENGTH = 20;
|
static final int INJECT_SCROLL_EVENT_PAYLOAD_LENGTH = 20;
|
||||||
|
static final int BACK_OR_SCREEN_ON_LENGTH = 1;
|
||||||
static final int SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH = 1;
|
static final int SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH = 1;
|
||||||
static final int SET_CLIPBOARD_FIXED_PAYLOAD_LENGTH = 1;
|
static final int SET_CLIPBOARD_FIXED_PAYLOAD_LENGTH = 1;
|
||||||
|
|
||||||
@@ -66,13 +67,15 @@ public class ControlMessageReader {
|
|||||||
case ControlMessage.TYPE_INJECT_SCROLL_EVENT:
|
case ControlMessage.TYPE_INJECT_SCROLL_EVENT:
|
||||||
msg = parseInjectScrollEvent();
|
msg = parseInjectScrollEvent();
|
||||||
break;
|
break;
|
||||||
|
case ControlMessage.TYPE_BACK_OR_SCREEN_ON:
|
||||||
|
msg = parseBackOrScreenOnEvent();
|
||||||
|
break;
|
||||||
case ControlMessage.TYPE_SET_CLIPBOARD:
|
case ControlMessage.TYPE_SET_CLIPBOARD:
|
||||||
msg = parseSetClipboard();
|
msg = parseSetClipboard();
|
||||||
break;
|
break;
|
||||||
case ControlMessage.TYPE_SET_SCREEN_POWER_MODE:
|
case ControlMessage.TYPE_SET_SCREEN_POWER_MODE:
|
||||||
msg = parseSetScreenPowerMode();
|
msg = parseSetScreenPowerMode();
|
||||||
break;
|
break;
|
||||||
case ControlMessage.TYPE_BACK_OR_SCREEN_ON:
|
|
||||||
case ControlMessage.TYPE_EXPAND_NOTIFICATION_PANEL:
|
case ControlMessage.TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||||
case ControlMessage.TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
case ControlMessage.TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||||
case ControlMessage.TYPE_GET_CLIPBOARD:
|
case ControlMessage.TYPE_GET_CLIPBOARD:
|
||||||
@@ -150,6 +153,14 @@ public class ControlMessageReader {
|
|||||||
return ControlMessage.createInjectScrollEvent(position, hScroll, vScroll);
|
return ControlMessage.createInjectScrollEvent(position, hScroll, vScroll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ControlMessage parseBackOrScreenOnEvent() {
|
||||||
|
if (buffer.remaining() < BACK_OR_SCREEN_ON_LENGTH) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int action = toUnsigned(buffer.get());
|
||||||
|
return ControlMessage.createBackOrScreenOn(action);
|
||||||
|
}
|
||||||
|
|
||||||
private ControlMessage parseSetClipboard() {
|
private ControlMessage parseSetClipboard() {
|
||||||
if (buffer.remaining() < SET_CLIPBOARD_FIXED_PAYLOAD_LENGTH) {
|
if (buffer.remaining() < SET_CLIPBOARD_FIXED_PAYLOAD_LENGTH) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
public class Controller {
|
public class Controller {
|
||||||
|
|
||||||
private static final int DEVICE_ID_VIRTUAL = -1;
|
private static final int DEFAULT_DEVICE_ID = 0;
|
||||||
|
|
||||||
private static final ScheduledExecutorService EXECUTOR = Executors.newSingleThreadScheduledExecutor();
|
private static final ScheduledExecutorService EXECUTOR = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ public class Controller {
|
|||||||
|
|
||||||
MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords();
|
MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords();
|
||||||
coords.orientation = 0;
|
coords.orientation = 0;
|
||||||
coords.size = 1;
|
coords.size = 0;
|
||||||
|
|
||||||
pointerProperties[i] = props;
|
pointerProperties[i] = props;
|
||||||
pointerCoords[i] = coords;
|
pointerCoords[i] = coords;
|
||||||
@@ -101,7 +101,7 @@ public class Controller {
|
|||||||
break;
|
break;
|
||||||
case ControlMessage.TYPE_BACK_OR_SCREEN_ON:
|
case ControlMessage.TYPE_BACK_OR_SCREEN_ON:
|
||||||
if (device.supportsInputEvents()) {
|
if (device.supportsInputEvents()) {
|
||||||
pressBackOrTurnScreenOn();
|
pressBackOrTurnScreenOn(msg.getAction());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ControlMessage.TYPE_EXPAND_NOTIFICATION_PANEL:
|
case ControlMessage.TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||||
@@ -208,9 +208,13 @@ public class Controller {
|
|||||||
// Right-click and middle-click only work if the source is a mouse
|
// Right-click and middle-click only work if the source is a mouse
|
||||||
boolean nonPrimaryButtonPressed = (buttons & ~MotionEvent.BUTTON_PRIMARY) != 0;
|
boolean nonPrimaryButtonPressed = (buttons & ~MotionEvent.BUTTON_PRIMARY) != 0;
|
||||||
int source = nonPrimaryButtonPressed ? InputDevice.SOURCE_MOUSE : InputDevice.SOURCE_TOUCHSCREEN;
|
int source = nonPrimaryButtonPressed ? InputDevice.SOURCE_MOUSE : InputDevice.SOURCE_TOUCHSCREEN;
|
||||||
|
if (source != InputDevice.SOURCE_MOUSE) {
|
||||||
|
// Buttons must not be set for touch events
|
||||||
|
buttons = 0;
|
||||||
|
}
|
||||||
|
|
||||||
MotionEvent event = MotionEvent
|
MotionEvent event = MotionEvent
|
||||||
.obtain(lastTouchDown, now, action, pointerCount, pointerProperties, pointerCoords, 0, buttons, 1f, 1f, DEVICE_ID_VIRTUAL, 0, source,
|
.obtain(lastTouchDown, now, action, pointerCount, pointerProperties, pointerCoords, 0, buttons, 1f, 1f, DEFAULT_DEVICE_ID, 0, source,
|
||||||
0);
|
0);
|
||||||
return device.injectEvent(event);
|
return device.injectEvent(event);
|
||||||
}
|
}
|
||||||
@@ -233,7 +237,7 @@ public class Controller {
|
|||||||
coords.setAxisValue(MotionEvent.AXIS_VSCROLL, vScroll);
|
coords.setAxisValue(MotionEvent.AXIS_VSCROLL, vScroll);
|
||||||
|
|
||||||
MotionEvent event = MotionEvent
|
MotionEvent event = MotionEvent
|
||||||
.obtain(lastTouchDown, now, MotionEvent.ACTION_SCROLL, 1, pointerProperties, pointerCoords, 0, 0, 1f, 1f, DEVICE_ID_VIRTUAL, 0,
|
.obtain(lastTouchDown, now, MotionEvent.ACTION_SCROLL, 1, pointerProperties, pointerCoords, 0, 0, 1f, 1f, DEFAULT_DEVICE_ID, 0,
|
||||||
InputDevice.SOURCE_TOUCHSCREEN, 0);
|
InputDevice.SOURCE_TOUCHSCREEN, 0);
|
||||||
return device.injectEvent(event);
|
return device.injectEvent(event);
|
||||||
}
|
}
|
||||||
@@ -251,12 +255,22 @@ public class Controller {
|
|||||||
}, 200, TimeUnit.MILLISECONDS);
|
}, 200, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean pressBackOrTurnScreenOn() {
|
private boolean pressBackOrTurnScreenOn(int action) {
|
||||||
int keycode = Device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER;
|
if (Device.isScreenOn()) {
|
||||||
if (keepPowerModeOff && keycode == KeyEvent.KEYCODE_POWER) {
|
return device.injectKeyEvent(action, KeyEvent.KEYCODE_BACK, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Screen is off
|
||||||
|
// Only press POWER on ACTION_DOWN
|
||||||
|
if (action != KeyEvent.ACTION_DOWN) {
|
||||||
|
// do nothing,
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keepPowerModeOff) {
|
||||||
schedulePowerModeOff();
|
schedulePowerModeOff();
|
||||||
}
|
}
|
||||||
return device.injectKeycode(keycode);
|
return device.injectKeycode(KeyEvent.KEYCODE_POWER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setClipboard(String text, boolean paste) {
|
private boolean setClipboard(String text, boolean paste) {
|
||||||
|
|||||||
@@ -153,13 +153,17 @@ public final class Device {
|
|||||||
return Build.MODEL;
|
return Build.MODEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean supportsInputEvents(int displayId) {
|
||||||
|
return displayId == 0 || Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean supportsInputEvents() {
|
public boolean supportsInputEvents() {
|
||||||
return supportsInputEvents;
|
return supportsInputEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean injectEvent(InputEvent inputEvent, int mode) {
|
public static boolean injectEvent(InputEvent inputEvent, int mode, int displayId) {
|
||||||
if (!supportsInputEvents()) {
|
if (!supportsInputEvents(displayId)) {
|
||||||
throw new AssertionError("Could not inject input event if !supportsInputEvents()");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (displayId != 0 && !InputManager.setDisplayId(inputEvent, displayId)) {
|
if (displayId != 0 && !InputManager.setDisplayId(inputEvent, displayId)) {
|
||||||
@@ -169,10 +173,29 @@ public final class Device {
|
|||||||
return SERVICE_MANAGER.getInputManager().injectInputEvent(inputEvent, mode);
|
return SERVICE_MANAGER.getInputManager().injectInputEvent(inputEvent, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean injectEvent(InputEvent inputEvent, int mode) {
|
||||||
|
if (!supportsInputEvents()) {
|
||||||
|
throw new AssertionError("Could not inject input event if !supportsInputEvents()");
|
||||||
|
}
|
||||||
|
|
||||||
|
return injectEvent(inputEvent, mode, displayId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean injectEventOnDisplay(InputEvent event, int displayId) {
|
||||||
|
return injectEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC, displayId);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean injectEvent(InputEvent event) {
|
public boolean injectEvent(InputEvent event) {
|
||||||
return injectEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
|
return injectEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean injectKeyEvent(int action, int keyCode, int repeat, int metaState, int displayId) {
|
||||||
|
long now = SystemClock.uptimeMillis();
|
||||||
|
KeyEvent event = new KeyEvent(now, now, action, keyCode, repeat, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
|
||||||
|
InputDevice.SOURCE_KEYBOARD);
|
||||||
|
return injectEventOnDisplay(event, displayId);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean injectKeyEvent(int action, int keyCode, int repeat, int metaState) {
|
public boolean injectKeyEvent(int action, int keyCode, int repeat, int metaState) {
|
||||||
long now = SystemClock.uptimeMillis();
|
long now = SystemClock.uptimeMillis();
|
||||||
KeyEvent event = new KeyEvent(now, now, action, keyCode, repeat, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
|
KeyEvent event = new KeyEvent(now, now, action, keyCode, repeat, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
|
||||||
@@ -180,6 +203,10 @@ public final class Device {
|
|||||||
return injectEvent(event);
|
return injectEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean injectKeycode(int keyCode, int displayId) {
|
||||||
|
return injectKeyEvent(KeyEvent.ACTION_DOWN, keyCode, 0, 0, displayId) && injectKeyEvent(KeyEvent.ACTION_UP, keyCode, 0, 0, displayId);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean injectKeycode(int keyCode) {
|
public boolean injectKeycode(int keyCode) {
|
||||||
return injectKeyEvent(KeyEvent.ACTION_DOWN, keyCode, 0, 0) && injectKeyEvent(KeyEvent.ACTION_UP, keyCode, 0, 0);
|
return injectKeyEvent(KeyEvent.ACTION_DOWN, keyCode, 0, 0) && injectKeyEvent(KeyEvent.ACTION_UP, keyCode, 0, 0);
|
||||||
}
|
}
|
||||||
@@ -249,6 +276,13 @@ public final class Device {
|
|||||||
return SurfaceControl.setDisplayPowerMode(d, mode);
|
return SurfaceControl.setDisplayPowerMode(d, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean powerOffScreen(int displayId) {
|
||||||
|
if (!isScreenOn()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return injectKeycode(KeyEvent.KEYCODE_POWER, displayId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable auto-rotation (if enabled), set the screen rotation and re-enable auto-rotation (if it was enabled).
|
* Disable auto-rotation (if enabled), set the screen rotation and re-enable auto-rotation (if it was enabled).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class Options {
|
|||||||
private boolean stayAwake;
|
private boolean stayAwake;
|
||||||
private String codecOptions;
|
private String codecOptions;
|
||||||
private String encoderName;
|
private String encoderName;
|
||||||
|
private boolean powerOffScreenOnClose;
|
||||||
|
|
||||||
public Ln.Level getLogLevel() {
|
public Ln.Level getLogLevel() {
|
||||||
return logLevel;
|
return logLevel;
|
||||||
@@ -129,4 +130,12 @@ public class Options {
|
|||||||
public void setEncoderName(String encoderName) {
|
public void setEncoderName(String encoderName) {
|
||||||
this.encoderName = encoderName;
|
this.encoderName = encoderName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPowerOffScreenOnClose(boolean powerOffScreenOnClose) {
|
||||||
|
this.powerOffScreenOnClose = powerOffScreenOnClose;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getPowerOffScreenOnClose() {
|
||||||
|
return this.powerOffScreenOnClose;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public final class Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CleanUp.configure(mustDisableShowTouchesOnCleanUp, restoreStayOn, true);
|
CleanUp.configure(mustDisableShowTouchesOnCleanUp, restoreStayOn, true, options.getPowerOffScreenOnClose(), options.getDisplayId());
|
||||||
|
|
||||||
boolean tunnelForward = options.isTunnelForward();
|
boolean tunnelForward = options.isTunnelForward();
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ public final class Server {
|
|||||||
"The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")");
|
"The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
final int expectedParameters = 15;
|
final int expectedParameters = 16;
|
||||||
if (args.length != expectedParameters) {
|
if (args.length != expectedParameters) {
|
||||||
throw new IllegalArgumentException("Expecting " + expectedParameters + " parameters");
|
throw new IllegalArgumentException("Expecting " + expectedParameters + " parameters");
|
||||||
}
|
}
|
||||||
@@ -185,6 +185,9 @@ public final class Server {
|
|||||||
String encoderName = "-".equals(args[14]) ? null : args[14];
|
String encoderName = "-".equals(args[14]) ? null : args[14];
|
||||||
options.setEncoderName(encoderName);
|
options.setEncoderName(encoderName);
|
||||||
|
|
||||||
|
boolean powerOffScreenOnClose = Boolean.parseBoolean(args[15]);
|
||||||
|
options.setPowerOffScreenOnClose(powerOffScreenOnClose);
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,7 +233,7 @@ public final class Server {
|
|||||||
if (encoders != null && encoders.length > 0) {
|
if (encoders != null && encoders.length > 0) {
|
||||||
Ln.e("Try to use one of the available encoders:");
|
Ln.e("Try to use one of the available encoders:");
|
||||||
for (MediaCodecInfo encoder : encoders) {
|
for (MediaCodecInfo encoder : encoders) {
|
||||||
Ln.e(" scrcpy --encoder-name '" + encoder.getName() + "'");
|
Ln.e(" scrcpy --encoder '" + encoder.getName() + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ public class ControlMessageReaderTest {
|
|||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
DataOutputStream dos = new DataOutputStream(bos);
|
DataOutputStream dos = new DataOutputStream(bos);
|
||||||
dos.writeByte(ControlMessage.TYPE_BACK_OR_SCREEN_ON);
|
dos.writeByte(ControlMessage.TYPE_BACK_OR_SCREEN_ON);
|
||||||
|
dos.writeByte(KeyEvent.ACTION_UP);
|
||||||
|
|
||||||
byte[] packet = bos.toByteArray();
|
byte[] packet = bos.toByteArray();
|
||||||
|
|
||||||
@@ -161,6 +162,7 @@ public class ControlMessageReaderTest {
|
|||||||
ControlMessage event = reader.next();
|
ControlMessage event = reader.next();
|
||||||
|
|
||||||
Assert.assertEquals(ControlMessage.TYPE_BACK_OR_SCREEN_ON, event.getType());
|
Assert.assertEquals(ControlMessage.TYPE_BACK_OR_SCREEN_ON, event.getType());
|
||||||
|
Assert.assertEquals(KeyEvent.ACTION_DOWN, event.getAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user