Compare commits
26 commits
Author | SHA1 | Date | |
---|---|---|---|
57fb08e443 | |||
02ae0db6cd | |||
739ff9dce0 | |||
65b023ac6d | |||
a045e28df8 | |||
52138fd921 | |||
1bb0df5da1 | |||
562ec6e9b3 | |||
1be5daf999 | |||
57387fa707 | |||
4e811a4a68 | |||
99a4a48477 | |||
1d97d77032 | |||
45b0f8123a | |||
c1a34881d7 | |||
057c7a4df4 | |||
979ce64dc0 | |||
9a0bd545d5 | |||
c4d008b96a | |||
0d45c29d13 | |||
37c840a4c8 | |||
f488cbd7e7 | |||
790f04e91f | |||
96e3963afc | |||
63b2b5ca4e | |||
a846c01883 |
10
BUILD.md
10
BUILD.md
|
@ -15,7 +15,7 @@ First, you need to install the required packages:
|
|||
sudo apt install ffmpeg libsdl2-2.0-0 adb wget \
|
||||
gcc git pkg-config meson ninja-build libsdl2-dev \
|
||||
libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev \
|
||||
libusb-1.0-0 libusb-dev
|
||||
libusb-1.0-0 libusb-1.0-0-dev
|
||||
```
|
||||
|
||||
Then clone the repo and execute the installation script
|
||||
|
@ -94,7 +94,7 @@ sudo apt install ffmpeg libsdl2-2.0-0 adb libusb-1.0-0
|
|||
# client build dependencies
|
||||
sudo apt install gcc git pkg-config meson ninja-build libsdl2-dev \
|
||||
libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev \
|
||||
libusb-dev
|
||||
libusb-1.0-0-dev
|
||||
|
||||
# server build dependencies
|
||||
sudo apt install openjdk-11-jdk
|
||||
|
@ -270,10 +270,10 @@ install` must be run as root)._
|
|||
|
||||
#### Option 2: Use prebuilt server
|
||||
|
||||
- [`scrcpy-server-v1.19`][direct-scrcpy-server]
|
||||
_(SHA-256: 876f9322182e6aac6a58db1334f4225855ef3a17eaebc80aab6601d9d1ecb867)_
|
||||
- [`scrcpy-server-v1.20`][direct-scrcpy-server]
|
||||
_(SHA-256: b20aee4951f99b060c4a44000ba94de973f9604758ef62beb253b371aad3df34)_
|
||||
|
||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.19/scrcpy-server-v1.19
|
||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.20/scrcpy-server-v1.20
|
||||
|
||||
Download the prebuilt server somewhere, and specify its path during the Meson
|
||||
configuration:
|
||||
|
|
18
FAQ.it.md
18
FAQ.it.md
|
@ -140,6 +140,24 @@ Potresti anche dover configurare il [comportamento di ridimensionamento][scaling
|
|||
[scaling behavior]: https://github.com/Genymobile/scrcpy/issues/40#issuecomment-424466723
|
||||
|
||||
|
||||
### Problema con Wayland
|
||||
|
||||
Per impostazione predefinita, SDL utilizza x11 su Linux. Il [video driver] può essere cambiato attraversio la variabile d'ambiente `SDL_VIDEODRIVER`:
|
||||
|
||||
[video driver]: https://wiki.libsdl.org/FAQUsingSDL#how_do_i_choose_a_specific_video_driver
|
||||
|
||||
```bash
|
||||
export SDL_VIDEODRIVER=wayland
|
||||
scrcpy
|
||||
```
|
||||
|
||||
Su alcune distribuzioni (almeno Fedora), il pacchetto `libdecor` deve essere installato manualmente.
|
||||
|
||||
Vedi le issues [#2554] e [#2559].
|
||||
|
||||
[#2554]: https://github.com/Genymobile/scrcpy/issues/2554
|
||||
[#2559]: https://github.com/Genymobile/scrcpy/issues/2559
|
||||
|
||||
|
||||
### Crash del compositore KWin
|
||||
|
||||
|
|
23
FAQ.md
23
FAQ.md
|
@ -222,6 +222,27 @@ scrcpy -m 800
|
|||
You could also try another [encoder](README.md#encoder).
|
||||
|
||||
|
||||
If you encounter this exception on Android 12, then just upgrade to scrcpy >=
|
||||
1.18 (see [#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
|
||||
|
||||
|
||||
## Command line on Windows
|
||||
|
||||
Some Windows users are not familiar with the command line. Here is how to open a
|
||||
|
@ -262,6 +283,6 @@ to add some arguments.
|
|||
|
||||
This FAQ is available in other languages:
|
||||
|
||||
- [Italiano (Italiano, `it`) - v1.17](FAQ.it.md)
|
||||
- [Italiano (Italiano, `it`) - v1.19](FAQ.it.md)
|
||||
- [한국어 (Korean, `ko`) - v1.11](FAQ.ko.md)
|
||||
- [简体中文 (Simplified Chinese, `zh-Hans`) - v1.18](FAQ.zh-Hans.md)
|
||||
|
|
121
README.it.md
121
README.it.md
|
@ -1,6 +1,6 @@
|
|||
_Apri il [README](README.md) originale e sempre aggiornato._
|
||||
|
||||
# scrcpy (v1.17)
|
||||
# scrcpy (v1.19)
|
||||
|
||||
Questa applicazione fornisce la visualizzazione e il controllo dei dispositivi Android collegati via USB (o [via TCP/IP][article-tcpip]). Non richiede alcun accesso _root_.
|
||||
Funziona su _GNU/Linux_, _Windows_ e _macOS_.
|
||||
|
@ -205,10 +205,11 @@ Se anche `--max-size` è specificata, il ridimensionamento è applicato dopo il
|
|||
Per bloccare l'orientamento della trasmissione:
|
||||
|
||||
```bash
|
||||
scrcpy --lock-video-orientation 0 # orientamento naturale
|
||||
scrcpy --lock-video-orientation 1 # 90° antiorario
|
||||
scrcpy --lock-video-orientation 2 # 180°
|
||||
scrcpy --lock-video-orientation 3 # 90° orario
|
||||
scrcpy --lock-video-orientation # orientamento iniziale (corrente)
|
||||
scrcpy --lock-video-orientation=0 # orientamento naturale
|
||||
scrcpy --lock-video-orientation=1 # 90° antiorario
|
||||
scrcpy --lock-video-orientation=2 # 180°
|
||||
scrcpy --lock-video-orientation=3 # 90° orario
|
||||
```
|
||||
|
||||
Questo influisce sull'orientamento della registrazione.
|
||||
|
@ -231,7 +232,9 @@ Per elencare i codificatori disponibili puoi immettere un nome di codificatore n
|
|||
scrcpy --encoder _
|
||||
```
|
||||
|
||||
### Registrazione
|
||||
### Cattura
|
||||
|
||||
#### Registrazione
|
||||
|
||||
È possibile registrare lo schermo durante la trasmissione:
|
||||
|
||||
|
@ -253,6 +256,75 @@ I "fotogrammi saltati" sono registrati nonostante non siano mostrati in tempo re
|
|||
[packet delay variation]: https://en.wikipedia.org/wiki/Packet_delay_variation
|
||||
|
||||
|
||||
#### v4l2loopback
|
||||
|
||||
Su Linux è possibile inviare il flusso video ad un dispositivo v4l2 loopback, cosicchè un dispositivo Android possa essere aperto come una webcam da qualsiasi strumento compatibile con v4l2.
|
||||
|
||||
Il modulo `v4l2loopback` deve essere installato:
|
||||
|
||||
```bash
|
||||
sudo apt install v4l2loopback-dkms
|
||||
```
|
||||
|
||||
Per creare un dispositvo v4l2:
|
||||
|
||||
```bash
|
||||
sudo modprobe v4l2loopback
|
||||
```
|
||||
|
||||
Questo creerà un nuovo dispositivo video in `/dev/videoN` dove `N` è un intero (più [opzioni](https://github.com/umlaeute/v4l2loopback#options) sono disponibili per crere più dispositivi o dispositivi con ID specifici).
|
||||
|
||||
Per elencare i dispositvi attivati:
|
||||
|
||||
```bash
|
||||
# necessita del pacchetto v4l-utils
|
||||
v4l2-ctl --list-devices
|
||||
|
||||
# semplice ma potrebbe essere sufficiente
|
||||
ls /dev/video*
|
||||
```
|
||||
|
||||
Per avviare scrcpy utilizzando un v4l2 sink:
|
||||
|
||||
```bash
|
||||
scrcpy --v4l2-sink=/dev/videoN
|
||||
scrcpy --v4l2-sink=/dev/videoN --no-display # disabilita la finestra di trasmissione
|
||||
scrcpy --v4l2-sink=/dev/videoN -N # versione corta
|
||||
```
|
||||
|
||||
(sostituisci `N` con l'ID del dispositivo, controlla con `ls /dev/video*`)
|
||||
|
||||
Una volta abilitato, puoi aprire il tuo flusso video con uno strumento compatibile con v4l2:
|
||||
|
||||
```bash
|
||||
ffplay -i /dev/videoN
|
||||
vlc v4l2:///dev/videoN # VLC potrebbe aggiungere del ritardo per il buffer
|
||||
```
|
||||
|
||||
Per esempio potresti catturare il video in [OBS].
|
||||
|
||||
[OBS]: https://obsproject.com/
|
||||
|
||||
|
||||
#### Buffering
|
||||
|
||||
È possibile aggiungere del buffer. Questo aumenta la latenza ma riduce il jitter (vedi [#2464]).
|
||||
|
||||
[#2464]: https://github.com/Genymobile/scrcpy/issues/2464
|
||||
|
||||
L'opzione è disponibile per il buffer della visualizzazione:
|
||||
|
||||
```bash
|
||||
scrcpy --display-buffer=50 # aggiungi 50 ms di buffer per la visualizzazione
|
||||
```
|
||||
|
||||
e per il V4L2 sink:
|
||||
|
||||
```bash
|
||||
scrcpy --v4l2-buffer=500 # aggiungi 50 ms di buffer per il v4l2 sink
|
||||
```
|
||||
|
||||
|
||||
### Connessione
|
||||
|
||||
#### Wireless
|
||||
|
@ -479,15 +551,6 @@ scrcpy --turn-screen-off --stay-awake
|
|||
scrcpy -Sw
|
||||
```
|
||||
|
||||
#### Renderizzare i fotogrammi scaduti
|
||||
|
||||
Per minimizzare la latenza _scrcpy_ renderizza sempre l'ultimo fotogramma decodificato disponibile in maniera predefinita e tralascia quelli precedenti.
|
||||
|
||||
Per forzare la renderizzazione di tutti i fotogrammi (a costo di una possibile latenza superiore), utilizzare:
|
||||
|
||||
```bash
|
||||
scrcpy --render-expired-frames
|
||||
```
|
||||
|
||||
#### Mostrare i tocchi
|
||||
|
||||
|
@ -607,14 +670,14 @@ Non c'è alcuna risposta visiva, un log è stampato nella console.
|
|||
|
||||
#### Trasferimento di file verso il dispositivo
|
||||
|
||||
Per trasferire un file in `/sdcard/` del dispositivo trascina e rilascia un file (non APK) nella finestra di _scrcpy_.
|
||||
Per trasferire un file in `/sdcard/Download` del dispositivo trascina e rilascia un file (non APK) nella finestra di _scrcpy_.
|
||||
|
||||
Non c'è alcuna risposta visiva, un log è stampato nella console.
|
||||
|
||||
La cartella di destinazione può essere cambiata all'avvio:
|
||||
|
||||
```bash
|
||||
scrcpy --push-target=/sdcard/Download/
|
||||
scrcpy --push-target=/sdcard/Movies/
|
||||
```
|
||||
|
||||
|
||||
|
@ -653,10 +716,10 @@ _<kbd>[Super]</kbd> è il pulsante <kbd>Windows</kbd> o <kbd>Cmd</kbd>._
|
|||
| Rotazione schermo a sinistra | <kbd>MOD</kbd>+<kbd>←</kbd> _(sinistra)_
|
||||
| Rotazione schermo a destra | <kbd>MOD</kbd>+<kbd>→</kbd> _(destra)_
|
||||
| Ridimensiona finestra a 1:1 (pixel-perfect) | <kbd>MOD</kbd>+<kbd>g</kbd>
|
||||
| Ridimensiona la finestra per rimuovere i bordi neri | <kbd>MOD</kbd>+<kbd>w</kbd> \| _Doppio click¹_
|
||||
| Ridimensiona la finestra per rimuovere i bordi neri | <kbd>MOD</kbd>+<kbd>w</kbd> \| _Doppio click sinistro¹_
|
||||
| Premi il tasto `HOME` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _Click centrale_
|
||||
| Premi il tasto `BACK` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _Click destro²_
|
||||
| Premi il tasto `APP_SWITCH` | <kbd>MOD</kbd>+<kbd>s</kbd>
|
||||
| Premi il tasto `APP_SWITCH` | <kbd>MOD</kbd>+<kbd>s</kbd> \| _4° click³_
|
||||
| Premi il tasto `MENU` (sblocca lo schermo) | <kbd>MOD</kbd>+<kbd>m</kbd>
|
||||
| Premi il tasto `VOLUME_UP` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(su)_
|
||||
| Premi il tasto `VOLUME_DOWN` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(giù)_
|
||||
|
@ -665,18 +728,26 @@ _<kbd>[Super]</kbd> è il pulsante <kbd>Windows</kbd> o <kbd>Cmd</kbd>._
|
|||
| Spegni lo schermo del dispositivo (continua a trasmettere) | <kbd>MOD</kbd>+<kbd>o</kbd>
|
||||
| Accendi lo schermo del dispositivo | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>o</kbd>
|
||||
| Ruota lo schermo del dispositivo | <kbd>MOD</kbd>+<kbd>r</kbd>
|
||||
| Espandi il pannello delle notifiche | <kbd>MOD</kbd>+<kbd>n</kbd>
|
||||
| Chiudi il pannello delle notifiche | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
||||
| Copia negli appunti³ | <kbd>MOD</kbd>+<kbd>c</kbd>
|
||||
| Taglia negli appunti³ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
||||
| Sincronizza gli appunti e incolla³ | <kbd>MOD</kbd>+<kbd>v</kbd>
|
||||
| Espandi il pannello delle notifiche | <kbd>MOD</kbd>+<kbd>n</kbd> \| _5° click³_
|
||||
| Espandi il pannello delle impostazioni | <kbd>MOD</kbd>+<kbd>n</kbd>+<kbd>n</kbd> \| _Doppio 5° click³_
|
||||
| Chiudi pannelli | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
||||
| Copia negli appunti⁴ | <kbd>MOD</kbd>+<kbd>c</kbd>
|
||||
| Taglia negli appunti⁴ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
||||
| Sincronizza gli appunti e incolla⁴ | <kbd>MOD</kbd>+<kbd>v</kbd>
|
||||
| Inietta il testo degli appunti del computer | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>
|
||||
| Abilita/Disabilita il contatore FPS (su stdout) | <kbd>MOD</kbd>+<kbd>i</kbd>
|
||||
| Pizzica per zoomare | <kbd>Ctrl</kbd>+_click e trascina_
|
||||
|
||||
_¹Doppio click sui bordi neri per rimuoverli._
|
||||
_²Il tasto destro accende lo schermo se era spento, preme BACK in caso contrario._
|
||||
_³Solo in Android >= 7._
|
||||
_³4° e 5° pulsante del mouse, se il tuo mouse ne dispone._
|
||||
_⁴Solo in Android >= 7._
|
||||
|
||||
Le scorciatoie con pulsanti ripetuti sono eseguite rilasciando e premendo il pulsante una seconda volta. Per esempio, per eseguire "Espandi il pannello delle impostazioni":
|
||||
|
||||
1. Premi e tieni premuto <kbd>MOD</kbd>.
|
||||
2. Poi premi due volte <kbd>n</kbd>.
|
||||
3. Infine rilascia <kbd>MOD</kbd>.
|
||||
|
||||
Tutte le scorciatoie <kbd>Ctrl</kbd>+_tasto_ sono inoltrate al dispositivo, così sono gestite dall'applicazione attiva.
|
||||
|
||||
|
|
132
README.jp.md
132
README.jp.md
|
@ -1,6 +1,6 @@
|
|||
_Only the original [README](README.md) is guaranteed to be up-to-date._
|
||||
|
||||
# scrcpy (v1.17)
|
||||
# scrcpy (v1.19)
|
||||
|
||||
このアプリケーションはUSB(もしくは[TCP/IP経由][article-tcpip])で接続されたAndroidデバイスの表示と制御を提供します。このアプリケーションは _root_ でのアクセスを必要としません。このアプリケーションは _GNU/Linux_ 、 _Windows_ そして _macOS_ 上で動作します。
|
||||
|
||||
|
@ -103,18 +103,21 @@ scoop install adb # まだ入手していない場合
|
|||
brew install scrcpy
|
||||
```
|
||||
|
||||
`PATH`から`adb`へのアクセスが必要です。もしまだ持っていない場合:
|
||||
`PATH`からアクセス可能な`adb`が必要です。もし持っていない場合はインストールしてください。
|
||||
|
||||
```bash
|
||||
# Homebrew >= 2.6.0
|
||||
brew install --cask android-platform-tools
|
||||
|
||||
# Homebrew < 2.6.0
|
||||
brew cask install android-platform-tools
|
||||
brew install android-platform-tools
|
||||
```
|
||||
|
||||
また、[アプリケーションをビルド][BUILD]することも可能です。
|
||||
`adb`は[MacPorts]からでもインストールできます。
|
||||
|
||||
```bash
|
||||
sudo port install scrcpy
|
||||
```
|
||||
|
||||
[MacPorts]: https://www.macports.org/
|
||||
|
||||
また、[アプリケーションをビルド][BUILD]することも可能です。
|
||||
|
||||
## 実行
|
||||
|
||||
|
@ -184,10 +187,11 @@ scrcpy --crop 1224:1440:0:0 # オフセット位置(0,0)で1224x1440
|
|||
ミラーリングの向きをロックするには:
|
||||
|
||||
```bash
|
||||
scrcpy --lock-video-orientation 0 # 自然な向き
|
||||
scrcpy --lock-video-orientation 1 # 90°反時計回り
|
||||
scrcpy --lock-video-orientation 2 # 180°
|
||||
scrcpy --lock-video-orientation 3 # 90°時計回り
|
||||
scrcpy --lock-video-orientation # 現在の向き
|
||||
scrcpy --lock-video-orientation=0 # 自然な向き
|
||||
scrcpy --lock-video-orientation=1 # 90°反時計回り
|
||||
scrcpy --lock-video-orientation=2 # 180°
|
||||
scrcpy --lock-video-orientation=3 # 90°時計回り
|
||||
```
|
||||
|
||||
この設定は録画の向きに影響します。
|
||||
|
@ -210,7 +214,9 @@ scrcpy --encoder OMX.qcom.video.encoder.avc
|
|||
scrcpy --encoder _
|
||||
```
|
||||
|
||||
### 録画
|
||||
### キャプチャ
|
||||
|
||||
#### 録画
|
||||
|
||||
ミラーリング中に画面の録画をすることが可能です:
|
||||
|
||||
|
@ -233,6 +239,77 @@ scrcpy -Nr file.mkv
|
|||
|
||||
[パケット遅延のバリエーション]: https://en.wikipedia.org/wiki/Packet_delay_variation
|
||||
|
||||
#### v4l2loopback
|
||||
|
||||
Linuxでは、ビデオストリームをv4l2ループバックデバイスに送信することができます。
|
||||
v4l2loopbackのデバイスにビデオストリームを送信することで、Androidデバイスをウェブカメラのようにv4l2対応ツールで開くこともできます。
|
||||
|
||||
`v4l2loopback` モジュールのインストールが必要です。
|
||||
|
||||
```bash
|
||||
sudo apt install v4l2loopback-dkms
|
||||
```
|
||||
|
||||
v4l2デバイスを作成する。
|
||||
|
||||
```bash
|
||||
sudo modprobe v4l2loopback
|
||||
```
|
||||
|
||||
これにより、新しいビデオデバイスが `/dev/videoN` に作成されます。(`N` は整数)
|
||||
(複数のデバイスや特定のIDのデバイスを作成するために、より多くの[オプション](https://github.com/umlaeute/v4l2loopback#options)が利用可能です。
|
||||
多くの[オプション]()が利用可能で複数のデバイスや特定のIDのデバイスを作成できます。
|
||||
|
||||
|
||||
有効なデバイスを一覧表示する:
|
||||
|
||||
```bash
|
||||
# v4l-utilsパッケージが必要
|
||||
v4l2-ctl --list-devices
|
||||
|
||||
# シンプルですが十分これで確認できます
|
||||
ls /dev/video*
|
||||
```
|
||||
|
||||
v4l2シンクを使用してscrcpyを起動する。
|
||||
|
||||
```bash
|
||||
scrcpy --v4l2-sink=/dev/videoN
|
||||
scrcpy --v4l2-sink=/dev/videoN --no-display # ミラーリングウィンドウを無効化する
|
||||
scrcpy --v4l2-sink=/dev/videoN -N # 短縮版
|
||||
```
|
||||
|
||||
(`N` をデバイス ID に置き換えて、`ls /dev/video*` で確認してください)
|
||||
有効にすると、v4l2対応のツールでビデオストリームを開けます。
|
||||
|
||||
```bash
|
||||
ffplay -i /dev/videoN
|
||||
vlc v4l2:///dev/videoN # VLCではバッファリングの遅延が発生する場合があります
|
||||
```
|
||||
|
||||
例えばですが [OBS]の中にこの映像を取り込めことができます。
|
||||
|
||||
[OBS]: https://obsproject.com/
|
||||
|
||||
|
||||
#### Buffering
|
||||
|
||||
バッファリングを追加することも可能です。これによりレイテンシーは増加しますが、ジッターは減少します。(参照
|
||||
[#2464])
|
||||
|
||||
[#2464]: https://github.com/Genymobile/scrcpy/issues/2464
|
||||
|
||||
このオプションでディスプレイバッファリングを設定できます。
|
||||
|
||||
```bash
|
||||
scrcpy --display-buffer=50 # ディスプレイに50msのバッファリングを追加する
|
||||
```
|
||||
|
||||
V4L2の場合はこちらのオプションで設定できます。
|
||||
|
||||
```bash
|
||||
scrcpy --v4l2-buffer=500 # add 500 ms buffering for v4l2 sink
|
||||
```
|
||||
|
||||
### 接続
|
||||
|
||||
|
@ -457,16 +534,6 @@ scrcpy -Sw
|
|||
```
|
||||
|
||||
|
||||
#### 期限切れフレームをレンダリングする
|
||||
|
||||
初期状態では、待ち時間を最小限にするために、_scrcpy_ は最後にデコードされたフレームをレンダリングし、前のフレームを削除します。
|
||||
|
||||
全フレームのレンダリングを強制するには(待ち時間が長くなる可能性があります):
|
||||
|
||||
```bash
|
||||
scrcpy --render-expired-frames
|
||||
```
|
||||
|
||||
#### タッチを表示
|
||||
|
||||
プレゼンテーションの場合(物理デバイス上で)物理的なタッチを表示すると便利な場合があります。
|
||||
|
@ -586,14 +653,14 @@ APKをインストールするには、(`.apk`で終わる)APKファイルを _s
|
|||
|
||||
#### デバイスにファイルを送る
|
||||
|
||||
デバイスの`/sdcard/`ディレクトリにファイルを送るには、(APKではない)ファイルを _scrcpy_ の画面にドラッグ&ドロップします。
|
||||
デバイスの`/sdcard/Download`ディレクトリにファイルを送るには、(APKではない)ファイルを _scrcpy_ の画面にドラッグ&ドロップします。
|
||||
|
||||
見た目のフィードバックはありません。コンソールにログが出力されます。
|
||||
|
||||
転送先ディレクトリを起動時に変更することができます:
|
||||
|
||||
```bash
|
||||
scrcpy --push-target /sdcard/foo/bar/
|
||||
scrcpy --push-target=/sdcard/Movies/
|
||||
```
|
||||
|
||||
|
||||
|
@ -634,7 +701,7 @@ _<kbd>[Super]</kbd>は通常<kbd>Windows</kbd>もしくは<kbd>Cmd</kbd>キー
|
|||
| ウィンドウサイズを変更して黒い境界線を削除 | <kbd>MOD</kbd>+<kbd>w</kbd> \| _ダブルクリック¹_
|
||||
| `HOME`をクリック | <kbd>MOD</kbd>+<kbd>h</kbd> \| _真ん中クリック_
|
||||
| `BACK`をクリック | <kbd>MOD</kbd>+<kbd>b</kbd> \| _右クリック²_
|
||||
| `APP_SWITCH`をクリック | <kbd>MOD</kbd>+<kbd>s</kbd>
|
||||
| `APP_SWITCH`をクリック | <kbd>MOD</kbd>+<kbd>s</kbd> \| _4クリック³_
|
||||
| `MENU` (画面のアンロック)をクリック | <kbd>MOD</kbd>+<kbd>m</kbd>
|
||||
| `VOLUME_UP`をクリック | <kbd>MOD</kbd>+<kbd>↑</kbd> _(上)_
|
||||
| `VOLUME_DOWN`をクリック | <kbd>MOD</kbd>+<kbd>↓</kbd> _(下)_
|
||||
|
@ -643,7 +710,8 @@ _<kbd>[Super]</kbd>は通常<kbd>Windows</kbd>もしくは<kbd>Cmd</kbd>キー
|
|||
| デバイス画面をオフにする(ミラーリングしたまま) | <kbd>MOD</kbd>+<kbd>o</kbd>
|
||||
| デバイス画面をオンにする | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>o</kbd>
|
||||
| デバイス画面を回転する | <kbd>MOD</kbd>+<kbd>r</kbd>
|
||||
| 通知パネルを展開する | <kbd>MOD</kbd>+<kbd>n</kbd>
|
||||
| 通知パネルを展開する | <kbd>MOD</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>c</kbd>
|
||||
| クリップボードへのカット³ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
||||
|
@ -654,11 +722,17 @@ _<kbd>[Super]</kbd>は通常<kbd>Windows</kbd>もしくは<kbd>Cmd</kbd>キー
|
|||
|
||||
_¹黒い境界線を削除するため、境界線上でダブルクリック_
|
||||
_²もしスクリーンがオフの場合、右クリックでスクリーンをオンする。それ以外の場合はBackを押します._
|
||||
_³Android 7以上のみ._
|
||||
_³4と5はマウスのボタンです、もしあなたのマウスにボタンがあれば使えます._
|
||||
_⁴Android 7以上のみ._
|
||||
|
||||
キーを繰り返すショートカットはキーを離して2回目を押したら実行されます。例えば「設定パネルを展開する」を実行する場合は以下のように操作する。
|
||||
|
||||
1. <kbd>MOD</kbd> キーを押し、押したままにする.
|
||||
2. その後に <kbd>n</kbd>キーを2回押す.
|
||||
3. 最後に <kbd>MOD</kbd>キーを離す.
|
||||
|
||||
全ての<kbd>Ctrl</kbd>+_キー_ ショートカットはデバイスに転送されます、そのためアクティブなアプリケーションによって処理されます。
|
||||
|
||||
|
||||
## カスタムパス
|
||||
|
||||
特定の _adb_ バイナリを使用する場合、そのパスを環境変数`ADB`で構成します:
|
||||
|
|
51
README.md
51
README.md
|
@ -1,26 +1,37 @@
|
|||
# scrcpy (v1.19)
|
||||
# scrcpy (v1.20)
|
||||
|
||||
![icon](data/icon.png)
|
||||
<img src="data/icon.svg" width="128" height="128" alt="scrcpy" align="right" />
|
||||
|
||||
[Read in another language](#translations)
|
||||
|
||||
This application provides display and control of Android devices connected on
|
||||
USB (or [over TCP/IP][article-tcpip]). It does not require any _root_ access.
|
||||
This application provides display and control of Android devices connected via
|
||||
USB (or [over TCP/IP](#wireless)). It does not require any _root_ access.
|
||||
It works on _GNU/Linux_, _Windows_ and _macOS_.
|
||||
|
||||
![screenshot](assets/screenshot-debian-600.jpg)
|
||||
|
||||
It focuses on:
|
||||
|
||||
- **lightness** (native, displays only the device screen)
|
||||
- **performance** (30~60fps)
|
||||
- **quality** (1920×1080 or above)
|
||||
- **low latency** ([35~70ms][lowlatency])
|
||||
- **low startup time** (~1 second to display the first image)
|
||||
- **non-intrusiveness** (nothing is left installed on the device)
|
||||
- **lightness**: native, displays only the device screen
|
||||
- **performance**: 30~120fps, depending on the device
|
||||
- **quality**: 1920×1080 or above
|
||||
- **low latency**: [35~70ms][lowlatency]
|
||||
- **low startup time**: ~1 second to display the first image
|
||||
- **non-intrusiveness**: nothing is left installed on the device
|
||||
- **user benefits**: no account, no ads, no internet required
|
||||
- **freedom**: free and open source software
|
||||
|
||||
[lowlatency]: https://github.com/Genymobile/scrcpy/pull/646
|
||||
|
||||
Its features include:
|
||||
- [recording](#recording)
|
||||
- mirroring with [device screen off](#turn-screen-off)
|
||||
- [copy-paste](#copy-paste) in both directions
|
||||
- [configurable quality](#capture-configuration)
|
||||
- device screen [as a webcam (V4L2)](#v4l2loopback) (Linux-only)
|
||||
- [physical keyboard simulation (HID)](#physical-keyboard-simulation-hid)
|
||||
(Linux-only)
|
||||
- and more…
|
||||
|
||||
## Requirements
|
||||
|
||||
|
@ -90,10 +101,10 @@ process][BUILD_simple]).
|
|||
For Windows, for simplicity, a prebuilt archive with all the dependencies
|
||||
(including `adb`) is available:
|
||||
|
||||
- [`scrcpy-win64-v1.19.zip`][direct-win64]
|
||||
_(SHA-256: 383d6483f25ac0092d4bb9fef6c967351ecd50fc248e0c82932db97d6d32f11b)_
|
||||
- [`scrcpy-win64-v1.20.zip`][direct-win64]
|
||||
_(SHA-256: 548532b616288bcaeceff6881ad5e6f0928e5ae2b48c380385f03627401cfdba)_
|
||||
|
||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.19/scrcpy-win64-v1.19.zip
|
||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.20/scrcpy-win64-v1.20.zip
|
||||
|
||||
It is also available in [Chocolatey]:
|
||||
|
||||
|
@ -326,7 +337,9 @@ For example, you could capture the video within [OBS].
|
|||
#### Buffering
|
||||
|
||||
It is possible to add buffering. This increases latency but reduces jitter (see
|
||||
#2464).
|
||||
[#2464]).
|
||||
|
||||
[#2464]: https://github.com/Genymobile/scrcpy/issues/2464
|
||||
|
||||
The option is available for display buffering:
|
||||
|
||||
|
@ -686,7 +699,7 @@ a location inverted through the center of the screen.
|
|||
By default, scrcpy uses Android key or text injection: it works everywhere, but
|
||||
is limited to ASCII.
|
||||
|
||||
On Linux, scrcpy can simulate a USB physical keyboard on Android to provide a
|
||||
On Linux, scrcpy can simulate a physical USB keyboard on Android to provide a
|
||||
better input experience (using [USB HID over AOAv2][hid-aoav2]): the virtual
|
||||
keyboard is disabled and it works for all characters and IME.
|
||||
|
||||
|
@ -937,12 +950,12 @@ Read the [developers page].
|
|||
This README is available in other languages:
|
||||
|
||||
- [Indonesian (Indonesia, `id`) - v1.16](README.id.md)
|
||||
- [Italiano (Italiano, `it`) - v1.17](README.it.md)
|
||||
- [日本語 (Japanese, `jp`) - v1.17](README.jp.md)
|
||||
- [Italiano (Italiano, `it`) - v1.19](README.it.md)
|
||||
- [日本語 (Japanese, `jp`) - v1.19](README.jp.md)
|
||||
- [한국어 (Korean, `ko`) - v1.11](README.ko.md)
|
||||
- [português brasileiro (Brazilian Portuguese, `pt-BR`) - v1.17](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)
|
||||
- [简体中文 (Simplified Chinese, `zh-Hans`) - v1.17](README.zh-Hans.md)
|
||||
- [简体中文 (Simplified Chinese, `zh-Hans`) - v1.20](README.zh-Hans.md)
|
||||
- [繁體中文 (Traditional Chinese, `zh-Hant`) - v1.15](README.zh-Hant.md)
|
||||
- [Turkish (Turkish, `tr`) - v1.18](README.tr.md)
|
||||
|
||||
|
|
174
README.pt-br.md
174
README.pt-br.md
|
@ -1,6 +1,6 @@
|
|||
_Apenas o [README](README.md) original é garantido estar atualizado._
|
||||
|
||||
# scrcpy (v1.17)
|
||||
# scrcpy (v1.19)
|
||||
|
||||
Esta aplicação fornece exibição e controle de dispositivos Android conectados via
|
||||
USB (ou [via TCP/IP][article-tcpip]). Não requer nenhum acesso _root_.
|
||||
|
@ -38,6 +38,18 @@ controlá-lo usando teclado e mouse.
|
|||
|
||||
<a href="https://repology.org/project/scrcpy/versions"><img src="https://repology.org/badge/vertical-allrepos/scrcpy.svg" alt="Packaging status" align="right"></a>
|
||||
|
||||
### Sumário
|
||||
|
||||
- Linux: `apt install scrcpy`
|
||||
- Windows: [baixar][direct-win64]
|
||||
- macOS: `brew install scrcpy`
|
||||
|
||||
Compilar pelos arquivos fontes: [BUILD] ([processo simplificado][BUILD_simple])
|
||||
|
||||
[BUILD]: BUILD.md
|
||||
[BUILD_simple]: BUILD.md#simple
|
||||
|
||||
|
||||
### Linux
|
||||
|
||||
No Debian (_testing_ e _sid_ por enquanto) e Ubuntu (20.04):
|
||||
|
@ -67,9 +79,7 @@ Para Gentoo, uma [Ebuild] está disponível: [`scrcpy/`][ebuild-link].
|
|||
[Ebuild]: https://wiki.gentoo.org/wiki/Ebuild
|
||||
[ebuild-link]: https://github.com/maggu2810/maggu2810-overlay/tree/master/app-mobilephone/scrcpy
|
||||
|
||||
Você também pode [compilar o app manualmente][BUILD] (não se preocupe, não é tão
|
||||
difícil).
|
||||
|
||||
Você também pode [compilar o app manualmente][BUILD] ([processo simplificado][BUILD_simple]).
|
||||
|
||||
|
||||
### Windows
|
||||
|
@ -113,13 +123,18 @@ brew install scrcpy
|
|||
Você precisa do `adb`, acessível pelo seu `PATH`. Se você ainda não o tem:
|
||||
|
||||
```bash
|
||||
# Homebrew >= 2.6.0
|
||||
brew install --cask android-platform-tools
|
||||
|
||||
# Homebrew < 2.6.0
|
||||
brew cask install android-platform-tools
|
||||
brew install android-platform-tools
|
||||
```
|
||||
|
||||
Está também disponivel em [MacPorts], que prepara o adb para você:
|
||||
|
||||
```bash
|
||||
sudo port install scrcpy
|
||||
```
|
||||
|
||||
[MacPorts]: https://www.macports.org/
|
||||
|
||||
|
||||
Você também pode [compilar o app manualmente][BUILD].
|
||||
|
||||
|
||||
|
@ -195,10 +210,11 @@ Se `--max-size` também for especificado, o redimensionamento é aplicado após
|
|||
Para travar a orientação do espelhamento:
|
||||
|
||||
```bash
|
||||
scrcpy --lock-video-orientation 0 # orientação natural
|
||||
scrcpy --lock-video-orientation 1 # 90° sentido anti-horário
|
||||
scrcpy --lock-video-orientation 2 # 180°
|
||||
scrcpy --lock-video-orientation 3 # 90° sentido horário
|
||||
scrcpy --lock-video-orientation # orientação inicial (Atual)
|
||||
scrcpy --lock-video-orientation=0 # orientação natural
|
||||
scrcpy --lock-video-orientation=1 # 90° sentido anti-horário
|
||||
scrcpy --lock-video-orientation=2 # 180°
|
||||
scrcpy --lock-video-orientation=3 # 90° sentido horário
|
||||
```
|
||||
|
||||
Isso afeta a orientação de gravação.
|
||||
|
@ -222,7 +238,9 @@ erro dará os encoders disponíveis:
|
|||
scrcpy --encoder _
|
||||
```
|
||||
|
||||
### Gravando
|
||||
### Captura
|
||||
|
||||
#### Gravando
|
||||
|
||||
É possível gravar a tela enquanto ocorre o espelhamento:
|
||||
|
||||
|
@ -246,6 +264,79 @@ pacotes][packet delay variation] não impacta o arquivo gravado.
|
|||
[packet delay variation]: https://en.wikipedia.org/wiki/Packet_delay_variation
|
||||
|
||||
|
||||
#### v4l2loopback
|
||||
|
||||
Em Linux, é possível enviar a transmissão do video para um disposiivo v4l2 loopback, assim
|
||||
o dispositivo Android pode ser aberto como uma webcam por qualquer ferramneta capaz de v4l2
|
||||
|
||||
The module `v4l2loopback` must be installed:
|
||||
|
||||
```bash
|
||||
sudo apt install v4l2loopback-dkms
|
||||
```
|
||||
|
||||
Para criar um dispositivo v4l2:
|
||||
|
||||
```bash
|
||||
sudo modprobe v4l2loopback
|
||||
```
|
||||
|
||||
Isso criara um novo dispositivo de vídeo em `/dev/videoN`, onde `N` é uma integer
|
||||
(mais [opções](https://github.com/umlaeute/v4l2loopback#options) estão disponiveis
|
||||
para criar varios dispositivos ou dispositivos com IDs específicas).
|
||||
|
||||
Para listar os dispositivos disponíveis:
|
||||
|
||||
```bash
|
||||
# requer o pacote v4l-utils
|
||||
v4l2-ctl --list-devices
|
||||
|
||||
# simples, mas pode ser suficiente
|
||||
ls /dev/video*
|
||||
```
|
||||
|
||||
Para iniciar o scrcpy usando o coletor v4l2 (sink):
|
||||
|
||||
```bash
|
||||
scrcpy --v4l2-sink=/dev/videoN
|
||||
scrcpy --v4l2-sink=/dev/videoN --no-display # desativa a janela espelhada
|
||||
scrcpy --v4l2-sink=/dev/videoN -N # versão curta
|
||||
```
|
||||
|
||||
(troque `N` pelo ID do dipositivo, verifique com `ls /dev/video*`)
|
||||
|
||||
Uma vez ativado, você pode abrir suas trasmissões de videos com uma ferramenta capaz de v4l2:
|
||||
|
||||
```bash
|
||||
ffplay -i /dev/videoN
|
||||
vlc v4l2:///dev/videoN # VLC pode adicionar um pouco de atraso de buffering
|
||||
```
|
||||
|
||||
Por exemplo, você pode capturar o video dentro do [OBS].
|
||||
|
||||
[OBS]: https://obsproject.com/
|
||||
|
||||
|
||||
#### Buffering
|
||||
|
||||
É possivel adicionar buffering. Isso aumenta a latência, mas reduz a tenção (jitter) (veja
|
||||
[#2464]).
|
||||
|
||||
[#2464]: https://github.com/Genymobile/scrcpy/issues/2464
|
||||
|
||||
A opção éta disponivel para buffering de exibição:
|
||||
|
||||
```bash
|
||||
scrcpy --display-buffer=50 # adiciona 50 ms de buffering para a exibição
|
||||
```
|
||||
|
||||
e coletor V4L2:
|
||||
|
||||
```bash
|
||||
scrcpy --v4l2-buffer=500 # adiciona 500 ms de buffering para coletor V4L2
|
||||
```
|
||||
|
||||
,
|
||||
### Conexão
|
||||
|
||||
#### Sem fio
|
||||
|
@ -488,18 +579,6 @@ scrcpy -Sw
|
|||
```
|
||||
|
||||
|
||||
#### Renderizar frames expirados
|
||||
|
||||
Por padrão, para minimizar a latência, _scrcpy_ sempre renderiza o último frame decodificado
|
||||
disponível, e descarta o anterior.
|
||||
|
||||
Para forçar a renderização de todos os frames (com o custo de um possível aumento de
|
||||
latência), use:
|
||||
|
||||
```bash
|
||||
scrcpy --render-expired-frames
|
||||
```
|
||||
|
||||
#### Mostrar toques
|
||||
|
||||
Para apresentações, pode ser útil mostrar toques físicos (no dispositivo
|
||||
|
@ -647,7 +726,7 @@ Não existe feedback visual, um log é imprimido no console.
|
|||
|
||||
#### Enviar arquivo para dispositivo
|
||||
|
||||
Para enviar um arquivo para `/sdcard/` no dispositivo, arraste e solte um arquivo (não-APK) para a
|
||||
Para enviar um arquivo para `/sdcard/Download/` no dispositivo, arraste e solte um arquivo (não-APK) para a
|
||||
janela do _scrcpy_.
|
||||
|
||||
Não existe feedback visual, um log é imprimido no console.
|
||||
|
@ -694,12 +773,12 @@ _<kbd>[Super]</kbd> é tipicamente a tecla <kbd>Windows</kbd> ou <kbd>Cmd</kbd>.
|
|||
| Mudar modo de tela cheia | <kbd>MOD</kbd>+<kbd>f</kbd>
|
||||
| Rotacionar display para esquerda | <kbd>MOD</kbd>+<kbd>←</kbd> _(esquerda)_
|
||||
| Rotacionar display para direita | <kbd>MOD</kbd>+<kbd>→</kbd> _(direita)_
|
||||
| Redimensionar janela para 1:1 (pixel-perfect) | <kbd>MOD</kbd>+<kbd>g</kbd>
|
||||
| Redimensionar janela para remover bordas pretas | <kbd>MOD</kbd>+<kbd>w</kbd> \| _Clique-duplo¹_
|
||||
| Redimensionar janela para 1:1 (pixel-perfeito) | <kbd>MOD</kbd>+<kbd>g</kbd>
|
||||
| Redimensionar janela para remover bordas pretas | <kbd>MOD</kbd>+<kbd>w</kbd> \| _Clique-duplo-esquerdo¹_
|
||||
| Clicar em `HOME` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _Clique-do-meio_
|
||||
| Clicar em `BACK` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _Clique-direito²_
|
||||
| Clicar em `APP_SWITCH` | <kbd>MOD</kbd>+<kbd>s</kbd>
|
||||
| Clicar em `MENU` (desbloquear tela | <kbd>MOD</kbd>+<kbd>m</kbd>
|
||||
| Clicar em `APP_SWITCH` | <kbd>MOD</kbd>+<kbd>s</kbd> \| _Clique-do-4.°³_
|
||||
| Clicar em `MENU` (desbloquear tela) | <kbd>MOD</kbd>+<kbd>m</kbd>
|
||||
| Clicar em `VOLUME_UP` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(cima)_
|
||||
| Clicar em `VOLUME_DOWN` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(baixo)_
|
||||
| Clicar em `POWER` | <kbd>MOD</kbd>+<kbd>p</kbd>
|
||||
|
@ -707,18 +786,27 @@ _<kbd>[Super]</kbd> é tipicamente a tecla <kbd>Windows</kbd> ou <kbd>Cmd</kbd>.
|
|||
| Desligar tela do dispositivo (continuar espelhando) | <kbd>MOD</kbd>+<kbd>o</kbd>
|
||||
| Ligar tela do dispositivo | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>o</kbd>
|
||||
| Rotacionar tela do dispositivo | <kbd>MOD</kbd>+<kbd>r</kbd>
|
||||
| Expandir painel de notificação | <kbd>MOD</kbd>+<kbd>n</kbd>
|
||||
| Colapsar painel de notificação | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
||||
| Copiar para área de transferência³ | <kbd>MOD</kbd>+<kbd>c</kbd>
|
||||
| Recortar para área de transferência³ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
||||
| Sincronizar áreas de transferência e colar³ | <kbd>MOD</kbd>+<kbd>v</kbd>
|
||||
| Expandir painel de notificação | <kbd>MOD</kbd>+<kbd>n</kbd> \| _Clique-do-5.°³_
|
||||
| Expandir painel de configurção | <kbd>MOD</kbd>+<kbd>n</kbd>+<kbd>n</kbd> \| _Clique-duplo-do-5.°³_
|
||||
| Colapsar paineis | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
||||
| Copiar para área de transferência⁴ | <kbd>MOD</kbd>+<kbd>c</kbd>
|
||||
| Recortar para área de transferência⁴ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
||||
| Sincronizar áreas de transferência e colar⁴ | <kbd>MOD</kbd>+<kbd>v</kbd>
|
||||
| Injetar texto da área de transferência do computador | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>
|
||||
| Ativar/desativar contador de FPS (em stdout) | <kbd>MOD</kbd>+<kbd>i</kbd>
|
||||
| Pinçar para dar zoom | <kbd>Ctrl</kbd>+_clicar-e-mover_
|
||||
| Pinçar para dar zoom | <kbd>Ctrl</kbd>+_Clicar-e-mover_
|
||||
|
||||
_¹Clique-duplo em bordas pretas para removê-las._
|
||||
_²Clique-direito liga a tela se ela estiver desligada, pressiona BACK caso contrário._
|
||||
_³Apenas em Android >= 7._
|
||||
_¹Clique-duplo-esquerdo na borda preta para remove-la._
|
||||
_²Clique-direito liga a tela caso esteja desligada, pressione BACK caso contrário._
|
||||
_³4.° and 5.° botões do mouse, caso o mouse possua._
|
||||
_⁴Apenas em Android >= 7._
|
||||
|
||||
Atalhos com teclas reptidas são executados soltando e precionando a tecla
|
||||
uma segunda vez. Por exemplo, para executar "Expandir painel de Configurção":
|
||||
|
||||
1. Mantenha pressionado <kbd>MOD</kbd>.
|
||||
2. Depois click duas vezes <kbd>n</kbd>.
|
||||
3. Finalmente, solte <kbd>MOD</kbd>.
|
||||
|
||||
Todos os atalhos <kbd>Ctrl</kbd>+_tecla_ são encaminhados para o dispositivo, para que eles sejam
|
||||
tratados pela aplicação ativa.
|
||||
|
@ -729,7 +817,9 @@ tratados pela aplicação ativa.
|
|||
Para usar um binário _adb_ específico, configure seu caminho na variável de ambiente
|
||||
`ADB`:
|
||||
|
||||
ADB=/caminho/para/adb scrcpy
|
||||
```bash
|
||||
ADB=/caminho/para/adb scrcpy
|
||||
```
|
||||
|
||||
Para sobrepor o caminho do arquivo `scrcpy-server`, configure seu caminho em
|
||||
`SCRCPY_SERVER_PATH`.
|
||||
|
@ -751,8 +841,6 @@ Um colega me desafiou a encontrar um nome tão impronunciável quanto [gnirehtet
|
|||
|
||||
Veja [BUILD].
|
||||
|
||||
[BUILD]: BUILD.md
|
||||
|
||||
|
||||
## Problemas comuns
|
||||
|
||||
|
|
|
@ -2,27 +2,41 @@ _Only the original [README](README.md) is guaranteed to be up-to-date._
|
|||
|
||||
只有原版的[README](README.md)会保持最新。
|
||||
|
||||
本文根据[ed130e05]进行翻译。
|
||||
Current version is based on [65b023a]
|
||||
|
||||
[ed130e05]: https://github.com/Genymobile/scrcpy/blob/ed130e05d55615d6014d93f15cfcb92ad62b01d8/README.md
|
||||
本文根据[65b023a]进行翻译。
|
||||
|
||||
# scrcpy (v1.17)
|
||||
[65b023a]: https://github.com/Genymobile/scrcpy/blob/65b023ac6d586593193fd5290f65e25603b68e02/README.md
|
||||
|
||||
# scrcpy (v1.20)
|
||||
|
||||
<img src="data/icon.svg" width="128" height="128" alt="scrcpy" align="right" />
|
||||
|
||||
本应用程序可以显示并控制通过 USB (或 [TCP/IP][article-tcpip]) 连接的安卓设备,且不需要任何 _root_ 权限。本程序支持 _GNU/Linux_, _Windows_ 和 _macOS_。
|
||||
|
||||
![screenshot](assets/screenshot-debian-600.jpg)
|
||||
|
||||
它专注于:
|
||||
本应用专注于:
|
||||
|
||||
- **轻量** (原生,仅显示设备屏幕)
|
||||
- **性能** (30~60fps)
|
||||
- **质量** (分辨率可达 1920×1080 或更高)
|
||||
- **低延迟** ([35~70ms][lowlatency])
|
||||
- **快速启动** (最快 1 秒内即可显示第一帧)
|
||||
- **无侵入性** (不会在设备上遗留任何程序)
|
||||
- **轻量**: 原生,仅显示设备屏幕
|
||||
- **性能**: 30~120fps,取决于设备
|
||||
- **质量**: 分辨率可达 1920×1080 或更高
|
||||
- **低延迟**: [35~70ms][lowlatency]
|
||||
- **快速启动**: 最快 1 秒内即可显示第一帧
|
||||
- **无侵入性**: 不会在设备上遗留任何程序
|
||||
- **用户利益**: 无需帐号,无广告,无需联网
|
||||
- **自由**: 自由和开源软件
|
||||
|
||||
[lowlatency]: https://github.com/Genymobile/scrcpy/pull/646
|
||||
|
||||
功能:
|
||||
- [屏幕录制](#屏幕录制)
|
||||
- 镜像时[关闭设备屏幕](#关闭设备屏幕)
|
||||
- 双向[复制粘贴](#复制粘贴)
|
||||
- [可配置显示质量](#采集设置)
|
||||
- 以设备屏幕[作为摄像头(V4L2)](#v4l2loopback) (仅限 Linux)
|
||||
- [模拟物理键盘 (HID)](#物理键盘模拟-hid) (仅限 Linux)
|
||||
- 更多 ……
|
||||
|
||||
## 系统要求
|
||||
|
||||
|
@ -41,6 +55,17 @@ _Only the original [README](README.md) is guaranteed to be up-to-date._
|
|||
|
||||
<a href="https://repology.org/project/scrcpy/versions"><img src="https://repology.org/badge/vertical-allrepos/scrcpy.svg" alt="Packaging status" align="right"></a>
|
||||
|
||||
### 概要
|
||||
|
||||
- Linux: `apt install scrcpy`
|
||||
- Windows: [下载][direct-win64]
|
||||
- macOS: `brew install scrcpy`
|
||||
|
||||
从源代码编译: [构建][BUILD] ([简化过程][BUILD_simple])
|
||||
|
||||
[BUILD]: BUILD.md
|
||||
[BUILD_simple]: BUILD.md#simple
|
||||
|
||||
### Linux
|
||||
|
||||
在 Debian (目前仅支持 _testing_ 和 _sid_ 分支) 和Ubuntu (20.04) 上:
|
||||
|
@ -70,13 +95,12 @@ apt install scrcpy
|
|||
[Ebuild]: https://wiki.gentoo.org/wiki/Ebuild
|
||||
[ebuild-link]: https://github.com/maggu2810/maggu2810-overlay/tree/master/app-mobilephone/scrcpy
|
||||
|
||||
您也可以[自行构建][BUILD] (不必担心,这并不困难)。
|
||||
|
||||
您也可以[自行构建][BUILD] ([简化过程][BUILD_simple])。
|
||||
|
||||
|
||||
### Windows
|
||||
|
||||
在 Windows 上,简便起见,我们提供包含了所有依赖 (包括 `adb`) 的预编译包。
|
||||
在 Windows 上,为简便起见,我们提供包含了所有依赖 (包括 `adb`) 的预编译包。
|
||||
|
||||
- [README](README.md#windows)
|
||||
|
||||
|
@ -114,13 +138,17 @@ brew install scrcpy
|
|||
你还需要在 `PATH` 内有 `adb`。如果还没有:
|
||||
|
||||
```bash
|
||||
# Homebrew >= 2.6.0
|
||||
brew install --cask android-platform-tools
|
||||
|
||||
# Homebrew < 2.6.0
|
||||
brew cask install android-platform-tools
|
||||
brew install android-platform-tools
|
||||
```
|
||||
|
||||
或者通过 [MacPorts],该方法同时设置好 adb:
|
||||
|
||||
```bash
|
||||
sudo port install scrcpy
|
||||
```
|
||||
|
||||
[MacPorts]: https://www.macports.org/
|
||||
|
||||
您也可以[自行构建][BUILD]。
|
||||
|
||||
|
||||
|
@ -140,7 +168,7 @@ scrcpy --help
|
|||
|
||||
## 功能介绍
|
||||
|
||||
### 捕获设置
|
||||
### 采集设置
|
||||
|
||||
#### 降低分辨率
|
||||
|
||||
|
@ -158,7 +186,7 @@ scrcpy -m 1024 # 简写
|
|||
|
||||
#### 修改码率
|
||||
|
||||
默认码率是 8Mbps。要改变视频的码率 (例如改为 2Mbps):
|
||||
默认码率是 8 Mbps。改变视频码率 (例如改为 2 Mbps):
|
||||
|
||||
```bash
|
||||
scrcpy --bit-rate 2M
|
||||
|
@ -167,7 +195,7 @@ scrcpy -b 2M # 简写
|
|||
|
||||
#### 限制帧率
|
||||
|
||||
要限制捕获的帧率:
|
||||
要限制采集的帧率:
|
||||
|
||||
```bash
|
||||
scrcpy --max-fps 15
|
||||
|
@ -194,10 +222,11 @@ scrcpy --crop 1224:1440:0:0 # 以 (0,0) 为原点的 1224x1440 像素
|
|||
要锁定镜像画面的方向:
|
||||
|
||||
```bash
|
||||
scrcpy --lock-video-orientation 0 # 自然方向
|
||||
scrcpy --lock-video-orientation 1 # 逆时针旋转 90°
|
||||
scrcpy --lock-video-orientation 2 # 180°
|
||||
scrcpy --lock-video-orientation 3 # 顺时针旋转 90°
|
||||
scrcpy --lock-video-orientation # 初始(目前)方向
|
||||
scrcpy --lock-video-orientation=0 # 自然方向
|
||||
scrcpy --lock-video-orientation=1 # 逆时针旋转 90°
|
||||
scrcpy --lock-video-orientation=2 # 180°
|
||||
scrcpy --lock-video-orientation=3 # 顺时针旋转 90°
|
||||
```
|
||||
|
||||
只影响录制的方向。
|
||||
|
@ -219,7 +248,9 @@ scrcpy --encoder OMX.qcom.video.encoder.avc
|
|||
scrcpy --encoder _
|
||||
```
|
||||
|
||||
### 屏幕录制
|
||||
### 采集
|
||||
|
||||
#### 屏幕录制
|
||||
|
||||
可以在镜像的同时录制视频:
|
||||
|
||||
|
@ -241,6 +272,75 @@ scrcpy -Nr file.mkv
|
|||
[packet delay variation]: https://en.wikipedia.org/wiki/Packet_delay_variation
|
||||
|
||||
|
||||
#### v4l2loopback
|
||||
|
||||
在 Linux 上,可以将视频流发送至 v4l2 回环 (loopback) 设备,因此可以使用任何 v4l2 工具像摄像头一样打开安卓设备。
|
||||
|
||||
需安装 `v4l2loopback` 模块:
|
||||
|
||||
```bash
|
||||
sudo apt install v4l2loopback-dkms
|
||||
```
|
||||
|
||||
创建一个 v4l2 设备:
|
||||
|
||||
```bash
|
||||
sudo modprobe v4l2loopback
|
||||
```
|
||||
|
||||
这样会在 `/dev/videoN` 创建一个新的视频设备,其中 `N` 是整数。 ([更多选项](https://github.com/umlaeute/v4l2loopback#options) 可以用来创建多个设备或者特定 ID 的设备)。
|
||||
|
||||
列出已启用的设备:
|
||||
|
||||
```bash
|
||||
# 需要 v4l-utils 包
|
||||
v4l2-ctl --list-devices
|
||||
|
||||
# 简单但或许足够
|
||||
ls /dev/video*
|
||||
```
|
||||
|
||||
使用一个 v4l2 漏开启 scrcpy:
|
||||
|
||||
```bash
|
||||
scrcpy --v4l2-sink=/dev/videoN
|
||||
scrcpy --v4l2-sink=/dev/videoN --no-display # 禁用窗口镜像
|
||||
scrcpy --v4l2-sink=/dev/videoN -N # 简写
|
||||
```
|
||||
|
||||
(将 `N` 替换为设备 ID,使用 `ls /dev/video*` 命令查看)
|
||||
|
||||
启用之后,可以使用 v4l2 工具打开视频流:
|
||||
|
||||
```bash
|
||||
ffplay -i /dev/videoN
|
||||
vlc v4l2:///dev/videoN # VLC 可能存在一些缓冲延迟
|
||||
```
|
||||
|
||||
例如,可以在 [OBS] 中采集视频。
|
||||
|
||||
[OBS]: https://obsproject.com/
|
||||
|
||||
|
||||
#### 缓冲
|
||||
|
||||
可以加入缓冲,会增加延迟,但可以减少抖动 (见 [#2464])。
|
||||
|
||||
[#2464]: https://github.com/Genymobile/scrcpy/issues/2464
|
||||
|
||||
对于显示缓冲:
|
||||
|
||||
```bash
|
||||
scrcpy --display-buffer=50 # 为显示增加 50 毫秒的缓冲
|
||||
```
|
||||
|
||||
对于 V4L2 漏:
|
||||
|
||||
```bash
|
||||
scrcpy --v4l2-buffer=500 # 为 v4l2 漏增加 500 毫秒的缓冲
|
||||
```
|
||||
|
||||
|
||||
### 连接
|
||||
|
||||
#### 无线
|
||||
|
@ -249,16 +349,17 @@ _Scrcpy_ 使用 `adb` 与设备通信,并且 `adb` 支持通过 TCP/IP [连接
|
|||
|
||||
1. 将设备和电脑连接至同一 Wi-Fi。
|
||||
2. 打开 设置 → 关于手机 → 状态信息,获取设备的 IP 地址,也可以执行以下的命令:
|
||||
|
||||
```bash
|
||||
adb shell ip route | awk '{print $9}'
|
||||
```
|
||||
|
||||
3. 启用设备的网络 adb 功能 `adb tcpip 5555`。
|
||||
3. 启用设备的网络 adb 功能: `adb tcpip 5555`。
|
||||
4. 断开设备的 USB 连接。
|
||||
5. 连接到您的设备:`adb connect DEVICE_IP:5555` _(将 `DEVICE_IP` 替换为设备 IP)_.
|
||||
5. 连接到您的设备:`adb connect DEVICE_IP:5555` _(将 `DEVICE_IP` 替换为设备 IP)_。
|
||||
6. 正常运行 `scrcpy`。
|
||||
|
||||
可能需要降低码率和分辨率:
|
||||
可能降低码率和分辨率会更好一些:
|
||||
|
||||
```bash
|
||||
scrcpy --bit-rate 2M --max-size 800
|
||||
|
@ -327,7 +428,7 @@ scrcpy --force-adb-forward
|
|||
```
|
||||
|
||||
|
||||
类似无线网络连接,可能需要降低画面质量:
|
||||
类似地,对于无线连接,可能需要降低画面质量:
|
||||
|
||||
```
|
||||
scrcpy -b2M -m800 --max-fps 15
|
||||
|
@ -353,7 +454,7 @@ scrcpy --window-x 100 --window-y 100 --window-width 800 --window-height 600
|
|||
|
||||
#### 无边框
|
||||
|
||||
关闭边框:
|
||||
禁用窗口边框:
|
||||
|
||||
```bash
|
||||
scrcpy --window-borderless
|
||||
|
@ -369,7 +470,7 @@ scrcpy --always-on-top
|
|||
|
||||
#### 全屏
|
||||
|
||||
您可以通过如下命令直接全屏启动scrcpy:
|
||||
您可以通过如下命令直接全屏启动 scrcpy:
|
||||
|
||||
```bash
|
||||
scrcpy --fullscreen
|
||||
|
@ -394,7 +495,7 @@ scrcpy --rotation 1
|
|||
|
||||
也可以使用 <kbd>MOD</kbd>+<kbd>←</kbd> _(左箭头)_ 和 <kbd>MOD</kbd>+<kbd>→</kbd> _(右箭头)_ 随时更改。
|
||||
|
||||
需要注意的是, _scrcpy_ 有三个不同的方向:
|
||||
需要注意的是, _scrcpy_ 中有三类旋转方向:
|
||||
- <kbd>MOD</kbd>+<kbd>r</kbd> 请求设备在竖屏和横屏之间切换 (如果前台应用程序不支持请求的朝向,可能会拒绝该请求)。
|
||||
- [`--lock-video-orientation`](#锁定屏幕方向) 改变镜像的朝向 (设备传输到电脑的画面的朝向)。这会影响录制。
|
||||
- `--rotation` (或 <kbd>MOD</kbd>+<kbd>←</kbd>/<kbd>MOD</kbd>+<kbd>→</kbd>) 只旋转窗口的内容。这只影响显示,不影响录制。
|
||||
|
@ -404,7 +505,7 @@ scrcpy --rotation 1
|
|||
|
||||
#### 只读
|
||||
|
||||
禁用电脑对设备的控制 (如键盘输入、鼠标事件和文件拖放):
|
||||
禁用电脑对设备的控制 (任何可与设备交互的方式:如键盘输入、鼠标事件和文件拖放):
|
||||
|
||||
```bash
|
||||
scrcpy --no-control
|
||||
|
@ -430,14 +531,14 @@ adb shell dumpsys display # 在输出中搜索 “mDisplayId=”
|
|||
|
||||
#### 保持常亮
|
||||
|
||||
阻止设备在连接时休眠:
|
||||
阻止设备在连接时一段时间后休眠:
|
||||
|
||||
```bash
|
||||
scrcpy --stay-awake
|
||||
scrcpy -w
|
||||
```
|
||||
|
||||
程序关闭时会恢复设备原来的设置。
|
||||
scrcpy 关闭时会恢复设备原来的设置。
|
||||
|
||||
|
||||
#### 关闭设备屏幕
|
||||
|
@ -451,7 +552,7 @@ scrcpy -S
|
|||
|
||||
或者在任何时候按 <kbd>MOD</kbd>+<kbd>o</kbd>。
|
||||
|
||||
要重新打开屏幕,按下 <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>o</kbd>.
|
||||
要重新打开屏幕,按下 <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>o</kbd>。
|
||||
|
||||
在Android上,`电源` 按钮始终能把屏幕打开。为了方便,对于在 _scrcpy_ 中发出的 `电源` 事件 (通过鼠标右键或 <kbd>MOD</kbd>+<kbd>p</kbd>),会 (尽最大的努力) 在短暂的延迟后将屏幕关闭。设备上的 `电源` 按钮仍然能打开设备屏幕。
|
||||
|
||||
|
@ -462,20 +563,17 @@ scrcpy --turn-screen-off --stay-awake
|
|||
scrcpy -Sw
|
||||
```
|
||||
|
||||
#### 退出时息屏
|
||||
|
||||
#### 渲染过期帧
|
||||
|
||||
默认状态下,为了降低延迟, _scrcpy_ 永远渲染解码成功的最近一帧,并跳过前面任意帧。
|
||||
|
||||
强制渲染所有帧 (可能导致延迟变高):
|
||||
scrcpy 退出时关闭设备屏幕:
|
||||
|
||||
```bash
|
||||
scrcpy --render-expired-frames
|
||||
scrcpy --power-off-on-close
|
||||
```
|
||||
|
||||
#### 显示触摸
|
||||
|
||||
在演示时,可能会需要显示物理触摸点 (在物理设备上的触摸点)。
|
||||
在演示时,可能会需要显示 (在物理设备上的) 物理触摸点。
|
||||
|
||||
Android 在 _开发者选项_ 中提供了这项功能。
|
||||
|
||||
|
@ -538,10 +636,32 @@ scrcpy --disable-screensaver
|
|||
|
||||
更准确的说,在按住鼠标左键时按住 <kbd>Ctrl</kbd>。直到松开鼠标左键,所有鼠标移动将以屏幕中心为原点,缩放或旋转内容 (如果应用支持)。
|
||||
|
||||
实际上,_scrcpy_ 会在以屏幕中心对称的位置上生成由“虚拟手指”发出的额外触摸事件。
|
||||
实际上,_scrcpy_ 会在关于屏幕中心对称的位置上用“虚拟手指”发出触摸事件。
|
||||
|
||||
#### 物理键盘模拟 (HID)
|
||||
|
||||
#### 文字注入偏好
|
||||
默认情况下,scrcpy 使用安卓按键或文本注入,这在任何情况都可以使用,但仅限于ASCII字符。
|
||||
|
||||
在 Linux 上,scrcpy 可以模拟为 Android 上的物理 USB 键盘,以提供更好地输入体验 (使用 [USB HID over AOAv2][hid-aoav2]):禁用虚拟键盘,并适用于任何字符和输入法。
|
||||
|
||||
[hid-aoav2]: https://source.android.com/devices/accessories/aoa2#hid-support
|
||||
|
||||
不过,这种方法仅支持 USB 连接以及 Linux平台。
|
||||
|
||||
启用 HID 模式:
|
||||
|
||||
```bash
|
||||
scrcpy --hid-keyboard
|
||||
scrcpy -K # 简写
|
||||
```
|
||||
|
||||
如果失败了 (如设备未通过 USB 连接),则自动回退至默认模式 (终端中会输出日志)。这即允许通过 USB 和 TCP/IP 连接时使用相同的命令行参数。
|
||||
|
||||
在这种模式下,原始按键事件 (扫描码) 被发送给设备,而与宿主机按键映射无关。因此,若键盘布局不匹配,需要在 Android 设备上进行配置,具体为 设置 → 系统 → 语言和输入法 → [实体键盘]。
|
||||
|
||||
[Physical keyboard]: https://github.com/Genymobile/scrcpy/pull/2632#issuecomment-923756915
|
||||
|
||||
#### 文本注入偏好
|
||||
|
||||
打字的时候,系统会产生两种[事件][textevents]:
|
||||
- _按键事件_ ,代表一个按键被按下或松开。
|
||||
|
@ -557,13 +677,15 @@ scrcpy --prefer-text
|
|||
|
||||
(这会导致键盘在游戏中工作不正常)
|
||||
|
||||
该选项不影响 HID 键盘 (该模式下,所有按键都发送为扫描码)。
|
||||
|
||||
[textevents]: https://blog.rom1v.com/2018/03/introducing-scrcpy/#handle-text-input
|
||||
[prefertext]: https://github.com/Genymobile/scrcpy/issues/650#issuecomment-512945343
|
||||
|
||||
|
||||
#### 按键重复
|
||||
|
||||
默认状态下,按住一个按键不放会生成多个重复按键事件。在某些游戏中这可能会导致性能问题。
|
||||
默认状态下,按住一个按键不放会生成多个重复按键事件。在某些游戏中这通常没有实际用途,且可能会导致性能问题。
|
||||
|
||||
避免转发重复按键事件:
|
||||
|
||||
|
@ -571,10 +693,11 @@ scrcpy --prefer-text
|
|||
scrcpy --no-key-repeat
|
||||
```
|
||||
|
||||
该选项不影响 HID 键盘 (该模式下,按键重复由 Android 直接管理)。
|
||||
|
||||
#### 右键和中键
|
||||
|
||||
默认状态下,右键会触发返回键 (或电源键),中键会触发 HOME 键。要禁用这些快捷键并把所有点击转发到设备:
|
||||
默认状态下,右键会触发返回键 (或电源键开启),中键会触发 HOME 键。要禁用这些快捷键并把所有点击转发到设备:
|
||||
|
||||
```bash
|
||||
scrcpy --forward-all-clicks
|
||||
|
@ -587,27 +710,27 @@ scrcpy --forward-all-clicks
|
|||
|
||||
将 APK 文件 (文件名以 `.apk` 结尾) 拖放到 _scrcpy_ 窗口来安装。
|
||||
|
||||
该操作在屏幕上不会出现任何变化,而会在控制台输出一条日志。
|
||||
不会有视觉反馈,终端会输出一条日志。
|
||||
|
||||
|
||||
#### 将文件推送至设备
|
||||
|
||||
要推送文件到设备的 `/sdcard/`,将 (非 APK) 文件拖放至 _scrcpy_ 窗口。
|
||||
要推送文件到设备的 `/sdcard/Download/`,将 (非 APK) 文件拖放至 _scrcpy_ 窗口。
|
||||
|
||||
该操作没有可见的响应,只会在控制台输出日志。
|
||||
不会有视觉反馈,终端会输出一条日志。
|
||||
|
||||
在启动时可以修改目标目录:
|
||||
|
||||
```bash
|
||||
scrcpy --push-target /sdcard/foo/bar/
|
||||
scrcpy --push-target=/sdcard/Movies/
|
||||
```
|
||||
|
||||
|
||||
### 音频转发
|
||||
|
||||
_Scrcpy_ 不支持音频。请使用 [sndcpy].
|
||||
_Scrcpy_ 不支持音频。请使用 [sndcpy]。
|
||||
|
||||
另外请阅读 [issue #14]。
|
||||
另见 [issue #14]。
|
||||
|
||||
[sndcpy]: https://github.com/rom1v/sndcpy
|
||||
[issue #14]: https://github.com/Genymobile/scrcpy/issues/14
|
||||
|
@ -632,36 +755,46 @@ _<kbd>[Super]</kbd> 键通常是指 <kbd>Windows</kbd> 或 <kbd>Cmd</kbd> 键。
|
|||
|
||||
[Super]: https://en.wikipedia.org/wiki/Super_key_(keyboard_button)
|
||||
|
||||
| 操作 | 快捷键 |
|
||||
| --------------------------------- | :------------------------------------------- |
|
||||
| 全屏 | <kbd>MOD</kbd>+<kbd>f</kbd> |
|
||||
| 向左旋转屏幕 | <kbd>MOD</kbd>+<kbd>←</kbd> _(左箭头)_ |
|
||||
| 向右旋转屏幕 | <kbd>MOD</kbd>+<kbd>→</kbd> _(右箭头)_ |
|
||||
| 将窗口大小重置为1:1 (匹配像素) | <kbd>MOD</kbd>+<kbd>g</kbd> |
|
||||
| 将窗口大小重置为消除黑边 | <kbd>MOD</kbd>+<kbd>w</kbd> \| _双击¹_ |
|
||||
| 点按 `主屏幕` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _鼠标中键_ |
|
||||
| 点按 `返回` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _鼠标右键²_ |
|
||||
| 点按 `切换应用` | <kbd>MOD</kbd>+<kbd>s</kbd> |
|
||||
| 点按 `菜单` (解锁屏幕) | <kbd>MOD</kbd>+<kbd>m</kbd> |
|
||||
| 点按 `音量+` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(上箭头)_ |
|
||||
| 点按 `音量-` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(下箭头)_ |
|
||||
| 点按 `电源` | <kbd>MOD</kbd>+<kbd>p</kbd> |
|
||||
| 打开屏幕 | _鼠标右键²_ |
|
||||
| 关闭设备屏幕 (但继续在电脑上显示) | <kbd>MOD</kbd>+<kbd>o</kbd> |
|
||||
| 打开设备屏幕 | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>o</kbd> |
|
||||
| 旋转设备屏幕 | <kbd>MOD</kbd>+<kbd>r</kbd> |
|
||||
| 展开通知面板 | <kbd>MOD</kbd>+<kbd>n</kbd> |
|
||||
| 收起通知面板 | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd> |
|
||||
| 复制到剪贴板³ | <kbd>MOD</kbd>+<kbd>c</kbd> |
|
||||
| 剪切到剪贴板³ | <kbd>MOD</kbd>+<kbd>x</kbd> |
|
||||
| 同步剪贴板并粘贴³ | <kbd>MOD</kbd>+<kbd>v</kbd> |
|
||||
| 注入电脑剪贴板文本 | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd> |
|
||||
| 打开/关闭FPS显示 (在 stdout) | <kbd>MOD</kbd>+<kbd>i</kbd> |
|
||||
| 捏拉缩放 | <kbd>Ctrl</kbd>+_按住并移动鼠标_ |
|
||||
| 操作 | 快捷键
|
||||
| --------------------------------- | :-------------------------------------------
|
||||
| 全屏 | <kbd>MOD</kbd>+<kbd>f</kbd>
|
||||
| 向左旋转屏幕 | <kbd>MOD</kbd>+<kbd>←</kbd> _(左箭头)_
|
||||
| 向右旋转屏幕 | <kbd>MOD</kbd>+<kbd>→</kbd> _(右箭头)_
|
||||
| 将窗口大小重置为1:1 (匹配像素) | <kbd>MOD</kbd>+<kbd>g</kbd>
|
||||
| 将窗口大小重置为消除黑边 | <kbd>MOD</kbd>+<kbd>w</kbd> \| _双击左键¹_
|
||||
| 点按 `主屏幕` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _中键_
|
||||
| 点按 `返回` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _右键²_
|
||||
| 点按 `切换应用` | <kbd>MOD</kbd>+<kbd>s</kbd> \| _第4键³_
|
||||
| 点按 `菜单` (解锁屏幕) | <kbd>MOD</kbd>+<kbd>m</kbd>
|
||||
| 点按 `音量+` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(上箭头)_
|
||||
| 点按 `音量-` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(下箭头)_
|
||||
| 点按 `电源` | <kbd>MOD</kbd>+<kbd>p</kbd>
|
||||
| 打开屏幕 | _鼠标右键²_
|
||||
| 关闭设备屏幕 (但继续在电脑上显示) | <kbd>MOD</kbd>+<kbd>o</kbd>
|
||||
| 打开设备屏幕 | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>o</kbd>
|
||||
| 旋转设备屏幕 | <kbd>MOD</kbd>+<kbd>r</kbd>
|
||||
| 展开通知面板 | <kbd>MOD</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>c</kbd>
|
||||
| 剪切到剪贴板⁴ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
||||
| 同步剪贴板并粘贴⁴ | <kbd>MOD</kbd>+<kbd>v</kbd>
|
||||
| 注入电脑剪贴板文本 | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>
|
||||
| 打开/关闭FPS显示 (至标准输出) | <kbd>MOD</kbd>+<kbd>i</kbd>
|
||||
| 捏拉缩放 | <kbd>Ctrl</kbd>+_按住并移动鼠标_
|
||||
| 拖放 APK 文件 | 从电脑安装 APK 文件
|
||||
| 拖放非 APK 文件 | [将文件推送至设备](#push-file-to-device)
|
||||
|
||||
_¹双击黑边可以去除黑边_
|
||||
_²点击鼠标右键将在屏幕熄灭时点亮屏幕,其余情况则视为按下返回键 。_
|
||||
_³需要安卓版本 Android >= 7。_
|
||||
_¹双击黑边可以去除黑边。_
|
||||
_²点击鼠标右键将在屏幕熄灭时点亮屏幕,其余情况则视为按下返回键 。_
|
||||
_³鼠标的第4键和第5键。_
|
||||
_⁴需要安卓版本 Android >= 7。_
|
||||
|
||||
有重复按键的快捷键通过松开再按下一个按键来进行,如“展开设置面板”:
|
||||
|
||||
1. 按下 <kbd>MOD</kbd> 不放。
|
||||
2. 双击 <kbd>n</kbd>。
|
||||
3. 松开 <kbd>MOD</kbd>。
|
||||
|
||||
所有的 <kbd>Ctrl</kbd>+_按键_ 的快捷键都会被转发到设备,所以会由当前应用程序进行处理。
|
||||
|
||||
|
@ -670,18 +803,20 @@ _³需要安卓版本 Android >= 7。_
|
|||
|
||||
要使用指定的 _adb_ 二进制文件,可以设置环境变量 `ADB`:
|
||||
|
||||
ADB=/path/to/adb scrcpy
|
||||
```bash
|
||||
ADB=/path/to/adb scrcpy
|
||||
```
|
||||
|
||||
要覆盖 `scrcpy-server` 的路径,可以设置 `SCRCPY_SERVER_PATH`。
|
||||
|
||||
[useful]: https://github.com/Genymobile/scrcpy/issues/278#issuecomment-429330345
|
||||
要覆盖图标,可以设置其路径至 `SCRCPY_ICON_PATH`。
|
||||
|
||||
|
||||
## 为什么叫 _scrcpy_ ?
|
||||
|
||||
一个同事让我找出一个和 [gnirehtet] 一样难以发音的名字。
|
||||
|
||||
[`strcpy`] 复制一个 **str**ing; `scrcpy` 复制一个 **scr**een。
|
||||
[`strcpy`] 复制一个 **str**ing (字符串); `scrcpy` 复制一个 **scr**een (屏幕)。
|
||||
|
||||
[gnirehtet]: https://github.com/Genymobile/gnirehtet
|
||||
[`strcpy`]: http://man7.org/linux/man-pages/man3/strcpy.3.html
|
||||
|
@ -689,14 +824,12 @@ _³需要安卓版本 Android >= 7。_
|
|||
|
||||
## 如何构建?
|
||||
|
||||
请查看[BUILD]。
|
||||
|
||||
[BUILD]: BUILD.md
|
||||
请查看 [BUILD]。
|
||||
|
||||
|
||||
## 常见问题
|
||||
|
||||
请查看[FAQ](FAQ.md)。
|
||||
请查看 [FAQ](FAQ.md)。
|
||||
|
||||
|
||||
## 开发者
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
src = [
|
||||
'src/main.c',
|
||||
'src/adb.c',
|
||||
'src/adb_tunnel.c',
|
||||
'src/cli.c',
|
||||
'src/clock.c',
|
||||
'src/compat.c',
|
||||
|
@ -32,7 +33,7 @@ src = [
|
|||
'src/util/process.c',
|
||||
'src/util/process_intr.c',
|
||||
'src/util/strbuf.c',
|
||||
'src/util/str_util.c',
|
||||
'src/util/str.c',
|
||||
'src/util/term.c',
|
||||
'src/util/thread.c',
|
||||
'src/util/tick.c',
|
||||
|
@ -198,8 +199,8 @@ if get_option('buildtype') == 'debug'
|
|||
'tests/test_cli.c',
|
||||
'src/cli.c',
|
||||
'src/options.c',
|
||||
'src/util/str.c',
|
||||
'src/util/strbuf.c',
|
||||
'src/util/str_util.c',
|
||||
'src/util/term.c',
|
||||
]],
|
||||
['test_clock', [
|
||||
|
@ -209,8 +210,8 @@ if get_option('buildtype') == 'debug'
|
|||
['test_control_msg_serialize', [
|
||||
'tests/test_control_msg_serialize.c',
|
||||
'src/control_msg.c',
|
||||
'src/util/str.c',
|
||||
'src/util/strbuf.c',
|
||||
'src/util/str_util.c',
|
||||
]],
|
||||
['test_device_msg_deserialize', [
|
||||
'tests/test_device_msg_deserialize.c',
|
||||
|
@ -223,10 +224,10 @@ if get_option('buildtype') == 'debug'
|
|||
'tests/test_strbuf.c',
|
||||
'src/util/strbuf.c',
|
||||
]],
|
||||
['test_strutil', [
|
||||
'tests/test_strutil.c',
|
||||
['test_str', [
|
||||
'tests/test_str.c',
|
||||
'src/util/str.c',
|
||||
'src/util/strbuf.c',
|
||||
'src/util/str_util.c',
|
||||
]],
|
||||
]
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "util/file.h"
|
||||
#include "util/log.h"
|
||||
#include "util/str_util.h"
|
||||
#include "util/str.h"
|
||||
|
||||
static const char *adb_command;
|
||||
|
||||
|
@ -190,11 +190,11 @@ adb_push(const char *serial, const char *local, const char *remote) {
|
|||
#ifdef __WINDOWS__
|
||||
// Windows will parse the string, so the paths must be quoted
|
||||
// (see sys/win/command.c)
|
||||
local = strquote(local);
|
||||
local = sc_str_quote(local);
|
||||
if (!local) {
|
||||
return SC_PROCESS_NONE;
|
||||
}
|
||||
remote = strquote(remote);
|
||||
remote = sc_str_quote(remote);
|
||||
if (!remote) {
|
||||
free((void *) local);
|
||||
return SC_PROCESS_NONE;
|
||||
|
@ -217,7 +217,7 @@ adb_install(const char *serial, const char *local) {
|
|||
#ifdef __WINDOWS__
|
||||
// Windows will parse the string, so the local name must be quoted
|
||||
// (see sys/win/command.c)
|
||||
local = strquote(local);
|
||||
local = sc_str_quote(local);
|
||||
if (!local) {
|
||||
return SC_PROCESS_NONE;
|
||||
}
|
||||
|
|
192
app/src/adb_tunnel.c
Normal file
192
app/src/adb_tunnel.c
Normal file
|
@ -0,0 +1,192 @@
|
|||
#include "adb_tunnel.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "adb.h"
|
||||
#include "util/log.h"
|
||||
#include "util/net_intr.h"
|
||||
#include "util/process_intr.h"
|
||||
|
||||
#define SC_SOCKET_NAME "scrcpy"
|
||||
|
||||
static bool
|
||||
enable_tunnel_reverse(struct sc_intr *intr, const char *serial,
|
||||
uint16_t local_port) {
|
||||
sc_pid pid = adb_reverse(serial, SC_SOCKET_NAME, local_port);
|
||||
return sc_process_check_success_intr(intr, pid, "adb reverse");
|
||||
}
|
||||
|
||||
static bool
|
||||
disable_tunnel_reverse(struct sc_intr *intr, const char *serial) {
|
||||
sc_pid pid = adb_reverse_remove(serial, SC_SOCKET_NAME);
|
||||
return sc_process_check_success_intr(intr, pid, "adb reverse --remove");
|
||||
}
|
||||
|
||||
static bool
|
||||
enable_tunnel_forward(struct sc_intr *intr, const char *serial,
|
||||
uint16_t local_port) {
|
||||
sc_pid pid = adb_forward(serial, local_port, SC_SOCKET_NAME);
|
||||
return sc_process_check_success_intr(intr, pid, "adb forward");
|
||||
}
|
||||
|
||||
static bool
|
||||
disable_tunnel_forward(struct sc_intr *intr, const char *serial,
|
||||
uint16_t local_port) {
|
||||
sc_pid pid = adb_forward_remove(serial, local_port);
|
||||
return sc_process_check_success_intr(intr, pid, "adb forward --remove");
|
||||
}
|
||||
|
||||
static bool
|
||||
listen_on_port(struct sc_intr *intr, sc_socket socket, uint16_t port) {
|
||||
return net_listen_intr(intr, socket, IPV4_LOCALHOST, port, 1);
|
||||
}
|
||||
|
||||
static bool
|
||||
enable_tunnel_reverse_any_port(struct sc_adb_tunnel *tunnel,
|
||||
struct sc_intr *intr, const char *serial,
|
||||
struct sc_port_range port_range) {
|
||||
uint16_t port = port_range.first;
|
||||
for (;;) {
|
||||
if (!enable_tunnel_reverse(intr, serial, port)) {
|
||||
// the command itself failed, it will fail on any port
|
||||
return false;
|
||||
}
|
||||
|
||||
// At the application level, the device part is "the server" because it
|
||||
// serves video stream and control. However, at the network level, the
|
||||
// client listens and the server connects to the client. That way, the
|
||||
// client can listen before starting the server app, so there is no
|
||||
// need to try to connect until the server socket is listening on the
|
||||
// device.
|
||||
sc_socket server_socket = net_socket();
|
||||
if (server_socket != SC_SOCKET_NONE) {
|
||||
bool ok = listen_on_port(intr, server_socket, port);
|
||||
if (ok) {
|
||||
// success
|
||||
tunnel->server_socket = server_socket;
|
||||
tunnel->local_port = port;
|
||||
tunnel->enabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
net_close(server_socket);
|
||||
}
|
||||
|
||||
if (sc_intr_is_interrupted(intr)) {
|
||||
// Stop immediately
|
||||
return false;
|
||||
}
|
||||
|
||||
// failure, disable tunnel and try another port
|
||||
if (!disable_tunnel_reverse(intr, serial)) {
|
||||
LOGW("Could not remove reverse tunnel on port %" PRIu16, port);
|
||||
}
|
||||
|
||||
// check before incrementing to avoid overflow on port 65535
|
||||
if (port < port_range.last) {
|
||||
LOGW("Could not listen on port %" PRIu16", retrying on %" PRIu16,
|
||||
port, (uint16_t) (port + 1));
|
||||
port++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (port_range.first == port_range.last) {
|
||||
LOGE("Could not listen on port %" PRIu16, port_range.first);
|
||||
} else {
|
||||
LOGE("Could not listen on any port in range %" PRIu16 ":%" PRIu16,
|
||||
port_range.first, port_range.last);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
enable_tunnel_forward_any_port(struct sc_adb_tunnel *tunnel,
|
||||
struct sc_intr *intr, const char *serial,
|
||||
struct sc_port_range port_range) {
|
||||
tunnel->forward = true;
|
||||
|
||||
uint16_t port = port_range.first;
|
||||
for (;;) {
|
||||
if (enable_tunnel_forward(intr, serial, port)) {
|
||||
// success
|
||||
tunnel->local_port = port;
|
||||
tunnel->enabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sc_intr_is_interrupted(intr)) {
|
||||
// Stop immediately
|
||||
return false;
|
||||
}
|
||||
|
||||
if (port < port_range.last) {
|
||||
LOGW("Could not forward port %" PRIu16", retrying on %" PRIu16,
|
||||
port, (uint16_t) (port + 1));
|
||||
port++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (port_range.first == port_range.last) {
|
||||
LOGE("Could not forward port %" PRIu16, port_range.first);
|
||||
} else {
|
||||
LOGE("Could not forward any port in range %" PRIu16 ":%" PRIu16,
|
||||
port_range.first, port_range.last);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sc_adb_tunnel_init(struct sc_adb_tunnel *tunnel) {
|
||||
tunnel->enabled = false;
|
||||
tunnel->forward = false;
|
||||
tunnel->server_socket = SC_SOCKET_NONE;
|
||||
tunnel->local_port = 0;
|
||||
}
|
||||
|
||||
bool
|
||||
sc_adb_tunnel_open(struct sc_adb_tunnel *tunnel, struct sc_intr *intr,
|
||||
const char *serial, struct sc_port_range port_range,
|
||||
bool force_adb_forward) {
|
||||
assert(!tunnel->enabled);
|
||||
|
||||
if (!force_adb_forward) {
|
||||
// Attempt to use "adb reverse"
|
||||
if (enable_tunnel_reverse_any_port(tunnel, intr, serial, port_range)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if "adb reverse" does not work (e.g. over "adb connect"), it
|
||||
// fallbacks to "adb forward", so the app socket is the client
|
||||
|
||||
LOGW("'adb reverse' failed, fallback to 'adb forward'");
|
||||
}
|
||||
|
||||
return enable_tunnel_forward_any_port(tunnel, intr, serial, port_range);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_adb_tunnel_close(struct sc_adb_tunnel *tunnel, struct sc_intr *intr,
|
||||
const char *serial) {
|
||||
assert(tunnel->enabled);
|
||||
|
||||
bool ret;
|
||||
if (tunnel->forward) {
|
||||
ret = disable_tunnel_forward(intr, serial, tunnel->local_port);
|
||||
} else {
|
||||
ret = disable_tunnel_reverse(intr, serial);
|
||||
|
||||
assert(tunnel->server_socket != SC_SOCKET_NONE);
|
||||
if (!net_close(tunnel->server_socket)) {
|
||||
LOGW("Could not close server socket");
|
||||
}
|
||||
|
||||
// server_socket is never used anymore
|
||||
}
|
||||
|
||||
// Consider tunnel disabled even if the command failed
|
||||
tunnel->enabled = false;
|
||||
|
||||
return ret;
|
||||
}
|
47
app/src/adb_tunnel.h
Normal file
47
app/src/adb_tunnel.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
#ifndef SC_ADB_TUNNEL_H
|
||||
#define SC_ADB_TUNNEL_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "options.h"
|
||||
#include "util/intr.h"
|
||||
#include "util/net.h"
|
||||
|
||||
struct sc_adb_tunnel {
|
||||
bool enabled;
|
||||
bool forward; // use "adb forward" instead of "adb reverse"
|
||||
sc_socket server_socket; // only used if !forward
|
||||
uint16_t local_port;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize the adb tunnel struct to default values
|
||||
*/
|
||||
void
|
||||
sc_adb_tunnel_init(struct sc_adb_tunnel *tunnel);
|
||||
|
||||
/**
|
||||
* Open a tunnel
|
||||
*
|
||||
* Blocking calls may be interrupted asynchronously via `intr`.
|
||||
*
|
||||
* If `force_adb_forward` is not set, then attempts to set up an "adb reverse"
|
||||
* tunnel first. Only if it fails (typical on old Android version connected via
|
||||
* TCP/IP), use "adb forward".
|
||||
*/
|
||||
bool
|
||||
sc_adb_tunnel_open(struct sc_adb_tunnel *tunnel, struct sc_intr *intr,
|
||||
const char *serial, struct sc_port_range port_range,
|
||||
bool force_adb_forward);
|
||||
|
||||
/**
|
||||
* Close the tunnel
|
||||
*/
|
||||
bool
|
||||
sc_adb_tunnel_close(struct sc_adb_tunnel *tunnel, struct sc_intr *intr,
|
||||
const char *serial);
|
||||
|
||||
#endif
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
#include "options.h"
|
||||
#include "util/log.h"
|
||||
#include "util/str.h"
|
||||
#include "util/strbuf.h"
|
||||
#include "util/str_util.h"
|
||||
#include "util/term.h"
|
||||
|
||||
#define STR_IMPL_(x) #x
|
||||
|
@ -779,9 +779,9 @@ parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
|
|||
long value;
|
||||
bool ok;
|
||||
if (accept_suffix) {
|
||||
ok = parse_integer_with_suffix(s, &value);
|
||||
ok = sc_str_parse_integer_with_suffix(s, &value);
|
||||
} else {
|
||||
ok = parse_integer(s, &value);
|
||||
ok = sc_str_parse_integer(s, &value);
|
||||
}
|
||||
if (!ok) {
|
||||
LOGE("Could not parse %s: %s", name, s);
|
||||
|
@ -801,7 +801,7 @@ parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
|
|||
static size_t
|
||||
parse_integers_arg(const char *s, size_t max_items, long *out, long min,
|
||||
long max, const char *name) {
|
||||
size_t count = parse_integers(s, ':', max_items, out);
|
||||
size_t count = sc_str_parse_integers(s, ':', max_items, out);
|
||||
if (!count) {
|
||||
LOGE("Could not parse %s: %s", name, s);
|
||||
return 0;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "util/buffer_util.h"
|
||||
#include "util/log.h"
|
||||
#include "util/str_util.h"
|
||||
#include "util/str.h"
|
||||
|
||||
/**
|
||||
* Map an enum value to a string based on an array, without crashing on an
|
||||
|
@ -66,7 +66,7 @@ write_position(uint8_t *buf, const struct sc_position *position) {
|
|||
// write length (2 bytes) + string (non nul-terminated)
|
||||
static size_t
|
||||
write_string(const char *utf8, size_t max_len, unsigned char *buf) {
|
||||
size_t len = utf8_truncation_index(utf8, max_len);
|
||||
size_t len = sc_str_utf8_truncation_index(utf8, max_len);
|
||||
buffer_write32be(buf, len);
|
||||
memcpy(&buf[4], utf8, len);
|
||||
return 4 + len;
|
||||
|
|
|
@ -307,7 +307,7 @@ sc_key_processor_process_key(struct sc_key_processor *kp,
|
|||
// requested. Wait a bit so that the clipboard is set before
|
||||
// injecting Ctrl+v via HID, otherwise it would paste the old
|
||||
// clipboard content.
|
||||
hid_event.delay = SC_TICK_FROM_MS(2);
|
||||
hid_event.delay = SC_TICK_FROM_MS(5);
|
||||
}
|
||||
|
||||
if (!sc_aoa_push_hid_event(kb->aoa, &hid_event)) {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "compat.h"
|
||||
#include "util/file.h"
|
||||
#include "util/log.h"
|
||||
#include "util/str_util.h"
|
||||
#include "util/str.h"
|
||||
|
||||
#define SCRCPY_PORTABLE_ICON_FILENAME "icon.png"
|
||||
#define SCRCPY_DEFAULT_ICON_PATH \
|
||||
|
@ -26,7 +26,7 @@ get_icon_path(void) {
|
|||
if (icon_path_env) {
|
||||
// if the envvar is set, use it
|
||||
#ifdef __WINDOWS__
|
||||
char *icon_path = utf8_from_wide_char(icon_path_env);
|
||||
char *icon_path = sc_str_from_wchars(icon_path_env);
|
||||
#else
|
||||
char *icon_path = strdup(icon_path_env);
|
||||
#endif
|
||||
|
@ -158,6 +158,12 @@ free_ctx:
|
|||
return result;
|
||||
}
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 10)
|
||||
// SDL_PixelFormatEnum has been introduced in SDL 2.0.10. Use int for older SDL
|
||||
// versions.
|
||||
typedef int SDL_PixelFormatEnum;
|
||||
#endif
|
||||
|
||||
static SDL_PixelFormatEnum
|
||||
to_sdl_pixel_format(enum AVPixelFormat fmt) {
|
||||
switch (fmt) {
|
||||
|
@ -172,7 +178,9 @@ to_sdl_pixel_format(enum AVPixelFormat fmt) {
|
|||
case AV_PIX_FMT_BGR565BE: return SDL_PIXELFORMAT_BGR565;
|
||||
case AV_PIX_FMT_BGR555BE: return SDL_PIXELFORMAT_BGR555;
|
||||
case AV_PIX_FMT_RGB444BE: return SDL_PIXELFORMAT_RGB444;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 12)
|
||||
case AV_PIX_FMT_BGR444BE: return SDL_PIXELFORMAT_BGR444;
|
||||
#endif
|
||||
case AV_PIX_FMT_PAL8: return SDL_PIXELFORMAT_INDEX8;
|
||||
default: return SDL_PIXELFORMAT_UNKNOWN;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <libavutil/time.h>
|
||||
|
||||
#include "util/log.h"
|
||||
#include "util/str_util.h"
|
||||
#include "util/str.h"
|
||||
|
||||
/** Downcast packet_sink to recorder */
|
||||
#define DOWNCAST(SINK) container_of(SINK, struct recorder, packet_sink)
|
||||
|
@ -26,7 +26,7 @@ find_muxer(const char *name) {
|
|||
oformat = av_oformat_next(oformat);
|
||||
#endif
|
||||
// until null or containing the requested name
|
||||
} while (oformat && !strlist_contains(oformat->name, ',', name));
|
||||
} while (oformat && !sc_str_list_contains(oformat->name, ',', name));
|
||||
return oformat;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#endif
|
||||
|
||||
struct scrcpy {
|
||||
struct server server;
|
||||
struct sc_server server;
|
||||
struct screen screen;
|
||||
struct stream stream;
|
||||
struct decoder decoder;
|
||||
|
@ -286,7 +286,7 @@ stream_on_eos(struct stream *stream, void *userdata) {
|
|||
}
|
||||
|
||||
static void
|
||||
server_on_connection_failed(struct server *server, void *userdata) {
|
||||
sc_server_on_connection_failed(struct sc_server *server, void *userdata) {
|
||||
(void) server;
|
||||
(void) userdata;
|
||||
|
||||
|
@ -294,7 +294,7 @@ server_on_connection_failed(struct server *server, void *userdata) {
|
|||
}
|
||||
|
||||
static void
|
||||
server_on_connected(struct server *server, void *userdata) {
|
||||
sc_server_on_connected(struct sc_server *server, void *userdata) {
|
||||
(void) server;
|
||||
(void) userdata;
|
||||
|
||||
|
@ -302,7 +302,7 @@ server_on_connected(struct server *server, void *userdata) {
|
|||
}
|
||||
|
||||
static void
|
||||
server_on_disconnected(struct server *server, void *userdata) {
|
||||
sc_server_on_disconnected(struct sc_server *server, void *userdata) {
|
||||
(void) server;
|
||||
(void) userdata;
|
||||
|
||||
|
@ -340,7 +340,7 @@ scrcpy(struct scrcpy_options *options) {
|
|||
bool controller_started = false;
|
||||
bool screen_initialized = false;
|
||||
|
||||
struct server_params params = {
|
||||
struct sc_server_params params = {
|
||||
.serial = options->serial,
|
||||
.log_level = options->log_level,
|
||||
.crop = options->crop,
|
||||
|
@ -359,16 +359,16 @@ scrcpy(struct scrcpy_options *options) {
|
|||
.power_off_on_close = options->power_off_on_close,
|
||||
};
|
||||
|
||||
static const struct server_callbacks cbs = {
|
||||
.on_connection_failed = server_on_connection_failed,
|
||||
.on_connected = server_on_connected,
|
||||
.on_disconnected = server_on_disconnected,
|
||||
static const struct sc_server_callbacks cbs = {
|
||||
.on_connection_failed = sc_server_on_connection_failed,
|
||||
.on_connected = sc_server_on_connected,
|
||||
.on_disconnected = sc_server_on_disconnected,
|
||||
};
|
||||
if (!server_init(&s->server, ¶ms, &cbs, NULL)) {
|
||||
if (!sc_server_init(&s->server, ¶ms, &cbs, NULL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!server_start(&s->server)) {
|
||||
if (!sc_server_start(&s->server)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -392,7 +392,7 @@ scrcpy(struct scrcpy_options *options) {
|
|||
}
|
||||
|
||||
// It is necessarily initialized here, since the device is connected
|
||||
struct server_info *info = &s->server.info;
|
||||
struct sc_server_info *info = &s->server.info;
|
||||
|
||||
if (options->display && options->control) {
|
||||
if (!file_handler_init(&s->file_handler, options->serial,
|
||||
|
@ -608,7 +608,7 @@ end:
|
|||
|
||||
if (server_started) {
|
||||
// shutdown the sockets and kill the server
|
||||
server_stop(&s->server);
|
||||
sc_server_stop(&s->server);
|
||||
}
|
||||
|
||||
// now that the sockets are shutdown, the stream and controller are
|
||||
|
@ -653,7 +653,7 @@ end:
|
|||
file_handler_destroy(&s->file_handler);
|
||||
}
|
||||
|
||||
server_destroy(&s->server);
|
||||
sc_server_destroy(&s->server);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
370
app/src/server.c
370
app/src/server.c
|
@ -10,14 +10,14 @@
|
|||
#include "adb.h"
|
||||
#include "util/file.h"
|
||||
#include "util/log.h"
|
||||
#include "util/net.h"
|
||||
#include "util/str_util.h"
|
||||
#include "util/net_intr.h"
|
||||
#include "util/process_intr.h"
|
||||
#include "util/str.h"
|
||||
|
||||
#define SOCKET_NAME "scrcpy"
|
||||
#define SERVER_FILENAME "scrcpy-server"
|
||||
#define SC_SERVER_FILENAME "scrcpy-server"
|
||||
|
||||
#define DEFAULT_SERVER_PATH PREFIX "/share/scrcpy/" SERVER_FILENAME
|
||||
#define DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
|
||||
#define SC_SERVER_PATH_DEFAULT PREFIX "/share/scrcpy/" SC_SERVER_FILENAME
|
||||
#define SC_DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
|
||||
|
||||
static char *
|
||||
get_server_path(void) {
|
||||
|
@ -29,7 +29,7 @@ get_server_path(void) {
|
|||
if (server_path_env) {
|
||||
// if the envvar is set, use it
|
||||
#ifdef __WINDOWS__
|
||||
char *server_path = utf8_from_wide_char(server_path_env);
|
||||
char *server_path = sc_str_from_wchars(server_path_env);
|
||||
#else
|
||||
char *server_path = strdup(server_path_env);
|
||||
#endif
|
||||
|
@ -42,18 +42,18 @@ get_server_path(void) {
|
|||
}
|
||||
|
||||
#ifndef PORTABLE
|
||||
LOGD("Using server: " DEFAULT_SERVER_PATH);
|
||||
char *server_path = strdup(DEFAULT_SERVER_PATH);
|
||||
LOGD("Using server: " SC_SERVER_PATH_DEFAULT);
|
||||
char *server_path = strdup(SC_SERVER_PATH_DEFAULT);
|
||||
if (!server_path) {
|
||||
LOGE("Could not allocate memory");
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
char *server_path = sc_file_get_local_path(SERVER_FILENAME);
|
||||
char *server_path = sc_file_get_local_path(SC_SERVER_FILENAME);
|
||||
if (!server_path) {
|
||||
LOGE("Could not get local file path, "
|
||||
"using " SERVER_FILENAME " from current directory");
|
||||
return strdup(SERVER_FILENAME);
|
||||
"using " SC_SERVER_FILENAME " from current directory");
|
||||
return strdup(SC_SERVER_FILENAME);
|
||||
}
|
||||
|
||||
LOGD("Using server (portable): %s", server_path);
|
||||
|
@ -63,7 +63,7 @@ get_server_path(void) {
|
|||
}
|
||||
|
||||
static void
|
||||
server_params_destroy(struct server_params *params) {
|
||||
sc_server_params_destroy(struct sc_server_params *params) {
|
||||
// The server stores a copy of the params provided by the user
|
||||
free((char *) params->serial);
|
||||
free((char *) params->crop);
|
||||
|
@ -72,7 +72,8 @@ server_params_destroy(struct server_params *params) {
|
|||
}
|
||||
|
||||
static bool
|
||||
server_params_copy(struct server_params *dst, const struct server_params *src) {
|
||||
sc_server_params_copy(struct sc_server_params *dst,
|
||||
const struct sc_server_params *src) {
|
||||
*dst = *src;
|
||||
|
||||
// The params reference user-allocated memory, so we must copy them to
|
||||
|
@ -96,12 +97,12 @@ server_params_copy(struct server_params *dst, const struct server_params *src) {
|
|||
return true;
|
||||
|
||||
error:
|
||||
server_params_destroy(dst);
|
||||
sc_server_params_destroy(dst);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
push_server(const char *serial) {
|
||||
push_server(struct sc_intr *intr, const char *serial) {
|
||||
char *server_path = get_server_path();
|
||||
if (!server_path) {
|
||||
return false;
|
||||
|
@ -111,158 +112,9 @@ push_server(const char *serial) {
|
|||
free(server_path);
|
||||
return false;
|
||||
}
|
||||
sc_pid pid = adb_push(serial, server_path, DEVICE_SERVER_PATH);
|
||||
sc_pid pid = adb_push(serial, server_path, SC_DEVICE_SERVER_PATH);
|
||||
free(server_path);
|
||||
return sc_process_check_success(pid, "adb push", true);
|
||||
}
|
||||
|
||||
static bool
|
||||
enable_tunnel_reverse(const char *serial, uint16_t local_port) {
|
||||
sc_pid pid = adb_reverse(serial, SOCKET_NAME, local_port);
|
||||
return sc_process_check_success(pid, "adb reverse", true);
|
||||
}
|
||||
|
||||
static bool
|
||||
disable_tunnel_reverse(const char *serial) {
|
||||
sc_pid pid = adb_reverse_remove(serial, SOCKET_NAME);
|
||||
return sc_process_check_success(pid, "adb reverse --remove", true);
|
||||
}
|
||||
|
||||
static bool
|
||||
enable_tunnel_forward(const char *serial, uint16_t local_port) {
|
||||
sc_pid pid = adb_forward(serial, local_port, SOCKET_NAME);
|
||||
return sc_process_check_success(pid, "adb forward", true);
|
||||
}
|
||||
|
||||
static bool
|
||||
disable_tunnel_forward(const char *serial, uint16_t local_port) {
|
||||
sc_pid pid = adb_forward_remove(serial, local_port);
|
||||
return sc_process_check_success(pid, "adb forward --remove", true);
|
||||
}
|
||||
|
||||
static bool
|
||||
disable_tunnel(struct server *server) {
|
||||
assert(server->tunnel_enabled);
|
||||
|
||||
const char *serial = server->params.serial;
|
||||
bool ok = server->tunnel_forward
|
||||
? disable_tunnel_forward(serial, server->local_port)
|
||||
: disable_tunnel_reverse(serial);
|
||||
|
||||
// Consider tunnel disabled even if the command failed
|
||||
server->tunnel_enabled = false;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
static bool
|
||||
listen_on_port(sc_socket socket, uint16_t port) {
|
||||
#define IPV4_LOCALHOST 0x7F000001
|
||||
return net_listen(socket, IPV4_LOCALHOST, port, 1);
|
||||
}
|
||||
|
||||
static bool
|
||||
enable_tunnel_reverse_any_port(struct server *server,
|
||||
struct sc_port_range port_range) {
|
||||
const char *serial = server->params.serial;
|
||||
uint16_t port = port_range.first;
|
||||
for (;;) {
|
||||
if (!enable_tunnel_reverse(serial, port)) {
|
||||
// the command itself failed, it will fail on any port
|
||||
return false;
|
||||
}
|
||||
|
||||
// At the application level, the device part is "the server" because it
|
||||
// serves video stream and control. However, at the network level, the
|
||||
// client listens and the server connects to the client. That way, the
|
||||
// client can listen before starting the server app, so there is no
|
||||
// need to try to connect until the server socket is listening on the
|
||||
// device.
|
||||
sc_socket server_socket = net_socket();
|
||||
if (server_socket != SC_INVALID_SOCKET) {
|
||||
bool ok = listen_on_port(server_socket, port);
|
||||
if (ok) {
|
||||
// success
|
||||
server->server_socket = server_socket;
|
||||
server->local_port = port;
|
||||
server->tunnel_enabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
net_close(server_socket);
|
||||
}
|
||||
|
||||
// failure, disable tunnel and try another port
|
||||
if (!disable_tunnel_reverse(serial)) {
|
||||
LOGW("Could not remove reverse tunnel on port %" PRIu16, port);
|
||||
}
|
||||
|
||||
// check before incrementing to avoid overflow on port 65535
|
||||
if (port < port_range.last) {
|
||||
LOGW("Could not listen on port %" PRIu16", retrying on %" PRIu16,
|
||||
port, (uint16_t) (port + 1));
|
||||
port++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (port_range.first == port_range.last) {
|
||||
LOGE("Could not listen on port %" PRIu16, port_range.first);
|
||||
} else {
|
||||
LOGE("Could not listen on any port in range %" PRIu16 ":%" PRIu16,
|
||||
port_range.first, port_range.last);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
enable_tunnel_forward_any_port(struct server *server,
|
||||
struct sc_port_range port_range) {
|
||||
server->tunnel_forward = true;
|
||||
|
||||
const char *serial = server->params.serial;
|
||||
uint16_t port = port_range.first;
|
||||
for (;;) {
|
||||
if (enable_tunnel_forward(serial, port)) {
|
||||
// success
|
||||
server->local_port = port;
|
||||
server->tunnel_enabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (port < port_range.last) {
|
||||
LOGW("Could not forward port %" PRIu16", retrying on %" PRIu16,
|
||||
port, (uint16_t) (port + 1));
|
||||
port++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (port_range.first == port_range.last) {
|
||||
LOGE("Could not forward port %" PRIu16, port_range.first);
|
||||
} else {
|
||||
LOGE("Could not forward any port in range %" PRIu16 ":%" PRIu16,
|
||||
port_range.first, port_range.last);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
enable_tunnel_any_port(struct server *server, struct sc_port_range port_range,
|
||||
bool force_adb_forward) {
|
||||
if (!force_adb_forward) {
|
||||
// Attempt to use "adb reverse"
|
||||
if (enable_tunnel_reverse_any_port(server, port_range)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if "adb reverse" does not work (e.g. over "adb connect"), it
|
||||
// fallbacks to "adb forward", so the app socket is the client
|
||||
|
||||
LOGW("'adb reverse' failed, fallback to 'adb forward'");
|
||||
}
|
||||
|
||||
return enable_tunnel_forward_any_port(server, port_range);
|
||||
return sc_process_check_success_intr(intr, pid, "adb push");
|
||||
}
|
||||
|
||||
static const char *
|
||||
|
@ -285,7 +137,8 @@ log_level_to_server_string(enum sc_log_level level) {
|
|||
}
|
||||
|
||||
static sc_pid
|
||||
execute_server(struct server *server, const struct server_params *params) {
|
||||
execute_server(struct sc_server *server,
|
||||
const struct sc_server_params *params) {
|
||||
const char *serial = server->params.serial;
|
||||
|
||||
char max_size_string[6];
|
||||
|
@ -301,7 +154,7 @@ execute_server(struct server *server, const struct server_params *params) {
|
|||
sprintf(display_id_string, "%"PRIu32, params->display_id);
|
||||
const char *const cmd[] = {
|
||||
"shell",
|
||||
"CLASSPATH=" DEVICE_SERVER_PATH,
|
||||
"CLASSPATH=" SC_DEVICE_SERVER_PATH,
|
||||
"app_process",
|
||||
#ifdef SERVER_DEBUGGER
|
||||
# define SERVER_DEBUGGER_PORT "5005"
|
||||
|
@ -323,7 +176,7 @@ execute_server(struct server *server, const struct server_params *params) {
|
|||
bit_rate_string,
|
||||
max_fps_string,
|
||||
lock_video_orientation_string,
|
||||
server->tunnel_forward ? "true" : "false",
|
||||
server->tunnel.forward ? "true" : "false",
|
||||
params->crop ? params->crop : "-",
|
||||
"true", // always send frame meta (packet boundaries + timestamp)
|
||||
params->control ? "true" : "false",
|
||||
|
@ -349,8 +202,8 @@ execute_server(struct server *server, const struct server_params *params) {
|
|||
}
|
||||
|
||||
static bool
|
||||
connect_and_read_byte(sc_socket socket, uint16_t port) {
|
||||
bool ok = net_connect(socket, IPV4_LOCALHOST, port);
|
||||
connect_and_read_byte(struct sc_intr *intr, sc_socket socket, uint16_t port) {
|
||||
bool ok = net_connect_intr(intr, socket, IPV4_LOCALHOST, port);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
@ -358,7 +211,7 @@ connect_and_read_byte(sc_socket socket, uint16_t port) {
|
|||
char byte;
|
||||
// the connection may succeed even if the server behind the "adb tunnel"
|
||||
// is not listening, so read one byte to detect a working connection
|
||||
if (net_recv(socket, &byte, 1) != 1) {
|
||||
if (net_recv_intr(intr, socket, &byte, 1) != 1) {
|
||||
// the server is not listening yet behind the adb tunnel
|
||||
return false;
|
||||
}
|
||||
|
@ -367,13 +220,13 @@ connect_and_read_byte(sc_socket socket, uint16_t port) {
|
|||
}
|
||||
|
||||
static sc_socket
|
||||
connect_to_server(struct server *server, uint32_t attempts, sc_tick delay) {
|
||||
uint16_t port = server->local_port;
|
||||
connect_to_server(struct sc_server *server, uint32_t attempts, sc_tick delay) {
|
||||
uint16_t port = server->tunnel.local_port;
|
||||
do {
|
||||
LOGD("Remaining connection attempts: %d", (int) attempts);
|
||||
sc_socket socket = net_socket();
|
||||
if (socket != SC_INVALID_SOCKET) {
|
||||
bool ok = connect_and_read_byte(socket, port);
|
||||
if (socket != SC_SOCKET_NONE) {
|
||||
bool ok = connect_and_read_byte(&server->intr, socket, port);
|
||||
if (ok) {
|
||||
// it worked!
|
||||
return socket;
|
||||
|
@ -398,13 +251,13 @@ connect_to_server(struct server *server, uint32_t attempts, sc_tick delay) {
|
|||
}
|
||||
}
|
||||
} while (--attempts > 0);
|
||||
return SC_INVALID_SOCKET;
|
||||
return SC_SOCKET_NONE;
|
||||
}
|
||||
|
||||
bool
|
||||
server_init(struct server *server, const struct server_params *params,
|
||||
const struct server_callbacks *cbs, void *cbs_userdata) {
|
||||
bool ok = server_params_copy(&server->params, params);
|
||||
sc_server_init(struct sc_server *server, const struct sc_server_params *params,
|
||||
const struct sc_server_callbacks *cbs, void *cbs_userdata) {
|
||||
bool ok = sc_server_params_copy(&server->params, params);
|
||||
if (!ok) {
|
||||
LOGE("Could not copy server params");
|
||||
return false;
|
||||
|
@ -413,7 +266,7 @@ server_init(struct server *server, const struct server_params *params,
|
|||
ok = sc_mutex_init(&server->mutex);
|
||||
if (!ok) {
|
||||
LOGE("Could not create server mutex");
|
||||
server_params_destroy(&server->params);
|
||||
sc_server_params_destroy(&server->params);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -421,20 +274,25 @@ server_init(struct server *server, const struct server_params *params,
|
|||
if (!ok) {
|
||||
LOGE("Could not create server cond_stopped");
|
||||
sc_mutex_destroy(&server->mutex);
|
||||
server_params_destroy(&server->params);
|
||||
sc_server_params_destroy(&server->params);
|
||||
return false;
|
||||
}
|
||||
|
||||
ok = sc_intr_init(&server->intr);
|
||||
if (!ok) {
|
||||
LOGE("Could not create intr");
|
||||
sc_cond_destroy(&server->cond_stopped);
|
||||
sc_mutex_destroy(&server->mutex);
|
||||
sc_server_params_destroy(&server->params);
|
||||
return false;
|
||||
}
|
||||
|
||||
server->stopped = false;
|
||||
|
||||
server->server_socket = SC_INVALID_SOCKET;
|
||||
server->video_socket = SC_INVALID_SOCKET;
|
||||
server->control_socket = SC_INVALID_SOCKET;
|
||||
server->video_socket = SC_SOCKET_NONE;
|
||||
server->control_socket = SC_SOCKET_NONE;
|
||||
|
||||
server->local_port = 0;
|
||||
|
||||
server->tunnel_enabled = false;
|
||||
server->tunnel_forward = false;
|
||||
sc_adb_tunnel_init(&server->tunnel);
|
||||
|
||||
assert(cbs);
|
||||
assert(cbs->on_connection_failed);
|
||||
|
@ -448,78 +306,76 @@ server_init(struct server *server, const struct server_params *params,
|
|||
}
|
||||
|
||||
static bool
|
||||
device_read_info(sc_socket device_socket, struct server_info *info) {
|
||||
unsigned char buf[DEVICE_NAME_FIELD_LENGTH + 4];
|
||||
ssize_t r = net_recv_all(device_socket, buf, sizeof(buf));
|
||||
if (r < DEVICE_NAME_FIELD_LENGTH + 4) {
|
||||
device_read_info(struct sc_intr *intr, sc_socket device_socket,
|
||||
struct sc_server_info *info) {
|
||||
unsigned char buf[SC_DEVICE_NAME_FIELD_LENGTH + 4];
|
||||
ssize_t r = net_recv_all_intr(intr, device_socket, buf, sizeof(buf));
|
||||
if (r < SC_DEVICE_NAME_FIELD_LENGTH + 4) {
|
||||
LOGE("Could not retrieve device information");
|
||||
return false;
|
||||
}
|
||||
// in case the client sends garbage
|
||||
buf[DEVICE_NAME_FIELD_LENGTH - 1] = '\0';
|
||||
buf[SC_DEVICE_NAME_FIELD_LENGTH - 1] = '\0';
|
||||
memcpy(info->device_name, (char *) buf, sizeof(info->device_name));
|
||||
|
||||
info->frame_size.width = (buf[DEVICE_NAME_FIELD_LENGTH] << 8)
|
||||
| buf[DEVICE_NAME_FIELD_LENGTH + 1];
|
||||
info->frame_size.height = (buf[DEVICE_NAME_FIELD_LENGTH + 2] << 8)
|
||||
| buf[DEVICE_NAME_FIELD_LENGTH + 3];
|
||||
info->frame_size.width = (buf[SC_DEVICE_NAME_FIELD_LENGTH] << 8)
|
||||
| buf[SC_DEVICE_NAME_FIELD_LENGTH + 1];
|
||||
info->frame_size.height = (buf[SC_DEVICE_NAME_FIELD_LENGTH + 2] << 8)
|
||||
| buf[SC_DEVICE_NAME_FIELD_LENGTH + 3];
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
server_connect_to(struct server *server, struct server_info *info) {
|
||||
assert(server->tunnel_enabled);
|
||||
sc_server_connect_to(struct sc_server *server, struct sc_server_info *info) {
|
||||
struct sc_adb_tunnel *tunnel = &server->tunnel;
|
||||
|
||||
sc_socket video_socket = SC_INVALID_SOCKET;
|
||||
sc_socket control_socket = SC_INVALID_SOCKET;
|
||||
if (!server->tunnel_forward) {
|
||||
video_socket = net_accept(server->server_socket);
|
||||
if (video_socket == SC_INVALID_SOCKET) {
|
||||
assert(tunnel->enabled);
|
||||
|
||||
const char *serial = server->params.serial;
|
||||
|
||||
sc_socket video_socket = SC_SOCKET_NONE;
|
||||
sc_socket control_socket = SC_SOCKET_NONE;
|
||||
if (!tunnel->forward) {
|
||||
video_socket = net_accept_intr(&server->intr, tunnel->server_socket);
|
||||
if (video_socket == SC_SOCKET_NONE) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
control_socket = net_accept(server->server_socket);
|
||||
if (control_socket == SC_INVALID_SOCKET) {
|
||||
control_socket = net_accept_intr(&server->intr, tunnel->server_socket);
|
||||
if (control_socket == SC_SOCKET_NONE) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// we don't need the server socket anymore
|
||||
if (!net_close(server->server_socket)) {
|
||||
LOGW("Could not close server socket on connect");
|
||||
}
|
||||
// Do not attempt to close it again on server_destroy()
|
||||
server->server_socket = SC_INVALID_SOCKET;
|
||||
} else {
|
||||
uint32_t attempts = 100;
|
||||
sc_tick delay = SC_TICK_FROM_MS(100);
|
||||
video_socket = connect_to_server(server, attempts, delay);
|
||||
if (video_socket == SC_INVALID_SOCKET) {
|
||||
if (video_socket == SC_SOCKET_NONE) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// we know that the device is listening, we don't need several attempts
|
||||
control_socket = net_socket();
|
||||
if (control_socket == SC_INVALID_SOCKET) {
|
||||
if (control_socket == SC_SOCKET_NONE) {
|
||||
goto fail;
|
||||
}
|
||||
bool ok = net_connect(control_socket, IPV4_LOCALHOST,
|
||||
server->local_port);
|
||||
bool ok = net_connect_intr(&server->intr, control_socket,
|
||||
IPV4_LOCALHOST, tunnel->local_port);
|
||||
if (!ok) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
// we don't need the adb tunnel anymore
|
||||
disable_tunnel(server); // ignore failure
|
||||
sc_adb_tunnel_close(tunnel, &server->intr, serial);
|
||||
|
||||
// The sockets will be closed on stop if device_read_info() fails
|
||||
bool ok = device_read_info(video_socket, info);
|
||||
bool ok = device_read_info(&server->intr, video_socket, info);
|
||||
if (!ok) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
assert(video_socket != SC_INVALID_SOCKET);
|
||||
assert(control_socket != SC_INVALID_SOCKET);
|
||||
assert(video_socket != SC_SOCKET_NONE);
|
||||
assert(control_socket != SC_SOCKET_NONE);
|
||||
|
||||
server->video_socket = video_socket;
|
||||
server->control_socket = control_socket;
|
||||
|
@ -527,36 +383,33 @@ server_connect_to(struct server *server, struct server_info *info) {
|
|||
return true;
|
||||
|
||||
fail:
|
||||
if (video_socket != SC_INVALID_SOCKET) {
|
||||
if (video_socket != SC_SOCKET_NONE) {
|
||||
if (!net_close(video_socket)) {
|
||||
LOGW("Could not close video socket");
|
||||
}
|
||||
}
|
||||
|
||||
if (control_socket != SC_INVALID_SOCKET) {
|
||||
if (control_socket != SC_SOCKET_NONE) {
|
||||
if (!net_close(control_socket)) {
|
||||
LOGW("Could not close control socket");
|
||||
}
|
||||
}
|
||||
|
||||
// Always leave this function with tunnel disabled
|
||||
disable_tunnel(server);
|
||||
sc_adb_tunnel_close(tunnel, &server->intr, serial);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
server_on_terminated(void *userdata) {
|
||||
struct server *server = userdata;
|
||||
sc_server_on_terminated(void *userdata) {
|
||||
struct sc_server *server = userdata;
|
||||
|
||||
// No need for synchronization, server_socket is initialized before the
|
||||
// observer thread is created.
|
||||
if (server->server_socket != SC_INVALID_SOCKET) {
|
||||
// If the server process dies before connecting to the server socket,
|
||||
// then the client will be stuck forever on accept(). To avoid the
|
||||
// problem, wake up the accept() call when the server dies.
|
||||
net_interrupt(server->server_socket);
|
||||
}
|
||||
// If the server process dies before connecting to the server socket,
|
||||
// then the client will be stuck forever on accept(). To avoid the problem,
|
||||
// wake up the accept() call (or any other) when the server dies, like on
|
||||
// stop() (it is safe to call interrupt() twice).
|
||||
sc_intr_interrupt(&server->intr);
|
||||
|
||||
server->cbs->on_disconnected(server, server->cbs_userdata);
|
||||
|
||||
|
@ -565,17 +418,17 @@ server_on_terminated(void *userdata) {
|
|||
|
||||
static int
|
||||
run_server(void *data) {
|
||||
struct server *server = data;
|
||||
struct sc_server *server = data;
|
||||
|
||||
const struct server_params *params = &server->params;
|
||||
const struct sc_server_params *params = &server->params;
|
||||
|
||||
bool ok = push_server(params->serial);
|
||||
bool ok = push_server(&server->intr, params->serial);
|
||||
if (!ok) {
|
||||
goto error_connection_failed;
|
||||
}
|
||||
|
||||
ok = enable_tunnel_any_port(server, params->port_range,
|
||||
params->force_adb_forward);
|
||||
ok = sc_adb_tunnel_open(&server->tunnel, &server->intr, params->serial,
|
||||
params->port_range, params->force_adb_forward);
|
||||
if (!ok) {
|
||||
goto error_connection_failed;
|
||||
}
|
||||
|
@ -583,23 +436,23 @@ run_server(void *data) {
|
|||
// server will connect to our server socket
|
||||
sc_pid pid = execute_server(server, params);
|
||||
if (pid == SC_PROCESS_NONE) {
|
||||
disable_tunnel(server);
|
||||
sc_adb_tunnel_close(&server->tunnel, &server->intr, params->serial);
|
||||
goto error_connection_failed;
|
||||
}
|
||||
|
||||
static const struct sc_process_listener listener = {
|
||||
.on_terminated = server_on_terminated,
|
||||
.on_terminated = sc_server_on_terminated,
|
||||
};
|
||||
struct sc_process_observer observer;
|
||||
ok = sc_process_observer_init(&observer, pid, &listener, server);
|
||||
if (!ok) {
|
||||
sc_process_terminate(pid);
|
||||
sc_process_wait(pid, true); // ignore exit code
|
||||
disable_tunnel(server);
|
||||
sc_adb_tunnel_close(&server->tunnel, &server->intr, params->serial);
|
||||
goto error_connection_failed;
|
||||
}
|
||||
|
||||
ok = server_connect_to(server, &server->info);
|
||||
ok = sc_server_connect_to(server, &server->info);
|
||||
// The tunnel is always closed by server_connect_to()
|
||||
if (!ok) {
|
||||
sc_process_terminate(pid);
|
||||
|
@ -619,23 +472,6 @@ run_server(void *data) {
|
|||
}
|
||||
sc_mutex_unlock(&server->mutex);
|
||||
|
||||
// Server stop has been requested
|
||||
if (server->server_socket != SC_INVALID_SOCKET) {
|
||||
if (!net_interrupt(server->server_socket)) {
|
||||
LOGW("Could not interrupt server socket");
|
||||
}
|
||||
}
|
||||
if (server->video_socket != SC_INVALID_SOCKET) {
|
||||
if (!net_interrupt(server->video_socket)) {
|
||||
LOGW("Could not interrupt video socket");
|
||||
}
|
||||
}
|
||||
if (server->control_socket != SC_INVALID_SOCKET) {
|
||||
if (!net_interrupt(server->control_socket)) {
|
||||
LOGW("Could not interrupt control socket");
|
||||
}
|
||||
}
|
||||
|
||||
// Give some delay for the server to terminate properly
|
||||
#define WATCHDOG_DELAY SC_TICK_FROM_SEC(1)
|
||||
sc_tick deadline = sc_tick_now() + WATCHDOG_DELAY;
|
||||
|
@ -665,7 +501,7 @@ error_connection_failed:
|
|||
}
|
||||
|
||||
bool
|
||||
server_start(struct server *server) {
|
||||
sc_server_start(struct sc_server *server) {
|
||||
bool ok = sc_thread_create(&server->thread, run_server, "server", server);
|
||||
if (!ok) {
|
||||
LOGE("Could not create server thread");
|
||||
|
@ -676,18 +512,20 @@ server_start(struct server *server) {
|
|||
}
|
||||
|
||||
void
|
||||
server_stop(struct server *server) {
|
||||
sc_server_stop(struct sc_server *server) {
|
||||
sc_mutex_lock(&server->mutex);
|
||||
server->stopped = true;
|
||||
sc_cond_signal(&server->cond_stopped);
|
||||
sc_intr_interrupt(&server->intr);
|
||||
sc_mutex_unlock(&server->mutex);
|
||||
|
||||
sc_thread_join(&server->thread, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
server_destroy(struct server *server) {
|
||||
server_params_destroy(&server->params);
|
||||
sc_server_destroy(struct sc_server *server) {
|
||||
sc_server_params_destroy(&server->params);
|
||||
sc_intr_destroy(&server->intr);
|
||||
sc_cond_destroy(&server->cond_stopped);
|
||||
sc_mutex_destroy(&server->mutex);
|
||||
}
|
||||
|
|
|
@ -8,19 +8,21 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "adb.h"
|
||||
#include "adb_tunnel.h"
|
||||
#include "coords.h"
|
||||
#include "options.h"
|
||||
#include "util/intr.h"
|
||||
#include "util/log.h"
|
||||
#include "util/net.h"
|
||||
#include "util/thread.h"
|
||||
|
||||
#define DEVICE_NAME_FIELD_LENGTH 64
|
||||
struct server_info {
|
||||
char device_name[DEVICE_NAME_FIELD_LENGTH];
|
||||
#define SC_DEVICE_NAME_FIELD_LENGTH 64
|
||||
struct sc_server_info {
|
||||
char device_name[SC_DEVICE_NAME_FIELD_LENGTH];
|
||||
struct sc_size frame_size;
|
||||
};
|
||||
|
||||
struct server_params {
|
||||
struct sc_server_params {
|
||||
const char *serial;
|
||||
enum sc_log_level log_level;
|
||||
const char *crop;
|
||||
|
@ -39,63 +41,62 @@ struct server_params {
|
|||
bool power_off_on_close;
|
||||
};
|
||||
|
||||
struct server {
|
||||
struct sc_server {
|
||||
// The internal allocated strings are copies owned by the server
|
||||
struct server_params params;
|
||||
struct sc_server_params params;
|
||||
|
||||
sc_thread thread;
|
||||
struct server_info info; // initialized once connected
|
||||
struct sc_server_info info; // initialized once connected
|
||||
|
||||
sc_mutex mutex;
|
||||
sc_cond cond_stopped;
|
||||
bool stopped;
|
||||
|
||||
sc_socket server_socket; // only used if !tunnel_forward
|
||||
struct sc_intr intr;
|
||||
struct sc_adb_tunnel tunnel;
|
||||
|
||||
sc_socket video_socket;
|
||||
sc_socket control_socket;
|
||||
uint16_t local_port; // selected from port_range
|
||||
bool tunnel_enabled;
|
||||
bool tunnel_forward; // use "adb forward" instead of "adb reverse"
|
||||
|
||||
const struct server_callbacks *cbs;
|
||||
const struct sc_server_callbacks *cbs;
|
||||
void *cbs_userdata;
|
||||
};
|
||||
|
||||
struct server_callbacks {
|
||||
struct sc_server_callbacks {
|
||||
/**
|
||||
* Called when the server failed to connect
|
||||
*
|
||||
* If it is called, then on_connected() and on_disconnected() will never be
|
||||
* called.
|
||||
*/
|
||||
void (*on_connection_failed)(struct server *server, void *userdata);
|
||||
void (*on_connection_failed)(struct sc_server *server, void *userdata);
|
||||
|
||||
/**
|
||||
* Called on server connection
|
||||
*/
|
||||
void (*on_connected)(struct server *server, void *userdata);
|
||||
void (*on_connected)(struct sc_server *server, void *userdata);
|
||||
|
||||
/**
|
||||
* Called on server disconnection (after it has been connected)
|
||||
*/
|
||||
void (*on_disconnected)(struct server *server, void *userdata);
|
||||
void (*on_disconnected)(struct sc_server *server, void *userdata);
|
||||
};
|
||||
|
||||
// init the server with the given params
|
||||
bool
|
||||
server_init(struct server *server, const struct server_params *params,
|
||||
const struct server_callbacks *cbs, void *cbs_userdata);
|
||||
sc_server_init(struct sc_server *server, const struct sc_server_params *params,
|
||||
const struct sc_server_callbacks *cbs, void *cbs_userdata);
|
||||
|
||||
// start the server asynchronously
|
||||
bool
|
||||
server_start(struct server *server);
|
||||
sc_server_start(struct sc_server *server);
|
||||
|
||||
// disconnect and kill the server process
|
||||
void
|
||||
server_stop(struct server *server);
|
||||
sc_server_stop(struct sc_server *server);
|
||||
|
||||
// close and release sockets
|
||||
void
|
||||
server_destroy(struct server *server);
|
||||
sc_server_destroy(struct sc_server *server);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <sys/stat.h>
|
||||
|
||||
#include "util/log.h"
|
||||
#include "util/str_util.h"
|
||||
#include "util/str.h"
|
||||
|
||||
char *
|
||||
sc_file_get_executable_path(void) {
|
||||
|
@ -19,12 +19,12 @@ sc_file_get_executable_path(void) {
|
|||
return NULL;
|
||||
}
|
||||
buf[len] = '\0';
|
||||
return utf8_from_wide_char(buf);
|
||||
return sc_str_from_wchars(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_file_is_regular(const char *path) {
|
||||
wchar_t *wide_path = utf8_to_wide_char(path);
|
||||
wchar_t *wide_path = sc_str_to_wchars(path);
|
||||
if (!wide_path) {
|
||||
LOGC("Could not allocate wide char string");
|
||||
return false;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include "util/log.h"
|
||||
#include "util/str_util.h"
|
||||
#include "util/str.h"
|
||||
|
||||
#define CMD_MAX_LEN 8192
|
||||
|
||||
|
@ -13,7 +13,7 @@ build_cmd(char *cmd, size_t len, const char *const argv[]) {
|
|||
// <http://daviddeley.com/autohotkey/parameters/parameters.htm#WINPASS>
|
||||
// only make it work for this very specific program
|
||||
// (don't handle escaping nor quotes)
|
||||
size_t ret = xstrjoin(cmd, argv, ' ', len);
|
||||
size_t ret = sc_str_join(cmd, argv, ' ', len);
|
||||
if (ret >= len) {
|
||||
LOGE("Command too long (%" SC_PRIsizet " chars)", len - 1);
|
||||
return false;
|
||||
|
@ -88,7 +88,7 @@ sc_process_execute_p(const char *const argv[], HANDLE *handle,
|
|||
goto error_close_stderr;
|
||||
}
|
||||
|
||||
wchar_t *wide = utf8_to_wide_char(cmd);
|
||||
wchar_t *wide = sc_str_to_wchars(cmd);
|
||||
free(cmd);
|
||||
if (!wide) {
|
||||
LOGC("Could not allocate wide char string");
|
||||
|
|
|
@ -12,7 +12,7 @@ sc_intr_init(struct sc_intr *intr) {
|
|||
return false;
|
||||
}
|
||||
|
||||
intr->socket = SC_INVALID_SOCKET;
|
||||
intr->socket = SC_SOCKET_NONE;
|
||||
intr->process = SC_PROCESS_NONE;
|
||||
|
||||
atomic_store_explicit(&intr->interrupted, false, memory_order_relaxed);
|
||||
|
@ -37,7 +37,7 @@ sc_intr_set_socket(struct sc_intr *intr, sc_socket socket) {
|
|||
|
||||
bool
|
||||
sc_intr_set_process(struct sc_intr *intr, sc_pid pid) {
|
||||
assert(intr->socket == SC_INVALID_SOCKET);
|
||||
assert(intr->socket == SC_SOCKET_NONE);
|
||||
|
||||
sc_mutex_lock(&intr->mutex);
|
||||
bool interrupted =
|
||||
|
@ -57,13 +57,13 @@ sc_intr_interrupt(struct sc_intr *intr) {
|
|||
atomic_store_explicit(&intr->interrupted, true, memory_order_relaxed);
|
||||
|
||||
// No more than one component to interrupt
|
||||
assert(intr->socket == SC_INVALID_SOCKET ||
|
||||
assert(intr->socket == SC_SOCKET_NONE ||
|
||||
intr->process == SC_PROCESS_NONE);
|
||||
|
||||
if (intr->socket != SC_INVALID_SOCKET) {
|
||||
if (intr->socket != SC_SOCKET_NONE) {
|
||||
LOGD("Interrupting socket");
|
||||
net_interrupt(intr->socket);
|
||||
intr->socket = SC_INVALID_SOCKET;
|
||||
intr->socket = SC_SOCKET_NONE;
|
||||
}
|
||||
if (intr->process != SC_PROCESS_NONE) {
|
||||
LOGD("Interrupting process");
|
||||
|
@ -76,7 +76,7 @@ sc_intr_interrupt(struct sc_intr *intr) {
|
|||
|
||||
void
|
||||
sc_intr_destroy(struct sc_intr *intr) {
|
||||
assert(intr->socket == SC_INVALID_SOCKET);
|
||||
assert(intr->socket == SC_SOCKET_NONE);
|
||||
assert(intr->process == SC_PROCESS_NONE);
|
||||
|
||||
sc_mutex_destroy(&intr->mutex);
|
||||
|
|
|
@ -37,7 +37,7 @@ sc_intr_init(struct sc_intr *intr);
|
|||
/**
|
||||
* Set a socket as the interruptible component
|
||||
*
|
||||
* Call with SC_INVALID_SOCKET to unset.
|
||||
* Call with SC_SOCKET_NONE to unset.
|
||||
*/
|
||||
bool
|
||||
sc_intr_set_socket(struct sc_intr *intr, sc_socket socket);
|
||||
|
|
|
@ -46,13 +46,13 @@ static inline sc_socket
|
|||
wrap(sc_raw_socket sock) {
|
||||
#ifdef __WINDOWS__
|
||||
if (sock == INVALID_SOCKET) {
|
||||
return SC_INVALID_SOCKET;
|
||||
return SC_SOCKET_NONE;
|
||||
}
|
||||
|
||||
struct sc_socket_windows *socket = malloc(sizeof(*socket));
|
||||
if (!socket) {
|
||||
closesocket(sock);
|
||||
return SC_INVALID_SOCKET;
|
||||
return SC_SOCKET_NONE;
|
||||
}
|
||||
|
||||
socket->socket = sock;
|
||||
|
@ -67,7 +67,7 @@ wrap(sc_raw_socket sock) {
|
|||
static inline sc_raw_socket
|
||||
unwrap(sc_socket socket) {
|
||||
#ifdef __WINDOWS__
|
||||
if (socket == SC_INVALID_SOCKET) {
|
||||
if (socket == SC_SOCKET_NONE) {
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ sc_socket
|
|||
net_socket(void) {
|
||||
sc_raw_socket raw_sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
sc_socket sock = wrap(raw_sock);
|
||||
if (sock == SC_INVALID_SOCKET) {
|
||||
if (sock == SC_SOCKET_NONE) {
|
||||
net_perror("socket");
|
||||
}
|
||||
return sock;
|
||||
|
@ -195,7 +195,7 @@ net_send_all(sc_socket socket, const void *buf, size_t len) {
|
|||
|
||||
bool
|
||||
net_interrupt(sc_socket socket) {
|
||||
assert(socket != SC_INVALID_SOCKET);
|
||||
assert(socket != SC_SOCKET_NONE);
|
||||
|
||||
sc_raw_socket raw_sock = unwrap(socket);
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
# include <winsock2.h>
|
||||
# include <stdatomic.h>
|
||||
# define SC_INVALID_SOCKET NULL
|
||||
# define SC_SOCKET_NONE NULL
|
||||
typedef struct sc_socket_windows {
|
||||
SOCKET socket;
|
||||
atomic_flag closed;
|
||||
|
@ -20,10 +20,13 @@
|
|||
#else // not __WINDOWS__
|
||||
|
||||
# include <sys/socket.h>
|
||||
# define SC_INVALID_SOCKET -1
|
||||
# define SC_SOCKET_NONE -1
|
||||
typedef int sc_socket;
|
||||
|
||||
#endif
|
||||
|
||||
#define IPV4_LOCALHOST 0x7F000001
|
||||
|
||||
bool
|
||||
net_init(void);
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ net_connect_intr(struct sc_intr *intr, sc_socket socket, uint32_t addr,
|
|||
|
||||
bool ret = net_connect(socket, addr, port);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ net_listen_intr(struct sc_intr *intr, sc_socket socket, uint32_t addr,
|
|||
|
||||
bool ret = net_listen(socket, addr, port, backlog);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,12 @@ sc_socket
|
|||
net_accept_intr(struct sc_intr *intr, sc_socket server_socket) {
|
||||
if (!sc_intr_set_socket(intr, server_socket)) {
|
||||
// Already interrupted
|
||||
return SC_INVALID_SOCKET;
|
||||
return SC_SOCKET_NONE;
|
||||
}
|
||||
|
||||
sc_socket socket = net_accept(server_socket);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
return socket;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ net_recv_intr(struct sc_intr *intr, sc_socket socket, void *buf, size_t len) {
|
|||
|
||||
ssize_t r = net_recv(socket, buf, len);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ net_recv_all_intr(struct sc_intr *intr, sc_socket socket, void *buf,
|
|||
|
||||
ssize_t r = net_recv_all(socket, buf, len);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ net_send_intr(struct sc_intr *intr, sc_socket socket, const void *buf,
|
|||
|
||||
ssize_t w = net_send(socket, buf, len);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
return w;
|
||||
}
|
||||
|
||||
|
@ -92,6 +92,6 @@ net_send_all_intr(struct sc_intr *intr, sc_socket socket, const void *buf,
|
|||
|
||||
ssize_t w = net_send_all(socket, buf, len);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
return w;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "str_util.h"
|
||||
#include "str.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
@ -13,7 +13,7 @@
|
|||
#endif
|
||||
|
||||
size_t
|
||||
xstrncpy(char *dest, const char *src, size_t n) {
|
||||
sc_strncpy(char *dest, const char *src, size_t n) {
|
||||
size_t i;
|
||||
for (i = 0; i < n - 1 && src[i] != '\0'; ++i)
|
||||
dest[i] = src[i];
|
||||
|
@ -23,7 +23,7 @@ xstrncpy(char *dest, const char *src, size_t n) {
|
|||
}
|
||||
|
||||
size_t
|
||||
xstrjoin(char *dst, const char *const tokens[], char sep, size_t n) {
|
||||
sc_str_join(char *dst, const char *const tokens[], char sep, size_t n) {
|
||||
const char *const *remaining = tokens;
|
||||
const char *token = *remaining++;
|
||||
size_t i = 0;
|
||||
|
@ -33,7 +33,7 @@ xstrjoin(char *dst, const char *const tokens[], char sep, size_t n) {
|
|||
if (i == n)
|
||||
goto truncated;
|
||||
}
|
||||
size_t w = xstrncpy(dst + i, token, n - i);
|
||||
size_t w = sc_strncpy(dst + i, token, n - i);
|
||||
if (w >= n - i)
|
||||
goto truncated;
|
||||
i += w;
|
||||
|
@ -47,7 +47,7 @@ truncated:
|
|||
}
|
||||
|
||||
char *
|
||||
strquote(const char *src) {
|
||||
sc_str_quote(const char *src) {
|
||||
size_t len = strlen(src);
|
||||
char *quoted = malloc(len + 3);
|
||||
if (!quoted) {
|
||||
|
@ -61,7 +61,7 @@ strquote(const char *src) {
|
|||
}
|
||||
|
||||
bool
|
||||
parse_integer(const char *s, long *out) {
|
||||
sc_str_parse_integer(const char *s, long *out) {
|
||||
char *endptr;
|
||||
if (*s == '\0') {
|
||||
return false;
|
||||
|
@ -80,7 +80,8 @@ parse_integer(const char *s, long *out) {
|
|||
}
|
||||
|
||||
size_t
|
||||
parse_integers(const char *s, const char sep, size_t max_items, long *out) {
|
||||
sc_str_parse_integers(const char *s, const char sep, size_t max_items,
|
||||
long *out) {
|
||||
size_t count = 0;
|
||||
char *endptr;
|
||||
do {
|
||||
|
@ -109,7 +110,7 @@ parse_integers(const char *s, const char sep, size_t max_items, long *out) {
|
|||
}
|
||||
|
||||
bool
|
||||
parse_integer_with_suffix(const char *s, long *out) {
|
||||
sc_str_parse_integer_with_suffix(const char *s, long *out) {
|
||||
char *endptr;
|
||||
if (*s == '\0') {
|
||||
return false;
|
||||
|
@ -143,7 +144,7 @@ parse_integer_with_suffix(const char *s, long *out) {
|
|||
}
|
||||
|
||||
bool
|
||||
strlist_contains(const char *list, char sep, const char *s) {
|
||||
sc_str_list_contains(const char *list, char sep, const char *s) {
|
||||
char *p;
|
||||
do {
|
||||
p = strchr(list, sep);
|
||||
|
@ -161,7 +162,7 @@ strlist_contains(const char *list, char sep, const char *s) {
|
|||
}
|
||||
|
||||
size_t
|
||||
utf8_truncation_index(const char *utf8, size_t max_len) {
|
||||
sc_str_utf8_truncation_index(const char *utf8, size_t max_len) {
|
||||
size_t len = strlen(utf8);
|
||||
if (len <= max_len) {
|
||||
return len;
|
||||
|
@ -179,7 +180,7 @@ utf8_truncation_index(const char *utf8, size_t max_len) {
|
|||
#ifdef _WIN32
|
||||
|
||||
wchar_t *
|
||||
utf8_to_wide_char(const char *utf8) {
|
||||
sc_str_to_wchars(const char *utf8) {
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
|
||||
if (!len) {
|
||||
return NULL;
|
||||
|
@ -195,7 +196,7 @@ utf8_to_wide_char(const char *utf8) {
|
|||
}
|
||||
|
||||
char *
|
||||
utf8_from_wide_char(const wchar_t *ws) {
|
||||
sc_str_from_wchars(const wchar_t *ws) {
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, ws, -1, NULL, 0, NULL, NULL);
|
||||
if (!len) {
|
||||
return NULL;
|
||||
|
@ -212,7 +213,8 @@ utf8_from_wide_char(const wchar_t *ws) {
|
|||
|
||||
#endif
|
||||
|
||||
char *sc_str_wrap_lines(const char *input, unsigned columns, unsigned indent) {
|
||||
char *
|
||||
sc_str_wrap_lines(const char *input, unsigned columns, unsigned indent) {
|
||||
assert(indent < columns);
|
||||
|
||||
struct sc_strbuf buf;
|
106
app/src/util/str.h
Normal file
106
app/src/util/str.h
Normal file
|
@ -0,0 +1,106 @@
|
|||
#ifndef SC_STR_H
|
||||
#define SC_STR_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* Like strncpy(), except:
|
||||
* - it copies at most n-1 chars
|
||||
* - the dest string is nul-terminated
|
||||
* - it does not write useless bytes if strlen(src) < n
|
||||
* - it returns the number of chars actually written (max n-1) if src has
|
||||
* been copied completely, or n if src has been truncated
|
||||
*/
|
||||
size_t
|
||||
sc_strncpy(char *dest, const char *src, size_t n);
|
||||
|
||||
/**
|
||||
* Join tokens by separator `sep` into `dst`
|
||||
*
|
||||
* Return the number of chars actually written (max n-1) if no truncation
|
||||
* occurred, or n if truncated.
|
||||
*/
|
||||
size_t
|
||||
sc_str_join(char *dst, const char *const tokens[], char sep, size_t n);
|
||||
|
||||
/**
|
||||
* Quote a string
|
||||
*
|
||||
* Return a new allocated string, surrounded with quotes (`"`).
|
||||
*/
|
||||
char *
|
||||
sc_str_quote(const char *src);
|
||||
|
||||
/**
|
||||
* Parse `s` as an integer into `out`
|
||||
*
|
||||
* Return true if the conversion succeeded, false otherwise.
|
||||
*/
|
||||
bool
|
||||
sc_str_parse_integer(const char *s, long *out);
|
||||
|
||||
/**
|
||||
* Parse `s` as integers separated by `sep` (for example `1234:2000`) into `out`
|
||||
*
|
||||
* Returns the number of integers on success, 0 on failure.
|
||||
*/
|
||||
size_t
|
||||
sc_str_parse_integers(const char *s, const char sep, size_t max_items,
|
||||
long *out);
|
||||
|
||||
/**
|
||||
* Parse `s` as an integer into `out`
|
||||
*
|
||||
* Like `sc_str_parse_integer()`, but accept 'k'/'K' (x1000) and 'm'/'M'
|
||||
* (x1000000) as suffixes.
|
||||
*
|
||||
* Return true if the conversion succeeded, false otherwise.
|
||||
*/
|
||||
bool
|
||||
sc_str_parse_integer_with_suffix(const char *s, long *out);
|
||||
|
||||
/**
|
||||
* Search `s` in the list separated by `sep`
|
||||
*
|
||||
* For example, sc_str_list_contains("a,bc,def", ',', "bc") returns true.
|
||||
*/
|
||||
bool
|
||||
sc_str_list_contains(const char *list, char sep, const char *s);
|
||||
|
||||
/**
|
||||
* Return the index to truncate a UTF-8 string at a valid position
|
||||
*/
|
||||
size_t
|
||||
sc_str_utf8_truncation_index(const char *utf8, size_t max_len);
|
||||
|
||||
#ifdef _WIN32
|
||||
/**
|
||||
* Convert a UTF-8 string to a wchar_t string
|
||||
*
|
||||
* Return the new allocated string, to be freed by the caller.
|
||||
*/
|
||||
wchar_t *
|
||||
sc_str_to_wchars(const char *utf8);
|
||||
|
||||
/**
|
||||
* Convert a wchar_t string to a UTF-8 string
|
||||
*
|
||||
* Return the new allocated string, to be freed by the caller.
|
||||
*/
|
||||
char *
|
||||
sc_str_from_wchars(const wchar_t *s);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Wrap input lines to fit in `columns` columns
|
||||
*
|
||||
* Break input lines at word boundaries (spaces) so that they fit in `columns`
|
||||
* columns, left-indented by `indent` spaces.
|
||||
*/
|
||||
char *
|
||||
sc_str_wrap_lines(const char *input, unsigned columns, unsigned indent);
|
||||
|
||||
#endif
|
|
@ -1,73 +0,0 @@
|
|||
#ifndef STRUTIL_H
|
||||
#define STRUTIL_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// like strncpy, except:
|
||||
// - it copies at most n-1 chars
|
||||
// - the dest string is nul-terminated
|
||||
// - it does not write useless bytes if strlen(src) < n
|
||||
// - it returns the number of chars actually written (max n-1) if src has
|
||||
// been copied completely, or n if src has been truncated
|
||||
size_t
|
||||
xstrncpy(char *dest, const char *src, size_t n);
|
||||
|
||||
// join tokens by sep into dst
|
||||
// returns the number of chars actually written (max n-1) if no truncation
|
||||
// occurred, or n if truncated
|
||||
size_t
|
||||
xstrjoin(char *dst, const char *const tokens[], char sep, size_t n);
|
||||
|
||||
// quote a string
|
||||
// returns the new allocated string, to be freed by the caller
|
||||
char *
|
||||
strquote(const char *src);
|
||||
|
||||
// parse s as an integer into value
|
||||
// returns true if the conversion succeeded, false otherwise
|
||||
bool
|
||||
parse_integer(const char *s, long *out);
|
||||
|
||||
// parse s as integers separated by sep (for example '1234:2000')
|
||||
// returns the number of integers on success, 0 on failure
|
||||
size_t
|
||||
parse_integers(const char *s, const char sep, size_t max_items, long *out);
|
||||
|
||||
// parse s as an integer into value
|
||||
// like parse_integer(), but accept 'k'/'K' (x1000) and 'm'/'M' (x1000000) as
|
||||
// suffix
|
||||
// returns true if the conversion succeeded, false otherwise
|
||||
bool
|
||||
parse_integer_with_suffix(const char *s, long *out);
|
||||
|
||||
// search s in the list separated by sep
|
||||
// for example, strlist_contains("a,bc,def", ',', "bc") returns true
|
||||
bool
|
||||
strlist_contains(const char *list, char sep, const char *s);
|
||||
|
||||
// return the index to truncate a UTF-8 string at a valid position
|
||||
size_t
|
||||
utf8_truncation_index(const char *utf8, size_t max_len);
|
||||
|
||||
#ifdef _WIN32
|
||||
// convert a UTF-8 string to a wchar_t string
|
||||
// returns the new allocated string, to be freed by the caller
|
||||
wchar_t *
|
||||
utf8_to_wide_char(const char *utf8);
|
||||
|
||||
char *
|
||||
utf8_from_wide_char(const wchar_t *s);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Wrap input lines to fit in `columns` columns
|
||||
*
|
||||
* Break input lines at word boundaries (spaces) so that they fit in `columns`
|
||||
* columns, left-indented by `indent` spaces.
|
||||
*/
|
||||
char *sc_str_wrap_lines(const char *input, unsigned columns, unsigned indent);
|
||||
|
||||
#endif
|
|
@ -1,7 +1,7 @@
|
|||
#include "v4l2_sink.h"
|
||||
|
||||
#include "util/log.h"
|
||||
#include "util/str_util.h"
|
||||
#include "util/str.h"
|
||||
|
||||
/** Downcast frame_sink to sc_v4l2_sink */
|
||||
#define DOWNCAST(SINK) container_of(SINK, struct sc_v4l2_sink, frame_sink)
|
||||
|
@ -21,7 +21,7 @@ find_muxer(const char *name) {
|
|||
oformat = av_oformat_next(oformat);
|
||||
#endif
|
||||
// until null or containing the requested name
|
||||
} while (oformat && !strlist_contains(oformat->name, ',', name));
|
||||
} while (oformat && !sc_str_list_contains(oformat->name, ',', name));
|
||||
return oformat;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util/str_util.h"
|
||||
#include "util/str.h"
|
||||
|
||||
static void test_xstrncpy_simple(void) {
|
||||
static void test_strncpy_simple(void) {
|
||||
char s[] = "xxxxxxxxxx";
|
||||
size_t w = xstrncpy(s, "abcdef", sizeof(s));
|
||||
size_t w = sc_strncpy(s, "abcdef", sizeof(s));
|
||||
|
||||
// returns strlen of copied string
|
||||
assert(w == 6);
|
||||
|
@ -24,9 +24,9 @@ static void test_xstrncpy_simple(void) {
|
|||
assert(!strcmp("abcdef", s));
|
||||
}
|
||||
|
||||
static void test_xstrncpy_just_fit(void) {
|
||||
static void test_strncpy_just_fit(void) {
|
||||
char s[] = "xxxxxx";
|
||||
size_t w = xstrncpy(s, "abcdef", sizeof(s));
|
||||
size_t w = sc_strncpy(s, "abcdef", sizeof(s));
|
||||
|
||||
// returns strlen of copied string
|
||||
assert(w == 6);
|
||||
|
@ -38,9 +38,9 @@ static void test_xstrncpy_just_fit(void) {
|
|||
assert(!strcmp("abcdef", s));
|
||||
}
|
||||
|
||||
static void test_xstrncpy_truncated(void) {
|
||||
static void test_strncpy_truncated(void) {
|
||||
char s[] = "xxx";
|
||||
size_t w = xstrncpy(s, "abcdef", sizeof(s));
|
||||
size_t w = sc_strncpy(s, "abcdef", sizeof(s));
|
||||
|
||||
// returns 'n' (sizeof(s))
|
||||
assert(w == 4);
|
||||
|
@ -52,10 +52,10 @@ static void test_xstrncpy_truncated(void) {
|
|||
assert(!strncmp("abcdef", s, 3));
|
||||
}
|
||||
|
||||
static void test_xstrjoin_simple(void) {
|
||||
static void test_join_simple(void) {
|
||||
const char *const tokens[] = { "abc", "de", "fghi", NULL };
|
||||
char s[] = "xxxxxxxxxxxxxx";
|
||||
size_t w = xstrjoin(s, tokens, ' ', sizeof(s));
|
||||
size_t w = sc_str_join(s, tokens, ' ', sizeof(s));
|
||||
|
||||
// returns strlen of concatenation
|
||||
assert(w == 11);
|
||||
|
@ -70,10 +70,10 @@ static void test_xstrjoin_simple(void) {
|
|||
assert(!strcmp("abc de fghi", s));
|
||||
}
|
||||
|
||||
static void test_xstrjoin_just_fit(void) {
|
||||
static void test_join_just_fit(void) {
|
||||
const char *const tokens[] = { "abc", "de", "fghi", NULL };
|
||||
char s[] = "xxxxxxxxxxx";
|
||||
size_t w = xstrjoin(s, tokens, ' ', sizeof(s));
|
||||
size_t w = sc_str_join(s, tokens, ' ', sizeof(s));
|
||||
|
||||
// returns strlen of concatenation
|
||||
assert(w == 11);
|
||||
|
@ -85,10 +85,10 @@ static void test_xstrjoin_just_fit(void) {
|
|||
assert(!strcmp("abc de fghi", s));
|
||||
}
|
||||
|
||||
static void test_xstrjoin_truncated_in_token(void) {
|
||||
static void test_join_truncated_in_token(void) {
|
||||
const char *const tokens[] = { "abc", "de", "fghi", NULL };
|
||||
char s[] = "xxxxx";
|
||||
size_t w = xstrjoin(s, tokens, ' ', sizeof(s));
|
||||
size_t w = sc_str_join(s, tokens, ' ', sizeof(s));
|
||||
|
||||
// returns 'n' (sizeof(s))
|
||||
assert(w == 6);
|
||||
|
@ -100,10 +100,10 @@ static void test_xstrjoin_truncated_in_token(void) {
|
|||
assert(!strcmp("abc d", s));
|
||||
}
|
||||
|
||||
static void test_xstrjoin_truncated_before_sep(void) {
|
||||
static void test_join_truncated_before_sep(void) {
|
||||
const char *const tokens[] = { "abc", "de", "fghi", NULL };
|
||||
char s[] = "xxxxxx";
|
||||
size_t w = xstrjoin(s, tokens, ' ', sizeof(s));
|
||||
size_t w = sc_str_join(s, tokens, ' ', sizeof(s));
|
||||
|
||||
// returns 'n' (sizeof(s))
|
||||
assert(w == 7);
|
||||
|
@ -115,10 +115,10 @@ static void test_xstrjoin_truncated_before_sep(void) {
|
|||
assert(!strcmp("abc de", s));
|
||||
}
|
||||
|
||||
static void test_xstrjoin_truncated_after_sep(void) {
|
||||
static void test_join_truncated_after_sep(void) {
|
||||
const char *const tokens[] = { "abc", "de", "fghi", NULL };
|
||||
char s[] = "xxxxxxx";
|
||||
size_t w = xstrjoin(s, tokens, ' ', sizeof(s));
|
||||
size_t w = sc_str_join(s, tokens, ' ', sizeof(s));
|
||||
|
||||
// returns 'n' (sizeof(s))
|
||||
assert(w == 8);
|
||||
|
@ -130,9 +130,9 @@ static void test_xstrjoin_truncated_after_sep(void) {
|
|||
assert(!strcmp("abc de ", s));
|
||||
}
|
||||
|
||||
static void test_strquote(void) {
|
||||
static void test_quote(void) {
|
||||
const char *s = "abcde";
|
||||
char *out = strquote(s);
|
||||
char *out = sc_str_quote(s);
|
||||
|
||||
// add '"' at the beginning and the end
|
||||
assert(!strcmp("\"abcde\"", out));
|
||||
|
@ -146,71 +146,71 @@ static void test_utf8_truncate(void) {
|
|||
|
||||
size_t count;
|
||||
|
||||
count = utf8_truncation_index(s, 1);
|
||||
count = sc_str_utf8_truncation_index(s, 1);
|
||||
assert(count == 1);
|
||||
|
||||
count = utf8_truncation_index(s, 2);
|
||||
count = sc_str_utf8_truncation_index(s, 2);
|
||||
assert(count == 1); // É is 2 bytes-wide
|
||||
|
||||
count = utf8_truncation_index(s, 3);
|
||||
count = sc_str_utf8_truncation_index(s, 3);
|
||||
assert(count == 3);
|
||||
|
||||
count = utf8_truncation_index(s, 4);
|
||||
count = sc_str_utf8_truncation_index(s, 4);
|
||||
assert(count == 4);
|
||||
|
||||
count = utf8_truncation_index(s, 5);
|
||||
count = sc_str_utf8_truncation_index(s, 5);
|
||||
assert(count == 4); // Ô is 2 bytes-wide
|
||||
|
||||
count = utf8_truncation_index(s, 6);
|
||||
count = sc_str_utf8_truncation_index(s, 6);
|
||||
assert(count == 6);
|
||||
|
||||
count = utf8_truncation_index(s, 7);
|
||||
count = sc_str_utf8_truncation_index(s, 7);
|
||||
assert(count == 7);
|
||||
|
||||
count = utf8_truncation_index(s, 8);
|
||||
count = sc_str_utf8_truncation_index(s, 8);
|
||||
assert(count == 7); // no more chars
|
||||
}
|
||||
|
||||
static void test_parse_integer(void) {
|
||||
long value;
|
||||
bool ok = parse_integer("1234", &value);
|
||||
bool ok = sc_str_parse_integer("1234", &value);
|
||||
assert(ok);
|
||||
assert(value == 1234);
|
||||
|
||||
ok = parse_integer("-1234", &value);
|
||||
ok = sc_str_parse_integer("-1234", &value);
|
||||
assert(ok);
|
||||
assert(value == -1234);
|
||||
|
||||
ok = parse_integer("1234k", &value);
|
||||
ok = sc_str_parse_integer("1234k", &value);
|
||||
assert(!ok);
|
||||
|
||||
ok = parse_integer("123456789876543212345678987654321", &value);
|
||||
ok = sc_str_parse_integer("123456789876543212345678987654321", &value);
|
||||
assert(!ok); // out-of-range
|
||||
}
|
||||
|
||||
static void test_parse_integers(void) {
|
||||
long values[5];
|
||||
|
||||
size_t count = parse_integers("1234", ':', 5, values);
|
||||
size_t count = sc_str_parse_integers("1234", ':', 5, values);
|
||||
assert(count == 1);
|
||||
assert(values[0] == 1234);
|
||||
|
||||
count = parse_integers("1234:5678", ':', 5, values);
|
||||
count = sc_str_parse_integers("1234:5678", ':', 5, values);
|
||||
assert(count == 2);
|
||||
assert(values[0] == 1234);
|
||||
assert(values[1] == 5678);
|
||||
|
||||
count = parse_integers("1234:5678", ':', 2, values);
|
||||
count = sc_str_parse_integers("1234:5678", ':', 2, values);
|
||||
assert(count == 2);
|
||||
assert(values[0] == 1234);
|
||||
assert(values[1] == 5678);
|
||||
|
||||
count = parse_integers("1234:-5678", ':', 2, values);
|
||||
count = sc_str_parse_integers("1234:-5678", ':', 2, values);
|
||||
assert(count == 2);
|
||||
assert(values[0] == 1234);
|
||||
assert(values[1] == -5678);
|
||||
|
||||
count = parse_integers("1:2:3:4:5", ':', 5, values);
|
||||
count = sc_str_parse_integers("1:2:3:4:5", ':', 5, values);
|
||||
assert(count == 5);
|
||||
assert(values[0] == 1);
|
||||
assert(values[1] == 2);
|
||||
|
@ -218,85 +218,85 @@ static void test_parse_integers(void) {
|
|||
assert(values[3] == 4);
|
||||
assert(values[4] == 5);
|
||||
|
||||
count = parse_integers("1234:5678", ':', 1, values);
|
||||
count = sc_str_parse_integers("1234:5678", ':', 1, values);
|
||||
assert(count == 0); // max_items == 1
|
||||
|
||||
count = parse_integers("1:2:3:4:5", ':', 3, values);
|
||||
count = sc_str_parse_integers("1:2:3:4:5", ':', 3, values);
|
||||
assert(count == 0); // max_items == 3
|
||||
|
||||
count = parse_integers(":1234", ':', 5, values);
|
||||
count = sc_str_parse_integers(":1234", ':', 5, values);
|
||||
assert(count == 0); // invalid
|
||||
|
||||
count = parse_integers("1234:", ':', 5, values);
|
||||
count = sc_str_parse_integers("1234:", ':', 5, values);
|
||||
assert(count == 0); // invalid
|
||||
|
||||
count = parse_integers("1234:", ':', 1, values);
|
||||
count = sc_str_parse_integers("1234:", ':', 1, values);
|
||||
assert(count == 0); // invalid, even when max_items == 1
|
||||
|
||||
count = parse_integers("1234::5678", ':', 5, values);
|
||||
count = sc_str_parse_integers("1234::5678", ':', 5, values);
|
||||
assert(count == 0); // invalid
|
||||
}
|
||||
|
||||
static void test_parse_integer_with_suffix(void) {
|
||||
long value;
|
||||
bool ok = parse_integer_with_suffix("1234", &value);
|
||||
bool ok = sc_str_parse_integer_with_suffix("1234", &value);
|
||||
assert(ok);
|
||||
assert(value == 1234);
|
||||
|
||||
ok = parse_integer_with_suffix("-1234", &value);
|
||||
ok = sc_str_parse_integer_with_suffix("-1234", &value);
|
||||
assert(ok);
|
||||
assert(value == -1234);
|
||||
|
||||
ok = parse_integer_with_suffix("1234k", &value);
|
||||
ok = sc_str_parse_integer_with_suffix("1234k", &value);
|
||||
assert(ok);
|
||||
assert(value == 1234000);
|
||||
|
||||
ok = parse_integer_with_suffix("1234m", &value);
|
||||
ok = sc_str_parse_integer_with_suffix("1234m", &value);
|
||||
assert(ok);
|
||||
assert(value == 1234000000);
|
||||
|
||||
ok = parse_integer_with_suffix("-1234k", &value);
|
||||
ok = sc_str_parse_integer_with_suffix("-1234k", &value);
|
||||
assert(ok);
|
||||
assert(value == -1234000);
|
||||
|
||||
ok = parse_integer_with_suffix("-1234m", &value);
|
||||
ok = sc_str_parse_integer_with_suffix("-1234m", &value);
|
||||
assert(ok);
|
||||
assert(value == -1234000000);
|
||||
|
||||
ok = parse_integer_with_suffix("123456789876543212345678987654321", &value);
|
||||
ok = sc_str_parse_integer_with_suffix("123456789876543212345678987654321", &value);
|
||||
assert(!ok); // out-of-range
|
||||
|
||||
char buf[32];
|
||||
|
||||
sprintf(buf, "%ldk", LONG_MAX / 2000);
|
||||
ok = parse_integer_with_suffix(buf, &value);
|
||||
ok = sc_str_parse_integer_with_suffix(buf, &value);
|
||||
assert(ok);
|
||||
assert(value == LONG_MAX / 2000 * 1000);
|
||||
|
||||
sprintf(buf, "%ldm", LONG_MAX / 2000);
|
||||
ok = parse_integer_with_suffix(buf, &value);
|
||||
ok = sc_str_parse_integer_with_suffix(buf, &value);
|
||||
assert(!ok);
|
||||
|
||||
sprintf(buf, "%ldk", LONG_MIN / 2000);
|
||||
ok = parse_integer_with_suffix(buf, &value);
|
||||
ok = sc_str_parse_integer_with_suffix(buf, &value);
|
||||
assert(ok);
|
||||
assert(value == LONG_MIN / 2000 * 1000);
|
||||
|
||||
sprintf(buf, "%ldm", LONG_MIN / 2000);
|
||||
ok = parse_integer_with_suffix(buf, &value);
|
||||
ok = sc_str_parse_integer_with_suffix(buf, &value);
|
||||
assert(!ok);
|
||||
}
|
||||
|
||||
static void test_strlist_contains(void) {
|
||||
assert(strlist_contains("a,bc,def", ',', "bc"));
|
||||
assert(!strlist_contains("a,bc,def", ',', "b"));
|
||||
assert(strlist_contains("", ',', ""));
|
||||
assert(strlist_contains("abc,", ',', ""));
|
||||
assert(strlist_contains(",abc", ',', ""));
|
||||
assert(strlist_contains("abc,,def", ',', ""));
|
||||
assert(!strlist_contains("abc", ',', ""));
|
||||
assert(strlist_contains(",,|x", '|', ",,"));
|
||||
assert(strlist_contains("xyz", '\0', "xyz"));
|
||||
assert(sc_str_list_contains("a,bc,def", ',', "bc"));
|
||||
assert(!sc_str_list_contains("a,bc,def", ',', "b"));
|
||||
assert(sc_str_list_contains("", ',', ""));
|
||||
assert(sc_str_list_contains("abc,", ',', ""));
|
||||
assert(sc_str_list_contains(",abc", ',', ""));
|
||||
assert(sc_str_list_contains("abc,,def", ',', ""));
|
||||
assert(!sc_str_list_contains("abc", ',', ""));
|
||||
assert(sc_str_list_contains(",,|x", '|', ",,"));
|
||||
assert(sc_str_list_contains("xyz", '\0', "xyz"));
|
||||
}
|
||||
|
||||
static void test_wrap_lines(void) {
|
||||
|
@ -341,15 +341,15 @@ int main(int argc, char *argv[]) {
|
|||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
test_xstrncpy_simple();
|
||||
test_xstrncpy_just_fit();
|
||||
test_xstrncpy_truncated();
|
||||
test_xstrjoin_simple();
|
||||
test_xstrjoin_just_fit();
|
||||
test_xstrjoin_truncated_in_token();
|
||||
test_xstrjoin_truncated_before_sep();
|
||||
test_xstrjoin_truncated_after_sep();
|
||||
test_strquote();
|
||||
test_strncpy_simple();
|
||||
test_strncpy_just_fit();
|
||||
test_strncpy_truncated();
|
||||
test_join_simple();
|
||||
test_join_just_fit();
|
||||
test_join_truncated_in_token();
|
||||
test_join_truncated_before_sep();
|
||||
test_join_truncated_after_sep();
|
||||
test_quote();
|
||||
test_utf8_truncate();
|
||||
test_parse_integer();
|
||||
test_parse_integers();
|
|
@ -2,8 +2,8 @@
|
|||
set -e
|
||||
|
||||
BUILDDIR=build-auto
|
||||
PREBUILT_SERVER_URL=https://github.com/Genymobile/scrcpy/releases/download/v1.19/scrcpy-server-v1.19
|
||||
PREBUILT_SERVER_SHA256=876f9322182e6aac6a58db1334f4225855ef3a17eaebc80aab6601d9d1ecb867
|
||||
PREBUILT_SERVER_URL=https://github.com/Genymobile/scrcpy/releases/download/v1.20/scrcpy-server-v1.20
|
||||
PREBUILT_SERVER_SHA256=b20aee4951f99b060c4a44000ba94de973f9604758ef62beb253b371aad3df34
|
||||
|
||||
echo "[scrcpy] Downloading prebuilt server..."
|
||||
wget "$PREBUILT_SERVER_URL" -O scrcpy-server
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
project('scrcpy', 'c',
|
||||
version: '1.19',
|
||||
version: '1.20',
|
||||
meson_version: '>= 0.48',
|
||||
default_options: [
|
||||
'c_std=c11',
|
||||
|
|
|
@ -6,8 +6,8 @@ android {
|
|||
applicationId "com.genymobile.scrcpy"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 31
|
||||
versionCode 11900
|
||||
versionName "1.19"
|
||||
versionCode 12000
|
||||
versionName "1.20"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
|
|
@ -12,15 +12,17 @@
|
|||
set -e
|
||||
|
||||
SCRCPY_DEBUG=false
|
||||
SCRCPY_VERSION_NAME=1.19
|
||||
SCRCPY_VERSION_NAME=1.20
|
||||
|
||||
PLATFORM=${ANDROID_PLATFORM:-30}
|
||||
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-30.0.0}
|
||||
PLATFORM_VERSION=31
|
||||
PLATFORM=${ANDROID_PLATFORM:-$PLATFORM_VERSION}
|
||||
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-31.0.0}
|
||||
|
||||
BUILD_DIR="$(realpath ${BUILD_DIR:-build_manual})"
|
||||
CLASSES_DIR="$BUILD_DIR/classes"
|
||||
SERVER_DIR=$(dirname "$0")
|
||||
SERVER_BINARY=scrcpy-server
|
||||
ANDROID_JAR="$ANDROID_HOME/platforms/android-$PLATFORM/android.jar"
|
||||
|
||||
echo "Platform: android-$PLATFORM"
|
||||
echo "Build-tools: $BUILD_TOOLS"
|
||||
|
@ -47,23 +49,40 @@ cd "$SERVER_DIR/src/main/aidl"
|
|||
|
||||
echo "Compiling java sources..."
|
||||
cd ../java
|
||||
javac -bootclasspath "$ANDROID_HOME/platforms/android-$PLATFORM/android.jar" \
|
||||
-cp "$CLASSES_DIR" -d "$CLASSES_DIR" -source 1.8 -target 1.8 \
|
||||
javac -bootclasspath "$ANDROID_JAR" -cp "$CLASSES_DIR" -d "$CLASSES_DIR" \
|
||||
-source 1.8 -target 1.8 \
|
||||
com/genymobile/scrcpy/*.java \
|
||||
com/genymobile/scrcpy/wrappers/*.java
|
||||
|
||||
echo "Dexing..."
|
||||
cd "$CLASSES_DIR"
|
||||
"$ANDROID_HOME/build-tools/$BUILD_TOOLS/dx" --dex \
|
||||
--output "$BUILD_DIR/classes.dex" \
|
||||
android/view/*.class \
|
||||
android/content/*.class \
|
||||
com/genymobile/scrcpy/*.class \
|
||||
com/genymobile/scrcpy/wrappers/*.class
|
||||
|
||||
echo "Archiving..."
|
||||
cd "$BUILD_DIR"
|
||||
jar cvf "$SERVER_BINARY" classes.dex
|
||||
rm -rf classes.dex classes
|
||||
if [[ $PLATFORM_VERSION -lt 31 ]]
|
||||
then
|
||||
# use dx
|
||||
"$ANDROID_HOME/build-tools/$BUILD_TOOLS/dx" --dex \
|
||||
--output "$BUILD_DIR/classes.dex" \
|
||||
android/view/*.class \
|
||||
android/content/*.class \
|
||||
com/genymobile/scrcpy/*.class \
|
||||
com/genymobile/scrcpy/wrappers/*.class
|
||||
|
||||
echo "Archiving..."
|
||||
cd "$BUILD_DIR"
|
||||
jar cvf "$SERVER_BINARY" classes.dex
|
||||
rm -rf classes.dex classes
|
||||
else
|
||||
# use d8
|
||||
"$ANDROID_HOME/build-tools/$BUILD_TOOLS/d8" --classpath "$ANDROID_JAR" \
|
||||
--output "$BUILD_DIR/classes.zip" \
|
||||
android/view/*.class \
|
||||
android/content/*.class \
|
||||
com/genymobile/scrcpy/*.class \
|
||||
com/genymobile/scrcpy/wrappers/*.class
|
||||
|
||||
cd "$BUILD_DIR"
|
||||
mv classes.zip "$SERVER_BINARY"
|
||||
rm -rf classes
|
||||
fi
|
||||
|
||||
echo "Server generated in $BUILD_DIR/$SERVER_BINARY"
|
||||
|
|
Loading…
Reference in a new issue