Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
b47e3ec018 |
8
FAQ.md
8
FAQ.md
@ -159,8 +159,6 @@ In developer options, enable:
|
||||
> **USB debugging (Security settings)**
|
||||
> _Allow granting permissions and simulating input via USB debugging_
|
||||
|
||||
Rebooting the device is necessary once this option is set.
|
||||
|
||||
[simulating input]: https://github.com/Genymobile/scrcpy/issues/70#issuecomment-373286323
|
||||
|
||||
|
||||
@ -170,12 +168,12 @@ The default text injection method is [limited to ASCII characters][text-input].
|
||||
A trick allows to also inject some [accented characters][accented-characters],
|
||||
but that's all. See [#37].
|
||||
|
||||
It is also possible to simulate a [physical keyboard][hid] (HID).
|
||||
Since scrcpy v1.20, it is possible to simulate a [physical keyboard][hid] (HID).
|
||||
|
||||
[text-input]: https://github.com/Genymobile/scrcpy/issues?q=is%3Aopen+is%3Aissue+label%3Aunicode
|
||||
[accented-characters]: https://blog.rom1v.com/2018/03/introducing-scrcpy/#handle-accented-characters
|
||||
[#37]: https://github.com/Genymobile/scrcpy/issues/37
|
||||
[hid]: doc/hid-otg.md
|
||||
[hid]: README.md#physical-keyboard-simulation-hid
|
||||
|
||||
|
||||
## Client issues
|
||||
@ -231,4 +229,4 @@ Translations of this FAQ in other languages are available in the [wiki].
|
||||
|
||||
[wiki]: https://github.com/Genymobile/scrcpy/wiki
|
||||
|
||||
Only this FAQ file is guaranteed to be up-to-date.
|
||||
Only this README file is guaranteed to be up-to-date.
|
||||
|
22
README.md
22
README.md
@ -1,11 +1,11 @@
|
||||
# scrcpy (v2.1.1)
|
||||
# scrcpy (v2.0)
|
||||
|
||||
<img src="app/data/icon.svg" width="128" height="128" alt="scrcpy" align="right" />
|
||||
|
||||
_pronounced "**scr**een **c**o**py**"_
|
||||
|
||||
This application mirrors Android devices (video and audio) connected via
|
||||
USB or [over TCP/IP](doc/connection.md#tcpip-wireless), and allows to control the
|
||||
USB or [over TCP/IP](doc/device.md#tcpip-wireless), and allows to control the
|
||||
device with the keyboard and the mouse of the computer. It does not require any
|
||||
_root_ access. It works on _Linux_, _Windows_ and _macOS_.
|
||||
|
||||
@ -30,7 +30,7 @@ Its features include:
|
||||
- mirroring with [Android device screen off](doc/device.md#turn-screen-off)
|
||||
- [copy-paste](doc/control.md#copy-paste) in both directions
|
||||
- [configurable quality](doc/video.md)
|
||||
- Android device screen [as a webcam (V4L2)](doc/v4l2.md) (Linux-only)
|
||||
- Android device [as a webcam (V4L2)](doc/v4l2.md) (Linux-only)
|
||||
- [physical keyboard/mouse simulation (HID)](doc/hid-otg.md)
|
||||
- [OTG mode](doc/hid-otg.md#otg)
|
||||
- and more…
|
||||
@ -39,7 +39,7 @@ Its features include:
|
||||
|
||||
The Android device requires at least API 21 (Android 5.0).
|
||||
|
||||
[Audio forwarding](doc/audio.md) is supported for API >= 30 (Android 11+).
|
||||
[Audio forwarding](doc/audio.md) is supported from API 30 (Android 11).
|
||||
|
||||
Make sure you [enabled USB debugging][enable-adb] on your device(s).
|
||||
|
||||
@ -47,14 +47,10 @@ Make sure you [enabled USB debugging][enable-adb] on your device(s).
|
||||
|
||||
On some devices, you also need to enable [an additional option][control] `USB
|
||||
debugging (Security Settings)` (this is an item different from `USB debugging`)
|
||||
to control it using a keyboard and mouse. Rebooting the device is necessary once
|
||||
this option is set.
|
||||
to control it using a keyboard and mouse.
|
||||
|
||||
[control]: https://github.com/Genymobile/scrcpy/issues/70#issuecomment-373286323
|
||||
|
||||
Note that USB debugging is not required to run scrcpy in [OTG
|
||||
mode](doc/hid-otg.md#otg).
|
||||
|
||||
|
||||
## Get the app
|
||||
|
||||
@ -68,11 +64,10 @@ mode](doc/hid-otg.md#otg).
|
||||
The application provides a lot of features and configuration options. They are
|
||||
documented in the following pages:
|
||||
|
||||
- [Connection](doc/connection.md)
|
||||
- [Device](doc/device.md)
|
||||
- [Video](doc/video.md)
|
||||
- [Audio](doc/audio.md)
|
||||
- [Control](doc/control.md)
|
||||
- [Device](doc/device.md)
|
||||
- [Window](doc/window.md)
|
||||
- [Recording](doc/recording.md)
|
||||
- [Tunnels](doc/tunnels.md)
|
||||
@ -118,10 +113,7 @@ For general questions or discussions, you can also use:
|
||||
I'm [@rom1v](https://github.com/rom1v), the author and maintainer of _scrcpy_.
|
||||
|
||||
If you appreciate this application, you can [support my open source
|
||||
work][donate]:
|
||||
- [GitHub Sponsors](https://github.com/sponsors/rom1v)
|
||||
- [Liberapay](https://liberapay.com/rom1v/)
|
||||
- [PayPal](https://paypal.me/rom2v)
|
||||
work][donate].
|
||||
|
||||
[donate]: https://blog.rom1v.com/about/#support-my-open-source-work
|
||||
|
||||
|
@ -23,8 +23,6 @@ _scrcpy() {
|
||||
--kill-adb-on-close
|
||||
-K --hid-keyboard
|
||||
--legacy-paste
|
||||
--list-camera-sizes
|
||||
--list-cameras
|
||||
--list-displays
|
||||
--list-encoders
|
||||
--lock-video-orientation
|
||||
@ -46,8 +44,6 @@ _scrcpy() {
|
||||
--no-video-playback
|
||||
--otg
|
||||
-p --port=
|
||||
--pause-on-exit
|
||||
--pause-on-exit=
|
||||
--power-off-on-close
|
||||
--prefer-text
|
||||
--print-fps
|
||||
@ -101,10 +97,6 @@ _scrcpy() {
|
||||
COMPREPLY=($(compgen -W 'unlocked initial 0 1 2 3' -- "$cur"))
|
||||
return
|
||||
;;
|
||||
--pause-on-exit)
|
||||
COMPREPLY=($(compgen -W 'true false if-error' -- "$cur"))
|
||||
return
|
||||
;;
|
||||
-r|--record)
|
||||
COMPREPLY=($(compgen -f -- "$cur"))
|
||||
return
|
||||
|
@ -1,2 +1,4 @@
|
||||
@echo off
|
||||
scrcpy.exe --pause-on-exit=if-error %*
|
||||
scrcpy.exe %*
|
||||
:: if the exit code is >= 1, then pause
|
||||
if errorlevel 1 pause
|
||||
|
@ -5,7 +5,7 @@ Comment=Display and control your Android device
|
||||
# For some users, the PATH or ADB environment variables are set from the shell
|
||||
# startup file, like .bashrc or .zshrc… Run an interactive shell to get
|
||||
# environment correctly initialized.
|
||||
Exec=/bin/sh -c "\"\\$SHELL\" -i -c scrcpy --pause-on-exit=if-error"
|
||||
Exec=/bin/bash --norc --noprofile -i -c "\"\\$SHELL\" -i -c scrcpy || read -p 'Press Enter to quit...'"
|
||||
Icon=scrcpy
|
||||
Terminal=true
|
||||
Type=Application
|
||||
|
@ -30,8 +30,6 @@ arguments=(
|
||||
'--kill-adb-on-close[Kill adb when scrcpy terminates]'
|
||||
{-K,--hid-keyboard}'[Simulate a physical keyboard by using HID over AOAv2]'
|
||||
'--legacy-paste[Inject computer clipboard text as a sequence of key events on Ctrl+v]'
|
||||
'--list-camera-sizes[List the valid camera capture sizes]'
|
||||
'--list-cameras[List cameras available on the device]'
|
||||
'--list-displays[List displays available on the device]'
|
||||
'--list-encoders[List video and audio encoders available on the device]'
|
||||
'--lock-video-orientation=[Lock video orientation]:orientation:(unlocked initial 0 1 2 3)'
|
||||
@ -52,7 +50,6 @@ arguments=(
|
||||
'--no-video-playback[Disable video playback]'
|
||||
'--otg[Run in OTG mode \(simulating physical keyboard and mouse\)]'
|
||||
{-p,--port=}'[\[port\[\:port\]\] Set the TCP port \(range\) used by the client to listen]'
|
||||
'--pause-on-exit=[Make scrcpy pause before exiting]:mode:(true false if-error)'
|
||||
'--power-off-on-close[Turn the device screen off when closing scrcpy]'
|
||||
'--prefer-text[Inject alpha characters and space as text events instead of key events]'
|
||||
'--print-fps[Start FPS counter, to print frame logs to the console]'
|
||||
|
@ -6,10 +6,10 @@ cd "$DIR"
|
||||
mkdir -p "$PREBUILT_DATA_DIR"
|
||||
cd "$PREBUILT_DATA_DIR"
|
||||
|
||||
DEP_DIR=platform-tools-34.0.3
|
||||
DEP_DIR=platform-tools-34.0.1
|
||||
|
||||
FILENAME=platform-tools_r34.0.3-windows.zip
|
||||
SHA256SUM=fce992e93eb786fc9f47df93d83a7b912c46742d45c39d712c02e06d05b72e2b
|
||||
FILENAME=platform-tools_r34.0.1-windows.zip
|
||||
SHA256SUM=5dd9c2be744c224fa3a7cbe30ba02d2cb378c763bd0f797a7e47e9f3156a5daa
|
||||
|
||||
if [[ -d "$DEP_DIR" ]]
|
||||
then
|
||||
|
@ -13,7 +13,7 @@ BEGIN
|
||||
VALUE "LegalCopyright", "Romain Vimont, Genymobile"
|
||||
VALUE "OriginalFilename", "scrcpy.exe"
|
||||
VALUE "ProductName", "scrcpy"
|
||||
VALUE "ProductVersion", "2.1.1"
|
||||
VALUE "ProductVersion", "2.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
20
app/scrcpy.1
20
app/scrcpy.1
@ -21,7 +21,7 @@ Make scrcpy window always on top (above other windows).
|
||||
|
||||
.TP
|
||||
.BI "\-\-audio\-bit\-rate " value
|
||||
Encode the audio at the given bit rate, expressed in bits/s. Unit suffixes are supported: '\fBK\fR' (x1000) and '\fBM\fR' (x1000000).
|
||||
Encode the audio at the given bit\-rate, expressed in bits/s. Unit suffixes are supported: '\fBK\fR' (x1000) and '\fBM\fR' (x1000000).
|
||||
|
||||
Default is 128K (128000).
|
||||
|
||||
@ -71,7 +71,7 @@ Default is 5.
|
||||
|
||||
.TP
|
||||
.BI "\-b, \-\-video\-bit\-rate " value
|
||||
Encode the video at the given bit rate, expressed in bits/s. Unit suffixes are supported: '\fBK\fR' (x1000) and '\fBM\fR' (x1000000).
|
||||
Encode the video at the given bit\-rate, expressed in bits/s. Unit suffixes are supported: '\fBK\fR' (x1000) and '\fBM\fR' (x1000000).
|
||||
|
||||
Default is 8M (8000000).
|
||||
|
||||
@ -155,12 +155,6 @@ Inject computer clipboard text as a sequence of key events on Ctrl+v (like MOD+S
|
||||
|
||||
This is a workaround for some devices not behaving as expected when setting the device clipboard programmatically.
|
||||
|
||||
.B \-\-list\-camera\-sizes
|
||||
List the valid camera capture sizes.
|
||||
|
||||
.B \-\-list\-cameras
|
||||
List cameras available on the device.
|
||||
|
||||
.TP
|
||||
.B \-\-list\-encoders
|
||||
List video and audio encoders available on the device.
|
||||
@ -273,16 +267,6 @@ Set the TCP port (range) used by the client to listen.
|
||||
|
||||
Default is 27183:27199.
|
||||
|
||||
.TP
|
||||
\fB\-\-pause\-on\-exit\fR[=\fImode\fR]
|
||||
Configure pause on exit. Possible values are "true" (always pause on exit), "false" (never pause on exit) and "if-error" (pause only if an error occured).
|
||||
|
||||
This is useful to prevent the terminal window from automatically closing, so that error messages can be read.
|
||||
|
||||
Default is "false".
|
||||
|
||||
Passing the option without argument is equivalent to passing "true".
|
||||
|
||||
.TP
|
||||
.B \-\-power\-off\-on\-close
|
||||
Turn the device screen off when closing scrcpy.
|
||||
|
@ -70,7 +70,7 @@ argv_to_string(const char *const *argv, char *buf, size_t bufsize) {
|
||||
}
|
||||
|
||||
static void
|
||||
show_adb_installation_msg(void) {
|
||||
show_adb_installation_msg() {
|
||||
#ifndef __WINDOWS__
|
||||
static const struct {
|
||||
const char *binary;
|
||||
@ -628,8 +628,8 @@ sc_adb_select_device(struct sc_intr *intr,
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGI("ADB device found:");
|
||||
sc_adb_devices_log(SC_LOG_LEVEL_INFO, vec.data, vec.size);
|
||||
LOGD("ADB device found:");
|
||||
sc_adb_devices_log(SC_LOG_LEVEL_DEBUG, vec.data, vec.size);
|
||||
|
||||
// Move devics into out_device (do not destroy device)
|
||||
sc_adb_device_move(out_device, device);
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "util/log.h"
|
||||
#include "util/str.h"
|
||||
|
||||
static bool
|
||||
bool
|
||||
sc_adb_parse_device(char *line, struct sc_adb_device *device) {
|
||||
// One device line looks like:
|
||||
// "0123456789abcdef device usb:2-1 product:MyProduct model:MyModel "
|
||||
|
209
app/src/cli.c
209
app/src/cli.c
@ -76,15 +76,9 @@ enum {
|
||||
OPT_NO_VIDEO,
|
||||
OPT_NO_AUDIO_PLAYBACK,
|
||||
OPT_NO_VIDEO_PLAYBACK,
|
||||
OPT_VIDEO_SOURCE,
|
||||
OPT_AUDIO_SOURCE,
|
||||
OPT_KILL_ADB_ON_CLOSE,
|
||||
OPT_TIME_LIMIT,
|
||||
OPT_PAUSE_ON_EXIT,
|
||||
OPT_LIST_CAMERAS,
|
||||
OPT_LIST_CAMERA_SIZES,
|
||||
OPT_CAMERA_ID,
|
||||
OPT_CAMERA_SIZE,
|
||||
};
|
||||
|
||||
struct sc_option {
|
||||
@ -130,7 +124,7 @@ static const struct sc_option options[] = {
|
||||
.longopt_id = OPT_AUDIO_BIT_RATE,
|
||||
.longopt = "audio-bit-rate",
|
||||
.argdesc = "value",
|
||||
.text = "Encode the audio at the given bit rate, expressed in bits/s. "
|
||||
.text = "Encode the audio at the given bit-rate, expressed in bits/s. "
|
||||
"Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
|
||||
"Default is 128K (128000).",
|
||||
},
|
||||
@ -191,7 +185,7 @@ static const struct sc_option options[] = {
|
||||
.shortopt = 'b',
|
||||
.longopt = "video-bit-rate",
|
||||
.argdesc = "value",
|
||||
.text = "Encode the video at the given bit rate, expressed in bits/s. "
|
||||
.text = "Encode the video at the given bit-rate, expressed in bits/s. "
|
||||
"Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
|
||||
"Default is 8M (8000000).",
|
||||
},
|
||||
@ -201,22 +195,6 @@ static const struct sc_option options[] = {
|
||||
.longopt = "bit-rate",
|
||||
.argdesc = "value",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_CAMERA_ID,
|
||||
.longopt = "camera",
|
||||
.argdesc = "id",
|
||||
.text = "Specify the device camera id to mirror when using "
|
||||
"--video-source=camera.\n"
|
||||
"The available camera ids can be listed by:\n"
|
||||
" scrcpy --list-cameras\n"
|
||||
"Default is \"auto\" (the first one)",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_CAMERA_SIZE,
|
||||
.longopt = "camera-size",
|
||||
.argdesc = "<width>x<height>",
|
||||
.text = "Specify an explicit camera capture size.",
|
||||
},
|
||||
{
|
||||
// Not really deprecated (--codec has never been released), but without
|
||||
// declaring an explicit --codec option, getopt_long() partial matching
|
||||
@ -334,16 +312,6 @@ static const struct sc_option options[] = {
|
||||
"This is a workaround for some devices not behaving as "
|
||||
"expected when setting the device clipboard programmatically.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_LIST_CAMERAS,
|
||||
.longopt = "list-cameras",
|
||||
.text = "List device cameras.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_LIST_CAMERA_SIZES,
|
||||
.longopt = "list-camera-sizes",
|
||||
.text = "List the valid camera capture sizes.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_LIST_DISPLAYS,
|
||||
.longopt = "list-displays",
|
||||
@ -495,20 +463,6 @@ static const struct sc_option options[] = {
|
||||
"Default is " STR(DEFAULT_LOCAL_PORT_RANGE_FIRST) ":"
|
||||
STR(DEFAULT_LOCAL_PORT_RANGE_LAST) ".",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_PAUSE_ON_EXIT,
|
||||
.longopt = "pause-on-exit",
|
||||
.argdesc = "mode",
|
||||
.optional_arg = true,
|
||||
.text = "Configure pause on exit. Possible values are \"true\" (always "
|
||||
"pause on exit), \"false\" (never pause on exit) and "
|
||||
"\"if-error\" (pause only if an error occured).\n"
|
||||
"This is useful to prevent the terminal window from "
|
||||
"automatically closing, so that error messages can be read.\n"
|
||||
"Default is \"false\".\n"
|
||||
"Passing the option without argument is equivalent to passing "
|
||||
"\"true\".",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_POWER_OFF_ON_CLOSE,
|
||||
.longopt = "power-off-on-close",
|
||||
@ -715,13 +669,6 @@ static const struct sc_option options[] = {
|
||||
"codec provided by --video-codec).\n"
|
||||
"The available encoders can be listed by --list-encoders.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_VIDEO_SOURCE,
|
||||
.longopt = "video-source",
|
||||
.argdesc = "source",
|
||||
.text = "Select the video source (display or camera).\n"
|
||||
"Default is display.",
|
||||
},
|
||||
{
|
||||
.shortopt = 'w',
|
||||
.longopt = "stay-awake",
|
||||
@ -1123,7 +1070,7 @@ print_shortcut(const struct sc_shortcut *shortcut, unsigned cols) {
|
||||
while (shortcut->shortcuts[i]) {
|
||||
printf(" %s\n", shortcut->shortcuts[i]);
|
||||
++i;
|
||||
}
|
||||
};
|
||||
|
||||
char *text = sc_str_wrap_lines(shortcut->text, cols, 8);
|
||||
if (!text) {
|
||||
@ -1242,9 +1189,9 @@ parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
|
||||
}
|
||||
|
||||
static size_t
|
||||
parse_integers_arg(const char *s, const char sep, size_t max_items, long *out,
|
||||
long min, long max, const char *name) {
|
||||
size_t count = sc_str_parse_integers(s, sep, max_items, out);
|
||||
parse_integers_arg(const char *s, size_t max_items, long *out, long min,
|
||||
long max, const char *name) {
|
||||
size_t count = sc_str_parse_integers(s, ':', max_items, out);
|
||||
if (!count) {
|
||||
LOGE("Could not parse %s: %s", name, s);
|
||||
return 0;
|
||||
@ -1400,7 +1347,7 @@ parse_window_dimension(const char *s, uint16_t *dimension) {
|
||||
static bool
|
||||
parse_port_range(const char *s, struct sc_port_range *port_range) {
|
||||
long values[2];
|
||||
size_t count = parse_integers_arg(s, ':', 2, values, 0, 0xFFFF, "port");
|
||||
size_t count = parse_integers_arg(s, 2, values, 0, 0xFFFF, "port");
|
||||
if (!count) {
|
||||
return false;
|
||||
}
|
||||
@ -1662,22 +1609,6 @@ parse_audio_codec(const char *optarg, enum sc_codec *codec) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_video_source(const char *optarg, enum sc_video_source *source) {
|
||||
if (!strcmp(optarg, "display")) {
|
||||
*source = SC_VIDEO_SOURCE_DISPLAY;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!strcmp(optarg, "camera")) {
|
||||
*source = SC_VIDEO_SOURCE_CAMERA;
|
||||
return true;
|
||||
}
|
||||
|
||||
LOGE("Unsupported video source: %s (expected display or camera)", optarg);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_audio_source(const char *optarg, enum sc_audio_source *source) {
|
||||
if (!strcmp(optarg, "mic")) {
|
||||
@ -1706,29 +1637,6 @@ parse_time_limit(const char *s, sc_tick *tick) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_pause_on_exit(const char *s, enum sc_pause_on_exit *pause_on_exit) {
|
||||
if (!s || !strcmp(s, "true")) {
|
||||
*pause_on_exit = SC_PAUSE_ON_EXIT_TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!strcmp(s, "false")) {
|
||||
*pause_on_exit = SC_PAUSE_ON_EXIT_FALSE;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!strcmp(s, "if-error")) {
|
||||
*pause_on_exit = SC_PAUSE_ON_EXIT_IF_ERROR;
|
||||
return true;
|
||||
}
|
||||
|
||||
LOGE("Unsupported pause on exit mode: %s "
|
||||
"(expected true, false or if-error)", optarg);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
const char *optstring, const struct option *longopts) {
|
||||
@ -2037,16 +1945,10 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
return false;
|
||||
#endif
|
||||
case OPT_LIST_ENCODERS:
|
||||
opts->list |= SC_OPTION_LIST_ENCODERS;
|
||||
opts->list_encoders = true;
|
||||
break;
|
||||
case OPT_LIST_DISPLAYS:
|
||||
opts->list |= SC_OPTION_LIST_DISPLAYS;
|
||||
break;
|
||||
case OPT_LIST_CAMERAS:
|
||||
opts->list |= SC_OPTION_LIST_CAMERAS;
|
||||
break;
|
||||
case OPT_LIST_CAMERA_SIZES:
|
||||
opts->list |= SC_OPTION_LIST_CAMERA_SIZES;
|
||||
opts->list_displays = true;
|
||||
break;
|
||||
case OPT_REQUIRE_AUDIO:
|
||||
opts->require_audio = true;
|
||||
@ -2062,11 +1964,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_VIDEO_SOURCE:
|
||||
if (!parse_video_source(optarg, &opts->video_source)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_AUDIO_SOURCE:
|
||||
if (!parse_audio_source(optarg, &opts->audio_source)) {
|
||||
return false;
|
||||
@ -2080,17 +1977,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_PAUSE_ON_EXIT:
|
||||
if (!parse_pause_on_exit(optarg, &args->pause_on_exit)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_CAMERA_ID:
|
||||
opts->camera_id = optarg;
|
||||
break;
|
||||
case OPT_CAMERA_SIZE:
|
||||
opts->camera_size = optarg;
|
||||
break;
|
||||
default:
|
||||
// getopt prints the error message on stderr
|
||||
return false;
|
||||
@ -2136,6 +2022,12 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
opts->audio_playback = false;
|
||||
}
|
||||
|
||||
if (!opts->video_playback && !otg) {
|
||||
// If video playback is disabled and OTG are disabled, then there is
|
||||
// no way to control the device.
|
||||
opts->control = false;
|
||||
}
|
||||
|
||||
if (opts->video && !opts->video_playback && !opts->record_filename
|
||||
&& !v4l2) {
|
||||
LOGI("No video playback, no recording, no V4L2 sink: video disabled");
|
||||
@ -2184,40 +2076,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
opts->force_adb_forward = true;
|
||||
}
|
||||
|
||||
if (opts->video_source == SC_VIDEO_SOURCE_CAMERA) {
|
||||
if (opts->lock_video_orientation !=
|
||||
SC_LOCK_VIDEO_ORIENTATION_UNLOCKED) {
|
||||
LOGE("--lock-video-orientation is not supported for camera");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!opts->camera_id) {
|
||||
LOGE("Camera id must be specified by --camera=ID "
|
||||
"(list the available ids with --list-cameras)");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!opts->camera_size) {
|
||||
LOGE("Camera size must be specified by --camera-size=WIDTHxHEIGHT");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opts->control) {
|
||||
LOGI("Camera video source: control disabled");
|
||||
opts->control = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (opts->audio && opts->audio_source == SC_AUDIO_SOURCE_AUTO) {
|
||||
// Select the audio source according to the video source
|
||||
if (opts->video_source == SC_VIDEO_SOURCE_DISPLAY) {
|
||||
opts->audio_source = SC_AUDIO_SOURCE_OUTPUT;
|
||||
} else {
|
||||
opts->audio_source = SC_AUDIO_SOURCE_MIC;
|
||||
LOGI("Camera video source: microphone audio source selected");
|
||||
}
|
||||
}
|
||||
|
||||
if (opts->record_format && !opts->record_filename) {
|
||||
LOGE("Record format specified without recording");
|
||||
return false;
|
||||
@ -2338,37 +2196,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
return true;
|
||||
}
|
||||
|
||||
static enum sc_pause_on_exit
|
||||
sc_get_pause_on_exit(int argc, char *argv[]) {
|
||||
// Read arguments backwards so that the last --pause-on-exit is considered
|
||||
// (same behavior as getopt())
|
||||
for (int i = argc - 1; i >= 1; --i) {
|
||||
const char *arg = argv[i];
|
||||
// Starts with "--pause-on-exit"
|
||||
if (!strncmp("--pause-on-exit", arg, 15)) {
|
||||
if (arg[15] == '\0') {
|
||||
// No argument
|
||||
return SC_PAUSE_ON_EXIT_TRUE;
|
||||
}
|
||||
if (arg[15] != '=') {
|
||||
// Invalid parameter, ignore
|
||||
return SC_PAUSE_ON_EXIT_FALSE;
|
||||
}
|
||||
const char *value = &arg[16];
|
||||
if (!strcmp(value, "true")) {
|
||||
return SC_PAUSE_ON_EXIT_TRUE;
|
||||
}
|
||||
if (!strcmp(value, "if-error")) {
|
||||
return SC_PAUSE_ON_EXIT_IF_ERROR;
|
||||
}
|
||||
// Set to false, inclusing when the value is invalid
|
||||
return SC_PAUSE_ON_EXIT_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return SC_PAUSE_ON_EXIT_FALSE;
|
||||
}
|
||||
|
||||
bool
|
||||
scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
||||
struct sc_getopt_adapter adapter;
|
||||
@ -2382,11 +2209,5 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
||||
|
||||
sc_getopt_adapter_destroy(&adapter);
|
||||
|
||||
if (!ret && args->pause_on_exit == SC_PAUSE_ON_EXIT_FALSE) {
|
||||
// Check if "--pause-on-exit" is present in the arguments list, because
|
||||
// it must be taken into account even if command line parsing failed
|
||||
args->pause_on_exit = sc_get_pause_on_exit(argc, argv);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -7,17 +7,10 @@
|
||||
|
||||
#include "options.h"
|
||||
|
||||
enum sc_pause_on_exit {
|
||||
SC_PAUSE_ON_EXIT_TRUE,
|
||||
SC_PAUSE_ON_EXIT_FALSE,
|
||||
SC_PAUSE_ON_EXIT_IF_ERROR,
|
||||
};
|
||||
|
||||
struct scrcpy_cli_args {
|
||||
struct scrcpy_options opts;
|
||||
bool help;
|
||||
bool version;
|
||||
enum sc_pause_on_exit pause_on_exit;
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -53,7 +53,7 @@ sc_display_init(struct sc_display *display, SDL_Window *window, bool mipmaps) {
|
||||
display->mipmaps = true;
|
||||
} else {
|
||||
LOGW("Trilinear filtering disabled "
|
||||
"(OpenGL 3.0+ or ES 2.0+ required)");
|
||||
"(OpenGL 3.0+ or ES 2.0+ required");
|
||||
}
|
||||
} else {
|
||||
LOGI("Trilinear filtering disabled");
|
||||
|
@ -271,7 +271,7 @@ error:
|
||||
}
|
||||
|
||||
SDL_Surface *
|
||||
scrcpy_icon_load(void) {
|
||||
scrcpy_icon_load() {
|
||||
char *icon_path = get_icon_path();
|
||||
if (!icon_path) {
|
||||
return NULL;
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "util/str.h"
|
||||
#endif
|
||||
|
||||
static int
|
||||
int
|
||||
main_scrcpy(int argc, char *argv[]) {
|
||||
#ifdef _WIN32
|
||||
// disable buffering, we want logs immediately
|
||||
@ -39,32 +39,26 @@ main_scrcpy(int argc, char *argv[]) {
|
||||
.opts = scrcpy_options_default,
|
||||
.help = false,
|
||||
.version = false,
|
||||
.pause_on_exit = SC_PAUSE_ON_EXIT_FALSE,
|
||||
};
|
||||
|
||||
#ifndef NDEBUG
|
||||
args.opts.log_level = SC_LOG_LEVEL_DEBUG;
|
||||
#endif
|
||||
|
||||
enum scrcpy_exit_code ret;
|
||||
|
||||
if (!scrcpy_parse_args(&args, argc, argv)) {
|
||||
ret = SCRCPY_EXIT_FAILURE;
|
||||
goto end;
|
||||
return SCRCPY_EXIT_FAILURE;
|
||||
}
|
||||
|
||||
sc_set_log_level(args.opts.log_level);
|
||||
|
||||
if (args.help) {
|
||||
scrcpy_print_usage(argv[0]);
|
||||
ret = SCRCPY_EXIT_SUCCESS;
|
||||
goto end;
|
||||
return SCRCPY_EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (args.version) {
|
||||
scrcpy_print_version();
|
||||
ret = SCRCPY_EXIT_SUCCESS;
|
||||
goto end;
|
||||
return SCRCPY_EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
|
||||
@ -78,26 +72,18 @@ main_scrcpy(int argc, char *argv[]) {
|
||||
#endif
|
||||
|
||||
if (!net_init()) {
|
||||
ret = SCRCPY_EXIT_FAILURE;
|
||||
goto end;
|
||||
return SCRCPY_EXIT_FAILURE;
|
||||
}
|
||||
|
||||
sc_log_configure();
|
||||
|
||||
#ifdef HAVE_USB
|
||||
ret = args.opts.otg ? scrcpy_otg(&args.opts) : scrcpy(&args.opts);
|
||||
enum scrcpy_exit_code ret = args.opts.otg ? scrcpy_otg(&args.opts)
|
||||
: scrcpy(&args.opts);
|
||||
#else
|
||||
ret = scrcpy(&args.opts);
|
||||
enum scrcpy_exit_code ret = scrcpy(&args.opts);
|
||||
#endif
|
||||
|
||||
end:
|
||||
if (args.pause_on_exit == SC_PAUSE_ON_EXIT_TRUE ||
|
||||
(args.pause_on_exit == SC_PAUSE_ON_EXIT_IF_ERROR &&
|
||||
ret != SCRCPY_EXIT_SUCCESS)) {
|
||||
printf("Press Enter to continue...\n");
|
||||
getchar();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -11,13 +11,10 @@ const struct scrcpy_options scrcpy_options_default = {
|
||||
.audio_codec_options = NULL,
|
||||
.video_encoder = NULL,
|
||||
.audio_encoder = NULL,
|
||||
.camera_id = NULL,
|
||||
.camera_size = NULL,
|
||||
.log_level = SC_LOG_LEVEL_INFO,
|
||||
.video_codec = SC_CODEC_H264,
|
||||
.audio_codec = SC_CODEC_OPUS,
|
||||
.video_source = SC_VIDEO_SOURCE_DISPLAY,
|
||||
.audio_source = SC_AUDIO_SOURCE_AUTO,
|
||||
.audio_source = SC_AUDIO_SOURCE_OUTPUT,
|
||||
.record_format = SC_RECORD_FORMAT_AUTO,
|
||||
.keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_INJECT,
|
||||
.mouse_input_mode = SC_MOUSE_INPUT_MODE_INJECT,
|
||||
@ -82,6 +79,7 @@ const struct scrcpy_options scrcpy_options_default = {
|
||||
.video = true,
|
||||
.audio = true,
|
||||
.require_audio = false,
|
||||
.list_encoders = false,
|
||||
.list_displays = false,
|
||||
.kill_adb_on_close = false,
|
||||
.list = 0,
|
||||
};
|
||||
|
@ -44,13 +44,7 @@ enum sc_codec {
|
||||
SC_CODEC_RAW,
|
||||
};
|
||||
|
||||
enum sc_video_source {
|
||||
SC_VIDEO_SOURCE_DISPLAY,
|
||||
SC_VIDEO_SOURCE_CAMERA,
|
||||
};
|
||||
|
||||
enum sc_audio_source {
|
||||
SC_AUDIO_SOURCE_AUTO, // OUTPUT for video DISPLAY, MIC for video CAMERA
|
||||
SC_AUDIO_SOURCE_OUTPUT,
|
||||
SC_AUDIO_SOURCE_MIC,
|
||||
};
|
||||
@ -123,12 +117,9 @@ struct scrcpy_options {
|
||||
const char *audio_codec_options;
|
||||
const char *video_encoder;
|
||||
const char *audio_encoder;
|
||||
const char *camera_id;
|
||||
const char *camera_size;
|
||||
enum sc_log_level log_level;
|
||||
enum sc_codec video_codec;
|
||||
enum sc_codec audio_codec;
|
||||
enum sc_video_source video_source;
|
||||
enum sc_audio_source audio_source;
|
||||
enum sc_record_format record_format;
|
||||
enum sc_keyboard_input_mode keyboard_input_mode;
|
||||
@ -188,12 +179,9 @@ struct scrcpy_options {
|
||||
bool video;
|
||||
bool audio;
|
||||
bool require_audio;
|
||||
bool list_encoders;
|
||||
bool list_displays;
|
||||
bool kill_adb_on_close;
|
||||
#define SC_OPTION_LIST_ENCODERS 0x1
|
||||
#define SC_OPTION_LIST_DISPLAYS 0x2
|
||||
#define SC_OPTION_LIST_CAMERAS 0x4
|
||||
#define SC_OPTION_LIST_CAMERA_SIZES 0x8
|
||||
uint8_t list;
|
||||
};
|
||||
|
||||
extern const struct scrcpy_options scrcpy_options_default;
|
||||
|
@ -90,7 +90,7 @@ push_event(uint32_t type, const char *name) {
|
||||
#define PUSH_EVENT(TYPE) push_event(TYPE, # TYPE)
|
||||
|
||||
#ifdef _WIN32
|
||||
static BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) {
|
||||
BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) {
|
||||
if (ctrl_type == CTRL_C_EVENT) {
|
||||
PUSH_EVENT(SDL_QUIT);
|
||||
return TRUE;
|
||||
@ -252,9 +252,7 @@ sc_audio_demuxer_on_ended(struct sc_demuxer *demuxer,
|
||||
|
||||
// Contrary to the video demuxer, keep mirroring if only the audio fails
|
||||
// (unless --require-audio is set).
|
||||
if (status == SC_DEMUXER_STATUS_EOS) {
|
||||
PUSH_EVENT(SC_EVENT_DEVICE_DISCONNECTED);
|
||||
} else if (status == SC_DEMUXER_STATUS_ERROR
|
||||
if (status == SC_DEMUXER_STATUS_ERROR
|
||||
|| (status == SC_DEMUXER_STATUS_DISABLED
|
||||
&& options->require_audio)) {
|
||||
PUSH_EVENT(SC_EVENT_DEMUXER_ERROR);
|
||||
@ -297,7 +295,7 @@ sc_timeout_on_timeout(struct sc_timeout *timeout, void *userdata) {
|
||||
|
||||
// Generate a scrcpy id to differentiate multiple running scrcpy instances
|
||||
static uint32_t
|
||||
scrcpy_generate_scid(void) {
|
||||
scrcpy_generate_scid() {
|
||||
struct sc_rand rand;
|
||||
sc_rand_init(&rand);
|
||||
// Only use 31 bits to avoid issues with signed values on the Java-side
|
||||
@ -351,7 +349,6 @@ scrcpy(struct scrcpy_options *options) {
|
||||
.log_level = options->log_level,
|
||||
.video_codec = options->video_codec,
|
||||
.audio_codec = options->audio_codec,
|
||||
.video_source = options->video_source,
|
||||
.audio_source = options->audio_source,
|
||||
.crop = options->crop,
|
||||
.port_range = options->port_range,
|
||||
@ -372,8 +369,6 @@ scrcpy(struct scrcpy_options *options) {
|
||||
.audio_codec_options = options->audio_codec_options,
|
||||
.video_encoder = options->video_encoder,
|
||||
.audio_encoder = options->audio_encoder,
|
||||
.camera_id = options->camera_id,
|
||||
.camera_size = options->camera_size,
|
||||
.force_adb_forward = options->force_adb_forward,
|
||||
.power_off_on_close = options->power_off_on_close,
|
||||
.clipboard_autosync = options->clipboard_autosync,
|
||||
@ -382,8 +377,9 @@ scrcpy(struct scrcpy_options *options) {
|
||||
.tcpip_dst = options->tcpip_dst,
|
||||
.cleanup = options->cleanup,
|
||||
.power_on = options->power_on,
|
||||
.list_encoders = options->list_encoders,
|
||||
.list_displays = options->list_displays,
|
||||
.kill_adb_on_close = options->kill_adb_on_close,
|
||||
.list = options->list,
|
||||
};
|
||||
|
||||
static const struct sc_server_callbacks cbs = {
|
||||
@ -401,7 +397,7 @@ scrcpy(struct scrcpy_options *options) {
|
||||
|
||||
server_started = true;
|
||||
|
||||
if (options->list) {
|
||||
if (options->list_encoders || options->list_displays) {
|
||||
bool ok = await_for_server(NULL);
|
||||
ret = ok ? SCRCPY_EXIT_SUCCESS : SCRCPY_EXIT_FAILURE;
|
||||
goto end;
|
||||
@ -452,7 +448,9 @@ scrcpy(struct scrcpy_options *options) {
|
||||
|
||||
struct sc_file_pusher *fp = NULL;
|
||||
|
||||
if (options->video_playback && options->control) {
|
||||
// control implies video playback
|
||||
assert(!options->control || options->video_playback);
|
||||
if (options->control) {
|
||||
if (!sc_file_pusher_init(&s->file_pusher, serial,
|
||||
options->push_target)) {
|
||||
goto end;
|
||||
|
@ -488,7 +488,6 @@ sc_screen_show_initial_window(struct sc_screen *screen) {
|
||||
}
|
||||
|
||||
SDL_ShowWindow(screen->window);
|
||||
sc_screen_update_content_rect(screen);
|
||||
}
|
||||
|
||||
void
|
||||
@ -849,8 +848,6 @@ sc_screen_convert_drawable_to_frame_coords(struct sc_screen *screen,
|
||||
int32_t w = screen->content_size.width;
|
||||
int32_t h = screen->content_size.height;
|
||||
|
||||
// screen->rect must be initialized to avoid a division by zero
|
||||
assert(screen->rect.w && screen->rect.h);
|
||||
|
||||
x = (int64_t) (x - screen->rect.x) * w / screen->rect.w;
|
||||
y = (int64_t) (y - screen->rect.y) * h / screen->rect.h;
|
||||
|
@ -76,7 +76,6 @@ sc_server_params_destroy(struct sc_server_params *params) {
|
||||
free((char *) params->video_encoder);
|
||||
free((char *) params->audio_encoder);
|
||||
free((char *) params->tcpip_dst);
|
||||
free((char *) params->camera_id);
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -87,15 +86,14 @@ sc_server_params_copy(struct sc_server_params *dst,
|
||||
// The params reference user-allocated memory, so we must copy them to
|
||||
// handle them from another thread
|
||||
|
||||
#define COPY(FIELD) do { \
|
||||
#define COPY(FIELD) \
|
||||
dst->FIELD = NULL; \
|
||||
if (src->FIELD) { \
|
||||
dst->FIELD = strdup(src->FIELD); \
|
||||
if (!dst->FIELD) { \
|
||||
goto error; \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
}
|
||||
|
||||
COPY(req_serial);
|
||||
COPY(crop);
|
||||
@ -104,7 +102,6 @@ sc_server_params_copy(struct sc_server_params *dst,
|
||||
COPY(video_encoder);
|
||||
COPY(audio_encoder);
|
||||
COPY(tcpip_dst);
|
||||
COPY(camera_id);
|
||||
#undef COPY
|
||||
|
||||
return true;
|
||||
@ -218,13 +215,13 @@ execute_server(struct sc_server *server,
|
||||
cmd[count++] = SCRCPY_VERSION;
|
||||
|
||||
unsigned dyn_idx = count; // from there, the strings are allocated
|
||||
#define ADD_PARAM(fmt, ...) do { \
|
||||
#define ADD_PARAM(fmt, ...) { \
|
||||
char *p; \
|
||||
if (asprintf(&p, fmt, ## __VA_ARGS__) == -1) { \
|
||||
goto end; \
|
||||
} \
|
||||
cmd[count++] = p; \
|
||||
} while(0)
|
||||
}
|
||||
|
||||
ADD_PARAM("scid=%08x", params->scid);
|
||||
ADD_PARAM("log_level=%s", log_level_to_server_string(params->log_level));
|
||||
@ -249,11 +246,8 @@ execute_server(struct sc_server *server,
|
||||
ADD_PARAM("audio_codec=%s",
|
||||
sc_server_get_codec_name(params->audio_codec));
|
||||
}
|
||||
if (params->video_source != SC_VIDEO_SOURCE_DISPLAY) {
|
||||
assert(params->video_source == SC_VIDEO_SOURCE_CAMERA);
|
||||
ADD_PARAM("video_source=camera");
|
||||
}
|
||||
if (params->audio_source == SC_AUDIO_SOURCE_MIC) {
|
||||
if (params->audio_source != SC_AUDIO_SOURCE_OUTPUT) {
|
||||
assert(params->audio_source == SC_AUDIO_SOURCE_MIC);
|
||||
ADD_PARAM("audio_source=mic");
|
||||
}
|
||||
if (params->max_size) {
|
||||
@ -279,12 +273,6 @@ execute_server(struct sc_server *server,
|
||||
if (params->display_id) {
|
||||
ADD_PARAM("display_id=%" PRIu32, params->display_id);
|
||||
}
|
||||
if (params->camera_id) {
|
||||
ADD_PARAM("camera_id=%s", params->camera_id);
|
||||
}
|
||||
if (params->camera_size) {
|
||||
ADD_PARAM("camera_size=%s", params->camera_size);
|
||||
}
|
||||
if (params->show_touches) {
|
||||
ADD_PARAM("show_touches=true");
|
||||
}
|
||||
@ -322,18 +310,12 @@ execute_server(struct sc_server *server,
|
||||
// By default, power_on is true
|
||||
ADD_PARAM("power_on=false");
|
||||
}
|
||||
if (params->list & SC_OPTION_LIST_ENCODERS) {
|
||||
if (params->list_encoders) {
|
||||
ADD_PARAM("list_encoders=true");
|
||||
}
|
||||
if (params->list & SC_OPTION_LIST_DISPLAYS) {
|
||||
if (params->list_displays) {
|
||||
ADD_PARAM("list_displays=true");
|
||||
}
|
||||
if (params->list & SC_OPTION_LIST_CAMERAS) {
|
||||
ADD_PARAM("list_cameras=true");
|
||||
}
|
||||
if (params->list & SC_OPTION_LIST_CAMERA_SIZES) {
|
||||
ADD_PARAM("list_camera_sizes=true");
|
||||
}
|
||||
|
||||
#undef ADD_PARAM
|
||||
|
||||
@ -551,8 +533,8 @@ sc_server_connect_to(struct sc_server *server, struct sc_server_info *info) {
|
||||
if (audio_socket == SC_SOCKET_NONE) {
|
||||
goto fail;
|
||||
}
|
||||
bool ok = net_connect_intr(&server->intr, audio_socket,
|
||||
tunnel_host, tunnel_port);
|
||||
bool ok = net_connect_intr(&server->intr, audio_socket, tunnel_host,
|
||||
tunnel_port);
|
||||
if (!ok) {
|
||||
goto fail;
|
||||
}
|
||||
@ -913,7 +895,7 @@ run_server(void *data) {
|
||||
|
||||
// If --list-* is passed, then the server just prints the requested data
|
||||
// then exits.
|
||||
if (params->list) {
|
||||
if (params->list_encoders || params->list_displays) {
|
||||
sc_pid pid = execute_server(server, params);
|
||||
if (pid == SC_PROCESS_NONE) {
|
||||
goto error_connection_failed;
|
||||
|
@ -26,15 +26,12 @@ struct sc_server_params {
|
||||
enum sc_log_level log_level;
|
||||
enum sc_codec video_codec;
|
||||
enum sc_codec audio_codec;
|
||||
enum sc_video_source video_source;
|
||||
enum sc_audio_source audio_source;
|
||||
const char *crop;
|
||||
const char *video_codec_options;
|
||||
const char *audio_codec_options;
|
||||
const char *video_encoder;
|
||||
const char *audio_encoder;
|
||||
const char *camera_id;
|
||||
const char *camera_size;
|
||||
struct sc_port_range port_range;
|
||||
uint32_t tunnel_host;
|
||||
uint16_t tunnel_port;
|
||||
@ -59,8 +56,9 @@ struct sc_server_params {
|
||||
bool select_tcpip;
|
||||
bool cleanup;
|
||||
bool power_on;
|
||||
bool list_encoders;
|
||||
bool list_displays;
|
||||
bool kill_adb_on_close;
|
||||
uint8_t list;
|
||||
};
|
||||
|
||||
struct sc_server {
|
||||
|
@ -105,6 +105,10 @@ scrcpy_otg(struct scrcpy_options *options) {
|
||||
|
||||
usb_device_initialized = true;
|
||||
|
||||
LOGI("USB device: %s (%04x:%04x) %s %s", usb_device.serial,
|
||||
(unsigned) usb_device.vid, (unsigned) usb_device.pid,
|
||||
usb_device.manufacturer, usb_device.product);
|
||||
|
||||
ok = sc_usb_connect(&s->usb, usb_device.device, &cbs, NULL);
|
||||
if (!ok) {
|
||||
goto end;
|
||||
|
@ -93,7 +93,7 @@ sc_usb_device_move(struct sc_usb_device *dst, struct sc_usb_device *src) {
|
||||
src->product = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
sc_usb_devices_destroy(struct sc_vec_usb_devices *usb_devices) {
|
||||
for (size_t i = 0; i < usb_devices->size; ++i) {
|
||||
sc_usb_device_destroy(&usb_devices->data[i]);
|
||||
@ -213,8 +213,8 @@ sc_usb_select_device(struct sc_usb *usb, const char *serial,
|
||||
assert(sel_count == 1); // sel_idx is valid only if sel_count == 1
|
||||
struct sc_usb_device *device = &vec.data[sel_idx];
|
||||
|
||||
LOGI("USB device found:");
|
||||
sc_usb_devices_log(SC_LOG_LEVEL_INFO, vec.data, vec.size);
|
||||
LOGD("USB device found:");
|
||||
sc_usb_devices_log(SC_LOG_LEVEL_DEBUG, vec.data, vec.size);
|
||||
|
||||
// Move device into out_device (do not destroy device)
|
||||
sc_usb_device_move(out_device, device);
|
||||
|
@ -147,7 +147,7 @@ sc_sdl_log_print(void *userdata, int category, SDL_LogPriority priority,
|
||||
}
|
||||
|
||||
void
|
||||
sc_log_configure(void) {
|
||||
sc_log_configure() {
|
||||
SDL_LogSetOutputFunction(sc_sdl_log_print, NULL);
|
||||
// Redirect FFmpeg logs to SDL logs
|
||||
av_log_set_callback(sc_av_log_callback);
|
||||
|
@ -36,6 +36,6 @@ sc_log_windows_error(const char *prefix, int error);
|
||||
#endif
|
||||
|
||||
void
|
||||
sc_log_configure(void);
|
||||
sc_log_configure();
|
||||
|
||||
#endif
|
||||
|
@ -190,10 +190,10 @@ sc_vecdeque_reallocdata_(void *ptr, size_t newcap, size_t item_size,
|
||||
|
||||
size_t right_len = MIN(size, oldcap - oldorigin);
|
||||
assert(right_len);
|
||||
memcpy(newptr, (char *) ptr + (oldorigin * item_size), right_len * item_size);
|
||||
memcpy(newptr, ptr + (oldorigin * item_size), right_len * item_size);
|
||||
|
||||
if (size > right_len) {
|
||||
memcpy((char *) newptr + (right_len * item_size), ptr,
|
||||
memcpy(newptr + (right_len * item_size), ptr,
|
||||
(size - right_len) * item_size);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include "util/bytebuf.h"
|
||||
|
||||
static void test_bytebuf_simple(void) {
|
||||
void test_bytebuf_simple(void) {
|
||||
struct sc_bytebuf buf;
|
||||
uint8_t data[20];
|
||||
|
||||
@ -34,7 +34,7 @@ static void test_bytebuf_simple(void) {
|
||||
sc_bytebuf_destroy(&buf);
|
||||
}
|
||||
|
||||
static void test_bytebuf_boundaries(void) {
|
||||
void test_bytebuf_boundaries(void) {
|
||||
struct sc_bytebuf buf;
|
||||
uint8_t data[20];
|
||||
|
||||
@ -71,7 +71,7 @@ static void test_bytebuf_boundaries(void) {
|
||||
sc_bytebuf_destroy(&buf);
|
||||
}
|
||||
|
||||
static void test_bytebuf_two_steps_write(void) {
|
||||
void test_bytebuf_two_steps_write(void) {
|
||||
struct sc_bytebuf buf;
|
||||
uint8_t data[20];
|
||||
|
||||
|
@ -358,7 +358,7 @@ static void test_index_of_column(void) {
|
||||
assert(sc_str_index_of_column(" a bc d", 1, " ") == 2);
|
||||
}
|
||||
|
||||
static void test_remove_trailing_cr(void) {
|
||||
static void test_remove_trailing_cr() {
|
||||
char s[] = "abc\r";
|
||||
sc_str_remove_trailing_cr(s, sizeof(s) - 1);
|
||||
assert(!strcmp(s, "abc"));
|
||||
|
@ -102,7 +102,7 @@ static void test_vecdeque_reserve(void) {
|
||||
sc_vecdeque_destroy(&vdq);
|
||||
}
|
||||
|
||||
static void test_vecdeque_grow(void) {
|
||||
static void test_vecdeque_grow() {
|
||||
struct SC_VECDEQUE(int) vdq = SC_VECDEQUE_INITIALIZER;
|
||||
|
||||
bool ok = sc_vecdeque_reserve(&vdq, 20);
|
||||
@ -142,7 +142,7 @@ static void test_vecdeque_grow(void) {
|
||||
sc_vecdeque_destroy(&vdq);
|
||||
}
|
||||
|
||||
static void test_vecdeque_push_hole(void) {
|
||||
static void test_vecdeque_push_hole() {
|
||||
struct SC_VECDEQUE(int) vdq = SC_VECDEQUE_INITIALIZER;
|
||||
|
||||
bool ok = sc_vecdeque_reserve(&vdq, 20);
|
||||
|
@ -187,7 +187,7 @@ static void test_vector_index_of(void) {
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_grow(void) {
|
||||
static void test_vector_grow() {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
|
||||
bool ok;
|
||||
|
23
doc/audio.md
23
doc/audio.md
@ -71,20 +71,6 @@ scrcpy --audio-codec=aac
|
||||
scrcpy --audio-codec=raw
|
||||
```
|
||||
|
||||
In particular, if you get the following error:
|
||||
|
||||
> Failed to initialize audio/opus, error 0xfffffffe
|
||||
|
||||
then your device has no Opus encoder: try `scrcpy --audio-codec=aac`.
|
||||
|
||||
For advanced usage, to pass arbitrary parameters to the [`MediaFormat`],
|
||||
check `--audio-codec-options` in the manpage or in `scrcpy --help`.
|
||||
|
||||
[`MediaFormat`]: https://developer.android.com/reference/android/media/MediaFormat
|
||||
|
||||
|
||||
## Encoder
|
||||
|
||||
Several encoders may be available on the device. They can be listed by:
|
||||
|
||||
```bash
|
||||
@ -93,14 +79,19 @@ scrcpy --list-encoders
|
||||
|
||||
To select a specific encoder:
|
||||
|
||||
```bash
|
||||
```
|
||||
scrcpy --audio-codec=opus --audio-encoder='c2.android.opus.encoder'
|
||||
```
|
||||
|
||||
For advanced usage, to pass arbitrary parameters to the [`MediaFormat`],
|
||||
check `--audio-codec-options` in the manpage or in `scrcpy --help`.
|
||||
|
||||
[`MediaFormat`]: https://developer.android.com/reference/android/media/MediaFormat
|
||||
|
||||
|
||||
## Bit rate
|
||||
|
||||
The default audio bit rate is 128Kbps. To change it:
|
||||
The default video bit-rate is 128Kbps. To change it:
|
||||
|
||||
```bash
|
||||
scrcpy --audio-bit-rate=64K
|
||||
|
@ -77,7 +77,7 @@ pip3 install meson
|
||||
sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
|
||||
|
||||
# client build dependencies
|
||||
sudo dnf install SDL2-devel ffms2-devel libusb1-devel meson gcc make
|
||||
sudo dnf install SDL2-devel ffms2-devel libusb-devel meson gcc make
|
||||
|
||||
# server build dependencies
|
||||
sudo dnf install java-devel
|
||||
@ -233,10 +233,10 @@ install` must be run as root)._
|
||||
|
||||
#### Option 2: Use prebuilt server
|
||||
|
||||
- [`scrcpy-server-v2.1.1`][direct-scrcpy-server]
|
||||
<sub>SHA-256: `9558db6c56743a1dc03b38f59801fb40e91cc891f8fc0c89e5b0b067761f148e`</sub>
|
||||
- [`scrcpy-server-v2.0`][direct-scrcpy-server]
|
||||
<sub>SHA-256: `9e241615f578cd690bb43311000debdecf6a9c50a7082b001952f18f6f21ddc2`</sub>
|
||||
|
||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v2.1.1/scrcpy-server-v2.1.1
|
||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v2.0/scrcpy-server-v2.0
|
||||
|
||||
Download the prebuilt server somewhere, and specify its path during the Meson
|
||||
configuration:
|
||||
|
@ -1,125 +0,0 @@
|
||||
# Connection
|
||||
|
||||
## Selection
|
||||
|
||||
If exactly one device is connected (i.e. listed by `adb devices`), then it is
|
||||
automatically selected.
|
||||
|
||||
However, if there are multiple devices connected, you must specify the one to
|
||||
use in one of 4 ways:
|
||||
- by its serial:
|
||||
```bash
|
||||
scrcpy --serial=0123456789abcdef
|
||||
scrcpy -s 0123456789abcdef # short version
|
||||
|
||||
# the serial is the ip:port if connected over TCP/IP (same behavior as adb)
|
||||
scrcpy --serial=192.168.1.1:5555
|
||||
```
|
||||
- the one connected over USB (if there is exactly one):
|
||||
```bash
|
||||
scrcpy --select-usb
|
||||
scrcpy -d # short version
|
||||
```
|
||||
- the one connected over TCP/IP (if there is exactly one):
|
||||
```bash
|
||||
scrcpy --select-tcpip
|
||||
scrcpy -e # short version
|
||||
```
|
||||
- a device already listening on TCP/IP (see [below](#tcpip-wireless)):
|
||||
```bash
|
||||
scrcpy --tcpip=192.168.1.1:5555
|
||||
scrcpy --tcpip=192.168.1.1 # default port is 5555
|
||||
```
|
||||
|
||||
The serial may also be provided via the environment variable `ANDROID_SERIAL`
|
||||
(also used by `adb`):
|
||||
|
||||
```bash
|
||||
# in bash
|
||||
export ANDROID_SERIAL=0123456789abcdef
|
||||
scrcpy
|
||||
```
|
||||
|
||||
```cmd
|
||||
:: in cmd
|
||||
set ANDROID_SERIAL=0123456789abcdef
|
||||
scrcpy
|
||||
```
|
||||
|
||||
```powershell
|
||||
# in PowerShell
|
||||
$env:ANDROID_SERIAL = '0123456789abcdef'
|
||||
scrcpy
|
||||
```
|
||||
|
||||
|
||||
## TCP/IP (wireless)
|
||||
|
||||
_Scrcpy_ uses `adb` to communicate with the device, and `adb` can [connect] to a
|
||||
device over TCP/IP. The device must be connected on the same network as the
|
||||
computer.
|
||||
|
||||
[connect]: https://developer.android.com/studio/command-line/adb.html#wireless
|
||||
|
||||
|
||||
### Automatic
|
||||
|
||||
An option `--tcpip` allows to configure the connection automatically. There are
|
||||
two variants.
|
||||
|
||||
If the device (accessible at 192.168.1.1 in this example) already listens on a
|
||||
port (typically 5555) for incoming _adb_ connections, then run:
|
||||
|
||||
```bash
|
||||
scrcpy --tcpip=192.168.1.1 # default port is 5555
|
||||
scrcpy --tcpip=192.168.1.1:5555
|
||||
```
|
||||
|
||||
If _adb_ TCP/IP mode is disabled on the device (or if you don't know the IP
|
||||
address), connect the device over USB, then run:
|
||||
|
||||
```bash
|
||||
scrcpy --tcpip # without arguments
|
||||
```
|
||||
|
||||
It will automatically find the device IP address and adb port, enable TCP/IP
|
||||
mode if necessary, then connect to the device before starting.
|
||||
|
||||
|
||||
### Manual
|
||||
|
||||
Alternatively, it is possible to enable the TCP/IP connection manually using
|
||||
`adb`:
|
||||
|
||||
1. Plug the device into a USB port on your computer.
|
||||
2. Connect the device to the same Wi-Fi network as your computer.
|
||||
3. Get your device IP address, in Settings → About phone → Status, or by
|
||||
executing this command:
|
||||
|
||||
```bash
|
||||
adb shell ip route | awk '{print $9}'
|
||||
```
|
||||
|
||||
4. Enable `adb` over TCP/IP on your device: `adb tcpip 5555`.
|
||||
5. Unplug your device.
|
||||
6. Connect to your device: `adb connect DEVICE_IP:5555` _(replace `DEVICE_IP`
|
||||
with the device IP address you found)_.
|
||||
7. Run `scrcpy` as usual.
|
||||
8. Run `adb disconnect` once you're done.
|
||||
|
||||
Since Android 11, a [wireless debugging option][adb-wireless] allows to bypass
|
||||
having to physically connect your device directly to your computer.
|
||||
|
||||
[adb-wireless]: https://developer.android.com/studio/command-line/adb#wireless-android11-command-line
|
||||
|
||||
|
||||
## Autostart
|
||||
|
||||
A small tool (by the scrcpy author) allows to run arbitrary commands whenever a
|
||||
new Android device is connected: [AutoAdb]. It can be used to start scrcpy:
|
||||
|
||||
```bash
|
||||
autoadb scrcpy -s '{}'
|
||||
```
|
||||
|
||||
[AutoAdb]: https://github.com/rom1v/autoadb
|
@ -359,7 +359,7 @@ metadata]:
|
||||
- the initial video width (`u32`)
|
||||
- the initial video height (`u32`)
|
||||
- On the _audio_ socket, 4 bytes:
|
||||
- the codec id (`u32`) (OPUS, AAC or RAW)
|
||||
- the codec id ('u32`) (OPUS, AAC or RAW)
|
||||
|
||||
[codec metadata]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/Streamer.java#L33-L51
|
||||
|
||||
|
158
doc/device.md
158
doc/device.md
@ -1,9 +1,156 @@
|
||||
# Device
|
||||
|
||||
## Selection
|
||||
|
||||
If exactly one device is connected (i.e. listed by `adb devices`), then it is
|
||||
automatically selected.
|
||||
|
||||
However, if there are multiple devices connected, you must specify the one to
|
||||
use in one of 4 ways:
|
||||
- by its serial:
|
||||
```bash
|
||||
scrcpy --serial=0123456789abcdef
|
||||
scrcpy -s 0123456789abcdef # short version
|
||||
|
||||
# the serial is the ip:port if connected over TCP/IP (same behavior as adb)
|
||||
scrcpy --serial=192.168.1.1:5555
|
||||
```
|
||||
- the one connected over USB (if there is exactly one):
|
||||
```bash
|
||||
scrcpy --select-usb
|
||||
scrcpy -d # short version
|
||||
```
|
||||
- the one connected over TCP/IP (if there is exactly one):
|
||||
```bash
|
||||
scrcpy --select-tcpip
|
||||
scrcpy -e # short version
|
||||
```
|
||||
- a device already listening on TCP/IP (see [below](#tcpip-wireless)):
|
||||
```bash
|
||||
scrcpy --tcpip=192.168.1.1:5555
|
||||
scrcpy --tcpip=192.168.1.1 # default port is 5555
|
||||
```
|
||||
|
||||
The serial may also be provided via the environment variable `ANDROID_SERIAL`
|
||||
(also used by `adb`):
|
||||
|
||||
```bash
|
||||
# in bash
|
||||
export ANDROID_SERIAL=0123456789abcdef
|
||||
scrcpy
|
||||
```
|
||||
|
||||
```cmd
|
||||
:: in cmd
|
||||
set ANDROID_SERIAL=0123456789abcdef
|
||||
scrcpy
|
||||
```
|
||||
|
||||
```powershell
|
||||
# in PowerShell
|
||||
$env:ANDROID_SERIAL = '0123456789abcdef'
|
||||
scrcpy
|
||||
```
|
||||
|
||||
|
||||
## TCP/IP (wireless)
|
||||
|
||||
_Scrcpy_ uses `adb` to communicate with the device, and `adb` can [connect] to a
|
||||
device over TCP/IP. The device must be connected on the same network as the
|
||||
computer.
|
||||
|
||||
[connect]: https://developer.android.com/studio/command-line/adb.html#wireless
|
||||
|
||||
|
||||
### Automatic
|
||||
|
||||
An option `--tcpip` allows to configure the connection automatically. There are
|
||||
two variants.
|
||||
|
||||
If the device (accessible at 192.168.1.1 in this example) already listens on a
|
||||
port (typically 5555) for incoming _adb_ connections, then run:
|
||||
|
||||
```bash
|
||||
scrcpy --tcpip=192.168.1.1 # default port is 5555
|
||||
scrcpy --tcpip=192.168.1.1:5555
|
||||
```
|
||||
|
||||
If _adb_ TCP/IP mode is disabled on the device (or if you don't know the IP
|
||||
address), connect the device over USB, then run:
|
||||
|
||||
```bash
|
||||
scrcpy --tcpip # without arguments
|
||||
```
|
||||
|
||||
It will automatically find the device IP address and adb port, enable TCP/IP
|
||||
mode if necessary, then connect to the device before starting.
|
||||
|
||||
|
||||
### Manual
|
||||
|
||||
Alternatively, it is possible to enable the TCP/IP connection manually using
|
||||
`adb`:
|
||||
|
||||
1. Plug the device into a USB port on your computer.
|
||||
2. Connect the device to the same Wi-Fi network as your computer.
|
||||
3. Get your device IP address, in Settings → About phone → Status, or by
|
||||
executing this command:
|
||||
|
||||
```bash
|
||||
adb shell ip route | awk '{print $9}'
|
||||
```
|
||||
|
||||
4. Enable `adb` over TCP/IP on your device: `adb tcpip 5555`.
|
||||
5. Unplug your device.
|
||||
6. Connect to your device: `adb connect DEVICE_IP:5555` _(replace `DEVICE_IP`
|
||||
with the device IP address you found)_.
|
||||
7. Run `scrcpy` as usual.
|
||||
8. Run `adb disconnect` once you're done.
|
||||
|
||||
Since Android 11, a [wireless debugging option][adb-wireless] allows to bypass
|
||||
having to physically connect your device directly to your computer.
|
||||
|
||||
[adb-wireless]: https://developer.android.com/studio/command-line/adb#wireless-android11-command-line
|
||||
|
||||
|
||||
## Autostart
|
||||
|
||||
A small tool (by the scrcpy author) allows to run arbitrary commands whenever a
|
||||
new Android device is connected: [AutoAdb]. It can be used to start scrcpy:
|
||||
|
||||
```bash
|
||||
autoadb scrcpy -s '{}'
|
||||
```
|
||||
|
||||
[AutoAdb]: https://github.com/rom1v/autoadb
|
||||
|
||||
|
||||
## Display
|
||||
|
||||
If several displays are available on the Android device, it is possible to
|
||||
select the display to mirror:
|
||||
|
||||
```bash
|
||||
scrcpy --display=1
|
||||
```
|
||||
|
||||
The list of display ids can be retrieved by:
|
||||
|
||||
```bash
|
||||
scrcpy --list-displays
|
||||
```
|
||||
|
||||
A secondary display may only be controlled if the device runs at least Android
|
||||
10 (otherwise it is mirrored as read-only).
|
||||
|
||||
|
||||
## Actions
|
||||
|
||||
Some command line arguments perform actions on the device itself while scrcpy is
|
||||
running.
|
||||
|
||||
## Stay awake
|
||||
|
||||
### Stay awake
|
||||
|
||||
To prevent the device from sleeping after a delay **when the device is plugged
|
||||
in**:
|
||||
@ -19,7 +166,7 @@ If the device is not plugged in (i.e. only connected over TCP/IP),
|
||||
`--stay-awake` has no effect (this is the Android behavior).
|
||||
|
||||
|
||||
## Turn screen off
|
||||
### Turn screen off
|
||||
|
||||
It is possible to turn the device screen off while mirroring on start with a
|
||||
command-line option:
|
||||
@ -47,7 +194,7 @@ scrcpy -Sw # short version
|
||||
```
|
||||
|
||||
|
||||
## Show touches
|
||||
### Show touches
|
||||
|
||||
For presentations, it may be useful to show physical touches (on the physical
|
||||
device). Android exposes this feature in _Developers options_.
|
||||
@ -63,7 +210,7 @@ scrcpy -t # short version
|
||||
Note that it only shows _physical_ touches (by a finger on the device).
|
||||
|
||||
|
||||
## Power off on close
|
||||
### Power off on close
|
||||
|
||||
To turn the device screen off when closing _scrcpy_:
|
||||
|
||||
@ -71,10 +218,11 @@ To turn the device screen off when closing _scrcpy_:
|
||||
scrcpy --power-off-on-close
|
||||
```
|
||||
|
||||
## Power on on start
|
||||
### Power on on start
|
||||
|
||||
By default, on start, the device is powered on. To prevent this behavior:
|
||||
|
||||
```bash
|
||||
scrcpy --no-power-on
|
||||
```
|
||||
|
||||
|
@ -106,7 +106,3 @@ scrcpy --otg # keyboard and mouse
|
||||
|
||||
Like `--hid-keyboard` and `--hid-mouse`, it only works if the device is
|
||||
connected over USB.
|
||||
|
||||
## HID/OTG issues on Windows
|
||||
|
||||
See [FAQ](/FAQ.md#hidotg-issues-on-windows).
|
||||
|
@ -9,10 +9,12 @@ Scrcpy is packaged in several distributions and package managers:
|
||||
- Debian/Ubuntu: `apt install scrcpy`
|
||||
- Arch Linux: `pacman -S scrcpy`
|
||||
- Fedora: `dnf copr enable zeno/scrcpy && dnf install scrcpy`
|
||||
- Gentoo: `emerge scrcpy`
|
||||
- Gentoo: [ebuild][ebuild-link] file
|
||||
- Snap: `snap install scrcpy`
|
||||
- … (see [repology](https://repology.org/project/scrcpy/versions))
|
||||
|
||||
[ebuild-link]: https://github.com/maggu2810/maggu2810-overlay/tree/master/app-mobilephone/scrcpy
|
||||
|
||||
### Latest version
|
||||
|
||||
However, the packaged version is not always the latest release. To install the
|
||||
|
@ -29,7 +29,7 @@ _<kbd>[Super]</kbd> is typically the <kbd>Windows</kbd> or <kbd>Cmd</kbd> key._
|
||||
| Resize window to 1:1 (pixel-perfect) | <kbd>MOD</kbd>+<kbd>g</kbd>
|
||||
| Resize window to remove black borders | <kbd>MOD</kbd>+<kbd>w</kbd> \| _Double-left-click¹_
|
||||
| Click on `HOME` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _Middle-click_
|
||||
| Click on `BACK` | <kbd>MOD</kbd>+<kbd>b</kbd> \| <kbd>MOD</kbd>+<kbd>Backspace</kbd> \| _Right-click²_
|
||||
| Click on `BACK` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _Right-click²_
|
||||
| Click on `APP_SWITCH` | <kbd>MOD</kbd>+<kbd>s</kbd> \| _4th-click³_
|
||||
| Click on `MENU` (unlock screen)⁴ | <kbd>MOD</kbd>+<kbd>m</kbd>
|
||||
| Click on `VOLUME_UP` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(up)_
|
||||
|
34
doc/video.md
34
doc/video.md
@ -21,7 +21,7 @@ If encoding fails, scrcpy automatically tries again with a lower definition
|
||||
|
||||
## Bit rate
|
||||
|
||||
The default video bit rate is 8 Mbps. To change it:
|
||||
The default video bit-rate is 8 Mbps. To change it:
|
||||
|
||||
```bash
|
||||
scrcpy --video-bit-rate=2M
|
||||
@ -66,14 +66,6 @@ scrcpy --video-codec=av1
|
||||
H265 may provide better quality, but H264 should provide lower latency.
|
||||
AV1 encoders are not common on current Android devices.
|
||||
|
||||
For advanced usage, to pass arbitrary parameters to the [`MediaFormat`],
|
||||
check `--video-codec-options` in the manpage or in `scrcpy --help`.
|
||||
|
||||
[`MediaFormat`]: https://developer.android.com/reference/android/media/MediaFormat
|
||||
|
||||
|
||||
## Encoder
|
||||
|
||||
Several encoders may be available on the device. They can be listed by:
|
||||
|
||||
```bash
|
||||
@ -87,6 +79,11 @@ try another one:
|
||||
scrcpy --video-codec=h264 --video-encoder='OMX.qcom.video.encoder.avc'
|
||||
```
|
||||
|
||||
For advanced usage, to pass arbitrary parameters to the [`MediaFormat`],
|
||||
check `--video-codec-options` in the manpage or in `scrcpy --help`.
|
||||
|
||||
[`MediaFormat`]: https://developer.android.com/reference/android/media/MediaFormat
|
||||
|
||||
|
||||
## Rotation
|
||||
|
||||
@ -137,25 +134,6 @@ phone, landscape for a tablet).
|
||||
If `--max-size` is also specified, resizing is applied after cropping.
|
||||
|
||||
|
||||
## Display
|
||||
|
||||
If several displays are available on the Android device, it is possible to
|
||||
select the display to mirror:
|
||||
|
||||
```bash
|
||||
scrcpy --display=1
|
||||
```
|
||||
|
||||
The list of display ids can be retrieved by:
|
||||
|
||||
```bash
|
||||
scrcpy --list-displays
|
||||
```
|
||||
|
||||
A secondary display may only be controlled if the device runs at least Android
|
||||
10 (otherwise it is mirrored as read-only).
|
||||
|
||||
|
||||
## Buffering
|
||||
|
||||
By default, there is no video buffering, to get the lowest possible latency.
|
||||
|
@ -4,24 +4,18 @@
|
||||
|
||||
Download the [latest release]:
|
||||
|
||||
- [`scrcpy-win64-v2.1.1.zip`][direct-win64] (64-bit)
|
||||
<sub>SHA-256: `f77281e1bce2f9934617699c581f063d5b327f012eff602ee98fb2ef550c25c2`</sub>
|
||||
- [`scrcpy-win32-v2.1.1.zip`][direct-win32] (32-bit)
|
||||
<sub>SHA-256: `ef7ae7fbe9449f2643febdc2244fb186d1a746a3c736394150cfd14f06d3c943`</sub>
|
||||
- [`scrcpy-win64-v2.0.zip`][direct-win64] (64-bit)
|
||||
<sub>SHA-256: `ae4c8d37a496b43f8974ba8f07f708e22a9570ba0cddc3dc3a36edbccd4d2a20`</sub>
|
||||
- [`scrcpy-win32-v2.0.zip`][direct-win32] (32-bit)
|
||||
<sub>SHA-256: `15d98c02cb0e0bbd84f8b5d54991e0f6925569b1286a86a40743944fcb1c2d8c`</sub>
|
||||
|
||||
[latest release]: https://github.com/Genymobile/scrcpy/releases/latest
|
||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v2.1.1/scrcpy-win64-v2.1.1.zip
|
||||
[direct-win32]: https://github.com/Genymobile/scrcpy/releases/download/v2.1.1/scrcpy-win32-v2.1.1.zip
|
||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v2.0/scrcpy-win64-v2.0.zip
|
||||
[direct-win32]: https://github.com/Genymobile/scrcpy/releases/download/v2.0/scrcpy-win32-v2.0.zip
|
||||
|
||||
and extract it.
|
||||
|
||||
Alternatively, you could install it from packages manager, like [Winget]:
|
||||
|
||||
```bash
|
||||
winget install scrcpy
|
||||
```
|
||||
|
||||
or [Chocolatey]:
|
||||
Alternatively, you could install it from packages manager, like [Chocolatey]:
|
||||
|
||||
```bash
|
||||
choco install scrcpy
|
||||
@ -36,7 +30,6 @@ scoop install scrcpy
|
||||
scoop install adb # if you don't have it yet
|
||||
```
|
||||
|
||||
[Winget]: https://github.com/microsoft/winget-cli
|
||||
[Chocolatey]: https://chocolatey.org/
|
||||
[Scoop]: https://scoop.sh
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
set -e
|
||||
|
||||
BUILDDIR=build-auto
|
||||
PREBUILT_SERVER_URL=https://github.com/Genymobile/scrcpy/releases/download/v2.1.1/scrcpy-server-v2.1.1
|
||||
PREBUILT_SERVER_SHA256=9558db6c56743a1dc03b38f59801fb40e91cc891f8fc0c89e5b0b067761f148e
|
||||
PREBUILT_SERVER_URL=https://github.com/Genymobile/scrcpy/releases/download/v2.0/scrcpy-server-v2.0
|
||||
PREBUILT_SERVER_SHA256=9e241615f578cd690bb43311000debdecf6a9c50a7082b001952f18f6f21ddc2
|
||||
|
||||
echo "[scrcpy] Downloading prebuilt server..."
|
||||
wget "$PREBUILT_SERVER_URL" -O scrcpy-server
|
||||
|
@ -1,5 +1,5 @@
|
||||
project('scrcpy', 'c',
|
||||
version: '2.1.1',
|
||||
version: '2.0',
|
||||
meson_version: '>= 0.48',
|
||||
default_options: [
|
||||
'c_std=c11',
|
||||
@ -7,8 +7,6 @@ project('scrcpy', 'c',
|
||||
'b_ndebug=if-release',
|
||||
])
|
||||
|
||||
add_project_arguments('-Wmissing-prototypes', language: 'c')
|
||||
|
||||
if get_option('compile_app')
|
||||
subdir('app')
|
||||
endif
|
||||
|
12
release.mk
12
release.mk
@ -98,9 +98,9 @@ dist-win32: build-server build-win32
|
||||
cp app/prebuilt-deps/data/ffmpeg-6.0-scrcpy-4/win32/bin/avcodec-60.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/ffmpeg-6.0-scrcpy-4/win32/bin/avformat-60.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/ffmpeg-6.0-scrcpy-4/win32/bin/swresample-4.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-34.0.3/adb.exe "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-34.0.3/AdbWinApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-34.0.3/AdbWinUsbApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-34.0.1/adb.exe "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-34.0.1/AdbWinApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-34.0.1/AdbWinUsbApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/SDL2-2.28.0/i686-w64-mingw32/bin/SDL2.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/libusb-1.0.26/libusb-MinGW-Win32/bin/msys-usb-1.0.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
|
||||
@ -116,9 +116,9 @@ dist-win64: build-server build-win64
|
||||
cp app/prebuilt-deps/data/ffmpeg-6.0-scrcpy-4/win64/bin/avcodec-60.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/ffmpeg-6.0-scrcpy-4/win64/bin/avformat-60.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/ffmpeg-6.0-scrcpy-4/win64/bin/swresample-4.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-34.0.3/adb.exe "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-34.0.3/AdbWinApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-34.0.3/AdbWinUsbApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-34.0.1/adb.exe "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-34.0.1/AdbWinApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-34.0.1/AdbWinUsbApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/SDL2-2.28.0/x86_64-w64-mingw32/bin/SDL2.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/libusb-1.0.26/libusb-MinGW-x64/bin/msys-usb-1.0.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
|
||||
|
@ -7,8 +7,8 @@ android {
|
||||
applicationId "com.genymobile.scrcpy"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 33
|
||||
versionCode 20101
|
||||
versionName "2.1.1"
|
||||
versionCode 20000
|
||||
versionName "2.0"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
@ -12,7 +12,7 @@
|
||||
set -e
|
||||
|
||||
SCRCPY_DEBUG=false
|
||||
SCRCPY_VERSION_NAME=2.1.1
|
||||
SCRCPY_VERSION_NAME=2.0
|
||||
|
||||
PLATFORM=${ANDROID_PLATFORM:-33}
|
||||
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-33.0.0}
|
||||
@ -48,7 +48,6 @@ cd "$SERVER_DIR/src/main/aidl"
|
||||
"$BUILD_TOOLS_DIR/aidl" -o"$GEN_DIR" android/view/IRotationWatcher.aidl
|
||||
"$BUILD_TOOLS_DIR/aidl" -o"$GEN_DIR" \
|
||||
android/content/IOnPrimaryClipChangedListener.aidl
|
||||
"$BUILD_TOOLS_DIR/aidl" -o"$GEN_DIR" android/view/IDisplayFoldListener.aidl
|
||||
|
||||
echo "Compiling java sources..."
|
||||
cd ../java
|
||||
|
@ -118,7 +118,7 @@ public final class AudioCapture {
|
||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
|
||||
startWorkaroundAndroid11();
|
||||
try {
|
||||
tryStartRecording(5, 100);
|
||||
tryStartRecording(3, 100);
|
||||
} finally {
|
||||
stopWorkaroundAndroid11();
|
||||
}
|
||||
|
@ -1,198 +0,0 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.hardware.camera2.CameraAccessException;
|
||||
import android.hardware.camera2.CameraCaptureSession;
|
||||
import android.hardware.camera2.CameraDevice;
|
||||
import android.hardware.camera2.CaptureFailure;
|
||||
import android.hardware.camera2.CaptureRequest;
|
||||
import android.hardware.camera2.params.OutputConfiguration;
|
||||
import android.hardware.camera2.params.SessionConfiguration;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.view.Surface;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class CameraCapture extends SurfaceCapture {
|
||||
|
||||
private final String cameraId;
|
||||
private final Size explicitSize;
|
||||
|
||||
private HandlerThread cameraThread;
|
||||
private Handler cameraHandler;
|
||||
private CameraDevice cameraDevice;
|
||||
private Executor cameraExecutor;
|
||||
|
||||
private final AtomicBoolean disconnected = new AtomicBoolean();
|
||||
|
||||
public CameraCapture(String cameraId, Size explicitSize) {
|
||||
this.cameraId = cameraId;
|
||||
this.explicitSize = explicitSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws IOException {
|
||||
cameraThread = new HandlerThread("camera");
|
||||
cameraThread.start();
|
||||
cameraHandler = new Handler(cameraThread.getLooper());
|
||||
cameraExecutor = new HandlerExecutor(cameraHandler);
|
||||
|
||||
try {
|
||||
cameraDevice = openCamera(cameraId);
|
||||
} catch (CameraAccessException | InterruptedException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Surface surface) throws IOException {
|
||||
try {
|
||||
CameraCaptureSession session = createCaptureSession(cameraDevice, surface);
|
||||
CaptureRequest.Builder requestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
|
||||
requestBuilder.addTarget(surface);
|
||||
CaptureRequest request = requestBuilder.build();
|
||||
setRepeatingRequest(session, request);
|
||||
} catch (CameraAccessException | InterruptedException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
if (cameraDevice != null) {
|
||||
cameraDevice.close();
|
||||
}
|
||||
if (cameraThread != null) {
|
||||
cameraThread.quitSafely();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getSize() {
|
||||
return explicitSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMaxSize(int size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@TargetApi(Build.VERSION_CODES.S)
|
||||
private CameraDevice openCamera(String id) throws CameraAccessException, InterruptedException {
|
||||
Ln.v("Open Camera: " + id);
|
||||
|
||||
CompletableFuture<CameraDevice> future = new CompletableFuture<>();
|
||||
ServiceManager.getCameraManager().openCamera(id, new CameraDevice.StateCallback() {
|
||||
@Override
|
||||
public void onOpened(CameraDevice camera) {
|
||||
Ln.v("Open Camera Success");
|
||||
future.complete(camera);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected(CameraDevice camera) {
|
||||
Ln.w("Camera disconnected");
|
||||
disconnected.set(true);
|
||||
requestReset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(CameraDevice camera, int error) {
|
||||
int cameraAccessExceptionErrorCode;
|
||||
switch (error) {
|
||||
case CameraDevice.StateCallback.ERROR_CAMERA_IN_USE:
|
||||
cameraAccessExceptionErrorCode = CameraAccessException.CAMERA_IN_USE;
|
||||
break;
|
||||
case CameraDevice.StateCallback.ERROR_MAX_CAMERAS_IN_USE:
|
||||
cameraAccessExceptionErrorCode = CameraAccessException.MAX_CAMERAS_IN_USE;
|
||||
break;
|
||||
case CameraDevice.StateCallback.ERROR_CAMERA_DISABLED:
|
||||
cameraAccessExceptionErrorCode = CameraAccessException.CAMERA_DISABLED;
|
||||
break;
|
||||
case CameraDevice.StateCallback.ERROR_CAMERA_DEVICE:
|
||||
case CameraDevice.StateCallback.ERROR_CAMERA_SERVICE:
|
||||
default:
|
||||
cameraAccessExceptionErrorCode = CameraAccessException.CAMERA_ERROR;
|
||||
break;
|
||||
}
|
||||
future.completeExceptionally(new CameraAccessException(cameraAccessExceptionErrorCode));
|
||||
}
|
||||
}, cameraHandler);
|
||||
|
||||
try {
|
||||
return future.get();
|
||||
} catch (ExecutionException e) {
|
||||
throw (CameraAccessException) e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.S)
|
||||
private CameraCaptureSession createCaptureSession(CameraDevice camera, Surface surface) throws CameraAccessException, InterruptedException {
|
||||
Ln.d("Create Capture Session");
|
||||
|
||||
CompletableFuture<CameraCaptureSession> future = new CompletableFuture<>();
|
||||
// replace by createCaptureSession(SessionConfiguration)
|
||||
OutputConfiguration outputConfig = new OutputConfiguration(surface);
|
||||
List<OutputConfiguration> outputs = Arrays.asList(outputConfig);
|
||||
SessionConfiguration sessionConfig = new SessionConfiguration(SessionConfiguration.SESSION_REGULAR, outputs, cameraExecutor,
|
||||
new CameraCaptureSession.StateCallback() {
|
||||
@Override
|
||||
public void onConfigured(CameraCaptureSession session) {
|
||||
Ln.d("Create Capture Session Success");
|
||||
future.complete(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigureFailed(CameraCaptureSession session) {
|
||||
future.completeExceptionally(new CameraAccessException(CameraAccessException.CAMERA_ERROR));
|
||||
}
|
||||
});
|
||||
|
||||
camera.createCaptureSession(sessionConfig);
|
||||
|
||||
try {
|
||||
return future.get();
|
||||
} catch (ExecutionException e) {
|
||||
throw (CameraAccessException) e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.S)
|
||||
private void setRepeatingRequest(CameraCaptureSession session, CaptureRequest request) throws CameraAccessException, InterruptedException {
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
session.setRepeatingRequest(request, new CameraCaptureSession.CaptureCallback() {
|
||||
@Override
|
||||
public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp, long frameNumber) {
|
||||
future.complete(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure failure) {
|
||||
future.completeExceptionally(new CameraAccessException(CameraAccessException.CAMERA_ERROR));
|
||||
}
|
||||
}, cameraHandler);
|
||||
|
||||
try {
|
||||
future.get();
|
||||
} catch (ExecutionException e) {
|
||||
throw (CameraAccessException) e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return disconnected.get();
|
||||
}
|
||||
}
|
@ -64,6 +64,8 @@ public final class DesktopConnection implements Closeable {
|
||||
throws IOException {
|
||||
String socketName = getSocketName(scid);
|
||||
|
||||
LocalSocket firstSocket = null;
|
||||
|
||||
LocalSocket videoSocket = null;
|
||||
LocalSocket audioSocket = null;
|
||||
LocalSocket controlSocket = null;
|
||||
@ -72,28 +74,24 @@ public final class DesktopConnection implements Closeable {
|
||||
try (LocalServerSocket localServerSocket = new LocalServerSocket(socketName)) {
|
||||
if (video) {
|
||||
videoSocket = localServerSocket.accept();
|
||||
if (sendDummyByte) {
|
||||
// send one byte so the client may read() to detect a connection error
|
||||
videoSocket.getOutputStream().write(0);
|
||||
sendDummyByte = false;
|
||||
}
|
||||
firstSocket = videoSocket;
|
||||
}
|
||||
if (audio) {
|
||||
audioSocket = localServerSocket.accept();
|
||||
if (sendDummyByte) {
|
||||
// send one byte so the client may read() to detect a connection error
|
||||
audioSocket.getOutputStream().write(0);
|
||||
sendDummyByte = false;
|
||||
if (firstSocket == null) {
|
||||
firstSocket = audioSocket;
|
||||
}
|
||||
}
|
||||
if (control) {
|
||||
controlSocket = localServerSocket.accept();
|
||||
if (sendDummyByte) {
|
||||
// send one byte so the client may read() to detect a connection error
|
||||
controlSocket.getOutputStream().write(0);
|
||||
sendDummyByte = false;
|
||||
if (firstSocket == null) {
|
||||
firstSocket = controlSocket;
|
||||
}
|
||||
}
|
||||
if (sendDummyByte) {
|
||||
// send one byte so the client may read() to detect a connection error
|
||||
firstSocket.getOutputStream().write(0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (video) {
|
||||
|
@ -99,32 +99,25 @@ public final class Device {
|
||||
}
|
||||
}, displayId);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
ServiceManager.getWindowManager().registerDisplayFoldListener(new IDisplayFoldListener.Stub() {
|
||||
@Override
|
||||
public void onDisplayFoldChanged(int displayId, boolean folded) {
|
||||
if (Device.this.displayId != displayId) {
|
||||
// Ignore events related to other display ids
|
||||
ServiceManager.getWindowManager().registerDisplayFoldListener(new IDisplayFoldListener.Stub() {
|
||||
@Override
|
||||
public void onDisplayFoldChanged(int displayId, boolean folded) {
|
||||
synchronized (Device.this) {
|
||||
DisplayInfo displayInfo = ServiceManager.getDisplayManager().getDisplayInfo(displayId);
|
||||
if (displayInfo == null) {
|
||||
Ln.e("Display " + displayId + " not found\n" + LogUtils.buildDisplayListMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (Device.this) {
|
||||
DisplayInfo displayInfo = ServiceManager.getDisplayManager().getDisplayInfo(displayId);
|
||||
if (displayInfo == null) {
|
||||
Ln.e("Display " + displayId + " not found\n" + LogUtils.buildDisplayListMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
screenInfo = ScreenInfo.computeScreenInfo(displayInfo.getRotation(), displayInfo.getSize(), options.getCrop(),
|
||||
options.getMaxSize(), options.getLockVideoOrientation());
|
||||
// notify
|
||||
if (foldListener != null) {
|
||||
foldListener.onFoldChanged(displayId, folded);
|
||||
}
|
||||
screenInfo = ScreenInfo.computeScreenInfo(displayInfo.getRotation(), displayInfo.getSize(), options.getCrop(),
|
||||
options.getMaxSize(), options.getLockVideoOrientation());
|
||||
// notify
|
||||
if (foldListener != null) {
|
||||
foldListener.onFoldChanged(displayId, folded);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (options.getControl() && options.getClipboardAutosync()) {
|
||||
// If control and autosync are enabled, synchronize Android clipboard to the computer automatically
|
||||
|
@ -1,23 +0,0 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import android.os.Handler;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
// Inspired from hidden android.os.HandlerExecutor
|
||||
|
||||
public class HandlerExecutor implements Executor {
|
||||
private final Handler handler;
|
||||
|
||||
public HandlerExecutor(Handler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable command) {
|
||||
if (!handler.post(command)) {
|
||||
throw new RejectedExecutionException(handler + " is shutting down");
|
||||
}
|
||||
}
|
||||
}
|
@ -3,13 +3,6 @@ package com.genymobile.scrcpy;
|
||||
import com.genymobile.scrcpy.wrappers.DisplayManager;
|
||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.hardware.camera2.CameraAccessException;
|
||||
import android.hardware.camera2.CameraCharacteristics;
|
||||
import android.hardware.camera2.CameraManager;
|
||||
import android.hardware.camera2.params.StreamConfigurationMap;
|
||||
import android.media.MediaCodec;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class LogUtils {
|
||||
@ -67,50 +60,4 @@ public final class LogUtils {
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String getCameraFacingName(int facing) {
|
||||
switch (facing) {
|
||||
case CameraCharacteristics.LENS_FACING_FRONT:
|
||||
return "front";
|
||||
case CameraCharacteristics.LENS_FACING_BACK:
|
||||
return "back";
|
||||
case CameraCharacteristics.LENS_FACING_EXTERNAL:
|
||||
return "external";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
public static String buildCameraListMessage(boolean includeSizes) {
|
||||
StringBuilder builder = new StringBuilder("List of cameras:");
|
||||
CameraManager cameraManager = ServiceManager.getCameraManager();
|
||||
try {
|
||||
String[] cameraIds = cameraManager.getCameraIdList();
|
||||
if (cameraIds == null || cameraIds.length == 0) {
|
||||
builder.append("\n (none)");
|
||||
} else {
|
||||
for (String id : cameraIds) {
|
||||
builder.append("\n --video-source=camera --camera=").append(id);
|
||||
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(id);
|
||||
int facing = characteristics.get(CameraCharacteristics.LENS_FACING);
|
||||
builder.append(" (").append(getCameraFacingName(facing)).append(", ");
|
||||
|
||||
Rect activeSize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
|
||||
builder.append(activeSize.width()).append("x").append(activeSize.height());
|
||||
builder.append(')');
|
||||
|
||||
if (includeSizes) {
|
||||
StreamConfigurationMap configs = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
|
||||
android.util.Size[] sizes = configs.getOutputSizes(MediaCodec.class);
|
||||
for (android.util.Size size : sizes) {
|
||||
builder.append("\n - ").append(size.getWidth()).append('x').append(size.getHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (CameraAccessException e) {
|
||||
builder.append("\n (access denied)");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ public class Options {
|
||||
private int maxSize;
|
||||
private VideoCodec videoCodec = VideoCodec.H264;
|
||||
private AudioCodec audioCodec = AudioCodec.OPUS;
|
||||
private VideoSource videoSource = VideoSource.DISPLAY;
|
||||
private AudioSource audioSource = AudioSource.OUTPUT;
|
||||
private int videoBitRate = 8000000;
|
||||
private int audioBitRate = 128000;
|
||||
@ -24,8 +23,6 @@ public class Options {
|
||||
private Rect crop;
|
||||
private boolean control = true;
|
||||
private int displayId;
|
||||
private String cameraId;
|
||||
private Size cameraSize;
|
||||
private boolean showTouches;
|
||||
private boolean stayAwake;
|
||||
private List<CodecOption> videoCodecOptions;
|
||||
@ -41,8 +38,6 @@ public class Options {
|
||||
|
||||
private boolean listEncoders;
|
||||
private boolean listDisplays;
|
||||
private boolean listCameras;
|
||||
private boolean listCameraSizes;
|
||||
|
||||
// Options not used by the scrcpy client, but useful to use scrcpy-server directly
|
||||
private boolean sendDeviceMeta = true; // send device name and size
|
||||
@ -78,10 +73,6 @@ public class Options {
|
||||
return audioCodec;
|
||||
}
|
||||
|
||||
public VideoSource getVideoSource() {
|
||||
return videoSource;
|
||||
}
|
||||
|
||||
public AudioSource getAudioSource() {
|
||||
return audioSource;
|
||||
}
|
||||
@ -118,14 +109,6 @@ public class Options {
|
||||
return displayId;
|
||||
}
|
||||
|
||||
public String getCameraId() {
|
||||
return cameraId;
|
||||
}
|
||||
|
||||
public Size getCameraSize() {
|
||||
return cameraSize;
|
||||
}
|
||||
|
||||
public boolean getShowTouches() {
|
||||
return showTouches;
|
||||
}
|
||||
@ -170,10 +153,6 @@ public class Options {
|
||||
return powerOn;
|
||||
}
|
||||
|
||||
public boolean getList() {
|
||||
return listEncoders || listDisplays || listCameras || listCameraSizes;
|
||||
}
|
||||
|
||||
public boolean getListEncoders() {
|
||||
return listEncoders;
|
||||
}
|
||||
@ -182,14 +161,6 @@ public class Options {
|
||||
return listDisplays;
|
||||
}
|
||||
|
||||
public boolean getListCameras() {
|
||||
return listCameras;
|
||||
}
|
||||
|
||||
public boolean getListCameraSizes() {
|
||||
return listCameraSizes;
|
||||
}
|
||||
|
||||
public boolean getSendDeviceMeta() {
|
||||
return sendDeviceMeta;
|
||||
}
|
||||
@ -259,13 +230,6 @@ public class Options {
|
||||
}
|
||||
options.audioCodec = audioCodec;
|
||||
break;
|
||||
case "video_source":
|
||||
VideoSource videoSource = VideoSource.findByName(value);
|
||||
if (videoSource == null) {
|
||||
throw new IllegalArgumentException("Video source " + value + " not supported");
|
||||
}
|
||||
options.videoSource = videoSource;
|
||||
break;
|
||||
case "audio_source":
|
||||
AudioSource audioSource = AudioSource.findByName(value);
|
||||
if (audioSource == null) {
|
||||
@ -342,18 +306,6 @@ public class Options {
|
||||
case "list_displays":
|
||||
options.listDisplays = Boolean.parseBoolean(value);
|
||||
break;
|
||||
case "list_cameras":
|
||||
options.listCameras = Boolean.parseBoolean(value);
|
||||
break;
|
||||
case "list_camera_sizes":
|
||||
options.listCameraSizes = Boolean.parseBoolean(value);
|
||||
break;
|
||||
case "camera_id":
|
||||
options.cameraId = value;
|
||||
break;
|
||||
case "camera_size":
|
||||
options.cameraSize = parseSize(value);
|
||||
break;
|
||||
case "send_device_meta":
|
||||
options.sendDeviceMeta = Boolean.parseBoolean(value);
|
||||
break;
|
||||
@ -399,18 +351,4 @@ public class Options {
|
||||
int y = Integer.parseInt(tokens[3]);
|
||||
return new Rect(x, y, x + width, y + height);
|
||||
}
|
||||
|
||||
private static Size parseSize(String size) {
|
||||
if (size.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// input format: "<width>x<height>"
|
||||
String[] tokens = size.split("x");
|
||||
if (tokens.length != 2) {
|
||||
throw new IllegalArgumentException("Invalid size format (expected <width>x<height>): \"" + size + "\"");
|
||||
}
|
||||
int width = Integer.parseInt(tokens[0]);
|
||||
int height = Integer.parseInt(tokens[1]);
|
||||
return new Size(width, height);
|
||||
}
|
||||
}
|
||||
|
@ -1,84 +0,0 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import com.genymobile.scrcpy.wrappers.SurfaceControl;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.view.Surface;
|
||||
|
||||
public class ScreenCapture extends SurfaceCapture implements Device.RotationListener, Device.FoldListener {
|
||||
|
||||
private final Device device;
|
||||
private IBinder display;
|
||||
|
||||
public ScreenCapture(Device device) {
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
display = createDisplay();
|
||||
device.setRotationListener(this);
|
||||
device.setFoldListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Surface surface) {
|
||||
ScreenInfo screenInfo = device.getScreenInfo();
|
||||
Rect contentRect = screenInfo.getContentRect();
|
||||
|
||||
// does not include the locked video orientation
|
||||
Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
|
||||
int videoRotation = screenInfo.getVideoRotation();
|
||||
int layerStack = device.getLayerStack();
|
||||
setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
device.setRotationListener(null);
|
||||
device.setFoldListener(null);
|
||||
SurfaceControl.destroyDisplay(display);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getSize() {
|
||||
return device.getScreenInfo().getVideoSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMaxSize(int size) {
|
||||
device.setMaxSize(size);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFoldChanged(int displayId, boolean folded) {
|
||||
requestReset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRotationChanged(int rotation) {
|
||||
requestReset();
|
||||
}
|
||||
|
||||
private static IBinder createDisplay() {
|
||||
// Since Android 12 (preview), secure displays could not be created with shell permissions anymore.
|
||||
// On Android 12 preview, SDK_INT is still R (not S), but CODENAME is "S".
|
||||
boolean secure = Build.VERSION.SDK_INT < Build.VERSION_CODES.R || (Build.VERSION.SDK_INT == Build.VERSION_CODES.R && !"S".equals(
|
||||
Build.VERSION.CODENAME));
|
||||
return SurfaceControl.createDisplay("scrcpy", secure);
|
||||
}
|
||||
|
||||
private static void setDisplaySurface(IBinder display, Surface surface, int orientation, Rect deviceRect, Rect displayRect, int layerStack) {
|
||||
SurfaceControl.openTransaction();
|
||||
try {
|
||||
SurfaceControl.setDisplaySurface(display, surface);
|
||||
SurfaceControl.setDisplayProjection(display, orientation, deviceRect, displayRect);
|
||||
SurfaceControl.setDisplayLayerStack(display, layerStack);
|
||||
} finally {
|
||||
SurfaceControl.closeTransaction();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import com.genymobile.scrcpy.wrappers.SurfaceControl;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.media.MediaCodec;
|
||||
import android.media.MediaCodecInfo;
|
||||
import android.media.MediaFormat;
|
||||
import android.os.Looper;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
import android.view.Surface;
|
||||
|
||||
@ -12,7 +16,7 @@ import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class SurfaceEncoder implements AsyncProcessor {
|
||||
public class ScreenEncoder implements Device.RotationListener, Device.FoldListener, AsyncProcessor {
|
||||
|
||||
private static final int DEFAULT_I_FRAME_INTERVAL = 10; // seconds
|
||||
private static final int REPEAT_FRAME_DELAY_US = 100_000; // repeat after 100ms
|
||||
@ -22,7 +26,9 @@ public class SurfaceEncoder implements AsyncProcessor {
|
||||
private static final int[] MAX_SIZE_FALLBACK = {2560, 1920, 1600, 1280, 1024, 800};
|
||||
private static final int MAX_CONSECUTIVE_ERRORS = 3;
|
||||
|
||||
private final SurfaceCapture capture;
|
||||
private final AtomicBoolean resetCapture = new AtomicBoolean();
|
||||
|
||||
private final Device device;
|
||||
private final Streamer streamer;
|
||||
private final String encoderName;
|
||||
private final List<CodecOption> codecOptions;
|
||||
@ -36,9 +42,9 @@ public class SurfaceEncoder implements AsyncProcessor {
|
||||
private Thread thread;
|
||||
private final AtomicBoolean stopped = new AtomicBoolean();
|
||||
|
||||
public SurfaceEncoder(SurfaceCapture capture, Streamer streamer, int videoBitRate, int maxFps, List<CodecOption> codecOptions, String encoderName,
|
||||
public ScreenEncoder(Device device, Streamer streamer, int videoBitRate, int maxFps, List<CodecOption> codecOptions, String encoderName,
|
||||
boolean downsizeOnError) {
|
||||
this.capture = capture;
|
||||
this.device = device;
|
||||
this.streamer = streamer;
|
||||
this.videoBitRate = videoBitRate;
|
||||
this.maxFps = maxFps;
|
||||
@ -47,29 +53,51 @@ public class SurfaceEncoder implements AsyncProcessor {
|
||||
this.downsizeOnError = downsizeOnError;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFoldChanged(int displayId, boolean folded) {
|
||||
resetCapture.set(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRotationChanged(int rotation) {
|
||||
resetCapture.set(true);
|
||||
}
|
||||
|
||||
private boolean consumeResetCapture() {
|
||||
return resetCapture.getAndSet(false);
|
||||
}
|
||||
|
||||
private void streamScreen() throws IOException, ConfigurationException {
|
||||
Codec codec = streamer.getCodec();
|
||||
MediaCodec mediaCodec = createMediaCodec(codec, encoderName);
|
||||
MediaFormat format = createFormat(codec.getMimeType(), videoBitRate, maxFps, codecOptions);
|
||||
IBinder display = createDisplay();
|
||||
device.setRotationListener(this);
|
||||
device.setFoldListener(this);
|
||||
|
||||
capture.init();
|
||||
streamer.writeVideoHeader(device.getScreenInfo().getVideoSize());
|
||||
|
||||
boolean alive;
|
||||
try {
|
||||
streamer.writeVideoHeader(capture.getSize());
|
||||
|
||||
boolean alive;
|
||||
|
||||
do {
|
||||
Size size = capture.getSize();
|
||||
format.setInteger(MediaFormat.KEY_WIDTH, size.getWidth());
|
||||
format.setInteger(MediaFormat.KEY_HEIGHT, size.getHeight());
|
||||
ScreenInfo screenInfo = device.getScreenInfo();
|
||||
Rect contentRect = screenInfo.getContentRect();
|
||||
|
||||
// include the locked video orientation
|
||||
Rect videoRect = screenInfo.getVideoSize().toRect();
|
||||
format.setInteger(MediaFormat.KEY_WIDTH, videoRect.width());
|
||||
format.setInteger(MediaFormat.KEY_HEIGHT, videoRect.height());
|
||||
|
||||
Surface surface = null;
|
||||
try {
|
||||
mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
|
||||
surface = mediaCodec.createInputSurface();
|
||||
|
||||
capture.start(surface);
|
||||
// does not include the locked video orientation
|
||||
Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
|
||||
int videoRotation = screenInfo.getVideoRotation();
|
||||
int layerStack = device.getLayerStack();
|
||||
setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
|
||||
|
||||
mediaCodec.start();
|
||||
|
||||
@ -78,7 +106,7 @@ public class SurfaceEncoder implements AsyncProcessor {
|
||||
mediaCodec.stop();
|
||||
} catch (IllegalStateException | IllegalArgumentException e) {
|
||||
Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage());
|
||||
if (!prepareRetry(size)) {
|
||||
if (!prepareRetry(device, screenInfo)) {
|
||||
throw e;
|
||||
}
|
||||
Ln.i("Retrying...");
|
||||
@ -92,11 +120,13 @@ public class SurfaceEncoder implements AsyncProcessor {
|
||||
} while (alive);
|
||||
} finally {
|
||||
mediaCodec.release();
|
||||
capture.release();
|
||||
device.setRotationListener(null);
|
||||
device.setFoldListener(null);
|
||||
SurfaceControl.destroyDisplay(display);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean prepareRetry(Size currentSize) {
|
||||
private boolean prepareRetry(Device device, ScreenInfo screenInfo) {
|
||||
if (firstFrameSent) {
|
||||
++consecutiveErrors;
|
||||
if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) {
|
||||
@ -116,19 +146,16 @@ public class SurfaceEncoder implements AsyncProcessor {
|
||||
|
||||
// Downsizing on error is only enabled if an encoding failure occurs before the first frame (downsizing later could be surprising)
|
||||
|
||||
int newMaxSize = chooseMaxSizeFallback(currentSize);
|
||||
int newMaxSize = chooseMaxSizeFallback(screenInfo.getVideoSize());
|
||||
Ln.i("newMaxSize = " + newMaxSize);
|
||||
if (newMaxSize == 0) {
|
||||
// Must definitively fail
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean accepted = capture.setMaxSize(newMaxSize);
|
||||
if (!accepted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Retry with a smaller size
|
||||
// Retry with a smaller device size
|
||||
Ln.i("Retrying with -m" + newMaxSize + "...");
|
||||
device.setMaxSize(newMaxSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -149,14 +176,14 @@ public class SurfaceEncoder implements AsyncProcessor {
|
||||
boolean alive = true;
|
||||
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
||||
|
||||
while (!capture.consumeReset() && !eof) {
|
||||
while (!consumeResetCapture() && !eof) {
|
||||
if (stopped.get()) {
|
||||
alive = false;
|
||||
break;
|
||||
}
|
||||
int outputBufferId = codec.dequeueOutputBuffer(bufferInfo, -1);
|
||||
try {
|
||||
if (capture.consumeReset()) {
|
||||
if (consumeResetCapture()) {
|
||||
// must restart encoding with new size
|
||||
break;
|
||||
}
|
||||
@ -181,11 +208,6 @@ public class SurfaceEncoder implements AsyncProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
if (capture.isClosed()) {
|
||||
// The capture might have been closed internally (for example if the camera is disconnected)
|
||||
alive = false;
|
||||
}
|
||||
|
||||
return !eof && alive;
|
||||
}
|
||||
|
||||
@ -242,13 +264,28 @@ public class SurfaceEncoder implements AsyncProcessor {
|
||||
return format;
|
||||
}
|
||||
|
||||
private static IBinder createDisplay() {
|
||||
// Since Android 12 (preview), secure displays could not be created with shell permissions anymore.
|
||||
// On Android 12 preview, SDK_INT is still R (not S), but CODENAME is "S".
|
||||
boolean secure = Build.VERSION.SDK_INT < Build.VERSION_CODES.R || (Build.VERSION.SDK_INT == Build.VERSION_CODES.R && !"S"
|
||||
.equals(Build.VERSION.CODENAME));
|
||||
return SurfaceControl.createDisplay("scrcpy", secure);
|
||||
}
|
||||
|
||||
private static void setDisplaySurface(IBinder display, Surface surface, int orientation, Rect deviceRect, Rect displayRect, int layerStack) {
|
||||
SurfaceControl.openTransaction();
|
||||
try {
|
||||
SurfaceControl.setDisplaySurface(display, surface);
|
||||
SurfaceControl.setDisplayProjection(display, orientation, deviceRect, displayRect);
|
||||
SurfaceControl.setDisplayLayerStack(display, layerStack);
|
||||
} finally {
|
||||
SurfaceControl.closeTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(TerminationListener listener) {
|
||||
thread = new Thread(() -> {
|
||||
// Some devices (Meizu) deadlock if the video encoding thread has no Looper
|
||||
// <https://github.com/Genymobile/scrcpy/issues/4143>
|
||||
Looper.prepare();
|
||||
|
||||
try {
|
||||
streamScreen();
|
||||
} catch (ConfigurationException e) {
|
@ -2,7 +2,6 @@ package com.genymobile.scrcpy;
|
||||
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Looper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -100,8 +99,7 @@ public final class Server {
|
||||
boolean audio = options.getAudio();
|
||||
boolean sendDummyByte = options.getSendDummyByte();
|
||||
|
||||
boolean camera = true;
|
||||
Workarounds.apply(audio, camera);
|
||||
Workarounds.apply(audio);
|
||||
|
||||
List<AsyncProcessor> asyncProcessors = new ArrayList<>();
|
||||
|
||||
@ -134,15 +132,9 @@ public final class Server {
|
||||
if (video) {
|
||||
Streamer videoStreamer = new Streamer(connection.getVideoFd(), options.getVideoCodec(), options.getSendCodecMeta(),
|
||||
options.getSendFrameMeta());
|
||||
SurfaceCapture surfaceCapture;
|
||||
if (options.getVideoSource() == VideoSource.DISPLAY) {
|
||||
surfaceCapture = new ScreenCapture(device);
|
||||
} else {
|
||||
surfaceCapture = new CameraCapture(options.getCameraId(), options.getCameraSize());
|
||||
}
|
||||
SurfaceEncoder surfaceEncoder = new SurfaceEncoder(surfaceCapture, videoStreamer, options.getVideoBitRate(), options.getMaxFps(),
|
||||
ScreenEncoder screenEncoder = new ScreenEncoder(device, videoStreamer, options.getVideoBitRate(), options.getMaxFps(),
|
||||
options.getVideoCodecOptions(), options.getVideoEncoder(), options.getDownsizeOnError());
|
||||
asyncProcessors.add(surfaceEncoder);
|
||||
asyncProcessors.add(screenEncoder);
|
||||
}
|
||||
|
||||
Completion completion = new Completion(asyncProcessors.size());
|
||||
@ -187,7 +179,7 @@ public final class Server {
|
||||
|
||||
Ln.initLogLevel(options.getLogLevel());
|
||||
|
||||
if (options.getList()) {
|
||||
if (options.getListEncoders() || options.getListDisplays()) {
|
||||
if (options.getCleanup()) {
|
||||
CleanUp.unlinkSelf();
|
||||
}
|
||||
@ -199,10 +191,6 @@ public final class Server {
|
||||
if (options.getListDisplays()) {
|
||||
Ln.i(LogUtils.buildDisplayListMessage());
|
||||
}
|
||||
if (options.getListCameras() || options.getListCameraSizes()) {
|
||||
Workarounds.apply(false, true);
|
||||
Ln.i(LogUtils.buildCameraListMessage(options.getListCameraSizes()));
|
||||
}
|
||||
// Just print the requested data, do not mirror
|
||||
return;
|
||||
}
|
||||
|
@ -1,71 +0,0 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import android.view.Surface;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* A video source which can be rendered on a Surface for encoding.
|
||||
*/
|
||||
public abstract class SurfaceCapture {
|
||||
|
||||
private final AtomicBoolean resetCapture = new AtomicBoolean();
|
||||
|
||||
/**
|
||||
* Request the encoding session to be restarted, for example if the capture implementation detects that the video source size has changed (on
|
||||
* device rotation for example).
|
||||
*/
|
||||
protected void requestReset() {
|
||||
resetCapture.set(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consume the reset request (intended to be called by the encoder).
|
||||
*
|
||||
* @return {@code true} if a reset request was pending, {@code false} otherwise.
|
||||
*/
|
||||
public boolean consumeReset() {
|
||||
return resetCapture.getAndSet(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called once before the capture starts.
|
||||
*/
|
||||
public abstract void init() throws IOException;
|
||||
|
||||
/**
|
||||
* Called after the capture ends (if and only if {@link #init()} has been called).
|
||||
*/
|
||||
public abstract void release();
|
||||
|
||||
/**
|
||||
* Start the capture to the target surface.
|
||||
*
|
||||
* @param surface the surface which will be encoded
|
||||
*/
|
||||
public abstract void start(Surface surface) throws IOException;
|
||||
|
||||
/**
|
||||
* Return the video size
|
||||
*
|
||||
* @return the video size
|
||||
*/
|
||||
public abstract Size getSize();
|
||||
|
||||
/**
|
||||
* Set the maximum capture size (set by the encoder if it does not support the current size).
|
||||
*
|
||||
* @param size Maximum size
|
||||
*/
|
||||
public abstract boolean setMaxSize(int size);
|
||||
|
||||
/**
|
||||
* Indicate if the capture has been closed internally.
|
||||
*
|
||||
* @return {@code true} is the capture is closed, {@code false} otherwise.
|
||||
*/
|
||||
public boolean isClosed() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import android.media.MediaRecorder;
|
||||
|
||||
public enum VideoSource {
|
||||
DISPLAY("display"),
|
||||
CAMERA("camera");
|
||||
|
||||
private final String name;
|
||||
|
||||
VideoSource(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
static VideoSource findByName(String name) {
|
||||
for (VideoSource videoSource : VideoSource.values()) {
|
||||
if (name.equals(videoSource.name)) {
|
||||
return videoSource;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -28,13 +28,14 @@ public final class Workarounds {
|
||||
// not instantiable
|
||||
}
|
||||
|
||||
public static void apply(boolean audio, boolean camera) {
|
||||
public static void apply(boolean audio) {
|
||||
Workarounds.prepareMainLooper();
|
||||
|
||||
boolean mustFillAppInfo = false;
|
||||
boolean mustFillBaseContext = true;
|
||||
boolean mustFillBaseContext = false;
|
||||
boolean mustFillAppContext = false;
|
||||
|
||||
|
||||
if (Build.BRAND.equalsIgnoreCase("meizu")) {
|
||||
// Workarounds must be applied for Meizu phones:
|
||||
// - <https://github.com/Genymobile/scrcpy/issues/240>
|
||||
@ -64,10 +65,6 @@ public final class Workarounds {
|
||||
mustFillAppContext = true;
|
||||
}
|
||||
|
||||
if (camera) {
|
||||
mustFillAppInfo = true;
|
||||
}
|
||||
|
||||
if (mustFillAppInfo) {
|
||||
Workarounds.fillAppInfo();
|
||||
}
|
||||
@ -157,7 +154,7 @@ public final class Workarounds {
|
||||
}
|
||||
}
|
||||
|
||||
private static void fillBaseContext() {
|
||||
public static void fillBaseContext() {
|
||||
try {
|
||||
fillActivityThread();
|
||||
|
||||
|
@ -17,7 +17,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
|
||||
public final class ActivityManager {
|
||||
public class ActivityManager {
|
||||
|
||||
private final IInterface manager;
|
||||
private Method getContentProviderExternalMethod;
|
||||
|
@ -11,7 +11,7 @@ import android.os.IInterface;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class ClipboardManager {
|
||||
public class ClipboardManager {
|
||||
private final IInterface manager;
|
||||
private Method getPrimaryClipMethod;
|
||||
private Method setPrimaryClipMethod;
|
||||
|
@ -14,7 +14,7 @@ import java.io.Closeable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class ContentProvider implements Closeable {
|
||||
public class ContentProvider implements Closeable {
|
||||
|
||||
public static final String TABLE_SYSTEM = "system";
|
||||
public static final String TABLE_SECURE = "secure";
|
||||
|
@ -1,15 +1,9 @@
|
||||
package com.genymobile.scrcpy.wrappers;
|
||||
|
||||
import com.genymobile.scrcpy.FakeContext;
|
||||
import com.genymobile.scrcpy.Workarounds;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.hardware.camera2.CameraManager;
|
||||
import android.os.IBinder;
|
||||
import android.os.IInterface;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@ -32,7 +26,6 @@ public final class ServiceManager {
|
||||
private static StatusBarManager statusBarManager;
|
||||
private static ClipboardManager clipboardManager;
|
||||
private static ActivityManager activityManager;
|
||||
private static CameraManager cameraManager;
|
||||
|
||||
private ServiceManager() {
|
||||
/* not instantiable */
|
||||
@ -136,16 +129,4 @@ public final class ServiceManager {
|
||||
|
||||
return activityManager;
|
||||
}
|
||||
|
||||
public static CameraManager getCameraManager() {
|
||||
if (cameraManager == null) {
|
||||
try {
|
||||
Constructor<CameraManager> ctor = CameraManager.class.getDeclaredConstructor(Context.class);
|
||||
cameraManager = ctor.newInstance(FakeContext.get());
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
return cameraManager;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import android.os.IInterface;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class StatusBarManager {
|
||||
public class StatusBarManager {
|
||||
|
||||
private final IInterface manager;
|
||||
private Method expandNotificationsPanelMethod;
|
||||
|
@ -2,7 +2,6 @@ package com.genymobile.scrcpy.wrappers;
|
||||
|
||||
import com.genymobile.scrcpy.Ln;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.IInterface;
|
||||
import android.view.IRotationWatcher;
|
||||
import android.view.IDisplayFoldListener;
|
||||
@ -107,17 +106,16 @@ public final class WindowManager {
|
||||
cls.getMethod("watchRotation", IRotationWatcher.class).invoke(manager, rotationWatcher);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Ln.e("Could not register rotation watcher", e);
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(29)
|
||||
public void registerDisplayFoldListener(IDisplayFoldListener foldListener) {
|
||||
try {
|
||||
Class<?> cls = manager.getClass();
|
||||
cls.getMethod("registerDisplayFoldListener", IDisplayFoldListener.class).invoke(manager, foldListener);
|
||||
} catch (Exception e) {
|
||||
Ln.e("Could not register display fold listener", e);
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user