Compare commits
6 Commits
hid.13
...
input_trai
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10b0ba413e | ||
|
|
e94649c5b5 | ||
|
|
9a0224a3f0 | ||
|
|
8df42cec82 | ||
|
|
31131039bb | ||
|
|
fa100b814b |
15
BUILD.md
15
BUILD.md
@@ -88,12 +88,11 @@ Install the required packages from your package manager.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# runtime dependencies
|
# runtime dependencies
|
||||||
sudo apt install ffmpeg libsdl2-2.0-0 adb libusb-1.0-0
|
sudo apt install ffmpeg libsdl2-2.0-0 adb
|
||||||
|
|
||||||
# client build dependencies
|
# client build dependencies
|
||||||
sudo apt install gcc git pkg-config meson ninja-build libsdl2-dev \
|
sudo apt install gcc git pkg-config meson ninja-build libsdl2-dev \
|
||||||
libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev\
|
libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev
|
||||||
libusb-dev
|
|
||||||
|
|
||||||
# server build dependencies
|
# server build dependencies
|
||||||
sudo apt install openjdk-11-jdk
|
sudo apt install openjdk-11-jdk
|
||||||
@@ -115,7 +114,7 @@ pip3 install meson
|
|||||||
sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
|
sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
|
||||||
|
|
||||||
# client build dependencies
|
# client build dependencies
|
||||||
sudo dnf install SDL2-devel ffms2-devel libusb-devel meson gcc make
|
sudo dnf install SDL2-devel ffms2-devel meson gcc make
|
||||||
|
|
||||||
# server build dependencies
|
# server build dependencies
|
||||||
sudo dnf install java-devel
|
sudo dnf install java-devel
|
||||||
@@ -160,8 +159,7 @@ install the required packages:
|
|||||||
```bash
|
```bash
|
||||||
# runtime dependencies
|
# runtime dependencies
|
||||||
pacman -S mingw-w64-x86_64-SDL2 \
|
pacman -S mingw-w64-x86_64-SDL2 \
|
||||||
mingw-w64-x86_64-ffmpeg \
|
mingw-w64-x86_64-ffmpeg
|
||||||
mingw-w64-x86_64-libusb
|
|
||||||
|
|
||||||
# client build dependencies
|
# client build dependencies
|
||||||
pacman -S mingw-w64-x86_64-make \
|
pacman -S mingw-w64-x86_64-make \
|
||||||
@@ -175,8 +173,7 @@ For a 32 bits version, replace `x86_64` by `i686`:
|
|||||||
```bash
|
```bash
|
||||||
# runtime dependencies
|
# runtime dependencies
|
||||||
pacman -S mingw-w64-i686-SDL2 \
|
pacman -S mingw-w64-i686-SDL2 \
|
||||||
mingw-w64-i686-ffmpeg \
|
mingw-w64-i686-ffmpeg
|
||||||
mingw-w64-i686-libusb
|
|
||||||
|
|
||||||
# client build dependencies
|
# client build dependencies
|
||||||
pacman -S mingw-w64-i686-make \
|
pacman -S mingw-w64-i686-make \
|
||||||
@@ -200,7 +197,7 @@ Install the packages with [Homebrew]:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# runtime dependencies
|
# runtime dependencies
|
||||||
brew install sdl2 ffmpeg libusb
|
brew install sdl2 ffmpeg
|
||||||
|
|
||||||
# client build dependencies
|
# client build dependencies
|
||||||
brew install pkg-config meson
|
brew install pkg-config meson
|
||||||
|
|||||||
18
FAQ.it.md
18
FAQ.it.md
@@ -140,24 +140,6 @@ Potresti anche dover configurare il [comportamento di ridimensionamento][scaling
|
|||||||
[scaling behavior]: https://github.com/Genymobile/scrcpy/issues/40#issuecomment-424466723
|
[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
|
### Crash del compositore KWin
|
||||||
|
|
||||||
|
|||||||
2
FAQ.md
2
FAQ.md
@@ -258,6 +258,6 @@ to add some arguments.
|
|||||||
|
|
||||||
This FAQ is available in other languages:
|
This FAQ is available in other languages:
|
||||||
|
|
||||||
- [Italiano (Italiano, `it`) - v1.19](FAQ.it.md)
|
- [Italiano (Italiano, `it`) - v1.17](FAQ.it.md)
|
||||||
- [한국어 (Korean, `ko`) - v1.11](FAQ.ko.md)
|
- [한국어 (Korean, `ko`) - v1.11](FAQ.ko.md)
|
||||||
- [简体中文 (Simplified Chinese, `zh-Hans`) - v1.18](FAQ.zh-Hans.md)
|
- [简体中文 (Simplified Chinese, `zh-Hans`) - v1.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._
|
_Apri il [README](README.md) originale e sempre aggiornato._
|
||||||
|
|
||||||
# scrcpy (v1.19)
|
# scrcpy (v1.17)
|
||||||
|
|
||||||
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_.
|
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_.
|
Funziona su _GNU/Linux_, _Windows_ e _macOS_.
|
||||||
@@ -205,11 +205,10 @@ Se anche `--max-size` è specificata, il ridimensionamento è applicato dopo il
|
|||||||
Per bloccare l'orientamento della trasmissione:
|
Per bloccare l'orientamento della trasmissione:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scrcpy --lock-video-orientation # orientamento iniziale (corrente)
|
scrcpy --lock-video-orientation 0 # orientamento naturale
|
||||||
scrcpy --lock-video-orientation=0 # orientamento naturale
|
scrcpy --lock-video-orientation 1 # 90° antiorario
|
||||||
scrcpy --lock-video-orientation=1 # 90° antiorario
|
scrcpy --lock-video-orientation 2 # 180°
|
||||||
scrcpy --lock-video-orientation=2 # 180°
|
scrcpy --lock-video-orientation 3 # 90° orario
|
||||||
scrcpy --lock-video-orientation=3 # 90° orario
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Questo influisce sull'orientamento della registrazione.
|
Questo influisce sull'orientamento della registrazione.
|
||||||
@@ -232,9 +231,7 @@ Per elencare i codificatori disponibili puoi immettere un nome di codificatore n
|
|||||||
scrcpy --encoder _
|
scrcpy --encoder _
|
||||||
```
|
```
|
||||||
|
|
||||||
### Cattura
|
### Registrazione
|
||||||
|
|
||||||
#### Registrazione
|
|
||||||
|
|
||||||
È possibile registrare lo schermo durante la trasmissione:
|
È possibile registrare lo schermo durante la trasmissione:
|
||||||
|
|
||||||
@@ -256,75 +253,6 @@ I "fotogrammi saltati" sono registrati nonostante non siano mostrati in tempo re
|
|||||||
[packet delay variation]: https://en.wikipedia.org/wiki/Packet_delay_variation
|
[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
|
### Connessione
|
||||||
|
|
||||||
#### Wireless
|
#### Wireless
|
||||||
@@ -551,6 +479,15 @@ scrcpy --turn-screen-off --stay-awake
|
|||||||
scrcpy -Sw
|
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
|
#### Mostrare i tocchi
|
||||||
|
|
||||||
@@ -670,14 +607,14 @@ Non c'è alcuna risposta visiva, un log è stampato nella console.
|
|||||||
|
|
||||||
#### Trasferimento di file verso il dispositivo
|
#### Trasferimento di file verso il dispositivo
|
||||||
|
|
||||||
Per trasferire un file in `/sdcard/Download` del dispositivo trascina e rilascia un file (non APK) nella finestra di _scrcpy_.
|
Per trasferire un file in `/sdcard/` del dispositivo trascina e rilascia un file (non APK) nella finestra di _scrcpy_.
|
||||||
|
|
||||||
Non c'è alcuna risposta visiva, un log è stampato nella console.
|
Non c'è alcuna risposta visiva, un log è stampato nella console.
|
||||||
|
|
||||||
La cartella di destinazione può essere cambiata all'avvio:
|
La cartella di destinazione può essere cambiata all'avvio:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scrcpy --push-target=/sdcard/Movies/
|
scrcpy --push-target=/sdcard/Download/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -716,10 +653,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 sinistra | <kbd>MOD</kbd>+<kbd>←</kbd> _(sinistra)_
|
||||||
| Rotazione schermo a destra | <kbd>MOD</kbd>+<kbd>→</kbd> _(destra)_
|
| Rotazione schermo a destra | <kbd>MOD</kbd>+<kbd>→</kbd> _(destra)_
|
||||||
| Ridimensiona finestra a 1:1 (pixel-perfect) | <kbd>MOD</kbd>+<kbd>g</kbd>
|
| 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 sinistro¹_
|
| Ridimensiona la finestra per rimuovere i bordi neri | <kbd>MOD</kbd>+<kbd>w</kbd> \| _Doppio click¹_
|
||||||
| Premi il tasto `HOME` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _Click centrale_
|
| 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 `BACK` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _Click destro²_
|
||||||
| Premi il tasto `APP_SWITCH` | <kbd>MOD</kbd>+<kbd>s</kbd> \| _4° click³_
|
| Premi il tasto `APP_SWITCH` | <kbd>MOD</kbd>+<kbd>s</kbd>
|
||||||
| Premi il tasto `MENU` (sblocca lo schermo) | <kbd>MOD</kbd>+<kbd>m</kbd>
|
| 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_UP` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(su)_
|
||||||
| Premi il tasto `VOLUME_DOWN` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(giù)_
|
| Premi il tasto `VOLUME_DOWN` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(giù)_
|
||||||
@@ -728,26 +665,18 @@ _<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>
|
| 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>
|
| 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>
|
| Ruota lo schermo del dispositivo | <kbd>MOD</kbd>+<kbd>r</kbd>
|
||||||
| Espandi il pannello delle notifiche | <kbd>MOD</kbd>+<kbd>n</kbd> \| _5° click³_
|
| Espandi il pannello delle notifiche | <kbd>MOD</kbd>+<kbd>n</kbd>
|
||||||
| Espandi il pannello delle impostazioni | <kbd>MOD</kbd>+<kbd>n</kbd>+<kbd>n</kbd> \| _Doppio 5° click³_
|
| Chiudi il pannello delle notifiche | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
||||||
| Chiudi pannelli | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
| Copia negli appunti³ | <kbd>MOD</kbd>+<kbd>c</kbd>
|
||||||
| Copia negli appunti⁴ | <kbd>MOD</kbd>+<kbd>c</kbd>
|
| Taglia negli appunti³ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
||||||
| Taglia negli appunti⁴ | <kbd>MOD</kbd>+<kbd>x</kbd>
|
| Sincronizza gli appunti e incolla³ | <kbd>MOD</kbd>+<kbd>v</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>
|
| 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>
|
| Abilita/Disabilita il contatore FPS (su stdout) | <kbd>MOD</kbd>+<kbd>i</kbd>
|
||||||
| Pizzica per zoomare | <kbd>Ctrl</kbd>+_click e trascina_
|
| Pizzica per zoomare | <kbd>Ctrl</kbd>+_click e trascina_
|
||||||
|
|
||||||
_¹Doppio click sui bordi neri per rimuoverli._
|
_¹Doppio click sui bordi neri per rimuoverli._
|
||||||
_²Il tasto destro accende lo schermo se era spento, preme BACK in caso contrario._
|
_²Il tasto destro accende lo schermo se era spento, preme BACK in caso contrario._
|
||||||
_³4° e 5° pulsante del mouse, se il tuo mouse ne dispone._
|
_³Solo in Android >= 7._
|
||||||
_⁴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.
|
Tutte le scorciatoie <kbd>Ctrl</kbd>+_tasto_ sono inoltrate al dispositivo, così sono gestite dall'applicazione attiva.
|
||||||
|
|
||||||
|
|||||||
31
README.md
31
README.md
@@ -207,29 +207,6 @@ scrcpy --crop 1224:1440:0:0 # 1224x1440 at offset (0,0)
|
|||||||
|
|
||||||
If `--max-size` is also specified, resizing is applied after cropping.
|
If `--max-size` is also specified, resizing is applied after cropping.
|
||||||
|
|
||||||
#### USB HID over AOAv2
|
|
||||||
|
|
||||||
Scrcpy can simulate a USB physical keyboard on Android to provide better input
|
|
||||||
experience, you need to connect your device via USB, not wireless.
|
|
||||||
|
|
||||||
However, due to some limitation of libusb and WinUSB driver, you cannot use HID
|
|
||||||
over AOAv2 on Windows.
|
|
||||||
|
|
||||||
Currently a USB serial number is needed to use HID over AOAv2.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --serial XXXXXXXXXXXXXXXX # don't use HID
|
|
||||||
scrcpy --serial XXXXXXXXXXXXXXXX --input-mode inject # don't use HID
|
|
||||||
scrcpy --serial XXXXXXXXXXXXXXXX --input-mode hid # try HID and exit if failed
|
|
||||||
```
|
|
||||||
|
|
||||||
Serial number can be found by `adb get-serialno`.
|
|
||||||
|
|
||||||
If you are a non-QWERTY keyboard user and using HID mode, please remember to set
|
|
||||||
correct physical keyboard layout manually in Android settings, because scrcpy
|
|
||||||
just forwards scancodes to Android device and Android system is responsible for
|
|
||||||
converting scancodes to correct keycode on Android device (your system does this
|
|
||||||
on your PC).
|
|
||||||
|
|
||||||
#### Lock video orientation
|
#### Lock video orientation
|
||||||
|
|
||||||
@@ -347,9 +324,7 @@ For example, you could capture the video within [OBS].
|
|||||||
#### Buffering
|
#### Buffering
|
||||||
|
|
||||||
It is possible to add buffering. This increases latency but reduces jitter (see
|
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:
|
The option is available for display buffering:
|
||||||
|
|
||||||
@@ -911,10 +886,10 @@ Read the [developers page].
|
|||||||
This README is available in other languages:
|
This README is available in other languages:
|
||||||
|
|
||||||
- [Indonesian (Indonesia, `id`) - v1.16](README.id.md)
|
- [Indonesian (Indonesia, `id`) - v1.16](README.id.md)
|
||||||
- [Italiano (Italiano, `it`) - v1.19](README.it.md)
|
- [Italiano (Italiano, `it`) - v1.17](README.it.md)
|
||||||
- [日本語 (Japanese, `jp`) - v1.17](README.jp.md)
|
- [日本語 (Japanese, `jp`) - v1.17](README.jp.md)
|
||||||
- [한국어 (Korean, `ko`) - v1.11](README.ko.md)
|
- [한국어 (Korean, `ko`) - v1.11](README.ko.md)
|
||||||
- [Português Brasileiro (Brazilian Portuguese, `pt-BR`) - v1.19](README.pt-br.md)
|
- [português brasileiro (Brazilian Portuguese, `pt-BR`) - v1.17](README.pt-br.md)
|
||||||
- [Español (Spanish, `sp`) - v1.17](README.sp.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.17](README.zh-Hans.md)
|
||||||
- [繁體中文 (Traditional Chinese, `zh-Hant`) - v1.15](README.zh-Hant.md)
|
- [繁體中文 (Traditional Chinese, `zh-Hant`) - v1.15](README.zh-Hant.md)
|
||||||
|
|||||||
174
README.pt-br.md
174
README.pt-br.md
@@ -1,6 +1,6 @@
|
|||||||
_Apenas o [README](README.md) original é garantido estar atualizado._
|
_Apenas o [README](README.md) original é garantido estar atualizado._
|
||||||
|
|
||||||
# scrcpy (v1.19)
|
# scrcpy (v1.17)
|
||||||
|
|
||||||
Esta aplicação fornece exibição e controle de dispositivos Android conectados via
|
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_.
|
USB (ou [via TCP/IP][article-tcpip]). Não requer nenhum acesso _root_.
|
||||||
@@ -38,18 +38,6 @@ 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>
|
<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
|
### Linux
|
||||||
|
|
||||||
No Debian (_testing_ e _sid_ por enquanto) e Ubuntu (20.04):
|
No Debian (_testing_ e _sid_ por enquanto) e Ubuntu (20.04):
|
||||||
@@ -79,7 +67,9 @@ Para Gentoo, uma [Ebuild] está disponível: [`scrcpy/`][ebuild-link].
|
|||||||
[Ebuild]: https://wiki.gentoo.org/wiki/Ebuild
|
[Ebuild]: https://wiki.gentoo.org/wiki/Ebuild
|
||||||
[ebuild-link]: https://github.com/maggu2810/maggu2810-overlay/tree/master/app-mobilephone/scrcpy
|
[ebuild-link]: https://github.com/maggu2810/maggu2810-overlay/tree/master/app-mobilephone/scrcpy
|
||||||
|
|
||||||
Você também pode [compilar o app manualmente][BUILD] ([processo simplificado][BUILD_simple]).
|
Você também pode [compilar o app manualmente][BUILD] (não se preocupe, não é tão
|
||||||
|
difícil).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
@@ -123,18 +113,13 @@ brew install scrcpy
|
|||||||
Você precisa do `adb`, acessível pelo seu `PATH`. Se você ainda não o tem:
|
Você precisa do `adb`, acessível pelo seu `PATH`. Se você ainda não o tem:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
brew install android-platform-tools
|
# Homebrew >= 2.6.0
|
||||||
|
brew install --cask android-platform-tools
|
||||||
|
|
||||||
|
# Homebrew < 2.6.0
|
||||||
|
brew cask 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].
|
Você também pode [compilar o app manualmente][BUILD].
|
||||||
|
|
||||||
|
|
||||||
@@ -210,11 +195,10 @@ Se `--max-size` também for especificado, o redimensionamento é aplicado após
|
|||||||
Para travar a orientação do espelhamento:
|
Para travar a orientação do espelhamento:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scrcpy --lock-video-orientation # orientação inicial (Atual)
|
scrcpy --lock-video-orientation 0 # orientação natural
|
||||||
scrcpy --lock-video-orientation=0 # orientação natural
|
scrcpy --lock-video-orientation 1 # 90° sentido anti-horário
|
||||||
scrcpy --lock-video-orientation=1 # 90° sentido anti-horário
|
scrcpy --lock-video-orientation 2 # 180°
|
||||||
scrcpy --lock-video-orientation=2 # 180°
|
scrcpy --lock-video-orientation 3 # 90° sentido horário
|
||||||
scrcpy --lock-video-orientation=3 # 90° sentido horário
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Isso afeta a orientação de gravação.
|
Isso afeta a orientação de gravação.
|
||||||
@@ -238,9 +222,7 @@ erro dará os encoders disponíveis:
|
|||||||
scrcpy --encoder _
|
scrcpy --encoder _
|
||||||
```
|
```
|
||||||
|
|
||||||
### Captura
|
### Gravando
|
||||||
|
|
||||||
#### Gravando
|
|
||||||
|
|
||||||
É possível gravar a tela enquanto ocorre o espelhamento:
|
É possível gravar a tela enquanto ocorre o espelhamento:
|
||||||
|
|
||||||
@@ -264,79 +246,6 @@ pacotes][packet delay variation] não impacta o arquivo gravado.
|
|||||||
[packet delay variation]: https://en.wikipedia.org/wiki/Packet_delay_variation
|
[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
|
### Conexão
|
||||||
|
|
||||||
#### Sem fio
|
#### Sem fio
|
||||||
@@ -579,6 +488,18 @@ 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
|
#### Mostrar toques
|
||||||
|
|
||||||
Para apresentações, pode ser útil mostrar toques físicos (no dispositivo
|
Para apresentações, pode ser útil mostrar toques físicos (no dispositivo
|
||||||
@@ -726,7 +647,7 @@ Não existe feedback visual, um log é imprimido no console.
|
|||||||
|
|
||||||
#### Enviar arquivo para dispositivo
|
#### Enviar arquivo para dispositivo
|
||||||
|
|
||||||
Para enviar um arquivo para `/sdcard/Download/` no dispositivo, arraste e solte um arquivo (não-APK) para a
|
Para enviar um arquivo para `/sdcard/` no dispositivo, arraste e solte um arquivo (não-APK) para a
|
||||||
janela do _scrcpy_.
|
janela do _scrcpy_.
|
||||||
|
|
||||||
Não existe feedback visual, um log é imprimido no console.
|
Não existe feedback visual, um log é imprimido no console.
|
||||||
@@ -773,12 +694,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>
|
| Mudar modo de tela cheia | <kbd>MOD</kbd>+<kbd>f</kbd>
|
||||||
| Rotacionar display para esquerda | <kbd>MOD</kbd>+<kbd>←</kbd> _(esquerda)_
|
| Rotacionar display para esquerda | <kbd>MOD</kbd>+<kbd>←</kbd> _(esquerda)_
|
||||||
| Rotacionar display para direita | <kbd>MOD</kbd>+<kbd>→</kbd> _(direita)_
|
| Rotacionar display para direita | <kbd>MOD</kbd>+<kbd>→</kbd> _(direita)_
|
||||||
| Redimensionar janela para 1:1 (pixel-perfeito) | <kbd>MOD</kbd>+<kbd>g</kbd>
|
| 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-esquerdo¹_
|
| Redimensionar janela para remover bordas pretas | <kbd>MOD</kbd>+<kbd>w</kbd> \| _Clique-duplo¹_
|
||||||
| Clicar em `HOME` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _Clique-do-meio_
|
| 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 `BACK` | <kbd>MOD</kbd>+<kbd>b</kbd> \| _Clique-direito²_
|
||||||
| Clicar em `APP_SWITCH` | <kbd>MOD</kbd>+<kbd>s</kbd> \| _Clique-do-4.°³_
|
| Clicar em `APP_SWITCH` | <kbd>MOD</kbd>+<kbd>s</kbd>
|
||||||
| Clicar em `MENU` (desbloquear tela) | <kbd>MOD</kbd>+<kbd>m</kbd>
|
| Clicar em `MENU` (desbloquear tela | <kbd>MOD</kbd>+<kbd>m</kbd>
|
||||||
| Clicar em `VOLUME_UP` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(cima)_
|
| Clicar em `VOLUME_UP` | <kbd>MOD</kbd>+<kbd>↑</kbd> _(cima)_
|
||||||
| Clicar em `VOLUME_DOWN` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(baixo)_
|
| Clicar em `VOLUME_DOWN` | <kbd>MOD</kbd>+<kbd>↓</kbd> _(baixo)_
|
||||||
| Clicar em `POWER` | <kbd>MOD</kbd>+<kbd>p</kbd>
|
| Clicar em `POWER` | <kbd>MOD</kbd>+<kbd>p</kbd>
|
||||||
@@ -786,27 +707,18 @@ _<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>
|
| 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>
|
| Ligar tela do dispositivo | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>o</kbd>
|
||||||
| Rotacionar tela do dispositivo | <kbd>MOD</kbd>+<kbd>r</kbd>
|
| Rotacionar tela do dispositivo | <kbd>MOD</kbd>+<kbd>r</kbd>
|
||||||
| Expandir painel de notificação | <kbd>MOD</kbd>+<kbd>n</kbd> \| _Clique-do-5.°³_
|
| Expandir painel de notificação | <kbd>MOD</kbd>+<kbd>n</kbd>
|
||||||
| Expandir painel de configurção | <kbd>MOD</kbd>+<kbd>n</kbd>+<kbd>n</kbd> \| _Clique-duplo-do-5.°³_
|
| Colapsar painel de notificação | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
||||||
| Colapsar paineis | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd>
|
| Copiar para área de transferência³ | <kbd>MOD</kbd>+<kbd>c</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>
|
||||||
| 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>
|
||||||
| 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>
|
| 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>
|
| 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-esquerdo na borda preta para remove-la._
|
_¹Clique-duplo em bordas pretas para removê-las._
|
||||||
_²Clique-direito liga a tela caso esteja desligada, pressione BACK caso contrário._
|
_²Clique-direito liga a tela se ela estiver desligada, pressiona BACK caso contrário._
|
||||||
_³4.° and 5.° botões do mouse, caso o mouse possua._
|
_³Apenas em Android >= 7._
|
||||||
_⁴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
|
Todos os atalhos <kbd>Ctrl</kbd>+_tecla_ são encaminhados para o dispositivo, para que eles sejam
|
||||||
tratados pela aplicação ativa.
|
tratados pela aplicação ativa.
|
||||||
@@ -817,9 +729,7 @@ tratados pela aplicação ativa.
|
|||||||
Para usar um binário _adb_ específico, configure seu caminho na variável de ambiente
|
Para usar um binário _adb_ específico, configure seu caminho na variável de ambiente
|
||||||
`ADB`:
|
`ADB`:
|
||||||
|
|
||||||
```bash
|
ADB=/caminho/para/adb scrcpy
|
||||||
ADB=/caminho/para/adb scrcpy
|
|
||||||
```
|
|
||||||
|
|
||||||
Para sobrepor o caminho do arquivo `scrcpy-server`, configure seu caminho em
|
Para sobrepor o caminho do arquivo `scrcpy-server`, configure seu caminho em
|
||||||
`SCRCPY_SERVER_PATH`.
|
`SCRCPY_SERVER_PATH`.
|
||||||
@@ -841,6 +751,8 @@ Um colega me desafiou a encontrar um nome tão impronunciável quanto [gnirehtet
|
|||||||
|
|
||||||
Veja [BUILD].
|
Veja [BUILD].
|
||||||
|
|
||||||
|
[BUILD]: BUILD.md
|
||||||
|
|
||||||
|
|
||||||
## Problemas comuns
|
## Problemas comuns
|
||||||
|
|
||||||
|
|||||||
@@ -42,14 +42,6 @@ if v4l2_support
|
|||||||
src += [ 'src/v4l2_sink.c' ]
|
src += [ 'src/v4l2_sink.c' ]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
aoa_hid_support = host_machine.system() == 'linux'
|
|
||||||
if aoa_hid_support
|
|
||||||
src += [
|
|
||||||
'src/aoa_hid.c',
|
|
||||||
'src/hid_keyboard.c',
|
|
||||||
]
|
|
||||||
endif
|
|
||||||
|
|
||||||
check_functions = [
|
check_functions = [
|
||||||
'strdup'
|
'strdup'
|
||||||
]
|
]
|
||||||
@@ -70,11 +62,8 @@ if not get_option('crossbuild_windows')
|
|||||||
dependencies += dependency('libavdevice')
|
dependencies += dependency('libavdevice')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if aoa_hid_support
|
|
||||||
dependencies += dependency('libusb-1.0')
|
|
||||||
endif
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
# cross-compile mingw32 build (from Linux to Windows)
|
# cross-compile mingw32 build (from Linux to Windows)
|
||||||
prebuilt_sdl2 = meson.get_cross_property('prebuilt_sdl2')
|
prebuilt_sdl2 = meson.get_cross_property('prebuilt_sdl2')
|
||||||
sdl2_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/' + prebuilt_sdl2 + '/bin'
|
sdl2_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/' + prebuilt_sdl2 + '/bin'
|
||||||
@@ -151,9 +140,6 @@ conf.set('SERVER_DEBUGGER_METHOD_NEW', get_option('server_debugger_method') == '
|
|||||||
# enable V4L2 support (linux only)
|
# enable V4L2 support (linux only)
|
||||||
conf.set('HAVE_V4L2', v4l2_support)
|
conf.set('HAVE_V4L2', v4l2_support)
|
||||||
|
|
||||||
# enable HID over AOA support (linux only)
|
|
||||||
conf.set('HAVE_AOA_HID', aoa_hid_support)
|
|
||||||
|
|
||||||
configure_file(configuration: conf, output: 'config.h')
|
configure_file(configuration: conf, output: 'config.h')
|
||||||
|
|
||||||
src_dir = include_directories('src')
|
src_dir = include_directories('src')
|
||||||
|
|||||||
18
app/scrcpy.1
18
app/scrcpy.1
@@ -82,24 +82,6 @@ Start in fullscreen.
|
|||||||
.B \-h, \-\-help
|
.B \-h, \-\-help
|
||||||
Print this help.
|
Print this help.
|
||||||
|
|
||||||
.TP
|
|
||||||
.B \-K, \-\-keyboard\-hid
|
|
||||||
Simulate a physical keyboard by using HID over AOAv2.
|
|
||||||
|
|
||||||
This provides a better experience for IME users, and allows to generate non-ASCII characters, contrary to the default injection method.
|
|
||||||
|
|
||||||
It may only work over USB, and is currently only supported on Linux.
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.B \-i, \-\-input\-mode mode
|
|
||||||
Select input mode for keyboard events.
|
|
||||||
|
|
||||||
Possible values are "hid" and "inject".
|
|
||||||
|
|
||||||
"hid" uses Android's USB HID over AOAv2 feature to simulate physical keyboard's events, which provides better experience for IME users if supported by you device.
|
|
||||||
|
|
||||||
"inject" is the legacy scrcpy way by injecting keycode events on Android, works on most devices and is the default.
|
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-\-legacy\-paste
|
.B \-\-legacy\-paste
|
||||||
Inject computer clipboard text as a sequence of key events on Ctrl+v (like MOD+Shift+v).
|
Inject computer clipboard text as a sequence of key events on Ctrl+v (like MOD+Shift+v).
|
||||||
|
|||||||
@@ -109,9 +109,7 @@ show_adb_err_msg(enum process_result err, const char *const argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process_t
|
process_t
|
||||||
adb_execute_redirect(const char *serial, const char *const adb_cmd[],
|
adb_execute(const char *serial, const char *const adb_cmd[], size_t len) {
|
||||||
size_t len, pipe_t *pipe_stdin, pipe_t *pipe_stdout,
|
|
||||||
pipe_t *pipe_stderr) {
|
|
||||||
int i;
|
int i;
|
||||||
process_t process;
|
process_t process;
|
||||||
|
|
||||||
@@ -131,9 +129,7 @@ adb_execute_redirect(const char *serial, const char *const adb_cmd[],
|
|||||||
|
|
||||||
memcpy(&argv[i], adb_cmd, len * sizeof(const char *));
|
memcpy(&argv[i], adb_cmd, len * sizeof(const char *));
|
||||||
argv[len + i] = NULL;
|
argv[len + i] = NULL;
|
||||||
enum process_result r =
|
enum process_result r = process_execute(argv, &process);
|
||||||
process_execute_redirect(argv, &process, pipe_stdin, pipe_stdout,
|
|
||||||
pipe_stderr);
|
|
||||||
if (r != PROCESS_SUCCESS) {
|
if (r != PROCESS_SUCCESS) {
|
||||||
show_adb_err_msg(r, argv);
|
show_adb_err_msg(r, argv);
|
||||||
process = PROCESS_NONE;
|
process = PROCESS_NONE;
|
||||||
@@ -143,11 +139,6 @@ adb_execute_redirect(const char *serial, const char *const adb_cmd[],
|
|||||||
return process;
|
return process;
|
||||||
}
|
}
|
||||||
|
|
||||||
process_t
|
|
||||||
adb_execute(const char *serial, const char *const adb_cmd[], size_t len) {
|
|
||||||
return adb_execute_redirect(serial, adb_cmd, len, NULL, NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
process_t
|
process_t
|
||||||
adb_forward(const char *serial, uint16_t local_port,
|
adb_forward(const char *serial, uint16_t local_port,
|
||||||
const char *device_socket_name) {
|
const char *device_socket_name) {
|
||||||
@@ -233,47 +224,3 @@ adb_install(const char *serial, const char *local) {
|
|||||||
|
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
|
||||||
adb_execute_for_output(const char *serial, const char *const adb_cmd[],
|
|
||||||
size_t adb_cmd_len, char *buf, size_t buf_len,
|
|
||||||
const char *name) {
|
|
||||||
pipe_t pipe_stdout;
|
|
||||||
process_t proc = adb_execute_redirect(serial, adb_cmd, adb_cmd_len, NULL,
|
|
||||||
&pipe_stdout, NULL);
|
|
||||||
|
|
||||||
ssize_t r = read_pipe_all(pipe_stdout, buf, buf_len);
|
|
||||||
close_pipe(pipe_stdout);
|
|
||||||
|
|
||||||
if (!process_check_success(proc, name, true)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t
|
|
||||||
truncate_first_line(char *data, size_t len) {
|
|
||||||
data[len - 1] = '\0';
|
|
||||||
char *eol = strpbrk(data, "\r\n");
|
|
||||||
if (eol) {
|
|
||||||
*eol = '\0';
|
|
||||||
len = eol - data;
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
adb_get_serialno(void) {
|
|
||||||
char buf[128];
|
|
||||||
|
|
||||||
const char *const adb_cmd[] = {"get-serialno"};
|
|
||||||
ssize_t r = adb_execute_for_output(NULL, adb_cmd, ARRAY_LEN(adb_cmd),
|
|
||||||
buf, sizeof(buf), "get-serialno");
|
|
||||||
if (r <= 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
truncate_first_line(buf, r);
|
|
||||||
return strdup(buf);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,11 +11,6 @@
|
|||||||
process_t
|
process_t
|
||||||
adb_execute(const char *serial, const char *const adb_cmd[], size_t len);
|
adb_execute(const char *serial, const char *const adb_cmd[], size_t len);
|
||||||
|
|
||||||
process_t
|
|
||||||
adb_execute_redirect(const char *serial, const char *const adb_cmd[],
|
|
||||||
size_t len, pipe_t *pipe_stdin, pipe_t *pipe_stdout,
|
|
||||||
pipe_t *pipe_stderr);
|
|
||||||
|
|
||||||
process_t
|
process_t
|
||||||
adb_forward(const char *serial, uint16_t local_port,
|
adb_forward(const char *serial, uint16_t local_port,
|
||||||
const char *device_socket_name);
|
const char *device_socket_name);
|
||||||
@@ -36,8 +31,4 @@ adb_push(const char *serial, const char *local, const char *remote);
|
|||||||
process_t
|
process_t
|
||||||
adb_install(const char *serial, const char *local);
|
adb_install(const char *serial, const char *local);
|
||||||
|
|
||||||
// Return the result of "adb get-serialno".
|
|
||||||
char *
|
|
||||||
adb_get_serialno(void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,357 +0,0 @@
|
|||||||
#include "util/log.h"
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "aoa_hid.h"
|
|
||||||
|
|
||||||
// See <https://source.android.com/devices/accessories/aoa2#hid-support>.
|
|
||||||
#define ACCESSORY_REGISTER_HID 54
|
|
||||||
#define ACCESSORY_SET_HID_REPORT_DESC 56
|
|
||||||
#define ACCESSORY_SEND_HID_EVENT 57
|
|
||||||
#define ACCESSORY_UNREGISTER_HID 55
|
|
||||||
|
|
||||||
#define DEFAULT_TIMEOUT 1000
|
|
||||||
|
|
||||||
static void
|
|
||||||
hid_event_log(const struct hid_event *event) {
|
|
||||||
// HID Event: [00] FF FF FF FF...
|
|
||||||
assert(event->size);
|
|
||||||
unsigned buffer_size = event->size * 3 + 1;
|
|
||||||
char *buffer = malloc(buffer_size);
|
|
||||||
if (!buffer) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (unsigned i = 0; i < event->size; ++i) {
|
|
||||||
snprintf(buffer + i * 3, 4, " %02x", event->buffer[i]);
|
|
||||||
}
|
|
||||||
LOGV("HID Event: [%d]%s", event->from_accessory_id, buffer);
|
|
||||||
free(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
hid_event_destroy(struct hid_event *event) {
|
|
||||||
free(event->buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
log_libusb_error(enum libusb_error errcode) {
|
|
||||||
LOGW("libusb error: %s", libusb_strerror(errcode));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
accept_device(libusb_device *device, const char *serial) {
|
|
||||||
// do not log any USB error in this function, it is expected that many USB
|
|
||||||
// devices available on the computer have permission restrictions
|
|
||||||
|
|
||||||
struct libusb_device_descriptor desc;
|
|
||||||
libusb_get_device_descriptor(device, &desc);
|
|
||||||
|
|
||||||
if (!desc.iSerialNumber) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
libusb_device_handle *handle;
|
|
||||||
int result = libusb_open(device, &handle);
|
|
||||||
if (result < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buffer[128];
|
|
||||||
result = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber,
|
|
||||||
(unsigned char *) buffer,
|
|
||||||
sizeof(buffer));
|
|
||||||
libusb_close(handle);
|
|
||||||
if (result < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer[sizeof(buffer) - 1] = '\0'; // just in case
|
|
||||||
|
|
||||||
// accept the device if its serial matches
|
|
||||||
return !strcmp(buffer, serial);
|
|
||||||
}
|
|
||||||
|
|
||||||
static libusb_device *
|
|
||||||
aoa_find_usb_device(const char *serial) {
|
|
||||||
if (!serial) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
libusb_device **list;
|
|
||||||
libusb_device *result = NULL;
|
|
||||||
ssize_t count = libusb_get_device_list(NULL, &list);
|
|
||||||
if (count < 0) {
|
|
||||||
log_libusb_error((enum libusb_error) count);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < (size_t) count; ++i) {
|
|
||||||
libusb_device *device = list[i];
|
|
||||||
|
|
||||||
if (accept_device(device, serial)) {
|
|
||||||
result = libusb_ref_device(device);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
libusb_free_device_list(list, 1);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
aoa_open_usb_handle(libusb_device *device, libusb_device_handle **handle) {
|
|
||||||
int result = libusb_open(device, handle);
|
|
||||||
if (result < 0) {
|
|
||||||
log_libusb_error((enum libusb_error) result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
aoa_init(struct aoa *aoa, const char *serial) {
|
|
||||||
cbuf_init(&aoa->queue);
|
|
||||||
|
|
||||||
if (!sc_mutex_init(&aoa->mutex)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sc_cond_init(&aoa->event_cond)) {
|
|
||||||
sc_mutex_destroy(&aoa->mutex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (libusb_init(&aoa->usb_context) != LIBUSB_SUCCESS) {
|
|
||||||
sc_cond_destroy(&aoa->event_cond);
|
|
||||||
sc_mutex_destroy(&aoa->mutex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
aoa->usb_device = aoa_find_usb_device(serial);
|
|
||||||
if (!aoa->usb_device) {
|
|
||||||
LOGW("USB device of serial %s not found", serial);
|
|
||||||
libusb_exit(aoa->usb_context);
|
|
||||||
sc_mutex_destroy(&aoa->mutex);
|
|
||||||
sc_cond_destroy(&aoa->event_cond);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aoa_open_usb_handle(aoa->usb_device, &aoa->usb_handle) < 0) {
|
|
||||||
LOGW("Open USB handle failed");
|
|
||||||
libusb_unref_device(aoa->usb_device);
|
|
||||||
libusb_exit(aoa->usb_context);
|
|
||||||
sc_cond_destroy(&aoa->event_cond);
|
|
||||||
sc_mutex_destroy(&aoa->mutex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
aoa->stopped = false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
aoa_destroy(struct aoa *aoa) {
|
|
||||||
// Destroy remaining events
|
|
||||||
struct hid_event event;
|
|
||||||
while (cbuf_take(&aoa->queue, &event)) {
|
|
||||||
hid_event_destroy(&event);
|
|
||||||
}
|
|
||||||
|
|
||||||
libusb_close(aoa->usb_handle);
|
|
||||||
libusb_unref_device(aoa->usb_device);
|
|
||||||
libusb_exit(aoa->usb_context);
|
|
||||||
sc_cond_destroy(&aoa->event_cond);
|
|
||||||
sc_mutex_destroy(&aoa->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
aoa_register_hid(struct aoa *aoa, uint16_t accessory_id,
|
|
||||||
uint16_t report_desc_size) {
|
|
||||||
uint8_t request_type = LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR;
|
|
||||||
uint8_t request = ACCESSORY_REGISTER_HID;
|
|
||||||
// <https://source.android.com/devices/accessories/aoa2.html#hid-support>
|
|
||||||
// value (arg0): accessory assigned ID for the HID device
|
|
||||||
// index (arg1): total length of the HID report descriptor
|
|
||||||
uint16_t value = accessory_id;
|
|
||||||
uint16_t index = report_desc_size;
|
|
||||||
unsigned char *buffer = NULL;
|
|
||||||
uint16_t length = 0;
|
|
||||||
int result = libusb_control_transfer(aoa->usb_handle, request_type, request,
|
|
||||||
value, index, buffer, length,
|
|
||||||
DEFAULT_TIMEOUT);
|
|
||||||
if (result < 0) {
|
|
||||||
log_libusb_error((enum libusb_error) result);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
aoa_set_hid_report_desc(struct aoa *aoa, uint16_t accessory_id,
|
|
||||||
const unsigned char *report_desc,
|
|
||||||
uint16_t report_desc_size) {
|
|
||||||
uint8_t request_type = LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR;
|
|
||||||
uint8_t request = ACCESSORY_SET_HID_REPORT_DESC;
|
|
||||||
/**
|
|
||||||
* If the HID descriptor is longer than the endpoint zero max packet size,
|
|
||||||
* the descriptor will be sent in multiple ACCESSORY_SET_HID_REPORT_DESC
|
|
||||||
* commands. The data for the descriptor must be sent sequentially
|
|
||||||
* if multiple packets are needed.
|
|
||||||
* <https://source.android.com/devices/accessories/aoa2.html#hid-support>
|
|
||||||
*
|
|
||||||
* libusb handles packet abstraction internally, so we don't need to care
|
|
||||||
* about bMaxPacketSize0 here.
|
|
||||||
*
|
|
||||||
* See <https://libusb.sourceforge.io/api-1.0/libusb_packetoverflow.html>
|
|
||||||
*/
|
|
||||||
// value (arg0): accessory assigned ID for the HID device
|
|
||||||
// index (arg1): offset of data (buffer) in descriptor
|
|
||||||
uint16_t value = accessory_id;
|
|
||||||
uint16_t index = 0;
|
|
||||||
// libusb_control_transfer expects a pointer to non-const
|
|
||||||
unsigned char *buffer = (unsigned char *) report_desc;
|
|
||||||
uint16_t length = report_desc_size;
|
|
||||||
int result = libusb_control_transfer(aoa->usb_handle, request_type, request,
|
|
||||||
value, index, buffer, length,
|
|
||||||
DEFAULT_TIMEOUT);
|
|
||||||
if (result < 0) {
|
|
||||||
log_libusb_error((enum libusb_error) result);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
aoa_setup_hid(struct aoa *aoa, uint16_t accessory_id,
|
|
||||||
const unsigned char *report_desc, uint16_t report_desc_size) {
|
|
||||||
bool ok = aoa_register_hid(aoa, accessory_id, report_desc_size);
|
|
||||||
if (!ok) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = aoa_set_hid_report_desc(aoa, accessory_id, report_desc,
|
|
||||||
report_desc_size);
|
|
||||||
if (!ok) {
|
|
||||||
if (!aoa_unregister_hid(aoa, accessory_id)) {
|
|
||||||
LOGW("Could not unregister HID");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
aoa_send_hid_event(struct aoa *aoa, const struct hid_event *event) {
|
|
||||||
uint8_t request_type = LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR;
|
|
||||||
uint8_t request = ACCESSORY_SEND_HID_EVENT;
|
|
||||||
// <https://source.android.com/devices/accessories/aoa2.html#hid-support>
|
|
||||||
// value (arg0): accessory assigned ID for the HID device
|
|
||||||
// index (arg1): 0 (unused)
|
|
||||||
uint16_t value = event->from_accessory_id;
|
|
||||||
uint16_t index = 0;
|
|
||||||
unsigned char *buffer = event->buffer;
|
|
||||||
uint16_t length = event->size;
|
|
||||||
int result = libusb_control_transfer(aoa->usb_handle, request_type, request,
|
|
||||||
value, index, buffer, length,
|
|
||||||
DEFAULT_TIMEOUT);
|
|
||||||
if (result < 0) {
|
|
||||||
log_libusb_error((enum libusb_error) result);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
aoa_unregister_hid(struct aoa *aoa, const uint16_t accessory_id) {
|
|
||||||
uint8_t request_type = LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR;
|
|
||||||
uint8_t request = ACCESSORY_UNREGISTER_HID;
|
|
||||||
// <https://source.android.com/devices/accessories/aoa2.html#hid-support>
|
|
||||||
// value (arg0): accessory assigned ID for the HID device
|
|
||||||
// index (arg1): 0
|
|
||||||
uint16_t value = accessory_id;
|
|
||||||
uint16_t index = 0;
|
|
||||||
unsigned char *buffer = NULL;
|
|
||||||
uint16_t length = 0;
|
|
||||||
int result = libusb_control_transfer(aoa->usb_handle, request_type, request,
|
|
||||||
value, index, buffer, length,
|
|
||||||
DEFAULT_TIMEOUT);
|
|
||||||
if (result < 0) {
|
|
||||||
log_libusb_error((enum libusb_error) result);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
aoa_push_hid_event(struct aoa *aoa, const struct hid_event *event) {
|
|
||||||
hid_event_log(event);
|
|
||||||
sc_mutex_lock(&aoa->mutex);
|
|
||||||
bool was_empty = cbuf_is_empty(&aoa->queue);
|
|
||||||
bool res = cbuf_push(&aoa->queue, *event);
|
|
||||||
if (was_empty) {
|
|
||||||
sc_cond_signal(&aoa->event_cond);
|
|
||||||
}
|
|
||||||
sc_mutex_unlock(&aoa->mutex);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
run_aoa_thread(void *data) {
|
|
||||||
struct aoa *aoa = data;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
sc_mutex_lock(&aoa->mutex);
|
|
||||||
while (!aoa->stopped && cbuf_is_empty(&aoa->queue)) {
|
|
||||||
sc_cond_wait(&aoa->event_cond, &aoa->mutex);
|
|
||||||
}
|
|
||||||
if (aoa->stopped) {
|
|
||||||
// Stop immediately, do not process further events
|
|
||||||
sc_mutex_unlock(&aoa->mutex);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
struct hid_event event;
|
|
||||||
bool non_empty = cbuf_take(&aoa->queue, &event);
|
|
||||||
assert(non_empty);
|
|
||||||
(void) non_empty;
|
|
||||||
sc_mutex_unlock(&aoa->mutex);
|
|
||||||
|
|
||||||
bool ok = aoa_send_hid_event(aoa, &event);
|
|
||||||
hid_event_destroy(&event);
|
|
||||||
if (!ok) {
|
|
||||||
LOGW("Could not send HID event to USB device");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
aoa_start(struct aoa *aoa) {
|
|
||||||
LOGD("Starting AOA thread");
|
|
||||||
|
|
||||||
bool ok = sc_thread_create(&aoa->thread, run_aoa_thread, "aoa_thread", aoa);
|
|
||||||
if (!ok) {
|
|
||||||
LOGC("Could not start AOA thread");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
aoa_stop(struct aoa *aoa) {
|
|
||||||
sc_mutex_lock(&aoa->mutex);
|
|
||||||
aoa->stopped = true;
|
|
||||||
sc_cond_signal(&aoa->event_cond);
|
|
||||||
sc_mutex_unlock(&aoa->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
aoa_join(struct aoa *aoa) {
|
|
||||||
sc_thread_join(&aoa->thread, NULL);
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
#ifndef AOA_HID_H
|
|
||||||
#define AOA_HID_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include <libusb-1.0/libusb.h>
|
|
||||||
|
|
||||||
#include "scrcpy.h"
|
|
||||||
#include "util/cbuf.h"
|
|
||||||
#include "util/thread.h"
|
|
||||||
|
|
||||||
struct hid_event {
|
|
||||||
uint16_t from_accessory_id;
|
|
||||||
unsigned char *buffer;
|
|
||||||
uint16_t size;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct hid_event_queue CBUF(struct hid_event, 64);
|
|
||||||
|
|
||||||
struct aoa {
|
|
||||||
libusb_context *usb_context;
|
|
||||||
libusb_device *usb_device;
|
|
||||||
libusb_device_handle *usb_handle;
|
|
||||||
sc_thread thread;
|
|
||||||
sc_mutex mutex;
|
|
||||||
sc_cond event_cond;
|
|
||||||
bool stopped;
|
|
||||||
struct hid_event_queue queue;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool
|
|
||||||
aoa_init(struct aoa *aoa, const char *serial);
|
|
||||||
|
|
||||||
void
|
|
||||||
aoa_destroy(struct aoa *aoa);
|
|
||||||
|
|
||||||
bool
|
|
||||||
aoa_start(struct aoa *aoa);
|
|
||||||
|
|
||||||
void
|
|
||||||
aoa_stop(struct aoa *aoa);
|
|
||||||
|
|
||||||
void
|
|
||||||
aoa_join(struct aoa *aoa);
|
|
||||||
|
|
||||||
bool
|
|
||||||
aoa_setup_hid(struct aoa *aoa, uint16_t accessory_id,
|
|
||||||
const unsigned char *report_desc, uint16_t report_desc_size);
|
|
||||||
|
|
||||||
bool
|
|
||||||
aoa_unregister_hid(struct aoa *aoa, uint16_t accessory_id);
|
|
||||||
|
|
||||||
bool
|
|
||||||
aoa_push_hid_event(struct aoa *aoa, const struct hid_event *event);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -76,14 +76,6 @@ scrcpy_print_usage(const char *arg0) {
|
|||||||
" -f, --fullscreen\n"
|
" -f, --fullscreen\n"
|
||||||
" Start in fullscreen.\n"
|
" Start in fullscreen.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -K, --keyboard-hid\n"
|
|
||||||
" Simulate a physical keyboard by using HID over AOAv2.\n"
|
|
||||||
" It provides a better experience for IME users, and allows to\n"
|
|
||||||
" generate non-ASCII characters, contrary to the default\n"
|
|
||||||
" injection method.\n"
|
|
||||||
" It may only work over USB, and is currently only supported\n"
|
|
||||||
" on Linux.\n"
|
|
||||||
"\n"
|
|
||||||
" -h, --help\n"
|
" -h, --help\n"
|
||||||
" Print this help.\n"
|
" Print this help.\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -746,7 +738,6 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
OPT_FORWARD_ALL_CLICKS},
|
OPT_FORWARD_ALL_CLICKS},
|
||||||
{"fullscreen", no_argument, NULL, 'f'},
|
{"fullscreen", no_argument, NULL, 'f'},
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"keyboard-hid", no_argument, NULL, 'K'},
|
|
||||||
{"legacy-paste", no_argument, NULL, OPT_LEGACY_PASTE},
|
{"legacy-paste", no_argument, NULL, OPT_LEGACY_PASTE},
|
||||||
{"lock-video-orientation", optional_argument, NULL,
|
{"lock-video-orientation", optional_argument, NULL,
|
||||||
OPT_LOCK_VIDEO_ORIENTATION},
|
OPT_LOCK_VIDEO_ORIENTATION},
|
||||||
@@ -793,7 +784,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
optind = 0; // reset to start from the first argument in tests
|
optind = 0; // reset to start from the first argument in tests
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt_long(argc, argv, "b:c:fF:hKm:nNp:r:s:StTvV:w",
|
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTvV:w",
|
||||||
long_options, NULL)) != -1) {
|
long_options, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'b':
|
case 'b':
|
||||||
@@ -826,9 +817,6 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
case 'h':
|
case 'h':
|
||||||
args->help = true;
|
args->help = true;
|
||||||
break;
|
break;
|
||||||
case 'K':
|
|
||||||
opts->keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_HID;
|
|
||||||
break;
|
|
||||||
case OPT_MAX_FPS:
|
case OPT_MAX_FPS:
|
||||||
if (!parse_max_fps(optarg, &opts->max_fps)) {
|
if (!parse_max_fps(optarg, &opts->max_fps)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,356 +0,0 @@
|
|||||||
#include "hid_keyboard.h"
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <SDL2/SDL_events.h>
|
|
||||||
|
|
||||||
#include "util/log.h"
|
|
||||||
|
|
||||||
/** Downcast key processor to hid_keyboard */
|
|
||||||
#define DOWNCAST(KP) \
|
|
||||||
container_of(KP, struct hid_keyboard, key_processor)
|
|
||||||
|
|
||||||
#define HID_KEYBOARD_ACCESSORY_ID 1
|
|
||||||
|
|
||||||
#define HID_KEYBOARD_MODIFIER_NONE 0x00
|
|
||||||
#define HID_KEYBOARD_MODIFIER_LEFT_CONTROL (1 << 0)
|
|
||||||
#define HID_KEYBOARD_MODIFIER_LEFT_SHIFT (1 << 1)
|
|
||||||
#define HID_KEYBOARD_MODIFIER_LEFT_ALT (1 << 2)
|
|
||||||
#define HID_KEYBOARD_MODIFIER_LEFT_GUI (1 << 3)
|
|
||||||
#define HID_KEYBOARD_MODIFIER_RIGHT_CONTROL (1 << 4)
|
|
||||||
#define HID_KEYBOARD_MODIFIER_RIGHT_SHIFT (1 << 5)
|
|
||||||
#define HID_KEYBOARD_MODIFIER_RIGHT_ALT (1 << 6)
|
|
||||||
#define HID_KEYBOARD_MODIFIER_RIGHT_GUI (1 << 7)
|
|
||||||
|
|
||||||
#define HID_KEYBOARD_INDEX_MODIFIER 0
|
|
||||||
#define HID_KEYBOARD_INDEX_KEYS 2
|
|
||||||
|
|
||||||
// USB HID protocol says 6 keys in an event is the requirement for BIOS
|
|
||||||
// keyboard support, though OS could support more keys via modifying the report
|
|
||||||
// desc. 6 should be enough for scrcpy.
|
|
||||||
#define HID_KEYBOARD_MAX_KEYS 6
|
|
||||||
#define HID_KEYBOARD_EVENT_SIZE (2 + HID_KEYBOARD_MAX_KEYS)
|
|
||||||
|
|
||||||
#define HID_KEYBOARD_RESERVED 0x00
|
|
||||||
#define HID_KEYBOARD_ERROR_ROLL_OVER 0x01
|
|
||||||
|
|
||||||
#define SC_SCANCODE_CAPSLOCK 57
|
|
||||||
#define SC_SCANCODE_NUMLOCK 83
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For HID over AOAv2, only report descriptor is needed.
|
|
||||||
*
|
|
||||||
* The specification is available here:
|
|
||||||
* <https://www.usb.org/sites/default/files/hid1_11.pdf>
|
|
||||||
*
|
|
||||||
* In particular, read:
|
|
||||||
* - 6.2.2 Report Descriptor
|
|
||||||
* - Appendix B.1 Protocol 1 (Keyboard)
|
|
||||||
* - Appendix C: Keyboard Implementation
|
|
||||||
*
|
|
||||||
* Normally a basic HID keyboard uses 8 bytes:
|
|
||||||
* Modifier Reserved Key Key Key Key Key Key
|
|
||||||
*
|
|
||||||
* You can dump your device's report descriptor with:
|
|
||||||
*
|
|
||||||
* sudo usbhid-dump -m vid:pid -e descriptor
|
|
||||||
*
|
|
||||||
* (change vid:pid' to your device's vendor ID and product ID).
|
|
||||||
*/
|
|
||||||
static const unsigned char keyboard_report_desc[] = {
|
|
||||||
// Usage Page (Generic Desktop)
|
|
||||||
0x05, 0x01,
|
|
||||||
// Usage (Keyboard)
|
|
||||||
0x09, 0x06,
|
|
||||||
|
|
||||||
// Collection (Application)
|
|
||||||
0xA1, 0x01,
|
|
||||||
|
|
||||||
// Usage Page (Key Codes)
|
|
||||||
0x05, 0x07,
|
|
||||||
// Usage Minimum (224)
|
|
||||||
0x19, 0xE0,
|
|
||||||
// Usage Maximum (231)
|
|
||||||
0x29, 0xE7,
|
|
||||||
// Logical Minimum (0)
|
|
||||||
0x15, 0x00,
|
|
||||||
// Logical Maximum (1)
|
|
||||||
0x25, 0x01,
|
|
||||||
// Report Size (1)
|
|
||||||
0x75, 0x01,
|
|
||||||
// Report Count (8)
|
|
||||||
0x95, 0x08,
|
|
||||||
// Input (Data, Variable, Absolute): Modifier byte
|
|
||||||
0x81, 0x02,
|
|
||||||
|
|
||||||
// Report Size (8)
|
|
||||||
0x75, 0x08,
|
|
||||||
// Report Count (1)
|
|
||||||
0x95, 0x01,
|
|
||||||
// Input (Constant): Reserved byte
|
|
||||||
0x81, 0x01,
|
|
||||||
|
|
||||||
// Usage Page (LEDs)
|
|
||||||
0x05, 0x08,
|
|
||||||
// Usage Minimum (1)
|
|
||||||
0x19, 0x01,
|
|
||||||
// Usage Maximum (5)
|
|
||||||
0x29, 0x05,
|
|
||||||
// Report Size (1)
|
|
||||||
0x75, 0x01,
|
|
||||||
// Report Count (5)
|
|
||||||
0x95, 0x05,
|
|
||||||
// Output (Data, Variable, Absolute): LED report
|
|
||||||
0x91, 0x02,
|
|
||||||
|
|
||||||
// Report Size (3)
|
|
||||||
0x75, 0x03,
|
|
||||||
// Report Count (1)
|
|
||||||
0x95, 0x01,
|
|
||||||
// Output (Constant): LED report padding
|
|
||||||
0x91, 0x01,
|
|
||||||
|
|
||||||
// Usage Page (Key Codes)
|
|
||||||
0x05, 0x07,
|
|
||||||
// Usage Minimum (0)
|
|
||||||
0x19, 0x00,
|
|
||||||
// Usage Maximum (101)
|
|
||||||
0x29, HID_KEYBOARD_KEYS - 1,
|
|
||||||
// Logical Minimum (0)
|
|
||||||
0x15, 0x00,
|
|
||||||
// Logical Maximum(101)
|
|
||||||
0x25, HID_KEYBOARD_KEYS - 1,
|
|
||||||
// Report Size (8)
|
|
||||||
0x75, 0x08,
|
|
||||||
// Report Count (6)
|
|
||||||
0x95, HID_KEYBOARD_MAX_KEYS,
|
|
||||||
// Input (Data, Array): Keys
|
|
||||||
0x81, 0x00,
|
|
||||||
|
|
||||||
// End Collection
|
|
||||||
0xC0
|
|
||||||
};
|
|
||||||
|
|
||||||
static unsigned char *
|
|
||||||
create_hid_keyboard_event(void) {
|
|
||||||
unsigned char *buffer = malloc(HID_KEYBOARD_EVENT_SIZE);
|
|
||||||
if (!buffer) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer[HID_KEYBOARD_INDEX_MODIFIER] = HID_KEYBOARD_MODIFIER_NONE;
|
|
||||||
buffer[1] = HID_KEYBOARD_RESERVED;
|
|
||||||
memset(&buffer[HID_KEYBOARD_INDEX_KEYS], 0, HID_KEYBOARD_MAX_KEYS);
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned char
|
|
||||||
sdl_keymod_to_hid_modifiers(SDL_Keymod mod) {
|
|
||||||
unsigned char modifiers = HID_KEYBOARD_MODIFIER_NONE;
|
|
||||||
if (mod & KMOD_LCTRL) {
|
|
||||||
modifiers |= HID_KEYBOARD_MODIFIER_LEFT_CONTROL;
|
|
||||||
}
|
|
||||||
if (mod & KMOD_LSHIFT) {
|
|
||||||
modifiers |= HID_KEYBOARD_MODIFIER_LEFT_SHIFT;
|
|
||||||
}
|
|
||||||
if (mod & KMOD_LALT) {
|
|
||||||
modifiers |= HID_KEYBOARD_MODIFIER_LEFT_ALT;
|
|
||||||
}
|
|
||||||
if (mod & KMOD_LGUI) {
|
|
||||||
modifiers |= HID_KEYBOARD_MODIFIER_LEFT_GUI;
|
|
||||||
}
|
|
||||||
if (mod & KMOD_RCTRL) {
|
|
||||||
modifiers |= HID_KEYBOARD_MODIFIER_RIGHT_CONTROL;
|
|
||||||
}
|
|
||||||
if (mod & KMOD_RSHIFT) {
|
|
||||||
modifiers |= HID_KEYBOARD_MODIFIER_RIGHT_SHIFT;
|
|
||||||
}
|
|
||||||
if (mod & KMOD_RALT) {
|
|
||||||
modifiers |= HID_KEYBOARD_MODIFIER_RIGHT_ALT;
|
|
||||||
}
|
|
||||||
if (mod & KMOD_RGUI) {
|
|
||||||
modifiers |= HID_KEYBOARD_MODIFIER_RIGHT_GUI;
|
|
||||||
}
|
|
||||||
return modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
send_mod_lock_state(struct hid_keyboard *kb, unsigned lock_mod) {
|
|
||||||
assert(!(lock_mod & ~SC_MOD_MASK));
|
|
||||||
if (!lock_mod) {
|
|
||||||
// Nothing to do
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct hid_event hid_event;
|
|
||||||
hid_event.from_accessory_id = HID_KEYBOARD_ACCESSORY_ID;
|
|
||||||
hid_event.buffer = create_hid_keyboard_event();
|
|
||||||
if (!hid_event.buffer) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
hid_event.size = HID_KEYBOARD_EVENT_SIZE;
|
|
||||||
|
|
||||||
unsigned i = 0;
|
|
||||||
if (lock_mod & SC_MOD_CAPSLOCK) {
|
|
||||||
hid_event.buffer[HID_KEYBOARD_INDEX_KEYS + i] = SC_SCANCODE_CAPSLOCK;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
if (lock_mod & SC_MOD_NUMLOCK) {
|
|
||||||
hid_event.buffer[HID_KEYBOARD_INDEX_KEYS + i] = SC_SCANCODE_NUMLOCK;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for (int i = 0; i < HID_KEYBOARD_EVENT_SIZE; ++i)
|
|
||||||
// printf("%02x ", hid_event->buffer[i]);
|
|
||||||
// printf("\n");
|
|
||||||
|
|
||||||
if (!aoa_push_hid_event(kb->aoa, &hid_event)) {
|
|
||||||
LOGW("Could request HID event");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
convert_hid_keyboard_event(struct hid_keyboard *kb, struct hid_event *hid_event,
|
|
||||||
const SDL_KeyboardEvent *event) {
|
|
||||||
hid_event->buffer = create_hid_keyboard_event();
|
|
||||||
if (!hid_event->buffer) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
hid_event->size = HID_KEYBOARD_EVENT_SIZE;
|
|
||||||
|
|
||||||
unsigned char modifiers = sdl_keymod_to_hid_modifiers(event->keysym.mod);
|
|
||||||
|
|
||||||
SDL_Scancode scancode = event->keysym.scancode;
|
|
||||||
assert(scancode >= 0);
|
|
||||||
if (scancode < HID_KEYBOARD_KEYS) {
|
|
||||||
// Pressed is true and released is false
|
|
||||||
kb->keys[scancode] = (event->type == SDL_KEYDOWN);
|
|
||||||
LOGV("keys[%02x] = %s", scancode,
|
|
||||||
kb->keys[scancode] ? "true" : "false");
|
|
||||||
}
|
|
||||||
|
|
||||||
hid_event->buffer[HID_KEYBOARD_INDEX_MODIFIER] = modifiers;
|
|
||||||
|
|
||||||
// Re-calculate pressed keys every time
|
|
||||||
int keys_pressed_count = 0;
|
|
||||||
for (int i = 0; i < HID_KEYBOARD_KEYS; ++i) {
|
|
||||||
if (kb->keys[i]) {
|
|
||||||
// USB HID protocol says that if keys exceeds report count, a
|
|
||||||
// phantom state should be reported
|
|
||||||
if (keys_pressed_count >= HID_KEYBOARD_MAX_KEYS) {
|
|
||||||
// Pantom state:
|
|
||||||
// - Modifiers
|
|
||||||
// - Reserved
|
|
||||||
// - ErrorRollOver * HID_KEYBOARD_MAX_KEYS
|
|
||||||
memset(&hid_event->buffer[HID_KEYBOARD_INDEX_KEYS],
|
|
||||||
HID_KEYBOARD_ERROR_ROLL_OVER, HID_KEYBOARD_MAX_KEYS);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
hid_event->buffer[HID_KEYBOARD_INDEX_KEYS + keys_pressed_count] = i;
|
|
||||||
++keys_pressed_count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool
|
|
||||||
scancode_is_modifier(SDL_Scancode scancode) {
|
|
||||||
return scancode >= SDL_SCANCODE_LCTRL && scancode <= SDL_SCANCODE_RGUI;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
hid_keyboard_convert_event(struct hid_keyboard *kb, struct hid_event *hid_event,
|
|
||||||
const SDL_KeyboardEvent *event) {
|
|
||||||
LOGV(
|
|
||||||
"Type: %s, Repeat: %s, Modifiers: %02x, Key: %02x",
|
|
||||||
event->type == SDL_KEYDOWN ? "down" : "up",
|
|
||||||
event->repeat != 0 ? "true" : "false",
|
|
||||||
sdl_keymod_to_hid_modifiers(event->keysym.mod),
|
|
||||||
event->keysym.scancode
|
|
||||||
);
|
|
||||||
|
|
||||||
hid_event->from_accessory_id = HID_KEYBOARD_ACCESSORY_ID;
|
|
||||||
|
|
||||||
SDL_Scancode scancode = event->keysym.scancode;
|
|
||||||
assert(scancode >= 0);
|
|
||||||
// SDL also generates events when only modifiers are pressed, we cannot
|
|
||||||
// ignore them totally, for example press 'a' first then press 'Control',
|
|
||||||
// if we ignore 'Control' event, only 'a' is sent.
|
|
||||||
if (scancode < HID_KEYBOARD_KEYS || scancode_is_modifier(scancode)) {
|
|
||||||
return convert_hid_keyboard_event(kb, hid_event, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
sc_key_processor_process_key(struct sc_key_processor *kp,
|
|
||||||
const SDL_KeyboardEvent *event) {
|
|
||||||
if (event->repeat) {
|
|
||||||
// In USB HID protocol, key repeat is handled by the host (Android), so
|
|
||||||
// just ignore key repeat here.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct hid_keyboard *kb = DOWNCAST(kp);
|
|
||||||
|
|
||||||
struct hid_event hid_event;
|
|
||||||
// Not all keys are supported, just ignore unsupported keys
|
|
||||||
if (hid_keyboard_convert_event(kb, &hid_event, event)) {
|
|
||||||
if (!aoa_push_hid_event(kb->aoa, &hid_event)) {
|
|
||||||
LOGW("Could request HID event");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
sc_key_processor_process_text(struct sc_key_processor *kp,
|
|
||||||
const SDL_TextInputEvent *event) {
|
|
||||||
(void) kp;
|
|
||||||
(void) event;
|
|
||||||
|
|
||||||
// Never forward text input via HID (all the keys are injected separately)
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
hid_keyboard_init(struct hid_keyboard *kb, struct aoa *aoa, unsigned lock_mod) {
|
|
||||||
kb->aoa = aoa;
|
|
||||||
|
|
||||||
// FIXME In practice, sending CAPS_LOCK immediately after fails with a Pipe
|
|
||||||
// error but we must know immediately if this fails or not
|
|
||||||
bool ok = aoa_setup_hid(aoa, HID_KEYBOARD_ACCESSORY_ID,
|
|
||||||
keyboard_report_desc,
|
|
||||||
ARRAY_LEN(keyboard_report_desc));
|
|
||||||
if (!ok) {
|
|
||||||
LOGW("Register HID for keyboard failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset all states
|
|
||||||
memset(kb->keys, false, HID_KEYBOARD_KEYS);
|
|
||||||
|
|
||||||
static const struct sc_key_processor_ops ops = {
|
|
||||||
.process_key = sc_key_processor_process_key,
|
|
||||||
.process_text = sc_key_processor_process_text,
|
|
||||||
};
|
|
||||||
|
|
||||||
kb->key_processor.ops = &ops;
|
|
||||||
|
|
||||||
// FIXME to avoid pipe error
|
|
||||||
usleep(100000);
|
|
||||||
send_mod_lock_state(kb, lock_mod);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
hid_keyboard_destroy(struct hid_keyboard *kb) {
|
|
||||||
// Unregister HID keyboard so the soft keyboard shows again on Android
|
|
||||||
bool ok = aoa_unregister_hid(kb->aoa, HID_KEYBOARD_ACCESSORY_ID);
|
|
||||||
if (!ok) {
|
|
||||||
LOGW("Could not unregister HID");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
#ifndef HID_KEYBOARD_H
|
|
||||||
#define HID_KEYBOARD_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
|
|
||||||
#include "aoa_hid.h"
|
|
||||||
#include "trait/key_processor.h"
|
|
||||||
|
|
||||||
// See "SDL2/SDL_scancode.h".
|
|
||||||
// Maybe SDL_Keycode is used by most people, but SDL_Scancode is taken from USB
|
|
||||||
// HID protocol.
|
|
||||||
// 0x65 is Application, typically AT-101 Keyboard ends here.
|
|
||||||
#define HID_KEYBOARD_KEYS 0x66
|
|
||||||
|
|
||||||
#define SC_MOD_MASK 0x3
|
|
||||||
#define SC_MOD_CAPSLOCK 0x1
|
|
||||||
#define SC_MOD_NUMLOCK 0x2
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HID keyboard events are sequence-based, every time keyboard state changes
|
|
||||||
* it sends an array of currently pressed keys, the host is responsible for
|
|
||||||
* compare events and determine which key becomes pressed and which key becomes
|
|
||||||
* released. In order to convert SDL_KeyboardEvent to HID events, we first use
|
|
||||||
* an array of keys to save each keys' state. And when a SDL_KeyboardEvent was
|
|
||||||
* emitted, we updated our state, and then we use a loop to generate HID
|
|
||||||
* events. The sequence of array elements is unimportant and when too much keys
|
|
||||||
* pressed at the same time (more than report count), we should generate
|
|
||||||
* phantom state. Don't forget that modifiers should be updated too, even for
|
|
||||||
* phantom state.
|
|
||||||
*/
|
|
||||||
struct hid_keyboard {
|
|
||||||
struct sc_key_processor key_processor; // key processor trait
|
|
||||||
|
|
||||||
struct aoa *aoa;
|
|
||||||
bool keys[HID_KEYBOARD_KEYS];
|
|
||||||
};
|
|
||||||
|
|
||||||
bool
|
|
||||||
hid_keyboard_init(struct hid_keyboard *kb, struct aoa *aoa, unsigned lock_mod);
|
|
||||||
|
|
||||||
void
|
|
||||||
hid_keyboard_destroy(struct hid_keyboard *kb);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -376,8 +376,6 @@ input_manager_process_key(struct input_manager *im,
|
|||||||
|
|
||||||
bool smod = is_shortcut_mod(im, mod);
|
bool smod = is_shortcut_mod(im, mod);
|
||||||
|
|
||||||
LOGD("=== %x", (int) mod);
|
|
||||||
|
|
||||||
if (down && !repeat) {
|
if (down && !repeat) {
|
||||||
if (keycode == im->last_keycode && mod == im->last_mod) {
|
if (keycode == im->last_keycode && mod == im->last_mod) {
|
||||||
++im->key_repeat;
|
++im->key_repeat;
|
||||||
|
|||||||
108
app/src/scrcpy.c
108
app/src/scrcpy.c
@@ -18,9 +18,6 @@
|
|||||||
#include "events.h"
|
#include "events.h"
|
||||||
#include "file_handler.h"
|
#include "file_handler.h"
|
||||||
#include "input_manager.h"
|
#include "input_manager.h"
|
||||||
#ifdef HAVE_AOA_HID
|
|
||||||
# include "hid_keyboard.h"
|
|
||||||
#endif
|
|
||||||
#include "keyboard_inject.h"
|
#include "keyboard_inject.h"
|
||||||
#include "mouse_inject.h"
|
#include "mouse_inject.h"
|
||||||
#include "recorder.h"
|
#include "recorder.h"
|
||||||
@@ -45,15 +42,7 @@ struct scrcpy {
|
|||||||
#endif
|
#endif
|
||||||
struct controller controller;
|
struct controller controller;
|
||||||
struct file_handler file_handler;
|
struct file_handler file_handler;
|
||||||
#ifdef HAVE_AOA_HID
|
struct sc_keyboard_inject keyboard_inject;
|
||||||
struct aoa aoa;
|
|
||||||
#endif
|
|
||||||
union {
|
|
||||||
struct sc_keyboard_inject keyboard_inject;
|
|
||||||
#ifdef HAVE_AOA_HID
|
|
||||||
struct hid_keyboard keyboard_hid;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
struct sc_mouse_inject mouse_inject;
|
struct sc_mouse_inject mouse_inject;
|
||||||
struct input_manager input_manager;
|
struct input_manager input_manager;
|
||||||
};
|
};
|
||||||
@@ -254,20 +243,8 @@ stream_on_eos(struct stream *stream, void *userdata) {
|
|||||||
SDL_PushEvent(&stop_event);
|
SDL_PushEvent(&stop_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned
|
|
||||||
to_sc_mod(SDL_Keymod sdl_mod) {
|
|
||||||
unsigned mod = 0;
|
|
||||||
if (sdl_mod & KMOD_CAPS) {
|
|
||||||
mod |= SC_MOD_CAPSLOCK;
|
|
||||||
}
|
|
||||||
if (sdl_mod & KMOD_NUM) {
|
|
||||||
mod |= SC_MOD_NUMLOCK;
|
|
||||||
}
|
|
||||||
return mod;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
scrcpy(struct scrcpy_options *options) {
|
scrcpy(const struct scrcpy_options *options) {
|
||||||
static struct scrcpy scrcpy;
|
static struct scrcpy scrcpy;
|
||||||
struct scrcpy *s = &scrcpy;
|
struct scrcpy *s = &scrcpy;
|
||||||
|
|
||||||
@@ -284,9 +261,6 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
bool v4l2_sink_initialized = false;
|
bool v4l2_sink_initialized = false;
|
||||||
#endif
|
#endif
|
||||||
bool stream_started = false;
|
bool stream_started = false;
|
||||||
#ifdef HAVE_AOA_HID
|
|
||||||
bool aoa_hid_initialized = false;
|
|
||||||
#endif
|
|
||||||
bool controller_initialized = false;
|
bool controller_initialized = false;
|
||||||
bool controller_started = false;
|
bool controller_started = false;
|
||||||
bool screen_initialized = false;
|
bool screen_initialized = false;
|
||||||
@@ -446,69 +420,8 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
struct sc_mouse_processor *mp = NULL;
|
struct sc_mouse_processor *mp = NULL;
|
||||||
|
|
||||||
if (options->control) {
|
if (options->control) {
|
||||||
if (options->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_HID) {
|
sc_keyboard_inject_init(&s->keyboard_inject, &s->controller, options);
|
||||||
#ifdef HAVE_AOA_HID
|
kp = &s->keyboard_inject.key_processor;
|
||||||
bool aoa_hid_ok = false;
|
|
||||||
|
|
||||||
char *serialno = NULL;
|
|
||||||
|
|
||||||
const char *serial = options->serial;
|
|
||||||
if (!serial) {
|
|
||||||
serialno = adb_get_serialno();
|
|
||||||
if (!serialno) {
|
|
||||||
LOGE("Could not get device serial");
|
|
||||||
goto aoa_hid_end;
|
|
||||||
}
|
|
||||||
serial = serialno;
|
|
||||||
LOGI("Device serial: %s", serial);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ok = aoa_init(&s->aoa, serial);
|
|
||||||
free(serialno);
|
|
||||||
if (!ok) {
|
|
||||||
goto aoa_hid_end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!aoa_start(&s->aoa)) {
|
|
||||||
aoa_destroy(&s->aoa);
|
|
||||||
goto aoa_hid_end;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: SDL_GetModState() always returns 0 here :/
|
|
||||||
unsigned mod = to_sc_mod(SDL_GetModState());
|
|
||||||
if (!hid_keyboard_init(&s->keyboard_hid, &s->aoa, mod)) {
|
|
||||||
aoa_join(&s->aoa);
|
|
||||||
aoa_stop(&s->aoa);
|
|
||||||
aoa_destroy(&s->aoa);
|
|
||||||
goto aoa_hid_end;
|
|
||||||
}
|
|
||||||
|
|
||||||
aoa_hid_ok = true;
|
|
||||||
kp = &s->keyboard_hid.key_processor;
|
|
||||||
|
|
||||||
aoa_hid_initialized = true;
|
|
||||||
|
|
||||||
aoa_hid_end:
|
|
||||||
if (!aoa_hid_ok) {
|
|
||||||
LOGE("Failed to enable HID over AOA, "
|
|
||||||
"fallback to default keyboard injection method "
|
|
||||||
"(-K/--keyboard-hid ignored)");
|
|
||||||
options->keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_INJECT;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
LOGE("HID over AOA is not supported on this platform, "
|
|
||||||
"fallback to default keyboard injection method "
|
|
||||||
"(-K/--keyboard-hid ignored)");
|
|
||||||
options->keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_INJECT;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// keyboard_input_mode may have been reset if HID mode failed
|
|
||||||
if (options->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_INJECT) {
|
|
||||||
sc_keyboard_inject_init(&s->keyboard_inject, &s->controller,
|
|
||||||
options);
|
|
||||||
kp = &s->keyboard_inject.key_processor;
|
|
||||||
}
|
|
||||||
|
|
||||||
sc_mouse_inject_init(&s->mouse_inject, &s->controller, &s->screen);
|
sc_mouse_inject_init(&s->mouse_inject, &s->controller, &s->screen);
|
||||||
mp = &s->mouse_inject.mouse_processor;
|
mp = &s->mouse_inject.mouse_processor;
|
||||||
@@ -527,12 +440,6 @@ aoa_hid_end:
|
|||||||
end:
|
end:
|
||||||
// The stream is not stopped explicitly, because it will stop by itself on
|
// The stream is not stopped explicitly, because it will stop by itself on
|
||||||
// end-of-stream
|
// end-of-stream
|
||||||
#ifdef HAVE_AOA_HID
|
|
||||||
if (aoa_hid_initialized) {
|
|
||||||
hid_keyboard_destroy(&s->keyboard_hid);
|
|
||||||
aoa_stop(&s->aoa);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (controller_started) {
|
if (controller_started) {
|
||||||
controller_stop(&s->controller);
|
controller_stop(&s->controller);
|
||||||
}
|
}
|
||||||
@@ -560,13 +467,6 @@ end:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_AOA_HID
|
|
||||||
if (aoa_hid_initialized) {
|
|
||||||
aoa_join(&s->aoa);
|
|
||||||
aoa_destroy(&s->aoa);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Destroy the screen only after the stream is guaranteed to be finished,
|
// Destroy the screen only after the stream is guaranteed to be finished,
|
||||||
// because otherwise the screen could receive new frames after destruction
|
// because otherwise the screen could receive new frames after destruction
|
||||||
if (screen_initialized) {
|
if (screen_initialized) {
|
||||||
|
|||||||
@@ -33,11 +33,6 @@ enum sc_lock_video_orientation {
|
|||||||
SC_LOCK_VIDEO_ORIENTATION_3,
|
SC_LOCK_VIDEO_ORIENTATION_3,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum sc_keyboard_input_mode {
|
|
||||||
SC_KEYBOARD_INPUT_MODE_INJECT,
|
|
||||||
SC_KEYBOARD_INPUT_MODE_HID,
|
|
||||||
};
|
|
||||||
|
|
||||||
#define SC_MAX_SHORTCUT_MODS 8
|
#define SC_MAX_SHORTCUT_MODS 8
|
||||||
|
|
||||||
enum sc_shortcut_mod {
|
enum sc_shortcut_mod {
|
||||||
@@ -73,7 +68,6 @@ struct scrcpy_options {
|
|||||||
const char *v4l2_device;
|
const char *v4l2_device;
|
||||||
enum sc_log_level log_level;
|
enum sc_log_level log_level;
|
||||||
enum sc_record_format record_format;
|
enum sc_record_format record_format;
|
||||||
enum sc_keyboard_input_mode keyboard_input_mode;
|
|
||||||
struct sc_port_range port_range;
|
struct sc_port_range port_range;
|
||||||
struct sc_shortcut_mods shortcut_mods;
|
struct sc_shortcut_mods shortcut_mods;
|
||||||
uint16_t max_size;
|
uint16_t max_size;
|
||||||
@@ -118,7 +112,6 @@ struct scrcpy_options {
|
|||||||
.v4l2_device = NULL, \
|
.v4l2_device = NULL, \
|
||||||
.log_level = SC_LOG_LEVEL_INFO, \
|
.log_level = SC_LOG_LEVEL_INFO, \
|
||||||
.record_format = SC_RECORD_FORMAT_AUTO, \
|
.record_format = SC_RECORD_FORMAT_AUTO, \
|
||||||
.keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_INJECT, \
|
|
||||||
.port_range = { \
|
.port_range = { \
|
||||||
.first = DEFAULT_LOCAL_PORT_RANGE_FIRST, \
|
.first = DEFAULT_LOCAL_PORT_RANGE_FIRST, \
|
||||||
.last = DEFAULT_LOCAL_PORT_RANGE_LAST, \
|
.last = DEFAULT_LOCAL_PORT_RANGE_LAST, \
|
||||||
@@ -158,6 +151,6 @@ struct scrcpy_options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
scrcpy(struct scrcpy_options *options);
|
scrcpy(const struct scrcpy_options *options);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#include "util/process.h"
|
#include "util/process.h"
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
@@ -51,151 +50,65 @@ search_executable(const char *file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum process_result
|
enum process_result
|
||||||
process_execute_redirect(const char *const argv[], pid_t *pid, int *pipe_stdin,
|
process_execute(const char *const argv[], pid_t *pid) {
|
||||||
int *pipe_stdout, int *pipe_stderr) {
|
int fd[2];
|
||||||
int in[2];
|
|
||||||
int out[2];
|
|
||||||
int err[2];
|
|
||||||
int internal[2]; // communication between parent and children
|
|
||||||
|
|
||||||
if (pipe(internal) == -1) {
|
if (pipe(fd) == -1) {
|
||||||
perror("pipe");
|
perror("pipe");
|
||||||
return PROCESS_ERROR_GENERIC;
|
return PROCESS_ERROR_GENERIC;
|
||||||
}
|
}
|
||||||
if (pipe_stdin) {
|
|
||||||
if (pipe(in) == -1) {
|
enum process_result ret = PROCESS_SUCCESS;
|
||||||
perror("pipe");
|
|
||||||
close(internal[0]);
|
|
||||||
close(internal[1]);
|
|
||||||
return PROCESS_ERROR_GENERIC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pipe_stdout) {
|
|
||||||
if (pipe(out) == -1) {
|
|
||||||
perror("pipe");
|
|
||||||
// clean up
|
|
||||||
if (pipe_stdin) {
|
|
||||||
close(in[0]);
|
|
||||||
close(in[1]);
|
|
||||||
}
|
|
||||||
close(internal[0]);
|
|
||||||
close(internal[1]);
|
|
||||||
return PROCESS_ERROR_GENERIC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pipe_stderr) {
|
|
||||||
if (pipe(err) == -1) {
|
|
||||||
perror("pipe");
|
|
||||||
// clean up
|
|
||||||
if (pipe_stdout) {
|
|
||||||
close(out[0]);
|
|
||||||
close(out[1]);
|
|
||||||
}
|
|
||||||
if (pipe_stdin) {
|
|
||||||
close(in[0]);
|
|
||||||
close(in[1]);
|
|
||||||
}
|
|
||||||
close(internal[0]);
|
|
||||||
close(internal[1]);
|
|
||||||
return PROCESS_ERROR_GENERIC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*pid = fork();
|
*pid = fork();
|
||||||
if (*pid == -1) {
|
if (*pid == -1) {
|
||||||
perror("fork");
|
perror("fork");
|
||||||
// clean up
|
ret = PROCESS_ERROR_GENERIC;
|
||||||
if (pipe_stderr) {
|
goto end;
|
||||||
close(err[0]);
|
|
||||||
close(err[1]);
|
|
||||||
}
|
|
||||||
if (pipe_stdout) {
|
|
||||||
close(out[0]);
|
|
||||||
close(out[1]);
|
|
||||||
}
|
|
||||||
if (pipe_stdin) {
|
|
||||||
close(in[0]);
|
|
||||||
close(in[1]);
|
|
||||||
}
|
|
||||||
close(internal[0]);
|
|
||||||
close(internal[1]);
|
|
||||||
return PROCESS_ERROR_GENERIC;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*pid == 0) {
|
if (*pid > 0) {
|
||||||
if (pipe_stdin) {
|
// parent close write side
|
||||||
if (in[0] != STDIN_FILENO) {
|
close(fd[1]);
|
||||||
dup2(in[0], STDIN_FILENO);
|
fd[1] = -1;
|
||||||
close(in[0]);
|
// wait for EOF or receive errno from child
|
||||||
}
|
if (read(fd[0], &ret, sizeof(ret)) == -1) {
|
||||||
close(in[1]);
|
perror("read");
|
||||||
|
ret = PROCESS_ERROR_GENERIC;
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
if (pipe_stdout) {
|
} else if (*pid == 0) {
|
||||||
if (out[1] != STDOUT_FILENO) {
|
// child close read side
|
||||||
dup2(out[1], STDOUT_FILENO);
|
close(fd[0]);
|
||||||
close(out[1]);
|
if (fcntl(fd[1], F_SETFD, FD_CLOEXEC) == 0) {
|
||||||
|
execvp(argv[0], (char *const *)argv);
|
||||||
|
if (errno == ENOENT) {
|
||||||
|
ret = PROCESS_ERROR_MISSING_BINARY;
|
||||||
|
} else {
|
||||||
|
ret = PROCESS_ERROR_GENERIC;
|
||||||
}
|
}
|
||||||
close(out[0]);
|
|
||||||
}
|
|
||||||
if (pipe_stderr) {
|
|
||||||
if (err[1] != STDERR_FILENO) {
|
|
||||||
dup2(err[1], STDERR_FILENO);
|
|
||||||
close(err[1]);
|
|
||||||
}
|
|
||||||
close(err[0]);
|
|
||||||
}
|
|
||||||
close(internal[0]);
|
|
||||||
enum process_result err;
|
|
||||||
if (fcntl(internal[1], F_SETFD, FD_CLOEXEC) == 0) {
|
|
||||||
execvp(argv[0], (char *const *) argv);
|
|
||||||
perror("exec");
|
perror("exec");
|
||||||
err = errno == ENOENT ? PROCESS_ERROR_MISSING_BINARY
|
|
||||||
: PROCESS_ERROR_GENERIC;
|
|
||||||
} else {
|
} else {
|
||||||
perror("fcntl");
|
perror("fcntl");
|
||||||
err = PROCESS_ERROR_GENERIC;
|
ret = PROCESS_ERROR_GENERIC;
|
||||||
}
|
}
|
||||||
// send err to the parent
|
// send ret to the parent
|
||||||
if (write(internal[1], &err, sizeof(err)) == -1) {
|
if (write(fd[1], &ret, sizeof(ret)) == -1) {
|
||||||
perror("write");
|
perror("write");
|
||||||
}
|
}
|
||||||
close(internal[1]);
|
// close write side before exiting
|
||||||
|
close(fd[1]);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// parent
|
end:
|
||||||
assert(*pid > 0);
|
if (fd[0] != -1) {
|
||||||
|
close(fd[0]);
|
||||||
close(internal[1]);
|
|
||||||
|
|
||||||
enum process_result res = PROCESS_SUCCESS;
|
|
||||||
// wait for EOF or receive err from child
|
|
||||||
if (read(internal[0], &res, sizeof(res)) == -1) {
|
|
||||||
perror("read");
|
|
||||||
res = PROCESS_ERROR_GENERIC;
|
|
||||||
}
|
}
|
||||||
|
if (fd[1] != -1) {
|
||||||
close(internal[0]);
|
close(fd[1]);
|
||||||
|
|
||||||
if (pipe_stdin) {
|
|
||||||
close(in[0]);
|
|
||||||
*pipe_stdin = in[1];
|
|
||||||
}
|
}
|
||||||
if (pipe_stdout) {
|
return ret;
|
||||||
*pipe_stdout = out[0];
|
|
||||||
close(out[1]);
|
|
||||||
}
|
|
||||||
if (pipe_stderr) {
|
|
||||||
*pipe_stderr = err[0];
|
|
||||||
close(err[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum process_result
|
|
||||||
process_execute(const char *const argv[], pid_t *pid) {
|
|
||||||
return process_execute_redirect(argv, pid, NULL, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -262,15 +175,3 @@ is_regular_file(const char *path) {
|
|||||||
}
|
}
|
||||||
return S_ISREG(path_stat.st_mode);
|
return S_ISREG(path_stat.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
|
||||||
read_pipe(int pipe, char *data, size_t len) {
|
|
||||||
return read(pipe, data, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
close_pipe(int pipe) {
|
|
||||||
if (close(pipe)) {
|
|
||||||
perror("close pipe");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -23,129 +23,38 @@ build_cmd(char *cmd, size_t len, const char *const argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum process_result
|
enum process_result
|
||||||
process_execute_redirect(const char *const argv[], HANDLE *handle,
|
process_execute(const char *const argv[], HANDLE *handle) {
|
||||||
HANDLE *pipe_stdin, HANDLE *pipe_stdout,
|
|
||||||
HANDLE *pipe_stderr) {
|
|
||||||
enum process_result ret = PROCESS_ERROR_GENERIC;
|
|
||||||
|
|
||||||
SECURITY_ATTRIBUTES sa;
|
|
||||||
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
|
|
||||||
sa.lpSecurityDescriptor = NULL;
|
|
||||||
sa.bInheritHandle = TRUE;
|
|
||||||
|
|
||||||
HANDLE stdin_read_handle;
|
|
||||||
HANDLE stdout_write_handle;
|
|
||||||
HANDLE stderr_write_handle;
|
|
||||||
if (pipe_stdin) {
|
|
||||||
if (!CreatePipe(&stdin_read_handle, pipe_stdin, &sa, 0)) {
|
|
||||||
perror("pipe");
|
|
||||||
return PROCESS_ERROR_GENERIC;
|
|
||||||
}
|
|
||||||
if (!SetHandleInformation(*pipe_stdin, HANDLE_FLAG_INHERIT, 0)) {
|
|
||||||
LOGE("SetHandleInformation stdin failed");
|
|
||||||
goto error_close_stdin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pipe_stdout) {
|
|
||||||
if (!CreatePipe(pipe_stdout, &stdout_write_handle, &sa, 0)) {
|
|
||||||
perror("pipe");
|
|
||||||
goto error_close_stdin;
|
|
||||||
}
|
|
||||||
if (!SetHandleInformation(*pipe_stdout, HANDLE_FLAG_INHERIT, 0)) {
|
|
||||||
LOGE("SetHandleInformation stdout failed");
|
|
||||||
goto error_close_stdout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pipe_stderr) {
|
|
||||||
if (!CreatePipe(pipe_stderr, &stderr_write_handle, &sa, 0)) {
|
|
||||||
perror("pipe");
|
|
||||||
goto error_close_stdout;
|
|
||||||
}
|
|
||||||
if (!SetHandleInformation(*pipe_stderr, HANDLE_FLAG_INHERIT, 0)) {
|
|
||||||
LOGE("SetHandleInformation stderr failed");
|
|
||||||
goto error_close_stderr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
STARTUPINFOW si;
|
STARTUPINFOW si;
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
memset(&si, 0, sizeof(si));
|
memset(&si, 0, sizeof(si));
|
||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
if (pipe_stdin || pipe_stdout || pipe_stderr) {
|
|
||||||
si.dwFlags = STARTF_USESTDHANDLES;
|
|
||||||
if (pipe_stdin) {
|
|
||||||
si.hStdInput = stdin_read_handle;
|
|
||||||
}
|
|
||||||
if (pipe_stdout) {
|
|
||||||
si.hStdOutput = stdout_write_handle;
|
|
||||||
}
|
|
||||||
if (pipe_stderr) {
|
|
||||||
si.hStdError = stderr_write_handle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char *cmd = malloc(CMD_MAX_LEN);
|
char *cmd = malloc(CMD_MAX_LEN);
|
||||||
if (!cmd || !build_cmd(cmd, CMD_MAX_LEN, argv)) {
|
if (!cmd || !build_cmd(cmd, CMD_MAX_LEN, argv)) {
|
||||||
*handle = NULL;
|
*handle = NULL;
|
||||||
goto error_close_stderr;
|
return PROCESS_ERROR_GENERIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *wide = utf8_to_wide_char(cmd);
|
wchar_t *wide = utf8_to_wide_char(cmd);
|
||||||
free(cmd);
|
free(cmd);
|
||||||
if (!wide) {
|
if (!wide) {
|
||||||
LOGC("Could not allocate wide char string");
|
LOGC("Could not allocate wide char string");
|
||||||
goto error_close_stderr;
|
return PROCESS_ERROR_GENERIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CreateProcessW(NULL, wide, NULL, NULL, TRUE, 0, NULL, NULL, &si,
|
if (!CreateProcessW(NULL, wide, NULL, NULL, FALSE, 0, NULL, NULL, &si,
|
||||||
&pi)) {
|
&pi)) {
|
||||||
free(wide);
|
free(wide);
|
||||||
*handle = NULL;
|
*handle = NULL;
|
||||||
|
|
||||||
if (GetLastError() == ERROR_FILE_NOT_FOUND) {
|
if (GetLastError() == ERROR_FILE_NOT_FOUND) {
|
||||||
ret = PROCESS_ERROR_MISSING_BINARY;
|
return PROCESS_ERROR_MISSING_BINARY;
|
||||||
}
|
}
|
||||||
goto error_close_stderr;
|
return PROCESS_ERROR_GENERIC;
|
||||||
}
|
|
||||||
|
|
||||||
// These handles are used by the child process, close them for this process
|
|
||||||
if (pipe_stdin) {
|
|
||||||
CloseHandle(stdin_read_handle);
|
|
||||||
}
|
|
||||||
if (pipe_stdout) {
|
|
||||||
CloseHandle(stdout_write_handle);
|
|
||||||
}
|
|
||||||
if (pipe_stderr) {
|
|
||||||
CloseHandle(stderr_write_handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(wide);
|
free(wide);
|
||||||
*handle = pi.hProcess;
|
*handle = pi.hProcess;
|
||||||
|
|
||||||
return PROCESS_SUCCESS;
|
return PROCESS_SUCCESS;
|
||||||
|
|
||||||
error_close_stderr:
|
|
||||||
if (pipe_stderr) {
|
|
||||||
CloseHandle(*pipe_stderr);
|
|
||||||
CloseHandle(stderr_write_handle);
|
|
||||||
}
|
|
||||||
error_close_stdout:
|
|
||||||
if (pipe_stdout) {
|
|
||||||
CloseHandle(*pipe_stdout);
|
|
||||||
CloseHandle(stdout_write_handle);
|
|
||||||
}
|
|
||||||
error_close_stdin:
|
|
||||||
if (pipe_stdin) {
|
|
||||||
CloseHandle(*pipe_stdin);
|
|
||||||
CloseHandle(stdin_read_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum process_result
|
|
||||||
process_execute(const char *const argv[], HANDLE *handle) {
|
|
||||||
return process_execute_redirect(argv, handle, NULL, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -207,19 +116,3 @@ is_regular_file(const char *path) {
|
|||||||
}
|
}
|
||||||
return S_ISREG(path_stat.st_mode);
|
return S_ISREG(path_stat.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
|
||||||
read_pipe(HANDLE pipe, char *data, size_t len) {
|
|
||||||
DWORD r;
|
|
||||||
if (!ReadFile(pipe, data, len, &r, NULL)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
close_pipe(HANDLE pipe) {
|
|
||||||
if (!CloseHandle(pipe)) {
|
|
||||||
LOGW("Cannot close pipe");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -116,8 +116,9 @@ net_send(socket_t socket, const void *buf, size_t len) {
|
|||||||
ssize_t
|
ssize_t
|
||||||
net_send_all(socket_t socket, const void *buf, size_t len) {
|
net_send_all(socket_t socket, const void *buf, size_t len) {
|
||||||
size_t copied = 0;
|
size_t copied = 0;
|
||||||
|
ssize_t w = 0;
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
ssize_t w = send(socket, buf, len, 0);
|
w = send(socket, buf, len, 0);
|
||||||
if (w == -1) {
|
if (w == -1) {
|
||||||
return copied ? (ssize_t) copied : -1;
|
return copied ? (ssize_t) copied : -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,18 +19,3 @@ process_check_success(process_t proc, const char *name, bool close) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
|
||||||
read_pipe_all(pipe_t pipe, char *data, size_t len) {
|
|
||||||
size_t copied = 0;
|
|
||||||
while (len > 0) {
|
|
||||||
ssize_t r = read_pipe(pipe, data, len);
|
|
||||||
if (r <= 0) {
|
|
||||||
return copied ? (ssize_t) copied : r;
|
|
||||||
}
|
|
||||||
len -= r;
|
|
||||||
data += r;
|
|
||||||
copied += r;
|
|
||||||
}
|
|
||||||
return copied;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
# define NO_EXIT_CODE -1u // max value as unsigned
|
# define NO_EXIT_CODE -1u // max value as unsigned
|
||||||
typedef HANDLE process_t;
|
typedef HANDLE process_t;
|
||||||
typedef DWORD exit_code_t;
|
typedef DWORD exit_code_t;
|
||||||
typedef HANDLE pipe_t;
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -30,7 +29,6 @@
|
|||||||
# define NO_EXIT_CODE -1
|
# define NO_EXIT_CODE -1
|
||||||
typedef pid_t process_t;
|
typedef pid_t process_t;
|
||||||
typedef int exit_code_t;
|
typedef int exit_code_t;
|
||||||
typedef int pipe_t;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -44,14 +42,6 @@ enum process_result {
|
|||||||
enum process_result
|
enum process_result
|
||||||
process_execute(const char *const argv[], process_t *process);
|
process_execute(const char *const argv[], process_t *process);
|
||||||
|
|
||||||
enum process_result
|
|
||||||
process_execute_redirect(const char *const argv[], process_t *process,
|
|
||||||
pipe_t *pipe_stdin, pipe_t *pipe_stdout,
|
|
||||||
pipe_t *pipe_stderr);
|
|
||||||
|
|
||||||
bool
|
|
||||||
process_terminate(process_t pid);
|
|
||||||
|
|
||||||
// kill the process
|
// kill the process
|
||||||
bool
|
bool
|
||||||
process_terminate(process_t pid);
|
process_terminate(process_t pid);
|
||||||
@@ -88,13 +78,4 @@ get_executable_path(void);
|
|||||||
bool
|
bool
|
||||||
is_regular_file(const char *path);
|
is_regular_file(const char *path);
|
||||||
|
|
||||||
ssize_t
|
|
||||||
read_pipe(pipe_t pipe, char *data, size_t len);
|
|
||||||
|
|
||||||
ssize_t
|
|
||||||
read_pipe_all(pipe_t pipe, char *data, size_t len);
|
|
||||||
|
|
||||||
void
|
|
||||||
close_pipe(pipe_t pipe);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -183,11 +183,8 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
|
|||||||
goto error_mutex_destroy;
|
goto error_mutex_destroy;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AVOutputFormat *format = find_muxer("v4l2");
|
// FIXME
|
||||||
if (!format) {
|
const AVOutputFormat *format = find_muxer("video4linux2,v4l2");
|
||||||
// Alternative name
|
|
||||||
format = find_muxer("video4linux2");
|
|
||||||
}
|
|
||||||
if (!format) {
|
if (!format) {
|
||||||
LOGE("Could not find v4l2 muxer");
|
LOGE("Could not find v4l2 muxer");
|
||||||
goto error_cond_destroy;
|
goto error_cond_destroy;
|
||||||
|
|||||||
Reference in New Issue
Block a user