Compare commits
138 Commits
ffmpeg_win
...
adb_device
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc5276b0e1 | ||
|
|
582161607e | ||
|
|
146f65d7b2 | ||
|
|
5ed13ef477 | ||
|
|
9c545e8c29 | ||
|
|
0a619dc9ef | ||
|
|
4692d13179 | ||
|
|
02d46b2262 | ||
|
|
4389de1c23 | ||
|
|
85ff70fc95 | ||
|
|
700503df6c | ||
|
|
61969aeb80 | ||
|
|
b88c4aa75e | ||
|
|
8c50342fb2 | ||
|
|
0eadf95a3e | ||
|
|
6df2205cf3 | ||
|
|
61b6324ee9 | ||
|
|
f20137d2ac | ||
|
|
b60809a4da | ||
|
|
b0e04aa327 | ||
|
|
137d2c9791 | ||
|
|
6d41c53b61 | ||
|
|
8d540e83c7 | ||
|
|
2ea12f73db | ||
|
|
5d6bd8f9cd | ||
|
|
5b3ae2cb2f | ||
|
|
08f16a9dde | ||
|
|
386cf7d7ac | ||
|
|
5e2bfccab4 | ||
|
|
ba30ca5c1e | ||
|
|
028e7afe32 | ||
|
|
6ca9825c0f | ||
|
|
f807131c0a | ||
|
|
21106bd70a | ||
|
|
bd3c93ae3d | ||
|
|
9e3902f30c | ||
|
|
7810ca61b0 | ||
|
|
c460243ce2 | ||
|
|
7dec225ceb | ||
|
|
4ee62abe1d | ||
|
|
0080d0b0ff | ||
|
|
0bf7e4ddc4 | ||
|
|
c0a75ca746 | ||
|
|
f02f2135cd | ||
|
|
9b4360b6b8 | ||
|
|
c8d0f5cdeb | ||
|
|
22d9f0faf4 | ||
|
|
a1967b4dfd | ||
|
|
a86deab3d4 | ||
|
|
f4c7044b46 | ||
|
|
64a09513ae | ||
|
|
28054cd471 | ||
|
|
334f46995a | ||
|
|
38cdcdda50 | ||
|
|
eaba613633 | ||
|
|
b8d7f36ba3 | ||
|
|
80bec70852 | ||
|
|
5508c635cb | ||
|
|
ea68a003a2 | ||
|
|
c5be0d6438 | ||
|
|
91418c79ab | ||
|
|
36aaf70279 | ||
|
|
1a03206e36 | ||
|
|
37987b822e | ||
|
|
8fc9dca8cb | ||
|
|
1c17f57c10 | ||
|
|
d8b37fe189 | ||
|
|
0ee9e2ff51 | ||
|
|
1ab3692f3d | ||
|
|
bbef426a4b | ||
|
|
2114f48185 | ||
|
|
b779eca8d3 | ||
|
|
adda47b0f7 | ||
|
|
48e3ff284f | ||
|
|
1d6f9952ee | ||
|
|
d48d191262 | ||
|
|
2762f5d183 | ||
|
|
c996a6d462 | ||
|
|
8ea6fb1f0f | ||
|
|
b546c33eff | ||
|
|
8615813005 | ||
|
|
f51c53e913 | ||
|
|
c0de365f67 | ||
|
|
34e19dcc57 | ||
|
|
4817cadd09 | ||
|
|
02b5e87802 | ||
|
|
8e4d3beb01 | ||
|
|
50f4f1639c | ||
|
|
c8dc1917f4 | ||
|
|
9d2e00697e | ||
|
|
2faf9715be | ||
|
|
45a5e560df | ||
|
|
3ba32c2a0d | ||
|
|
6b21f4ae13 | ||
|
|
31a5d0c2bf | ||
|
|
f289d206ea | ||
|
|
ca516f4318 | ||
|
|
5d6076bffd | ||
|
|
e0bce1725b | ||
|
|
ae8fdda09e | ||
|
|
1ff69e21c2 | ||
|
|
a9429efa34 | ||
|
|
063d103dd6 | ||
|
|
4bf9c057fe | ||
|
|
17c97820b2 | ||
|
|
8c7f0ed5ea | ||
|
|
ac038f276e | ||
|
|
1f65b1bf87 | ||
|
|
d41a46dc95 | ||
|
|
308a1f8192 | ||
|
|
241a587e61 | ||
|
|
7e35bfe382 | ||
|
|
855819bbd8 | ||
|
|
557daf280e | ||
|
|
0b8e926330 | ||
|
|
0ec3361bc9 | ||
|
|
81ff7ebd06 | ||
|
|
1ffe312369 | ||
|
|
ebef027c4f | ||
|
|
8e4e7d42f1 | ||
|
|
b066dc0bbf | ||
|
|
262506c733 | ||
|
|
2eb6fe7d81 | ||
|
|
3a0ba7d0a4 | ||
|
|
75c5dc6859 | ||
|
|
fa30f9806a | ||
|
|
4fb61ac83d | ||
|
|
8fa9e6b01a | ||
|
|
0ec64baad4 | ||
|
|
15bf27afdd | ||
|
|
26b4104844 | ||
|
|
723faa5dee | ||
|
|
162043911e | ||
|
|
117fe32626 | ||
|
|
b7a06278fe | ||
|
|
479abc8c77 | ||
|
|
25a4135935 | ||
|
|
5704ec6967 |
6
BUILD.md
6
BUILD.md
@@ -270,10 +270,10 @@ install` must be run as root)._
|
|||||||
|
|
||||||
#### Option 2: Use prebuilt server
|
#### Option 2: Use prebuilt server
|
||||||
|
|
||||||
- [`scrcpy-server-v1.21`][direct-scrcpy-server]
|
- [`scrcpy-server-v1.22`][direct-scrcpy-server]
|
||||||
_(SHA-256: dbcccab523ee26796e55ea33652649e4b7af498edae9aa75e4d4d7869c0ab848)_
|
_(SHA-256: c05d273eec7533c0e106282e0254cf04e7f5e8f0c2920ca39448865fab2a419b)_
|
||||||
|
|
||||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.21/scrcpy-server-v1.21
|
[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
|
Download the prebuilt server somewhere, and specify its path during the Meson
|
||||||
configuration:
|
configuration:
|
||||||
|
|||||||
38
FAQ.md
38
FAQ.md
@@ -12,7 +12,7 @@ Here are the common reported problems and their status.
|
|||||||
|
|
||||||
In that case, it will print this error:
|
In that case, it will print this error:
|
||||||
|
|
||||||
> ERROR: "adb push" returned with value 1
|
> ERROR: "adb get-serialno" returned with value 1
|
||||||
|
|
||||||
This is typically not a bug in _scrcpy_, but a problem in your environment.
|
This is typically not a bug in _scrcpy_, but a problem in your environment.
|
||||||
|
|
||||||
@@ -32,28 +32,38 @@ in the release, so it should work out-of-the-box.
|
|||||||
|
|
||||||
### Device unauthorized
|
### Device unauthorized
|
||||||
|
|
||||||
Check [stackoverflow][device-unauthorized].
|
|
||||||
|
> 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.
|
||||||
|
|
||||||
|
If it does not open, check [stackoverflow][device-unauthorized].
|
||||||
|
|
||||||
[device-unauthorized]: https://stackoverflow.com/questions/23081263/adb-android-device-unauthorized
|
[device-unauthorized]: https://stackoverflow.com/questions/23081263/adb-android-device-unauthorized
|
||||||
|
|
||||||
|
|
||||||
### Device not detected
|
### Device not detected
|
||||||
|
|
||||||
> adb: error: failed to get feature set: no devices/emulators found
|
> error: no devices/emulators found
|
||||||
|
|
||||||
Check that you correctly enabled [adb debugging][enable-adb].
|
Check that you correctly enabled [adb debugging][enable-adb].
|
||||||
|
|
||||||
If your device is not detected, you may need some [drivers] (on Windows).
|
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
|
[enable-adb]: https://developer.android.com/studio/command-line/adb.html#Enabling
|
||||||
[drivers]: https://developer.android.com/studio/run/oem-usb.html
|
[drivers]: https://developer.android.com/studio/run/oem-usb.html
|
||||||
|
[google-usb-driver]: https://developer.android.com/studio/run/win-usb
|
||||||
|
|
||||||
|
|
||||||
### Several devices connected
|
### Several devices connected
|
||||||
|
|
||||||
If several devices are connected, you will encounter this error:
|
If several devices are connected, you will encounter this error:
|
||||||
|
|
||||||
> adb: error: failed to get feature set: more than one device/emulator
|
> error: more than one device/emulator
|
||||||
|
|
||||||
the identifier of the device you want to mirror must be provided:
|
the identifier of the device you want to mirror must be provided:
|
||||||
|
|
||||||
@@ -61,7 +71,7 @@ the identifier of the device you want to mirror must be provided:
|
|||||||
scrcpy -s 01234567890abcdef
|
scrcpy -s 01234567890abcdef
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that if your device is connected over TCP/IP, you'll get this message:
|
Note that if your device is connected over TCP/IP, you might get this message:
|
||||||
|
|
||||||
> adb: error: more than one device/emulator
|
> adb: error: more than one device/emulator
|
||||||
> ERROR: "adb reverse" returned with value 1
|
> ERROR: "adb reverse" returned with value 1
|
||||||
@@ -219,6 +229,9 @@ scrcpy -m 1024
|
|||||||
scrcpy -m 800
|
scrcpy -m 800
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Since scrcpy v1.22, scrcpy automatically tries again with a lower definition
|
||||||
|
before failing. This behavior can be disabled with `--no-downsize-on-error`.
|
||||||
|
|
||||||
You could also try another [encoder](README.md#encoder).
|
You could also try another [encoder](README.md#encoder).
|
||||||
|
|
||||||
|
|
||||||
@@ -245,8 +258,15 @@ Caused by: java.lang.IllegalArgumentException: displayToken must not be null
|
|||||||
|
|
||||||
## Command line on Windows
|
## Command line on Windows
|
||||||
|
|
||||||
Some Windows users are not familiar with the command line. Here is how to open a
|
Since v1.22, a "shortcut" has been added to directly open a terminal in the
|
||||||
terminal and run `scrcpy` with arguments:
|
scrcpy directory. Double-click on `open_a_terminal_here.bat`, then type your
|
||||||
|
command. For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy --record file.mkv
|
||||||
|
```
|
||||||
|
|
||||||
|
You could also open a terminal and go to the scrcpy folder manually:
|
||||||
|
|
||||||
1. Press <kbd>Windows</kbd>+<kbd>r</kbd>, this opens a dialog box.
|
1. Press <kbd>Windows</kbd>+<kbd>r</kbd>, this opens a dialog box.
|
||||||
2. Type `cmd` and press <kbd>Enter</kbd>, this opens a terminal.
|
2. Type `cmd` and press <kbd>Enter</kbd>, this opens a terminal.
|
||||||
@@ -285,4 +305,4 @@ This FAQ is available in other languages:
|
|||||||
|
|
||||||
- [Italiano (Italiano, `it`) - v1.19](FAQ.it.md)
|
- [Italiano (Italiano, `it`) - v1.19](FAQ.it.md)
|
||||||
- [한국어 (Korean, `ko`) - v1.11](FAQ.ko.md)
|
- [한국어 (Korean, `ko`) - v1.11](FAQ.ko.md)
|
||||||
- [简体中文 (Simplified Chinese, `zh-Hans`) - v1.18](FAQ.zh-Hans.md)
|
- [简体中文 (Simplified Chinese, `zh-Hans`) - v1.22](FAQ.zh-Hans.md)
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
只有原版的[FAQ](FAQ.md)会保持更新。
|
_Only the original [FAQ.md](FAQ.md) is guaranteed to be up-to-date._
|
||||||
本文根据[d6aaa5]翻译。
|
|
||||||
|
|
||||||
[d6aaa5]:https://github.com/Genymobile/scrcpy/blob/d6aaa5bf9aa3710660c683b6e3e0ed971ee44af5/FAQ.md
|
_只有原版的 [FAQ.md](FAQ.md)是保证最新的。_
|
||||||
|
|
||||||
|
Current version is based on [28054cd]
|
||||||
|
|
||||||
|
本文根据[28054cd]进行翻译。
|
||||||
|
|
||||||
|
[28054cd]: https://github.com/Genymobile/scrcpy/blob/28054cd471f848733e11372c9d745cd5d71e6ce7/FAQ.md
|
||||||
|
|
||||||
# 常见问题
|
# 常见问题
|
||||||
|
|
||||||
@@ -13,7 +18,7 @@
|
|||||||
|
|
||||||
在这种情况中,将会输出这个错误:
|
在这种情况中,将会输出这个错误:
|
||||||
|
|
||||||
> ERROR: "adb push" returned with value 1
|
> ERROR: "adb get-serialno" returned with value 1
|
||||||
|
|
||||||
这通常不是 _scrcpy_ 的bug,而是你的环境的问题。
|
这通常不是 _scrcpy_ 的bug,而是你的环境的问题。
|
||||||
|
|
||||||
@@ -33,28 +38,37 @@ adb devices
|
|||||||
|
|
||||||
### 设备未授权
|
### 设备未授权
|
||||||
|
|
||||||
参见这里 [stackoverflow][device-unauthorized].
|
|
||||||
|
> 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.
|
||||||
|
|
||||||
|
连接时,在设备上应该会打开一个弹出窗口。 您必须授权 USB 调试。
|
||||||
|
|
||||||
|
如果没有打开,参见[stackoverflow][device-unauthorized].
|
||||||
|
|
||||||
[device-unauthorized]: https://stackoverflow.com/questions/23081263/adb-android-device-unauthorized
|
[device-unauthorized]: https://stackoverflow.com/questions/23081263/adb-android-device-unauthorized
|
||||||
|
|
||||||
|
|
||||||
### 未检测到设备
|
### 未检测到设备
|
||||||
|
|
||||||
> adb: error: failed to get feature set: no devices/emulators found
|
> error: no devices/emulators found
|
||||||
|
|
||||||
确认已经正确启用 [adb debugging][enable-adb].
|
确认已经正确启用 [adb debugging][enable-adb].
|
||||||
|
|
||||||
如果你的设备没有被检测到,你可能需要一些[驱动][drivers] (在 Windows上).
|
如果你的设备没有被检测到,你可能需要一些[驱动][drivers] (在 Windows上)。这里有一个单独的 [适用于Google设备的USB驱动][google-usb-driver].
|
||||||
|
|
||||||
[enable-adb]: https://developer.android.com/studio/command-line/adb.html#Enabling
|
[enable-adb]: https://developer.android.com/studio/command-line/adb.html#Enabling
|
||||||
[drivers]: https://developer.android.com/studio/run/oem-usb.html
|
[drivers]: https://developer.android.com/studio/run/oem-usb.html
|
||||||
|
[google-usb-driver]: https://developer.android.com/studio/run/win-usb
|
||||||
|
|
||||||
|
|
||||||
### 已连接多个设备
|
### 已连接多个设备
|
||||||
|
|
||||||
如果连接了多个设备,您将遇到以下错误:
|
如果连接了多个设备,您将遇到以下错误:
|
||||||
|
|
||||||
> adb: error: failed to get feature set: more than one device/emulator
|
> error: more than one device/emulator
|
||||||
|
|
||||||
必须提供要镜像的设备的标识符:
|
必须提供要镜像的设备的标识符:
|
||||||
|
|
||||||
@@ -90,19 +104,19 @@ scrcpy
|
|||||||
### 设备断开连接
|
### 设备断开连接
|
||||||
|
|
||||||
如果 _scrcpy_ 在警告“设备连接断开”的情况下自动中止,那就意味着`adb`连接已经断开了。
|
如果 _scrcpy_ 在警告“设备连接断开”的情况下自动中止,那就意味着`adb`连接已经断开了。
|
||||||
请尝试使用另一条USB线或者电脑上的另一个USB接口。
|
|
||||||
请参看 [#281] 和 [#283]。
|
请尝试使用另一条USB线或者电脑上的另一个USB接口。请参看 [#281] 和 [#283]。
|
||||||
|
|
||||||
[#281]: https://github.com/Genymobile/scrcpy/issues/281
|
[#281]: https://github.com/Genymobile/scrcpy/issues/281
|
||||||
[#283]: https://github.com/Genymobile/scrcpy/issues/283
|
[#283]: https://github.com/Genymobile/scrcpy/issues/283
|
||||||
|
|
||||||
|
|
||||||
## 控制相关问题
|
## 控制相关问题
|
||||||
|
|
||||||
### 鼠标和键盘不起作用
|
### 鼠标和键盘不起作用
|
||||||
|
|
||||||
|
|
||||||
在某些设备上,您可能需要启用一个选项以允许 [模拟输入][simulating input]。
|
在某些设备上,您可能需要启用一个选项以允许 [模拟输入][simulating input]。
|
||||||
|
|
||||||
在开发者选项中,打开:
|
在开发者选项中,打开:
|
||||||
|
|
||||||
> **USB调试 (安全设置)**
|
> **USB调试 (安全设置)**
|
||||||
@@ -115,10 +129,12 @@ scrcpy
|
|||||||
|
|
||||||
可输入的文本[被限制为ASCII字符][text-input]。也可以用一些小技巧输入一些[带重音符号的字符][accented-characters],但是仅此而已。参见[#37]。
|
可输入的文本[被限制为ASCII字符][text-input]。也可以用一些小技巧输入一些[带重音符号的字符][accented-characters],但是仅此而已。参见[#37]。
|
||||||
|
|
||||||
|
自 Linux 上的 scrcpy v1.20 之后,可以模拟[物理键盘][hid] (HID)。
|
||||||
|
|
||||||
[text-input]: https://github.com/Genymobile/scrcpy/issues?q=is%3Aopen+is%3Aissue+label%3Aunicode
|
[text-input]: https://github.com/Genymobile/scrcpy/issues?q=is%3Aopen+is%3Aissue+label%3Aunicode
|
||||||
[accented-characters]: https://blog.rom1v.com/2018/03/introducing-scrcpy/#handle-accented-characters
|
[accented-characters]: https://blog.rom1v.com/2018/03/introducing-scrcpy/#handle-accented-characters
|
||||||
[#37]: https://github.com/Genymobile/scrcpy/issues/37
|
[#37]: https://github.com/Genymobile/scrcpy/issues/37
|
||||||
|
[hid]: README.md#physical-keyboard-simulation-hid
|
||||||
|
|
||||||
|
|
||||||
## 客户端相关问题
|
## 客户端相关问题
|
||||||
@@ -129,7 +145,6 @@ scrcpy
|
|||||||
|
|
||||||
[#40]: https://github.com/Genymobile/scrcpy/issues/40
|
[#40]: https://github.com/Genymobile/scrcpy/issues/40
|
||||||
|
|
||||||
|
|
||||||
为了提升降尺度的质量,如果渲染器是OpenGL并且支持mip映射,就会自动开启三线性过滤。
|
为了提升降尺度的质量,如果渲染器是OpenGL并且支持mip映射,就会自动开启三线性过滤。
|
||||||
|
|
||||||
在Windows上,你可能希望强制使用OpenGL:
|
在Windows上,你可能希望强制使用OpenGL:
|
||||||
@@ -177,6 +192,7 @@ scrcpy
|
|||||||
## 崩溃
|
## 崩溃
|
||||||
|
|
||||||
### 异常
|
### 异常
|
||||||
|
|
||||||
可能有很多原因。一个常见的原因是您的设备无法按给定清晰度进行编码:
|
可能有很多原因。一个常见的原因是您的设备无法按给定清晰度进行编码:
|
||||||
|
|
||||||
> ```
|
> ```
|
||||||
@@ -204,12 +220,40 @@ scrcpy -m 1024
|
|||||||
scrcpy -m 800
|
scrcpy -m 800
|
||||||
```
|
```
|
||||||
|
|
||||||
|
自 scrcpy v1.22以来,scrcpy 会自动在失败前以更低的分辨率重试。这种行为可以用`--no-downsize-on-error`关闭。
|
||||||
|
|
||||||
你也可以尝试另一种 [编码器](README.md#encoder)。
|
你也可以尝试另一种 [编码器](README.md#encoder)。
|
||||||
|
|
||||||
|
|
||||||
|
如果您在 Android 12 上遇到此异常,则只需升级到 scrcpy >= 1.18 (见 [#2129]):
|
||||||
|
|
||||||
|
```
|
||||||
|
> ERROR: Exception on thread Thread[main,5,main]
|
||||||
|
java.lang.AssertionError: java.lang.reflect.InvocationTargetException
|
||||||
|
at com.genymobile.scrcpy.wrappers.SurfaceControl.setDisplaySurface(SurfaceControl.java:75)
|
||||||
|
...
|
||||||
|
Caused by: java.lang.reflect.InvocationTargetException
|
||||||
|
at java.lang.reflect.Method.invoke(Native Method)
|
||||||
|
at com.genymobile.scrcpy.wrappers.SurfaceControl.setDisplaySurface(SurfaceControl.java:73)
|
||||||
|
... 7 more
|
||||||
|
Caused by: java.lang.IllegalArgumentException: displayToken must not be null
|
||||||
|
at android.view.SurfaceControl$Transaction.setDisplaySurface(SurfaceControl.java:3067)
|
||||||
|
at android.view.SurfaceControl.setDisplaySurface(SurfaceControl.java:2147)
|
||||||
|
... 9 more
|
||||||
|
```
|
||||||
|
|
||||||
|
[#2129]: https://github.com/Genymobile/scrcpy/issues/2129
|
||||||
|
|
||||||
|
|
||||||
## Windows命令行
|
## Windows命令行
|
||||||
|
|
||||||
一些Windows用户不熟悉命令行。以下是如何打开终端并带参数执行`scrcpy`:
|
从 v1.22 开始,增加了一个“快捷方式”,可以直接在 scrcpy 目录打开一个终端。双击`open_a_terminal_here.bat`,然后输入你的命令。 例如:
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy --record file.mkv
|
||||||
|
```
|
||||||
|
|
||||||
|
您也可以打开终端并手动转到 scrcpy 文件夹:
|
||||||
|
|
||||||
1. 按下 <kbd>Windows</kbd>+<kbd>r</kbd>,打开一个对话框。
|
1. 按下 <kbd>Windows</kbd>+<kbd>r</kbd>,打开一个对话框。
|
||||||
2. 输入 `cmd` 并按 <kbd>Enter</kbd>,这样就打开了一个终端。
|
2. 输入 `cmd` 并按 <kbd>Enter</kbd>,这样就打开了一个终端。
|
||||||
@@ -233,7 +277,7 @@ scrcpy -m 800
|
|||||||
scrcpy --prefer-text --turn-screen-off --stay-awake
|
scrcpy --prefer-text --turn-screen-off --stay-awake
|
||||||
```
|
```
|
||||||
|
|
||||||
然后双击刚刚创建的文件。
|
然后只需双击刚刚创建的文件。
|
||||||
|
|
||||||
你也可以编辑 `scrcpy-console.bat` 或者 `scrcpy-noconsole.vbs`(的副本)来添加参数。
|
你也可以编辑 `scrcpy-console.bat` 或者 `scrcpy-noconsole.vbs`(的副本)来添加参数。
|
||||||
|
|
||||||
|
|||||||
81
README.md
81
README.md
@@ -1,7 +1,9 @@
|
|||||||
# scrcpy (v1.21)
|
# scrcpy (v1.22)
|
||||||
|
|
||||||
<img src="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**"_
|
||||||
|
|
||||||
[Read in another language](#translations)
|
[Read in another language](#translations)
|
||||||
|
|
||||||
This application provides display and control of Android devices connected via
|
This application provides display and control of Android devices connected via
|
||||||
@@ -33,6 +35,7 @@ Its features include:
|
|||||||
(Linux-only)
|
(Linux-only)
|
||||||
- [physical mouse simulation (HID)](#physical-mouse-simulation-hid)
|
- [physical mouse simulation (HID)](#physical-mouse-simulation-hid)
|
||||||
(Linux-only)
|
(Linux-only)
|
||||||
|
- [OTG mode](#otg) (Linux-only)
|
||||||
- and more…
|
- and more…
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
@@ -73,6 +76,12 @@ On Debian and Ubuntu:
|
|||||||
apt install scrcpy
|
apt install scrcpy
|
||||||
```
|
```
|
||||||
|
|
||||||
|
On Arch Linux:
|
||||||
|
|
||||||
|
```
|
||||||
|
pacman -S scrcpy
|
||||||
|
```
|
||||||
|
|
||||||
A [Snap] package is available: [`scrcpy`][snap-link].
|
A [Snap] package is available: [`scrcpy`][snap-link].
|
||||||
|
|
||||||
[snap-link]: https://snapstats.org/snaps/scrcpy
|
[snap-link]: https://snapstats.org/snaps/scrcpy
|
||||||
@@ -84,10 +93,6 @@ For Fedora, a [COPR] package is available: [`scrcpy`][copr-link].
|
|||||||
[COPR]: https://fedoraproject.org/wiki/Category:Copr
|
[COPR]: https://fedoraproject.org/wiki/Category:Copr
|
||||||
[copr-link]: https://copr.fedorainfracloud.org/coprs/zeno/scrcpy/
|
[copr-link]: https://copr.fedorainfracloud.org/coprs/zeno/scrcpy/
|
||||||
|
|
||||||
For Arch Linux, an [AUR] package is available: [`scrcpy`][aur-link].
|
|
||||||
|
|
||||||
[AUR]: https://wiki.archlinux.org/index.php/Arch_User_Repository
|
|
||||||
[aur-link]: https://aur.archlinux.org/packages/scrcpy/
|
|
||||||
|
|
||||||
For Gentoo, an [Ebuild] is available: [`scrcpy/`][ebuild-link].
|
For Gentoo, an [Ebuild] is available: [`scrcpy/`][ebuild-link].
|
||||||
|
|
||||||
@@ -103,10 +108,10 @@ process][BUILD_simple]).
|
|||||||
For Windows, for simplicity, a prebuilt archive with all the dependencies
|
For Windows, for simplicity, a prebuilt archive with all the dependencies
|
||||||
(including `adb`) is available:
|
(including `adb`) is available:
|
||||||
|
|
||||||
- [`scrcpy-win64-v1.21.zip`][direct-win64]
|
- [`scrcpy-win64-v1.22.zip`][direct-win64]
|
||||||
_(SHA-256: fdab0c1421353b592a9bbcebd6e252675eadccca65cca8105686feaa9c1ded53)_
|
_(SHA-256: ce4d9b8cc761e29862c4a72d8ad6f538bdd1f1831d15fd1f36633cd3b403db82)_
|
||||||
|
|
||||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.21/scrcpy-win64-v1.21.zip
|
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.22/scrcpy-win64-v1.22.zip
|
||||||
|
|
||||||
It is also available in [Chocolatey]:
|
It is also available in [Chocolatey]:
|
||||||
|
|
||||||
@@ -417,7 +422,7 @@ scrcpy -b2M -m800 # short version
|
|||||||
|
|
||||||
#### Multi-devices
|
#### Multi-devices
|
||||||
|
|
||||||
If several devices are listed in `adb devices`, you must specify the _serial_:
|
If several devices are listed in `adb devices`, you can specify the _serial_:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scrcpy --serial 0123456789abcdef
|
scrcpy --serial 0123456789abcdef
|
||||||
@@ -431,6 +436,19 @@ scrcpy --serial 192.168.0.1:5555
|
|||||||
scrcpy -s 192.168.0.1:5555 # short version
|
scrcpy -s 192.168.0.1:5555 # short version
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If only one device is connected via either USB or TCP/IP, it is possible to
|
||||||
|
select it automatically:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Select the only device connected via USB
|
||||||
|
scrcpy -d # like adb -d
|
||||||
|
scrcpy --select-usb # long version
|
||||||
|
|
||||||
|
# Select the only device connected via TCP/IP
|
||||||
|
scrcpy -e # like adb -e
|
||||||
|
scrcpy --select-tcpip # long version
|
||||||
|
```
|
||||||
|
|
||||||
You can start several instances of _scrcpy_ for several devices.
|
You can start several instances of _scrcpy_ for several devices.
|
||||||
|
|
||||||
#### Autostart on device connection
|
#### Autostart on device connection
|
||||||
@@ -847,6 +865,36 @@ Special capture keys, either <kbd>Alt</kbd> or <kbd>Super</kbd>, toggle
|
|||||||
the mouse back to the computer.
|
the mouse back to the computer.
|
||||||
|
|
||||||
|
|
||||||
|
#### OTG
|
||||||
|
|
||||||
|
It is possible to run _scrcpy_ with only physical keyboard and mouse simulation
|
||||||
|
(HID), as if the computer keyboard and mouse were plugged directly to the device
|
||||||
|
via an OTG cable.
|
||||||
|
|
||||||
|
In this mode, _adb_ (USB debugging) is not necessary, and mirroring is disabled.
|
||||||
|
|
||||||
|
To enable OTG mode:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --otg
|
||||||
|
# Pass the serial if several USB devices are available
|
||||||
|
scrcpy --otg -s 0123456789abcdef
|
||||||
|
```
|
||||||
|
|
||||||
|
It is possible to enable only HID keyboard or HID mouse:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --otg --hid-keyboard # keyboard only
|
||||||
|
scrcpy --otg --hid-mouse # mouse only
|
||||||
|
scrcpy --otg --hid-keyboard --hid-mouse # keyboard and mouse
|
||||||
|
# for convenience, enable both by default
|
||||||
|
scrcpy --otg # keyboard and mouse
|
||||||
|
```
|
||||||
|
|
||||||
|
Like `--hid-keyboard` and `--hid-mouse`, it only works if the device is
|
||||||
|
connected by USB, and is currently only supported on Linux.
|
||||||
|
|
||||||
|
|
||||||
#### Text injection preference
|
#### Text injection preference
|
||||||
|
|
||||||
There are two kinds of [events][textevents] generated when typing text:
|
There are two kinds of [events][textevents] generated when typing text:
|
||||||
@@ -967,7 +1015,7 @@ _<kbd>[Super]</kbd> is typically the <kbd>Windows</kbd> or <kbd>Cmd</kbd> key._
|
|||||||
| Click on `HOME` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _Middle-click_
|
| Click on `HOME` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _Middle-click_
|
||||||
| Click on `BACK` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _Right-click²_
|
| Click on `BACK` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _Right-click²_
|
||||||
| Click on `APP_SWITCH` | <kbd>MOD</kbd>+<kbd>s</kbd> \| _4th-click³_
|
| Click on `APP_SWITCH` | <kbd>MOD</kbd>+<kbd>s</kbd> \| _4th-click³_
|
||||||
| Click on `MENU` (unlock screen) | <kbd>MOD</kbd>+<kbd>m</kbd>
|
| Click on `MENU` (unlock screen)⁴ | <kbd>MOD</kbd>+<kbd>m</kbd>
|
||||||
| Click on `VOLUME_UP` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(up)_
|
| Click on `VOLUME_UP` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(up)_
|
||||||
| Click on `VOLUME_DOWN` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(down)_
|
| Click on `VOLUME_DOWN` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(down)_
|
||||||
| Click on `POWER` | <kbd>MOD</kbd>+<kbd>p</kbd>
|
| Click on `POWER` | <kbd>MOD</kbd>+<kbd>p</kbd>
|
||||||
@@ -978,9 +1026,9 @@ _<kbd>[Super]</kbd> is typically the <kbd>Windows</kbd> or <kbd>Cmd</kbd> key._
|
|||||||
| Expand notification panel | <kbd>MOD</kbd>+<kbd>n</kbd> \| _5th-click³_
|
| Expand notification panel | <kbd>MOD</kbd>+<kbd>n</kbd> \| _5th-click³_
|
||||||
| Expand settings panel | <kbd>MOD</kbd>+<kbd>n</kbd>+<kbd>n</kbd> \| _Double-5th-click³_
|
| Expand settings panel | <kbd>MOD</kbd>+<kbd>n</kbd>+<kbd>n</kbd> \| _Double-5th-click³_
|
||||||
| Collapse panels | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
| Collapse panels | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
||||||
| Copy to clipboard⁴ | <kbd>MOD</kbd>+<kbd>c</kbd>
|
| Copy to clipboard⁵ | <kbd>MOD</kbd>+<kbd>c</kbd>
|
||||||
| Cut to clipboard⁴ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
| Cut to clipboard⁵ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
||||||
| Synchronize clipboards and paste⁴ | <kbd>MOD</kbd>+<kbd>v</kbd>
|
| Synchronize clipboards and paste⁵ | <kbd>MOD</kbd>+<kbd>v</kbd>
|
||||||
| Inject computer clipboard text | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>
|
| Inject computer clipboard text | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>
|
||||||
| Enable/disable FPS counter (on stdout) | <kbd>MOD</kbd>+<kbd>i</kbd>
|
| Enable/disable FPS counter (on stdout) | <kbd>MOD</kbd>+<kbd>i</kbd>
|
||||||
| Pinch-to-zoom | <kbd>Ctrl</kbd>+_click-and-move_
|
| Pinch-to-zoom | <kbd>Ctrl</kbd>+_click-and-move_
|
||||||
@@ -990,7 +1038,8 @@ _<kbd>[Super]</kbd> is typically the <kbd>Windows</kbd> or <kbd>Cmd</kbd> key._
|
|||||||
_¹Double-click on black borders to remove them._
|
_¹Double-click on black borders to remove them._
|
||||||
_²Right-click turns the screen on if it was off, presses BACK otherwise._
|
_²Right-click turns the screen on if it was off, presses BACK otherwise._
|
||||||
_³4th and 5th mouse buttons, if your mouse has them._
|
_³4th and 5th mouse buttons, if your mouse has them._
|
||||||
_⁴Only on Android >= 7._
|
_⁴For react-native apps in development, `MENU` triggers development menu._
|
||||||
|
_⁵Only on Android >= 7._
|
||||||
|
|
||||||
Shortcuts with repeated keys are executted by releasing and pressing the key a
|
Shortcuts with repeated keys are executted by releasing and pressing the key a
|
||||||
second time. For example, to execute "Expand settings panel":
|
second time. For example, to execute "Expand settings panel":
|
||||||
@@ -1079,8 +1128,8 @@ This README is available in other languages:
|
|||||||
- [日本語 (Japanese, `jp`) - v1.19](README.jp.md)
|
- [日本語 (Japanese, `jp`) - v1.19](README.jp.md)
|
||||||
- [한국어 (Korean, `ko`) - v1.11](README.ko.md)
|
- [한국어 (Korean, `ko`) - v1.11](README.ko.md)
|
||||||
- [Português Brasileiro (Brazilian Portuguese, `pt-BR`) - v1.19](README.pt-br.md)
|
- [Português Brasileiro (Brazilian Portuguese, `pt-BR`) - v1.19](README.pt-br.md)
|
||||||
- [Español (Spanish, `sp`) - v1.17](README.sp.md)
|
- [Español (Spanish, `sp`) - v1.21](README.sp.md)
|
||||||
- [简体中文 (Simplified Chinese, `zh-Hans`) - v1.20](README.zh-Hans.md)
|
- [简体中文 (Simplified Chinese, `zh-Hans`) - v1.22](README.zh-Hans.md)
|
||||||
- [繁體中文 (Traditional Chinese, `zh-Hant`) - v1.15](README.zh-Hant.md)
|
- [繁體中文 (Traditional Chinese, `zh-Hant`) - v1.15](README.zh-Hant.md)
|
||||||
- [Turkish (Turkish, `tr`) - v1.18](README.tr.md)
|
- [Turkish (Turkish, `tr`) - v1.18](README.tr.md)
|
||||||
|
|
||||||
|
|||||||
341
README.sp.md
341
README.sp.md
@@ -1,24 +1,36 @@
|
|||||||
Solo se garantiza que el archivo [README](README.md) original esté actualizado.
|
Solo se garantiza que el archivo [README](README.md) original esté actualizado.
|
||||||
|
|
||||||
# scrcpy (v1.17)
|
# scrcpy (v1.21)
|
||||||
|
|
||||||
Esta aplicación proporciona imagen y control de un dispositivo Android conectado
|
<img src="data/icon.svg" width="128" height="128" alt="scrcpy" align="right" />
|
||||||
por USB (o [por TCP/IP][article-tcpip]). No requiere acceso _root_.
|
|
||||||
|
Esta aplicación proporciona control e imagen de un dispositivo Android conectado
|
||||||
|
por USB (o [por TCP/IP](#conexión)). No requiere acceso _root_.
|
||||||
Compatible con _GNU/Linux_, _Windows_ y _macOS_.
|
Compatible con _GNU/Linux_, _Windows_ y _macOS_.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Sus características principales son:
|
Se enfoca en:
|
||||||
|
- **ser ligera**: aplicación nativa, solo muestra la imagen del dispositivo
|
||||||
- **ligero** (nativo, solo muestra la imagen del dispositivo)
|
- **rendimiento**: 30~120fps, dependiendo del dispositivo
|
||||||
- **desempeño** (30~60fps)
|
- **calidad**: 1920×1080 o superior
|
||||||
- **calidad** (1920×1080 o superior)
|
- **baja latencia**: [35~70ms][lowlatency]
|
||||||
- **baja latencia** ([35~70ms][lowlatency])
|
- **inicio rápido**: ~1 segundo para mostrar la primera imagen
|
||||||
- **corto tiempo de inicio** (~1 segundo para mostrar la primera imagen)
|
- **no intrusivo**: no deja nada instalado en el dispositivo
|
||||||
- **no intrusivo** (no se deja nada instalado en el dispositivo)
|
- **beneficios**: sin cuentas, sin anuncios, no requiere acceso a internet
|
||||||
|
- **libertad**: software gratis y de código abierto
|
||||||
|
|
||||||
[lowlatency]: https://github.com/Genymobile/scrcpy/pull/646
|
[lowlatency]: https://github.com/Genymobile/scrcpy/pull/646
|
||||||
|
|
||||||
|
Con la aplicación puede:
|
||||||
|
- [grabar la pantalla](#capturas-y-grabaciones)
|
||||||
|
- duplicar la imagen con [la pantalla apagada](#apagar-la-pantalla)
|
||||||
|
- [copiar y pegar](#copiar-y-pegar) en ambos sentidos
|
||||||
|
- [configurar la calidad](#configuración-de-captura)
|
||||||
|
- usar la pantalla del dispositivo [como webcam (V4L2)](#v4l2loopback) (solo en Linux)
|
||||||
|
- [emular un teclado físico (HID)](#emular-teclado-físico-hid)
|
||||||
|
(solo en Linux)
|
||||||
|
- y mucho más…
|
||||||
|
|
||||||
## Requisitos
|
## Requisitos
|
||||||
|
|
||||||
@@ -51,7 +63,7 @@ Construir desde la fuente: [BUILD] ([proceso simplificado][BUILD_simple])
|
|||||||
|
|
||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
En Debian (_test_ y _sid_ por ahora) y Ubuntu (20.04):
|
En Debian y Ubuntu:
|
||||||
|
|
||||||
```
|
```
|
||||||
apt install scrcpy
|
apt install scrcpy
|
||||||
@@ -125,7 +137,7 @@ Necesitarás `adb`, accesible desde `PATH`. Si aún no lo tienes:
|
|||||||
brew install android-platform-tools
|
brew install android-platform-tools
|
||||||
```
|
```
|
||||||
|
|
||||||
También está disponible en [MacPorts], que configurará el adb automáticamente:
|
También está disponible en [MacPorts], que configura el adb automáticamente:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo port install scrcpy
|
sudo port install scrcpy
|
||||||
@@ -153,7 +165,7 @@ scrcpy --help
|
|||||||
|
|
||||||
## Características
|
## Características
|
||||||
|
|
||||||
### Capturar configuración
|
### Configuración de captura
|
||||||
|
|
||||||
#### Reducir la definición
|
#### Reducir la definición
|
||||||
|
|
||||||
@@ -208,10 +220,11 @@ Si `--max-size` también está especificado, el cambio de tamaño es aplicado de
|
|||||||
Para fijar la rotación de la transmisión:
|
Para fijar la rotación de la transmisión:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scrcpy --lock-video-orientation 0 # orientación normal
|
scrcpy --lock-video-orientation # orientación inicial
|
||||||
scrcpy --lock-video-orientation 1 # 90° contrarreloj
|
scrcpy --lock-video-orientation=0 # orientación normal
|
||||||
scrcpy --lock-video-orientation 2 # 180°
|
scrcpy --lock-video-orientation=1 # 90° contrarreloj
|
||||||
scrcpy --lock-video-orientation 3 # 90° sentido de las agujas del reloj
|
scrcpy --lock-video-orientation=2 # 180°
|
||||||
|
scrcpy --lock-video-orientation=3 # 90° sentido de las agujas del reloj
|
||||||
```
|
```
|
||||||
|
|
||||||
Esto afecta la rotación de la grabación.
|
Esto afecta la rotación de la grabación.
|
||||||
@@ -233,7 +246,10 @@ Para listar los codificadores disponibles, puedes pasar un nombre de codificador
|
|||||||
scrcpy --encoder _
|
scrcpy --encoder _
|
||||||
```
|
```
|
||||||
|
|
||||||
### Grabación
|
### Capturas y grabaciones
|
||||||
|
|
||||||
|
|
||||||
|
#### Grabación
|
||||||
|
|
||||||
Es posible grabar la pantalla mientras se transmite:
|
Es posible grabar la pantalla mientras se transmite:
|
||||||
|
|
||||||
@@ -250,17 +266,117 @@ scrcpy -Nr file.mkv
|
|||||||
# interrumpe la grabación con Ctrl+C
|
# interrumpe la grabación con Ctrl+C
|
||||||
```
|
```
|
||||||
|
|
||||||
"Skipped frames" son grabados, incluso si no son mostrados en tiempo real (por razones de desempeño). Los frames tienen _marcas de tiempo_ en el dispositivo, por lo que el "[packet delay
|
Los "skipped frames" son grabados, incluso si no se mostrados en tiempo real (por razones de desempeño). Los frames tienen _marcas de tiempo_ en el dispositivo, por lo que el "[packet delay
|
||||||
variation]" no impacta el archivo grabado.
|
variation]" no impacta el archivo grabado.
|
||||||
|
|
||||||
[packet delay variation]: https://en.wikipedia.org/wiki/Packet_delay_variation
|
[packet delay variation]: https://en.wikipedia.org/wiki/Packet_delay_variation
|
||||||
|
|
||||||
|
|
||||||
|
#### v4l2loopback
|
||||||
|
|
||||||
|
En Linux se puede mandar el stream del video a un dispositivo loopback v4l2, por
|
||||||
|
lo que se puede abrir el dispositivo Android como una webcam con cualquier
|
||||||
|
programa compatible con v4l2.
|
||||||
|
|
||||||
|
Se debe instalar el modulo `v4l2loopback`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt install v4l2loopback-dkms
|
||||||
|
```
|
||||||
|
|
||||||
|
Para crear un dispositivo v4l2:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo modprobe v4l2loopback
|
||||||
|
```
|
||||||
|
|
||||||
|
Esto va a crear un nuevo dispositivo de video en `/dev/videoN`, donde `N` es un número
|
||||||
|
(hay más [opciones](https://github.com/umlaeute/v4l2loopback#options) disponibles
|
||||||
|
para crear múltiples dispositivos o usar un ID en específico).
|
||||||
|
|
||||||
|
Para ver los dispositivos disponibles:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# requiere el paquete v4l-utils
|
||||||
|
v4l2-ctl --list-devices
|
||||||
|
# simple pero generalmente suficiente
|
||||||
|
ls /dev/video*
|
||||||
|
```
|
||||||
|
|
||||||
|
Para iniciar scrcpy usando una fuente v4l2:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --v4l2-sink=/dev/videoN
|
||||||
|
scrcpy --v4l2-sink=/dev/videoN --no-display # deshabilita la transmisión de imagen
|
||||||
|
scrcpy --v4l2-sink=/dev/videoN -N # más corto
|
||||||
|
```
|
||||||
|
|
||||||
|
(reemplace `N` con el ID del dispositivo, compruebe con `ls /dev/video*`)
|
||||||
|
|
||||||
|
Una vez habilitado, podés abrir el stream del video con una herramienta compatible con v4l2:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ffplay -i /dev/videoN
|
||||||
|
vlc v4l2:///dev/videoN # VLC puede agregar un delay por buffering
|
||||||
|
```
|
||||||
|
|
||||||
|
Por ejemplo, podrías capturar el video usando [OBS].
|
||||||
|
|
||||||
|
[OBS]: https://obsproject.com/
|
||||||
|
|
||||||
|
|
||||||
|
#### Buffering
|
||||||
|
|
||||||
|
Es posible agregar buffering al video. Esto reduce el ruido en la imagen ("jitter")
|
||||||
|
pero aumenta la latencia (vea [#2464]).
|
||||||
|
|
||||||
|
[#2464]: https://github.com/Genymobile/scrcpy/issues/2464
|
||||||
|
|
||||||
|
La opción de buffering está disponible para la transmisión de imagen:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --display-buffer=50 # agrega 50 ms de buffering a la imagen
|
||||||
|
```
|
||||||
|
|
||||||
|
y las fuentes V4L2:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --v4l2-buffer=500 # agrega 500 ms de buffering a la fuente v4l2
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Conexión
|
### Conexión
|
||||||
|
|
||||||
#### Inalámbrica
|
#### TCP/IP (Inalámbrica)
|
||||||
|
|
||||||
_Scrcpy_ usa `adb` para comunicarse con el dispositivo, y `adb` puede [conectarse] vía TCP/IP:
|
_Scrcpy_ usa `adb` para comunicarse con el dispositivo, y `adb` puede [conectarse] vía TCP/IP.
|
||||||
|
El dispositivo debe estar conectado a la misma red que la computadora:
|
||||||
|
|
||||||
|
##### Automático
|
||||||
|
|
||||||
|
La opción `--tcpip` permite configurar la conexión automáticamente. Hay 2 variables.
|
||||||
|
|
||||||
|
Si el dispositivo (accesible en 192.168.1.1 para este ejemplo) ya está escuchando
|
||||||
|
en un puerto (generalmente 5555) esperando una conexión adb entrante, entonces corré:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --tcpip=192.168.1.1 # el puerto default es 5555
|
||||||
|
scrcpy --tcpip=192.168.1.1:5555
|
||||||
|
```
|
||||||
|
|
||||||
|
Si el dispositivo no tiene habilitado el modo adb TCP/IP (o si no sabés la dirección IP),
|
||||||
|
entonces conectá el dispositivo por USB y corré:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --tcpip # sin argumentos
|
||||||
|
```
|
||||||
|
|
||||||
|
El programa buscará automáticamente la IP del dispositivo, habilitará el modo TCP/IP, y
|
||||||
|
se conectará al dispositivo antes de comenzar a transmitir la imagen.
|
||||||
|
|
||||||
|
##### Manual
|
||||||
|
|
||||||
|
Como alternativa, se puede habilitar la conexión TCP/IP manualmente usando `adb`:
|
||||||
|
|
||||||
1. Conecta el dispositivo al mismo Wi-Fi que tu computadora.
|
1. Conecta el dispositivo al mismo Wi-Fi que tu computadora.
|
||||||
2. Obtén la dirección IP del dispositivo, en Ajustes → Acerca del dispositivo → Estado, o ejecutando este comando:
|
2. Obtén la dirección IP del dispositivo, en Ajustes → Acerca del dispositivo → Estado, o ejecutando este comando:
|
||||||
@@ -302,7 +418,7 @@ scrcpy -s 192.168.0.1:5555 # versión breve
|
|||||||
|
|
||||||
Puedes iniciar múltiples instancias de _scrcpy_ para múltiples dispositivos.
|
Puedes iniciar múltiples instancias de _scrcpy_ para múltiples dispositivos.
|
||||||
|
|
||||||
#### Autoiniciar al detectar dispositivo
|
#### Iniciar automáticamente al detectar dispositivo
|
||||||
|
|
||||||
Puedes utilizar [AutoAdb]:
|
Puedes utilizar [AutoAdb]:
|
||||||
|
|
||||||
@@ -312,37 +428,82 @@ autoadb scrcpy -s '{}'
|
|||||||
|
|
||||||
[AutoAdb]: https://github.com/rom1v/autoadb
|
[AutoAdb]: https://github.com/rom1v/autoadb
|
||||||
|
|
||||||
#### Túnel SSH
|
#### Túneles
|
||||||
|
|
||||||
Para conectarse a un dispositivo remoto, es posible conectar un cliente local de `adb` a un servidor remoto `adb` (siempre y cuando utilicen la misma versión de protocolos _adb_):
|
Para conectarse a un dispositivo remoto, es posible conectar un cliente local `adb` a un servidor remoto `adb` (siempre y cuando utilicen la misma versión de protocolos _adb_).
|
||||||
|
|
||||||
|
##### Servidor ADB remoto
|
||||||
|
|
||||||
|
Para conectarse a un servidor ADB remoto, haz que el servidor escuche en todas las interfaces:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
adb kill-server # cierra el servidor local adb en 5037
|
adb kill-server
|
||||||
ssh -CN -L5037:localhost:5037 -R27183:localhost:27183 your_remote_computer
|
adb -a nodaemon server start
|
||||||
# conserva este servidor abierto
|
# conserva este servidor abierto
|
||||||
```
|
```
|
||||||
|
|
||||||
Desde otra terminal:
|
**Advertencia: todas las comunicaciones entre los clientes y el servidor ADB están desencriptadas.**
|
||||||
|
|
||||||
|
Supondremos que este servidor se puede acceder desde 192.168.1.2. Entonces, desde otra
|
||||||
|
terminal, corré scrcpy:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
export ADB_SERVER_SOCKET=tcp:192.168.1.2:5037
|
||||||
|
scrcpy --tunnel-host=192.168.1.2
|
||||||
|
```
|
||||||
|
|
||||||
|
Por default, scrcpy usa el puerto local que se usó para establecer el tunel
|
||||||
|
`adb forward` (típicamente `27183`, vea `--port`). También es posible forzar un
|
||||||
|
puerto diferente (puede resultar útil en situaciones más complejas, donde haya
|
||||||
|
múltiples redirecciones):
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy --tunnel-port=1234
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
##### Túnel SSH
|
||||||
|
|
||||||
|
Para comunicarse con un servidor ADB remoto de forma segura, es preferible usar un túnel SSH.
|
||||||
|
|
||||||
|
Primero, asegurate que el servidor ADB está corriendo en la computadora remota:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
adb start-server
|
||||||
|
```
|
||||||
|
|
||||||
|
Después, establecé el túnel SSH:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# local 5038 --> remoto 5037
|
||||||
|
# local 27183 <-- remoto 27183
|
||||||
|
ssh -CN -L5038:localhost:5037 -R27183:localhost:27183 your_remote_computer
|
||||||
|
# conserva este servidor abierto
|
||||||
|
```
|
||||||
|
|
||||||
|
Desde otra terminal, corré scrcpy:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export ADB_SERVER_SOCKET=tcp:localhost:5038
|
||||||
scrcpy
|
scrcpy
|
||||||
```
|
```
|
||||||
|
|
||||||
Para evitar habilitar "remote port forwarding", puedes forzar una "forward connection" (nótese el argumento `-L` en vez de `-R`):
|
Para evitar habilitar "remote port forwarding", puedes forzar una "forward connection" (nótese el argumento `-L` en vez de `-R`):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
adb kill-server # cierra el servidor local adb en 5037
|
# local 5038 --> remoto 5037
|
||||||
ssh -CN -L5037:localhost:5037 -L27183:localhost:27183 your_remote_computer
|
# local 27183 --> remoto 27183
|
||||||
|
ssh -CN -L5038:localhost:5037 -L27183:localhost:27183 your_remote_computer
|
||||||
# conserva este servidor abierto
|
# conserva este servidor abierto
|
||||||
```
|
```
|
||||||
|
|
||||||
Desde otra terminal:
|
Desde otra terminal, corré scrcpy:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
export ADB_SERVER_SOCKET=tcp:localhost:5038
|
||||||
scrcpy --force-adb-forward
|
scrcpy --force-adb-forward
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
Al igual que las conexiones inalámbricas, puede resultar útil reducir la calidad:
|
Al igual que las conexiones inalámbricas, puede resultar útil reducir la calidad:
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -402,7 +563,7 @@ Se puede rotar la ventana:
|
|||||||
scrcpy --rotation 1
|
scrcpy --rotation 1
|
||||||
```
|
```
|
||||||
|
|
||||||
Los valores posibles son:
|
Los posibles valores son:
|
||||||
- `0`: sin rotación
|
- `0`: sin rotación
|
||||||
- `1`: 90 grados contrarreloj
|
- `1`: 90 grados contrarreloj
|
||||||
- `2`: 180 grados
|
- `2`: 180 grados
|
||||||
@@ -416,7 +577,7 @@ Nótese que _scrcpy_ maneja 3 diferentes rotaciones:
|
|||||||
- `--rotation` (o <kbd>MOD</kbd>+<kbd>←</kbd>/<kbd>MOD</kbd>+<kbd>→</kbd>) rota solo el contenido de la imagen. Esto solo afecta a la imagen mostrada, no a la grabación.
|
- `--rotation` (o <kbd>MOD</kbd>+<kbd>←</kbd>/<kbd>MOD</kbd>+<kbd>→</kbd>) rota solo el contenido de la imagen. Esto solo afecta a la imagen mostrada, no a la grabación.
|
||||||
|
|
||||||
|
|
||||||
### Otras opciones menores
|
### Otras opciones
|
||||||
|
|
||||||
#### Solo lectura ("Read-only")
|
#### Solo lectura ("Read-only")
|
||||||
|
|
||||||
@@ -479,14 +640,12 @@ scrcpy -Sw # versión breve
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
#### Renderizar frames vencidos
|
#### Apagar al cerrar la aplicación
|
||||||
|
|
||||||
Por defecto, para minimizar la latencia, _scrcpy_ siempre renderiza el último frame disponible decodificado, e ignora cualquier frame anterior.
|
Para apagar la pantalla del dispositivo al cerrar scrcpy:
|
||||||
|
|
||||||
Para forzar el renderizado de todos los frames (a costo de posible aumento de latencia), use:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scrcpy --render-expired-frames
|
scrcpy --power-off-on-close
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Mostrar clicks
|
#### Mostrar clicks
|
||||||
@@ -548,6 +707,8 @@ Además, <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd> permite inyectar el texto
|
|||||||
|
|
||||||
Algunos dispositivos no se comportan como es esperado al establecer el portapapeles programáticamente. La opción `--legacy-paste` está disponible para cambiar el comportamiento de <kbd>Ctrl</kbd>+<kbd>v</kbd> y <kbd>MOD</kbd>+<kbd>v</kbd> para que también inyecten el texto del portapapeles de la computadora como una secuencia de teclas (de la misma forma que <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>).
|
Algunos dispositivos no se comportan como es esperado al establecer el portapapeles programáticamente. La opción `--legacy-paste` está disponible para cambiar el comportamiento de <kbd>Ctrl</kbd>+<kbd>v</kbd> y <kbd>MOD</kbd>+<kbd>v</kbd> para que también inyecten el texto del portapapeles de la computadora como una secuencia de teclas (de la misma forma que <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>).
|
||||||
|
|
||||||
|
Para deshabilitar la auto-sincronización del portapapeles, use `--no-clipboard-autosync`.
|
||||||
|
|
||||||
#### Pellizcar para zoom
|
#### Pellizcar para zoom
|
||||||
|
|
||||||
Para simular "pinch-to-zoom": <kbd>Ctrl</kbd>+_click-y-mover_.
|
Para simular "pinch-to-zoom": <kbd>Ctrl</kbd>+_click-y-mover_.
|
||||||
@@ -556,6 +717,48 @@ Más precisamente, mantén <kbd>Ctrl</kbd> mientras presionas botón izquierdo.
|
|||||||
|
|
||||||
Concretamente, scrcpy genera clicks adicionales con un "dedo virtual" en la posición invertida respecto al centro de la pantalla.
|
Concretamente, scrcpy genera clicks adicionales con un "dedo virtual" en la posición invertida respecto al centro de la pantalla.
|
||||||
|
|
||||||
|
#### Emular teclado físico (HID)
|
||||||
|
|
||||||
|
Por default, scrcpy usa el sistema de Android para la injección de teclas o texto:
|
||||||
|
funciona en todas partes, pero está limitado a ASCII.
|
||||||
|
|
||||||
|
En Linux, scrcpy puede emular un teclado USB físico en Android para proveer
|
||||||
|
una mejor experiencia al enviar _inputs_ (usando [USB HID vía AOAv2][hid-aoav2]):
|
||||||
|
deshabilita el teclado virtual y funciona para todos los caracteres y IME.
|
||||||
|
|
||||||
|
[hid-aoav2]: https://source.android.com/devices/accessories/aoa2#hid-support
|
||||||
|
|
||||||
|
Sin embargo, solo funciona si el dispositivo está conectado por USB, y por ahora
|
||||||
|
solo funciona en Linux.
|
||||||
|
|
||||||
|
Para habilitar este modo:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --hid-keyboard
|
||||||
|
scrcpy -K # más corto
|
||||||
|
```
|
||||||
|
|
||||||
|
Si por alguna razón falla (por ejemplo si el dispositivo no está conectado vía
|
||||||
|
USB), automáticamente vuelve al modo default (un mensaje se escribirá en la consola).
|
||||||
|
Se puede usar los mismos argumentos en la línea de comandos tanto si se conecta con
|
||||||
|
USB o vía TCP/IP.
|
||||||
|
|
||||||
|
En este modo, los _raw key events_ (_scancodes_) se envían al dispositivo, independientemente
|
||||||
|
del mapeo del teclado en el host. Por eso, si el diseño de tu teclado no concuerda, debe ser
|
||||||
|
configurado en el dispositivo Android, en Ajustes → Sistema → Idioma y Entrada de Texto
|
||||||
|
→ [Teclado Físico].
|
||||||
|
|
||||||
|
Se puede iniciar automáticamente en esta página de ajustes:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
adb shell am start -a android.settings.HARD_KEYBOARD_SETTINGS
|
||||||
|
```
|
||||||
|
|
||||||
|
Sin embargo, la opción solo está disponible cuando el teclado HID está activo
|
||||||
|
(o cuando se conecta un teclado físico).
|
||||||
|
|
||||||
|
[Teclado Físico]: https://github.com/Genymobile/scrcpy/pull/2632#issuecomment-923756915
|
||||||
|
|
||||||
|
|
||||||
#### Preferencias de inyección de texto
|
#### Preferencias de inyección de texto
|
||||||
|
|
||||||
@@ -573,13 +776,23 @@ scrcpy --prefer-text
|
|||||||
|
|
||||||
(Pero esto romperá el comportamiento del teclado en los juegos)
|
(Pero esto romperá el comportamiento del teclado en los juegos)
|
||||||
|
|
||||||
|
Por el contrario, se puede forzar scrcpy para siempre injectar _raw key events_:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --raw-key-events
|
||||||
|
```
|
||||||
|
|
||||||
|
Estas opciones no tienen efecto en los teclados HID (todos los _key events_ son enviados como
|
||||||
|
_scancodes_ en este modo).
|
||||||
|
|
||||||
[textevents]: https://blog.rom1v.com/2018/03/introducing-scrcpy/#handle-text-input
|
[textevents]: https://blog.rom1v.com/2018/03/introducing-scrcpy/#handle-text-input
|
||||||
[prefertext]: https://github.com/Genymobile/scrcpy/issues/650#issuecomment-512945343
|
[prefertext]: https://github.com/Genymobile/scrcpy/issues/650#issuecomment-512945343
|
||||||
|
|
||||||
|
|
||||||
#### Repetir tecla
|
#### Repetir tecla
|
||||||
|
|
||||||
Por defecto, mantener una tecla presionada genera múltiples _key events_. Esto puede causar problemas de desempeño en algunos juegos, donde estos eventos no tienen sentido de todos modos.
|
Por defecto, mantener una tecla presionada genera múltiples _key events_. Esto puede
|
||||||
|
causar problemas de desempeño en algunos juegos, donde estos eventos no tienen sentido de todos modos.
|
||||||
|
|
||||||
Para evitar enviar _key events_ repetidos:
|
Para evitar enviar _key events_ repetidos:
|
||||||
|
|
||||||
@@ -587,6 +800,9 @@ Para evitar enviar _key events_ repetidos:
|
|||||||
scrcpy --no-key-repeat
|
scrcpy --no-key-repeat
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Estas opciones no tienen efecto en los teclados HID (Android maneja directamente
|
||||||
|
las repeticiones de teclas en este modo)
|
||||||
|
|
||||||
|
|
||||||
#### Botón derecho y botón del medio
|
#### Botón derecho y botón del medio
|
||||||
|
|
||||||
@@ -608,14 +824,15 @@ No hay respuesta visual, un mensaje se escribirá en la consola.
|
|||||||
|
|
||||||
#### Enviar archivos al dispositivo
|
#### Enviar archivos al dispositivo
|
||||||
|
|
||||||
Para enviar un archivo a `/sdcard/` en el dispositivo, arrastre y suelte un archivo (no APK) a la ventana de _scrcpy_.
|
Para enviar un archivo a `/sdcard/Download/` en el dispositivo, arrastre y suelte
|
||||||
|
un archivo (no APK) a la ventana de _scrcpy_.
|
||||||
|
|
||||||
No hay respuesta visual, un mensaje se escribirá en la consola.
|
No hay ninguna respuesta visual, un mensaje se escribirá en la consola.
|
||||||
|
|
||||||
El directorio de destino puede ser modificado al iniciar:
|
El directorio de destino puede ser modificado al iniciar:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scrcpy --push-target=/sdcard/Download/
|
scrcpy --push-target=/sdcard/Movies/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -653,11 +870,11 @@ _<kbd>[Super]</kbd> es generalmente la tecla <kbd>Windows</kbd> o <kbd>Cmd</kbd>
|
|||||||
| Rotar pantalla hacia la izquierda | <kbd>MOD</kbd>+<kbd>←</kbd> _(izquierda)_
|
| Rotar pantalla hacia la izquierda | <kbd>MOD</kbd>+<kbd>←</kbd> _(izquierda)_
|
||||||
| Rotar pantalla hacia la derecha | <kbd>MOD</kbd>+<kbd>→</kbd> _(derecha)_
|
| Rotar pantalla hacia la derecha | <kbd>MOD</kbd>+<kbd>→</kbd> _(derecha)_
|
||||||
| Ajustar ventana a 1:1 ("pixel-perfect") | <kbd>MOD</kbd>+<kbd>g</kbd>
|
| Ajustar ventana a 1:1 ("pixel-perfect") | <kbd>MOD</kbd>+<kbd>g</kbd>
|
||||||
| Ajustar ventana para quitar los bordes negros| <kbd>MOD</kbd>+<kbd>w</kbd> \| _Doble click¹_
|
| Ajustar ventana para quitar los bordes negros| <kbd>MOD</kbd>+<kbd>w</kbd> \| _Doble click izquierdo¹_
|
||||||
| Click en `INICIO` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _Botón del medio_
|
| Click en `INICIO` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _Click medio_
|
||||||
| Click en `RETROCEDER` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _Botón derecho²_
|
| Click en `RETROCEDER` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _Click derecho²_
|
||||||
| Click en `CAMBIAR APLICACIÓN` | <kbd>MOD</kbd>+<kbd>s</kbd>
|
| Click en `CAMBIAR APLICACIÓN` | <kbd>MOD</kbd>+<kbd>s</kbd> \| _Cuarto botón³_
|
||||||
| Click en `MENÚ` (desbloquear pantalla) | <kbd>MOD</kbd>+<kbd>m</kbd>
|
| Click en `MENÚ` (desbloquear pantalla)⁴ | <kbd>MOD</kbd>+<kbd>m</kbd>
|
||||||
| Click en `SUBIR VOLUMEN` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(arriba)_
|
| Click en `SUBIR VOLUMEN` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(arriba)_
|
||||||
| Click en `BAJAR VOLUME` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(abajo)_
|
| Click en `BAJAR VOLUME` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(abajo)_
|
||||||
| Click en `ENCENDIDO` | <kbd>MOD</kbd>+<kbd>p</kbd>
|
| Click en `ENCENDIDO` | <kbd>MOD</kbd>+<kbd>p</kbd>
|
||||||
@@ -665,18 +882,30 @@ _<kbd>[Super]</kbd> es generalmente la tecla <kbd>Windows</kbd> o <kbd>Cmd</kbd>
|
|||||||
| Apagar pantalla (manteniendo la transmisión) | <kbd>MOD</kbd>+<kbd>o</kbd>
|
| Apagar pantalla (manteniendo la transmisión) | <kbd>MOD</kbd>+<kbd>o</kbd>
|
||||||
| Encender pantalla | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>o</kbd>
|
| Encender pantalla | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>o</kbd>
|
||||||
| Rotar pantalla del dispositivo | <kbd>MOD</kbd>+<kbd>r</kbd>
|
| Rotar pantalla del dispositivo | <kbd>MOD</kbd>+<kbd>r</kbd>
|
||||||
| Abrir panel de notificaciones | <kbd>MOD</kbd>+<kbd>n</kbd>
|
| Abrir panel de notificaciones | <kbd>MOD</kbd>+<kbd>n</kbd> \| _Quinto botón³_
|
||||||
| Cerrar panel de notificaciones | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
| Abrir panel de configuración | <kbd>MOD</kbd>+<kbd>n</kbd>+<kbd>n</kbd> \| _Doble quinto botón³_
|
||||||
| Copiar al portapapeles³ | <kbd>MOD</kbd>+<kbd>c</kbd>
|
| Cerrar paneles | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
||||||
| Cortar al portapapeles³ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
| Copiar al portapapeles⁵ | <kbd>MOD</kbd>+<kbd>c</kbd>
|
||||||
| Synchronizar portapapeles y pegar³ | <kbd>MOD</kbd>+<kbd>v</kbd>
|
| Cortar al portapapeles⁵ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
||||||
| inyectar texto del portapapeles de la PC | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>
|
| Synchronizar portapapeles y pegar⁵ | <kbd>MOD</kbd>+<kbd>v</kbd>
|
||||||
|
| Inyectar texto del portapapeles de la PC | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>
|
||||||
| Habilitar/Deshabilitar contador de FPS (en stdout) | <kbd>MOD</kbd>+<kbd>i</kbd>
|
| Habilitar/Deshabilitar contador de FPS (en stdout) | <kbd>MOD</kbd>+<kbd>i</kbd>
|
||||||
| Pellizcar para zoom | <kbd>Ctrl</kbd>+_click-y-mover_
|
| Pellizcar para zoom | <kbd>Ctrl</kbd>+_click-y-mover_
|
||||||
|
| Arrastrar y soltar un archivo (APK) | Instalar APK desde la computadora
|
||||||
|
| Arrastrar y soltar un archivo (no APK) | [Mover archivo al dispositivo](#enviar-archivos-al-dispositivo)
|
||||||
|
|
||||||
_¹Doble click en los bordes negros para eliminarlos._
|
_¹Doble click en los bordes negros para eliminarlos._
|
||||||
_²Botón derecho enciende la pantalla si estaba apagada, sino ejecuta RETROCEDER._
|
_²Botón derecho enciende la pantalla si estaba apagada, sino ejecuta RETROCEDER._
|
||||||
_³Solo en Android >= 7._
|
_³Cuarto y quinto botón del mouse, si tu mouse los tiene._
|
||||||
|
_⁴Para las apps react-native en desarrollo, `MENU` activa el menú de desarrollo._
|
||||||
|
_⁵Solo en Android >= 7._
|
||||||
|
|
||||||
|
Los shortcuts con teclas repetidas se ejecutan soltando y volviendo a apretar la tecla
|
||||||
|
por segunda vez. Por ejemplo, para ejecutar "Abrir panel de configuración":
|
||||||
|
|
||||||
|
1. Apretá y mantené apretado <kbd>MOD</kbd>.
|
||||||
|
2. Después apretá dos veces la tecla <kbd>n</kbd>.
|
||||||
|
3. Por último, soltá la tecla <kbd>MOD</kbd>.
|
||||||
|
|
||||||
Todos los atajos <kbd>Ctrl</kbd>+_tecla_ son enviados al dispositivo para que sean manejados por la aplicación activa.
|
Todos los atajos <kbd>Ctrl</kbd>+_tecla_ son enviados al dispositivo para que sean manejados por la aplicación activa.
|
||||||
|
|
||||||
@@ -691,6 +920,8 @@ ADB=/path/to/adb scrcpy
|
|||||||
|
|
||||||
Para sobreescribir el path del archivo `scrcpy-server`, configure el path en `SCRCPY_SERVER_PATH`.
|
Para sobreescribir el path del archivo `scrcpy-server`, configure el path en `SCRCPY_SERVER_PATH`.
|
||||||
|
|
||||||
|
Para sobreescribir el ícono, configure el path en `SCRCPY_ICON_PATH`.
|
||||||
|
|
||||||
|
|
||||||
## ¿Por qué _scrcpy_?
|
## ¿Por qué _scrcpy_?
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
_Only the original [README](README.md) is guaranteed to be up-to-date._
|
_Only the original [README](README.md) is guaranteed to be up-to-date._
|
||||||
|
|
||||||
只有原版的[README](README.md)会保持最新。
|
_只有原版的 [README](README.md)是保证最新的。_
|
||||||
|
|
||||||
Current version is based on [65b023a]
|
Current version is based on [f4c7044]
|
||||||
|
|
||||||
本文根据[65b023a]进行翻译。
|
本文根据[f4c7044]进行翻译。
|
||||||
|
|
||||||
[65b023a]: https://github.com/Genymobile/scrcpy/blob/65b023ac6d586593193fd5290f65e25603b68e02/README.md
|
[f4c7044]: https://github.com/Genymobile/scrcpy/blob/f4c7044b46ae28eb64cb5e1a15c9649a44023c70/README.md
|
||||||
|
|
||||||
# scrcpy (v1.20)
|
# scrcpy (v1.22)
|
||||||
|
|
||||||
<img src="data/icon.svg" width="128" height="128" alt="scrcpy" align="right" />
|
<img src="data/icon.svg" width="128" height="128" alt="scrcpy" align="right" />
|
||||||
|
|
||||||
|
_发音为 "**scr**een **c**o**py**"_
|
||||||
|
|
||||||
本应用程序可以显示并控制通过 USB (或 [TCP/IP][article-tcpip]) 连接的安卓设备,且不需要任何 _root_ 权限。本程序支持 _GNU/Linux_, _Windows_ 和 _macOS_。
|
本应用程序可以显示并控制通过 USB (或 [TCP/IP][article-tcpip]) 连接的安卓设备,且不需要任何 _root_ 权限。本程序支持 _GNU/Linux_, _Windows_ 和 _macOS_。
|
||||||
|
|
||||||

|

|
||||||
@@ -36,6 +38,8 @@ Current version is based on [65b023a]
|
|||||||
- [可配置显示质量](#采集设置)
|
- [可配置显示质量](#采集设置)
|
||||||
- 以设备屏幕[作为摄像头(V4L2)](#v4l2loopback) (仅限 Linux)
|
- 以设备屏幕[作为摄像头(V4L2)](#v4l2loopback) (仅限 Linux)
|
||||||
- [模拟物理键盘 (HID)](#物理键盘模拟-hid) (仅限 Linux)
|
- [模拟物理键盘 (HID)](#物理键盘模拟-hid) (仅限 Linux)
|
||||||
|
- [物理鼠标模拟 (HID)](#物理鼠标模拟-hid) (仅限 Linux)
|
||||||
|
- [OTG模式](#otg) (仅限 Linux)
|
||||||
- 更多 ……
|
- 更多 ……
|
||||||
|
|
||||||
## 系统要求
|
## 系统要求
|
||||||
@@ -68,12 +72,18 @@ Current version is based on [65b023a]
|
|||||||
|
|
||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
在 Debian (目前仅支持 _testing_ 和 _sid_ 分支) 和Ubuntu (20.04) 上:
|
在 Debian 和 Ubuntu 上:
|
||||||
|
|
||||||
```
|
```
|
||||||
apt install scrcpy
|
apt install scrcpy
|
||||||
```
|
```
|
||||||
|
|
||||||
|
在 Arch Linux 上:
|
||||||
|
|
||||||
|
```
|
||||||
|
pacman -S scrcpy
|
||||||
|
```
|
||||||
|
|
||||||
我们也提供 [Snap] 包: [`scrcpy`][snap-link]。
|
我们也提供 [Snap] 包: [`scrcpy`][snap-link]。
|
||||||
|
|
||||||
[snap-link]: https://snapstats.org/snaps/scrcpy
|
[snap-link]: https://snapstats.org/snaps/scrcpy
|
||||||
@@ -85,11 +95,6 @@ apt install scrcpy
|
|||||||
[COPR]: https://fedoraproject.org/wiki/Category:Copr
|
[COPR]: https://fedoraproject.org/wiki/Category:Copr
|
||||||
[copr-link]: https://copr.fedorainfracloud.org/coprs/zeno/scrcpy/
|
[copr-link]: https://copr.fedorainfracloud.org/coprs/zeno/scrcpy/
|
||||||
|
|
||||||
对 Arch Linux 我们提供 [AUR] 包: [`scrcpy`][aur-link]。
|
|
||||||
|
|
||||||
[AUR]: https://wiki.archlinux.org/index.php/Arch_User_Repository
|
|
||||||
[aur-link]: https://aur.archlinux.org/packages/scrcpy/
|
|
||||||
|
|
||||||
对 Gentoo 我们提供 [Ebuild] 包:[`scrcpy/`][ebuild-link]。
|
对 Gentoo 我们提供 [Ebuild] 包:[`scrcpy/`][ebuild-link]。
|
||||||
|
|
||||||
[Ebuild]: https://wiki.gentoo.org/wiki/Ebuild
|
[Ebuild]: https://wiki.gentoo.org/wiki/Ebuild
|
||||||
@@ -343,9 +348,32 @@ scrcpy --v4l2-buffer=500 # 为 v4l2 漏增加 500 毫秒的缓冲
|
|||||||
|
|
||||||
### 连接
|
### 连接
|
||||||
|
|
||||||
#### 无线
|
#### TCP/IP (无线)
|
||||||
|
|
||||||
_Scrcpy_ 使用 `adb` 与设备通信,并且 `adb` 支持通过 TCP/IP [连接]到设备:
|
_Scrcpy_ 使用 `adb` 与设备通信,并且 `adb` 支持通过 TCP/IP [连接]到设备(设备必须连接与电脑相同的网络)。
|
||||||
|
|
||||||
|
##### 自动配置
|
||||||
|
|
||||||
|
参数 `--tcpip` 允许自动配置连接。这里有两种方式。
|
||||||
|
|
||||||
|
对于传入的 adb 连接,如果设备(在这个例子中以192.168.1.1为可用地址)已经监听了一个端口(通常是5555),运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --tcpip=192.168.1.1 # 默认端口是5555
|
||||||
|
scrcpy --tcpip=192.168.1.1:5555
|
||||||
|
```
|
||||||
|
|
||||||
|
如果adb TCP/IP(无线) 模式在某些设备上不被启用(或者你不知道IP地址),用USB连接设备,然后运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --tcpip # 无需其他参数
|
||||||
|
```
|
||||||
|
|
||||||
|
这将会自动寻找设备IP地址,启用TCP/IP模式,然后在启动之前连接到设备。
|
||||||
|
|
||||||
|
##### 手动配置
|
||||||
|
|
||||||
|
或者,可以通过 `adb` 使用手动启用 TCP/IP 连接:
|
||||||
|
|
||||||
1. 将设备和电脑连接至同一 Wi-Fi。
|
1. 将设备和电脑连接至同一 Wi-Fi。
|
||||||
2. 打开 设置 → 关于手机 → 状态信息,获取设备的 IP 地址,也可以执行以下的命令:
|
2. 打开 设置 → 关于手机 → 状态信息,获取设备的 IP 地址,也可以执行以下的命令:
|
||||||
@@ -359,7 +387,7 @@ _Scrcpy_ 使用 `adb` 与设备通信,并且 `adb` 支持通过 TCP/IP [连接
|
|||||||
5. 连接到您的设备:`adb connect DEVICE_IP:5555` _(将 `DEVICE_IP` 替换为设备 IP)_。
|
5. 连接到您的设备:`adb connect DEVICE_IP:5555` _(将 `DEVICE_IP` 替换为设备 IP)_。
|
||||||
6. 正常运行 `scrcpy`。
|
6. 正常运行 `scrcpy`。
|
||||||
|
|
||||||
可能降低码率和分辨率会更好一些:
|
降低比特率和分辨率可能很有用:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scrcpy --bit-rate 2M --max-size 800
|
scrcpy --bit-rate 2M --max-size 800
|
||||||
@@ -397,33 +425,75 @@ autoadb scrcpy -s '{}'
|
|||||||
|
|
||||||
[AutoAdb]: https://github.com/rom1v/autoadb
|
[AutoAdb]: https://github.com/rom1v/autoadb
|
||||||
|
|
||||||
#### SSH 隧道
|
#### 隧道
|
||||||
|
|
||||||
要远程连接到设备,可以将本地的 adb 客户端连接到远程的 adb 服务端 (需要两端的 _adb_ 协议版本相同):
|
要远程连接到设备,可以将本地的 adb 客户端连接到远程的 adb 服务端 (需要两端的 _adb_ 协议版本相同)。
|
||||||
|
|
||||||
|
##### 远程ADB服务器
|
||||||
|
|
||||||
|
要连接到一个远程ADB服务器,让服务器在所有接口上监听:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
adb kill-server # 关闭本地 5037 端口上的 adb 服务端
|
adb kill-server
|
||||||
ssh -CN -L5037:localhost:5037 -R27183:localhost:27183 your_remote_computer
|
adb -a nodaemon server start
|
||||||
# 保持该窗口开启
|
# 保持该窗口开启
|
||||||
```
|
```
|
||||||
|
|
||||||
在另一个终端:
|
**警告:所有客户端与ADB服务器的交流都是未加密的。**
|
||||||
|
|
||||||
|
假设此服务器可在 192.168.1.2 访问。 然后,从另一个终端,运行 scrcpy:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
export ADB_SERVER_SOCKET=tcp:192.168.1.2:5037
|
||||||
|
scrcpy --tunnel-host=192.168.1.2
|
||||||
|
```
|
||||||
|
|
||||||
|
默认情况下,scrcpy使用用于 `adb forward` 隧道建立的本地端口(通常是 `27183`,见 `--port` )。它也可以强制使用一个不同的隧道端口(当涉及更多的重定向时,这在更复杂的情况下可能很有用):
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy --tunnel-port=1234
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
##### SSH 隧道
|
||||||
|
|
||||||
|
为了安全地与远程ADB服务器通信,最好使用SSH隧道。
|
||||||
|
|
||||||
|
首先,确保ADB服务器正在远程计算机上运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
adb start-server
|
||||||
|
```
|
||||||
|
|
||||||
|
然后,建立一个SSH隧道:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 本地 5038 --> 远程 5037
|
||||||
|
# 本地 27183 <-- 远程 27183
|
||||||
|
ssh -CN -L5038:localhost:5037 -R27183:localhost:27183 your_remote_computer
|
||||||
|
# 保持该窗口开启
|
||||||
|
```
|
||||||
|
|
||||||
|
在另一个终端上,运行scrcpy:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export ADB_SERVER_SOCKET=tcp:localhost:5038
|
||||||
scrcpy
|
scrcpy
|
||||||
```
|
```
|
||||||
|
|
||||||
若要不使用远程端口转发,可以强制使用正向连接 (注意 `-L` 和 `-R` 的区别):
|
若要不使用远程端口转发,可以强制使用正向连接(注意是 `-L` 而不是 `-R` ):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
adb kill-server # 关闭本地 5037 端口上的 adb 服务端
|
# 本地 5038 --> 远程 5037
|
||||||
ssh -CN -L5037:localhost:5037 -L27183:localhost:27183 your_remote_computer
|
# 本地 27183 <-- 远程 27183
|
||||||
|
ssh -CN -L5038:localhost:5037 -L27183:localhost:27183 your_remote_computer
|
||||||
# 保持该窗口开启
|
# 保持该窗口开启
|
||||||
```
|
```
|
||||||
|
|
||||||
在另一个终端:
|
在另一个终端上,运行scrcpy:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
export ADB_SERVER_SOCKET=tcp:localhost:5038
|
||||||
scrcpy --force-adb-forward
|
scrcpy --force-adb-forward
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -441,7 +511,7 @@ scrcpy -b2M -m800 --max-fps 15
|
|||||||
窗口的标题默认为设备型号。可以通过如下命令修改:
|
窗口的标题默认为设备型号。可以通过如下命令修改:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scrcpy --window-title 'My device'
|
scrcpy --window-title "我的设备"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 位置和大小
|
#### 位置和大小
|
||||||
@@ -630,6 +700,8 @@ scrcpy --disable-screensaver
|
|||||||
|
|
||||||
一些设备不支持通过程序设置剪贴板。通过 `--legacy-paste` 选项可以修改 <kbd>Ctrl</kbd>+<kbd>v</kbd> 和 <kbd>MOD</kbd>+<kbd>v</kbd> 的工作方式,使它们通过按键事件 (同 <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>) 来注入电脑剪贴板内容。
|
一些设备不支持通过程序设置剪贴板。通过 `--legacy-paste` 选项可以修改 <kbd>Ctrl</kbd>+<kbd>v</kbd> 和 <kbd>MOD</kbd>+<kbd>v</kbd> 的工作方式,使它们通过按键事件 (同 <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>) 来注入电脑剪贴板内容。
|
||||||
|
|
||||||
|
要禁用自动剪贴板同步功能,使用`--no-clipboard-autosync`。
|
||||||
|
|
||||||
#### 双指缩放
|
#### 双指缩放
|
||||||
|
|
||||||
模拟“双指缩放”:<kbd>Ctrl</kbd>+_按住并移动鼠标_。
|
模拟“双指缩放”:<kbd>Ctrl</kbd>+_按住并移动鼠标_。
|
||||||
@@ -659,11 +731,60 @@ scrcpy -K # 简写
|
|||||||
|
|
||||||
在这种模式下,原始按键事件 (扫描码) 被发送给设备,而与宿主机按键映射无关。因此,若键盘布局不匹配,需要在 Android 设备上进行配置,具体为 设置 → 系统 → 语言和输入法 → [实体键盘]。
|
在这种模式下,原始按键事件 (扫描码) 被发送给设备,而与宿主机按键映射无关。因此,若键盘布局不匹配,需要在 Android 设备上进行配置,具体为 设置 → 系统 → 语言和输入法 → [实体键盘]。
|
||||||
|
|
||||||
[Physical keyboard]: https://github.com/Genymobile/scrcpy/pull/2632#issuecomment-923756915
|
[实体键盘]: https://github.com/Genymobile/scrcpy/pull/2632#issuecomment-923756915
|
||||||
|
|
||||||
|
#### 物理鼠标模拟 (HID)
|
||||||
|
|
||||||
|
与物理键盘模拟类似,可以模拟一个物理鼠标。 同样,它仅在设备通过 USB 连接时才有效,并且目前仅在 Linux 上受支持。
|
||||||
|
|
||||||
|
默认情况下,scrcpy 使用 Android 鼠标事件注入,使用绝对坐标。 通过模拟物理鼠标,在Android设备上出现鼠标指针,并注入鼠标相对运动、点击和滚动。
|
||||||
|
|
||||||
|
启用此模式:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --hid-mouse
|
||||||
|
scrcpy -M # 简写
|
||||||
|
```
|
||||||
|
|
||||||
|
您还可以将 `--forward-all-clicks` 添加到 [转发所有点击][forward_all_clicks].
|
||||||
|
|
||||||
|
[forward_all_clicks]: #右键和中键
|
||||||
|
|
||||||
|
启用此模式后,计算机鼠标将被“捕获”(鼠标指针从计算机上消失并出现在 Android 设备上)。
|
||||||
|
|
||||||
|
特殊的捕获键,<kbd>Alt</kbd> 或 <kbd>Super</kbd>,切换(禁用或启用)鼠标捕获。 使用其中之一将鼠标的控制权交还给计算机。
|
||||||
|
|
||||||
|
|
||||||
|
#### OTG
|
||||||
|
|
||||||
|
可以仅使用物理键盘和鼠标模拟 (HID) 运行 _scrcpy_,就好像计算机键盘和鼠标通过 OTG 线直接插入设备一样。
|
||||||
|
|
||||||
|
在这个模式下,_adb_ (USB 调试)是不必要的,且镜像被禁用。
|
||||||
|
|
||||||
|
启用 OTG 模式:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --otg
|
||||||
|
# 如果有多个 USB 设备可用,则通过序列号选择
|
||||||
|
scrcpy --otg -s 0123456789abcdef
|
||||||
|
```
|
||||||
|
|
||||||
|
只开启 HID 键盘 或 HID 鼠标 是可行的:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --otg --hid-keyboard # 只开启 HID 键盘
|
||||||
|
scrcpy --otg --hid-mouse # 只开启 HID 鼠标
|
||||||
|
scrcpy --otg --hid-keyboard --hid-mouse # 开启 HID 键盘 和 HID 鼠标
|
||||||
|
# 为了方便,默认两者都开启
|
||||||
|
scrcpy --otg # 开启 HID 键盘 和 HID 鼠标
|
||||||
|
```
|
||||||
|
|
||||||
|
像 `--hid-keyboard` 和 `--hid-mouse` 一样,它只在设备通过 USB 连接时才有效,且目前仅在 Linux 上支持。
|
||||||
|
|
||||||
|
|
||||||
#### 文本注入偏好
|
#### 文本注入偏好
|
||||||
|
|
||||||
打字的时候,系统会产生两种[事件][textevents]:
|
输入文字的时候,系统会产生两种[事件][textevents]:
|
||||||
- _按键事件_ ,代表一个按键被按下或松开。
|
- _按键事件_ ,代表一个按键被按下或松开。
|
||||||
- _文本事件_ ,代表一个字符被输入。
|
- _文本事件_ ,代表一个字符被输入。
|
||||||
|
|
||||||
@@ -675,7 +796,13 @@ scrcpy -K # 简写
|
|||||||
scrcpy --prefer-text
|
scrcpy --prefer-text
|
||||||
```
|
```
|
||||||
|
|
||||||
(这会导致键盘在游戏中工作不正常)
|
(但这会导致键盘在游戏中工作不正常)
|
||||||
|
|
||||||
|
相反,您可以强制始终注入原始按键事件:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --raw-key-events
|
||||||
|
```
|
||||||
|
|
||||||
该选项不影响 HID 键盘 (该模式下,所有按键都发送为扫描码)。
|
该选项不影响 HID 键盘 (该模式下,所有按键都发送为扫描码)。
|
||||||
|
|
||||||
@@ -765,7 +892,7 @@ _<kbd>[Super]</kbd> 键通常是指 <kbd>Windows</kbd> 或 <kbd>Cmd</kbd> 键。
|
|||||||
| 点按 `主屏幕` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _中键_
|
| 点按 `主屏幕` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _中键_
|
||||||
| 点按 `返回` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _右键²_
|
| 点按 `返回` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _右键²_
|
||||||
| 点按 `切换应用` | <kbd>MOD</kbd>+<kbd>s</kbd> \| _第4键³_
|
| 点按 `切换应用` | <kbd>MOD</kbd>+<kbd>s</kbd> \| _第4键³_
|
||||||
| 点按 `菜单` (解锁屏幕) | <kbd>MOD</kbd>+<kbd>m</kbd>
|
| 点按 `菜单` (解锁屏幕)⁴ | <kbd>MOD</kbd>+<kbd>m</kbd>
|
||||||
| 点按 `音量+` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(上箭头)_
|
| 点按 `音量+` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(上箭头)_
|
||||||
| 点按 `音量-` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(下箭头)_
|
| 点按 `音量-` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(下箭头)_
|
||||||
| 点按 `电源` | <kbd>MOD</kbd>+<kbd>p</kbd>
|
| 点按 `电源` | <kbd>MOD</kbd>+<kbd>p</kbd>
|
||||||
@@ -776,9 +903,9 @@ _<kbd>[Super]</kbd> 键通常是指 <kbd>Windows</kbd> 或 <kbd>Cmd</kbd> 键。
|
|||||||
| 展开通知面板 | <kbd>MOD</kbd>+<kbd>n</kbd> \| _第5键³_
|
| 展开通知面板 | <kbd>MOD</kbd>+<kbd>n</kbd> \| _第5键³_
|
||||||
| 展开设置面板 | <kbd>MOD</kbd>+<kbd>n</kbd>+<kbd>n</kbd> \| _双击第5键³_
|
| 展开设置面板 | <kbd>MOD</kbd>+<kbd>n</kbd>+<kbd>n</kbd> \| _双击第5键³_
|
||||||
| 收起通知面板 | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
| 收起通知面板 | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
||||||
| 复制到剪贴板⁴ | <kbd>MOD</kbd>+<kbd>c</kbd>
|
| 复制到剪贴板⁵ | <kbd>MOD</kbd>+<kbd>c</kbd>
|
||||||
| 剪切到剪贴板⁴ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
| 剪切到剪贴板⁵ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
||||||
| 同步剪贴板并粘贴⁴ | <kbd>MOD</kbd>+<kbd>v</kbd>
|
| 同步剪贴板并粘贴⁵ | <kbd>MOD</kbd>+<kbd>v</kbd>
|
||||||
| 注入电脑剪贴板文本 | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>
|
| 注入电脑剪贴板文本 | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>
|
||||||
| 打开/关闭FPS显示 (至标准输出) | <kbd>MOD</kbd>+<kbd>i</kbd>
|
| 打开/关闭FPS显示 (至标准输出) | <kbd>MOD</kbd>+<kbd>i</kbd>
|
||||||
| 捏拉缩放 | <kbd>Ctrl</kbd>+_按住并移动鼠标_
|
| 捏拉缩放 | <kbd>Ctrl</kbd>+_按住并移动鼠标_
|
||||||
@@ -788,7 +915,8 @@ _<kbd>[Super]</kbd> 键通常是指 <kbd>Windows</kbd> 或 <kbd>Cmd</kbd> 键。
|
|||||||
_¹双击黑边可以去除黑边。_
|
_¹双击黑边可以去除黑边。_
|
||||||
_²点击鼠标右键将在屏幕熄灭时点亮屏幕,其余情况则视为按下返回键 。_
|
_²点击鼠标右键将在屏幕熄灭时点亮屏幕,其余情况则视为按下返回键 。_
|
||||||
_³鼠标的第4键和第5键。_
|
_³鼠标的第4键和第5键。_
|
||||||
_⁴需要安卓版本 Android >= 7。_
|
_⁴对于开发中的 react-native 应用程序,`MENU` 触发开发菜单。_
|
||||||
|
_⁵需要安卓版本 Android >= 7。_
|
||||||
|
|
||||||
有重复按键的快捷键通过松开再按下一个按键来进行,如“展开设置面板”:
|
有重复按键的快捷键通过松开再按下一个按键来进行,如“展开设置面板”:
|
||||||
|
|
||||||
@@ -816,7 +944,7 @@ ADB=/path/to/adb scrcpy
|
|||||||
|
|
||||||
一个同事让我找出一个和 [gnirehtet] 一样难以发音的名字。
|
一个同事让我找出一个和 [gnirehtet] 一样难以发音的名字。
|
||||||
|
|
||||||
[`strcpy`] 复制一个 **str**ing (字符串); `scrcpy` 复制一个 **scr**een (屏幕)。
|
[`strcpy`] 源于 **str**ing (字符串); `scrcpy` 源于 **scr**een (屏幕)。
|
||||||
|
|
||||||
[gnirehtet]: https://github.com/Genymobile/gnirehtet
|
[gnirehtet]: https://github.com/Genymobile/gnirehtet
|
||||||
[`strcpy`]: http://man7.org/linux/man-pages/man3/strcpy.3.html
|
[`strcpy`]: http://man7.org/linux/man-pages/man3/strcpy.3.html
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
src = [
|
src = [
|
||||||
'src/main.c',
|
'src/main.c',
|
||||||
'src/adb.c',
|
'src/adb/adb.c',
|
||||||
'src/adb_parser.c',
|
'src/adb/adb_device.c',
|
||||||
'src/adb_tunnel.c',
|
'src/adb/adb_parser.c',
|
||||||
|
'src/adb/adb_tunnel.c',
|
||||||
'src/cli.c',
|
'src/cli.c',
|
||||||
'src/clock.c',
|
'src/clock.c',
|
||||||
'src/compat.c',
|
'src/compat.c',
|
||||||
'src/control_msg.c',
|
'src/control_msg.c',
|
||||||
'src/controller.c',
|
'src/controller.c',
|
||||||
'src/decoder.c',
|
'src/decoder.c',
|
||||||
|
'src/demuxer.c',
|
||||||
'src/device_msg.c',
|
'src/device_msg.c',
|
||||||
'src/icon.c',
|
'src/icon.c',
|
||||||
'src/file_handler.c',
|
'src/file_pusher.c',
|
||||||
'src/fps_counter.c',
|
'src/fps_counter.c',
|
||||||
'src/frame_buffer.c',
|
'src/frame_buffer.c',
|
||||||
'src/input_manager.c',
|
'src/input_manager.c',
|
||||||
@@ -24,7 +26,6 @@ src = [
|
|||||||
'src/scrcpy.c',
|
'src/scrcpy.c',
|
||||||
'src/screen.c',
|
'src/screen.c',
|
||||||
'src/server.c',
|
'src/server.c',
|
||||||
'src/stream.c',
|
|
||||||
'src/video_buffer.c',
|
'src/video_buffer.c',
|
||||||
'src/util/acksync.c',
|
'src/util/acksync.c',
|
||||||
'src/util/file.c',
|
'src/util/file.c',
|
||||||
@@ -72,12 +73,15 @@ if v4l2_support
|
|||||||
src += [ 'src/v4l2_sink.c' ]
|
src += [ 'src/v4l2_sink.c' ]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
aoa_hid_support = host_machine.system() == 'linux'
|
usb_support = host_machine.system() == 'linux'
|
||||||
if aoa_hid_support
|
if usb_support
|
||||||
src += [
|
src += [
|
||||||
'src/aoa_hid.c',
|
'src/usb/aoa_hid.c',
|
||||||
'src/hid_keyboard.c',
|
'src/usb/hid_keyboard.c',
|
||||||
'src/hid_mouse.c',
|
'src/usb/hid_mouse.c',
|
||||||
|
'src/usb/scrcpy_otg.c',
|
||||||
|
'src/usb/screen_otg.c',
|
||||||
|
'src/usb/usb.c',
|
||||||
]
|
]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -99,16 +103,16 @@ if not crossbuild_windows
|
|||||||
dependencies += dependency('libavdevice')
|
dependencies += dependency('libavdevice')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if aoa_hid_support
|
if usb_support
|
||||||
dependencies += dependency('libusb-1.0')
|
dependencies += dependency('libusb-1.0')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
else
|
else
|
||||||
# cross-compile mingw32 build (from Linux to Windows)
|
# cross-compile mingw32 build (from Linux to Windows)
|
||||||
prebuilt_sdl2 = meson.get_cross_property('prebuilt_sdl2')
|
prebuilt_sdl2 = meson.get_cross_property('prebuilt_sdl2')
|
||||||
sdl2_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/' + prebuilt_sdl2 + '/bin'
|
sdl2_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/data/' + prebuilt_sdl2 + '/bin'
|
||||||
sdl2_lib_dir = meson.current_source_dir() + '/../prebuilt-deps/' + prebuilt_sdl2 + '/lib'
|
sdl2_lib_dir = meson.current_source_dir() + '/../prebuilt-deps/data/' + prebuilt_sdl2 + '/lib'
|
||||||
sdl2_include_dir = '../prebuilt-deps/' + prebuilt_sdl2 + '/include'
|
sdl2_include_dir = '../prebuilt-deps/data/' + prebuilt_sdl2 + '/include'
|
||||||
|
|
||||||
sdl2 = declare_dependency(
|
sdl2 = declare_dependency(
|
||||||
dependencies: [
|
dependencies: [
|
||||||
@@ -119,8 +123,8 @@ else
|
|||||||
)
|
)
|
||||||
|
|
||||||
prebuilt_ffmpeg = meson.get_cross_property('prebuilt_ffmpeg')
|
prebuilt_ffmpeg = meson.get_cross_property('prebuilt_ffmpeg')
|
||||||
ffmpeg_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/' + prebuilt_ffmpeg + '/bin'
|
ffmpeg_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/data/' + prebuilt_ffmpeg + '/bin'
|
||||||
ffmpeg_include_dir = '../prebuilt-deps/' + prebuilt_ffmpeg + '/include'
|
ffmpeg_include_dir = '../prebuilt-deps/data/' + prebuilt_ffmpeg + '/include'
|
||||||
|
|
||||||
# ffmpeg versions are different for win32 and win64 builds
|
# ffmpeg versions are different for win32 and win64 builds
|
||||||
ffmpeg_avcodec = meson.get_cross_property('ffmpeg_avcodec')
|
ffmpeg_avcodec = meson.get_cross_property('ffmpeg_avcodec')
|
||||||
@@ -193,7 +197,7 @@ conf.set('SERVER_DEBUGGER_METHOD_NEW', get_option('server_debugger_method') == '
|
|||||||
conf.set('HAVE_V4L2', v4l2_support)
|
conf.set('HAVE_V4L2', v4l2_support)
|
||||||
|
|
||||||
# enable HID over AOA support (linux only)
|
# enable HID over AOA support (linux only)
|
||||||
conf.set('HAVE_AOA_HID', aoa_hid_support)
|
conf.set('HAVE_USB', usb_support)
|
||||||
|
|
||||||
configure_file(configuration: conf, output: 'config.h')
|
configure_file(configuration: conf, output: 'config.h')
|
||||||
|
|
||||||
@@ -218,7 +222,8 @@ if get_option('buildtype') == 'debug'
|
|||||||
tests = [
|
tests = [
|
||||||
['test_adb_parser', [
|
['test_adb_parser', [
|
||||||
'tests/test_adb_parser.c',
|
'tests/test_adb_parser.c',
|
||||||
'src/adb_parser.c',
|
'src/adb/adb_device.c',
|
||||||
|
'src/adb/adb_parser.c',
|
||||||
'src/util/str.c',
|
'src/util/str.c',
|
||||||
'src/util/strbuf.c',
|
'src/util/strbuf.c',
|
||||||
]],
|
]],
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ BEGIN
|
|||||||
VALUE "LegalCopyright", "Romain Vimont, Genymobile"
|
VALUE "LegalCopyright", "Romain Vimont, Genymobile"
|
||||||
VALUE "OriginalFilename", "scrcpy.exe"
|
VALUE "OriginalFilename", "scrcpy.exe"
|
||||||
VALUE "ProductName", "scrcpy"
|
VALUE "ProductName", "scrcpy"
|
||||||
VALUE "ProductVersion", "1.21"
|
VALUE "ProductVersion", "1.22"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|||||||
32
app/scrcpy.1
32
app/scrcpy.1
@@ -43,6 +43,12 @@ The values are expressed in the device natural orientation (typically, portrait
|
|||||||
.B \-\-max\-size
|
.B \-\-max\-size
|
||||||
value is computed on the cropped 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
|
.TP
|
||||||
.BI "\-\-disable-screensaver"
|
.BI "\-\-disable-screensaver"
|
||||||
Disable screensaver while scrcpy is running.
|
Disable screensaver while scrcpy is running.
|
||||||
@@ -62,6 +68,12 @@ Add a buffering delay (in milliseconds) before displaying. This increases latenc
|
|||||||
|
|
||||||
Default is 0 (no buffering).
|
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
|
.TP
|
||||||
.BI "\-\-encoder " name
|
.BI "\-\-encoder " name
|
||||||
Use a specific MediaCodec encoder (must be a H.264 encoder).
|
Use a specific MediaCodec encoder (must be a H.264 encoder).
|
||||||
@@ -140,6 +152,12 @@ By default, scrcpy automatically synchronizes the computer clipboard to the devi
|
|||||||
|
|
||||||
This option disables this automatic synchronization.
|
This option disables this automatic synchronization.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B \-\-no\-downsize\-on\-error
|
||||||
|
By default, on MediaCodec error, scrcpy automatically tries again with a lower definition.
|
||||||
|
|
||||||
|
This option disables this behavior.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-n, \-\-no\-control
|
.B \-n, \-\-no\-control
|
||||||
Disable device control (mirror the device in read\-only).
|
Disable device control (mirror the device in read\-only).
|
||||||
@@ -156,6 +174,20 @@ Do not forward repeated key events when a key is held down.
|
|||||||
.B \-\-no\-mipmaps
|
.B \-\-no\-mipmaps
|
||||||
If the renderer is OpenGL 3.0+ or OpenGL ES 2.0+, then mipmaps are automatically generated to improve downscaling quality. This option disables the generation of mipmaps.
|
If the renderer is OpenGL 3.0+ or OpenGL ES 2.0+, then mipmaps are automatically generated to improve downscaling quality. This option disables the generation of mipmaps.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B \-\-otg
|
||||||
|
Run in OTG mode: simulate physical keyboard and mouse, as if the computer keyboard and mouse were plugged directly to the device via an OTG cable.
|
||||||
|
|
||||||
|
In this mode, adb (USB debugging) is not necessary, and mirroring is disabled.
|
||||||
|
|
||||||
|
LAlt, LSuper or RSuper toggle the mouse capture mode, to give control of the mouse back to the computer.
|
||||||
|
|
||||||
|
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, and is currently only supported on Linux.
|
||||||
|
|
||||||
|
See \fB\-\-hid\-keyboard\fR and \fB\-\-hid\-mouse\fR.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-p, \-\-port " port[:port]
|
.BI "\-p, \-\-port " port[:port]
|
||||||
Set the TCP port (range) used by the client to listen.
|
Set the TCP port (range) used by the client to listen.
|
||||||
|
|||||||
471
app/src/adb.c
471
app/src/adb.c
@@ -1,471 +0,0 @@
|
|||||||
#include "adb.h"
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "adb_parser.h"
|
|
||||||
#include "util/file.h"
|
|
||||||
#include "util/log.h"
|
|
||||||
#include "util/process_intr.h"
|
|
||||||
#include "util/str.h"
|
|
||||||
|
|
||||||
static const char *adb_command;
|
|
||||||
|
|
||||||
static inline const char *
|
|
||||||
get_adb_command(void) {
|
|
||||||
if (!adb_command) {
|
|
||||||
adb_command = getenv("ADB");
|
|
||||||
if (!adb_command)
|
|
||||||
adb_command = "adb";
|
|
||||||
}
|
|
||||||
return adb_command;
|
|
||||||
}
|
|
||||||
|
|
||||||
// serialize argv to string "[arg1], [arg2], [arg3]"
|
|
||||||
static size_t
|
|
||||||
argv_to_string(const char *const *argv, char *buf, size_t bufsize) {
|
|
||||||
size_t idx = 0;
|
|
||||||
bool first = true;
|
|
||||||
while (*argv) {
|
|
||||||
const char *arg = *argv;
|
|
||||||
size_t len = strlen(arg);
|
|
||||||
// count space for "[], ...\0"
|
|
||||||
if (idx + len + 8 >= bufsize) {
|
|
||||||
// not enough space, truncate
|
|
||||||
assert(idx < bufsize - 4);
|
|
||||||
memcpy(&buf[idx], "...", 3);
|
|
||||||
idx += 3;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (first) {
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
buf[idx++] = ',';
|
|
||||||
buf[idx++] = ' ';
|
|
||||||
}
|
|
||||||
buf[idx++] = '[';
|
|
||||||
memcpy(&buf[idx], arg, len);
|
|
||||||
idx += len;
|
|
||||||
buf[idx++] = ']';
|
|
||||||
argv++;
|
|
||||||
}
|
|
||||||
assert(idx < bufsize);
|
|
||||||
buf[idx] = '\0';
|
|
||||||
return idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
show_adb_installation_msg() {
|
|
||||||
#ifndef __WINDOWS__
|
|
||||||
static const struct {
|
|
||||||
const char *binary;
|
|
||||||
const char *command;
|
|
||||||
} pkg_managers[] = {
|
|
||||||
{"apt", "apt install adb"},
|
|
||||||
{"apt-get", "apt-get install adb"},
|
|
||||||
{"brew", "brew cask install android-platform-tools"},
|
|
||||||
{"dnf", "dnf install android-tools"},
|
|
||||||
{"emerge", "emerge dev-util/android-tools"},
|
|
||||||
{"pacman", "pacman -S android-tools"},
|
|
||||||
};
|
|
||||||
for (size_t i = 0; i < ARRAY_LEN(pkg_managers); ++i) {
|
|
||||||
if (sc_file_executable_exists(pkg_managers[i].binary)) {
|
|
||||||
LOGI("You may install 'adb' by \"%s\"", pkg_managers[i].command);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LOGI("You may download and install 'adb' from "
|
|
||||||
"https://developer.android.com/studio/releases/platform-tools");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
show_adb_err_msg(enum sc_process_result err, const char *const argv[]) {
|
|
||||||
#define MAX_COMMAND_STRING_LEN 1024
|
|
||||||
char *buf = malloc(MAX_COMMAND_STRING_LEN);
|
|
||||||
if (!buf) {
|
|
||||||
LOG_OOM();
|
|
||||||
LOGE("Failed to execute");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (err) {
|
|
||||||
case SC_PROCESS_ERROR_GENERIC:
|
|
||||||
argv_to_string(argv, buf, MAX_COMMAND_STRING_LEN);
|
|
||||||
LOGE("Failed to execute: %s", buf);
|
|
||||||
break;
|
|
||||||
case SC_PROCESS_ERROR_MISSING_BINARY:
|
|
||||||
argv_to_string(argv, buf, MAX_COMMAND_STRING_LEN);
|
|
||||||
LOGE("Command not found: %s", buf);
|
|
||||||
LOGE("(make 'adb' accessible from your PATH or define its full"
|
|
||||||
"path in the ADB environment variable)");
|
|
||||||
show_adb_installation_msg();
|
|
||||||
break;
|
|
||||||
case SC_PROCESS_SUCCESS:
|
|
||||||
// do nothing
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
process_check_success_internal(sc_pid pid, const char *name, bool close,
|
|
||||||
unsigned flags) {
|
|
||||||
bool log_errors = !(flags & SC_ADB_NO_LOGERR);
|
|
||||||
|
|
||||||
if (pid == SC_PROCESS_NONE) {
|
|
||||||
if (log_errors) {
|
|
||||||
LOGE("Could not execute \"%s\"", name);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
sc_exit_code exit_code = sc_process_wait(pid, close);
|
|
||||||
if (exit_code) {
|
|
||||||
if (log_errors) {
|
|
||||||
if (exit_code != SC_EXIT_CODE_NONE) {
|
|
||||||
LOGE("\"%s\" returned with value %" SC_PRIexitcode, name,
|
|
||||||
exit_code);
|
|
||||||
} else {
|
|
||||||
LOGE("\"%s\" exited unexpectedly", name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
process_check_success_intr(struct sc_intr *intr, sc_pid pid, const char *name,
|
|
||||||
unsigned flags) {
|
|
||||||
if (!sc_intr_set_process(intr, pid)) {
|
|
||||||
// Already interrupted
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always pass close=false, interrupting would be racy otherwise
|
|
||||||
bool ret = process_check_success_internal(pid, name, false, flags);
|
|
||||||
|
|
||||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
|
||||||
|
|
||||||
// Close separately
|
|
||||||
sc_process_close(pid);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char **
|
|
||||||
adb_create_argv(const char *serial, const char *const adb_cmd[], size_t len) {
|
|
||||||
const char **argv = malloc((len + 4) * sizeof(*argv));
|
|
||||||
if (!argv) {
|
|
||||||
LOG_OOM();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
argv[0] = get_adb_command();
|
|
||||||
int i;
|
|
||||||
if (serial) {
|
|
||||||
argv[1] = "-s";
|
|
||||||
argv[2] = serial;
|
|
||||||
i = 3;
|
|
||||||
} else {
|
|
||||||
i = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(&argv[i], adb_cmd, len * sizeof(const char *));
|
|
||||||
argv[len + i] = NULL;
|
|
||||||
return argv;
|
|
||||||
}
|
|
||||||
|
|
||||||
static sc_pid
|
|
||||||
adb_execute_p(const char *serial, const char *const adb_cmd[], size_t len,
|
|
||||||
unsigned flags, sc_pipe *pout) {
|
|
||||||
const char **argv = adb_create_argv(serial, adb_cmd, len);
|
|
||||||
if (!argv) {
|
|
||||||
return SC_PROCESS_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned process_flags = 0;
|
|
||||||
if (flags & SC_ADB_NO_STDOUT) {
|
|
||||||
process_flags |= SC_PROCESS_NO_STDOUT;
|
|
||||||
}
|
|
||||||
if (flags & SC_ADB_NO_STDERR) {
|
|
||||||
process_flags |= SC_PROCESS_NO_STDERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
sc_pid pid;
|
|
||||||
enum sc_process_result r =
|
|
||||||
sc_process_execute_p(argv, &pid, process_flags, NULL, pout, NULL);
|
|
||||||
if (r != SC_PROCESS_SUCCESS) {
|
|
||||||
// If the execution itself failed (not the command exit code), log the
|
|
||||||
// error in all cases
|
|
||||||
show_adb_err_msg(r, argv);
|
|
||||||
pid = SC_PROCESS_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(argv);
|
|
||||||
return pid;
|
|
||||||
}
|
|
||||||
|
|
||||||
sc_pid
|
|
||||||
adb_execute(const char *serial, const char *const adb_cmd[], size_t len,
|
|
||||||
unsigned flags) {
|
|
||||||
return adb_execute_p(serial, adb_cmd, len, flags, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
|
|
||||||
const char *device_socket_name, unsigned flags) {
|
|
||||||
char local[4 + 5 + 1]; // tcp:PORT
|
|
||||||
char remote[108 + 14 + 1]; // localabstract:NAME
|
|
||||||
sprintf(local, "tcp:%" PRIu16, local_port);
|
|
||||||
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name);
|
|
||||||
const char *const adb_cmd[] = {"forward", local, remote};
|
|
||||||
|
|
||||||
sc_pid pid = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd), flags);
|
|
||||||
return process_check_success_intr(intr, pid, "adb forward", flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_forward_remove(struct sc_intr *intr, const char *serial,
|
|
||||||
uint16_t local_port, unsigned flags) {
|
|
||||||
char local[4 + 5 + 1]; // tcp:PORT
|
|
||||||
sprintf(local, "tcp:%" PRIu16, local_port);
|
|
||||||
const char *const adb_cmd[] = {"forward", "--remove", local};
|
|
||||||
|
|
||||||
sc_pid pid = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd), flags);
|
|
||||||
return process_check_success_intr(intr, pid, "adb forward --remove", flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_reverse(struct sc_intr *intr, const char *serial,
|
|
||||||
const char *device_socket_name, uint16_t local_port,
|
|
||||||
unsigned flags) {
|
|
||||||
char local[4 + 5 + 1]; // tcp:PORT
|
|
||||||
char remote[108 + 14 + 1]; // localabstract:NAME
|
|
||||||
sprintf(local, "tcp:%" PRIu16, local_port);
|
|
||||||
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name);
|
|
||||||
const char *const adb_cmd[] = {"reverse", remote, local};
|
|
||||||
|
|
||||||
sc_pid pid = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd), flags);
|
|
||||||
return process_check_success_intr(intr, pid, "adb reverse", flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_reverse_remove(struct sc_intr *intr, const char *serial,
|
|
||||||
const char *device_socket_name, unsigned flags) {
|
|
||||||
char remote[108 + 14 + 1]; // localabstract:NAME
|
|
||||||
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name);
|
|
||||||
const char *const adb_cmd[] = {"reverse", "--remove", remote};
|
|
||||||
|
|
||||||
sc_pid pid = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd), flags);
|
|
||||||
return process_check_success_intr(intr, pid, "adb reverse --remove", flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_push(struct sc_intr *intr, const char *serial, const char *local,
|
|
||||||
const char *remote, unsigned flags) {
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
// Windows will parse the string, so the paths must be quoted
|
|
||||||
// (see sys/win/command.c)
|
|
||||||
local = sc_str_quote(local);
|
|
||||||
if (!local) {
|
|
||||||
return SC_PROCESS_NONE;
|
|
||||||
}
|
|
||||||
remote = sc_str_quote(remote);
|
|
||||||
if (!remote) {
|
|
||||||
free((void *) local);
|
|
||||||
return SC_PROCESS_NONE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char *const adb_cmd[] = {"push", local, remote};
|
|
||||||
sc_pid pid = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd), flags);
|
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
free((void *) remote);
|
|
||||||
free((void *) local);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return process_check_success_intr(intr, pid, "adb push", flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_install(struct sc_intr *intr, const char *serial, const char *local,
|
|
||||||
unsigned flags) {
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
// Windows will parse the string, so the local name must be quoted
|
|
||||||
// (see sys/win/command.c)
|
|
||||||
local = sc_str_quote(local);
|
|
||||||
if (!local) {
|
|
||||||
return SC_PROCESS_NONE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char *const adb_cmd[] = {"install", "-r", local};
|
|
||||||
sc_pid pid = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd), flags);
|
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
free((void *) local);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return process_check_success_intr(intr, pid, "adb install", flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_tcpip(struct sc_intr *intr, const char *serial, uint16_t port,
|
|
||||||
unsigned flags) {
|
|
||||||
char port_string[5 + 1];
|
|
||||||
sprintf(port_string, "%" PRIu16, port);
|
|
||||||
const char *const adb_cmd[] = {"tcpip", port_string};
|
|
||||||
|
|
||||||
sc_pid pid = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd), flags);
|
|
||||||
return process_check_success_intr(intr, pid, "adb tcpip", flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_connect(struct sc_intr *intr, const char *ip_port, unsigned flags) {
|
|
||||||
const char *const adb_cmd[] = {"connect", ip_port};
|
|
||||||
|
|
||||||
sc_pipe pout;
|
|
||||||
sc_pid pid = adb_execute_p(NULL, adb_cmd, ARRAY_LEN(adb_cmd), flags, &pout);
|
|
||||||
if (pid == SC_PROCESS_NONE) {
|
|
||||||
LOGE("Could not execute \"adb connect\"");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// "adb connect" always returns successfully (with exit code 0), even in
|
|
||||||
// case of failure. As a workaround, check if its output starts with
|
|
||||||
// "connected".
|
|
||||||
char buf[128];
|
|
||||||
ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, sizeof(buf));
|
|
||||||
sc_pipe_close(pout);
|
|
||||||
|
|
||||||
bool ok = process_check_success_intr(intr, pid, "adb connect", flags);
|
|
||||||
if (!ok) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r == -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = !strncmp("connected", buf, sizeof("connected") - 1);
|
|
||||||
if (!ok && !(flags & SC_ADB_NO_STDERR)) {
|
|
||||||
// "adb connect" also prints errors to stdout. Since we capture it,
|
|
||||||
// re-print the error to stderr.
|
|
||||||
sc_str_truncate(buf, r, "\r\n");
|
|
||||||
fprintf(stderr, "%s\n", buf);
|
|
||||||
}
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_disconnect(struct sc_intr *intr, const char *ip_port, unsigned flags) {
|
|
||||||
const char *const adb_cmd[] = {"disconnect", ip_port};
|
|
||||||
size_t len = ip_port ? ARRAY_LEN(adb_cmd)
|
|
||||||
: ARRAY_LEN(adb_cmd) - 1;
|
|
||||||
|
|
||||||
sc_pid pid = adb_execute(NULL, adb_cmd, len, flags);
|
|
||||||
return process_check_success_intr(intr, pid, "adb disconnect", flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
adb_getprop(struct sc_intr *intr, const char *serial, const char *prop,
|
|
||||||
unsigned flags) {
|
|
||||||
const char *const adb_cmd[] = {"shell", "getprop", prop};
|
|
||||||
|
|
||||||
sc_pipe pout;
|
|
||||||
sc_pid pid =
|
|
||||||
adb_execute_p(serial, adb_cmd, ARRAY_LEN(adb_cmd), flags, &pout);
|
|
||||||
if (pid == SC_PROCESS_NONE) {
|
|
||||||
LOGE("Could not execute \"adb getprop\"");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buf[128];
|
|
||||||
ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, sizeof(buf));
|
|
||||||
sc_pipe_close(pout);
|
|
||||||
|
|
||||||
bool ok = process_check_success_intr(intr, pid, "adb getprop", flags);
|
|
||||||
if (!ok) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r == -1) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
sc_str_truncate(buf, r, " \r\n");
|
|
||||||
|
|
||||||
return strdup(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
adb_get_serialno(struct sc_intr *intr, unsigned flags) {
|
|
||||||
const char *const adb_cmd[] = {"get-serialno"};
|
|
||||||
|
|
||||||
sc_pipe pout;
|
|
||||||
sc_pid pid = adb_execute_p(NULL, adb_cmd, ARRAY_LEN(adb_cmd), flags, &pout);
|
|
||||||
if (pid == SC_PROCESS_NONE) {
|
|
||||||
LOGE("Could not execute \"adb get-serialno\"");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buf[128];
|
|
||||||
ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, sizeof(buf));
|
|
||||||
sc_pipe_close(pout);
|
|
||||||
|
|
||||||
bool ok = process_check_success_intr(intr, pid, "adb get-serialno", flags);
|
|
||||||
if (!ok) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r == -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
sc_str_truncate(buf, r, " \r\n");
|
|
||||||
|
|
||||||
return strdup(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
adb_get_device_ip(struct sc_intr *intr, const char *serial, unsigned flags) {
|
|
||||||
const char *const cmd[] = {"shell", "ip", "route"};
|
|
||||||
|
|
||||||
sc_pipe pout;
|
|
||||||
sc_pid pid = adb_execute_p(serial, cmd, ARRAY_LEN(cmd), flags, &pout);
|
|
||||||
if (pid == SC_PROCESS_NONE) {
|
|
||||||
LOGD("Could not execute \"ip route\"");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// "adb shell ip route" output should contain only a few lines
|
|
||||||
char buf[1024];
|
|
||||||
ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, sizeof(buf));
|
|
||||||
sc_pipe_close(pout);
|
|
||||||
|
|
||||||
bool ok = process_check_success_intr(intr, pid, "ip route", flags);
|
|
||||||
if (!ok) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r == -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert((size_t) r <= sizeof(buf));
|
|
||||||
if (r == sizeof(buf) && buf[sizeof(buf) - 1] != '\0') {
|
|
||||||
// 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.\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sc_adb_parse_device_ip_from_output(buf, r);
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
#ifndef SC_ADB_H
|
|
||||||
#define SC_ADB_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#include "util/intr.h"
|
|
||||||
|
|
||||||
#define SC_ADB_NO_STDOUT (1 << 0)
|
|
||||||
#define SC_ADB_NO_STDERR (1 << 1)
|
|
||||||
#define SC_ADB_NO_LOGERR (1 << 2)
|
|
||||||
|
|
||||||
#define SC_ADB_SILENT (SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR)
|
|
||||||
|
|
||||||
sc_pid
|
|
||||||
adb_execute(const char *serial, const char *const adb_cmd[], size_t len,
|
|
||||||
unsigned flags);
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
|
|
||||||
const char *device_socket_name, unsigned flags);
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_forward_remove(struct sc_intr *intr, const char *serial,
|
|
||||||
uint16_t local_port, unsigned flags);
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_reverse(struct sc_intr *intr, const char *serial,
|
|
||||||
const char *device_socket_name, uint16_t local_port,
|
|
||||||
unsigned flags);
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_reverse_remove(struct sc_intr *intr, const char *serial,
|
|
||||||
const char *device_socket_name, unsigned flags);
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_push(struct sc_intr *intr, const char *serial, const char *local,
|
|
||||||
const char *remote, unsigned flags);
|
|
||||||
|
|
||||||
bool
|
|
||||||
adb_install(struct sc_intr *intr, const char *serial, const char *local,
|
|
||||||
unsigned flags);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute `adb tcpip <port>`
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
adb_tcpip(struct sc_intr *intr, const char *serial, uint16_t port,
|
|
||||||
unsigned flags);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute `adb connect <ip_port>`
|
|
||||||
*
|
|
||||||
* `ip_port` may not be NULL.
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
adb_connect(struct sc_intr *intr, const char *ip_port, unsigned flags);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute `adb disconnect [<ip_port>]`
|
|
||||||
*
|
|
||||||
* If `ip_port` is NULL, execute `adb disconnect`.
|
|
||||||
* Otherwise, execute `adb disconnect <ip_port>`.
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
adb_disconnect(struct sc_intr *intr, const char *ip_port, unsigned flags);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute `adb getprop <prop>`
|
|
||||||
*/
|
|
||||||
char *
|
|
||||||
adb_getprop(struct sc_intr *intr, const char *serial, const char *prop,
|
|
||||||
unsigned flags);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute `adb get-serialno`
|
|
||||||
*
|
|
||||||
* Return the result, to be freed by the caller, or NULL on error.
|
|
||||||
*/
|
|
||||||
char *
|
|
||||||
adb_get_serialno(struct sc_intr *intr, unsigned flags);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempt to retrieve the device IP
|
|
||||||
*
|
|
||||||
* Return the IP as a string of the form "xxx.xxx.xxx.xxx", to be freed by the
|
|
||||||
* caller, or NULL on error.
|
|
||||||
*/
|
|
||||||
char *
|
|
||||||
adb_get_device_ip(struct sc_intr *intr, const char *serial, unsigned flags);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
692
app/src/adb/adb.c
Normal file
692
app/src/adb/adb.c
Normal file
@@ -0,0 +1,692 @@
|
|||||||
|
#include "adb.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "adb_parser.h"
|
||||||
|
#include "util/file.h"
|
||||||
|
#include "util/log.h"
|
||||||
|
#include "util/process_intr.h"
|
||||||
|
#include "util/str.h"
|
||||||
|
|
||||||
|
/* Convenience macro to expand:
|
||||||
|
*
|
||||||
|
* const char *const argv[] =
|
||||||
|
* SC_ADB_COMMAND("shell", "echo", "hello");
|
||||||
|
*
|
||||||
|
* to:
|
||||||
|
*
|
||||||
|
* const char *const argv[] =
|
||||||
|
* { sc_adb_get_executable(), "shell", "echo", "hello", NULL };
|
||||||
|
*/
|
||||||
|
#define SC_ADB_COMMAND(...) { sc_adb_get_executable(), __VA_ARGS__, NULL }
|
||||||
|
|
||||||
|
static const char *adb_executable;
|
||||||
|
|
||||||
|
const char *
|
||||||
|
sc_adb_get_executable(void) {
|
||||||
|
if (!adb_executable) {
|
||||||
|
adb_executable = getenv("ADB");
|
||||||
|
if (!adb_executable)
|
||||||
|
adb_executable = "adb";
|
||||||
|
}
|
||||||
|
return adb_executable;
|
||||||
|
}
|
||||||
|
|
||||||
|
// serialize argv to string "[arg1], [arg2], [arg3]"
|
||||||
|
static size_t
|
||||||
|
argv_to_string(const char *const *argv, char *buf, size_t bufsize) {
|
||||||
|
size_t idx = 0;
|
||||||
|
bool first = true;
|
||||||
|
while (*argv) {
|
||||||
|
const char *arg = *argv;
|
||||||
|
size_t len = strlen(arg);
|
||||||
|
// count space for "[], ...\0"
|
||||||
|
if (idx + len + 8 >= bufsize) {
|
||||||
|
// not enough space, truncate
|
||||||
|
assert(idx < bufsize - 4);
|
||||||
|
memcpy(&buf[idx], "...", 3);
|
||||||
|
idx += 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
buf[idx++] = ',';
|
||||||
|
buf[idx++] = ' ';
|
||||||
|
}
|
||||||
|
buf[idx++] = '[';
|
||||||
|
memcpy(&buf[idx], arg, len);
|
||||||
|
idx += len;
|
||||||
|
buf[idx++] = ']';
|
||||||
|
argv++;
|
||||||
|
}
|
||||||
|
assert(idx < bufsize);
|
||||||
|
buf[idx] = '\0';
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
show_adb_installation_msg() {
|
||||||
|
#ifndef __WINDOWS__
|
||||||
|
static const struct {
|
||||||
|
const char *binary;
|
||||||
|
const char *command;
|
||||||
|
} pkg_managers[] = {
|
||||||
|
{"apt", "apt install adb"},
|
||||||
|
{"apt-get", "apt-get install adb"},
|
||||||
|
{"brew", "brew cask install android-platform-tools"},
|
||||||
|
{"dnf", "dnf install android-tools"},
|
||||||
|
{"emerge", "emerge dev-util/android-tools"},
|
||||||
|
{"pacman", "pacman -S android-tools"},
|
||||||
|
};
|
||||||
|
for (size_t i = 0; i < ARRAY_LEN(pkg_managers); ++i) {
|
||||||
|
if (sc_file_executable_exists(pkg_managers[i].binary)) {
|
||||||
|
LOGI("You may install 'adb' by \"%s\"", pkg_managers[i].command);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
show_adb_err_msg(enum sc_process_result err, const char *const argv[]) {
|
||||||
|
#define MAX_COMMAND_STRING_LEN 1024
|
||||||
|
char *buf = malloc(MAX_COMMAND_STRING_LEN);
|
||||||
|
if (!buf) {
|
||||||
|
LOG_OOM();
|
||||||
|
LOGE("Failed to execute");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (err) {
|
||||||
|
case SC_PROCESS_ERROR_GENERIC:
|
||||||
|
argv_to_string(argv, buf, MAX_COMMAND_STRING_LEN);
|
||||||
|
LOGE("Failed to execute: %s", buf);
|
||||||
|
break;
|
||||||
|
case SC_PROCESS_ERROR_MISSING_BINARY:
|
||||||
|
argv_to_string(argv, buf, MAX_COMMAND_STRING_LEN);
|
||||||
|
LOGE("Command not found: %s", buf);
|
||||||
|
LOGE("(make 'adb' accessible from your PATH or define its full"
|
||||||
|
"path in the ADB environment variable)");
|
||||||
|
show_adb_installation_msg();
|
||||||
|
break;
|
||||||
|
case SC_PROCESS_SUCCESS:
|
||||||
|
// do nothing
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
process_check_success_internal(sc_pid pid, const char *name, bool close,
|
||||||
|
unsigned flags) {
|
||||||
|
bool log_errors = !(flags & SC_ADB_NO_LOGERR);
|
||||||
|
|
||||||
|
if (pid == SC_PROCESS_NONE) {
|
||||||
|
if (log_errors) {
|
||||||
|
LOGE("Could not execute \"%s\"", name);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
sc_exit_code exit_code = sc_process_wait(pid, close);
|
||||||
|
if (exit_code) {
|
||||||
|
if (log_errors) {
|
||||||
|
if (exit_code != SC_EXIT_CODE_NONE) {
|
||||||
|
LOGE("\"%s\" returned with value %" SC_PRIexitcode, name,
|
||||||
|
exit_code);
|
||||||
|
} else {
|
||||||
|
LOGE("\"%s\" exited unexpectedly", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
process_check_success_intr(struct sc_intr *intr, sc_pid pid, const char *name,
|
||||||
|
unsigned flags) {
|
||||||
|
if (!sc_intr_set_process(intr, pid)) {
|
||||||
|
// Already interrupted
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always pass close=false, interrupting would be racy otherwise
|
||||||
|
bool ret = process_check_success_internal(pid, name, false, flags);
|
||||||
|
|
||||||
|
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||||
|
|
||||||
|
// Close separately
|
||||||
|
sc_process_close(pid);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static sc_pid
|
||||||
|
sc_adb_execute_p(const char *const argv[], unsigned flags, sc_pipe *pout) {
|
||||||
|
unsigned process_flags = 0;
|
||||||
|
if (flags & SC_ADB_NO_STDOUT) {
|
||||||
|
process_flags |= SC_PROCESS_NO_STDOUT;
|
||||||
|
}
|
||||||
|
if (flags & SC_ADB_NO_STDERR) {
|
||||||
|
process_flags |= SC_PROCESS_NO_STDERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
sc_pid pid;
|
||||||
|
enum sc_process_result r =
|
||||||
|
sc_process_execute_p(argv, &pid, process_flags, NULL, pout, NULL);
|
||||||
|
if (r != SC_PROCESS_SUCCESS) {
|
||||||
|
// If the execution itself failed (not the command exit code), log the
|
||||||
|
// error in all cases
|
||||||
|
show_adb_err_msg(r, argv);
|
||||||
|
pid = SC_PROCESS_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
sc_pid
|
||||||
|
sc_adb_execute(const char *const argv[], unsigned flags) {
|
||||||
|
return sc_adb_execute_p(argv, flags, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_start_server(struct sc_intr *intr, unsigned flags) {
|
||||||
|
const char *const argv[] = SC_ADB_COMMAND("start-server");
|
||||||
|
|
||||||
|
sc_pid pid = sc_adb_execute(argv, flags);
|
||||||
|
return process_check_success_intr(intr, pid, "adb start-server", flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
|
||||||
|
const char *device_socket_name, unsigned flags) {
|
||||||
|
char local[4 + 5 + 1]; // tcp:PORT
|
||||||
|
char remote[108 + 14 + 1]; // localabstract:NAME
|
||||||
|
sprintf(local, "tcp:%" PRIu16, local_port);
|
||||||
|
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name);
|
||||||
|
|
||||||
|
assert(serial);
|
||||||
|
const char *const argv[] =
|
||||||
|
SC_ADB_COMMAND("-s", serial, "forward", local, remote);
|
||||||
|
|
||||||
|
sc_pid pid = sc_adb_execute(argv, flags);
|
||||||
|
return process_check_success_intr(intr, pid, "adb forward", flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_forward_remove(struct sc_intr *intr, const char *serial,
|
||||||
|
uint16_t local_port, unsigned flags) {
|
||||||
|
char local[4 + 5 + 1]; // tcp:PORT
|
||||||
|
sprintf(local, "tcp:%" PRIu16, local_port);
|
||||||
|
|
||||||
|
assert(serial);
|
||||||
|
const char *const argv[] =
|
||||||
|
SC_ADB_COMMAND("-s", serial, "forward", "--remove", local);
|
||||||
|
|
||||||
|
sc_pid pid = sc_adb_execute(argv, flags);
|
||||||
|
return process_check_success_intr(intr, pid, "adb forward --remove", flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_reverse(struct sc_intr *intr, const char *serial,
|
||||||
|
const char *device_socket_name, uint16_t local_port,
|
||||||
|
unsigned flags) {
|
||||||
|
char local[4 + 5 + 1]; // tcp:PORT
|
||||||
|
char remote[108 + 14 + 1]; // localabstract:NAME
|
||||||
|
sprintf(local, "tcp:%" PRIu16, local_port);
|
||||||
|
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name);
|
||||||
|
assert(serial);
|
||||||
|
const char *const argv[] =
|
||||||
|
SC_ADB_COMMAND("-s", serial, "reverse", remote, local);
|
||||||
|
|
||||||
|
sc_pid pid = sc_adb_execute(argv, flags);
|
||||||
|
return process_check_success_intr(intr, pid, "adb reverse", flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_reverse_remove(struct sc_intr *intr, const char *serial,
|
||||||
|
const char *device_socket_name, unsigned flags) {
|
||||||
|
char remote[108 + 14 + 1]; // localabstract:NAME
|
||||||
|
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name);
|
||||||
|
|
||||||
|
assert(serial);
|
||||||
|
const char *const argv[] =
|
||||||
|
SC_ADB_COMMAND("-s", serial, "reverse", "--remove", remote);
|
||||||
|
|
||||||
|
sc_pid pid = sc_adb_execute(argv, flags);
|
||||||
|
return process_check_success_intr(intr, pid, "adb reverse --remove", flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_push(struct sc_intr *intr, const char *serial, const char *local,
|
||||||
|
const char *remote, unsigned flags) {
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
// Windows will parse the string, so the paths must be quoted
|
||||||
|
// (see sys/win/command.c)
|
||||||
|
local = sc_str_quote(local);
|
||||||
|
if (!local) {
|
||||||
|
return SC_PROCESS_NONE;
|
||||||
|
}
|
||||||
|
remote = sc_str_quote(remote);
|
||||||
|
if (!remote) {
|
||||||
|
free((void *) local);
|
||||||
|
return SC_PROCESS_NONE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
assert(serial);
|
||||||
|
const char *const argv[] =
|
||||||
|
SC_ADB_COMMAND("-s", serial, "push", local, remote);
|
||||||
|
|
||||||
|
sc_pid pid = sc_adb_execute(argv, flags);
|
||||||
|
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
free((void *) remote);
|
||||||
|
free((void *) local);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return process_check_success_intr(intr, pid, "adb push", flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_install(struct sc_intr *intr, const char *serial, const char *local,
|
||||||
|
unsigned flags) {
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
// Windows will parse the string, so the local name must be quoted
|
||||||
|
// (see sys/win/command.c)
|
||||||
|
local = sc_str_quote(local);
|
||||||
|
if (!local) {
|
||||||
|
return SC_PROCESS_NONE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
assert(serial);
|
||||||
|
const char *const argv[] =
|
||||||
|
SC_ADB_COMMAND("-s", serial, "install", "-r", local);
|
||||||
|
|
||||||
|
sc_pid pid = sc_adb_execute(argv, flags);
|
||||||
|
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
free((void *) local);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return process_check_success_intr(intr, pid, "adb install", flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_tcpip(struct sc_intr *intr, const char *serial, uint16_t port,
|
||||||
|
unsigned flags) {
|
||||||
|
char port_string[5 + 1];
|
||||||
|
sprintf(port_string, "%" PRIu16, port);
|
||||||
|
|
||||||
|
assert(serial);
|
||||||
|
const char *const argv[] =
|
||||||
|
SC_ADB_COMMAND("-s", serial, "tcpip", port_string);
|
||||||
|
|
||||||
|
sc_pid pid = sc_adb_execute(argv, flags);
|
||||||
|
return process_check_success_intr(intr, pid, "adb tcpip", flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_connect(struct sc_intr *intr, const char *ip_port, unsigned flags) {
|
||||||
|
const char *const argv[] = SC_ADB_COMMAND("connect", ip_port);
|
||||||
|
|
||||||
|
sc_pipe pout;
|
||||||
|
sc_pid pid = sc_adb_execute_p(argv, flags, &pout);
|
||||||
|
if (pid == SC_PROCESS_NONE) {
|
||||||
|
LOGE("Could not execute \"adb connect\"");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// "adb connect" always returns successfully (with exit code 0), even in
|
||||||
|
// case of failure. As a workaround, check if its output starts with
|
||||||
|
// "connected".
|
||||||
|
char buf[128];
|
||||||
|
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 connect", flags);
|
||||||
|
if (!ok) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert((size_t) r < sizeof(buf));
|
||||||
|
buf[r] = '\0';
|
||||||
|
|
||||||
|
ok = !strncmp("connected", buf, sizeof("connected") - 1);
|
||||||
|
if (!ok && !(flags & SC_ADB_NO_STDERR)) {
|
||||||
|
// "adb connect" also prints errors to stdout. Since we capture it,
|
||||||
|
// re-print the error to stderr.
|
||||||
|
size_t len = strcspn(buf, "\r\n");
|
||||||
|
buf[len] = '\0';
|
||||||
|
fprintf(stderr, "%s\n", buf);
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_disconnect(struct sc_intr *intr, const char *ip_port, unsigned flags) {
|
||||||
|
assert(ip_port);
|
||||||
|
const char *const argv[] = SC_ADB_COMMAND("disconnect", ip_port);
|
||||||
|
|
||||||
|
sc_pid pid = sc_adb_execute(argv, flags);
|
||||||
|
return process_check_success_intr(intr, pid, "adb disconnect", flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
sc_adb_list_devices(struct sc_intr *intr, unsigned flags,
|
||||||
|
struct sc_adb_device *devices, size_t len) {
|
||||||
|
const char *const argv[] = SC_ADB_COMMAND("devices", "-l");
|
||||||
|
|
||||||
|
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\"");
|
||||||
|
return -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) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r == -1) {
|
||||||
|
return -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 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
|
||||||
|
return sc_adb_parse_devices(buf, devices, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
sc_adb_accept_device(const struct sc_adb_device *device,
|
||||||
|
const struct sc_adb_device_selector *selector) {
|
||||||
|
switch (selector->type) {
|
||||||
|
case SC_ADB_DEVICE_SELECT_ALL:
|
||||||
|
return true;
|
||||||
|
case SC_ADB_DEVICE_SELECT_SERIAL:
|
||||||
|
assert(selector->serial);
|
||||||
|
char *device_serial_colon = strchr(device->serial, ':');
|
||||||
|
if (device_serial_colon) {
|
||||||
|
// The device serial is an IP:port...
|
||||||
|
char *serial_colon = strchr(selector->serial, ':');
|
||||||
|
if (!serial_colon) {
|
||||||
|
// But the requested serial has no ':', so only consider
|
||||||
|
// the IP part of the device serial. This allows to use
|
||||||
|
// "192.168.1.1" to match any "192.168.1.1:port".
|
||||||
|
size_t serial_len = strlen(selector->serial);
|
||||||
|
size_t device_ip_len = device_serial_colon - device->serial;
|
||||||
|
if (serial_len != device_ip_len) {
|
||||||
|
// They are not equal, they don't even have the same
|
||||||
|
// length
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !strncmp(selector->serial, device->serial,
|
||||||
|
device_ip_len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !strcmp(selector->serial, device->serial);
|
||||||
|
case SC_ADB_DEVICE_SELECT_USB:
|
||||||
|
return !sc_adb_is_serial_tcpip(device->serial);
|
||||||
|
case SC_ADB_DEVICE_SELECT_TCPIP:
|
||||||
|
return sc_adb_is_serial_tcpip(device->serial);
|
||||||
|
default:
|
||||||
|
assert(!"Missing SC_ADB_DEVICE_SELECT_* handling");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
sc_adb_devices_select(struct sc_adb_device *devices, size_t len,
|
||||||
|
const struct sc_adb_device_selector *selector,
|
||||||
|
size_t *idx_out) {
|
||||||
|
size_t count = 0;
|
||||||
|
for (size_t i = 0; i < len; ++i) {
|
||||||
|
struct sc_adb_device *device = &devices[i];
|
||||||
|
device->selected = sc_adb_accept_device(device, selector);
|
||||||
|
if (device->selected) {
|
||||||
|
if (idx_out && !count) {
|
||||||
|
*idx_out = i;
|
||||||
|
}
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sc_adb_devices_log(enum sc_log_level level, struct sc_adb_device *devices,
|
||||||
|
size_t count) {
|
||||||
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
struct sc_adb_device *d = &devices[i];
|
||||||
|
const char *selection = d->selected ? "-->" : " ";
|
||||||
|
const char *type = sc_adb_is_serial_tcpip(d->serial) ? "(tcpip)"
|
||||||
|
: " (usb)";
|
||||||
|
LOG(level, " %s %s %-20s %16s %s",
|
||||||
|
selection, type, d->serial, d->state, d->model ? d->model : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
sc_adb_device_check_state(struct sc_adb_device *device,
|
||||||
|
struct sc_adb_device *devices, size_t count) {
|
||||||
|
const char *state = device->state;
|
||||||
|
|
||||||
|
if (!strcmp("device", state)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp("unauthorized", state)) {
|
||||||
|
LOGE("Device is unauthorized:");
|
||||||
|
sc_adb_devices_log(SC_LOG_LEVEL_ERROR, devices, count);
|
||||||
|
LOGE("A popup should open on the device to request authorization.");
|
||||||
|
LOGE("Check the FAQ: "
|
||||||
|
"<https://github.com/Genymobile/scrcpy/blob/master/FAQ.md>");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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_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 (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(devices, count, selector, &sel_idx);
|
||||||
|
|
||||||
|
if (sel_count == 0) {
|
||||||
|
// if count > 0 && sel_count == 0, then necessarily a selection is
|
||||||
|
// requested
|
||||||
|
assert(selector->type != SC_ADB_DEVICE_SELECT_ALL);
|
||||||
|
|
||||||
|
switch (selector->type) {
|
||||||
|
case SC_ADB_DEVICE_SELECT_SERIAL:
|
||||||
|
assert(selector->serial);
|
||||||
|
LOGE("Could not find ADB device %s:", selector->serial);
|
||||||
|
break;
|
||||||
|
case SC_ADB_DEVICE_SELECT_USB:
|
||||||
|
LOGE("Could not find any ADB device over USB:");
|
||||||
|
break;
|
||||||
|
case SC_ADB_DEVICE_SELECT_TCPIP:
|
||||||
|
LOGE("Could not find any ADB device over TCP/IP:");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(!"Unexpected selector type");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sc_adb_devices_log(SC_LOG_LEVEL_ERROR, devices, count);
|
||||||
|
sc_adb_devices_destroy_all(devices, count);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sel_count > 1) {
|
||||||
|
switch (selector->type) {
|
||||||
|
case SC_ADB_DEVICE_SELECT_ALL:
|
||||||
|
LOGE("Multiple (%" SC_PRIsizet ") ADB devices:", sel_count);
|
||||||
|
break;
|
||||||
|
case SC_ADB_DEVICE_SELECT_SERIAL:
|
||||||
|
assert(selector->serial);
|
||||||
|
LOGE("Multiple (%" SC_PRIsizet ") ADB devices with serial %s:",
|
||||||
|
sel_count, selector->serial);
|
||||||
|
break;
|
||||||
|
case SC_ADB_DEVICE_SELECT_USB:
|
||||||
|
LOGE("Multiple (%" SC_PRIsizet ") ADB devices over USB:",
|
||||||
|
sel_count);
|
||||||
|
break;
|
||||||
|
case SC_ADB_DEVICE_SELECT_TCPIP:
|
||||||
|
LOGE("Multiple (%" SC_PRIsizet ") ADB devices over TCP/IP:",
|
||||||
|
sel_count);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(!"Unexpected selector type");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sc_adb_devices_log(SC_LOG_LEVEL_ERROR, devices, count);
|
||||||
|
LOGE("Select a device via -s (--serial), -d (--select-usb) or -e "
|
||||||
|
"(--select-tcpip)");
|
||||||
|
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 = &devices[sel_idx];
|
||||||
|
|
||||||
|
bool ok = sc_adb_device_check_state(device, devices, count);
|
||||||
|
if (!ok) {
|
||||||
|
sc_adb_devices_destroy_all(devices, count);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGD("ADB device found:");
|
||||||
|
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_all(devices, count);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
sc_adb_getprop(struct sc_intr *intr, const char *serial, const char *prop,
|
||||||
|
unsigned flags) {
|
||||||
|
assert(serial);
|
||||||
|
const char *const argv[] =
|
||||||
|
SC_ADB_COMMAND("-s", serial, "shell", "getprop", prop);
|
||||||
|
|
||||||
|
sc_pipe pout;
|
||||||
|
sc_pid pid = sc_adb_execute_p(argv, flags, &pout);
|
||||||
|
if (pid == SC_PROCESS_NONE) {
|
||||||
|
LOGE("Could not execute \"adb getprop\"");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buf[128];
|
||||||
|
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 getprop", flags);
|
||||||
|
if (!ok) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r == -1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert((size_t) r < sizeof(buf));
|
||||||
|
buf[r] = '\0';
|
||||||
|
size_t len = strcspn(buf, " \r\n");
|
||||||
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
return strdup(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
sc_adb_get_device_ip(struct sc_intr *intr, const char *serial, unsigned flags) {
|
||||||
|
assert(serial);
|
||||||
|
const char *const argv[] =
|
||||||
|
SC_ADB_COMMAND("-s", serial, "shell", "ip", "route");
|
||||||
|
|
||||||
|
sc_pipe pout;
|
||||||
|
sc_pid pid = sc_adb_execute_p(argv, flags, &pout);
|
||||||
|
if (pid == SC_PROCESS_NONE) {
|
||||||
|
LOGD("Could not execute \"ip route\"");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// "adb shell ip route" output should contain only a few lines
|
||||||
|
char buf[1024];
|
||||||
|
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, "ip route", flags);
|
||||||
|
if (!ok) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r == -1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert((size_t) r < sizeof(buf));
|
||||||
|
if (r == sizeof(buf) - 1) {
|
||||||
|
// 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.\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// It is parsed as a NUL-terminated string
|
||||||
|
buf[r] = '\0';
|
||||||
|
|
||||||
|
return sc_adb_parse_device_ip_from_output(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_is_serial_tcpip(const char *serial) {
|
||||||
|
return strchr(serial, ':');
|
||||||
|
}
|
||||||
123
app/src/adb/adb.h
Normal file
123
app/src/adb/adb.h
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
#ifndef SC_ADB_H
|
||||||
|
#define SC_ADB_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#include "adb_device.h"
|
||||||
|
#include "util/intr.h"
|
||||||
|
|
||||||
|
#define SC_ADB_NO_STDOUT (1 << 0)
|
||||||
|
#define SC_ADB_NO_STDERR (1 << 1)
|
||||||
|
#define SC_ADB_NO_LOGERR (1 << 2)
|
||||||
|
|
||||||
|
#define SC_ADB_SILENT (SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR)
|
||||||
|
|
||||||
|
const char *
|
||||||
|
sc_adb_get_executable(void);
|
||||||
|
|
||||||
|
enum sc_adb_device_selector_type {
|
||||||
|
SC_ADB_DEVICE_SELECT_ALL,
|
||||||
|
SC_ADB_DEVICE_SELECT_SERIAL,
|
||||||
|
SC_ADB_DEVICE_SELECT_USB,
|
||||||
|
SC_ADB_DEVICE_SELECT_TCPIP,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sc_adb_device_selector {
|
||||||
|
enum sc_adb_device_selector_type type;
|
||||||
|
const char *serial;
|
||||||
|
};
|
||||||
|
|
||||||
|
sc_pid
|
||||||
|
sc_adb_execute(const char *const argv[], unsigned flags);
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_start_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);
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_forward_remove(struct sc_intr *intr, const char *serial,
|
||||||
|
uint16_t local_port, unsigned flags);
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_reverse(struct sc_intr *intr, const char *serial,
|
||||||
|
const char *device_socket_name, uint16_t local_port,
|
||||||
|
unsigned flags);
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_reverse_remove(struct sc_intr *intr, const char *serial,
|
||||||
|
const char *device_socket_name, unsigned flags);
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_push(struct sc_intr *intr, const char *serial, const char *local,
|
||||||
|
const char *remote, unsigned flags);
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_install(struct sc_intr *intr, const char *serial, const char *local,
|
||||||
|
unsigned flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute `adb tcpip <port>`
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
sc_adb_tcpip(struct sc_intr *intr, const char *serial, uint16_t port,
|
||||||
|
unsigned flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute `adb connect <ip_port>`
|
||||||
|
*
|
||||||
|
* `ip_port` may not be NULL.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
sc_adb_connect(struct sc_intr *intr, const char *ip_port, unsigned flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute `adb disconnect [<ip_port>]`
|
||||||
|
*
|
||||||
|
* If `ip_port` is NULL, execute `adb disconnect`.
|
||||||
|
* Otherwise, execute `adb disconnect <ip_port>`.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
sc_adb_disconnect(struct sc_intr *intr, const char *ip_port, unsigned flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute `adb devices` and parse the result to select a device
|
||||||
|
*
|
||||||
|
* Return true if a single matching device is found, and write it to out_device.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
sc_adb_select_device(struct sc_intr *intr,
|
||||||
|
const struct sc_adb_device_selector *selector,
|
||||||
|
unsigned flags, struct sc_adb_device *out_device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute `adb getprop <prop>`
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
sc_adb_getprop(struct sc_intr *intr, const char *serial, const char *prop,
|
||||||
|
unsigned flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to retrieve the device IP
|
||||||
|
*
|
||||||
|
* Return the IP as a string of the form "xxx.xxx.xxx.xxx", to be freed by the
|
||||||
|
* caller, or NULL on error.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
sc_adb_get_device_ip(struct sc_intr *intr, const char *serial, unsigned flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicate if the serial represents an IP address
|
||||||
|
*
|
||||||
|
* In practice, it just returns true if and only if it contains a ':', which is
|
||||||
|
* sufficient to distinguish an ip:port from a real USB serial.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
sc_adb_is_serial_tcpip(const char *serial);
|
||||||
|
|
||||||
|
#endif
|
||||||
26
app/src/adb/adb_device.c
Normal file
26
app/src/adb/adb_device.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "adb_device.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_adb_device_destroy(struct sc_adb_device *device) {
|
||||||
|
free(device->serial);
|
||||||
|
free(device->state);
|
||||||
|
free(device->model);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_adb_device_move(struct sc_adb_device *dst, struct sc_adb_device *src) {
|
||||||
|
*dst = *src;
|
||||||
|
src->serial = NULL;
|
||||||
|
src->state = NULL;
|
||||||
|
src->model = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
34
app/src/adb/adb_device.h
Normal file
34
app/src/adb/adb_device.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef SC_ADB_DEVICE_H
|
||||||
|
#define SC_ADB_DEVICE_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
struct sc_adb_device {
|
||||||
|
char *serial;
|
||||||
|
char *state;
|
||||||
|
char *model;
|
||||||
|
bool selected;
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_adb_device_destroy(struct sc_adb_device *device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move src to dst
|
||||||
|
*
|
||||||
|
* After this call, the content of src is undefined, except that
|
||||||
|
* sc_adb_device_destroy() can be called.
|
||||||
|
*
|
||||||
|
* This is useful to take a device from a list that will be destroyed, without
|
||||||
|
* making unnecessary copies.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
sc_adb_device_move(struct sc_adb_device *dst, struct sc_adb_device *src);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_adb_devices_destroy_all(struct sc_adb_device *devices, size_t count);
|
||||||
|
|
||||||
|
#endif
|
||||||
231
app/src/adb/adb_parser.c
Normal file
231
app/src/adb/adb_parser.c
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
#include "adb_parser.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "util/log.h"
|
||||||
|
#include "util/str.h"
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_parse_device(char *line, struct sc_adb_device *device) {
|
||||||
|
// One device line looks like:
|
||||||
|
// "0123456789abcdef device usb:2-1 product:MyProduct model:MyModel "
|
||||||
|
// "device:MyDevice transport_id:1"
|
||||||
|
|
||||||
|
if (line[0] == '*') {
|
||||||
|
// Garbage lines printed by adb daemon while starting start with a '*'
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strncmp("adb server", line, sizeof("adb server") - 1)) {
|
||||||
|
// Ignore lines starting with "adb server":
|
||||||
|
// adb server version (41) doesn't match this client (39); killing...
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *s = line; // cursor in the line
|
||||||
|
|
||||||
|
// After the serial:
|
||||||
|
// - "adb devices" writes a single '\t'
|
||||||
|
// - "adb devices -l" writes multiple spaces
|
||||||
|
// For flexibility, accept both.
|
||||||
|
size_t serial_len = strcspn(s, " \t");
|
||||||
|
if (!serial_len) {
|
||||||
|
// empty serial
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool eol = s[serial_len] == '\0';
|
||||||
|
if (eol) {
|
||||||
|
// serial alone is unexpected
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
s[serial_len] = '\0';
|
||||||
|
char *serial = s;
|
||||||
|
s += serial_len + 1;
|
||||||
|
// After the serial, there might be several spaces
|
||||||
|
s += strspn(s, " \t"); // consume all separators
|
||||||
|
|
||||||
|
size_t state_len = strcspn(s, " ");
|
||||||
|
if (!state_len) {
|
||||||
|
// empty state
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
eol = s[state_len] == '\0';
|
||||||
|
s[state_len] = '\0';
|
||||||
|
char *state = s;
|
||||||
|
|
||||||
|
char *model = NULL;
|
||||||
|
if (!eol) {
|
||||||
|
s += state_len + 1;
|
||||||
|
|
||||||
|
// Iterate over all properties "key:value key:value ..."
|
||||||
|
for (;;) {
|
||||||
|
size_t token_len = strcspn(s, " ");
|
||||||
|
if (!token_len) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
eol = s[token_len] == '\0';
|
||||||
|
s[token_len] = '\0';
|
||||||
|
char *token = s;
|
||||||
|
|
||||||
|
if (!strncmp("model:", token, sizeof("model:") - 1)) {
|
||||||
|
model = &token[sizeof("model:") - 1];
|
||||||
|
// We only need the model
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eol) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
s+= token_len + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
device->serial = strdup(serial);
|
||||||
|
if (!device->serial) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
device->state = strdup(state);
|
||||||
|
if (!device->state) {
|
||||||
|
free(device->serial);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model) {
|
||||||
|
device->model = strdup(model);
|
||||||
|
if (!device->model) {
|
||||||
|
LOG_OOM();
|
||||||
|
// model is optional, do not fail
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
device->model = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
device->selected = false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
size_t idx_line = 0;
|
||||||
|
while (str[idx_line] != '\0') {
|
||||||
|
char *line = &str[idx_line];
|
||||||
|
size_t len = strcspn(line, "\n");
|
||||||
|
|
||||||
|
// The next line starts after the '\n' (replaced by `\0`)
|
||||||
|
idx_line += len;
|
||||||
|
|
||||||
|
if (str[idx_line] != '\0') {
|
||||||
|
// The next line starts after the '\n'
|
||||||
|
++idx_line;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!header_found) {
|
||||||
|
if (!strncmp(line, HEADER, HEADER_LEN)) {
|
||||||
|
header_found = true;
|
||||||
|
}
|
||||||
|
// Skip everything until the header, there might be garbage lines
|
||||||
|
// related to daemon starting before
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The line, but without any trailing '\r'
|
||||||
|
size_t line_len = sc_str_remove_trailing_cr(line, len);
|
||||||
|
line[line_len] = '\0';
|
||||||
|
|
||||||
|
bool ok = sc_adb_parse_device(line, &devices[dev_count]);
|
||||||
|
if (!ok) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
++dev_count;
|
||||||
|
|
||||||
|
assert(dev_count <= devices_len);
|
||||||
|
if (dev_count == devices_len) {
|
||||||
|
// Max number of devices reached
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!header_found) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dev_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
sc_adb_parse_device_ip_from_line(char *line) {
|
||||||
|
// One line from "ip route" looks like:
|
||||||
|
// "192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.x"
|
||||||
|
|
||||||
|
// Get the location of the device name (index of "wlan0" in the example)
|
||||||
|
ssize_t idx_dev_name = sc_str_index_of_column(line, 2, " ");
|
||||||
|
if (idx_dev_name == -1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the location of the ip address (column 8, but column 6 if we start
|
||||||
|
// from column 2). Must be computed before truncating individual columns.
|
||||||
|
ssize_t idx_ip = sc_str_index_of_column(&line[idx_dev_name], 6, " ");
|
||||||
|
if (idx_ip == -1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// idx_ip is searched from &line[idx_dev_name]
|
||||||
|
idx_ip += idx_dev_name;
|
||||||
|
|
||||||
|
char *dev_name = &line[idx_dev_name];
|
||||||
|
size_t dev_name_len = strcspn(dev_name, " \t");
|
||||||
|
dev_name[dev_name_len] = '\0';
|
||||||
|
|
||||||
|
char *ip = &line[idx_ip];
|
||||||
|
size_t ip_len = strcspn(ip, " \t");
|
||||||
|
ip[ip_len] = '\0';
|
||||||
|
|
||||||
|
// Only consider lines where the device name starts with "wlan"
|
||||||
|
if (strncmp(dev_name, "wlan", sizeof("wlan") - 1)) {
|
||||||
|
LOGD("Device ip lookup: ignoring %s (%s)", ip, dev_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strdup(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
sc_adb_parse_device_ip_from_output(char *str) {
|
||||||
|
size_t idx_line = 0;
|
||||||
|
while (str[idx_line] != '\0') {
|
||||||
|
char *line = &str[idx_line];
|
||||||
|
size_t len = strcspn(line, "\n");
|
||||||
|
|
||||||
|
// The same, but without any trailing '\r'
|
||||||
|
size_t line_len = sc_str_remove_trailing_cr(line, len);
|
||||||
|
line[line_len] = '\0';
|
||||||
|
|
||||||
|
char *ip = sc_adb_parse_device_ip_from_line(line);
|
||||||
|
if (ip) {
|
||||||
|
// Found
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
idx_line += len;
|
||||||
|
|
||||||
|
if (str[idx_line] != '\0') {
|
||||||
|
// The next line starts after the '\n'
|
||||||
|
++idx_line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
31
app/src/adb/adb_parser.h
Normal file
31
app/src/adb/adb_parser.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef SC_ADB_PARSER_H
|
||||||
|
#define SC_ADB_PARSER_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "adb_device.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the available devices from the output of `adb devices`
|
||||||
|
*
|
||||||
|
* The parameter must be a NUL-terminated string.
|
||||||
|
*
|
||||||
|
* Warning: this function modifies the buffer for optimization purposes.
|
||||||
|
*/
|
||||||
|
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`
|
||||||
|
*
|
||||||
|
* The parameter must be a NUL-terminated string.
|
||||||
|
*
|
||||||
|
* Warning: this function modifies the buffer for optimization purposes.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
sc_adb_parse_device_ip_from_output(char *str);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -20,7 +20,7 @@ enable_tunnel_reverse_any_port(struct sc_adb_tunnel *tunnel,
|
|||||||
struct sc_port_range port_range) {
|
struct sc_port_range port_range) {
|
||||||
uint16_t port = port_range.first;
|
uint16_t port = port_range.first;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (!adb_reverse(intr, serial, SC_SOCKET_NAME, port,
|
if (!sc_adb_reverse(intr, serial, SC_SOCKET_NAME, port,
|
||||||
SC_ADB_NO_STDOUT)) {
|
SC_ADB_NO_STDOUT)) {
|
||||||
// the command itself failed, it will fail on any port
|
// the command itself failed, it will fail on any port
|
||||||
return false;
|
return false;
|
||||||
@@ -52,7 +52,7 @@ enable_tunnel_reverse_any_port(struct sc_adb_tunnel *tunnel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// failure, disable tunnel and try another port
|
// failure, disable tunnel and try another port
|
||||||
if (!adb_reverse_remove(intr, serial, SC_SOCKET_NAME,
|
if (!sc_adb_reverse_remove(intr, serial, SC_SOCKET_NAME,
|
||||||
SC_ADB_NO_STDOUT)) {
|
SC_ADB_NO_STDOUT)) {
|
||||||
LOGW("Could not remove reverse tunnel on port %" PRIu16, port);
|
LOGW("Could not remove reverse tunnel on port %" PRIu16, port);
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,8 @@ enable_tunnel_forward_any_port(struct sc_adb_tunnel *tunnel,
|
|||||||
|
|
||||||
uint16_t port = port_range.first;
|
uint16_t port = port_range.first;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (adb_forward(intr, serial, port, SC_SOCKET_NAME, SC_ADB_NO_STDOUT)) {
|
if (sc_adb_forward(intr, serial, port, SC_SOCKET_NAME,
|
||||||
|
SC_ADB_NO_STDOUT)) {
|
||||||
// success
|
// success
|
||||||
tunnel->local_port = port;
|
tunnel->local_port = port;
|
||||||
tunnel->enabled = true;
|
tunnel->enabled = true;
|
||||||
@@ -148,10 +149,10 @@ sc_adb_tunnel_close(struct sc_adb_tunnel *tunnel, struct sc_intr *intr,
|
|||||||
|
|
||||||
bool ret;
|
bool ret;
|
||||||
if (tunnel->forward) {
|
if (tunnel->forward) {
|
||||||
ret = adb_forward_remove(intr, serial, tunnel->local_port,
|
ret = sc_adb_forward_remove(intr, serial, tunnel->local_port,
|
||||||
SC_ADB_NO_STDOUT);
|
SC_ADB_NO_STDOUT);
|
||||||
} else {
|
} else {
|
||||||
ret = adb_reverse_remove(intr, serial, SC_SOCKET_NAME,
|
ret = sc_adb_reverse_remove(intr, serial, SC_SOCKET_NAME,
|
||||||
SC_ADB_NO_STDOUT);
|
SC_ADB_NO_STDOUT);
|
||||||
|
|
||||||
assert(tunnel->server_socket != SC_SOCKET_NONE);
|
assert(tunnel->server_socket != SC_SOCKET_NONE);
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
#include "adb_parser.h"
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "util/log.h"
|
|
||||||
#include "util/str.h"
|
|
||||||
|
|
||||||
static char *
|
|
||||||
sc_adb_parse_device_ip_from_line(char *line, size_t len) {
|
|
||||||
// One line from "ip route" looks lile:
|
|
||||||
// "192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.x"
|
|
||||||
|
|
||||||
// Get the location of the device name (index of "wlan0" in the example)
|
|
||||||
ssize_t idx_dev_name = sc_str_index_of_column(line, 2, " ");
|
|
||||||
if (idx_dev_name == -1) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the location of the ip address (column 8, but column 6 if we start
|
|
||||||
// from column 2). Must be computed before truncating individual columns.
|
|
||||||
ssize_t idx_ip = sc_str_index_of_column(&line[idx_dev_name], 6, " ");
|
|
||||||
if (idx_ip == -1) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
// idx_ip is searched from &line[idx_dev_name]
|
|
||||||
idx_ip += idx_dev_name;
|
|
||||||
|
|
||||||
char *dev_name = &line[idx_dev_name];
|
|
||||||
sc_str_truncate(dev_name, len - idx_dev_name + 1, " \t");
|
|
||||||
|
|
||||||
char *ip = &line[idx_ip];
|
|
||||||
sc_str_truncate(ip, len - idx_ip + 1, " \t");
|
|
||||||
|
|
||||||
// Only consider lines where the device name starts with "wlan"
|
|
||||||
if (strncmp(dev_name, "wlan", sizeof("wlan") - 1)) {
|
|
||||||
LOGD("Device ip lookup: ignoring %s (%s)", ip, dev_name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return strdup(ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
sc_adb_parse_device_ip_from_output(char *buf, size_t buf_len) {
|
|
||||||
size_t idx_line = 0;
|
|
||||||
while (idx_line < buf_len && buf[idx_line] != '\0') {
|
|
||||||
char *line = &buf[idx_line];
|
|
||||||
size_t len = sc_str_truncate(line, buf_len - idx_line, "\n");
|
|
||||||
|
|
||||||
// The same, but without any trailing '\r'
|
|
||||||
size_t line_len = sc_str_remove_trailing_cr(line, len);
|
|
||||||
|
|
||||||
char *ip = sc_adb_parse_device_ip_from_line(line, line_len);
|
|
||||||
if (ip) {
|
|
||||||
// Found
|
|
||||||
return ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The next line starts after the '\n' (replaced by `\0`)
|
|
||||||
idx_line += len + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#ifndef SC_ADB_PARSER_H
|
|
||||||
#define SC_ADB_PARSER_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include "stddef.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the ip from the output of `adb shell ip route`
|
|
||||||
*/
|
|
||||||
char *
|
|
||||||
sc_adb_parse_device_ip_from_output(char *buf, size_t buf_len);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
142
app/src/cli.c
142
app/src/cli.c
@@ -52,6 +52,8 @@
|
|||||||
#define OPT_NO_CLIPBOARD_AUTOSYNC 1032
|
#define OPT_NO_CLIPBOARD_AUTOSYNC 1032
|
||||||
#define OPT_TCPIP 1033
|
#define OPT_TCPIP 1033
|
||||||
#define OPT_RAW_KEY_EVENTS 1034
|
#define OPT_RAW_KEY_EVENTS 1034
|
||||||
|
#define OPT_NO_DOWNSIZE_ON_ERROR 1035
|
||||||
|
#define OPT_OTG 1036
|
||||||
|
|
||||||
struct sc_option {
|
struct sc_option {
|
||||||
char shortopt;
|
char shortopt;
|
||||||
@@ -116,6 +118,12 @@ static const struct sc_option options[] = {
|
|||||||
"(typically, portrait for a phone, landscape for a tablet). "
|
"(typically, portrait for a phone, landscape for a tablet). "
|
||||||
"Any --max-size value is cmoputed on the cropped size.",
|
"Any --max-size value is cmoputed 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).",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.longopt_id = OPT_DISABLE_SCREENSAVER,
|
.longopt_id = OPT_DISABLE_SCREENSAVER,
|
||||||
.longopt = "disable-screensaver",
|
.longopt = "disable-screensaver",
|
||||||
@@ -139,6 +147,12 @@ static const struct sc_option options[] = {
|
|||||||
"This increases latency to compensate for jitter.\n"
|
"This increases latency to compensate for jitter.\n"
|
||||||
"Default is 0 (no buffering).",
|
"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_id = OPT_ENCODER_NAME,
|
||||||
.longopt = "encoder",
|
.longopt = "encoder",
|
||||||
@@ -236,6 +250,13 @@ static const struct sc_option options[] = {
|
|||||||
"is preserved.\n"
|
"is preserved.\n"
|
||||||
"Default is 0 (unlimited).",
|
"Default is 0 (unlimited).",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.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,
|
.longopt_id = OPT_NO_CLIPBOARD_AUTOSYNC,
|
||||||
.longopt = "no-clipboard-autosync",
|
.longopt = "no-clipboard-autosync",
|
||||||
@@ -268,6 +289,22 @@ static const struct sc_option options[] = {
|
|||||||
"mipmaps are automatically generated to improve downscaling "
|
"mipmaps are automatically generated to improve downscaling "
|
||||||
"quality. This option disables the generation of mipmaps.",
|
"quality. This option disables the generation of mipmaps.",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.longopt_id = OPT_OTG,
|
||||||
|
.longopt = "otg",
|
||||||
|
.text = "Run in OTG mode: simulate physical keyboard and mouse, "
|
||||||
|
"as if the computer keyboard and mouse were plugged directly "
|
||||||
|
"to the device via an OTG cable.\n"
|
||||||
|
"In this mode, adb (USB debugging) is not necessary, and "
|
||||||
|
"mirroring is disabled.\n"
|
||||||
|
"LAlt, LSuper or RSuper toggle the mouse capture mode, to give "
|
||||||
|
"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, and is currently only supported "
|
||||||
|
"on Linux.\n"
|
||||||
|
"See --hid-keyboard and --hid-mouse.",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.shortopt = 'p',
|
.shortopt = 'p',
|
||||||
.longopt = "port",
|
.longopt = "port",
|
||||||
@@ -1295,6 +1332,12 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'd':
|
||||||
|
opts->select_usb = true;
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
opts->select_tcpip = true;
|
||||||
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
opts->fullscreen = true;
|
opts->fullscreen = true;
|
||||||
break;
|
break;
|
||||||
@@ -1310,14 +1353,14 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
args->help = true;
|
args->help = true;
|
||||||
break;
|
break;
|
||||||
case 'K':
|
case 'K':
|
||||||
#ifdef HAVE_AOA_HID
|
#ifdef HAVE_USB
|
||||||
opts->keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_HID;
|
opts->keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_HID;
|
||||||
|
break;
|
||||||
#else
|
#else
|
||||||
LOGE("HID over AOA (-K/--hid-keyboard) is not supported on "
|
LOGE("HID over AOA (-K/--hid-keyboard) is not supported on "
|
||||||
"this platform. It is only available on Linux.");
|
"this platform. It is only available on Linux.");
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
break;
|
|
||||||
case OPT_MAX_FPS:
|
case OPT_MAX_FPS:
|
||||||
if (!parse_max_fps(optarg, &opts->max_fps)) {
|
if (!parse_max_fps(optarg, &opts->max_fps)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1329,14 +1372,14 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
#ifdef HAVE_AOA_HID
|
#ifdef HAVE_USB
|
||||||
opts->mouse_input_mode = SC_MOUSE_INPUT_MODE_HID;
|
opts->mouse_input_mode = SC_MOUSE_INPUT_MODE_HID;
|
||||||
|
break;
|
||||||
#else
|
#else
|
||||||
LOGE("HID over AOA (-M/--hid-mouse) is not supported on this"
|
LOGE("HID over AOA (-M/--hid-mouse) is not supported on this"
|
||||||
"platform. It is only available on Linux.");
|
"platform. It is only available on Linux.");
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
break;
|
|
||||||
case OPT_LOCK_VIDEO_ORIENTATION:
|
case OPT_LOCK_VIDEO_ORIENTATION:
|
||||||
if (!parse_lock_video_orientation(optarg,
|
if (!parse_lock_video_orientation(optarg,
|
||||||
&opts->lock_video_orientation)) {
|
&opts->lock_video_orientation)) {
|
||||||
@@ -1489,24 +1532,36 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
opts->tcpip = true;
|
opts->tcpip = true;
|
||||||
opts->tcpip_dst = optarg;
|
opts->tcpip_dst = optarg;
|
||||||
break;
|
break;
|
||||||
|
case OPT_NO_DOWNSIZE_ON_ERROR:
|
||||||
|
opts->downsize_on_error = false;
|
||||||
|
break;
|
||||||
|
case OPT_OTG:
|
||||||
|
#ifdef HAVE_USB
|
||||||
|
opts->otg = true;
|
||||||
|
break;
|
||||||
|
#else
|
||||||
|
LOGE("OTG mode (--otg) is not supported on this platform. It "
|
||||||
|
"is only available on Linux.");
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
case OPT_V4L2_SINK:
|
case OPT_V4L2_SINK:
|
||||||
#ifdef HAVE_V4L2
|
#ifdef HAVE_V4L2
|
||||||
opts->v4l2_device = optarg;
|
opts->v4l2_device = optarg;
|
||||||
|
break;
|
||||||
#else
|
#else
|
||||||
LOGE("V4L2 (--v4l2-sink) is only available on Linux.");
|
LOGE("V4L2 (--v4l2-sink) is only available on Linux.");
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
break;
|
|
||||||
case OPT_V4L2_BUFFER:
|
case OPT_V4L2_BUFFER:
|
||||||
#ifdef HAVE_V4L2
|
#ifdef HAVE_V4L2
|
||||||
if (!parse_buffering_time(optarg, &opts->v4l2_buffer)) {
|
if (!parse_buffering_time(optarg, &opts->v4l2_buffer)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
#else
|
#else
|
||||||
LOGE("V4L2 (--v4l2-buffer) is only available on Linux.");
|
LOGE("V4L2 (--v4l2-buffer) is only available on Linux.");
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
// getopt prints the error message on stderr
|
// getopt prints the error message on stderr
|
||||||
return false;
|
return false;
|
||||||
@@ -1522,8 +1577,16 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
// If a TCP/IP address is provided, then tcpip must be enabled
|
// If a TCP/IP address is provided, then tcpip must be enabled
|
||||||
assert(opts->tcpip || !opts->tcpip_dst);
|
assert(opts->tcpip || !opts->tcpip_dst);
|
||||||
|
|
||||||
if (opts->serial && opts->tcpip_dst) {
|
unsigned selectors = !!opts->serial
|
||||||
LOGE("Incompatible options: -s/--serial and --tcpip with an argument");
|
+ !!opts->tcpip_dst
|
||||||
|
+ opts->select_tcpip
|
||||||
|
+ opts->select_usb;
|
||||||
|
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"
|
||||||
|
" --tcpip=<addr> (with an argument)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1534,13 +1597,20 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts->v4l2_device && opts->lock_video_orientation
|
if (opts->v4l2_device) {
|
||||||
== SC_LOCK_VIDEO_ORIENTATION_UNLOCKED) {
|
if (opts->lock_video_orientation ==
|
||||||
|
SC_LOCK_VIDEO_ORIENTATION_UNLOCKED) {
|
||||||
LOGI("Video orientation is locked for v4l2 sink. "
|
LOGI("Video orientation is locked for v4l2 sink. "
|
||||||
"See --lock-video-orientation.");
|
"See --lock-video-orientation.");
|
||||||
opts->lock_video_orientation = SC_LOCK_VIDEO_ORIENTATION_INITIAL;
|
opts->lock_video_orientation = SC_LOCK_VIDEO_ORIENTATION_INITIAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// V4L2 could not handle size change.
|
||||||
|
// Do not log because downsizing on error is the default behavior,
|
||||||
|
// not an explicit request from the user.
|
||||||
|
opts->downsize_on_error = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (opts->v4l2_buffer && !opts->v4l2_device) {
|
if (opts->v4l2_buffer && !opts->v4l2_device) {
|
||||||
LOGE("V4L2 buffer value without V4L2 sink\n");
|
LOGE("V4L2 buffer value without V4L2 sink\n");
|
||||||
return false;
|
return false;
|
||||||
@@ -1573,15 +1643,61 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opts->control && opts->turn_screen_off) {
|
if (!opts->control) {
|
||||||
|
if (opts->turn_screen_off) {
|
||||||
LOGE("Could not request to turn screen off if control is disabled");
|
LOGE("Could not request to turn screen off if control is disabled");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (opts->stay_awake) {
|
||||||
if (!opts->control && opts->stay_awake) {
|
|
||||||
LOGE("Could not request to stay awake if control is disabled");
|
LOGE("Could not request to stay awake if control is disabled");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (opts->show_touches) {
|
||||||
|
LOGE("Could not request to show touches if control is disabled");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (opts->power_off_on_close) {
|
||||||
|
LOGE("Could not request power off on close if control is disabled");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_USB
|
||||||
|
if (opts->otg) {
|
||||||
|
// OTG mode is compatible with only very few options.
|
||||||
|
// Only report obvious errors.
|
||||||
|
if (opts->record_filename) {
|
||||||
|
LOGE("OTG mode: could not record");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (opts->turn_screen_off) {
|
||||||
|
LOGE("OTG mode: could not turn screen off");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (opts->stay_awake) {
|
||||||
|
LOGE("OTG mode: could not stay awake");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (opts->show_touches) {
|
||||||
|
LOGE("OTG mode: could not request to show touches");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (opts->power_off_on_close) {
|
||||||
|
LOGE("OTG mode: could not request power off on close");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (opts->display_id) {
|
||||||
|
LOGE("OTG mode: could not select display");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#ifdef HAVE_V4L2
|
||||||
|
if (opts->v4l2_device) {
|
||||||
|
LOGE("OTG mode: could not sink to V4L2 device");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,10 @@
|
|||||||
|
|
||||||
#ifndef __WIN32
|
#ifndef __WIN32
|
||||||
# define PRIu64_ PRIu64
|
# define PRIu64_ PRIu64
|
||||||
|
# define SC_PRIsizet "zu"
|
||||||
#else
|
#else
|
||||||
# define PRIu64_ "I64u" // Windows...
|
# define PRIu64_ "I64u" // Windows...
|
||||||
|
# define SC_PRIsizet "Iu"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// In ffmpeg/doc/APIchanges:
|
// In ffmpeg/doc/APIchanges:
|
||||||
|
|||||||
@@ -92,19 +92,19 @@ size_t
|
|||||||
sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf) {
|
sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf) {
|
||||||
buf[0] = msg->type;
|
buf[0] = msg->type;
|
||||||
switch (msg->type) {
|
switch (msg->type) {
|
||||||
case CONTROL_MSG_TYPE_INJECT_KEYCODE:
|
case SC_CONTROL_MSG_TYPE_INJECT_KEYCODE:
|
||||||
buf[1] = msg->inject_keycode.action;
|
buf[1] = msg->inject_keycode.action;
|
||||||
buffer_write32be(&buf[2], msg->inject_keycode.keycode);
|
buffer_write32be(&buf[2], msg->inject_keycode.keycode);
|
||||||
buffer_write32be(&buf[6], msg->inject_keycode.repeat);
|
buffer_write32be(&buf[6], msg->inject_keycode.repeat);
|
||||||
buffer_write32be(&buf[10], msg->inject_keycode.metastate);
|
buffer_write32be(&buf[10], msg->inject_keycode.metastate);
|
||||||
return 14;
|
return 14;
|
||||||
case CONTROL_MSG_TYPE_INJECT_TEXT: {
|
case SC_CONTROL_MSG_TYPE_INJECT_TEXT: {
|
||||||
size_t len =
|
size_t len =
|
||||||
write_string(msg->inject_text.text,
|
write_string(msg->inject_text.text,
|
||||||
CONTROL_MSG_INJECT_TEXT_MAX_LENGTH, &buf[1]);
|
SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH, &buf[1]);
|
||||||
return 1 + len;
|
return 1 + len;
|
||||||
}
|
}
|
||||||
case CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT:
|
case SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT:
|
||||||
buf[1] = msg->inject_touch_event.action;
|
buf[1] = msg->inject_touch_event.action;
|
||||||
buffer_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);
|
write_position(&buf[10], &msg->inject_touch_event.position);
|
||||||
@@ -113,7 +113,7 @@ sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf) {
|
|||||||
buffer_write16be(&buf[22], pressure);
|
buffer_write16be(&buf[22], pressure);
|
||||||
buffer_write32be(&buf[24], msg->inject_touch_event.buttons);
|
buffer_write32be(&buf[24], msg->inject_touch_event.buttons);
|
||||||
return 28;
|
return 28;
|
||||||
case CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT:
|
case SC_CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT:
|
||||||
write_position(&buf[1], &msg->inject_scroll_event.position);
|
write_position(&buf[1], &msg->inject_scroll_event.position);
|
||||||
buffer_write32be(&buf[13],
|
buffer_write32be(&buf[13],
|
||||||
(uint32_t) msg->inject_scroll_event.hscroll);
|
(uint32_t) msg->inject_scroll_event.hscroll);
|
||||||
@@ -121,27 +121,26 @@ sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf) {
|
|||||||
(uint32_t) msg->inject_scroll_event.vscroll);
|
(uint32_t) msg->inject_scroll_event.vscroll);
|
||||||
buffer_write32be(&buf[21], msg->inject_scroll_event.buttons);
|
buffer_write32be(&buf[21], msg->inject_scroll_event.buttons);
|
||||||
return 25;
|
return 25;
|
||||||
case CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON:
|
case SC_CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON:
|
||||||
buf[1] = msg->inject_keycode.action;
|
buf[1] = msg->inject_keycode.action;
|
||||||
return 2;
|
return 2;
|
||||||
case CONTROL_MSG_TYPE_GET_CLIPBOARD:
|
case SC_CONTROL_MSG_TYPE_GET_CLIPBOARD:
|
||||||
buf[1] = msg->get_clipboard.copy_key;
|
buf[1] = msg->get_clipboard.copy_key;
|
||||||
return 2;
|
return 2;
|
||||||
case CONTROL_MSG_TYPE_SET_CLIPBOARD: {
|
case SC_CONTROL_MSG_TYPE_SET_CLIPBOARD:
|
||||||
buffer_write64be(&buf[1], msg->set_clipboard.sequence);
|
buffer_write64be(&buf[1], msg->set_clipboard.sequence);
|
||||||
buf[9] = !!msg->set_clipboard.paste;
|
buf[9] = !!msg->set_clipboard.paste;
|
||||||
size_t len = write_string(msg->set_clipboard.text,
|
size_t len = write_string(msg->set_clipboard.text,
|
||||||
CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH,
|
SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH,
|
||||||
&buf[10]);
|
&buf[10]);
|
||||||
return 10 + len;
|
return 10 + len;
|
||||||
}
|
case SC_CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE:
|
||||||
case CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE:
|
|
||||||
buf[1] = msg->set_screen_power_mode.mode;
|
buf[1] = msg->set_screen_power_mode.mode;
|
||||||
return 2;
|
return 2;
|
||||||
case CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL:
|
case SC_CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||||
case CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL:
|
case SC_CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL:
|
||||||
case CONTROL_MSG_TYPE_COLLAPSE_PANELS:
|
case SC_CONTROL_MSG_TYPE_COLLAPSE_PANELS:
|
||||||
case CONTROL_MSG_TYPE_ROTATE_DEVICE:
|
case SC_CONTROL_MSG_TYPE_ROTATE_DEVICE:
|
||||||
// no additional data
|
// no additional data
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
@@ -154,17 +153,17 @@ void
|
|||||||
sc_control_msg_log(const struct sc_control_msg *msg) {
|
sc_control_msg_log(const struct sc_control_msg *msg) {
|
||||||
#define LOG_CMSG(fmt, ...) LOGV("input: " fmt, ## __VA_ARGS__)
|
#define LOG_CMSG(fmt, ...) LOGV("input: " fmt, ## __VA_ARGS__)
|
||||||
switch (msg->type) {
|
switch (msg->type) {
|
||||||
case CONTROL_MSG_TYPE_INJECT_KEYCODE:
|
case SC_CONTROL_MSG_TYPE_INJECT_KEYCODE:
|
||||||
LOG_CMSG("key %-4s code=%d repeat=%" PRIu32 " meta=%06lx",
|
LOG_CMSG("key %-4s code=%d repeat=%" PRIu32 " meta=%06lx",
|
||||||
KEYEVENT_ACTION_LABEL(msg->inject_keycode.action),
|
KEYEVENT_ACTION_LABEL(msg->inject_keycode.action),
|
||||||
(int) msg->inject_keycode.keycode,
|
(int) msg->inject_keycode.keycode,
|
||||||
msg->inject_keycode.repeat,
|
msg->inject_keycode.repeat,
|
||||||
(long) msg->inject_keycode.metastate);
|
(long) msg->inject_keycode.metastate);
|
||||||
break;
|
break;
|
||||||
case CONTROL_MSG_TYPE_INJECT_TEXT:
|
case SC_CONTROL_MSG_TYPE_INJECT_TEXT:
|
||||||
LOG_CMSG("text \"%s\"", msg->inject_text.text);
|
LOG_CMSG("text \"%s\"", msg->inject_text.text);
|
||||||
break;
|
break;
|
||||||
case CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT: {
|
case SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT: {
|
||||||
int action = msg->inject_touch_event.action
|
int action = msg->inject_touch_event.action
|
||||||
& AMOTION_EVENT_ACTION_MASK;
|
& AMOTION_EVENT_ACTION_MASK;
|
||||||
uint64_t id = msg->inject_touch_event.pointer_id;
|
uint64_t id = msg->inject_touch_event.pointer_id;
|
||||||
@@ -191,7 +190,7 @@ sc_control_msg_log(const struct sc_control_msg *msg) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT:
|
case SC_CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT:
|
||||||
LOG_CMSG("scroll position=%" PRIi32 ",%" PRIi32 " hscroll=%" PRIi32
|
LOG_CMSG("scroll position=%" PRIi32 ",%" PRIi32 " hscroll=%" PRIi32
|
||||||
" vscroll=%" PRIi32 " buttons=%06lx",
|
" vscroll=%" PRIi32 " buttons=%06lx",
|
||||||
msg->inject_scroll_event.position.point.x,
|
msg->inject_scroll_event.position.point.x,
|
||||||
@@ -200,34 +199,34 @@ sc_control_msg_log(const struct sc_control_msg *msg) {
|
|||||||
msg->inject_scroll_event.vscroll,
|
msg->inject_scroll_event.vscroll,
|
||||||
(long) msg->inject_scroll_event.buttons);
|
(long) msg->inject_scroll_event.buttons);
|
||||||
break;
|
break;
|
||||||
case CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON:
|
case SC_CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON:
|
||||||
LOG_CMSG("back-or-screen-on %s",
|
LOG_CMSG("back-or-screen-on %s",
|
||||||
KEYEVENT_ACTION_LABEL(msg->inject_keycode.action));
|
KEYEVENT_ACTION_LABEL(msg->inject_keycode.action));
|
||||||
break;
|
break;
|
||||||
case CONTROL_MSG_TYPE_GET_CLIPBOARD:
|
case SC_CONTROL_MSG_TYPE_GET_CLIPBOARD:
|
||||||
LOG_CMSG("get clipboard copy_key=%s",
|
LOG_CMSG("get clipboard copy_key=%s",
|
||||||
copy_key_labels[msg->get_clipboard.copy_key]);
|
copy_key_labels[msg->get_clipboard.copy_key]);
|
||||||
break;
|
break;
|
||||||
case CONTROL_MSG_TYPE_SET_CLIPBOARD:
|
case SC_CONTROL_MSG_TYPE_SET_CLIPBOARD:
|
||||||
LOG_CMSG("clipboard %" PRIu64_ " %s \"%s\"",
|
LOG_CMSG("clipboard %" PRIu64_ " %s \"%s\"",
|
||||||
msg->set_clipboard.sequence,
|
msg->set_clipboard.sequence,
|
||||||
msg->set_clipboard.paste ? "paste" : "nopaste",
|
msg->set_clipboard.paste ? "paste" : "nopaste",
|
||||||
msg->set_clipboard.text);
|
msg->set_clipboard.text);
|
||||||
break;
|
break;
|
||||||
case CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE:
|
case SC_CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE:
|
||||||
LOG_CMSG("power mode %s",
|
LOG_CMSG("power mode %s",
|
||||||
SCREEN_POWER_MODE_LABEL(msg->set_screen_power_mode.mode));
|
SCREEN_POWER_MODE_LABEL(msg->set_screen_power_mode.mode));
|
||||||
break;
|
break;
|
||||||
case CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL:
|
case SC_CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||||
LOG_CMSG("expand notification panel");
|
LOG_CMSG("expand notification panel");
|
||||||
break;
|
break;
|
||||||
case CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL:
|
case SC_CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL:
|
||||||
LOG_CMSG("expand settings panel");
|
LOG_CMSG("expand settings panel");
|
||||||
break;
|
break;
|
||||||
case CONTROL_MSG_TYPE_COLLAPSE_PANELS:
|
case SC_CONTROL_MSG_TYPE_COLLAPSE_PANELS:
|
||||||
LOG_CMSG("collapse panels");
|
LOG_CMSG("collapse panels");
|
||||||
break;
|
break;
|
||||||
case CONTROL_MSG_TYPE_ROTATE_DEVICE:
|
case SC_CONTROL_MSG_TYPE_ROTATE_DEVICE:
|
||||||
LOG_CMSG("rotate device");
|
LOG_CMSG("rotate device");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -239,10 +238,10 @@ sc_control_msg_log(const struct sc_control_msg *msg) {
|
|||||||
void
|
void
|
||||||
sc_control_msg_destroy(struct sc_control_msg *msg) {
|
sc_control_msg_destroy(struct sc_control_msg *msg) {
|
||||||
switch (msg->type) {
|
switch (msg->type) {
|
||||||
case CONTROL_MSG_TYPE_INJECT_TEXT:
|
case SC_CONTROL_MSG_TYPE_INJECT_TEXT:
|
||||||
free(msg->inject_text.text);
|
free(msg->inject_text.text);
|
||||||
break;
|
break;
|
||||||
case CONTROL_MSG_TYPE_SET_CLIPBOARD:
|
case SC_CONTROL_MSG_TYPE_SET_CLIPBOARD:
|
||||||
free(msg->set_clipboard.text);
|
free(msg->set_clipboard.text);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -11,40 +11,40 @@
|
|||||||
#include "android/keycodes.h"
|
#include "android/keycodes.h"
|
||||||
#include "coords.h"
|
#include "coords.h"
|
||||||
|
|
||||||
#define CONTROL_MSG_MAX_SIZE (1 << 18) // 256k
|
#define SC_CONTROL_MSG_MAX_SIZE (1 << 18) // 256k
|
||||||
|
|
||||||
#define CONTROL_MSG_INJECT_TEXT_MAX_LENGTH 300
|
#define SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH 300
|
||||||
// type: 1 byte; sequence: 8 bytes; paste flag: 1 byte; length: 4 bytes
|
// type: 1 byte; sequence: 8 bytes; paste flag: 1 byte; length: 4 bytes
|
||||||
#define CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH (CONTROL_MSG_MAX_SIZE - 14)
|
#define SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH (SC_CONTROL_MSG_MAX_SIZE - 14)
|
||||||
|
|
||||||
#define POINTER_ID_MOUSE UINT64_C(-1)
|
#define POINTER_ID_MOUSE UINT64_C(-1)
|
||||||
#define POINTER_ID_VIRTUAL_FINGER UINT64_C(-2)
|
#define POINTER_ID_VIRTUAL_FINGER UINT64_C(-2)
|
||||||
|
|
||||||
enum sc_control_msg_type {
|
enum sc_control_msg_type {
|
||||||
CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
SC_CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
||||||
CONTROL_MSG_TYPE_INJECT_TEXT,
|
SC_CONTROL_MSG_TYPE_INJECT_TEXT,
|
||||||
CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||||
CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
SC_CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
||||||
CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
SC_CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
||||||
CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
SC_CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
||||||
CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
SC_CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
||||||
CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
SC_CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
||||||
CONTROL_MSG_TYPE_GET_CLIPBOARD,
|
SC_CONTROL_MSG_TYPE_GET_CLIPBOARD,
|
||||||
CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
SC_CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
||||||
CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE,
|
SC_CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE,
|
||||||
CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
SC_CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum screen_power_mode {
|
enum sc_screen_power_mode {
|
||||||
// see <https://android.googlesource.com/platform/frameworks/base.git/+/pie-release-2/core/java/android/view/SurfaceControl.java#305>
|
// see <https://android.googlesource.com/platform/frameworks/base.git/+/pie-release-2/core/java/android/view/SurfaceControl.java#305>
|
||||||
SCREEN_POWER_MODE_OFF = 0,
|
SC_SCREEN_POWER_MODE_OFF = 0,
|
||||||
SCREEN_POWER_MODE_NORMAL = 2,
|
SC_SCREEN_POWER_MODE_NORMAL = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum get_clipboard_copy_key {
|
enum sc_copy_key {
|
||||||
GET_CLIPBOARD_COPY_KEY_NONE,
|
SC_COPY_KEY_NONE,
|
||||||
GET_CLIPBOARD_COPY_KEY_COPY,
|
SC_COPY_KEY_COPY,
|
||||||
GET_CLIPBOARD_COPY_KEY_CUT,
|
SC_COPY_KEY_CUT,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sc_control_msg {
|
struct sc_control_msg {
|
||||||
@@ -77,7 +77,7 @@ struct sc_control_msg {
|
|||||||
// screen may only be turned on on ACTION_DOWN
|
// screen may only be turned on on ACTION_DOWN
|
||||||
} back_or_screen_on;
|
} back_or_screen_on;
|
||||||
struct {
|
struct {
|
||||||
enum get_clipboard_copy_key copy_key;
|
enum sc_copy_key copy_key;
|
||||||
} get_clipboard;
|
} get_clipboard;
|
||||||
struct {
|
struct {
|
||||||
uint64_t sequence;
|
uint64_t sequence;
|
||||||
@@ -85,7 +85,7 @@ struct sc_control_msg {
|
|||||||
bool paste;
|
bool paste;
|
||||||
} set_clipboard;
|
} set_clipboard;
|
||||||
struct {
|
struct {
|
||||||
enum screen_power_mode mode;
|
enum sc_screen_power_mode mode;
|
||||||
} set_screen_power_mode;
|
} set_screen_power_mode;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ sc_controller_push_msg(struct sc_controller *controller,
|
|||||||
static bool
|
static bool
|
||||||
process_msg(struct sc_controller *controller,
|
process_msg(struct sc_controller *controller,
|
||||||
const struct sc_control_msg *msg) {
|
const struct sc_control_msg *msg) {
|
||||||
static unsigned char serialized_msg[CONTROL_MSG_MAX_SIZE];
|
static unsigned char serialized_msg[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t length = sc_control_msg_serialize(msg, serialized_msg);
|
size_t length = sc_control_msg_serialize(msg, serialized_msg);
|
||||||
if (!length) {
|
if (!length) {
|
||||||
return false;
|
return false;
|
||||||
@@ -113,7 +113,7 @@ sc_controller_start(struct sc_controller *controller) {
|
|||||||
bool ok = sc_thread_create(&controller->thread, run_controller,
|
bool ok = sc_thread_create(&controller->thread, run_controller,
|
||||||
"scrcpy-ctl", controller);
|
"scrcpy-ctl", controller);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGC("Could not start controller thread");
|
LOGE("Could not start controller thread");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,10 @@
|
|||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
|
|
||||||
/** Downcast packet_sink to decoder */
|
/** Downcast packet_sink to decoder */
|
||||||
#define DOWNCAST(SINK) container_of(SINK, struct decoder, packet_sink)
|
#define DOWNCAST(SINK) container_of(SINK, struct sc_decoder, packet_sink)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
decoder_close_first_sinks(struct decoder *decoder, unsigned count) {
|
sc_decoder_close_first_sinks(struct sc_decoder *decoder, unsigned count) {
|
||||||
while (count) {
|
while (count) {
|
||||||
struct sc_frame_sink *sink = decoder->sinks[--count];
|
struct sc_frame_sink *sink = decoder->sinks[--count];
|
||||||
sink->ops->close(sink);
|
sink->ops->close(sink);
|
||||||
@@ -20,17 +20,17 @@ decoder_close_first_sinks(struct decoder *decoder, unsigned count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
decoder_close_sinks(struct decoder *decoder) {
|
sc_decoder_close_sinks(struct sc_decoder *decoder) {
|
||||||
decoder_close_first_sinks(decoder, decoder->sink_count);
|
sc_decoder_close_first_sinks(decoder, decoder->sink_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
decoder_open_sinks(struct decoder *decoder) {
|
sc_decoder_open_sinks(struct sc_decoder *decoder) {
|
||||||
for (unsigned i = 0; i < decoder->sink_count; ++i) {
|
for (unsigned i = 0; i < decoder->sink_count; ++i) {
|
||||||
struct sc_frame_sink *sink = decoder->sinks[i];
|
struct sc_frame_sink *sink = decoder->sinks[i];
|
||||||
if (!sink->ops->open(sink)) {
|
if (!sink->ops->open(sink)) {
|
||||||
LOGE("Could not open frame sink %d", i);
|
LOGE("Could not open frame sink %d", i);
|
||||||
decoder_close_first_sinks(decoder, i);
|
sc_decoder_close_first_sinks(decoder, i);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ decoder_open_sinks(struct decoder *decoder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
decoder_open(struct decoder *decoder, const AVCodec *codec) {
|
sc_decoder_open(struct sc_decoder *decoder, const AVCodec *codec) {
|
||||||
decoder->codec_ctx = avcodec_alloc_context3(codec);
|
decoder->codec_ctx = avcodec_alloc_context3(codec);
|
||||||
if (!decoder->codec_ctx) {
|
if (!decoder->codec_ctx) {
|
||||||
LOG_OOM();
|
LOG_OOM();
|
||||||
@@ -62,7 +62,7 @@ decoder_open(struct decoder *decoder, const AVCodec *codec) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!decoder_open_sinks(decoder)) {
|
if (!sc_decoder_open_sinks(decoder)) {
|
||||||
LOGE("Could not open decoder sinks");
|
LOGE("Could not open decoder sinks");
|
||||||
av_frame_free(&decoder->frame);
|
av_frame_free(&decoder->frame);
|
||||||
avcodec_close(decoder->codec_ctx);
|
avcodec_close(decoder->codec_ctx);
|
||||||
@@ -74,15 +74,15 @@ decoder_open(struct decoder *decoder, const AVCodec *codec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
decoder_close(struct decoder *decoder) {
|
sc_decoder_close(struct sc_decoder *decoder) {
|
||||||
decoder_close_sinks(decoder);
|
sc_decoder_close_sinks(decoder);
|
||||||
av_frame_free(&decoder->frame);
|
av_frame_free(&decoder->frame);
|
||||||
avcodec_close(decoder->codec_ctx);
|
avcodec_close(decoder->codec_ctx);
|
||||||
avcodec_free_context(&decoder->codec_ctx);
|
avcodec_free_context(&decoder->codec_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
push_frame_to_sinks(struct decoder *decoder, const AVFrame *frame) {
|
push_frame_to_sinks(struct sc_decoder *decoder, const AVFrame *frame) {
|
||||||
for (unsigned i = 0; i < decoder->sink_count; ++i) {
|
for (unsigned i = 0; i < decoder->sink_count; ++i) {
|
||||||
struct sc_frame_sink *sink = decoder->sinks[i];
|
struct sc_frame_sink *sink = decoder->sinks[i];
|
||||||
if (!sink->ops->push(sink, frame)) {
|
if (!sink->ops->push(sink, frame)) {
|
||||||
@@ -95,7 +95,7 @@ push_frame_to_sinks(struct decoder *decoder, const AVFrame *frame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
decoder_push(struct decoder *decoder, const AVPacket *packet) {
|
sc_decoder_push(struct sc_decoder *decoder, const AVPacket *packet) {
|
||||||
bool is_config = packet->pts == AV_NOPTS_VALUE;
|
bool is_config = packet->pts == AV_NOPTS_VALUE;
|
||||||
if (is_config) {
|
if (is_config) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
@@ -124,39 +124,40 @@ decoder_push(struct decoder *decoder, const AVPacket *packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
decoder_packet_sink_open(struct sc_packet_sink *sink, const AVCodec *codec) {
|
sc_decoder_packet_sink_open(struct sc_packet_sink *sink, const AVCodec *codec) {
|
||||||
struct decoder *decoder = DOWNCAST(sink);
|
struct sc_decoder *decoder = DOWNCAST(sink);
|
||||||
return decoder_open(decoder, codec);
|
return sc_decoder_open(decoder, codec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
decoder_packet_sink_close(struct sc_packet_sink *sink) {
|
sc_decoder_packet_sink_close(struct sc_packet_sink *sink) {
|
||||||
struct decoder *decoder = DOWNCAST(sink);
|
struct sc_decoder *decoder = DOWNCAST(sink);
|
||||||
decoder_close(decoder);
|
sc_decoder_close(decoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
decoder_packet_sink_push(struct sc_packet_sink *sink, const AVPacket *packet) {
|
sc_decoder_packet_sink_push(struct sc_packet_sink *sink,
|
||||||
struct decoder *decoder = DOWNCAST(sink);
|
const AVPacket *packet) {
|
||||||
return decoder_push(decoder, packet);
|
struct sc_decoder *decoder = DOWNCAST(sink);
|
||||||
|
return sc_decoder_push(decoder, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
decoder_init(struct decoder *decoder) {
|
sc_decoder_init(struct sc_decoder *decoder) {
|
||||||
decoder->sink_count = 0;
|
decoder->sink_count = 0;
|
||||||
|
|
||||||
static const struct sc_packet_sink_ops ops = {
|
static const struct sc_packet_sink_ops ops = {
|
||||||
.open = decoder_packet_sink_open,
|
.open = sc_decoder_packet_sink_open,
|
||||||
.close = decoder_packet_sink_close,
|
.close = sc_decoder_packet_sink_close,
|
||||||
.push = decoder_packet_sink_push,
|
.push = sc_decoder_packet_sink_push,
|
||||||
};
|
};
|
||||||
|
|
||||||
decoder->packet_sink.ops = &ops;
|
decoder->packet_sink.ops = &ops;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
decoder_add_sink(struct decoder *decoder, struct sc_frame_sink *sink) {
|
sc_decoder_add_sink(struct sc_decoder *decoder, struct sc_frame_sink *sink) {
|
||||||
assert(decoder->sink_count < DECODER_MAX_SINKS);
|
assert(decoder->sink_count < SC_DECODER_MAX_SINKS);
|
||||||
assert(sink);
|
assert(sink);
|
||||||
assert(sink->ops);
|
assert(sink->ops);
|
||||||
decoder->sinks[decoder->sink_count++] = sink;
|
decoder->sinks[decoder->sink_count++] = sink;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef DECODER_H
|
#ifndef SC_DECODER_H
|
||||||
#define DECODER_H
|
#define SC_DECODER_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
@@ -9,12 +9,12 @@
|
|||||||
#include <libavcodec/avcodec.h>
|
#include <libavcodec/avcodec.h>
|
||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
|
|
||||||
#define DECODER_MAX_SINKS 2
|
#define SC_DECODER_MAX_SINKS 2
|
||||||
|
|
||||||
struct decoder {
|
struct sc_decoder {
|
||||||
struct sc_packet_sink packet_sink; // packet sink trait
|
struct sc_packet_sink packet_sink; // packet sink trait
|
||||||
|
|
||||||
struct sc_frame_sink *sinks[DECODER_MAX_SINKS];
|
struct sc_frame_sink *sinks[SC_DECODER_MAX_SINKS];
|
||||||
unsigned sink_count;
|
unsigned sink_count;
|
||||||
|
|
||||||
AVCodecContext *codec_ctx;
|
AVCodecContext *codec_ctx;
|
||||||
@@ -22,9 +22,9 @@ struct decoder {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
decoder_init(struct decoder *decoder);
|
sc_decoder_init(struct sc_decoder *decoder);
|
||||||
|
|
||||||
void
|
void
|
||||||
decoder_add_sink(struct decoder *decoder, struct sc_frame_sink *sink);
|
sc_decoder_add_sink(struct sc_decoder *decoder, struct sc_frame_sink *sink);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "stream.h"
|
#include "demuxer.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <libavutil/time.h>
|
#include <libavutil/time.h>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
#define NO_PTS UINT64_C(-1)
|
#define NO_PTS UINT64_C(-1)
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
stream_recv_packet(struct stream *stream, AVPacket *packet) {
|
sc_demuxer_recv_packet(struct sc_demuxer *demuxer, AVPacket *packet) {
|
||||||
// The video stream contains raw packets, without time information. When we
|
// The video stream contains raw packets, without time information. When we
|
||||||
// record, we retrieve the timestamps separately, from a "meta" header
|
// record, we retrieve the timestamps separately, from a "meta" header
|
||||||
// added by the server before each raw packet.
|
// added by the server before each raw packet.
|
||||||
@@ -30,7 +30,7 @@ stream_recv_packet(struct stream *stream, AVPacket *packet) {
|
|||||||
// It is followed by <packet_size> bytes containing the packet/frame.
|
// It is followed by <packet_size> bytes containing the packet/frame.
|
||||||
|
|
||||||
uint8_t header[HEADER_SIZE];
|
uint8_t header[HEADER_SIZE];
|
||||||
ssize_t r = net_recv_all(stream->socket, header, HEADER_SIZE);
|
ssize_t r = net_recv_all(demuxer->socket, header, HEADER_SIZE);
|
||||||
if (r < HEADER_SIZE) {
|
if (r < HEADER_SIZE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ stream_recv_packet(struct stream *stream, AVPacket *packet) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_recv_all(stream->socket, packet->data, len);
|
r = net_recv_all(demuxer->socket, packet->data, len);
|
||||||
if (r < 0 || ((uint32_t) r) < len) {
|
if (r < 0 || ((uint32_t) r) < len) {
|
||||||
av_packet_unref(packet);
|
av_packet_unref(packet);
|
||||||
return false;
|
return false;
|
||||||
@@ -57,9 +57,9 @@ stream_recv_packet(struct stream *stream, AVPacket *packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
push_packet_to_sinks(struct stream *stream, const AVPacket *packet) {
|
push_packet_to_sinks(struct sc_demuxer *demuxer, const AVPacket *packet) {
|
||||||
for (unsigned i = 0; i < stream->sink_count; ++i) {
|
for (unsigned i = 0; i < demuxer->sink_count; ++i) {
|
||||||
struct sc_packet_sink *sink = stream->sinks[i];
|
struct sc_packet_sink *sink = demuxer->sinks[i];
|
||||||
if (!sink->ops->push(sink, packet)) {
|
if (!sink->ops->push(sink, packet)) {
|
||||||
LOGE("Could not send config packet to sink %d", i);
|
LOGE("Could not send config packet to sink %d", i);
|
||||||
return false;
|
return false;
|
||||||
@@ -69,13 +69,13 @@ push_packet_to_sinks(struct stream *stream, const AVPacket *packet) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static void
|
||||||
stream_parse(struct stream *stream, AVPacket *packet) {
|
sc_demuxer_parse(struct sc_demuxer *demuxer, AVPacket *packet) {
|
||||||
uint8_t *in_data = packet->data;
|
uint8_t *in_data = packet->data;
|
||||||
int in_len = packet->size;
|
int in_len = packet->size;
|
||||||
uint8_t *out_data = NULL;
|
uint8_t *out_data = NULL;
|
||||||
int out_len = 0;
|
int out_len = 0;
|
||||||
int r = av_parser_parse2(stream->parser, stream->codec_ctx,
|
int r = av_parser_parse2(demuxer->parser, demuxer->codec_ctx,
|
||||||
&out_data, &out_len, in_data, in_len,
|
&out_data, &out_len, in_data, in_len,
|
||||||
AV_NOPTS_VALUE, AV_NOPTS_VALUE, -1);
|
AV_NOPTS_VALUE, AV_NOPTS_VALUE, -1);
|
||||||
|
|
||||||
@@ -84,13 +84,64 @@ stream_parse(struct stream *stream, AVPacket *packet) {
|
|||||||
(void) r;
|
(void) r;
|
||||||
assert(out_len == in_len);
|
assert(out_len == in_len);
|
||||||
|
|
||||||
if (stream->parser->key_frame == 1) {
|
if (demuxer->parser->key_frame == 1) {
|
||||||
packet->flags |= AV_PKT_FLAG_KEY;
|
packet->flags |= AV_PKT_FLAG_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
packet->dts = packet->pts;
|
packet->dts = packet->pts;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
sc_demuxer_push_packet(struct sc_demuxer *demuxer, AVPacket *packet) {
|
||||||
|
bool is_config = packet->pts == AV_NOPTS_VALUE;
|
||||||
|
|
||||||
|
// A config packet must not be decoded immediately (it contains no
|
||||||
|
// frame); instead, it must be concatenated with the future data packet.
|
||||||
|
if (demuxer->pending || is_config) {
|
||||||
|
size_t offset;
|
||||||
|
if (demuxer->pending) {
|
||||||
|
offset = demuxer->pending->size;
|
||||||
|
if (av_grow_packet(demuxer->pending, packet->size)) {
|
||||||
|
LOG_OOM();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
offset = 0;
|
||||||
|
demuxer->pending = av_packet_alloc();
|
||||||
|
if (!demuxer->pending) {
|
||||||
|
LOG_OOM();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (av_new_packet(demuxer->pending, packet->size)) {
|
||||||
|
LOG_OOM();
|
||||||
|
av_packet_free(&demuxer->pending);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(demuxer->pending->data + offset, packet->data, packet->size);
|
||||||
|
|
||||||
|
if (!is_config) {
|
||||||
|
// prepare the concat packet to send to the decoder
|
||||||
|
demuxer->pending->pts = packet->pts;
|
||||||
|
demuxer->pending->dts = packet->dts;
|
||||||
|
demuxer->pending->flags = packet->flags;
|
||||||
|
packet = demuxer->pending;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_config) {
|
||||||
|
// data packet
|
||||||
|
sc_demuxer_parse(demuxer, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ok = push_packet_to_sinks(demuxer, packet);
|
||||||
|
|
||||||
|
if (!is_config && demuxer->pending) {
|
||||||
|
// the pending packet must be discarded (consumed or error)
|
||||||
|
av_packet_free(&demuxer->pending);
|
||||||
|
}
|
||||||
|
|
||||||
bool ok = push_packet_to_sinks(stream, packet);
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGE("Could not process packet");
|
LOGE("Could not process packet");
|
||||||
return false;
|
return false;
|
||||||
@@ -99,87 +150,26 @@ stream_parse(struct stream *stream, AVPacket *packet) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
|
||||||
stream_push_packet(struct stream *stream, AVPacket *packet) {
|
|
||||||
bool is_config = packet->pts == AV_NOPTS_VALUE;
|
|
||||||
|
|
||||||
// A config packet must not be decoded immediately (it contains no
|
|
||||||
// frame); instead, it must be concatenated with the future data packet.
|
|
||||||
if (stream->pending || is_config) {
|
|
||||||
size_t offset;
|
|
||||||
if (stream->pending) {
|
|
||||||
offset = stream->pending->size;
|
|
||||||
if (av_grow_packet(stream->pending, packet->size)) {
|
|
||||||
LOG_OOM();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
offset = 0;
|
|
||||||
stream->pending = av_packet_alloc();
|
|
||||||
if (!stream->pending) {
|
|
||||||
LOG_OOM();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (av_new_packet(stream->pending, packet->size)) {
|
|
||||||
LOG_OOM();
|
|
||||||
av_packet_free(&stream->pending);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(stream->pending->data + offset, packet->data, packet->size);
|
|
||||||
|
|
||||||
if (!is_config) {
|
|
||||||
// prepare the concat packet to send to the decoder
|
|
||||||
stream->pending->pts = packet->pts;
|
|
||||||
stream->pending->dts = packet->dts;
|
|
||||||
stream->pending->flags = packet->flags;
|
|
||||||
packet = stream->pending;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_config) {
|
|
||||||
// config packet
|
|
||||||
bool ok = push_packet_to_sinks(stream, packet);
|
|
||||||
if (!ok) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// data packet
|
|
||||||
bool ok = stream_parse(stream, packet);
|
|
||||||
|
|
||||||
if (stream->pending) {
|
|
||||||
// the pending packet must be discarded (consumed or error)
|
|
||||||
av_packet_free(&stream->pending);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
stream_close_first_sinks(struct stream *stream, unsigned count) {
|
sc_demuxer_close_first_sinks(struct sc_demuxer *demuxer, unsigned count) {
|
||||||
while (count) {
|
while (count) {
|
||||||
struct sc_packet_sink *sink = stream->sinks[--count];
|
struct sc_packet_sink *sink = demuxer->sinks[--count];
|
||||||
sink->ops->close(sink);
|
sink->ops->close(sink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
stream_close_sinks(struct stream *stream) {
|
sc_demuxer_close_sinks(struct sc_demuxer *demuxer) {
|
||||||
stream_close_first_sinks(stream, stream->sink_count);
|
sc_demuxer_close_first_sinks(demuxer, demuxer->sink_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
stream_open_sinks(struct stream *stream, const AVCodec *codec) {
|
sc_demuxer_open_sinks(struct sc_demuxer *demuxer, const AVCodec *codec) {
|
||||||
for (unsigned i = 0; i < stream->sink_count; ++i) {
|
for (unsigned i = 0; i < demuxer->sink_count; ++i) {
|
||||||
struct sc_packet_sink *sink = stream->sinks[i];
|
struct sc_packet_sink *sink = demuxer->sinks[i];
|
||||||
if (!sink->ops->open(sink, codec)) {
|
if (!sink->ops->open(sink, codec)) {
|
||||||
LOGE("Could not open packet sink %d", i);
|
LOGE("Could not open packet sink %d", i);
|
||||||
stream_close_first_sinks(stream, i);
|
sc_demuxer_close_first_sinks(demuxer, i);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,8 +178,8 @@ stream_open_sinks(struct stream *stream, const AVCodec *codec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
run_stream(void *data) {
|
run_demuxer(void *data) {
|
||||||
struct stream *stream = data;
|
struct sc_demuxer *demuxer = data;
|
||||||
|
|
||||||
const AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264);
|
const AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264);
|
||||||
if (!codec) {
|
if (!codec) {
|
||||||
@@ -197,26 +187,26 @@ run_stream(void *data) {
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream->codec_ctx = avcodec_alloc_context3(codec);
|
demuxer->codec_ctx = avcodec_alloc_context3(codec);
|
||||||
if (!stream->codec_ctx) {
|
if (!demuxer->codec_ctx) {
|
||||||
LOG_OOM();
|
LOG_OOM();
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stream_open_sinks(stream, codec)) {
|
if (!sc_demuxer_open_sinks(demuxer, codec)) {
|
||||||
LOGE("Could not open stream sinks");
|
LOGE("Could not open demuxer sinks");
|
||||||
goto finally_free_codec_ctx;
|
goto finally_free_codec_ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream->parser = av_parser_init(AV_CODEC_ID_H264);
|
demuxer->parser = av_parser_init(AV_CODEC_ID_H264);
|
||||||
if (!stream->parser) {
|
if (!demuxer->parser) {
|
||||||
LOGE("Could not initialize parser");
|
LOGE("Could not initialize parser");
|
||||||
goto finally_close_sinks;
|
goto finally_close_sinks;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We must only pass complete frames to av_parser_parse2()!
|
// We must only pass complete frames to av_parser_parse2()!
|
||||||
// It's more complicated, but this allows to reduce the latency by 1 frame!
|
// It's more complicated, but this allows to reduce the latency by 1 frame!
|
||||||
stream->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
|
demuxer->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
|
||||||
|
|
||||||
AVPacket *packet = av_packet_alloc();
|
AVPacket *packet = av_packet_alloc();
|
||||||
if (!packet) {
|
if (!packet) {
|
||||||
@@ -225,13 +215,13 @@ run_stream(void *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
bool ok = stream_recv_packet(stream, packet);
|
bool ok = sc_demuxer_recv_packet(demuxer, packet);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
// end of stream
|
// end of stream
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = stream_push_packet(stream, packet);
|
ok = sc_demuxer_push_packet(demuxer, packet);
|
||||||
av_packet_unref(packet);
|
av_packet_unref(packet);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
// cannot process packet (error already logged)
|
// cannot process packet (error already logged)
|
||||||
@@ -241,58 +231,58 @@ run_stream(void *data) {
|
|||||||
|
|
||||||
LOGD("End of frames");
|
LOGD("End of frames");
|
||||||
|
|
||||||
if (stream->pending) {
|
if (demuxer->pending) {
|
||||||
av_packet_free(&stream->pending);
|
av_packet_free(&demuxer->pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
av_packet_free(&packet);
|
av_packet_free(&packet);
|
||||||
finally_close_parser:
|
finally_close_parser:
|
||||||
av_parser_close(stream->parser);
|
av_parser_close(demuxer->parser);
|
||||||
finally_close_sinks:
|
finally_close_sinks:
|
||||||
stream_close_sinks(stream);
|
sc_demuxer_close_sinks(demuxer);
|
||||||
finally_free_codec_ctx:
|
finally_free_codec_ctx:
|
||||||
avcodec_free_context(&stream->codec_ctx);
|
avcodec_free_context(&demuxer->codec_ctx);
|
||||||
end:
|
end:
|
||||||
stream->cbs->on_eos(stream, stream->cbs_userdata);
|
demuxer->cbs->on_eos(demuxer, demuxer->cbs_userdata);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stream_init(struct stream *stream, sc_socket socket,
|
sc_demuxer_init(struct sc_demuxer *demuxer, sc_socket socket,
|
||||||
const struct stream_callbacks *cbs, void *cbs_userdata) {
|
const struct sc_demuxer_callbacks *cbs, void *cbs_userdata) {
|
||||||
stream->socket = socket;
|
demuxer->socket = socket;
|
||||||
stream->pending = NULL;
|
demuxer->pending = NULL;
|
||||||
stream->sink_count = 0;
|
demuxer->sink_count = 0;
|
||||||
|
|
||||||
assert(cbs && cbs->on_eos);
|
assert(cbs && cbs->on_eos);
|
||||||
|
|
||||||
stream->cbs = cbs;
|
demuxer->cbs = cbs;
|
||||||
stream->cbs_userdata = cbs_userdata;
|
demuxer->cbs_userdata = cbs_userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stream_add_sink(struct stream *stream, struct sc_packet_sink *sink) {
|
sc_demuxer_add_sink(struct sc_demuxer *demuxer, struct sc_packet_sink *sink) {
|
||||||
assert(stream->sink_count < STREAM_MAX_SINKS);
|
assert(demuxer->sink_count < SC_DEMUXER_MAX_SINKS);
|
||||||
assert(sink);
|
assert(sink);
|
||||||
assert(sink->ops);
|
assert(sink->ops);
|
||||||
stream->sinks[stream->sink_count++] = sink;
|
demuxer->sinks[demuxer->sink_count++] = sink;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
stream_start(struct stream *stream) {
|
sc_demuxer_start(struct sc_demuxer *demuxer) {
|
||||||
LOGD("Starting stream thread");
|
LOGD("Starting demuxer thread");
|
||||||
|
|
||||||
bool ok =
|
bool ok = sc_thread_create(&demuxer->thread, run_demuxer, "scrcpy-demuxer",
|
||||||
sc_thread_create(&stream->thread, run_stream, "scrcpy-stream", stream);
|
demuxer);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGC("Could not start stream thread");
|
LOGE("Could not start demuxer thread");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stream_join(struct stream *stream) {
|
sc_demuxer_join(struct sc_demuxer *demuxer) {
|
||||||
sc_thread_join(&stream->thread, NULL);
|
sc_thread_join(&demuxer->thread, NULL);
|
||||||
}
|
}
|
||||||
51
app/src/demuxer.h
Normal file
51
app/src/demuxer.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#ifndef SC_DEMUXER_H
|
||||||
|
#define SC_DEMUXER_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <libavcodec/avcodec.h>
|
||||||
|
#include <libavformat/avformat.h>
|
||||||
|
|
||||||
|
#include "trait/packet_sink.h"
|
||||||
|
#include "util/net.h"
|
||||||
|
#include "util/thread.h"
|
||||||
|
|
||||||
|
#define SC_DEMUXER_MAX_SINKS 2
|
||||||
|
|
||||||
|
struct sc_demuxer {
|
||||||
|
sc_socket socket;
|
||||||
|
sc_thread thread;
|
||||||
|
|
||||||
|
struct sc_packet_sink *sinks[SC_DEMUXER_MAX_SINKS];
|
||||||
|
unsigned sink_count;
|
||||||
|
|
||||||
|
AVCodecContext *codec_ctx;
|
||||||
|
AVCodecParserContext *parser;
|
||||||
|
// successive packets may need to be concatenated, until a non-config
|
||||||
|
// packet is available
|
||||||
|
AVPacket *pending;
|
||||||
|
|
||||||
|
const struct sc_demuxer_callbacks *cbs;
|
||||||
|
void *cbs_userdata;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sc_demuxer_callbacks {
|
||||||
|
void (*on_eos)(struct sc_demuxer *demuxer, void *userdata);
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_demuxer_init(struct sc_demuxer *demuxer, sc_socket socket,
|
||||||
|
const struct sc_demuxer_callbacks *cbs, void *cbs_userdata);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_demuxer_add_sink(struct sc_demuxer *demuxer, struct sc_packet_sink *sink);
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_demuxer_start(struct sc_demuxer *demuxer);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_demuxer_join(struct sc_demuxer *demuxer);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -2,3 +2,4 @@
|
|||||||
#define EVENT_STREAM_STOPPED (SDL_USEREVENT + 1)
|
#define EVENT_STREAM_STOPPED (SDL_USEREVENT + 1)
|
||||||
#define EVENT_SERVER_CONNECTION_FAILED (SDL_USEREVENT + 2)
|
#define EVENT_SERVER_CONNECTION_FAILED (SDL_USEREVENT + 2)
|
||||||
#define EVENT_SERVER_CONNECTED (SDL_USEREVENT + 3)
|
#define EVENT_SERVER_CONNECTED (SDL_USEREVENT + 3)
|
||||||
|
#define EVENT_USB_DEVICE_DISCONNECTED (SDL_USEREVENT + 4)
|
||||||
|
|||||||
@@ -1,178 +0,0 @@
|
|||||||
#include "file_handler.h"
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "adb.h"
|
|
||||||
#include "util/log.h"
|
|
||||||
#include "util/process_intr.h"
|
|
||||||
|
|
||||||
#define DEFAULT_PUSH_TARGET "/sdcard/Download/"
|
|
||||||
|
|
||||||
static void
|
|
||||||
file_handler_request_destroy(struct file_handler_request *req) {
|
|
||||||
free(req->file);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
file_handler_init(struct file_handler *file_handler, const char *serial,
|
|
||||||
const char *push_target) {
|
|
||||||
assert(serial);
|
|
||||||
|
|
||||||
cbuf_init(&file_handler->queue);
|
|
||||||
|
|
||||||
bool ok = sc_mutex_init(&file_handler->mutex);
|
|
||||||
if (!ok) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = sc_cond_init(&file_handler->event_cond);
|
|
||||||
if (!ok) {
|
|
||||||
sc_mutex_destroy(&file_handler->mutex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = sc_intr_init(&file_handler->intr);
|
|
||||||
if (!ok) {
|
|
||||||
sc_cond_destroy(&file_handler->event_cond);
|
|
||||||
sc_mutex_destroy(&file_handler->mutex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
file_handler->serial = strdup(serial);
|
|
||||||
if (!file_handler->serial) {
|
|
||||||
LOG_OOM();
|
|
||||||
sc_intr_destroy(&file_handler->intr);
|
|
||||||
sc_cond_destroy(&file_handler->event_cond);
|
|
||||||
sc_mutex_destroy(&file_handler->mutex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// lazy initialization
|
|
||||||
file_handler->initialized = false;
|
|
||||||
|
|
||||||
file_handler->stopped = false;
|
|
||||||
|
|
||||||
file_handler->push_target = push_target ? push_target : DEFAULT_PUSH_TARGET;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
file_handler_destroy(struct file_handler *file_handler) {
|
|
||||||
sc_cond_destroy(&file_handler->event_cond);
|
|
||||||
sc_mutex_destroy(&file_handler->mutex);
|
|
||||||
sc_intr_destroy(&file_handler->intr);
|
|
||||||
free(file_handler->serial);
|
|
||||||
|
|
||||||
struct file_handler_request req;
|
|
||||||
while (cbuf_take(&file_handler->queue, &req)) {
|
|
||||||
file_handler_request_destroy(&req);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
file_handler_request(struct file_handler *file_handler,
|
|
||||||
file_handler_action_t action, char *file) {
|
|
||||||
// start file_handler if it's used for the first time
|
|
||||||
if (!file_handler->initialized) {
|
|
||||||
if (!file_handler_start(file_handler)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
file_handler->initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGI("Request to %s %s", action == ACTION_INSTALL_APK ? "install" : "push",
|
|
||||||
file);
|
|
||||||
struct file_handler_request req = {
|
|
||||||
.action = action,
|
|
||||||
.file = file,
|
|
||||||
};
|
|
||||||
|
|
||||||
sc_mutex_lock(&file_handler->mutex);
|
|
||||||
bool was_empty = cbuf_is_empty(&file_handler->queue);
|
|
||||||
bool res = cbuf_push(&file_handler->queue, req);
|
|
||||||
if (was_empty) {
|
|
||||||
sc_cond_signal(&file_handler->event_cond);
|
|
||||||
}
|
|
||||||
sc_mutex_unlock(&file_handler->mutex);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
run_file_handler(void *data) {
|
|
||||||
struct file_handler *file_handler = data;
|
|
||||||
struct sc_intr *intr = &file_handler->intr;
|
|
||||||
|
|
||||||
const char *serial = file_handler->serial;
|
|
||||||
assert(serial);
|
|
||||||
|
|
||||||
const char *push_target = file_handler->push_target;
|
|
||||||
assert(push_target);
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
sc_mutex_lock(&file_handler->mutex);
|
|
||||||
while (!file_handler->stopped && cbuf_is_empty(&file_handler->queue)) {
|
|
||||||
sc_cond_wait(&file_handler->event_cond, &file_handler->mutex);
|
|
||||||
}
|
|
||||||
if (file_handler->stopped) {
|
|
||||||
// stop immediately, do not process further events
|
|
||||||
sc_mutex_unlock(&file_handler->mutex);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
struct file_handler_request req;
|
|
||||||
bool non_empty = cbuf_take(&file_handler->queue, &req);
|
|
||||||
assert(non_empty);
|
|
||||||
(void) non_empty;
|
|
||||||
sc_mutex_unlock(&file_handler->mutex);
|
|
||||||
|
|
||||||
if (req.action == ACTION_INSTALL_APK) {
|
|
||||||
LOGI("Installing %s...", req.file);
|
|
||||||
bool ok = adb_install(intr, serial, req.file, 0);
|
|
||||||
if (ok) {
|
|
||||||
LOGI("%s successfully installed", req.file);
|
|
||||||
} else {
|
|
||||||
LOGE("Failed to install %s", req.file);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOGI("Pushing %s...", req.file);
|
|
||||||
bool ok = adb_push(intr, serial, req.file, push_target, 0);
|
|
||||||
if (ok) {
|
|
||||||
LOGI("%s successfully pushed to %s", req.file, push_target);
|
|
||||||
} else {
|
|
||||||
LOGE("Failed to push %s to %s", req.file, push_target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file_handler_request_destroy(&req);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
file_handler_start(struct file_handler *file_handler) {
|
|
||||||
LOGD("Starting file_handler thread");
|
|
||||||
|
|
||||||
bool ok = sc_thread_create(&file_handler->thread, run_file_handler,
|
|
||||||
"scrcpy-file", file_handler);
|
|
||||||
if (!ok) {
|
|
||||||
LOGC("Could not start file_handler thread");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
file_handler_stop(struct file_handler *file_handler) {
|
|
||||||
sc_mutex_lock(&file_handler->mutex);
|
|
||||||
file_handler->stopped = true;
|
|
||||||
sc_cond_signal(&file_handler->event_cond);
|
|
||||||
sc_intr_interrupt(&file_handler->intr);
|
|
||||||
sc_mutex_unlock(&file_handler->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
file_handler_join(struct file_handler *file_handler) {
|
|
||||||
sc_thread_join(&file_handler->thread, NULL);
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
#ifndef FILE_HANDLER_H
|
|
||||||
#define FILE_HANDLER_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "adb.h"
|
|
||||||
#include "util/cbuf.h"
|
|
||||||
#include "util/thread.h"
|
|
||||||
#include "util/intr.h"
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
ACTION_INSTALL_APK,
|
|
||||||
ACTION_PUSH_FILE,
|
|
||||||
} file_handler_action_t;
|
|
||||||
|
|
||||||
struct file_handler_request {
|
|
||||||
file_handler_action_t action;
|
|
||||||
char *file;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct file_handler_request_queue CBUF(struct file_handler_request, 16);
|
|
||||||
|
|
||||||
struct file_handler {
|
|
||||||
char *serial;
|
|
||||||
const char *push_target;
|
|
||||||
sc_thread thread;
|
|
||||||
sc_mutex mutex;
|
|
||||||
sc_cond event_cond;
|
|
||||||
bool stopped;
|
|
||||||
bool initialized;
|
|
||||||
struct file_handler_request_queue queue;
|
|
||||||
|
|
||||||
struct sc_intr intr;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool
|
|
||||||
file_handler_init(struct file_handler *file_handler, const char *serial,
|
|
||||||
const char *push_target);
|
|
||||||
|
|
||||||
void
|
|
||||||
file_handler_destroy(struct file_handler *file_handler);
|
|
||||||
|
|
||||||
bool
|
|
||||||
file_handler_start(struct file_handler *file_handler);
|
|
||||||
|
|
||||||
void
|
|
||||||
file_handler_stop(struct file_handler *file_handler);
|
|
||||||
|
|
||||||
void
|
|
||||||
file_handler_join(struct file_handler *file_handler);
|
|
||||||
|
|
||||||
// take ownership of file, and will free() it
|
|
||||||
bool
|
|
||||||
file_handler_request(struct file_handler *file_handler,
|
|
||||||
file_handler_action_t action,
|
|
||||||
char *file);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
178
app/src/file_pusher.c
Normal file
178
app/src/file_pusher.c
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
#include "file_pusher.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "adb/adb.h"
|
||||||
|
#include "util/log.h"
|
||||||
|
#include "util/process_intr.h"
|
||||||
|
|
||||||
|
#define DEFAULT_PUSH_TARGET "/sdcard/Download/"
|
||||||
|
|
||||||
|
static void
|
||||||
|
sc_file_pusher_request_destroy(struct sc_file_pusher_request *req) {
|
||||||
|
free(req->file);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_file_pusher_init(struct sc_file_pusher *fp, const char *serial,
|
||||||
|
const char *push_target) {
|
||||||
|
assert(serial);
|
||||||
|
|
||||||
|
cbuf_init(&fp->queue);
|
||||||
|
|
||||||
|
bool ok = sc_mutex_init(&fp->mutex);
|
||||||
|
if (!ok) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = sc_cond_init(&fp->event_cond);
|
||||||
|
if (!ok) {
|
||||||
|
sc_mutex_destroy(&fp->mutex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = sc_intr_init(&fp->intr);
|
||||||
|
if (!ok) {
|
||||||
|
sc_cond_destroy(&fp->event_cond);
|
||||||
|
sc_mutex_destroy(&fp->mutex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fp->serial = strdup(serial);
|
||||||
|
if (!fp->serial) {
|
||||||
|
LOG_OOM();
|
||||||
|
sc_intr_destroy(&fp->intr);
|
||||||
|
sc_cond_destroy(&fp->event_cond);
|
||||||
|
sc_mutex_destroy(&fp->mutex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// lazy initialization
|
||||||
|
fp->initialized = false;
|
||||||
|
|
||||||
|
fp->stopped = false;
|
||||||
|
|
||||||
|
fp->push_target = push_target ? push_target : DEFAULT_PUSH_TARGET;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_file_pusher_destroy(struct sc_file_pusher *fp) {
|
||||||
|
sc_cond_destroy(&fp->event_cond);
|
||||||
|
sc_mutex_destroy(&fp->mutex);
|
||||||
|
sc_intr_destroy(&fp->intr);
|
||||||
|
free(fp->serial);
|
||||||
|
|
||||||
|
struct sc_file_pusher_request req;
|
||||||
|
while (cbuf_take(&fp->queue, &req)) {
|
||||||
|
sc_file_pusher_request_destroy(&req);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_file_pusher_request(struct sc_file_pusher *fp,
|
||||||
|
enum sc_file_pusher_action action, char *file) {
|
||||||
|
// start file_pusher if it's used for the first time
|
||||||
|
if (!fp->initialized) {
|
||||||
|
if (!sc_file_pusher_start(fp)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fp->initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGI("Request to %s %s", action == SC_FILE_PUSHER_ACTION_INSTALL_APK
|
||||||
|
? "install" : "push",
|
||||||
|
file);
|
||||||
|
struct sc_file_pusher_request req = {
|
||||||
|
.action = action,
|
||||||
|
.file = file,
|
||||||
|
};
|
||||||
|
|
||||||
|
sc_mutex_lock(&fp->mutex);
|
||||||
|
bool was_empty = cbuf_is_empty(&fp->queue);
|
||||||
|
bool res = cbuf_push(&fp->queue, req);
|
||||||
|
if (was_empty) {
|
||||||
|
sc_cond_signal(&fp->event_cond);
|
||||||
|
}
|
||||||
|
sc_mutex_unlock(&fp->mutex);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
run_file_pusher(void *data) {
|
||||||
|
struct sc_file_pusher *fp = data;
|
||||||
|
struct sc_intr *intr = &fp->intr;
|
||||||
|
|
||||||
|
const char *serial = fp->serial;
|
||||||
|
assert(serial);
|
||||||
|
|
||||||
|
const char *push_target = fp->push_target;
|
||||||
|
assert(push_target);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
sc_mutex_lock(&fp->mutex);
|
||||||
|
while (!fp->stopped && cbuf_is_empty(&fp->queue)) {
|
||||||
|
sc_cond_wait(&fp->event_cond, &fp->mutex);
|
||||||
|
}
|
||||||
|
if (fp->stopped) {
|
||||||
|
// stop immediately, do not process further events
|
||||||
|
sc_mutex_unlock(&fp->mutex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
struct sc_file_pusher_request req;
|
||||||
|
bool non_empty = cbuf_take(&fp->queue, &req);
|
||||||
|
assert(non_empty);
|
||||||
|
(void) non_empty;
|
||||||
|
sc_mutex_unlock(&fp->mutex);
|
||||||
|
|
||||||
|
if (req.action == SC_FILE_PUSHER_ACTION_INSTALL_APK) {
|
||||||
|
LOGI("Installing %s...", req.file);
|
||||||
|
bool ok = sc_adb_install(intr, serial, req.file, 0);
|
||||||
|
if (ok) {
|
||||||
|
LOGI("%s successfully installed", req.file);
|
||||||
|
} else {
|
||||||
|
LOGE("Failed to install %s", req.file);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGI("Pushing %s...", req.file);
|
||||||
|
bool ok = sc_adb_push(intr, serial, req.file, push_target, 0);
|
||||||
|
if (ok) {
|
||||||
|
LOGI("%s successfully pushed to %s", req.file, push_target);
|
||||||
|
} else {
|
||||||
|
LOGE("Failed to push %s to %s", req.file, push_target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sc_file_pusher_request_destroy(&req);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_file_pusher_start(struct sc_file_pusher *fp) {
|
||||||
|
LOGD("Starting file_pusher thread");
|
||||||
|
|
||||||
|
bool ok = sc_thread_create(&fp->thread, run_file_pusher, "scrcpy-file", fp);
|
||||||
|
if (!ok) {
|
||||||
|
LOGE("Could not start file_pusher thread");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_file_pusher_stop(struct sc_file_pusher *fp) {
|
||||||
|
sc_mutex_lock(&fp->mutex);
|
||||||
|
fp->stopped = true;
|
||||||
|
sc_cond_signal(&fp->event_cond);
|
||||||
|
sc_intr_interrupt(&fp->intr);
|
||||||
|
sc_mutex_unlock(&fp->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_file_pusher_join(struct sc_file_pusher *fp) {
|
||||||
|
sc_thread_join(&fp->thread, NULL);
|
||||||
|
}
|
||||||
58
app/src/file_pusher.h
Normal file
58
app/src/file_pusher.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#ifndef SC_FILE_PUSHER_H
|
||||||
|
#define SC_FILE_PUSHER_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "util/cbuf.h"
|
||||||
|
#include "util/thread.h"
|
||||||
|
#include "util/intr.h"
|
||||||
|
|
||||||
|
enum sc_file_pusher_action {
|
||||||
|
SC_FILE_PUSHER_ACTION_INSTALL_APK,
|
||||||
|
SC_FILE_PUSHER_ACTION_PUSH_FILE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sc_file_pusher_request {
|
||||||
|
enum sc_file_pusher_action action;
|
||||||
|
char *file;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sc_file_pusher_request_queue CBUF(struct sc_file_pusher_request, 16);
|
||||||
|
|
||||||
|
struct sc_file_pusher {
|
||||||
|
char *serial;
|
||||||
|
const char *push_target;
|
||||||
|
sc_thread thread;
|
||||||
|
sc_mutex mutex;
|
||||||
|
sc_cond event_cond;
|
||||||
|
bool stopped;
|
||||||
|
bool initialized;
|
||||||
|
struct sc_file_pusher_request_queue queue;
|
||||||
|
|
||||||
|
struct sc_intr intr;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_file_pusher_init(struct sc_file_pusher *fp, const char *serial,
|
||||||
|
const char *push_target);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_file_pusher_destroy(struct sc_file_pusher *fp);
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_file_pusher_start(struct sc_file_pusher *fp);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_file_pusher_stop(struct sc_file_pusher *fp);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_file_pusher_join(struct sc_file_pusher *fp);
|
||||||
|
|
||||||
|
// take ownership of file, and will free() it
|
||||||
|
bool
|
||||||
|
sc_file_pusher_request(struct sc_file_pusher *fp,
|
||||||
|
enum sc_file_pusher_action action, char *file);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -51,8 +51,6 @@ swap_frames(AVFrame **lhs, AVFrame **rhs) {
|
|||||||
bool
|
bool
|
||||||
sc_frame_buffer_push(struct sc_frame_buffer *fb, const AVFrame *frame,
|
sc_frame_buffer_push(struct sc_frame_buffer *fb, const AVFrame *frame,
|
||||||
bool *previous_frame_skipped) {
|
bool *previous_frame_skipped) {
|
||||||
sc_mutex_lock(&fb->mutex);
|
|
||||||
|
|
||||||
// Use a temporary frame to preserve pending_frame in case of error.
|
// Use a temporary frame to preserve pending_frame in case of error.
|
||||||
// tmp_frame is an empty frame, no need to call av_frame_unref() beforehand.
|
// tmp_frame is an empty frame, no need to call av_frame_unref() beforehand.
|
||||||
int r = av_frame_ref(fb->tmp_frame, frame);
|
int r = av_frame_ref(fb->tmp_frame, frame);
|
||||||
@@ -61,6 +59,8 @@ sc_frame_buffer_push(struct sc_frame_buffer *fb, const AVFrame *frame,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sc_mutex_lock(&fb->mutex);
|
||||||
|
|
||||||
// Now that av_frame_ref() succeeded, we can replace the previous
|
// Now that av_frame_ref() succeeded, we can replace the previous
|
||||||
// pending_frame
|
// pending_frame
|
||||||
swap_frames(&fb->pending_frame, &fb->tmp_frame);
|
swap_frames(&fb->pending_frame, &fb->tmp_frame);
|
||||||
|
|||||||
@@ -377,4 +377,76 @@ struct sc_touch_event {
|
|||||||
float pressure;
|
float pressure;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline uint16_t
|
||||||
|
sc_mods_state_from_sdl(uint16_t mods_state) {
|
||||||
|
return mods_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline enum sc_keycode
|
||||||
|
sc_keycode_from_sdl(SDL_Keycode keycode) {
|
||||||
|
return (enum sc_keycode) keycode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline enum sc_scancode
|
||||||
|
sc_scancode_from_sdl(SDL_Scancode scancode) {
|
||||||
|
return (enum sc_scancode) scancode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline enum sc_action
|
||||||
|
sc_action_from_sdl_keyboard_type(uint32_t type) {
|
||||||
|
assert(type == SDL_KEYDOWN || type == SDL_KEYUP);
|
||||||
|
if (type == SDL_KEYDOWN) {
|
||||||
|
return SC_ACTION_DOWN;
|
||||||
|
}
|
||||||
|
return SC_ACTION_UP;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline enum sc_action
|
||||||
|
sc_action_from_sdl_mousebutton_type(uint32_t type) {
|
||||||
|
assert(type == SDL_MOUSEBUTTONDOWN || type == SDL_MOUSEBUTTONUP);
|
||||||
|
if (type == SDL_MOUSEBUTTONDOWN) {
|
||||||
|
return SC_ACTION_DOWN;
|
||||||
|
}
|
||||||
|
return SC_ACTION_UP;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline enum sc_touch_action
|
||||||
|
sc_touch_action_from_sdl(uint32_t type) {
|
||||||
|
assert(type == SDL_FINGERMOTION || type == SDL_FINGERDOWN ||
|
||||||
|
type == SDL_FINGERUP);
|
||||||
|
if (type == SDL_FINGERMOTION) {
|
||||||
|
return SC_TOUCH_ACTION_MOVE;
|
||||||
|
}
|
||||||
|
if (type == SDL_FINGERDOWN) {
|
||||||
|
return SC_TOUCH_ACTION_DOWN;
|
||||||
|
}
|
||||||
|
return SC_TOUCH_ACTION_UP;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline enum sc_mouse_button
|
||||||
|
sc_mouse_button_from_sdl(uint8_t button) {
|
||||||
|
if (button >= SDL_BUTTON_LEFT && button <= SDL_BUTTON_X2) {
|
||||||
|
// SC_MOUSE_BUTTON_* constants are initialized from SDL_BUTTON(index)
|
||||||
|
return SDL_BUTTON(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SC_MOUSE_BUTTON_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint8_t
|
||||||
|
sc_mouse_buttons_state_from_sdl(uint32_t buttons_state,
|
||||||
|
bool forward_all_clicks) {
|
||||||
|
assert(buttons_state < 0x100); // fits in uint8_t
|
||||||
|
|
||||||
|
uint8_t mask = SC_MOUSE_BUTTON_LEFT;
|
||||||
|
if (forward_all_clicks) {
|
||||||
|
mask |= SC_MOUSE_BUTTON_RIGHT
|
||||||
|
| SC_MOUSE_BUTTON_MIDDLE
|
||||||
|
| SC_MOUSE_BUTTON_X1
|
||||||
|
| SC_MOUSE_BUTTON_X2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buttons_state & mask;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,78 +7,6 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
|
|
||||||
static inline uint16_t
|
|
||||||
sc_mods_state_from_sdl(uint16_t mods_state) {
|
|
||||||
return mods_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline enum sc_keycode
|
|
||||||
sc_keycode_from_sdl(SDL_Keycode keycode) {
|
|
||||||
return (enum sc_keycode) keycode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline enum sc_scancode
|
|
||||||
sc_scancode_from_sdl(SDL_Scancode scancode) {
|
|
||||||
return (enum sc_scancode) scancode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline enum sc_action
|
|
||||||
sc_action_from_sdl_keyboard_type(uint32_t type) {
|
|
||||||
assert(type == SDL_KEYDOWN || type == SDL_KEYUP);
|
|
||||||
if (type == SDL_KEYDOWN) {
|
|
||||||
return SC_ACTION_DOWN;
|
|
||||||
}
|
|
||||||
return SC_ACTION_UP;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline enum sc_action
|
|
||||||
sc_action_from_sdl_mousebutton_type(uint32_t type) {
|
|
||||||
assert(type == SDL_MOUSEBUTTONDOWN || type == SDL_MOUSEBUTTONUP);
|
|
||||||
if (type == SDL_MOUSEBUTTONDOWN) {
|
|
||||||
return SC_ACTION_DOWN;
|
|
||||||
}
|
|
||||||
return SC_ACTION_UP;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline enum sc_touch_action
|
|
||||||
sc_touch_action_from_sdl(uint32_t type) {
|
|
||||||
assert(type == SDL_FINGERMOTION || type == SDL_FINGERDOWN ||
|
|
||||||
type == SDL_FINGERUP);
|
|
||||||
if (type == SDL_FINGERMOTION) {
|
|
||||||
return SC_TOUCH_ACTION_MOVE;
|
|
||||||
}
|
|
||||||
if (type == SDL_FINGERDOWN) {
|
|
||||||
return SC_TOUCH_ACTION_DOWN;
|
|
||||||
}
|
|
||||||
return SC_TOUCH_ACTION_UP;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline enum sc_mouse_button
|
|
||||||
sc_mouse_button_from_sdl(uint8_t button) {
|
|
||||||
if (button >= SDL_BUTTON_LEFT && button <= SDL_BUTTON_X2) {
|
|
||||||
// SC_MOUSE_BUTTON_* constants are initialized from SDL_BUTTON(index)
|
|
||||||
return SDL_BUTTON(button);
|
|
||||||
}
|
|
||||||
|
|
||||||
return SC_MOUSE_BUTTON_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint8_t
|
|
||||||
sc_mouse_buttons_state_from_sdl(uint32_t buttons_state,
|
|
||||||
bool forward_all_clicks) {
|
|
||||||
assert(buttons_state < 0x100); // fits in uint8_t
|
|
||||||
|
|
||||||
uint8_t mask = SC_MOUSE_BUTTON_LEFT;
|
|
||||||
if (forward_all_clicks) {
|
|
||||||
mask |= SC_MOUSE_BUTTON_RIGHT
|
|
||||||
| SC_MOUSE_BUTTON_MIDDLE
|
|
||||||
| SC_MOUSE_BUTTON_X1
|
|
||||||
| SC_MOUSE_BUTTON_X2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return buttons_state & mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SC_SDL_SHORTCUT_MODS_MASK (KMOD_CTRL | KMOD_ALT | KMOD_GUI)
|
#define SC_SDL_SHORTCUT_MODS_MASK (KMOD_CTRL | KMOD_ALT | KMOD_GUI)
|
||||||
|
|
||||||
static inline uint16_t
|
static inline uint16_t
|
||||||
@@ -124,15 +52,15 @@ is_shortcut_mod(struct sc_input_manager *im, uint16_t sdl_mod) {
|
|||||||
void
|
void
|
||||||
sc_input_manager_init(struct sc_input_manager *im,
|
sc_input_manager_init(struct sc_input_manager *im,
|
||||||
const struct sc_input_manager_params *params) {
|
const struct sc_input_manager_params *params) {
|
||||||
assert(!params->control || (params->kp && params->kp->ops));
|
assert(!params->controller || (params->kp && params->kp->ops));
|
||||||
assert(!params->control || (params->mp && params->mp->ops));
|
assert(!params->controller || (params->mp && params->mp->ops));
|
||||||
|
|
||||||
im->controller = params->controller;
|
im->controller = params->controller;
|
||||||
|
im->fp = params->fp;
|
||||||
im->screen = params->screen;
|
im->screen = params->screen;
|
||||||
im->kp = params->kp;
|
im->kp = params->kp;
|
||||||
im->mp = params->mp;
|
im->mp = params->mp;
|
||||||
|
|
||||||
im->control = params->control;
|
|
||||||
im->forward_all_clicks = params->forward_all_clicks;
|
im->forward_all_clicks = params->forward_all_clicks;
|
||||||
im->legacy_paste = params->legacy_paste;
|
im->legacy_paste = params->legacy_paste;
|
||||||
im->clipboard_autosync = params->clipboard_autosync;
|
im->clipboard_autosync = params->clipboard_autosync;
|
||||||
@@ -161,7 +89,7 @@ send_keycode(struct sc_controller *controller, enum android_keycode keycode,
|
|||||||
enum sc_action action, const char *name) {
|
enum sc_action action, const char *name) {
|
||||||
// send DOWN event
|
// send DOWN event
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
msg.type = SC_CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
||||||
msg.inject_keycode.action = action == SC_ACTION_DOWN
|
msg.inject_keycode.action = action == SC_ACTION_DOWN
|
||||||
? AKEY_EVENT_ACTION_DOWN
|
? AKEY_EVENT_ACTION_DOWN
|
||||||
: AKEY_EVENT_ACTION_UP;
|
: AKEY_EVENT_ACTION_UP;
|
||||||
@@ -215,7 +143,7 @@ static void
|
|||||||
press_back_or_turn_screen_on(struct sc_controller *controller,
|
press_back_or_turn_screen_on(struct sc_controller *controller,
|
||||||
enum sc_action action) {
|
enum sc_action action) {
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON;
|
msg.type = SC_CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON;
|
||||||
msg.back_or_screen_on.action = action == SC_ACTION_DOWN
|
msg.back_or_screen_on.action = action == SC_ACTION_DOWN
|
||||||
? AKEY_EVENT_ACTION_DOWN
|
? AKEY_EVENT_ACTION_DOWN
|
||||||
: AKEY_EVENT_ACTION_UP;
|
: AKEY_EVENT_ACTION_UP;
|
||||||
@@ -228,7 +156,7 @@ press_back_or_turn_screen_on(struct sc_controller *controller,
|
|||||||
static void
|
static void
|
||||||
expand_notification_panel(struct sc_controller *controller) {
|
expand_notification_panel(struct sc_controller *controller) {
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL;
|
msg.type = SC_CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL;
|
||||||
|
|
||||||
if (!sc_controller_push_msg(controller, &msg)) {
|
if (!sc_controller_push_msg(controller, &msg)) {
|
||||||
LOGW("Could not request 'expand notification panel'");
|
LOGW("Could not request 'expand notification panel'");
|
||||||
@@ -238,7 +166,7 @@ expand_notification_panel(struct sc_controller *controller) {
|
|||||||
static void
|
static void
|
||||||
expand_settings_panel(struct sc_controller *controller) {
|
expand_settings_panel(struct sc_controller *controller) {
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL;
|
msg.type = SC_CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL;
|
||||||
|
|
||||||
if (!sc_controller_push_msg(controller, &msg)) {
|
if (!sc_controller_push_msg(controller, &msg)) {
|
||||||
LOGW("Could not request 'expand settings panel'");
|
LOGW("Could not request 'expand settings panel'");
|
||||||
@@ -248,7 +176,7 @@ expand_settings_panel(struct sc_controller *controller) {
|
|||||||
static void
|
static void
|
||||||
collapse_panels(struct sc_controller *controller) {
|
collapse_panels(struct sc_controller *controller) {
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_COLLAPSE_PANELS;
|
msg.type = SC_CONTROL_MSG_TYPE_COLLAPSE_PANELS;
|
||||||
|
|
||||||
if (!sc_controller_push_msg(controller, &msg)) {
|
if (!sc_controller_push_msg(controller, &msg)) {
|
||||||
LOGW("Could not request 'collapse notification panel'");
|
LOGW("Could not request 'collapse notification panel'");
|
||||||
@@ -257,9 +185,9 @@ collapse_panels(struct sc_controller *controller) {
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
get_device_clipboard(struct sc_controller *controller,
|
get_device_clipboard(struct sc_controller *controller,
|
||||||
enum get_clipboard_copy_key copy_key) {
|
enum sc_copy_key copy_key) {
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_GET_CLIPBOARD;
|
msg.type = SC_CONTROL_MSG_TYPE_GET_CLIPBOARD;
|
||||||
msg.get_clipboard.copy_key = copy_key;
|
msg.get_clipboard.copy_key = copy_key;
|
||||||
|
|
||||||
if (!sc_controller_push_msg(controller, &msg)) {
|
if (!sc_controller_push_msg(controller, &msg)) {
|
||||||
@@ -287,7 +215,7 @@ set_device_clipboard(struct sc_controller *controller, bool paste,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_SET_CLIPBOARD;
|
msg.type = SC_CONTROL_MSG_TYPE_SET_CLIPBOARD;
|
||||||
msg.set_clipboard.sequence = sequence;
|
msg.set_clipboard.sequence = sequence;
|
||||||
msg.set_clipboard.text = text_dup;
|
msg.set_clipboard.text = text_dup;
|
||||||
msg.set_clipboard.paste = paste;
|
msg.set_clipboard.paste = paste;
|
||||||
@@ -303,9 +231,9 @@ set_device_clipboard(struct sc_controller *controller, bool paste,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
set_screen_power_mode(struct sc_controller *controller,
|
set_screen_power_mode(struct sc_controller *controller,
|
||||||
enum screen_power_mode mode) {
|
enum sc_screen_power_mode mode) {
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
|
msg.type = SC_CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
|
||||||
msg.set_screen_power_mode.mode = mode;
|
msg.set_screen_power_mode.mode = mode;
|
||||||
|
|
||||||
if (!sc_controller_push_msg(controller, &msg)) {
|
if (!sc_controller_push_msg(controller, &msg)) {
|
||||||
@@ -350,7 +278,7 @@ clipboard_paste(struct sc_controller *controller) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_INJECT_TEXT;
|
msg.type = SC_CONTROL_MSG_TYPE_INJECT_TEXT;
|
||||||
msg.inject_text.text = text_dup;
|
msg.inject_text.text = text_dup;
|
||||||
if (!sc_controller_push_msg(controller, &msg)) {
|
if (!sc_controller_push_msg(controller, &msg)) {
|
||||||
free(text_dup);
|
free(text_dup);
|
||||||
@@ -361,7 +289,7 @@ clipboard_paste(struct sc_controller *controller) {
|
|||||||
static void
|
static void
|
||||||
rotate_device(struct sc_controller *controller) {
|
rotate_device(struct sc_controller *controller) {
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_ROTATE_DEVICE;
|
msg.type = SC_CONTROL_MSG_TYPE_ROTATE_DEVICE;
|
||||||
|
|
||||||
if (!sc_controller_push_msg(controller, &msg)) {
|
if (!sc_controller_push_msg(controller, &msg)) {
|
||||||
LOGW("Could not request device rotation");
|
LOGW("Could not request device rotation");
|
||||||
@@ -407,7 +335,7 @@ simulate_virtual_finger(struct sc_input_manager *im,
|
|||||||
bool up = action == AMOTION_EVENT_ACTION_UP;
|
bool up = action == AMOTION_EVENT_ACTION_UP;
|
||||||
|
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
msg.type = SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
||||||
msg.inject_touch_event.action = action;
|
msg.inject_touch_event.action = action;
|
||||||
msg.inject_touch_event.position.screen_size = im->screen->frame_size;
|
msg.inject_touch_event.position.screen_size = im->screen->frame_size;
|
||||||
msg.inject_touch_event.position.point = point;
|
msg.inject_touch_event.position.point = point;
|
||||||
@@ -433,9 +361,7 @@ inverse_point(struct sc_point point, struct sc_size size) {
|
|||||||
static void
|
static void
|
||||||
sc_input_manager_process_key(struct sc_input_manager *im,
|
sc_input_manager_process_key(struct sc_input_manager *im,
|
||||||
const SDL_KeyboardEvent *event) {
|
const SDL_KeyboardEvent *event) {
|
||||||
// control: indicates the state of the command-line option --no-control
|
// controller is NULL if --no-control is requested
|
||||||
bool control = im->control;
|
|
||||||
|
|
||||||
struct sc_controller *controller = im->controller;
|
struct sc_controller *controller = im->controller;
|
||||||
|
|
||||||
SDL_Keycode keycode = event->keysym.sym;
|
SDL_Keycode keycode = event->keysym.sym;
|
||||||
@@ -462,47 +388,47 @@ sc_input_manager_process_key(struct sc_input_manager *im,
|
|||||||
enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP;
|
enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP;
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case SDLK_h:
|
case SDLK_h:
|
||||||
if (control && !shift && !repeat) {
|
if (controller && !shift && !repeat) {
|
||||||
action_home(controller, action);
|
action_home(controller, action);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_b: // fall-through
|
case SDLK_b: // fall-through
|
||||||
case SDLK_BACKSPACE:
|
case SDLK_BACKSPACE:
|
||||||
if (control && !shift && !repeat) {
|
if (controller && !shift && !repeat) {
|
||||||
action_back(controller, action);
|
action_back(controller, action);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_s:
|
case SDLK_s:
|
||||||
if (control && !shift && !repeat) {
|
if (controller && !shift && !repeat) {
|
||||||
action_app_switch(controller, action);
|
action_app_switch(controller, action);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_m:
|
case SDLK_m:
|
||||||
if (control && !shift && !repeat) {
|
if (controller && !shift && !repeat) {
|
||||||
action_menu(controller, action);
|
action_menu(controller, action);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_p:
|
case SDLK_p:
|
||||||
if (control && !shift && !repeat) {
|
if (controller && !shift && !repeat) {
|
||||||
action_power(controller, action);
|
action_power(controller, action);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_o:
|
case SDLK_o:
|
||||||
if (control && !repeat && down) {
|
if (controller && !repeat && down) {
|
||||||
enum screen_power_mode mode = shift
|
enum sc_screen_power_mode mode = shift
|
||||||
? SCREEN_POWER_MODE_NORMAL
|
? SC_SCREEN_POWER_MODE_NORMAL
|
||||||
: SCREEN_POWER_MODE_OFF;
|
: SC_SCREEN_POWER_MODE_OFF;
|
||||||
set_screen_power_mode(controller, mode);
|
set_screen_power_mode(controller, mode);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_DOWN:
|
case SDLK_DOWN:
|
||||||
if (control && !shift) {
|
if (controller && !shift) {
|
||||||
// forward repeated events
|
// forward repeated events
|
||||||
action_volume_down(controller, action);
|
action_volume_down(controller, action);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_UP:
|
case SDLK_UP:
|
||||||
if (control && !shift) {
|
if (controller && !shift) {
|
||||||
// forward repeated events
|
// forward repeated events
|
||||||
action_volume_up(controller, action);
|
action_volume_up(controller, action);
|
||||||
}
|
}
|
||||||
@@ -518,19 +444,17 @@ sc_input_manager_process_key(struct sc_input_manager *im,
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_c:
|
case SDLK_c:
|
||||||
if (control && !shift && !repeat && down) {
|
if (controller && !shift && !repeat && down) {
|
||||||
get_device_clipboard(controller,
|
get_device_clipboard(controller, SC_COPY_KEY_COPY);
|
||||||
GET_CLIPBOARD_COPY_KEY_COPY);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_x:
|
case SDLK_x:
|
||||||
if (control && !shift && !repeat && down) {
|
if (controller && !shift && !repeat && down) {
|
||||||
get_device_clipboard(controller,
|
get_device_clipboard(controller, SC_COPY_KEY_CUT);
|
||||||
GET_CLIPBOARD_COPY_KEY_CUT);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_v:
|
case SDLK_v:
|
||||||
if (control && !repeat && down) {
|
if (controller && !repeat && down) {
|
||||||
if (shift || im->legacy_paste) {
|
if (shift || im->legacy_paste) {
|
||||||
// inject the text as input events
|
// inject the text as input events
|
||||||
clipboard_paste(controller);
|
clipboard_paste(controller);
|
||||||
@@ -563,7 +487,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_n:
|
case SDLK_n:
|
||||||
if (control && !repeat && down) {
|
if (controller && !repeat && down) {
|
||||||
if (shift) {
|
if (shift) {
|
||||||
collapse_panels(controller);
|
collapse_panels(controller);
|
||||||
} else if (im->key_repeat == 0) {
|
} else if (im->key_repeat == 0) {
|
||||||
@@ -574,7 +498,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case SDLK_r:
|
case SDLK_r:
|
||||||
if (control && !shift && !repeat && down) {
|
if (controller && !shift && !repeat && down) {
|
||||||
rotate_device(controller);
|
rotate_device(controller);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -583,7 +507,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!control) {
|
if (!controller) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,7 +624,7 @@ sc_input_manager_process_touch(struct sc_input_manager *im,
|
|||||||
static void
|
static void
|
||||||
sc_input_manager_process_mouse_button(struct sc_input_manager *im,
|
sc_input_manager_process_mouse_button(struct sc_input_manager *im,
|
||||||
const SDL_MouseButtonEvent *event) {
|
const SDL_MouseButtonEvent *event) {
|
||||||
bool control = im->control;
|
struct sc_controller *controller = im->controller;
|
||||||
|
|
||||||
if (event->which == SDL_TOUCH_MOUSEID) {
|
if (event->which == SDL_TOUCH_MOUSEID) {
|
||||||
// simulated from touch events, so it's a duplicate
|
// simulated from touch events, so it's a duplicate
|
||||||
@@ -709,28 +633,30 @@ sc_input_manager_process_mouse_button(struct sc_input_manager *im,
|
|||||||
|
|
||||||
bool down = event->type == SDL_MOUSEBUTTONDOWN;
|
bool down = event->type == SDL_MOUSEBUTTONDOWN;
|
||||||
if (!im->forward_all_clicks) {
|
if (!im->forward_all_clicks) {
|
||||||
|
if (controller) {
|
||||||
enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP;
|
enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP;
|
||||||
|
|
||||||
if (control && event->button == SDL_BUTTON_X1) {
|
if (event->button == SDL_BUTTON_X1) {
|
||||||
action_app_switch(im->controller, action);
|
action_app_switch(controller, action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (control && event->button == SDL_BUTTON_X2 && down) {
|
if (event->button == SDL_BUTTON_X2 && down) {
|
||||||
if (event->clicks < 2) {
|
if (event->clicks < 2) {
|
||||||
expand_notification_panel(im->controller);
|
expand_notification_panel(controller);
|
||||||
} else {
|
} else {
|
||||||
expand_settings_panel(im->controller);
|
expand_settings_panel(controller);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (control && event->button == SDL_BUTTON_RIGHT) {
|
if (event->button == SDL_BUTTON_RIGHT) {
|
||||||
press_back_or_turn_screen_on(im->controller, action);
|
press_back_or_turn_screen_on(controller, action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (control && event->button == SDL_BUTTON_MIDDLE) {
|
if (event->button == SDL_BUTTON_MIDDLE) {
|
||||||
action_home(im->controller, action);
|
action_home(controller, action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// double-click on black borders resize to fit the device screen
|
// double-click on black borders resize to fit the device screen
|
||||||
if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) {
|
if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) {
|
||||||
@@ -750,7 +676,7 @@ sc_input_manager_process_mouse_button(struct sc_input_manager *im,
|
|||||||
// otherwise, send the click event to the device
|
// otherwise, send the click event to the device
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!control) {
|
if (!controller) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -834,45 +760,81 @@ sc_input_manager_process_mouse_wheel(struct sc_input_manager *im,
|
|||||||
im->mp->ops->process_mouse_scroll(im->mp, &evt);
|
im->mp->ops->process_mouse_scroll(im->mp, &evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
static bool
|
||||||
|
is_apk(const char *file) {
|
||||||
|
const char *ext = strrchr(file, '.');
|
||||||
|
return ext && !strcmp(ext, ".apk");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sc_input_manager_process_file(struct sc_input_manager *im,
|
||||||
|
const SDL_DropEvent *event) {
|
||||||
|
char *file = strdup(event->file);
|
||||||
|
SDL_free(event->file);
|
||||||
|
if (!file) {
|
||||||
|
LOG_OOM();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum sc_file_pusher_action action;
|
||||||
|
if (is_apk(file)) {
|
||||||
|
action = SC_FILE_PUSHER_ACTION_INSTALL_APK;
|
||||||
|
} else {
|
||||||
|
action = SC_FILE_PUSHER_ACTION_PUSH_FILE;
|
||||||
|
}
|
||||||
|
bool ok = sc_file_pusher_request(im->fp, action, file);
|
||||||
|
if (!ok) {
|
||||||
|
free(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
sc_input_manager_handle_event(struct sc_input_manager *im, SDL_Event *event) {
|
sc_input_manager_handle_event(struct sc_input_manager *im, SDL_Event *event) {
|
||||||
|
bool control = im->controller;
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case SDL_TEXTINPUT:
|
case SDL_TEXTINPUT:
|
||||||
if (!im->control) {
|
if (!control) {
|
||||||
return true;
|
break;
|
||||||
}
|
}
|
||||||
sc_input_manager_process_text_input(im, &event->text);
|
sc_input_manager_process_text_input(im, &event->text);
|
||||||
return true;
|
break;
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
// some key events do not interact with the device, so process the
|
// some key events do not interact with the device, so process the
|
||||||
// event even if control is disabled
|
// event even if control is disabled
|
||||||
sc_input_manager_process_key(im, &event->key);
|
sc_input_manager_process_key(im, &event->key);
|
||||||
return true;
|
break;
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
if (!im->control) {
|
if (!control) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sc_input_manager_process_mouse_motion(im, &event->motion);
|
sc_input_manager_process_mouse_motion(im, &event->motion);
|
||||||
return true;
|
break;
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
if (!im->control) {
|
if (!control) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sc_input_manager_process_mouse_wheel(im, &event->wheel);
|
sc_input_manager_process_mouse_wheel(im, &event->wheel);
|
||||||
return true;
|
break;
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
// some mouse events do not interact with the device, so process
|
// some mouse events do not interact with the device, so process
|
||||||
// the event even if control is disabled
|
// the event even if control is disabled
|
||||||
sc_input_manager_process_mouse_button(im, &event->button);
|
sc_input_manager_process_mouse_button(im, &event->button);
|
||||||
return true;
|
break;
|
||||||
case SDL_FINGERMOTION:
|
case SDL_FINGERMOTION:
|
||||||
case SDL_FINGERDOWN:
|
case SDL_FINGERDOWN:
|
||||||
case SDL_FINGERUP:
|
case SDL_FINGERUP:
|
||||||
|
if (!control) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
sc_input_manager_process_touch(im, &event->tfinger);
|
sc_input_manager_process_touch(im, &event->tfinger);
|
||||||
return true;
|
break;
|
||||||
|
case SDL_DROPFILE: {
|
||||||
|
if (!control) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sc_input_manager_process_file(im, &event->drop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
|
#include "file_pusher.h"
|
||||||
#include "fps_counter.h"
|
#include "fps_counter.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "trait/key_processor.h"
|
#include "trait/key_processor.h"
|
||||||
@@ -15,12 +16,12 @@
|
|||||||
|
|
||||||
struct sc_input_manager {
|
struct sc_input_manager {
|
||||||
struct sc_controller *controller;
|
struct sc_controller *controller;
|
||||||
|
struct sc_file_pusher *fp;
|
||||||
struct sc_screen *screen;
|
struct sc_screen *screen;
|
||||||
|
|
||||||
struct sc_key_processor *kp;
|
struct sc_key_processor *kp;
|
||||||
struct sc_mouse_processor *mp;
|
struct sc_mouse_processor *mp;
|
||||||
|
|
||||||
bool control;
|
|
||||||
bool forward_all_clicks;
|
bool forward_all_clicks;
|
||||||
bool legacy_paste;
|
bool legacy_paste;
|
||||||
bool clipboard_autosync;
|
bool clipboard_autosync;
|
||||||
@@ -44,11 +45,11 @@ struct sc_input_manager {
|
|||||||
|
|
||||||
struct sc_input_manager_params {
|
struct sc_input_manager_params {
|
||||||
struct sc_controller *controller;
|
struct sc_controller *controller;
|
||||||
|
struct sc_file_pusher *fp;
|
||||||
struct sc_screen *screen;
|
struct sc_screen *screen;
|
||||||
struct sc_key_processor *kp;
|
struct sc_key_processor *kp;
|
||||||
struct sc_mouse_processor *mp;
|
struct sc_mouse_processor *mp;
|
||||||
|
|
||||||
bool control;
|
|
||||||
bool forward_all_clicks;
|
bool forward_all_clicks;
|
||||||
bool legacy_paste;
|
bool legacy_paste;
|
||||||
bool clipboard_autosync;
|
bool clipboard_autosync;
|
||||||
@@ -59,7 +60,7 @@ void
|
|||||||
sc_input_manager_init(struct sc_input_manager *im,
|
sc_input_manager_init(struct sc_input_manager *im,
|
||||||
const struct sc_input_manager_params *params);
|
const struct sc_input_manager_params *params);
|
||||||
|
|
||||||
bool
|
void
|
||||||
sc_input_manager_handle_event(struct sc_input_manager *im, SDL_Event *event);
|
sc_input_manager_handle_event(struct sc_input_manager *im, SDL_Event *event);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ convert_meta_state(uint16_t mod) {
|
|||||||
static bool
|
static bool
|
||||||
convert_input_key(const struct sc_key_event *event, struct sc_control_msg *msg,
|
convert_input_key(const struct sc_key_event *event, struct sc_control_msg *msg,
|
||||||
enum sc_key_inject_mode key_inject_mode, uint32_t repeat) {
|
enum sc_key_inject_mode key_inject_mode, uint32_t repeat) {
|
||||||
msg->type = CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
msg->type = SC_CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
||||||
|
|
||||||
if (!convert_keycode(event->keycode, &msg->inject_keycode.keycode,
|
if (!convert_keycode(event->keycode, &msg->inject_keycode.keycode,
|
||||||
event->mods_state, key_inject_mode)) {
|
event->mods_state, key_inject_mode)) {
|
||||||
@@ -310,7 +310,7 @@ sc_key_processor_process_text(struct sc_key_processor *kp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_INJECT_TEXT;
|
msg.type = SC_CONTROL_MSG_TYPE_INJECT_TEXT;
|
||||||
msg.inject_text.text = strdup(event->text);
|
msg.inject_text.text = strdup(event->text);
|
||||||
if (!msg.inject_text.text) {
|
if (!msg.inject_text.text) {
|
||||||
LOGW("Could not strdup input text");
|
LOGW("Could not strdup input text");
|
||||||
|
|||||||
@@ -13,26 +13,25 @@
|
|||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "scrcpy.h"
|
#include "scrcpy.h"
|
||||||
|
#include "usb/scrcpy_otg.h"
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_version(void) {
|
print_version(void) {
|
||||||
fprintf(stderr, "scrcpy %s\n\n", SCRCPY_VERSION);
|
printf("\ndependencies:\n");
|
||||||
|
printf(" - SDL %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION,
|
||||||
fprintf(stderr, "dependencies:\n");
|
|
||||||
fprintf(stderr, " - SDL %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION,
|
|
||||||
SDL_PATCHLEVEL);
|
SDL_PATCHLEVEL);
|
||||||
fprintf(stderr, " - libavcodec %d.%d.%d\n", LIBAVCODEC_VERSION_MAJOR,
|
printf(" - libavcodec %d.%d.%d\n", LIBAVCODEC_VERSION_MAJOR,
|
||||||
LIBAVCODEC_VERSION_MINOR,
|
LIBAVCODEC_VERSION_MINOR,
|
||||||
LIBAVCODEC_VERSION_MICRO);
|
LIBAVCODEC_VERSION_MICRO);
|
||||||
fprintf(stderr, " - libavformat %d.%d.%d\n", LIBAVFORMAT_VERSION_MAJOR,
|
printf(" - libavformat %d.%d.%d\n", LIBAVFORMAT_VERSION_MAJOR,
|
||||||
LIBAVFORMAT_VERSION_MINOR,
|
LIBAVFORMAT_VERSION_MINOR,
|
||||||
LIBAVFORMAT_VERSION_MICRO);
|
LIBAVFORMAT_VERSION_MICRO);
|
||||||
fprintf(stderr, " - libavutil %d.%d.%d\n", LIBAVUTIL_VERSION_MAJOR,
|
printf(" - libavutil %d.%d.%d\n", LIBAVUTIL_VERSION_MAJOR,
|
||||||
LIBAVUTIL_VERSION_MINOR,
|
LIBAVUTIL_VERSION_MINOR,
|
||||||
LIBAVUTIL_VERSION_MICRO);
|
LIBAVUTIL_VERSION_MICRO);
|
||||||
#ifdef HAVE_V4L2
|
#ifdef HAVE_V4L2
|
||||||
fprintf(stderr, " - libavdevice %d.%d.%d\n", LIBAVDEVICE_VERSION_MAJOR,
|
printf(" - libavdevice %d.%d.%d\n", LIBAVDEVICE_VERSION_MAJOR,
|
||||||
LIBAVDEVICE_VERSION_MINOR,
|
LIBAVDEVICE_VERSION_MINOR,
|
||||||
LIBAVDEVICE_VERSION_MICRO);
|
LIBAVDEVICE_VERSION_MICRO);
|
||||||
#endif
|
#endif
|
||||||
@@ -90,9 +89,14 @@ main(int argc, char *argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int res = scrcpy(&args.opts) ? 0 : 1;
|
#ifdef HAVE_USB
|
||||||
|
bool ok = args.opts.otg ? scrcpy_otg(&args.opts)
|
||||||
|
: scrcpy(&args.opts);
|
||||||
|
#else
|
||||||
|
bool ok = scrcpy(&args.opts);
|
||||||
|
#endif
|
||||||
|
|
||||||
avformat_network_deinit(); // ignore failure
|
avformat_network_deinit(); // ignore failure
|
||||||
|
|
||||||
return res;
|
return ok ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
|
|||||||
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
||||||
|
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
.type = SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||||
.inject_touch_event = {
|
.inject_touch_event = {
|
||||||
.action = AMOTION_EVENT_ACTION_MOVE,
|
.action = AMOTION_EVENT_ACTION_MOVE,
|
||||||
.pointer_id = POINTER_ID_MOUSE,
|
.pointer_id = POINTER_ID_MOUSE,
|
||||||
@@ -87,7 +87,7 @@ sc_mouse_processor_process_mouse_click(struct sc_mouse_processor *mp,
|
|||||||
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
||||||
|
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
.type = SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||||
.inject_touch_event = {
|
.inject_touch_event = {
|
||||||
.action = convert_mouse_action(event->action),
|
.action = convert_mouse_action(event->action),
|
||||||
.pointer_id = POINTER_ID_MOUSE,
|
.pointer_id = POINTER_ID_MOUSE,
|
||||||
@@ -108,7 +108,7 @@ sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,
|
|||||||
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
||||||
|
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
.type = SC_CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
||||||
.inject_scroll_event = {
|
.inject_scroll_event = {
|
||||||
.position = event->position,
|
.position = event->position,
|
||||||
.hscroll = event->hscroll,
|
.hscroll = event->hscroll,
|
||||||
@@ -128,7 +128,7 @@ sc_mouse_processor_process_touch(struct sc_mouse_processor *mp,
|
|||||||
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
||||||
|
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
.type = SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||||
.inject_touch_event = {
|
.inject_touch_event = {
|
||||||
.action = convert_touch_action(event->action),
|
.action = convert_touch_action(event->action),
|
||||||
.pointer_id = event->pointer_id,
|
.pointer_id = event->pointer_id,
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ const struct scrcpy_options scrcpy_options_default = {
|
|||||||
.display_id = 0,
|
.display_id = 0,
|
||||||
.display_buffer = 0,
|
.display_buffer = 0,
|
||||||
.v4l2_buffer = 0,
|
.v4l2_buffer = 0,
|
||||||
|
#ifdef HAVE_USB
|
||||||
|
.otg = false,
|
||||||
|
#endif
|
||||||
.show_touches = false,
|
.show_touches = false,
|
||||||
.fullscreen = false,
|
.fullscreen = false,
|
||||||
.always_on_top = false,
|
.always_on_top = false,
|
||||||
@@ -54,6 +57,9 @@ const struct scrcpy_options scrcpy_options_default = {
|
|||||||
.legacy_paste = false,
|
.legacy_paste = false,
|
||||||
.power_off_on_close = false,
|
.power_off_on_close = false,
|
||||||
.clipboard_autosync = true,
|
.clipboard_autosync = true,
|
||||||
|
.downsize_on_error = true,
|
||||||
.tcpip = false,
|
.tcpip = false,
|
||||||
.tcpip_dst = NULL,
|
.tcpip_dst = NULL,
|
||||||
|
.select_tcpip = false,
|
||||||
|
.select_usb = false,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -112,6 +112,9 @@ struct scrcpy_options {
|
|||||||
uint32_t display_id;
|
uint32_t display_id;
|
||||||
sc_tick display_buffer;
|
sc_tick display_buffer;
|
||||||
sc_tick v4l2_buffer;
|
sc_tick v4l2_buffer;
|
||||||
|
#ifdef HAVE_USB
|
||||||
|
bool otg;
|
||||||
|
#endif
|
||||||
bool show_touches;
|
bool show_touches;
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
bool always_on_top;
|
bool always_on_top;
|
||||||
@@ -129,8 +132,11 @@ struct scrcpy_options {
|
|||||||
bool legacy_paste;
|
bool legacy_paste;
|
||||||
bool power_off_on_close;
|
bool power_off_on_close;
|
||||||
bool clipboard_autosync;
|
bool clipboard_autosync;
|
||||||
|
bool downsize_on_error;
|
||||||
bool tcpip;
|
bool tcpip;
|
||||||
const char *tcpip_dst;
|
const char *tcpip_dst;
|
||||||
|
bool select_usb;
|
||||||
|
bool select_tcpip;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const struct scrcpy_options scrcpy_options_default;
|
extern const struct scrcpy_options scrcpy_options_default;
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ receiver_start(struct receiver *receiver) {
|
|||||||
bool ok = sc_thread_create(&receiver->thread, run_receiver,
|
bool ok = sc_thread_create(&receiver->thread, run_receiver,
|
||||||
"scrcpy-receiver", receiver);
|
"scrcpy-receiver", receiver);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGC("Could not start receiver thread");
|
LOGE("Could not start receiver thread");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "util/str.h"
|
#include "util/str.h"
|
||||||
|
|
||||||
/** Downcast packet_sink to recorder */
|
/** Downcast packet_sink to recorder */
|
||||||
#define DOWNCAST(SINK) container_of(SINK, struct recorder, packet_sink)
|
#define DOWNCAST(SINK) container_of(SINK, struct sc_recorder, packet_sink)
|
||||||
|
|
||||||
static const AVRational SCRCPY_TIME_BASE = {1, 1000000}; // timestamps in us
|
static const AVRational SCRCPY_TIME_BASE = {1, 1000000}; // timestamps in us
|
||||||
|
|
||||||
@@ -30,9 +30,9 @@ find_muxer(const char *name) {
|
|||||||
return oformat;
|
return oformat;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct record_packet *
|
static struct sc_record_packet *
|
||||||
record_packet_new(const AVPacket *packet) {
|
sc_record_packet_new(const AVPacket *packet) {
|
||||||
struct record_packet *rec = malloc(sizeof(*rec));
|
struct sc_record_packet *rec = malloc(sizeof(*rec));
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
LOG_OOM();
|
LOG_OOM();
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -54,22 +54,22 @@ record_packet_new(const AVPacket *packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
record_packet_delete(struct record_packet *rec) {
|
sc_record_packet_delete(struct sc_record_packet *rec) {
|
||||||
av_packet_free(&rec->packet);
|
av_packet_free(&rec->packet);
|
||||||
free(rec);
|
free(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
recorder_queue_clear(struct recorder_queue *queue) {
|
sc_recorder_queue_clear(struct sc_recorder_queue *queue) {
|
||||||
while (!sc_queue_is_empty(queue)) {
|
while (!sc_queue_is_empty(queue)) {
|
||||||
struct record_packet *rec;
|
struct sc_record_packet *rec;
|
||||||
sc_queue_take(queue, next, &rec);
|
sc_queue_take(queue, next, &rec);
|
||||||
record_packet_delete(rec);
|
sc_record_packet_delete(rec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
recorder_get_format_name(enum sc_record_format format) {
|
sc_recorder_get_format_name(enum sc_record_format format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case SC_RECORD_FORMAT_MP4: return "mp4";
|
case SC_RECORD_FORMAT_MP4: return "mp4";
|
||||||
case SC_RECORD_FORMAT_MKV: return "matroska";
|
case SC_RECORD_FORMAT_MKV: return "matroska";
|
||||||
@@ -78,7 +78,7 @@ recorder_get_format_name(enum sc_record_format format) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
recorder_write_header(struct recorder *recorder, const AVPacket *packet) {
|
sc_recorder_write_header(struct sc_recorder *recorder, const AVPacket *packet) {
|
||||||
AVStream *ostream = recorder->ctx->streams[0];
|
AVStream *ostream = recorder->ctx->streams[0];
|
||||||
|
|
||||||
uint8_t *extradata = av_malloc(packet->size * sizeof(uint8_t));
|
uint8_t *extradata = av_malloc(packet->size * sizeof(uint8_t));
|
||||||
@@ -103,19 +103,19 @@ recorder_write_header(struct recorder *recorder, const AVPacket *packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
recorder_rescale_packet(struct recorder *recorder, AVPacket *packet) {
|
sc_recorder_rescale_packet(struct sc_recorder *recorder, AVPacket *packet) {
|
||||||
AVStream *ostream = recorder->ctx->streams[0];
|
AVStream *ostream = recorder->ctx->streams[0];
|
||||||
av_packet_rescale_ts(packet, SCRCPY_TIME_BASE, ostream->time_base);
|
av_packet_rescale_ts(packet, SCRCPY_TIME_BASE, ostream->time_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
recorder_write(struct recorder *recorder, AVPacket *packet) {
|
sc_recorder_write(struct sc_recorder *recorder, AVPacket *packet) {
|
||||||
if (!recorder->header_written) {
|
if (!recorder->header_written) {
|
||||||
if (packet->pts != AV_NOPTS_VALUE) {
|
if (packet->pts != AV_NOPTS_VALUE) {
|
||||||
LOGE("The first packet is not a config packet");
|
LOGE("The first packet is not a config packet");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool ok = recorder_write_header(recorder, packet);
|
bool ok = sc_recorder_write_header(recorder, packet);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -128,13 +128,13 @@ recorder_write(struct recorder *recorder, AVPacket *packet) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
recorder_rescale_packet(recorder, packet);
|
sc_recorder_rescale_packet(recorder, packet);
|
||||||
return av_write_frame(recorder->ctx, packet) >= 0;
|
return av_write_frame(recorder->ctx, packet) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
run_recorder(void *data) {
|
run_recorder(void *data) {
|
||||||
struct recorder *recorder = data;
|
struct sc_recorder *recorder = data;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
sc_mutex_lock(&recorder->mutex);
|
sc_mutex_lock(&recorder->mutex);
|
||||||
@@ -148,29 +148,29 @@ run_recorder(void *data) {
|
|||||||
|
|
||||||
if (recorder->stopped && sc_queue_is_empty(&recorder->queue)) {
|
if (recorder->stopped && sc_queue_is_empty(&recorder->queue)) {
|
||||||
sc_mutex_unlock(&recorder->mutex);
|
sc_mutex_unlock(&recorder->mutex);
|
||||||
struct record_packet *last = recorder->previous;
|
struct sc_record_packet *last = recorder->previous;
|
||||||
if (last) {
|
if (last) {
|
||||||
// assign an arbitrary duration to the last packet
|
// assign an arbitrary duration to the last packet
|
||||||
last->packet->duration = 100000;
|
last->packet->duration = 100000;
|
||||||
bool ok = recorder_write(recorder, last->packet);
|
bool ok = sc_recorder_write(recorder, last->packet);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
// failing to write the last frame is not very serious, no
|
// failing to write the last frame is not very serious, no
|
||||||
// future frame may depend on it, so the resulting file
|
// future frame may depend on it, so the resulting file
|
||||||
// will still be valid
|
// will still be valid
|
||||||
LOGW("Could not record last packet");
|
LOGW("Could not record last packet");
|
||||||
}
|
}
|
||||||
record_packet_delete(last);
|
sc_record_packet_delete(last);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct record_packet *rec;
|
struct sc_record_packet *rec;
|
||||||
sc_queue_take(&recorder->queue, next, &rec);
|
sc_queue_take(&recorder->queue, next, &rec);
|
||||||
|
|
||||||
sc_mutex_unlock(&recorder->mutex);
|
sc_mutex_unlock(&recorder->mutex);
|
||||||
|
|
||||||
// recorder->previous is only written from this thread, no need to lock
|
// recorder->previous is only written from this thread, no need to lock
|
||||||
struct record_packet *previous = recorder->previous;
|
struct sc_record_packet *previous = recorder->previous;
|
||||||
recorder->previous = rec;
|
recorder->previous = rec;
|
||||||
|
|
||||||
if (!previous) {
|
if (!previous) {
|
||||||
@@ -186,15 +186,15 @@ run_recorder(void *data) {
|
|||||||
rec->packet->pts - previous->packet->pts;
|
rec->packet->pts - previous->packet->pts;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok = recorder_write(recorder, previous->packet);
|
bool ok = sc_recorder_write(recorder, previous->packet);
|
||||||
record_packet_delete(previous);
|
sc_record_packet_delete(previous);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGE("Could not record packet");
|
LOGE("Could not record packet");
|
||||||
|
|
||||||
sc_mutex_lock(&recorder->mutex);
|
sc_mutex_lock(&recorder->mutex);
|
||||||
recorder->failed = true;
|
recorder->failed = true;
|
||||||
// discard pending packets
|
// discard pending packets
|
||||||
recorder_queue_clear(&recorder->queue);
|
sc_recorder_queue_clear(&recorder->queue);
|
||||||
sc_mutex_unlock(&recorder->mutex);
|
sc_mutex_unlock(&recorder->mutex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -216,7 +216,7 @@ run_recorder(void *data) {
|
|||||||
if (recorder->failed) {
|
if (recorder->failed) {
|
||||||
LOGE("Recording failed to %s", recorder->filename);
|
LOGE("Recording failed to %s", recorder->filename);
|
||||||
} else {
|
} else {
|
||||||
const char *format_name = recorder_get_format_name(recorder->format);
|
const char *format_name = sc_recorder_get_format_name(recorder->format);
|
||||||
LOGI("Recording complete to %s file: %s", format_name,
|
LOGI("Recording complete to %s file: %s", format_name,
|
||||||
recorder->filename);
|
recorder->filename);
|
||||||
}
|
}
|
||||||
@@ -227,7 +227,7 @@ run_recorder(void *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
recorder_open(struct recorder *recorder, const AVCodec *input_codec) {
|
sc_recorder_open(struct sc_recorder *recorder, const AVCodec *input_codec) {
|
||||||
bool ok = sc_mutex_init(&recorder->mutex);
|
bool ok = sc_mutex_init(&recorder->mutex);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return false;
|
return false;
|
||||||
@@ -244,7 +244,7 @@ recorder_open(struct recorder *recorder, const AVCodec *input_codec) {
|
|||||||
recorder->header_written = false;
|
recorder->header_written = false;
|
||||||
recorder->previous = NULL;
|
recorder->previous = NULL;
|
||||||
|
|
||||||
const char *format_name = recorder_get_format_name(recorder->format);
|
const char *format_name = sc_recorder_get_format_name(recorder->format);
|
||||||
assert(format_name);
|
assert(format_name);
|
||||||
const AVOutputFormat *format = find_muxer(format_name);
|
const AVOutputFormat *format = find_muxer(format_name);
|
||||||
if (!format) {
|
if (!format) {
|
||||||
@@ -290,7 +290,7 @@ recorder_open(struct recorder *recorder, const AVCodec *input_codec) {
|
|||||||
ok = sc_thread_create(&recorder->thread, run_recorder, "scrcpy-recorder",
|
ok = sc_thread_create(&recorder->thread, run_recorder, "scrcpy-recorder",
|
||||||
recorder);
|
recorder);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGC("Could not start recorder thread");
|
LOGE("Could not start recorder thread");
|
||||||
goto error_avio_close;
|
goto error_avio_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +311,7 @@ error_mutex_destroy:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
recorder_close(struct recorder *recorder) {
|
sc_recorder_close(struct sc_recorder *recorder) {
|
||||||
sc_mutex_lock(&recorder->mutex);
|
sc_mutex_lock(&recorder->mutex);
|
||||||
recorder->stopped = true;
|
recorder->stopped = true;
|
||||||
sc_cond_signal(&recorder->queue_cond);
|
sc_cond_signal(&recorder->queue_cond);
|
||||||
@@ -326,7 +326,7 @@ recorder_close(struct recorder *recorder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
recorder_push(struct recorder *recorder, const AVPacket *packet) {
|
sc_recorder_push(struct sc_recorder *recorder, const AVPacket *packet) {
|
||||||
sc_mutex_lock(&recorder->mutex);
|
sc_mutex_lock(&recorder->mutex);
|
||||||
assert(!recorder->stopped);
|
assert(!recorder->stopped);
|
||||||
|
|
||||||
@@ -336,7 +336,7 @@ recorder_push(struct recorder *recorder, const AVPacket *packet) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct record_packet *rec = record_packet_new(packet);
|
struct sc_record_packet *rec = sc_record_packet_new(packet);
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
LOG_OOM();
|
LOG_OOM();
|
||||||
sc_mutex_unlock(&recorder->mutex);
|
sc_mutex_unlock(&recorder->mutex);
|
||||||
@@ -351,25 +351,27 @@ recorder_push(struct recorder *recorder, const AVPacket *packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
recorder_packet_sink_open(struct sc_packet_sink *sink, const AVCodec *codec) {
|
sc_recorder_packet_sink_open(struct sc_packet_sink *sink,
|
||||||
struct recorder *recorder = DOWNCAST(sink);
|
const AVCodec *codec) {
|
||||||
return recorder_open(recorder, codec);
|
struct sc_recorder *recorder = DOWNCAST(sink);
|
||||||
|
return sc_recorder_open(recorder, codec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
recorder_packet_sink_close(struct sc_packet_sink *sink) {
|
sc_recorder_packet_sink_close(struct sc_packet_sink *sink) {
|
||||||
struct recorder *recorder = DOWNCAST(sink);
|
struct sc_recorder *recorder = DOWNCAST(sink);
|
||||||
recorder_close(recorder);
|
sc_recorder_close(recorder);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
recorder_packet_sink_push(struct sc_packet_sink *sink, const AVPacket *packet) {
|
sc_recorder_packet_sink_push(struct sc_packet_sink *sink,
|
||||||
struct recorder *recorder = DOWNCAST(sink);
|
const AVPacket *packet) {
|
||||||
return recorder_push(recorder, packet);
|
struct sc_recorder *recorder = DOWNCAST(sink);
|
||||||
|
return sc_recorder_push(recorder, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
recorder_init(struct recorder *recorder,
|
sc_recorder_init(struct sc_recorder *recorder,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
enum sc_record_format format,
|
enum sc_record_format format,
|
||||||
struct sc_size declared_frame_size) {
|
struct sc_size declared_frame_size) {
|
||||||
@@ -383,9 +385,9 @@ recorder_init(struct recorder *recorder,
|
|||||||
recorder->declared_frame_size = declared_frame_size;
|
recorder->declared_frame_size = declared_frame_size;
|
||||||
|
|
||||||
static const struct sc_packet_sink_ops ops = {
|
static const struct sc_packet_sink_ops ops = {
|
||||||
.open = recorder_packet_sink_open,
|
.open = sc_recorder_packet_sink_open,
|
||||||
.close = recorder_packet_sink_close,
|
.close = sc_recorder_packet_sink_close,
|
||||||
.push = recorder_packet_sink_push,
|
.push = sc_recorder_packet_sink_push,
|
||||||
};
|
};
|
||||||
|
|
||||||
recorder->packet_sink.ops = &ops;
|
recorder->packet_sink.ops = &ops;
|
||||||
@@ -394,6 +396,6 @@ recorder_init(struct recorder *recorder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
recorder_destroy(struct recorder *recorder) {
|
sc_recorder_destroy(struct sc_recorder *recorder) {
|
||||||
free(recorder->filename);
|
free(recorder->filename);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef RECORDER_H
|
#ifndef SC_RECORDER_H
|
||||||
#define RECORDER_H
|
#define SC_RECORDER_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
#include "util/queue.h"
|
#include "util/queue.h"
|
||||||
#include "util/thread.h"
|
#include "util/thread.h"
|
||||||
|
|
||||||
struct record_packet {
|
struct sc_record_packet {
|
||||||
AVPacket *packet;
|
AVPacket *packet;
|
||||||
struct record_packet *next;
|
struct sc_record_packet *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct recorder_queue SC_QUEUE(struct record_packet);
|
struct sc_recorder_queue SC_QUEUE(struct sc_record_packet);
|
||||||
|
|
||||||
struct recorder {
|
struct sc_recorder {
|
||||||
struct sc_packet_sink packet_sink; // packet sink trait
|
struct sc_packet_sink packet_sink; // packet sink trait
|
||||||
|
|
||||||
char *filename;
|
char *filename;
|
||||||
@@ -33,20 +33,21 @@ struct recorder {
|
|||||||
sc_cond queue_cond;
|
sc_cond queue_cond;
|
||||||
bool stopped; // set on recorder_close()
|
bool stopped; // set on recorder_close()
|
||||||
bool failed; // set on packet write failure
|
bool failed; // set on packet write failure
|
||||||
struct recorder_queue queue;
|
struct sc_recorder_queue queue;
|
||||||
|
|
||||||
// we can write a packet only once we received the next one so that we can
|
// we can write a packet only once we received the next one so that we can
|
||||||
// set its duration (next_pts - current_pts)
|
// set its duration (next_pts - current_pts)
|
||||||
// "previous" is only accessed from the recorder thread, so it does not
|
// "previous" is only accessed from the recorder thread, so it does not
|
||||||
// need to be protected by the mutex
|
// need to be protected by the mutex
|
||||||
struct record_packet *previous;
|
struct sc_record_packet *previous;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
recorder_init(struct recorder *recorder, const char *filename,
|
sc_recorder_init(struct sc_recorder *recorder, const char *filename,
|
||||||
enum sc_record_format format, struct sc_size declared_frame_size);
|
enum sc_record_format format,
|
||||||
|
struct sc_size declared_frame_size);
|
||||||
|
|
||||||
void
|
void
|
||||||
recorder_destroy(struct recorder *recorder);
|
sc_recorder_destroy(struct sc_recorder *recorder);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
239
app/src/scrcpy.c
239
app/src/scrcpy.c
@@ -15,18 +15,20 @@
|
|||||||
|
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "decoder.h"
|
#include "decoder.h"
|
||||||
|
#include "demuxer.h"
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
#include "file_handler.h"
|
#include "file_pusher.h"
|
||||||
#ifdef HAVE_AOA_HID
|
|
||||||
# include "hid_keyboard.h"
|
|
||||||
# include "hid_mouse.h"
|
|
||||||
#endif
|
|
||||||
#include "keyboard_inject.h"
|
#include "keyboard_inject.h"
|
||||||
#include "mouse_inject.h"
|
#include "mouse_inject.h"
|
||||||
#include "recorder.h"
|
#include "recorder.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "stream.h"
|
#ifdef HAVE_USB
|
||||||
|
# include "usb/aoa_hid.h"
|
||||||
|
# include "usb/hid_keyboard.h"
|
||||||
|
# include "usb/hid_mouse.h"
|
||||||
|
# include "usb/usb.h"
|
||||||
|
#endif
|
||||||
#include "util/acksync.h"
|
#include "util/acksync.h"
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "util/net.h"
|
#include "util/net.h"
|
||||||
@@ -37,28 +39,29 @@
|
|||||||
struct scrcpy {
|
struct scrcpy {
|
||||||
struct sc_server server;
|
struct sc_server server;
|
||||||
struct sc_screen screen;
|
struct sc_screen screen;
|
||||||
struct stream stream;
|
struct sc_demuxer demuxer;
|
||||||
struct decoder decoder;
|
struct sc_decoder decoder;
|
||||||
struct recorder recorder;
|
struct sc_recorder recorder;
|
||||||
#ifdef HAVE_V4L2
|
#ifdef HAVE_V4L2
|
||||||
struct sc_v4l2_sink v4l2_sink;
|
struct sc_v4l2_sink v4l2_sink;
|
||||||
#endif
|
#endif
|
||||||
struct sc_controller controller;
|
struct sc_controller controller;
|
||||||
struct file_handler file_handler;
|
struct sc_file_pusher file_pusher;
|
||||||
#ifdef HAVE_AOA_HID
|
#ifdef HAVE_USB
|
||||||
|
struct sc_usb usb;
|
||||||
struct sc_aoa aoa;
|
struct sc_aoa aoa;
|
||||||
// sequence/ack helper to synchronize clipboard and Ctrl+v via HID
|
// sequence/ack helper to synchronize clipboard and Ctrl+v via HID
|
||||||
struct sc_acksync acksync;
|
struct sc_acksync acksync;
|
||||||
#endif
|
#endif
|
||||||
union {
|
union {
|
||||||
struct sc_keyboard_inject keyboard_inject;
|
struct sc_keyboard_inject keyboard_inject;
|
||||||
#ifdef HAVE_AOA_HID
|
#ifdef HAVE_USB
|
||||||
struct sc_hid_keyboard keyboard_hid;
|
struct sc_hid_keyboard keyboard_hid;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
union {
|
union {
|
||||||
struct sc_mouse_inject mouse_inject;
|
struct sc_mouse_inject mouse_inject;
|
||||||
#ifdef HAVE_AOA_HID
|
#ifdef HAVE_USB
|
||||||
struct sc_hid_mouse mouse_hid;
|
struct sc_hid_mouse mouse_hid;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
@@ -140,77 +143,25 @@ sdl_configure(bool display, bool disable_screensaver) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (disable_screensaver) {
|
if (disable_screensaver) {
|
||||||
LOGD("Screensaver disabled");
|
|
||||||
SDL_DisableScreenSaver();
|
SDL_DisableScreenSaver();
|
||||||
} else {
|
} else {
|
||||||
LOGD("Screensaver enabled");
|
|
||||||
SDL_EnableScreenSaver();
|
SDL_EnableScreenSaver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
is_apk(const char *file) {
|
event_loop(struct scrcpy *s) {
|
||||||
const char *ext = strrchr(file, '.');
|
|
||||||
return ext && !strcmp(ext, ".apk");
|
|
||||||
}
|
|
||||||
|
|
||||||
enum event_result {
|
|
||||||
EVENT_RESULT_CONTINUE,
|
|
||||||
EVENT_RESULT_STOPPED_BY_USER,
|
|
||||||
EVENT_RESULT_STOPPED_BY_EOS,
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum event_result
|
|
||||||
handle_event(struct scrcpy *s, const struct scrcpy_options *options,
|
|
||||||
SDL_Event *event) {
|
|
||||||
switch (event->type) {
|
|
||||||
case EVENT_STREAM_STOPPED:
|
|
||||||
LOGD("Video stream stopped");
|
|
||||||
return EVENT_RESULT_STOPPED_BY_EOS;
|
|
||||||
case SDL_QUIT:
|
|
||||||
LOGD("User requested to quit");
|
|
||||||
return EVENT_RESULT_STOPPED_BY_USER;
|
|
||||||
case SDL_DROPFILE: {
|
|
||||||
if (!options->control) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
char *file = strdup(event->drop.file);
|
|
||||||
SDL_free(event->drop.file);
|
|
||||||
if (!file) {
|
|
||||||
LOGW("Could not strdup drop filename\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
file_handler_action_t action;
|
|
||||||
if (is_apk(file)) {
|
|
||||||
action = ACTION_INSTALL_APK;
|
|
||||||
} else {
|
|
||||||
action = ACTION_PUSH_FILE;
|
|
||||||
}
|
|
||||||
file_handler_request(&s->file_handler, action, file);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool consumed = sc_screen_handle_event(&s->screen, event);
|
|
||||||
(void) consumed;
|
|
||||||
|
|
||||||
end:
|
|
||||||
return EVENT_RESULT_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
event_loop(struct scrcpy *s, const struct scrcpy_options *options) {
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_WaitEvent(&event)) {
|
while (SDL_WaitEvent(&event)) {
|
||||||
enum event_result result = handle_event(s, options, &event);
|
switch (event.type) {
|
||||||
switch (result) {
|
case EVENT_STREAM_STOPPED:
|
||||||
case EVENT_RESULT_STOPPED_BY_USER:
|
|
||||||
return true;
|
|
||||||
case EVENT_RESULT_STOPPED_BY_EOS:
|
|
||||||
LOGW("Device disconnected");
|
LOGW("Device disconnected");
|
||||||
return false;
|
return false;
|
||||||
case EVENT_RESULT_CONTINUE:
|
case SDL_QUIT:
|
||||||
|
LOGD("User requested to quit");
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
sc_screen_handle_event(&s->screen, &event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,8 +229,8 @@ av_log_callback(void *avcl, int level, const char *fmt, va_list vl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
stream_on_eos(struct stream *stream, void *userdata) {
|
sc_demuxer_on_eos(struct sc_demuxer *demuxer, void *userdata) {
|
||||||
(void) stream;
|
(void) demuxer;
|
||||||
(void) userdata;
|
(void) userdata;
|
||||||
|
|
||||||
PUSH_EVENT(EVENT_STREAM_STOPPED);
|
PUSH_EVENT(EVENT_STREAM_STOPPED);
|
||||||
@@ -318,7 +269,7 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
|
|
||||||
// Minimal SDL initialization
|
// Minimal SDL initialization
|
||||||
if (SDL_Init(SDL_INIT_EVENTS)) {
|
if (SDL_Init(SDL_INIT_EVENTS)) {
|
||||||
LOGC("Could not initialize SDL: %s", SDL_GetError());
|
LOGE("Could not initialize SDL: %s", SDL_GetError());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,13 +278,13 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
bool server_started = false;
|
bool server_started = false;
|
||||||
bool file_handler_initialized = false;
|
bool file_pusher_initialized = false;
|
||||||
bool recorder_initialized = false;
|
bool recorder_initialized = false;
|
||||||
#ifdef HAVE_V4L2
|
#ifdef HAVE_V4L2
|
||||||
bool v4l2_sink_initialized = false;
|
bool v4l2_sink_initialized = false;
|
||||||
#endif
|
#endif
|
||||||
bool stream_started = false;
|
bool demuxer_started = false;
|
||||||
#ifdef HAVE_AOA_HID
|
#ifdef HAVE_USB
|
||||||
bool aoa_hid_initialized = false;
|
bool aoa_hid_initialized = false;
|
||||||
bool hid_keyboard_initialized = false;
|
bool hid_keyboard_initialized = false;
|
||||||
bool hid_mouse_initialized = false;
|
bool hid_mouse_initialized = false;
|
||||||
@@ -345,7 +296,9 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
struct sc_acksync *acksync = NULL;
|
struct sc_acksync *acksync = NULL;
|
||||||
|
|
||||||
struct sc_server_params params = {
|
struct sc_server_params params = {
|
||||||
.serial = options->serial,
|
.req_serial = options->serial,
|
||||||
|
.select_usb = options->select_usb,
|
||||||
|
.select_tcpip = options->select_tcpip,
|
||||||
.log_level = options->log_level,
|
.log_level = options->log_level,
|
||||||
.crop = options->crop,
|
.crop = options->crop,
|
||||||
.port_range = options->port_range,
|
.port_range = options->port_range,
|
||||||
@@ -364,6 +317,7 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
.force_adb_forward = options->force_adb_forward,
|
.force_adb_forward = options->force_adb_forward,
|
||||||
.power_off_on_close = options->power_off_on_close,
|
.power_off_on_close = options->power_off_on_close,
|
||||||
.clipboard_autosync = options->clipboard_autosync,
|
.clipboard_autosync = options->clipboard_autosync,
|
||||||
|
.downsize_on_error = options->downsize_on_error,
|
||||||
.tcpip = options->tcpip,
|
.tcpip = options->tcpip,
|
||||||
.tcpip_dst = options->tcpip_dst,
|
.tcpip_dst = options->tcpip_dst,
|
||||||
};
|
};
|
||||||
@@ -389,7 +343,7 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
|
|
||||||
// Initialize SDL video in addition if display is enabled
|
// Initialize SDL video in addition if display is enabled
|
||||||
if (options->display && SDL_Init(SDL_INIT_VIDEO)) {
|
if (options->display && SDL_Init(SDL_INIT_VIDEO)) {
|
||||||
LOGC("Could not initialize SDL: %s", SDL_GetError());
|
LOGE("Could not initialize SDL: %s", SDL_GetError());
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,30 +357,33 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
// It is necessarily initialized here, since the device is connected
|
// It is necessarily initialized here, since the device is connected
|
||||||
struct sc_server_info *info = &s->server.info;
|
struct sc_server_info *info = &s->server.info;
|
||||||
|
|
||||||
const char *serial = s->server.params.serial;
|
const char *serial = s->server.serial;
|
||||||
assert(serial);
|
assert(serial);
|
||||||
|
|
||||||
|
struct sc_file_pusher *fp = NULL;
|
||||||
|
|
||||||
if (options->display && options->control) {
|
if (options->display && options->control) {
|
||||||
if (!file_handler_init(&s->file_handler, serial,
|
if (!sc_file_pusher_init(&s->file_pusher, serial,
|
||||||
options->push_target)) {
|
options->push_target)) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
file_handler_initialized = true;
|
fp = &s->file_pusher;
|
||||||
|
file_pusher_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct decoder *dec = NULL;
|
struct sc_decoder *dec = NULL;
|
||||||
bool needs_decoder = options->display;
|
bool needs_decoder = options->display;
|
||||||
#ifdef HAVE_V4L2
|
#ifdef HAVE_V4L2
|
||||||
needs_decoder |= !!options->v4l2_device;
|
needs_decoder |= !!options->v4l2_device;
|
||||||
#endif
|
#endif
|
||||||
if (needs_decoder) {
|
if (needs_decoder) {
|
||||||
decoder_init(&s->decoder);
|
sc_decoder_init(&s->decoder);
|
||||||
dec = &s->decoder;
|
dec = &s->decoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct recorder *rec = NULL;
|
struct sc_recorder *rec = NULL;
|
||||||
if (options->record_filename) {
|
if (options->record_filename) {
|
||||||
if (!recorder_init(&s->recorder,
|
if (!sc_recorder_init(&s->recorder,
|
||||||
options->record_filename,
|
options->record_filename,
|
||||||
options->record_format,
|
options->record_format,
|
||||||
info->frame_size)) {
|
info->frame_size)) {
|
||||||
@@ -438,24 +395,25 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
|
|
||||||
av_log_set_callback(av_log_callback);
|
av_log_set_callback(av_log_callback);
|
||||||
|
|
||||||
static const struct stream_callbacks stream_cbs = {
|
static const struct sc_demuxer_callbacks demuxer_cbs = {
|
||||||
.on_eos = stream_on_eos,
|
.on_eos = sc_demuxer_on_eos,
|
||||||
};
|
};
|
||||||
stream_init(&s->stream, s->server.video_socket, &stream_cbs, NULL);
|
sc_demuxer_init(&s->demuxer, s->server.video_socket, &demuxer_cbs, NULL);
|
||||||
|
|
||||||
if (dec) {
|
if (dec) {
|
||||||
stream_add_sink(&s->stream, &dec->packet_sink);
|
sc_demuxer_add_sink(&s->demuxer, &dec->packet_sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rec) {
|
if (rec) {
|
||||||
stream_add_sink(&s->stream, &rec->packet_sink);
|
sc_demuxer_add_sink(&s->demuxer, &rec->packet_sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct sc_controller *controller = NULL;
|
||||||
struct sc_key_processor *kp = NULL;
|
struct sc_key_processor *kp = NULL;
|
||||||
struct sc_mouse_processor *mp = NULL;
|
struct sc_mouse_processor *mp = NULL;
|
||||||
|
|
||||||
if (options->control) {
|
if (options->control) {
|
||||||
#ifdef HAVE_AOA_HID
|
#ifdef HAVE_USB
|
||||||
bool use_hid_keyboard =
|
bool use_hid_keyboard =
|
||||||
options->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_HID;
|
options->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_HID;
|
||||||
bool use_hid_mouse =
|
bool use_hid_mouse =
|
||||||
@@ -466,9 +424,39 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = sc_aoa_init(&s->aoa, serial, &s->acksync);
|
ok = sc_usb_init(&s->usb);
|
||||||
|
if (!ok) {
|
||||||
|
LOGE("Failed to initialize USB");
|
||||||
|
sc_acksync_destroy(&s->acksync);
|
||||||
|
goto aoa_hid_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(serial);
|
||||||
|
struct sc_usb_device usb_device;
|
||||||
|
ok = sc_usb_select_device(&s->usb, serial, &usb_device);
|
||||||
|
if (!ok) {
|
||||||
|
sc_usb_destroy(&s->usb);
|
||||||
|
goto aoa_hid_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGI("USB device: %s (%04" PRIx16 ":%04" PRIx16 ") %s %s",
|
||||||
|
usb_device.serial, usb_device.vid, usb_device.pid,
|
||||||
|
usb_device.manufacturer, usb_device.product);
|
||||||
|
|
||||||
|
ok = sc_usb_connect(&s->usb, usb_device.device, NULL, NULL);
|
||||||
|
sc_usb_device_destroy(&usb_device);
|
||||||
|
if (!ok) {
|
||||||
|
LOGE("Failed to connect to USB device %s", serial);
|
||||||
|
sc_usb_destroy(&s->usb);
|
||||||
|
sc_acksync_destroy(&s->acksync);
|
||||||
|
goto aoa_hid_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = sc_aoa_init(&s->aoa, &s->usb, &s->acksync);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGE("Failed to enable HID over AOA");
|
LOGE("Failed to enable HID over AOA");
|
||||||
|
sc_usb_disconnect(&s->usb);
|
||||||
|
sc_usb_destroy(&s->usb);
|
||||||
sc_acksync_destroy(&s->acksync);
|
sc_acksync_destroy(&s->acksync);
|
||||||
goto aoa_hid_end;
|
goto aoa_hid_end;
|
||||||
}
|
}
|
||||||
@@ -495,6 +483,8 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
|
|
||||||
if (!need_aoa || !sc_aoa_start(&s->aoa)) {
|
if (!need_aoa || !sc_aoa_start(&s->aoa)) {
|
||||||
sc_acksync_destroy(&s->acksync);
|
sc_acksync_destroy(&s->acksync);
|
||||||
|
sc_usb_disconnect(&s->usb);
|
||||||
|
sc_usb_destroy(&s->usb);
|
||||||
sc_aoa_destroy(&s->aoa);
|
sc_aoa_destroy(&s->aoa);
|
||||||
goto aoa_hid_end;
|
goto aoa_hid_end;
|
||||||
}
|
}
|
||||||
@@ -556,11 +546,12 @@ aoa_hid_end:
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
controller_started = true;
|
controller_started = true;
|
||||||
|
controller = &s->controller;
|
||||||
|
|
||||||
if (options->turn_screen_off) {
|
if (options->turn_screen_off) {
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
|
msg.type = SC_CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
|
||||||
msg.set_screen_power_mode.mode = SCREEN_POWER_MODE_OFF;
|
msg.set_screen_power_mode.mode = SC_SCREEN_POWER_MODE_OFF;
|
||||||
|
|
||||||
if (!sc_controller_push_msg(&s->controller, &msg)) {
|
if (!sc_controller_push_msg(&s->controller, &msg)) {
|
||||||
LOGW("Could not request 'set screen power mode'");
|
LOGW("Could not request 'set screen power mode'");
|
||||||
@@ -569,15 +560,18 @@ aoa_hid_end:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// There is a controller if and only if control is enabled
|
||||||
|
assert(options->control == !!controller);
|
||||||
|
|
||||||
if (options->display) {
|
if (options->display) {
|
||||||
const char *window_title =
|
const char *window_title =
|
||||||
options->window_title ? options->window_title : info->device_name;
|
options->window_title ? options->window_title : info->device_name;
|
||||||
|
|
||||||
struct sc_screen_params screen_params = {
|
struct sc_screen_params screen_params = {
|
||||||
.controller = &s->controller,
|
.controller = controller,
|
||||||
|
.fp = fp,
|
||||||
.kp = kp,
|
.kp = kp,
|
||||||
.mp = mp,
|
.mp = mp,
|
||||||
.control = options->control,
|
|
||||||
.forward_all_clicks = options->forward_all_clicks,
|
.forward_all_clicks = options->forward_all_clicks,
|
||||||
.legacy_paste = options->legacy_paste,
|
.legacy_paste = options->legacy_paste,
|
||||||
.clipboard_autosync = options->clipboard_autosync,
|
.clipboard_autosync = options->clipboard_autosync,
|
||||||
@@ -601,7 +595,7 @@ aoa_hid_end:
|
|||||||
}
|
}
|
||||||
screen_initialized = true;
|
screen_initialized = true;
|
||||||
|
|
||||||
decoder_add_sink(&s->decoder, &s->screen.frame_sink);
|
sc_decoder_add_sink(&s->decoder, &s->screen.frame_sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_V4L2
|
#ifdef HAVE_V4L2
|
||||||
@@ -611,35 +605,39 @@ aoa_hid_end:
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder_add_sink(&s->decoder, &s->v4l2_sink.frame_sink);
|
sc_decoder_add_sink(&s->decoder, &s->v4l2_sink.frame_sink);
|
||||||
|
|
||||||
v4l2_sink_initialized = true;
|
v4l2_sink_initialized = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// now we consumed the header values, the socket receives the video stream
|
// now we consumed the header values, the socket receives the video stream
|
||||||
// start the stream
|
// start the demuxer
|
||||||
if (!stream_start(&s->stream)) {
|
if (!sc_demuxer_start(&s->demuxer)) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
stream_started = true;
|
demuxer_started = true;
|
||||||
|
|
||||||
ret = event_loop(s, options);
|
ret = event_loop(s);
|
||||||
LOGD("quit...");
|
LOGD("quit...");
|
||||||
|
|
||||||
// Close the window immediately on closing, because screen_destroy() may
|
// Close the window immediately on closing, because screen_destroy() may
|
||||||
// only be called once the stream thread is joined (it may take time)
|
// only be called once the demuxer thread is joined (it may take time)
|
||||||
sc_screen_hide_window(&s->screen);
|
sc_screen_hide_window(&s->screen);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
// The stream is not stopped explicitly, because it will stop by itself on
|
// The demuxer is not stopped explicitly, because it will stop by itself on
|
||||||
// end-of-stream
|
// end-of-stream
|
||||||
#ifdef HAVE_AOA_HID
|
#ifdef HAVE_USB
|
||||||
if (aoa_hid_initialized) {
|
if (aoa_hid_initialized) {
|
||||||
if (hid_keyboard_initialized) {
|
if (hid_keyboard_initialized) {
|
||||||
sc_hid_keyboard_destroy(&s->keyboard_hid);
|
sc_hid_keyboard_destroy(&s->keyboard_hid);
|
||||||
}
|
}
|
||||||
|
if (hid_mouse_initialized) {
|
||||||
|
sc_hid_mouse_destroy(&s->mouse_hid);
|
||||||
|
}
|
||||||
sc_aoa_stop(&s->aoa);
|
sc_aoa_stop(&s->aoa);
|
||||||
|
sc_usb_stop(&s->usb);
|
||||||
}
|
}
|
||||||
if (acksync) {
|
if (acksync) {
|
||||||
sc_acksync_destroy(acksync);
|
sc_acksync_destroy(acksync);
|
||||||
@@ -648,8 +646,8 @@ end:
|
|||||||
if (controller_started) {
|
if (controller_started) {
|
||||||
sc_controller_stop(&s->controller);
|
sc_controller_stop(&s->controller);
|
||||||
}
|
}
|
||||||
if (file_handler_initialized) {
|
if (file_pusher_initialized) {
|
||||||
file_handler_stop(&s->file_handler);
|
sc_file_pusher_stop(&s->file_pusher);
|
||||||
}
|
}
|
||||||
if (screen_initialized) {
|
if (screen_initialized) {
|
||||||
sc_screen_interrupt(&s->screen);
|
sc_screen_interrupt(&s->screen);
|
||||||
@@ -660,10 +658,10 @@ end:
|
|||||||
sc_server_stop(&s->server);
|
sc_server_stop(&s->server);
|
||||||
}
|
}
|
||||||
|
|
||||||
// now that the sockets are shutdown, the stream and controller are
|
// now that the sockets are shutdown, the demuxer and controller are
|
||||||
// interrupted, we can join them
|
// interrupted, we can join them
|
||||||
if (stream_started) {
|
if (demuxer_started) {
|
||||||
stream_join(&s->stream);
|
sc_demuxer_join(&s->demuxer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_V4L2
|
#ifdef HAVE_V4L2
|
||||||
@@ -672,14 +670,17 @@ end:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_AOA_HID
|
#ifdef HAVE_USB
|
||||||
if (aoa_hid_initialized) {
|
if (aoa_hid_initialized) {
|
||||||
sc_aoa_join(&s->aoa);
|
sc_aoa_join(&s->aoa);
|
||||||
sc_aoa_destroy(&s->aoa);
|
sc_aoa_destroy(&s->aoa);
|
||||||
|
sc_usb_join(&s->usb);
|
||||||
|
sc_usb_disconnect(&s->usb);
|
||||||
|
sc_usb_destroy(&s->usb);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Destroy the screen only after the stream is guaranteed to be finished,
|
// Destroy the screen only after the demuxer is guaranteed to be finished,
|
||||||
// because otherwise the screen could receive new frames after destruction
|
// because otherwise the screen could receive new frames after destruction
|
||||||
if (screen_initialized) {
|
if (screen_initialized) {
|
||||||
sc_screen_join(&s->screen);
|
sc_screen_join(&s->screen);
|
||||||
@@ -694,12 +695,12 @@ end:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (recorder_initialized) {
|
if (recorder_initialized) {
|
||||||
recorder_destroy(&s->recorder);
|
sc_recorder_destroy(&s->recorder);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_handler_initialized) {
|
if (file_pusher_initialized) {
|
||||||
file_handler_join(&s->file_handler);
|
sc_file_pusher_join(&s->file_pusher);
|
||||||
file_handler_destroy(&s->file_handler);
|
sc_file_pusher_destroy(&s->file_pusher);
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_server_destroy(&s->server);
|
sc_server_destroy(&s->server);
|
||||||
|
|||||||
131
app/src/screen.c
131
app/src/screen.c
@@ -156,7 +156,13 @@ get_initial_optimal_size(struct sc_size content_size, uint16_t req_width,
|
|||||||
return window_size;
|
return window_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline bool
|
||||||
|
sc_screen_is_relative_mode(struct sc_screen *screen) {
|
||||||
|
// screen->im.mp may be NULL if --no-control
|
||||||
|
return screen->im.mp && screen->im.mp->relative_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
sc_screen_capture_mouse(struct sc_screen *screen, bool capture) {
|
sc_screen_capture_mouse(struct sc_screen *screen, bool capture) {
|
||||||
if (SDL_SetRelativeMouseMode(capture)) {
|
if (SDL_SetRelativeMouseMode(capture)) {
|
||||||
LOGE("Could not set relative mouse mode to %s: %s",
|
LOGE("Could not set relative mouse mode to %s: %s",
|
||||||
@@ -369,6 +375,12 @@ sc_screen_init(struct sc_screen *screen,
|
|||||||
screen->mouse_captured = false;
|
screen->mouse_captured = false;
|
||||||
screen->mouse_capture_key_pressed = 0;
|
screen->mouse_capture_key_pressed = 0;
|
||||||
|
|
||||||
|
screen->req.x = params->window_x;
|
||||||
|
screen->req.y = params->window_y;
|
||||||
|
screen->req.width = params->window_width;
|
||||||
|
screen->req.height = params->window_height;
|
||||||
|
screen->req.fullscreen = params->fullscreen;
|
||||||
|
|
||||||
static const struct sc_video_buffer_callbacks cbs = {
|
static const struct sc_video_buffer_callbacks cbs = {
|
||||||
.on_new_frame = sc_video_buffer_on_new_frame,
|
.on_new_frame = sc_video_buffer_on_new_frame,
|
||||||
};
|
};
|
||||||
@@ -397,9 +409,6 @@ sc_screen_init(struct sc_screen *screen,
|
|||||||
get_rotated_size(screen->frame_size, screen->rotation);
|
get_rotated_size(screen->frame_size, screen->rotation);
|
||||||
screen->content_size = content_size;
|
screen->content_size = content_size;
|
||||||
|
|
||||||
struct sc_size window_size =
|
|
||||||
get_initial_optimal_size(content_size,params->window_width,
|
|
||||||
params->window_height);
|
|
||||||
uint32_t window_flags = SDL_WINDOW_HIDDEN
|
uint32_t window_flags = SDL_WINDOW_HIDDEN
|
||||||
| SDL_WINDOW_RESIZABLE
|
| SDL_WINDOW_RESIZABLE
|
||||||
| SDL_WINDOW_ALLOW_HIGHDPI;
|
| SDL_WINDOW_ALLOW_HIGHDPI;
|
||||||
@@ -410,22 +419,18 @@ sc_screen_init(struct sc_screen *screen,
|
|||||||
window_flags |= SDL_WINDOW_BORDERLESS;
|
window_flags |= SDL_WINDOW_BORDERLESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = params->window_x != SC_WINDOW_POSITION_UNDEFINED
|
// The window will be positioned and sized on first video frame
|
||||||
? params->window_x : (int) SDL_WINDOWPOS_UNDEFINED;
|
screen->window =
|
||||||
int y = params->window_y != SC_WINDOW_POSITION_UNDEFINED
|
SDL_CreateWindow(params->window_title, 0, 0, 0, 0, window_flags);
|
||||||
? params->window_y : (int) SDL_WINDOWPOS_UNDEFINED;
|
|
||||||
screen->window = SDL_CreateWindow(params->window_title, x, y,
|
|
||||||
window_size.width, window_size.height,
|
|
||||||
window_flags);
|
|
||||||
if (!screen->window) {
|
if (!screen->window) {
|
||||||
LOGC("Could not create window: %s", SDL_GetError());
|
LOGE("Could not create window: %s", SDL_GetError());
|
||||||
goto error_destroy_fps_counter;
|
goto error_destroy_fps_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
screen->renderer = SDL_CreateRenderer(screen->window, -1,
|
screen->renderer = SDL_CreateRenderer(screen->window, -1,
|
||||||
SDL_RENDERER_ACCELERATED);
|
SDL_RENDERER_ACCELERATED);
|
||||||
if (!screen->renderer) {
|
if (!screen->renderer) {
|
||||||
LOGC("Could not create renderer: %s", SDL_GetError());
|
LOGE("Could not create renderer: %s", SDL_GetError());
|
||||||
goto error_destroy_window;
|
goto error_destroy_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,7 +479,7 @@ sc_screen_init(struct sc_screen *screen,
|
|||||||
params->frame_size.height);
|
params->frame_size.height);
|
||||||
screen->texture = create_texture(screen);
|
screen->texture = create_texture(screen);
|
||||||
if (!screen->texture) {
|
if (!screen->texture) {
|
||||||
LOGC("Could not create texture: %s", SDL_GetError());
|
LOGE("Could not create texture: %s", SDL_GetError());
|
||||||
goto error_destroy_renderer;
|
goto error_destroy_renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,10 +491,10 @@ sc_screen_init(struct sc_screen *screen,
|
|||||||
|
|
||||||
struct sc_input_manager_params im_params = {
|
struct sc_input_manager_params im_params = {
|
||||||
.controller = params->controller,
|
.controller = params->controller,
|
||||||
|
.fp = params->fp,
|
||||||
.screen = screen,
|
.screen = screen,
|
||||||
.kp = params->kp,
|
.kp = params->kp,
|
||||||
.mp = params->mp,
|
.mp = params->mp,
|
||||||
.control = params->control,
|
|
||||||
.forward_all_clicks = params->forward_all_clicks,
|
.forward_all_clicks = params->forward_all_clicks,
|
||||||
.legacy_paste = params->legacy_paste,
|
.legacy_paste = params->legacy_paste,
|
||||||
.clipboard_autosync = params->clipboard_autosync,
|
.clipboard_autosync = params->clipboard_autosync,
|
||||||
@@ -498,17 +503,6 @@ sc_screen_init(struct sc_screen *screen,
|
|||||||
|
|
||||||
sc_input_manager_init(&screen->im, &im_params);
|
sc_input_manager_init(&screen->im, &im_params);
|
||||||
|
|
||||||
// Reset the window size to trigger a SIZE_CHANGED event, to workaround
|
|
||||||
// HiDPI issues with some SDL renderers when several displays having
|
|
||||||
// different HiDPI scaling are connected
|
|
||||||
SDL_SetWindowSize(screen->window, window_size.width, window_size.height);
|
|
||||||
|
|
||||||
sc_screen_update_content_rect(screen);
|
|
||||||
|
|
||||||
if (params->fullscreen) {
|
|
||||||
sc_screen_switch_fullscreen(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
||||||
SDL_AddEventWatch(event_watcher, screen);
|
SDL_AddEventWatch(event_watcher, screen);
|
||||||
#endif
|
#endif
|
||||||
@@ -545,7 +539,23 @@ error_destroy_video_buffer:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sc_screen_show_window(struct sc_screen *screen) {
|
sc_screen_show_initial_window(struct sc_screen *screen) {
|
||||||
|
int x = screen->req.x != SC_WINDOW_POSITION_UNDEFINED
|
||||||
|
? screen->req.x : (int) SDL_WINDOWPOS_CENTERED;
|
||||||
|
int y = screen->req.y != SC_WINDOW_POSITION_UNDEFINED
|
||||||
|
? screen->req.y : (int) SDL_WINDOWPOS_CENTERED;
|
||||||
|
|
||||||
|
struct sc_size window_size =
|
||||||
|
get_initial_optimal_size(screen->content_size, screen->req.width,
|
||||||
|
screen->req.height);
|
||||||
|
|
||||||
|
set_window_size(screen, window_size);
|
||||||
|
SDL_SetWindowPosition(screen->window, x, y);
|
||||||
|
|
||||||
|
if (screen->req.fullscreen) {
|
||||||
|
sc_screen_switch_fullscreen(screen);
|
||||||
|
}
|
||||||
|
|
||||||
SDL_ShowWindow(screen->window);
|
SDL_ShowWindow(screen->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -656,7 +666,7 @@ prepare_for_frame(struct sc_screen *screen, struct sc_size new_frame_size) {
|
|||||||
screen->frame_size.width, screen->frame_size.height);
|
screen->frame_size.width, screen->frame_size.height);
|
||||||
screen->texture = create_texture(screen);
|
screen->texture = create_texture(screen);
|
||||||
if (!screen->texture) {
|
if (!screen->texture) {
|
||||||
LOGC("Could not create texture: %s", SDL_GetError());
|
LOGE("Could not create texture: %s", SDL_GetError());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -693,6 +703,17 @@ sc_screen_update_frame(struct sc_screen *screen) {
|
|||||||
}
|
}
|
||||||
update_texture(screen, frame);
|
update_texture(screen, frame);
|
||||||
|
|
||||||
|
if (!screen->has_frame) {
|
||||||
|
screen->has_frame = true;
|
||||||
|
// this is the very first frame, show the window
|
||||||
|
sc_screen_show_initial_window(screen);
|
||||||
|
|
||||||
|
if (sc_screen_is_relative_mode(screen)) {
|
||||||
|
// Capture mouse on start
|
||||||
|
sc_screen_capture_mouse(screen, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sc_screen_render(screen, false);
|
sc_screen_render(screen, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -760,24 +781,22 @@ sc_screen_is_mouse_capture_key(SDL_Keycode key) {
|
|||||||
return key == SDLK_LALT || key == SDLK_LGUI || key == SDLK_RGUI;
|
return key == SDLK_LALT || key == SDLK_LGUI || key == SDLK_RGUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
|
sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
|
||||||
|
bool relative_mode = sc_screen_is_relative_mode(screen);
|
||||||
|
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case EVENT_NEW_FRAME:
|
case EVENT_NEW_FRAME: {
|
||||||
if (!screen->has_frame) {
|
|
||||||
screen->has_frame = true;
|
|
||||||
// this is the very first frame, show the window
|
|
||||||
sc_screen_show_window(screen);
|
|
||||||
}
|
|
||||||
bool ok = sc_screen_update_frame(screen);
|
bool ok = sc_screen_update_frame(screen);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGW("Frame update failed\n");
|
LOGW("Frame update failed\n");
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
|
}
|
||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
if (!screen->has_frame) {
|
if (!screen->has_frame) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
switch (event->window.event) {
|
switch (event->window.event) {
|
||||||
case SDL_WINDOWEVENT_EXPOSED:
|
case SDL_WINDOWEVENT_EXPOSED:
|
||||||
@@ -803,70 +822,72 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
|
|||||||
sc_screen_render(screen, true);
|
sc_screen_render(screen, true);
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||||
if (screen->im.mp->relative_mode) {
|
if (relative_mode) {
|
||||||
sc_screen_capture_mouse(screen, false);
|
sc_screen_capture_mouse(screen, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
if (screen->im.mp->relative_mode) {
|
if (relative_mode) {
|
||||||
SDL_Keycode key = event->key.keysym.sym;
|
SDL_Keycode key = event->key.keysym.sym;
|
||||||
if (sc_screen_is_mouse_capture_key(key)) {
|
if (sc_screen_is_mouse_capture_key(key)) {
|
||||||
if (!screen->mouse_capture_key_pressed) {
|
if (!screen->mouse_capture_key_pressed) {
|
||||||
screen->mouse_capture_key_pressed = key;
|
screen->mouse_capture_key_pressed = key;
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
// Another mouse capture key has been pressed, cancel
|
// Another mouse capture key has been pressed, cancel
|
||||||
// mouse (un)capture
|
// mouse (un)capture
|
||||||
screen->mouse_capture_key_pressed = 0;
|
screen->mouse_capture_key_pressed = 0;
|
||||||
// Do not return, the event must be forwarded to the
|
|
||||||
// input manager
|
|
||||||
}
|
}
|
||||||
|
// Mouse capture keys are never forwarded to the device
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
if (screen->im.mp->relative_mode) {
|
if (relative_mode) {
|
||||||
SDL_Keycode key = event->key.keysym.sym;
|
SDL_Keycode key = event->key.keysym.sym;
|
||||||
SDL_Keycode cap = screen->mouse_capture_key_pressed;
|
SDL_Keycode cap = screen->mouse_capture_key_pressed;
|
||||||
screen->mouse_capture_key_pressed = 0;
|
screen->mouse_capture_key_pressed = 0;
|
||||||
|
if (sc_screen_is_mouse_capture_key(key)) {
|
||||||
if (key == cap) {
|
if (key == cap) {
|
||||||
// A mouse capture key has been pressed then released:
|
// A mouse capture key has been pressed then released:
|
||||||
// toggle the capture mouse mode
|
// toggle the capture mouse mode
|
||||||
sc_screen_capture_mouse(screen, !screen->mouse_captured);
|
sc_screen_capture_mouse(screen,
|
||||||
return true;
|
!screen->mouse_captured);
|
||||||
|
}
|
||||||
|
// Mouse capture keys are never forwarded to the device
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
// Do not return, the event must be forwarded to the input
|
|
||||||
// manager
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
if (screen->im.mp->relative_mode && !screen->mouse_captured) {
|
if (relative_mode && !screen->mouse_captured) {
|
||||||
// Do not forward to input manager, the mouse will be captured
|
// Do not forward to input manager, the mouse will be captured
|
||||||
// on SDL_MOUSEBUTTONUP
|
// on SDL_MOUSEBUTTONUP
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_FINGERMOTION:
|
case SDL_FINGERMOTION:
|
||||||
case SDL_FINGERDOWN:
|
case SDL_FINGERDOWN:
|
||||||
case SDL_FINGERUP:
|
case SDL_FINGERUP:
|
||||||
if (screen->im.mp->relative_mode) {
|
if (relative_mode) {
|
||||||
// Touch events are not compatible with relative mode
|
// Touch events are not compatible with relative mode
|
||||||
// (coordinates are not relative)
|
// (coordinates are not relative)
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
if (screen->im.mp->relative_mode && !screen->mouse_captured) {
|
if (relative_mode && !screen->mouse_captured) {
|
||||||
sc_screen_capture_mouse(screen, true);
|
sc_screen_capture_mouse(screen, true);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sc_input_manager_handle_event(&screen->im, event);
|
sc_input_manager_handle_event(&screen->im, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sc_point
|
struct sc_point
|
||||||
|
|||||||
@@ -28,6 +28,15 @@ struct sc_screen {
|
|||||||
struct sc_video_buffer vb;
|
struct sc_video_buffer vb;
|
||||||
struct fps_counter fps_counter;
|
struct fps_counter fps_counter;
|
||||||
|
|
||||||
|
// The initial requested window properties
|
||||||
|
struct {
|
||||||
|
int16_t x;
|
||||||
|
int16_t y;
|
||||||
|
uint16_t width;
|
||||||
|
uint16_t height;
|
||||||
|
bool fullscreen;
|
||||||
|
} req;
|
||||||
|
|
||||||
SDL_Window *window;
|
SDL_Window *window;
|
||||||
SDL_Renderer *renderer;
|
SDL_Renderer *renderer;
|
||||||
SDL_Texture *texture;
|
SDL_Texture *texture;
|
||||||
@@ -61,10 +70,10 @@ struct sc_screen {
|
|||||||
|
|
||||||
struct sc_screen_params {
|
struct sc_screen_params {
|
||||||
struct sc_controller *controller;
|
struct sc_controller *controller;
|
||||||
|
struct sc_file_pusher *fp;
|
||||||
struct sc_key_processor *kp;
|
struct sc_key_processor *kp;
|
||||||
struct sc_mouse_processor *mp;
|
struct sc_mouse_processor *mp;
|
||||||
|
|
||||||
bool control;
|
|
||||||
bool forward_all_clicks;
|
bool forward_all_clicks;
|
||||||
bool legacy_paste;
|
bool legacy_paste;
|
||||||
bool clipboard_autosync;
|
bool clipboard_autosync;
|
||||||
@@ -74,10 +83,10 @@ struct sc_screen_params {
|
|||||||
struct sc_size frame_size;
|
struct sc_size frame_size;
|
||||||
bool always_on_top;
|
bool always_on_top;
|
||||||
|
|
||||||
int16_t window_x;
|
int16_t window_x; // accepts SC_WINDOW_POSITION_UNDEFINED
|
||||||
int16_t window_y;
|
int16_t window_y; // accepts SC_WINDOW_POSITION_UNDEFINED
|
||||||
uint16_t window_width; // accepts SC_WINDOW_POSITION_UNDEFINED
|
uint16_t window_width;
|
||||||
uint16_t window_height; // accepts SC_WINDOW_POSITION_UNDEFINED
|
uint16_t window_height;
|
||||||
|
|
||||||
bool window_borderless;
|
bool window_borderless;
|
||||||
|
|
||||||
@@ -130,7 +139,7 @@ void
|
|||||||
sc_screen_set_rotation(struct sc_screen *screen, unsigned rotation);
|
sc_screen_set_rotation(struct sc_screen *screen, unsigned rotation);
|
||||||
|
|
||||||
// react to SDL events
|
// react to SDL events
|
||||||
bool
|
void
|
||||||
sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event);
|
sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event);
|
||||||
|
|
||||||
// convert point from window coordinates to frame coordinates
|
// convert point from window coordinates to frame coordinates
|
||||||
|
|||||||
236
app/src/server.c
236
app/src/server.c
@@ -7,7 +7,7 @@
|
|||||||
#include <SDL2/SDL_timer.h>
|
#include <SDL2/SDL_timer.h>
|
||||||
#include <SDL2/SDL_platform.h>
|
#include <SDL2/SDL_platform.h>
|
||||||
|
|
||||||
#include "adb.h"
|
#include "adb/adb.h"
|
||||||
#include "util/file.h"
|
#include "util/file.h"
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "util/net_intr.h"
|
#include "util/net_intr.h"
|
||||||
@@ -65,7 +65,7 @@ get_server_path(void) {
|
|||||||
static void
|
static void
|
||||||
sc_server_params_destroy(struct sc_server_params *params) {
|
sc_server_params_destroy(struct sc_server_params *params) {
|
||||||
// The server stores a copy of the params provided by the user
|
// The server stores a copy of the params provided by the user
|
||||||
free((char *) params->serial);
|
free((char *) params->req_serial);
|
||||||
free((char *) params->crop);
|
free((char *) params->crop);
|
||||||
free((char *) params->codec_options);
|
free((char *) params->codec_options);
|
||||||
free((char *) params->encoder_name);
|
free((char *) params->encoder_name);
|
||||||
@@ -89,7 +89,7 @@ sc_server_params_copy(struct sc_server_params *dst,
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
COPY(serial);
|
COPY(req_serial);
|
||||||
COPY(crop);
|
COPY(crop);
|
||||||
COPY(codec_options);
|
COPY(codec_options);
|
||||||
COPY(encoder_name);
|
COPY(encoder_name);
|
||||||
@@ -114,7 +114,7 @@ push_server(struct sc_intr *intr, const char *serial) {
|
|||||||
free(server_path);
|
free(server_path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool ok = adb_push(intr, serial, server_path, SC_DEVICE_SERVER_PATH, 0);
|
bool ok = sc_adb_push(intr, serial, server_path, SC_DEVICE_SERVER_PATH, 0);
|
||||||
free(server_path);
|
free(server_path);
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
@@ -157,8 +157,14 @@ execute_server(struct sc_server *server,
|
|||||||
const struct sc_server_params *params) {
|
const struct sc_server_params *params) {
|
||||||
sc_pid pid = SC_PROCESS_NONE;
|
sc_pid pid = SC_PROCESS_NONE;
|
||||||
|
|
||||||
|
const char *serial = server->serial;
|
||||||
|
assert(serial);
|
||||||
|
|
||||||
const char *cmd[128];
|
const char *cmd[128];
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
|
cmd[count++] = sc_adb_get_executable();
|
||||||
|
cmd[count++] = "-s";
|
||||||
|
cmd[count++] = serial;
|
||||||
cmd[count++] = "shell";
|
cmd[count++] = "shell";
|
||||||
cmd[count++] = "CLASSPATH=" SC_DEVICE_SERVER_PATH;
|
cmd[count++] = "CLASSPATH=" SC_DEVICE_SERVER_PATH;
|
||||||
cmd[count++] = "app_process";
|
cmd[count++] = "app_process";
|
||||||
@@ -234,9 +240,14 @@ execute_server(struct sc_server *server,
|
|||||||
// By default, clipboard_autosync is true
|
// By default, clipboard_autosync is true
|
||||||
ADD_PARAM("clipboard_autosync=false");
|
ADD_PARAM("clipboard_autosync=false");
|
||||||
}
|
}
|
||||||
|
if (!params->downsize_on_error) {
|
||||||
|
// By default, downsize_on_error is true
|
||||||
|
ADD_PARAM("downsize_on_error=false");
|
||||||
|
}
|
||||||
|
|
||||||
#undef ADD_PARAM
|
#undef ADD_PARAM
|
||||||
#undef STRBOOL
|
|
||||||
|
cmd[count++] = NULL;
|
||||||
|
|
||||||
#ifdef SERVER_DEBUGGER
|
#ifdef SERVER_DEBUGGER
|
||||||
LOGI("Server debugger waiting for a client on device port "
|
LOGI("Server debugger waiting for a client on device port "
|
||||||
@@ -250,7 +261,7 @@ execute_server(struct sc_server *server,
|
|||||||
// Then click on "Debug"
|
// Then click on "Debug"
|
||||||
#endif
|
#endif
|
||||||
// Inherit both stdout and stderr (all server logs are printed to stdout)
|
// Inherit both stdout and stderr (all server logs are printed to stdout)
|
||||||
pid = adb_execute(params->serial, cmd, count, 0);
|
pid = sc_adb_execute(cmd, 0);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
for (unsigned i = dyn_idx; i < count; ++i) {
|
for (unsigned i = dyn_idx; i < count; ++i) {
|
||||||
@@ -342,6 +353,7 @@ sc_server_init(struct sc_server *server, const struct sc_server_params *params,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
server->serial = NULL;
|
||||||
server->stopped = false;
|
server->stopped = false;
|
||||||
|
|
||||||
server->video_socket = SC_SOCKET_NONE;
|
server->video_socket = SC_SOCKET_NONE;
|
||||||
@@ -386,7 +398,9 @@ sc_server_connect_to(struct sc_server *server, struct sc_server_info *info) {
|
|||||||
|
|
||||||
assert(tunnel->enabled);
|
assert(tunnel->enabled);
|
||||||
|
|
||||||
const char *serial = server->params.serial;
|
const char *serial = server->serial;
|
||||||
|
assert(serial);
|
||||||
|
|
||||||
bool control = server->params.control;
|
bool control = server->params.control;
|
||||||
|
|
||||||
sc_socket video_socket = SC_SOCKET_NONE;
|
sc_socket video_socket = SC_SOCKET_NONE;
|
||||||
@@ -490,32 +504,11 @@ sc_server_on_terminated(void *userdata) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
sc_server_fill_serial(struct sc_server *server) {
|
is_tcpip_mode_enabled(struct sc_server *server, const char *serial) {
|
||||||
// Retrieve the actual device immediately if not provided, so that all
|
|
||||||
// future adb commands are executed for this specific device, even if other
|
|
||||||
// devices are connected afterwards (without "more than one
|
|
||||||
// device/emulator" error)
|
|
||||||
if (!server->params.serial) {
|
|
||||||
// The serial is owned by sc_server_params, and will be freed on destroy
|
|
||||||
server->params.serial = adb_get_serialno(&server->intr, 0);
|
|
||||||
if (!server->params.serial) {
|
|
||||||
LOGE("Could not get device serial");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGD("Device serial: %s", server->params.serial);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
is_tcpip_mode_enabled(struct sc_server *server) {
|
|
||||||
struct sc_intr *intr = &server->intr;
|
struct sc_intr *intr = &server->intr;
|
||||||
const char *serial = server->params.serial;
|
|
||||||
|
|
||||||
char *current_port =
|
char *current_port =
|
||||||
adb_getprop(intr, serial, "service.adb.tcp.port", SC_ADB_SILENT);
|
sc_adb_getprop(intr, serial, "service.adb.tcp.port", SC_ADB_SILENT);
|
||||||
if (!current_port) {
|
if (!current_port) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -527,9 +520,9 @@ is_tcpip_mode_enabled(struct sc_server *server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
wait_tcpip_mode_enabled(struct sc_server *server, unsigned attempts,
|
wait_tcpip_mode_enabled(struct sc_server *server, const char *serial,
|
||||||
sc_tick delay) {
|
unsigned attempts, sc_tick delay) {
|
||||||
if (is_tcpip_mode_enabled(server)) {
|
if (is_tcpip_mode_enabled(server, serial)) {
|
||||||
LOGI("TCP/IP mode enabled");
|
LOGI("TCP/IP mode enabled");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -544,7 +537,7 @@ wait_tcpip_mode_enabled(struct sc_server *server, unsigned attempts,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_tcpip_mode_enabled(server)) {
|
if (is_tcpip_mode_enabled(server, serial)) {
|
||||||
LOGI("TCP/IP mode enabled");
|
LOGI("TCP/IP mode enabled");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -569,29 +562,30 @@ append_port_5555(const char *ip) {
|
|||||||
return ip_port;
|
return ip_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static char *
|
||||||
sc_server_switch_to_tcpip(struct sc_server *server, char **out_ip_port) {
|
sc_server_switch_to_tcpip(struct sc_server *server, const char *serial) {
|
||||||
const char *serial = server->params.serial;
|
|
||||||
assert(serial);
|
assert(serial);
|
||||||
|
|
||||||
struct sc_intr *intr = &server->intr;
|
struct sc_intr *intr = &server->intr;
|
||||||
|
|
||||||
char *ip = adb_get_device_ip(intr, serial, 0);
|
LOGI("Switching device %s to TCP/IP...", serial);
|
||||||
|
|
||||||
|
char *ip = sc_adb_get_device_ip(intr, serial, 0);
|
||||||
if (!ip) {
|
if (!ip) {
|
||||||
LOGE("Device IP not found");
|
LOGE("Device IP not found");
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ip_port = append_port_5555(ip);
|
char *ip_port = append_port_5555(ip);
|
||||||
free(ip);
|
free(ip);
|
||||||
if (!ip_port) {
|
if (!ip_port) {
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tcp_mode = is_tcpip_mode_enabled(server);
|
bool tcp_mode = is_tcpip_mode_enabled(server, serial);
|
||||||
|
|
||||||
if (!tcp_mode) {
|
if (!tcp_mode) {
|
||||||
bool ok = adb_tcpip(intr, serial, 5555, SC_ADB_NO_STDOUT);
|
bool ok = sc_adb_tcpip(intr, serial, 5555, SC_ADB_NO_STDOUT);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGE("Could not restart adbd in TCP/IP mode");
|
LOGE("Could not restart adbd in TCP/IP mode");
|
||||||
goto error;
|
goto error;
|
||||||
@@ -599,19 +593,17 @@ sc_server_switch_to_tcpip(struct sc_server *server, char **out_ip_port) {
|
|||||||
|
|
||||||
unsigned attempts = 40;
|
unsigned attempts = 40;
|
||||||
sc_tick delay = SC_TICK_FROM_MS(250);
|
sc_tick delay = SC_TICK_FROM_MS(250);
|
||||||
ok = wait_tcpip_mode_enabled(server, attempts, delay);
|
ok = wait_tcpip_mode_enabled(server, serial, attempts, delay);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*out_ip_port = ip_port;
|
return ip_port;
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free(ip_port);
|
free(ip_port);
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@@ -619,73 +611,52 @@ sc_server_connect_to_tcpip(struct sc_server *server, const char *ip_port) {
|
|||||||
struct sc_intr *intr = &server->intr;
|
struct sc_intr *intr = &server->intr;
|
||||||
|
|
||||||
// Error expected if not connected, do not report any error
|
// Error expected if not connected, do not report any error
|
||||||
adb_disconnect(intr, ip_port, SC_ADB_SILENT);
|
sc_adb_disconnect(intr, ip_port, SC_ADB_SILENT);
|
||||||
|
|
||||||
bool ok = adb_connect(intr, ip_port, 0);
|
LOGI("Connecting to %s...", ip_port);
|
||||||
|
|
||||||
|
bool ok = sc_adb_connect(intr, ip_port, 0);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGE("Could not connect to %s", ip_port);
|
LOGE("Could not connect to %s", ip_port);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override the serial, owned by the sc_server_params
|
|
||||||
free((void *) server->params.serial);
|
|
||||||
server->params.serial = strdup(ip_port);
|
|
||||||
if (!server->params.serial) {
|
|
||||||
LOG_OOM();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGI("Connected to %s", ip_port);
|
LOGI("Connected to %s", ip_port);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
sc_server_configure_tcpip(struct sc_server *server) {
|
sc_server_configure_tcpip_known_address(struct sc_server *server,
|
||||||
char *ip_port;
|
const char *addr) {
|
||||||
|
|
||||||
const struct sc_server_params *params = &server->params;
|
|
||||||
|
|
||||||
// If tcpip parameter is given, then it must connect to this address.
|
|
||||||
// Therefore, the device is unknown, so serial is meaningless at this point.
|
|
||||||
assert(!params->serial || !params->tcpip_dst);
|
|
||||||
|
|
||||||
if (params->tcpip_dst) {
|
|
||||||
// Append ":5555" if no port is present
|
// Append ":5555" if no port is present
|
||||||
bool contains_port = strchr(params->tcpip_dst, ':');
|
bool contains_port = strchr(addr, ':');
|
||||||
ip_port = contains_port ? strdup(params->tcpip_dst)
|
char *ip_port = contains_port ? strdup(addr) : append_port_5555(addr);
|
||||||
: append_port_5555(params->tcpip_dst);
|
|
||||||
if (!ip_port) {
|
if (!ip_port) {
|
||||||
LOG_OOM();
|
LOG_OOM();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// The device IP address must be retrieved from the current
|
server->serial = ip_port;
|
||||||
// connected device
|
return sc_server_connect_to_tcpip(server, ip_port);
|
||||||
if (!sc_server_fill_serial(server)) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The serial is either the real serial when connected via USB, or
|
static bool
|
||||||
// the IP:PORT when connected over TCP/IP. Only the latter contains
|
sc_server_configure_tcpip_unknown_address(struct sc_server *server,
|
||||||
// a colon.
|
const char *serial) {
|
||||||
bool is_already_tcpip = strchr(params->serial, ':');
|
bool is_already_tcpip = sc_adb_is_serial_tcpip(serial);
|
||||||
if (is_already_tcpip) {
|
if (is_already_tcpip) {
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
LOGI("Device already connected via TCP/IP: %s", params->serial);
|
LOGI("Device already connected via TCP/IP: %s", serial);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok = sc_server_switch_to_tcpip(server, &ip_port);
|
char *ip_port = sc_server_switch_to_tcpip(server, serial);
|
||||||
if (!ok) {
|
if (!ip_port) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// On success, this call changes params->serial
|
server->serial = ip_port;
|
||||||
bool ok = sc_server_connect_to_tcpip(server, ip_port);
|
return sc_server_connect_to_tcpip(server, ip_port);
|
||||||
free(ip_port);
|
|
||||||
return ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -694,30 +665,83 @@ run_server(void *data) {
|
|||||||
|
|
||||||
const struct sc_server_params *params = &server->params;
|
const struct sc_server_params *params = &server->params;
|
||||||
|
|
||||||
if (params->serial) {
|
// Execute "adb start-server" before "adb devices" so that daemon starting
|
||||||
LOGD("Device serial: %s", params->serial);
|
// output/errors is correctly printed in the console ("adb devices" output
|
||||||
|
// is parsed, so it is not output)
|
||||||
|
bool ok = sc_adb_start_server(&server->intr, 0);
|
||||||
|
if (!ok) {
|
||||||
|
LOGE("Could not start adb daemon");
|
||||||
|
goto error_connection_failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// params->tcpip_dst implies params->tcpip
|
||||||
|
assert(!params->tcpip_dst || params->tcpip);
|
||||||
|
|
||||||
|
// If tcpip_dst parameter is given, then it must connect to this address.
|
||||||
|
// Therefore, the device is unknown, so serial is meaningless at this point.
|
||||||
|
assert(!params->req_serial || !params->tcpip_dst);
|
||||||
|
|
||||||
|
// A device must be selected via a serial in all cases except when --tcpip=
|
||||||
|
// is called with a parameter (in that case, the device may initially not
|
||||||
|
// exist, and scrcpy will execute "adb connect").
|
||||||
|
bool need_initial_serial = !params->tcpip_dst;
|
||||||
|
|
||||||
|
if (need_initial_serial) {
|
||||||
|
// At most one of the 3 following parameters may be set
|
||||||
|
assert(!!params->req_serial
|
||||||
|
+ params->select_usb
|
||||||
|
+ params->select_tcpip <= 1);
|
||||||
|
|
||||||
|
struct sc_adb_device_selector selector;
|
||||||
|
if (params->req_serial) {
|
||||||
|
selector.type = SC_ADB_DEVICE_SELECT_SERIAL;
|
||||||
|
selector.serial = params->req_serial;
|
||||||
|
} else if (params->select_usb) {
|
||||||
|
selector.type = SC_ADB_DEVICE_SELECT_USB;
|
||||||
|
} else if (params->select_tcpip) {
|
||||||
|
selector.type = SC_ADB_DEVICE_SELECT_TCPIP;
|
||||||
|
} else {
|
||||||
|
selector.type = SC_ADB_DEVICE_SELECT_ALL;
|
||||||
|
}
|
||||||
|
struct sc_adb_device device;
|
||||||
|
ok = sc_adb_select_device(&server->intr, &selector, 0, &device);
|
||||||
|
if (!ok) {
|
||||||
|
goto error_connection_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->tcpip) {
|
if (params->tcpip) {
|
||||||
// params->serial may be changed after this call
|
assert(!params->tcpip_dst);
|
||||||
bool ok = sc_server_configure_tcpip(server);
|
ok = sc_server_configure_tcpip_unknown_address(server,
|
||||||
|
device.serial);
|
||||||
|
sc_adb_device_destroy(&device);
|
||||||
|
if (!ok) {
|
||||||
|
goto error_connection_failed;
|
||||||
|
}
|
||||||
|
assert(server->serial);
|
||||||
|
} else {
|
||||||
|
// "move" the device.serial without copy
|
||||||
|
server->serial = device.serial;
|
||||||
|
// the serial must not be freed by the destructor
|
||||||
|
device.serial = NULL;
|
||||||
|
sc_adb_device_destroy(&device);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ok = sc_server_configure_tcpip_known_address(server, params->tcpip_dst);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto error_connection_failed;
|
goto error_connection_failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is ok to call this function even if the device serial has been
|
const char *serial = server->serial;
|
||||||
// changed by switching over TCP/IP
|
assert(serial);
|
||||||
if (!sc_server_fill_serial(server)) {
|
LOGD("Device serial: %s", serial);
|
||||||
goto error_connection_failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ok = push_server(&server->intr, params->serial);
|
ok = push_server(&server->intr, serial);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto error_connection_failed;
|
goto error_connection_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = sc_adb_tunnel_open(&server->tunnel, &server->intr, params->serial,
|
ok = sc_adb_tunnel_open(&server->tunnel, &server->intr, serial,
|
||||||
params->port_range, params->force_adb_forward);
|
params->port_range, params->force_adb_forward);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto error_connection_failed;
|
goto error_connection_failed;
|
||||||
@@ -726,7 +750,7 @@ run_server(void *data) {
|
|||||||
// server will connect to our server socket
|
// server will connect to our server socket
|
||||||
sc_pid pid = execute_server(server, params);
|
sc_pid pid = execute_server(server, params);
|
||||||
if (pid == SC_PROCESS_NONE) {
|
if (pid == SC_PROCESS_NONE) {
|
||||||
sc_adb_tunnel_close(&server->tunnel, &server->intr, params->serial);
|
sc_adb_tunnel_close(&server->tunnel, &server->intr, serial);
|
||||||
goto error_connection_failed;
|
goto error_connection_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,7 +762,7 @@ run_server(void *data) {
|
|||||||
if (!ok) {
|
if (!ok) {
|
||||||
sc_process_terminate(pid);
|
sc_process_terminate(pid);
|
||||||
sc_process_wait(pid, true); // ignore exit code
|
sc_process_wait(pid, true); // ignore exit code
|
||||||
sc_adb_tunnel_close(&server->tunnel, &server->intr, params->serial);
|
sc_adb_tunnel_close(&server->tunnel, &server->intr, serial);
|
||||||
goto error_connection_failed;
|
goto error_connection_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -765,12 +789,10 @@ run_server(void *data) {
|
|||||||
// Interrupt sockets to wake up socket blocking calls on the server
|
// Interrupt sockets to wake up socket blocking calls on the server
|
||||||
assert(server->video_socket != SC_SOCKET_NONE);
|
assert(server->video_socket != SC_SOCKET_NONE);
|
||||||
net_interrupt(server->video_socket);
|
net_interrupt(server->video_socket);
|
||||||
net_close(server->video_socket);
|
|
||||||
|
|
||||||
if (server->control_socket != SC_SOCKET_NONE) {
|
if (server->control_socket != SC_SOCKET_NONE) {
|
||||||
// There is no control_socket if --no-control is set
|
// There is no control_socket if --no-control is set
|
||||||
net_interrupt(server->control_socket);
|
net_interrupt(server->control_socket);
|
||||||
net_close(server->control_socket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give some delay for the server to terminate properly
|
// Give some delay for the server to terminate properly
|
||||||
@@ -826,6 +848,14 @@ sc_server_stop(struct sc_server *server) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
sc_server_destroy(struct sc_server *server) {
|
sc_server_destroy(struct sc_server *server) {
|
||||||
|
if (server->video_socket != SC_SOCKET_NONE) {
|
||||||
|
net_close(server->video_socket);
|
||||||
|
}
|
||||||
|
if (server->control_socket != SC_SOCKET_NONE) {
|
||||||
|
net_close(server->control_socket);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(server->serial);
|
||||||
sc_server_params_destroy(&server->params);
|
sc_server_params_destroy(&server->params);
|
||||||
sc_intr_destroy(&server->intr);
|
sc_intr_destroy(&server->intr);
|
||||||
sc_cond_destroy(&server->cond_stopped);
|
sc_cond_destroy(&server->cond_stopped);
|
||||||
|
|||||||
@@ -7,8 +7,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "adb.h"
|
#include "adb/adb_tunnel.h"
|
||||||
#include "adb_tunnel.h"
|
|
||||||
#include "coords.h"
|
#include "coords.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "util/intr.h"
|
#include "util/intr.h"
|
||||||
@@ -23,7 +22,7 @@ struct sc_server_info {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct sc_server_params {
|
struct sc_server_params {
|
||||||
const char *serial;
|
const char *req_serial;
|
||||||
enum sc_log_level log_level;
|
enum sc_log_level log_level;
|
||||||
const char *crop;
|
const char *crop;
|
||||||
const char *codec_options;
|
const char *codec_options;
|
||||||
@@ -42,13 +41,17 @@ struct sc_server_params {
|
|||||||
bool force_adb_forward;
|
bool force_adb_forward;
|
||||||
bool power_off_on_close;
|
bool power_off_on_close;
|
||||||
bool clipboard_autosync;
|
bool clipboard_autosync;
|
||||||
|
bool downsize_on_error;
|
||||||
bool tcpip;
|
bool tcpip;
|
||||||
const char *tcpip_dst;
|
const char *tcpip_dst;
|
||||||
|
bool select_usb;
|
||||||
|
bool select_tcpip;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sc_server {
|
struct sc_server {
|
||||||
// The internal allocated strings are copies owned by the server
|
// The internal allocated strings are copies owned by the server
|
||||||
struct sc_server_params params;
|
struct sc_server_params params;
|
||||||
|
char *serial;
|
||||||
|
|
||||||
sc_thread thread;
|
sc_thread thread;
|
||||||
struct sc_server_info info; // initialized once connected
|
struct sc_server_info info; // initialized once connected
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ sc_process_execute_p(const char *const argv[], sc_pid *pid, unsigned flags,
|
|||||||
bool
|
bool
|
||||||
sc_process_terminate(pid_t pid) {
|
sc_process_terminate(pid_t pid) {
|
||||||
if (pid <= 0) {
|
if (pid <= 0) {
|
||||||
LOGC("Requested to kill %d, this is an error. Please report the bug.\n",
|
LOGE("Requested to kill %d, this is an error. Please report the bug.\n",
|
||||||
(int) pid);
|
(int) pid);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,85 +45,9 @@ sc_hid_event_destroy(struct sc_hid_event *hid_event) {
|
|||||||
free(hid_event->buffer);
|
free(hid_event->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
|
||||||
log_libusb_error(enum libusb_error errcode) {
|
|
||||||
LOGW("libusb error: %s", libusb_strerror(errcode));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
accept_device(libusb_device *device, const char *serial) {
|
|
||||||
// do not log any USB error in this function, it is expected that many USB
|
|
||||||
// devices available on the computer have permission restrictions
|
|
||||||
|
|
||||||
struct libusb_device_descriptor desc;
|
|
||||||
libusb_get_device_descriptor(device, &desc);
|
|
||||||
|
|
||||||
if (!desc.iSerialNumber) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
libusb_device_handle *handle;
|
|
||||||
int result = libusb_open(device, &handle);
|
|
||||||
if (result < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buffer[128];
|
|
||||||
result = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber,
|
|
||||||
(unsigned char *) buffer,
|
|
||||||
sizeof(buffer));
|
|
||||||
libusb_close(handle);
|
|
||||||
if (result < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer[sizeof(buffer) - 1] = '\0'; // just in case
|
|
||||||
|
|
||||||
// accept the device if its serial matches
|
|
||||||
return !strcmp(buffer, serial);
|
|
||||||
}
|
|
||||||
|
|
||||||
static libusb_device *
|
|
||||||
sc_aoa_find_usb_device(const char *serial) {
|
|
||||||
if (!serial) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
libusb_device **list;
|
|
||||||
libusb_device *result = NULL;
|
|
||||||
ssize_t count = libusb_get_device_list(NULL, &list);
|
|
||||||
if (count < 0) {
|
|
||||||
log_libusb_error((enum libusb_error) count);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < (size_t) count; ++i) {
|
|
||||||
libusb_device *device = list[i];
|
|
||||||
|
|
||||||
if (accept_device(device, serial)) {
|
|
||||||
result = libusb_ref_device(device);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
libusb_free_device_list(list, 1);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
sc_aoa_open_usb_handle(libusb_device *device, libusb_device_handle **handle) {
|
|
||||||
int result = libusb_open(device, handle);
|
|
||||||
if (result < 0) {
|
|
||||||
log_libusb_error((enum libusb_error) result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_aoa_init(struct sc_aoa *aoa, const char *serial,
|
sc_aoa_init(struct sc_aoa *aoa, struct sc_usb *usb,
|
||||||
struct sc_acksync *acksync) {
|
struct sc_acksync *acksync) {
|
||||||
assert(acksync);
|
|
||||||
|
|
||||||
cbuf_init(&aoa->queue);
|
cbuf_init(&aoa->queue);
|
||||||
|
|
||||||
if (!sc_mutex_init(&aoa->mutex)) {
|
if (!sc_mutex_init(&aoa->mutex)) {
|
||||||
@@ -135,32 +59,9 @@ sc_aoa_init(struct sc_aoa *aoa, const char *serial,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (libusb_init(&aoa->usb_context) != LIBUSB_SUCCESS) {
|
|
||||||
sc_cond_destroy(&aoa->event_cond);
|
|
||||||
sc_mutex_destroy(&aoa->mutex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
aoa->usb_device = sc_aoa_find_usb_device(serial);
|
|
||||||
if (!aoa->usb_device) {
|
|
||||||
LOGW("USB device of serial %s not found", serial);
|
|
||||||
libusb_exit(aoa->usb_context);
|
|
||||||
sc_mutex_destroy(&aoa->mutex);
|
|
||||||
sc_cond_destroy(&aoa->event_cond);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sc_aoa_open_usb_handle(aoa->usb_device, &aoa->usb_handle) < 0) {
|
|
||||||
LOGW("Open USB handle failed");
|
|
||||||
libusb_unref_device(aoa->usb_device);
|
|
||||||
libusb_exit(aoa->usb_context);
|
|
||||||
sc_cond_destroy(&aoa->event_cond);
|
|
||||||
sc_mutex_destroy(&aoa->mutex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
aoa->stopped = false;
|
aoa->stopped = false;
|
||||||
aoa->acksync = acksync;
|
aoa->acksync = acksync;
|
||||||
|
aoa->usb = usb;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -173,9 +74,6 @@ sc_aoa_destroy(struct sc_aoa *aoa) {
|
|||||||
sc_hid_event_destroy(&event);
|
sc_hid_event_destroy(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
libusb_close(aoa->usb_handle);
|
|
||||||
libusb_unref_device(aoa->usb_device);
|
|
||||||
libusb_exit(aoa->usb_context);
|
|
||||||
sc_cond_destroy(&aoa->event_cond);
|
sc_cond_destroy(&aoa->event_cond);
|
||||||
sc_mutex_destroy(&aoa->mutex);
|
sc_mutex_destroy(&aoa->mutex);
|
||||||
}
|
}
|
||||||
@@ -192,11 +90,11 @@ sc_aoa_register_hid(struct sc_aoa *aoa, uint16_t accessory_id,
|
|||||||
uint16_t index = report_desc_size;
|
uint16_t index = report_desc_size;
|
||||||
unsigned char *buffer = NULL;
|
unsigned char *buffer = NULL;
|
||||||
uint16_t length = 0;
|
uint16_t length = 0;
|
||||||
int result = libusb_control_transfer(aoa->usb_handle, request_type, request,
|
int result = libusb_control_transfer(aoa->usb->handle, request_type,
|
||||||
value, index, buffer, length,
|
request, value, index, buffer, length,
|
||||||
DEFAULT_TIMEOUT);
|
DEFAULT_TIMEOUT);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
log_libusb_error((enum libusb_error) result);
|
LOGE("REGISTER_HID: libusb error: %s", libusb_strerror(result));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,11 +126,11 @@ sc_aoa_set_hid_report_desc(struct sc_aoa *aoa, uint16_t accessory_id,
|
|||||||
// libusb_control_transfer expects a pointer to non-const
|
// libusb_control_transfer expects a pointer to non-const
|
||||||
unsigned char *buffer = (unsigned char *) report_desc;
|
unsigned char *buffer = (unsigned char *) report_desc;
|
||||||
uint16_t length = report_desc_size;
|
uint16_t length = report_desc_size;
|
||||||
int result = libusb_control_transfer(aoa->usb_handle, request_type, request,
|
int result = libusb_control_transfer(aoa->usb->handle, request_type,
|
||||||
value, index, buffer, length,
|
request, value, index, buffer, length,
|
||||||
DEFAULT_TIMEOUT);
|
DEFAULT_TIMEOUT);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
log_libusb_error((enum libusb_error) result);
|
LOGE("SET_HID_REPORT_DESC: libusb error: %s", libusb_strerror(result));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,11 +168,11 @@ sc_aoa_send_hid_event(struct sc_aoa *aoa, const struct sc_hid_event *event) {
|
|||||||
uint16_t index = 0;
|
uint16_t index = 0;
|
||||||
unsigned char *buffer = event->buffer;
|
unsigned char *buffer = event->buffer;
|
||||||
uint16_t length = event->size;
|
uint16_t length = event->size;
|
||||||
int result = libusb_control_transfer(aoa->usb_handle, request_type, request,
|
int result = libusb_control_transfer(aoa->usb->handle, request_type,
|
||||||
value, index, buffer, length,
|
request, value, index, buffer, length,
|
||||||
DEFAULT_TIMEOUT);
|
DEFAULT_TIMEOUT);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
log_libusb_error((enum libusb_error) result);
|
LOGE("SEND_HID_EVENT: libusb error: %s", libusb_strerror(result));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,11 +190,11 @@ sc_aoa_unregister_hid(struct sc_aoa *aoa, const uint16_t accessory_id) {
|
|||||||
uint16_t index = 0;
|
uint16_t index = 0;
|
||||||
unsigned char *buffer = NULL;
|
unsigned char *buffer = NULL;
|
||||||
uint16_t length = 0;
|
uint16_t length = 0;
|
||||||
int result = libusb_control_transfer(aoa->usb_handle, request_type, request,
|
int result = libusb_control_transfer(aoa->usb->handle, request_type,
|
||||||
value, index, buffer, length,
|
request, value, index, buffer, length,
|
||||||
DEFAULT_TIMEOUT);
|
DEFAULT_TIMEOUT);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
log_libusb_error((enum libusb_error) result);
|
LOGE("UNREGISTER_HID: libusb error: %s", libusb_strerror(result));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,6 +241,11 @@ run_aoa_thread(void *data) {
|
|||||||
|
|
||||||
if (ack_to_wait != SC_SEQUENCE_INVALID) {
|
if (ack_to_wait != SC_SEQUENCE_INVALID) {
|
||||||
LOGD("Waiting ack from server sequence=%" PRIu64_, ack_to_wait);
|
LOGD("Waiting ack from server sequence=%" PRIu64_, ack_to_wait);
|
||||||
|
|
||||||
|
// If some events have ack_to_wait set, then sc_aoa must have been
|
||||||
|
// initialized with a non NULL acksync
|
||||||
|
assert(aoa->acksync);
|
||||||
|
|
||||||
// Do not block the loop indefinitely if the ack never comes (it
|
// Do not block the loop indefinitely if the ack never comes (it
|
||||||
// should never happen)
|
// should never happen)
|
||||||
sc_tick deadline = sc_tick_now() + SC_TICK_FROM_MS(500);
|
sc_tick deadline = sc_tick_now() + SC_TICK_FROM_MS(500);
|
||||||
@@ -375,7 +278,7 @@ sc_aoa_start(struct sc_aoa *aoa) {
|
|||||||
|
|
||||||
bool ok = sc_thread_create(&aoa->thread, run_aoa_thread, "scrcpy-aoa", aoa);
|
bool ok = sc_thread_create(&aoa->thread, run_aoa_thread, "scrcpy-aoa", aoa);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGC("Could not start AOA thread");
|
LOGE("Could not start AOA thread");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,8 +292,10 @@ sc_aoa_stop(struct sc_aoa *aoa) {
|
|||||||
sc_cond_signal(&aoa->event_cond);
|
sc_cond_signal(&aoa->event_cond);
|
||||||
sc_mutex_unlock(&aoa->mutex);
|
sc_mutex_unlock(&aoa->mutex);
|
||||||
|
|
||||||
|
if (aoa->acksync) {
|
||||||
sc_acksync_interrupt(aoa->acksync);
|
sc_acksync_interrupt(aoa->acksync);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_aoa_join(struct sc_aoa *aoa) {
|
sc_aoa_join(struct sc_aoa *aoa) {
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <libusb-1.0/libusb.h>
|
#include <libusb-1.0/libusb.h>
|
||||||
|
|
||||||
|
#include "usb.h"
|
||||||
#include "util/acksync.h"
|
#include "util/acksync.h"
|
||||||
#include "util/cbuf.h"
|
#include "util/cbuf.h"
|
||||||
#include "util/thread.h"
|
#include "util/thread.h"
|
||||||
@@ -29,9 +30,7 @@ sc_hid_event_destroy(struct sc_hid_event *hid_event);
|
|||||||
struct sc_hid_event_queue CBUF(struct sc_hid_event, 64);
|
struct sc_hid_event_queue CBUF(struct sc_hid_event, 64);
|
||||||
|
|
||||||
struct sc_aoa {
|
struct sc_aoa {
|
||||||
libusb_context *usb_context;
|
struct sc_usb *usb;
|
||||||
libusb_device *usb_device;
|
|
||||||
libusb_device_handle *usb_handle;
|
|
||||||
sc_thread thread;
|
sc_thread thread;
|
||||||
sc_mutex mutex;
|
sc_mutex mutex;
|
||||||
sc_cond event_cond;
|
sc_cond event_cond;
|
||||||
@@ -42,7 +41,7 @@ struct sc_aoa {
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_aoa_init(struct sc_aoa *aoa, const char *serial, struct sc_acksync *acksync);
|
sc_aoa_init(struct sc_aoa *aoa, struct sc_usb *usb, struct sc_acksync *acksync);
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_aoa_destroy(struct sc_aoa *aoa);
|
sc_aoa_destroy(struct sc_aoa *aoa);
|
||||||
@@ -262,6 +262,6 @@ void
|
|||||||
sc_hid_mouse_destroy(struct sc_hid_mouse *mouse) {
|
sc_hid_mouse_destroy(struct sc_hid_mouse *mouse) {
|
||||||
bool ok = sc_aoa_unregister_hid(mouse->aoa, HID_MOUSE_ACCESSORY_ID);
|
bool ok = sc_aoa_unregister_hid(mouse->aoa, HID_MOUSE_ACCESSORY_ID);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGW("Could not unregister HID");
|
LOGW("Could not unregister HID mouse");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef HID_MOUSE_H
|
#ifndef SC_HID_MOUSE_H
|
||||||
#define HID_MOUSE_H
|
#define SC_HID_MOUSE_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
199
app/src/usb/scrcpy_otg.c
Normal file
199
app/src/usb/scrcpy_otg.c
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
#include "scrcpy_otg.h"
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
#include "events.h"
|
||||||
|
#include "screen_otg.h"
|
||||||
|
#include "util/log.h"
|
||||||
|
|
||||||
|
struct scrcpy_otg {
|
||||||
|
struct sc_usb usb;
|
||||||
|
struct sc_aoa aoa;
|
||||||
|
struct sc_hid_keyboard keyboard;
|
||||||
|
struct sc_hid_mouse mouse;
|
||||||
|
|
||||||
|
struct sc_screen_otg screen_otg;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
sc_usb_on_disconnected(struct sc_usb *usb, void *userdata) {
|
||||||
|
(void) usb;
|
||||||
|
(void) userdata;
|
||||||
|
|
||||||
|
SDL_Event event;
|
||||||
|
event.type = EVENT_USB_DEVICE_DISCONNECTED;
|
||||||
|
int ret = SDL_PushEvent(&event);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOGE("Could not post USB disconnection event: %s", SDL_GetError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 false;
|
||||||
|
case SDL_QUIT:
|
||||||
|
LOGD("User requested to quit");
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
sc_screen_otg_handle_event(&s->screen_otg, &event);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
scrcpy_otg(struct scrcpy_options *options) {
|
||||||
|
static struct scrcpy_otg scrcpy_otg;
|
||||||
|
struct scrcpy_otg *s = &scrcpy_otg;
|
||||||
|
|
||||||
|
const char *serial = options->serial;
|
||||||
|
|
||||||
|
// Minimal SDL initialization
|
||||||
|
if (SDL_Init(SDL_INIT_EVENTS)) {
|
||||||
|
LOGE("Could not initialize SDL: %s", SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
atexit(SDL_Quit);
|
||||||
|
|
||||||
|
if (!SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1")) {
|
||||||
|
LOGW("Could not enable mouse focus clickthrough");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
struct sc_hid_keyboard *keyboard = NULL;
|
||||||
|
struct sc_hid_mouse *mouse = NULL;
|
||||||
|
bool usb_device_initialized = false;
|
||||||
|
bool usb_connected = false;
|
||||||
|
bool aoa_started = false;
|
||||||
|
bool aoa_initialized = false;
|
||||||
|
|
||||||
|
static const struct sc_usb_callbacks cbs = {
|
||||||
|
.on_disconnected = sc_usb_on_disconnected,
|
||||||
|
};
|
||||||
|
bool ok = sc_usb_init(&s->usb);
|
||||||
|
if (!ok) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sc_usb_device usb_device;
|
||||||
|
ok = sc_usb_select_device(&s->usb, serial, &usb_device);
|
||||||
|
if (!ok) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGI("USB device: %s (%04" PRIx16 ":%04" PRIx16 ") %s %s",
|
||||||
|
usb_device.serial, usb_device.vid, usb_device.pid,
|
||||||
|
usb_device.manufacturer, usb_device.product);
|
||||||
|
|
||||||
|
ok = sc_usb_connect(&s->usb, usb_device.device, &cbs, NULL);
|
||||||
|
if (!ok) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
usb_connected = true;
|
||||||
|
|
||||||
|
ok = sc_aoa_init(&s->aoa, &s->usb, NULL);
|
||||||
|
if (!ok) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
aoa_initialized = true;
|
||||||
|
|
||||||
|
bool enable_keyboard =
|
||||||
|
options->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_HID;
|
||||||
|
bool enable_mouse =
|
||||||
|
options->mouse_input_mode == SC_MOUSE_INPUT_MODE_HID;
|
||||||
|
|
||||||
|
// If neither --hid-keyboard or --hid-mouse is passed, enable both
|
||||||
|
if (!enable_keyboard && !enable_mouse) {
|
||||||
|
enable_keyboard = true;
|
||||||
|
enable_mouse = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enable_keyboard) {
|
||||||
|
ok = sc_hid_keyboard_init(&s->keyboard, &s->aoa);
|
||||||
|
if (!ok) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
keyboard = &s->keyboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enable_mouse) {
|
||||||
|
ok = sc_hid_mouse_init(&s->mouse, &s->aoa);
|
||||||
|
if (!ok) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
mouse = &s->mouse;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = sc_aoa_start(&s->aoa);
|
||||||
|
if (!ok) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
aoa_started = true;
|
||||||
|
|
||||||
|
const char *window_title = options->window_title;
|
||||||
|
if (!window_title) {
|
||||||
|
window_title = usb_device.product ? usb_device.product : "scrcpy";
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sc_screen_otg_params params = {
|
||||||
|
.keyboard = keyboard,
|
||||||
|
.mouse = mouse,
|
||||||
|
.window_title = window_title,
|
||||||
|
.always_on_top = options->always_on_top,
|
||||||
|
.window_x = options->window_x,
|
||||||
|
.window_y = options->window_y,
|
||||||
|
.window_borderless = options->window_borderless,
|
||||||
|
};
|
||||||
|
|
||||||
|
ok = sc_screen_otg_init(&s->screen_otg, ¶ms);
|
||||||
|
if (!ok) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
// usb_device not needed anymore
|
||||||
|
sc_usb_device_destroy(&usb_device);
|
||||||
|
usb_device_initialized = false;
|
||||||
|
|
||||||
|
ret = event_loop(s);
|
||||||
|
LOGD("quit...");
|
||||||
|
|
||||||
|
end:
|
||||||
|
if (aoa_started) {
|
||||||
|
sc_aoa_stop(&s->aoa);
|
||||||
|
}
|
||||||
|
sc_usb_stop(&s->usb);
|
||||||
|
|
||||||
|
if (mouse) {
|
||||||
|
sc_hid_mouse_destroy(&s->mouse);
|
||||||
|
}
|
||||||
|
if (keyboard) {
|
||||||
|
sc_hid_keyboard_destroy(&s->keyboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aoa_initialized) {
|
||||||
|
sc_aoa_join(&s->aoa);
|
||||||
|
sc_aoa_destroy(&s->aoa);
|
||||||
|
}
|
||||||
|
|
||||||
|
sc_usb_join(&s->usb);
|
||||||
|
|
||||||
|
if (usb_connected) {
|
||||||
|
sc_usb_disconnect(&s->usb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usb_device_initialized) {
|
||||||
|
sc_usb_device_destroy(&usb_device);
|
||||||
|
}
|
||||||
|
|
||||||
|
sc_usb_destroy(&s->usb);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
12
app/src/usb/scrcpy_otg.h
Normal file
12
app/src/usb/scrcpy_otg.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef SCRCPY_OTG_H
|
||||||
|
#define SCRCPY_OTG_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
|
bool
|
||||||
|
scrcpy_otg(struct scrcpy_options *options);
|
||||||
|
|
||||||
|
#endif
|
||||||
267
app/src/usb/screen_otg.c
Normal file
267
app/src/usb/screen_otg.c
Normal file
@@ -0,0 +1,267 @@
|
|||||||
|
#include "screen_otg.h"
|
||||||
|
|
||||||
|
#include "icon.h"
|
||||||
|
#include "options.h"
|
||||||
|
#include "util/log.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
screen->mouse_captured = capture;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sc_screen_otg_render(struct sc_screen_otg *screen) {
|
||||||
|
SDL_RenderClear(screen->renderer);
|
||||||
|
if (screen->texture) {
|
||||||
|
SDL_RenderCopy(screen->renderer, screen->texture, NULL, NULL);
|
||||||
|
}
|
||||||
|
SDL_RenderPresent(screen->renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_screen_otg_init(struct sc_screen_otg *screen,
|
||||||
|
const struct sc_screen_otg_params *params) {
|
||||||
|
screen->keyboard = params->keyboard;
|
||||||
|
screen->mouse = params->mouse;
|
||||||
|
|
||||||
|
screen->mouse_captured = false;
|
||||||
|
screen->mouse_capture_key_pressed = 0;
|
||||||
|
|
||||||
|
const char *title = params->window_title;
|
||||||
|
assert(title);
|
||||||
|
|
||||||
|
int x = params->window_x != SC_WINDOW_POSITION_UNDEFINED
|
||||||
|
? params->window_x : (int) SDL_WINDOWPOS_UNDEFINED;
|
||||||
|
int y = params->window_y != SC_WINDOW_POSITION_UNDEFINED
|
||||||
|
? params->window_y : (int) SDL_WINDOWPOS_UNDEFINED;
|
||||||
|
int width = 256;
|
||||||
|
int height = 256;
|
||||||
|
|
||||||
|
uint32_t window_flags = 0;
|
||||||
|
if (params->always_on_top) {
|
||||||
|
window_flags |= SDL_WINDOW_ALWAYS_ON_TOP;
|
||||||
|
}
|
||||||
|
if (params->window_borderless) {
|
||||||
|
window_flags |= SDL_WINDOW_BORDERLESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
screen->window = SDL_CreateWindow(title, x, y, width, height, window_flags);
|
||||||
|
if (!screen->window) {
|
||||||
|
LOGE("Could not create window: %s", SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
screen->renderer = SDL_CreateRenderer(screen->window, -1, 0);
|
||||||
|
if (!screen->renderer) {
|
||||||
|
LOGE("Could not create renderer: %s", SDL_GetError());
|
||||||
|
goto error_destroy_window;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Surface *icon = scrcpy_icon_load();
|
||||||
|
|
||||||
|
if (icon) {
|
||||||
|
SDL_SetWindowIcon(screen->window, icon);
|
||||||
|
|
||||||
|
screen->texture = SDL_CreateTextureFromSurface(screen->renderer, icon);
|
||||||
|
scrcpy_icon_destroy(icon);
|
||||||
|
if (!screen->texture) {
|
||||||
|
goto error_destroy_renderer;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
screen->texture = NULL;
|
||||||
|
LOGW("Could not load icon");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (screen->mouse) {
|
||||||
|
// Capture mouse on start
|
||||||
|
sc_screen_otg_capture_mouse(screen, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
error_destroy_window:
|
||||||
|
SDL_DestroyWindow(screen->window);
|
||||||
|
error_destroy_renderer:
|
||||||
|
SDL_DestroyRenderer(screen->renderer);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_screen_otg_destroy(struct sc_screen_otg *screen) {
|
||||||
|
if (screen->texture) {
|
||||||
|
SDL_DestroyTexture(screen->texture);
|
||||||
|
}
|
||||||
|
SDL_DestroyRenderer(screen->renderer);
|
||||||
|
SDL_DestroyWindow(screen->window);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
sc_screen_otg_is_mouse_capture_key(SDL_Keycode key) {
|
||||||
|
return key == SDLK_LALT || key == SDLK_LGUI || key == SDLK_RGUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sc_screen_otg_process_key(struct sc_screen_otg *screen,
|
||||||
|
const SDL_KeyboardEvent *event) {
|
||||||
|
assert(screen->keyboard);
|
||||||
|
struct sc_key_processor *kp = &screen->keyboard->key_processor;
|
||||||
|
|
||||||
|
struct sc_key_event evt = {
|
||||||
|
.action = sc_action_from_sdl_keyboard_type(event->type),
|
||||||
|
.keycode = sc_keycode_from_sdl(event->keysym.sym),
|
||||||
|
.scancode = sc_scancode_from_sdl(event->keysym.scancode),
|
||||||
|
.repeat = event->repeat,
|
||||||
|
.mods_state = sc_mods_state_from_sdl(event->keysym.mod),
|
||||||
|
};
|
||||||
|
|
||||||
|
assert(kp->ops->process_key);
|
||||||
|
kp->ops->process_key(kp, &evt, SC_SEQUENCE_INVALID);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sc_screen_otg_process_mouse_motion(struct sc_screen_otg *screen,
|
||||||
|
const SDL_MouseMotionEvent *event) {
|
||||||
|
assert(screen->mouse);
|
||||||
|
struct sc_mouse_processor *mp = &screen->mouse->mouse_processor;
|
||||||
|
|
||||||
|
struct sc_mouse_motion_event evt = {
|
||||||
|
// .position not used for HID events
|
||||||
|
.xrel = event->xrel,
|
||||||
|
.yrel = event->yrel,
|
||||||
|
.buttons_state = sc_mouse_buttons_state_from_sdl(event->state, true),
|
||||||
|
};
|
||||||
|
|
||||||
|
assert(mp->ops->process_mouse_motion);
|
||||||
|
mp->ops->process_mouse_motion(mp, &evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sc_screen_otg_process_mouse_button(struct sc_screen_otg *screen,
|
||||||
|
const SDL_MouseButtonEvent *event) {
|
||||||
|
assert(screen->mouse);
|
||||||
|
struct sc_mouse_processor *mp = &screen->mouse->mouse_processor;
|
||||||
|
|
||||||
|
uint32_t sdl_buttons_state = SDL_GetMouseState(NULL, NULL);
|
||||||
|
|
||||||
|
struct sc_mouse_click_event evt = {
|
||||||
|
// .position not used for HID events
|
||||||
|
.action = sc_action_from_sdl_mousebutton_type(event->type),
|
||||||
|
.button = sc_mouse_button_from_sdl(event->button),
|
||||||
|
.buttons_state =
|
||||||
|
sc_mouse_buttons_state_from_sdl(sdl_buttons_state, true),
|
||||||
|
};
|
||||||
|
|
||||||
|
assert(mp->ops->process_mouse_click);
|
||||||
|
mp->ops->process_mouse_click(mp, &evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sc_screen_otg_process_mouse_wheel(struct sc_screen_otg *screen,
|
||||||
|
const SDL_MouseWheelEvent *event) {
|
||||||
|
assert(screen->mouse);
|
||||||
|
struct sc_mouse_processor *mp = &screen->mouse->mouse_processor;
|
||||||
|
|
||||||
|
uint32_t sdl_buttons_state = SDL_GetMouseState(NULL, NULL);
|
||||||
|
|
||||||
|
struct sc_mouse_scroll_event evt = {
|
||||||
|
// .position not used for HID events
|
||||||
|
.hscroll = event->x,
|
||||||
|
.vscroll = event->y,
|
||||||
|
.buttons_state =
|
||||||
|
sc_mouse_buttons_state_from_sdl(sdl_buttons_state, true),
|
||||||
|
};
|
||||||
|
|
||||||
|
assert(mp->ops->process_mouse_scroll);
|
||||||
|
mp->ops->process_mouse_scroll(mp, &evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_screen_otg_handle_event(struct sc_screen_otg *screen, SDL_Event *event) {
|
||||||
|
switch (event->type) {
|
||||||
|
case SDL_WINDOWEVENT:
|
||||||
|
switch (event->window.event) {
|
||||||
|
case SDL_WINDOWEVENT_EXPOSED:
|
||||||
|
sc_screen_otg_render(screen);
|
||||||
|
break;
|
||||||
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||||
|
if (screen->mouse) {
|
||||||
|
sc_screen_otg_capture_mouse(screen, false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
if (screen->mouse) {
|
||||||
|
SDL_Keycode key = event->key.keysym.sym;
|
||||||
|
if (sc_screen_otg_is_mouse_capture_key(key)) {
|
||||||
|
if (!screen->mouse_capture_key_pressed) {
|
||||||
|
screen->mouse_capture_key_pressed = key;
|
||||||
|
} else {
|
||||||
|
// Another mouse capture key has been pressed, cancel
|
||||||
|
// mouse (un)capture
|
||||||
|
screen->mouse_capture_key_pressed = 0;
|
||||||
|
}
|
||||||
|
// Mouse capture keys are never forwarded to the device
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (screen->keyboard) {
|
||||||
|
sc_screen_otg_process_key(screen, &event->key);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDL_KEYUP:
|
||||||
|
if (screen->mouse) {
|
||||||
|
SDL_Keycode key = event->key.keysym.sym;
|
||||||
|
SDL_Keycode cap = screen->mouse_capture_key_pressed;
|
||||||
|
screen->mouse_capture_key_pressed = 0;
|
||||||
|
if (sc_screen_otg_is_mouse_capture_key(key)) {
|
||||||
|
if (key == cap) {
|
||||||
|
// A mouse capture key has been pressed then released:
|
||||||
|
// toggle the capture mouse mode
|
||||||
|
sc_screen_otg_capture_mouse(screen,
|
||||||
|
!screen->mouse_captured);
|
||||||
|
}
|
||||||
|
// Mouse capture keys are never forwarded to the device
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (screen->keyboard) {
|
||||||
|
sc_screen_otg_process_key(screen, &event->key);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDL_MOUSEMOTION:
|
||||||
|
if (screen->mouse && screen->mouse_captured) {
|
||||||
|
sc_screen_otg_process_mouse_motion(screen, &event->motion);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
if (screen->mouse && screen->mouse_captured) {
|
||||||
|
sc_screen_otg_process_mouse_button(screen, &event->button);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
if (screen->mouse) {
|
||||||
|
if (screen->mouse_captured) {
|
||||||
|
sc_screen_otg_process_mouse_button(screen, &event->button);
|
||||||
|
} else {
|
||||||
|
sc_screen_otg_capture_mouse(screen, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDL_MOUSEWHEEL:
|
||||||
|
if (screen->mouse && screen->mouse_captured) {
|
||||||
|
sc_screen_otg_process_mouse_wheel(screen, &event->wheel);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
46
app/src/usb/screen_otg.h
Normal file
46
app/src/usb/screen_otg.h
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#ifndef SC_SCREEN_OTG_H
|
||||||
|
#define SC_SCREEN_OTG_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
#include "hid_keyboard.h"
|
||||||
|
#include "hid_mouse.h"
|
||||||
|
|
||||||
|
struct sc_screen_otg {
|
||||||
|
struct sc_hid_keyboard *keyboard;
|
||||||
|
struct sc_hid_mouse *mouse;
|
||||||
|
|
||||||
|
SDL_Window *window;
|
||||||
|
SDL_Renderer *renderer;
|
||||||
|
SDL_Texture *texture;
|
||||||
|
|
||||||
|
// See equivalent mechanism in screen.h
|
||||||
|
bool mouse_captured;
|
||||||
|
SDL_Keycode mouse_capture_key_pressed;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sc_screen_otg_params {
|
||||||
|
struct sc_hid_keyboard *keyboard;
|
||||||
|
struct sc_hid_mouse *mouse;
|
||||||
|
|
||||||
|
const char *window_title;
|
||||||
|
bool always_on_top;
|
||||||
|
int16_t window_x; // accepts SC_WINDOW_POSITION_UNDEFINED
|
||||||
|
int16_t window_y; // accepts SC_WINDOW_POSITION_UNDEFINED
|
||||||
|
bool window_borderless;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_screen_otg_init(struct sc_screen_otg *screen,
|
||||||
|
const struct sc_screen_otg_params *params);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_screen_otg_destroy(struct sc_screen_otg *screen);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_screen_otg_handle_event(struct sc_screen_otg *screen, SDL_Event *event);
|
||||||
|
|
||||||
|
#endif
|
||||||
341
app/src/usb/usb.c
Normal file
341
app/src/usb/usb.c
Normal file
@@ -0,0 +1,341 @@
|
|||||||
|
#include "usb.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "util/log.h"
|
||||||
|
|
||||||
|
static char *
|
||||||
|
read_string(libusb_device_handle *handle, uint8_t desc_index) {
|
||||||
|
char buffer[128];
|
||||||
|
int result =
|
||||||
|
libusb_get_string_descriptor_ascii(handle, desc_index,
|
||||||
|
(unsigned char *) buffer,
|
||||||
|
sizeof(buffer));
|
||||||
|
if (result < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert((size_t) result <= sizeof(buffer));
|
||||||
|
|
||||||
|
// When non-negative, 'result' contains the number of bytes written
|
||||||
|
char *s = malloc(result + 1);
|
||||||
|
memcpy(s, buffer, result);
|
||||||
|
s[result] = '\0';
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
sc_usb_read_device(libusb_device *device, struct sc_usb_device *out) {
|
||||||
|
// Do not log any USB error in this function, it is expected that many USB
|
||||||
|
// devices available on the computer have permission restrictions
|
||||||
|
|
||||||
|
struct libusb_device_descriptor desc;
|
||||||
|
int result = libusb_get_device_descriptor(device, &desc);
|
||||||
|
if (result < 0 || !desc.iSerialNumber) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
libusb_device_handle *handle;
|
||||||
|
result = libusb_open(device, &handle);
|
||||||
|
if (result < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *device_serial = read_string(handle, desc.iSerialNumber);
|
||||||
|
if (!device_serial) {
|
||||||
|
libusb_close(handle);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
out->device = libusb_ref_device(device);
|
||||||
|
out->serial = device_serial;
|
||||||
|
out->vid = desc.idVendor;
|
||||||
|
out->pid = desc.idProduct;
|
||||||
|
out->manufacturer = read_string(handle, desc.iManufacturer);
|
||||||
|
out->product = read_string(handle, desc.iProduct);
|
||||||
|
out->selected = false;
|
||||||
|
|
||||||
|
libusb_close(handle);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_usb_device_destroy(struct sc_usb_device *usb_device) {
|
||||||
|
if (usb_device->device) {
|
||||||
|
libusb_unref_device(usb_device->device);
|
||||||
|
}
|
||||||
|
free(usb_device->serial);
|
||||||
|
free(usb_device->manufacturer);
|
||||||
|
free(usb_device->product);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_usb_device_move(struct sc_usb_device *dst, struct sc_usb_device *src) {
|
||||||
|
*dst = *src;
|
||||||
|
src->device = NULL;
|
||||||
|
src->serial = NULL;
|
||||||
|
src->manufacturer = NULL;
|
||||||
|
src->product = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t idx = 0;
|
||||||
|
for (size_t i = 0; i < (size_t) count && idx < len; ++i) {
|
||||||
|
libusb_device *device = list[i];
|
||||||
|
|
||||||
|
if (sc_usb_read_device(device, &devices[idx])) {
|
||||||
|
++idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
libusb_free_device_list(list, 1);
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
sc_usb_accept_device(const struct sc_usb_device *device, const char *serial) {
|
||||||
|
if (!serial) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !strcmp(serial, device->serial);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
sc_usb_devices_select(struct sc_usb_device *devices, size_t len,
|
||||||
|
const char *serial, size_t *idx_out) {
|
||||||
|
size_t count = 0;
|
||||||
|
for (size_t i = 0; i < len; ++i) {
|
||||||
|
struct sc_usb_device *device = &devices[i];
|
||||||
|
device->selected = sc_usb_accept_device(device, serial);
|
||||||
|
if (device->selected) {
|
||||||
|
if (idx_out && !count) {
|
||||||
|
*idx_out = i;
|
||||||
|
}
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sc_usb_devices_log(enum sc_log_level level, struct sc_usb_device *devices,
|
||||||
|
size_t count) {
|
||||||
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
struct sc_usb_device *d = &devices[i];
|
||||||
|
const char *selection = d->selected ? "-->" : " ";
|
||||||
|
LOG(level, " %s %-18s (%04" PRIx16 ":%04" PRIx16 ") %s %s",
|
||||||
|
selection, d->serial, d->vid, d->pid, d->manufacturer, d->product);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_usb_select_device(struct sc_usb *usb, const char *serial,
|
||||||
|
struct sc_usb_device *out_device) {
|
||||||
|
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 (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(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, usb_devices, count);
|
||||||
|
sc_usb_devices_destroy_all(usb_devices, count);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sel_count > 1) {
|
||||||
|
if (serial) {
|
||||||
|
LOGE("Multiple (%" SC_PRIsizet ") USB devices with serial %s:",
|
||||||
|
sel_count, serial);
|
||||||
|
} else {
|
||||||
|
LOGE("Multiple (%" SC_PRIsizet ") USB devices:", sel_count);
|
||||||
|
}
|
||||||
|
sc_usb_devices_log(SC_LOG_LEVEL_ERROR, usb_devices, count);
|
||||||
|
LOGE("Select a device via -s (--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 = &usb_devices[sel_idx];
|
||||||
|
|
||||||
|
LOGD("USB device found:");
|
||||||
|
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_all(usb_devices, count);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_usb_init(struct sc_usb *usb) {
|
||||||
|
usb->handle = NULL;
|
||||||
|
return libusb_init(&usb->context) == LIBUSB_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_usb_destroy(struct sc_usb *usb) {
|
||||||
|
libusb_exit(usb->context);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
sc_usb_libusb_callback(libusb_context *ctx, libusb_device *device,
|
||||||
|
libusb_hotplug_event event, void *userdata) {
|
||||||
|
(void) ctx;
|
||||||
|
(void) device;
|
||||||
|
(void) event;
|
||||||
|
|
||||||
|
struct sc_usb *usb = userdata;
|
||||||
|
|
||||||
|
libusb_device *dev = libusb_get_device(usb->handle);
|
||||||
|
assert(dev);
|
||||||
|
if (dev != device) {
|
||||||
|
// Not the connected device
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
// event thread: <https://stackoverflow.com/a/60119225/1987178>
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
run_libusb_event_handler(void *data) {
|
||||||
|
struct sc_usb *usb = data;
|
||||||
|
while (!atomic_load(&usb->stopped)) {
|
||||||
|
// Interrupted by events or by libusb_hotplug_deregister_callback()
|
||||||
|
libusb_handle_events(usb->context);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
sc_usb_register_callback(struct sc_usb *usb) {
|
||||||
|
if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
|
||||||
|
LOGW("libusb does not have hotplug capability");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
libusb_device *device = libusb_get_device(usb->handle);
|
||||||
|
assert(device);
|
||||||
|
|
||||||
|
struct libusb_device_descriptor desc;
|
||||||
|
int result = libusb_get_device_descriptor(device, &desc);
|
||||||
|
if (result < 0) {
|
||||||
|
LOGE("Device descriptor: libusb error: %s", libusb_strerror(result));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int events = LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT;
|
||||||
|
int flags = LIBUSB_HOTPLUG_NO_FLAGS;
|
||||||
|
int vendor_id = desc.idVendor;
|
||||||
|
int product_id = desc.idProduct;
|
||||||
|
int dev_class = LIBUSB_HOTPLUG_MATCH_ANY;
|
||||||
|
result = libusb_hotplug_register_callback(usb->context, events, flags,
|
||||||
|
vendor_id, product_id, dev_class,
|
||||||
|
sc_usb_libusb_callback, usb,
|
||||||
|
&usb->callback_handle);
|
||||||
|
if (result < 0) {
|
||||||
|
LOGE("Register hotplog callback: libusb error: %s",
|
||||||
|
libusb_strerror(result));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
usb->has_callback_handle = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_usb_connect(struct sc_usb *usb, libusb_device *device,
|
||||||
|
const struct sc_usb_callbacks *cbs, void *cbs_userdata) {
|
||||||
|
int result = libusb_open(device, &usb->handle);
|
||||||
|
if (result < 0) {
|
||||||
|
LOGE("Open USB device: libusb error: %s", libusb_strerror(result));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
usb->has_callback_handle = false;
|
||||||
|
usb->has_libusb_event_thread = false;
|
||||||
|
|
||||||
|
// If cbs is set, then cbs->on_disconnected must be set
|
||||||
|
assert(!cbs || cbs->on_disconnected);
|
||||||
|
usb->cbs = cbs;
|
||||||
|
usb->cbs_userdata = cbs_userdata;
|
||||||
|
|
||||||
|
if (cbs) {
|
||||||
|
atomic_init(&usb->stopped, false);
|
||||||
|
if (sc_usb_register_callback(usb)) {
|
||||||
|
// Create a thread to process libusb events, so that device
|
||||||
|
// disconnection could be detected immediately
|
||||||
|
usb->has_libusb_event_thread =
|
||||||
|
sc_thread_create(&usb->libusb_event_thread,
|
||||||
|
run_libusb_event_handler, "scrcpy-usbev", usb);
|
||||||
|
if (!usb->has_libusb_event_thread) {
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_usb_disconnect(struct sc_usb *usb) {
|
||||||
|
libusb_close(usb->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_usb_stop(struct sc_usb *usb) {
|
||||||
|
if (usb->has_callback_handle) {
|
||||||
|
atomic_store(&usb->stopped, true);
|
||||||
|
libusb_hotplug_deregister_callback(usb->context, usb->callback_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_usb_join(struct sc_usb *usb) {
|
||||||
|
if (usb->has_libusb_event_thread) {
|
||||||
|
sc_thread_join(&usb->libusb_event_thread, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
82
app/src/usb/usb.h
Normal file
82
app/src/usb/usb.h
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#ifndef SC_USB_H
|
||||||
|
#define SC_USB_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <libusb-1.0/libusb.h>
|
||||||
|
|
||||||
|
#include "util/thread.h"
|
||||||
|
|
||||||
|
struct sc_usb {
|
||||||
|
libusb_context *context;
|
||||||
|
libusb_device_handle *handle;
|
||||||
|
|
||||||
|
const struct sc_usb_callbacks *cbs;
|
||||||
|
void *cbs_userdata;
|
||||||
|
|
||||||
|
bool has_callback_handle;
|
||||||
|
libusb_hotplug_callback_handle callback_handle;
|
||||||
|
|
||||||
|
bool has_libusb_event_thread;
|
||||||
|
sc_thread libusb_event_thread;
|
||||||
|
|
||||||
|
atomic_bool stopped; // only used if cbs != NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sc_usb_callbacks {
|
||||||
|
void (*on_disconnected)(struct sc_usb *usb, void *userdata);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sc_usb_device {
|
||||||
|
libusb_device *device;
|
||||||
|
char *serial;
|
||||||
|
char *manufacturer;
|
||||||
|
char *product;
|
||||||
|
uint16_t vid;
|
||||||
|
uint16_t pid;
|
||||||
|
bool selected;
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_usb_device_destroy(struct sc_usb_device *usb_device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move src to dst
|
||||||
|
*
|
||||||
|
* After this call, the content of src is undefined, except that
|
||||||
|
* sc_usb_device_destroy() can be called.
|
||||||
|
*
|
||||||
|
* This is useful to take a device from a list that will be destroyed, without
|
||||||
|
* making unnecessary copies.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
sc_usb_device_move(struct sc_usb_device *dst, struct sc_usb_device *src);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_usb_devices_destroy_all(struct sc_usb_device *usb_devices, size_t count);
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_usb_init(struct sc_usb *usb);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_usb_destroy(struct sc_usb *usb);
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_usb_select_device(struct sc_usb *usb, const char *serial,
|
||||||
|
struct sc_usb_device *out_device);
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_usb_connect(struct sc_usb *usb, libusb_device *device,
|
||||||
|
const struct sc_usb_callbacks *cbs, void *cbs_userdata);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_usb_disconnect(struct sc_usb *usb);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_usb_stop(struct sc_usb *usb);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_usb_join(struct sc_usb *usb);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
# include <windows.h>
|
||||||
|
#endif
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
static SDL_LogPriority
|
static SDL_LogPriority
|
||||||
@@ -51,3 +54,34 @@ sc_get_log_level(void) {
|
|||||||
SDL_LogPriority sdl_log = SDL_LogGetPriority(SDL_LOG_CATEGORY_APPLICATION);
|
SDL_LogPriority sdl_log = SDL_LogGetPriority(SDL_LOG_CATEGORY_APPLICATION);
|
||||||
return log_level_sdl_to_sc(sdl_log);
|
return log_level_sdl_to_sc(sdl_log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_log(enum sc_log_level level, const char *fmt, ...) {
|
||||||
|
SDL_LogPriority sdl_level = log_level_sc_to_sdl(level);
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, sdl_level, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
bool
|
||||||
|
sc_log_windows_error(const char *prefix, int error) {
|
||||||
|
assert(prefix);
|
||||||
|
|
||||||
|
char *message;
|
||||||
|
DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM;
|
||||||
|
DWORD lang_id = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
|
||||||
|
int ret =
|
||||||
|
FormatMessage(flags, NULL, error, lang_id, (char *) &message, 0, NULL);
|
||||||
|
if (ret <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: message already contains a trailing '\n'
|
||||||
|
LOGE("%s: [%d] %s", prefix, error, message);
|
||||||
|
LocalFree(message);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -15,10 +15,9 @@
|
|||||||
#define LOGI(...) SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
#define LOGI(...) SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||||
#define LOGW(...) SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
#define LOGW(...) SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||||
#define LOGE(...) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
#define LOGE(...) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||||
#define LOGC(...) SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
|
||||||
|
|
||||||
#define LOG_OOM() \
|
#define LOG_OOM() \
|
||||||
LOGC("OOM: %s:%d %s()", __FILE__, __LINE__, __func__)
|
LOGE("OOM: %s:%d %s()", __FILE__, __LINE__, __func__)
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_set_log_level(enum sc_log_level level);
|
sc_set_log_level(enum sc_log_level level);
|
||||||
@@ -26,4 +25,14 @@ sc_set_log_level(enum sc_log_level level);
|
|||||||
enum sc_log_level
|
enum sc_log_level
|
||||||
sc_get_log_level(void);
|
sc_get_log_level(void);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_log(enum sc_log_level level, const char *fmt, ...);
|
||||||
|
#define LOG(LEVEL, ...) sc_log((LEVEL), __VA_ARGS__)
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Log system error (typically returned by GetLastError() or similar)
|
||||||
|
bool
|
||||||
|
sc_log_windows_error(const char *prefix, int error);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ net_init(void) {
|
|||||||
WSADATA wsa;
|
WSADATA wsa;
|
||||||
int res = WSAStartup(MAKEWORD(2, 2), &wsa) < 0;
|
int res = WSAStartup(MAKEWORD(2, 2), &wsa) < 0;
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
LOGC("WSAStartup failed with error %d", res);
|
LOGE("WSAStartup failed with error %d", res);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -117,14 +117,7 @@ set_cloexec_flag(sc_raw_socket raw_sock) {
|
|||||||
static void
|
static void
|
||||||
net_perror(const char *s) {
|
net_perror(const char *s) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int error = WSAGetLastError();
|
sc_log_windows_error(s, WSAGetLastError());
|
||||||
char *wsa_message;
|
|
||||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
|
||||||
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
||||||
(char *) &wsa_message, 0, NULL);
|
|
||||||
// no explicit '\n', wsa_message already contains a trailing '\n'
|
|
||||||
fprintf(stderr, "%s: [%d] %s", s, error, wsa_message);
|
|
||||||
LocalFree(wsa_message);
|
|
||||||
#else
|
#else
|
||||||
perror(s);
|
perror(s);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,10 +12,8 @@
|
|||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
# define SC_PRIexitcode "lu"
|
# define SC_PRIexitcode "lu"
|
||||||
// <https://stackoverflow.com/a/44383330/1987178>
|
|
||||||
# define SC_PRIsizet "Iu"
|
|
||||||
# define SC_PROCESS_NONE NULL
|
# define SC_PROCESS_NONE NULL
|
||||||
# define SC_EXIT_CODE_NONE -1u // max value as unsigned
|
# define SC_EXIT_CODE_NONE -1UL // max value as unsigned long
|
||||||
typedef HANDLE sc_pid;
|
typedef HANDLE sc_pid;
|
||||||
typedef DWORD sc_exit_code;
|
typedef DWORD sc_exit_code;
|
||||||
typedef HANDLE sc_pipe;
|
typedef HANDLE sc_pipe;
|
||||||
@@ -23,7 +21,6 @@
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# define SC_PRIsizet "zu"
|
|
||||||
# define SC_PRIexitcode "d"
|
# define SC_PRIexitcode "d"
|
||||||
# define SC_PROCESS_NONE -1
|
# define SC_PROCESS_NONE -1
|
||||||
# define SC_EXIT_CODE_NONE -1
|
# define SC_EXIT_CODE_NONE -1
|
||||||
|
|||||||
@@ -297,14 +297,6 @@ error:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
|
||||||
sc_str_truncate(char *data, size_t len, const char *endchars) {
|
|
||||||
data[len - 1] = '\0';
|
|
||||||
size_t idx = strcspn(data, endchars);
|
|
||||||
data[idx] = '\0';
|
|
||||||
return idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
sc_str_index_of_column(const char *s, unsigned col, const char *seps) {
|
sc_str_index_of_column(const char *s, unsigned col, const char *seps) {
|
||||||
size_t colidx = 0;
|
size_t colidx = 0;
|
||||||
|
|||||||
@@ -103,17 +103,6 @@ sc_str_from_wchars(const wchar_t *s);
|
|||||||
char *
|
char *
|
||||||
sc_str_wrap_lines(const char *input, unsigned columns, unsigned indent);
|
sc_str_wrap_lines(const char *input, unsigned columns, unsigned indent);
|
||||||
|
|
||||||
/**
|
|
||||||
* Truncate the data after any of the characters from `endchars`
|
|
||||||
*
|
|
||||||
* An '\0' is always written at the end of the data, even if no newline
|
|
||||||
* character is encountered.
|
|
||||||
*
|
|
||||||
* Return the size of the resulting line.
|
|
||||||
*/
|
|
||||||
size_t
|
|
||||||
sc_str_truncate(char *data, size_t len, const char *endchars);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the start of a column in a string
|
* Find the start of a column in a string
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ sc_mutex_lock(sc_mutex *mutex) {
|
|||||||
int r = SDL_LockMutex(mutex->mutex);
|
int r = SDL_LockMutex(mutex->mutex);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (r) {
|
if (r) {
|
||||||
LOGC("Could not lock mutex: %s", SDL_GetError());
|
LOGE("Could not lock mutex: %s", SDL_GetError());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ sc_mutex_unlock(sc_mutex *mutex) {
|
|||||||
int r = SDL_UnlockMutex(mutex->mutex);
|
int r = SDL_UnlockMutex(mutex->mutex);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (r) {
|
if (r) {
|
||||||
LOGC("Could not lock mutex: %s", SDL_GetError());
|
LOGE("Could not lock mutex: %s", SDL_GetError());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -118,7 +118,7 @@ sc_cond_wait(sc_cond *cond, sc_mutex *mutex) {
|
|||||||
int r = SDL_CondWait(cond->cond, mutex->mutex);
|
int r = SDL_CondWait(cond->cond, mutex->mutex);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (r) {
|
if (r) {
|
||||||
LOGC("Could not wait on condition: %s", SDL_GetError());
|
LOGE("Could not wait on condition: %s", SDL_GetError());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ sc_cond_timedwait(sc_cond *cond, sc_mutex *mutex, sc_tick deadline) {
|
|||||||
int r = SDL_CondWaitTimeout(cond->cond, mutex->mutex, ms);
|
int r = SDL_CondWaitTimeout(cond->cond, mutex->mutex, ms);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
LOGC("Could not wait on condition with timeout: %s", SDL_GetError());
|
LOGE("Could not wait on condition with timeout: %s", SDL_GetError());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ sc_cond_signal(sc_cond *cond) {
|
|||||||
int r = SDL_CondSignal(cond->cond);
|
int r = SDL_CondSignal(cond->cond);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (r) {
|
if (r) {
|
||||||
LOGC("Could not signal a condition: %s", SDL_GetError());
|
LOGE("Could not signal a condition: %s", SDL_GetError());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -169,7 +169,7 @@ sc_cond_broadcast(sc_cond *cond) {
|
|||||||
int r = SDL_CondBroadcast(cond->cond);
|
int r = SDL_CondBroadcast(cond->cond);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (r) {
|
if (r) {
|
||||||
LOGC("Could not broadcast a condition: %s", SDL_GetError());
|
LOGE("Could not broadcast a condition: %s", SDL_GetError());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
|
|||||||
LOGD("Starting v4l2 thread");
|
LOGD("Starting v4l2 thread");
|
||||||
ok = sc_thread_create(&vs->thread, run_v4l2_sink, "scrcpy-v4l2", vs);
|
ok = sc_thread_create(&vs->thread, run_v4l2_sink, "scrcpy-v4l2", vs);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGC("Could not start v4l2 thread");
|
LOGE("Could not start v4l2 thread");
|
||||||
goto error_av_packet_free;
|
goto error_av_packet_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,163 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "adb_parser.h"
|
#include "adb/adb_device.h"
|
||||||
|
#include "adb/adb_parser.h"
|
||||||
|
|
||||||
|
static void test_adb_devices() {
|
||||||
|
char output[] =
|
||||||
|
"List of devices attached\n"
|
||||||
|
"0123456789abcdef device usb:2-1 product:MyProduct model:MyModel "
|
||||||
|
"device:MyDevice transport_id:1\n"
|
||||||
|
"192.168.1.1:5555 device product:MyWifiProduct model:MyWifiModel "
|
||||||
|
"device:MyWifiDevice trandport_id:2\n";
|
||||||
|
|
||||||
|
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 = &devices[0];
|
||||||
|
assert(!strcmp("0123456789abcdef", device->serial));
|
||||||
|
assert(!strcmp("device", device->state));
|
||||||
|
assert(!strcmp("MyModel", device->model));
|
||||||
|
|
||||||
|
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_all(devices, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_adb_devices_cr() {
|
||||||
|
char output[] =
|
||||||
|
"List of devices attached\r\n"
|
||||||
|
"0123456789abcdef device usb:2-1 product:MyProduct model:MyModel "
|
||||||
|
"device:MyDevice transport_id:1\r\n"
|
||||||
|
"192.168.1.1:5555 device product:MyWifiProduct model:MyWifiModel "
|
||||||
|
"device:MyWifiDevice trandport_id:2\r\n";
|
||||||
|
|
||||||
|
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 = &devices[0];
|
||||||
|
assert(!strcmp("0123456789abcdef", device->serial));
|
||||||
|
assert(!strcmp("device", device->state));
|
||||||
|
assert(!strcmp("MyModel", device->model));
|
||||||
|
|
||||||
|
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_all(devices, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_adb_devices_daemon_start() {
|
||||||
|
char output[] =
|
||||||
|
"* daemon not running; starting now at tcp:5037\n"
|
||||||
|
"* daemon started successfully\n"
|
||||||
|
"List of devices attached\n"
|
||||||
|
"0123456789abcdef device usb:2-1 product:MyProduct model:MyModel "
|
||||||
|
"device:MyDevice transport_id:1\n";
|
||||||
|
|
||||||
|
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 = &devices[0];
|
||||||
|
assert(!strcmp("0123456789abcdef", device->serial));
|
||||||
|
assert(!strcmp("device", device->state));
|
||||||
|
assert(!strcmp("MyModel", device->model));
|
||||||
|
|
||||||
|
sc_adb_device_destroy(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_adb_devices_daemon_start_mixed() {
|
||||||
|
char output[] =
|
||||||
|
"List of devices attached\n"
|
||||||
|
"adb server version (41) doesn't match this client (39); killing...\n"
|
||||||
|
"* daemon started successfully *\n"
|
||||||
|
"0123456789abcdef unauthorized usb:1-1\n"
|
||||||
|
"87654321 device usb:2-1 product:MyProduct model:MyModel "
|
||||||
|
"device:MyDevice\n";
|
||||||
|
|
||||||
|
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 = &devices[0];
|
||||||
|
assert(!strcmp("0123456789abcdef", device->serial));
|
||||||
|
assert(!strcmp("unauthorized", device->state));
|
||||||
|
fprintf(stderr, "==== [%s]\n", device->model);
|
||||||
|
assert(!device->model);
|
||||||
|
|
||||||
|
device = &devices[1];
|
||||||
|
assert(!strcmp("87654321", device->serial));
|
||||||
|
assert(!strcmp("device", device->state));
|
||||||
|
assert(!strcmp("MyModel", device->model));
|
||||||
|
|
||||||
|
sc_adb_devices_destroy_all(devices, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_adb_devices_without_eol() {
|
||||||
|
char output[] =
|
||||||
|
"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_adb_device *device = &devices[0];
|
||||||
|
assert(!strcmp("0123456789abcdef", device->serial));
|
||||||
|
assert(!strcmp("device", device->state));
|
||||||
|
assert(!strcmp("MyModel", device->model));
|
||||||
|
|
||||||
|
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_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_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() {
|
||||||
|
char output[] =
|
||||||
|
"List of devices attached\n"
|
||||||
|
"0123456789abcdef unauthorized usb:1-4 transport_id:3\n";
|
||||||
|
|
||||||
|
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 = &devices[0];
|
||||||
|
assert(!strcmp("0123456789abcdef", device->serial));
|
||||||
|
assert(!strcmp("unauthorized", device->state));
|
||||||
|
assert(!device->model);
|
||||||
|
|
||||||
|
sc_adb_device_destroy(device);
|
||||||
|
}
|
||||||
|
|
||||||
static void test_get_ip_single_line() {
|
static void test_get_ip_single_line() {
|
||||||
char ip_route[] = "192.168.1.0/24 dev wlan0 proto kernel scope link src "
|
char ip_route[] = "192.168.1.0/24 dev wlan0 proto kernel scope link src "
|
||||||
"192.168.12.34\r\r\n";
|
"192.168.12.34\r\r\n";
|
||||||
|
|
||||||
char *ip = sc_adb_parse_device_ip_from_output(ip_route, sizeof(ip_route));
|
char *ip = sc_adb_parse_device_ip_from_output(ip_route);
|
||||||
assert(ip);
|
assert(ip);
|
||||||
assert(!strcmp(ip, "192.168.12.34"));
|
assert(!strcmp(ip, "192.168.12.34"));
|
||||||
free(ip);
|
free(ip);
|
||||||
@@ -18,7 +168,7 @@ static void test_get_ip_single_line_without_eol() {
|
|||||||
char ip_route[] = "192.168.1.0/24 dev wlan0 proto kernel scope link src "
|
char ip_route[] = "192.168.1.0/24 dev wlan0 proto kernel scope link src "
|
||||||
"192.168.12.34";
|
"192.168.12.34";
|
||||||
|
|
||||||
char *ip = sc_adb_parse_device_ip_from_output(ip_route, sizeof(ip_route));
|
char *ip = sc_adb_parse_device_ip_from_output(ip_route);
|
||||||
assert(ip);
|
assert(ip);
|
||||||
assert(!strcmp(ip, "192.168.12.34"));
|
assert(!strcmp(ip, "192.168.12.34"));
|
||||||
free(ip);
|
free(ip);
|
||||||
@@ -28,7 +178,7 @@ static void test_get_ip_single_line_with_trailing_space() {
|
|||||||
char ip_route[] = "192.168.1.0/24 dev wlan0 proto kernel scope link src "
|
char ip_route[] = "192.168.1.0/24 dev wlan0 proto kernel scope link src "
|
||||||
"192.168.12.34 \n";
|
"192.168.12.34 \n";
|
||||||
|
|
||||||
char *ip = sc_adb_parse_device_ip_from_output(ip_route, sizeof(ip_route));
|
char *ip = sc_adb_parse_device_ip_from_output(ip_route);
|
||||||
assert(ip);
|
assert(ip);
|
||||||
assert(!strcmp(ip, "192.168.12.34"));
|
assert(!strcmp(ip, "192.168.12.34"));
|
||||||
free(ip);
|
free(ip);
|
||||||
@@ -40,7 +190,7 @@ static void test_get_ip_multiline_first_ok() {
|
|||||||
"10.0.0.0/24 dev rmnet proto kernel scope link src "
|
"10.0.0.0/24 dev rmnet proto kernel scope link src "
|
||||||
"10.0.0.2\r\n";
|
"10.0.0.2\r\n";
|
||||||
|
|
||||||
char *ip = sc_adb_parse_device_ip_from_output(ip_route, sizeof(ip_route));
|
char *ip = sc_adb_parse_device_ip_from_output(ip_route);
|
||||||
assert(ip);
|
assert(ip);
|
||||||
assert(!strcmp(ip, "192.168.1.2"));
|
assert(!strcmp(ip, "192.168.1.2"));
|
||||||
free(ip);
|
free(ip);
|
||||||
@@ -52,7 +202,7 @@ static void test_get_ip_multiline_second_ok() {
|
|||||||
"192.168.1.0/24 dev wlan0 proto kernel scope link src "
|
"192.168.1.0/24 dev wlan0 proto kernel scope link src "
|
||||||
"192.168.1.3\r\n";
|
"192.168.1.3\r\n";
|
||||||
|
|
||||||
char *ip = sc_adb_parse_device_ip_from_output(ip_route, sizeof(ip_route));
|
char *ip = sc_adb_parse_device_ip_from_output(ip_route);
|
||||||
assert(ip);
|
assert(ip);
|
||||||
assert(!strcmp(ip, "192.168.1.3"));
|
assert(!strcmp(ip, "192.168.1.3"));
|
||||||
free(ip);
|
free(ip);
|
||||||
@@ -62,7 +212,15 @@ static void test_get_ip_no_wlan() {
|
|||||||
char ip_route[] = "192.168.1.0/24 dev rmnet proto kernel scope link src "
|
char ip_route[] = "192.168.1.0/24 dev rmnet proto kernel scope link src "
|
||||||
"192.168.12.34\r\r\n";
|
"192.168.12.34\r\r\n";
|
||||||
|
|
||||||
char *ip = sc_adb_parse_device_ip_from_output(ip_route, sizeof(ip_route));
|
char *ip = sc_adb_parse_device_ip_from_output(ip_route);
|
||||||
|
assert(!ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_get_ip_no_wlan_without_eol() {
|
||||||
|
char ip_route[] = "192.168.1.0/24 dev rmnet proto kernel scope link src "
|
||||||
|
"192.168.12.34";
|
||||||
|
|
||||||
|
char *ip = sc_adb_parse_device_ip_from_output(ip_route);
|
||||||
assert(!ip);
|
assert(!ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +228,7 @@ static void test_get_ip_truncated() {
|
|||||||
char ip_route[] = "192.168.1.0/24 dev rmnet proto kernel scope link src "
|
char ip_route[] = "192.168.1.0/24 dev rmnet proto kernel scope link src "
|
||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
char *ip = sc_adb_parse_device_ip_from_output(ip_route, sizeof(ip_route));
|
char *ip = sc_adb_parse_device_ip_from_output(ip_route);
|
||||||
assert(!ip);
|
assert(!ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,11 +236,21 @@ int main(int argc, char *argv[]) {
|
|||||||
(void) argc;
|
(void) argc;
|
||||||
(void) argv;
|
(void) argv;
|
||||||
|
|
||||||
|
test_adb_devices();
|
||||||
|
test_adb_devices_cr();
|
||||||
|
test_adb_devices_daemon_start();
|
||||||
|
test_adb_devices_daemon_start_mixed();
|
||||||
|
test_adb_devices_without_eol();
|
||||||
|
test_adb_devices_without_header();
|
||||||
|
test_adb_devices_corrupted();
|
||||||
|
test_adb_devices_spaces();
|
||||||
|
|
||||||
test_get_ip_single_line();
|
test_get_ip_single_line();
|
||||||
test_get_ip_single_line_without_eol();
|
test_get_ip_single_line_without_eol();
|
||||||
test_get_ip_single_line_with_trailing_space();
|
test_get_ip_single_line_with_trailing_space();
|
||||||
test_get_ip_multiline_first_ok();
|
test_get_ip_multiline_first_ok();
|
||||||
test_get_ip_multiline_second_ok();
|
test_get_ip_multiline_second_ok();
|
||||||
test_get_ip_no_wlan();
|
test_get_ip_no_wlan();
|
||||||
|
test_get_ip_no_wlan_without_eol();
|
||||||
test_get_ip_truncated();
|
test_get_ip_truncated();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
static void test_serialize_inject_keycode(void) {
|
static void test_serialize_inject_keycode(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
.type = SC_CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
||||||
.inject_keycode = {
|
.inject_keycode = {
|
||||||
.action = AKEY_EVENT_ACTION_UP,
|
.action = AKEY_EVENT_ACTION_UP,
|
||||||
.keycode = AKEYCODE_ENTER,
|
.keycode = AKEYCODE_ENTER,
|
||||||
@@ -16,12 +16,12 @@ static void test_serialize_inject_keycode(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 14);
|
assert(size == 14);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
SC_CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
||||||
0x01, // AKEY_EVENT_ACTION_UP
|
0x01, // AKEY_EVENT_ACTION_UP
|
||||||
0x00, 0x00, 0x00, 0x42, // AKEYCODE_ENTER
|
0x00, 0x00, 0x00, 0x42, // AKEYCODE_ENTER
|
||||||
0x00, 0x00, 0x00, 0X05, // repeat
|
0x00, 0x00, 0x00, 0X05, // repeat
|
||||||
@@ -32,18 +32,18 @@ static void test_serialize_inject_keycode(void) {
|
|||||||
|
|
||||||
static void test_serialize_inject_text(void) {
|
static void test_serialize_inject_text(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_INJECT_TEXT,
|
.type = SC_CONTROL_MSG_TYPE_INJECT_TEXT,
|
||||||
.inject_text = {
|
.inject_text = {
|
||||||
.text = "hello, world!",
|
.text = "hello, world!",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 18);
|
assert(size == 18);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_INJECT_TEXT,
|
SC_CONTROL_MSG_TYPE_INJECT_TEXT,
|
||||||
0x00, 0x00, 0x00, 0x0d, // text length
|
0x00, 0x00, 0x00, 0x0d, // text length
|
||||||
'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', // text
|
'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', // text
|
||||||
};
|
};
|
||||||
@@ -52,30 +52,30 @@ static void test_serialize_inject_text(void) {
|
|||||||
|
|
||||||
static void test_serialize_inject_text_long(void) {
|
static void test_serialize_inject_text_long(void) {
|
||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = CONTROL_MSG_TYPE_INJECT_TEXT;
|
msg.type = SC_CONTROL_MSG_TYPE_INJECT_TEXT;
|
||||||
char text[CONTROL_MSG_INJECT_TEXT_MAX_LENGTH + 1];
|
char text[SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH + 1];
|
||||||
memset(text, 'a', CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);
|
memset(text, 'a', SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);
|
||||||
text[CONTROL_MSG_INJECT_TEXT_MAX_LENGTH] = '\0';
|
text[SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH] = '\0';
|
||||||
msg.inject_text.text = text;
|
msg.inject_text.text = text;
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 5 + CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);
|
assert(size == 5 + SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);
|
||||||
|
|
||||||
unsigned char expected[5 + CONTROL_MSG_INJECT_TEXT_MAX_LENGTH];
|
unsigned char expected[5 + SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH];
|
||||||
expected[0] = CONTROL_MSG_TYPE_INJECT_TEXT;
|
expected[0] = SC_CONTROL_MSG_TYPE_INJECT_TEXT;
|
||||||
expected[1] = 0x00;
|
expected[1] = 0x00;
|
||||||
expected[2] = 0x00;
|
expected[2] = 0x00;
|
||||||
expected[3] = 0x01;
|
expected[3] = 0x01;
|
||||||
expected[4] = 0x2c; // text length (32 bits)
|
expected[4] = 0x2c; // text length (32 bits)
|
||||||
memset(&expected[5], 'a', CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);
|
memset(&expected[5], 'a', SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);
|
||||||
|
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_serialize_inject_touch_event(void) {
|
static void test_serialize_inject_touch_event(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
.type = SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||||
.inject_touch_event = {
|
.inject_touch_event = {
|
||||||
.action = AMOTION_EVENT_ACTION_DOWN,
|
.action = AMOTION_EVENT_ACTION_DOWN,
|
||||||
.pointer_id = UINT64_C(0x1234567887654321),
|
.pointer_id = UINT64_C(0x1234567887654321),
|
||||||
@@ -94,12 +94,12 @@ static void test_serialize_inject_touch_event(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 28);
|
assert(size == 28);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||||
0x00, // AKEY_EVENT_ACTION_DOWN
|
0x00, // AKEY_EVENT_ACTION_DOWN
|
||||||
0x12, 0x34, 0x56, 0x78, 0x87, 0x65, 0x43, 0x21, // pointer id
|
0x12, 0x34, 0x56, 0x78, 0x87, 0x65, 0x43, 0x21, // pointer id
|
||||||
0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0xc8, // 100 200
|
0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0xc8, // 100 200
|
||||||
@@ -112,7 +112,7 @@ static void test_serialize_inject_touch_event(void) {
|
|||||||
|
|
||||||
static void test_serialize_inject_scroll_event(void) {
|
static void test_serialize_inject_scroll_event(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
.type = SC_CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
||||||
.inject_scroll_event = {
|
.inject_scroll_event = {
|
||||||
.position = {
|
.position = {
|
||||||
.point = {
|
.point = {
|
||||||
@@ -130,12 +130,12 @@ static void test_serialize_inject_scroll_event(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 25);
|
assert(size == 25);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
SC_CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
||||||
0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x04, 0x02, // 260 1026
|
0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x04, 0x02, // 260 1026
|
||||||
0x04, 0x38, 0x07, 0x80, // 1080 1920
|
0x04, 0x38, 0x07, 0x80, // 1080 1920
|
||||||
0x00, 0x00, 0x00, 0x01, // 1
|
0x00, 0x00, 0x00, 0x01, // 1
|
||||||
@@ -147,18 +147,18 @@ static void test_serialize_inject_scroll_event(void) {
|
|||||||
|
|
||||||
static void test_serialize_back_or_screen_on(void) {
|
static void test_serialize_back_or_screen_on(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
.type = SC_CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
||||||
.back_or_screen_on = {
|
.back_or_screen_on = {
|
||||||
.action = AKEY_EVENT_ACTION_UP,
|
.action = AKEY_EVENT_ACTION_UP,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 2);
|
assert(size == 2);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
SC_CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
||||||
0x01, // AKEY_EVENT_ACTION_UP
|
0x01, // AKEY_EVENT_ACTION_UP
|
||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
@@ -166,71 +166,71 @@ static void test_serialize_back_or_screen_on(void) {
|
|||||||
|
|
||||||
static void test_serialize_expand_notification_panel(void) {
|
static void test_serialize_expand_notification_panel(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
.type = SC_CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 1);
|
assert(size == 1);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
SC_CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_serialize_expand_settings_panel(void) {
|
static void test_serialize_expand_settings_panel(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
.type = SC_CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 1);
|
assert(size == 1);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
SC_CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_serialize_collapse_panels(void) {
|
static void test_serialize_collapse_panels(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
.type = SC_CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 1);
|
assert(size == 1);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
SC_CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_serialize_get_clipboard(void) {
|
static void test_serialize_get_clipboard(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_GET_CLIPBOARD,
|
.type = SC_CONTROL_MSG_TYPE_GET_CLIPBOARD,
|
||||||
.get_clipboard = {
|
.get_clipboard = {
|
||||||
.copy_key = GET_CLIPBOARD_COPY_KEY_COPY,
|
.copy_key = SC_COPY_KEY_COPY,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 2);
|
assert(size == 2);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_GET_CLIPBOARD,
|
SC_CONTROL_MSG_TYPE_GET_CLIPBOARD,
|
||||||
GET_CLIPBOARD_COPY_KEY_COPY,
|
SC_COPY_KEY_COPY,
|
||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_serialize_set_clipboard(void) {
|
static void test_serialize_set_clipboard(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
.type = SC_CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
||||||
.set_clipboard = {
|
.set_clipboard = {
|
||||||
.sequence = UINT64_C(0x0102030405060708),
|
.sequence = UINT64_C(0x0102030405060708),
|
||||||
.paste = true,
|
.paste = true,
|
||||||
@@ -238,12 +238,12 @@ static void test_serialize_set_clipboard(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 27);
|
assert(size == 27);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
SC_CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
||||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // sequence
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // sequence
|
||||||
1, // paste
|
1, // paste
|
||||||
0x00, 0x00, 0x00, 0x0d, // text length
|
0x00, 0x00, 0x00, 0x0d, // text length
|
||||||
@@ -254,7 +254,7 @@ static void test_serialize_set_clipboard(void) {
|
|||||||
|
|
||||||
static void test_serialize_set_clipboard_long(void) {
|
static void test_serialize_set_clipboard_long(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
.type = SC_CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
||||||
.set_clipboard = {
|
.set_clipboard = {
|
||||||
.sequence = UINT64_C(0x0102030405060708),
|
.sequence = UINT64_C(0x0102030405060708),
|
||||||
.paste = true,
|
.paste = true,
|
||||||
@@ -262,60 +262,60 @@ static void test_serialize_set_clipboard_long(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
char text[CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH + 1];
|
char text[SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH + 1];
|
||||||
memset(text, 'a', CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH);
|
memset(text, 'a', SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH);
|
||||||
text[CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH] = '\0';
|
text[SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH] = '\0';
|
||||||
msg.set_clipboard.text = text;
|
msg.set_clipboard.text = text;
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == CONTROL_MSG_MAX_SIZE);
|
assert(size == SC_CONTROL_MSG_MAX_SIZE);
|
||||||
|
|
||||||
unsigned char expected[CONTROL_MSG_MAX_SIZE] = {
|
unsigned char expected[SC_CONTROL_MSG_MAX_SIZE] = {
|
||||||
CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
SC_CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
||||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // sequence
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // sequence
|
||||||
1, // paste
|
1, // paste
|
||||||
// text length
|
// text length
|
||||||
CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH >> 24,
|
SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH >> 24,
|
||||||
(CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH >> 16) & 0xff,
|
(SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH >> 16) & 0xff,
|
||||||
(CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH >> 8) & 0xff,
|
(SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH >> 8) & 0xff,
|
||||||
CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH & 0xff,
|
SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH & 0xff,
|
||||||
};
|
};
|
||||||
memset(expected + 14, 'a', CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH);
|
memset(expected + 14, 'a', SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH);
|
||||||
|
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_serialize_set_screen_power_mode(void) {
|
static void test_serialize_set_screen_power_mode(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE,
|
.type = SC_CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE,
|
||||||
.set_screen_power_mode = {
|
.set_screen_power_mode = {
|
||||||
.mode = SCREEN_POWER_MODE_NORMAL,
|
.mode = SC_SCREEN_POWER_MODE_NORMAL,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 2);
|
assert(size == 2);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE,
|
SC_CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE,
|
||||||
0x02, // SCREEN_POWER_MODE_NORMAL
|
0x02, // SC_SCREEN_POWER_MODE_NORMAL
|
||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_serialize_rotate_device(void) {
|
static void test_serialize_rotate_device(void) {
|
||||||
struct sc_control_msg msg = {
|
struct sc_control_msg msg = {
|
||||||
.type = CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
.type = SC_CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 1);
|
assert(size == 1);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const unsigned char expected[] = {
|
||||||
CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
SC_CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -338,32 +338,6 @@ static void test_wrap_lines(void) {
|
|||||||
free(formatted);
|
free(formatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_truncate(void) {
|
|
||||||
char s[] = "hello\nworld\n!";
|
|
||||||
size_t len = sc_str_truncate(s, sizeof(s), "\n");
|
|
||||||
|
|
||||||
assert(len == 5);
|
|
||||||
assert(!strcmp("hello", s));
|
|
||||||
|
|
||||||
char s2[] = "hello\r\nworkd\r\n!";
|
|
||||||
len = sc_str_truncate(s2, sizeof(s2), "\n\r");
|
|
||||||
|
|
||||||
assert(len == 5);
|
|
||||||
assert(!strcmp("hello", s));
|
|
||||||
|
|
||||||
char s3[] = "hello world\n!";
|
|
||||||
len = sc_str_truncate(s3, sizeof(s3), " \n\r");
|
|
||||||
|
|
||||||
assert(len == 5);
|
|
||||||
assert(!strcmp("hello", s3));
|
|
||||||
|
|
||||||
char s4[] = "hello ";
|
|
||||||
len = sc_str_truncate(s4, sizeof(s4), " \n\r");
|
|
||||||
|
|
||||||
assert(len == 5);
|
|
||||||
assert(!strcmp("hello", s4));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_index_of_column(void) {
|
static void test_index_of_column(void) {
|
||||||
assert(sc_str_index_of_column("a bc d", 0, " ") == 0);
|
assert(sc_str_index_of_column("a bc d", 0, " ") == 0);
|
||||||
assert(sc_str_index_of_column("a bc d", 1, " ") == 2);
|
assert(sc_str_index_of_column("a bc d", 1, " ") == 2);
|
||||||
@@ -417,7 +391,6 @@ int main(int argc, char *argv[]) {
|
|||||||
test_parse_integer_with_suffix();
|
test_parse_integer_with_suffix();
|
||||||
test_strlist_contains();
|
test_strlist_contains();
|
||||||
test_wrap_lines();
|
test_wrap_lines();
|
||||||
test_truncate();
|
|
||||||
test_index_of_column();
|
test_index_of_column();
|
||||||
test_remove_trailing_cr();
|
test_remove_trailing_cr();
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -19,5 +19,5 @@ endian = 'little'
|
|||||||
ffmpeg_avcodec = 'avcodec-58'
|
ffmpeg_avcodec = 'avcodec-58'
|
||||||
ffmpeg_avformat = 'avformat-58'
|
ffmpeg_avformat = 'avformat-58'
|
||||||
ffmpeg_avutil = 'avutil-56'
|
ffmpeg_avutil = 'avutil-56'
|
||||||
prebuilt_ffmpeg = 'ffmpeg-4.3.1-win32-shared'
|
prebuilt_ffmpeg = 'ffmpeg-win32-4.3.1'
|
||||||
prebuilt_sdl2 = 'SDL2-2.0.18/i686-w64-mingw32'
|
prebuilt_sdl2 = 'SDL2-2.0.20/i686-w64-mingw32'
|
||||||
|
|||||||
@@ -19,5 +19,5 @@ endian = 'little'
|
|||||||
ffmpeg_avcodec = 'avcodec-59'
|
ffmpeg_avcodec = 'avcodec-59'
|
||||||
ffmpeg_avformat = 'avformat-59'
|
ffmpeg_avformat = 'avformat-59'
|
||||||
ffmpeg_avutil = 'avutil-57'
|
ffmpeg_avutil = 'avutil-57'
|
||||||
prebuilt_ffmpeg = 'ffmpeg-5.0-full_build-shared'
|
prebuilt_ffmpeg = 'ffmpeg-win64-5.0'
|
||||||
prebuilt_sdl2 = 'SDL2-2.0.18/x86_64-w64-mingw32'
|
prebuilt_sdl2 = 'SDL2-2.0.20/x86_64-w64-mingw32'
|
||||||
|
|||||||
1
data/open_a_terminal_here.bat
Normal file
1
data/open_a_terminal_here.bat
Normal file
@@ -0,0 +1 @@
|
|||||||
|
@cmd
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
BUILDDIR=build-auto
|
BUILDDIR=build-auto
|
||||||
PREBUILT_SERVER_URL=https://github.com/Genymobile/scrcpy/releases/download/v1.21/scrcpy-server-v1.21
|
PREBUILT_SERVER_URL=https://github.com/Genymobile/scrcpy/releases/download/v1.22/scrcpy-server-v1.22
|
||||||
PREBUILT_SERVER_SHA256=dbcccab523ee26796e55ea33652649e4b7af498edae9aa75e4d4d7869c0ab848
|
PREBUILT_SERVER_SHA256=c05d273eec7533c0e106282e0254cf04e7f5e8f0c2920ca39448865fab2a419b
|
||||||
|
|
||||||
echo "[scrcpy] Downloading prebuilt server..."
|
echo "[scrcpy] Downloading prebuilt server..."
|
||||||
wget "$PREBUILT_SERVER_URL" -O scrcpy-server
|
wget "$PREBUILT_SERVER_URL" -O scrcpy-server
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
project('scrcpy', 'c',
|
project('scrcpy', 'c',
|
||||||
version: '1.21',
|
version: '1.22',
|
||||||
meson_version: '>= 0.48',
|
meson_version: '>= 0.48',
|
||||||
default_options: [
|
default_options: [
|
||||||
'c_std=c11',
|
'c_std=c11',
|
||||||
|
|||||||
5
prebuilt-deps/.gitignore
vendored
5
prebuilt-deps/.gitignore
vendored
@@ -1,4 +1 @@
|
|||||||
*
|
/data
|
||||||
!/.gitignore
|
|
||||||
!/Makefile
|
|
||||||
!/prepare-dep
|
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
.PHONY: prepare-win32 prepare-win64 \
|
|
||||||
prepare-ffmpeg-win32 \
|
|
||||||
prepare-ffmpeg-win64 \
|
|
||||||
prepare-sdl2 \
|
|
||||||
prepare-adb
|
|
||||||
|
|
||||||
prepare-win32: prepare-sdl2 prepare-ffmpeg-win32 prepare-adb
|
|
||||||
prepare-win64: prepare-sdl2 prepare-ffmpeg-win64 prepare-adb
|
|
||||||
|
|
||||||
# Use old FFmpeg version for win32, there are no new prebuilts
|
|
||||||
prepare-ffmpeg-win32:
|
|
||||||
@./prepare-dep https://github.com/Genymobile/scrcpy/releases/download/v1.16/ffmpeg-4.3.1-win32-shared.zip \
|
|
||||||
357af9901a456f4dcbacd107e83a934d344c9cb07ddad8aaf80612eeab7d26d2 \
|
|
||||||
ffmpeg-4.3.1-win32-shared
|
|
||||||
@./prepare-dep https://github.com/Genymobile/scrcpy/releases/download/v1.16/ffmpeg-4.3.1-win32-dev.zip \
|
|
||||||
230efb08e9bcf225bd474da29676c70e591fc94d8790a740ca801408fddcb78b \
|
|
||||||
ffmpeg-4.3.1-win32-dev
|
|
||||||
ln -sf ../ffmpeg-4.3.1-win32-dev/include ffmpeg-4.3.1-win32-shared/
|
|
||||||
|
|
||||||
prepare-ffmpeg-win64:
|
|
||||||
@./prepare-dep https://github.com/GyanD/codexffmpeg/releases/download/5.0/ffmpeg-5.0-full_build-shared.7z \
|
|
||||||
e5900f6cecd4c438d398bd2fc308736c10b857cd8dd61c11bcfb05bff5d1211a \
|
|
||||||
ffmpeg-5.0-full_build-shared
|
|
||||||
|
|
||||||
prepare-sdl2:
|
|
||||||
@./prepare-dep https://libsdl.org/release/SDL2-devel-2.0.18-mingw.tar.gz \
|
|
||||||
bbad7c6947f6ca3e05292f065852ed8b62f319fc5533047e7708769c4dbae394 \
|
|
||||||
SDL2-2.0.18
|
|
||||||
|
|
||||||
prepare-adb:
|
|
||||||
@./prepare-dep https://dl.google.com/android/repository/platform-tools_r31.0.3-windows.zip \
|
|
||||||
0f4b8fdd26af2c3733539d6eebb3c2ed499ea1d4bb1f4e0ecc2d6016961a6e24 \
|
|
||||||
platform-tools
|
|
||||||
22
prebuilt-deps/common
Executable file
22
prebuilt-deps/common
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
PREBUILT_DATA_DIR=data
|
||||||
|
|
||||||
|
checksum() {
|
||||||
|
local file="$1"
|
||||||
|
local sum="$2"
|
||||||
|
echo "$file: verifying checksum..."
|
||||||
|
echo "$sum $file" | sha256sum -c
|
||||||
|
}
|
||||||
|
|
||||||
|
get_file() {
|
||||||
|
local url="$1"
|
||||||
|
local file="$2"
|
||||||
|
local sum="$3"
|
||||||
|
if [[ -f "$file" ]]
|
||||||
|
then
|
||||||
|
echo "$file: found"
|
||||||
|
else
|
||||||
|
echo "$file: not found, downloading..."
|
||||||
|
wget "$url" -O "$file"
|
||||||
|
fi
|
||||||
|
checksum "$file" "$sum"
|
||||||
|
}
|
||||||
32
prebuilt-deps/prepare-adb.sh
Executable file
32
prebuilt-deps/prepare-adb.sh
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
DIR=$(dirname ${BASH_SOURCE[0]})
|
||||||
|
cd "$DIR"
|
||||||
|
. common
|
||||||
|
mkdir -p "$PREBUILT_DATA_DIR"
|
||||||
|
cd "$PREBUILT_DATA_DIR"
|
||||||
|
|
||||||
|
DEP_DIR=platform-tools-31.0.3
|
||||||
|
|
||||||
|
FILENAME=platform-tools_r31.0.3-windows.zip
|
||||||
|
SHA256SUM=0f4b8fdd26af2c3733539d6eebb3c2ed499ea1d4bb1f4e0ecc2d6016961a6e24
|
||||||
|
|
||||||
|
if [[ -d "$DEP_DIR" ]]
|
||||||
|
then
|
||||||
|
echo "$DEP_DIR" found
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
get_file "https://dl.google.com/android/repository/$FILENAME" \
|
||||||
|
"$FILENAME" "$SHA256SUM"
|
||||||
|
|
||||||
|
mkdir "$DEP_DIR"
|
||||||
|
cd "$DEP_DIR"
|
||||||
|
|
||||||
|
ZIP_PREFIX=platform-tools
|
||||||
|
unzip "../$FILENAME" \
|
||||||
|
"$ZIP_PREFIX"/AdbWinApi.dll \
|
||||||
|
"$ZIP_PREFIX"/AdbWinUsbApi.dll \
|
||||||
|
"$ZIP_PREFIX"/adb.exe
|
||||||
|
mv "$ZIP_PREFIX"/* .
|
||||||
|
rmdir "$ZIP_PREFIX"
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -e
|
|
||||||
url="$1"
|
|
||||||
sum="$2"
|
|
||||||
dir="$3"
|
|
||||||
|
|
||||||
checksum() {
|
|
||||||
local file="$1"
|
|
||||||
local sum="$2"
|
|
||||||
echo "$file: verifying checksum..."
|
|
||||||
echo "$sum $file" | sha256sum -c
|
|
||||||
}
|
|
||||||
|
|
||||||
get_file() {
|
|
||||||
local url="$1"
|
|
||||||
local file="$2"
|
|
||||||
local sum="$3"
|
|
||||||
if [[ -f "$file" ]]
|
|
||||||
then
|
|
||||||
echo "$file: found"
|
|
||||||
else
|
|
||||||
echo "$file: not found, downloading..."
|
|
||||||
wget "$url" -O "$file"
|
|
||||||
fi
|
|
||||||
checksum "$file" "$sum"
|
|
||||||
}
|
|
||||||
|
|
||||||
extract() {
|
|
||||||
local file="$1"
|
|
||||||
echo "Extracting $file..."
|
|
||||||
if [[ "$file" == *.zip ]]
|
|
||||||
then
|
|
||||||
unzip -q "$file"
|
|
||||||
elif [[ "$file" == *.tar.gz ]]
|
|
||||||
then
|
|
||||||
tar xf "$file"
|
|
||||||
elif [[ "$file" == *.7z ]]
|
|
||||||
then
|
|
||||||
7z x "$file"
|
|
||||||
else
|
|
||||||
echo "Unsupported file: $file"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
get_dep() {
|
|
||||||
local url="$1"
|
|
||||||
local sum="$2"
|
|
||||||
local dir="$3"
|
|
||||||
local file="${url##*/}"
|
|
||||||
if [[ -d "$dir" ]]
|
|
||||||
then
|
|
||||||
echo "$dir: found"
|
|
||||||
else
|
|
||||||
echo "$dir: not found"
|
|
||||||
get_file "$url" "$file" "$sum"
|
|
||||||
extract "$file"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
get_dep "$url" "$sum" "$dir"
|
|
||||||
45
prebuilt-deps/prepare-ffmpeg-win32.sh
Executable file
45
prebuilt-deps/prepare-ffmpeg-win32.sh
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
DIR=$(dirname ${BASH_SOURCE[0]})
|
||||||
|
cd "$DIR"
|
||||||
|
. common
|
||||||
|
mkdir -p "$PREBUILT_DATA_DIR"
|
||||||
|
cd "$PREBUILT_DATA_DIR"
|
||||||
|
|
||||||
|
DEP_DIR=ffmpeg-win32-4.3.1
|
||||||
|
|
||||||
|
FILENAME_SHARED=ffmpeg-4.3.1-win32-shared.zip
|
||||||
|
SHA256SUM_SHARED=357af9901a456f4dcbacd107e83a934d344c9cb07ddad8aaf80612eeab7d26d2
|
||||||
|
|
||||||
|
FILENAME_DEV=ffmpeg-4.3.1-win32-dev.zip
|
||||||
|
SHA256SUM_DEV=230efb08e9bcf225bd474da29676c70e591fc94d8790a740ca801408fddcb78b
|
||||||
|
|
||||||
|
if [[ -d "$DEP_DIR" ]]
|
||||||
|
then
|
||||||
|
echo "$DEP_DIR" found
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
get_file "https://github.com/Genymobile/scrcpy/releases/download/v1.16/$FILENAME_SHARED" \
|
||||||
|
"$FILENAME_SHARED" "$SHA256SUM_SHARED"
|
||||||
|
get_file "https://github.com/Genymobile/scrcpy/releases/download/v1.16/$FILENAME_DEV" \
|
||||||
|
"$FILENAME_DEV" "$SHA256SUM_DEV"
|
||||||
|
|
||||||
|
mkdir "$DEP_DIR"
|
||||||
|
cd "$DEP_DIR"
|
||||||
|
|
||||||
|
ZIP_PREFIX_SHARED=ffmpeg-4.3.1-win32-shared
|
||||||
|
unzip "../$FILENAME_SHARED" \
|
||||||
|
"$ZIP_PREFIX_SHARED"/bin/avutil-56.dll \
|
||||||
|
"$ZIP_PREFIX_SHARED"/bin/avcodec-58.dll \
|
||||||
|
"$ZIP_PREFIX_SHARED"/bin/avformat-58.dll \
|
||||||
|
"$ZIP_PREFIX_SHARED"/bin/swresample-3.dll \
|
||||||
|
"$ZIP_PREFIX_SHARED"/bin/swscale-5.dll
|
||||||
|
|
||||||
|
ZIP_PREFIX_DEV=ffmpeg-4.3.1-win32-dev
|
||||||
|
unzip "../$FILENAME_DEV" \
|
||||||
|
"$ZIP_PREFIX_DEV/include/*"
|
||||||
|
|
||||||
|
mv "$ZIP_PREFIX_SHARED"/* .
|
||||||
|
mv "$ZIP_PREFIX_DEV"/* .
|
||||||
|
rmdir "$ZIP_PREFIX_SHARED" "$ZIP_PREFIX_DEV"
|
||||||
35
prebuilt-deps/prepare-ffmpeg-win64.sh
Executable file
35
prebuilt-deps/prepare-ffmpeg-win64.sh
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
DIR=$(dirname ${BASH_SOURCE[0]})
|
||||||
|
cd "$DIR"
|
||||||
|
. common
|
||||||
|
mkdir -p "$PREBUILT_DATA_DIR"
|
||||||
|
cd "$PREBUILT_DATA_DIR"
|
||||||
|
|
||||||
|
DEP_DIR=ffmpeg-win64-5.0
|
||||||
|
|
||||||
|
FILENAME=ffmpeg-5.0-full_build-shared.7z
|
||||||
|
SHA256SUM=e5900f6cecd4c438d398bd2fc308736c10b857cd8dd61c11bcfb05bff5d1211a
|
||||||
|
|
||||||
|
if [[ -d "$DEP_DIR" ]]
|
||||||
|
then
|
||||||
|
echo "$DEP_DIR" found
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
get_file "https://github.com/GyanD/codexffmpeg/releases/download/5.0/$FILENAME" \
|
||||||
|
"$FILENAME" "$SHA256SUM"
|
||||||
|
|
||||||
|
mkdir "$DEP_DIR"
|
||||||
|
cd "$DEP_DIR"
|
||||||
|
|
||||||
|
ZIP_PREFIX=ffmpeg-5.0-full_build-shared
|
||||||
|
7z x "../$FILENAME" \
|
||||||
|
"$ZIP_PREFIX"/bin/avutil-57.dll \
|
||||||
|
"$ZIP_PREFIX"/bin/avcodec-59.dll \
|
||||||
|
"$ZIP_PREFIX"/bin/avformat-59.dll \
|
||||||
|
"$ZIP_PREFIX"/bin/swresample-4.dll \
|
||||||
|
"$ZIP_PREFIX"/bin/swscale-6.dll \
|
||||||
|
"$ZIP_PREFIX"/include
|
||||||
|
mv "$ZIP_PREFIX"/* .
|
||||||
|
rmdir "$ZIP_PREFIX"
|
||||||
32
prebuilt-deps/prepare-sdl.sh
Executable file
32
prebuilt-deps/prepare-sdl.sh
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
DIR=$(dirname ${BASH_SOURCE[0]})
|
||||||
|
cd "$DIR"
|
||||||
|
. common
|
||||||
|
mkdir -p "$PREBUILT_DATA_DIR"
|
||||||
|
cd "$PREBUILT_DATA_DIR"
|
||||||
|
|
||||||
|
DEP_DIR=SDL2-2.0.20
|
||||||
|
|
||||||
|
FILENAME=SDL2-devel-2.0.20-mingw.tar.gz
|
||||||
|
SHA256SUM=38094d82a857d6c62352e5c5cdec74948c5b4d25c59cbd298d6d233568976bd1
|
||||||
|
|
||||||
|
if [[ -d "$DEP_DIR" ]]
|
||||||
|
then
|
||||||
|
echo "$DEP_DIR" found
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
get_file "https://libsdl.org/release/$FILENAME" "$FILENAME" "$SHA256SUM"
|
||||||
|
|
||||||
|
mkdir "$DEP_DIR"
|
||||||
|
cd "$DEP_DIR"
|
||||||
|
|
||||||
|
TAR_PREFIX="$DEP_DIR" # root directory inside the tar has the same name
|
||||||
|
tar xf "../$FILENAME" --strip-components=1 \
|
||||||
|
"$TAR_PREFIX"/i686-w64-mingw32/bin/SDL2.dll \
|
||||||
|
"$TAR_PREFIX"/i686-w64-mingw32/include/ \
|
||||||
|
"$TAR_PREFIX"/i686-w64-mingw32/lib/ \
|
||||||
|
"$TAR_PREFIX"/x86_64-w64-mingw32/bin/SDL2.dll \
|
||||||
|
"$TAR_PREFIX"/x86_64-w64-mingw32/include/ \
|
||||||
|
"$TAR_PREFIX"/x86_64-w64-mingw32/lib/ \
|
||||||
46
release.mk
46
release.mk
@@ -63,7 +63,9 @@ build-server:
|
|||||||
ninja -C "$(SERVER_BUILD_DIR)"
|
ninja -C "$(SERVER_BUILD_DIR)"
|
||||||
|
|
||||||
prepare-deps-win32:
|
prepare-deps-win32:
|
||||||
-$(MAKE) -C prebuilt-deps prepare-win32
|
@prebuilt-deps/prepare-adb.sh
|
||||||
|
@prebuilt-deps/prepare-sdl.sh
|
||||||
|
@prebuilt-deps/prepare-ffmpeg-win32.sh
|
||||||
|
|
||||||
build-win32: prepare-deps-win32
|
build-win32: prepare-deps-win32
|
||||||
[ -d "$(WIN32_BUILD_DIR)" ] || ( mkdir "$(WIN32_BUILD_DIR)" && \
|
[ -d "$(WIN32_BUILD_DIR)" ] || ( mkdir "$(WIN32_BUILD_DIR)" && \
|
||||||
@@ -75,7 +77,9 @@ build-win32: prepare-deps-win32
|
|||||||
ninja -C "$(WIN32_BUILD_DIR)"
|
ninja -C "$(WIN32_BUILD_DIR)"
|
||||||
|
|
||||||
prepare-deps-win64:
|
prepare-deps-win64:
|
||||||
-$(MAKE) -C prebuilt-deps prepare-win64
|
@prebuilt-deps/prepare-adb.sh
|
||||||
|
@prebuilt-deps/prepare-sdl.sh
|
||||||
|
@prebuilt-deps/prepare-ffmpeg-win64.sh
|
||||||
|
|
||||||
build-win64: prepare-deps-win64
|
build-win64: prepare-deps-win64
|
||||||
[ -d "$(WIN64_BUILD_DIR)" ] || ( mkdir "$(WIN64_BUILD_DIR)" && \
|
[ -d "$(WIN64_BUILD_DIR)" ] || ( mkdir "$(WIN64_BUILD_DIR)" && \
|
||||||
@@ -93,15 +97,16 @@ dist-win32: build-server build-win32
|
|||||||
cp data/scrcpy-console.bat "$(DIST)/$(WIN32_TARGET_DIR)"
|
cp data/scrcpy-console.bat "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||||
cp data/scrcpy-noconsole.vbs "$(DIST)/$(WIN32_TARGET_DIR)"
|
cp data/scrcpy-noconsole.vbs "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||||
cp data/icon.png "$(DIST)/$(WIN32_TARGET_DIR)"
|
cp data/icon.png "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||||
cp prebuilt-deps/ffmpeg-4.3.1-win32-shared/bin/avutil-56.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
cp data/open_a_terminal_here.bat "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||||
cp prebuilt-deps/ffmpeg-4.3.1-win32-shared/bin/avcodec-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
cp prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/avutil-56.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||||
cp prebuilt-deps/ffmpeg-4.3.1-win32-shared/bin/avformat-58.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/ffmpeg-4.3.1-win32-shared/bin/swresample-3.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/ffmpeg-4.3.1-win32-shared/bin/swscale-5.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/platform-tools/adb.exe "$(DIST)/$(WIN32_TARGET_DIR)/"
|
cp prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/swscale-5.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||||
cp prebuilt-deps/platform-tools/AdbWinApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
cp prebuilt-deps/data/platform-tools-31.0.3/adb.exe "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||||
cp prebuilt-deps/platform-tools/AdbWinUsbApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
cp prebuilt-deps/data/platform-tools-31.0.3/AdbWinApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||||
cp prebuilt-deps/SDL2-2.0.18/i686-w64-mingw32/bin/SDL2.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)/"
|
||||||
|
|
||||||
dist-win64: build-server build-win64
|
dist-win64: build-server build-win64
|
||||||
mkdir -p "$(DIST)/$(WIN64_TARGET_DIR)"
|
mkdir -p "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||||
@@ -110,15 +115,16 @@ dist-win64: build-server build-win64
|
|||||||
cp data/scrcpy-console.bat "$(DIST)/$(WIN64_TARGET_DIR)"
|
cp data/scrcpy-console.bat "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||||
cp data/scrcpy-noconsole.vbs "$(DIST)/$(WIN64_TARGET_DIR)"
|
cp data/scrcpy-noconsole.vbs "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||||
cp data/icon.png "$(DIST)/$(WIN64_TARGET_DIR)"
|
cp data/icon.png "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||||
cp prebuilt-deps/ffmpeg-5.0-full_build-shared/bin/avutil-57.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
cp data/open_a_terminal_here.bat "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||||
cp prebuilt-deps/ffmpeg-5.0-full_build-shared/bin/avcodec-59.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
cp prebuilt-deps/data/ffmpeg-win64-5.0/bin/avutil-57.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||||
cp prebuilt-deps/ffmpeg-5.0-full_build-shared/bin/avformat-59.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
cp prebuilt-deps/data/ffmpeg-win64-5.0/bin/avcodec-59.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||||
cp prebuilt-deps/ffmpeg-5.0-full_build-shared/bin/swresample-4.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
cp prebuilt-deps/data/ffmpeg-win64-5.0/bin/avformat-59.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||||
cp prebuilt-deps/ffmpeg-5.0-full_build-shared/bin/swscale-6.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
cp prebuilt-deps/data/ffmpeg-win64-5.0/bin/swresample-4.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||||
cp prebuilt-deps/platform-tools/adb.exe "$(DIST)/$(WIN64_TARGET_DIR)/"
|
cp prebuilt-deps/data/ffmpeg-win64-5.0/bin/swscale-6.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||||
cp prebuilt-deps/platform-tools/AdbWinApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
cp prebuilt-deps/data/platform-tools-31.0.3/adb.exe "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||||
cp prebuilt-deps/platform-tools/AdbWinUsbApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
cp prebuilt-deps/data/platform-tools-31.0.3/AdbWinApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||||
cp prebuilt-deps/SDL2-2.0.18/x86_64-w64-mingw32/bin/SDL2.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)/"
|
||||||
|
|
||||||
zip-win32: dist-win32
|
zip-win32: dist-win32
|
||||||
cd "$(DIST)/$(WIN32_TARGET_DIR)"; \
|
cd "$(DIST)/$(WIN32_TARGET_DIR)"; \
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ android {
|
|||||||
applicationId "com.genymobile.scrcpy"
|
applicationId "com.genymobile.scrcpy"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 31
|
targetSdkVersion 31
|
||||||
versionCode 12100
|
versionCode 12200
|
||||||
versionName "1.21"
|
versionName "1.22"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
SCRCPY_DEBUG=false
|
SCRCPY_DEBUG=false
|
||||||
SCRCPY_VERSION_NAME=1.21
|
SCRCPY_VERSION_NAME=1.22
|
||||||
|
|
||||||
PLATFORM=${ANDROID_PLATFORM:-31}
|
PLATFORM=${ANDROID_PLATFORM:-31}
|
||||||
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-31.0.0}
|
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-31.0.0}
|
||||||
|
|||||||
@@ -46,15 +46,17 @@ public final class DesktopConnection implements Closeable {
|
|||||||
return localSocket;
|
return localSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DesktopConnection open(Device device, boolean tunnelForward, boolean control) throws IOException {
|
public static DesktopConnection open(boolean tunnelForward, boolean control, boolean sendDummyByte) throws IOException {
|
||||||
LocalSocket videoSocket;
|
LocalSocket videoSocket;
|
||||||
LocalSocket controlSocket = null;
|
LocalSocket controlSocket = null;
|
||||||
if (tunnelForward) {
|
if (tunnelForward) {
|
||||||
LocalServerSocket localServerSocket = new LocalServerSocket(SOCKET_NAME);
|
LocalServerSocket localServerSocket = new LocalServerSocket(SOCKET_NAME);
|
||||||
try {
|
try {
|
||||||
videoSocket = localServerSocket.accept();
|
videoSocket = localServerSocket.accept();
|
||||||
|
if (sendDummyByte) {
|
||||||
// send one byte so the client may read() to detect a connection error
|
// send one byte so the client may read() to detect a connection error
|
||||||
videoSocket.getOutputStream().write(0);
|
videoSocket.getOutputStream().write(0);
|
||||||
|
}
|
||||||
if (control) {
|
if (control) {
|
||||||
try {
|
try {
|
||||||
controlSocket = localServerSocket.accept();
|
controlSocket = localServerSocket.accept();
|
||||||
@@ -78,10 +80,7 @@ public final class DesktopConnection implements Closeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopConnection connection = new DesktopConnection(videoSocket, controlSocket);
|
return new DesktopConnection(videoSocket, controlSocket);
|
||||||
Size videoSize = device.getScreenInfo().getVideoSize();
|
|
||||||
connection.send(Device.getDeviceName(), videoSize.getWidth(), videoSize.getHeight());
|
|
||||||
return connection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
@@ -95,7 +94,7 @@ public final class DesktopConnection implements Closeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void send(String deviceName, int width, int height) throws IOException {
|
public void sendDeviceMeta(String deviceName, int width, int height) throws IOException {
|
||||||
byte[] buffer = new byte[DEVICE_NAME_FIELD_LENGTH + 4];
|
byte[] buffer = new byte[DEVICE_NAME_FIELD_LENGTH + 4];
|
||||||
|
|
||||||
byte[] deviceNameBytes = deviceName.getBytes(StandardCharsets.UTF_8);
|
byte[] deviceNameBytes = deviceName.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ public final class Device {
|
|||||||
void onClipboardTextChanged(String text);
|
void onClipboardTextChanged(String text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Size deviceSize;
|
||||||
|
private final Rect crop;
|
||||||
|
private int maxSize;
|
||||||
|
private final int lockVideoOrientation;
|
||||||
|
|
||||||
private ScreenInfo screenInfo;
|
private ScreenInfo screenInfo;
|
||||||
private RotationListener rotationListener;
|
private RotationListener rotationListener;
|
||||||
private ClipboardListener clipboardListener;
|
private ClipboardListener clipboardListener;
|
||||||
@@ -69,7 +74,12 @@ public final class Device {
|
|||||||
|
|
||||||
int displayInfoFlags = displayInfo.getFlags();
|
int displayInfoFlags = displayInfo.getFlags();
|
||||||
|
|
||||||
screenInfo = ScreenInfo.computeScreenInfo(displayInfo, options.getCrop(), options.getMaxSize(), options.getLockVideoOrientation());
|
deviceSize = displayInfo.getSize();
|
||||||
|
crop = options.getCrop();
|
||||||
|
maxSize = options.getMaxSize();
|
||||||
|
lockVideoOrientation = options.getLockVideoOrientation();
|
||||||
|
|
||||||
|
screenInfo = ScreenInfo.computeScreenInfo(displayInfo.getRotation(), deviceSize, crop, maxSize, lockVideoOrientation);
|
||||||
layerStack = displayInfo.getLayerStack();
|
layerStack = displayInfo.getLayerStack();
|
||||||
|
|
||||||
SERVICE_MANAGER.getWindowManager().registerRotationWatcher(new IRotationWatcher.Stub() {
|
SERVICE_MANAGER.getWindowManager().registerRotationWatcher(new IRotationWatcher.Stub() {
|
||||||
@@ -123,6 +133,11 @@ public final class Device {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void setMaxSize(int newMaxSize) {
|
||||||
|
maxSize = newMaxSize;
|
||||||
|
screenInfo = ScreenInfo.computeScreenInfo(screenInfo.getReverseVideoRotation(), deviceSize, crop, newMaxSize, lockVideoOrientation);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized ScreenInfo getScreenInfo() {
|
public synchronized ScreenInfo getScreenInfo() {
|
||||||
return screenInfo;
|
return screenInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ public class Options {
|
|||||||
private int lockVideoOrientation = -1;
|
private int lockVideoOrientation = -1;
|
||||||
private boolean tunnelForward;
|
private boolean tunnelForward;
|
||||||
private Rect crop;
|
private Rect crop;
|
||||||
private boolean sendFrameMeta = true; // send PTS so that the client may record properly
|
|
||||||
private boolean control = true;
|
private boolean control = true;
|
||||||
private int displayId;
|
private int displayId;
|
||||||
private boolean showTouches;
|
private boolean showTouches;
|
||||||
@@ -21,6 +20,12 @@ public class Options {
|
|||||||
private String encoderName;
|
private String encoderName;
|
||||||
private boolean powerOffScreenOnClose;
|
private boolean powerOffScreenOnClose;
|
||||||
private boolean clipboardAutosync = true;
|
private boolean clipboardAutosync = true;
|
||||||
|
private boolean downsizeOnError = true;
|
||||||
|
|
||||||
|
// Options not used by the scrcpy client, but useful to use scrcpy-server directly
|
||||||
|
private boolean sendDeviceMeta = true; // send device name and size
|
||||||
|
private boolean sendFrameMeta = true; // send PTS so that the client may record properly
|
||||||
|
private boolean sendDummyByte = true; // write a byte on start to detect connection issues
|
||||||
|
|
||||||
public Ln.Level getLogLevel() {
|
public Ln.Level getLogLevel() {
|
||||||
return logLevel;
|
return logLevel;
|
||||||
@@ -78,14 +83,6 @@ public class Options {
|
|||||||
this.crop = crop;
|
this.crop = crop;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getSendFrameMeta() {
|
|
||||||
return sendFrameMeta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSendFrameMeta(boolean sendFrameMeta) {
|
|
||||||
this.sendFrameMeta = sendFrameMeta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getControl() {
|
public boolean getControl() {
|
||||||
return control;
|
return control;
|
||||||
}
|
}
|
||||||
@@ -149,4 +146,36 @@ public class Options {
|
|||||||
public void setClipboardAutosync(boolean clipboardAutosync) {
|
public void setClipboardAutosync(boolean clipboardAutosync) {
|
||||||
this.clipboardAutosync = clipboardAutosync;
|
this.clipboardAutosync = clipboardAutosync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getDownsizeOnError() {
|
||||||
|
return downsizeOnError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownsizeOnError(boolean downsizeOnError) {
|
||||||
|
this.downsizeOnError = downsizeOnError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getSendDeviceMeta() {
|
||||||
|
return sendDeviceMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSendDeviceMeta(boolean sendDeviceMeta) {
|
||||||
|
this.sendDeviceMeta = sendDeviceMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getSendFrameMeta() {
|
||||||
|
return sendFrameMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSendFrameMeta(boolean sendFrameMeta) {
|
||||||
|
this.sendFrameMeta = sendFrameMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getSendDummyByte() {
|
||||||
|
return sendDummyByte;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSendDummyByte(boolean sendDummyByte) {
|
||||||
|
this.sendDummyByte = sendDummyByte;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ public class ScreenEncoder implements Device.RotationListener {
|
|||||||
private static final int REPEAT_FRAME_DELAY_US = 100_000; // repeat after 100ms
|
private static final int REPEAT_FRAME_DELAY_US = 100_000; // repeat after 100ms
|
||||||
private static final String KEY_MAX_FPS_TO_ENCODER = "max-fps-to-encoder";
|
private static final String KEY_MAX_FPS_TO_ENCODER = "max-fps-to-encoder";
|
||||||
|
|
||||||
|
// Keep the values in descending order
|
||||||
|
private static final int[] MAX_SIZE_FALLBACK = {2560, 1920, 1600, 1280, 1024, 800};
|
||||||
|
|
||||||
private static final int NO_PTS = -1;
|
private static final int NO_PTS = -1;
|
||||||
|
|
||||||
private final AtomicBoolean rotationChanged = new AtomicBoolean();
|
private final AtomicBoolean rotationChanged = new AtomicBoolean();
|
||||||
@@ -35,14 +38,19 @@ public class ScreenEncoder implements Device.RotationListener {
|
|||||||
private final int bitRate;
|
private final int bitRate;
|
||||||
private final int maxFps;
|
private final int maxFps;
|
||||||
private final boolean sendFrameMeta;
|
private final boolean sendFrameMeta;
|
||||||
|
private final boolean downsizeOnError;
|
||||||
private long ptsOrigin;
|
private long ptsOrigin;
|
||||||
|
|
||||||
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, List<CodecOption> codecOptions, String encoderName) {
|
private boolean firstFrameSent;
|
||||||
|
|
||||||
|
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, List<CodecOption> codecOptions, String encoderName,
|
||||||
|
boolean downsizeOnError) {
|
||||||
this.sendFrameMeta = sendFrameMeta;
|
this.sendFrameMeta = sendFrameMeta;
|
||||||
this.bitRate = bitRate;
|
this.bitRate = bitRate;
|
||||||
this.maxFps = maxFps;
|
this.maxFps = maxFps;
|
||||||
this.codecOptions = codecOptions;
|
this.codecOptions = codecOptions;
|
||||||
this.encoderName = encoderName;
|
this.encoderName = encoderName;
|
||||||
|
this.downsizeOnError = downsizeOnError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -81,27 +89,60 @@ public class ScreenEncoder implements Device.RotationListener {
|
|||||||
Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
|
Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
|
||||||
int videoRotation = screenInfo.getVideoRotation();
|
int videoRotation = screenInfo.getVideoRotation();
|
||||||
int layerStack = device.getLayerStack();
|
int layerStack = device.getLayerStack();
|
||||||
|
|
||||||
setSize(format, videoRect.width(), videoRect.height());
|
setSize(format, videoRect.width(), videoRect.height());
|
||||||
|
|
||||||
|
Surface surface = null;
|
||||||
|
try {
|
||||||
configure(codec, format);
|
configure(codec, format);
|
||||||
Surface surface = codec.createInputSurface();
|
surface = codec.createInputSurface();
|
||||||
setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
|
setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
|
||||||
codec.start();
|
codec.start();
|
||||||
try {
|
|
||||||
alive = encode(codec, fd);
|
alive = encode(codec, fd);
|
||||||
// do not call stop() on exception, it would trigger an IllegalStateException
|
// do not call stop() on exception, it would trigger an IllegalStateException
|
||||||
codec.stop();
|
codec.stop();
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage());
|
||||||
|
if (!downsizeOnError || firstFrameSent) {
|
||||||
|
// Fail immediately
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
int newMaxSize = chooseMaxSizeFallback(screenInfo.getVideoSize());
|
||||||
|
if (newMaxSize == 0) {
|
||||||
|
// Definitively fail
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retry with a smaller device size
|
||||||
|
Ln.i("Retrying with -m" + newMaxSize + "...");
|
||||||
|
device.setMaxSize(newMaxSize);
|
||||||
|
alive = true;
|
||||||
} finally {
|
} finally {
|
||||||
destroyDisplay(display);
|
destroyDisplay(display);
|
||||||
codec.release();
|
codec.release();
|
||||||
|
if (surface != null) {
|
||||||
surface.release();
|
surface.release();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} while (alive);
|
} while (alive);
|
||||||
} finally {
|
} finally {
|
||||||
device.setRotationListener(null);
|
device.setRotationListener(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int chooseMaxSizeFallback(Size failedSize) {
|
||||||
|
int currentMaxSize = Math.max(failedSize.getWidth(), failedSize.getHeight());
|
||||||
|
for (int value : MAX_SIZE_FALLBACK) {
|
||||||
|
if (value < currentMaxSize) {
|
||||||
|
// We found a smaller value to reduce the video size
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// No fallback, fail definitively
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean encode(MediaCodec codec, FileDescriptor fd) throws IOException {
|
private boolean encode(MediaCodec codec, FileDescriptor fd) throws IOException {
|
||||||
boolean eof = false;
|
boolean eof = false;
|
||||||
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
||||||
@@ -122,6 +163,10 @@ public class ScreenEncoder implements Device.RotationListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IO.writeFully(fd, codecBuffer);
|
IO.writeFully(fd, codecBuffer);
|
||||||
|
if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) == 0) {
|
||||||
|
// If this is not a config packet, then it contains a frame
|
||||||
|
firstFrameSent = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (outputBufferId >= 0) {
|
if (outputBufferId >= 0) {
|
||||||
|
|||||||
@@ -80,15 +80,12 @@ public final class ScreenInfo {
|
|||||||
return new ScreenInfo(newContentRect, newUnlockedVideoSize, newDeviceRotation, lockedVideoOrientation);
|
return new ScreenInfo(newContentRect, newUnlockedVideoSize, newDeviceRotation, lockedVideoOrientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ScreenInfo computeScreenInfo(DisplayInfo displayInfo, Rect crop, int maxSize, int lockedVideoOrientation) {
|
public static ScreenInfo computeScreenInfo(int rotation, Size deviceSize, Rect crop, int maxSize, int lockedVideoOrientation) {
|
||||||
int rotation = displayInfo.getRotation();
|
|
||||||
|
|
||||||
if (lockedVideoOrientation == Device.LOCK_VIDEO_ORIENTATION_INITIAL) {
|
if (lockedVideoOrientation == Device.LOCK_VIDEO_ORIENTATION_INITIAL) {
|
||||||
// The user requested to lock the video orientation to the current orientation
|
// The user requested to lock the video orientation to the current orientation
|
||||||
lockedVideoOrientation = rotation;
|
lockedVideoOrientation = rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
Size deviceSize = displayInfo.getSize();
|
|
||||||
Rect contentRect = new Rect(0, 0, deviceSize.getWidth(), deviceSize.getHeight());
|
Rect contentRect = new Rect(0, 0, deviceSize.getWidth(), deviceSize.getHeight());
|
||||||
if (crop != null) {
|
if (crop != null) {
|
||||||
if (rotation % 2 != 0) { // 180s preserve dimensions
|
if (rotation % 2 != 0) { // 180s preserve dimensions
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.genymobile.scrcpy;
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.media.MediaCodec;
|
|
||||||
import android.media.MediaCodecInfo;
|
import android.media.MediaCodecInfo;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@@ -20,6 +19,7 @@ public final class Server {
|
|||||||
private static void initAndCleanUp(Options options) {
|
private static void initAndCleanUp(Options options) {
|
||||||
boolean mustDisableShowTouchesOnCleanUp = false;
|
boolean mustDisableShowTouchesOnCleanUp = false;
|
||||||
int restoreStayOn = -1;
|
int restoreStayOn = -1;
|
||||||
|
boolean restoreNormalPowerMode = options.getControl(); // only restore power mode if control is enabled
|
||||||
if (options.getShowTouches() || options.getStayAwake()) {
|
if (options.getShowTouches() || options.getStayAwake()) {
|
||||||
Settings settings = Device.getSettings();
|
Settings settings = Device.getSettings();
|
||||||
if (options.getShowTouches()) {
|
if (options.getShowTouches()) {
|
||||||
@@ -52,7 +52,8 @@ public final class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CleanUp.configure(options.getDisplayId(), restoreStayOn, mustDisableShowTouchesOnCleanUp, true, options.getPowerOffScreenOnClose());
|
CleanUp.configure(options.getDisplayId(), restoreStayOn, mustDisableShowTouchesOnCleanUp, restoreNormalPowerMode,
|
||||||
|
options.getPowerOffScreenOnClose());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Ln.e("Could not configure cleanup", e);
|
Ln.e("Could not configure cleanup", e);
|
||||||
}
|
}
|
||||||
@@ -67,10 +68,15 @@ public final class Server {
|
|||||||
|
|
||||||
boolean tunnelForward = options.isTunnelForward();
|
boolean tunnelForward = options.isTunnelForward();
|
||||||
boolean control = options.getControl();
|
boolean control = options.getControl();
|
||||||
|
boolean sendDummyByte = options.getSendDummyByte();
|
||||||
|
|
||||||
try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward, control)) {
|
try (DesktopConnection connection = DesktopConnection.open(tunnelForward, control, sendDummyByte)) {
|
||||||
|
if (options.getSendDeviceMeta()) {
|
||||||
|
Size videoSize = device.getScreenInfo().getVideoSize();
|
||||||
|
connection.sendDeviceMeta(Device.getDeviceName(), videoSize.getWidth(), videoSize.getHeight());
|
||||||
|
}
|
||||||
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps(), codecOptions,
|
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps(), codecOptions,
|
||||||
options.getEncoderName());
|
options.getEncoderName(), options.getDownsizeOnError());
|
||||||
|
|
||||||
Thread controllerThread = null;
|
Thread controllerThread = null;
|
||||||
Thread deviceMessageSenderThread = null;
|
Thread deviceMessageSenderThread = null;
|
||||||
@@ -200,10 +206,6 @@ public final class Server {
|
|||||||
Rect crop = parseCrop(value);
|
Rect crop = parseCrop(value);
|
||||||
options.setCrop(crop);
|
options.setCrop(crop);
|
||||||
break;
|
break;
|
||||||
case "send_frame_meta":
|
|
||||||
boolean sendFrameMeta = Boolean.parseBoolean(value);
|
|
||||||
options.setSendFrameMeta(sendFrameMeta);
|
|
||||||
break;
|
|
||||||
case "control":
|
case "control":
|
||||||
boolean control = Boolean.parseBoolean(value);
|
boolean control = Boolean.parseBoolean(value);
|
||||||
options.setControl(control);
|
options.setControl(control);
|
||||||
@@ -237,6 +239,30 @@ public final class Server {
|
|||||||
boolean clipboardAutosync = Boolean.parseBoolean(value);
|
boolean clipboardAutosync = Boolean.parseBoolean(value);
|
||||||
options.setClipboardAutosync(clipboardAutosync);
|
options.setClipboardAutosync(clipboardAutosync);
|
||||||
break;
|
break;
|
||||||
|
case "downsize_on_error":
|
||||||
|
boolean downsizeOnError = Boolean.parseBoolean(value);
|
||||||
|
options.setDownsizeOnError(downsizeOnError);
|
||||||
|
break;
|
||||||
|
case "send_device_meta":
|
||||||
|
boolean sendDeviceMeta = Boolean.parseBoolean(value);
|
||||||
|
options.setSendDeviceMeta(sendDeviceMeta);
|
||||||
|
break;
|
||||||
|
case "send_frame_meta":
|
||||||
|
boolean sendFrameMeta = Boolean.parseBoolean(value);
|
||||||
|
options.setSendFrameMeta(sendFrameMeta);
|
||||||
|
break;
|
||||||
|
case "send_dummy_byte":
|
||||||
|
boolean sendDummyByte = Boolean.parseBoolean(value);
|
||||||
|
options.setSendDummyByte(sendDummyByte);
|
||||||
|
break;
|
||||||
|
case "raw_video_stream":
|
||||||
|
boolean rawVideoStream = Boolean.parseBoolean(value);
|
||||||
|
if (rawVideoStream) {
|
||||||
|
options.setSendDeviceMeta(false);
|
||||||
|
options.setSendFrameMeta(false);
|
||||||
|
options.setSendDummyByte(false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Ln.w("Unknown server option: " + key);
|
Ln.w("Unknown server option: " + key);
|
||||||
break;
|
break;
|
||||||
@@ -263,16 +289,6 @@ public final class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void suggestFix(Throwable e) {
|
private static void suggestFix(Throwable e) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
||||||
if (e instanceof MediaCodec.CodecException) {
|
|
||||||
MediaCodec.CodecException mce = (MediaCodec.CodecException) e;
|
|
||||||
if (mce.getErrorCode() == 0xfffffc0e) {
|
|
||||||
Ln.e("The hardware encoder is not able to encode at the given definition.");
|
|
||||||
Ln.e("Try with a lower definition:");
|
|
||||||
Ln.e(" scrcpy -m 1024");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (e instanceof InvalidDisplayIdException) {
|
if (e instanceof InvalidDisplayIdException) {
|
||||||
InvalidDisplayIdException idie = (InvalidDisplayIdException) e;
|
InvalidDisplayIdException idie = (InvalidDisplayIdException) e;
|
||||||
int[] displayIds = idie.getAvailableDisplayIds();
|
int[] displayIds = idie.getAvailableDisplayIds();
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public final class InputManager {
|
|||||||
|
|
||||||
private final IInterface manager;
|
private final IInterface manager;
|
||||||
private Method injectInputEventMethod;
|
private Method injectInputEventMethod;
|
||||||
|
private boolean alternativeInjectInputEventMethod;
|
||||||
|
|
||||||
private static Method setDisplayIdMethod;
|
private static Method setDisplayIdMethod;
|
||||||
|
|
||||||
@@ -25,7 +26,12 @@ public final class InputManager {
|
|||||||
|
|
||||||
private Method getInjectInputEventMethod() throws NoSuchMethodException {
|
private Method getInjectInputEventMethod() throws NoSuchMethodException {
|
||||||
if (injectInputEventMethod == null) {
|
if (injectInputEventMethod == null) {
|
||||||
|
try {
|
||||||
injectInputEventMethod = manager.getClass().getMethod("injectInputEvent", InputEvent.class, int.class);
|
injectInputEventMethod = manager.getClass().getMethod("injectInputEvent", InputEvent.class, int.class);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
injectInputEventMethod = manager.getClass().getMethod("injectInputEvent", InputEvent.class, int.class, int.class);
|
||||||
|
alternativeInjectInputEventMethod = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return injectInputEventMethod;
|
return injectInputEventMethod;
|
||||||
}
|
}
|
||||||
@@ -33,6 +39,10 @@ public final class InputManager {
|
|||||||
public boolean injectInputEvent(InputEvent inputEvent, int mode) {
|
public boolean injectInputEvent(InputEvent inputEvent, int mode) {
|
||||||
try {
|
try {
|
||||||
Method method = getInjectInputEventMethod();
|
Method method = getInjectInputEventMethod();
|
||||||
|
if (alternativeInjectInputEventMethod) {
|
||||||
|
// See <https://github.com/Genymobile/scrcpy/issues/2250>
|
||||||
|
return (boolean) method.invoke(manager, inputEvent, mode, 0);
|
||||||
|
}
|
||||||
return (boolean) method.invoke(manager, inputEvent, mode);
|
return (boolean) method.invoke(manager, inputEvent, mode);
|
||||||
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||||
Ln.e("Could not invoke method", e);
|
Ln.e("Could not invoke method", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user