Compare commits
22 Commits
exit_code
...
libusb-all
Author | SHA1 | Date | |
---|---|---|---|
ef82204c20 | |||
26ee63d9e9 | |||
0d3ed2f669 | |||
0480581789 | |||
c0bc183157 | |||
dddd960a9e | |||
5b05936093 | |||
14b608dbcc | |||
1718bfe00e | |||
4ad12755da | |||
a6bedb4301 | |||
a432134685 | |||
e78eb83cb9 | |||
f5b737857f | |||
4a759f9b55 | |||
c28e616a44 | |||
70a0d9cc37 | |||
b11c6550c7 | |||
7d7953e278 | |||
54d48321fd | |||
3456ca19c7 | |||
79eb78a9e8 |
18
BUILD.md
18
BUILD.md
@ -161,8 +161,7 @@ install the required packages:
|
||||
```bash
|
||||
# runtime dependencies
|
||||
pacman -S mingw-w64-x86_64-SDL2 \
|
||||
mingw-w64-x86_64-ffmpeg \
|
||||
mingw-w64-x86_64-libusb
|
||||
mingw-w64-x86_64-ffmpeg
|
||||
|
||||
# client build dependencies
|
||||
pacman -S mingw-w64-x86_64-make \
|
||||
@ -176,8 +175,7 @@ For a 32 bits version, replace `x86_64` by `i686`:
|
||||
```bash
|
||||
# runtime dependencies
|
||||
pacman -S mingw-w64-i686-SDL2 \
|
||||
mingw-w64-i686-ffmpeg \
|
||||
mingw-w64-i686-libusb
|
||||
mingw-w64-i686-ffmpeg
|
||||
|
||||
# client build dependencies
|
||||
pacman -S mingw-w64-i686-make \
|
||||
@ -201,7 +199,7 @@ Install the packages with [Homebrew]:
|
||||
|
||||
```bash
|
||||
# runtime dependencies
|
||||
brew install sdl2 ffmpeg libusb
|
||||
brew install sdl2 ffmpeg
|
||||
|
||||
# client build dependencies
|
||||
brew install pkg-config meson
|
||||
@ -260,7 +258,7 @@ set ANDROID_SDK_ROOT=%LOCALAPPDATA%\Android\sdk
|
||||
Then, build:
|
||||
|
||||
```bash
|
||||
meson x --buildtype=release --strip -Db_lto=true
|
||||
meson x --buildtype release --strip -Db_lto=true
|
||||
ninja -Cx # DO NOT RUN AS ROOT
|
||||
```
|
||||
|
||||
@ -272,16 +270,16 @@ install` must be run as root)._
|
||||
|
||||
#### Option 2: Use prebuilt server
|
||||
|
||||
- [`scrcpy-server-v1.23`][direct-scrcpy-server]
|
||||
_(SHA-256: 2a913fd47478c0b306fca507cb0beb625e49a19ff9fc7ab904e36ef5b9fe7e68)_
|
||||
- [`scrcpy-server-v1.22`][direct-scrcpy-server]
|
||||
_(SHA-256: c05d273eec7533c0e106282e0254cf04e7f5e8f0c2920ca39448865fab2a419b)_
|
||||
|
||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.23/scrcpy-server-v1.23
|
||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.22/scrcpy-server-v1.22
|
||||
|
||||
Download the prebuilt server somewhere, and specify its path during the Meson
|
||||
configuration:
|
||||
|
||||
```bash
|
||||
meson x --buildtype=release --strip -Db_lto=true \
|
||||
meson x --buildtype release --strip -Db_lto=true \
|
||||
-Dprebuilt_server=/path/to/scrcpy-server
|
||||
ninja -Cx # DO NOT RUN AS ROOT
|
||||
```
|
||||
|
88
FAQ.md
88
FAQ.md
@ -4,16 +4,23 @@
|
||||
|
||||
Here are the common reported problems and their status.
|
||||
|
||||
If you encounter any error, the first step is to upgrade to the latest version.
|
||||
|
||||
|
||||
## `adb` issues
|
||||
|
||||
`scrcpy` execute `adb` commands to initialize the connection with the device. If
|
||||
`adb` fails, then scrcpy will not work.
|
||||
|
||||
In that case, it will print this error:
|
||||
|
||||
> ERROR: "adb get-serialno" returned with value 1
|
||||
|
||||
This is typically not a bug in _scrcpy_, but a problem in your environment.
|
||||
|
||||
To find out the cause, execute:
|
||||
|
||||
```bash
|
||||
adb devices
|
||||
```
|
||||
|
||||
### `adb` not found
|
||||
|
||||
@ -23,30 +30,13 @@ On Windows, the current directory is in your `PATH`, and `adb.exe` is included
|
||||
in the release, so it should work out-of-the-box.
|
||||
|
||||
|
||||
### Device not detected
|
||||
|
||||
> ERROR: Could not find any ADB device
|
||||
|
||||
Check that you correctly enabled [adb debugging][enable-adb].
|
||||
|
||||
Your device must be detected by `adb`:
|
||||
|
||||
```
|
||||
adb devices
|
||||
```
|
||||
|
||||
If your device is not detected, you may need some [drivers] (on Windows). There is a separate [USB driver for Google devices][google-usb-driver].
|
||||
|
||||
[enable-adb]: https://developer.android.com/studio/command-line/adb.html#Enabling
|
||||
[drivers]: https://developer.android.com/studio/run/oem-usb.html
|
||||
[google-usb-driver]: https://developer.android.com/studio/run/win-usb
|
||||
|
||||
|
||||
### Device unauthorized
|
||||
|
||||
> ERROR: Device is unauthorized:
|
||||
> ERROR: --> (usb) 0123456789abcdef unauthorized
|
||||
> ERROR: A popup should open on the device to request authorization.
|
||||
|
||||
> error: device unauthorized.
|
||||
> This adb server's $ADB_VENDOR_KEYS is not set
|
||||
> Try 'adb kill-server' if that seems wrong.
|
||||
> Otherwise check for a confirmation dialog on your device.
|
||||
|
||||
When connecting, a popup should open on the device. You must authorize USB
|
||||
debugging.
|
||||
@ -56,27 +46,29 @@ If it does not open, check [stackoverflow][device-unauthorized].
|
||||
[device-unauthorized]: https://stackoverflow.com/questions/23081263/adb-android-device-unauthorized
|
||||
|
||||
|
||||
### Device not detected
|
||||
|
||||
> error: no devices/emulators found
|
||||
|
||||
Check that you correctly enabled [adb debugging][enable-adb].
|
||||
|
||||
If your device is not detected, you may need some [drivers] (on Windows). There is a separate [USB driver for Google devices][google-usb-driver].
|
||||
|
||||
[enable-adb]: https://developer.android.com/studio/command-line/adb.html#Enabling
|
||||
[drivers]: https://developer.android.com/studio/run/oem-usb.html
|
||||
[google-usb-driver]: https://developer.android.com/studio/run/win-usb
|
||||
|
||||
|
||||
### Several devices connected
|
||||
|
||||
If several devices are connected, you will encounter this error:
|
||||
|
||||
ERROR: Multiple (2) ADB devices:
|
||||
ERROR: --> (usb) 0123456789abcdef device Nexus_5
|
||||
ERROR: --> (tcpip) 192.168.1.5:5555 device GM1913
|
||||
ERROR: Select a device via -s (--serial), -d (--select-usb) or -e (--select-tcpip)
|
||||
> error: more than one device/emulator
|
||||
|
||||
In that case, you can either provide the identifier of the device you want to
|
||||
mirror:
|
||||
the identifier of the device you want to mirror must be provided:
|
||||
|
||||
```bash
|
||||
scrcpy -s 0123456789abcdef
|
||||
```
|
||||
|
||||
Or request the single USB (or TCP/IP) device:
|
||||
|
||||
```bash
|
||||
scrcpy -d # USB device
|
||||
scrcpy -e # TCP/IP device
|
||||
scrcpy -s 01234567890abcdef
|
||||
```
|
||||
|
||||
Note that if your device is connected over TCP/IP, you might get this message:
|
||||
@ -158,24 +150,22 @@ screen, then you might get poor quality, especially visible on text (see [#40]).
|
||||
|
||||
[#40]: https://github.com/Genymobile/scrcpy/issues/40
|
||||
|
||||
This problem should be fixed in scrcpy v1.22: **update to the latest version**.
|
||||
To improve downscaling quality, trilinear filtering is enabled automatically
|
||||
if the renderer is OpenGL and if it supports mipmapping.
|
||||
|
||||
On older versions, you must configure the [scaling behavior]:
|
||||
On Windows, you might want to force OpenGL:
|
||||
|
||||
```
|
||||
scrcpy --render-driver=opengl
|
||||
```
|
||||
|
||||
You may also need to configure the [scaling behavior]:
|
||||
|
||||
> `scrcpy.exe` > Properties > Compatibility > Change high DPI settings >
|
||||
> Override high DPI scaling behavior > Scaling performed by: _Application_.
|
||||
|
||||
[scaling behavior]: https://github.com/Genymobile/scrcpy/issues/40#issuecomment-424466723
|
||||
|
||||
Also, to improve downscaling quality, trilinear filtering is enabled
|
||||
automatically if the renderer is OpenGL and if it supports mipmapping.
|
||||
|
||||
On Windows, you might want to force OpenGL to enable mipmapping:
|
||||
|
||||
```
|
||||
scrcpy --render-driver=opengl
|
||||
```
|
||||
|
||||
|
||||
### Issue with Wayland
|
||||
|
||||
|
1016
README.de.md
1016
README.de.md
File diff suppressed because it is too large
Load Diff
87
README.md
87
README.md
@ -1,6 +1,6 @@
|
||||
# scrcpy (v1.23)
|
||||
# scrcpy (v1.22)
|
||||
|
||||
<img src="app/data/icon.svg" width="128" height="128" alt="scrcpy" align="right" />
|
||||
<img src="data/icon.svg" width="128" height="128" alt="scrcpy" align="right" />
|
||||
|
||||
_pronounced "**scr**een **c**o**py**"_
|
||||
|
||||
@ -32,8 +32,10 @@ Its features include:
|
||||
- [configurable quality](#capture-configuration)
|
||||
- device screen [as a webcam (V4L2)](#v4l2loopback) (Linux-only)
|
||||
- [physical keyboard simulation (HID)](#physical-keyboard-simulation-hid)
|
||||
(Linux-only)
|
||||
- [physical mouse simulation (HID)](#physical-mouse-simulation-hid)
|
||||
- [OTG mode](#otg)
|
||||
(Linux-only)
|
||||
- [OTG mode](#otg) (Linux-only)
|
||||
- and more…
|
||||
|
||||
## Requirements
|
||||
@ -106,10 +108,10 @@ process][BUILD_simple]).
|
||||
For Windows, for simplicity, a prebuilt archive with all the dependencies
|
||||
(including `adb`) is available:
|
||||
|
||||
- [`scrcpy-win64-v1.23.zip`][direct-win64]
|
||||
_(SHA-256: d2f601b1d0157faf65153d8a093d827fd65aec5d5842d677ac86fb2b5b7704cc)_
|
||||
- [`scrcpy-win64-v1.22.zip`][direct-win64]
|
||||
_(SHA-256: ce4d9b8cc761e29862c4a72d8ad6f538bdd1f1831d15fd1f36633cd3b403db82)_
|
||||
|
||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.23/scrcpy-win64-v1.23.zip
|
||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.22/scrcpy-win64-v1.22.zip
|
||||
|
||||
It is also available in [Chocolatey]:
|
||||
|
||||
@ -213,15 +215,6 @@ scrcpy --max-fps 15
|
||||
|
||||
This is officially supported since Android 10, but may work on earlier versions.
|
||||
|
||||
The actual capture framerate may be printed to the console:
|
||||
|
||||
```
|
||||
scrcpy --print-fps
|
||||
```
|
||||
|
||||
It may also be enabled or disabled at any time with <kbd>MOD</kbd>+<kbd>i</kbd>.
|
||||
|
||||
|
||||
#### Crop
|
||||
|
||||
The device screen may be cropped to mirror only part of the screen.
|
||||
@ -404,30 +397,18 @@ connect to the device before starting.
|
||||
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
|
||||
1. Connect the device to the same Wi-Fi as your computer.
|
||||
2. 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.
|
||||
|
||||
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#connect-to-a-device-over-wi-fi-android-11+
|
||||
|
||||
If the connection randomly drops, run your `scrcpy` command to reconnect. If it
|
||||
says there are no devices/emulators found, try running `adb connect
|
||||
DEVICE_IP:5555` again, and then `scrcpy` as usual. If it still says there are
|
||||
none found, try running `adb disconnect` and then run those two commands again.
|
||||
3. Enable adb over TCP/IP on your device: `adb tcpip 5555`.
|
||||
4. Unplug your device.
|
||||
5. Connect to your device: `adb connect DEVICE_IP:5555` _(replace `DEVICE_IP`)_.
|
||||
6. Run `scrcpy` as usual.
|
||||
|
||||
It may be useful to decrease the bit-rate and the definition:
|
||||
|
||||
@ -460,12 +441,12 @@ select it automatically:
|
||||
|
||||
```bash
|
||||
# Select the only device connected via USB
|
||||
scrcpy -d # like adb -d
|
||||
scrcpy --select-usb # long version
|
||||
scrcpy --select-usb
|
||||
scrcpy -U # short version
|
||||
|
||||
# Select the only device connected via TCP/IP
|
||||
scrcpy -e # like adb -e
|
||||
scrcpy --select-tcpip # long version
|
||||
scrcpy --select-tcpip
|
||||
scrcpy -T # short version
|
||||
```
|
||||
|
||||
You can start several instances of _scrcpy_ for several devices.
|
||||
@ -817,17 +798,14 @@ a location inverted through the center of the screen.
|
||||
By default, scrcpy uses Android key or text injection: it works everywhere, but
|
||||
is limited to ASCII.
|
||||
|
||||
Alternatively, scrcpy can simulate a physical USB keyboard on Android to provide
|
||||
a better input experience (using [USB HID over AOAv2][hid-aoav2]): the virtual
|
||||
On Linux, scrcpy can simulate a physical USB keyboard on Android to provide a
|
||||
better input experience (using [USB HID over AOAv2][hid-aoav2]): the virtual
|
||||
keyboard is disabled and it works for all characters and IME.
|
||||
|
||||
[hid-aoav2]: https://source.android.com/devices/accessories/aoa2#hid-support
|
||||
|
||||
However, it only works if the device is connected by USB.
|
||||
|
||||
Note: On Windows, it may only work in [OTG mode](#otg), not while mirroring (it
|
||||
is not possible to open a USB device if it is already open by another process
|
||||
like the adb daemon).
|
||||
However, it only works if the device is connected by USB, and is currently only
|
||||
supported on Linux.
|
||||
|
||||
To enable this mode:
|
||||
|
||||
@ -860,7 +838,8 @@ a physical keyboard is connected).
|
||||
#### Physical mouse simulation (HID)
|
||||
|
||||
Similarly to the physical keyboard simulation, it is possible to simulate a
|
||||
physical mouse. Likewise, it only works if the device is connected by USB.
|
||||
physical mouse. Likewise, it only works if the device is connected by USB, and
|
||||
is currently only supported on Linux.
|
||||
|
||||
By default, scrcpy uses Android mouse events injection, using absolute
|
||||
coordinates. By simulating a physical mouse, a mouse pointer appears on the
|
||||
@ -913,7 +892,7 @@ scrcpy --otg # keyboard and mouse
|
||||
```
|
||||
|
||||
Like `--hid-keyboard` and `--hid-mouse`, it only works if the device is
|
||||
connected by USB.
|
||||
connected by USB, and is currently only supported on Linux.
|
||||
|
||||
|
||||
#### Text injection preference
|
||||
@ -1105,9 +1084,7 @@ See [BUILD].
|
||||
|
||||
## Common issues
|
||||
|
||||
See the [FAQ].md).
|
||||
|
||||
[FAQ]: FAQ.md
|
||||
See the [FAQ](FAQ.md).
|
||||
|
||||
|
||||
## Developers
|
||||
@ -1142,22 +1119,10 @@ Read the [developers page].
|
||||
[article-intro]: https://blog.rom1v.com/2018/03/introducing-scrcpy/
|
||||
[article-tcpip]: https://www.genymotion.com/blog/open-source-project-scrcpy-now-works-wirelessly/
|
||||
|
||||
## Contact
|
||||
|
||||
If you encounter a bug, please read the [FAQ] first, then open an [issue].
|
||||
|
||||
[issue]: https://github.com/Genymobile/scrcpy/issues
|
||||
|
||||
For general questions or discussions, you could also use:
|
||||
|
||||
- Reddit: [`r/scrcpy`](https://www.reddit.com/r/scrcpy)
|
||||
- Twitter: [`@scrcpy_app`](https://twitter.com/scrcpy_app)
|
||||
|
||||
## Translations
|
||||
|
||||
This README is available in other languages:
|
||||
|
||||
- [Deutsch (German, `de`) - v1.22](README.de.md)
|
||||
- [Indonesian (Indonesia, `id`) - v1.16](README.id.md)
|
||||
- [Italiano (Italiano, `it`) - v1.19](README.it.md)
|
||||
- [日本語 (Japanese, `jp`) - v1.19](README.jp.md)
|
||||
|
@ -1,121 +0,0 @@
|
||||
_scrcpy() {
|
||||
local cur prev words cword
|
||||
local opts="
|
||||
--always-on-top
|
||||
-b --bit-rate=
|
||||
--codec-options=
|
||||
--crop=
|
||||
-d --select-usb
|
||||
--disable-screensaver
|
||||
--display=
|
||||
--display-buffer=
|
||||
-e --select-tcpip
|
||||
--encoder=
|
||||
--force-adb-forward
|
||||
--forward-all-clicks
|
||||
-f --fullscreen
|
||||
-K --hid-keyboard
|
||||
-h --help
|
||||
--legacy-paste
|
||||
--lock-video-orientation
|
||||
--lock-video-orientation=
|
||||
--max-fps=
|
||||
-M --hid-mouse
|
||||
-m --max-size=
|
||||
--no-cleanup
|
||||
--no-clipboard-on-error
|
||||
--no-downsize-on-error
|
||||
-n --no-control
|
||||
-N --no-display
|
||||
--no-key-repeat
|
||||
--no-mipmaps
|
||||
--otg
|
||||
-p --port=
|
||||
--power-off-on-close
|
||||
--prefer-text
|
||||
--print-fps
|
||||
--push-target=
|
||||
--raw-key-events
|
||||
-r --record=
|
||||
--record-format=
|
||||
--render-driver=
|
||||
--rotation=
|
||||
-s --serial=
|
||||
--shortcut-mod=
|
||||
-S --turn-screen-off
|
||||
-t --show-touches
|
||||
--tcpip
|
||||
--tcpip=
|
||||
--tunnel-host=
|
||||
--tunnel-port=
|
||||
--v4l2-buffer=
|
||||
--v4l2-sink=
|
||||
-V --verbosity=
|
||||
-v --version
|
||||
-w --stay-awake
|
||||
--window-borderless
|
||||
--window-title=
|
||||
--window-x=
|
||||
--window-y=
|
||||
--window-width=
|
||||
--window-height="
|
||||
|
||||
_init_completion -s || return
|
||||
|
||||
case "$prev" in
|
||||
--lock-video-orientation)
|
||||
COMPREPLY=($(compgen -W 'unlocked initial 0 1 2 3' -- "$cur"))
|
||||
return
|
||||
;;
|
||||
-r|--record)
|
||||
COMPREPLY=($(compgen -f -- "$cur"))
|
||||
return
|
||||
;;
|
||||
--record-format)
|
||||
COMPREPLY=($(compgen -W 'mkv mp4' -- "$cur"))
|
||||
return
|
||||
;;
|
||||
--render-driver)
|
||||
COMPREPLY=($(compgen -W 'direct3d opengl opengles2 opengles metal software' -- "$cur"))
|
||||
return
|
||||
;;
|
||||
--rotation)
|
||||
COMPREPLY=($(compgen -W '0 1 2 3' -- "$cur"))
|
||||
return
|
||||
;;
|
||||
--shortcut-mod)
|
||||
# Only auto-complete a single key
|
||||
COMPREPLY=($(compgen -W 'lctrl rctrl lalt ralt lsuper rsuper' -- "$cur"))
|
||||
return
|
||||
;;
|
||||
-V|--verbosity)
|
||||
COMPREPLY=($(compgen -W 'verbose debug info warn error' -- "$cur"))
|
||||
return
|
||||
;;
|
||||
-b|--bitrate \
|
||||
|--codec-options \
|
||||
|--crop \
|
||||
|--display \
|
||||
|--display-buffer \
|
||||
|--encoder \
|
||||
|--max-fps \
|
||||
|-m|--max-size \
|
||||
|-p|--port \
|
||||
|--push-target \
|
||||
|-s|--serial \
|
||||
|--tunnel-host \
|
||||
|--tunnel-port \
|
||||
|--v4l2-buffer \
|
||||
|--v4l2-sink \
|
||||
|--tcpip \
|
||||
|--window-*)
|
||||
# Option accepting an argument, but nothing to auto-complete
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
COMPREPLY=($(compgen -W "$opts" -- "$cur"))
|
||||
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
||||
}
|
||||
|
||||
complete -F _scrcpy scrcpy
|
@ -1,69 +0,0 @@
|
||||
#compdef -N scrcpy -N scrcpy.exe
|
||||
#
|
||||
# name: scrcpy
|
||||
# auth: hltdev [hltdev8642@gmail.com]
|
||||
# desc: completion file for scrcpy (all OSes)
|
||||
#
|
||||
|
||||
local arguments
|
||||
|
||||
arguments=(
|
||||
'--always-on-top[Make scrcpy window always on top \(above other windows\)]'
|
||||
{-b,--bit-rate=}'[Encode the video at the given bit-rate]'
|
||||
'--codec-options=[Set a list of comma-separated key\:type=value options for the device encoder]'
|
||||
'--crop=[\[width\:height\:x\:y\] Crop the device screen on the server]'
|
||||
{-d,--select-usb}'[Use USB device]'
|
||||
'--disable-screensaver[Disable screensaver while scrcpy is running]'
|
||||
'--display=[Specify the display id to mirror]'
|
||||
'--display-buffer=[Add a buffering delay \(in milliseconds\) before displaying]'
|
||||
{-e,--select-tcpip}'[Use TCP/IP device]'
|
||||
'--encoder=[Use a specific MediaCodec encoder \(must be a H.264 encoder\)]'
|
||||
'--force-adb-forward[Do not attempt to use \"adb reverse\" to connect to the device]'
|
||||
'--forward-all-clicks[Forward clicks to device]'
|
||||
{-f,--fullscreen}'[Start in fullscreen]'
|
||||
{-K,--hid-keyboard}'[Simulate a physical keyboard by using HID over AOAv2]'
|
||||
{-h,--help}'[Print the help]'
|
||||
'--legacy-paste[Inject computer clipboard text as a sequence of key events on Ctrl+v]'
|
||||
'--lock-video-orientation=[Lock video orientation]:orientation:(unlocked initial 0 1 2 3)'
|
||||
'--max-fps=[Limit the frame rate of screen capture]'
|
||||
{-M,--hid-mouse}'[Simulate a physical mouse by using HID over AOAv2]'
|
||||
{-m,--max-size=}'[Limit both the width and height of the video to value]'
|
||||
'--no-cleanup[Disable device cleanup actions on exit]'
|
||||
'--no-clipboard-autosync[Disable automatic clipboard synchronization]'
|
||||
'--no-downsize-on-error[Disable lowering definition on MediaCodec error]'
|
||||
{-n,--no-control}'[Disable device control \(mirror the device in read only\)]'
|
||||
{-N,--no-display}'[Do not display device \(during screen recording or when V4L2 sink is enabled\)]'
|
||||
'--no-key-repeat[Do not forward repeated key events when a key is held down]'
|
||||
'--no-mipmaps[Disable the generation of mipmaps]'
|
||||
'--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]'
|
||||
'--power-off-on-close[Turn the device screen off when closing scrcpy]'
|
||||
'--prefer-text[Inject alpha characters and space as text events instead of key events]'
|
||||
'--print-fps[Start FPS counter, to print frame logs to the console]'
|
||||
'--push-target=[Set the target directory for pushing files to the device by drag and drop]'
|
||||
'--raw-key-events[Inject key events for all input keys, and ignore text events]'
|
||||
{-r,--record=}'[Record screen to file]:record file:_files'
|
||||
'--record-format=[Force recording format]:format:(mp4 mkv)'
|
||||
'--render-driver=[Request SDL to use the given render driver]:driver name:(direct3d opengl opengles2 opengles metal software)'
|
||||
'--rotation=[Set the initial display rotation]:rotation values:(0 1 2 3)'
|
||||
{-s,--serial=}'[The device serial number \(mandatory for multiple devices only\)]'
|
||||
'--shortcut-mod=[\[key1,key2+key3,...\] Specify the modifiers to use for scrcpy shortcuts]:shortcut mod:(lctrl rctrl lalt ralt lsuper rsuper)'
|
||||
{-S,--turn-screen-off}'[Turn the device screen off immediately]'
|
||||
{-t,--show-touches}'[Show physical touches]'
|
||||
'--tcpip[\(optional \[ip\:port\]\) Configure and connect the device over TCP/IP]'
|
||||
'--tunnel-host=[Set the IP address of the adb tunnel to reach the scrcpy server]'
|
||||
'--tunnel-port=[Set the TCP port of the adb tunnel to reach the scrcpy server]'
|
||||
'--v4l2-buffer=[Add a buffering delay \(in milliseconds\) before pushing frames]'
|
||||
'--v4l2-sink=[\[\/dev\/videoN\] Output to v4l2loopback device]'
|
||||
{-V,--verbosity=}'[Set the log level]:verbosity:(verbose debug info warn error)'
|
||||
{-v,--version}'[Print the version of scrcpy]'
|
||||
{-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-title=[Set a custom window title]'
|
||||
'--window-x=[Set the initial window horizontal position]'
|
||||
'--window-y=[Set the initial window vertical position]'
|
||||
'--window-width=[Set the initial window width]'
|
||||
'--window-height=[Set the initial window height]'
|
||||
)
|
||||
|
||||
_arguments -s $arguments
|
@ -26,7 +26,6 @@ src = [
|
||||
'src/scrcpy.c',
|
||||
'src/screen.c',
|
||||
'src/server.c',
|
||||
'src/version.c',
|
||||
'src/video_buffer.c',
|
||||
'src/util/acksync.c',
|
||||
'src/util/file.c',
|
||||
@ -69,12 +68,12 @@ else
|
||||
endif
|
||||
endif
|
||||
|
||||
v4l2_support = get_option('v4l2') and host_machine.system() == 'linux'
|
||||
v4l2_support = host_machine.system() == 'linux'
|
||||
if v4l2_support
|
||||
src += [ 'src/v4l2_sink.c' ]
|
||||
endif
|
||||
|
||||
usb_support = get_option('usb')
|
||||
usb_support = true
|
||||
if usb_support
|
||||
src += [
|
||||
'src/usb/aoa_hid.c',
|
||||
@ -111,9 +110,9 @@ if not crossbuild_windows
|
||||
else
|
||||
# cross-compile mingw32 build (from Linux to Windows)
|
||||
prebuilt_sdl2 = meson.get_cross_property('prebuilt_sdl2')
|
||||
sdl2_bin_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_sdl2 + '/bin'
|
||||
sdl2_lib_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_sdl2 + '/lib'
|
||||
sdl2_include_dir = 'prebuilt-deps/data/' + prebuilt_sdl2 + '/include'
|
||||
sdl2_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/data/' + prebuilt_sdl2 + '/bin'
|
||||
sdl2_lib_dir = meson.current_source_dir() + '/../prebuilt-deps/data/' + prebuilt_sdl2 + '/lib'
|
||||
sdl2_include_dir = '../prebuilt-deps/data/' + prebuilt_sdl2 + '/include'
|
||||
|
||||
sdl2 = declare_dependency(
|
||||
dependencies: [
|
||||
@ -124,8 +123,8 @@ else
|
||||
)
|
||||
|
||||
prebuilt_ffmpeg = meson.get_cross_property('prebuilt_ffmpeg')
|
||||
ffmpeg_bin_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_ffmpeg + '/bin'
|
||||
ffmpeg_include_dir = 'prebuilt-deps/data/' + prebuilt_ffmpeg + '/include'
|
||||
ffmpeg_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/data/' + prebuilt_ffmpeg + '/bin'
|
||||
ffmpeg_include_dir = '../prebuilt-deps/data/' + prebuilt_ffmpeg + '/include'
|
||||
|
||||
# ffmpeg versions are different for win32 and win64 builds
|
||||
ffmpeg_avcodec = meson.get_cross_property('ffmpeg_avcodec')
|
||||
@ -143,8 +142,8 @@ else
|
||||
|
||||
prebuilt_libusb = meson.get_cross_property('prebuilt_libusb')
|
||||
prebuilt_libusb_root = meson.get_cross_property('prebuilt_libusb_root')
|
||||
libusb_bin_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_libusb + '/dll'
|
||||
libusb_include_dir = 'prebuilt-deps/data/' + prebuilt_libusb_root + '/include'
|
||||
libusb_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/data/' + prebuilt_libusb + '/dll'
|
||||
libusb_include_dir = '../prebuilt-deps/data/' + prebuilt_libusb_root + '/include'
|
||||
|
||||
libusb = declare_dependency(
|
||||
dependencies: [
|
||||
@ -224,13 +223,9 @@ executable('scrcpy', src,
|
||||
c_args: [])
|
||||
|
||||
install_man('scrcpy.1')
|
||||
install_data('data/icon.png',
|
||||
install_data('../data/icon.png',
|
||||
rename: 'scrcpy.png',
|
||||
install_dir: 'share/icons/hicolor/256x256/apps')
|
||||
install_data('data/zsh-completion/_scrcpy',
|
||||
install_dir: 'share/zsh/site-functions')
|
||||
install_data('data/bash-completion/scrcpy',
|
||||
install_dir: 'share/bash-completion/completions')
|
||||
|
||||
|
||||
### TESTS
|
||||
@ -286,9 +281,6 @@ if get_option('buildtype') == 'debug'
|
||||
'src/util/str.c',
|
||||
'src/util/strbuf.c',
|
||||
]],
|
||||
['test_vector', [
|
||||
'tests/test_vector.c',
|
||||
]],
|
||||
]
|
||||
|
||||
foreach t : tests
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <winuser.h>
|
||||
|
||||
0 ICON "data/icon.ico"
|
||||
0 ICON "../data/icon.ico"
|
||||
1 RT_MANIFEST "scrcpy-windows.manifest"
|
||||
2 VERSIONINFO
|
||||
BEGIN
|
||||
@ -13,7 +13,7 @@ BEGIN
|
||||
VALUE "LegalCopyright", "Romain Vimont, Genymobile"
|
||||
VALUE "OriginalFilename", "scrcpy.exe"
|
||||
VALUE "ProductName", "scrcpy"
|
||||
VALUE "ProductVersion", "1.23"
|
||||
VALUE "ProductVersion", "1.22"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
42
app/scrcpy.1
42
app/scrcpy.1
@ -43,12 +43,6 @@ The values are expressed in the device natural orientation (typically, portrait
|
||||
.B \-\-max\-size
|
||||
value is computed on the cropped size.
|
||||
|
||||
.TP
|
||||
.B \-d, \-\-select\-usb
|
||||
Use USB device (if there is exactly one, like adb -d).
|
||||
|
||||
Also see \fB\-e\fR (\fB\-\-select\-tcpip\fR).
|
||||
|
||||
.TP
|
||||
.BI "\-\-disable-screensaver"
|
||||
Disable screensaver while scrcpy is running.
|
||||
@ -68,12 +62,6 @@ Add a buffering delay (in milliseconds) before displaying. This increases latenc
|
||||
|
||||
Default is 0 (no buffering).
|
||||
|
||||
.TP
|
||||
.B \-e, \-\-select\-tcpip
|
||||
Use TCP/IP device (if there is exactly one, like adb -e).
|
||||
|
||||
Also see \fB\-d\fR (\fB\-\-select\-usb\fR).
|
||||
|
||||
.TP
|
||||
.BI "\-\-encoder " name
|
||||
Use a specific MediaCodec encoder (must be a H.264 encoder).
|
||||
@ -100,7 +88,7 @@ Simulate a physical keyboard by using HID over AOAv2.
|
||||
|
||||
This provides a better experience for IME users, and allows to generate non-ASCII characters, contrary to the default injection method.
|
||||
|
||||
It may only work over USB.
|
||||
It may only work over USB, and is currently only supported on Linux.
|
||||
|
||||
The keyboard layout must be configured (once and for all) on the device, via Settings -> System -> Languages and input -> Physical keyboard. This settings page can be started directly:
|
||||
|
||||
@ -142,16 +130,10 @@ In this mode, the computer mouse is captured to control the device directly (rel
|
||||
|
||||
LAlt, LSuper or RSuper toggle the capture mode, to give control of the mouse back to the computer.
|
||||
|
||||
It may only work over USB.
|
||||
It may only work over USB, and is currently only supported on Linux.
|
||||
|
||||
Also see \fB\-\-hid\-keyboard\fR.
|
||||
|
||||
.TP
|
||||
.B \-\-no\-cleanup
|
||||
By default, scrcpy removes the server binary from the device and restores the device state (show touches, stay awake and power mode) on exit.
|
||||
|
||||
This option disables this cleanup.
|
||||
|
||||
.TP
|
||||
.B \-\-no\-clipboard\-autosync
|
||||
By default, scrcpy automatically synchronizes the computer clipboard to the device clipboard before injecting Ctrl+v, and the device clipboard to the computer clipboard whenever it changes.
|
||||
@ -190,7 +172,7 @@ LAlt, LSuper or RSuper toggle the mouse capture mode, to give control of the mou
|
||||
|
||||
If any of \fB\-\-hid\-keyboard\fR or \fB\-\-hid\-mouse\fR is set, only enable keyboard or mouse respectively, otherwise enable both.
|
||||
|
||||
It may only work over USB.
|
||||
It may only work over USB, and is currently only supported on Linux.
|
||||
|
||||
See \fB\-\-hid\-keyboard\fR and \fB\-\-hid\-mouse\fR.
|
||||
|
||||
@ -211,10 +193,6 @@ Inject alpha characters and space as text events instead of key events.
|
||||
This avoids issues when combining multiple keys to enter special characters,
|
||||
but breaks the expected behavior of alpha keys in games (typically WASD).
|
||||
|
||||
.TP
|
||||
.B "\-\-print\-fps
|
||||
Start FPS counter, to print framerate logs to the console. It can be started or stopped at any time with MOD+i.
|
||||
|
||||
.TP
|
||||
.BI "\-\-push\-target " path
|
||||
Set the target directory for pushing files to the device by drag & drop. It is passed as\-is to "adb push".
|
||||
@ -295,6 +273,14 @@ Set the TCP port of the adb tunnel to reach the scrcpy server. This option autom
|
||||
|
||||
Default is 0 (not forced): the local port used for establishing the tunnel will be used.
|
||||
|
||||
.TP
|
||||
.B \-T, \-\-select\-tcpip
|
||||
Use TCP/IP device (if there is exactly one).
|
||||
|
||||
.TP
|
||||
.B \-U, \-\-select\-usb
|
||||
Use USB device (if there is exactly one).
|
||||
|
||||
.TP
|
||||
.BI "\-\-v4l2-sink " /dev/videoN
|
||||
Output to v4l2loopback device.
|
||||
@ -355,12 +341,6 @@ Set the initial window height.
|
||||
|
||||
Default is 0 (automatic).
|
||||
|
||||
.SH EXIT STATUS
|
||||
.B scrcpy
|
||||
will exit with code 0 on normal program termination. If an initial
|
||||
connection cannot be established, the exit code 1 will be returned. If the
|
||||
device disconnects while a session is active, exit code 2 will be returned.
|
||||
|
||||
.SH SHORTCUTS
|
||||
|
||||
In the following list, MOD is the shortcut modifier. By default, it's (left)
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "adb_device.h"
|
||||
#include "adb_parser.h"
|
||||
#include "util/file.h"
|
||||
#include "util/log.h"
|
||||
@ -151,7 +150,7 @@ process_check_success_internal(sc_pid pid, const char *name, bool close,
|
||||
static bool
|
||||
process_check_success_intr(struct sc_intr *intr, sc_pid pid, const char *name,
|
||||
unsigned flags) {
|
||||
if (intr && !sc_intr_set_process(intr, pid)) {
|
||||
if (!sc_intr_set_process(intr, pid)) {
|
||||
// Already interrupted
|
||||
return false;
|
||||
}
|
||||
@ -159,9 +158,7 @@ process_check_success_intr(struct sc_intr *intr, sc_pid pid, const char *name,
|
||||
// Always pass close=false, interrupting would be racy otherwise
|
||||
bool ret = process_check_success_internal(pid, name, false, flags);
|
||||
|
||||
if (intr) {
|
||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||
}
|
||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||
|
||||
// Close separately
|
||||
sc_process_close(pid);
|
||||
@ -205,14 +202,6 @@ sc_adb_start_server(struct sc_intr *intr, unsigned flags) {
|
||||
return process_check_success_intr(intr, pid, "adb start-server", flags);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_adb_kill_server(struct sc_intr *intr, unsigned flags) {
|
||||
const char *const argv[] = SC_ADB_COMMAND("kill-server");
|
||||
|
||||
sc_pid pid = sc_adb_execute(argv, flags);
|
||||
return process_check_success_intr(intr, pid, "adb kill-server", flags);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
|
||||
const char *device_socket_name, unsigned flags) {
|
||||
@ -393,55 +382,45 @@ sc_adb_disconnect(struct sc_intr *intr, const char *ip_port, unsigned flags) {
|
||||
return process_check_success_intr(intr, pid, "adb disconnect", flags);
|
||||
}
|
||||
|
||||
static bool
|
||||
static ssize_t
|
||||
sc_adb_list_devices(struct sc_intr *intr, unsigned flags,
|
||||
struct sc_vec_adb_devices *out_vec) {
|
||||
struct sc_adb_device *devices, size_t len) {
|
||||
const char *const argv[] = SC_ADB_COMMAND("devices", "-l");
|
||||
|
||||
#define BUFSIZE 65536
|
||||
char *buf = malloc(BUFSIZE);
|
||||
if (!buf) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sc_pipe pout;
|
||||
sc_pid pid = sc_adb_execute_p(argv, flags, &pout);
|
||||
if (pid == SC_PROCESS_NONE) {
|
||||
LOGE("Could not execute \"adb devices -l\"");
|
||||
free(buf);
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, BUFSIZE - 1);
|
||||
char buf[4096];
|
||||
ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, sizeof(buf) - 1);
|
||||
sc_pipe_close(pout);
|
||||
|
||||
bool ok = process_check_success_intr(intr, pid, "adb devices -l", flags);
|
||||
if (!ok) {
|
||||
free(buf);
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (r == -1) {
|
||||
free(buf);
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert((size_t) r < BUFSIZE);
|
||||
if (r == BUFSIZE - 1) {
|
||||
assert((size_t) r < sizeof(buf));
|
||||
if (r == sizeof(buf) - 1) {
|
||||
// The implementation assumes that the output of "adb devices -l" fits
|
||||
// in the buffer in a single pass
|
||||
LOGW("Result of \"adb devices -l\" does not fit in 64Kb. "
|
||||
"Please report an issue.");
|
||||
return false;
|
||||
LOGW("Result of \"adb devices -l\" does not fit in 4Kb. "
|
||||
"Please report an issue.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// It is parsed as a NUL-terminated string
|
||||
buf[r] = '\0';
|
||||
|
||||
// List all devices to the output list directly
|
||||
ok = sc_adb_parse_devices(buf, out_vec);
|
||||
free(buf);
|
||||
return ok;
|
||||
return sc_adb_parse_devices(buf, devices, len);
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -540,21 +519,22 @@ bool
|
||||
sc_adb_select_device(struct sc_intr *intr,
|
||||
const struct sc_adb_device_selector *selector,
|
||||
unsigned flags, struct sc_adb_device *out_device) {
|
||||
struct sc_vec_adb_devices vec = SC_VECTOR_INITIALIZER;
|
||||
bool ok = sc_adb_list_devices(intr, flags, &vec);
|
||||
if (!ok) {
|
||||
struct sc_adb_device devices[16];
|
||||
ssize_t count =
|
||||
sc_adb_list_devices(intr, flags, devices, ARRAY_LEN(devices));
|
||||
if (count == -1) {
|
||||
LOGE("Could not list ADB devices");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vec.size == 0) {
|
||||
if (count == 0) {
|
||||
LOGE("Could not find any ADB device");
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t sel_idx; // index of the single matching device if sel_count == 1
|
||||
size_t sel_count =
|
||||
sc_adb_devices_select(vec.data, vec.size, selector, &sel_idx);
|
||||
sc_adb_devices_select(devices, count, selector, &sel_idx);
|
||||
|
||||
if (sel_count == 0) {
|
||||
// if count > 0 && sel_count == 0, then necessarily a selection is
|
||||
@ -577,8 +557,8 @@ sc_adb_select_device(struct sc_intr *intr,
|
||||
break;
|
||||
}
|
||||
|
||||
sc_adb_devices_log(SC_LOG_LEVEL_ERROR, vec.data, vec.size);
|
||||
sc_adb_devices_destroy(&vec);
|
||||
sc_adb_devices_log(SC_LOG_LEVEL_ERROR, devices, count);
|
||||
sc_adb_devices_destroy_all(devices, count);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -604,28 +584,29 @@ sc_adb_select_device(struct sc_intr *intr,
|
||||
assert(!"Unexpected selector type");
|
||||
break;
|
||||
}
|
||||
sc_adb_devices_log(SC_LOG_LEVEL_ERROR, vec.data, vec.size);
|
||||
LOGE("Select a device via -s (--serial), -d (--select-usb) or -e "
|
||||
"(--select-tcpip)");
|
||||
sc_adb_devices_destroy(&vec);
|
||||
sc_adb_devices_log(SC_LOG_LEVEL_ERROR, devices, count);
|
||||
if (selector->type != SC_ADB_DEVICE_SELECT_ALL) {
|
||||
LOGE("Specify the device via -s or --serial");
|
||||
}
|
||||
sc_adb_devices_destroy_all(devices, count);
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(sel_count == 1); // sel_idx is valid only if sel_count == 1
|
||||
struct sc_adb_device *device = &vec.data[sel_idx];
|
||||
struct sc_adb_device *device = &devices[sel_idx];
|
||||
|
||||
ok = sc_adb_device_check_state(device, vec.data, vec.size);
|
||||
bool ok = sc_adb_device_check_state(device, devices, count);
|
||||
if (!ok) {
|
||||
sc_adb_devices_destroy(&vec);
|
||||
sc_adb_devices_destroy_all(devices, count);
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGD("ADB device found:");
|
||||
sc_adb_devices_log(SC_LOG_LEVEL_DEBUG, vec.data, vec.size);
|
||||
sc_adb_devices_log(SC_LOG_LEVEL_DEBUG, devices, count);
|
||||
|
||||
// Move devics into out_device (do not destroy device)
|
||||
sc_adb_device_move(out_device, device);
|
||||
sc_adb_devices_destroy(&vec);
|
||||
sc_adb_devices_destroy_all(devices, count);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -696,7 +677,7 @@ sc_adb_get_device_ip(struct sc_intr *intr, const char *serial, unsigned flags) {
|
||||
// The implementation assumes that the output of "ip route" fits in the
|
||||
// buffer in a single pass
|
||||
LOGW("Result of \"ip route\" does not fit in 1Kb. "
|
||||
"Please report an issue.");
|
||||
"Please report an issue.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,6 @@ sc_adb_execute(const char *const argv[], unsigned flags);
|
||||
bool
|
||||
sc_adb_start_server(struct sc_intr *intr, unsigned flags);
|
||||
|
||||
bool
|
||||
sc_adb_kill_server(struct sc_intr *intr, unsigned flags);
|
||||
|
||||
bool
|
||||
sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
|
||||
const char *device_socket_name, unsigned flags);
|
||||
|
@ -18,10 +18,9 @@ sc_adb_device_move(struct sc_adb_device *dst, struct sc_adb_device *src) {
|
||||
}
|
||||
|
||||
void
|
||||
sc_adb_devices_destroy(struct sc_vec_adb_devices *devices) {
|
||||
for (size_t i = 0; i < devices->size; ++i) {
|
||||
sc_adb_device_destroy(&devices->data[i]);
|
||||
sc_adb_devices_destroy_all(struct sc_adb_device *devices, size_t count) {
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
sc_adb_device_destroy(&devices[i]);
|
||||
}
|
||||
sc_vector_destroy(devices);
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,6 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "util/vector.h"
|
||||
|
||||
struct sc_adb_device {
|
||||
char *serial;
|
||||
char *state;
|
||||
@ -15,13 +13,11 @@ struct sc_adb_device {
|
||||
bool selected;
|
||||
};
|
||||
|
||||
struct sc_vec_adb_devices SC_VECTOR(struct sc_adb_device);
|
||||
|
||||
void
|
||||
sc_adb_device_destroy(struct sc_adb_device *device);
|
||||
|
||||
/**
|
||||
* Move src to dst
|
||||
* Move src to dest
|
||||
*
|
||||
* After this call, the content of src is undefined, except that
|
||||
* sc_adb_device_destroy() can be called.
|
||||
@ -33,6 +29,6 @@ void
|
||||
sc_adb_device_move(struct sc_adb_device *dst, struct sc_adb_device *src);
|
||||
|
||||
void
|
||||
sc_adb_devices_destroy(struct sc_vec_adb_devices *devices);
|
||||
sc_adb_devices_destroy_all(struct sc_adb_device *devices, size_t count);
|
||||
|
||||
#endif
|
||||
|
@ -109,8 +109,11 @@ sc_adb_parse_device(char *line, struct sc_adb_device *device) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
sc_adb_parse_devices(char *str, struct sc_vec_adb_devices *out_vec) {
|
||||
ssize_t
|
||||
sc_adb_parse_devices(char *str, struct sc_adb_device *devices,
|
||||
size_t devices_len) {
|
||||
size_t dev_count = 0;
|
||||
|
||||
#define HEADER "List of devices attached"
|
||||
#define HEADER_LEN (sizeof(HEADER) - 1)
|
||||
bool header_found = false;
|
||||
@ -141,24 +144,25 @@ sc_adb_parse_devices(char *str, struct sc_vec_adb_devices *out_vec) {
|
||||
size_t line_len = sc_str_remove_trailing_cr(line, len);
|
||||
line[line_len] = '\0';
|
||||
|
||||
struct sc_adb_device device;
|
||||
bool ok = sc_adb_parse_device(line, &device);
|
||||
bool ok = sc_adb_parse_device(line, &devices[dev_count]);
|
||||
if (!ok) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ok = sc_vector_push(out_vec, device);
|
||||
if (!ok) {
|
||||
LOG_OOM();
|
||||
LOGE("Could not push adb_device to vector");
|
||||
sc_adb_device_destroy(&device);
|
||||
// continue anyway
|
||||
continue;
|
||||
++dev_count;
|
||||
|
||||
assert(dev_count <= devices_len);
|
||||
if (dev_count == devices_len) {
|
||||
// Max number of devices reached
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(header_found || out_vec->size == 0);
|
||||
return header_found;
|
||||
if (!header_found) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return dev_count;
|
||||
}
|
||||
|
||||
static char *
|
||||
|
@ -14,8 +14,9 @@
|
||||
*
|
||||
* Warning: this function modifies the buffer for optimization purposes.
|
||||
*/
|
||||
bool
|
||||
sc_adb_parse_devices(char *str, struct sc_vec_adb_devices *out_vec);
|
||||
ssize_t
|
||||
sc_adb_parse_devices(char *str, struct sc_adb_device *devices,
|
||||
size_t devices_len);
|
||||
|
||||
/**
|
||||
* Parse the ip from the output of `adb shell ip route`
|
||||
|
137
app/src/cli.c
137
app/src/cli.c
@ -54,8 +54,6 @@
|
||||
#define OPT_RAW_KEY_EVENTS 1034
|
||||
#define OPT_NO_DOWNSIZE_ON_ERROR 1035
|
||||
#define OPT_OTG 1036
|
||||
#define OPT_NO_CLEANUP 1037
|
||||
#define OPT_PRINT_FPS 1038
|
||||
|
||||
struct sc_option {
|
||||
char shortopt;
|
||||
@ -118,13 +116,7 @@ static const struct sc_option options[] = {
|
||||
.text = "Crop the device screen on the server.\n"
|
||||
"The values are expressed in the device natural orientation "
|
||||
"(typically, portrait for a phone, landscape for a tablet). "
|
||||
"Any --max-size value is computed on the cropped size.",
|
||||
},
|
||||
{
|
||||
.shortopt = 'd',
|
||||
.longopt = "select-usb",
|
||||
.text = "Use USB device (if there is exactly one, like adb -d).\n"
|
||||
"Also see -e (--select-tcpip).",
|
||||
"Any --max-size value is cmoputed on the cropped size.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_DISABLE_SCREENSAVER,
|
||||
@ -149,12 +141,6 @@ static const struct sc_option options[] = {
|
||||
"This increases latency to compensate for jitter.\n"
|
||||
"Default is 0 (no buffering).",
|
||||
},
|
||||
{
|
||||
.shortopt = 'e',
|
||||
.longopt = "select-tcpip",
|
||||
.text = "Use TCP/IP device (if there is exactly one, like adb -e).\n"
|
||||
"Also see -d (--select-usb).",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_ENCODER_NAME,
|
||||
.longopt = "encoder",
|
||||
@ -186,7 +172,8 @@ static const struct sc_option options[] = {
|
||||
"It provides a better experience for IME users, and allows to "
|
||||
"generate non-ASCII characters, contrary to the default "
|
||||
"injection method.\n"
|
||||
"It may only work over USB.\n"
|
||||
"It may only work over USB, and is currently only supported "
|
||||
"on Linux.\n"
|
||||
"The keyboard layout must be configured (once and for all) on "
|
||||
"the device, via Settings -> System -> Languages and input -> "
|
||||
"Physical keyboard. This settings page can be started "
|
||||
@ -238,7 +225,8 @@ static const struct sc_option options[] = {
|
||||
"device directly (relative mouse mode).\n"
|
||||
"LAlt, LSuper or RSuper toggle the capture mode, to give "
|
||||
"control of the mouse back to the computer.\n"
|
||||
"It may only work over USB.\n"
|
||||
"It may only work over USB, and is currently only supported "
|
||||
"on Linux.\n"
|
||||
"Also see --hid-keyboard.",
|
||||
},
|
||||
{
|
||||
@ -251,12 +239,11 @@ static const struct sc_option options[] = {
|
||||
"Default is 0 (unlimited).",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_NO_CLEANUP,
|
||||
.longopt = "no-cleanup",
|
||||
.text = "By default, scrcpy removes the server binary from the device "
|
||||
"and restores the device state (show touches, stay awake and "
|
||||
"power mode) on exit.\n"
|
||||
"This option disables this cleanup."
|
||||
.longopt_id = OPT_NO_DOWNSIZE_ON_ERROR,
|
||||
.longopt = "no-downsize-on-error",
|
||||
.text = "By default, on MediaCodec error, scrcpy automatically tries "
|
||||
"again with a lower definition.\n"
|
||||
"This option disables this behavior.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_NO_CLIPBOARD_AUTOSYNC,
|
||||
@ -267,13 +254,6 @@ static const struct sc_option options[] = {
|
||||
"it changes.\n"
|
||||
"This option disables this automatic synchronization."
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_NO_DOWNSIZE_ON_ERROR,
|
||||
.longopt = "no-downsize-on-error",
|
||||
.text = "By default, on MediaCodec error, scrcpy automatically tries "
|
||||
"again with a lower definition.\n"
|
||||
"This option disables this behavior.",
|
||||
},
|
||||
{
|
||||
.shortopt = 'n',
|
||||
.longopt = "no-control",
|
||||
@ -309,7 +289,8 @@ static const struct sc_option options[] = {
|
||||
"control of the mouse back to the computer.\n"
|
||||
"If any of --hid-keyboard or --hid-mouse is set, only enable "
|
||||
"keyboard or mouse respectively, otherwise enable both.\n"
|
||||
"It may only work over USB.\n"
|
||||
"It may only work over USB, and is currently only supported "
|
||||
"on Linux.\n"
|
||||
"See --hid-keyboard and --hid-mouse.",
|
||||
},
|
||||
{
|
||||
@ -334,12 +315,6 @@ static const struct sc_option options[] = {
|
||||
"special character, but breaks the expected behavior of alpha "
|
||||
"keys in games (typically WASD).",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_PRINT_FPS,
|
||||
.longopt = "print-fps",
|
||||
.text = "Start FPS counter, to print framerate logs to the console. "
|
||||
"It can be started or stopped at any time with MOD+i.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_PUSH_TARGET,
|
||||
.longopt = "push-target",
|
||||
@ -422,20 +397,6 @@ static const struct sc_option options[] = {
|
||||
"on exit.\n"
|
||||
"It only shows physical touches (not clicks from scrcpy).",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_TCPIP,
|
||||
.longopt = "tcpip",
|
||||
.argdesc = "ip[:port]",
|
||||
.optional_arg = true,
|
||||
.text = "Configure and reconnect the device over TCP/IP.\n"
|
||||
"If a destination address is provided, then scrcpy connects to "
|
||||
"this address before starting. The device must listen on the "
|
||||
"given TCP port (default is 5555).\n"
|
||||
"If no destination address is provided, then scrcpy attempts "
|
||||
"to find the IP address of the current device (typically "
|
||||
"connected over USB), enables TCP/IP mode, then connects to "
|
||||
"this address before starting.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_TUNNEL_HOST,
|
||||
.longopt = "tunnel-host",
|
||||
@ -455,6 +416,16 @@ static const struct sc_option options[] = {
|
||||
"Default is 0 (not forced): the local port used for "
|
||||
"establishing the tunnel will be used.",
|
||||
},
|
||||
{
|
||||
.shortopt = 'T',
|
||||
.longopt = "select-tcpip",
|
||||
.text = "Use TCP/IP device (if there is exactly one).",
|
||||
},
|
||||
{
|
||||
.shortopt = 'U',
|
||||
.longopt = "select-usb",
|
||||
.text = "Use USB device (if there is exactly one).",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_V4L2_SINK,
|
||||
.longopt = "v4l2-sink",
|
||||
@ -497,6 +468,20 @@ static const struct sc_option options[] = {
|
||||
.text = "Keep the device on while scrcpy is running, when the device "
|
||||
"is plugged in.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_TCPIP,
|
||||
.longopt = "tcpip",
|
||||
.argdesc = "ip[:port]",
|
||||
.optional_arg = true,
|
||||
.text = "Configure and reconnect the device over TCP/IP.\n"
|
||||
"If a destination address is provided, then scrcpy connects to "
|
||||
"this address before starting. The device must listen on the "
|
||||
"given TCP port (default is 5555).\n"
|
||||
"If no destination address is provided, then scrcpy attempts "
|
||||
"to find the IP address of the current device (typically "
|
||||
"connected over USB), enables TCP/IP mode, then connects to "
|
||||
"this address before starting.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_WINDOW_BORDERLESS,
|
||||
.longopt = "window-borderless",
|
||||
@ -1345,12 +1330,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
opts->select_usb = true;
|
||||
break;
|
||||
case 'e':
|
||||
opts->select_tcpip = true;
|
||||
break;
|
||||
case 'f':
|
||||
opts->fullscreen = true;
|
||||
break;
|
||||
@ -1370,7 +1349,8 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
opts->keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_HID;
|
||||
break;
|
||||
#else
|
||||
LOGE("HID over AOA (-K/--hid-keyboard) is disabled.");
|
||||
LOGE("HID over AOA (-K/--hid-keyboard) is not supported on "
|
||||
"this platform. It is only available on Linux.");
|
||||
return false;
|
||||
#endif
|
||||
case OPT_MAX_FPS:
|
||||
@ -1388,7 +1368,8 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
opts->mouse_input_mode = SC_MOUSE_INPUT_MODE_HID;
|
||||
break;
|
||||
#else
|
||||
LOGE("HID over AOA (-M/--hid-mouse) is disabled.");
|
||||
LOGE("HID over AOA (-M/--hid-mouse) is not supported on this"
|
||||
"platform. It is only available on Linux.");
|
||||
return false;
|
||||
#endif
|
||||
case OPT_LOCK_VIDEO_ORIENTATION:
|
||||
@ -1430,6 +1411,12 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
case 't':
|
||||
opts->show_touches = true;
|
||||
break;
|
||||
case 'T':
|
||||
opts->select_tcpip = true;
|
||||
break;
|
||||
case 'U':
|
||||
opts->select_usb = true;
|
||||
break;
|
||||
case OPT_ALWAYS_ON_TOP:
|
||||
opts->always_on_top = true;
|
||||
break;
|
||||
@ -1546,18 +1533,13 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
case OPT_NO_DOWNSIZE_ON_ERROR:
|
||||
opts->downsize_on_error = false;
|
||||
break;
|
||||
case OPT_NO_CLEANUP:
|
||||
opts->cleanup = false;
|
||||
break;
|
||||
case OPT_PRINT_FPS:
|
||||
opts->start_fps_counter = true;
|
||||
break;
|
||||
case OPT_OTG:
|
||||
#ifdef HAVE_USB
|
||||
opts->otg = true;
|
||||
break;
|
||||
#else
|
||||
LOGE("OTG mode (--otg) is disabled.");
|
||||
LOGE("OTG mode (--otg) is not supported on this platform. It "
|
||||
"is only available on Linux.");
|
||||
return false;
|
||||
#endif
|
||||
case OPT_V4L2_SINK:
|
||||
@ -1565,8 +1547,7 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
opts->v4l2_device = optarg;
|
||||
break;
|
||||
#else
|
||||
LOGE("V4L2 (--v4l2-sink) is disabled (or unsupported on this "
|
||||
"platform).");
|
||||
LOGE("V4L2 (--v4l2-sink) is only available on Linux.");
|
||||
return false;
|
||||
#endif
|
||||
case OPT_V4L2_BUFFER:
|
||||
@ -1601,8 +1582,8 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
if (selectors > 1) {
|
||||
LOGE("At most one device selector option may be passed, among:\n"
|
||||
" --serial (-s)\n"
|
||||
" --select-usb (-d)\n"
|
||||
" --select-tcpip (-e)\n"
|
||||
" --select-usb (-U)\n"
|
||||
" --select-tcpip (-T)\n"
|
||||
" --tcpip=<addr> (with an argument)");
|
||||
return false;
|
||||
}
|
||||
@ -1680,18 +1661,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
}
|
||||
|
||||
#ifdef HAVE_USB
|
||||
|
||||
# ifdef _WIN32
|
||||
if (!opts->otg && (opts->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_HID
|
||||
|| opts->mouse_input_mode == SC_MOUSE_INPUT_MODE_HID)) {
|
||||
LOGE("On Windows, it is not possible to open a USB device already open "
|
||||
"by another process (like adb).");
|
||||
LOGE("Therefore, -K/--hid-keyboard and -M/--hid-mouse may only work in "
|
||||
"OTG mode (--otg).");
|
||||
return false;
|
||||
}
|
||||
# endif
|
||||
|
||||
if (opts->otg) {
|
||||
// OTG mode is compatible with only very few options.
|
||||
// Only report obvious errors.
|
||||
@ -1719,12 +1688,12 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
||||
LOGE("OTG mode: could not select display");
|
||||
return false;
|
||||
}
|
||||
# ifdef HAVE_V4L2
|
||||
#ifdef HAVE_V4L2
|
||||
if (opts->v4l2_device) {
|
||||
LOGE("OTG mode: could not sink to V4L2 device");
|
||||
return false;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -63,17 +63,17 @@ static const char *const copy_key_labels[] = {
|
||||
|
||||
static void
|
||||
write_position(uint8_t *buf, const struct sc_position *position) {
|
||||
sc_write32be(&buf[0], position->point.x);
|
||||
sc_write32be(&buf[4], position->point.y);
|
||||
sc_write16be(&buf[8], position->screen_size.width);
|
||||
sc_write16be(&buf[10], position->screen_size.height);
|
||||
buffer_write32be(&buf[0], position->point.x);
|
||||
buffer_write32be(&buf[4], position->point.y);
|
||||
buffer_write16be(&buf[8], position->screen_size.width);
|
||||
buffer_write16be(&buf[10], position->screen_size.height);
|
||||
}
|
||||
|
||||
// write length (4 bytes) + string (non null-terminated)
|
||||
static size_t
|
||||
write_string(const char *utf8, size_t max_len, unsigned char *buf) {
|
||||
size_t len = sc_str_utf8_truncation_index(utf8, max_len);
|
||||
sc_write32be(buf, len);
|
||||
buffer_write32be(buf, len);
|
||||
memcpy(&buf[4], utf8, len);
|
||||
return 4 + len;
|
||||
}
|
||||
@ -94,9 +94,9 @@ sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf) {
|
||||
switch (msg->type) {
|
||||
case SC_CONTROL_MSG_TYPE_INJECT_KEYCODE:
|
||||
buf[1] = msg->inject_keycode.action;
|
||||
sc_write32be(&buf[2], msg->inject_keycode.keycode);
|
||||
sc_write32be(&buf[6], msg->inject_keycode.repeat);
|
||||
sc_write32be(&buf[10], msg->inject_keycode.metastate);
|
||||
buffer_write32be(&buf[2], msg->inject_keycode.keycode);
|
||||
buffer_write32be(&buf[6], msg->inject_keycode.repeat);
|
||||
buffer_write32be(&buf[10], msg->inject_keycode.metastate);
|
||||
return 14;
|
||||
case SC_CONTROL_MSG_TYPE_INJECT_TEXT: {
|
||||
size_t len =
|
||||
@ -106,20 +106,20 @@ sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf) {
|
||||
}
|
||||
case SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT:
|
||||
buf[1] = msg->inject_touch_event.action;
|
||||
sc_write64be(&buf[2], msg->inject_touch_event.pointer_id);
|
||||
buffer_write64be(&buf[2], msg->inject_touch_event.pointer_id);
|
||||
write_position(&buf[10], &msg->inject_touch_event.position);
|
||||
uint16_t pressure =
|
||||
to_fixed_point_16(msg->inject_touch_event.pressure);
|
||||
sc_write16be(&buf[22], pressure);
|
||||
sc_write32be(&buf[24], msg->inject_touch_event.buttons);
|
||||
buffer_write16be(&buf[22], pressure);
|
||||
buffer_write32be(&buf[24], msg->inject_touch_event.buttons);
|
||||
return 28;
|
||||
case SC_CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT:
|
||||
write_position(&buf[1], &msg->inject_scroll_event.position);
|
||||
sc_write32be(&buf[13],
|
||||
buffer_write32be(&buf[13],
|
||||
(uint32_t) msg->inject_scroll_event.hscroll);
|
||||
sc_write32be(&buf[17],
|
||||
buffer_write32be(&buf[17],
|
||||
(uint32_t) msg->inject_scroll_event.vscroll);
|
||||
sc_write32be(&buf[21], msg->inject_scroll_event.buttons);
|
||||
buffer_write32be(&buf[21], msg->inject_scroll_event.buttons);
|
||||
return 25;
|
||||
case SC_CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON:
|
||||
buf[1] = msg->inject_keycode.action;
|
||||
@ -128,7 +128,7 @@ sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf) {
|
||||
buf[1] = msg->get_clipboard.copy_key;
|
||||
return 2;
|
||||
case SC_CONTROL_MSG_TYPE_SET_CLIPBOARD:
|
||||
sc_write64be(&buf[1], msg->set_clipboard.sequence);
|
||||
buffer_write64be(&buf[1], msg->set_clipboard.sequence);
|
||||
buf[9] = !!msg->set_clipboard.paste;
|
||||
size_t len = write_string(msg->set_clipboard.text,
|
||||
SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH,
|
||||
|
@ -10,12 +10,10 @@
|
||||
#include "util/buffer_util.h"
|
||||
#include "util/log.h"
|
||||
|
||||
#define SC_PACKET_HEADER_SIZE 12
|
||||
#define BUFSIZE 0x10000
|
||||
|
||||
#define SC_PACKET_FLAG_CONFIG (UINT64_C(1) << 63)
|
||||
#define SC_PACKET_FLAG_KEY_FRAME (UINT64_C(1) << 62)
|
||||
|
||||
#define SC_PACKET_PTS_MASK (SC_PACKET_FLAG_KEY_FRAME - 1)
|
||||
#define HEADER_SIZE 12
|
||||
#define NO_PTS UINT64_C(-1)
|
||||
|
||||
static bool
|
||||
sc_demuxer_recv_packet(struct sc_demuxer *demuxer, AVPacket *packet) {
|
||||
@ -30,24 +28,16 @@ sc_demuxer_recv_packet(struct sc_demuxer *demuxer, AVPacket *packet) {
|
||||
// size
|
||||
//
|
||||
// It is followed by <packet_size> bytes containing the packet/frame.
|
||||
//
|
||||
// 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
|
||||
// | `- config packet
|
||||
// `-- key frame
|
||||
|
||||
uint8_t header[SC_PACKET_HEADER_SIZE];
|
||||
ssize_t r = net_recv_all(demuxer->socket, header, SC_PACKET_HEADER_SIZE);
|
||||
if (r < SC_PACKET_HEADER_SIZE) {
|
||||
uint8_t header[HEADER_SIZE];
|
||||
ssize_t r = net_recv_all(demuxer->socket, header, HEADER_SIZE);
|
||||
if (r < HEADER_SIZE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t pts_flags = sc_read64be(header);
|
||||
uint32_t len = sc_read32be(&header[8]);
|
||||
uint64_t pts = buffer_read64be(header);
|
||||
uint32_t len = buffer_read32be(&header[8]);
|
||||
assert(pts == NO_PTS || (pts & 0x8000000000000000) == 0);
|
||||
assert(len);
|
||||
|
||||
if (av_new_packet(packet, len)) {
|
||||
@ -61,17 +51,8 @@ sc_demuxer_recv_packet(struct sc_demuxer *demuxer, AVPacket *packet) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pts_flags & SC_PACKET_FLAG_CONFIG) {
|
||||
packet->pts = AV_NOPTS_VALUE;
|
||||
} else {
|
||||
packet->pts = pts_flags & SC_PACKET_PTS_MASK;
|
||||
}
|
||||
packet->pts = pts != NO_PTS ? (int64_t) pts : AV_NOPTS_VALUE;
|
||||
|
||||
if (pts_flags & SC_PACKET_FLAG_KEY_FRAME) {
|
||||
packet->flags |= AV_PKT_FLAG_KEY;
|
||||
}
|
||||
|
||||
packet->dts = packet->pts;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -88,6 +69,28 @@ push_packet_to_sinks(struct sc_demuxer *demuxer, const AVPacket *packet) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
sc_demuxer_parse(struct sc_demuxer *demuxer, AVPacket *packet) {
|
||||
uint8_t *in_data = packet->data;
|
||||
int in_len = packet->size;
|
||||
uint8_t *out_data = NULL;
|
||||
int out_len = 0;
|
||||
int r = av_parser_parse2(demuxer->parser, demuxer->codec_ctx,
|
||||
&out_data, &out_len, in_data, in_len,
|
||||
AV_NOPTS_VALUE, AV_NOPTS_VALUE, -1);
|
||||
|
||||
// PARSER_FLAG_COMPLETE_FRAMES is set
|
||||
assert(r == in_len);
|
||||
(void) r;
|
||||
assert(out_len == in_len);
|
||||
|
||||
if (demuxer->parser->key_frame == 1) {
|
||||
packet->flags |= AV_PKT_FLAG_KEY;
|
||||
}
|
||||
|
||||
packet->dts = packet->pts;
|
||||
}
|
||||
|
||||
static bool
|
||||
sc_demuxer_push_packet(struct sc_demuxer *demuxer, AVPacket *packet) {
|
||||
bool is_config = packet->pts == AV_NOPTS_VALUE;
|
||||
@ -127,6 +130,11 @@ sc_demuxer_push_packet(struct sc_demuxer *demuxer, AVPacket *packet) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_config) {
|
||||
// data packet
|
||||
sc_demuxer_parse(demuxer, packet);
|
||||
}
|
||||
|
||||
bool ok = push_packet_to_sinks(demuxer, packet);
|
||||
|
||||
if (!is_config && demuxer->pending) {
|
||||
|
@ -18,7 +18,7 @@ device_msg_deserialize(const unsigned char *buf, size_t len,
|
||||
msg->type = buf[0];
|
||||
switch (msg->type) {
|
||||
case DEVICE_MSG_TYPE_CLIPBOARD: {
|
||||
size_t clipboard_len = sc_read32be(&buf[1]);
|
||||
size_t clipboard_len = buffer_read32be(&buf[1]);
|
||||
if (clipboard_len > len - 5) {
|
||||
return 0; // not available
|
||||
}
|
||||
@ -36,7 +36,7 @@ device_msg_deserialize(const unsigned char *buf, size_t len,
|
||||
return 5 + clipboard_len;
|
||||
}
|
||||
case DEVICE_MSG_TYPE_ACK_CLIPBOARD: {
|
||||
uint64_t sequence = sc_read64be(&buf[1]);
|
||||
uint64_t sequence = buffer_read64be(&buf[1]);
|
||||
msg->ack_clipboard.sequence = sequence;
|
||||
return 9;
|
||||
}
|
||||
|
@ -4,10 +4,10 @@
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
#define SC_FPS_COUNTER_INTERVAL SC_TICK_FROM_SEC(1)
|
||||
#define FPS_COUNTER_INTERVAL SC_TICK_FROM_SEC(1)
|
||||
|
||||
bool
|
||||
sc_fps_counter_init(struct sc_fps_counter *counter) {
|
||||
fps_counter_init(struct fps_counter *counter) {
|
||||
bool ok = sc_mutex_init(&counter->mutex);
|
||||
if (!ok) {
|
||||
return false;
|
||||
@ -27,26 +27,26 @@ sc_fps_counter_init(struct sc_fps_counter *counter) {
|
||||
}
|
||||
|
||||
void
|
||||
sc_fps_counter_destroy(struct sc_fps_counter *counter) {
|
||||
fps_counter_destroy(struct fps_counter *counter) {
|
||||
sc_cond_destroy(&counter->state_cond);
|
||||
sc_mutex_destroy(&counter->mutex);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
is_started(struct sc_fps_counter *counter) {
|
||||
is_started(struct fps_counter *counter) {
|
||||
return atomic_load_explicit(&counter->started, memory_order_acquire);
|
||||
}
|
||||
|
||||
static inline void
|
||||
set_started(struct sc_fps_counter *counter, bool started) {
|
||||
set_started(struct fps_counter *counter, bool started) {
|
||||
atomic_store_explicit(&counter->started, started, memory_order_release);
|
||||
}
|
||||
|
||||
// must be called with mutex locked
|
||||
static void
|
||||
display_fps(struct sc_fps_counter *counter) {
|
||||
display_fps(struct fps_counter *counter) {
|
||||
unsigned rendered_per_second =
|
||||
counter->nr_rendered * SC_TICK_FREQ / SC_FPS_COUNTER_INTERVAL;
|
||||
counter->nr_rendered * SC_TICK_FREQ / FPS_COUNTER_INTERVAL;
|
||||
if (counter->nr_skipped) {
|
||||
LOGI("%u fps (+%u frames skipped)", rendered_per_second,
|
||||
counter->nr_skipped);
|
||||
@ -57,7 +57,7 @@ display_fps(struct sc_fps_counter *counter) {
|
||||
|
||||
// must be called with mutex locked
|
||||
static void
|
||||
check_interval_expired(struct sc_fps_counter *counter, sc_tick now) {
|
||||
check_interval_expired(struct fps_counter *counter, uint32_t now) {
|
||||
if (now < counter->next_timestamp) {
|
||||
return;
|
||||
}
|
||||
@ -67,13 +67,13 @@ check_interval_expired(struct sc_fps_counter *counter, sc_tick now) {
|
||||
counter->nr_skipped = 0;
|
||||
// add a multiple of the interval
|
||||
uint32_t elapsed_slices =
|
||||
(now - counter->next_timestamp) / SC_FPS_COUNTER_INTERVAL + 1;
|
||||
counter->next_timestamp += SC_FPS_COUNTER_INTERVAL * elapsed_slices;
|
||||
(now - counter->next_timestamp) / FPS_COUNTER_INTERVAL + 1;
|
||||
counter->next_timestamp += FPS_COUNTER_INTERVAL * elapsed_slices;
|
||||
}
|
||||
|
||||
static int
|
||||
run_fps_counter(void *data) {
|
||||
struct sc_fps_counter *counter = data;
|
||||
struct fps_counter *counter = data;
|
||||
|
||||
sc_mutex_lock(&counter->mutex);
|
||||
while (!counter->interrupted) {
|
||||
@ -94,9 +94,9 @@ run_fps_counter(void *data) {
|
||||
}
|
||||
|
||||
bool
|
||||
sc_fps_counter_start(struct sc_fps_counter *counter) {
|
||||
fps_counter_start(struct fps_counter *counter) {
|
||||
sc_mutex_lock(&counter->mutex);
|
||||
counter->next_timestamp = sc_tick_now() + SC_FPS_COUNTER_INTERVAL;
|
||||
counter->next_timestamp = sc_tick_now() + FPS_COUNTER_INTERVAL;
|
||||
counter->nr_rendered = 0;
|
||||
counter->nr_skipped = 0;
|
||||
sc_mutex_unlock(&counter->mutex);
|
||||
@ -117,24 +117,22 @@ sc_fps_counter_start(struct sc_fps_counter *counter) {
|
||||
counter->thread_started = true;
|
||||
}
|
||||
|
||||
LOGI("FPS counter started");
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
sc_fps_counter_stop(struct sc_fps_counter *counter) {
|
||||
fps_counter_stop(struct fps_counter *counter) {
|
||||
set_started(counter, false);
|
||||
sc_cond_signal(&counter->state_cond);
|
||||
LOGI("FPS counter stopped");
|
||||
}
|
||||
|
||||
bool
|
||||
sc_fps_counter_is_started(struct sc_fps_counter *counter) {
|
||||
fps_counter_is_started(struct fps_counter *counter) {
|
||||
return is_started(counter);
|
||||
}
|
||||
|
||||
void
|
||||
sc_fps_counter_interrupt(struct sc_fps_counter *counter) {
|
||||
fps_counter_interrupt(struct fps_counter *counter) {
|
||||
if (!counter->thread_started) {
|
||||
return;
|
||||
}
|
||||
@ -147,7 +145,7 @@ sc_fps_counter_interrupt(struct sc_fps_counter *counter) {
|
||||
}
|
||||
|
||||
void
|
||||
sc_fps_counter_join(struct sc_fps_counter *counter) {
|
||||
fps_counter_join(struct fps_counter *counter) {
|
||||
if (counter->thread_started) {
|
||||
// interrupted must be set by the thread calling join(), so no need to
|
||||
// lock for the assertion
|
||||
@ -158,7 +156,7 @@ sc_fps_counter_join(struct sc_fps_counter *counter) {
|
||||
}
|
||||
|
||||
void
|
||||
sc_fps_counter_add_rendered_frame(struct sc_fps_counter *counter) {
|
||||
fps_counter_add_rendered_frame(struct fps_counter *counter) {
|
||||
if (!is_started(counter)) {
|
||||
return;
|
||||
}
|
||||
@ -171,7 +169,7 @@ sc_fps_counter_add_rendered_frame(struct sc_fps_counter *counter) {
|
||||
}
|
||||
|
||||
void
|
||||
sc_fps_counter_add_skipped_frame(struct sc_fps_counter *counter) {
|
||||
fps_counter_add_skipped_frame(struct fps_counter *counter) {
|
||||
if (!is_started(counter)) {
|
||||
return;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#include "util/thread.h"
|
||||
|
||||
struct sc_fps_counter {
|
||||
struct fps_counter {
|
||||
sc_thread thread;
|
||||
sc_mutex mutex;
|
||||
sc_cond state_cond;
|
||||
@ -28,32 +28,32 @@ struct sc_fps_counter {
|
||||
};
|
||||
|
||||
bool
|
||||
sc_fps_counter_init(struct sc_fps_counter *counter);
|
||||
fps_counter_init(struct fps_counter *counter);
|
||||
|
||||
void
|
||||
sc_fps_counter_destroy(struct sc_fps_counter *counter);
|
||||
fps_counter_destroy(struct fps_counter *counter);
|
||||
|
||||
bool
|
||||
sc_fps_counter_start(struct sc_fps_counter *counter);
|
||||
fps_counter_start(struct fps_counter *counter);
|
||||
|
||||
void
|
||||
sc_fps_counter_stop(struct sc_fps_counter *counter);
|
||||
fps_counter_stop(struct fps_counter *counter);
|
||||
|
||||
bool
|
||||
sc_fps_counter_is_started(struct sc_fps_counter *counter);
|
||||
fps_counter_is_started(struct fps_counter *counter);
|
||||
|
||||
// request to stop the thread (on quit)
|
||||
// must be called before sc_fps_counter_join()
|
||||
// must be called before fps_counter_join()
|
||||
void
|
||||
sc_fps_counter_interrupt(struct sc_fps_counter *counter);
|
||||
fps_counter_interrupt(struct fps_counter *counter);
|
||||
|
||||
void
|
||||
sc_fps_counter_join(struct sc_fps_counter *counter);
|
||||
fps_counter_join(struct fps_counter *counter);
|
||||
|
||||
void
|
||||
sc_fps_counter_add_rendered_frame(struct sc_fps_counter *counter);
|
||||
fps_counter_add_rendered_frame(struct fps_counter *counter);
|
||||
|
||||
void
|
||||
sc_fps_counter_add_skipped_frame(struct sc_fps_counter *counter);
|
||||
fps_counter_add_skipped_frame(struct fps_counter *counter);
|
||||
|
||||
#endif
|
||||
|
@ -242,14 +242,18 @@ set_screen_power_mode(struct sc_controller *controller,
|
||||
}
|
||||
|
||||
static void
|
||||
switch_fps_counter_state(struct sc_fps_counter *fps_counter) {
|
||||
switch_fps_counter_state(struct fps_counter *fps_counter) {
|
||||
// the started state can only be written from the current thread, so there
|
||||
// is no ToCToU issue
|
||||
if (sc_fps_counter_is_started(fps_counter)) {
|
||||
sc_fps_counter_stop(fps_counter);
|
||||
if (fps_counter_is_started(fps_counter)) {
|
||||
fps_counter_stop(fps_counter);
|
||||
LOGI("FPS counter stopped");
|
||||
} else {
|
||||
sc_fps_counter_start(fps_counter);
|
||||
// Any error is already logged
|
||||
if (fps_counter_start(fps_counter)) {
|
||||
LOGI("FPS counter started");
|
||||
} else {
|
||||
LOGE("FPS counter starting failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,27 @@
|
||||
#include "scrcpy.h"
|
||||
#include "usb/scrcpy_otg.h"
|
||||
#include "util/log.h"
|
||||
#include "version.h"
|
||||
|
||||
static void
|
||||
print_version(void) {
|
||||
printf("\ndependencies:\n");
|
||||
printf(" - SDL %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION,
|
||||
SDL_PATCHLEVEL);
|
||||
printf(" - libavcodec %d.%d.%d\n", LIBAVCODEC_VERSION_MAJOR,
|
||||
LIBAVCODEC_VERSION_MINOR,
|
||||
LIBAVCODEC_VERSION_MICRO);
|
||||
printf(" - libavformat %d.%d.%d\n", LIBAVFORMAT_VERSION_MAJOR,
|
||||
LIBAVFORMAT_VERSION_MINOR,
|
||||
LIBAVFORMAT_VERSION_MICRO);
|
||||
printf(" - libavutil %d.%d.%d\n", LIBAVUTIL_VERSION_MAJOR,
|
||||
LIBAVUTIL_VERSION_MINOR,
|
||||
LIBAVUTIL_VERSION_MICRO);
|
||||
#ifdef HAVE_V4L2
|
||||
printf(" - libavdevice %d.%d.%d\n", LIBAVDEVICE_VERSION_MAJOR,
|
||||
LIBAVDEVICE_VERSION_MINOR,
|
||||
LIBAVDEVICE_VERSION_MICRO);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
@ -40,19 +60,19 @@ main(int argc, char *argv[]) {
|
||||
#endif
|
||||
|
||||
if (!scrcpy_parse_args(&args, argc, argv)) {
|
||||
return SCRCPY_EXIT_FAILURE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sc_set_log_level(args.opts.log_level);
|
||||
|
||||
if (args.help) {
|
||||
scrcpy_print_usage(argv[0]);
|
||||
return SCRCPY_EXIT_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (args.version) {
|
||||
scrcpy_print_version();
|
||||
return SCRCPY_EXIT_SUCCESS;
|
||||
print_version();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
|
||||
@ -66,17 +86,17 @@ main(int argc, char *argv[]) {
|
||||
#endif
|
||||
|
||||
if (avformat_network_init()) {
|
||||
return SCRCPY_EXIT_FAILURE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef HAVE_USB
|
||||
enum scrcpy_exit_code ret = args.opts.otg ? scrcpy_otg(&args.opts)
|
||||
: scrcpy(&args.opts);
|
||||
bool ok = args.opts.otg ? scrcpy_otg(&args.opts)
|
||||
: scrcpy(&args.opts);
|
||||
#else
|
||||
enum scrcpy_exit_code ret = scrcpy(&args.opts);
|
||||
bool ok = scrcpy(&args.opts);
|
||||
#endif
|
||||
|
||||
avformat_network_deinit(); // ignore failure
|
||||
|
||||
return ret;
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
|
@ -62,6 +62,4 @@ const struct scrcpy_options scrcpy_options_default = {
|
||||
.tcpip_dst = NULL,
|
||||
.select_tcpip = false,
|
||||
.select_usb = false,
|
||||
.cleanup = true,
|
||||
.start_fps_counter = false,
|
||||
};
|
||||
|
@ -137,8 +137,6 @@ struct scrcpy_options {
|
||||
const char *tcpip_dst;
|
||||
bool select_usb;
|
||||
bool select_tcpip;
|
||||
bool cleanup;
|
||||
bool start_fps_counter;
|
||||
};
|
||||
|
||||
extern const struct scrcpy_options scrcpy_options_default;
|
||||
|
@ -149,41 +149,38 @@ sdl_configure(bool display, bool disable_screensaver) {
|
||||
}
|
||||
}
|
||||
|
||||
static enum scrcpy_exit_code
|
||||
static bool
|
||||
event_loop(struct scrcpy *s) {
|
||||
SDL_Event event;
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case EVENT_STREAM_STOPPED:
|
||||
LOGW("Device disconnected");
|
||||
return SCRCPY_EXIT_DISCONNECTED;
|
||||
return false;
|
||||
case SDL_QUIT:
|
||||
LOGD("User requested to quit");
|
||||
return SCRCPY_EXIT_SUCCESS;
|
||||
return true;
|
||||
default:
|
||||
sc_screen_handle_event(&s->screen, &event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return SCRCPY_EXIT_FAILURE;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return true on success, false on error
|
||||
static bool
|
||||
await_for_server(bool *connected) {
|
||||
await_for_server(void) {
|
||||
SDL_Event event;
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
LOGD("User requested to quit");
|
||||
*connected = false;
|
||||
return true;
|
||||
return false;
|
||||
case EVENT_SERVER_CONNECTION_FAILED:
|
||||
LOGE("Server connection failed");
|
||||
return false;
|
||||
case EVENT_SERVER_CONNECTED:
|
||||
LOGD("Server connected");
|
||||
*connected = true;
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
@ -265,7 +262,7 @@ sc_server_on_disconnected(struct sc_server *server, void *userdata) {
|
||||
// event
|
||||
}
|
||||
|
||||
enum scrcpy_exit_code
|
||||
bool
|
||||
scrcpy(struct scrcpy_options *options) {
|
||||
static struct scrcpy scrcpy;
|
||||
struct scrcpy *s = &scrcpy;
|
||||
@ -273,12 +270,12 @@ scrcpy(struct scrcpy_options *options) {
|
||||
// Minimal SDL initialization
|
||||
if (SDL_Init(SDL_INIT_EVENTS)) {
|
||||
LOGE("Could not initialize SDL: %s", SDL_GetError());
|
||||
return SCRCPY_EXIT_FAILURE;
|
||||
return false;
|
||||
}
|
||||
|
||||
atexit(SDL_Quit);
|
||||
|
||||
enum scrcpy_exit_code ret = SCRCPY_EXIT_FAILURE;
|
||||
bool ret = false;
|
||||
|
||||
bool server_started = false;
|
||||
bool file_pusher_initialized = false;
|
||||
@ -323,7 +320,6 @@ scrcpy(struct scrcpy_options *options) {
|
||||
.downsize_on_error = options->downsize_on_error,
|
||||
.tcpip = options->tcpip,
|
||||
.tcpip_dst = options->tcpip_dst,
|
||||
.cleanup = options->cleanup,
|
||||
};
|
||||
|
||||
static const struct sc_server_callbacks cbs = {
|
||||
@ -332,7 +328,7 @@ scrcpy(struct scrcpy_options *options) {
|
||||
.on_disconnected = sc_server_on_disconnected,
|
||||
};
|
||||
if (!sc_server_init(&s->server, ¶ms, &cbs, NULL)) {
|
||||
return SCRCPY_EXIT_FAILURE;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sc_server_start(&s->server)) {
|
||||
@ -354,14 +350,7 @@ scrcpy(struct scrcpy_options *options) {
|
||||
sdl_configure(options->display, options->disable_screensaver);
|
||||
|
||||
// Await for server without blocking Ctrl+C handling
|
||||
bool connected;
|
||||
if (!await_for_server(&connected)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!connected) {
|
||||
// This is not an error, user requested to quit
|
||||
ret = SCRCPY_EXIT_SUCCESS;
|
||||
if (!await_for_server()) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
@ -598,7 +587,6 @@ aoa_hid_end:
|
||||
.rotation = options->rotation,
|
||||
.mipmaps = options->mipmaps,
|
||||
.fullscreen = options->fullscreen,
|
||||
.start_fps_counter = options->start_fps_counter,
|
||||
.buffering_time = options->display_buffer,
|
||||
};
|
||||
|
||||
|
@ -6,18 +6,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "options.h"
|
||||
|
||||
enum scrcpy_exit_code {
|
||||
// Normal program termination
|
||||
SCRCPY_EXIT_SUCCESS,
|
||||
|
||||
// No connection could be established
|
||||
SCRCPY_EXIT_FAILURE,
|
||||
|
||||
// Device was disconnected while running
|
||||
SCRCPY_EXIT_DISCONNECTED,
|
||||
};
|
||||
|
||||
enum scrcpy_exit_code
|
||||
bool
|
||||
scrcpy(struct scrcpy_options *options);
|
||||
|
||||
#endif
|
||||
|
@ -163,44 +163,14 @@ sc_screen_is_relative_mode(struct sc_screen *screen) {
|
||||
}
|
||||
|
||||
static void
|
||||
sc_screen_set_mouse_capture(struct sc_screen *screen, bool capture) {
|
||||
#ifdef __APPLE__
|
||||
// Workaround for SDL bug on macOS:
|
||||
// <https://github.com/libsdl-org/SDL/issues/5340>
|
||||
if (capture) {
|
||||
int mouse_x, mouse_y;
|
||||
SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
|
||||
|
||||
int x, y, w, h;
|
||||
SDL_GetWindowPosition(screen->window, &x, &y);
|
||||
SDL_GetWindowSize(screen->window, &w, &h);
|
||||
|
||||
bool outside_window = mouse_x < x || mouse_x >= x + w
|
||||
|| mouse_y < y || mouse_y >= y + h;
|
||||
if (outside_window) {
|
||||
SDL_WarpMouseInWindow(screen->window, w / 2, h / 2);
|
||||
}
|
||||
}
|
||||
#else
|
||||
(void) screen;
|
||||
#endif
|
||||
sc_screen_capture_mouse(struct sc_screen *screen, bool capture) {
|
||||
if (SDL_SetRelativeMouseMode(capture)) {
|
||||
LOGE("Could not set relative mouse mode to %s: %s",
|
||||
capture ? "true" : "false", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool
|
||||
sc_screen_get_mouse_capture(struct sc_screen *screen) {
|
||||
(void) screen;
|
||||
return SDL_GetRelativeMouseMode();
|
||||
}
|
||||
|
||||
static inline void
|
||||
sc_screen_toggle_mouse_capture(struct sc_screen *screen) {
|
||||
(void) screen;
|
||||
bool new_value = !sc_screen_get_mouse_capture(screen);
|
||||
sc_screen_set_mouse_capture(screen, new_value);
|
||||
screen->mouse_captured = capture;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -370,7 +340,7 @@ sc_video_buffer_on_new_frame(struct sc_video_buffer *vb, bool previous_skipped,
|
||||
|
||||
bool need_new_event;
|
||||
if (previous_skipped) {
|
||||
sc_fps_counter_add_skipped_frame(&screen->fps_counter);
|
||||
fps_counter_add_skipped_frame(&screen->fps_counter);
|
||||
// The EVENT_NEW_FRAME triggered for the previous frame will consume
|
||||
// this new frame instead, unless the previous event failed
|
||||
need_new_event = screen->event_failed;
|
||||
@ -402,6 +372,7 @@ sc_screen_init(struct sc_screen *screen,
|
||||
screen->fullscreen = false;
|
||||
screen->maximized = false;
|
||||
screen->event_failed = false;
|
||||
screen->mouse_captured = false;
|
||||
screen->mouse_capture_key_pressed = 0;
|
||||
|
||||
screen->req.x = params->window_x;
|
||||
@ -409,7 +380,6 @@ sc_screen_init(struct sc_screen *screen,
|
||||
screen->req.width = params->window_width;
|
||||
screen->req.height = params->window_height;
|
||||
screen->req.fullscreen = params->fullscreen;
|
||||
screen->req.start_fps_counter = params->start_fps_counter;
|
||||
|
||||
static const struct sc_video_buffer_callbacks cbs = {
|
||||
.on_new_frame = sc_video_buffer_on_new_frame,
|
||||
@ -426,7 +396,7 @@ sc_screen_init(struct sc_screen *screen,
|
||||
goto error_destroy_video_buffer;
|
||||
}
|
||||
|
||||
if (!sc_fps_counter_init(&screen->fps_counter)) {
|
||||
if (!fps_counter_init(&screen->fps_counter)) {
|
||||
goto error_stop_and_join_video_buffer;
|
||||
}
|
||||
|
||||
@ -558,7 +528,7 @@ error_destroy_renderer:
|
||||
error_destroy_window:
|
||||
SDL_DestroyWindow(screen->window);
|
||||
error_destroy_fps_counter:
|
||||
sc_fps_counter_destroy(&screen->fps_counter);
|
||||
fps_counter_destroy(&screen->fps_counter);
|
||||
error_stop_and_join_video_buffer:
|
||||
sc_video_buffer_stop(&screen->vb);
|
||||
sc_video_buffer_join(&screen->vb);
|
||||
@ -586,10 +556,6 @@ sc_screen_show_initial_window(struct sc_screen *screen) {
|
||||
sc_screen_switch_fullscreen(screen);
|
||||
}
|
||||
|
||||
if (screen->req.start_fps_counter) {
|
||||
sc_fps_counter_start(&screen->fps_counter);
|
||||
}
|
||||
|
||||
SDL_ShowWindow(screen->window);
|
||||
}
|
||||
|
||||
@ -601,13 +567,13 @@ sc_screen_hide_window(struct sc_screen *screen) {
|
||||
void
|
||||
sc_screen_interrupt(struct sc_screen *screen) {
|
||||
sc_video_buffer_stop(&screen->vb);
|
||||
sc_fps_counter_interrupt(&screen->fps_counter);
|
||||
fps_counter_interrupt(&screen->fps_counter);
|
||||
}
|
||||
|
||||
void
|
||||
sc_screen_join(struct sc_screen *screen) {
|
||||
sc_video_buffer_join(&screen->vb);
|
||||
sc_fps_counter_join(&screen->fps_counter);
|
||||
fps_counter_join(&screen->fps_counter);
|
||||
}
|
||||
|
||||
void
|
||||
@ -619,7 +585,7 @@ sc_screen_destroy(struct sc_screen *screen) {
|
||||
SDL_DestroyTexture(screen->texture);
|
||||
SDL_DestroyRenderer(screen->renderer);
|
||||
SDL_DestroyWindow(screen->window);
|
||||
sc_fps_counter_destroy(&screen->fps_counter);
|
||||
fps_counter_destroy(&screen->fps_counter);
|
||||
sc_video_buffer_destroy(&screen->vb);
|
||||
}
|
||||
|
||||
@ -729,7 +695,7 @@ sc_screen_update_frame(struct sc_screen *screen) {
|
||||
sc_video_buffer_consume(&screen->vb, screen->frame);
|
||||
AVFrame *frame = screen->frame;
|
||||
|
||||
sc_fps_counter_add_rendered_frame(&screen->fps_counter);
|
||||
fps_counter_add_rendered_frame(&screen->fps_counter);
|
||||
|
||||
struct sc_size new_frame_size = {frame->width, frame->height};
|
||||
if (!prepare_for_frame(screen, new_frame_size)) {
|
||||
@ -744,7 +710,7 @@ sc_screen_update_frame(struct sc_screen *screen) {
|
||||
|
||||
if (sc_screen_is_relative_mode(screen)) {
|
||||
// Capture mouse on start
|
||||
sc_screen_set_mouse_capture(screen, true);
|
||||
sc_screen_capture_mouse(screen, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -857,7 +823,7 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
if (relative_mode) {
|
||||
sc_screen_set_mouse_capture(screen, false);
|
||||
sc_screen_capture_mouse(screen, false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -887,7 +853,8 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
|
||||
if (key == cap) {
|
||||
// A mouse capture key has been pressed then released:
|
||||
// toggle the capture mouse mode
|
||||
sc_screen_toggle_mouse_capture(screen);
|
||||
sc_screen_capture_mouse(screen,
|
||||
!screen->mouse_captured);
|
||||
}
|
||||
// Mouse capture keys are never forwarded to the device
|
||||
return;
|
||||
@ -897,7 +864,7 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
|
||||
case SDL_MOUSEWHEEL:
|
||||
case SDL_MOUSEMOTION:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if (relative_mode && !sc_screen_get_mouse_capture(screen)) {
|
||||
if (relative_mode && !screen->mouse_captured) {
|
||||
// Do not forward to input manager, the mouse will be captured
|
||||
// on SDL_MOUSEBUTTONUP
|
||||
return;
|
||||
@ -913,8 +880,8 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (relative_mode && !sc_screen_get_mouse_capture(screen)) {
|
||||
sc_screen_set_mouse_capture(screen, true);
|
||||
if (relative_mode && !screen->mouse_captured) {
|
||||
sc_screen_capture_mouse(screen, true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
@ -26,7 +26,7 @@ struct sc_screen {
|
||||
|
||||
struct sc_input_manager im;
|
||||
struct sc_video_buffer vb;
|
||||
struct sc_fps_counter fps_counter;
|
||||
struct fps_counter fps_counter;
|
||||
|
||||
// The initial requested window properties
|
||||
struct {
|
||||
@ -35,7 +35,6 @@ struct sc_screen {
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
bool fullscreen;
|
||||
bool start_fps_counter;
|
||||
} req;
|
||||
|
||||
SDL_Window *window;
|
||||
@ -61,6 +60,7 @@ struct sc_screen {
|
||||
|
||||
bool event_failed; // in case SDL_PushEvent() returned an error
|
||||
|
||||
bool mouse_captured; // only relevant in relative mouse mode
|
||||
// To enable/disable mouse capture, a mouse capture key (LALT, LGUI or
|
||||
// RGUI) must be pressed. This variable tracks the pressed capture key.
|
||||
SDL_Keycode mouse_capture_key_pressed;
|
||||
@ -94,7 +94,6 @@ struct sc_screen_params {
|
||||
bool mipmaps;
|
||||
|
||||
bool fullscreen;
|
||||
bool start_fps_counter;
|
||||
|
||||
sc_tick buffering_time;
|
||||
};
|
||||
|
@ -244,10 +244,6 @@ execute_server(struct sc_server *server,
|
||||
// By default, downsize_on_error is true
|
||||
ADD_PARAM("downsize_on_error=false");
|
||||
}
|
||||
if (!params->cleanup) {
|
||||
// By default, cleanup is true
|
||||
ADD_PARAM("cleanup=false");
|
||||
}
|
||||
|
||||
#undef ADD_PARAM
|
||||
|
||||
@ -486,10 +482,8 @@ fail:
|
||||
}
|
||||
}
|
||||
|
||||
if (tunnel->enabled) {
|
||||
// Always leave this function with tunnel disabled
|
||||
sc_adb_tunnel_close(tunnel, &server->intr, serial);
|
||||
}
|
||||
// Always leave this function with tunnel disabled
|
||||
sc_adb_tunnel_close(tunnel, &server->intr, serial);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ struct sc_server_params {
|
||||
const char *tcpip_dst;
|
||||
bool select_usb;
|
||||
bool select_tcpip;
|
||||
bool cleanup;
|
||||
};
|
||||
|
||||
struct sc_server {
|
||||
|
@ -95,7 +95,6 @@ sc_aoa_register_hid(struct sc_aoa *aoa, uint16_t accessory_id,
|
||||
DEFAULT_TIMEOUT);
|
||||
if (result < 0) {
|
||||
LOGE("REGISTER_HID: libusb error: %s", libusb_strerror(result));
|
||||
sc_usb_check_disconnected(aoa->usb, result);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -132,7 +131,6 @@ sc_aoa_set_hid_report_desc(struct sc_aoa *aoa, uint16_t accessory_id,
|
||||
DEFAULT_TIMEOUT);
|
||||
if (result < 0) {
|
||||
LOGE("SET_HID_REPORT_DESC: libusb error: %s", libusb_strerror(result));
|
||||
sc_usb_check_disconnected(aoa->usb, result);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -175,7 +173,6 @@ sc_aoa_send_hid_event(struct sc_aoa *aoa, const struct sc_hid_event *event) {
|
||||
DEFAULT_TIMEOUT);
|
||||
if (result < 0) {
|
||||
LOGE("SEND_HID_EVENT: libusb error: %s", libusb_strerror(result));
|
||||
sc_usb_check_disconnected(aoa->usb, result);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -198,7 +195,6 @@ sc_aoa_unregister_hid(struct sc_aoa *aoa, const uint16_t accessory_id) {
|
||||
DEFAULT_TIMEOUT);
|
||||
if (result < 0) {
|
||||
LOGE("UNREGISTER_HID: libusb error: %s", libusb_strerror(result));
|
||||
sc_usb_check_disconnected(aoa->usb, result);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -340,7 +340,7 @@ push_mod_lock_state(struct sc_hid_keyboard *kb, uint16_t mods_state) {
|
||||
|
||||
if (!sc_aoa_push_hid_event(kb->aoa, &hid_event)) {
|
||||
sc_hid_event_destroy(&hid_event);
|
||||
LOGW("Could not request HID event (mod lock state)");
|
||||
LOGW("Could request HID event");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -382,7 +382,7 @@ sc_key_processor_process_key(struct sc_key_processor *kp,
|
||||
|
||||
if (!sc_aoa_push_hid_event(kb->aoa, &hid_event)) {
|
||||
sc_hid_event_destroy(&hid_event);
|
||||
LOGW("Could not request HID event (key)");
|
||||
LOGW("Could request HID event");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
|
||||
|
||||
if (!sc_aoa_push_hid_event(mouse->aoa, &hid_event)) {
|
||||
sc_hid_event_destroy(&hid_event);
|
||||
LOGW("Could not request HID event (mouse motion)");
|
||||
LOGW("Could request HID event");
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,7 +203,7 @@ sc_mouse_processor_process_mouse_click(struct sc_mouse_processor *mp,
|
||||
|
||||
if (!sc_aoa_push_hid_event(mouse->aoa, &hid_event)) {
|
||||
sc_hid_event_destroy(&hid_event);
|
||||
LOGW("Could not request HID event (mouse click)");
|
||||
LOGW("Could request HID event");
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,7 +228,7 @@ sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,
|
||||
|
||||
if (!sc_aoa_push_hid_event(mouse->aoa, &hid_event)) {
|
||||
sc_hid_event_destroy(&hid_event);
|
||||
LOGW("Could not request HID event (mouse scroll)");
|
||||
LOGW("Could request HID event");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "adb/adb.h"
|
||||
#include "events.h"
|
||||
#include "screen_otg.h"
|
||||
#include "util/log.h"
|
||||
@ -29,26 +28,26 @@ sc_usb_on_disconnected(struct sc_usb *usb, void *userdata) {
|
||||
}
|
||||
}
|
||||
|
||||
static enum scrcpy_exit_code
|
||||
static bool
|
||||
event_loop(struct scrcpy_otg *s) {
|
||||
SDL_Event event;
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case EVENT_USB_DEVICE_DISCONNECTED:
|
||||
LOGW("Device disconnected");
|
||||
return SCRCPY_EXIT_DISCONNECTED;
|
||||
return false;
|
||||
case SDL_QUIT:
|
||||
LOGD("User requested to quit");
|
||||
return SCRCPY_EXIT_SUCCESS;
|
||||
return true;
|
||||
default:
|
||||
sc_screen_otg_handle_event(&s->screen_otg, &event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return SCRCPY_EXIT_FAILURE;
|
||||
return false;
|
||||
}
|
||||
|
||||
enum scrcpy_exit_code
|
||||
bool
|
||||
scrcpy_otg(struct scrcpy_options *options) {
|
||||
static struct scrcpy_otg scrcpy_otg;
|
||||
struct scrcpy_otg *s = &scrcpy_otg;
|
||||
@ -67,7 +66,7 @@ scrcpy_otg(struct scrcpy_options *options) {
|
||||
LOGW("Could not enable mouse focus clickthrough");
|
||||
}
|
||||
|
||||
enum scrcpy_exit_code ret = SCRCPY_EXIT_FAILURE;
|
||||
bool ret = false;
|
||||
|
||||
struct sc_hid_keyboard *keyboard = NULL;
|
||||
struct sc_hid_mouse *mouse = NULL;
|
||||
@ -76,21 +75,12 @@ scrcpy_otg(struct scrcpy_options *options) {
|
||||
bool aoa_started = false;
|
||||
bool aoa_initialized = false;
|
||||
|
||||
#ifdef _WIN32
|
||||
// On Windows, only one process could open a USB device
|
||||
// <https://github.com/Genymobile/scrcpy/issues/2773>
|
||||
LOGI("Killing adb daemon (if any)...");
|
||||
unsigned flags = SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR;
|
||||
// uninterruptible (intr == NULL), but in practice it's very quick
|
||||
sc_adb_kill_server(NULL, flags);
|
||||
#endif
|
||||
|
||||
static const struct sc_usb_callbacks cbs = {
|
||||
.on_disconnected = sc_usb_on_disconnected,
|
||||
};
|
||||
bool ok = sc_usb_init(&s->usb);
|
||||
if (!ok) {
|
||||
return SCRCPY_EXIT_FAILURE;
|
||||
return false;
|
||||
}
|
||||
|
||||
struct sc_usb_device usb_device;
|
||||
@ -99,8 +89,6 @@ scrcpy_otg(struct scrcpy_options *options) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -3,10 +3,10 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "options.h"
|
||||
#include "scrcpy.h"
|
||||
|
||||
enum scrcpy_exit_code
|
||||
bool
|
||||
scrcpy_otg(struct scrcpy_options *options);
|
||||
|
||||
#endif
|
||||
|
@ -5,44 +5,15 @@
|
||||
#include "util/log.h"
|
||||
|
||||
static void
|
||||
sc_screen_otg_set_mouse_capture(struct sc_screen_otg *screen, bool capture) {
|
||||
#ifdef __APPLE__
|
||||
// Workaround for SDL bug on macOS:
|
||||
// <https://github.com/libsdl-org/SDL/issues/5340>
|
||||
if (capture) {
|
||||
int mouse_x, mouse_y;
|
||||
SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
|
||||
|
||||
int x, y, w, h;
|
||||
SDL_GetWindowPosition(screen->window, &x, &y);
|
||||
SDL_GetWindowSize(screen->window, &w, &h);
|
||||
|
||||
bool outside_window = mouse_x < x || mouse_x >= x + w
|
||||
|| mouse_y < y || mouse_y >= y + h;
|
||||
if (outside_window) {
|
||||
SDL_WarpMouseInWindow(screen->window, w / 2, h / 2);
|
||||
}
|
||||
}
|
||||
#else
|
||||
(void) screen;
|
||||
#endif
|
||||
sc_screen_otg_capture_mouse(struct sc_screen_otg *screen, bool capture) {
|
||||
assert(screen->mouse);
|
||||
if (SDL_SetRelativeMouseMode(capture)) {
|
||||
LOGE("Could not set relative mouse mode to %s: %s",
|
||||
capture ? "true" : "false", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool
|
||||
sc_screen_otg_get_mouse_capture(struct sc_screen_otg *screen) {
|
||||
(void) screen;
|
||||
return SDL_GetRelativeMouseMode();
|
||||
}
|
||||
|
||||
static inline void
|
||||
sc_screen_otg_toggle_mouse_capture(struct sc_screen_otg *screen) {
|
||||
(void) screen;
|
||||
bool new_value = !sc_screen_otg_get_mouse_capture(screen);
|
||||
sc_screen_otg_set_mouse_capture(screen, new_value);
|
||||
screen->mouse_captured = capture;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -60,6 +31,7 @@ sc_screen_otg_init(struct sc_screen_otg *screen,
|
||||
screen->keyboard = params->keyboard;
|
||||
screen->mouse = params->mouse;
|
||||
|
||||
screen->mouse_captured = false;
|
||||
screen->mouse_capture_key_pressed = 0;
|
||||
|
||||
const char *title = params->window_title;
|
||||
@ -109,7 +81,7 @@ sc_screen_otg_init(struct sc_screen_otg *screen,
|
||||
|
||||
if (screen->mouse) {
|
||||
// Capture mouse on start
|
||||
sc_screen_otg_set_mouse_capture(screen, true);
|
||||
sc_screen_otg_capture_mouse(screen, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -221,7 +193,7 @@ sc_screen_otg_handle_event(struct sc_screen_otg *screen, SDL_Event *event) {
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
if (screen->mouse) {
|
||||
sc_screen_otg_set_mouse_capture(screen, false);
|
||||
sc_screen_otg_capture_mouse(screen, false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -255,7 +227,8 @@ sc_screen_otg_handle_event(struct sc_screen_otg *screen, SDL_Event *event) {
|
||||
if (key == cap) {
|
||||
// A mouse capture key has been pressed then released:
|
||||
// toggle the capture mouse mode
|
||||
sc_screen_otg_toggle_mouse_capture(screen);
|
||||
sc_screen_otg_capture_mouse(screen,
|
||||
!screen->mouse_captured);
|
||||
}
|
||||
// Mouse capture keys are never forwarded to the device
|
||||
return;
|
||||
@ -267,26 +240,26 @@ sc_screen_otg_handle_event(struct sc_screen_otg *screen, SDL_Event *event) {
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
if (screen->mouse && sc_screen_otg_get_mouse_capture(screen)) {
|
||||
if (screen->mouse && screen->mouse_captured) {
|
||||
sc_screen_otg_process_mouse_motion(screen, &event->motion);
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if (screen->mouse && sc_screen_otg_get_mouse_capture(screen)) {
|
||||
if (screen->mouse && screen->mouse_captured) {
|
||||
sc_screen_otg_process_mouse_button(screen, &event->button);
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (screen->mouse) {
|
||||
if (sc_screen_otg_get_mouse_capture(screen)) {
|
||||
if (screen->mouse_captured) {
|
||||
sc_screen_otg_process_mouse_button(screen, &event->button);
|
||||
} else {
|
||||
sc_screen_otg_set_mouse_capture(screen, true);
|
||||
sc_screen_otg_capture_mouse(screen, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
if (screen->mouse && sc_screen_otg_get_mouse_capture(screen)) {
|
||||
if (screen->mouse && screen->mouse_captured) {
|
||||
sc_screen_otg_process_mouse_wheel(screen, &event->wheel);
|
||||
}
|
||||
break;
|
||||
|
@ -18,6 +18,7 @@ struct sc_screen_otg {
|
||||
SDL_Texture *texture;
|
||||
|
||||
// See equivalent mechanism in screen.h
|
||||
bool mouse_captured;
|
||||
SDL_Keycode mouse_capture_key_pressed;
|
||||
};
|
||||
|
||||
|
@ -3,9 +3,6 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "util/log.h"
|
||||
#include "util/vector.h"
|
||||
|
||||
struct sc_vec_usb_devices SC_VECTOR(struct sc_usb_device);
|
||||
|
||||
static char *
|
||||
read_string(libusb_device_handle *handle, uint8_t desc_index) {
|
||||
@ -15,7 +12,6 @@ read_string(libusb_device_handle *handle, uint8_t desc_index) {
|
||||
(unsigned char *) buffer,
|
||||
sizeof(buffer));
|
||||
if (result < 0) {
|
||||
LOGD("Read string: libusb error: %s", libusb_strerror(result));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -89,39 +85,33 @@ sc_usb_device_move(struct sc_usb_device *dst, struct sc_usb_device *src) {
|
||||
}
|
||||
|
||||
void
|
||||
sc_usb_devices_destroy(struct sc_vec_usb_devices *usb_devices) {
|
||||
for (size_t i = 0; i < usb_devices->size; ++i) {
|
||||
sc_usb_device_destroy(&usb_devices->data[i]);
|
||||
sc_usb_devices_destroy_all(struct sc_usb_device *usb_devices, size_t count) {
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
sc_usb_device_destroy(&usb_devices[i]);
|
||||
}
|
||||
sc_vector_destroy(usb_devices);
|
||||
}
|
||||
|
||||
static bool
|
||||
sc_usb_list_devices(struct sc_usb *usb, struct sc_vec_usb_devices *out_vec) {
|
||||
static ssize_t
|
||||
sc_usb_list_devices(struct sc_usb *usb, struct sc_usb_device *devices,
|
||||
size_t len) {
|
||||
libusb_device **list;
|
||||
ssize_t count = libusb_get_device_list(usb->context, &list);
|
||||
if (count < 0) {
|
||||
LOGE("List USB devices: libusb error: %s", libusb_strerror(count));
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < (size_t) count; ++i) {
|
||||
size_t idx = 0;
|
||||
for (size_t i = 0; i < (size_t) count && idx < len; ++i) {
|
||||
libusb_device *device = list[i];
|
||||
|
||||
struct sc_usb_device usb_device;
|
||||
if (sc_usb_read_device(device, &usb_device)) {
|
||||
bool ok = sc_vector_push(out_vec, usb_device);
|
||||
if (!ok) {
|
||||
LOG_OOM();
|
||||
LOGE("Could not push usb_device to vector");
|
||||
sc_usb_device_destroy(&usb_device);
|
||||
// continue anyway
|
||||
}
|
||||
if (sc_usb_read_device(device, &devices[idx])) {
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
|
||||
libusb_free_device_list(list, 1);
|
||||
return true;
|
||||
return idx;
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -167,28 +157,29 @@ sc_usb_devices_log(enum sc_log_level level, struct sc_usb_device *devices,
|
||||
bool
|
||||
sc_usb_select_device(struct sc_usb *usb, const char *serial,
|
||||
struct sc_usb_device *out_device) {
|
||||
struct sc_vec_usb_devices vec = SC_VECTOR_INITIALIZER;
|
||||
bool ok = sc_usb_list_devices(usb, &vec);
|
||||
if (!ok) {
|
||||
struct sc_usb_device usb_devices[16];
|
||||
ssize_t count =
|
||||
sc_usb_list_devices(usb, usb_devices, ARRAY_LEN(usb_devices));
|
||||
if (count == -1) {
|
||||
LOGE("Could not list USB devices");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vec.size == 0) {
|
||||
if (count == 0) {
|
||||
LOGE("Could not find any USB device");
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t sel_idx; // index of the single matching device if sel_count == 1
|
||||
size_t sel_count =
|
||||
sc_usb_devices_select(vec.data, vec.size, serial, &sel_idx);
|
||||
sc_usb_devices_select(usb_devices, count, serial, &sel_idx);
|
||||
|
||||
if (sel_count == 0) {
|
||||
// if count > 0 && sel_count == 0, then necessarily a serial is provided
|
||||
assert(serial);
|
||||
LOGE("Could not find USB device %s", serial);
|
||||
sc_usb_devices_log(SC_LOG_LEVEL_ERROR, vec.data, vec.size);
|
||||
sc_usb_devices_destroy(&vec);
|
||||
sc_usb_devices_log(SC_LOG_LEVEL_ERROR, usb_devices, count);
|
||||
sc_usb_devices_destroy_all(usb_devices, count);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -199,21 +190,23 @@ sc_usb_select_device(struct sc_usb *usb, const char *serial,
|
||||
} else {
|
||||
LOGE("Multiple (%" SC_PRIsizet ") USB devices:", sel_count);
|
||||
}
|
||||
sc_usb_devices_log(SC_LOG_LEVEL_ERROR, vec.data, vec.size);
|
||||
LOGE("Select a device via -s (--serial)");
|
||||
sc_usb_devices_destroy(&vec);
|
||||
sc_usb_devices_log(SC_LOG_LEVEL_ERROR, usb_devices, count);
|
||||
if (!serial) {
|
||||
LOGE("Specify the device via -s or --serial");
|
||||
}
|
||||
sc_usb_devices_destroy_all(usb_devices, count);
|
||||
return false;
|
||||
}
|
||||
|
||||
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 = &usb_devices[sel_idx];
|
||||
|
||||
LOGD("USB device found:");
|
||||
sc_usb_devices_log(SC_LOG_LEVEL_DEBUG, vec.data, vec.size);
|
||||
sc_usb_devices_log(SC_LOG_LEVEL_DEBUG, usb_devices, count);
|
||||
|
||||
// Move device into out_device (do not destroy device)
|
||||
sc_usb_device_move(out_device, device);
|
||||
sc_usb_devices_destroy(&vec);
|
||||
sc_usb_devices_destroy_all(usb_devices, count);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -228,24 +221,6 @@ sc_usb_destroy(struct sc_usb *usb) {
|
||||
libusb_exit(usb->context);
|
||||
}
|
||||
|
||||
static void
|
||||
sc_usb_report_disconnected(struct sc_usb *usb) {
|
||||
if (usb->cbs && !atomic_flag_test_and_set(&usb->disconnection_notified)) {
|
||||
assert(usb->cbs && usb->cbs->on_disconnected);
|
||||
usb->cbs->on_disconnected(usb, usb->cbs_userdata);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
sc_usb_check_disconnected(struct sc_usb *usb, int result) {
|
||||
if (result == LIBUSB_ERROR_NO_DEVICE || result == LIBUSB_ERROR_NOT_FOUND) {
|
||||
sc_usb_report_disconnected(usb);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static LIBUSB_CALL int
|
||||
sc_usb_libusb_callback(libusb_context *ctx, libusb_device *device,
|
||||
libusb_hotplug_event event, void *userdata) {
|
||||
@ -262,7 +237,8 @@ sc_usb_libusb_callback(libusb_context *ctx, libusb_device *device,
|
||||
return 0;
|
||||
}
|
||||
|
||||
sc_usb_report_disconnected(usb);
|
||||
assert(usb->cbs && usb->cbs->on_disconnected);
|
||||
usb->cbs->on_disconnected(usb, usb->cbs_userdata);
|
||||
|
||||
// Do not automatically deregister the callback by returning 1. Instead,
|
||||
// manually deregister to interrupt libusb_handle_events() from the libusb
|
||||
@ -283,8 +259,7 @@ run_libusb_event_handler(void *data) {
|
||||
static bool
|
||||
sc_usb_register_callback(struct sc_usb *usb) {
|
||||
if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
|
||||
LOGW("On this platform, libusb does not have hotplug capability; "
|
||||
"device disconnection will not be detected properly");
|
||||
LOGW("libusb does not have hotplug capability");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -336,7 +311,6 @@ sc_usb_connect(struct sc_usb *usb, libusb_device *device,
|
||||
|
||||
if (cbs) {
|
||||
atomic_init(&usb->stopped, false);
|
||||
usb->disconnection_notified = (atomic_flag) ATOMIC_FLAG_INIT;
|
||||
if (sc_usb_register_callback(usb)) {
|
||||
// Create a thread to process libusb events, so that device
|
||||
// disconnection could be detected immediately
|
||||
@ -347,6 +321,8 @@ sc_usb_connect(struct sc_usb *usb, libusb_device *device,
|
||||
LOGW("Libusb event thread handler could not be created, USB "
|
||||
"device disconnection might not be detected immediately");
|
||||
}
|
||||
} else {
|
||||
LOGW("Could not register USB device disconnection callback");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@ struct sc_usb {
|
||||
sc_thread libusb_event_thread;
|
||||
|
||||
atomic_bool stopped; // only used if cbs != NULL
|
||||
atomic_flag disconnection_notified;
|
||||
};
|
||||
|
||||
struct sc_usb_callbacks {
|
||||
@ -43,7 +42,7 @@ void
|
||||
sc_usb_device_destroy(struct sc_usb_device *usb_device);
|
||||
|
||||
/**
|
||||
* Move src to dst
|
||||
* Move src to dest
|
||||
*
|
||||
* After this call, the content of src is undefined, except that
|
||||
* sc_usb_device_destroy() can be called.
|
||||
@ -74,11 +73,6 @@ sc_usb_connect(struct sc_usb *usb, libusb_device *device,
|
||||
void
|
||||
sc_usb_disconnect(struct sc_usb *usb);
|
||||
|
||||
// A client should call this function with the return value of a libusb call
|
||||
// to detect disconnection immediately
|
||||
bool
|
||||
sc_usb_check_disconnected(struct sc_usb *usb, int result);
|
||||
|
||||
void
|
||||
sc_usb_stop(struct sc_usb *usb);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef SC_BUFFER_UTIL_H
|
||||
#define SC_BUFFER_UTIL_H
|
||||
#ifndef BUFFER_UTIL_H
|
||||
#define BUFFER_UTIL_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
@ -7,13 +7,13 @@
|
||||
#include <stdint.h>
|
||||
|
||||
static inline void
|
||||
sc_write16be(uint8_t *buf, uint16_t value) {
|
||||
buffer_write16be(uint8_t *buf, uint16_t value) {
|
||||
buf[0] = value >> 8;
|
||||
buf[1] = value;
|
||||
}
|
||||
|
||||
static inline void
|
||||
sc_write32be(uint8_t *buf, uint32_t value) {
|
||||
buffer_write32be(uint8_t *buf, uint32_t value) {
|
||||
buf[0] = value >> 24;
|
||||
buf[1] = value >> 16;
|
||||
buf[2] = value >> 8;
|
||||
@ -21,25 +21,25 @@ sc_write32be(uint8_t *buf, uint32_t value) {
|
||||
}
|
||||
|
||||
static inline void
|
||||
sc_write64be(uint8_t *buf, uint64_t value) {
|
||||
sc_write32be(buf, value >> 32);
|
||||
sc_write32be(&buf[4], (uint32_t) value);
|
||||
buffer_write64be(uint8_t *buf, uint64_t value) {
|
||||
buffer_write32be(buf, value >> 32);
|
||||
buffer_write32be(&buf[4], (uint32_t) value);
|
||||
}
|
||||
|
||||
static inline uint16_t
|
||||
sc_read16be(const uint8_t *buf) {
|
||||
buffer_read16be(const uint8_t *buf) {
|
||||
return (buf[0] << 8) | buf[1];
|
||||
}
|
||||
|
||||
static inline uint32_t
|
||||
sc_read32be(const uint8_t *buf) {
|
||||
buffer_read32be(const uint8_t *buf) {
|
||||
return ((uint32_t) buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
||||
}
|
||||
|
||||
static inline uint64_t
|
||||
sc_read64be(const uint8_t *buf) {
|
||||
uint32_t msb = sc_read32be(buf);
|
||||
uint32_t lsb = sc_read32be(&buf[4]);
|
||||
buffer_read64be(const uint8_t *buf) {
|
||||
uint32_t msb = buffer_read32be(buf);
|
||||
uint32_t lsb = buffer_read32be(&buf[4]);
|
||||
return ((uint64_t) msb << 32) | lsb;
|
||||
}
|
||||
|
||||
|
@ -3,33 +3,27 @@
|
||||
ssize_t
|
||||
sc_pipe_read_intr(struct sc_intr *intr, sc_pid pid, sc_pipe pipe, char *data,
|
||||
size_t len) {
|
||||
if (intr && !sc_intr_set_process(intr, pid)) {
|
||||
if (!sc_intr_set_process(intr, pid)) {
|
||||
// Already interrupted
|
||||
return false;
|
||||
}
|
||||
|
||||
ssize_t ret = sc_pipe_read(pipe, data, len);
|
||||
|
||||
if (intr) {
|
||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||
}
|
||||
|
||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
sc_pipe_read_all_intr(struct sc_intr *intr, sc_pid pid, sc_pipe pipe,
|
||||
char *data, size_t len) {
|
||||
if (intr && !sc_intr_set_process(intr, pid)) {
|
||||
if (!sc_intr_set_process(intr, pid)) {
|
||||
// Already interrupted
|
||||
return false;
|
||||
}
|
||||
|
||||
ssize_t ret = sc_pipe_read_all(pipe, data, len);
|
||||
|
||||
if (intr) {
|
||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||
}
|
||||
|
||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||
return ret;
|
||||
}
|
||||
|
@ -136,9 +136,7 @@ sc_cond_timedwait(sc_cond *cond, sc_mutex *mutex, sc_tick deadline) {
|
||||
return false; // timeout
|
||||
}
|
||||
|
||||
// Round up to the next millisecond to guarantee that the deadline is
|
||||
// reached when returning due to timeout
|
||||
uint32_t ms = SC_TICK_TO_MS(deadline - now + SC_TICK_FROM_MS(1) - 1);
|
||||
uint32_t ms = SC_TICK_TO_MS(deadline - now);
|
||||
int r = SDL_CondWaitTimeout(cond->cond, mutex->mutex, ms);
|
||||
#ifndef NDEBUG
|
||||
if (r < 0) {
|
||||
@ -150,8 +148,6 @@ sc_cond_timedwait(sc_cond *cond, sc_mutex *mutex, sc_tick deadline) {
|
||||
memory_order_relaxed);
|
||||
#endif
|
||||
assert(r == 0 || r == SDL_MUTEX_TIMEDOUT);
|
||||
// The deadline is reached on timeout
|
||||
assert(r != SDL_MUTEX_TIMEDOUT || sc_tick_now() >= deadline);
|
||||
return r == 0;
|
||||
}
|
||||
|
||||
|
@ -1,540 +0,0 @@
|
||||
#ifndef SC_VECTOR_H
|
||||
#define SC_VECTOR_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Adapted from vlc_vector:
|
||||
// <https://code.videolan.org/videolan/vlc/-/blob/0857947abaed9c89810cd96353aaa1b7e6ba3b0d/include/vlc_vector.h>
|
||||
|
||||
/**
|
||||
* Vector struct body
|
||||
*
|
||||
* A vector is a dynamic array, managed by the sc_vector_* helpers.
|
||||
*
|
||||
* It is generic over the type of its items, so it is implemented as macros.
|
||||
*
|
||||
* To use a vector, a new type must be defined:
|
||||
*
|
||||
* struct vec_int SC_VECTOR(int);
|
||||
*
|
||||
* The struct may be anonymous:
|
||||
*
|
||||
* struct SC_VECTOR(const char *) names;
|
||||
*
|
||||
* Vector size is accessible via `vec.size`, and items are intended to be
|
||||
* accessed directly, via `vec.data[i]`.
|
||||
*
|
||||
* Functions and macros having name ending with '_' are private.
|
||||
*/
|
||||
#define SC_VECTOR(type) \
|
||||
{ \
|
||||
size_t cap; \
|
||||
size_t size; \
|
||||
type *data; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Static initializer for a vector
|
||||
*/
|
||||
#define SC_VECTOR_INITIALIZER { 0, 0, NULL }
|
||||
|
||||
/**
|
||||
* Initialize an empty vector
|
||||
*/
|
||||
#define sc_vector_init(pv) \
|
||||
({ \
|
||||
(pv)->cap = 0; \
|
||||
(pv)->size = 0; \
|
||||
(pv)->data = NULL; \
|
||||
})
|
||||
|
||||
/**
|
||||
* Destroy a vector
|
||||
*
|
||||
* The vector may not be used anymore unless sc_vector_init() is called.
|
||||
*/
|
||||
#define sc_vector_destroy(pv) \
|
||||
free((pv)->data)
|
||||
|
||||
/**
|
||||
* Clear a vector
|
||||
*
|
||||
* Remove all items from the vector.
|
||||
*/
|
||||
#define sc_vector_clear(pv) \
|
||||
({ \
|
||||
sc_vector_destroy(pv); \
|
||||
sc_vector_init(pv);\
|
||||
})
|
||||
|
||||
/**
|
||||
* The minimal allocation size, in number of items
|
||||
*
|
||||
* Private.
|
||||
*/
|
||||
#define SC_VECTOR_MINCAP_ ((size_t) 10)
|
||||
|
||||
static inline size_t
|
||||
sc_vector_min_(size_t a, size_t b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
sc_vector_max_(size_t a, size_t b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
sc_vector_clamp_(size_t x, size_t min, size_t max)
|
||||
{
|
||||
return sc_vector_max_(min, sc_vector_min_(max, x));
|
||||
}
|
||||
|
||||
/**
|
||||
* Realloc data and update vector fields
|
||||
*
|
||||
* On reallocation success, update the vector capacity (*pcap) and size
|
||||
* (*psize), and return the reallocated data.
|
||||
*
|
||||
* On reallocation failure, return NULL without any change.
|
||||
*
|
||||
* Private.
|
||||
*
|
||||
* \param ptr the current `data` field of the vector to realloc
|
||||
* \param count the requested capacity, in number of items
|
||||
* \param size the size of one item
|
||||
* \param pcap a pointer to the `cap` field of the vector [IN/OUT]
|
||||
* \param psize a pointer to the `size` field of the vector [IN/OUT]
|
||||
* \return the new ptr on success, NULL on error
|
||||
*/
|
||||
static inline void *
|
||||
sc_vector_reallocdata_(void *ptr, size_t count, size_t size,
|
||||
size_t *restrict pcap, size_t *restrict psize)
|
||||
{
|
||||
void *p = realloc(ptr, count * size);
|
||||
if (!p) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*pcap = count;
|
||||
*psize = sc_vector_min_(*psize, count);
|
||||
return p;
|
||||
}
|
||||
|
||||
#define sc_vector_realloc_(pv, newcap) \
|
||||
({ \
|
||||
void *p = sc_vector_reallocdata_((pv)->data, newcap, sizeof(*(pv)->data), \
|
||||
&(pv)->cap, &(pv)->size); \
|
||||
if (p) { \
|
||||
(pv)->data = p; \
|
||||
} \
|
||||
(bool) p; \
|
||||
});
|
||||
|
||||
#define sc_vector_resize_(pv, newcap) \
|
||||
({ \
|
||||
bool ok; \
|
||||
if ((pv)->cap == (newcap)) { \
|
||||
ok = true; \
|
||||
} else if ((newcap) > 0) { \
|
||||
ok = sc_vector_realloc_(pv, (newcap)); \
|
||||
} else { \
|
||||
sc_vector_clear(pv); \
|
||||
ok = true; \
|
||||
} \
|
||||
ok; \
|
||||
})
|
||||
|
||||
static inline size_t
|
||||
sc_vector_growsize_(size_t value)
|
||||
{
|
||||
/* integer multiplication by 1.5 */
|
||||
return value + (value >> 1);
|
||||
}
|
||||
|
||||
/* SIZE_MAX/2 to fit in ssize_t, and so that cap*1.5 does not overflow. */
|
||||
#define sc_vector_max_cap_(pv) (SIZE_MAX / 2 / sizeof(*(pv)->data))
|
||||
|
||||
/**
|
||||
* Increase the capacity of the vector to at least `mincap`
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param mincap (size_t) the requested capacity
|
||||
* \retval true if no allocation failed
|
||||
* \retval false on allocation failure (the vector is left untouched)
|
||||
*/
|
||||
#define sc_vector_reserve(pv, mincap) \
|
||||
({ \
|
||||
bool ok; \
|
||||
/* avoid to allocate tiny arrays (< SC_VECTOR_MINCAP_) */ \
|
||||
size_t mincap_ = sc_vector_max_(mincap, SC_VECTOR_MINCAP_); \
|
||||
if (mincap_ <= (pv)->cap) { \
|
||||
/* nothing to do */ \
|
||||
ok = true; \
|
||||
} else if (mincap_ <= sc_vector_max_cap_(pv)) { \
|
||||
/* not too big */ \
|
||||
size_t newsize = sc_vector_growsize_((pv)->cap); \
|
||||
newsize = sc_vector_clamp_(newsize, mincap_, sc_vector_max_cap_(pv)); \
|
||||
ok = sc_vector_realloc_(pv, newsize); \
|
||||
} else { \
|
||||
ok = false; \
|
||||
} \
|
||||
ok; \
|
||||
})
|
||||
|
||||
#define sc_vector_shrink_to_fit(pv) \
|
||||
/* decreasing the size may not fail */ \
|
||||
(void) sc_vector_resize_(pv, (pv)->size)
|
||||
|
||||
/**
|
||||
* Resize the vector down automatically
|
||||
*
|
||||
* Shrink only when necessary (in practice when cap > (size+5)*1.5)
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
*/
|
||||
#define sc_vector_autoshrink(pv) \
|
||||
({ \
|
||||
bool must_shrink = \
|
||||
/* do not shrink to tiny size */ \
|
||||
(pv)->cap > SC_VECTOR_MINCAP_ && \
|
||||
/* no need to shrink */ \
|
||||
(pv)->cap >= sc_vector_growsize_((pv)->size + 5); \
|
||||
if (must_shrink) { \
|
||||
size_t newsize = sc_vector_max_((pv)->size + 5, SC_VECTOR_MINCAP_); \
|
||||
sc_vector_resize_(pv, newsize); \
|
||||
} \
|
||||
})
|
||||
|
||||
#define sc_vector_check_same_ptr_type_(a, b) \
|
||||
(void) ((a) == (b)) /* warn on type mismatch */
|
||||
|
||||
/**
|
||||
* Push an item at the end of the vector
|
||||
*
|
||||
* The amortized complexity is O(1).
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param item the item to append
|
||||
* \retval true if no allocation failed
|
||||
* \retval false on allocation failure (the vector is left untouched)
|
||||
*/
|
||||
#define sc_vector_push(pv, item) \
|
||||
({ \
|
||||
bool ok = sc_vector_reserve(pv, (pv)->size + 1); \
|
||||
if (ok) { \
|
||||
(pv)->data[(pv)->size++] = (item); \
|
||||
} \
|
||||
ok; \
|
||||
})
|
||||
|
||||
/**
|
||||
* Append `count` items at the end of the vector
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param items the items array to append
|
||||
* \param count the number of items in the array
|
||||
* \retval true if no allocation failed
|
||||
* \retval false on allocation failure (the vector is left untouched)
|
||||
*/
|
||||
#define sc_vector_push_all(pv, items, count) \
|
||||
sc_vector_push_all_(pv, items, (size_t) count)
|
||||
|
||||
#define sc_vector_push_all_(pv, items, count) \
|
||||
({ \
|
||||
sc_vector_check_same_ptr_type_((pv)->data, items); \
|
||||
bool ok = sc_vector_reserve(pv, (pv)->size + (count)); \
|
||||
if (ok) { \
|
||||
memcpy(&(pv)->data[(pv)->size], items, (count) * sizeof(*(pv)->data)); \
|
||||
(pv)->size += count; \
|
||||
} \
|
||||
ok; \
|
||||
})
|
||||
|
||||
/**
|
||||
* Insert an hole of size `count` to the given index
|
||||
*
|
||||
* The items in range [index; size-1] will be moved. The items in the hole are
|
||||
* left uninitialized.
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param index the index where the hole is to be inserted
|
||||
* \param count the number of items in the hole
|
||||
* \retval true if no allocation failed
|
||||
* \retval false on allocation failure (the vector is left untouched)
|
||||
*/
|
||||
#define sc_vector_insert_hole(pv, index, count) \
|
||||
sc_vector_insert_hole_(pv, (size_t) index, (size_t) count);
|
||||
|
||||
#define sc_vector_insert_hole_(pv, index, count) \
|
||||
({ \
|
||||
bool ok = sc_vector_reserve(pv, (pv)->size + (count)); \
|
||||
if (ok) { \
|
||||
if ((index) < (pv)->size) { \
|
||||
memmove(&(pv)->data[(index) + (count)], \
|
||||
&(pv)->data[(index)], \
|
||||
((pv)->size - (index)) * sizeof(*(pv)->data)); \
|
||||
} \
|
||||
(pv)->size += count; \
|
||||
} \
|
||||
ok; \
|
||||
})
|
||||
|
||||
/**
|
||||
* Insert an item at the given index
|
||||
*
|
||||
* The items in range [index; size-1] will be moved.
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param index the index where the item is to be inserted
|
||||
* \param item the item to append
|
||||
* \retval true if no allocation failed
|
||||
* \retval false on allocation failure (the vector is left untouched)
|
||||
*/
|
||||
#define sc_vector_insert(pv, index, item) \
|
||||
sc_vector_insert_(pv, (size_t) index, (size_t) item);
|
||||
|
||||
#define sc_vector_insert_(pv, index, item) \
|
||||
({ \
|
||||
bool ok = sc_vector_insert_hole_(pv, index, 1); \
|
||||
if (ok) { \
|
||||
(pv)->data[index] = (item); \
|
||||
} \
|
||||
ok; \
|
||||
})
|
||||
|
||||
/**
|
||||
* Insert `count` items at the given index
|
||||
*
|
||||
* The items in range [index; size-1] will be moved.
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param index the index where the items are to be inserted
|
||||
* \param items the items array to append
|
||||
* \param count the number of items in the array
|
||||
* \retval true if no allocation failed
|
||||
* \retval false on allocation failure (the vector is left untouched)
|
||||
*/
|
||||
#define sc_vector_insert_all(pv, index, items, count) \
|
||||
sc_vector_insert_all_(pv, (size_t) index, items, (size_t) count)
|
||||
|
||||
#define sc_vector_insert_all_(pv, index, items, count) \
|
||||
({ \
|
||||
sc_vector_check_same_ptr_type_((pv)->data, items); \
|
||||
bool ok = sc_vector_insert_hole_(pv, index, count); \
|
||||
if (ok) { \
|
||||
memcpy(&(pv)->data[index], items, count * sizeof(*(pv)->data)); \
|
||||
} \
|
||||
ok; \
|
||||
})
|
||||
|
||||
/** Reverse a char array in place */
|
||||
static inline void
|
||||
sc_char_array_reverse(char *array, size_t len)
|
||||
{
|
||||
for (size_t i = 0; i < len / 2; ++i)
|
||||
{
|
||||
char c = array[i];
|
||||
array[i] = array[len - i - 1];
|
||||
array[len - i - 1] = c;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Right-rotate a (char) array in place
|
||||
*
|
||||
* For example, left-rotating a char array containing {1, 2, 3, 4, 5, 6} with
|
||||
* distance 4 will result in {5, 6, 1, 2, 3, 4}.
|
||||
*
|
||||
* Private.
|
||||
*/
|
||||
static inline void
|
||||
sc_char_array_rotate_left(char *array, size_t len, size_t distance)
|
||||
{
|
||||
sc_char_array_reverse(array, distance);
|
||||
sc_char_array_reverse(&array[distance], len - distance);
|
||||
sc_char_array_reverse(array, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Right-rotate a (char) array in place
|
||||
*
|
||||
* For example, left-rotating a char array containing {1, 2, 3, 4, 5, 6} with
|
||||
* distance 2 will result in {5, 6, 1, 2, 3, 4}.
|
||||
*
|
||||
* Private.
|
||||
*/
|
||||
static inline void
|
||||
sc_char_array_rotate_right(char *array, size_t len, size_t distance)
|
||||
{
|
||||
sc_char_array_rotate_left(array, len, len - distance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move items in a (char) array in place
|
||||
*
|
||||
* Move slice [index, count] to target.
|
||||
*/
|
||||
static inline void
|
||||
sc_char_array_move(char *array, size_t idx, size_t count, size_t target)
|
||||
{
|
||||
if (idx < target) {
|
||||
sc_char_array_rotate_left(&array[idx], target - idx + count, count);
|
||||
} else {
|
||||
sc_char_array_rotate_right(&array[target], idx - target + count, count);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a slice of items to a given target index
|
||||
*
|
||||
* The items in range [index; count] will be moved so that the *new* position
|
||||
* of the first item is `target`.
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param index the index of the first item to move
|
||||
* \param count the number of items to move
|
||||
* \param target the new index of the moved slice
|
||||
*/
|
||||
#define sc_vector_move_slice(pv, index, count, target) \
|
||||
sc_vector_move_slice_(pv, (size_t) index, count, (size_t) target);
|
||||
|
||||
#define sc_vector_move_slice_(pv, index, count, target) \
|
||||
({ \
|
||||
sc_char_array_move((char *) (pv)->data, \
|
||||
(index) * sizeof(*(pv)->data), \
|
||||
(count) * sizeof(*(pv)->data), \
|
||||
(target) * sizeof(*(pv)->data)); \
|
||||
})
|
||||
|
||||
/**
|
||||
* Move an item to a given target index
|
||||
*
|
||||
* The items will be moved so that its *new* position is `target`.
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param index the index of the item to move
|
||||
* \param target the new index of the moved item
|
||||
*/
|
||||
#define sc_vector_move(pv, index, target) \
|
||||
sc_vector_move_slice(pv, index, 1, target)
|
||||
|
||||
/**
|
||||
* Remove a slice of items, without shrinking the array
|
||||
*
|
||||
* If you have no good reason to use the _noshrink() version, use
|
||||
* sc_vector_remove_slice() instead.
|
||||
*
|
||||
* The items in range [index+count; size-1] will be moved.
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param index the index of the first item to remove
|
||||
* \param count the number of items to remove
|
||||
*/
|
||||
#define sc_vector_remove_slice_noshrink(pv, index, count) \
|
||||
sc_vector_remove_slice_noshrink_(pv, (size_t) index, (size_t) count)
|
||||
|
||||
#define sc_vector_remove_slice_noshrink_(pv, index, count) \
|
||||
({ \
|
||||
if ((index) + (count) < (pv)->size) { \
|
||||
memmove(&(pv)->data[index], \
|
||||
&(pv)->data[(index) + (count)], \
|
||||
((pv)->size - (index) - (count)) * sizeof(*(pv)->data)); \
|
||||
} \
|
||||
(pv)->size -= count; \
|
||||
})
|
||||
|
||||
/**
|
||||
* Remove a slice of items
|
||||
*
|
||||
* The items in range [index+count; size-1] will be moved.
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param index the index of the first item to remove
|
||||
* \param count the number of items to remove
|
||||
*/
|
||||
#define sc_vector_remove_slice(pv, index, count) \
|
||||
({ \
|
||||
sc_vector_remove_slice_noshrink(pv, index, count); \
|
||||
sc_vector_autoshrink(pv); \
|
||||
})
|
||||
|
||||
/**
|
||||
* Remove an item, without shrinking the array
|
||||
*
|
||||
* If you have no good reason to use the _noshrink() version, use
|
||||
* sc_vector_remove() instead.
|
||||
*
|
||||
* The items in range [index+1; size-1] will be moved.
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param index the index of item to remove
|
||||
*/
|
||||
#define sc_vector_remove_noshrink(pv, index) \
|
||||
sc_vector_remove_slice_noshrink(pv, index, 1)
|
||||
|
||||
/**
|
||||
* Remove an item
|
||||
*
|
||||
* The items in range [index+1; size-1] will be moved.
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param index the index of item to remove
|
||||
*/
|
||||
#define sc_vector_remove(pv, index) \
|
||||
({ \
|
||||
sc_vector_remove_noshrink(pv, index); \
|
||||
sc_vector_autoshrink(pv); \
|
||||
})
|
||||
|
||||
/**
|
||||
* Remove an item
|
||||
*
|
||||
* The removed item is replaced by the last item of the vector.
|
||||
*
|
||||
* This does not preserve ordering, but is O(1). This is useful when the order
|
||||
* of items is not meaningful.
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param index the index of item to remove
|
||||
*/
|
||||
#define sc_vector_swap_remove(pv, index) \
|
||||
sc_vector_swap_remove_(pv, (size_t) index);
|
||||
|
||||
#define sc_vector_swap_remove_(pv, index) \
|
||||
({ \
|
||||
(pv)->data[index] = (pv)->data[(pv)->size-1]; \
|
||||
(pv)->size--; \
|
||||
});
|
||||
|
||||
/**
|
||||
* Return the index of an item
|
||||
*
|
||||
* Iterate over all items to find a given item.
|
||||
*
|
||||
* Use only for vectors of primitive types or pointers.
|
||||
*
|
||||
* Return the index, or -1 if not found.
|
||||
*
|
||||
* \param pv a pointer to the vector
|
||||
* \param item the item to find (compared with ==)
|
||||
*/
|
||||
#define sc_vector_index_of(pv, item) \
|
||||
({ \
|
||||
ssize_t idx = -1; \
|
||||
for (size_t i = 0; i < (pv)->size; ++i) { \
|
||||
if ((pv)->data[i] == (item)) { \
|
||||
idx = (ssize_t) i; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
idx; \
|
||||
})
|
||||
|
||||
#endif
|
@ -1,67 +0,0 @@
|
||||
#include "version.h"
|
||||
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavutil/avutil.h>
|
||||
#ifdef HAVE_V4L2
|
||||
# include <libavdevice/avdevice.h>
|
||||
#endif
|
||||
#ifdef HAVE_USB
|
||||
# include <libusb-1.0/libusb.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
scrcpy_print_version(void) {
|
||||
printf("\nDependencies (compiled / linked):\n");
|
||||
|
||||
SDL_version sdl;
|
||||
SDL_GetVersion(&sdl);
|
||||
printf(" - SDL: %u.%u.%u / %u.%u.%u\n",
|
||||
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL,
|
||||
(unsigned) sdl.major, (unsigned) sdl.minor, (unsigned) sdl.patch);
|
||||
|
||||
unsigned avcodec = avcodec_version();
|
||||
printf(" - libavcodec: %u.%u.%u / %u.%u.%u\n",
|
||||
LIBAVCODEC_VERSION_MAJOR,
|
||||
LIBAVCODEC_VERSION_MINOR,
|
||||
LIBAVCODEC_VERSION_MICRO,
|
||||
AV_VERSION_MAJOR(avcodec),
|
||||
AV_VERSION_MINOR(avcodec),
|
||||
AV_VERSION_MICRO(avcodec));
|
||||
|
||||
unsigned avformat = avformat_version();
|
||||
printf(" - libavformat: %u.%u.%u / %u.%u.%u\n",
|
||||
LIBAVFORMAT_VERSION_MAJOR,
|
||||
LIBAVFORMAT_VERSION_MINOR,
|
||||
LIBAVFORMAT_VERSION_MICRO,
|
||||
AV_VERSION_MAJOR(avformat),
|
||||
AV_VERSION_MINOR(avformat),
|
||||
AV_VERSION_MICRO(avformat));
|
||||
|
||||
unsigned avutil = avutil_version();
|
||||
printf(" - libavutil: %u.%u.%u / %u.%u.%u\n",
|
||||
LIBAVUTIL_VERSION_MAJOR,
|
||||
LIBAVUTIL_VERSION_MINOR,
|
||||
LIBAVUTIL_VERSION_MICRO,
|
||||
AV_VERSION_MAJOR(avutil),
|
||||
AV_VERSION_MINOR(avutil),
|
||||
AV_VERSION_MICRO(avutil));
|
||||
|
||||
#ifdef HAVE_V4L2
|
||||
unsigned avdevice = avdevice_version();
|
||||
printf(" - libavdevice: %u.%u.%u / %u.%u.%u\n",
|
||||
LIBAVDEVICE_VERSION_MAJOR,
|
||||
LIBAVDEVICE_VERSION_MINOR,
|
||||
LIBAVDEVICE_VERSION_MICRO,
|
||||
AV_VERSION_MAJOR(avdevice),
|
||||
AV_VERSION_MINOR(avdevice),
|
||||
AV_VERSION_MICRO(avdevice));
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_USB
|
||||
const struct libusb_version *usb = libusb_get_version();
|
||||
// The compiled version may not be known
|
||||
printf(" - libusb: - / %u.%u.%u\n",
|
||||
(unsigned) usb->major, (unsigned) usb->minor, (unsigned) usb->micro);
|
||||
#endif
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
#ifndef SC_VERSION_H
|
||||
#define SC_VERSION_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
void
|
||||
scrcpy_print_version(void);
|
||||
|
||||
#endif
|
@ -13,22 +13,21 @@ static void test_adb_devices() {
|
||||
"192.168.1.1:5555 device product:MyWifiProduct model:MyWifiModel "
|
||||
"device:MyWifiDevice trandport_id:2\n";
|
||||
|
||||
struct sc_vec_adb_devices vec = SC_VECTOR_INITIALIZER;
|
||||
bool ok = sc_adb_parse_devices(output, &vec);
|
||||
assert(ok);
|
||||
assert(vec.size == 2);
|
||||
struct sc_adb_device devices[16];
|
||||
ssize_t count = sc_adb_parse_devices(output, devices, ARRAY_LEN(devices));
|
||||
assert(count == 2);
|
||||
|
||||
struct sc_adb_device *device = &vec.data[0];
|
||||
struct sc_adb_device *device = &devices[0];
|
||||
assert(!strcmp("0123456789abcdef", device->serial));
|
||||
assert(!strcmp("device", device->state));
|
||||
assert(!strcmp("MyModel", device->model));
|
||||
|
||||
device = &vec.data[1];
|
||||
device = &devices[1];
|
||||
assert(!strcmp("192.168.1.1:5555", device->serial));
|
||||
assert(!strcmp("device", device->state));
|
||||
assert(!strcmp("MyWifiModel", device->model));
|
||||
|
||||
sc_adb_devices_destroy(&vec);
|
||||
sc_adb_devices_destroy_all(devices, count);
|
||||
}
|
||||
|
||||
static void test_adb_devices_cr() {
|
||||
@ -39,22 +38,21 @@ static void test_adb_devices_cr() {
|
||||
"192.168.1.1:5555 device product:MyWifiProduct model:MyWifiModel "
|
||||
"device:MyWifiDevice trandport_id:2\r\n";
|
||||
|
||||
struct sc_vec_adb_devices vec = SC_VECTOR_INITIALIZER;
|
||||
bool ok = sc_adb_parse_devices(output, &vec);
|
||||
assert(ok);
|
||||
assert(vec.size == 2);
|
||||
struct sc_adb_device devices[16];
|
||||
ssize_t count = sc_adb_parse_devices(output, devices, ARRAY_LEN(devices));
|
||||
assert(count == 2);
|
||||
|
||||
struct sc_adb_device *device = &vec.data[0];
|
||||
struct sc_adb_device *device = &devices[0];
|
||||
assert(!strcmp("0123456789abcdef", device->serial));
|
||||
assert(!strcmp("device", device->state));
|
||||
assert(!strcmp("MyModel", device->model));
|
||||
|
||||
device = &vec.data[1];
|
||||
device = &devices[1];
|
||||
assert(!strcmp("192.168.1.1:5555", device->serial));
|
||||
assert(!strcmp("device", device->state));
|
||||
assert(!strcmp("MyWifiModel", device->model));
|
||||
|
||||
sc_adb_devices_destroy(&vec);
|
||||
sc_adb_devices_destroy_all(devices, count);
|
||||
}
|
||||
|
||||
static void test_adb_devices_daemon_start() {
|
||||
@ -65,17 +63,16 @@ static void test_adb_devices_daemon_start() {
|
||||
"0123456789abcdef device usb:2-1 product:MyProduct model:MyModel "
|
||||
"device:MyDevice transport_id:1\n";
|
||||
|
||||
struct sc_vec_adb_devices vec = SC_VECTOR_INITIALIZER;
|
||||
bool ok = sc_adb_parse_devices(output, &vec);
|
||||
assert(ok);
|
||||
assert(vec.size == 1);
|
||||
struct sc_adb_device devices[16];
|
||||
ssize_t count = sc_adb_parse_devices(output, devices, ARRAY_LEN(devices));
|
||||
assert(count == 1);
|
||||
|
||||
struct sc_adb_device *device = &vec.data[0];
|
||||
struct sc_adb_device *device = &devices[0];
|
||||
assert(!strcmp("0123456789abcdef", device->serial));
|
||||
assert(!strcmp("device", device->state));
|
||||
assert(!strcmp("MyModel", device->model));
|
||||
|
||||
sc_adb_devices_destroy(&vec);
|
||||
sc_adb_device_destroy(device);
|
||||
}
|
||||
|
||||
static void test_adb_devices_daemon_start_mixed() {
|
||||
@ -87,22 +84,22 @@ static void test_adb_devices_daemon_start_mixed() {
|
||||
"87654321 device usb:2-1 product:MyProduct model:MyModel "
|
||||
"device:MyDevice\n";
|
||||
|
||||
struct sc_vec_adb_devices vec = SC_VECTOR_INITIALIZER;
|
||||
bool ok = sc_adb_parse_devices(output, &vec);
|
||||
assert(ok);
|
||||
assert(vec.size == 2);
|
||||
struct sc_adb_device devices[16];
|
||||
ssize_t count = sc_adb_parse_devices(output, devices, ARRAY_LEN(devices));
|
||||
assert(count == 2);
|
||||
|
||||
struct sc_adb_device *device = &vec.data[0];
|
||||
struct sc_adb_device *device = &devices[0];
|
||||
assert(!strcmp("0123456789abcdef", device->serial));
|
||||
assert(!strcmp("unauthorized", device->state));
|
||||
fprintf(stderr, "==== [%s]\n", device->model);
|
||||
assert(!device->model);
|
||||
|
||||
device = &vec.data[1];
|
||||
device = &devices[1];
|
||||
assert(!strcmp("87654321", device->serial));
|
||||
assert(!strcmp("device", device->state));
|
||||
assert(!strcmp("MyModel", device->model));
|
||||
|
||||
sc_adb_devices_destroy(&vec);
|
||||
sc_adb_devices_destroy_all(devices, count);
|
||||
}
|
||||
|
||||
static void test_adb_devices_without_eol() {
|
||||
@ -110,39 +107,34 @@ static void test_adb_devices_without_eol() {
|
||||
"List of devices attached\n"
|
||||
"0123456789abcdef device usb:2-1 product:MyProduct model:MyModel "
|
||||
"device:MyDevice transport_id:1";
|
||||
struct sc_adb_device devices[16];
|
||||
ssize_t count = sc_adb_parse_devices(output, devices, ARRAY_LEN(devices));
|
||||
assert(count == 1);
|
||||
|
||||
struct sc_vec_adb_devices vec = SC_VECTOR_INITIALIZER;
|
||||
bool ok = sc_adb_parse_devices(output, &vec);
|
||||
assert(ok);
|
||||
assert(vec.size == 1);
|
||||
|
||||
struct sc_adb_device *device = &vec.data[0];
|
||||
struct sc_adb_device *device = &devices[0];
|
||||
assert(!strcmp("0123456789abcdef", device->serial));
|
||||
assert(!strcmp("device", device->state));
|
||||
assert(!strcmp("MyModel", device->model));
|
||||
|
||||
sc_adb_devices_destroy(&vec);
|
||||
sc_adb_device_destroy(device);
|
||||
}
|
||||
|
||||
static void test_adb_devices_without_header() {
|
||||
char output[] =
|
||||
"0123456789abcdef device usb:2-1 product:MyProduct model:MyModel "
|
||||
"device:MyDevice transport_id:1\n";
|
||||
|
||||
struct sc_vec_adb_devices vec = SC_VECTOR_INITIALIZER;
|
||||
bool ok = sc_adb_parse_devices(output, &vec);
|
||||
assert(!ok);
|
||||
struct sc_adb_device devices[16];
|
||||
ssize_t count = sc_adb_parse_devices(output, devices, ARRAY_LEN(devices));
|
||||
assert(count == -1);
|
||||
}
|
||||
|
||||
static void test_adb_devices_corrupted() {
|
||||
char output[] =
|
||||
"List of devices attached\n"
|
||||
"corrupted_garbage\n";
|
||||
|
||||
struct sc_vec_adb_devices vec = SC_VECTOR_INITIALIZER;
|
||||
bool ok = sc_adb_parse_devices(output, &vec);
|
||||
assert(ok);
|
||||
assert(vec.size == 0);
|
||||
struct sc_adb_device devices[16];
|
||||
ssize_t count = sc_adb_parse_devices(output, devices, ARRAY_LEN(devices));
|
||||
assert(count == 0);
|
||||
}
|
||||
|
||||
static void test_adb_devices_spaces() {
|
||||
@ -150,17 +142,16 @@ static void test_adb_devices_spaces() {
|
||||
"List of devices attached\n"
|
||||
"0123456789abcdef unauthorized usb:1-4 transport_id:3\n";
|
||||
|
||||
struct sc_vec_adb_devices vec = SC_VECTOR_INITIALIZER;
|
||||
bool ok = sc_adb_parse_devices(output, &vec);
|
||||
assert(ok);
|
||||
assert(vec.size == 1);
|
||||
struct sc_adb_device devices[16];
|
||||
ssize_t count = sc_adb_parse_devices(output, devices, ARRAY_LEN(devices));
|
||||
assert(count == 1);
|
||||
|
||||
struct sc_adb_device *device = &vec.data[0];
|
||||
struct sc_adb_device *device = &devices[0];
|
||||
assert(!strcmp("0123456789abcdef", device->serial));
|
||||
assert(!strcmp("unauthorized", device->state));
|
||||
assert(!device->model);
|
||||
|
||||
sc_adb_devices_destroy(&vec);
|
||||
sc_adb_device_destroy(device);
|
||||
}
|
||||
|
||||
static void test_get_ip_single_line() {
|
||||
|
@ -8,7 +8,7 @@ static void test_buffer_write16be(void) {
|
||||
uint16_t val = 0xABCD;
|
||||
uint8_t buf[2];
|
||||
|
||||
sc_write16be(buf, val);
|
||||
buffer_write16be(buf, val);
|
||||
|
||||
assert(buf[0] == 0xAB);
|
||||
assert(buf[1] == 0xCD);
|
||||
@ -18,7 +18,7 @@ static void test_buffer_write32be(void) {
|
||||
uint32_t val = 0xABCD1234;
|
||||
uint8_t buf[4];
|
||||
|
||||
sc_write32be(buf, val);
|
||||
buffer_write32be(buf, val);
|
||||
|
||||
assert(buf[0] == 0xAB);
|
||||
assert(buf[1] == 0xCD);
|
||||
@ -30,7 +30,7 @@ static void test_buffer_write64be(void) {
|
||||
uint64_t val = 0xABCD1234567890EF;
|
||||
uint8_t buf[8];
|
||||
|
||||
sc_write64be(buf, val);
|
||||
buffer_write64be(buf, val);
|
||||
|
||||
assert(buf[0] == 0xAB);
|
||||
assert(buf[1] == 0xCD);
|
||||
@ -45,7 +45,7 @@ static void test_buffer_write64be(void) {
|
||||
static void test_buffer_read16be(void) {
|
||||
uint8_t buf[2] = {0xAB, 0xCD};
|
||||
|
||||
uint16_t val = sc_read16be(buf);
|
||||
uint16_t val = buffer_read16be(buf);
|
||||
|
||||
assert(val == 0xABCD);
|
||||
}
|
||||
@ -53,7 +53,7 @@ static void test_buffer_read16be(void) {
|
||||
static void test_buffer_read32be(void) {
|
||||
uint8_t buf[4] = {0xAB, 0xCD, 0x12, 0x34};
|
||||
|
||||
uint32_t val = sc_read32be(buf);
|
||||
uint32_t val = buffer_read32be(buf);
|
||||
|
||||
assert(val == 0xABCD1234);
|
||||
}
|
||||
@ -62,7 +62,7 @@ static void test_buffer_read64be(void) {
|
||||
uint8_t buf[8] = {0xAB, 0xCD, 0x12, 0x34,
|
||||
0x56, 0x78, 0x90, 0xEF};
|
||||
|
||||
uint64_t val = sc_read64be(buf);
|
||||
uint64_t val = buffer_read64be(buf);
|
||||
|
||||
assert(val == 0xABCD1234567890EF);
|
||||
}
|
||||
|
@ -1,421 +0,0 @@
|
||||
#include "common.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "util/vector.h"
|
||||
|
||||
static void test_vector_insert_remove(void) {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
|
||||
bool ok;
|
||||
|
||||
ok = sc_vector_push(&vec, 42);
|
||||
assert(ok);
|
||||
assert(vec.data[0] == 42);
|
||||
assert(vec.size == 1);
|
||||
|
||||
ok = sc_vector_push(&vec, 37);
|
||||
assert(ok);
|
||||
assert(vec.size == 2);
|
||||
assert(vec.data[0] == 42);
|
||||
assert(vec.data[1] == 37);
|
||||
|
||||
ok = sc_vector_insert(&vec, 1, 100);
|
||||
assert(ok);
|
||||
assert(vec.size == 3);
|
||||
assert(vec.data[0] == 42);
|
||||
assert(vec.data[1] == 100);
|
||||
assert(vec.data[2] == 37);
|
||||
|
||||
ok = sc_vector_push(&vec, 77);
|
||||
assert(ok);
|
||||
assert(vec.size == 4);
|
||||
assert(vec.data[0] == 42);
|
||||
assert(vec.data[1] == 100);
|
||||
assert(vec.data[2] == 37);
|
||||
assert(vec.data[3] == 77);
|
||||
|
||||
sc_vector_remove(&vec, 1);
|
||||
assert(vec.size == 3);
|
||||
assert(vec.data[0] == 42);
|
||||
assert(vec.data[1] == 37);
|
||||
assert(vec.data[2] == 77);
|
||||
|
||||
sc_vector_clear(&vec);
|
||||
assert(vec.size == 0);
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_push_array(void) {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
bool ok;
|
||||
|
||||
ok = sc_vector_push(&vec, 3); assert(ok);
|
||||
ok = sc_vector_push(&vec, 14); assert(ok);
|
||||
ok = sc_vector_push(&vec, 15); assert(ok);
|
||||
ok = sc_vector_push(&vec, 92); assert(ok);
|
||||
ok = sc_vector_push(&vec, 65); assert(ok);
|
||||
assert(vec.size == 5);
|
||||
|
||||
int items[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
ok = sc_vector_push_all(&vec, items, 8);
|
||||
|
||||
assert(ok);
|
||||
assert(vec.size == 13);
|
||||
assert(vec.data[0] == 3);
|
||||
assert(vec.data[1] == 14);
|
||||
assert(vec.data[2] == 15);
|
||||
assert(vec.data[3] == 92);
|
||||
assert(vec.data[4] == 65);
|
||||
assert(vec.data[5] == 1);
|
||||
assert(vec.data[6] == 2);
|
||||
assert(vec.data[7] == 3);
|
||||
assert(vec.data[8] == 4);
|
||||
assert(vec.data[9] == 5);
|
||||
assert(vec.data[10] == 6);
|
||||
assert(vec.data[11] == 7);
|
||||
assert(vec.data[12] == 8);
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_insert_array(void) {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
bool ok;
|
||||
|
||||
ok = sc_vector_push(&vec, 3); assert(ok);
|
||||
ok = sc_vector_push(&vec, 14); assert(ok);
|
||||
ok = sc_vector_push(&vec, 15); assert(ok);
|
||||
ok = sc_vector_push(&vec, 92); assert(ok);
|
||||
ok = sc_vector_push(&vec, 65); assert(ok);
|
||||
assert(vec.size == 5);
|
||||
|
||||
int items[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
ok = sc_vector_insert_all(&vec, 3, items, 8);
|
||||
assert(ok);
|
||||
assert(vec.size == 13);
|
||||
assert(vec.data[0] == 3);
|
||||
assert(vec.data[1] == 14);
|
||||
assert(vec.data[2] == 15);
|
||||
assert(vec.data[3] == 1);
|
||||
assert(vec.data[4] == 2);
|
||||
assert(vec.data[5] == 3);
|
||||
assert(vec.data[6] == 4);
|
||||
assert(vec.data[7] == 5);
|
||||
assert(vec.data[8] == 6);
|
||||
assert(vec.data[9] == 7);
|
||||
assert(vec.data[10] == 8);
|
||||
assert(vec.data[11] == 92);
|
||||
assert(vec.data[12] == 65);
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_remove_slice(void) {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
|
||||
bool ok;
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
ok = sc_vector_push(&vec, i);
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
assert(vec.size == 100);
|
||||
|
||||
sc_vector_remove_slice(&vec, 32, 60);
|
||||
assert(vec.size == 40);
|
||||
assert(vec.data[31] == 31);
|
||||
assert(vec.data[32] == 92);
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_swap_remove(void) {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
|
||||
bool ok;
|
||||
|
||||
ok = sc_vector_push(&vec, 3); assert(ok);
|
||||
ok = sc_vector_push(&vec, 14); assert(ok);
|
||||
ok = sc_vector_push(&vec, 15); assert(ok);
|
||||
ok = sc_vector_push(&vec, 92); assert(ok);
|
||||
ok = sc_vector_push(&vec, 65); assert(ok);
|
||||
assert(vec.size == 5);
|
||||
|
||||
sc_vector_swap_remove(&vec, 1);
|
||||
assert(vec.size == 4);
|
||||
assert(vec.data[0] == 3);
|
||||
assert(vec.data[1] == 65);
|
||||
assert(vec.data[2] == 15);
|
||||
assert(vec.data[3] == 92);
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_index_of(void) {
|
||||
struct SC_VECTOR(int) vec;
|
||||
sc_vector_init(&vec);
|
||||
|
||||
bool ok;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
ok = sc_vector_push(&vec, i);
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
ssize_t idx;
|
||||
|
||||
idx = sc_vector_index_of(&vec, 0);
|
||||
assert(idx == 0);
|
||||
|
||||
idx = sc_vector_index_of(&vec, 1);
|
||||
assert(idx == 1);
|
||||
|
||||
idx = sc_vector_index_of(&vec, 4);
|
||||
assert(idx == 4);
|
||||
|
||||
idx = sc_vector_index_of(&vec, 9);
|
||||
assert(idx == 9);
|
||||
|
||||
idx = sc_vector_index_of(&vec, 12);
|
||||
assert(idx == -1);
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_grow() {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
|
||||
bool ok;
|
||||
|
||||
for (int i = 0; i < 50; ++i)
|
||||
{
|
||||
ok = sc_vector_push(&vec, i); /* append */
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
assert(vec.cap >= 50);
|
||||
assert(vec.size == 50);
|
||||
|
||||
for (int i = 0; i < 25; ++i)
|
||||
{
|
||||
ok = sc_vector_insert(&vec, 20, i); /* insert in the middle */
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
assert(vec.cap >= 75);
|
||||
assert(vec.size == 75);
|
||||
|
||||
for (int i = 0; i < 25; ++i)
|
||||
{
|
||||
ok = sc_vector_insert(&vec, 0, i); /* prepend */
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
assert(vec.cap >= 100);
|
||||
assert(vec.size == 100);
|
||||
|
||||
for (int i = 0; i < 50; ++i)
|
||||
sc_vector_remove(&vec, 20); /* remove from the middle */
|
||||
|
||||
assert(vec.cap >= 50);
|
||||
assert(vec.size == 50);
|
||||
|
||||
for (int i = 0; i < 25; ++i)
|
||||
sc_vector_remove(&vec, 0); /* remove from the head */
|
||||
|
||||
assert(vec.cap >= 25);
|
||||
assert(vec.size == 25);
|
||||
|
||||
for (int i = 24; i >=0; --i)
|
||||
sc_vector_remove(&vec, i); /* remove from the tail */
|
||||
|
||||
assert(vec.size == 0);
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_exp_growth(void) {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
|
||||
size_t oldcap = vec.cap;
|
||||
int realloc_count = 0;
|
||||
bool ok;
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
{
|
||||
ok = sc_vector_push(&vec, i);
|
||||
assert(ok);
|
||||
if (vec.cap != oldcap)
|
||||
{
|
||||
realloc_count++;
|
||||
oldcap = vec.cap;
|
||||
}
|
||||
}
|
||||
|
||||
/* Test speciically for an expected growth factor of 1.5. In practice, the
|
||||
* result is even lower (19) due to the first alloc of size 10 */
|
||||
assert(realloc_count <= 23); /* ln(10000) / ln(1.5) ~= 23 */
|
||||
|
||||
realloc_count = 0;
|
||||
for (int i = 9999; i >= 0; --i)
|
||||
{
|
||||
sc_vector_remove(&vec, i);
|
||||
if (vec.cap != oldcap)
|
||||
{
|
||||
realloc_count++;
|
||||
oldcap = vec.cap;
|
||||
}
|
||||
}
|
||||
|
||||
assert(realloc_count <= 23); /* same expectations for removals */
|
||||
assert(realloc_count > 0); /* sc_vector_remove() must autoshrink */
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_reserve(void) {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
|
||||
bool ok;
|
||||
|
||||
ok = sc_vector_reserve(&vec, 800);
|
||||
assert(ok);
|
||||
assert(vec.cap >= 800);
|
||||
assert(vec.size == 0);
|
||||
|
||||
size_t initial_cap = vec.cap;
|
||||
|
||||
for (int i = 0; i < 800; ++i)
|
||||
{
|
||||
ok = sc_vector_push(&vec, i);
|
||||
assert(ok);
|
||||
assert(vec.cap == initial_cap); /* no realloc */
|
||||
}
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_shrink_to_fit(void) {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
|
||||
bool ok;
|
||||
|
||||
ok = sc_vector_reserve(&vec, 800);
|
||||
assert(ok);
|
||||
for (int i = 0; i < 250; ++i)
|
||||
{
|
||||
ok = sc_vector_push(&vec, i);
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
assert(vec.cap >= 800);
|
||||
assert(vec.size == 250);
|
||||
|
||||
sc_vector_shrink_to_fit(&vec);
|
||||
assert(vec.cap == 250);
|
||||
assert(vec.size == 250);
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_move(void) {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
|
||||
for (int i = 0; i < 7; ++i)
|
||||
{
|
||||
bool ok = sc_vector_push(&vec, i);
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
/* move item at 1 so that its new position is 4 */
|
||||
sc_vector_move(&vec, 1, 4);
|
||||
|
||||
assert(vec.size == 7);
|
||||
assert(vec.data[0] == 0);
|
||||
assert(vec.data[1] == 2);
|
||||
assert(vec.data[2] == 3);
|
||||
assert(vec.data[3] == 4);
|
||||
assert(vec.data[4] == 1);
|
||||
assert(vec.data[5] == 5);
|
||||
assert(vec.data[6] == 6);
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_move_slice_forward(void) {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
bool ok = sc_vector_push(&vec, i);
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
/* move slice {2, 3, 4, 5} so that its new position is 5 */
|
||||
sc_vector_move_slice(&vec, 2, 4, 5);
|
||||
|
||||
assert(vec.size == 10);
|
||||
assert(vec.data[0] == 0);
|
||||
assert(vec.data[1] == 1);
|
||||
assert(vec.data[2] == 6);
|
||||
assert(vec.data[3] == 7);
|
||||
assert(vec.data[4] == 8);
|
||||
assert(vec.data[5] == 2);
|
||||
assert(vec.data[6] == 3);
|
||||
assert(vec.data[7] == 4);
|
||||
assert(vec.data[8] == 5);
|
||||
assert(vec.data[9] == 9);
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
static void test_vector_move_slice_backward(void) {
|
||||
struct SC_VECTOR(int) vec = SC_VECTOR_INITIALIZER;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
bool ok = sc_vector_push(&vec, i);
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
/* move slice {5, 6, 7} so that its new position is 2 */
|
||||
sc_vector_move_slice(&vec, 5, 3, 2);
|
||||
|
||||
assert(vec.size == 10);
|
||||
assert(vec.data[0] == 0);
|
||||
assert(vec.data[1] == 1);
|
||||
assert(vec.data[2] == 5);
|
||||
assert(vec.data[3] == 6);
|
||||
assert(vec.data[4] == 7);
|
||||
assert(vec.data[5] == 2);
|
||||
assert(vec.data[6] == 3);
|
||||
assert(vec.data[7] == 4);
|
||||
assert(vec.data[8] == 8);
|
||||
assert(vec.data[9] == 9);
|
||||
|
||||
sc_vector_destroy(&vec);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
test_vector_insert_remove();
|
||||
test_vector_push_array();
|
||||
test_vector_insert_array();
|
||||
test_vector_remove_slice();
|
||||
test_vector_swap_remove();
|
||||
test_vector_move();
|
||||
test_vector_move_slice_forward();
|
||||
test_vector_move_slice_backward();
|
||||
test_vector_index_of();
|
||||
test_vector_grow();
|
||||
test_vector_exp_growth();
|
||||
test_vector_reserve();
|
||||
test_vector_shrink_to_fit();
|
||||
return 0;
|
||||
}
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
@ -2,8 +2,8 @@
|
||||
set -e
|
||||
|
||||
BUILDDIR=build-auto
|
||||
PREBUILT_SERVER_URL=https://github.com/Genymobile/scrcpy/releases/download/v1.23/scrcpy-server-v1.23
|
||||
PREBUILT_SERVER_SHA256=2a913fd47478c0b306fca507cb0beb625e49a19ff9fc7ab904e36ef5b9fe7e68
|
||||
PREBUILT_SERVER_URL=https://github.com/Genymobile/scrcpy/releases/download/v1.22/scrcpy-server-v1.22
|
||||
PREBUILT_SERVER_SHA256=c05d273eec7533c0e106282e0254cf04e7f5e8f0c2920ca39448865fab2a419b
|
||||
|
||||
echo "[scrcpy] Downloading prebuilt server..."
|
||||
wget "$PREBUILT_SERVER_URL" -O scrcpy-server
|
||||
@ -12,7 +12,7 @@ echo "$PREBUILT_SERVER_SHA256 scrcpy-server" | sha256sum --check
|
||||
|
||||
echo "[scrcpy] Building client..."
|
||||
rm -rf "$BUILDDIR"
|
||||
meson "$BUILDDIR" --buildtype=release --strip -Db_lto=true \
|
||||
meson "$BUILDDIR" --buildtype release --strip -Db_lto=true \
|
||||
-Dprebuilt_server=scrcpy-server
|
||||
cd "$BUILDDIR"
|
||||
ninja
|
||||
|
@ -1,5 +1,5 @@
|
||||
project('scrcpy', 'c',
|
||||
version: '1.23',
|
||||
version: '1.22',
|
||||
meson_version: '>= 0.48',
|
||||
default_options: [
|
||||
'c_std=c11',
|
||||
|
@ -4,5 +4,3 @@ option('prebuilt_server', type: 'string', description: 'Path of the prebuilt ser
|
||||
option('portable', type: 'boolean', value: false, description: 'Use scrcpy-server from the same directory as the scrcpy executable')
|
||||
option('server_debugger', type: 'boolean', value: false, description: 'Run a server debugger and wait for a client to be attached')
|
||||
option('server_debugger_method', type: 'combo', choices: ['old', 'new'], value: 'new', description: 'Select the debugger method (Android < 9: "old", Android >= 9: "new")')
|
||||
option('v4l2', type: 'boolean', value: true, description: 'Enable V4L2 feature when supported')
|
||||
option('usb', type: 'boolean', value: true, description: 'Enable HID/OTG features when supported')
|
||||
|
77
release.mk
77
release.mk
@ -63,28 +63,25 @@ build-server:
|
||||
ninja -C "$(SERVER_BUILD_DIR)"
|
||||
|
||||
prepare-deps-win32:
|
||||
@app/prebuilt-deps/prepare-adb.sh
|
||||
@app/prebuilt-deps/prepare-sdl.sh
|
||||
@app/prebuilt-deps/prepare-ffmpeg-win32.sh
|
||||
@app/prebuilt-deps/prepare-libusb.sh
|
||||
|
||||
prepare-deps-win64:
|
||||
@app/prebuilt-deps/prepare-adb.sh
|
||||
@app/prebuilt-deps/prepare-sdl.sh
|
||||
@app/prebuilt-deps/prepare-ffmpeg-win64.sh
|
||||
@app/prebuilt-deps/prepare-libusb.sh
|
||||
@prebuilt-deps/prepare-adb.sh
|
||||
@prebuilt-deps/prepare-sdl.sh
|
||||
@prebuilt-deps/prepare-ffmpeg-win32.sh
|
||||
@prebuilt-deps/prepare-libusb.sh
|
||||
|
||||
build-win32: prepare-deps-win32
|
||||
# -Dusb=false because of libusb-win32 build issue, cf #3011
|
||||
[ -d "$(WIN32_BUILD_DIR)" ] || ( mkdir "$(WIN32_BUILD_DIR)" && \
|
||||
meson "$(WIN32_BUILD_DIR)" \
|
||||
--cross-file cross_win32.txt \
|
||||
--buildtype release --strip -Db_lto=true \
|
||||
-Dusb=false \
|
||||
-Dcompile_server=false \
|
||||
-Dportable=true )
|
||||
ninja -C "$(WIN32_BUILD_DIR)"
|
||||
|
||||
prepare-deps-win64:
|
||||
@prebuilt-deps/prepare-adb.sh
|
||||
@prebuilt-deps/prepare-sdl.sh
|
||||
@prebuilt-deps/prepare-ffmpeg-win64.sh
|
||||
|
||||
build-win64: prepare-deps-win64
|
||||
[ -d "$(WIN64_BUILD_DIR)" ] || ( mkdir "$(WIN64_BUILD_DIR)" && \
|
||||
meson "$(WIN64_BUILD_DIR)" \
|
||||
@ -98,39 +95,39 @@ dist-win32: build-server build-win32
|
||||
mkdir -p "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||
cp "$(SERVER_BUILD_DIR)"/server/scrcpy-server "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp "$(WIN32_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/data/scrcpy-console.bat "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||
cp app/data/scrcpy-noconsole.vbs "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||
cp app/data/icon.png "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||
cp app/data/open_a_terminal_here.bat "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||
cp app/prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/avutil-56.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/avcodec-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/avformat-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/swresample-3.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/swscale-5.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-31.0.3/adb.exe "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-31.0.3/AdbWinApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-31.0.3/AdbWinUsbApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/SDL2-2.0.20/i686-w64-mingw32/bin/SDL2.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
#cp app/prebuilt-deps/data/libusb-1.0.25/MinGW32/dll/libusb-1.0.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp data/scrcpy-console.bat "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||
cp data/scrcpy-noconsole.vbs "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||
cp data/icon.png "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||
cp data/open_a_terminal_here.bat "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||
cp prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/avutil-56.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/avcodec-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/avformat-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/swresample-3.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/swscale-5.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/platform-tools-31.0.3/adb.exe "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/platform-tools-31.0.3/AdbWinApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/platform-tools-31.0.3/AdbWinUsbApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/SDL2-2.0.20/i686-w64-mingw32/bin/SDL2.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/libusb-1.0.25/MinGW32/dll/libusb-1.0.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
|
||||
dist-win64: build-server build-win64
|
||||
mkdir -p "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||
cp "$(SERVER_BUILD_DIR)"/server/scrcpy-server "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp "$(WIN64_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/data/scrcpy-console.bat "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||
cp app/data/scrcpy-noconsole.vbs "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||
cp app/data/icon.png "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||
cp app/data/open_a_terminal_here.bat "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||
cp app/prebuilt-deps/data/ffmpeg-win64-5.0/bin/avutil-57.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/ffmpeg-win64-5.0/bin/avcodec-59.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/ffmpeg-win64-5.0/bin/avformat-59.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/ffmpeg-win64-5.0/bin/swresample-4.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/ffmpeg-win64-5.0/bin/swscale-6.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-31.0.3/adb.exe "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-31.0.3/AdbWinApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/platform-tools-31.0.3/AdbWinUsbApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/SDL2-2.0.20/x86_64-w64-mingw32/bin/SDL2.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp app/prebuilt-deps/data/libusb-1.0.25/MinGW64/dll/libusb-1.0.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp data/scrcpy-console.bat "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||
cp data/scrcpy-noconsole.vbs "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||
cp data/icon.png "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||
cp data/open_a_terminal_here.bat "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||
cp prebuilt-deps/data/ffmpeg-win64-5.0/bin/avutil-57.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/ffmpeg-win64-5.0/bin/avcodec-59.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/ffmpeg-win64-5.0/bin/avformat-59.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/ffmpeg-win64-5.0/bin/swresample-4.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/ffmpeg-win64-5.0/bin/swscale-6.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/platform-tools-31.0.3/adb.exe "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/platform-tools-31.0.3/AdbWinApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/platform-tools-31.0.3/AdbWinUsbApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/SDL2-2.0.20/x86_64-w64-mingw32/bin/SDL2.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp prebuilt-deps/data/libusb-1.0.25/MinGW64/dll/libusb-1.0.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
|
||||
zip-win32: dist-win32
|
||||
cd "$(DIST)/$(WIN32_TARGET_DIR)"; \
|
||||
|
@ -6,8 +6,8 @@ android {
|
||||
applicationId "com.genymobile.scrcpy"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 31
|
||||
versionCode 12300
|
||||
versionName "1.23"
|
||||
versionCode 12200
|
||||
versionName "1.22"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
@ -12,7 +12,7 @@
|
||||
set -e
|
||||
|
||||
SCRCPY_DEBUG=false
|
||||
SCRCPY_VERSION_NAME=1.23
|
||||
SCRCPY_VERSION_NAME=1.22
|
||||
|
||||
PLATFORM=${ANDROID_PLATFORM:-31}
|
||||
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-31.0.0}
|
||||
|
@ -21,7 +21,6 @@ public class Options {
|
||||
private boolean powerOffScreenOnClose;
|
||||
private boolean clipboardAutosync = true;
|
||||
private boolean downsizeOnError = true;
|
||||
private boolean cleanup = true;
|
||||
|
||||
// Options not used by the scrcpy client, but useful to use scrcpy-server directly
|
||||
private boolean sendDeviceMeta = true; // send device name and size
|
||||
@ -156,14 +155,6 @@ public class Options {
|
||||
this.downsizeOnError = downsizeOnError;
|
||||
}
|
||||
|
||||
public boolean getCleanup() {
|
||||
return cleanup;
|
||||
}
|
||||
|
||||
public void setCleanup(boolean cleanup) {
|
||||
this.cleanup = cleanup;
|
||||
}
|
||||
|
||||
public boolean getSendDeviceMeta() {
|
||||
return sendDeviceMeta;
|
||||
}
|
||||
|
@ -28,8 +28,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||
// Keep the values in descending order
|
||||
private static final int[] MAX_SIZE_FALLBACK = {2560, 1920, 1600, 1280, 1024, 800};
|
||||
|
||||
private static final long PACKET_FLAG_CONFIG = 1L << 63;
|
||||
private static final long PACKET_FLAG_KEY_FRAME = 1L << 62;
|
||||
private static final int NO_PTS = -1;
|
||||
|
||||
private final AtomicBoolean rotationChanged = new AtomicBoolean();
|
||||
private final ByteBuffer headerBuffer = ByteBuffer.allocate(12);
|
||||
@ -102,7 +101,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||
alive = encode(codec, fd);
|
||||
// do not call stop() on exception, it would trigger an IllegalStateException
|
||||
codec.stop();
|
||||
} catch (IllegalStateException | IllegalArgumentException e) {
|
||||
} catch (IllegalStateException e) {
|
||||
Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage());
|
||||
if (!downsizeOnError || firstFrameSent) {
|
||||
// Fail immediately
|
||||
@ -184,15 +183,12 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||
|
||||
long pts;
|
||||
if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) != 0) {
|
||||
pts = PACKET_FLAG_CONFIG; // non-media data packet
|
||||
pts = NO_PTS; // non-media data packet
|
||||
} else {
|
||||
if (ptsOrigin == 0) {
|
||||
ptsOrigin = bufferInfo.presentationTimeUs;
|
||||
}
|
||||
pts = bufferInfo.presentationTimeUs - ptsOrigin;
|
||||
if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_KEY_FRAME) != 0) {
|
||||
pts |= PACKET_FLAG_KEY_FRAME;
|
||||
}
|
||||
}
|
||||
|
||||
headerBuffer.putLong(pts);
|
||||
|
@ -11,6 +11,7 @@ import java.util.Locale;
|
||||
|
||||
public final class Server {
|
||||
|
||||
|
||||
private Server() {
|
||||
// not instantiable
|
||||
}
|
||||
@ -50,13 +51,11 @@ public final class Server {
|
||||
}
|
||||
}
|
||||
|
||||
if (options.getCleanup()) {
|
||||
try {
|
||||
CleanUp.configure(options.getDisplayId(), restoreStayOn, mustDisableShowTouchesOnCleanUp, restoreNormalPowerMode,
|
||||
options.getPowerOffScreenOnClose());
|
||||
} catch (IOException e) {
|
||||
Ln.e("Could not configure cleanup", e);
|
||||
}
|
||||
try {
|
||||
CleanUp.configure(options.getDisplayId(), restoreStayOn, mustDisableShowTouchesOnCleanUp, restoreNormalPowerMode,
|
||||
options.getPowerOffScreenOnClose());
|
||||
} catch (IOException e) {
|
||||
Ln.e("Could not configure cleanup", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,10 +243,6 @@ public final class Server {
|
||||
boolean downsizeOnError = Boolean.parseBoolean(value);
|
||||
options.setDownsizeOnError(downsizeOnError);
|
||||
break;
|
||||
case "cleanup":
|
||||
boolean cleanup = Boolean.parseBoolean(value);
|
||||
options.setCleanup(cleanup);
|
||||
break;
|
||||
case "send_device_meta":
|
||||
boolean sendDeviceMeta = Boolean.parseBoolean(value);
|
||||
options.setSendDeviceMeta(sendDeviceMeta);
|
||||
|
Reference in New Issue
Block a user