Compare commits
65 Commits
rotatedevi
...
threadwait
Author | SHA1 | Date | |
---|---|---|---|
d76c7c3029 | |||
f2f032a494 | |||
728b976aae | |||
ff583bdde8 | |||
429153abfb | |||
5031b2c8ff | |||
4adf5fde6d | |||
e050cfdcd6 | |||
dc7c677728 | |||
3504c0016b | |||
89d1602185 | |||
566ba766af | |||
a0af402d96 | |||
600df37753 | |||
902b99174d | |||
cd69eb4a4f | |||
ae2d094362 | |||
c5f5d1e456 | |||
63286424bb | |||
da18c9cdab | |||
d3281f4b67 | |||
1982bc439b | |||
ef56cc6ff7 | |||
c0f428eb05 | |||
4794ca8ae7 | |||
f903cd376d | |||
e8127375ae | |||
1144f64214 | |||
39356602ed | |||
0fb22c3e98 | |||
96bd2c974d | |||
dc7fcf3c7a | |||
2a3a9d4ea9 | |||
ca0031cbde | |||
d1a9a76cc6 | |||
a8ceaf5284 | |||
83d48267a7 | |||
db6252e52b | |||
229eeb24a2 | |||
f9786e5034 | |||
78a320a763 | |||
7d5845196e | |||
31bd95022b | |||
4687a0ebac | |||
6965d051ae | |||
71df3175bd | |||
a0f8e7fd9f | |||
e4cebc8d4c | |||
ba1b36758e | |||
ad92a192b5 | |||
81a8e503e5 | |||
242e57d69b | |||
024c2f7e6b | |||
1eae139b6e | |||
419c869c9c | |||
929bf48c7e | |||
d950383b72 | |||
61274a7cdb | |||
64bcac9157 | |||
3259c60b22 | |||
e0b117de13 | |||
684e0abb74 | |||
86fcd89d80 | |||
8bc056b9c6 | |||
8ec077ce1b |
8
BUILD.md
8
BUILD.md
@ -40,7 +40,7 @@ Install the required packages from your package manager.
|
||||
|
||||
```bash
|
||||
# runtime dependencies
|
||||
sudo apt install ffmpeg libsdl2-2.0-0
|
||||
sudo apt install ffmpeg libsdl2-2.0-0 adb
|
||||
|
||||
# client build dependencies
|
||||
sudo apt install gcc git pkg-config meson ninja-build \
|
||||
@ -233,10 +233,10 @@ You can then [run](README.md#run) _scrcpy_.
|
||||
|
||||
## Prebuilt server
|
||||
|
||||
- [`scrcpy-server-v1.11`][direct-scrcpy-server]
|
||||
_(SHA-256: ff3a454012e91d9185cfe8ca7691cea16c43a7dcc08e92fa47ab9f0ea675abd1)_
|
||||
- [`scrcpy-server-v1.12.1`][direct-scrcpy-server]
|
||||
_(SHA-256: 63e569c8a1d0c1df31d48c4214871c479a601782945fed50c1e61167d78266ea)_
|
||||
|
||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.11/scrcpy-server-v1.11
|
||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.12.1/scrcpy-server-v1.12.1
|
||||
|
||||
Download the prebuilt server somewhere, and specify its path during the Meson
|
||||
configuration:
|
||||
|
13
DEVELOP.md
13
DEVELOP.md
@ -189,7 +189,7 @@ The client uses 4 threads:
|
||||
recording,
|
||||
- the **controller** thread, sending _control messages_ to the server,
|
||||
- the **receiver** thread (managed by the controller), receiving _device
|
||||
messages_ from the client.
|
||||
messages_ from the server.
|
||||
|
||||
In addition, another thread can be started if necessary to handle APK
|
||||
installation or file push requests (via drag&drop on the main window) or to
|
||||
@ -214,7 +214,7 @@ When a new decoded frame is available, the decoder _swaps_ the decoding and
|
||||
rendering frame (with proper synchronization). Thus, it immediatly starts
|
||||
to decode a new frame while the main thread renders the last one.
|
||||
|
||||
If a [recorder] is present (i.e. `--record` is enabled), then its muxes the raw
|
||||
If a [recorder] is present (i.e. `--record` is enabled), then it muxes the raw
|
||||
H.264 packet to the output video file.
|
||||
|
||||
[stream]: https://github.com/Genymobile/scrcpy/blob/ffe0417228fb78ab45b7ee4e202fc06fc8875bf3/app/src/stream.h
|
||||
@ -282,6 +282,15 @@ meson x -Dserver_debugger=true
|
||||
meson configure x -Dserver_debugger=true
|
||||
```
|
||||
|
||||
If your device runs Android 8 or below, set the `server_debugger_method` to
|
||||
`old` in addition:
|
||||
|
||||
```bash
|
||||
meson x -Dserver_debugger=true -Dserver_debugger_method=old
|
||||
# or, if x is already configured
|
||||
meson configure x -Dserver_debugger=true -Dserver_debugger_method=old
|
||||
```
|
||||
|
||||
Then recompile.
|
||||
|
||||
When you start scrcpy, it will start a debugger on port 5005 on the device.
|
||||
|
84
FAQ.ko.md
Normal file
84
FAQ.ko.md
Normal file
@ -0,0 +1,84 @@
|
||||
# 자주하는 질문 (FAQ)
|
||||
|
||||
다음은 자주 제보되는 문제들과 그들의 현황입니다.
|
||||
|
||||
|
||||
### Window 운영체제에서, 디바이스가 발견되지 않습니다.
|
||||
|
||||
가장 흔한 제보는 `adb`에 발견되지 않는 디바이스 혹은 권한 관련 문제입니다.
|
||||
다음 명령어를 호출하여 모든 것들에 이상이 없는지 확인하세요:
|
||||
|
||||
adb devices
|
||||
|
||||
Window는 당신의 디바이스를 감지하기 위해 [drivers]가 필요할 수도 있습니다.
|
||||
|
||||
[drivers]: https://developer.android.com/studio/run/oem-usb.html
|
||||
|
||||
|
||||
### 내 디바이스의 미러링만 가능하고, 디바이스와 상호작용을 할 수 없습니다.
|
||||
|
||||
일부 디바이스에서는, [simulating input]을 허용하기 위해서 한가지 옵션을 활성화해야 할 수도 있습니다.
|
||||
개발자 옵션에서 (developer options) 다음을 활성화 하세요:
|
||||
|
||||
> **USB debugging (Security settings)**
|
||||
> _권한 부여와 USB 디버깅을 통한 simulating input을 허용한다_
|
||||
|
||||
[simulating input]: https://github.com/Genymobile/scrcpy/issues/70#issuecomment-373286323
|
||||
|
||||
|
||||
### 마우스 클릭이 다른 곳에 적용됩니다.
|
||||
|
||||
Mac 운영체제에서, HiDPI support 와 여러 스크린 창이 있는 경우, 입력 위치가 잘못 파악될 수 있습니다.
|
||||
[issue 15]를 참고하세요.
|
||||
|
||||
[issue 15]: https://github.com/Genymobile/scrcpy/issues/15
|
||||
|
||||
차선책은 HiDPI support을 비활성화 하고 build하는 방법입니다:
|
||||
|
||||
```bash
|
||||
meson x --buildtype release -Dhidpi_support=false
|
||||
```
|
||||
|
||||
하지만, 동영상은 낮은 해상도로 재생될 것 입니다.
|
||||
|
||||
|
||||
### HiDPI display의 화질이 낮습니다.
|
||||
|
||||
Windows에서는, [scaling behavior] 환경을 설정해야 할 수도 있습니다.
|
||||
|
||||
> `scrcpy.exe` > Properties > Compatibility > Change high DPI settings >
|
||||
> Override high DPI scaling behavior > Scaling performed by: _Application_.
|
||||
|
||||
[scaling behavior]: https://github.com/Genymobile/scrcpy/issues/40#issuecomment-424466723
|
||||
|
||||
|
||||
### KWin compositor가 실행되지 않습니다
|
||||
|
||||
Plasma Desktop에서는,_scrcpy_ 가 실행중에는 compositor가 비활성화 됩니다.
|
||||
|
||||
차석책으로는, ["Block compositing"를 비활성화하세요][kwin].
|
||||
|
||||
[kwin]: https://github.com/Genymobile/scrcpy/issues/114#issuecomment-378778613
|
||||
|
||||
|
||||
###비디오 스트림을 열 수 없는 에러가 발생합니다.(Could not open video stream).
|
||||
|
||||
여러가지 원인이 있을 수 있습니다. 가장 흔한 원인은 디바이스의 하드웨어 인코더(hardware encoder)가
|
||||
주어진 해상도를 인코딩할 수 없는 경우입니다.
|
||||
|
||||
```
|
||||
ERROR: Exception on thread Thread[main,5,main]
|
||||
android.media.MediaCodec$CodecException: Error 0xfffffc0e
|
||||
...
|
||||
Exit due to uncaughtException in main thread:
|
||||
ERROR: Could not open video stream
|
||||
INFO: Initial texture: 1080x2336
|
||||
```
|
||||
|
||||
더 낮은 해상도로 시도 해보세요:
|
||||
|
||||
```
|
||||
scrcpy -m 1920
|
||||
scrcpy -m 1024
|
||||
scrcpy -m 800
|
||||
```
|
2
LICENSE
2
LICENSE
@ -188,7 +188,7 @@
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright (C) 2018 Genymobile
|
||||
Copyright (C) 2018-2019 Romain Vimont
|
||||
Copyright (C) 2018-2020 Romain Vimont
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
498
README.ko.md
Normal file
498
README.ko.md
Normal file
@ -0,0 +1,498 @@
|
||||
# scrcpy (v1.11)
|
||||
|
||||
This document will be updated frequently along with the original Readme file
|
||||
이 문서는 원어 리드미 파일의 업데이트에 따라 종종 업데이트 될 것입니다
|
||||
|
||||
이 어플리케이션은 UBS ( 혹은 [TCP/IP][article-tcpip] ) 로 연결된 Android 디바이스를 화면에 보여주고 관리하는 것을 제공합니다.
|
||||
_GNU/Linux_, _Windows_ 와 _macOS_ 상에서 작동합니다.
|
||||
(아래 설명에서 디바이스는 안드로이드 핸드폰을 의미합니다.)
|
||||
|
||||
[article-tcpip]:https://www.genymotion.com/blog/open-source-project-scrcpy-now-works-wirelessly/
|
||||
|
||||

|
||||
|
||||
주요 기능은 다음과 같습니다.
|
||||
|
||||
- **가벼움** (기본적이며 디바이스의 화면만을 보여줌)
|
||||
- **뛰어난 성능** (30~60fps)
|
||||
- **높은 품질** (1920×1080 이상의 해상도)
|
||||
- **빠른 반응 속도** ([35~70ms][lowlatency])
|
||||
- **짧은 부팅 시간** (첫 사진을 보여주는데 최대 1초 소요됨)
|
||||
- **장치 설치와는 무관함** (디바이스에 설치하지 않아도 됨)
|
||||
|
||||
[lowlatency]: https://github.com/Genymobile/scrcpy/pull/646
|
||||
|
||||
|
||||
## 요구사항
|
||||
|
||||
안드로이드 장치는 최소 API 21 (Android 5.0) 을 필요로 합니다.
|
||||
|
||||
디바이스에 [adb debugging][enable-adb]이 가능한지 확인하십시오.
|
||||
|
||||
[enable-adb]: https://developer.android.com/studio/command-line/adb.html#Enabling
|
||||
|
||||
어떤 디바이스에서는, 키보드와 마우스를 사용하기 위해서 [추가 옵션][control] 이 필요하기도 합니다.
|
||||
|
||||
[control]: https://github.com/Genymobile/scrcpy/issues/70#issuecomment-373286323
|
||||
|
||||
|
||||
## 앱 설치하기
|
||||
|
||||
|
||||
### Linux (리눅스)
|
||||
|
||||
리눅스 상에서는 보통 [어플을 직접 설치][BUILD] 해야합니다. 어렵지 않으므로 걱정하지 않아도 됩니다.
|
||||
|
||||
[BUILD]:https://github.com/Genymobile/scrcpy/blob/master/BUILD.md
|
||||
|
||||
[Snap] 패키지가 가능합니다 : [`scrcpy`][snap-link].
|
||||
|
||||
[snap-link]: https://snapstats.org/snaps/scrcpy
|
||||
|
||||
[snap]: https://en.wikipedia.org/wiki/Snappy_(package_manager)
|
||||
|
||||
Arch Linux에서, [AUR] 패키지가 가능합니다 : [`scrcpy`][aur-link].
|
||||
|
||||
[AUR]: https://wiki.archlinux.org/index.php/Arch_User_Repository
|
||||
[aur-link]: https://aur.archlinux.org/packages/scrcpy/
|
||||
|
||||
Gentoo에서 ,[Ebuild] 가 가능합니다 : [`scrcpy/`][ebuild-link].
|
||||
|
||||
[Ebuild]: https://wiki.gentoo.org/wiki/Ebuild
|
||||
[ebuild-link]: https://github.com/maggu2810/maggu2810-overlay/tree/master/app-mobilephone/scrcpy
|
||||
|
||||
|
||||
### Windows (윈도우)
|
||||
|
||||
윈도우 상에서, 간단하게 설치하기 위해 종속성이 있는 사전 구축된 아카이브가 제공됩니다 (`adb` 포함) :
|
||||
해당 파일은 Readme원본 링크를 통해서 다운로드가 가능합니다.
|
||||
- [`scrcpy-win`][direct-win]
|
||||
|
||||
[direct-win]: https://github.com/Genymobile/scrcpy/blob/master/README.md#windows
|
||||
|
||||
|
||||
[어플을 직접 설치][BUILD] 할 수도 있습니다.
|
||||
|
||||
|
||||
### macOS (맥 OS)
|
||||
|
||||
이 어플리케이션은 아래 사항을 따라 설치한다면 [Homebrew] 에서도 사용 가능합니다 :
|
||||
|
||||
[Homebrew]: https://brew.sh/
|
||||
|
||||
```bash
|
||||
brew install scrcpy
|
||||
```
|
||||
|
||||
`PATH` 로부터 접근 가능한 `adb` 가 필요합니다. 아직 설치하지 않았다면 다음을 따라 설치해야 합니다 :
|
||||
|
||||
```bash
|
||||
brew cask install android-platform-tools
|
||||
```
|
||||
|
||||
[어플을 직접 설치][BUILD] 할 수도 있습니다.
|
||||
|
||||
|
||||
## 실행
|
||||
|
||||
안드로이드 디바이스를 연결하고 실행하십시오:
|
||||
|
||||
```bash
|
||||
scrcpy
|
||||
```
|
||||
|
||||
다음과 같이 명령창 옵션 기능도 제공합니다.
|
||||
|
||||
```bash
|
||||
scrcpy --help
|
||||
```
|
||||
|
||||
## 기능
|
||||
|
||||
### 캡쳐 환경 설정
|
||||
|
||||
|
||||
###사이즈 재정의
|
||||
|
||||
가끔씩 성능을 향상시키기위해 안드로이드 디바이스를 낮은 해상도에서 미러링하는 것이 유용할 때도 있습니다.
|
||||
|
||||
너비와 높이를 제한하기 위해 특정 값으로 지정할 수 있습니다 (e.g. 1024) :
|
||||
|
||||
```bash
|
||||
scrcpy --max-size 1024
|
||||
scrcpy -m 1024 # 축약 버전
|
||||
```
|
||||
|
||||
이 외의 크기도 디바이스의 가로 세로 비율이 유지된 상태에서 계산됩니다.
|
||||
이러한 방식으로 디바이스 상에서 1920×1080 는 모니터 상에서1024×576로 미러링될 것 입니다.
|
||||
|
||||
|
||||
### bit-rate 변경
|
||||
|
||||
기본 bit-rate 는 8 Mbps입니다. 비디오 bit-rate 를 변경하기 위해선 다음과 같이 입력하십시오 (e.g. 2 Mbps로 변경):
|
||||
|
||||
```bash
|
||||
scrcpy --bit-rate 2M
|
||||
scrcpy -b 2M # 축약 버전
|
||||
```
|
||||
|
||||
###프레임 비율 제한
|
||||
|
||||
안드로이드 버전 10이상의 디바이스에서는, 다음의 명령어로 캡쳐 화면의 프레임 비율을 제한할 수 있습니다:
|
||||
|
||||
```bash
|
||||
scrcpy --max-fps 15
|
||||
```
|
||||
|
||||
|
||||
### Crop (잘라내기)
|
||||
|
||||
디바이스 화면은 화면의 일부만 미러링하기 위해 잘라질 것입니다.
|
||||
|
||||
예를 들어, *Oculus Go* 의 한 쪽 눈만 미러링할 때 유용합니다 :
|
||||
|
||||
```bash
|
||||
scrcpy --crop 1224:1440:0:0 # 1224x1440 at offset (0,0)
|
||||
scrcpy -c 1224:1440:0:0 # 축약 버전
|
||||
```
|
||||
|
||||
만약 `--max-size` 도 지정하는 경우, 잘라낸 다음에 재정의된 크기가 적용될 것입니다.
|
||||
|
||||
|
||||
### 화면 녹화
|
||||
|
||||
미러링하는 동안 화면 녹화를 할 수 있습니다 :
|
||||
|
||||
```bash
|
||||
scrcpy --record file.mp4
|
||||
scrcpy -r file.mkv
|
||||
```
|
||||
|
||||
녹화하는 동안 미러링을 멈출 수 있습니다 :
|
||||
|
||||
```bash
|
||||
scrcpy --no-display --record file.mp4
|
||||
scrcpy -Nr file.mkv
|
||||
# Ctrl+C 로 녹화를 중단할 수 있습니다.
|
||||
# 윈도우 상에서 Ctrl+C 는 정상정으로 종료되지 않을 수 있으므로, 디바이스 연결을 해제하십시오.
|
||||
```
|
||||
|
||||
"skipped frames" 은 모니터 화면에 보여지지 않았지만 녹화되었습니다 ( 성능 문제로 인해 ). 프레임은 디바이스 상에서 _타임 스탬프 ( 어느 시점에 데이터가 존재했다는 사실을 증명하기 위해 특정 위치에 시각을 표시 )_ 되었으므로, [packet delay
|
||||
variation] 은 녹화된 파일에 영향을 끼치지 않습니다.
|
||||
|
||||
[packet delay variation]: https://en.wikipedia.org/wiki/Packet_delay_variation
|
||||
|
||||
## 연결
|
||||
|
||||
### 무선연결
|
||||
|
||||
_Scrcpy_ 장치와 정보를 주고받기 위해 `adb` 를 사용합니다. `adb` 는 TCIP/IP 를 통해 디바이스와 [연결][connect] 할 수 있습니다 :
|
||||
|
||||
1. 컴퓨터와 디바이스를 동일한 Wi-Fi 에 연결합니다.
|
||||
2. 디바이스의 IP address 를 확인합니다 (설정 → 내 기기 → 상태 / 혹은 인터넷에 '내 IP'검색 시 확인 가능합니다. ).
|
||||
3. TCP/IP 를 통해 디바이스에서 adb 를 사용할 수 있게 합니다: `adb tcpip 5555`.
|
||||
4. 디바이스 연결을 해제합니다.
|
||||
5. adb 를 통해 디바이스에 연결을 합니다\: `adb connect DEVICE_IP:5555` _(`DEVICE_IP` 대신)_.
|
||||
6. `scrcpy` 실행합니다.
|
||||
|
||||
다음은 bit-rate 와 해상도를 줄이는데 유용합니다 :
|
||||
|
||||
```bash
|
||||
scrcpy --bit-rate 2M --max-size 800
|
||||
scrcpy -b2M -m800 # 축약 버전
|
||||
```
|
||||
|
||||
[connect]: https://developer.android.com/studio/command-line/adb.html#wireless
|
||||
|
||||
|
||||
|
||||
### 여러 디바이스 사용 가능
|
||||
|
||||
만약에 여러 디바이스들이 `adb devices` 목록에 표시되었다면, _serial_ 을 명시해야합니다:
|
||||
|
||||
```bash
|
||||
scrcpy --serial 0123456789abcdef
|
||||
scrcpy -s 0123456789abcdef # 축약 버전
|
||||
```
|
||||
|
||||
_scrcpy_ 로 여러 디바이스를 연결해 사용할 수 있습니다.
|
||||
|
||||
|
||||
#### SSH tunnel
|
||||
|
||||
떨어져 있는 디바이스와 연결하기 위해서는, 로컬 `adb` client와 떨어져 있는 `adb` 서버를 연결해야 합니다. (디바이스와 클라이언트가 동일한 버전의 _adb_ protocol을 사용할 경우에 제공됩니다.):
|
||||
|
||||
```bash
|
||||
adb kill-server # 5037의 로컬 local adb server를 중단
|
||||
ssh -CN -L5037:localhost:5037 -R27183:localhost:27183 your_remote_computer
|
||||
# 실행 유지
|
||||
```
|
||||
|
||||
다른 터미널에서는 :
|
||||
|
||||
```bash
|
||||
scrcpy
|
||||
```
|
||||
|
||||
무선 연결과 동일하게, 화질을 줄이는 것이 나을 수 있습니다:
|
||||
|
||||
```
|
||||
scrcpy -b2M -m800 --max-fps 15
|
||||
```
|
||||
|
||||
## Window에서의 배치
|
||||
|
||||
### 맞춤형 window 제목
|
||||
|
||||
기본적으로, window의 이름은 디바이스의 모델명 입니다.
|
||||
다음의 명령어를 통해 변경하세요.
|
||||
|
||||
```bash
|
||||
scrcpy --window-title 'My device'
|
||||
```
|
||||
|
||||
|
||||
### 배치와 크기
|
||||
|
||||
초기 window창의 배치와 크기는 다음과 같이 설정할 수 있습니다:
|
||||
|
||||
```bash
|
||||
scrcpy --window-x 100 --window-y 100 --window-width 800 --window-height 600
|
||||
```
|
||||
|
||||
|
||||
### 경계 없애기
|
||||
|
||||
윈도우 장식(경계선 등)을 다음과 같이 제거할 수 있습니다:
|
||||
|
||||
```bash
|
||||
scrcpy --window-borderless
|
||||
```
|
||||
|
||||
### 항상 모든 윈도우 위에 실행창 고정
|
||||
|
||||
이 어플리케이션의 윈도우 창은 다음의 명령어로 다른 window 위에 디스플레이 할 수 있습니다:
|
||||
|
||||
```bash
|
||||
scrcpy --always-on-top
|
||||
scrcpy -T # 축약 버전
|
||||
```
|
||||
|
||||
### 전체 화면
|
||||
|
||||
이 어플리케이션은 전체화면으로 바로 시작할 수 있습니다.
|
||||
|
||||
```bash
|
||||
scrcpy --fullscreen
|
||||
scrcpy -f # short version
|
||||
```
|
||||
|
||||
전체 화면은 `Ctrl`+`f`키로 끄거나 켤 수 있습니다.
|
||||
|
||||
|
||||
## 다른 미러링 옵션
|
||||
|
||||
### 읽기 전용(Read-only)
|
||||
|
||||
권한을 제한하기 위해서는 (디바이스와 관련된 모든 것: 입력 키, 마우스 이벤트 , 파일의 드래그 앤 드랍(drag&drop)):
|
||||
|
||||
```bash
|
||||
scrcpy --no-control
|
||||
scrcpy -n
|
||||
```
|
||||
|
||||
### 화면 끄기
|
||||
|
||||
미러링을 실행하는 와중에 디바이스의 화면을 끌 수 있게 하기 위해서는
|
||||
다음의 커맨드 라인 옵션을(command line option) 입력하세요:
|
||||
|
||||
```bash
|
||||
scrcpy --turn-screen-off
|
||||
scrcpy -S
|
||||
```
|
||||
|
||||
혹은 `Ctrl`+`o`을 눌러 언제든지 디바이스의 화면을 끌 수 있습니다.
|
||||
|
||||
다시 화면을 켜기 위해서는`POWER` (혹은 `Ctrl`+`p`)를 누르세요.
|
||||
|
||||
|
||||
### 유효기간이 지난 프레임 제공 (Render expired frames)
|
||||
|
||||
디폴트로, 대기시간을 최소화하기 위해 _scrcpy_ 는 항상 마지막으로 디코딩된 프레임을 제공합니다
|
||||
과거의 프레임은 하나씩 삭제합니다.
|
||||
|
||||
모든 프레임을 강제로 렌더링하기 위해서는 (대기 시간이 증가될 수 있습니다)
|
||||
다음의 명령어를 사용하세요:
|
||||
|
||||
```bash
|
||||
scrcpy --render-expired-frames
|
||||
```
|
||||
|
||||
|
||||
### 화면에 터치 나타내기
|
||||
|
||||
발표를 할 때, 물리적인 기기에 한 물리적 터치를 나타내는 것이 유용할 수 있습니다.
|
||||
|
||||
안드로이드 운영체제는 이런 기능을 _Developers options_에서 제공합니다.
|
||||
|
||||
_Scrcpy_ 는 이런 기능을 시작할 때와 종료할 때 옵션으로 제공합니다.
|
||||
|
||||
```bash
|
||||
scrcpy --show-touches
|
||||
scrcpy -t
|
||||
```
|
||||
|
||||
화면에 _물리적인 터치만_ 나타나는 것에 유의하세요 (손가락을 디바이스에 대는 행위).
|
||||
|
||||
|
||||
### 입력 제어
|
||||
|
||||
#### 복사-붙여넣기
|
||||
|
||||
컴퓨터와 디바이스 양방향으로 클립보드를 복사하는 것이 가능합니다:
|
||||
|
||||
- `Ctrl`+`c` 디바이스의 클립보드를 컴퓨터로 복사합니다;
|
||||
- `Ctrl`+`Shift`+`v` 컴퓨터의 클립보드를 디바이스로 복사합니다;
|
||||
- `Ctrl`+`v` 컴퓨터의 클립보드를 text event 로써 _붙여넣습니다_ ( 그러나, ASCII 코드가 아닌 경우 실행되지 않습니다 )
|
||||
|
||||
#### 텍스트 삽입 우선 순위
|
||||
|
||||
텍스트를 입력할 때 생성되는 두 가지의 [events][textevents] 가 있습니다:
|
||||
- _key events_, 키가 눌려있는 지에 대한 신호;
|
||||
- _text events_, 텍스트가 입력되었는지에 대한 신호.
|
||||
|
||||
기본적으로, 글자들은 key event 를 이용해 입력되기 때문에, 키보드는 게임에서처럼 처리합니다 ( 보통 WASD 키에 대해서 ).
|
||||
|
||||
그러나 이는 [issues 를 발생][prefertext]시킵니다. 이와 관련된 문제를 접할 경우, 아래와 같이 피할 수 있습니다:
|
||||
|
||||
```bash
|
||||
scrcpy --prefer-text
|
||||
```
|
||||
|
||||
( 그러나 이는 게임에서의 처리를 중단할 수 있습니다 )
|
||||
|
||||
[textevents]: https://blog.rom1v.com/2018/03/introducing-scrcpy/#handle-text-input
|
||||
[prefertext]: https://github.com/Genymobile/scrcpy/issues/650#issuecomment-512945343
|
||||
|
||||
|
||||
### 파일 드랍
|
||||
|
||||
### APK 실행하기
|
||||
|
||||
APK를 실행하기 위해서는, APK file(파일명이`.apk`로 끝나는 파일)을 드래그하고 _scrcpy_ window에 드랍하세요 (drag and drop)
|
||||
|
||||
시각적인 피드백은 없고,log 하나가 콘솔에 출력될 것입니다.
|
||||
|
||||
### 디바이스에 파일 push하기
|
||||
|
||||
디바이스의`/sdcard/`에 파일을 push하기 위해서는,
|
||||
APK파일이 아닌 파일을_scrcpy_ window에 드래그하고 드랍하세요.(drag and drop).
|
||||
|
||||
시각적인 피드백은 없고,log 하나가 콘솔에 출력될 것입니다.
|
||||
|
||||
해당 디렉토리는 시작할 때 변경이 가능합니다:
|
||||
|
||||
```bash
|
||||
scrcpy --push-target /sdcard/foo/bar/
|
||||
```
|
||||
|
||||
### 오디오의 전달
|
||||
|
||||
_scrcpy_는 오디오를 직접 전달해주지 않습니다. [USBaudio] (Linux-only)를 사용하세요.
|
||||
|
||||
추가적으로 [issue #14]를 참고하세요.
|
||||
|
||||
[USBaudio]: https://github.com/rom1v/usbaudio
|
||||
[issue #14]: https://github.com/Genymobile/scrcpy/issues/14
|
||||
|
||||
## 단축키
|
||||
|
||||
| 실행내용 | 단축키 | 단축키 (macOS)
|
||||
| -------------------------------------- |:----------------------------- |:-----------------------------
|
||||
| 전체화면 모드로 전환 | `Ctrl`+`f` | `Cmd`+`f`
|
||||
| window를 1:1비율로 전환하기(픽셀 맞춤) | `Ctrl`+`g` | `Cmd`+`g`
|
||||
| 검은 공백 제거 위한 window 크기 조정 | `Ctrl`+`x` \| _Double-click¹_ | `Cmd`+`x` \| _Double-click¹_
|
||||
|`HOME` 클릭 | `Ctrl`+`h` \| _Middle-click_ | `Ctrl`+`h` \| _Middle-click_
|
||||
| `BACK` 클릭 | `Ctrl`+`b` \| _Right-click²_ | `Cmd`+`b` \| _Right-click²_
|
||||
| `APP_SWITCH` 클릭 | `Ctrl`+`s` | `Cmd`+`s`
|
||||
| `MENU` 클릭 | `Ctrl`+`m` | `Ctrl`+`m`
|
||||
| `VOLUME_UP` 클릭 | `Ctrl`+`↑` _(up)_ | `Cmd`+`↑` _(up)_
|
||||
| `VOLUME_DOWN` 클릭 | `Ctrl`+`↓` _(down)_ | `Cmd`+`↓` _(down)_
|
||||
| `POWER` 클릭 | `Ctrl`+`p` | `Cmd`+`p`
|
||||
| 전원 켜기 | _Right-click²_ | _Right-click²_
|
||||
| 미러링 중 디바이스 화면 끄기 | `Ctrl`+`o` | `Cmd`+`o`
|
||||
| 알림 패널 늘리기 | `Ctrl`+`n` | `Cmd`+`n`
|
||||
| 알림 패널 닫기 | `Ctrl`+`Shift`+`n` | `Cmd`+`Shift`+`n`
|
||||
| 디바이스의 clipboard 컴퓨터로 복사하기 | `Ctrl`+`c` | `Cmd`+`c`
|
||||
| 컴퓨터의 clipboard 디바이스에 붙여넣기 | `Ctrl`+`v` | `Cmd`+`v`
|
||||
| Copy computer clipboard to device | `Ctrl`+`Shift`+`v` | `Cmd`+`Shift`+`v`
|
||||
| Enable/disable FPS counter (on stdout) | `Ctrl`+`i` | `Cmd`+`i`
|
||||
|
||||
_¹검은 공백을 제거하기 위해서는 그 부분을 더블 클릭하세요_
|
||||
_²화면이 꺼진 상태에서 우클릭 시 다시 켜지며, 그 외의 상태에서는 뒤로 돌아갑니다.
|
||||
|
||||
## 맞춤 경로 (custom path)
|
||||
|
||||
특정한 _adb_ binary를 사용하기 위해서는, 그것의 경로를 환경변수로 설정하세요.
|
||||
`ADB`:
|
||||
|
||||
ADB=/path/to/adb scrcpy
|
||||
|
||||
`scrcpy-server.jar`파일의 경로에 오버라이드 하기 위해서는, 그것의 경로를 `SCRCPY_SERVER_PATH`에 저장하세요.
|
||||
|
||||
[useful]: https://github.com/Genymobile/scrcpy/issues/278#issuecomment-429330345
|
||||
|
||||
|
||||
## _scrcpy_ 인 이유?
|
||||
|
||||
한 동료가 [gnirehtet]와 같이 발음하기 어려운 이름을 찾을 수 있는지 도발했습니다.
|
||||
|
||||
[`strcpy`] 는 **str**ing을 copy하고; `scrcpy`는 **scr**een을 copy합니다.
|
||||
|
||||
[gnirehtet]: https://github.com/Genymobile/gnirehtet
|
||||
[`strcpy`]: http://man7.org/linux/man-pages/man3/strcpy.3.html
|
||||
|
||||
|
||||
|
||||
## 빌드하는 방법?
|
||||
|
||||
[BUILD]을 참고하세요.
|
||||
|
||||
[BUILD]: BUILD.md
|
||||
|
||||
## 흔한 issue
|
||||
|
||||
[FAQ](FAQ.md)을 참고하세요.
|
||||
|
||||
|
||||
## 개발자들
|
||||
|
||||
[developers page]를 참고하세요.
|
||||
|
||||
[developers page]: DEVELOP.md
|
||||
|
||||
|
||||
## 라이선스
|
||||
|
||||
Copyright (C) 2018 Genymobile
|
||||
Copyright (C) 2018-2020 Romain Vimont
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
## 관련 글 (articles)
|
||||
|
||||
- [scrcpy 소개][article-intro]
|
||||
- [무선으로 연결하는 Scrcpy][article-tcpip]
|
||||
|
||||
[article-intro]: https://blog.rom1v.com/2018/03/introducing-scrcpy/
|
||||
[article-tcpip]: https://www.genymotion.com/blog/open-source-project-scrcpy-now-works-wirelessly/
|
99
README.md
99
README.md
@ -1,4 +1,4 @@
|
||||
# scrcpy (v1.11)
|
||||
# scrcpy (v1.12.1)
|
||||
|
||||
This application provides display and control of Android devices connected on
|
||||
USB (or [over TCP/IP][article-tcpip]). It does not require any _root_ access.
|
||||
@ -37,8 +37,11 @@ control it using keyboard and mouse.
|
||||
|
||||
### Linux
|
||||
|
||||
On Linux, you typically need to [build the app manually][BUILD]. Don't worry,
|
||||
it's not that hard.
|
||||
In Debian (_testing_ and _sid_ for now):
|
||||
|
||||
```
|
||||
apt install scrcpy
|
||||
```
|
||||
|
||||
A [Snap] package is available: [`scrcpy`][snap-link].
|
||||
|
||||
@ -56,19 +59,37 @@ For Gentoo, an [Ebuild] is available: [`scrcpy/`][ebuild-link].
|
||||
[Ebuild]: https://wiki.gentoo.org/wiki/Ebuild
|
||||
[ebuild-link]: https://github.com/maggu2810/maggu2810-overlay/tree/master/app-mobilephone/scrcpy
|
||||
|
||||
You could also [build the app manually][BUILD] (don't worry, it's not that
|
||||
hard).
|
||||
|
||||
|
||||
|
||||
### Windows
|
||||
|
||||
For Windows, for simplicity, prebuilt archives with all the dependencies
|
||||
(including `adb`) are available:
|
||||
|
||||
- [`scrcpy-win32-v1.11.zip`][direct-win32]
|
||||
_(SHA-256: f25ed46e6f3e81e0ff9b9b4df7fe1a4bbd13f8396b7391be0a488b64c675b41e)_
|
||||
- [`scrcpy-win64-v1.11.zip`][direct-win64]
|
||||
_(SHA-256: 3802c9ea0307d437947ff150ec65e53990b0beaacd0c8d0bed19c7650ce141bd)_
|
||||
- [`scrcpy-win32-v1.12.1.zip`][direct-win32]
|
||||
_(SHA-256: 0f4b3b063536b50a2df05dc42c760f9cc0093a9a26dbdf02d8232c74dab43480)_
|
||||
- [`scrcpy-win64-v1.12.1.zip`][direct-win64]
|
||||
_(SHA-256: 57d34b6d16cfd9fe169bc37c4df58ebd256d05c1ea3febc63d9cb0a027ab47c9)_
|
||||
|
||||
[direct-win32]: https://github.com/Genymobile/scrcpy/releases/download/v1.11/scrcpy-win32-v1.11.zip
|
||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.11/scrcpy-win64-v1.11.zip
|
||||
[direct-win32]: https://github.com/Genymobile/scrcpy/releases/download/v1.12.1/scrcpy-win32-v1.12.1.zip
|
||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.12.1/scrcpy-win64-v1.12.1.zip
|
||||
|
||||
It is also available in [Chocolatey]:
|
||||
|
||||
[Chocolatey]: https://chocolatey.org/
|
||||
|
||||
```bash
|
||||
choco install scrcpy
|
||||
```
|
||||
|
||||
You need `adb`, accessible from your `PATH`. If you don't have it yet:
|
||||
|
||||
```bash
|
||||
choco install adb
|
||||
```
|
||||
|
||||
You can also [build the app manually][BUILD].
|
||||
|
||||
@ -137,12 +158,14 @@ scrcpy -b 2M # short version
|
||||
|
||||
#### Limit frame rate
|
||||
|
||||
On devices with Android >= 10, the capture frame rate can be limited:
|
||||
The capture frame rate can be limited:
|
||||
|
||||
```bash
|
||||
scrcpy --max-fps 15
|
||||
```
|
||||
|
||||
This is officially supported since Android 10, but may work on earlier versions.
|
||||
|
||||
#### Crop
|
||||
|
||||
The device screen may be cropped to mirror only part of the screen.
|
||||
@ -156,6 +179,21 @@ scrcpy --crop 1224:1440:0:0 # 1224x1440 at offset (0,0)
|
||||
If `--max-size` is also specified, resizing is applied after cropping.
|
||||
|
||||
|
||||
#### Lock video orientation
|
||||
|
||||
|
||||
To lock the orientation of the mirroring:
|
||||
|
||||
```bash
|
||||
scrcpy --lock-video-orientation 0 # natural orientation
|
||||
scrcpy --lock-video-orientation 1 # 90° counterclockwise
|
||||
scrcpy --lock-video-orientation 2 # 180°
|
||||
scrcpy --lock-video-orientation 3 # 90° clockwise
|
||||
```
|
||||
|
||||
This affects recording orientation.
|
||||
|
||||
|
||||
### Recording
|
||||
|
||||
It is possible to record the screen while mirroring:
|
||||
@ -214,8 +252,25 @@ scrcpy --serial 0123456789abcdef
|
||||
scrcpy -s 0123456789abcdef # short version
|
||||
```
|
||||
|
||||
If the device is connected over TCP/IP:
|
||||
|
||||
```bash
|
||||
scrcpy --serial 192.168.0.1:5555
|
||||
scrcpy -s 192.168.0.1:5555 # short version
|
||||
```
|
||||
|
||||
You can start several instances of _scrcpy_ for several devices.
|
||||
|
||||
#### Autostart on device connection
|
||||
|
||||
You could use [AutoAdb]:
|
||||
|
||||
```bash
|
||||
autoadb scrcpy -s '{}'
|
||||
```
|
||||
|
||||
[AutoAdb]: https://github.com/rom1v/usbaudio
|
||||
|
||||
#### SSH tunnel
|
||||
|
||||
To connect to a remote device, it is possible to connect a local `adb` client to
|
||||
@ -298,6 +353,21 @@ scrcpy --no-control
|
||||
scrcpy -n
|
||||
```
|
||||
|
||||
#### Display
|
||||
|
||||
If several displays are available, it is possible to select the display to
|
||||
mirror:
|
||||
|
||||
```bash
|
||||
scrcpy --display 1
|
||||
```
|
||||
|
||||
The list of display ids can be retrieved by:
|
||||
|
||||
```
|
||||
adb shell dumpsys display # search "mDisplayId=" in the output
|
||||
```
|
||||
|
||||
#### Turn screen off
|
||||
|
||||
It is possible to turn the device screen off while mirroring on start with a
|
||||
@ -343,6 +413,13 @@ Note that it only shows _physical_ touches (with the finger on the device).
|
||||
|
||||
### Input control
|
||||
|
||||
#### Rotate device screen
|
||||
|
||||
Press `Ctrl`+`r` to switch between portrait and landscape modes.
|
||||
|
||||
Note that it rotates only if the application in foreground supports the
|
||||
requested orientation.
|
||||
|
||||
#### Copy-paste
|
||||
|
||||
It is possible to synchronize clipboards between the computer and the device, in
|
||||
@ -482,7 +559,7 @@ Read the [developers page].
|
||||
## Licence
|
||||
|
||||
Copyright (C) 2018 Genymobile
|
||||
Copyright (C) 2018-2019 Romain Vimont
|
||||
Copyright (C) 2018-2020 Romain Vimont
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,6 @@
|
||||
src = [
|
||||
'src/main.c',
|
||||
'src/cli.c',
|
||||
'src/command.c',
|
||||
'src/control_msg.c',
|
||||
'src/controller.c',
|
||||
@ -75,11 +76,9 @@ cc = meson.get_compiler('c')
|
||||
|
||||
if host_machine.system() == 'windows'
|
||||
src += [ 'src/sys/win/command.c' ]
|
||||
src += [ 'src/sys/win/net.c' ]
|
||||
dependencies += cc.find_library('ws2_32')
|
||||
else
|
||||
src += [ 'src/sys/unix/command.c' ]
|
||||
src += [ 'src/sys/unix/net.c' ]
|
||||
endif
|
||||
|
||||
conf = configuration_data()
|
||||
@ -97,14 +96,21 @@ conf.set_quoted('PREFIX', get_option('prefix'))
|
||||
# directory as the executable)
|
||||
conf.set('PORTABLE', get_option('portable'))
|
||||
|
||||
# the default client TCP port for the "adb reverse" tunnel
|
||||
# the default client TCP port range for the "adb reverse" tunnel
|
||||
# overridden by option --port
|
||||
conf.set('DEFAULT_LOCAL_PORT', '27183')
|
||||
conf.set('DEFAULT_LOCAL_PORT_RANGE_FIRST', '27183')
|
||||
conf.set('DEFAULT_LOCAL_PORT_RANGE_LAST', '27199')
|
||||
|
||||
# the default max video size for both dimensions, in pixels
|
||||
# overridden by option --max-size
|
||||
conf.set('DEFAULT_MAX_SIZE', '0') # 0: unlimited
|
||||
|
||||
# the default video orientation
|
||||
# natural device orientation is 0 and each increment adds 90 degrees
|
||||
# counterclockwise
|
||||
# overridden by option --lock-video-orientation
|
||||
conf.set('DEFAULT_LOCK_VIDEO_ORIENTATION', '-1') # -1: unlocked
|
||||
|
||||
# the default video bitrate, in bits/second
|
||||
# overridden by option --bit-rate
|
||||
conf.set('DEFAULT_BIT_RATE', '8000000') # 8Mbps
|
||||
@ -118,6 +124,9 @@ conf.set('WINDOWS_NOCONSOLE', get_option('windows_noconsole'))
|
||||
# run a server debugger and wait for a client to be attached
|
||||
conf.set('SERVER_DEBUGGER', get_option('server_debugger'))
|
||||
|
||||
# select the debugger method ('old' for Android < 9, 'new' for Android >= 9)
|
||||
conf.set('SERVER_DEBUGGER_METHOD_NEW', get_option('server_debugger_method') == 'new')
|
||||
|
||||
configure_file(configuration: conf, output: 'config.h')
|
||||
|
||||
src_dir = include_directories('src')
|
||||
@ -140,34 +149,43 @@ install_man('scrcpy.1')
|
||||
|
||||
### TESTS
|
||||
|
||||
tests = [
|
||||
['test_buffer_util', [
|
||||
'tests/test_buffer_util.c'
|
||||
]],
|
||||
['test_cbuf', [
|
||||
'tests/test_cbuf.c',
|
||||
]],
|
||||
['test_control_event_serialize', [
|
||||
'tests/test_control_msg_serialize.c',
|
||||
'src/control_msg.c',
|
||||
'src/util/str_util.c'
|
||||
]],
|
||||
['test_device_event_deserialize', [
|
||||
'tests/test_device_msg_deserialize.c',
|
||||
'src/device_msg.c'
|
||||
]],
|
||||
['test_queue', [
|
||||
'tests/test_queue.c',
|
||||
]],
|
||||
['test_strutil', [
|
||||
'tests/test_strutil.c',
|
||||
'src/util/str_util.c'
|
||||
]],
|
||||
]
|
||||
# do not build tests in release (assertions would not be executed at all)
|
||||
if get_option('buildtype') == 'debug'
|
||||
tests = [
|
||||
['test_buffer_util', [
|
||||
'tests/test_buffer_util.c'
|
||||
]],
|
||||
['test_cbuf', [
|
||||
'tests/test_cbuf.c',
|
||||
]],
|
||||
['test_cli', [
|
||||
'tests/test_cli.c',
|
||||
'src/cli.c',
|
||||
'src/util/str_util.c',
|
||||
]],
|
||||
['test_control_event_serialize', [
|
||||
'tests/test_control_msg_serialize.c',
|
||||
'src/control_msg.c',
|
||||
'src/util/str_util.c',
|
||||
]],
|
||||
['test_device_event_deserialize', [
|
||||
'tests/test_device_msg_deserialize.c',
|
||||
'src/device_msg.c',
|
||||
]],
|
||||
['test_queue', [
|
||||
'tests/test_queue.c',
|
||||
]],
|
||||
['test_strutil', [
|
||||
'tests/test_strutil.c',
|
||||
'src/util/str_util.c',
|
||||
]],
|
||||
]
|
||||
|
||||
foreach t : tests
|
||||
exe = executable(t[0], t[1],
|
||||
include_directories: src_dir,
|
||||
dependencies: dependencies)
|
||||
test(t[0], exe)
|
||||
endforeach
|
||||
foreach t : tests
|
||||
exe = executable(t[0], t[1],
|
||||
include_directories: src_dir,
|
||||
dependencies: dependencies,
|
||||
c_args: ['-DSDL_MAIN_HANDLED'])
|
||||
test(t[0], exe)
|
||||
endforeach
|
||||
endif
|
||||
|
45
app/scrcpy.1
45
app/scrcpy.1
@ -26,13 +26,22 @@ Encode the video at the given bit\-rate, expressed in bits/s. Unit suffixes are
|
||||
Default is 8000000.
|
||||
|
||||
.TP
|
||||
.BI \-\-crop " width\fR:\fIheight\fR:\fIx\fR:\fIy
|
||||
.BI "\-\-crop " width\fR:\fIheight\fR:\fIx\fR:\fIy
|
||||
Crop the device screen on the server.
|
||||
|
||||
The values are expressed in the device natural orientation (typically, portrait for a phone, landscape for a tablet). Any
|
||||
.B \-\-max\-size
|
||||
value is computed on the cropped size.
|
||||
|
||||
.TP
|
||||
.BI "\-\-display " id
|
||||
Specify the display id to mirror.
|
||||
|
||||
The list of possible display ids can be listed by "adb shell dumpsys display"
|
||||
(search "mDisplayId=" in the output).
|
||||
|
||||
Default is 0.
|
||||
|
||||
.TP
|
||||
.B \-f, \-\-fullscreen
|
||||
Start in fullscreen.
|
||||
@ -42,8 +51,14 @@ Start in fullscreen.
|
||||
Print this help.
|
||||
|
||||
.TP
|
||||
.BI \-\-max\-fps " value
|
||||
Limit the framerate of screen capture (only supported on devices with Android >= 10).
|
||||
.BI "\-\-lock\-video\-orientation " value
|
||||
Lock video orientation to \fIvalue\fR. Values are integers in the range [-1..3]. Natural device orientation is 0 and each increment adds 90 degrees counterclockwise.
|
||||
|
||||
Default is -1 (unlocked).
|
||||
|
||||
.TP
|
||||
.BI "\-\-max\-fps " value
|
||||
Limit the framerate of screen capture (officially supported since Android 10, but may work on earlier versions).
|
||||
|
||||
.TP
|
||||
.BI "\-m, \-\-max\-size " value
|
||||
@ -60,10 +75,10 @@ Disable device control (mirror the device in read\-only).
|
||||
Do not display device (only when screen recording is enabled).
|
||||
|
||||
.TP
|
||||
.BI "\-p, \-\-port " port
|
||||
Set the TCP port the client listens on.
|
||||
.BI "\-p, \-\-port " port[:port]
|
||||
Set the TCP port (range) used by the client to listen.
|
||||
|
||||
Default is 27183.
|
||||
Default is 27183:27199.
|
||||
|
||||
.TP
|
||||
.B \-\-prefer\-text
|
||||
@ -88,7 +103,7 @@ The format is determined by the
|
||||
option if set, or by the file extension (.mp4 or .mkv).
|
||||
|
||||
.TP
|
||||
.BI \-\-record\-format " format
|
||||
.BI "\-\-record\-format " format
|
||||
Force recording format (either mp4 or mkv).
|
||||
|
||||
.TP
|
||||
@ -118,29 +133,29 @@ Print the version of scrcpy.
|
||||
Disable window decorations (display borderless window).
|
||||
|
||||
.TP
|
||||
.BI \-\-window\-title " text
|
||||
.BI "\-\-window\-title " text
|
||||
Set a custom window title.
|
||||
|
||||
.TP
|
||||
.BI \-\-window\-x " value
|
||||
.BI "\-\-window\-x " value
|
||||
Set the initial window horizontal position.
|
||||
|
||||
Default is -1 (automatic).\n
|
||||
Default is "auto".\n
|
||||
|
||||
.TP
|
||||
.BI \-\-window\-y " value
|
||||
.BI "\-\-window\-y " value
|
||||
Set the initial window vertical position.
|
||||
|
||||
Default is -1 (automatic).\n
|
||||
Default is "auto".\n
|
||||
|
||||
.TP
|
||||
.BI \-\-window\-width " value
|
||||
.BI "\-\-window\-width " value
|
||||
Set the initial window width.
|
||||
|
||||
Default is 0 (automatic).\n
|
||||
|
||||
.TP
|
||||
.BI \-\-window\-height " value
|
||||
.BI "\-\-window\-height " value
|
||||
Set the initial window height.
|
||||
|
||||
Default is 0 (automatic).\n
|
||||
@ -261,7 +276,7 @@ Copyright \(co 2018 Genymobile
|
||||
Genymobile
|
||||
.UE
|
||||
|
||||
Copyright \(co 2018\-2019
|
||||
Copyright \(co 2018\-2020
|
||||
.MT rom@rom1v.com
|
||||
Romain Vimont
|
||||
.ME
|
||||
|
631
app/src/cli.c
Normal file
631
app/src/cli.c
Normal file
@ -0,0 +1,631 @@
|
||||
#include "cli.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <getopt.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "recorder.h"
|
||||
#include "util/log.h"
|
||||
#include "util/str_util.h"
|
||||
|
||||
void
|
||||
scrcpy_print_usage(const char *arg0) {
|
||||
#ifdef __APPLE__
|
||||
# define CTRL_OR_CMD "Cmd"
|
||||
#else
|
||||
# define CTRL_OR_CMD "Ctrl"
|
||||
#endif
|
||||
fprintf(stderr,
|
||||
"Usage: %s [options]\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
"\n"
|
||||
" --always-on-top\n"
|
||||
" Make scrcpy window always on top (above other windows).\n"
|
||||
"\n"
|
||||
" -b, --bit-rate value\n"
|
||||
" Encode the video at the given bit-rate, expressed in bits/s.\n"
|
||||
" Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
|
||||
" Default is %d.\n"
|
||||
"\n"
|
||||
" --crop width:height:x:y\n"
|
||||
" Crop the device screen on the server.\n"
|
||||
" The values are expressed in the device natural orientation\n"
|
||||
" (typically, portrait for a phone, landscape for a tablet).\n"
|
||||
" Any --max-size value is computed on the cropped size.\n"
|
||||
"\n"
|
||||
" --display id\n"
|
||||
" Specify the display id to mirror.\n"
|
||||
"\n"
|
||||
" The list of possible display ids can be listed by:\n"
|
||||
" adb shell dumpsys display\n"
|
||||
" (search \"mDisplayId=\" in the output)\n"
|
||||
"\n"
|
||||
" Default is 0.\n"
|
||||
"\n"
|
||||
" -f, --fullscreen\n"
|
||||
" Start in fullscreen.\n"
|
||||
"\n"
|
||||
" -h, --help\n"
|
||||
" Print this help.\n"
|
||||
"\n"
|
||||
" --lock-video-orientation value\n"
|
||||
" Lock video orientation to value. Values are integers in the\n"
|
||||
" range [-1..3]. Natural device orientation is 0 and each\n"
|
||||
" increment adds 90 degrees counterclockwise.\n"
|
||||
" Default is %d%s.\n"
|
||||
"\n"
|
||||
" --max-fps value\n"
|
||||
" Limit the frame rate of screen capture (officially supported\n"
|
||||
" since Android 10, but may work on earlier versions).\n"
|
||||
"\n"
|
||||
" -m, --max-size value\n"
|
||||
" Limit both the width and height of the video to value. The\n"
|
||||
" other dimension is computed so that the device aspect-ratio\n"
|
||||
" is preserved.\n"
|
||||
" Default is %d%s.\n"
|
||||
"\n"
|
||||
" -n, --no-control\n"
|
||||
" Disable device control (mirror the device in read-only).\n"
|
||||
"\n"
|
||||
" -N, --no-display\n"
|
||||
" Do not display device (only when screen recording is\n"
|
||||
" enabled).\n"
|
||||
"\n"
|
||||
" -p, --port port[:port]\n"
|
||||
" Set the TCP port (range) used by the client to listen.\n"
|
||||
" Default is %d:%d.\n"
|
||||
"\n"
|
||||
" --prefer-text\n"
|
||||
" Inject alpha characters and space as text events instead of\n"
|
||||
" key events.\n"
|
||||
" This avoids issues when combining multiple keys to enter a\n"
|
||||
" special character, but breaks the expected behavior of alpha\n"
|
||||
" keys in games (typically WASD).\n"
|
||||
"\n"
|
||||
" --push-target path\n"
|
||||
" Set the target directory for pushing files to the device by\n"
|
||||
" drag & drop. It is passed as-is to \"adb push\".\n"
|
||||
" Default is \"/sdcard/\".\n"
|
||||
"\n"
|
||||
" -r, --record file.mp4\n"
|
||||
" Record screen to file.\n"
|
||||
" The format is determined by the --record-format option if\n"
|
||||
" set, or by the file extension (.mp4 or .mkv).\n"
|
||||
"\n"
|
||||
" --record-format format\n"
|
||||
" Force recording format (either mp4 or mkv).\n"
|
||||
"\n"
|
||||
" --render-expired-frames\n"
|
||||
" By default, to minimize latency, scrcpy always renders the\n"
|
||||
" last available decoded frame, and drops any previous ones.\n"
|
||||
" This flag forces to render all frames, at a cost of a\n"
|
||||
" possible increased latency.\n"
|
||||
"\n"
|
||||
" -s, --serial serial\n"
|
||||
" The device serial number. Mandatory only if several devices\n"
|
||||
" are connected to adb.\n"
|
||||
"\n"
|
||||
" -S, --turn-screen-off\n"
|
||||
" Turn the device screen off immediately.\n"
|
||||
"\n"
|
||||
" -t, --show-touches\n"
|
||||
" Enable \"show touches\" on start, disable on quit.\n"
|
||||
" It only shows physical touches (not clicks from scrcpy).\n"
|
||||
"\n"
|
||||
" -v, --version\n"
|
||||
" Print the version of scrcpy.\n"
|
||||
"\n"
|
||||
" --window-borderless\n"
|
||||
" Disable window decorations (display borderless window).\n"
|
||||
"\n"
|
||||
" --window-title text\n"
|
||||
" Set a custom window title.\n"
|
||||
"\n"
|
||||
" --window-x value\n"
|
||||
" Set the initial window horizontal position.\n"
|
||||
" Default is \"auto\".\n"
|
||||
"\n"
|
||||
" --window-y value\n"
|
||||
" Set the initial window vertical position.\n"
|
||||
" Default is \"auto\".\n"
|
||||
"\n"
|
||||
" --window-width value\n"
|
||||
" Set the initial window width.\n"
|
||||
" Default is 0 (automatic).\n"
|
||||
"\n"
|
||||
" --window-height value\n"
|
||||
" Set the initial window width.\n"
|
||||
" Default is 0 (automatic).\n"
|
||||
"\n"
|
||||
"Shortcuts:\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+f\n"
|
||||
" switch fullscreen mode\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+g\n"
|
||||
" resize window to 1:1 (pixel-perfect)\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+x\n"
|
||||
" Double-click on black borders\n"
|
||||
" resize window to remove black borders\n"
|
||||
"\n"
|
||||
" Ctrl+h\n"
|
||||
" Middle-click\n"
|
||||
" click on HOME\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+b\n"
|
||||
" " CTRL_OR_CMD "+Backspace\n"
|
||||
" Right-click (when screen is on)\n"
|
||||
" click on BACK\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+s\n"
|
||||
" click on APP_SWITCH\n"
|
||||
"\n"
|
||||
" Ctrl+m\n"
|
||||
" click on MENU\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+Up\n"
|
||||
" click on VOLUME_UP\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+Down\n"
|
||||
" click on VOLUME_DOWN\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+p\n"
|
||||
" click on POWER (turn screen on/off)\n"
|
||||
"\n"
|
||||
" Right-click (when screen is off)\n"
|
||||
" power on\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+o\n"
|
||||
" turn device screen off (keep mirroring)\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+r\n"
|
||||
" rotate device screen\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+n\n"
|
||||
" expand notification panel\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+Shift+n\n"
|
||||
" collapse notification panel\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+c\n"
|
||||
" copy device clipboard to computer\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+v\n"
|
||||
" paste computer clipboard to device\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+Shift+v\n"
|
||||
" copy computer clipboard to device\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+i\n"
|
||||
" enable/disable FPS counter (print frames/second in logs)\n"
|
||||
"\n"
|
||||
" Drag & drop APK file\n"
|
||||
" install APK from computer\n"
|
||||
"\n",
|
||||
arg0,
|
||||
DEFAULT_BIT_RATE,
|
||||
DEFAULT_LOCK_VIDEO_ORIENTATION, DEFAULT_LOCK_VIDEO_ORIENTATION >= 0 ? "" : " (unlocked)",
|
||||
DEFAULT_MAX_SIZE, DEFAULT_MAX_SIZE ? "" : " (unlimited)",
|
||||
DEFAULT_LOCAL_PORT_RANGE_FIRST, DEFAULT_LOCAL_PORT_RANGE_LAST);
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
|
||||
long max, const char *name) {
|
||||
long value;
|
||||
bool ok;
|
||||
if (accept_suffix) {
|
||||
ok = parse_integer_with_suffix(s, &value);
|
||||
} else {
|
||||
ok = parse_integer(s, &value);
|
||||
}
|
||||
if (!ok) {
|
||||
LOGE("Could not parse %s: %s", name, s);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value < min || value > max) {
|
||||
LOGE("Could not parse %s: value (%ld) out-of-range (%ld; %ld)",
|
||||
name, value, min, max);
|
||||
return false;
|
||||
}
|
||||
|
||||
*out = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static size_t
|
||||
parse_integers_arg(const char *s, size_t max_items, long *out, long min,
|
||||
long max, const char *name) {
|
||||
size_t count = parse_integers(s, ':', max_items, out);
|
||||
if (!count) {
|
||||
LOGE("Could not parse %s: %s", name, s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
long value = out[i];
|
||||
if (value < min || value > max) {
|
||||
LOGE("Could not parse %s: value (%ld) out-of-range (%ld; %ld)",
|
||||
name, value, min, max);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_bit_rate(const char *s, uint32_t *bit_rate) {
|
||||
long value;
|
||||
// long may be 32 bits (it is the case on mingw), so do not use more than
|
||||
// 31 bits (long is signed)
|
||||
bool ok = parse_integer_arg(s, &value, true, 0, 0x7FFFFFFF, "bit-rate");
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*bit_rate = (uint32_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_max_size(const char *s, uint16_t *max_size) {
|
||||
long value;
|
||||
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF, "max size");
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*max_size = (uint16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_max_fps(const char *s, uint16_t *max_fps) {
|
||||
long value;
|
||||
bool ok = parse_integer_arg(s, &value, false, 0, 1000, "max fps");
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*max_fps = (uint16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_lock_video_orientation(const char *s, int8_t *lock_video_orientation) {
|
||||
long value;
|
||||
bool ok = parse_integer_arg(s, &value, false, -1, 3,
|
||||
"lock video orientation");
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*lock_video_orientation = (int8_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_window_position(const char *s, int16_t *position) {
|
||||
// special value for "auto"
|
||||
static_assert(WINDOW_POSITION_UNDEFINED == -0x8000, "unexpected value");
|
||||
|
||||
if (!strcmp(s, "auto")) {
|
||||
*position = WINDOW_POSITION_UNDEFINED;
|
||||
return true;
|
||||
}
|
||||
|
||||
long value;
|
||||
bool ok = parse_integer_arg(s, &value, false, -0x7FFF, 0x7FFF,
|
||||
"window position");
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*position = (int16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_window_dimension(const char *s, uint16_t *dimension) {
|
||||
long value;
|
||||
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF,
|
||||
"window dimension");
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*dimension = (uint16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_port_range(const char *s, struct port_range *port_range) {
|
||||
long values[2];
|
||||
size_t count = parse_integers_arg(s, 2, values, 0, 0xFFFF, "port");
|
||||
if (!count) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t v0 = (uint16_t) values[0];
|
||||
if (count == 1) {
|
||||
port_range->first = v0;
|
||||
port_range->last = v0;
|
||||
return true;
|
||||
}
|
||||
|
||||
assert(count == 2);
|
||||
uint16_t v1 = (uint16_t) values[1];
|
||||
if (v0 < v1) {
|
||||
port_range->first = v0;
|
||||
port_range->last = v1;
|
||||
} else {
|
||||
port_range->first = v1;
|
||||
port_range->last = v0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_display_id(const char *s, uint16_t *display_id) {
|
||||
long value;
|
||||
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF, "display id");
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*display_id = (uint16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_record_format(const char *optarg, enum recorder_format *format) {
|
||||
if (!strcmp(optarg, "mp4")) {
|
||||
*format = RECORDER_FORMAT_MP4;
|
||||
return true;
|
||||
}
|
||||
if (!strcmp(optarg, "mkv")) {
|
||||
*format = RECORDER_FORMAT_MKV;
|
||||
return true;
|
||||
}
|
||||
LOGE("Unsupported format: %s (expected mp4 or mkv)", optarg);
|
||||
return false;
|
||||
}
|
||||
|
||||
static enum recorder_format
|
||||
guess_record_format(const char *filename) {
|
||||
size_t len = strlen(filename);
|
||||
if (len < 4) {
|
||||
return 0;
|
||||
}
|
||||
const char *ext = &filename[len - 4];
|
||||
if (!strcmp(ext, ".mp4")) {
|
||||
return RECORDER_FORMAT_MP4;
|
||||
}
|
||||
if (!strcmp(ext, ".mkv")) {
|
||||
return RECORDER_FORMAT_MKV;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define OPT_RENDER_EXPIRED_FRAMES 1000
|
||||
#define OPT_WINDOW_TITLE 1001
|
||||
#define OPT_PUSH_TARGET 1002
|
||||
#define OPT_ALWAYS_ON_TOP 1003
|
||||
#define OPT_CROP 1004
|
||||
#define OPT_RECORD_FORMAT 1005
|
||||
#define OPT_PREFER_TEXT 1006
|
||||
#define OPT_WINDOW_X 1007
|
||||
#define OPT_WINDOW_Y 1008
|
||||
#define OPT_WINDOW_WIDTH 1009
|
||||
#define OPT_WINDOW_HEIGHT 1010
|
||||
#define OPT_WINDOW_BORDERLESS 1011
|
||||
#define OPT_MAX_FPS 1012
|
||||
#define OPT_LOCK_VIDEO_ORIENTATION 1013
|
||||
#define OPT_DISPLAY_ID 1014
|
||||
|
||||
bool
|
||||
scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
||||
static const struct option long_options[] = {
|
||||
{"always-on-top", no_argument, NULL, OPT_ALWAYS_ON_TOP},
|
||||
{"bit-rate", required_argument, NULL, 'b'},
|
||||
{"crop", required_argument, NULL, OPT_CROP},
|
||||
{"display", required_argument, NULL, OPT_DISPLAY_ID},
|
||||
{"fullscreen", no_argument, NULL, 'f'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"lock-video-orientation", required_argument, NULL,
|
||||
OPT_LOCK_VIDEO_ORIENTATION},
|
||||
{"max-fps", required_argument, NULL, OPT_MAX_FPS},
|
||||
{"max-size", required_argument, NULL, 'm'},
|
||||
{"no-control", no_argument, NULL, 'n'},
|
||||
{"no-display", no_argument, NULL, 'N'},
|
||||
{"port", required_argument, NULL, 'p'},
|
||||
{"push-target", required_argument, NULL, OPT_PUSH_TARGET},
|
||||
{"record", required_argument, NULL, 'r'},
|
||||
{"record-format", required_argument, NULL, OPT_RECORD_FORMAT},
|
||||
{"render-expired-frames", no_argument, NULL,
|
||||
OPT_RENDER_EXPIRED_FRAMES},
|
||||
{"serial", required_argument, NULL, 's'},
|
||||
{"show-touches", no_argument, NULL, 't'},
|
||||
{"turn-screen-off", no_argument, NULL, 'S'},
|
||||
{"prefer-text", no_argument, NULL, OPT_PREFER_TEXT},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"window-title", required_argument, NULL, OPT_WINDOW_TITLE},
|
||||
{"window-x", required_argument, NULL, OPT_WINDOW_X},
|
||||
{"window-y", required_argument, NULL, OPT_WINDOW_Y},
|
||||
{"window-width", required_argument, NULL, OPT_WINDOW_WIDTH},
|
||||
{"window-height", required_argument, NULL, OPT_WINDOW_HEIGHT},
|
||||
{"window-borderless", no_argument, NULL,
|
||||
OPT_WINDOW_BORDERLESS},
|
||||
{NULL, 0, NULL, 0 },
|
||||
};
|
||||
|
||||
struct scrcpy_options *opts = &args->opts;
|
||||
|
||||
optind = 0; // reset to start from the first argument in tests
|
||||
|
||||
int c;
|
||||
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTv", long_options,
|
||||
NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'b':
|
||||
if (!parse_bit_rate(optarg, &opts->bit_rate)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
LOGW("Deprecated option -c. Use --crop instead.");
|
||||
// fall through
|
||||
case OPT_CROP:
|
||||
opts->crop = optarg;
|
||||
break;
|
||||
case OPT_DISPLAY_ID:
|
||||
if (!parse_display_id(optarg, &opts->display_id)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
opts->fullscreen = true;
|
||||
break;
|
||||
case 'F':
|
||||
LOGW("Deprecated option -F. Use --record-format instead.");
|
||||
// fall through
|
||||
case OPT_RECORD_FORMAT:
|
||||
if (!parse_record_format(optarg, &opts->record_format)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
args->help = true;
|
||||
break;
|
||||
case OPT_MAX_FPS:
|
||||
if (!parse_max_fps(optarg, &opts->max_fps)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
if (!parse_max_size(optarg, &opts->max_size)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_LOCK_VIDEO_ORIENTATION:
|
||||
if (!parse_lock_video_orientation(optarg, &opts->lock_video_orientation)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
opts->control = false;
|
||||
break;
|
||||
case 'N':
|
||||
opts->display = false;
|
||||
break;
|
||||
case 'p':
|
||||
if (!parse_port_range(optarg, &opts->port_range)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
opts->record_filename = optarg;
|
||||
break;
|
||||
case 's':
|
||||
opts->serial = optarg;
|
||||
break;
|
||||
case 'S':
|
||||
opts->turn_screen_off = true;
|
||||
break;
|
||||
case 't':
|
||||
opts->show_touches = true;
|
||||
break;
|
||||
case 'T':
|
||||
LOGW("Deprecated option -T. Use --always-on-top instead.");
|
||||
// fall through
|
||||
case OPT_ALWAYS_ON_TOP:
|
||||
opts->always_on_top = true;
|
||||
break;
|
||||
case 'v':
|
||||
args->version = true;
|
||||
break;
|
||||
case OPT_RENDER_EXPIRED_FRAMES:
|
||||
opts->render_expired_frames = true;
|
||||
break;
|
||||
case OPT_WINDOW_TITLE:
|
||||
opts->window_title = optarg;
|
||||
break;
|
||||
case OPT_WINDOW_X:
|
||||
if (!parse_window_position(optarg, &opts->window_x)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_Y:
|
||||
if (!parse_window_position(optarg, &opts->window_y)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_WIDTH:
|
||||
if (!parse_window_dimension(optarg, &opts->window_width)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_HEIGHT:
|
||||
if (!parse_window_dimension(optarg, &opts->window_height)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_BORDERLESS:
|
||||
opts->window_borderless = true;
|
||||
break;
|
||||
case OPT_PUSH_TARGET:
|
||||
opts->push_target = optarg;
|
||||
break;
|
||||
case OPT_PREFER_TEXT:
|
||||
opts->prefer_text = true;
|
||||
break;
|
||||
default:
|
||||
// getopt prints the error message on stderr
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!opts->display && !opts->record_filename) {
|
||||
LOGE("-N/--no-display requires screen recording (-r/--record)");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!opts->display && opts->fullscreen) {
|
||||
LOGE("-f/--fullscreen-window is incompatible with -N/--no-display");
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = optind;
|
||||
if (index < argc) {
|
||||
LOGE("Unexpected additional argument: %s", argv[index]);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opts->record_format && !opts->record_filename) {
|
||||
LOGE("Record format specified without recording");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opts->record_filename && !opts->record_format) {
|
||||
opts->record_format = guess_record_format(opts->record_filename);
|
||||
if (!opts->record_format) {
|
||||
LOGE("No format specified for \"%s\" (try with -F mkv)",
|
||||
opts->record_filename);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!opts->control && opts->turn_screen_off) {
|
||||
LOGE("Could not request to turn screen off if control is disabled");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
21
app/src/cli.h
Normal file
21
app/src/cli.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef SCRCPY_CLI_H
|
||||
#define SCRCPY_CLI_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "scrcpy.h"
|
||||
|
||||
struct scrcpy_cli_args {
|
||||
struct scrcpy_options opts;
|
||||
bool help;
|
||||
bool version;
|
||||
};
|
||||
|
||||
void
|
||||
scrcpy_print_usage(const char *arg0);
|
||||
|
||||
bool
|
||||
scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]);
|
||||
|
||||
#endif
|
@ -55,6 +55,32 @@ argv_to_string(const char *const *argv, char *buf, size_t bufsize) {
|
||||
return idx;
|
||||
}
|
||||
|
||||
static void
|
||||
show_adb_installation_msg() {
|
||||
#ifndef __WINDOWS__
|
||||
static const struct {
|
||||
const char *binary;
|
||||
const char *command;
|
||||
} pkg_managers[] = {
|
||||
{"apt", "apt install adb"},
|
||||
{"apt-get", "apt-get install adb"},
|
||||
{"brew", "brew cask install android-platform-tools"},
|
||||
{"dnf", "dnf install android-tools"},
|
||||
{"emerge", "emerge dev-util/android-tools"},
|
||||
{"pacman", "pacman -S android-tools"},
|
||||
};
|
||||
for (size_t i = 0; i < ARRAY_LEN(pkg_managers); ++i) {
|
||||
if (cmd_search(pkg_managers[i].binary)) {
|
||||
LOGI("You may install 'adb' by \"%s\"", pkg_managers[i].command);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
LOGI("You may download and install 'adb' from "
|
||||
"https://developer.android.com/studio/releases/platform-tools");
|
||||
}
|
||||
|
||||
static void
|
||||
show_adb_err_msg(enum process_result err, const char *const argv[]) {
|
||||
char buf[512];
|
||||
@ -68,6 +94,7 @@ show_adb_err_msg(enum process_result err, const char *const argv[]) {
|
||||
LOGE("Command not found: %s", buf);
|
||||
LOGE("(make 'adb' accessible from your PATH or define its full"
|
||||
"path in the ADB environment variable)");
|
||||
show_adb_installation_msg();
|
||||
break;
|
||||
case PROCESS_SUCCESS:
|
||||
// do nothing
|
||||
|
@ -43,6 +43,11 @@ enum process_result {
|
||||
PROCESS_ERROR_MISSING_BINARY,
|
||||
};
|
||||
|
||||
#ifndef __WINDOWS__
|
||||
bool
|
||||
cmd_search(const char *file);
|
||||
#endif
|
||||
|
||||
enum process_result
|
||||
cmd_execute(const char *const argv[], process_t *process);
|
||||
|
||||
@ -85,4 +90,8 @@ process_check_success(process_t proc, const char *name);
|
||||
char *
|
||||
get_executable_path(void);
|
||||
|
||||
// returns true if the file exists and is not a directory
|
||||
bool
|
||||
is_regular_file(const char *path);
|
||||
|
||||
#endif
|
||||
|
@ -27,4 +27,9 @@ struct position {
|
||||
struct point point;
|
||||
};
|
||||
|
||||
struct port_range {
|
||||
uint16_t first;
|
||||
uint16_t last;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -94,6 +94,23 @@ convert_keycode(SDL_Keycode from, enum android_keycode *to, uint16_t mod,
|
||||
MAP(SDLK_UP, AKEYCODE_DPAD_UP);
|
||||
}
|
||||
|
||||
if (!(mod & (KMOD_NUM | KMOD_SHIFT))) {
|
||||
// Handle Numpad events when Num Lock is disabled
|
||||
// If SHIFT is pressed, a text event will be sent instead
|
||||
switch(from) {
|
||||
MAP(SDLK_KP_0, AKEYCODE_INSERT);
|
||||
MAP(SDLK_KP_1, AKEYCODE_MOVE_END);
|
||||
MAP(SDLK_KP_2, AKEYCODE_DPAD_DOWN);
|
||||
MAP(SDLK_KP_3, AKEYCODE_PAGE_DOWN);
|
||||
MAP(SDLK_KP_4, AKEYCODE_DPAD_LEFT);
|
||||
MAP(SDLK_KP_6, AKEYCODE_DPAD_RIGHT);
|
||||
MAP(SDLK_KP_7, AKEYCODE_MOVE_HOME);
|
||||
MAP(SDLK_KP_8, AKEYCODE_DPAD_UP);
|
||||
MAP(SDLK_KP_9, AKEYCODE_PAGE_UP);
|
||||
MAP(SDLK_KP_PERIOD, AKEYCODE_FORWARD_DEL);
|
||||
}
|
||||
}
|
||||
|
||||
if (prefer_text) {
|
||||
// do not forward alpha and space key events
|
||||
return false;
|
||||
|
578
app/src/main.c
578
app/src/main.c
@ -1,210 +1,16 @@
|
||||
#include "scrcpy.h"
|
||||
|
||||
#include <getopt.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "cli.h"
|
||||
#include "compat.h"
|
||||
#include "recorder.h"
|
||||
#include "util/log.h"
|
||||
|
||||
struct args {
|
||||
struct scrcpy_options opts;
|
||||
bool help;
|
||||
bool version;
|
||||
};
|
||||
|
||||
static void usage(const char *arg0) {
|
||||
#ifdef __APPLE__
|
||||
# define CTRL_OR_CMD "Cmd"
|
||||
#else
|
||||
# define CTRL_OR_CMD "Ctrl"
|
||||
#endif
|
||||
fprintf(stderr,
|
||||
"Usage: %s [options]\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
"\n"
|
||||
" --always-on-top\n"
|
||||
" Make scrcpy window always on top (above other windows).\n"
|
||||
"\n"
|
||||
" -b, --bit-rate value\n"
|
||||
" Encode the video at the given bit-rate, expressed in bits/s.\n"
|
||||
" Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
|
||||
" Default is %d.\n"
|
||||
"\n"
|
||||
" --crop width:height:x:y\n"
|
||||
" Crop the device screen on the server.\n"
|
||||
" The values are expressed in the device natural orientation\n"
|
||||
" (typically, portrait for a phone, landscape for a tablet).\n"
|
||||
" Any --max-size value is computed on the cropped size.\n"
|
||||
"\n"
|
||||
" -f, --fullscreen\n"
|
||||
" Start in fullscreen.\n"
|
||||
"\n"
|
||||
" -h, --help\n"
|
||||
" Print this help.\n"
|
||||
"\n"
|
||||
" --max-fps value\n"
|
||||
" Limit the frame rate of screen capture (only supported on\n"
|
||||
" devices with Android >= 10).\n"
|
||||
"\n"
|
||||
" -m, --max-size value\n"
|
||||
" Limit both the width and height of the video to value. The\n"
|
||||
" other dimension is computed so that the device aspect-ratio\n"
|
||||
" is preserved.\n"
|
||||
" Default is %d%s.\n"
|
||||
"\n"
|
||||
" -n, --no-control\n"
|
||||
" Disable device control (mirror the device in read-only).\n"
|
||||
"\n"
|
||||
" -N, --no-display\n"
|
||||
" Do not display device (only when screen recording is\n"
|
||||
" enabled).\n"
|
||||
"\n"
|
||||
" -p, --port port\n"
|
||||
" Set the TCP port the client listens on.\n"
|
||||
" Default is %d.\n"
|
||||
"\n"
|
||||
" --prefer-text\n"
|
||||
" Inject alpha characters and space as text events instead of\n"
|
||||
" key events.\n"
|
||||
" This avoids issues when combining multiple keys to enter a\n"
|
||||
" special character, but breaks the expected behavior of alpha\n"
|
||||
" keys in games (typically WASD).\n"
|
||||
"\n"
|
||||
" --push-target path\n"
|
||||
" Set the target directory for pushing files to the device by\n"
|
||||
" drag & drop. It is passed as-is to \"adb push\".\n"
|
||||
" Default is \"/sdcard/\".\n"
|
||||
"\n"
|
||||
" -r, --record file.mp4\n"
|
||||
" Record screen to file.\n"
|
||||
" The format is determined by the --record-format option if\n"
|
||||
" set, or by the file extension (.mp4 or .mkv).\n"
|
||||
"\n"
|
||||
" --record-format format\n"
|
||||
" Force recording format (either mp4 or mkv).\n"
|
||||
"\n"
|
||||
" --render-expired-frames\n"
|
||||
" By default, to minimize latency, scrcpy always renders the\n"
|
||||
" last available decoded frame, and drops any previous ones.\n"
|
||||
" This flag forces to render all frames, at a cost of a\n"
|
||||
" possible increased latency.\n"
|
||||
"\n"
|
||||
" -s, --serial serial\n"
|
||||
" The device serial number. Mandatory only if several devices\n"
|
||||
" are connected to adb.\n"
|
||||
"\n"
|
||||
" -S, --turn-screen-off\n"
|
||||
" Turn the device screen off immediately.\n"
|
||||
"\n"
|
||||
" -t, --show-touches\n"
|
||||
" Enable \"show touches\" on start, disable on quit.\n"
|
||||
" It only shows physical touches (not clicks from scrcpy).\n"
|
||||
"\n"
|
||||
" -v, --version\n"
|
||||
" Print the version of scrcpy.\n"
|
||||
"\n"
|
||||
" --window-borderless\n"
|
||||
" Disable window decorations (display borderless window).\n"
|
||||
"\n"
|
||||
" --window-title text\n"
|
||||
" Set a custom window title.\n"
|
||||
"\n"
|
||||
" --window-x value\n"
|
||||
" Set the initial window horizontal position.\n"
|
||||
" Default is -1 (automatic).\n"
|
||||
"\n"
|
||||
" --window-y value\n"
|
||||
" Set the initial window vertical position.\n"
|
||||
" Default is -1 (automatic).\n"
|
||||
"\n"
|
||||
" --window-width value\n"
|
||||
" Set the initial window width.\n"
|
||||
" Default is 0 (automatic).\n"
|
||||
"\n"
|
||||
" --window-height value\n"
|
||||
" Set the initial window width.\n"
|
||||
" Default is 0 (automatic).\n"
|
||||
"\n"
|
||||
"Shortcuts:\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+f\n"
|
||||
" switch fullscreen mode\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+g\n"
|
||||
" resize window to 1:1 (pixel-perfect)\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+x\n"
|
||||
" Double-click on black borders\n"
|
||||
" resize window to remove black borders\n"
|
||||
"\n"
|
||||
" Ctrl+h\n"
|
||||
" Middle-click\n"
|
||||
" click on HOME\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+b\n"
|
||||
" " CTRL_OR_CMD "+Backspace\n"
|
||||
" Right-click (when screen is on)\n"
|
||||
" click on BACK\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+s\n"
|
||||
" click on APP_SWITCH\n"
|
||||
"\n"
|
||||
" Ctrl+m\n"
|
||||
" click on MENU\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+Up\n"
|
||||
" click on VOLUME_UP\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+Down\n"
|
||||
" click on VOLUME_DOWN\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+p\n"
|
||||
" click on POWER (turn screen on/off)\n"
|
||||
"\n"
|
||||
" Right-click (when screen is off)\n"
|
||||
" power on\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+o\n"
|
||||
" turn device screen off (keep mirroring)\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+r\n"
|
||||
" rotate device screen\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+n\n"
|
||||
" expand notification panel\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+Shift+n\n"
|
||||
" collapse notification panel\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+c\n"
|
||||
" copy device clipboard to computer\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+v\n"
|
||||
" paste computer clipboard to device\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+Shift+v\n"
|
||||
" copy computer clipboard to device\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+i\n"
|
||||
" enable/disable FPS counter (print frames/second in logs)\n"
|
||||
"\n"
|
||||
" Drag & drop APK file\n"
|
||||
" install APK from computer\n"
|
||||
"\n",
|
||||
arg0,
|
||||
DEFAULT_BIT_RATE,
|
||||
DEFAULT_MAX_SIZE, DEFAULT_MAX_SIZE ? "" : " (unlimited)",
|
||||
DEFAULT_LOCAL_PORT);
|
||||
}
|
||||
|
||||
static void
|
||||
print_version(void) {
|
||||
fprintf(stderr, "scrcpy %s\n\n", SCRCPY_VERSION);
|
||||
@ -223,373 +29,6 @@ print_version(void) {
|
||||
LIBAVUTIL_VERSION_MICRO);
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_bit_rate(char *optarg, uint32_t *bit_rate) {
|
||||
char *endptr;
|
||||
if (*optarg == '\0') {
|
||||
LOGE("Bit-rate parameter is empty");
|
||||
return false;
|
||||
}
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
int mul = 1;
|
||||
if (*endptr != '\0') {
|
||||
if (optarg == endptr) {
|
||||
LOGE("Invalid bit-rate: %s", optarg);
|
||||
return false;
|
||||
}
|
||||
if ((*endptr == 'M' || *endptr == 'm') && endptr[1] == '\0') {
|
||||
mul = 1000000;
|
||||
} else if ((*endptr == 'K' || *endptr == 'k') && endptr[1] == '\0') {
|
||||
mul = 1000;
|
||||
} else {
|
||||
LOGE("Invalid bit-rate unit: %s", optarg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (value < 0 || ((uint32_t) -1) / mul < (unsigned long) value) {
|
||||
LOGE("Bitrate must be positive and less than 2^32: %s", optarg);
|
||||
return false;
|
||||
}
|
||||
|
||||
*bit_rate = (uint32_t) value * mul;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_max_size(char *optarg, uint16_t *max_size) {
|
||||
char *endptr;
|
||||
if (*optarg == '\0') {
|
||||
LOGE("Max size parameter is empty");
|
||||
return false;
|
||||
}
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*endptr != '\0') {
|
||||
LOGE("Invalid max size: %s", optarg);
|
||||
return false;
|
||||
}
|
||||
if (value & ~0xffff) {
|
||||
LOGE("Max size must be between 0 and 65535: %ld", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
*max_size = (uint16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_max_fps(const char *optarg, uint16_t *max_fps) {
|
||||
char *endptr;
|
||||
if (*optarg == '\0') {
|
||||
LOGE("Max FPS parameter is empty");
|
||||
return false;
|
||||
}
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*endptr != '\0') {
|
||||
LOGE("Invalid max FPS: %s", optarg);
|
||||
return false;
|
||||
}
|
||||
if (value & ~0xffff) {
|
||||
// in practice, it should not be higher than 60
|
||||
LOGE("Max FPS value is invalid: %ld", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
*max_fps = (uint16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_window_position(char *optarg, int16_t *position) {
|
||||
char *endptr;
|
||||
if (*optarg == '\0') {
|
||||
LOGE("Window position parameter is empty");
|
||||
return false;
|
||||
}
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*endptr != '\0') {
|
||||
LOGE("Invalid window position: %s", optarg);
|
||||
return false;
|
||||
}
|
||||
if (value < -1 || value > 0x7fff) {
|
||||
LOGE("Window position must be between -1 and 32767: %ld", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
*position = (int16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_window_dimension(char *optarg, uint16_t *dimension) {
|
||||
char *endptr;
|
||||
if (*optarg == '\0') {
|
||||
LOGE("Window dimension parameter is empty");
|
||||
return false;
|
||||
}
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*endptr != '\0') {
|
||||
LOGE("Invalid window dimension: %s", optarg);
|
||||
return false;
|
||||
}
|
||||
if (value & ~0xffff) {
|
||||
LOGE("Window position must be between 0 and 65535: %ld", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
*dimension = (uint16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_port(char *optarg, uint16_t *port) {
|
||||
char *endptr;
|
||||
if (*optarg == '\0') {
|
||||
LOGE("Port parameter is empty");
|
||||
return false;
|
||||
}
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*endptr != '\0') {
|
||||
LOGE("Invalid port: %s", optarg);
|
||||
return false;
|
||||
}
|
||||
if (value & ~0xffff) {
|
||||
LOGE("Port out of range: %ld", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
*port = (uint16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_record_format(const char *optarg, enum recorder_format *format) {
|
||||
if (!strcmp(optarg, "mp4")) {
|
||||
*format = RECORDER_FORMAT_MP4;
|
||||
return true;
|
||||
}
|
||||
if (!strcmp(optarg, "mkv")) {
|
||||
*format = RECORDER_FORMAT_MKV;
|
||||
return true;
|
||||
}
|
||||
LOGE("Unsupported format: %s (expected mp4 or mkv)", optarg);
|
||||
return false;
|
||||
}
|
||||
|
||||
static enum recorder_format
|
||||
guess_record_format(const char *filename) {
|
||||
size_t len = strlen(filename);
|
||||
if (len < 4) {
|
||||
return 0;
|
||||
}
|
||||
const char *ext = &filename[len - 4];
|
||||
if (!strcmp(ext, ".mp4")) {
|
||||
return RECORDER_FORMAT_MP4;
|
||||
}
|
||||
if (!strcmp(ext, ".mkv")) {
|
||||
return RECORDER_FORMAT_MKV;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define OPT_RENDER_EXPIRED_FRAMES 1000
|
||||
#define OPT_WINDOW_TITLE 1001
|
||||
#define OPT_PUSH_TARGET 1002
|
||||
#define OPT_ALWAYS_ON_TOP 1003
|
||||
#define OPT_CROP 1004
|
||||
#define OPT_RECORD_FORMAT 1005
|
||||
#define OPT_PREFER_TEXT 1006
|
||||
#define OPT_WINDOW_X 1007
|
||||
#define OPT_WINDOW_Y 1008
|
||||
#define OPT_WINDOW_WIDTH 1009
|
||||
#define OPT_WINDOW_HEIGHT 1010
|
||||
#define OPT_WINDOW_BORDERLESS 1011
|
||||
#define OPT_MAX_FPS 1012
|
||||
|
||||
static bool
|
||||
parse_args(struct args *args, int argc, char *argv[]) {
|
||||
static const struct option long_options[] = {
|
||||
{"always-on-top", no_argument, NULL, OPT_ALWAYS_ON_TOP},
|
||||
{"bit-rate", required_argument, NULL, 'b'},
|
||||
{"crop", required_argument, NULL, OPT_CROP},
|
||||
{"fullscreen", no_argument, NULL, 'f'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"max-fps", required_argument, NULL, OPT_MAX_FPS},
|
||||
{"max-size", required_argument, NULL, 'm'},
|
||||
{"no-control", no_argument, NULL, 'n'},
|
||||
{"no-display", no_argument, NULL, 'N'},
|
||||
{"port", required_argument, NULL, 'p'},
|
||||
{"push-target", required_argument, NULL, OPT_PUSH_TARGET},
|
||||
{"record", required_argument, NULL, 'r'},
|
||||
{"record-format", required_argument, NULL, OPT_RECORD_FORMAT},
|
||||
{"render-expired-frames", no_argument, NULL,
|
||||
OPT_RENDER_EXPIRED_FRAMES},
|
||||
{"serial", required_argument, NULL, 's'},
|
||||
{"show-touches", no_argument, NULL, 't'},
|
||||
{"turn-screen-off", no_argument, NULL, 'S'},
|
||||
{"prefer-text", no_argument, NULL, OPT_PREFER_TEXT},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"window-title", required_argument, NULL, OPT_WINDOW_TITLE},
|
||||
{"window-x", required_argument, NULL, OPT_WINDOW_X},
|
||||
{"window-y", required_argument, NULL, OPT_WINDOW_Y},
|
||||
{"window-width", required_argument, NULL, OPT_WINDOW_WIDTH},
|
||||
{"window-height", required_argument, NULL, OPT_WINDOW_HEIGHT},
|
||||
{"window-borderless", no_argument, NULL,
|
||||
OPT_WINDOW_BORDERLESS},
|
||||
{NULL, 0, NULL, 0 },
|
||||
};
|
||||
|
||||
struct scrcpy_options *opts = &args->opts;
|
||||
|
||||
int c;
|
||||
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTv", long_options,
|
||||
NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'b':
|
||||
if (!parse_bit_rate(optarg, &opts->bit_rate)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
LOGW("Deprecated option -c. Use --crop instead.");
|
||||
// fall through
|
||||
case OPT_CROP:
|
||||
opts->crop = optarg;
|
||||
break;
|
||||
case 'f':
|
||||
opts->fullscreen = true;
|
||||
break;
|
||||
case 'F':
|
||||
LOGW("Deprecated option -F. Use --record-format instead.");
|
||||
// fall through
|
||||
case OPT_RECORD_FORMAT:
|
||||
if (!parse_record_format(optarg, &opts->record_format)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
args->help = true;
|
||||
break;
|
||||
case OPT_MAX_FPS:
|
||||
if (!parse_max_fps(optarg, &opts->max_fps)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
if (!parse_max_size(optarg, &opts->max_size)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
opts->control = false;
|
||||
break;
|
||||
case 'N':
|
||||
opts->display = false;
|
||||
break;
|
||||
case 'p':
|
||||
if (!parse_port(optarg, &opts->port)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
opts->record_filename = optarg;
|
||||
break;
|
||||
case 's':
|
||||
opts->serial = optarg;
|
||||
break;
|
||||
case 'S':
|
||||
opts->turn_screen_off = true;
|
||||
break;
|
||||
case 't':
|
||||
opts->show_touches = true;
|
||||
break;
|
||||
case 'T':
|
||||
LOGW("Deprecated option -T. Use --always-on-top instead.");
|
||||
// fall through
|
||||
case OPT_ALWAYS_ON_TOP:
|
||||
opts->always_on_top = true;
|
||||
break;
|
||||
case 'v':
|
||||
args->version = true;
|
||||
break;
|
||||
case OPT_RENDER_EXPIRED_FRAMES:
|
||||
opts->render_expired_frames = true;
|
||||
break;
|
||||
case OPT_WINDOW_TITLE:
|
||||
opts->window_title = optarg;
|
||||
break;
|
||||
case OPT_WINDOW_X:
|
||||
if (!parse_window_position(optarg, &opts->window_x)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_Y:
|
||||
if (!parse_window_position(optarg, &opts->window_y)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_WIDTH:
|
||||
if (!parse_window_dimension(optarg, &opts->window_width)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_HEIGHT:
|
||||
if (!parse_window_dimension(optarg, &opts->window_height)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_BORDERLESS:
|
||||
opts->window_borderless = true;
|
||||
break;
|
||||
case OPT_PUSH_TARGET:
|
||||
opts->push_target = optarg;
|
||||
break;
|
||||
case OPT_PREFER_TEXT:
|
||||
opts->prefer_text = true;
|
||||
break;
|
||||
default:
|
||||
// getopt prints the error message on stderr
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!opts->display && !opts->record_filename) {
|
||||
LOGE("-N/--no-display requires screen recording (-r/--record)");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!opts->display && opts->fullscreen) {
|
||||
LOGE("-f/--fullscreen-window is incompatible with -N/--no-display");
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = optind;
|
||||
if (index < argc) {
|
||||
LOGE("Unexpected additional argument: %s", argv[index]);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opts->record_format && !opts->record_filename) {
|
||||
LOGE("Record format specified without recording");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opts->record_filename && !opts->record_format) {
|
||||
opts->record_format = guess_record_format(opts->record_filename);
|
||||
if (!opts->record_format) {
|
||||
LOGE("No format specified for \"%s\" (try with -F mkv)",
|
||||
opts->record_filename);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!opts->control && opts->turn_screen_off) {
|
||||
LOGE("Could not request to turn screen off if control is disabled");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
#ifdef __WINDOWS__
|
||||
@ -598,18 +37,23 @@ main(int argc, char *argv[]) {
|
||||
setbuf(stdout, NULL);
|
||||
setbuf(stderr, NULL);
|
||||
#endif
|
||||
struct args args = {
|
||||
|
||||
#ifndef NDEBUG
|
||||
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG);
|
||||
#endif
|
||||
|
||||
struct scrcpy_cli_args args = {
|
||||
.opts = SCRCPY_OPTIONS_DEFAULT,
|
||||
.help = false,
|
||||
.version = false,
|
||||
};
|
||||
|
||||
if (!parse_args(&args, argc, argv)) {
|
||||
if (!scrcpy_parse_args(&args, argc, argv)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.help) {
|
||||
usage(argv[0]);
|
||||
scrcpy_print_usage(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -628,10 +72,6 @@ main(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG);
|
||||
#endif
|
||||
|
||||
int res = scrcpy(&args.opts) ? 0 : 1;
|
||||
|
||||
avformat_network_deinit(); // ignore failure
|
||||
|
@ -60,9 +60,9 @@ sdl_init_and_configure(bool display) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Use the best available scale quality
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2")) {
|
||||
LOGW("Could not enable bilinear filtering");
|
||||
// Linear filtering
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) {
|
||||
LOGW("Could not enable linear filtering");
|
||||
}
|
||||
|
||||
#ifdef SCRCPY_SDL_HAS_HINT_MOUSE_FOCUS_CLICKTHROUGH
|
||||
@ -280,11 +280,13 @@ scrcpy(const struct scrcpy_options *options) {
|
||||
bool record = !!options->record_filename;
|
||||
struct server_params params = {
|
||||
.crop = options->crop,
|
||||
.local_port = options->port,
|
||||
.port_range = options->port_range,
|
||||
.max_size = options->max_size,
|
||||
.bit_rate = options->bit_rate,
|
||||
.max_fps = options->max_fps,
|
||||
.lock_video_orientation = options->lock_video_orientation,
|
||||
.control = options->control,
|
||||
.display_id = options->display_id,
|
||||
};
|
||||
if (!server_start(&server, options->serial, ¶ms)) {
|
||||
return false;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
#include "input_manager.h"
|
||||
#include "recorder.h"
|
||||
|
||||
@ -15,14 +16,16 @@ struct scrcpy_options {
|
||||
const char *window_title;
|
||||
const char *push_target;
|
||||
enum recorder_format record_format;
|
||||
uint16_t port;
|
||||
struct port_range port_range;
|
||||
uint16_t max_size;
|
||||
uint32_t bit_rate;
|
||||
uint16_t max_fps;
|
||||
int16_t window_x;
|
||||
int16_t window_y;
|
||||
int8_t lock_video_orientation;
|
||||
int16_t window_x; // WINDOW_POSITION_UNDEFINED for "auto"
|
||||
int16_t window_y; // WINDOW_POSITION_UNDEFINED for "auto"
|
||||
uint16_t window_width;
|
||||
uint16_t window_height;
|
||||
uint16_t display_id;
|
||||
bool show_touches;
|
||||
bool fullscreen;
|
||||
bool always_on_top;
|
||||
@ -41,14 +44,19 @@ struct scrcpy_options {
|
||||
.window_title = NULL, \
|
||||
.push_target = NULL, \
|
||||
.record_format = RECORDER_FORMAT_AUTO, \
|
||||
.port = DEFAULT_LOCAL_PORT, \
|
||||
.max_size = DEFAULT_LOCAL_PORT, \
|
||||
.port_range = { \
|
||||
.first = DEFAULT_LOCAL_PORT_RANGE_FIRST, \
|
||||
.last = DEFAULT_LOCAL_PORT_RANGE_LAST, \
|
||||
}, \
|
||||
.max_size = DEFAULT_MAX_SIZE, \
|
||||
.bit_rate = DEFAULT_BIT_RATE, \
|
||||
.max_fps = 0, \
|
||||
.window_x = -1, \
|
||||
.window_y = -1, \
|
||||
.lock_video_orientation = DEFAULT_LOCK_VIDEO_ORIENTATION, \
|
||||
.window_x = WINDOW_POSITION_UNDEFINED, \
|
||||
.window_y = WINDOW_POSITION_UNDEFINED, \
|
||||
.window_width = 0, \
|
||||
.window_height = 0, \
|
||||
.display_id = 0, \
|
||||
.show_touches = false, \
|
||||
.fullscreen = false, \
|
||||
.always_on_top = false, \
|
||||
|
@ -186,8 +186,10 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
||||
window_flags |= SDL_WINDOW_BORDERLESS;
|
||||
}
|
||||
|
||||
int x = window_x != -1 ? window_x : (int) SDL_WINDOWPOS_UNDEFINED;
|
||||
int y = window_y != -1 ? window_y : (int) SDL_WINDOWPOS_UNDEFINED;
|
||||
int x = window_x != WINDOW_POSITION_UNDEFINED
|
||||
? window_x : (int) SDL_WINDOWPOS_UNDEFINED;
|
||||
int y = window_y != WINDOW_POSITION_UNDEFINED
|
||||
? window_y : (int) SDL_WINDOWPOS_UNDEFINED;
|
||||
screen->window = SDL_CreateWindow(window_title, x, y,
|
||||
window_size.width, window_size.height,
|
||||
window_flags);
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
|
||||
#define WINDOW_POSITION_UNDEFINED (-0x8000)
|
||||
|
||||
struct video_buffer;
|
||||
|
||||
struct screen {
|
||||
@ -53,6 +55,7 @@ void
|
||||
screen_init(struct screen *screen);
|
||||
|
||||
// initialize screen, create window, renderer and texture (window is hidden)
|
||||
// window_x and window_y accept WINDOW_POSITION_UNDEFINED
|
||||
bool
|
||||
screen_init_rendering(struct screen *screen, const char *window_title,
|
||||
struct size frame_size, bool always_on_top,
|
||||
|
278
app/src/server.c
278
app/src/server.c
@ -5,12 +5,15 @@
|
||||
#include <inttypes.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL2/SDL_thread.h>
|
||||
#include <SDL2/SDL_timer.h>
|
||||
#include <SDL2/SDL_platform.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "command.h"
|
||||
#include "util/log.h"
|
||||
#include "util/net.h"
|
||||
#include "util/str_util.h"
|
||||
|
||||
#define SOCKET_NAME "scrcpy"
|
||||
#define SERVER_FILENAME "scrcpy-server"
|
||||
@ -18,20 +21,39 @@
|
||||
#define DEFAULT_SERVER_PATH PREFIX "/share/scrcpy/" SERVER_FILENAME
|
||||
#define DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
|
||||
|
||||
static const char *
|
||||
static char *
|
||||
get_server_path(void) {
|
||||
#ifdef __WINDOWS__
|
||||
const wchar_t *server_path_env = _wgetenv(L"SCRCPY_SERVER_PATH");
|
||||
#else
|
||||
const char *server_path_env = getenv("SCRCPY_SERVER_PATH");
|
||||
#endif
|
||||
if (server_path_env) {
|
||||
LOGD("Using SCRCPY_SERVER_PATH: %s", server_path_env);
|
||||
// if the envvar is set, use it
|
||||
return server_path_env;
|
||||
#ifdef __WINDOWS__
|
||||
char *server_path = utf8_from_wide_char(server_path_env);
|
||||
#else
|
||||
char *server_path = SDL_strdup(server_path_env);
|
||||
#endif
|
||||
if (!server_path) {
|
||||
LOGE("Could not allocate memory");
|
||||
return NULL;
|
||||
}
|
||||
LOGD("Using SCRCPY_SERVER_PATH: %s", server_path);
|
||||
return server_path;
|
||||
}
|
||||
|
||||
#ifndef PORTABLE
|
||||
LOGD("Using server: " DEFAULT_SERVER_PATH);
|
||||
char *server_path = SDL_strdup(DEFAULT_SERVER_PATH);
|
||||
if (!server_path) {
|
||||
LOGE("Could not allocate memory");
|
||||
return NULL;
|
||||
}
|
||||
// the absolute path is hardcoded
|
||||
return DEFAULT_SERVER_PATH;
|
||||
return server_path;
|
||||
#else
|
||||
|
||||
// use scrcpy-server in the same directory as the executable
|
||||
char *executable_path = get_executable_path();
|
||||
if (!executable_path) {
|
||||
@ -67,7 +89,17 @@ get_server_path(void) {
|
||||
|
||||
static bool
|
||||
push_server(const char *serial) {
|
||||
process_t process = adb_push(serial, get_server_path(), DEVICE_SERVER_PATH);
|
||||
char *server_path = get_server_path();
|
||||
if (!server_path) {
|
||||
return false;
|
||||
}
|
||||
if (!is_regular_file(server_path)) {
|
||||
LOGE("'%s' does not exist or is not a regular file\n", server_path);
|
||||
SDL_free(server_path);
|
||||
return false;
|
||||
}
|
||||
process_t process = adb_push(serial, server_path, DEVICE_SERVER_PATH);
|
||||
SDL_free(server_path);
|
||||
return process_check_success(process, "adb push");
|
||||
}
|
||||
|
||||
@ -95,17 +127,6 @@ disable_tunnel_forward(const char *serial, uint16_t local_port) {
|
||||
return process_check_success(process, "adb forward --remove");
|
||||
}
|
||||
|
||||
static bool
|
||||
enable_tunnel(struct server *server) {
|
||||
if (enable_tunnel_reverse(server->serial, server->local_port)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
LOGW("'adb reverse' failed, fallback to 'adb forward'");
|
||||
server->tunnel_forward = true;
|
||||
return enable_tunnel_forward(server->serial, server->local_port);
|
||||
}
|
||||
|
||||
static bool
|
||||
disable_tunnel(struct server *server) {
|
||||
if (server->tunnel_forward) {
|
||||
@ -114,21 +135,125 @@ disable_tunnel(struct server *server) {
|
||||
return disable_tunnel_reverse(server->serial);
|
||||
}
|
||||
|
||||
static socket_t
|
||||
listen_on_port(uint16_t port) {
|
||||
#define IPV4_LOCALHOST 0x7F000001
|
||||
return net_listen(IPV4_LOCALHOST, port, 1);
|
||||
}
|
||||
|
||||
static bool
|
||||
enable_tunnel_reverse_any_port(struct server *server,
|
||||
struct port_range port_range) {
|
||||
uint16_t port = port_range.first;
|
||||
for (;;) {
|
||||
if (!enable_tunnel_reverse(server->serial, port)) {
|
||||
// the command itself failed, it will fail on any port
|
||||
return false;
|
||||
}
|
||||
|
||||
// At the application level, the device part is "the server" because it
|
||||
// serves video stream and control. However, at the network level, the
|
||||
// client listens and the server connects to the client. That way, the
|
||||
// client can listen before starting the server app, so there is no
|
||||
// need to try to connect until the server socket is listening on the
|
||||
// device.
|
||||
server->server_socket = listen_on_port(port);
|
||||
if (server->server_socket != INVALID_SOCKET) {
|
||||
// success
|
||||
server->local_port = port;
|
||||
return true;
|
||||
}
|
||||
|
||||
// failure, disable tunnel and try another port
|
||||
if (!disable_tunnel_reverse(server->serial)) {
|
||||
LOGW("Could not remove reverse tunnel on port %" PRIu16, port);
|
||||
}
|
||||
|
||||
// check before incrementing to avoid overflow on port 65535
|
||||
if (port < port_range.last) {
|
||||
LOGW("Could not listen on port %" PRIu16", retrying on %" PRIu16,
|
||||
port, port + 1);
|
||||
port++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (port_range.first == port_range.last) {
|
||||
LOGE("Could not listen on port %" PRIu16, port_range.first);
|
||||
} else {
|
||||
LOGE("Could not listen on any port in range %" PRIu16 ":%" PRIu16,
|
||||
port_range.first, port_range.last);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
enable_tunnel_forward_any_port(struct server *server,
|
||||
struct port_range port_range) {
|
||||
server->tunnel_forward = true;
|
||||
uint16_t port = port_range.first;
|
||||
for (;;) {
|
||||
if (enable_tunnel_forward(server->serial, port)) {
|
||||
// success
|
||||
server->local_port = port;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (port < port_range.last) {
|
||||
LOGW("Could not forward port %" PRIu16", retrying on %" PRIu16,
|
||||
port, port + 1);
|
||||
port++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (port_range.first == port_range.last) {
|
||||
LOGE("Could not forward port %" PRIu16, port_range.first);
|
||||
} else {
|
||||
LOGE("Could not forward any port in range %" PRIu16 ":%" PRIu16,
|
||||
port_range.first, port_range.last);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
enable_tunnel_any_port(struct server *server, struct port_range port_range) {
|
||||
if (enable_tunnel_reverse_any_port(server, port_range)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if "adb reverse" does not work (e.g. over "adb connect"), it fallbacks to
|
||||
// "adb forward", so the app socket is the client
|
||||
|
||||
LOGW("'adb reverse' failed, fallback to 'adb forward'");
|
||||
return enable_tunnel_forward_any_port(server, port_range);
|
||||
}
|
||||
|
||||
static process_t
|
||||
execute_server(struct server *server, const struct server_params *params) {
|
||||
char max_size_string[6];
|
||||
char bit_rate_string[11];
|
||||
char max_fps_string[6];
|
||||
char lock_video_orientation_string[3];
|
||||
char display_id_string[6];
|
||||
sprintf(max_size_string, "%"PRIu16, params->max_size);
|
||||
sprintf(bit_rate_string, "%"PRIu32, params->bit_rate);
|
||||
sprintf(max_fps_string, "%"PRIu16, params->max_fps);
|
||||
sprintf(lock_video_orientation_string, "%"PRIi8, params->lock_video_orientation);
|
||||
sprintf(display_id_string, "%"PRIu16, params->display_id);
|
||||
const char *const cmd[] = {
|
||||
"shell",
|
||||
"CLASSPATH=" DEVICE_SERVER_PATH,
|
||||
"app_process",
|
||||
#ifdef SERVER_DEBUGGER
|
||||
# define SERVER_DEBUGGER_PORT "5005"
|
||||
# ifdef SERVER_DEBUGGER_METHOD_NEW
|
||||
/* Android 9 and above */
|
||||
"-XjdwpProvider:internal -XjdwpOptions:transport=dt_socket,suspend=y,server=y,address="
|
||||
# else
|
||||
/* Android 8 and below */
|
||||
"-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address="
|
||||
# endif
|
||||
SERVER_DEBUGGER_PORT,
|
||||
#endif
|
||||
"/", // unused
|
||||
@ -137,10 +262,12 @@ execute_server(struct server *server, const struct server_params *params) {
|
||||
max_size_string,
|
||||
bit_rate_string,
|
||||
max_fps_string,
|
||||
lock_video_orientation_string,
|
||||
server->tunnel_forward ? "true" : "false",
|
||||
params->crop ? params->crop : "-",
|
||||
"true", // always send frame meta (packet boundaries + timestamp)
|
||||
params->control ? "true" : "false",
|
||||
display_id_string,
|
||||
};
|
||||
#ifdef SERVER_DEBUGGER
|
||||
LOGI("Server debugger waiting for a client on device port "
|
||||
@ -156,13 +283,6 @@ execute_server(struct server *server, const struct server_params *params) {
|
||||
return adb_execute(server->serial, cmd, sizeof(cmd) / sizeof(cmd[0]));
|
||||
}
|
||||
|
||||
#define IPV4_LOCALHOST 0x7F000001
|
||||
|
||||
static socket_t
|
||||
listen_on_port(uint16_t port) {
|
||||
return net_listen(IPV4_LOCALHOST, port, 1);
|
||||
}
|
||||
|
||||
static socket_t
|
||||
connect_and_read_byte(uint16_t port) {
|
||||
socket_t socket = net_connect(IPV4_LOCALHOST, port);
|
||||
@ -198,14 +318,12 @@ connect_to_server(uint16_t port, uint32_t attempts, uint32_t delay) {
|
||||
}
|
||||
|
||||
static void
|
||||
close_socket(socket_t *socket) {
|
||||
assert(*socket != INVALID_SOCKET);
|
||||
net_shutdown(*socket, SHUT_RDWR);
|
||||
if (!net_close(*socket)) {
|
||||
close_socket(socket_t socket) {
|
||||
assert(socket != INVALID_SOCKET);
|
||||
net_shutdown(socket, SHUT_RDWR);
|
||||
if (!net_close(socket)) {
|
||||
LOGW("Could not close socket");
|
||||
return;
|
||||
}
|
||||
*socket = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
void
|
||||
@ -213,10 +331,26 @@ server_init(struct server *server) {
|
||||
*server = (struct server) SERVER_INITIALIZER;
|
||||
}
|
||||
|
||||
static int
|
||||
run_wait_server(void *data) {
|
||||
struct server *server = data;
|
||||
cmd_simple_wait(server->process, NULL); // ignore exit code
|
||||
// no need for synchronization, server_socket is initialized before this
|
||||
// thread was created
|
||||
if (server->server_socket != INVALID_SOCKET
|
||||
&& SDL_AtomicCAS(&server->server_socket_closed, 0, 1)) {
|
||||
// On Linux, accept() is unblocked by shutdown(), but on Windows, it is
|
||||
// unblocked by closesocket(). Therefore, call both (close_socket()).
|
||||
close_socket(server->server_socket);
|
||||
}
|
||||
LOGD("Server terminated");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
server_start(struct server *server, const char *serial,
|
||||
const struct server_params *params) {
|
||||
server->local_port = params->local_port;
|
||||
server->port_range = params->port_range;
|
||||
|
||||
if (serial) {
|
||||
server->serial = SDL_strdup(serial);
|
||||
@ -226,49 +360,47 @@ server_start(struct server *server, const char *serial,
|
||||
}
|
||||
|
||||
if (!push_server(serial)) {
|
||||
SDL_free(server->serial);
|
||||
return false;
|
||||
goto error1;
|
||||
}
|
||||
|
||||
if (!enable_tunnel(server)) {
|
||||
SDL_free(server->serial);
|
||||
return false;
|
||||
}
|
||||
|
||||
// if "adb reverse" does not work (e.g. over "adb connect"), it fallbacks to
|
||||
// "adb forward", so the app socket is the client
|
||||
if (!server->tunnel_forward) {
|
||||
// At the application level, the device part is "the server" because it
|
||||
// serves video stream and control. However, at the network level, the
|
||||
// client listens and the server connects to the client. That way, the
|
||||
// client can listen before starting the server app, so there is no
|
||||
// need to try to connect until the server socket is listening on the
|
||||
// device.
|
||||
|
||||
server->server_socket = listen_on_port(params->local_port);
|
||||
if (server->server_socket == INVALID_SOCKET) {
|
||||
LOGE("Could not listen on port %" PRIu16, params->local_port);
|
||||
disable_tunnel(server);
|
||||
SDL_free(server->serial);
|
||||
return false;
|
||||
}
|
||||
if (!enable_tunnel_any_port(server, params->port_range)) {
|
||||
goto error1;
|
||||
}
|
||||
|
||||
// server will connect to our server socket
|
||||
server->process = execute_server(server, params);
|
||||
|
||||
if (server->process == PROCESS_NONE) {
|
||||
if (!server->tunnel_forward) {
|
||||
close_socket(&server->server_socket);
|
||||
}
|
||||
disable_tunnel(server);
|
||||
SDL_free(server->serial);
|
||||
return false;
|
||||
goto error2;
|
||||
}
|
||||
|
||||
// If the server process dies before connecting to the server socket, then
|
||||
// the client will be stuck forever on accept(). To avoid the problem, we
|
||||
// must be able to wake up the accept() call when the server dies. To keep
|
||||
// things simple and multiplatform, just spawn a new thread waiting for the
|
||||
// server process and calling shutdown()/close() on the server socket if
|
||||
// necessary to wake up any accept() blocking call.
|
||||
server->wait_server_thread =
|
||||
SDL_CreateThread(run_wait_server, "wait-server", server);
|
||||
if (!server->wait_server_thread) {
|
||||
cmd_terminate(server->process);
|
||||
cmd_simple_wait(server->process, NULL); // ignore exit code
|
||||
goto error2;
|
||||
}
|
||||
|
||||
server->tunnel_enabled = true;
|
||||
|
||||
return true;
|
||||
|
||||
error2:
|
||||
if (!server->tunnel_forward) {
|
||||
// the wait server thread is not started, SDL_AtomicSet() is sufficient
|
||||
SDL_AtomicSet(&server->server_socket_closed, 1);
|
||||
close_socket(server->server_socket);
|
||||
}
|
||||
disable_tunnel(server);
|
||||
error1:
|
||||
SDL_free(server->serial);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
@ -286,7 +418,11 @@ server_connect_to(struct server *server) {
|
||||
}
|
||||
|
||||
// we don't need the server socket anymore
|
||||
close_socket(&server->server_socket);
|
||||
if (SDL_AtomicCAS(&server->server_socket_closed, 0, 1)) {
|
||||
// close it from here
|
||||
close_socket(server->server_socket);
|
||||
// otherwise, it is closed by run_wait_server()
|
||||
}
|
||||
} else {
|
||||
uint32_t attempts = 100;
|
||||
uint32_t delay = 100; // ms
|
||||
@ -313,29 +449,27 @@ server_connect_to(struct server *server) {
|
||||
|
||||
void
|
||||
server_stop(struct server *server) {
|
||||
if (server->server_socket != INVALID_SOCKET) {
|
||||
close_socket(&server->server_socket);
|
||||
if (server->server_socket != INVALID_SOCKET
|
||||
&& SDL_AtomicCAS(&server->server_socket_closed, 0, 1)) {
|
||||
close_socket(server->server_socket);
|
||||
}
|
||||
if (server->video_socket != INVALID_SOCKET) {
|
||||
close_socket(&server->video_socket);
|
||||
close_socket(server->video_socket);
|
||||
}
|
||||
if (server->control_socket != INVALID_SOCKET) {
|
||||
close_socket(&server->control_socket);
|
||||
close_socket(server->control_socket);
|
||||
}
|
||||
|
||||
assert(server->process != PROCESS_NONE);
|
||||
|
||||
if (!cmd_terminate(server->process)) {
|
||||
LOGW("Could not terminate server");
|
||||
}
|
||||
|
||||
cmd_simple_wait(server->process, NULL); // ignore exit code
|
||||
LOGD("Server terminated");
|
||||
cmd_terminate(server->process);
|
||||
|
||||
if (server->tunnel_enabled) {
|
||||
// ignore failure
|
||||
disable_tunnel(server);
|
||||
}
|
||||
|
||||
SDL_WaitThread(server->wait_server_thread, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -3,40 +3,54 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <SDL2/SDL_atomic.h>
|
||||
#include <SDL2/SDL_thread.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "command.h"
|
||||
#include "common.h"
|
||||
#include "util/net.h"
|
||||
|
||||
struct server {
|
||||
char *serial;
|
||||
process_t process;
|
||||
SDL_Thread *wait_server_thread;
|
||||
SDL_atomic_t server_socket_closed;
|
||||
socket_t server_socket; // only used if !tunnel_forward
|
||||
socket_t video_socket;
|
||||
socket_t control_socket;
|
||||
uint16_t local_port;
|
||||
struct port_range port_range;
|
||||
uint16_t local_port; // selected from port_range
|
||||
bool tunnel_enabled;
|
||||
bool tunnel_forward; // use "adb forward" instead of "adb reverse"
|
||||
};
|
||||
|
||||
#define SERVER_INITIALIZER { \
|
||||
.serial = NULL, \
|
||||
.process = PROCESS_NONE, \
|
||||
.server_socket = INVALID_SOCKET, \
|
||||
.video_socket = INVALID_SOCKET, \
|
||||
#define SERVER_INITIALIZER { \
|
||||
.serial = NULL, \
|
||||
.process = PROCESS_NONE, \
|
||||
.wait_server_thread = NULL, \
|
||||
.server_socket_closed = {0}, \
|
||||
.server_socket = INVALID_SOCKET, \
|
||||
.video_socket = INVALID_SOCKET, \
|
||||
.control_socket = INVALID_SOCKET, \
|
||||
.local_port = 0, \
|
||||
.tunnel_enabled = false, \
|
||||
.tunnel_forward = false, \
|
||||
.port_range = { \
|
||||
.first = 0, \
|
||||
.last = 0, \
|
||||
}, \
|
||||
.local_port = 0, \
|
||||
.tunnel_enabled = false, \
|
||||
.tunnel_forward = false, \
|
||||
}
|
||||
|
||||
struct server_params {
|
||||
const char *crop;
|
||||
uint16_t local_port;
|
||||
struct port_range port_range;
|
||||
uint16_t max_size;
|
||||
uint32_t bit_rate;
|
||||
uint16_t max_fps;
|
||||
int8_t lock_video_orientation;
|
||||
bool control;
|
||||
uint16_t display_id;
|
||||
};
|
||||
|
||||
// init default values
|
||||
|
@ -14,12 +14,50 @@
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
bool
|
||||
cmd_search(const char *file) {
|
||||
char *path = getenv("PATH");
|
||||
if (!path)
|
||||
return false;
|
||||
path = strdup(path);
|
||||
if (!path)
|
||||
return false;
|
||||
|
||||
bool ret = false;
|
||||
size_t file_len = strlen(file);
|
||||
char *saveptr;
|
||||
for (char *dir = strtok_r(path, ":", &saveptr); dir;
|
||||
dir = strtok_r(NULL, ":", &saveptr)) {
|
||||
size_t dir_len = strlen(dir);
|
||||
char *fullpath = malloc(dir_len + file_len + 2);
|
||||
if (!fullpath)
|
||||
continue;
|
||||
memcpy(fullpath, dir, dir_len);
|
||||
fullpath[dir_len] = '/';
|
||||
memcpy(fullpath + dir_len + 1, file, file_len + 1);
|
||||
|
||||
struct stat sb;
|
||||
bool fullpath_executable = stat(fullpath, &sb) == 0 &&
|
||||
sb.st_mode & S_IXUSR;
|
||||
free(fullpath);
|
||||
if (fullpath_executable) {
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
enum process_result
|
||||
cmd_execute(const char *const argv[], pid_t *pid) {
|
||||
int fd[2];
|
||||
@ -127,3 +165,14 @@ get_executable_path(void) {
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
is_regular_file(const char *path) {
|
||||
struct stat path_stat;
|
||||
|
||||
if (stat(path, &path_stat)) {
|
||||
perror("stat");
|
||||
return false;
|
||||
}
|
||||
return S_ISREG(path_stat.st_mode);
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
#include "util/net.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
bool
|
||||
net_init(void) {
|
||||
// do nothing
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
net_cleanup(void) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
bool
|
||||
net_close(socket_t socket) {
|
||||
return !close(socket);
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
#include "command.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "util/log.h"
|
||||
#include "util/str_util.h"
|
||||
@ -90,3 +92,22 @@ get_executable_path(void) {
|
||||
buf[len] = '\0';
|
||||
return utf8_from_wide_char(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
is_regular_file(const char *path) {
|
||||
wchar_t *wide_path = utf8_to_wide_char(path);
|
||||
if (!wide_path) {
|
||||
LOGC("Could not allocate wide char string");
|
||||
return false;
|
||||
}
|
||||
|
||||
struct _stat path_stat;
|
||||
int r = _wstat(wide_path, &path_stat);
|
||||
SDL_free(wide_path);
|
||||
|
||||
if (r) {
|
||||
perror("stat");
|
||||
return false;
|
||||
}
|
||||
return S_ISREG(path_stat.st_mode);
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
#include "util/net.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "util/log.h"
|
||||
|
||||
bool
|
||||
net_init(void) {
|
||||
WSADATA wsa;
|
||||
int res = WSAStartup(MAKEWORD(2, 2), &wsa) < 0;
|
||||
if (res < 0) {
|
||||
LOGC("WSAStartup failed with error %d", res);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
net_cleanup(void) {
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
bool
|
||||
net_close(socket_t socket) {
|
||||
return !closesocket(socket);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
#include "net.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <SDL2/SDL_platform.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
@ -115,3 +116,32 @@ bool
|
||||
net_shutdown(socket_t socket, int how) {
|
||||
return !shutdown(socket, how);
|
||||
}
|
||||
|
||||
bool
|
||||
net_init(void) {
|
||||
#ifdef __WINDOWS__
|
||||
WSADATA wsa;
|
||||
int res = WSAStartup(MAKEWORD(2, 2), &wsa) < 0;
|
||||
if (res < 0) {
|
||||
LOGC("WSAStartup failed with error %d", res);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
net_cleanup(void) {
|
||||
#ifdef __WINDOWS__
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
net_close(socket_t socket) {
|
||||
#ifdef __WINDOWS__
|
||||
return !closesocket(socket);
|
||||
#else
|
||||
return !close(socket);
|
||||
#endif
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "str_util.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -60,6 +62,88 @@ strquote(const char *src) {
|
||||
return quoted;
|
||||
}
|
||||
|
||||
bool
|
||||
parse_integer(const char *s, long *out) {
|
||||
char *endptr;
|
||||
if (*s == '\0') {
|
||||
return false;
|
||||
}
|
||||
errno = 0;
|
||||
long value = strtol(s, &endptr, 0);
|
||||
if (errno == ERANGE) {
|
||||
return false;
|
||||
}
|
||||
if (*endptr != '\0') {
|
||||
return false;
|
||||
}
|
||||
|
||||
*out = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t
|
||||
parse_integers(const char *s, const char sep, size_t max_items, long *out) {
|
||||
size_t count = 0;
|
||||
char *endptr;
|
||||
do {
|
||||
errno = 0;
|
||||
long value = strtol(s, &endptr, 0);
|
||||
if (errno == ERANGE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (endptr == s || (*endptr != sep && *endptr != '\0')) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
out[count++] = value;
|
||||
if (*endptr == sep) {
|
||||
if (count >= max_items) {
|
||||
// max items already reached, could not accept a new item
|
||||
return 0;
|
||||
}
|
||||
// parse the next token during the next iteration
|
||||
s = endptr + 1;
|
||||
}
|
||||
} while (*endptr != '\0');
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
bool
|
||||
parse_integer_with_suffix(const char *s, long *out) {
|
||||
char *endptr;
|
||||
if (*s == '\0') {
|
||||
return false;
|
||||
}
|
||||
errno = 0;
|
||||
long value = strtol(s, &endptr, 0);
|
||||
if (errno == ERANGE) {
|
||||
return false;
|
||||
}
|
||||
int mul = 1;
|
||||
if (*endptr != '\0') {
|
||||
if (s == endptr) {
|
||||
return false;
|
||||
}
|
||||
if ((*endptr == 'M' || *endptr == 'm') && endptr[1] == '\0') {
|
||||
mul = 1000000;
|
||||
} else if ((*endptr == 'K' || *endptr == 'k') && endptr[1] == '\0') {
|
||||
mul = 1000;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((value < 0 && LONG_MIN / mul > value) ||
|
||||
(value > 0 && LONG_MAX / mul < value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*out = value * mul;
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t
|
||||
utf8_truncation_index(const char *utf8, size_t max_len) {
|
||||
size_t len = strlen(utf8);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef STRUTIL_H
|
||||
#define STRUTIL_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "config.h"
|
||||
@ -25,6 +26,23 @@ xstrjoin(char *dst, const char *const tokens[], char sep, size_t n);
|
||||
char *
|
||||
strquote(const char *src);
|
||||
|
||||
// parse s as an integer into value
|
||||
// returns true if the conversion succeeded, false otherwise
|
||||
bool
|
||||
parse_integer(const char *s, long *out);
|
||||
|
||||
// parse s as integers separated by sep (for example '1234:2000')
|
||||
// returns the number of integers on success, 0 on failure
|
||||
size_t
|
||||
parse_integers(const char *s, const char sep, size_t max_items, long *out);
|
||||
|
||||
// parse s as an integer into value
|
||||
// like parse_integer(), but accept 'k'/'K' (x1000) and 'm'/'M' (x1000000) as
|
||||
// suffix
|
||||
// returns true if the conversion succeeded, false otherwise
|
||||
bool
|
||||
parse_integer_with_suffix(const char *s, long *out);
|
||||
|
||||
// return the index to truncate a UTF-8 string at a valid position
|
||||
size_t
|
||||
utf8_truncation_index(const char *utf8, size_t max_len);
|
||||
|
131
app/tests/test_cli.c
Normal file
131
app/tests/test_cli.c
Normal file
@ -0,0 +1,131 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "cli.h"
|
||||
#include "common.h"
|
||||
|
||||
static void test_flag_version(void) {
|
||||
struct scrcpy_cli_args args = {
|
||||
.opts = SCRCPY_OPTIONS_DEFAULT,
|
||||
.help = false,
|
||||
.version = false,
|
||||
};
|
||||
|
||||
char *argv[] = {"scrcpy", "-v"};
|
||||
|
||||
bool ok = scrcpy_parse_args(&args, 2, argv);
|
||||
assert(ok);
|
||||
assert(!args.help);
|
||||
assert(args.version);
|
||||
}
|
||||
|
||||
static void test_flag_help(void) {
|
||||
struct scrcpy_cli_args args = {
|
||||
.opts = SCRCPY_OPTIONS_DEFAULT,
|
||||
.help = false,
|
||||
.version = false,
|
||||
};
|
||||
|
||||
char *argv[] = {"scrcpy", "-v"};
|
||||
|
||||
bool ok = scrcpy_parse_args(&args, 2, argv);
|
||||
assert(ok);
|
||||
assert(!args.help);
|
||||
assert(args.version);
|
||||
}
|
||||
|
||||
static void test_options(void) {
|
||||
struct scrcpy_cli_args args = {
|
||||
.opts = SCRCPY_OPTIONS_DEFAULT,
|
||||
.help = false,
|
||||
.version = false,
|
||||
};
|
||||
|
||||
char *argv[] = {
|
||||
"scrcpy",
|
||||
"--always-on-top",
|
||||
"--bit-rate", "5M",
|
||||
"--crop", "100:200:300:400",
|
||||
"--fullscreen",
|
||||
"--max-fps", "30",
|
||||
"--max-size", "1024",
|
||||
"--lock-video-orientation", "2",
|
||||
// "--no-control" is not compatible with "--turn-screen-off"
|
||||
// "--no-display" is not compatible with "--fulscreen"
|
||||
"--port", "1234:1236",
|
||||
"--push-target", "/sdcard/Movies",
|
||||
"--record", "file",
|
||||
"--record-format", "mkv",
|
||||
"--render-expired-frames",
|
||||
"--serial", "0123456789abcdef",
|
||||
"--show-touches",
|
||||
"--turn-screen-off",
|
||||
"--prefer-text",
|
||||
"--window-title", "my device",
|
||||
"--window-x", "100",
|
||||
"--window-y", "-1",
|
||||
"--window-width", "600",
|
||||
"--window-height", "0",
|
||||
"--window-borderless",
|
||||
};
|
||||
|
||||
bool ok = scrcpy_parse_args(&args, ARRAY_LEN(argv), argv);
|
||||
assert(ok);
|
||||
|
||||
const struct scrcpy_options *opts = &args.opts;
|
||||
assert(opts->always_on_top);
|
||||
fprintf(stderr, "%d\n", (int) opts->bit_rate);
|
||||
assert(opts->bit_rate == 5000000);
|
||||
assert(!strcmp(opts->crop, "100:200:300:400"));
|
||||
assert(opts->fullscreen);
|
||||
assert(opts->max_fps == 30);
|
||||
assert(opts->max_size == 1024);
|
||||
assert(opts->lock_video_orientation == 2);
|
||||
assert(opts->port_range.first == 1234);
|
||||
assert(opts->port_range.last == 1236);
|
||||
assert(!strcmp(opts->push_target, "/sdcard/Movies"));
|
||||
assert(!strcmp(opts->record_filename, "file"));
|
||||
assert(opts->record_format == RECORDER_FORMAT_MKV);
|
||||
assert(opts->render_expired_frames);
|
||||
assert(!strcmp(opts->serial, "0123456789abcdef"));
|
||||
assert(opts->show_touches);
|
||||
assert(opts->turn_screen_off);
|
||||
assert(opts->prefer_text);
|
||||
assert(!strcmp(opts->window_title, "my device"));
|
||||
assert(opts->window_x == 100);
|
||||
assert(opts->window_y == -1);
|
||||
assert(opts->window_width == 600);
|
||||
assert(opts->window_height == 0);
|
||||
assert(opts->window_borderless);
|
||||
}
|
||||
|
||||
static void test_options2(void) {
|
||||
struct scrcpy_cli_args args = {
|
||||
.opts = SCRCPY_OPTIONS_DEFAULT,
|
||||
.help = false,
|
||||
.version = false,
|
||||
};
|
||||
|
||||
char *argv[] = {
|
||||
"scrcpy",
|
||||
"--no-control",
|
||||
"--no-display",
|
||||
"--record", "file.mp4", // cannot enable --no-display without recording
|
||||
};
|
||||
|
||||
bool ok = scrcpy_parse_args(&args, ARRAY_LEN(argv), argv);
|
||||
assert(ok);
|
||||
|
||||
const struct scrcpy_options *opts = &args.opts;
|
||||
assert(!opts->control);
|
||||
assert(!opts->display);
|
||||
assert(!strcmp(opts->record_filename, "file.mp4"));
|
||||
assert(opts->record_format == RECORDER_FORMAT_MP4);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_flag_version();
|
||||
test_flag_help();
|
||||
test_options();
|
||||
test_options2();
|
||||
return 0;
|
||||
};
|
@ -1,4 +1,6 @@
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
@ -168,6 +170,122 @@ static void test_utf8_truncate(void) {
|
||||
assert(count == 7); // no more chars
|
||||
}
|
||||
|
||||
static void test_parse_integer(void) {
|
||||
long value;
|
||||
bool ok = parse_integer("1234", &value);
|
||||
assert(ok);
|
||||
assert(value == 1234);
|
||||
|
||||
ok = parse_integer("-1234", &value);
|
||||
assert(ok);
|
||||
assert(value == -1234);
|
||||
|
||||
ok = parse_integer("1234k", &value);
|
||||
assert(!ok);
|
||||
|
||||
ok = parse_integer("123456789876543212345678987654321", &value);
|
||||
assert(!ok); // out-of-range
|
||||
}
|
||||
|
||||
static void test_parse_integers(void) {
|
||||
long values[5];
|
||||
|
||||
size_t count = parse_integers("1234", ':', 5, values);
|
||||
assert(count == 1);
|
||||
assert(values[0] == 1234);
|
||||
|
||||
count = parse_integers("1234:5678", ':', 5, values);
|
||||
assert(count == 2);
|
||||
assert(values[0] == 1234);
|
||||
assert(values[1] == 5678);
|
||||
|
||||
count = parse_integers("1234:5678", ':', 2, values);
|
||||
assert(count == 2);
|
||||
assert(values[0] == 1234);
|
||||
assert(values[1] == 5678);
|
||||
|
||||
count = parse_integers("1234:-5678", ':', 2, values);
|
||||
assert(count == 2);
|
||||
assert(values[0] == 1234);
|
||||
assert(values[1] == -5678);
|
||||
|
||||
count = parse_integers("1:2:3:4:5", ':', 5, values);
|
||||
assert(count == 5);
|
||||
assert(values[0] == 1);
|
||||
assert(values[1] == 2);
|
||||
assert(values[2] == 3);
|
||||
assert(values[3] == 4);
|
||||
assert(values[4] == 5);
|
||||
|
||||
count = parse_integers("1234:5678", ':', 1, values);
|
||||
assert(count == 0); // max_items == 1
|
||||
|
||||
count = parse_integers("1:2:3:4:5", ':', 3, values);
|
||||
assert(count == 0); // max_items == 3
|
||||
|
||||
count = parse_integers(":1234", ':', 5, values);
|
||||
assert(count == 0); // invalid
|
||||
|
||||
count = parse_integers("1234:", ':', 5, values);
|
||||
assert(count == 0); // invalid
|
||||
|
||||
count = parse_integers("1234:", ':', 1, values);
|
||||
assert(count == 0); // invalid, even when max_items == 1
|
||||
|
||||
count = parse_integers("1234::5678", ':', 5, values);
|
||||
assert(count == 0); // invalid
|
||||
}
|
||||
|
||||
static void test_parse_integer_with_suffix(void) {
|
||||
long value;
|
||||
bool ok = parse_integer_with_suffix("1234", &value);
|
||||
assert(ok);
|
||||
assert(value == 1234);
|
||||
|
||||
ok = parse_integer_with_suffix("-1234", &value);
|
||||
assert(ok);
|
||||
assert(value == -1234);
|
||||
|
||||
ok = parse_integer_with_suffix("1234k", &value);
|
||||
assert(ok);
|
||||
assert(value == 1234000);
|
||||
|
||||
ok = parse_integer_with_suffix("1234m", &value);
|
||||
assert(ok);
|
||||
assert(value == 1234000000);
|
||||
|
||||
ok = parse_integer_with_suffix("-1234k", &value);
|
||||
assert(ok);
|
||||
assert(value == -1234000);
|
||||
|
||||
ok = parse_integer_with_suffix("-1234m", &value);
|
||||
assert(ok);
|
||||
assert(value == -1234000000);
|
||||
|
||||
ok = parse_integer_with_suffix("123456789876543212345678987654321", &value);
|
||||
assert(!ok); // out-of-range
|
||||
|
||||
char buf[32];
|
||||
|
||||
sprintf(buf, "%ldk", LONG_MAX / 2000);
|
||||
ok = parse_integer_with_suffix(buf, &value);
|
||||
assert(ok);
|
||||
assert(value == LONG_MAX / 2000 * 1000);
|
||||
|
||||
sprintf(buf, "%ldm", LONG_MAX / 2000);
|
||||
ok = parse_integer_with_suffix(buf, &value);
|
||||
assert(!ok);
|
||||
|
||||
sprintf(buf, "%ldk", LONG_MIN / 2000);
|
||||
ok = parse_integer_with_suffix(buf, &value);
|
||||
assert(ok);
|
||||
assert(value == LONG_MIN / 2000 * 1000);
|
||||
|
||||
sprintf(buf, "%ldm", LONG_MIN / 2000);
|
||||
ok = parse_integer_with_suffix(buf, &value);
|
||||
assert(!ok);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_xstrncpy_simple();
|
||||
test_xstrncpy_just_fit();
|
||||
@ -179,5 +297,8 @@ int main(void) {
|
||||
test_xstrjoin_truncated_after_sep();
|
||||
test_strquote();
|
||||
test_utf8_truncate();
|
||||
test_parse_integer();
|
||||
test_parse_integers();
|
||||
test_parse_integer_with_suffix();
|
||||
return 0;
|
||||
}
|
||||
|
@ -129,11 +129,6 @@ page at http://checkstyle.sourceforge.net/config.html -->
|
||||
</module>
|
||||
<module name="IllegalInstantiation" />
|
||||
<module name="InnerAssignment" />
|
||||
<module name="MagicNumber">
|
||||
<property name="severity" value="info" />
|
||||
<property name="ignoreHashCodeMethod" value="true" />
|
||||
<property name="ignoreAnnotation" value="true" />
|
||||
</module>
|
||||
<module name="MissingSwitchDefault" />
|
||||
<module name="SimplifyBooleanExpression" />
|
||||
<module name="SimplifyBooleanReturn" />
|
||||
|
@ -1,5 +1,5 @@
|
||||
project('scrcpy', 'c',
|
||||
version: '1.11',
|
||||
version: '1.12.1',
|
||||
meson_version: '>= 0.37',
|
||||
default_options: [
|
||||
'c_std=c11',
|
||||
|
@ -6,3 +6,4 @@ option('prebuilt_server', type: 'string', description: 'Path of the prebuilt ser
|
||||
option('portable', type: 'boolean', value: false, description: 'Use scrcpy-server from the same directory as the scrcpy executable')
|
||||
option('hidpi_support', type: 'boolean', value: true, description: 'Enable High DPI support')
|
||||
option('server_debugger', type: 'boolean', value: false, description: 'Run a server debugger and wait for a client to be attached')
|
||||
option('server_debugger_method', type: 'combo', choices: ['old', 'new'], value: 'new', description: 'Select the debugger method (Android < 9: "old", Android >= 9: "new")')
|
||||
|
@ -6,8 +6,8 @@ android {
|
||||
applicationId "com.genymobile.scrcpy"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 29
|
||||
versionCode 12
|
||||
versionName "1.11"
|
||||
versionCode 14
|
||||
versionName "1.12.1"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
@ -12,7 +12,7 @@
|
||||
set -e
|
||||
|
||||
SCRCPY_DEBUG=false
|
||||
SCRCPY_VERSION_NAME=1.11
|
||||
SCRCPY_VERSION_NAME=1.12.1
|
||||
|
||||
PLATFORM=${ANDROID_PLATFORM:-29}
|
||||
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-29.0.2}
|
||||
|
@ -8,11 +8,10 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ControlMessageReader {
|
||||
|
||||
private static final int INJECT_KEYCODE_PAYLOAD_LENGTH = 9;
|
||||
private static final int INJECT_MOUSE_EVENT_PAYLOAD_LENGTH = 17;
|
||||
private static final int INJECT_TOUCH_EVENT_PAYLOAD_LENGTH = 21;
|
||||
private static final int INJECT_SCROLL_EVENT_PAYLOAD_LENGTH = 20;
|
||||
private static final int SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH = 1;
|
||||
static final int INJECT_KEYCODE_PAYLOAD_LENGTH = 9;
|
||||
static final int INJECT_TOUCH_EVENT_PAYLOAD_LENGTH = 27;
|
||||
static final int INJECT_SCROLL_EVENT_PAYLOAD_LENGTH = 20;
|
||||
static final int SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH = 1;
|
||||
|
||||
public static final int TEXT_MAX_LENGTH = 300;
|
||||
public static final int CLIPBOARD_TEXT_MAX_LENGTH = 4093;
|
||||
@ -122,7 +121,6 @@ public class ControlMessageReader {
|
||||
return ControlMessage.createInjectText(text);
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
private ControlMessage parseInjectTouchEvent() {
|
||||
if (buffer.remaining() < INJECT_TOUCH_EVENT_PAYLOAD_LENGTH) {
|
||||
return null;
|
||||
@ -172,12 +170,10 @@ public class ControlMessageReader {
|
||||
return new Position(x, y, screenWidth, screenHeight);
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
private static int toUnsigned(short value) {
|
||||
return value & 0xffff;
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
private static int toUnsigned(byte value) {
|
||||
return value & 0xff;
|
||||
}
|
||||
|
@ -47,7 +47,6 @@ public class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
public void control() throws IOException {
|
||||
// on start, power on the device
|
||||
if (!device.isScreenOn()) {
|
||||
@ -76,19 +75,29 @@ public class Controller {
|
||||
ControlMessage msg = connection.receiveControlMessage();
|
||||
switch (msg.getType()) {
|
||||
case ControlMessage.TYPE_INJECT_KEYCODE:
|
||||
injectKeycode(msg.getAction(), msg.getKeycode(), msg.getMetaState());
|
||||
if (device.supportsInputEvents()) {
|
||||
injectKeycode(msg.getAction(), msg.getKeycode(), msg.getMetaState());
|
||||
}
|
||||
break;
|
||||
case ControlMessage.TYPE_INJECT_TEXT:
|
||||
injectText(msg.getText());
|
||||
if (device.supportsInputEvents()) {
|
||||
injectText(msg.getText());
|
||||
}
|
||||
break;
|
||||
case ControlMessage.TYPE_INJECT_TOUCH_EVENT:
|
||||
injectTouch(msg.getAction(), msg.getPointerId(), msg.getPosition(), msg.getPressure(), msg.getButtons());
|
||||
if (device.supportsInputEvents()) {
|
||||
injectTouch(msg.getAction(), msg.getPointerId(), msg.getPosition(), msg.getPressure(), msg.getButtons());
|
||||
}
|
||||
break;
|
||||
case ControlMessage.TYPE_INJECT_SCROLL_EVENT:
|
||||
injectScroll(msg.getPosition(), msg.getHScroll(), msg.getVScroll());
|
||||
if (device.supportsInputEvents()) {
|
||||
injectScroll(msg.getPosition(), msg.getHScroll(), msg.getVScroll());
|
||||
}
|
||||
break;
|
||||
case ControlMessage.TYPE_BACK_OR_SCREEN_ON:
|
||||
pressBackOrTurnScreenOn();
|
||||
if (device.supportsInputEvents()) {
|
||||
pressBackOrTurnScreenOn();
|
||||
}
|
||||
break;
|
||||
case ControlMessage.TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||
device.expandNotificationPanel();
|
||||
@ -104,7 +113,9 @@ public class Controller {
|
||||
device.setClipboardText(msg.getText());
|
||||
break;
|
||||
case ControlMessage.TYPE_SET_SCREEN_POWER_MODE:
|
||||
device.setScreenPowerMode(msg.getAction());
|
||||
if (device.supportsInputEvents()) {
|
||||
device.setScreenPowerMode(msg.getAction());
|
||||
}
|
||||
break;
|
||||
case ControlMessage.TYPE_ROTATE_DEVICE:
|
||||
device.rotateDevice();
|
||||
|
@ -84,7 +84,6 @@ public final class DesktopConnection implements Closeable {
|
||||
controlSocket.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
private void send(String deviceName, int width, int height) throws IOException {
|
||||
byte[] buffer = new byte[DEVICE_NAME_FIELD_LENGTH + 4];
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import com.genymobile.scrcpy.wrappers.InputManager;
|
||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||
import com.genymobile.scrcpy.wrappers.SurfaceControl;
|
||||
import com.genymobile.scrcpy.wrappers.WindowManager;
|
||||
@ -25,13 +26,40 @@ public final class Device {
|
||||
private ScreenInfo screenInfo;
|
||||
private RotationListener rotationListener;
|
||||
|
||||
/**
|
||||
* Logical display identifier
|
||||
*/
|
||||
private final int displayId;
|
||||
|
||||
/**
|
||||
* The surface flinger layer stack associated with this logical display
|
||||
*/
|
||||
private final int layerStack;
|
||||
|
||||
/**
|
||||
* The FLAG_PRESENTATION from the DisplayInfo
|
||||
*/
|
||||
private final boolean isPresentationDisplay;
|
||||
|
||||
public Device(Options options) {
|
||||
screenInfo = computeScreenInfo(options.getCrop(), options.getMaxSize());
|
||||
displayId = options.getDisplayId();
|
||||
DisplayInfo displayInfo = serviceManager.getDisplayManager().getDisplayInfo(displayId);
|
||||
if (displayInfo == null) {
|
||||
int[] displayIds = serviceManager.getDisplayManager().getDisplayIds();
|
||||
throw new InvalidDisplayIdException(displayId, displayIds);
|
||||
}
|
||||
|
||||
int displayInfoFlags = displayInfo.getFlags();
|
||||
|
||||
screenInfo = ScreenInfo.computeScreenInfo(displayInfo, options.getCrop(), options.getMaxSize(), options.getLockedVideoOrientation());
|
||||
layerStack = displayInfo.getLayerStack();
|
||||
isPresentationDisplay = (displayInfoFlags & DisplayInfo.FLAG_PRESENTATION) != 0;
|
||||
|
||||
registerRotationWatcher(new IRotationWatcher.Stub() {
|
||||
@Override
|
||||
public void onRotationChanged(int rotation) throws RemoteException {
|
||||
synchronized (Device.this) {
|
||||
screenInfo = screenInfo.withRotation(rotation);
|
||||
screenInfo = screenInfo.withDeviceRotation(rotation);
|
||||
|
||||
// notify
|
||||
if (rotationListener != null) {
|
||||
@ -40,88 +68,69 @@ public final class Device {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if ((displayInfoFlags & DisplayInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS) == 0) {
|
||||
Ln.w("Display doesn't have FLAG_SUPPORTS_PROTECTED_BUFFERS flag, mirroring can be restricted");
|
||||
}
|
||||
|
||||
if (!supportsInputEvents()) {
|
||||
Ln.w("Input events are not supported for displays with FLAG_PRESENTATION enabled for devices with API lower than 29");
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized ScreenInfo getScreenInfo() {
|
||||
return screenInfo;
|
||||
}
|
||||
|
||||
private ScreenInfo computeScreenInfo(Rect crop, int maxSize) {
|
||||
DisplayInfo displayInfo = serviceManager.getDisplayManager().getDisplayInfo();
|
||||
boolean rotated = (displayInfo.getRotation() & 1) != 0;
|
||||
Size deviceSize = displayInfo.getSize();
|
||||
Rect contentRect = new Rect(0, 0, deviceSize.getWidth(), deviceSize.getHeight());
|
||||
if (crop != null) {
|
||||
if (rotated) {
|
||||
// the crop (provided by the user) is expressed in the natural orientation
|
||||
crop = flipRect(crop);
|
||||
}
|
||||
if (!contentRect.intersect(crop)) {
|
||||
// intersect() changes contentRect so that it is intersected with crop
|
||||
Ln.w("Crop rectangle (" + formatCrop(crop) + ") does not intersect device screen (" + formatCrop(deviceSize.toRect()) + ")");
|
||||
contentRect = new Rect(); // empty
|
||||
}
|
||||
}
|
||||
|
||||
Size videoSize = computeVideoSize(contentRect.width(), contentRect.height(), maxSize);
|
||||
return new ScreenInfo(contentRect, videoSize, rotated);
|
||||
}
|
||||
|
||||
private static String formatCrop(Rect rect) {
|
||||
return rect.width() + ":" + rect.height() + ":" + rect.left + ":" + rect.top;
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
private static Size computeVideoSize(int w, int h, int maxSize) {
|
||||
// Compute the video size and the padding of the content inside this video.
|
||||
// Principle:
|
||||
// - scale down the great side of the screen to maxSize (if necessary);
|
||||
// - scale down the other side so that the aspect ratio is preserved;
|
||||
// - round this value to the nearest multiple of 8 (H.264 only accepts multiples of 8)
|
||||
w &= ~7; // in case it's not a multiple of 8
|
||||
h &= ~7;
|
||||
if (maxSize > 0) {
|
||||
if (BuildConfig.DEBUG && maxSize % 8 != 0) {
|
||||
throw new AssertionError("Max size must be a multiple of 8");
|
||||
}
|
||||
boolean portrait = h > w;
|
||||
int major = portrait ? h : w;
|
||||
int minor = portrait ? w : h;
|
||||
if (major > maxSize) {
|
||||
int minorExact = minor * maxSize / major;
|
||||
// +4 to round the value to the nearest multiple of 8
|
||||
minor = (minorExact + 4) & ~7;
|
||||
major = maxSize;
|
||||
}
|
||||
w = portrait ? minor : major;
|
||||
h = portrait ? major : minor;
|
||||
}
|
||||
return new Size(w, h);
|
||||
public int getLayerStack() {
|
||||
return layerStack;
|
||||
}
|
||||
|
||||
public Point getPhysicalPoint(Position position) {
|
||||
// it hides the field on purpose, to read it with a lock
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
ScreenInfo screenInfo = getScreenInfo(); // read with synchronization
|
||||
Size videoSize = screenInfo.getVideoSize();
|
||||
Size clientVideoSize = position.getScreenSize();
|
||||
if (!videoSize.equals(clientVideoSize)) {
|
||||
|
||||
// ignore the locked video orientation, the events will apply in coordinates considered in the physical device orientation
|
||||
Size unlockedVideoSize = screenInfo.getUnlockedVideoSize();
|
||||
|
||||
int reverseVideoRotation = screenInfo.getReverseVideoRotation();
|
||||
// reverse the video rotation to apply the events
|
||||
Position devicePosition = position.rotate(reverseVideoRotation);
|
||||
|
||||
Size clientVideoSize = devicePosition.getScreenSize();
|
||||
if (!unlockedVideoSize.equals(clientVideoSize)) {
|
||||
// The client sends a click relative to a video with wrong dimensions,
|
||||
// the device may have been rotated since the event was generated, so ignore the event
|
||||
return null;
|
||||
}
|
||||
Rect contentRect = screenInfo.getContentRect();
|
||||
Point point = position.getPoint();
|
||||
int scaledX = contentRect.left + point.getX() * contentRect.width() / videoSize.getWidth();
|
||||
int scaledY = contentRect.top + point.getY() * contentRect.height() / videoSize.getHeight();
|
||||
return new Point(scaledX, scaledY);
|
||||
Point point = devicePosition.getPoint();
|
||||
int convertedX = contentRect.left + point.getX() * contentRect.width() / unlockedVideoSize.getWidth();
|
||||
int convertedY = contentRect.top + point.getY() * contentRect.height() / unlockedVideoSize.getHeight();
|
||||
return new Point(convertedX, convertedY);
|
||||
}
|
||||
|
||||
public static String getDeviceName() {
|
||||
return Build.MODEL;
|
||||
}
|
||||
|
||||
public boolean supportsInputEvents() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
return true;
|
||||
}
|
||||
return !isPresentationDisplay;
|
||||
}
|
||||
|
||||
public boolean injectInputEvent(InputEvent inputEvent, int mode) {
|
||||
if (!supportsInputEvents()) {
|
||||
throw new AssertionError("Could not inject input event if !supportsInputEvents()");
|
||||
}
|
||||
|
||||
if (displayId != 0 && !InputManager.setDisplayId(inputEvent, displayId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return serviceManager.getInputManager().injectInputEvent(inputEvent, mode);
|
||||
}
|
||||
|
||||
@ -191,8 +200,4 @@ public final class Device {
|
||||
wm.thawRotation();
|
||||
}
|
||||
}
|
||||
|
||||
static Rect flipRect(Rect crop) {
|
||||
return new Rect(crop.top, crop.left, crop.bottom, crop.right);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ public class DeviceMessageWriter {
|
||||
private final byte[] rawBuffer = new byte[MAX_EVENT_SIZE];
|
||||
private final ByteBuffer buffer = ByteBuffer.wrap(rawBuffer);
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
public void writeTo(DeviceMessage msg, OutputStream output) throws IOException {
|
||||
buffer.clear();
|
||||
buffer.put((byte) DeviceMessage.TYPE_CLIPBOARD);
|
||||
|
@ -1,12 +1,25 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
public final class DisplayInfo {
|
||||
private final int displayId;
|
||||
private final Size size;
|
||||
private final int rotation;
|
||||
private final int layerStack;
|
||||
private final int flags;
|
||||
|
||||
public DisplayInfo(Size size, int rotation) {
|
||||
public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 0x00000001;
|
||||
public static final int FLAG_PRESENTATION = 0x00000008;
|
||||
|
||||
public DisplayInfo(int displayId, Size size, int rotation, int layerStack, int flags) {
|
||||
this.displayId = displayId;
|
||||
this.size = size;
|
||||
this.rotation = rotation;
|
||||
this.layerStack = layerStack;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public int getDisplayId() {
|
||||
return displayId;
|
||||
}
|
||||
|
||||
public Size getSize() {
|
||||
@ -16,5 +29,13 @@ public final class DisplayInfo {
|
||||
public int getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public int getLayerStack() {
|
||||
return layerStack;
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
return flags;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
public class InvalidDisplayIdException extends RuntimeException {
|
||||
|
||||
private final int displayId;
|
||||
private final int[] availableDisplayIds;
|
||||
|
||||
public InvalidDisplayIdException(int displayId, int[] availableDisplayIds) {
|
||||
super("There is no display having id " + displayId);
|
||||
this.displayId = displayId;
|
||||
this.availableDisplayIds = availableDisplayIds;
|
||||
}
|
||||
|
||||
public int getDisplayId() {
|
||||
return displayId;
|
||||
}
|
||||
|
||||
public int[] getAvailableDisplayIds() {
|
||||
return availableDisplayIds;
|
||||
}
|
||||
}
|
@ -6,10 +6,12 @@ public class Options {
|
||||
private int maxSize;
|
||||
private int bitRate;
|
||||
private int maxFps;
|
||||
private int lockedVideoOrientation;
|
||||
private boolean tunnelForward;
|
||||
private Rect crop;
|
||||
private boolean sendFrameMeta; // send PTS so that the client may record properly
|
||||
private boolean control;
|
||||
private int displayId;
|
||||
|
||||
public int getMaxSize() {
|
||||
return maxSize;
|
||||
@ -35,6 +37,14 @@ public class Options {
|
||||
this.maxFps = maxFps;
|
||||
}
|
||||
|
||||
public int getLockedVideoOrientation() {
|
||||
return lockedVideoOrientation;
|
||||
}
|
||||
|
||||
public void setLockedVideoOrientation(int lockedVideoOrientation) {
|
||||
this.lockedVideoOrientation = lockedVideoOrientation;
|
||||
}
|
||||
|
||||
public boolean isTunnelForward() {
|
||||
return tunnelForward;
|
||||
}
|
||||
@ -66,4 +76,12 @@ public class Options {
|
||||
public void setControl(boolean control) {
|
||||
this.control = control;
|
||||
}
|
||||
|
||||
public int getDisplayId() {
|
||||
return displayId;
|
||||
}
|
||||
|
||||
public void setDisplayId(int displayId) {
|
||||
this.displayId = displayId;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,19 @@ public class Position {
|
||||
return screenSize;
|
||||
}
|
||||
|
||||
public Position rotate(int rotation) {
|
||||
switch (rotation) {
|
||||
case 1:
|
||||
return new Position(new Point(screenSize.getHeight() - point.getY(), point.getX()), screenSize.rotate());
|
||||
case 2:
|
||||
return new Position(new Point(screenSize.getWidth() - point.getX(), screenSize.getHeight() - point.getY()), screenSize);
|
||||
case 3:
|
||||
return new Position(new Point(point.getY(), screenSize.getWidth() - point.getX()), screenSize.rotate());
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
@ -6,7 +6,6 @@ import android.graphics.Rect;
|
||||
import android.media.MediaCodec;
|
||||
import android.media.MediaCodecInfo;
|
||||
import android.media.MediaFormat;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.view.Surface;
|
||||
|
||||
@ -19,6 +18,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||
|
||||
private static final int DEFAULT_I_FRAME_INTERVAL = 10; // seconds
|
||||
private static final int REPEAT_FRAME_DELAY_US = 100_000; // repeat after 100ms
|
||||
private static final String KEY_MAX_FPS_TO_ENCODER = "max-fps-to-encoder";
|
||||
|
||||
private static final int NO_PTS = -1;
|
||||
|
||||
@ -27,19 +27,21 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||
|
||||
private int bitRate;
|
||||
private int maxFps;
|
||||
private int lockedVideoOrientation;
|
||||
private int iFrameInterval;
|
||||
private boolean sendFrameMeta;
|
||||
private long ptsOrigin;
|
||||
|
||||
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, int iFrameInterval) {
|
||||
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, int lockedVideoOrientation, int iFrameInterval) {
|
||||
this.sendFrameMeta = sendFrameMeta;
|
||||
this.bitRate = bitRate;
|
||||
this.maxFps = maxFps;
|
||||
this.lockedVideoOrientation = lockedVideoOrientation;
|
||||
this.iFrameInterval = iFrameInterval;
|
||||
}
|
||||
|
||||
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps) {
|
||||
this(sendFrameMeta, bitRate, maxFps, DEFAULT_I_FRAME_INTERVAL);
|
||||
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, int lockedVideoOrientation) {
|
||||
this(sendFrameMeta, bitRate, maxFps, lockedVideoOrientation, DEFAULT_I_FRAME_INTERVAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,12 +64,19 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||
do {
|
||||
MediaCodec codec = createCodec();
|
||||
IBinder display = createDisplay();
|
||||
Rect contentRect = device.getScreenInfo().getContentRect();
|
||||
Rect videoRect = device.getScreenInfo().getVideoSize().toRect();
|
||||
ScreenInfo screenInfo = device.getScreenInfo();
|
||||
Rect contentRect = screenInfo.getContentRect();
|
||||
// include the locked video orientation
|
||||
Rect videoRect = screenInfo.getVideoSize().toRect();
|
||||
// does not include the locked video orientation
|
||||
Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
|
||||
int videoRotation = screenInfo.getVideoRotation();
|
||||
int layerStack = device.getLayerStack();
|
||||
|
||||
setSize(format, videoRect.width(), videoRect.height());
|
||||
configure(codec, format);
|
||||
Surface surface = codec.createInputSurface();
|
||||
setDisplaySurface(display, surface, contentRect, videoRect);
|
||||
setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
|
||||
codec.start();
|
||||
try {
|
||||
alive = encode(codec, fd);
|
||||
@ -138,7 +147,6 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||
return MediaCodec.createEncoderByType("video/avc");
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
private static MediaFormat createFormat(int bitRate, int maxFps, int iFrameInterval) {
|
||||
MediaFormat format = new MediaFormat();
|
||||
format.setString(MediaFormat.KEY_MIME, "video/avc");
|
||||
@ -150,11 +158,10 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||
// display the very first frame, and recover from bad quality when no new frames
|
||||
format.setLong(MediaFormat.KEY_REPEAT_PREVIOUS_FRAME_AFTER, REPEAT_FRAME_DELAY_US); // µs
|
||||
if (maxFps > 0) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
format.setFloat(MediaFormat.KEY_MAX_FPS_TO_ENCODER, maxFps);
|
||||
} else {
|
||||
Ln.w("Max FPS is only supported since Android 10, the option has been ignored");
|
||||
}
|
||||
// The key existed privately before Android 10:
|
||||
// <https://android.googlesource.com/platform/frameworks/base/+/625f0aad9f7a259b6881006ad8710adce57d1384%5E%21/>
|
||||
// <https://github.com/Genymobile/scrcpy/issues/488#issuecomment-567321437>
|
||||
format.setFloat(KEY_MAX_FPS_TO_ENCODER, maxFps);
|
||||
}
|
||||
return format;
|
||||
}
|
||||
@ -172,12 +179,12 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||
format.setInteger(MediaFormat.KEY_HEIGHT, height);
|
||||
}
|
||||
|
||||
private static void setDisplaySurface(IBinder display, Surface surface, Rect deviceRect, Rect displayRect) {
|
||||
private static void setDisplaySurface(IBinder display, Surface surface, int orientation, Rect deviceRect, Rect displayRect, int layerStack) {
|
||||
SurfaceControl.openTransaction();
|
||||
try {
|
||||
SurfaceControl.setDisplaySurface(display, surface);
|
||||
SurfaceControl.setDisplayProjection(display, 0, deviceRect, displayRect);
|
||||
SurfaceControl.setDisplayLayerStack(display, 0);
|
||||
SurfaceControl.setDisplayProjection(display, orientation, deviceRect, displayRect);
|
||||
SurfaceControl.setDisplayLayerStack(display, layerStack);
|
||||
} finally {
|
||||
SurfaceControl.closeTransaction();
|
||||
}
|
||||
|
@ -3,29 +3,161 @@ package com.genymobile.scrcpy;
|
||||
import android.graphics.Rect;
|
||||
|
||||
public final class ScreenInfo {
|
||||
/**
|
||||
* Device (physical) size, possibly cropped
|
||||
*/
|
||||
private final Rect contentRect; // device size, possibly cropped
|
||||
private final Size videoSize;
|
||||
private final boolean rotated;
|
||||
|
||||
public ScreenInfo(Rect contentRect, Size videoSize, boolean rotated) {
|
||||
/**
|
||||
* Video size, possibly smaller than the device size, already taking the device rotation and crop into account.
|
||||
* <p>
|
||||
* However, it does not include the locked video orientation.
|
||||
*/
|
||||
private final Size unlockedVideoSize;
|
||||
|
||||
/**
|
||||
* Device rotation, related to the natural device orientation (0, 1, 2 or 3)
|
||||
*/
|
||||
private final int deviceRotation;
|
||||
|
||||
/**
|
||||
* The locked video orientation (-1: disabled, 0: normal, 1: 90° CCW, 2: 180°, 3: 90° CW)
|
||||
*/
|
||||
private final int lockedVideoOrientation;
|
||||
|
||||
public ScreenInfo(Rect contentRect, Size unlockedVideoSize, int deviceRotation, int lockedVideoOrientation) {
|
||||
this.contentRect = contentRect;
|
||||
this.videoSize = videoSize;
|
||||
this.rotated = rotated;
|
||||
this.unlockedVideoSize = unlockedVideoSize;
|
||||
this.deviceRotation = deviceRotation;
|
||||
this.lockedVideoOrientation = lockedVideoOrientation;
|
||||
}
|
||||
|
||||
public Rect getContentRect() {
|
||||
return contentRect;
|
||||
}
|
||||
|
||||
public Size getVideoSize() {
|
||||
return videoSize;
|
||||
/**
|
||||
* Return the video size as if locked video orientation was not set.
|
||||
*
|
||||
* @return the unlocked video size
|
||||
*/
|
||||
public Size getUnlockedVideoSize() {
|
||||
return unlockedVideoSize;
|
||||
}
|
||||
|
||||
public ScreenInfo withRotation(int rotation) {
|
||||
boolean newRotated = (rotation & 1) != 0;
|
||||
if (rotated == newRotated) {
|
||||
/**
|
||||
* Return the actual video size if locked video orientation is set.
|
||||
*
|
||||
* @return the actual video size
|
||||
*/
|
||||
public Size getVideoSize() {
|
||||
if (getVideoRotation() % 2 == 0) {
|
||||
return unlockedVideoSize;
|
||||
}
|
||||
|
||||
return unlockedVideoSize.rotate();
|
||||
}
|
||||
|
||||
public int getDeviceRotation() {
|
||||
return deviceRotation;
|
||||
}
|
||||
|
||||
public ScreenInfo withDeviceRotation(int newDeviceRotation) {
|
||||
if (newDeviceRotation == deviceRotation) {
|
||||
return this;
|
||||
}
|
||||
return new ScreenInfo(Device.flipRect(contentRect), videoSize.rotate(), newRotated);
|
||||
// true if changed between portrait and landscape
|
||||
boolean orientationChanged = (deviceRotation + newDeviceRotation) % 2 != 0;
|
||||
Rect newContentRect;
|
||||
Size newUnlockedVideoSize;
|
||||
if (orientationChanged) {
|
||||
newContentRect = flipRect(contentRect);
|
||||
newUnlockedVideoSize = unlockedVideoSize.rotate();
|
||||
} else {
|
||||
newContentRect = contentRect;
|
||||
newUnlockedVideoSize = unlockedVideoSize;
|
||||
}
|
||||
return new ScreenInfo(newContentRect, newUnlockedVideoSize, newDeviceRotation, lockedVideoOrientation);
|
||||
}
|
||||
|
||||
public static ScreenInfo computeScreenInfo(DisplayInfo displayInfo, Rect crop, int maxSize, int lockedVideoOrientation) {
|
||||
int rotation = displayInfo.getRotation();
|
||||
Size deviceSize = displayInfo.getSize();
|
||||
Rect contentRect = new Rect(0, 0, deviceSize.getWidth(), deviceSize.getHeight());
|
||||
if (crop != null) {
|
||||
if (rotation % 2 != 0) { // 180s preserve dimensions
|
||||
// the crop (provided by the user) is expressed in the natural orientation
|
||||
crop = flipRect(crop);
|
||||
}
|
||||
if (!contentRect.intersect(crop)) {
|
||||
// intersect() changes contentRect so that it is intersected with crop
|
||||
Ln.w("Crop rectangle (" + formatCrop(crop) + ") does not intersect device screen (" + formatCrop(deviceSize.toRect()) + ")");
|
||||
contentRect = new Rect(); // empty
|
||||
}
|
||||
}
|
||||
|
||||
Size videoSize = computeVideoSize(contentRect.width(), contentRect.height(), maxSize);
|
||||
return new ScreenInfo(contentRect, videoSize, rotation, lockedVideoOrientation);
|
||||
}
|
||||
|
||||
private static String formatCrop(Rect rect) {
|
||||
return rect.width() + ":" + rect.height() + ":" + rect.left + ":" + rect.top;
|
||||
}
|
||||
|
||||
private static Size computeVideoSize(int w, int h, int maxSize) {
|
||||
// Compute the video size and the padding of the content inside this video.
|
||||
// Principle:
|
||||
// - scale down the great side of the screen to maxSize (if necessary);
|
||||
// - scale down the other side so that the aspect ratio is preserved;
|
||||
// - round this value to the nearest multiple of 8 (H.264 only accepts multiples of 8)
|
||||
w &= ~7; // in case it's not a multiple of 8
|
||||
h &= ~7;
|
||||
if (maxSize > 0) {
|
||||
if (BuildConfig.DEBUG && maxSize % 8 != 0) {
|
||||
throw new AssertionError("Max size must be a multiple of 8");
|
||||
}
|
||||
boolean portrait = h > w;
|
||||
int major = portrait ? h : w;
|
||||
int minor = portrait ? w : h;
|
||||
if (major > maxSize) {
|
||||
int minorExact = minor * maxSize / major;
|
||||
// +4 to round the value to the nearest multiple of 8
|
||||
minor = (minorExact + 4) & ~7;
|
||||
major = maxSize;
|
||||
}
|
||||
w = portrait ? minor : major;
|
||||
h = portrait ? major : minor;
|
||||
}
|
||||
return new Size(w, h);
|
||||
}
|
||||
|
||||
private static Rect flipRect(Rect crop) {
|
||||
return new Rect(crop.top, crop.left, crop.bottom, crop.right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rotation to apply to the device rotation to get the requested locked video orientation
|
||||
*
|
||||
* @return the rotation offset
|
||||
*/
|
||||
public int getVideoRotation() {
|
||||
if (lockedVideoOrientation == -1) {
|
||||
// no offset
|
||||
return 0;
|
||||
}
|
||||
return (deviceRotation + 4 - lockedVideoOrientation) % 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rotation to apply to the requested locked video orientation to get the device rotation
|
||||
*
|
||||
* @return the (reverse) rotation offset
|
||||
*/
|
||||
public int getReverseVideoRotation() {
|
||||
if (lockedVideoOrientation == -1) {
|
||||
// no offset
|
||||
return 0;
|
||||
}
|
||||
return (lockedVideoOrientation + 4 - deviceRotation) % 4;
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,12 @@ public final class Server {
|
||||
}
|
||||
|
||||
private static void scrcpy(Options options) throws IOException {
|
||||
Ln.i("Device: " + Build.MANUFACTURER + " " + Build.MODEL + " (Android " + Build.VERSION.RELEASE + ")");
|
||||
final Device device = new Device(options);
|
||||
boolean tunnelForward = options.isTunnelForward();
|
||||
try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward)) {
|
||||
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps());
|
||||
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps(),
|
||||
options.getLockedVideoOrientation());
|
||||
|
||||
if (options.getControl()) {
|
||||
Controller controller = new Controller(device, connection);
|
||||
@ -67,7 +69,6 @@ public final class Server {
|
||||
}).start();
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
private static Options createOptions(String... args) {
|
||||
if (args.length < 1) {
|
||||
throw new IllegalArgumentException("Missing client version");
|
||||
@ -76,11 +77,11 @@ public final class Server {
|
||||
String clientVersion = args[0];
|
||||
if (!clientVersion.equals(BuildConfig.VERSION_NAME)) {
|
||||
throw new IllegalArgumentException(
|
||||
"The server version (" + clientVersion + ") does not match the client " + "(" + BuildConfig.VERSION_NAME + ")");
|
||||
"The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")");
|
||||
}
|
||||
|
||||
if (args.length != 8) {
|
||||
throw new IllegalArgumentException("Expecting 8 parameters");
|
||||
if (args.length != 10) {
|
||||
throw new IllegalArgumentException("Expecting 10 parameters");
|
||||
}
|
||||
|
||||
Options options = new Options();
|
||||
@ -94,23 +95,28 @@ public final class Server {
|
||||
int maxFps = Integer.parseInt(args[3]);
|
||||
options.setMaxFps(maxFps);
|
||||
|
||||
int lockedVideoOrientation = Integer.parseInt(args[4]);
|
||||
options.setLockedVideoOrientation(lockedVideoOrientation);
|
||||
|
||||
// use "adb forward" instead of "adb tunnel"? (so the server must listen)
|
||||
boolean tunnelForward = Boolean.parseBoolean(args[4]);
|
||||
boolean tunnelForward = Boolean.parseBoolean(args[5]);
|
||||
options.setTunnelForward(tunnelForward);
|
||||
|
||||
Rect crop = parseCrop(args[5]);
|
||||
Rect crop = parseCrop(args[6]);
|
||||
options.setCrop(crop);
|
||||
|
||||
boolean sendFrameMeta = Boolean.parseBoolean(args[6]);
|
||||
boolean sendFrameMeta = Boolean.parseBoolean(args[7]);
|
||||
options.setSendFrameMeta(sendFrameMeta);
|
||||
|
||||
boolean control = Boolean.parseBoolean(args[7]);
|
||||
boolean control = Boolean.parseBoolean(args[8]);
|
||||
options.setControl(control);
|
||||
|
||||
int displayId = Integer.parseInt(args[9]);
|
||||
options.setDisplayId(displayId);
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
private static Rect parseCrop(String crop) {
|
||||
if ("-".equals(crop)) {
|
||||
return null;
|
||||
@ -146,6 +152,16 @@ public final class Server {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e instanceof InvalidDisplayIdException) {
|
||||
InvalidDisplayIdException idie = (InvalidDisplayIdException) e;
|
||||
int[] displayIds = idie.getAvailableDisplayIds();
|
||||
if (displayIds != null && displayIds.length > 0) {
|
||||
Ln.e("Try to use one of the available display ids:");
|
||||
for (int id : displayIds) {
|
||||
Ln.e(" scrcpy --display " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
|
@ -5,7 +5,6 @@ public final class StringUtils {
|
||||
// not instantiable
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
public static int getUtf8TruncationIndex(byte[] utf8, int maxLength) {
|
||||
int len = utf8.length;
|
||||
if (len <= maxLength) {
|
||||
|
@ -73,7 +73,7 @@ public final class Workarounds {
|
||||
mInitialApplicationField.set(activityThread, app);
|
||||
} catch (Throwable throwable) {
|
||||
// this is a workaround, so failing is not an error
|
||||
Ln.w("Could not fill app info: " + throwable.getMessage());
|
||||
Ln.d("Could not fill app info: " + throwable.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,15 +12,28 @@ public final class DisplayManager {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
public DisplayInfo getDisplayInfo() {
|
||||
public DisplayInfo getDisplayInfo(int displayId) {
|
||||
try {
|
||||
Object displayInfo = manager.getClass().getMethod("getDisplayInfo", int.class).invoke(manager, 0);
|
||||
Object displayInfo = manager.getClass().getMethod("getDisplayInfo", int.class).invoke(manager, displayId);
|
||||
if (displayInfo == null) {
|
||||
return null;
|
||||
}
|
||||
Class<?> cls = displayInfo.getClass();
|
||||
// width and height already take the rotation into account
|
||||
int width = cls.getDeclaredField("logicalWidth").getInt(displayInfo);
|
||||
int height = cls.getDeclaredField("logicalHeight").getInt(displayInfo);
|
||||
int rotation = cls.getDeclaredField("rotation").getInt(displayInfo);
|
||||
return new DisplayInfo(new Size(width, height), rotation);
|
||||
int layerStack = cls.getDeclaredField("layerStack").getInt(displayInfo);
|
||||
int flags = cls.getDeclaredField("flags").getInt(displayInfo);
|
||||
return new DisplayInfo(displayId, new Size(width, height), rotation, layerStack, flags);
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int[] getDisplayIds() {
|
||||
try {
|
||||
return (int[]) manager.getClass().getMethod("getDisplayIds").invoke(manager);
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ public final class InputManager {
|
||||
private final IInterface manager;
|
||||
private Method injectInputEventMethod;
|
||||
|
||||
private static Method setDisplayIdMethod;
|
||||
|
||||
public InputManager(IInterface manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
@ -37,4 +39,23 @@ public final class InputManager {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static Method getSetDisplayIdMethod() throws NoSuchMethodException {
|
||||
if (setDisplayIdMethod == null) {
|
||||
setDisplayIdMethod = InputEvent.class.getMethod("setDisplayId", int.class);
|
||||
}
|
||||
return setDisplayIdMethod;
|
||||
}
|
||||
|
||||
public static boolean setDisplayId(InputEvent inputEvent, int displayId) {
|
||||
try {
|
||||
Method method = getSetDisplayIdMethod();
|
||||
method.invoke(inputEvent, displayId);
|
||||
return true;
|
||||
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||
// just a warning, it might happen on old devices
|
||||
Ln.w("Cannot associate a display id to the input event");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,9 @@ public class ControlMessageReaderTest {
|
||||
dos.writeInt(KeyEvent.META_CTRL_ON);
|
||||
byte[] packet = bos.toByteArray();
|
||||
|
||||
// The message type (1 byte) does not count
|
||||
Assert.assertEquals(ControlMessageReader.INJECT_KEYCODE_PAYLOAD_LENGTH, packet.length - 1);
|
||||
|
||||
reader.readFrom(new ByteArrayInputStream(packet));
|
||||
ControlMessage event = reader.next();
|
||||
|
||||
@ -77,7 +80,6 @@ public class ControlMessageReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
public void testParseTouchEvent() throws IOException {
|
||||
ControlMessageReader reader = new ControlMessageReader();
|
||||
|
||||
@ -95,6 +97,9 @@ public class ControlMessageReaderTest {
|
||||
|
||||
byte[] packet = bos.toByteArray();
|
||||
|
||||
// The message type (1 byte) does not count
|
||||
Assert.assertEquals(ControlMessageReader.INJECT_TOUCH_EVENT_PAYLOAD_LENGTH, packet.length - 1);
|
||||
|
||||
reader.readFrom(new ByteArrayInputStream(packet));
|
||||
ControlMessage event = reader.next();
|
||||
|
||||
@ -110,7 +115,6 @@ public class ControlMessageReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
public void testParseScrollEvent() throws IOException {
|
||||
ControlMessageReader reader = new ControlMessageReader();
|
||||
|
||||
@ -126,6 +130,9 @@ public class ControlMessageReaderTest {
|
||||
|
||||
byte[] packet = bos.toByteArray();
|
||||
|
||||
// The message type (1 byte) does not count
|
||||
Assert.assertEquals(ControlMessageReader.INJECT_SCROLL_EVENT_PAYLOAD_LENGTH, packet.length - 1);
|
||||
|
||||
reader.readFrom(new ByteArrayInputStream(packet));
|
||||
ControlMessage event = reader.next();
|
||||
|
||||
@ -233,6 +240,9 @@ public class ControlMessageReaderTest {
|
||||
|
||||
byte[] packet = bos.toByteArray();
|
||||
|
||||
// The message type (1 byte) does not count
|
||||
Assert.assertEquals(ControlMessageReader.SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH, packet.length - 1);
|
||||
|
||||
reader.readFrom(new ByteArrayInputStream(packet));
|
||||
ControlMessage event = reader.next();
|
||||
|
||||
|
@ -8,7 +8,6 @@ import java.nio.charset.StandardCharsets;
|
||||
public class StringUtilsTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
public void testUtf8Truncate() {
|
||||
String s = "aÉbÔc";
|
||||
byte[] utf8 = s.getBytes(StandardCharsets.UTF_8);
|
||||
|
Reference in New Issue
Block a user