Compare commits
90 Commits
activity_t
...
v2.2
Author | SHA1 | Date | |
---|---|---|---|
c3c7bf7af3 | |||
5000368c2f | |||
855ae4adb1 | |||
a8db3ec9e2 | |||
ff579990c2 | |||
b8c5853aa6 | |||
c64d150202 | |||
8350a61926 | |||
5580803406 | |||
9bfc749803 | |||
6af4bd601f | |||
4722bff423 | |||
928f8b8eb3 | |||
9fc5835485 | |||
dd36d6135f | |||
faebb7d70a | |||
7f8d079c8c | |||
64930e71b9 | |||
d544e577c0 | |||
bfeecc0131 | |||
f032262cd7 | |||
cd63896d63 | |||
f085765e04 | |||
a2fb1b40f6 | |||
41ccb5883e | |||
23e116064d | |||
3432029a3d | |||
7a2b756f1e | |||
b7ad652a75 | |||
76a99a7fcd | |||
68b55ef2fe | |||
bc8913e12b | |||
3c2013de10 | |||
8cef8bac94 | |||
0bbe8a7007 | |||
9fdb882509 | |||
8e7b041f35 | |||
9ade389069 | |||
90ba885547 | |||
7adf98e9d4 | |||
90ca46ee41 | |||
1c864a88eb | |||
1650b7c058 | |||
a7c3c9a54c | |||
111d02fca4 | |||
36670dda40 | |||
0983f0a194 | |||
110b3a16f6 | |||
1ee46970e3 | |||
fcdf847dd3 | |||
ad05a01800 | |||
328ed3650d | |||
c14668b177 | |||
637f48f360 | |||
d391fc3b69 | |||
75ad925423 | |||
7e936fa879 | |||
01d785d9a3 | |||
fe6e9acb36 | |||
625934fb1b | |||
85b55b3c4e | |||
7b7076ef85 | |||
808bd14e30 | |||
0049b3ce07 | |||
5764f47fee | |||
2dab1f7024 | |||
744312ec64 | |||
b9315620e2 | |||
ea59d525bd | |||
0ffcfa0f5c | |||
c0f3c080b6 | |||
d046678f85 | |||
fae3fbc934 | |||
5061b7e02c | |||
09009c2aa7 | |||
fb21bbf763 | |||
0f1afff7a6 | |||
4ad7479425 | |||
958f22490b | |||
cb20bcb16f | |||
8f0b38cc4f | |||
a1e8a34001 | |||
00534b0b2d | |||
21df2c240e | |||
2d3059e1ab | |||
478aece68f | |||
55899c091e | |||
d9a644df9c | |||
45717733a1 | |||
6ad037ea04 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ build/
|
|||||||
.gradle/
|
.gradle/
|
||||||
/x/
|
/x/
|
||||||
local.properties
|
local.properties
|
||||||
|
/scrcpy-server
|
||||||
|
8
FAQ.md
8
FAQ.md
@ -159,6 +159,8 @@ In developer options, enable:
|
|||||||
> **USB debugging (Security settings)**
|
> **USB debugging (Security settings)**
|
||||||
> _Allow granting permissions and simulating input via USB debugging_
|
> _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
|
[simulating input]: https://github.com/Genymobile/scrcpy/issues/70#issuecomment-373286323
|
||||||
|
|
||||||
|
|
||||||
@ -168,12 +170,12 @@ The default text injection method is [limited to ASCII characters][text-input].
|
|||||||
A trick allows to also inject some [accented characters][accented-characters],
|
A trick allows to also inject some [accented characters][accented-characters],
|
||||||
but that's all. See [#37].
|
but that's all. See [#37].
|
||||||
|
|
||||||
Since scrcpy v1.20, it is possible to simulate a [physical keyboard][hid] (HID).
|
It is also possible to simulate a [physical keyboard][hid] (HID).
|
||||||
|
|
||||||
[text-input]: https://github.com/Genymobile/scrcpy/issues?q=is%3Aopen+is%3Aissue+label%3Aunicode
|
[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
|
[accented-characters]: https://blog.rom1v.com/2018/03/introducing-scrcpy/#handle-accented-characters
|
||||||
[#37]: https://github.com/Genymobile/scrcpy/issues/37
|
[#37]: https://github.com/Genymobile/scrcpy/issues/37
|
||||||
[hid]: README.md#physical-keyboard-simulation-hid
|
[hid]: doc/hid-otg.md
|
||||||
|
|
||||||
|
|
||||||
## Client issues
|
## Client issues
|
||||||
@ -229,4 +231,4 @@ Translations of this FAQ in other languages are available in the [wiki].
|
|||||||
|
|
||||||
[wiki]: https://github.com/Genymobile/scrcpy/wiki
|
[wiki]: https://github.com/Genymobile/scrcpy/wiki
|
||||||
|
|
||||||
Only this README file is guaranteed to be up-to-date.
|
Only this FAQ file is guaranteed to be up-to-date.
|
||||||
|
26
README.md
26
README.md
@ -1,11 +1,11 @@
|
|||||||
# scrcpy (v2.0)
|
# scrcpy (v2.1.1)
|
||||||
|
|
||||||
<img src="app/data/icon.svg" width="128" height="128" alt="scrcpy" align="right" />
|
<img src="app/data/icon.svg" width="128" height="128" alt="scrcpy" align="right" />
|
||||||
|
|
||||||
_pronounced "**scr**een **c**o**py**"_
|
_pronounced "**scr**een **c**o**py**"_
|
||||||
|
|
||||||
This application mirrors Android devices (video and audio) connected via
|
This application mirrors Android devices (video and audio) connected via
|
||||||
USB or [over TCP/IP](doc/device.md#tcpip-wireless), and allows to control the
|
USB or [over TCP/IP](doc/connection.md#tcpip-wireless), and allows to control the
|
||||||
device with the keyboard and the mouse of the computer. It does not require any
|
device with the keyboard and the mouse of the computer. It does not require any
|
||||||
_root_ access. It works on _Linux_, _Windows_ and _macOS_.
|
_root_ access. It works on _Linux_, _Windows_ and _macOS_.
|
||||||
|
|
||||||
@ -25,12 +25,13 @@ It focuses on:
|
|||||||
[lowlatency]: https://github.com/Genymobile/scrcpy/pull/646
|
[lowlatency]: https://github.com/Genymobile/scrcpy/pull/646
|
||||||
|
|
||||||
Its features include:
|
Its features include:
|
||||||
- [audio forwarding](doc/audio.md) (Android >= 11)
|
- [audio forwarding](doc/audio.md) (Android 11+)
|
||||||
- [recording](doc/recording.md)
|
- [recording](doc/recording.md)
|
||||||
- mirroring with [Android device screen off](doc/device.md#turn-screen-off)
|
- mirroring with [Android device screen off](doc/device.md#turn-screen-off)
|
||||||
- [copy-paste](doc/control.md#copy-paste) in both directions
|
- [copy-paste](doc/control.md#copy-paste) in both directions
|
||||||
- [configurable quality](doc/video.md)
|
- [configurable quality](doc/video.md)
|
||||||
- Android device [as a webcam (V4L2)](doc/v4l2.md) (Linux-only)
|
- [camera mirroring](doc/camera.md) (Android 12+)
|
||||||
|
- [mirroring as a webcam (V4L2)](doc/v4l2.md) (Linux-only)
|
||||||
- [physical keyboard/mouse simulation (HID)](doc/hid-otg.md)
|
- [physical keyboard/mouse simulation (HID)](doc/hid-otg.md)
|
||||||
- [OTG mode](doc/hid-otg.md#otg)
|
- [OTG mode](doc/hid-otg.md#otg)
|
||||||
- and more…
|
- and more…
|
||||||
@ -39,7 +40,7 @@ Its features include:
|
|||||||
|
|
||||||
The Android device requires at least API 21 (Android 5.0).
|
The Android device requires at least API 21 (Android 5.0).
|
||||||
|
|
||||||
[Audio forwarding](doc/audio.md) is supported from API 30 (Android 11).
|
[Audio forwarding](doc/audio.md) is supported for API >= 30 (Android 11+).
|
||||||
|
|
||||||
Make sure you [enabled USB debugging][enable-adb] on your device(s).
|
Make sure you [enabled USB debugging][enable-adb] on your device(s).
|
||||||
|
|
||||||
@ -47,10 +48,14 @@ 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
|
On some devices, you also need to enable [an additional option][control] `USB
|
||||||
debugging (Security Settings)` (this is an item different from `USB debugging`)
|
debugging (Security Settings)` (this is an item different from `USB debugging`)
|
||||||
to control it using a keyboard and mouse.
|
to control it using a keyboard and mouse. Rebooting the device is necessary once
|
||||||
|
this option is set.
|
||||||
|
|
||||||
[control]: https://github.com/Genymobile/scrcpy/issues/70#issuecomment-373286323
|
[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
|
## Get the app
|
||||||
|
|
||||||
@ -64,14 +69,16 @@ to control it using a keyboard and mouse.
|
|||||||
The application provides a lot of features and configuration options. They are
|
The application provides a lot of features and configuration options. They are
|
||||||
documented in the following pages:
|
documented in the following pages:
|
||||||
|
|
||||||
- [Device](doc/device.md)
|
- [Connection](doc/connection.md)
|
||||||
- [Video](doc/video.md)
|
- [Video](doc/video.md)
|
||||||
- [Audio](doc/audio.md)
|
- [Audio](doc/audio.md)
|
||||||
- [Control](doc/control.md)
|
- [Control](doc/control.md)
|
||||||
|
- [Device](doc/device.md)
|
||||||
- [Window](doc/window.md)
|
- [Window](doc/window.md)
|
||||||
- [Recording](doc/recording.md)
|
- [Recording](doc/recording.md)
|
||||||
- [Tunnels](doc/tunnels.md)
|
- [Tunnels](doc/tunnels.md)
|
||||||
- [HID/OTG](doc/hid-otg.md)
|
- [HID/OTG](doc/hid-otg.md)
|
||||||
|
- [Camera](doc/camera.md)
|
||||||
- [Video4Linux](doc/v4l2.md)
|
- [Video4Linux](doc/v4l2.md)
|
||||||
- [Shortcuts](doc/shortcuts.md)
|
- [Shortcuts](doc/shortcuts.md)
|
||||||
|
|
||||||
@ -113,7 +120,10 @@ For general questions or discussions, you can also use:
|
|||||||
I'm [@rom1v](https://github.com/rom1v), the author and maintainer of _scrcpy_.
|
I'm [@rom1v](https://github.com/rom1v), the author and maintainer of _scrcpy_.
|
||||||
|
|
||||||
If you appreciate this application, you can [support my open source
|
If you appreciate this application, you can [support my open source
|
||||||
work][donate].
|
work][donate]:
|
||||||
|
- [GitHub Sponsors](https://github.com/sponsors/rom1v)
|
||||||
|
- [Liberapay](https://liberapay.com/rom1v/)
|
||||||
|
- [PayPal](https://paypal.me/rom2v)
|
||||||
|
|
||||||
[donate]: https://blog.rom1v.com/about/#support-my-open-source-work
|
[donate]: https://blog.rom1v.com/about/#support-my-open-source-work
|
||||||
|
|
||||||
|
@ -10,10 +10,16 @@ _scrcpy() {
|
|||||||
--audio-source=
|
--audio-source=
|
||||||
--audio-output-buffer=
|
--audio-output-buffer=
|
||||||
-b --video-bit-rate=
|
-b --video-bit-rate=
|
||||||
|
--camera-ar=
|
||||||
|
--camera-id=
|
||||||
|
--camera-facing=
|
||||||
|
--camera-fps=
|
||||||
|
--camera-high-speed
|
||||||
|
--camera-size=
|
||||||
--crop=
|
--crop=
|
||||||
-d --select-usb
|
-d --select-usb
|
||||||
--disable-screensaver
|
--disable-screensaver
|
||||||
--display=
|
--display-id=
|
||||||
--display-buffer=
|
--display-buffer=
|
||||||
-e --select-tcpip
|
-e --select-tcpip
|
||||||
-f --fullscreen
|
-f --fullscreen
|
||||||
@ -23,6 +29,8 @@ _scrcpy() {
|
|||||||
--kill-adb-on-close
|
--kill-adb-on-close
|
||||||
-K --hid-keyboard
|
-K --hid-keyboard
|
||||||
--legacy-paste
|
--legacy-paste
|
||||||
|
--list-camera-sizes
|
||||||
|
--list-cameras
|
||||||
--list-displays
|
--list-displays
|
||||||
--list-encoders
|
--list-encoders
|
||||||
--lock-video-orientation
|
--lock-video-orientation
|
||||||
@ -44,6 +52,8 @@ _scrcpy() {
|
|||||||
--no-video-playback
|
--no-video-playback
|
||||||
--otg
|
--otg
|
||||||
-p --port=
|
-p --port=
|
||||||
|
--pause-on-exit
|
||||||
|
--pause-on-exit=
|
||||||
--power-off-on-close
|
--power-off-on-close
|
||||||
--prefer-text
|
--prefer-text
|
||||||
--print-fps
|
--print-fps
|
||||||
@ -70,6 +80,7 @@ _scrcpy() {
|
|||||||
--video-codec=
|
--video-codec=
|
||||||
--video-codec-options=
|
--video-codec-options=
|
||||||
--video-encoder=
|
--video-encoder=
|
||||||
|
--video-source=
|
||||||
-w --stay-awake
|
-w --stay-awake
|
||||||
--window-borderless
|
--window-borderless
|
||||||
--window-title=
|
--window-title=
|
||||||
@ -89,14 +100,26 @@ _scrcpy() {
|
|||||||
COMPREPLY=($(compgen -W 'opus aac raw' -- "$cur"))
|
COMPREPLY=($(compgen -W 'opus aac raw' -- "$cur"))
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
--video-source)
|
||||||
|
COMPREPLY=($(compgen -W 'display camera' -- "$cur"))
|
||||||
|
return
|
||||||
|
;;
|
||||||
--audio-source)
|
--audio-source)
|
||||||
COMPREPLY=($(compgen -W 'output mic' -- "$cur"))
|
COMPREPLY=($(compgen -W 'output mic' -- "$cur"))
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
--camera-facing)
|
||||||
|
COMPREPLY=($(compgen -W 'front back external' -- "$cur"))
|
||||||
|
return
|
||||||
|
;;
|
||||||
--lock-video-orientation)
|
--lock-video-orientation)
|
||||||
COMPREPLY=($(compgen -W 'unlocked initial 0 1 2 3' -- "$cur"))
|
COMPREPLY=($(compgen -W 'unlocked initial 0 1 2 3' -- "$cur"))
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
--pause-on-exit)
|
||||||
|
COMPREPLY=($(compgen -W 'true false if-error' -- "$cur"))
|
||||||
|
return
|
||||||
|
;;
|
||||||
-r|--record)
|
-r|--record)
|
||||||
COMPREPLY=($(compgen -f -- "$cur"))
|
COMPREPLY=($(compgen -f -- "$cur"))
|
||||||
return
|
return
|
||||||
@ -133,8 +156,12 @@ _scrcpy() {
|
|||||||
|--audio-codec-options \
|
|--audio-codec-options \
|
||||||
|--audio-encoder \
|
|--audio-encoder \
|
||||||
|--audio-output-buffer \
|
|--audio-output-buffer \
|
||||||
|
|--camera-ar \
|
||||||
|
|--camera-id \
|
||||||
|
|--camera-fps \
|
||||||
|
|--camera-size \
|
||||||
|--crop \
|
|--crop \
|
||||||
|--display \
|
|--display-id \
|
||||||
|--display-buffer \
|
|--display-buffer \
|
||||||
|--max-fps \
|
|--max-fps \
|
||||||
|-m|--max-size \
|
|-m|--max-size \
|
||||||
|
@ -1,4 +1,2 @@
|
|||||||
@echo off
|
@echo off
|
||||||
scrcpy.exe %*
|
scrcpy.exe --pause-on-exit=if-error %*
|
||||||
:: if the exit code is >= 1, then pause
|
|
||||||
if errorlevel 1 pause
|
|
||||||
|
@ -5,7 +5,7 @@ Comment=Display and control your Android device
|
|||||||
# For some users, the PATH or ADB environment variables are set from the shell
|
# For some users, the PATH or ADB environment variables are set from the shell
|
||||||
# startup file, like .bashrc or .zshrc… Run an interactive shell to get
|
# startup file, like .bashrc or .zshrc… Run an interactive shell to get
|
||||||
# environment correctly initialized.
|
# environment correctly initialized.
|
||||||
Exec=/bin/bash --norc --noprofile -i -c "\"\\$SHELL\" -i -c scrcpy || read -p 'Press Enter to quit...'"
|
Exec=/bin/sh -c "\"\\$SHELL\" -i -c scrcpy --pause-on-exit=if-error"
|
||||||
Icon=scrcpy
|
Icon=scrcpy
|
||||||
Terminal=true
|
Terminal=true
|
||||||
Type=Application
|
Type=Application
|
||||||
|
@ -17,10 +17,16 @@ arguments=(
|
|||||||
'--audio-source=[Select the audio source]:source:(output mic)'
|
'--audio-source=[Select the audio source]:source:(output mic)'
|
||||||
'--audio-output-buffer=[Configure the size of the SDL audio output buffer (in milliseconds)]'
|
'--audio-output-buffer=[Configure the size of the SDL audio output buffer (in milliseconds)]'
|
||||||
{-b,--video-bit-rate=}'[Encode the video at the given bit-rate]'
|
{-b,--video-bit-rate=}'[Encode the video at the given bit-rate]'
|
||||||
|
'--camera-ar=[Select the camera size by its aspect ratio]'
|
||||||
|
'--camera-high-speed=[Enable high-speed camera capture mode]'
|
||||||
|
'--camera-id=[Specify the camera id to mirror]'
|
||||||
|
'--camera-facing=[Select the device camera by its facing direction]:facing:(front back external)'
|
||||||
|
'--camera-fps=[Specify the camera capture frame rate]'
|
||||||
|
'--camera-size=[Specify an explicit camera capture size]'
|
||||||
'--crop=[\[width\:height\:x\:y\] Crop the device screen on the server]'
|
'--crop=[\[width\:height\:x\:y\] Crop the device screen on the server]'
|
||||||
{-d,--select-usb}'[Use USB device]'
|
{-d,--select-usb}'[Use USB device]'
|
||||||
'--disable-screensaver[Disable screensaver while scrcpy is running]'
|
'--disable-screensaver[Disable screensaver while scrcpy is running]'
|
||||||
'--display=[Specify the display id to mirror]'
|
'--display-id=[Specify the display id to mirror]'
|
||||||
'--display-buffer=[Add a buffering delay \(in milliseconds\) before displaying]'
|
'--display-buffer=[Add a buffering delay \(in milliseconds\) before displaying]'
|
||||||
{-e,--select-tcpip}'[Use TCP/IP device]'
|
{-e,--select-tcpip}'[Use TCP/IP device]'
|
||||||
{-f,--fullscreen}'[Start in fullscreen]'
|
{-f,--fullscreen}'[Start in fullscreen]'
|
||||||
@ -30,6 +36,8 @@ arguments=(
|
|||||||
'--kill-adb-on-close[Kill adb when scrcpy terminates]'
|
'--kill-adb-on-close[Kill adb when scrcpy terminates]'
|
||||||
{-K,--hid-keyboard}'[Simulate a physical keyboard by using HID over AOAv2]'
|
{-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]'
|
'--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-displays[List displays available on the device]'
|
||||||
'--list-encoders[List video and audio encoders 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)'
|
'--lock-video-orientation=[Lock video orientation]:orientation:(unlocked initial 0 1 2 3)'
|
||||||
@ -50,6 +58,7 @@ arguments=(
|
|||||||
'--no-video-playback[Disable video playback]'
|
'--no-video-playback[Disable video playback]'
|
||||||
'--otg[Run in OTG mode \(simulating physical keyboard and mouse\)]'
|
'--otg[Run in OTG mode \(simulating physical keyboard and mouse\)]'
|
||||||
{-p,--port=}'[\[port\[\:port\]\] Set the TCP port \(range\) used by the client to listen]'
|
{-p,--port=}'[\[port\[\:port\]\] Set the TCP port \(range\) used by the client to listen]'
|
||||||
|
'--pause-on-exit=[Make scrcpy pause before exiting]:mode:(true false if-error)'
|
||||||
'--power-off-on-close[Turn the device screen off when closing scrcpy]'
|
'--power-off-on-close[Turn the device screen off when closing scrcpy]'
|
||||||
'--prefer-text[Inject alpha characters and space as text events instead of key events]'
|
'--prefer-text[Inject alpha characters and space as text events instead of key events]'
|
||||||
'--print-fps[Start FPS counter, to print frame logs to the console]'
|
'--print-fps[Start FPS counter, to print frame logs to the console]'
|
||||||
@ -75,6 +84,7 @@ arguments=(
|
|||||||
'--video-codec=[Select the video codec]:codec:(h264 h265 av1)'
|
'--video-codec=[Select the video codec]:codec:(h264 h265 av1)'
|
||||||
'--video-codec-options=[Set a list of comma-separated key\:type=value options for the device video encoder]'
|
'--video-codec-options=[Set a list of comma-separated key\:type=value options for the device video encoder]'
|
||||||
'--video-encoder=[Use a specific MediaCodec video encoder]'
|
'--video-encoder=[Use a specific MediaCodec video encoder]'
|
||||||
|
'--video-source=[Select the video source]:source:(display camera)'
|
||||||
{-w,--stay-awake}'[Keep the device on while scrcpy is running, when the device is plugged in]'
|
{-w,--stay-awake}'[Keep the device on while scrcpy is running, when the device is plugged in]'
|
||||||
'--window-borderless[Disable window decorations \(display borderless window\)]'
|
'--window-borderless[Disable window decorations \(display borderless window\)]'
|
||||||
'--window-title=[Set a custom window title]'
|
'--window-title=[Set a custom window title]'
|
||||||
|
@ -6,10 +6,10 @@ cd "$DIR"
|
|||||||
mkdir -p "$PREBUILT_DATA_DIR"
|
mkdir -p "$PREBUILT_DATA_DIR"
|
||||||
cd "$PREBUILT_DATA_DIR"
|
cd "$PREBUILT_DATA_DIR"
|
||||||
|
|
||||||
DEP_DIR=platform-tools-34.0.1
|
DEP_DIR=platform-tools-34.0.5
|
||||||
|
|
||||||
FILENAME=platform-tools_r34.0.1-windows.zip
|
FILENAME=platform-tools_r34.0.5-windows.zip
|
||||||
SHA256SUM=5dd9c2be744c224fa3a7cbe30ba02d2cb378c763bd0f797a7e47e9f3156a5daa
|
SHA256SUM=3f8320152704377de150418a3c4c9d07d16d80a6c0d0d8f7289c22c499e33571
|
||||||
|
|
||||||
if [[ -d "$DEP_DIR" ]]
|
if [[ -d "$DEP_DIR" ]]
|
||||||
then
|
then
|
||||||
|
@ -6,10 +6,10 @@ cd "$DIR"
|
|||||||
mkdir -p "$PREBUILT_DATA_DIR"
|
mkdir -p "$PREBUILT_DATA_DIR"
|
||||||
cd "$PREBUILT_DATA_DIR"
|
cd "$PREBUILT_DATA_DIR"
|
||||||
|
|
||||||
DEP_DIR=SDL2-2.26.4
|
DEP_DIR=SDL2-2.28.4
|
||||||
|
|
||||||
FILENAME=SDL2-devel-2.26.4-mingw.tar.gz
|
FILENAME=SDL2-devel-2.28.4-mingw.tar.gz
|
||||||
SHA256SUM=fe899c8642caac2f180b1ee6f786857ddcaa0adc1fa82474312b09dd47d74712
|
SHA256SUM=779d091072cf97291f80030f5232d97aa3d48ab0f2c14fe0b9d9a33c593cdc35
|
||||||
|
|
||||||
if [[ -d "$DEP_DIR" ]]
|
if [[ -d "$DEP_DIR" ]]
|
||||||
then
|
then
|
||||||
|
@ -13,7 +13,7 @@ BEGIN
|
|||||||
VALUE "LegalCopyright", "Romain Vimont, Genymobile"
|
VALUE "LegalCopyright", "Romain Vimont, Genymobile"
|
||||||
VALUE "OriginalFilename", "scrcpy.exe"
|
VALUE "OriginalFilename", "scrcpy.exe"
|
||||||
VALUE "ProductName", "scrcpy"
|
VALUE "ProductName", "scrcpy"
|
||||||
VALUE "ProductVersion", "2.0"
|
VALUE "ProductVersion", "v2.2"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
112
app/scrcpy.1
112
app/scrcpy.1
@ -21,7 +21,7 @@ Make scrcpy window always on top (above other windows).
|
|||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-audio\-bit\-rate " value
|
.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).
|
Default is 128K (128000).
|
||||||
|
|
||||||
@ -45,15 +45,15 @@ Set a list of comma-separated key:type=value options for the device audio encode
|
|||||||
|
|
||||||
The possible values for 'type' are 'int' (default), 'long', 'float' and 'string'.
|
The possible values for 'type' are 'int' (default), 'long', 'float' and 'string'.
|
||||||
|
|
||||||
The list of possible codec options is available in the Android documentation
|
The list of possible codec options is available in the Android documentation:
|
||||||
.UR https://d.android.com/reference/android/media/MediaFormat
|
|
||||||
.UE .
|
<https://d.android.com/reference/android/media/MediaFormat>
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-audio\-encoder " name
|
.BI "\-\-audio\-encoder " name
|
||||||
Use a specific MediaCodec audio encoder (depending on the codec provided by \fB\-\-audio\-codec\fR).
|
Use a specific MediaCodec audio encoder (depending on the codec provided by \fB\-\-audio\-codec\fR).
|
||||||
|
|
||||||
The available encoders can be listed by \-\-list\-encoders.
|
The available encoders can be listed by \fB\-\-list\-encoders\fR.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-audio\-source " source
|
.BI "\-\-audio\-source " source
|
||||||
@ -71,10 +71,44 @@ Default is 5.
|
|||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-b, \-\-video\-bit\-rate " value
|
.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).
|
Default is 8M (8000000).
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI "\-\-camera\-ar " ar
|
||||||
|
Select the camera size by its aspect ratio (+/- 10%).
|
||||||
|
|
||||||
|
Possible values are "sensor" (use the camera sensor aspect ratio), "\fInum\fR:\fIden\fR" (e.g. "4:3") and "\fIvalue\fR" (e.g. "1.6").
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B \-\-camera\-high\-speed
|
||||||
|
Enable high-speed camera capture mode.
|
||||||
|
|
||||||
|
This mode is restricted to specific resolutions and frame rates, listed by \fB\-\-list\-camera\-sizes\fR.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI "\-\-camera\-id " id
|
||||||
|
Specify the device camera id to mirror.
|
||||||
|
|
||||||
|
The available camera ids can be listed by \fB\-\-list\-cameras\fR.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI "\-\-camera\-facing " facing
|
||||||
|
Select the device camera by its facing direction.
|
||||||
|
|
||||||
|
Possible values are "front", "back" and "external".
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI "\-\-camera\-fps " fps
|
||||||
|
Specify the camera capture frame rate.
|
||||||
|
|
||||||
|
If not specified, Android's default frame rate (30 fps) is used.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI "\-\-camera\-size " width\fRx\fIheight
|
||||||
|
Specify an explicit camera capture size.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-crop " width\fR:\fIheight\fR:\fIx\fR:\fIy
|
.BI "\-\-crop " width\fR:\fIheight\fR:\fIx\fR:\fIy
|
||||||
Crop the device screen on the server.
|
Crop the device screen on the server.
|
||||||
@ -94,10 +128,10 @@ Also see \fB\-e\fR (\fB\-\-select\-tcpip\fR).
|
|||||||
Disable screensaver while scrcpy is running.
|
Disable screensaver while scrcpy is running.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-display " id
|
.BI "\-\-display\-id " id
|
||||||
Specify the device display id to mirror.
|
Specify the device display id to mirror.
|
||||||
|
|
||||||
The available display ids can be listed by \-\-list\-displays.
|
The available display ids can be listed by \fB\-\-list\-displays\fR.
|
||||||
|
|
||||||
Default is 0.
|
Default is 0.
|
||||||
|
|
||||||
@ -155,6 +189,14 @@ 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.
|
This is a workaround for some devices not behaving as expected when setting the device clipboard programmatically.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B \-\-list\-camera\-sizes
|
||||||
|
List the valid camera capture sizes.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B \-\-list\-cameras
|
||||||
|
List cameras available on the device.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-\-list\-encoders
|
.B \-\-list\-encoders
|
||||||
List video and audio encoders available on the device.
|
List video and audio encoders available on the device.
|
||||||
@ -199,7 +241,7 @@ Disable device control (mirror the device in read\-only).
|
|||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-N, \-\-no\-playback
|
.B \-N, \-\-no\-playback
|
||||||
Disable video and audio playback on the computer (equivalent to --no-video-playback --no-audio-playback).
|
Disable video and audio playback on the computer (equivalent to \fB\-\-no\-video\-playback \-\-no\-audio\-playback\fR).
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-\-no\-audio
|
.B \-\-no\-audio
|
||||||
@ -267,6 +309,16 @@ Set the TCP port (range) used by the client to listen.
|
|||||||
|
|
||||||
Default is 27183:27199.
|
Default is 27183:27199.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
\fB\-\-pause\-on\-exit\fR[=\fImode\fR]
|
||||||
|
Configure pause on exit. Possible values are "true" (always pause on exit), "false" (never pause on exit) and "if-error" (pause only if an error occured).
|
||||||
|
|
||||||
|
This is useful to prevent the terminal window from automatically closing, so that error messages can be read.
|
||||||
|
|
||||||
|
Default is "false".
|
||||||
|
|
||||||
|
Passing the option without argument is equivalent to passing "true".
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-\-power\-off\-on\-close
|
.B \-\-power\-off\-on\-close
|
||||||
Turn the device screen off when closing scrcpy.
|
Turn the device screen off when closing scrcpy.
|
||||||
@ -311,8 +363,7 @@ Request SDL to use the given render driver (this is just a hint).
|
|||||||
|
|
||||||
Supported names are currently "direct3d", "opengl", "opengles2", "opengles", "metal" and "software".
|
Supported names are currently "direct3d", "opengl", "opengles2", "opengles", "metal" and "software".
|
||||||
|
|
||||||
.UR https://wiki.libsdl.org/SDL_HINT_RENDER_DRIVER
|
<https://wiki.libsdl.org/SDL_HINT_RENDER_DRIVER>
|
||||||
.UE
|
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-\-require\-audio
|
.B \-\-require\-audio
|
||||||
@ -360,13 +411,13 @@ Set the maximum mirroring time, in seconds.
|
|||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-tunnel\-host " ip
|
.BI "\-\-tunnel\-host " ip
|
||||||
Set the IP address of the adb tunnel to reach the scrcpy server. This option automatically enables --force-adb-forward.
|
Set the IP address of the adb tunnel to reach the scrcpy server. This option automatically enables \fB\-\-force\-adb\-forward\fR.
|
||||||
|
|
||||||
Default is localhost.
|
Default is localhost.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-tunnel\-port " port
|
.BI "\-\-tunnel\-port " port
|
||||||
Set the TCP port of the adb tunnel to reach the scrcpy server. This option automatically enables --force-adb-forward.
|
Set the TCP port of the adb tunnel to reach the scrcpy server. This option automatically enables \fB\-\-force\-adb\-forward\fR.
|
||||||
|
|
||||||
Default is 0 (not forced): the local port used for establishing the tunnel will be used.
|
Default is 0 (not forced): the local port used for establishing the tunnel will be used.
|
||||||
|
|
||||||
@ -406,15 +457,23 @@ Set a list of comma-separated key:type=value options for the device video encode
|
|||||||
|
|
||||||
The possible values for 'type' are 'int' (default), 'long', 'float' and 'string'.
|
The possible values for 'type' are 'int' (default), 'long', 'float' and 'string'.
|
||||||
|
|
||||||
The list of possible codec options is available in the Android documentation
|
The list of possible codec options is available in the Android documentation:
|
||||||
.UR https://d.android.com/reference/android/media/MediaFormat
|
|
||||||
.UE .
|
<https://d.android.com/reference/android/media/MediaFormat>
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-video\-encoder " name
|
.BI "\-\-video\-encoder " name
|
||||||
Use a specific MediaCodec video encoder (depending on the codec provided by \fB\-\-video\-codec\fR).
|
Use a specific MediaCodec video encoder (depending on the codec provided by \fB\-\-video\-codec\fR).
|
||||||
|
|
||||||
The available encoders can be listed by \-\-list\-encoders.
|
The available encoders can be listed by \fB\-\-list\-encoders\fR.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI "\-\-video\-source " source
|
||||||
|
Select the video source (display or camera).
|
||||||
|
|
||||||
|
Camera mirroring requires Android 12+.
|
||||||
|
|
||||||
|
Default is display.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-w, \-\-stay-awake
|
.B \-w, \-\-stay-awake
|
||||||
@ -576,7 +635,7 @@ Path to adb.
|
|||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B ANDROID_SERIAL
|
.B ANDROID_SERIAL
|
||||||
Device serial to use if no selector (-s, -d, -e or --tcpip=<addr>) is specified.
|
Device serial to use if no selector (\fB-s\fR, \fB-d\fR, \fB-e\fR or \fB\-\-tcpip=\fIaddr\fR) is specified.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B SCRCPY_ICON_PATH
|
.B SCRCPY_ICON_PATH
|
||||||
@ -599,23 +658,14 @@ for the Debian Project (and may be used by others).
|
|||||||
|
|
||||||
|
|
||||||
.SH "REPORTING BUGS"
|
.SH "REPORTING BUGS"
|
||||||
Report bugs to
|
Report bugs to <https://github.com/Genymobile/scrcpy/issues>.
|
||||||
.UR https://github.com/Genymobile/scrcpy/issues
|
|
||||||
.UE .
|
|
||||||
|
|
||||||
.SH COPYRIGHT
|
.SH COPYRIGHT
|
||||||
Copyright \(co 2018 Genymobile
|
Copyright \(co 2018 Genymobile <https://www.genymobile.com>
|
||||||
.UR https://www.genymobile.com
|
|
||||||
Genymobile
|
|
||||||
.UE
|
|
||||||
|
|
||||||
Copyright \(co 2018\-2023
|
Copyright \(co 2018\-2023 Romain Vimont <rom@rom1v.com>
|
||||||
.MT rom@rom1v.com
|
|
||||||
Romain Vimont
|
|
||||||
.ME
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0.
|
Licensed under the Apache License, Version 2.0.
|
||||||
|
|
||||||
.SH WWW
|
.SH WWW
|
||||||
.UR https://github.com/Genymobile/scrcpy
|
<https://github.com/Genymobile/scrcpy>
|
||||||
.UE
|
|
||||||
|
@ -70,7 +70,7 @@ argv_to_string(const char *const *argv, char *buf, size_t bufsize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
show_adb_installation_msg() {
|
show_adb_installation_msg(void) {
|
||||||
#ifndef __WINDOWS__
|
#ifndef __WINDOWS__
|
||||||
static const struct {
|
static const struct {
|
||||||
const char *binary;
|
const char *binary;
|
||||||
@ -218,8 +218,16 @@ sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
|
|||||||
const char *device_socket_name, unsigned flags) {
|
const char *device_socket_name, unsigned flags) {
|
||||||
char local[4 + 5 + 1]; // tcp:PORT
|
char local[4 + 5 + 1]; // tcp:PORT
|
||||||
char remote[108 + 14 + 1]; // localabstract:NAME
|
char remote[108 + 14 + 1]; // localabstract:NAME
|
||||||
sprintf(local, "tcp:%" PRIu16, local_port);
|
|
||||||
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name);
|
int r = snprintf(local, sizeof(local), "tcp:%" PRIu16, local_port);
|
||||||
|
assert(r >= 0 && (size_t) r < sizeof(local));
|
||||||
|
|
||||||
|
r = snprintf(remote, sizeof(remote), "localabstract:%s",
|
||||||
|
device_socket_name);
|
||||||
|
if (r < 0 || (size_t) r >= sizeof(remote)) {
|
||||||
|
LOGE("Could not write socket name");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
assert(serial);
|
assert(serial);
|
||||||
const char *const argv[] =
|
const char *const argv[] =
|
||||||
@ -233,7 +241,9 @@ bool
|
|||||||
sc_adb_forward_remove(struct sc_intr *intr, const char *serial,
|
sc_adb_forward_remove(struct sc_intr *intr, const char *serial,
|
||||||
uint16_t local_port, unsigned flags) {
|
uint16_t local_port, unsigned flags) {
|
||||||
char local[4 + 5 + 1]; // tcp:PORT
|
char local[4 + 5 + 1]; // tcp:PORT
|
||||||
sprintf(local, "tcp:%" PRIu16, local_port);
|
int r = snprintf(local, sizeof(local), "tcp:%" PRIu16, local_port);
|
||||||
|
assert(r >= 0 && (size_t) r < sizeof(local));
|
||||||
|
(void) r;
|
||||||
|
|
||||||
assert(serial);
|
assert(serial);
|
||||||
const char *const argv[] =
|
const char *const argv[] =
|
||||||
@ -249,8 +259,16 @@ sc_adb_reverse(struct sc_intr *intr, const char *serial,
|
|||||||
unsigned flags) {
|
unsigned flags) {
|
||||||
char local[4 + 5 + 1]; // tcp:PORT
|
char local[4 + 5 + 1]; // tcp:PORT
|
||||||
char remote[108 + 14 + 1]; // localabstract:NAME
|
char remote[108 + 14 + 1]; // localabstract:NAME
|
||||||
sprintf(local, "tcp:%" PRIu16, local_port);
|
int r = snprintf(local, sizeof(local), "tcp:%" PRIu16, local_port);
|
||||||
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name);
|
assert(r >= 0 && (size_t) r < sizeof(local));
|
||||||
|
|
||||||
|
r = snprintf(remote, sizeof(remote), "localabstract:%s",
|
||||||
|
device_socket_name);
|
||||||
|
if (r < 0 || (size_t) r >= sizeof(remote)) {
|
||||||
|
LOGE("Could not write socket name");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
assert(serial);
|
assert(serial);
|
||||||
const char *const argv[] =
|
const char *const argv[] =
|
||||||
SC_ADB_COMMAND("-s", serial, "reverse", remote, local);
|
SC_ADB_COMMAND("-s", serial, "reverse", remote, local);
|
||||||
@ -263,7 +281,12 @@ bool
|
|||||||
sc_adb_reverse_remove(struct sc_intr *intr, const char *serial,
|
sc_adb_reverse_remove(struct sc_intr *intr, const char *serial,
|
||||||
const char *device_socket_name, unsigned flags) {
|
const char *device_socket_name, unsigned flags) {
|
||||||
char remote[108 + 14 + 1]; // localabstract:NAME
|
char remote[108 + 14 + 1]; // localabstract:NAME
|
||||||
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name);
|
int r = snprintf(remote, sizeof(remote), "localabstract:%s",
|
||||||
|
device_socket_name);
|
||||||
|
if (r < 0 || (size_t) r >= sizeof(remote)) {
|
||||||
|
LOGE("Device socket name too long");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
assert(serial);
|
assert(serial);
|
||||||
const char *const argv[] =
|
const char *const argv[] =
|
||||||
@ -333,7 +356,9 @@ bool
|
|||||||
sc_adb_tcpip(struct sc_intr *intr, const char *serial, uint16_t port,
|
sc_adb_tcpip(struct sc_intr *intr, const char *serial, uint16_t port,
|
||||||
unsigned flags) {
|
unsigned flags) {
|
||||||
char port_string[5 + 1];
|
char port_string[5 + 1];
|
||||||
sprintf(port_string, "%" PRIu16, port);
|
int r = snprintf(port_string, sizeof(port_string), "%" PRIu16, port);
|
||||||
|
assert(r >= 0 && (size_t) r < sizeof(port_string));
|
||||||
|
(void) r;
|
||||||
|
|
||||||
assert(serial);
|
assert(serial);
|
||||||
const char *const argv[] =
|
const char *const argv[] =
|
||||||
@ -628,8 +653,8 @@ sc_adb_select_device(struct sc_intr *intr,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGD("ADB device found:");
|
LOGI("ADB device found:");
|
||||||
sc_adb_devices_log(SC_LOG_LEVEL_DEBUG, vec.data, vec.size);
|
sc_adb_devices_log(SC_LOG_LEVEL_INFO, vec.data, vec.size);
|
||||||
|
|
||||||
// Move devics into out_device (do not destroy device)
|
// Move devics into out_device (do not destroy device)
|
||||||
sc_adb_device_move(out_device, device);
|
sc_adb_device_move(out_device, device);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "util/str.h"
|
#include "util/str.h"
|
||||||
|
|
||||||
bool
|
static bool
|
||||||
sc_adb_parse_device(char *line, struct sc_adb_device *device) {
|
sc_adb_parse_device(char *line, struct sc_adb_device *device) {
|
||||||
// One device line looks like:
|
// One device line looks like:
|
||||||
// "0123456789abcdef device usb:2-1 product:MyProduct model:MyModel "
|
// "0123456789abcdef device usb:2-1 product:MyProduct model:MyModel "
|
||||||
|
331
app/src/cli.c
331
app/src/cli.c
@ -32,6 +32,7 @@ enum {
|
|||||||
OPT_WINDOW_BORDERLESS,
|
OPT_WINDOW_BORDERLESS,
|
||||||
OPT_MAX_FPS,
|
OPT_MAX_FPS,
|
||||||
OPT_LOCK_VIDEO_ORIENTATION,
|
OPT_LOCK_VIDEO_ORIENTATION,
|
||||||
|
OPT_DISPLAY,
|
||||||
OPT_DISPLAY_ID,
|
OPT_DISPLAY_ID,
|
||||||
OPT_ROTATION,
|
OPT_ROTATION,
|
||||||
OPT_RENDER_DRIVER,
|
OPT_RENDER_DRIVER,
|
||||||
@ -76,9 +77,19 @@ enum {
|
|||||||
OPT_NO_VIDEO,
|
OPT_NO_VIDEO,
|
||||||
OPT_NO_AUDIO_PLAYBACK,
|
OPT_NO_AUDIO_PLAYBACK,
|
||||||
OPT_NO_VIDEO_PLAYBACK,
|
OPT_NO_VIDEO_PLAYBACK,
|
||||||
|
OPT_VIDEO_SOURCE,
|
||||||
OPT_AUDIO_SOURCE,
|
OPT_AUDIO_SOURCE,
|
||||||
OPT_KILL_ADB_ON_CLOSE,
|
OPT_KILL_ADB_ON_CLOSE,
|
||||||
OPT_TIME_LIMIT,
|
OPT_TIME_LIMIT,
|
||||||
|
OPT_PAUSE_ON_EXIT,
|
||||||
|
OPT_LIST_CAMERAS,
|
||||||
|
OPT_LIST_CAMERA_SIZES,
|
||||||
|
OPT_CAMERA_ID,
|
||||||
|
OPT_CAMERA_SIZE,
|
||||||
|
OPT_CAMERA_FACING,
|
||||||
|
OPT_CAMERA_AR,
|
||||||
|
OPT_CAMERA_FPS,
|
||||||
|
OPT_CAMERA_HIGH_SPEED,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sc_option {
|
struct sc_option {
|
||||||
@ -124,7 +135,7 @@ static const struct sc_option options[] = {
|
|||||||
.longopt_id = OPT_AUDIO_BIT_RATE,
|
.longopt_id = OPT_AUDIO_BIT_RATE,
|
||||||
.longopt = "audio-bit-rate",
|
.longopt = "audio-bit-rate",
|
||||||
.argdesc = "value",
|
.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"
|
"Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
|
||||||
"Default is 128K (128000).",
|
"Default is 128K (128000).",
|
||||||
},
|
},
|
||||||
@ -185,7 +196,7 @@ static const struct sc_option options[] = {
|
|||||||
.shortopt = 'b',
|
.shortopt = 'b',
|
||||||
.longopt = "video-bit-rate",
|
.longopt = "video-bit-rate",
|
||||||
.argdesc = "value",
|
.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"
|
"Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
|
||||||
"Default is 8M (8000000).",
|
"Default is 8M (8000000).",
|
||||||
},
|
},
|
||||||
@ -195,6 +206,51 @@ static const struct sc_option options[] = {
|
|||||||
.longopt = "bit-rate",
|
.longopt = "bit-rate",
|
||||||
.argdesc = "value",
|
.argdesc = "value",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.longopt_id = OPT_CAMERA_AR,
|
||||||
|
.longopt = "camera-ar",
|
||||||
|
.argdesc = "ar",
|
||||||
|
.text = "Select the camera size by its aspect ratio (+/- 10%).\n"
|
||||||
|
"Possible values are \"sensor\" (use the camera sensor aspect "
|
||||||
|
"ratio), \"<num>:<den>\" (e.g. \"4:3\") or \"<value>\" (e.g. "
|
||||||
|
"\"1.6\")."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.longopt_id = OPT_CAMERA_ID,
|
||||||
|
.longopt = "camera-id",
|
||||||
|
.argdesc = "id",
|
||||||
|
.text = "Specify the device camera id to mirror.\n"
|
||||||
|
"The available camera ids can be listed by:\n"
|
||||||
|
" scrcpy --list-cameras",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.longopt_id = OPT_CAMERA_FACING,
|
||||||
|
.longopt = "camera-facing",
|
||||||
|
.argdesc = "facing",
|
||||||
|
.text = "Select the device camera by its facing direction.\n"
|
||||||
|
"Possible values are \"front\", \"back\" and \"external\".",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.longopt_id = OPT_CAMERA_HIGH_SPEED,
|
||||||
|
.longopt = "camera-high-speed",
|
||||||
|
.text = "Enable high-speed camera capture mode.\n"
|
||||||
|
"This mode is restricted to specific resolutions and frame "
|
||||||
|
"rates, listed by --list-camera-sizes.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.longopt_id = OPT_CAMERA_SIZE,
|
||||||
|
.longopt = "camera-size",
|
||||||
|
.argdesc = "<width>x<height>",
|
||||||
|
.text = "Specify an explicit camera capture size.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.longopt_id = OPT_CAMERA_FPS,
|
||||||
|
.longopt = "camera-fps",
|
||||||
|
.argdesc = "value",
|
||||||
|
.text = "Specify the camera capture frame rate.\n"
|
||||||
|
"If not specified, Android's default frame rate (30 fps) is "
|
||||||
|
"used.",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
// Not really deprecated (--codec has never been released), but without
|
// Not really deprecated (--codec has never been released), but without
|
||||||
// declaring an explicit --codec option, getopt_long() partial matching
|
// declaring an explicit --codec option, getopt_long() partial matching
|
||||||
@ -231,9 +287,15 @@ static const struct sc_option options[] = {
|
|||||||
.text = "Disable screensaver while scrcpy is running.",
|
.text = "Disable screensaver while scrcpy is running.",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.longopt_id = OPT_DISPLAY_ID,
|
// deprecated
|
||||||
|
.longopt_id = OPT_DISPLAY,
|
||||||
.longopt = "display",
|
.longopt = "display",
|
||||||
.argdesc = "id",
|
.argdesc = "id",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.longopt_id = OPT_DISPLAY_ID,
|
||||||
|
.longopt = "display-id",
|
||||||
|
.argdesc = "id",
|
||||||
.text = "Specify the device display id to mirror.\n"
|
.text = "Specify the device display id to mirror.\n"
|
||||||
"The available display ids can be listed by:\n"
|
"The available display ids can be listed by:\n"
|
||||||
" scrcpy --list-displays\n"
|
" scrcpy --list-displays\n"
|
||||||
@ -312,6 +374,16 @@ static const struct sc_option options[] = {
|
|||||||
"This is a workaround for some devices not behaving as "
|
"This is a workaround for some devices not behaving as "
|
||||||
"expected when setting the device clipboard programmatically.",
|
"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_id = OPT_LIST_DISPLAYS,
|
||||||
.longopt = "list-displays",
|
.longopt = "list-displays",
|
||||||
@ -463,6 +535,20 @@ static const struct sc_option options[] = {
|
|||||||
"Default is " STR(DEFAULT_LOCAL_PORT_RANGE_FIRST) ":"
|
"Default is " STR(DEFAULT_LOCAL_PORT_RANGE_FIRST) ":"
|
||||||
STR(DEFAULT_LOCAL_PORT_RANGE_LAST) ".",
|
STR(DEFAULT_LOCAL_PORT_RANGE_LAST) ".",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.longopt_id = OPT_PAUSE_ON_EXIT,
|
||||||
|
.longopt = "pause-on-exit",
|
||||||
|
.argdesc = "mode",
|
||||||
|
.optional_arg = true,
|
||||||
|
.text = "Configure pause on exit. Possible values are \"true\" (always "
|
||||||
|
"pause on exit), \"false\" (never pause on exit) and "
|
||||||
|
"\"if-error\" (pause only if an error occured).\n"
|
||||||
|
"This is useful to prevent the terminal window from "
|
||||||
|
"automatically closing, so that error messages can be read.\n"
|
||||||
|
"Default is \"false\".\n"
|
||||||
|
"Passing the option without argument is equivalent to passing "
|
||||||
|
"\"true\".",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.longopt_id = OPT_POWER_OFF_ON_CLOSE,
|
.longopt_id = OPT_POWER_OFF_ON_CLOSE,
|
||||||
.longopt = "power-off-on-close",
|
.longopt = "power-off-on-close",
|
||||||
@ -669,6 +755,14 @@ static const struct sc_option options[] = {
|
|||||||
"codec provided by --video-codec).\n"
|
"codec provided by --video-codec).\n"
|
||||||
"The available encoders can be listed by --list-encoders.",
|
"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"
|
||||||
|
"Camera mirroring requires Android 12+.\n"
|
||||||
|
"Default is display.",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.shortopt = 'w',
|
.shortopt = 'w',
|
||||||
.longopt = "stay-awake",
|
.longopt = "stay-awake",
|
||||||
@ -1070,7 +1164,7 @@ print_shortcut(const struct sc_shortcut *shortcut, unsigned cols) {
|
|||||||
while (shortcut->shortcuts[i]) {
|
while (shortcut->shortcuts[i]) {
|
||||||
printf(" %s\n", shortcut->shortcuts[i]);
|
printf(" %s\n", shortcut->shortcuts[i]);
|
||||||
++i;
|
++i;
|
||||||
};
|
}
|
||||||
|
|
||||||
char *text = sc_str_wrap_lines(shortcut->text, cols, 8);
|
char *text = sc_str_wrap_lines(shortcut->text, cols, 8);
|
||||||
if (!text) {
|
if (!text) {
|
||||||
@ -1189,9 +1283,9 @@ parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
parse_integers_arg(const char *s, size_t max_items, long *out, long min,
|
parse_integers_arg(const char *s, const char sep, size_t max_items, long *out,
|
||||||
long max, const char *name) {
|
long min, long max, const char *name) {
|
||||||
size_t count = sc_str_parse_integers(s, ':', max_items, out);
|
size_t count = sc_str_parse_integers(s, sep, max_items, out);
|
||||||
if (!count) {
|
if (!count) {
|
||||||
LOGE("Could not parse %s: %s", name, s);
|
LOGE("Could not parse %s: %s", name, s);
|
||||||
return 0;
|
return 0;
|
||||||
@ -1238,7 +1332,7 @@ parse_max_size(const char *s, uint16_t *max_size) {
|
|||||||
static bool
|
static bool
|
||||||
parse_max_fps(const char *s, uint16_t *max_fps) {
|
parse_max_fps(const char *s, uint16_t *max_fps) {
|
||||||
long value;
|
long value;
|
||||||
bool ok = parse_integer_arg(s, &value, false, 0, 1000, "max fps");
|
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF, "max fps");
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1347,7 +1441,7 @@ parse_window_dimension(const char *s, uint16_t *dimension) {
|
|||||||
static bool
|
static bool
|
||||||
parse_port_range(const char *s, struct sc_port_range *port_range) {
|
parse_port_range(const char *s, struct sc_port_range *port_range) {
|
||||||
long values[2];
|
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) {
|
if (!count) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1609,6 +1703,22 @@ parse_audio_codec(const char *optarg, enum sc_codec *codec) {
|
|||||||
return false;
|
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
|
static bool
|
||||||
parse_audio_source(const char *optarg, enum sc_audio_source *source) {
|
parse_audio_source(const char *optarg, enum sc_audio_source *source) {
|
||||||
if (!strcmp(optarg, "mic")) {
|
if (!strcmp(optarg, "mic")) {
|
||||||
@ -1625,6 +1735,46 @@ parse_audio_source(const char *optarg, enum sc_audio_source *source) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
parse_camera_facing(const char *optarg, enum sc_camera_facing *facing) {
|
||||||
|
if (!strcmp(optarg, "front")) {
|
||||||
|
*facing = SC_CAMERA_FACING_FRONT;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(optarg, "back")) {
|
||||||
|
*facing = SC_CAMERA_FACING_BACK;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(optarg, "external")) {
|
||||||
|
*facing = SC_CAMERA_FACING_EXTERNAL;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*optarg == '\0') {
|
||||||
|
// Empty string is a valid value (equivalent to not passing the option)
|
||||||
|
*facing = SC_CAMERA_FACING_ANY;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGE("Unsupported camera facing: %s (expected front, back or external)",
|
||||||
|
optarg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
parse_camera_fps(const char *s, uint16_t *camera_fps) {
|
||||||
|
long value;
|
||||||
|
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF, "camera fps");
|
||||||
|
if (!ok) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*camera_fps = (uint16_t) value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
parse_time_limit(const char *s, sc_tick *tick) {
|
parse_time_limit(const char *s, sc_tick *tick) {
|
||||||
long value;
|
long value;
|
||||||
@ -1637,6 +1787,29 @@ parse_time_limit(const char *s, sc_tick *tick) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
parse_pause_on_exit(const char *s, enum sc_pause_on_exit *pause_on_exit) {
|
||||||
|
if (!s || !strcmp(s, "true")) {
|
||||||
|
*pause_on_exit = SC_PAUSE_ON_EXIT_TRUE;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(s, "false")) {
|
||||||
|
*pause_on_exit = SC_PAUSE_ON_EXIT_FALSE;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(s, "if-error")) {
|
||||||
|
*pause_on_exit = SC_PAUSE_ON_EXIT_IF_ERROR;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGE("Unsupported pause on exit mode: %s "
|
||||||
|
"(expected true, false or if-error)", optarg);
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||||
const char *optstring, const struct option *longopts) {
|
const char *optstring, const struct option *longopts) {
|
||||||
@ -1664,6 +1837,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
case OPT_CROP:
|
case OPT_CROP:
|
||||||
opts->crop = optarg;
|
opts->crop = optarg;
|
||||||
break;
|
break;
|
||||||
|
case OPT_DISPLAY:
|
||||||
|
LOGW("--display is deprecated, use --display-id instead.");
|
||||||
|
// fall through
|
||||||
case OPT_DISPLAY_ID:
|
case OPT_DISPLAY_ID:
|
||||||
if (!parse_display_id(optarg, &opts->display_id)) {
|
if (!parse_display_id(optarg, &opts->display_id)) {
|
||||||
return false;
|
return false;
|
||||||
@ -1945,10 +2121,16 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
case OPT_LIST_ENCODERS:
|
case OPT_LIST_ENCODERS:
|
||||||
opts->list_encoders = true;
|
opts->list |= SC_OPTION_LIST_ENCODERS;
|
||||||
break;
|
break;
|
||||||
case OPT_LIST_DISPLAYS:
|
case OPT_LIST_DISPLAYS:
|
||||||
opts->list_displays = true;
|
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;
|
||||||
break;
|
break;
|
||||||
case OPT_REQUIRE_AUDIO:
|
case OPT_REQUIRE_AUDIO:
|
||||||
opts->require_audio = true;
|
opts->require_audio = true;
|
||||||
@ -1964,6 +2146,11 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case OPT_VIDEO_SOURCE:
|
||||||
|
if (!parse_video_source(optarg, &opts->video_source)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case OPT_AUDIO_SOURCE:
|
case OPT_AUDIO_SOURCE:
|
||||||
if (!parse_audio_source(optarg, &opts->audio_source)) {
|
if (!parse_audio_source(optarg, &opts->audio_source)) {
|
||||||
return false;
|
return false;
|
||||||
@ -1977,6 +2164,33 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case OPT_PAUSE_ON_EXIT:
|
||||||
|
if (!parse_pause_on_exit(optarg, &args->pause_on_exit)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OPT_CAMERA_AR:
|
||||||
|
opts->camera_ar = optarg;
|
||||||
|
break;
|
||||||
|
case OPT_CAMERA_ID:
|
||||||
|
opts->camera_id = optarg;
|
||||||
|
break;
|
||||||
|
case OPT_CAMERA_SIZE:
|
||||||
|
opts->camera_size = optarg;
|
||||||
|
break;
|
||||||
|
case OPT_CAMERA_FACING:
|
||||||
|
if (!parse_camera_facing(optarg, &opts->camera_facing)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OPT_CAMERA_FPS:
|
||||||
|
if (!parse_camera_fps(optarg, &opts->camera_fps)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OPT_CAMERA_HIGH_SPEED:
|
||||||
|
opts->camera_high_speed = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// getopt prints the error message on stderr
|
// getopt prints the error message on stderr
|
||||||
return false;
|
return false;
|
||||||
@ -2022,12 +2236,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
opts->audio_playback = false;
|
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
|
if (opts->video && !opts->video_playback && !opts->record_filename
|
||||||
&& !v4l2) {
|
&& !v4l2) {
|
||||||
LOGI("No video playback, no recording, no V4L2 sink: video disabled");
|
LOGI("No video playback, no recording, no V4L2 sink: video disabled");
|
||||||
@ -2076,6 +2284,58 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
opts->force_adb_forward = true;
|
opts->force_adb_forward = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts->video_source == SC_VIDEO_SOURCE_CAMERA) {
|
||||||
|
if (opts->display_id) {
|
||||||
|
LOGE("--display-id is only available with --video-source=display");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts->camera_id && opts->camera_facing != SC_CAMERA_FACING_ANY) {
|
||||||
|
LOGE("Could not specify both --camera-id and --camera-facing");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts->camera_size) {
|
||||||
|
if (opts->max_size) {
|
||||||
|
LOGE("Could not specify both --camera-size and -m/--max-size");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts->camera_ar) {
|
||||||
|
LOGE("Could not specify both --camera-size and --camera-ar");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts->camera_high_speed && !opts->camera_fps) {
|
||||||
|
LOGE("--camera-high-speed requires an explicit --camera-fps value");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts->control) {
|
||||||
|
LOGI("Camera video source: control disabled");
|
||||||
|
opts->control = false;
|
||||||
|
}
|
||||||
|
} else if (opts->camera_id
|
||||||
|
|| opts->camera_ar
|
||||||
|
|| opts->camera_facing != SC_CAMERA_FACING_ANY
|
||||||
|
|| opts->camera_fps
|
||||||
|
|| opts->camera_high_speed
|
||||||
|
|| opts->camera_size) {
|
||||||
|
LOGE("Camera options are only available with --video-source=camera");
|
||||||
|
return 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) {
|
if (opts->record_format && !opts->record_filename) {
|
||||||
LOGE("Record format specified without recording");
|
LOGE("Record format specified without recording");
|
||||||
return false;
|
return false;
|
||||||
@ -2196,6 +2456,37 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static enum sc_pause_on_exit
|
||||||
|
sc_get_pause_on_exit(int argc, char *argv[]) {
|
||||||
|
// Read arguments backwards so that the last --pause-on-exit is considered
|
||||||
|
// (same behavior as getopt())
|
||||||
|
for (int i = argc - 1; i >= 1; --i) {
|
||||||
|
const char *arg = argv[i];
|
||||||
|
// Starts with "--pause-on-exit"
|
||||||
|
if (!strncmp("--pause-on-exit", arg, 15)) {
|
||||||
|
if (arg[15] == '\0') {
|
||||||
|
// No argument
|
||||||
|
return SC_PAUSE_ON_EXIT_TRUE;
|
||||||
|
}
|
||||||
|
if (arg[15] != '=') {
|
||||||
|
// Invalid parameter, ignore
|
||||||
|
return SC_PAUSE_ON_EXIT_FALSE;
|
||||||
|
}
|
||||||
|
const char *value = &arg[16];
|
||||||
|
if (!strcmp(value, "true")) {
|
||||||
|
return SC_PAUSE_ON_EXIT_TRUE;
|
||||||
|
}
|
||||||
|
if (!strcmp(value, "if-error")) {
|
||||||
|
return SC_PAUSE_ON_EXIT_IF_ERROR;
|
||||||
|
}
|
||||||
|
// Set to false, inclusing when the value is invalid
|
||||||
|
return SC_PAUSE_ON_EXIT_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SC_PAUSE_ON_EXIT_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
||||||
struct sc_getopt_adapter adapter;
|
struct sc_getopt_adapter adapter;
|
||||||
@ -2209,5 +2500,11 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
|
|
||||||
sc_getopt_adapter_destroy(&adapter);
|
sc_getopt_adapter_destroy(&adapter);
|
||||||
|
|
||||||
|
if (!ret && args->pause_on_exit == SC_PAUSE_ON_EXIT_FALSE) {
|
||||||
|
// Check if "--pause-on-exit" is present in the arguments list, because
|
||||||
|
// it must be taken into account even if command line parsing failed
|
||||||
|
args->pause_on_exit = sc_get_pause_on_exit(argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,17 @@
|
|||||||
|
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
|
enum sc_pause_on_exit {
|
||||||
|
SC_PAUSE_ON_EXIT_TRUE,
|
||||||
|
SC_PAUSE_ON_EXIT_FALSE,
|
||||||
|
SC_PAUSE_ON_EXIT_IF_ERROR,
|
||||||
|
};
|
||||||
|
|
||||||
struct scrcpy_cli_args {
|
struct scrcpy_cli_args {
|
||||||
struct scrcpy_options opts;
|
struct scrcpy_options opts;
|
||||||
bool help;
|
bool help;
|
||||||
bool version;
|
bool version;
|
||||||
|
enum sc_pause_on_exit pause_on_exit;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -53,7 +53,7 @@ sc_display_init(struct sc_display *display, SDL_Window *window, bool mipmaps) {
|
|||||||
display->mipmaps = true;
|
display->mipmaps = true;
|
||||||
} else {
|
} else {
|
||||||
LOGW("Trilinear filtering disabled "
|
LOGW("Trilinear filtering disabled "
|
||||||
"(OpenGL 3.0+ or ES 2.0+ required");
|
"(OpenGL 3.0+ or ES 2.0+ required)");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOGI("Trilinear filtering disabled");
|
LOGI("Trilinear filtering disabled");
|
||||||
|
@ -271,7 +271,7 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface *
|
SDL_Surface *
|
||||||
scrcpy_icon_load() {
|
scrcpy_icon_load(void) {
|
||||||
char *icon_path = get_icon_path();
|
char *icon_path = get_icon_path();
|
||||||
if (!icon_path) {
|
if (!icon_path) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "util/str.h"
|
#include "util/str.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
static int
|
||||||
main_scrcpy(int argc, char *argv[]) {
|
main_scrcpy(int argc, char *argv[]) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// disable buffering, we want logs immediately
|
// disable buffering, we want logs immediately
|
||||||
@ -39,26 +39,32 @@ main_scrcpy(int argc, char *argv[]) {
|
|||||||
.opts = scrcpy_options_default,
|
.opts = scrcpy_options_default,
|
||||||
.help = false,
|
.help = false,
|
||||||
.version = false,
|
.version = false,
|
||||||
|
.pause_on_exit = SC_PAUSE_ON_EXIT_FALSE,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
args.opts.log_level = SC_LOG_LEVEL_DEBUG;
|
args.opts.log_level = SC_LOG_LEVEL_DEBUG;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum scrcpy_exit_code ret;
|
||||||
|
|
||||||
if (!scrcpy_parse_args(&args, argc, argv)) {
|
if (!scrcpy_parse_args(&args, argc, argv)) {
|
||||||
return SCRCPY_EXIT_FAILURE;
|
ret = SCRCPY_EXIT_FAILURE;
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_set_log_level(args.opts.log_level);
|
sc_set_log_level(args.opts.log_level);
|
||||||
|
|
||||||
if (args.help) {
|
if (args.help) {
|
||||||
scrcpy_print_usage(argv[0]);
|
scrcpy_print_usage(argv[0]);
|
||||||
return SCRCPY_EXIT_SUCCESS;
|
ret = SCRCPY_EXIT_SUCCESS;
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.version) {
|
if (args.version) {
|
||||||
scrcpy_print_version();
|
scrcpy_print_version();
|
||||||
return SCRCPY_EXIT_SUCCESS;
|
ret = SCRCPY_EXIT_SUCCESS;
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
|
#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
|
||||||
@ -72,18 +78,26 @@ main_scrcpy(int argc, char *argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!net_init()) {
|
if (!net_init()) {
|
||||||
return SCRCPY_EXIT_FAILURE;
|
ret = SCRCPY_EXIT_FAILURE;
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_log_configure();
|
sc_log_configure();
|
||||||
|
|
||||||
#ifdef HAVE_USB
|
#ifdef HAVE_USB
|
||||||
enum scrcpy_exit_code ret = args.opts.otg ? scrcpy_otg(&args.opts)
|
ret = args.opts.otg ? scrcpy_otg(&args.opts) : scrcpy(&args.opts);
|
||||||
: scrcpy(&args.opts);
|
|
||||||
#else
|
#else
|
||||||
enum scrcpy_exit_code ret = scrcpy(&args.opts);
|
ret = scrcpy(&args.opts);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
end:
|
||||||
|
if (args.pause_on_exit == SC_PAUSE_ON_EXIT_TRUE ||
|
||||||
|
(args.pause_on_exit == SC_PAUSE_ON_EXIT_IF_ERROR &&
|
||||||
|
ret != SCRCPY_EXIT_SUCCESS)) {
|
||||||
|
printf("Press Enter to continue...\n");
|
||||||
|
getchar();
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,13 +11,19 @@ const struct scrcpy_options scrcpy_options_default = {
|
|||||||
.audio_codec_options = NULL,
|
.audio_codec_options = NULL,
|
||||||
.video_encoder = NULL,
|
.video_encoder = NULL,
|
||||||
.audio_encoder = NULL,
|
.audio_encoder = NULL,
|
||||||
|
.camera_id = NULL,
|
||||||
|
.camera_size = NULL,
|
||||||
|
.camera_ar = NULL,
|
||||||
|
.camera_fps = 0,
|
||||||
.log_level = SC_LOG_LEVEL_INFO,
|
.log_level = SC_LOG_LEVEL_INFO,
|
||||||
.video_codec = SC_CODEC_H264,
|
.video_codec = SC_CODEC_H264,
|
||||||
.audio_codec = SC_CODEC_OPUS,
|
.audio_codec = SC_CODEC_OPUS,
|
||||||
.audio_source = SC_AUDIO_SOURCE_OUTPUT,
|
.video_source = SC_VIDEO_SOURCE_DISPLAY,
|
||||||
|
.audio_source = SC_AUDIO_SOURCE_AUTO,
|
||||||
.record_format = SC_RECORD_FORMAT_AUTO,
|
.record_format = SC_RECORD_FORMAT_AUTO,
|
||||||
.keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_INJECT,
|
.keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_INJECT,
|
||||||
.mouse_input_mode = SC_MOUSE_INPUT_MODE_INJECT,
|
.mouse_input_mode = SC_MOUSE_INPUT_MODE_INJECT,
|
||||||
|
.camera_facing = SC_CAMERA_FACING_ANY,
|
||||||
.port_range = {
|
.port_range = {
|
||||||
.first = DEFAULT_LOCAL_PORT_RANGE_FIRST,
|
.first = DEFAULT_LOCAL_PORT_RANGE_FIRST,
|
||||||
.last = DEFAULT_LOCAL_PORT_RANGE_LAST,
|
.last = DEFAULT_LOCAL_PORT_RANGE_LAST,
|
||||||
@ -79,7 +85,7 @@ const struct scrcpy_options scrcpy_options_default = {
|
|||||||
.video = true,
|
.video = true,
|
||||||
.audio = true,
|
.audio = true,
|
||||||
.require_audio = false,
|
.require_audio = false,
|
||||||
.list_encoders = false,
|
|
||||||
.list_displays = false,
|
|
||||||
.kill_adb_on_close = false,
|
.kill_adb_on_close = false,
|
||||||
|
.camera_high_speed = false,
|
||||||
|
.list = 0,
|
||||||
};
|
};
|
||||||
|
@ -44,11 +44,24 @@ enum sc_codec {
|
|||||||
SC_CODEC_RAW,
|
SC_CODEC_RAW,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum sc_video_source {
|
||||||
|
SC_VIDEO_SOURCE_DISPLAY,
|
||||||
|
SC_VIDEO_SOURCE_CAMERA,
|
||||||
|
};
|
||||||
|
|
||||||
enum sc_audio_source {
|
enum sc_audio_source {
|
||||||
|
SC_AUDIO_SOURCE_AUTO, // OUTPUT for video DISPLAY, MIC for video CAMERA
|
||||||
SC_AUDIO_SOURCE_OUTPUT,
|
SC_AUDIO_SOURCE_OUTPUT,
|
||||||
SC_AUDIO_SOURCE_MIC,
|
SC_AUDIO_SOURCE_MIC,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum sc_camera_facing {
|
||||||
|
SC_CAMERA_FACING_ANY,
|
||||||
|
SC_CAMERA_FACING_FRONT,
|
||||||
|
SC_CAMERA_FACING_BACK,
|
||||||
|
SC_CAMERA_FACING_EXTERNAL,
|
||||||
|
};
|
||||||
|
|
||||||
enum sc_lock_video_orientation {
|
enum sc_lock_video_orientation {
|
||||||
SC_LOCK_VIDEO_ORIENTATION_UNLOCKED = -1,
|
SC_LOCK_VIDEO_ORIENTATION_UNLOCKED = -1,
|
||||||
// lock the current orientation when scrcpy starts
|
// lock the current orientation when scrcpy starts
|
||||||
@ -117,13 +130,19 @@ struct scrcpy_options {
|
|||||||
const char *audio_codec_options;
|
const char *audio_codec_options;
|
||||||
const char *video_encoder;
|
const char *video_encoder;
|
||||||
const char *audio_encoder;
|
const char *audio_encoder;
|
||||||
|
const char *camera_id;
|
||||||
|
const char *camera_size;
|
||||||
|
const char *camera_ar;
|
||||||
|
uint16_t camera_fps;
|
||||||
enum sc_log_level log_level;
|
enum sc_log_level log_level;
|
||||||
enum sc_codec video_codec;
|
enum sc_codec video_codec;
|
||||||
enum sc_codec audio_codec;
|
enum sc_codec audio_codec;
|
||||||
|
enum sc_video_source video_source;
|
||||||
enum sc_audio_source audio_source;
|
enum sc_audio_source audio_source;
|
||||||
enum sc_record_format record_format;
|
enum sc_record_format record_format;
|
||||||
enum sc_keyboard_input_mode keyboard_input_mode;
|
enum sc_keyboard_input_mode keyboard_input_mode;
|
||||||
enum sc_mouse_input_mode mouse_input_mode;
|
enum sc_mouse_input_mode mouse_input_mode;
|
||||||
|
enum sc_camera_facing camera_facing;
|
||||||
struct sc_port_range port_range;
|
struct sc_port_range port_range;
|
||||||
uint32_t tunnel_host;
|
uint32_t tunnel_host;
|
||||||
uint16_t tunnel_port;
|
uint16_t tunnel_port;
|
||||||
@ -179,9 +198,13 @@ struct scrcpy_options {
|
|||||||
bool video;
|
bool video;
|
||||||
bool audio;
|
bool audio;
|
||||||
bool require_audio;
|
bool require_audio;
|
||||||
bool list_encoders;
|
|
||||||
bool list_displays;
|
|
||||||
bool kill_adb_on_close;
|
bool kill_adb_on_close;
|
||||||
|
bool camera_high_speed;
|
||||||
|
#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;
|
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)
|
#define PUSH_EVENT(TYPE) push_event(TYPE, # TYPE)
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) {
|
static BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) {
|
||||||
if (ctrl_type == CTRL_C_EVENT) {
|
if (ctrl_type == CTRL_C_EVENT) {
|
||||||
PUSH_EVENT(SDL_QUIT);
|
PUSH_EVENT(SDL_QUIT);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -252,7 +252,9 @@ sc_audio_demuxer_on_ended(struct sc_demuxer *demuxer,
|
|||||||
|
|
||||||
// Contrary to the video demuxer, keep mirroring if only the audio fails
|
// Contrary to the video demuxer, keep mirroring if only the audio fails
|
||||||
// (unless --require-audio is set).
|
// (unless --require-audio is set).
|
||||||
if (status == SC_DEMUXER_STATUS_ERROR
|
if (status == SC_DEMUXER_STATUS_EOS) {
|
||||||
|
PUSH_EVENT(SC_EVENT_DEVICE_DISCONNECTED);
|
||||||
|
} else if (status == SC_DEMUXER_STATUS_ERROR
|
||||||
|| (status == SC_DEMUXER_STATUS_DISABLED
|
|| (status == SC_DEMUXER_STATUS_DISABLED
|
||||||
&& options->require_audio)) {
|
&& options->require_audio)) {
|
||||||
PUSH_EVENT(SC_EVENT_DEMUXER_ERROR);
|
PUSH_EVENT(SC_EVENT_DEMUXER_ERROR);
|
||||||
@ -295,7 +297,7 @@ sc_timeout_on_timeout(struct sc_timeout *timeout, void *userdata) {
|
|||||||
|
|
||||||
// Generate a scrcpy id to differentiate multiple running scrcpy instances
|
// Generate a scrcpy id to differentiate multiple running scrcpy instances
|
||||||
static uint32_t
|
static uint32_t
|
||||||
scrcpy_generate_scid() {
|
scrcpy_generate_scid(void) {
|
||||||
struct sc_rand rand;
|
struct sc_rand rand;
|
||||||
sc_rand_init(&rand);
|
sc_rand_init(&rand);
|
||||||
// Only use 31 bits to avoid issues with signed values on the Java-side
|
// Only use 31 bits to avoid issues with signed values on the Java-side
|
||||||
@ -349,7 +351,9 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
.log_level = options->log_level,
|
.log_level = options->log_level,
|
||||||
.video_codec = options->video_codec,
|
.video_codec = options->video_codec,
|
||||||
.audio_codec = options->audio_codec,
|
.audio_codec = options->audio_codec,
|
||||||
|
.video_source = options->video_source,
|
||||||
.audio_source = options->audio_source,
|
.audio_source = options->audio_source,
|
||||||
|
.camera_facing = options->camera_facing,
|
||||||
.crop = options->crop,
|
.crop = options->crop,
|
||||||
.port_range = options->port_range,
|
.port_range = options->port_range,
|
||||||
.tunnel_host = options->tunnel_host,
|
.tunnel_host = options->tunnel_host,
|
||||||
@ -369,6 +373,10 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
.audio_codec_options = options->audio_codec_options,
|
.audio_codec_options = options->audio_codec_options,
|
||||||
.video_encoder = options->video_encoder,
|
.video_encoder = options->video_encoder,
|
||||||
.audio_encoder = options->audio_encoder,
|
.audio_encoder = options->audio_encoder,
|
||||||
|
.camera_id = options->camera_id,
|
||||||
|
.camera_size = options->camera_size,
|
||||||
|
.camera_ar = options->camera_ar,
|
||||||
|
.camera_fps = options->camera_fps,
|
||||||
.force_adb_forward = options->force_adb_forward,
|
.force_adb_forward = options->force_adb_forward,
|
||||||
.power_off_on_close = options->power_off_on_close,
|
.power_off_on_close = options->power_off_on_close,
|
||||||
.clipboard_autosync = options->clipboard_autosync,
|
.clipboard_autosync = options->clipboard_autosync,
|
||||||
@ -377,9 +385,9 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
.tcpip_dst = options->tcpip_dst,
|
.tcpip_dst = options->tcpip_dst,
|
||||||
.cleanup = options->cleanup,
|
.cleanup = options->cleanup,
|
||||||
.power_on = options->power_on,
|
.power_on = options->power_on,
|
||||||
.list_encoders = options->list_encoders,
|
|
||||||
.list_displays = options->list_displays,
|
|
||||||
.kill_adb_on_close = options->kill_adb_on_close,
|
.kill_adb_on_close = options->kill_adb_on_close,
|
||||||
|
.camera_high_speed = options->camera_high_speed,
|
||||||
|
.list = options->list,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct sc_server_callbacks cbs = {
|
static const struct sc_server_callbacks cbs = {
|
||||||
@ -397,7 +405,7 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
|
|
||||||
server_started = true;
|
server_started = true;
|
||||||
|
|
||||||
if (options->list_encoders || options->list_displays) {
|
if (options->list) {
|
||||||
bool ok = await_for_server(NULL);
|
bool ok = await_for_server(NULL);
|
||||||
ret = ok ? SCRCPY_EXIT_SUCCESS : SCRCPY_EXIT_FAILURE;
|
ret = ok ? SCRCPY_EXIT_SUCCESS : SCRCPY_EXIT_FAILURE;
|
||||||
goto end;
|
goto end;
|
||||||
@ -448,9 +456,7 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
|
|
||||||
struct sc_file_pusher *fp = NULL;
|
struct sc_file_pusher *fp = NULL;
|
||||||
|
|
||||||
// control implies video playback
|
if (options->video_playback && options->control) {
|
||||||
assert(!options->control || options->video_playback);
|
|
||||||
if (options->control) {
|
|
||||||
if (!sc_file_pusher_init(&s->file_pusher, serial,
|
if (!sc_file_pusher_init(&s->file_pusher, serial,
|
||||||
options->push_target)) {
|
options->push_target)) {
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -488,6 +488,7 @@ sc_screen_show_initial_window(struct sc_screen *screen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_ShowWindow(screen->window);
|
SDL_ShowWindow(screen->window);
|
||||||
|
sc_screen_update_content_rect(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -848,6 +849,8 @@ sc_screen_convert_drawable_to_frame_coords(struct sc_screen *screen,
|
|||||||
int32_t w = screen->content_size.width;
|
int32_t w = screen->content_size.width;
|
||||||
int32_t h = screen->content_size.height;
|
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;
|
x = (int64_t) (x - screen->rect.x) * w / screen->rect.w;
|
||||||
y = (int64_t) (y - screen->rect.y) * h / screen->rect.h;
|
y = (int64_t) (y - screen->rect.y) * h / screen->rect.h;
|
||||||
|
@ -76,6 +76,8 @@ sc_server_params_destroy(struct sc_server_params *params) {
|
|||||||
free((char *) params->video_encoder);
|
free((char *) params->video_encoder);
|
||||||
free((char *) params->audio_encoder);
|
free((char *) params->audio_encoder);
|
||||||
free((char *) params->tcpip_dst);
|
free((char *) params->tcpip_dst);
|
||||||
|
free((char *) params->camera_id);
|
||||||
|
free((char *) params->camera_ar);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@ -86,14 +88,15 @@ sc_server_params_copy(struct sc_server_params *dst,
|
|||||||
// The params reference user-allocated memory, so we must copy them to
|
// The params reference user-allocated memory, so we must copy them to
|
||||||
// handle them from another thread
|
// handle them from another thread
|
||||||
|
|
||||||
#define COPY(FIELD) \
|
#define COPY(FIELD) do { \
|
||||||
dst->FIELD = NULL; \
|
dst->FIELD = NULL; \
|
||||||
if (src->FIELD) { \
|
if (src->FIELD) { \
|
||||||
dst->FIELD = strdup(src->FIELD); \
|
dst->FIELD = strdup(src->FIELD); \
|
||||||
if (!dst->FIELD) { \
|
if (!dst->FIELD) { \
|
||||||
goto error; \
|
goto error; \
|
||||||
} \
|
} \
|
||||||
}
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
COPY(req_serial);
|
COPY(req_serial);
|
||||||
COPY(crop);
|
COPY(crop);
|
||||||
@ -102,6 +105,8 @@ sc_server_params_copy(struct sc_server_params *dst,
|
|||||||
COPY(video_encoder);
|
COPY(video_encoder);
|
||||||
COPY(audio_encoder);
|
COPY(audio_encoder);
|
||||||
COPY(tcpip_dst);
|
COPY(tcpip_dst);
|
||||||
|
COPY(camera_id);
|
||||||
|
COPY(camera_ar);
|
||||||
#undef COPY
|
#undef COPY
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -180,6 +185,20 @@ sc_server_get_codec_name(enum sc_codec codec) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
sc_server_get_camera_facing_name(enum sc_camera_facing camera_facing) {
|
||||||
|
switch (camera_facing) {
|
||||||
|
case SC_CAMERA_FACING_FRONT:
|
||||||
|
return "front";
|
||||||
|
case SC_CAMERA_FACING_BACK:
|
||||||
|
return "back";
|
||||||
|
case SC_CAMERA_FACING_EXTERNAL:
|
||||||
|
return "external";
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static sc_pid
|
static sc_pid
|
||||||
execute_server(struct sc_server *server,
|
execute_server(struct sc_server *server,
|
||||||
const struct sc_server_params *params) {
|
const struct sc_server_params *params) {
|
||||||
@ -215,13 +234,13 @@ execute_server(struct sc_server *server,
|
|||||||
cmd[count++] = SCRCPY_VERSION;
|
cmd[count++] = SCRCPY_VERSION;
|
||||||
|
|
||||||
unsigned dyn_idx = count; // from there, the strings are allocated
|
unsigned dyn_idx = count; // from there, the strings are allocated
|
||||||
#define ADD_PARAM(fmt, ...) { \
|
#define ADD_PARAM(fmt, ...) do { \
|
||||||
char *p; \
|
char *p; \
|
||||||
if (asprintf(&p, fmt, ## __VA_ARGS__) == -1) { \
|
if (asprintf(&p, fmt, ## __VA_ARGS__) == -1) { \
|
||||||
goto end; \
|
goto end; \
|
||||||
} \
|
} \
|
||||||
cmd[count++] = p; \
|
cmd[count++] = p; \
|
||||||
}
|
} while(0)
|
||||||
|
|
||||||
ADD_PARAM("scid=%08x", params->scid);
|
ADD_PARAM("scid=%08x", params->scid);
|
||||||
ADD_PARAM("log_level=%s", log_level_to_server_string(params->log_level));
|
ADD_PARAM("log_level=%s", log_level_to_server_string(params->log_level));
|
||||||
@ -246,8 +265,11 @@ execute_server(struct sc_server *server,
|
|||||||
ADD_PARAM("audio_codec=%s",
|
ADD_PARAM("audio_codec=%s",
|
||||||
sc_server_get_codec_name(params->audio_codec));
|
sc_server_get_codec_name(params->audio_codec));
|
||||||
}
|
}
|
||||||
if (params->audio_source != SC_AUDIO_SOURCE_OUTPUT) {
|
if (params->video_source != SC_VIDEO_SOURCE_DISPLAY) {
|
||||||
assert(params->audio_source == SC_AUDIO_SOURCE_MIC);
|
assert(params->video_source == SC_VIDEO_SOURCE_CAMERA);
|
||||||
|
ADD_PARAM("video_source=camera");
|
||||||
|
}
|
||||||
|
if (params->audio_source == SC_AUDIO_SOURCE_MIC) {
|
||||||
ADD_PARAM("audio_source=mic");
|
ADD_PARAM("audio_source=mic");
|
||||||
}
|
}
|
||||||
if (params->max_size) {
|
if (params->max_size) {
|
||||||
@ -273,6 +295,25 @@ execute_server(struct sc_server *server,
|
|||||||
if (params->display_id) {
|
if (params->display_id) {
|
||||||
ADD_PARAM("display_id=%" PRIu32, 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->camera_facing != SC_CAMERA_FACING_ANY) {
|
||||||
|
ADD_PARAM("camera_facing=%s",
|
||||||
|
sc_server_get_camera_facing_name(params->camera_facing));
|
||||||
|
}
|
||||||
|
if (params->camera_ar) {
|
||||||
|
ADD_PARAM("camera_ar=%s", params->camera_ar);
|
||||||
|
}
|
||||||
|
if (params->camera_fps) {
|
||||||
|
ADD_PARAM("camera_fps=%" PRIu16, params->camera_fps);
|
||||||
|
}
|
||||||
|
if (params->camera_high_speed) {
|
||||||
|
ADD_PARAM("camera_high_speed=true");
|
||||||
|
}
|
||||||
if (params->show_touches) {
|
if (params->show_touches) {
|
||||||
ADD_PARAM("show_touches=true");
|
ADD_PARAM("show_touches=true");
|
||||||
}
|
}
|
||||||
@ -310,12 +351,18 @@ execute_server(struct sc_server *server,
|
|||||||
// By default, power_on is true
|
// By default, power_on is true
|
||||||
ADD_PARAM("power_on=false");
|
ADD_PARAM("power_on=false");
|
||||||
}
|
}
|
||||||
if (params->list_encoders) {
|
if (params->list & SC_OPTION_LIST_ENCODERS) {
|
||||||
ADD_PARAM("list_encoders=true");
|
ADD_PARAM("list_encoders=true");
|
||||||
}
|
}
|
||||||
if (params->list_displays) {
|
if (params->list & SC_OPTION_LIST_DISPLAYS) {
|
||||||
ADD_PARAM("list_displays=true");
|
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
|
#undef ADD_PARAM
|
||||||
|
|
||||||
@ -533,8 +580,8 @@ sc_server_connect_to(struct sc_server *server, struct sc_server_info *info) {
|
|||||||
if (audio_socket == SC_SOCKET_NONE) {
|
if (audio_socket == SC_SOCKET_NONE) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
bool ok = net_connect_intr(&server->intr, audio_socket, tunnel_host,
|
bool ok = net_connect_intr(&server->intr, audio_socket,
|
||||||
tunnel_port);
|
tunnel_host, tunnel_port);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@ -895,7 +942,7 @@ run_server(void *data) {
|
|||||||
|
|
||||||
// If --list-* is passed, then the server just prints the requested data
|
// If --list-* is passed, then the server just prints the requested data
|
||||||
// then exits.
|
// then exits.
|
||||||
if (params->list_encoders || params->list_displays) {
|
if (params->list) {
|
||||||
sc_pid pid = execute_server(server, params);
|
sc_pid pid = execute_server(server, params);
|
||||||
if (pid == SC_PROCESS_NONE) {
|
if (pid == SC_PROCESS_NONE) {
|
||||||
goto error_connection_failed;
|
goto error_connection_failed;
|
||||||
|
@ -26,12 +26,18 @@ struct sc_server_params {
|
|||||||
enum sc_log_level log_level;
|
enum sc_log_level log_level;
|
||||||
enum sc_codec video_codec;
|
enum sc_codec video_codec;
|
||||||
enum sc_codec audio_codec;
|
enum sc_codec audio_codec;
|
||||||
|
enum sc_video_source video_source;
|
||||||
enum sc_audio_source audio_source;
|
enum sc_audio_source audio_source;
|
||||||
|
enum sc_camera_facing camera_facing;
|
||||||
const char *crop;
|
const char *crop;
|
||||||
const char *video_codec_options;
|
const char *video_codec_options;
|
||||||
const char *audio_codec_options;
|
const char *audio_codec_options;
|
||||||
const char *video_encoder;
|
const char *video_encoder;
|
||||||
const char *audio_encoder;
|
const char *audio_encoder;
|
||||||
|
const char *camera_id;
|
||||||
|
const char *camera_size;
|
||||||
|
const char *camera_ar;
|
||||||
|
uint16_t camera_fps;
|
||||||
struct sc_port_range port_range;
|
struct sc_port_range port_range;
|
||||||
uint32_t tunnel_host;
|
uint32_t tunnel_host;
|
||||||
uint16_t tunnel_port;
|
uint16_t tunnel_port;
|
||||||
@ -56,9 +62,9 @@ struct sc_server_params {
|
|||||||
bool select_tcpip;
|
bool select_tcpip;
|
||||||
bool cleanup;
|
bool cleanup;
|
||||||
bool power_on;
|
bool power_on;
|
||||||
bool list_encoders;
|
|
||||||
bool list_displays;
|
|
||||||
bool kill_adb_on_close;
|
bool kill_adb_on_close;
|
||||||
|
bool camera_high_speed;
|
||||||
|
uint8_t list;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sc_server {
|
struct sc_server {
|
||||||
|
@ -27,7 +27,8 @@
|
|||||||
// keyboard support, though OS could support more keys via modifying the report
|
// keyboard support, though OS could support more keys via modifying the report
|
||||||
// desc. 6 should be enough for scrcpy.
|
// desc. 6 should be enough for scrcpy.
|
||||||
#define HID_KEYBOARD_MAX_KEYS 6
|
#define HID_KEYBOARD_MAX_KEYS 6
|
||||||
#define HID_KEYBOARD_EVENT_SIZE (2 + HID_KEYBOARD_MAX_KEYS)
|
#define HID_KEYBOARD_EVENT_SIZE \
|
||||||
|
(HID_KEYBOARD_INDEX_KEYS + HID_KEYBOARD_MAX_KEYS)
|
||||||
|
|
||||||
#define HID_RESERVED 0x00
|
#define HID_RESERVED 0x00
|
||||||
#define HID_ERROR_ROLL_OVER 0x01
|
#define HID_ERROR_ROLL_OVER 0x01
|
||||||
|
@ -105,10 +105,6 @@ scrcpy_otg(struct scrcpy_options *options) {
|
|||||||
|
|
||||||
usb_device_initialized = true;
|
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);
|
ok = sc_usb_connect(&s->usb, usb_device.device, &cbs, NULL);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -93,7 +93,7 @@ sc_usb_device_move(struct sc_usb_device *dst, struct sc_usb_device *src) {
|
|||||||
src->product = NULL;
|
src->product = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
sc_usb_devices_destroy(struct sc_vec_usb_devices *usb_devices) {
|
sc_usb_devices_destroy(struct sc_vec_usb_devices *usb_devices) {
|
||||||
for (size_t i = 0; i < usb_devices->size; ++i) {
|
for (size_t i = 0; i < usb_devices->size; ++i) {
|
||||||
sc_usb_device_destroy(&usb_devices->data[i]);
|
sc_usb_device_destroy(&usb_devices->data[i]);
|
||||||
@ -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
|
assert(sel_count == 1); // sel_idx is valid only if sel_count == 1
|
||||||
struct sc_usb_device *device = &vec.data[sel_idx];
|
struct sc_usb_device *device = &vec.data[sel_idx];
|
||||||
|
|
||||||
LOGD("USB device found:");
|
LOGI("USB device found:");
|
||||||
sc_usb_devices_log(SC_LOG_LEVEL_DEBUG, vec.data, vec.size);
|
sc_usb_devices_log(SC_LOG_LEVEL_INFO, vec.data, vec.size);
|
||||||
|
|
||||||
// Move device into out_device (do not destroy device)
|
// Move device into out_device (do not destroy device)
|
||||||
sc_usb_device_move(out_device, device);
|
sc_usb_device_move(out_device, device);
|
||||||
|
@ -147,7 +147,7 @@ sc_sdl_log_print(void *userdata, int category, SDL_LogPriority priority,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_log_configure() {
|
sc_log_configure(void) {
|
||||||
SDL_LogSetOutputFunction(sc_sdl_log_print, NULL);
|
SDL_LogSetOutputFunction(sc_sdl_log_print, NULL);
|
||||||
// Redirect FFmpeg logs to SDL logs
|
// Redirect FFmpeg logs to SDL logs
|
||||||
av_log_set_callback(sc_av_log_callback);
|
av_log_set_callback(sc_av_log_callback);
|
||||||
|
@ -36,6 +36,6 @@ sc_log_windows_error(const char *prefix, int error);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_log_configure();
|
sc_log_configure(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -190,10 +190,10 @@ sc_vecdeque_reallocdata_(void *ptr, size_t newcap, size_t item_size,
|
|||||||
|
|
||||||
size_t right_len = MIN(size, oldcap - oldorigin);
|
size_t right_len = MIN(size, oldcap - oldorigin);
|
||||||
assert(right_len);
|
assert(right_len);
|
||||||
memcpy(newptr, ptr + (oldorigin * item_size), right_len * item_size);
|
memcpy(newptr, (char *) ptr + (oldorigin * item_size), right_len * item_size);
|
||||||
|
|
||||||
if (size > right_len) {
|
if (size > right_len) {
|
||||||
memcpy(newptr + (right_len * item_size), ptr,
|
memcpy((char *) newptr + (right_len * item_size), ptr,
|
||||||
(size - right_len) * item_size);
|
(size - right_len) * item_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "util/bytebuf.h"
|
#include "util/bytebuf.h"
|
||||||
|
|
||||||
void test_bytebuf_simple(void) {
|
static void test_bytebuf_simple(void) {
|
||||||
struct sc_bytebuf buf;
|
struct sc_bytebuf buf;
|
||||||
uint8_t data[20];
|
uint8_t data[20];
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ void test_bytebuf_simple(void) {
|
|||||||
sc_bytebuf_destroy(&buf);
|
sc_bytebuf_destroy(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_bytebuf_boundaries(void) {
|
static void test_bytebuf_boundaries(void) {
|
||||||
struct sc_bytebuf buf;
|
struct sc_bytebuf buf;
|
||||||
uint8_t data[20];
|
uint8_t data[20];
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ void test_bytebuf_boundaries(void) {
|
|||||||
sc_bytebuf_destroy(&buf);
|
sc_bytebuf_destroy(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_bytebuf_two_steps_write(void) {
|
static void test_bytebuf_two_steps_write(void) {
|
||||||
struct sc_bytebuf buf;
|
struct sc_bytebuf buf;
|
||||||
uint8_t data[20];
|
uint8_t data[20];
|
||||||
|
|
||||||
|
@ -269,21 +269,25 @@ static void test_parse_integer_with_suffix(void) {
|
|||||||
|
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
|
||||||
sprintf(buf, "%ldk", LONG_MAX / 2000);
|
int r = snprintf(buf, sizeof(buf), "%ldk", LONG_MAX / 2000);
|
||||||
|
assert(r >= 0 && (size_t) r < sizeof(buf));
|
||||||
ok = sc_str_parse_integer_with_suffix(buf, &value);
|
ok = sc_str_parse_integer_with_suffix(buf, &value);
|
||||||
assert(ok);
|
assert(ok);
|
||||||
assert(value == LONG_MAX / 2000 * 1000);
|
assert(value == LONG_MAX / 2000 * 1000);
|
||||||
|
|
||||||
sprintf(buf, "%ldm", LONG_MAX / 2000);
|
r = snprintf(buf, sizeof(buf), "%ldm", LONG_MAX / 2000);
|
||||||
|
assert(r >= 0 && (size_t) r < sizeof(buf));
|
||||||
ok = sc_str_parse_integer_with_suffix(buf, &value);
|
ok = sc_str_parse_integer_with_suffix(buf, &value);
|
||||||
assert(!ok);
|
assert(!ok);
|
||||||
|
|
||||||
sprintf(buf, "%ldk", LONG_MIN / 2000);
|
r = snprintf(buf, sizeof(buf), "%ldk", LONG_MIN / 2000);
|
||||||
|
assert(r >= 0 && (size_t) r < sizeof(buf));
|
||||||
ok = sc_str_parse_integer_with_suffix(buf, &value);
|
ok = sc_str_parse_integer_with_suffix(buf, &value);
|
||||||
assert(ok);
|
assert(ok);
|
||||||
assert(value == LONG_MIN / 2000 * 1000);
|
assert(value == LONG_MIN / 2000 * 1000);
|
||||||
|
|
||||||
sprintf(buf, "%ldm", LONG_MIN / 2000);
|
r = snprintf(buf, sizeof(buf), "%ldm", LONG_MIN / 2000);
|
||||||
|
assert(r >= 0 && (size_t) r < sizeof(buf));
|
||||||
ok = sc_str_parse_integer_with_suffix(buf, &value);
|
ok = sc_str_parse_integer_with_suffix(buf, &value);
|
||||||
assert(!ok);
|
assert(!ok);
|
||||||
}
|
}
|
||||||
@ -358,7 +362,7 @@ static void test_index_of_column(void) {
|
|||||||
assert(sc_str_index_of_column(" a bc d", 1, " ") == 2);
|
assert(sc_str_index_of_column(" a bc d", 1, " ") == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_remove_trailing_cr() {
|
static void test_remove_trailing_cr(void) {
|
||||||
char s[] = "abc\r";
|
char s[] = "abc\r";
|
||||||
sc_str_remove_trailing_cr(s, sizeof(s) - 1);
|
sc_str_remove_trailing_cr(s, sizeof(s) - 1);
|
||||||
assert(!strcmp(s, "abc"));
|
assert(!strcmp(s, "abc"));
|
||||||
|
@ -102,7 +102,7 @@ static void test_vecdeque_reserve(void) {
|
|||||||
sc_vecdeque_destroy(&vdq);
|
sc_vecdeque_destroy(&vdq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_vecdeque_grow() {
|
static void test_vecdeque_grow(void) {
|
||||||
struct SC_VECDEQUE(int) vdq = SC_VECDEQUE_INITIALIZER;
|
struct SC_VECDEQUE(int) vdq = SC_VECDEQUE_INITIALIZER;
|
||||||
|
|
||||||
bool ok = sc_vecdeque_reserve(&vdq, 20);
|
bool ok = sc_vecdeque_reserve(&vdq, 20);
|
||||||
@ -142,7 +142,7 @@ static void test_vecdeque_grow() {
|
|||||||
sc_vecdeque_destroy(&vdq);
|
sc_vecdeque_destroy(&vdq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_vecdeque_push_hole() {
|
static void test_vecdeque_push_hole(void) {
|
||||||
struct SC_VECDEQUE(int) vdq = SC_VECDEQUE_INITIALIZER;
|
struct SC_VECDEQUE(int) vdq = SC_VECDEQUE_INITIALIZER;
|
||||||
|
|
||||||
bool ok = sc_vecdeque_reserve(&vdq, 20);
|
bool ok = sc_vecdeque_reserve(&vdq, 20);
|
||||||
|
@ -187,7 +187,7 @@ static void test_vector_index_of(void) {
|
|||||||
sc_vector_destroy(&vec);
|
sc_vector_destroy(&vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_vector_grow() {
|
static void test_vector_grow(void) {
|
||||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
|
@ -17,5 +17,5 @@ endian = 'little'
|
|||||||
|
|
||||||
[properties]
|
[properties]
|
||||||
prebuilt_ffmpeg = 'ffmpeg-6.0-scrcpy-4/win32'
|
prebuilt_ffmpeg = 'ffmpeg-6.0-scrcpy-4/win32'
|
||||||
prebuilt_sdl2 = 'SDL2-2.26.4/i686-w64-mingw32'
|
prebuilt_sdl2 = 'SDL2-2.28.4/i686-w64-mingw32'
|
||||||
prebuilt_libusb = 'libusb-1.0.26/libusb-MinGW-Win32'
|
prebuilt_libusb = 'libusb-1.0.26/libusb-MinGW-Win32'
|
||||||
|
@ -17,5 +17,5 @@ endian = 'little'
|
|||||||
|
|
||||||
[properties]
|
[properties]
|
||||||
prebuilt_ffmpeg = 'ffmpeg-6.0-scrcpy-4/win64'
|
prebuilt_ffmpeg = 'ffmpeg-6.0-scrcpy-4/win64'
|
||||||
prebuilt_sdl2 = 'SDL2-2.26.4/x86_64-w64-mingw32'
|
prebuilt_sdl2 = 'SDL2-2.28.4/x86_64-w64-mingw32'
|
||||||
prebuilt_libusb = 'libusb-1.0.26/libusb-MinGW-x64'
|
prebuilt_libusb = 'libusb-1.0.26/libusb-MinGW-x64'
|
||||||
|
23
doc/audio.md
23
doc/audio.md
@ -71,6 +71,20 @@ scrcpy --audio-codec=aac
|
|||||||
scrcpy --audio-codec=raw
|
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:
|
Several encoders may be available on the device. They can be listed by:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -79,19 +93,14 @@ scrcpy --list-encoders
|
|||||||
|
|
||||||
To select a specific encoder:
|
To select a specific encoder:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
scrcpy --audio-codec=opus --audio-encoder='c2.android.opus.encoder'
|
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
|
## Bit rate
|
||||||
|
|
||||||
The default video bit-rate is 128Kbps. To change it:
|
The default audio bit rate is 128Kbps. To change it:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scrcpy --audio-bit-rate=64K
|
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
|
sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
|
||||||
|
|
||||||
# client build dependencies
|
# client build dependencies
|
||||||
sudo dnf install SDL2-devel ffms2-devel libusb-devel meson gcc make
|
sudo dnf install SDL2-devel ffms2-devel libusb1-devel meson gcc make
|
||||||
|
|
||||||
# server build dependencies
|
# server build dependencies
|
||||||
sudo dnf install java-devel
|
sudo dnf install java-devel
|
||||||
@ -233,10 +233,10 @@ install` must be run as root)._
|
|||||||
|
|
||||||
#### Option 2: Use prebuilt server
|
#### Option 2: Use prebuilt server
|
||||||
|
|
||||||
- [`scrcpy-server-v2.0`][direct-scrcpy-server]
|
- [`scrcpy-server-v2.1.1`][direct-scrcpy-server]
|
||||||
<sub>SHA-256: `9e241615f578cd690bb43311000debdecf6a9c50a7082b001952f18f6f21ddc2`</sub>
|
<sub>SHA-256: `9558db6c56743a1dc03b38f59801fb40e91cc891f8fc0c89e5b0b067761f148e`</sub>
|
||||||
|
|
||||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v2.0/scrcpy-server-v2.0
|
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v2.1.1/scrcpy-server-v2.1.1
|
||||||
|
|
||||||
Download the prebuilt server somewhere, and specify its path during the Meson
|
Download the prebuilt server somewhere, and specify its path during the Meson
|
||||||
configuration:
|
configuration:
|
||||||
|
150
doc/camera.md
Normal file
150
doc/camera.md
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
# Camera
|
||||||
|
|
||||||
|
Camera mirroring is supported for devices with Android 12 or higher.
|
||||||
|
|
||||||
|
To capture the camera instead of the device screen:
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy --video-source=camera
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, it automatically switches [audio source](audio.md#source) to
|
||||||
|
microphone (as if `--audio-source=mic` were also passed).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --video-source=display # default is --audio-source=output
|
||||||
|
scrcpy --video-source=camera # default is --audio-source=mic
|
||||||
|
scrcpy --video-source=display --audio-source=mic # force display AND microphone
|
||||||
|
scrcpy --video-source=camera --audio-source=output # force camera AND device audio output
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## List
|
||||||
|
|
||||||
|
To list the cameras available (with their declared valid sizes and frame rates):
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy --list-cameras
|
||||||
|
scrcpy --list-camera-sizes
|
||||||
|
```
|
||||||
|
|
||||||
|
_Note that the sizes and frame rates are declarative. They are not accurate on
|
||||||
|
all devices: some of them are declared but not supported, while some others are
|
||||||
|
not declared but supported._
|
||||||
|
|
||||||
|
|
||||||
|
## Selection
|
||||||
|
|
||||||
|
It is possible to pass an explicit camera id (as listed by `--list-cameras`):
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy --video-source=camera --camera-id=0
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, the camera may be selected automatically:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --video-source=camera # use the first camera
|
||||||
|
scrcpy --video-source=camera --camera-facing=front # use the first front camera
|
||||||
|
scrcpy --video-source=camera --camera-facing=back # use the first back camera
|
||||||
|
scrcpy --video-source=camera --camera-facing=external # use the first external camera
|
||||||
|
```
|
||||||
|
|
||||||
|
If `--camera-id` is specified, then `--camera-facing` is forbidden (the id
|
||||||
|
already determines the camera):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --video-source=camera --camera-id=0 --camera-facing=front # error
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Size selection
|
||||||
|
|
||||||
|
It is possible to pass an explicit camera size:
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy --video-source=camera --camera-size=1920x1080
|
||||||
|
```
|
||||||
|
|
||||||
|
The given size may be listed among the declared valid sizes
|
||||||
|
(`--list-camera-sizes`), but may also be anything else (some devices support
|
||||||
|
arbitrary sizes):
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy --video-source=camera --camera-size=1840x444
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, a declared valid size (among the ones listed by
|
||||||
|
`list-camera-sizes`) may be selected automatically.
|
||||||
|
|
||||||
|
Two constraints are supported:
|
||||||
|
- `-m`/`--max-size` (already used for display mirroring), for example `-m1920`;
|
||||||
|
- `--camera-ar` to specify an aspect ratio (`<num>:<den>`, `<value>` or
|
||||||
|
`sensor`).
|
||||||
|
|
||||||
|
Some examples:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --video-source=camera # use the greatest width and the greatest associated height
|
||||||
|
scrcpy --video-source=camera -m1920 # use the greatest width not above 1920 and the greatest associated height
|
||||||
|
scrcpy --video-source=camera --camera-ar=4:3 # use the greatest size with an aspect ratio of 4:3 (+/- 10%)
|
||||||
|
scrcpy --video-source=camera --camera-ar=1.6 # use the greatest size with an aspect ratio of 1.6 (+/- 10%)
|
||||||
|
scrcpy --video-source=camera --camera-ar=sensor # use the greatest size with the aspect ratio of the camera sensor (+/- 10%)
|
||||||
|
scrcpy --video-source=camera -m1920 --camera-ar=16:9 # use the greatest width not above 1920 and the closest to 16:9 aspect ratio
|
||||||
|
```
|
||||||
|
|
||||||
|
If `--camera-size` is specified, then `-m`/`--max-size` and `--camera-ar` are
|
||||||
|
forbidden (the size is determined by the value given explicitly):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --video-source=camera --camera-size=1920x1080 -m3000 # error
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Frame rate
|
||||||
|
|
||||||
|
By default, camera is captured at Android's default frame rate (30 fps).
|
||||||
|
|
||||||
|
To configure a different frame rate:
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy --video-source=camera --camera-fps=60
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## High speed capture
|
||||||
|
|
||||||
|
The Android camera API also supports a [high speed capture mode][high speed].
|
||||||
|
|
||||||
|
This mode is restricted to specific resolutions and frame rates, listed by
|
||||||
|
`--list-camera-sizes`.
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy --video-source=camera --camera-size=1920x1080 --camera-fps=240
|
||||||
|
```
|
||||||
|
|
||||||
|
[high speed]: https://developer.android.com/reference/android/hardware/camera2/CameraConstrainedHighSpeedCaptureSession
|
||||||
|
|
||||||
|
|
||||||
|
## Brace expansion tip
|
||||||
|
|
||||||
|
All camera options start with `--camera-`, so if your shell supports it, you can
|
||||||
|
benefit from [brace expansion] (for example, it is supported _bash_ and _zsh_):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --video-source=camera --camera-{facing=back,ar=16:9,high-speed,fps=120}
|
||||||
|
```
|
||||||
|
|
||||||
|
This will be expanded as:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --video-source=camera --camera-facing=back --camera-ar=16:9 --camera-high-speed --camera-fps=120
|
||||||
|
```
|
||||||
|
|
||||||
|
[brace expansion]: https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html
|
||||||
|
|
||||||
|
|
||||||
|
## Webcam
|
||||||
|
|
||||||
|
Combined with the [V4L2](v4l2.md) feature on Linux, the Android device camera
|
||||||
|
may be used as a webcam on the computer.
|
125
doc/connection.md
Normal file
125
doc/connection.md
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
# 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
|
445
doc/develop.md
445
doc/develop.md
@ -9,16 +9,52 @@ This application is composed of two parts:
|
|||||||
The client is responsible to push the server to the device and start its
|
The client is responsible to push the server to the device and start its
|
||||||
execution.
|
execution.
|
||||||
|
|
||||||
Once the client and the server are connected to each other, the server initially
|
The client and the server establish communication using separate sockets for
|
||||||
sends device information (name and initial screen dimensions), then starts to
|
video, audio and controls. Any of them may be disabled (but not all), so
|
||||||
send a raw H.264 video stream of the device screen. The client decodes the video
|
there are 1, 2 or 3 socket(s).
|
||||||
frames, and display them as soon as possible, without buffering, to minimize
|
|
||||||
latency. The client is not aware of the device rotation (which is handled by the
|
|
||||||
server), it just knows the dimensions of the video frames.
|
|
||||||
|
|
||||||
The client captures relevant keyboard and mouse events, that it transmits to the
|
The server initially sends the device name on the first socket (it is used for
|
||||||
server, which injects them to the device.
|
the scrcpy window title), then each socket is used for its own purpose. All
|
||||||
|
reads and writes are performed from a dedicated thread for each socket, both on
|
||||||
|
the client and on the server.
|
||||||
|
|
||||||
|
If video is enabled, then the server sends a raw video stream (H.264 by default)
|
||||||
|
of the device screen, with some additional headers for each packet. The client
|
||||||
|
decodes the video frames, and displays them as soon as possible, without
|
||||||
|
buffering (unless `--display-buffer=delay` is specified) to minimize latency.
|
||||||
|
The client is not aware of the device rotation (which is handled by the server),
|
||||||
|
it just knows the dimensions of the video frames it receives.
|
||||||
|
|
||||||
|
Similarly, if audio is enabled, then the server sends a raw audio stream (OPUS
|
||||||
|
by default) of the device audio output (or the microphone if
|
||||||
|
`--audio-source=mic` is specified), with some additional headers for each
|
||||||
|
packet. The client decodes the stream, attempts to keep a minimal latency by
|
||||||
|
maintaining an average buffering. The [blog post][scrcpy2] of the scrcpy v2.0
|
||||||
|
release gives more details about the audio feature.
|
||||||
|
|
||||||
|
If control is enabled, then the client captures relevant keyboard and mouse
|
||||||
|
events, that it transmits to the server, which injects them to the device. This
|
||||||
|
is the only socket which is used in both direction: input events are sent from
|
||||||
|
the client to the device, and when the device clipboard changes, the new content
|
||||||
|
is sent from the device to the client to support seamless copy-paste.
|
||||||
|
|
||||||
|
[scrcpy2]: https://blog.rom1v.com/2023/03/scrcpy-2-0-with-audio/
|
||||||
|
|
||||||
|
Note that the client-server roles are expressed at the application level:
|
||||||
|
|
||||||
|
- the server _serves_ video and audio streams, and handle requests from the
|
||||||
|
client,
|
||||||
|
- the client _controls_ the device through the server.
|
||||||
|
|
||||||
|
However, by default (when `--force-adb-forward` is not set), the roles are
|
||||||
|
reversed at the network level:
|
||||||
|
|
||||||
|
- the client opens a server socket and listen on a port before starting the
|
||||||
|
server,
|
||||||
|
- the server connects to the client.
|
||||||
|
|
||||||
|
This role inversion guarantees that the connection will not fail due to race
|
||||||
|
conditions without polling.
|
||||||
|
|
||||||
|
|
||||||
## Server
|
## Server
|
||||||
@ -32,15 +68,14 @@ The server is a Java application (with a [`public static void main(String...
|
|||||||
args)`][main] method), compiled against the Android framework, and executed as
|
args)`][main] method), compiled against the Android framework, and executed as
|
||||||
`shell` on the Android device.
|
`shell` on the Android device.
|
||||||
|
|
||||||
[main]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/server/src/main/java/com/genymobile/scrcpy/Server.java#L123
|
[main]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/Server.java#L193
|
||||||
|
|
||||||
To run such a Java application, the classes must be [_dexed_][dex] (typically,
|
To run such a Java application, the classes must be [_dexed_][dex] (typically,
|
||||||
to `classes.dex`). If `my.package.MainClass` is the main class, compiled to
|
to `classes.dex`). If `my.package.MainClass` is the main class, compiled to
|
||||||
`classes.dex`, pushed to the device in `/data/local/tmp`, then it can be run
|
`classes.dex`, pushed to the device in `/data/local/tmp`, then it can be run
|
||||||
with:
|
with:
|
||||||
|
|
||||||
adb shell CLASSPATH=/data/local/tmp/classes.dex \
|
adb shell CLASSPATH=/data/local/tmp/classes.dex app_process / my.package.MainClass
|
||||||
app_process / my.package.MainClass
|
|
||||||
|
|
||||||
_The path `/data/local/tmp` is a good candidate to push the server, since it's
|
_The path `/data/local/tmp` is a good candidate to push the server, since it's
|
||||||
readable and writable by `shell`, but not world-writable, so a malicious
|
readable and writable by `shell`, but not world-writable, so a malicious
|
||||||
@ -49,7 +84,7 @@ application may not replace the server just before the client executes it._
|
|||||||
Instead of a raw _dex_ file, `app_process` accepts a _jar_ containing
|
Instead of a raw _dex_ file, `app_process` accepts a _jar_ containing
|
||||||
`classes.dex` (e.g. an [APK]). For simplicity, and to benefit from the gradle
|
`classes.dex` (e.g. an [APK]). For simplicity, and to benefit from the gradle
|
||||||
build system, the server is built to an (unsigned) APK (renamed to
|
build system, the server is built to an (unsigned) APK (renamed to
|
||||||
`scrcpy-server`).
|
`scrcpy-server.jar`).
|
||||||
|
|
||||||
[dex]: https://en.wikipedia.org/wiki/Dalvik_(software)
|
[dex]: https://en.wikipedia.org/wiki/Dalvik_(software)
|
||||||
[apk]: https://en.wikipedia.org/wiki/Android_application_package
|
[apk]: https://en.wikipedia.org/wiki/Android_application_package
|
||||||
@ -65,42 +100,77 @@ They can be called using reflection though. The communication with hidden
|
|||||||
components is provided by [_wrappers_ classes][wrappers] and [aidl].
|
components is provided by [_wrappers_ classes][wrappers] and [aidl].
|
||||||
|
|
||||||
[hidden]: https://stackoverflow.com/a/31908373/1987178
|
[hidden]: https://stackoverflow.com/a/31908373/1987178
|
||||||
[wrappers]: https://github.com/Genymobile/scrcpy/tree/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/server/src/main/java/com/genymobile/scrcpy/wrappers
|
[wrappers]: https://github.com/Genymobile/scrcpy/tree/master/server/src/main/java/com/genymobile/scrcpy/wrappers
|
||||||
[aidl]: https://github.com/Genymobile/scrcpy/tree/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/server/src/main/aidl/android/view
|
[aidl]: https://github.com/Genymobile/scrcpy/tree/master/server/src/main/aidl
|
||||||
|
|
||||||
|
|
||||||
### Threading
|
|
||||||
|
|
||||||
The server uses 3 threads:
|
### Execution
|
||||||
|
|
||||||
- the **main** thread, encoding and streaming the video to the client;
|
The server is started by the client basically by executing the following
|
||||||
- the **controller** thread, listening for _control messages_ (typically,
|
commands:
|
||||||
keyboard and mouse events) from the client;
|
|
||||||
- the **receiver** thread (managed by the controller), sending _device messages_
|
|
||||||
to the clients (currently, it is only used to send the device clipboard
|
|
||||||
content).
|
|
||||||
|
|
||||||
Since the video encoding is typically hardware, there would be no benefit in
|
```bash
|
||||||
encoding and streaming in two different threads.
|
adb push scrcpy-server /data/local/tmp/scrcpy-server.jar
|
||||||
|
adb forward tcp:27183 localabstract:scrcpy
|
||||||
|
adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 2.1
|
||||||
|
```
|
||||||
|
|
||||||
|
The first argument (`2.1` in the example) is the client scrcpy version. The
|
||||||
|
server fails if the client and the server do not have the exact same version.
|
||||||
|
The protocol between the client and the server may change from version to
|
||||||
|
version (see [protocol](#protocol) below), and there is no backward or forward
|
||||||
|
compatibility (there is no point to use different client and server versions).
|
||||||
|
This check allows to detect misconfiguration (running an older or newer server
|
||||||
|
by mistake).
|
||||||
|
|
||||||
|
It is followed by any number of arguments, in the form of `key=value` pairs.
|
||||||
|
Their order is irrelevant. The possible keys and associated value types can be
|
||||||
|
found in the [server][server-options] and [client][client-options] code.
|
||||||
|
|
||||||
|
[server-options]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/Options.java#L181
|
||||||
|
[client-options]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/app/src/server.c#L226
|
||||||
|
|
||||||
|
For example, if we execute `scrcpy -m1920 --no-audio`, then the server
|
||||||
|
execution will look like this:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# scid is a random number to identify different clients running on the same device
|
||||||
|
adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 2.1 scid=12345678 log_level=info audio=false max_size=1920
|
||||||
|
```
|
||||||
|
|
||||||
|
### Components
|
||||||
|
|
||||||
|
When executed, its [`main()`][main] method is executed (on the "main" thread).
|
||||||
|
It parses the arguments, establishes the connection with the client and starts
|
||||||
|
the other "components":
|
||||||
|
- the **video** streamer: it captures the video screen and send encoded video
|
||||||
|
packets on the _video_ socket (from the _video_ thread).
|
||||||
|
- the **audio** streamer: it uses several threads to capture raw packets,
|
||||||
|
submits them to encoding and retrieve encoded packets, which it sends on the
|
||||||
|
_audio_ socket.
|
||||||
|
- the **controller**: it receives _control messages_ (typically input events)
|
||||||
|
on the _control_ socket from one thread, and sends _device messages_ (e.g. to
|
||||||
|
transmit the device clipboard content to the client) on the same _control
|
||||||
|
socket_ from another thread. Thus, the _control_ socket is used in both
|
||||||
|
directions (contrary to the _video_ and _audio_ sockets).
|
||||||
|
|
||||||
|
|
||||||
### Screen video encoding
|
### Screen video encoding
|
||||||
|
|
||||||
The encoding is managed by [`ScreenEncoder`].
|
The encoding is managed by [`ScreenEncoder`].
|
||||||
|
|
||||||
The video is encoded using the [`MediaCodec`] API. The codec takes its input
|
The video is encoded using the [`MediaCodec`] API. The codec encodes the content
|
||||||
from a [surface] associated to the display, and writes the resulting H.264
|
of a `Surface` associated to the display, and writes the encoding packets to the
|
||||||
stream to the provided output stream (the socket connected to the client).
|
client (on the _video_ socket).
|
||||||
|
|
||||||
[`ScreenEncoder`]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
|
[`ScreenEncoder`]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
|
||||||
[`MediaCodec`]: https://developer.android.com/reference/android/media/MediaCodec.html
|
[`MediaCodec`]: https://developer.android.com/reference/android/media/MediaCodec.html
|
||||||
[surface]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java#L68-L69
|
|
||||||
|
|
||||||
On device [rotation], the codec, surface and display are reinitialized, and a
|
On device rotation (or folding), the encoding session is [reset] and restarted.
|
||||||
new video stream is produced.
|
|
||||||
|
|
||||||
New frames are produced only when changes occur on the surface. This is good
|
New frames are produced only when changes occur on the surface. This avoids to
|
||||||
because it avoids to send unnecessary frames, but there are drawbacks:
|
send unnecessary frames, but by default there might be drawbacks:
|
||||||
|
|
||||||
- it does not send any frame on start if the device screen does not change,
|
- it does not send any frame on start if the device screen does not change,
|
||||||
- after fast motion changes, the last frame may have poor quality.
|
- after fast motion changes, the last frame may have poor quality.
|
||||||
@ -108,11 +178,24 @@ because it avoids to send unnecessary frames, but there are drawbacks:
|
|||||||
Both problems are [solved][repeat] by the flag
|
Both problems are [solved][repeat] by the flag
|
||||||
[`KEY_REPEAT_PREVIOUS_FRAME_AFTER`][repeat-flag].
|
[`KEY_REPEAT_PREVIOUS_FRAME_AFTER`][repeat-flag].
|
||||||
|
|
||||||
|
[reset]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java#L179
|
||||||
[rotation]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java#L90
|
[rotation]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java#L90
|
||||||
[repeat]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java#L147-L148
|
[repeat]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java#L246-L247
|
||||||
[repeat-flag]: https://developer.android.com/reference/android/media/MediaFormat.html#KEY_REPEAT_PREVIOUS_FRAME_AFTER
|
[repeat-flag]: https://developer.android.com/reference/android/media/MediaFormat.html#KEY_REPEAT_PREVIOUS_FRAME_AFTER
|
||||||
|
|
||||||
|
|
||||||
|
### Audio encoding
|
||||||
|
|
||||||
|
Similarly, the audio is [captured] using an [`AudioRecord`], and [encoded] using
|
||||||
|
the [`MediaCodec`] asynchronous API.
|
||||||
|
|
||||||
|
More details are available on the [blog post][scrcpy2] introducing the audio feature.
|
||||||
|
|
||||||
|
[captured]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
|
||||||
|
[encoded]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java
|
||||||
|
[`AudioRecord`]: https://developer.android.com/reference/android/media/AudioRecord
|
||||||
|
|
||||||
|
|
||||||
### Input events injection
|
### Input events injection
|
||||||
|
|
||||||
_Control messages_ are received from the client by the [`Controller`] (run in a
|
_Control messages_ are received from the client by the [`Controller`] (run in a
|
||||||
@ -124,13 +207,13 @@ separate thread). There are several types of input events:
|
|||||||
- other commands (e.g. to switch the screen on or to copy the clipboard).
|
- other commands (e.g. to switch the screen on or to copy the clipboard).
|
||||||
|
|
||||||
Some of them need to inject input events to the system. To do so, they use the
|
Some of them need to inject input events to the system. To do so, they use the
|
||||||
_hidden_ method [`InputManager.injectInputEvent`] (exposed by our
|
_hidden_ method [`InputManager.injectInputEvent()`] (exposed by the
|
||||||
[`InputManager` wrapper][inject-wrapper]).
|
[`InputManager` wrapper][inject-wrapper]).
|
||||||
|
|
||||||
[`Controller`]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/server/src/main/java/com/genymobile/scrcpy/Controller.java#L81
|
[`Controller`]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/Controller.java
|
||||||
[`KeyEvent`]: https://developer.android.com/reference/android/view/KeyEvent.html
|
[`KeyEvent`]: https://developer.android.com/reference/android/view/KeyEvent.html
|
||||||
[`MotionEvent`]: https://developer.android.com/reference/android/view/MotionEvent.html
|
[`MotionEvent`]: https://developer.android.com/reference/android/view/MotionEvent.html
|
||||||
[`InputManager.injectInputEvent`]: https://android.googlesource.com/platform/frameworks/base/+/oreo-release/core/java/android/hardware/input/InputManager.java#857
|
[`InputManager.injectInputEvent()`]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java#L34
|
||||||
[inject-wrapper]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java#L27
|
[inject-wrapper]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java#L27
|
||||||
|
|
||||||
|
|
||||||
@ -140,126 +223,222 @@ _hidden_ method [`InputManager.injectInputEvent`] (exposed by our
|
|||||||
The client relies on [SDL], which provides cross-platform API for UI, input
|
The client relies on [SDL], which provides cross-platform API for UI, input
|
||||||
events, threading, etc.
|
events, threading, etc.
|
||||||
|
|
||||||
The video stream is decoded by [libav] (FFmpeg).
|
The video and audio streams are decoded by [FFmpeg].
|
||||||
|
|
||||||
[SDL]: https://www.libsdl.org
|
[SDL]: https://www.libsdl.org
|
||||||
[libav]: https://www.libav.org/
|
[ffmpeg]: https://ffmpeg.org/
|
||||||
|
|
||||||
|
|
||||||
### Initialization
|
### Initialization
|
||||||
|
|
||||||
On startup, in addition to _libav_ and _SDL_ initialization, the client must
|
The client parses the command line arguments, then [runs one of two code
|
||||||
push and start the server on the device, and open two sockets (one for the video
|
paths][run]:
|
||||||
stream, one for control) so that they may communicate.
|
- scrcpy in "normal" mode ([`scrcpy.c`])
|
||||||
|
- scrcpy in [OTG mode](hid-otg.md) ([`scrcpy_otg.c`])
|
||||||
|
|
||||||
Note that the client-server roles are expressed at the application level:
|
[run]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/app/src/main.c#L81-L82
|
||||||
|
[`scrcpy.c`]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/app/src/scrcpy.c#L292-L293
|
||||||
|
[`scrcpy_otg.c`]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/app/src/usb/scrcpy_otg.c#L51-L52
|
||||||
|
|
||||||
- the server _serves_ video stream and handle requests from the client,
|
In the remaining of this document, we assume that the "normal" mode is used
|
||||||
- the client _controls_ the device through the server.
|
(read the code for the OTG mode).
|
||||||
|
|
||||||
However, the roles are reversed at the network level:
|
On startup, the client:
|
||||||
|
- opens the _video_, _audio_ and _control_ sockets;
|
||||||
- the client opens a server socket and listen on a port before starting the
|
- pushes and starts the server on the device;
|
||||||
server,
|
- initializes its components (demuxers, decoders, recorder…).
|
||||||
- the server connects to the client.
|
|
||||||
|
|
||||||
This role inversion guarantees that the connection will not fail due to race
|
|
||||||
conditions, and avoids polling.
|
|
||||||
|
|
||||||
_(Note that over TCP/IP, the roles are not reversed, due to a bug in `adb
|
|
||||||
reverse`. See commit [1038bad] and [issue #5].)_
|
|
||||||
|
|
||||||
Once the server is connected, it sends the device information (name and initial
|
|
||||||
screen dimensions). Thus, the client may init the window and renderer, before
|
|
||||||
the first frame is available.
|
|
||||||
|
|
||||||
To minimize startup time, SDL initialization is performed while listening for
|
|
||||||
the connection from the server (see commit [90a46b4]).
|
|
||||||
|
|
||||||
[1038bad]: https://github.com/Genymobile/scrcpy/commit/1038bad3850f18717a048a4d5c0f8110e54ee172
|
|
||||||
[issue #5]: https://github.com/Genymobile/scrcpy/issues/5
|
|
||||||
[90a46b4]: https://github.com/Genymobile/scrcpy/commit/90a46b4c45637d083e877020d85ade52a9a5fa8e
|
|
||||||
|
|
||||||
|
|
||||||
### Threading
|
### Video and audio streams
|
||||||
|
|
||||||
The client uses 4 threads:
|
Depending on the arguments passed to `scrcpy`, several components may be used.
|
||||||
|
Here is an overview of the video and audio components:
|
||||||
- the **main** thread, executing the SDL event loop,
|
|
||||||
- the **stream** thread, receiving the video and used for decoding and
|
|
||||||
recording,
|
|
||||||
- the **controller** thread, sending _control messages_ to the server,
|
|
||||||
- the **receiver** thread (managed by the controller), receiving _device
|
|
||||||
messages_ from the server.
|
|
||||||
|
|
||||||
In addition, another thread can be started if necessary to handle APK
|
|
||||||
installation or file push requests (via drag&drop on the main window) or to
|
|
||||||
print the framerate regularly in the console.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Stream
|
|
||||||
|
|
||||||
The video [stream] is received from the socket (connected to the server on the
|
|
||||||
device) in a separate thread.
|
|
||||||
|
|
||||||
If a [decoder] is present (i.e. `--no-display` is not set), then it uses _libav_
|
|
||||||
to decode the H.264 stream from the socket, and notifies the main thread when a
|
|
||||||
new frame is available.
|
|
||||||
|
|
||||||
There are two [frames][video_buffer] simultaneously in memory:
|
|
||||||
- the **decoding** frame, written by the decoder from the decoder thread,
|
|
||||||
- the **rendering** frame, rendered in a texture from the main thread.
|
|
||||||
|
|
||||||
When a new decoded frame is available, the decoder _swaps_ the decoding and
|
|
||||||
rendering frame (with proper synchronization). Thus, it immediately starts
|
|
||||||
to decode a new frame while the main thread renders the last one.
|
|
||||||
|
|
||||||
If a [recorder] is present (i.e. `--record` is enabled), then it muxes the raw
|
|
||||||
H.264 packet to the output video file.
|
|
||||||
|
|
||||||
[stream]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/app/src/stream.h
|
|
||||||
[decoder]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/app/src/decoder.h
|
|
||||||
[video_buffer]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/app/src/video_buffer.h
|
|
||||||
[recorder]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/app/src/recorder.h
|
|
||||||
|
|
||||||
```
|
```
|
||||||
+----------+ +----------+
|
V4L2 sink
|
||||||
---> | decoder | ---> | screen |
|
/
|
||||||
+---------+ / +----------+ +----------+
|
decoder
|
||||||
socket ---> | stream | ----
|
/ \
|
||||||
+---------+ \ +----------+
|
VIDEO -------------> demuxer display
|
||||||
---> | recorder |
|
\
|
||||||
+----------+
|
recorder
|
||||||
|
/
|
||||||
|
AUDIO -------------> demuxer
|
||||||
|
\
|
||||||
|
decoder --- audio player
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The _demuxer_ is responsible to extract video and audio packets (read some
|
||||||
|
header, split the video stream into packets at correct boundaries, etc.).
|
||||||
|
|
||||||
|
The demuxed packets may be sent to a _decoder_ (one per stream, to produce
|
||||||
|
frames) and to a recorder (receiving both video and audio stream to record a
|
||||||
|
single file). The packets are encoded on the device (by `MediaCodec`), but when
|
||||||
|
recording, they are _muxed_ (asynchronously) into a container (MKV or MP4) on
|
||||||
|
the client side.
|
||||||
|
|
||||||
|
Video frames are sent to the screen/display to be rendered in the scrcpy window.
|
||||||
|
They may also be sent to a [V4L2 sink](v4l2.md).
|
||||||
|
|
||||||
|
Audio "frames" (an array of decoded samples) are sent to the audio player.
|
||||||
|
|
||||||
|
|
||||||
### Controller
|
### Controller
|
||||||
|
|
||||||
The [controller] is responsible to send _control messages_ to the device. It
|
The _controller_ is responsible to send _control messages_ to the device. It
|
||||||
runs in a separate thread, to avoid I/O on the main thread.
|
runs in a separate thread, to avoid I/O on the main thread.
|
||||||
|
|
||||||
On SDL event, received on the main thread, the [input manager][inputmanager]
|
On SDL event, received on the main thread, the _input manager_ creates
|
||||||
creates appropriate [_control messages_][controlmsg]. It is responsible to
|
appropriate _control messages_. It is responsible to convert SDL events to
|
||||||
convert SDL events to Android events (using [convert]). It pushes the _control
|
Android events. It then pushes the _control messages_ to a queue hold by the
|
||||||
messages_ to a queue hold by the controller. On its own thread, the controller
|
controller. On its own thread, the controller takes messages from the queue,
|
||||||
takes messages from the queue, that it serializes and sends to the client.
|
that it serializes and sends to the client.
|
||||||
|
|
||||||
[controller]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/app/src/controller.h
|
|
||||||
[controlmsg]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/app/src/control_msg.h
|
|
||||||
[inputmanager]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/app/src/input_manager.h
|
|
||||||
[convert]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/app/src/convert.h
|
|
||||||
|
|
||||||
|
|
||||||
### UI and event loop
|
## Protocol
|
||||||
|
|
||||||
Initialization, input events and rendering are all [managed][scrcpy] in the main
|
The protocol between the client and the server must be considered _internal_: it
|
||||||
thread.
|
may (and will) change at any time for any reason. Everything may change (the
|
||||||
|
number of sockets, the order in which the sockets must be opened, the data
|
||||||
|
format on the wire…) from version to version. A client must always be run with a
|
||||||
|
matching server version.
|
||||||
|
|
||||||
Events are handled in the [event loop], which either updates the [screen] or
|
This section documents the current protocol in scrcpy v2.1.
|
||||||
delegates to the [input manager][inputmanager].
|
|
||||||
|
|
||||||
[scrcpy]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/app/src/scrcpy.c
|
### Connection
|
||||||
[event loop]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/app/src/scrcpy.c#L201
|
|
||||||
[screen]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/app/src/screen.h
|
Firstly, the client sets up an adb tunnel:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# By default, a reverse redirection: the computer listens, the device connects
|
||||||
|
adb reverse localabstract:scrcpy_<SCID> tcp:27183
|
||||||
|
|
||||||
|
# As a fallback (or if --force-adb forward is set), a forward redirection:
|
||||||
|
# the device listens, the computer connects
|
||||||
|
adb forward tcp:27183 localabstract:scrcpy_<SCID>
|
||||||
|
```
|
||||||
|
|
||||||
|
(`<SCID>` is a 31-bit random number, so that it does not fail when several
|
||||||
|
scrcpy instances start "at the same time" for the same device.)
|
||||||
|
|
||||||
|
Then, up to 3 sockets are opened, in that order:
|
||||||
|
- a _video_ socket
|
||||||
|
- an _audio_ socket
|
||||||
|
- a _control_ socket
|
||||||
|
|
||||||
|
Each one may be disabled (respectively by `--no-video`, `--no-audio` and
|
||||||
|
`--no-control`, directly or indirectly). For example, if `--no-audio` is set,
|
||||||
|
then the _video_ socket is opened first, then the _control_ socket.
|
||||||
|
|
||||||
|
On the _first_ socket opened (whichever it is), if the tunnel is _forward_, then
|
||||||
|
a [dummy byte] is sent from the device to the client. This allows to detect a
|
||||||
|
connection error (the client connection does not fail as long as there is an adb
|
||||||
|
forward redirection, even if nothing is listening on the device side).
|
||||||
|
|
||||||
|
Still on this _first_ socket, the device sends some [metadata][device meta] to
|
||||||
|
the client (currently only the device name, used as the window title, but there
|
||||||
|
might be other fields in the future).
|
||||||
|
|
||||||
|
[dummy byte]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java#L93
|
||||||
|
[device meta]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java#L151
|
||||||
|
|
||||||
|
You can read the [client][client-connection] and [server][server-connection]
|
||||||
|
code for more details.
|
||||||
|
|
||||||
|
[client-connection]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/app/src/server.c#L465-L466
|
||||||
|
[server-connection]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java#L63
|
||||||
|
|
||||||
|
Then each socket is used for its intended purpose.
|
||||||
|
|
||||||
|
### Video and audio
|
||||||
|
|
||||||
|
On the _video_ and _audio_ sockets, the device first sends some [codec
|
||||||
|
metadata]:
|
||||||
|
- On the _video_ socket, 12 bytes:
|
||||||
|
- the codec id (`u32`) (H264, H265 or AV1)
|
||||||
|
- the initial video width (`u32`)
|
||||||
|
- the initial video height (`u32`)
|
||||||
|
- On the _audio_ socket, 4 bytes:
|
||||||
|
- 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
|
||||||
|
|
||||||
|
Then each packet produced by `MediaCodec` is sent, prefixed by a 12-byte [frame
|
||||||
|
header]:
|
||||||
|
- config packet flag (`u1`)
|
||||||
|
- key frame flag (`u1`)
|
||||||
|
- PTS (`u62`)
|
||||||
|
- packet size (`u32`)
|
||||||
|
|
||||||
|
Here is a schema describing the frame header:
|
||||||
|
|
||||||
|
```
|
||||||
|
[. . . . . . . .|. . . .]. . . . . . . . . . . . . . . ...
|
||||||
|
<-------------> <-----> <-----------------------------...
|
||||||
|
PTS packet raw packet
|
||||||
|
size
|
||||||
|
<--------------------->
|
||||||
|
frame header
|
||||||
|
|
||||||
|
The most significant bits of the PTS are used for packet flags:
|
||||||
|
|
||||||
|
byte 7 byte 6 byte 5 byte 4 byte 3 byte 2 byte 1 byte 0
|
||||||
|
CK...... ........ ........ ........ ........ ........ ........ ........
|
||||||
|
^^<------------------------------------------------------------------->
|
||||||
|
|| PTS
|
||||||
|
| `- key frame
|
||||||
|
`-- config packet
|
||||||
|
```
|
||||||
|
|
||||||
|
[frame header]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/Streamer.java#L83
|
||||||
|
|
||||||
|
|
||||||
|
### Controls
|
||||||
|
|
||||||
|
Controls messages are sent via a custom binary protocol.
|
||||||
|
|
||||||
|
The only documentation for this protocol is the set of unit tests on both sides:
|
||||||
|
- `ControlMessage` (from client to device): [serialization](https://github.com/Genymobile/scrcpy/blob/master/app/tests/test_control_msg_serialize.c) | [deserialization](https://github.com/Genymobile/scrcpy/blob/master/server/src/test/java/com/genymobile/scrcpy/ControlMessageReaderTest.java)
|
||||||
|
- `DeviceMessage` (from device to client) [serialization](https://github.com/Genymobile/scrcpy/blob/master/server/src/test/java/com/genymobile/scrcpy/DeviceMessageWriterTest.java) | [deserialization](https://github.com/Genymobile/scrcpy/blob/master/app/tests/test_device_msg_deserialize.c)
|
||||||
|
|
||||||
|
|
||||||
|
## Standalone server
|
||||||
|
|
||||||
|
Although the server is designed to work for the scrcpy client, it can be used
|
||||||
|
with any client which uses the same protocol.
|
||||||
|
|
||||||
|
For simplicity, some [server-specific options] have been added to produce raw
|
||||||
|
streams easily:
|
||||||
|
- `send_device_meta=false`: disable the device metata (in practice, the device
|
||||||
|
name) sent on the _first_ socket
|
||||||
|
- `send_frame_meta=false`: disable the 12-byte header for each packet
|
||||||
|
- `send_dummy_byte`: disable the dummy byte sent on forward connections
|
||||||
|
- `send_codec_meta`: disable the codec information (and initial device size for
|
||||||
|
video)
|
||||||
|
- `raw_stream`: disable all the above
|
||||||
|
|
||||||
|
[server-specific options]: https://github.com/Genymobile/scrcpy/blob/a3cdf1a6b86ea22786e1f7d09b9c202feabc6949/server/src/main/java/com/genymobile/scrcpy/Options.java#L309-L329
|
||||||
|
|
||||||
|
Concretely, here is how to expose a raw H.264 stream on a TCP socket:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
adb push scrcpy-server-v2.1 /data/local/tmp/scrcpy-server-manual.jar
|
||||||
|
adb forward tcp:1234 localabstract:scrcpy
|
||||||
|
adb shell CLASSPATH=/data/local/tmp/scrcpy-server-manual.jar \
|
||||||
|
app_process / com.genymobile.scrcpy.Server 2.1 \
|
||||||
|
tunnel_forward=true audio=false control=false cleanup=false \
|
||||||
|
raw_stream=true max_size=1920
|
||||||
|
```
|
||||||
|
|
||||||
|
As soon as a client connects over TCP on port 1234, the device will start
|
||||||
|
streaming the video. For example, VLC can play the video (although you will
|
||||||
|
experience a very high latency, more details [here][vlc-0latency]):
|
||||||
|
|
||||||
|
```
|
||||||
|
vlc -Idummy --demux=h264 --network-caching=0 tcp://localhost:1234
|
||||||
|
```
|
||||||
|
|
||||||
|
[vlc-0latency]: https://code.videolan.org/rom1v/vlc/-/merge_requests/20
|
||||||
|
|
||||||
|
|
||||||
## Hack
|
## Hack
|
||||||
|
158
doc/device.md
158
doc/device.md
@ -1,156 +1,9 @@
|
|||||||
# Device
|
# 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
|
Some command line arguments perform actions on the device itself while scrcpy is
|
||||||
running.
|
running.
|
||||||
|
|
||||||
|
## Stay awake
|
||||||
### Stay awake
|
|
||||||
|
|
||||||
To prevent the device from sleeping after a delay **when the device is plugged
|
To prevent the device from sleeping after a delay **when the device is plugged
|
||||||
in**:
|
in**:
|
||||||
@ -166,7 +19,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).
|
`--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
|
It is possible to turn the device screen off while mirroring on start with a
|
||||||
command-line option:
|
command-line option:
|
||||||
@ -194,7 +47,7 @@ scrcpy -Sw # short version
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Show touches
|
## Show touches
|
||||||
|
|
||||||
For presentations, it may be useful to show physical touches (on the physical
|
For presentations, it may be useful to show physical touches (on the physical
|
||||||
device). Android exposes this feature in _Developers options_.
|
device). Android exposes this feature in _Developers options_.
|
||||||
@ -210,7 +63,7 @@ scrcpy -t # short version
|
|||||||
Note that it only shows _physical_ touches (by a finger on the device).
|
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_:
|
To turn the device screen off when closing _scrcpy_:
|
||||||
|
|
||||||
@ -218,11 +71,10 @@ To turn the device screen off when closing _scrcpy_:
|
|||||||
scrcpy --power-off-on-close
|
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:
|
By default, on start, the device is powered on. To prevent this behavior:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scrcpy --no-power-on
|
scrcpy --no-power-on
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -106,3 +106,7 @@ scrcpy --otg # keyboard and mouse
|
|||||||
|
|
||||||
Like `--hid-keyboard` and `--hid-mouse`, it only works if the device is
|
Like `--hid-keyboard` and `--hid-mouse`, it only works if the device is
|
||||||
connected over USB.
|
connected over USB.
|
||||||
|
|
||||||
|
## HID/OTG issues on Windows
|
||||||
|
|
||||||
|
See [FAQ](/FAQ.md#hidotg-issues-on-windows).
|
||||||
|
@ -9,12 +9,10 @@ Scrcpy is packaged in several distributions and package managers:
|
|||||||
- Debian/Ubuntu: `apt install scrcpy`
|
- Debian/Ubuntu: `apt install scrcpy`
|
||||||
- Arch Linux: `pacman -S scrcpy`
|
- Arch Linux: `pacman -S scrcpy`
|
||||||
- Fedora: `dnf copr enable zeno/scrcpy && dnf install scrcpy`
|
- Fedora: `dnf copr enable zeno/scrcpy && dnf install scrcpy`
|
||||||
- Gentoo: [ebuild][ebuild-link] file
|
- Gentoo: `emerge scrcpy`
|
||||||
- Snap: `snap install scrcpy`
|
- Snap: `snap install scrcpy`
|
||||||
- … (see [repology](https://repology.org/project/scrcpy/versions))
|
- … (see [repology](https://repology.org/project/scrcpy/versions))
|
||||||
|
|
||||||
[ebuild-link]: https://github.com/maggu2810/maggu2810-overlay/tree/master/app-mobilephone/scrcpy
|
|
||||||
|
|
||||||
### Latest version
|
### Latest version
|
||||||
|
|
||||||
However, the packaged version is not always the latest release. To install the
|
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 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¹_
|
| 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 `HOME` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _Middle-click_
|
||||||
| Click on `BACK` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _Right-click²_
|
| Click on `BACK` | <kbd>MOD</kbd>+<kbd>b</kbd> \| <kbd>MOD</kbd>+<kbd>Backspace</kbd> \| _Right-click²_
|
||||||
| Click on `APP_SWITCH` | <kbd>MOD</kbd>+<kbd>s</kbd> \| _4th-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 `MENU` (unlock screen)⁴ | <kbd>MOD</kbd>+<kbd>m</kbd>
|
||||||
| Click on `VOLUME_UP` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(up)_
|
| Click on `VOLUME_UP` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(up)_
|
||||||
|
43
doc/video.md
43
doc/video.md
@ -1,5 +1,14 @@
|
|||||||
# Video
|
# Video
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
By default, scrcpy mirrors the device screen.
|
||||||
|
|
||||||
|
It is possible to capture the device camera instead.
|
||||||
|
|
||||||
|
See the dedicated [camera](camera.md) page.
|
||||||
|
|
||||||
|
|
||||||
## Size
|
## Size
|
||||||
|
|
||||||
By default, scrcpy attempts to mirror at the Android device resolution.
|
By default, scrcpy attempts to mirror at the Android device resolution.
|
||||||
@ -21,7 +30,7 @@ If encoding fails, scrcpy automatically tries again with a lower definition
|
|||||||
|
|
||||||
## Bit rate
|
## 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
|
```bash
|
||||||
scrcpy --video-bit-rate=2M
|
scrcpy --video-bit-rate=2M
|
||||||
@ -66,6 +75,14 @@ scrcpy --video-codec=av1
|
|||||||
H265 may provide better quality, but H264 should provide lower latency.
|
H265 may provide better quality, but H264 should provide lower latency.
|
||||||
AV1 encoders are not common on current Android devices.
|
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:
|
Several encoders may be available on the device. They can be listed by:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -79,11 +96,6 @@ try another one:
|
|||||||
scrcpy --video-codec=h264 --video-encoder='OMX.qcom.video.encoder.avc'
|
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
|
## Rotation
|
||||||
|
|
||||||
@ -134,6 +146,25 @@ phone, landscape for a tablet).
|
|||||||
If `--max-size` is also specified, resizing is applied after cropping.
|
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-id=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
|
## Buffering
|
||||||
|
|
||||||
By default, there is no video buffering, to get the lowest possible latency.
|
By default, there is no video buffering, to get the lowest possible latency.
|
||||||
|
@ -4,18 +4,24 @@
|
|||||||
|
|
||||||
Download the [latest release]:
|
Download the [latest release]:
|
||||||
|
|
||||||
- [`scrcpy-win64-v2.0.zip`][direct-win64] (64-bit)
|
- [`scrcpy-win64-v2.1.1.zip`][direct-win64] (64-bit)
|
||||||
<sub>SHA-256: `ae4c8d37a496b43f8974ba8f07f708e22a9570ba0cddc3dc3a36edbccd4d2a20`</sub>
|
<sub>SHA-256: `f77281e1bce2f9934617699c581f063d5b327f012eff602ee98fb2ef550c25c2`</sub>
|
||||||
- [`scrcpy-win32-v2.0.zip`][direct-win32] (32-bit)
|
- [`scrcpy-win32-v2.1.1.zip`][direct-win32] (32-bit)
|
||||||
<sub>SHA-256: `15d98c02cb0e0bbd84f8b5d54991e0f6925569b1286a86a40743944fcb1c2d8c`</sub>
|
<sub>SHA-256: `ef7ae7fbe9449f2643febdc2244fb186d1a746a3c736394150cfd14f06d3c943`</sub>
|
||||||
|
|
||||||
[latest release]: https://github.com/Genymobile/scrcpy/releases/latest
|
[latest release]: https://github.com/Genymobile/scrcpy/releases/latest
|
||||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v2.0/scrcpy-win64-v2.0.zip
|
[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.0/scrcpy-win32-v2.0.zip
|
[direct-win32]: https://github.com/Genymobile/scrcpy/releases/download/v2.1.1/scrcpy-win32-v2.1.1.zip
|
||||||
|
|
||||||
and extract it.
|
and extract it.
|
||||||
|
|
||||||
Alternatively, you could install it from packages manager, like [Chocolatey]:
|
Alternatively, you could install it from packages manager, like [Winget]:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
winget install scrcpy
|
||||||
|
```
|
||||||
|
|
||||||
|
or [Chocolatey]:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
choco install scrcpy
|
choco install scrcpy
|
||||||
@ -30,6 +36,7 @@ scoop install scrcpy
|
|||||||
scoop install adb # if you don't have it yet
|
scoop install adb # if you don't have it yet
|
||||||
```
|
```
|
||||||
|
|
||||||
|
[Winget]: https://github.com/microsoft/winget-cli
|
||||||
[Chocolatey]: https://chocolatey.org/
|
[Chocolatey]: https://chocolatey.org/
|
||||||
[Scoop]: https://scoop.sh
|
[Scoop]: https://scoop.sh
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
BUILDDIR=build-auto
|
BUILDDIR=build-auto
|
||||||
PREBUILT_SERVER_URL=https://github.com/Genymobile/scrcpy/releases/download/v2.0/scrcpy-server-v2.0
|
PREBUILT_SERVER_URL=https://github.com/Genymobile/scrcpy/releases/download/v2.1.1/scrcpy-server-v2.1.1
|
||||||
PREBUILT_SERVER_SHA256=9e241615f578cd690bb43311000debdecf6a9c50a7082b001952f18f6f21ddc2
|
PREBUILT_SERVER_SHA256=9558db6c56743a1dc03b38f59801fb40e91cc891f8fc0c89e5b0b067761f148e
|
||||||
|
|
||||||
echo "[scrcpy] Downloading prebuilt server..."
|
echo "[scrcpy] Downloading prebuilt server..."
|
||||||
wget "$PREBUILT_SERVER_URL" -O scrcpy-server
|
wget "$PREBUILT_SERVER_URL" -O scrcpy-server
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
project('scrcpy', 'c',
|
project('scrcpy', 'c',
|
||||||
version: '2.0',
|
version: 'v2.2',
|
||||||
meson_version: '>= 0.48',
|
meson_version: '>= 0.48',
|
||||||
default_options: [
|
default_options: [
|
||||||
'c_std=c11',
|
'c_std=c11',
|
||||||
@ -7,6 +7,8 @@ project('scrcpy', 'c',
|
|||||||
'b_ndebug=if-release',
|
'b_ndebug=if-release',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
add_project_arguments('-Wmissing-prototypes', language: 'c')
|
||||||
|
|
||||||
if get_option('compile_app')
|
if get_option('compile_app')
|
||||||
subdir('app')
|
subdir('app')
|
||||||
endif
|
endif
|
||||||
|
16
release.mk
16
release.mk
@ -98,10 +98,10 @@ 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/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/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/ffmpeg-6.0-scrcpy-4/win32/bin/swresample-4.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.5/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.5/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/platform-tools-34.0.5/AdbWinUsbApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||||
cp app/prebuilt-deps/data/SDL2-2.26.4/i686-w64-mingw32/bin/SDL2.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
cp app/prebuilt-deps/data/SDL2-2.28.4/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)/"
|
cp app/prebuilt-deps/data/libusb-1.0.26/libusb-MinGW-Win32/bin/msys-usb-1.0.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||||
|
|
||||||
dist-win64: build-server build-win64
|
dist-win64: build-server build-win64
|
||||||
@ -116,10 +116,10 @@ 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/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/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/ffmpeg-6.0-scrcpy-4/win64/bin/swresample-4.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.5/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.5/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/platform-tools-34.0.5/AdbWinUsbApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||||
cp app/prebuilt-deps/data/SDL2-2.26.4/x86_64-w64-mingw32/bin/SDL2.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
cp app/prebuilt-deps/data/SDL2-2.28.4/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)/"
|
cp app/prebuilt-deps/data/libusb-1.0.26/libusb-MinGW-x64/bin/msys-usb-1.0.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||||
|
|
||||||
zip-win32: dist-win32
|
zip-win32: dist-win32
|
||||||
|
@ -7,8 +7,8 @@ android {
|
|||||||
applicationId "com.genymobile.scrcpy"
|
applicationId "com.genymobile.scrcpy"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 33
|
targetSdkVersion 33
|
||||||
versionCode 20000
|
versionCode 200
|
||||||
versionName "2.0"
|
versionName "v2.2"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
SCRCPY_DEBUG=false
|
SCRCPY_DEBUG=false
|
||||||
SCRCPY_VERSION_NAME=2.0
|
SCRCPY_VERSION_NAME=v2.2
|
||||||
|
|
||||||
PLATFORM=${ANDROID_PLATFORM:-33}
|
PLATFORM=${ANDROID_PLATFORM:-33}
|
||||||
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-33.0.0}
|
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-33.0.0}
|
||||||
@ -48,6 +48,7 @@ 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/view/IRotationWatcher.aidl
|
||||||
"$BUILD_TOOLS_DIR/aidl" -o"$GEN_DIR" \
|
"$BUILD_TOOLS_DIR/aidl" -o"$GEN_DIR" \
|
||||||
android/content/IOnPrimaryClipChangedListener.aidl
|
android/content/IOnPrimaryClipChangedListener.aidl
|
||||||
|
"$BUILD_TOOLS_DIR/aidl" -o"$GEN_DIR" android/view/IDisplayFoldListener.aidl
|
||||||
|
|
||||||
echo "Compiling java sources..."
|
echo "Compiling java sources..."
|
||||||
cd ../java
|
cd ../java
|
||||||
|
@ -118,7 +118,7 @@ public final class AudioCapture {
|
|||||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
|
||||||
startWorkaroundAndroid11();
|
startWorkaroundAndroid11();
|
||||||
try {
|
try {
|
||||||
tryStartRecording(3, 100);
|
tryStartRecording(5, 100);
|
||||||
} finally {
|
} finally {
|
||||||
stopWorkaroundAndroid11();
|
stopWorkaroundAndroid11();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
|
public final class CameraAspectRatio {
|
||||||
|
private static final float SENSOR = -1;
|
||||||
|
|
||||||
|
private float ar;
|
||||||
|
|
||||||
|
private CameraAspectRatio(float ar) {
|
||||||
|
this.ar = ar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CameraAspectRatio fromFloat(float ar) {
|
||||||
|
if (ar < 0) {
|
||||||
|
throw new IllegalArgumentException("Invalid aspect ratio: " + ar);
|
||||||
|
}
|
||||||
|
return new CameraAspectRatio(ar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CameraAspectRatio fromFraction(int w, int h) {
|
||||||
|
if (w <= 0 || h <= 0) {
|
||||||
|
throw new IllegalArgumentException("Invalid aspect ratio: " + w + ":" + h);
|
||||||
|
}
|
||||||
|
return new CameraAspectRatio((float) w / h);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CameraAspectRatio sensorAspectRatio() {
|
||||||
|
return new CameraAspectRatio(SENSOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSensor() {
|
||||||
|
return ar == SENSOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getAspectRatio() {
|
||||||
|
return ar;
|
||||||
|
}
|
||||||
|
}
|
352
server/src/main/java/com/genymobile/scrcpy/CameraCapture.java
Normal file
352
server/src/main/java/com/genymobile/scrcpy/CameraCapture.java
Normal file
@ -0,0 +1,352 @@
|
|||||||
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
|
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.hardware.camera2.CameraAccessException;
|
||||||
|
import android.hardware.camera2.CameraCaptureSession;
|
||||||
|
import android.hardware.camera2.CameraCharacteristics;
|
||||||
|
import android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession;
|
||||||
|
import android.hardware.camera2.CameraDevice;
|
||||||
|
import android.hardware.camera2.CameraManager;
|
||||||
|
import android.hardware.camera2.CaptureFailure;
|
||||||
|
import android.hardware.camera2.CaptureRequest;
|
||||||
|
import android.hardware.camera2.params.OutputConfiguration;
|
||||||
|
import android.hardware.camera2.params.SessionConfiguration;
|
||||||
|
import android.hardware.camera2.params.StreamConfigurationMap;
|
||||||
|
import android.media.MediaCodec;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.HandlerThread;
|
||||||
|
import android.util.Range;
|
||||||
|
import android.view.Surface;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class CameraCapture extends SurfaceCapture {
|
||||||
|
|
||||||
|
private final String explicitCameraId;
|
||||||
|
private final CameraFacing cameraFacing;
|
||||||
|
private final Size explicitSize;
|
||||||
|
private int maxSize;
|
||||||
|
private final CameraAspectRatio aspectRatio;
|
||||||
|
private final int fps;
|
||||||
|
private final boolean highSpeed;
|
||||||
|
|
||||||
|
private String cameraId;
|
||||||
|
private Size size;
|
||||||
|
|
||||||
|
private HandlerThread cameraThread;
|
||||||
|
private Handler cameraHandler;
|
||||||
|
private CameraDevice cameraDevice;
|
||||||
|
private Executor cameraExecutor;
|
||||||
|
|
||||||
|
private final AtomicBoolean disconnected = new AtomicBoolean();
|
||||||
|
|
||||||
|
public CameraCapture(String explicitCameraId, CameraFacing cameraFacing, Size explicitSize, int maxSize, CameraAspectRatio aspectRatio, int fps,
|
||||||
|
boolean highSpeed) {
|
||||||
|
this.explicitCameraId = explicitCameraId;
|
||||||
|
this.cameraFacing = cameraFacing;
|
||||||
|
this.explicitSize = explicitSize;
|
||||||
|
this.maxSize = maxSize;
|
||||||
|
this.aspectRatio = aspectRatio;
|
||||||
|
this.fps = fps;
|
||||||
|
this.highSpeed = highSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws IOException {
|
||||||
|
cameraThread = new HandlerThread("camera");
|
||||||
|
cameraThread.start();
|
||||||
|
cameraHandler = new Handler(cameraThread.getLooper());
|
||||||
|
cameraExecutor = new HandlerExecutor(cameraHandler);
|
||||||
|
|
||||||
|
try {
|
||||||
|
cameraId = selectCamera(explicitCameraId, cameraFacing);
|
||||||
|
if (cameraId == null) {
|
||||||
|
throw new IOException("No matching camera found");
|
||||||
|
}
|
||||||
|
|
||||||
|
size = selectSize(cameraId, explicitSize, maxSize, aspectRatio, highSpeed);
|
||||||
|
if (size == null) {
|
||||||
|
throw new IOException("Could not select camera size");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ln.i("Using camera '" + cameraId + "'");
|
||||||
|
cameraDevice = openCamera(cameraId);
|
||||||
|
} catch (CameraAccessException | InterruptedException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String selectCamera(String explicitCameraId, CameraFacing cameraFacing) throws CameraAccessException {
|
||||||
|
if (explicitCameraId != null) {
|
||||||
|
return explicitCameraId;
|
||||||
|
}
|
||||||
|
|
||||||
|
CameraManager cameraManager = ServiceManager.getCameraManager();
|
||||||
|
|
||||||
|
String[] cameraIds = cameraManager.getCameraIdList();
|
||||||
|
if (cameraFacing == null) {
|
||||||
|
// Use the first one
|
||||||
|
return cameraIds.length > 0 ? cameraIds[0] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String cameraId : cameraIds) {
|
||||||
|
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
|
||||||
|
|
||||||
|
int facing = characteristics.get(CameraCharacteristics.LENS_FACING);
|
||||||
|
if (cameraFacing.value() == facing) {
|
||||||
|
return cameraId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not found
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.N)
|
||||||
|
private static Size selectSize(String cameraId, Size explicitSize, int maxSize, CameraAspectRatio aspectRatio, boolean highSpeed)
|
||||||
|
throws CameraAccessException {
|
||||||
|
if (explicitSize != null) {
|
||||||
|
return explicitSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
CameraManager cameraManager = ServiceManager.getCameraManager();
|
||||||
|
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
|
||||||
|
|
||||||
|
StreamConfigurationMap configs = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
|
||||||
|
android.util.Size[] sizes = highSpeed ? configs.getHighSpeedVideoSizes() : configs.getOutputSizes(MediaCodec.class);
|
||||||
|
Stream<android.util.Size> stream = Arrays.stream(sizes);
|
||||||
|
if (maxSize > 0) {
|
||||||
|
stream = stream.filter(it -> it.getWidth() <= maxSize && it.getHeight() <= maxSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
Float targetAspectRatio = resolveAspectRatio(aspectRatio, characteristics);
|
||||||
|
if (targetAspectRatio != null) {
|
||||||
|
stream = stream.filter(it -> {
|
||||||
|
float ar = ((float) it.getWidth() / it.getHeight());
|
||||||
|
float arRatio = ar / targetAspectRatio;
|
||||||
|
// Accept if the aspect ratio is the target aspect ratio + or - 10%
|
||||||
|
return arRatio >= 0.9f && arRatio <= 1.1f;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<android.util.Size> selected = stream.max((s1, s2) -> {
|
||||||
|
// Greater width is better
|
||||||
|
int cmp = Integer.compare(s1.getWidth(), s2.getWidth());
|
||||||
|
if (cmp != 0) {
|
||||||
|
return cmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetAspectRatio != null) {
|
||||||
|
// Closer to the target aspect ratio is better
|
||||||
|
float ar1 = ((float) s1.getWidth() / s1.getHeight());
|
||||||
|
float arRatio1 = ar1 / targetAspectRatio;
|
||||||
|
float distance1 = Math.abs(1 - arRatio1);
|
||||||
|
|
||||||
|
float ar2 = ((float) s2.getWidth() / s2.getHeight());
|
||||||
|
float arRatio2 = ar2 / targetAspectRatio;
|
||||||
|
float distance2 = Math.abs(1 - arRatio2);
|
||||||
|
|
||||||
|
// Reverse the order because lower distance is better
|
||||||
|
cmp = Float.compare(distance2, distance1);
|
||||||
|
if (cmp != 0) {
|
||||||
|
return cmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Greater height is better
|
||||||
|
return Integer.compare(s1.getHeight(), s2.getHeight());
|
||||||
|
});
|
||||||
|
|
||||||
|
if (selected.isPresent()) {
|
||||||
|
android.util.Size size = selected.get();
|
||||||
|
return new Size(size.getWidth(), size.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not found
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Float resolveAspectRatio(CameraAspectRatio ratio, CameraCharacteristics characteristics) {
|
||||||
|
if (ratio == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ratio.isSensor()) {
|
||||||
|
Rect activeSize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
|
||||||
|
return (float) activeSize.width() / activeSize.height();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ratio.getAspectRatio();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Surface surface) throws IOException {
|
||||||
|
try {
|
||||||
|
CameraCaptureSession session = createCaptureSession(cameraDevice, surface);
|
||||||
|
CaptureRequest request = createCaptureRequest(surface);
|
||||||
|
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 size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setMaxSize(int maxSize) {
|
||||||
|
if (explicitSize != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.maxSize = maxSize;
|
||||||
|
try {
|
||||||
|
size = selectSize(cameraId, null, maxSize, aspectRatio, highSpeed);
|
||||||
|
return size != null;
|
||||||
|
} catch (CameraAccessException e) {
|
||||||
|
Ln.w("Could not select camera size", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
|
@TargetApi(Build.VERSION_CODES.S)
|
||||||
|
private CameraDevice openCamera(String id) throws CameraAccessException, InterruptedException {
|
||||||
|
CompletableFuture<CameraDevice> future = new CompletableFuture<>();
|
||||||
|
ServiceManager.getCameraManager().openCamera(id, new CameraDevice.StateCallback() {
|
||||||
|
@Override
|
||||||
|
public void onOpened(CameraDevice camera) {
|
||||||
|
Ln.d("Camera opened successfully");
|
||||||
|
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 {
|
||||||
|
CompletableFuture<CameraCaptureSession> future = new CompletableFuture<>();
|
||||||
|
OutputConfiguration outputConfig = new OutputConfiguration(surface);
|
||||||
|
List<OutputConfiguration> outputs = Arrays.asList(outputConfig);
|
||||||
|
|
||||||
|
int sessionType = highSpeed ? SessionConfiguration.SESSION_HIGH_SPEED : SessionConfiguration.SESSION_REGULAR;
|
||||||
|
SessionConfiguration sessionConfig = new SessionConfiguration(sessionType, outputs, cameraExecutor,
|
||||||
|
new CameraCaptureSession.StateCallback() {
|
||||||
|
@Override
|
||||||
|
public void onConfigured(CameraCaptureSession session) {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CaptureRequest createCaptureRequest(Surface surface) throws CameraAccessException {
|
||||||
|
CaptureRequest.Builder requestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
|
||||||
|
requestBuilder.addTarget(surface);
|
||||||
|
|
||||||
|
if (fps > 0) {
|
||||||
|
requestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, new Range<>(fps, fps));
|
||||||
|
}
|
||||||
|
|
||||||
|
return requestBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.S)
|
||||||
|
private void setRepeatingRequest(CameraCaptureSession session, CaptureRequest request) throws CameraAccessException, InterruptedException {
|
||||||
|
CameraCaptureSession.CaptureCallback callback = new CameraCaptureSession.CaptureCallback() {
|
||||||
|
@Override
|
||||||
|
public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp, long frameNumber) {
|
||||||
|
// Called for each frame captured, do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure failure) {
|
||||||
|
Ln.w("Camera capture failed: frame " + failure.getFrameNumber());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (highSpeed) {
|
||||||
|
CameraConstrainedHighSpeedCaptureSession highSpeedSession = (CameraConstrainedHighSpeedCaptureSession) session;
|
||||||
|
List<CaptureRequest> requests = highSpeedSession.createHighSpeedRequestList(request);
|
||||||
|
highSpeedSession.setRepeatingBurst(requests, callback, cameraHandler);
|
||||||
|
} else {
|
||||||
|
session.setRepeatingRequest(request, callback, cameraHandler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClosed() {
|
||||||
|
return disconnected.get();
|
||||||
|
}
|
||||||
|
}
|
33
server/src/main/java/com/genymobile/scrcpy/CameraFacing.java
Normal file
33
server/src/main/java/com/genymobile/scrcpy/CameraFacing.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.hardware.camera2.CameraCharacteristics;
|
||||||
|
|
||||||
|
public enum CameraFacing {
|
||||||
|
FRONT("front", CameraCharacteristics.LENS_FACING_FRONT),
|
||||||
|
BACK("back", CameraCharacteristics.LENS_FACING_BACK),
|
||||||
|
@SuppressLint("InlinedApi") // introduced in API 23
|
||||||
|
EXTERNAL("external", CameraCharacteristics.LENS_FACING_EXTERNAL);
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
CameraFacing(String name, int value) {
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int value() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static CameraFacing findByName(String name) {
|
||||||
|
for (CameraFacing facing : CameraFacing.values()) {
|
||||||
|
if (name.equals(facing.name)) {
|
||||||
|
return facing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -64,8 +64,6 @@ public final class DesktopConnection implements Closeable {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
String socketName = getSocketName(scid);
|
String socketName = getSocketName(scid);
|
||||||
|
|
||||||
LocalSocket firstSocket = null;
|
|
||||||
|
|
||||||
LocalSocket videoSocket = null;
|
LocalSocket videoSocket = null;
|
||||||
LocalSocket audioSocket = null;
|
LocalSocket audioSocket = null;
|
||||||
LocalSocket controlSocket = null;
|
LocalSocket controlSocket = null;
|
||||||
@ -74,23 +72,27 @@ public final class DesktopConnection implements Closeable {
|
|||||||
try (LocalServerSocket localServerSocket = new LocalServerSocket(socketName)) {
|
try (LocalServerSocket localServerSocket = new LocalServerSocket(socketName)) {
|
||||||
if (video) {
|
if (video) {
|
||||||
videoSocket = localServerSocket.accept();
|
videoSocket = localServerSocket.accept();
|
||||||
firstSocket = videoSocket;
|
if (sendDummyByte) {
|
||||||
|
// send one byte so the client may read() to detect a connection error
|
||||||
|
videoSocket.getOutputStream().write(0);
|
||||||
|
sendDummyByte = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (audio) {
|
if (audio) {
|
||||||
audioSocket = localServerSocket.accept();
|
audioSocket = localServerSocket.accept();
|
||||||
if (firstSocket == null) {
|
if (sendDummyByte) {
|
||||||
firstSocket = audioSocket;
|
// send one byte so the client may read() to detect a connection error
|
||||||
|
audioSocket.getOutputStream().write(0);
|
||||||
|
sendDummyByte = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (control) {
|
if (control) {
|
||||||
controlSocket = localServerSocket.accept();
|
controlSocket = localServerSocket.accept();
|
||||||
if (firstSocket == null) {
|
|
||||||
firstSocket = controlSocket;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sendDummyByte) {
|
if (sendDummyByte) {
|
||||||
// send one byte so the client may read() to detect a connection error
|
// send one byte so the client may read() to detect a connection error
|
||||||
firstSocket.getOutputStream().write(0);
|
controlSocket.getOutputStream().write(0);
|
||||||
|
sendDummyByte = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -130,20 +132,29 @@ public final class DesktopConnection implements Closeable {
|
|||||||
return controlSocket;
|
return controlSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void shutdown() throws IOException {
|
||||||
if (videoSocket != null) {
|
if (videoSocket != null) {
|
||||||
videoSocket.shutdownInput();
|
videoSocket.shutdownInput();
|
||||||
videoSocket.shutdownOutput();
|
videoSocket.shutdownOutput();
|
||||||
videoSocket.close();
|
|
||||||
}
|
}
|
||||||
if (audioSocket != null) {
|
if (audioSocket != null) {
|
||||||
audioSocket.shutdownInput();
|
audioSocket.shutdownInput();
|
||||||
audioSocket.shutdownOutput();
|
audioSocket.shutdownOutput();
|
||||||
audioSocket.close();
|
|
||||||
}
|
}
|
||||||
if (controlSocket != null) {
|
if (controlSocket != null) {
|
||||||
controlSocket.shutdownInput();
|
controlSocket.shutdownInput();
|
||||||
controlSocket.shutdownOutput();
|
controlSocket.shutdownOutput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
if (videoSocket != null) {
|
||||||
|
videoSocket.close();
|
||||||
|
}
|
||||||
|
if (audioSocket != null) {
|
||||||
|
audioSocket.close();
|
||||||
|
}
|
||||||
|
if (controlSocket != null) {
|
||||||
controlSocket.close();
|
controlSocket.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,9 +99,15 @@ public final class Device {
|
|||||||
}
|
}
|
||||||
}, displayId);
|
}, displayId);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
ServiceManager.getWindowManager().registerDisplayFoldListener(new IDisplayFoldListener.Stub() {
|
ServiceManager.getWindowManager().registerDisplayFoldListener(new IDisplayFoldListener.Stub() {
|
||||||
@Override
|
@Override
|
||||||
public void onDisplayFoldChanged(int displayId, boolean folded) {
|
public void onDisplayFoldChanged(int displayId, boolean folded) {
|
||||||
|
if (Device.this.displayId != displayId) {
|
||||||
|
// Ignore events related to other display ids
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (Device.this) {
|
synchronized (Device.this) {
|
||||||
DisplayInfo displayInfo = ServiceManager.getDisplayManager().getDisplayInfo(displayId);
|
DisplayInfo displayInfo = ServiceManager.getDisplayManager().getDisplayInfo(displayId);
|
||||||
if (displayInfo == null) {
|
if (displayInfo == null) {
|
||||||
@ -118,6 +124,7 @@ public final class Device {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (options.getControl() && options.getClipboardAutosync()) {
|
if (options.getControl() && options.getClipboardAutosync()) {
|
||||||
// If control and autosync are enabled, synchronize Android clipboard to the computer automatically
|
// If control and autosync are enabled, synchronize Android clipboard to the computer automatically
|
||||||
|
@ -2,11 +2,11 @@ package com.genymobile.scrcpy;
|
|||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.AttributionSource;
|
import android.content.AttributionSource;
|
||||||
import android.content.ContextWrapper;
|
import android.content.MutableContextWrapper;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
|
||||||
public final class FakeContext extends ContextWrapper {
|
public final class FakeContext extends MutableContextWrapper {
|
||||||
|
|
||||||
public static final String PACKAGE_NAME = "com.android.shell";
|
public static final String PACKAGE_NAME = "com.android.shell";
|
||||||
public static final int ROOT_UID = 0; // Like android.os.Process.ROOT_UID, but before API 29
|
public static final int ROOT_UID = 0; // Like android.os.Process.ROOT_UID, but before API 29
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,11 @@ package com.genymobile.scrcpy;
|
|||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.FileDescriptor;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log both to Android logger (so that logs are visible in "adb logcat") and standard output/error (so that they are visible in the terminal
|
* Log both to Android logger (so that logs are visible in "adb logcat") and standard output/error (so that they are visible in the terminal
|
||||||
* directly).
|
* directly).
|
||||||
@ -11,6 +16,9 @@ public final class Ln {
|
|||||||
private static final String TAG = "scrcpy";
|
private static final String TAG = "scrcpy";
|
||||||
private static final String PREFIX = "[server] ";
|
private static final String PREFIX = "[server] ";
|
||||||
|
|
||||||
|
private static final PrintStream CONSOLE_OUT = new PrintStream(new FileOutputStream(FileDescriptor.out));
|
||||||
|
private static final PrintStream CONSOLE_ERR = new PrintStream(new FileOutputStream(FileDescriptor.err));
|
||||||
|
|
||||||
enum Level {
|
enum Level {
|
||||||
VERBOSE, DEBUG, INFO, WARN, ERROR
|
VERBOSE, DEBUG, INFO, WARN, ERROR
|
||||||
}
|
}
|
||||||
@ -21,6 +29,12 @@ public final class Ln {
|
|||||||
// not instantiable
|
// not instantiable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void disableSystemStreams() {
|
||||||
|
PrintStream nullStream = new PrintStream(new NullOutputStream());
|
||||||
|
System.setOut(nullStream);
|
||||||
|
System.setErr(nullStream);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the log level.
|
* Initialize the log level.
|
||||||
* <p>
|
* <p>
|
||||||
@ -39,30 +53,30 @@ public final class Ln {
|
|||||||
public static void v(String message) {
|
public static void v(String message) {
|
||||||
if (isEnabled(Level.VERBOSE)) {
|
if (isEnabled(Level.VERBOSE)) {
|
||||||
Log.v(TAG, message);
|
Log.v(TAG, message);
|
||||||
System.out.print(PREFIX + "VERBOSE: " + message + '\n');
|
CONSOLE_OUT.print(PREFIX + "VERBOSE: " + message + '\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void d(String message) {
|
public static void d(String message) {
|
||||||
if (isEnabled(Level.DEBUG)) {
|
if (isEnabled(Level.DEBUG)) {
|
||||||
Log.d(TAG, message);
|
Log.d(TAG, message);
|
||||||
System.out.print(PREFIX + "DEBUG: " + message + '\n');
|
CONSOLE_OUT.print(PREFIX + "DEBUG: " + message + '\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void i(String message) {
|
public static void i(String message) {
|
||||||
if (isEnabled(Level.INFO)) {
|
if (isEnabled(Level.INFO)) {
|
||||||
Log.i(TAG, message);
|
Log.i(TAG, message);
|
||||||
System.out.print(PREFIX + "INFO: " + message + '\n');
|
CONSOLE_OUT.print(PREFIX + "INFO: " + message + '\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void w(String message, Throwable throwable) {
|
public static void w(String message, Throwable throwable) {
|
||||||
if (isEnabled(Level.WARN)) {
|
if (isEnabled(Level.WARN)) {
|
||||||
Log.w(TAG, message, throwable);
|
Log.w(TAG, message, throwable);
|
||||||
System.err.print(PREFIX + "WARN: " + message + '\n');
|
CONSOLE_ERR.print(PREFIX + "WARN: " + message + '\n');
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace(CONSOLE_ERR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,9 +88,9 @@ public final class Ln {
|
|||||||
public static void e(String message, Throwable throwable) {
|
public static void e(String message, Throwable throwable) {
|
||||||
if (isEnabled(Level.ERROR)) {
|
if (isEnabled(Level.ERROR)) {
|
||||||
Log.e(TAG, message, throwable);
|
Log.e(TAG, message, throwable);
|
||||||
System.err.print(PREFIX + "ERROR: " + message + "\n");
|
CONSOLE_ERR.print(PREFIX + "ERROR: " + message + '\n');
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace(CONSOLE_ERR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,4 +98,21 @@ public final class Ln {
|
|||||||
public static void e(String message) {
|
public static void e(String message) {
|
||||||
e(message, null);
|
e(message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class NullOutputStream extends OutputStream {
|
||||||
|
@Override
|
||||||
|
public void write(byte[] b) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(byte[] b, int off, int len) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(int b) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,17 @@ package com.genymobile.scrcpy;
|
|||||||
import com.genymobile.scrcpy.wrappers.DisplayManager;
|
import com.genymobile.scrcpy.wrappers.DisplayManager;
|
||||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
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 android.util.Range;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
public final class LogUtils {
|
public final class LogUtils {
|
||||||
|
|
||||||
@ -47,7 +57,7 @@ public final class LogUtils {
|
|||||||
builder.append("\n (none)");
|
builder.append("\n (none)");
|
||||||
} else {
|
} else {
|
||||||
for (int id : displayIds) {
|
for (int id : displayIds) {
|
||||||
builder.append("\n --display=").append(id).append(" (");
|
builder.append("\n --display-id=").append(id).append(" (");
|
||||||
DisplayInfo displayInfo = displayManager.getDisplayInfo(id);
|
DisplayInfo displayInfo = displayManager.getDisplayInfo(id);
|
||||||
if (displayInfo != null) {
|
if (displayInfo != null) {
|
||||||
Size size = displayInfo.getSize();
|
Size size = displayInfo.getSize();
|
||||||
@ -60,4 +70,75 @@ public final class LogUtils {
|
|||||||
}
|
}
|
||||||
return builder.toString();
|
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-id=").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()).append(", ");
|
||||||
|
|
||||||
|
// Capture frame rates for low-FPS mode are the same for every resolution
|
||||||
|
Range<Integer>[] lowFpsRanges = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
|
||||||
|
SortedSet<Integer> uniqueLowFps = getUniqueSet(lowFpsRanges);
|
||||||
|
builder.append("fps=").append(uniqueLowFps).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());
|
||||||
|
}
|
||||||
|
|
||||||
|
android.util.Size[] highSpeedSizes = configs.getHighSpeedVideoSizes();
|
||||||
|
if (highSpeedSizes.length > 0) {
|
||||||
|
builder.append("\n High speed capture (--camera-high-speed):");
|
||||||
|
for (android.util.Size size : highSpeedSizes) {
|
||||||
|
Range<Integer>[] highFpsRanges = configs.getHighSpeedVideoFpsRanges();
|
||||||
|
SortedSet<Integer> uniqueHighFps = getUniqueSet(highFpsRanges);
|
||||||
|
builder.append("\n - ").append(size.getWidth()).append("x").append(size.getHeight());
|
||||||
|
builder.append(" (fps=").append(uniqueHighFps).append(')');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (CameraAccessException e) {
|
||||||
|
builder.append("\n (access denied)");
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SortedSet<Integer> getUniqueSet(Range<Integer>[] ranges) {
|
||||||
|
SortedSet<Integer> set = new TreeSet<>();
|
||||||
|
for (Range<Integer> range : ranges) {
|
||||||
|
set.add(range.getUpper());
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ public class Options {
|
|||||||
private int maxSize;
|
private int maxSize;
|
||||||
private VideoCodec videoCodec = VideoCodec.H264;
|
private VideoCodec videoCodec = VideoCodec.H264;
|
||||||
private AudioCodec audioCodec = AudioCodec.OPUS;
|
private AudioCodec audioCodec = AudioCodec.OPUS;
|
||||||
|
private VideoSource videoSource = VideoSource.DISPLAY;
|
||||||
private AudioSource audioSource = AudioSource.OUTPUT;
|
private AudioSource audioSource = AudioSource.OUTPUT;
|
||||||
private int videoBitRate = 8000000;
|
private int videoBitRate = 8000000;
|
||||||
private int audioBitRate = 128000;
|
private int audioBitRate = 128000;
|
||||||
@ -23,6 +24,12 @@ public class Options {
|
|||||||
private Rect crop;
|
private Rect crop;
|
||||||
private boolean control = true;
|
private boolean control = true;
|
||||||
private int displayId;
|
private int displayId;
|
||||||
|
private String cameraId;
|
||||||
|
private Size cameraSize;
|
||||||
|
private CameraFacing cameraFacing;
|
||||||
|
private CameraAspectRatio cameraAspectRatio;
|
||||||
|
private int cameraFps;
|
||||||
|
private boolean cameraHighSpeed;
|
||||||
private boolean showTouches;
|
private boolean showTouches;
|
||||||
private boolean stayAwake;
|
private boolean stayAwake;
|
||||||
private List<CodecOption> videoCodecOptions;
|
private List<CodecOption> videoCodecOptions;
|
||||||
@ -38,6 +45,8 @@ public class Options {
|
|||||||
|
|
||||||
private boolean listEncoders;
|
private boolean listEncoders;
|
||||||
private boolean listDisplays;
|
private boolean listDisplays;
|
||||||
|
private boolean listCameras;
|
||||||
|
private boolean listCameraSizes;
|
||||||
|
|
||||||
// Options not used by the scrcpy client, but useful to use scrcpy-server directly
|
// Options not used by the scrcpy client, but useful to use scrcpy-server directly
|
||||||
private boolean sendDeviceMeta = true; // send device name and size
|
private boolean sendDeviceMeta = true; // send device name and size
|
||||||
@ -73,6 +82,10 @@ public class Options {
|
|||||||
return audioCodec;
|
return audioCodec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VideoSource getVideoSource() {
|
||||||
|
return videoSource;
|
||||||
|
}
|
||||||
|
|
||||||
public AudioSource getAudioSource() {
|
public AudioSource getAudioSource() {
|
||||||
return audioSource;
|
return audioSource;
|
||||||
}
|
}
|
||||||
@ -109,6 +122,30 @@ public class Options {
|
|||||||
return displayId;
|
return displayId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCameraId() {
|
||||||
|
return cameraId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Size getCameraSize() {
|
||||||
|
return cameraSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CameraFacing getCameraFacing() {
|
||||||
|
return cameraFacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CameraAspectRatio getCameraAspectRatio() {
|
||||||
|
return cameraAspectRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCameraFps() {
|
||||||
|
return cameraFps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getCameraHighSpeed() {
|
||||||
|
return cameraHighSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean getShowTouches() {
|
public boolean getShowTouches() {
|
||||||
return showTouches;
|
return showTouches;
|
||||||
}
|
}
|
||||||
@ -153,6 +190,10 @@ public class Options {
|
|||||||
return powerOn;
|
return powerOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getList() {
|
||||||
|
return listEncoders || listDisplays || listCameras || listCameraSizes;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean getListEncoders() {
|
public boolean getListEncoders() {
|
||||||
return listEncoders;
|
return listEncoders;
|
||||||
}
|
}
|
||||||
@ -161,6 +202,14 @@ public class Options {
|
|||||||
return listDisplays;
|
return listDisplays;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getListCameras() {
|
||||||
|
return listCameras;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getListCameraSizes() {
|
||||||
|
return listCameraSizes;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean getSendDeviceMeta() {
|
public boolean getSendDeviceMeta() {
|
||||||
return sendDeviceMeta;
|
return sendDeviceMeta;
|
||||||
}
|
}
|
||||||
@ -230,6 +279,13 @@ public class Options {
|
|||||||
}
|
}
|
||||||
options.audioCodec = audioCodec;
|
options.audioCodec = audioCodec;
|
||||||
break;
|
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":
|
case "audio_source":
|
||||||
AudioSource audioSource = AudioSource.findByName(value);
|
AudioSource audioSource = AudioSource.findByName(value);
|
||||||
if (audioSource == null) {
|
if (audioSource == null) {
|
||||||
@ -256,7 +312,9 @@ public class Options {
|
|||||||
options.tunnelForward = Boolean.parseBoolean(value);
|
options.tunnelForward = Boolean.parseBoolean(value);
|
||||||
break;
|
break;
|
||||||
case "crop":
|
case "crop":
|
||||||
|
if (!value.isEmpty()) {
|
||||||
options.crop = parseCrop(value);
|
options.crop = parseCrop(value);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "control":
|
case "control":
|
||||||
options.control = Boolean.parseBoolean(value);
|
options.control = Boolean.parseBoolean(value);
|
||||||
@ -306,6 +364,42 @@ public class Options {
|
|||||||
case "list_displays":
|
case "list_displays":
|
||||||
options.listDisplays = Boolean.parseBoolean(value);
|
options.listDisplays = Boolean.parseBoolean(value);
|
||||||
break;
|
break;
|
||||||
|
case "list_cameras":
|
||||||
|
options.listCameras = Boolean.parseBoolean(value);
|
||||||
|
break;
|
||||||
|
case "list_camera_sizes":
|
||||||
|
options.listCameraSizes = Boolean.parseBoolean(value);
|
||||||
|
break;
|
||||||
|
case "camera_id":
|
||||||
|
if (!value.isEmpty()) {
|
||||||
|
options.cameraId = value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "camera_size":
|
||||||
|
if (!value.isEmpty()) {
|
||||||
|
options.cameraSize = parseSize(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "camera_facing":
|
||||||
|
if (!value.isEmpty()) {
|
||||||
|
CameraFacing facing = CameraFacing.findByName(value);
|
||||||
|
if (facing == null) {
|
||||||
|
throw new IllegalArgumentException("Camera facing " + value + " not supported");
|
||||||
|
}
|
||||||
|
options.cameraFacing = facing;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "camera_ar":
|
||||||
|
if (!value.isEmpty()) {
|
||||||
|
options.cameraAspectRatio = parseCameraAspectRatio(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "camera_fps":
|
||||||
|
options.cameraFps = Integer.parseInt(value);
|
||||||
|
break;
|
||||||
|
case "camera_high_speed":
|
||||||
|
options.cameraHighSpeed = Boolean.parseBoolean(value);
|
||||||
|
break;
|
||||||
case "send_device_meta":
|
case "send_device_meta":
|
||||||
options.sendDeviceMeta = Boolean.parseBoolean(value);
|
options.sendDeviceMeta = Boolean.parseBoolean(value);
|
||||||
break;
|
break;
|
||||||
@ -337,9 +431,6 @@ public class Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Rect parseCrop(String crop) {
|
private static Rect parseCrop(String crop) {
|
||||||
if (crop.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// input format: "width:height:x:y"
|
// input format: "width:height:x:y"
|
||||||
String[] tokens = crop.split(":");
|
String[] tokens = crop.split(":");
|
||||||
if (tokens.length != 4) {
|
if (tokens.length != 4) {
|
||||||
@ -351,4 +442,31 @@ public class Options {
|
|||||||
int y = Integer.parseInt(tokens[3]);
|
int y = Integer.parseInt(tokens[3]);
|
||||||
return new Rect(x, y, x + width, y + height);
|
return new Rect(x, y, x + width, y + height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Size parseSize(String size) {
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CameraAspectRatio parseCameraAspectRatio(String ar) {
|
||||||
|
if ("sensor".equals(ar)) {
|
||||||
|
return CameraAspectRatio.sensorAspectRatio();
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] tokens = ar.split(":");
|
||||||
|
if (tokens.length == 2) {
|
||||||
|
int w = Integer.parseInt(tokens[0]);
|
||||||
|
int h = Integer.parseInt(tokens[1]);
|
||||||
|
return CameraAspectRatio.fromFraction(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
float floatAr = Float.parseFloat(tokens[0]);
|
||||||
|
return CameraAspectRatio.fromFloat(floatAr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,84 @@
|
|||||||
|
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 maxSize) {
|
||||||
|
device.setMaxSize(maxSize);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -87,7 +87,11 @@ public final class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void scrcpy(Options options) throws IOException, ConfigurationException {
|
private static void scrcpy(Options options) throws IOException, ConfigurationException {
|
||||||
Ln.i("Device: [" + Build.MANUFACTURER + "] " + Build.BRAND + " " + Build.MODEL + " (Android " + Build.VERSION.RELEASE + ")");
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S && options.getVideoSource() == VideoSource.CAMERA) {
|
||||||
|
Ln.e("Camera mirroring is not supported before Android 12");
|
||||||
|
throw new ConfigurationException("Camera mirroring is not supported");
|
||||||
|
}
|
||||||
|
|
||||||
final Device device = new Device(options);
|
final Device device = new Device(options);
|
||||||
|
|
||||||
Thread initThread = startInitThread(options);
|
Thread initThread = startInitThread(options);
|
||||||
@ -98,27 +102,9 @@ public final class Server {
|
|||||||
boolean video = options.getVideo();
|
boolean video = options.getVideo();
|
||||||
boolean audio = options.getAudio();
|
boolean audio = options.getAudio();
|
||||||
boolean sendDummyByte = options.getSendDummyByte();
|
boolean sendDummyByte = options.getSendDummyByte();
|
||||||
|
boolean camera = options.getVideoSource() == VideoSource.CAMERA;
|
||||||
|
|
||||||
Workarounds.prepareMainLooper();
|
Workarounds.apply(audio, camera);
|
||||||
|
|
||||||
// Workarounds must be applied for Meizu phones:
|
|
||||||
// - <https://github.com/Genymobile/scrcpy/issues/240>
|
|
||||||
// - <https://github.com/Genymobile/scrcpy/issues/365>
|
|
||||||
// - <https://github.com/Genymobile/scrcpy/issues/2656>
|
|
||||||
//
|
|
||||||
// But only apply when strictly necessary, since workarounds can cause other issues:
|
|
||||||
// - <https://github.com/Genymobile/scrcpy/issues/940>
|
|
||||||
// - <https://github.com/Genymobile/scrcpy/issues/994>
|
|
||||||
if (Build.BRAND.equalsIgnoreCase("meizu")) {
|
|
||||||
Workarounds.fillAppInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Before Android 11, audio is not supported.
|
|
||||||
// Since Android 12, we can properly set a context on the AudioRecord.
|
|
||||||
// Only on Android 11 we must fill the application context for the AudioRecord to work.
|
|
||||||
if (audio && Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
|
|
||||||
Workarounds.fillAppContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<AsyncProcessor> asyncProcessors = new ArrayList<>();
|
List<AsyncProcessor> asyncProcessors = new ArrayList<>();
|
||||||
|
|
||||||
@ -151,9 +137,16 @@ public final class Server {
|
|||||||
if (video) {
|
if (video) {
|
||||||
Streamer videoStreamer = new Streamer(connection.getVideoFd(), options.getVideoCodec(), options.getSendCodecMeta(),
|
Streamer videoStreamer = new Streamer(connection.getVideoFd(), options.getVideoCodec(), options.getSendCodecMeta(),
|
||||||
options.getSendFrameMeta());
|
options.getSendFrameMeta());
|
||||||
ScreenEncoder screenEncoder = new ScreenEncoder(device, videoStreamer, options.getVideoBitRate(), options.getMaxFps(),
|
SurfaceCapture surfaceCapture;
|
||||||
|
if (options.getVideoSource() == VideoSource.DISPLAY) {
|
||||||
|
surfaceCapture = new ScreenCapture(device);
|
||||||
|
} else {
|
||||||
|
surfaceCapture = new CameraCapture(options.getCameraId(), options.getCameraFacing(), options.getCameraSize(),
|
||||||
|
options.getMaxSize(), options.getCameraAspectRatio(), options.getCameraFps(), options.getCameraHighSpeed());
|
||||||
|
}
|
||||||
|
SurfaceEncoder surfaceEncoder = new SurfaceEncoder(surfaceCapture, videoStreamer, options.getVideoBitRate(), options.getMaxFps(),
|
||||||
options.getVideoCodecOptions(), options.getVideoEncoder(), options.getDownsizeOnError());
|
options.getVideoCodecOptions(), options.getVideoEncoder(), options.getDownsizeOnError());
|
||||||
asyncProcessors.add(screenEncoder);
|
asyncProcessors.add(surfaceEncoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
Completion completion = new Completion(asyncProcessors.size());
|
Completion completion = new Completion(asyncProcessors.size());
|
||||||
@ -170,6 +163,8 @@ public final class Server {
|
|||||||
asyncProcessor.stop();
|
asyncProcessor.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connection.shutdown();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
initThread.join();
|
initThread.join();
|
||||||
for (AsyncProcessor asyncProcessor : asyncProcessors) {
|
for (AsyncProcessor asyncProcessor : asyncProcessors) {
|
||||||
@ -189,16 +184,34 @@ public final class Server {
|
|||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) {
|
||||||
|
int status = 0;
|
||||||
|
try {
|
||||||
|
internalMain(args);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
Ln.e(t.getMessage(), t);
|
||||||
|
status = 1;
|
||||||
|
} finally {
|
||||||
|
// By default, the Java process exits when all non-daemon threads are terminated.
|
||||||
|
// The Android SDK might start some non-daemon threads internally, preventing the scrcpy server to exit.
|
||||||
|
// So force the process to exit explicitly.
|
||||||
|
System.exit(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void internalMain(String... args) throws Exception {
|
||||||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
|
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
|
||||||
Ln.e("Exception on thread " + t, e);
|
Ln.e("Exception on thread " + t, e);
|
||||||
});
|
});
|
||||||
|
|
||||||
Options options = Options.parse(args);
|
Options options = Options.parse(args);
|
||||||
|
|
||||||
|
Ln.disableSystemStreams();
|
||||||
Ln.initLogLevel(options.getLogLevel());
|
Ln.initLogLevel(options.getLogLevel());
|
||||||
|
|
||||||
if (options.getListEncoders() || options.getListDisplays()) {
|
Ln.i("Device: [" + Build.MANUFACTURER + "] " + Build.BRAND + " " + Build.MODEL + " (Android " + Build.VERSION.RELEASE + ")");
|
||||||
|
|
||||||
|
if (options.getList()) {
|
||||||
if (options.getCleanup()) {
|
if (options.getCleanup()) {
|
||||||
CleanUp.unlinkSelf();
|
CleanUp.unlinkSelf();
|
||||||
}
|
}
|
||||||
@ -210,6 +223,10 @@ public final class Server {
|
|||||||
if (options.getListDisplays()) {
|
if (options.getListDisplays()) {
|
||||||
Ln.i(LogUtils.buildDisplayListMessage());
|
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
|
// Just print the requested data, do not mirror
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
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 maxSize Maximum size
|
||||||
|
*/
|
||||||
|
public abstract boolean setMaxSize(int maxSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,13 +1,9 @@
|
|||||||
package com.genymobile.scrcpy;
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
import com.genymobile.scrcpy.wrappers.SurfaceControl;
|
|
||||||
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.media.MediaCodec;
|
import android.media.MediaCodec;
|
||||||
import android.media.MediaCodecInfo;
|
import android.media.MediaCodecInfo;
|
||||||
import android.media.MediaFormat;
|
import android.media.MediaFormat;
|
||||||
import android.os.Build;
|
import android.os.Looper;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
|
||||||
@ -16,7 +12,7 @@ import java.nio.ByteBuffer;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class ScreenEncoder implements Device.RotationListener, Device.FoldListener, AsyncProcessor {
|
public class SurfaceEncoder implements AsyncProcessor {
|
||||||
|
|
||||||
private static final int DEFAULT_I_FRAME_INTERVAL = 10; // seconds
|
private static final int DEFAULT_I_FRAME_INTERVAL = 10; // seconds
|
||||||
private static final int REPEAT_FRAME_DELAY_US = 100_000; // repeat after 100ms
|
private static final int REPEAT_FRAME_DELAY_US = 100_000; // repeat after 100ms
|
||||||
@ -26,9 +22,7 @@ public class ScreenEncoder implements Device.RotationListener, Device.FoldListen
|
|||||||
private static final int[] MAX_SIZE_FALLBACK = {2560, 1920, 1600, 1280, 1024, 800};
|
private static final int[] MAX_SIZE_FALLBACK = {2560, 1920, 1600, 1280, 1024, 800};
|
||||||
private static final int MAX_CONSECUTIVE_ERRORS = 3;
|
private static final int MAX_CONSECUTIVE_ERRORS = 3;
|
||||||
|
|
||||||
private final AtomicBoolean resetCapture = new AtomicBoolean();
|
private final SurfaceCapture capture;
|
||||||
|
|
||||||
private final Device device;
|
|
||||||
private final Streamer streamer;
|
private final Streamer streamer;
|
||||||
private final String encoderName;
|
private final String encoderName;
|
||||||
private final List<CodecOption> codecOptions;
|
private final List<CodecOption> codecOptions;
|
||||||
@ -42,9 +36,9 @@ public class ScreenEncoder implements Device.RotationListener, Device.FoldListen
|
|||||||
private Thread thread;
|
private Thread thread;
|
||||||
private final AtomicBoolean stopped = new AtomicBoolean();
|
private final AtomicBoolean stopped = new AtomicBoolean();
|
||||||
|
|
||||||
public ScreenEncoder(Device device, Streamer streamer, int videoBitRate, int maxFps, List<CodecOption> codecOptions, String encoderName,
|
public SurfaceEncoder(SurfaceCapture capture, Streamer streamer, int videoBitRate, int maxFps, List<CodecOption> codecOptions, String encoderName,
|
||||||
boolean downsizeOnError) {
|
boolean downsizeOnError) {
|
||||||
this.device = device;
|
this.capture = capture;
|
||||||
this.streamer = streamer;
|
this.streamer = streamer;
|
||||||
this.videoBitRate = videoBitRate;
|
this.videoBitRate = videoBitRate;
|
||||||
this.maxFps = maxFps;
|
this.maxFps = maxFps;
|
||||||
@ -53,51 +47,29 @@ public class ScreenEncoder implements Device.RotationListener, Device.FoldListen
|
|||||||
this.downsizeOnError = downsizeOnError;
|
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 {
|
private void streamScreen() throws IOException, ConfigurationException {
|
||||||
Codec codec = streamer.getCodec();
|
Codec codec = streamer.getCodec();
|
||||||
MediaCodec mediaCodec = createMediaCodec(codec, encoderName);
|
MediaCodec mediaCodec = createMediaCodec(codec, encoderName);
|
||||||
MediaFormat format = createFormat(codec.getMimeType(), videoBitRate, maxFps, codecOptions);
|
MediaFormat format = createFormat(codec.getMimeType(), videoBitRate, maxFps, codecOptions);
|
||||||
IBinder display = createDisplay();
|
|
||||||
device.setRotationListener(this);
|
|
||||||
device.setFoldListener(this);
|
|
||||||
|
|
||||||
streamer.writeVideoHeader(device.getScreenInfo().getVideoSize());
|
capture.init();
|
||||||
|
|
||||||
|
try {
|
||||||
|
streamer.writeVideoHeader(capture.getSize());
|
||||||
|
|
||||||
boolean alive;
|
boolean alive;
|
||||||
try {
|
|
||||||
do {
|
|
||||||
ScreenInfo screenInfo = device.getScreenInfo();
|
|
||||||
Rect contentRect = screenInfo.getContentRect();
|
|
||||||
|
|
||||||
// include the locked video orientation
|
do {
|
||||||
Rect videoRect = screenInfo.getVideoSize().toRect();
|
Size size = capture.getSize();
|
||||||
format.setInteger(MediaFormat.KEY_WIDTH, videoRect.width());
|
format.setInteger(MediaFormat.KEY_WIDTH, size.getWidth());
|
||||||
format.setInteger(MediaFormat.KEY_HEIGHT, videoRect.height());
|
format.setInteger(MediaFormat.KEY_HEIGHT, size.getHeight());
|
||||||
|
|
||||||
Surface surface = null;
|
Surface surface = null;
|
||||||
try {
|
try {
|
||||||
mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
|
mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
|
||||||
surface = mediaCodec.createInputSurface();
|
surface = mediaCodec.createInputSurface();
|
||||||
|
|
||||||
// does not include the locked video orientation
|
capture.start(surface);
|
||||||
Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
|
|
||||||
int videoRotation = screenInfo.getVideoRotation();
|
|
||||||
int layerStack = device.getLayerStack();
|
|
||||||
setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
|
|
||||||
|
|
||||||
mediaCodec.start();
|
mediaCodec.start();
|
||||||
|
|
||||||
@ -106,7 +78,7 @@ public class ScreenEncoder implements Device.RotationListener, Device.FoldListen
|
|||||||
mediaCodec.stop();
|
mediaCodec.stop();
|
||||||
} catch (IllegalStateException | IllegalArgumentException e) {
|
} catch (IllegalStateException | IllegalArgumentException e) {
|
||||||
Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage());
|
Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage());
|
||||||
if (!prepareRetry(device, screenInfo)) {
|
if (!prepareRetry(size)) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
Ln.i("Retrying...");
|
Ln.i("Retrying...");
|
||||||
@ -120,13 +92,11 @@ public class ScreenEncoder implements Device.RotationListener, Device.FoldListen
|
|||||||
} while (alive);
|
} while (alive);
|
||||||
} finally {
|
} finally {
|
||||||
mediaCodec.release();
|
mediaCodec.release();
|
||||||
device.setRotationListener(null);
|
capture.release();
|
||||||
device.setFoldListener(null);
|
|
||||||
SurfaceControl.destroyDisplay(display);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean prepareRetry(Device device, ScreenInfo screenInfo) {
|
private boolean prepareRetry(Size currentSize) {
|
||||||
if (firstFrameSent) {
|
if (firstFrameSent) {
|
||||||
++consecutiveErrors;
|
++consecutiveErrors;
|
||||||
if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) {
|
if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) {
|
||||||
@ -146,16 +116,19 @@ public class ScreenEncoder implements Device.RotationListener, Device.FoldListen
|
|||||||
|
|
||||||
// Downsizing on error is only enabled if an encoding failure occurs before the first frame (downsizing later could be surprising)
|
// Downsizing on error is only enabled if an encoding failure occurs before the first frame (downsizing later could be surprising)
|
||||||
|
|
||||||
int newMaxSize = chooseMaxSizeFallback(screenInfo.getVideoSize());
|
int newMaxSize = chooseMaxSizeFallback(currentSize);
|
||||||
Ln.i("newMaxSize = " + newMaxSize);
|
|
||||||
if (newMaxSize == 0) {
|
if (newMaxSize == 0) {
|
||||||
// Must definitively fail
|
// Must definitively fail
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retry with a smaller device size
|
boolean accepted = capture.setMaxSize(newMaxSize);
|
||||||
|
if (!accepted) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retry with a smaller size
|
||||||
Ln.i("Retrying with -m" + newMaxSize + "...");
|
Ln.i("Retrying with -m" + newMaxSize + "...");
|
||||||
device.setMaxSize(newMaxSize);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,14 +149,14 @@ public class ScreenEncoder implements Device.RotationListener, Device.FoldListen
|
|||||||
boolean alive = true;
|
boolean alive = true;
|
||||||
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
||||||
|
|
||||||
while (!consumeResetCapture() && !eof) {
|
while (!capture.consumeReset() && !eof) {
|
||||||
if (stopped.get()) {
|
if (stopped.get()) {
|
||||||
alive = false;
|
alive = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int outputBufferId = codec.dequeueOutputBuffer(bufferInfo, -1);
|
int outputBufferId = codec.dequeueOutputBuffer(bufferInfo, -1);
|
||||||
try {
|
try {
|
||||||
if (consumeResetCapture()) {
|
if (capture.consumeReset()) {
|
||||||
// must restart encoding with new size
|
// must restart encoding with new size
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -208,6 +181,11 @@ public class ScreenEncoder implements Device.RotationListener, Device.FoldListen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (capture.isClosed()) {
|
||||||
|
// The capture might have been closed internally (for example if the camera is disconnected)
|
||||||
|
alive = false;
|
||||||
|
}
|
||||||
|
|
||||||
return !eof && alive;
|
return !eof && alive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,28 +242,13 @@ public class ScreenEncoder implements Device.RotationListener, Device.FoldListen
|
|||||||
return format;
|
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
|
@Override
|
||||||
public void start(TerminationListener listener) {
|
public void start(TerminationListener listener) {
|
||||||
thread = new Thread(() -> {
|
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 {
|
try {
|
||||||
streamScreen();
|
streamScreen();
|
||||||
} catch (ConfigurationException e) {
|
} catch (ConfigurationException e) {
|
@ -6,7 +6,7 @@ import android.media.MediaFormat;
|
|||||||
public enum VideoCodec implements Codec {
|
public enum VideoCodec implements Codec {
|
||||||
H264(0x68_32_36_34, "h264", MediaFormat.MIMETYPE_VIDEO_AVC),
|
H264(0x68_32_36_34, "h264", MediaFormat.MIMETYPE_VIDEO_AVC),
|
||||||
H265(0x68_32_36_35, "h265", MediaFormat.MIMETYPE_VIDEO_HEVC),
|
H265(0x68_32_36_35, "h265", MediaFormat.MIMETYPE_VIDEO_HEVC),
|
||||||
@SuppressLint("InlinedApi") // introduced in API 21
|
@SuppressLint("InlinedApi") // introduced in API 29
|
||||||
AV1(0x00_61_76_31, "av1", MediaFormat.MIMETYPE_VIDEO_AV1);
|
AV1(0x00_61_76_31, "av1", MediaFormat.MIMETYPE_VIDEO_AV1);
|
||||||
|
|
||||||
private final int id; // 4-byte ASCII representation of the name
|
private final int id; // 4-byte ASCII representation of the name
|
||||||
|
22
server/src/main/java/com/genymobile/scrcpy/VideoSource.java
Normal file
22
server/src/main/java/com/genymobile/scrcpy/VideoSource.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
|
|||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.AttributionSource;
|
import android.content.AttributionSource;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.media.AudioAttributes;
|
import android.media.AudioAttributes;
|
||||||
@ -27,8 +28,60 @@ public final class Workarounds {
|
|||||||
// not instantiable
|
// not instantiable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void apply(boolean audio, boolean camera) {
|
||||||
|
Workarounds.prepareMainLooper();
|
||||||
|
|
||||||
|
boolean mustFillAppInfo = false;
|
||||||
|
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>
|
||||||
|
// - <https://github.com/Genymobile/scrcpy/issues/365>
|
||||||
|
// - <https://github.com/Genymobile/scrcpy/issues/2656>
|
||||||
|
//
|
||||||
|
// But only apply when strictly necessary, since workarounds can cause other issues:
|
||||||
|
// - <https://github.com/Genymobile/scrcpy/issues/940>
|
||||||
|
// - <https://github.com/Genymobile/scrcpy/issues/994>
|
||||||
|
mustFillAppInfo = true;
|
||||||
|
} else if (Build.BRAND.equalsIgnoreCase("honor")) {
|
||||||
|
// More workarounds must be applied for Honor devices:
|
||||||
|
// - <https://github.com/Genymobile/scrcpy/issues/4015>
|
||||||
|
//
|
||||||
|
// The system context must not be set for all devices, because it would cause other problems:
|
||||||
|
// - <https://github.com/Genymobile/scrcpy/issues/4015#issuecomment-1595382142>
|
||||||
|
// - <https://github.com/Genymobile/scrcpy/issues/3805#issuecomment-1596148031>
|
||||||
|
mustFillAppInfo = true;
|
||||||
|
mustFillBaseContext = true;
|
||||||
|
mustFillAppContext = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (audio && Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
|
||||||
|
// Before Android 11, audio is not supported.
|
||||||
|
// Since Android 12, we can properly set a context on the AudioRecord.
|
||||||
|
// Only on Android 11 we must fill the application context for the AudioRecord to work.
|
||||||
|
mustFillAppContext = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (camera) {
|
||||||
|
mustFillAppInfo = true;
|
||||||
|
mustFillBaseContext = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mustFillAppInfo) {
|
||||||
|
Workarounds.fillAppInfo();
|
||||||
|
}
|
||||||
|
if (mustFillBaseContext) {
|
||||||
|
Workarounds.fillBaseContext();
|
||||||
|
}
|
||||||
|
if (mustFillAppContext) {
|
||||||
|
Workarounds.fillAppContext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static void prepareMainLooper() {
|
private static void prepareMainLooper() {
|
||||||
// Some devices internally create a Handler when creating an input Surface, causing an exception:
|
// Some devices internally create a Handler when creating an input Surface, causing an exception:
|
||||||
// "Can't create handler inside thread that has not called Looper.prepare()"
|
// "Can't create handler inside thread that has not called Looper.prepare()"
|
||||||
// <https://github.com/Genymobile/scrcpy/issues/240>
|
// <https://github.com/Genymobile/scrcpy/issues/240>
|
||||||
@ -57,7 +110,7 @@ public final class Workarounds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
|
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
|
||||||
public static void fillAppInfo() {
|
private static void fillAppInfo() {
|
||||||
try {
|
try {
|
||||||
fillActivityThread();
|
fillActivityThread();
|
||||||
|
|
||||||
@ -86,7 +139,7 @@ public final class Workarounds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
|
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
|
||||||
public static void fillAppContext() {
|
private static void fillAppContext() {
|
||||||
try {
|
try {
|
||||||
fillActivityThread();
|
fillActivityThread();
|
||||||
|
|
||||||
@ -105,6 +158,19 @@ public final class Workarounds {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void fillBaseContext() {
|
||||||
|
try {
|
||||||
|
fillActivityThread();
|
||||||
|
|
||||||
|
Method getSystemContextMethod = activityThreadClass.getDeclaredMethod("getSystemContext");
|
||||||
|
Context context = (Context) getSystemContextMethod.invoke(activityThread);
|
||||||
|
FakeContext.get().setBaseContext(context);
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
// this is a workaround, so failing is not an error
|
||||||
|
Ln.d("Could not fill base context: " + throwable.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.R)
|
@TargetApi(Build.VERSION_CODES.R)
|
||||||
@SuppressLint("WrongConstant,MissingPermission,BlockedPrivateApi,SoonBlockedPrivateApi,DiscouragedPrivateApi")
|
@SuppressLint("WrongConstant,MissingPermission,BlockedPrivateApi,SoonBlockedPrivateApi,DiscouragedPrivateApi")
|
||||||
public static AudioRecord createAudioRecord(int source, int sampleRate, int channelConfig, int channels, int channelMask, int encoding) {
|
public static AudioRecord createAudioRecord(int source, int sampleRate, int channelConfig, int channels, int channelMask, int encoding) {
|
||||||
|
@ -17,7 +17,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
|
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
|
||||||
public class ActivityManager {
|
public final class ActivityManager {
|
||||||
|
|
||||||
private final IInterface manager;
|
private final IInterface manager;
|
||||||
private Method getContentProviderExternalMethod;
|
private Method getContentProviderExternalMethod;
|
||||||
|
@ -11,7 +11,7 @@ import android.os.IInterface;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class ClipboardManager {
|
public final class ClipboardManager {
|
||||||
private final IInterface manager;
|
private final IInterface manager;
|
||||||
private Method getPrimaryClipMethod;
|
private Method getPrimaryClipMethod;
|
||||||
private Method setPrimaryClipMethod;
|
private Method setPrimaryClipMethod;
|
||||||
|
@ -14,7 +14,7 @@ import java.io.Closeable;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class ContentProvider implements Closeable {
|
public final class ContentProvider implements Closeable {
|
||||||
|
|
||||||
public static final String TABLE_SYSTEM = "system";
|
public static final String TABLE_SYSTEM = "system";
|
||||||
public static final String TABLE_SECURE = "secure";
|
public static final String TABLE_SECURE = "secure";
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
package com.genymobile.scrcpy.wrappers;
|
package com.genymobile.scrcpy.wrappers;
|
||||||
|
|
||||||
|
import com.genymobile.scrcpy.FakeContext;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.hardware.camera2.CameraManager;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.IInterface;
|
import android.os.IInterface;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@ -26,6 +31,7 @@ public final class ServiceManager {
|
|||||||
private static StatusBarManager statusBarManager;
|
private static StatusBarManager statusBarManager;
|
||||||
private static ClipboardManager clipboardManager;
|
private static ClipboardManager clipboardManager;
|
||||||
private static ActivityManager activityManager;
|
private static ActivityManager activityManager;
|
||||||
|
private static CameraManager cameraManager;
|
||||||
|
|
||||||
private ServiceManager() {
|
private ServiceManager() {
|
||||||
/* not instantiable */
|
/* not instantiable */
|
||||||
@ -129,4 +135,16 @@ public final class ServiceManager {
|
|||||||
|
|
||||||
return activityManager;
|
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.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class StatusBarManager {
|
public final class StatusBarManager {
|
||||||
|
|
||||||
private final IInterface manager;
|
private final IInterface manager;
|
||||||
private Method expandNotificationsPanelMethod;
|
private Method expandNotificationsPanelMethod;
|
||||||
|
@ -2,6 +2,7 @@ package com.genymobile.scrcpy.wrappers;
|
|||||||
|
|
||||||
import com.genymobile.scrcpy.Ln;
|
import com.genymobile.scrcpy.Ln;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.os.IInterface;
|
import android.os.IInterface;
|
||||||
import android.view.IRotationWatcher;
|
import android.view.IRotationWatcher;
|
||||||
import android.view.IDisplayFoldListener;
|
import android.view.IDisplayFoldListener;
|
||||||
@ -106,16 +107,17 @@ public final class WindowManager {
|
|||||||
cls.getMethod("watchRotation", IRotationWatcher.class).invoke(manager, rotationWatcher);
|
cls.getMethod("watchRotation", IRotationWatcher.class).invoke(manager, rotationWatcher);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new AssertionError(e);
|
Ln.e("Could not register rotation watcher", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TargetApi(29)
|
||||||
public void registerDisplayFoldListener(IDisplayFoldListener foldListener) {
|
public void registerDisplayFoldListener(IDisplayFoldListener foldListener) {
|
||||||
try {
|
try {
|
||||||
Class<?> cls = manager.getClass();
|
Class<?> cls = manager.getClass();
|
||||||
cls.getMethod("registerDisplayFoldListener", IDisplayFoldListener.class).invoke(manager, foldListener);
|
cls.getMethod("registerDisplayFoldListener", IDisplayFoldListener.class).invoke(manager, foldListener);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new AssertionError(e);
|
Ln.e("Could not register display fold listener", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user