@yume-chan/scrcpy 0.0.19 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +15 -0
- package/CHANGELOG.md +9 -1
- package/README.md +105 -181
- package/esm/codec/h264.d.ts +1 -21
- package/esm/codec/h264.d.ts.map +1 -1
- package/esm/codec/h264.js +13 -234
- package/esm/codec/h264.js.map +1 -1
- package/esm/codec/h265.d.ts +454 -0
- package/esm/codec/h265.d.ts.map +1 -1
- package/esm/codec/h265.js +1060 -0
- package/esm/codec/h265.js.map +1 -1
- package/esm/codec/index.d.ts +1 -0
- package/esm/codec/index.d.ts.map +1 -1
- package/esm/codec/index.js +1 -0
- package/esm/codec/index.js.map +1 -1
- package/esm/codec/nalu.d.ts +44 -0
- package/esm/codec/nalu.d.ts.map +1 -0
- package/esm/codec/nalu.js +310 -0
- package/esm/codec/nalu.js.map +1 -0
- package/esm/control/back-or-screen-on.d.ts +1 -1
- package/esm/control/back-or-screen-on.d.ts.map +1 -1
- package/esm/control/index.d.ts +2 -0
- package/esm/control/index.d.ts.map +1 -1
- package/esm/control/index.js +2 -0
- package/esm/control/index.js.map +1 -1
- package/esm/control/inject-keycode.d.ts +1 -2
- package/esm/control/inject-keycode.d.ts.map +1 -1
- package/esm/control/inject-keycode.js +1 -2
- package/esm/control/inject-keycode.js.map +1 -1
- package/esm/control/inject-text.d.ts +1 -2
- package/esm/control/inject-text.d.ts.map +1 -1
- package/esm/control/inject-text.js +1 -2
- package/esm/control/inject-text.js.map +1 -1
- package/esm/control/inject-touch.d.ts +15 -20
- package/esm/control/inject-touch.d.ts.map +1 -1
- package/esm/control/inject-touch.js +14 -41
- package/esm/control/inject-touch.js.map +1 -1
- package/esm/control/rotate-device.d.ts +2 -4
- package/esm/control/rotate-device.d.ts.map +1 -1
- package/esm/control/rotate-device.js +2 -3
- package/esm/control/rotate-device.js.map +1 -1
- package/esm/control/serializer.d.ts +13 -23
- package/esm/control/serializer.d.ts.map +1 -1
- package/esm/control/serializer.js +23 -52
- package/esm/control/serializer.js.map +1 -1
- package/esm/control/set-screen-power-mode.d.ts +1 -2
- package/esm/control/set-screen-power-mode.d.ts.map +1 -1
- package/esm/control/set-screen-power-mode.js +1 -2
- package/esm/control/set-screen-power-mode.js.map +1 -1
- package/esm/control/type.d.ts +14 -0
- package/esm/control/type.d.ts.map +1 -1
- package/esm/control/type.js +22 -0
- package/esm/control/type.js.map +1 -1
- package/esm/control/writer.d.ts +28 -0
- package/esm/control/writer.d.ts.map +1 -0
- package/esm/control/writer.js +53 -0
- package/esm/control/writer.js.map +1 -0
- package/esm/device-message/stream.d.ts.map +1 -1
- package/esm/device-message/stream.js +23 -8
- package/esm/device-message/stream.js.map +1 -1
- package/esm/index.d.ts +1 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -2
- package/esm/index.js.map +1 -1
- package/esm/options/1_16/codec-options.d.ts +2 -3
- package/esm/options/1_16/codec-options.d.ts.map +1 -1
- package/esm/options/1_16/codec-options.js.map +1 -1
- package/esm/options/1_16/index.d.ts +3 -1
- package/esm/options/1_16/index.d.ts.map +1 -1
- package/esm/options/1_16/index.js +3 -1
- package/esm/options/1_16/index.js.map +1 -1
- package/esm/options/1_16/options.d.ts +42 -96
- package/esm/options/1_16/options.d.ts.map +1 -1
- package/esm/options/1_16/options.js +106 -143
- package/esm/options/1_16/options.js.map +1 -1
- package/esm/options/1_16/scroll.d.ts +1 -2
- package/esm/options/1_16/scroll.d.ts.map +1 -1
- package/esm/options/1_16/scroll.js +1 -2
- package/esm/options/1_16/scroll.js.map +1 -1
- package/esm/options/1_17.d.ts +1 -0
- package/esm/options/1_17.d.ts.map +1 -1
- package/esm/options/1_17.js +7 -1
- package/esm/options/1_17.js.map +1 -1
- package/esm/options/1_18.d.ts +49 -11
- package/esm/options/1_18.d.ts.map +1 -1
- package/esm/options/1_18.js +65 -32
- package/esm/options/1_18.js.map +1 -1
- package/esm/options/1_21.d.ts +26 -7
- package/esm/options/1_21.d.ts.map +1 -1
- package/esm/options/1_21.js +35 -20
- package/esm/options/1_21.js.map +1 -1
- package/esm/options/1_22/index.d.ts +1 -0
- package/esm/options/1_22/index.d.ts.map +1 -1
- package/esm/options/1_22/index.js +1 -0
- package/esm/options/1_22/index.js.map +1 -1
- package/esm/options/1_22/options.d.ts +32 -26
- package/esm/options/1_22/options.d.ts.map +1 -1
- package/esm/options/1_22/options.js +27 -16
- package/esm/options/1_22/options.js.map +1 -1
- package/esm/options/1_22/scroll.d.ts +1 -1
- package/esm/options/1_22/scroll.js +1 -1
- package/esm/options/1_23.d.ts +32 -8
- package/esm/options/1_23.d.ts.map +1 -1
- package/esm/options/1_23.js +24 -14
- package/esm/options/1_23.js.map +1 -1
- package/esm/options/1_24.d.ts +29 -4
- package/esm/options/1_24.d.ts.map +1 -1
- package/esm/options/1_24.js +17 -7
- package/esm/options/1_24.js.map +1 -1
- package/esm/options/1_25/options.d.ts +6 -2
- package/esm/options/1_25/options.d.ts.map +1 -1
- package/esm/options/1_25/options.js +16 -2
- package/esm/options/1_25/options.js.map +1 -1
- package/esm/options/1_25/scroll.d.ts.map +1 -1
- package/esm/options/1_25/scroll.js +2 -1
- package/esm/options/1_25/scroll.js.map +1 -1
- package/esm/options/2_0.d.ts +12 -8
- package/esm/options/2_0.d.ts.map +1 -1
- package/esm/options/2_0.js +80 -11
- package/esm/options/2_0.js.map +1 -1
- package/esm/options/codec.d.ts +4 -4
- package/esm/options/codec.d.ts.map +1 -1
- package/esm/options/codec.js +3 -3
- package/esm/options/codec.js.map +1 -1
- package/esm/options/index.d.ts +4 -0
- package/esm/options/index.d.ts.map +1 -1
- package/esm/options/index.js +4 -0
- package/esm/options/index.js.map +1 -1
- package/esm/options/types.d.ts +73 -33
- package/esm/options/types.d.ts.map +1 -1
- package/esm/options/types.js +52 -0
- package/esm/options/types.js.map +1 -1
- package/package.json +7 -14
- package/src/codec/av1.ts +33 -0
- package/src/codec/h264.ts +317 -0
- package/src/codec/h265.ts +1375 -0
- package/src/codec/index.ts +4 -0
- package/src/codec/nalu.ts +373 -0
- package/src/control/back-or-screen-on.ts +1 -1
- package/{esm/control/simple.js → src/control/basic.ts} +3 -3
- package/src/control/index.ts +2 -0
- package/src/control/inject-keycode.ts +1 -3
- package/src/control/inject-text.ts +1 -3
- package/src/control/inject-touch.ts +16 -55
- package/src/control/rotate-device.ts +2 -7
- package/src/control/serializer.ts +42 -101
- package/src/control/set-screen-power-mode.ts +1 -3
- package/src/control/type.ts +32 -0
- package/src/control/writer.ts +87 -0
- package/src/device-message/stream.ts +32 -12
- package/src/index.ts +1 -2
- package/src/options/1_16/codec-options.ts +2 -3
- package/src/options/1_16/float-to-uint16.ts +33 -0
- package/src/options/1_16/index.ts +3 -1
- package/src/options/1_16/init.ts +80 -0
- package/src/options/1_16/message.ts +55 -0
- package/src/options/1_16/options.ts +146 -255
- package/src/options/1_16/scroll.ts +1 -2
- package/src/options/1_17.ts +66 -0
- package/src/options/1_18.ts +101 -37
- package/src/options/1_21.ts +47 -25
- package/src/options/1_22/index.ts +1 -0
- package/src/options/1_22/init.ts +19 -0
- package/src/options/1_22/options.ts +38 -45
- package/src/options/1_22/scroll.ts +1 -1
- package/src/options/1_23.ts +33 -21
- package/src/options/1_24.ts +23 -11
- package/src/options/1_25/options.ts +22 -4
- package/src/options/1_25/scroll.ts +2 -1
- package/src/options/2_0.ts +342 -0
- package/src/options/codec.ts +98 -0
- package/src/options/index.ts +4 -0
- package/src/options/latest.ts +14 -0
- package/src/options/types.ts +152 -42
- package/tsconfig.build.json +9 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/esm/adb/client.d.ts +0 -41
- package/esm/adb/client.d.ts.map +0 -1
- package/esm/adb/client.js +0 -224
- package/esm/adb/client.js.map +0 -1
- package/esm/adb/connection.d.ts +0 -49
- package/esm/adb/connection.d.ts.map +0 -1
- package/esm/adb/connection.js +0 -122
- package/esm/adb/connection.js.map +0 -1
- package/esm/adb/index.d.ts +0 -4
- package/esm/adb/index.d.ts.map +0 -1
- package/esm/adb/index.js +0 -4
- package/esm/adb/index.js.map +0 -1
- package/esm/adb/options/1_16.d.ts +0 -8
- package/esm/adb/options/1_16.d.ts.map +0 -1
- package/esm/adb/options/1_16.js +0 -20
- package/esm/adb/options/1_16.js.map +0 -1
- package/esm/adb/options/1_22.d.ts +0 -8
- package/esm/adb/options/1_22.d.ts.map +0 -1
- package/esm/adb/options/1_22.js +0 -17
- package/esm/adb/options/1_22.js.map +0 -1
- package/esm/adb/options/1_26.d.ts +0 -9
- package/esm/adb/options/1_26.d.ts.map +0 -1
- package/esm/adb/options/1_26.js +0 -11
- package/esm/adb/options/1_26.js.map +0 -1
- package/esm/adb/options/2_0.d.ts +0 -8
- package/esm/adb/options/2_0.d.ts.map +0 -1
- package/esm/adb/options/2_0.js +0 -13
- package/esm/adb/options/2_0.js.map +0 -1
- package/esm/adb/options/index.d.ts +0 -4
- package/esm/adb/options/index.d.ts.map +0 -1
- package/esm/adb/options/index.js +0 -4
- package/esm/adb/options/index.js.map +0 -1
- package/esm/adb/options/types.d.ts +0 -24
- package/esm/adb/options/types.d.ts.map +0 -1
- package/esm/adb/options/types.js +0 -37
- package/esm/adb/options/types.js.map +0 -1
- package/esm/codec.d.ts +0 -34
- package/esm/codec.d.ts.map +0 -1
- package/esm/codec.js +0 -37
- package/esm/codec.js.map +0 -1
- package/esm/control/simple.d.ts +0 -5
- package/esm/control/simple.d.ts.map +0 -1
- package/esm/control/simple.js.map +0 -1
- package/esm/decoder.d.ts +0 -2
- package/esm/decoder.d.ts.map +0 -1
- package/esm/decoder.js +0 -2
- package/esm/decoder.js.map +0 -1
- package/esm/options/1.17.d.ts +0 -3
- package/esm/options/1.17.d.ts.map +0 -1
- package/esm/options/1.17.js +0 -2
- package/esm/options/1.17.js.map +0 -1
- package/esm/options/1_16/h264-configuration.d.ts +0 -49
- package/esm/options/1_16/h264-configuration.d.ts.map +0 -1
- package/esm/options/1_16/h264-configuration.js +0 -414
- package/esm/options/1_16/h264-configuration.js.map +0 -1
- package/esm/options/1_16/sps.d.ts +0 -22
- package/esm/options/1_16/sps.d.ts.map +0 -1
- package/esm/options/1_16/sps.js +0 -263
- package/esm/options/1_16/sps.js.map +0 -1
- package/esm/options/1_26.d.ts +0 -57
- package/esm/options/1_26.d.ts.map +0 -1
- package/esm/options/1_26.js +0 -67
- package/esm/options/1_26.js.map +0 -1
- package/esm/options/2.d.ts +0 -57
- package/esm/options/2.d.ts.map +0 -1
- package/esm/options/2.js +0 -67
- package/esm/options/2.js.map +0 -1
- package/src/adb/client.ts +0 -329
- package/src/adb/connection.ts +0 -209
- package/src/adb/index.ts +0 -3
- package/src/adb/options/1_16.ts +0 -32
- package/src/adb/options/1_22.ts +0 -26
- package/src/adb/options/index.ts +0 -3
- package/src/adb/options/types.ts +0 -75
- package/src/codec.ts +0 -35
- package/src/options/1_16/h264-configuration.ts +0 -485
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yume-chan/scrcpy",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.0.20",
|
|
6
|
+
"tag": "@yume-chan/scrcpy_v0.0.20",
|
|
7
|
+
"date": "Mon, 05 Jun 2023 02:51:41 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"none": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Add support for Scrcpy 2.0. New features including audio forwarding (supports PCM, AAC and OPUS encoding) and other video codecs (supports H.264 and H.265, AV1 not supported). Read the PR for new options and breaking changes. ([#495](https://github.com/yume-chan/ya-webadb/pull/495))"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"comment": "Move ADB related code to `@yume-chan/adb-scrcpy` package. This package now only implements the Scrcpy protocol."
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
4
19
|
{
|
|
5
20
|
"version": "0.0.19",
|
|
6
21
|
"tag": "@yume-chan/scrcpy_v0.0.19",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# Change Log - @yume-chan/scrcpy
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 05 Jun 2023 02:51:41 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.0.20
|
|
6
|
+
Mon, 05 Jun 2023 02:51:41 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- Add support for Scrcpy 2.0. New features including audio forwarding (supports PCM, AAC and OPUS encoding) and other video codecs (supports H.264 and H.265, AV1 not supported). Read the PR for new options and breaking changes. ([#495](https://github.com/yume-chan/ya-webadb/pull/495))
|
|
11
|
+
- Move ADB related code to `@yume-chan/adb-scrcpy` package. This package now only implements the Scrcpy protocol.
|
|
4
12
|
|
|
5
13
|
## 0.0.19
|
|
6
14
|
Sun, 09 Apr 2023 05:55:33 GMT
|
package/README.md
CHANGED
|
@@ -1,79 +1,94 @@
|
|
|
1
1
|
# @yume-chan/scrcpy
|
|
2
2
|
|
|
3
|
-
TypeScript
|
|
3
|
+
TypeScript library to communicate with [Scrcpy](https://github.com/Genymobile/scrcpy) server.
|
|
4
4
|
|
|
5
5
|
It's compatible with the official Scrcpy server binaries.
|
|
6
6
|
|
|
7
|
-
**WARNING:** The public API is UNSTABLE.
|
|
7
|
+
**WARNING:** The public API is UNSTABLE. Open a GitHub discussion if you have any questions.
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
- [Always read the streams](#always-read-the-streams)
|
|
27
|
-
- [Video stream](#video-stream)
|
|
28
|
-
- [Decode video stream](#decode-video-stream)
|
|
9
|
+
- [How does Scrcpy work](#how-does-scrcpy-work)
|
|
10
|
+
- [What does this package do](#what-does-this-package-do)
|
|
11
|
+
- [Prepare server binary](#prepare-server-binary)
|
|
12
|
+
- [`fetch-scrcpy-server`](#fetch-scrcpy-server)
|
|
13
|
+
- [Use the server binary](#use-the-server-binary)
|
|
14
|
+
- [Node.js CommonJS](#nodejs-commonjs)
|
|
15
|
+
- [Node.js ES module](#nodejs-es-module)
|
|
16
|
+
- [Webpack 4](#webpack-4)
|
|
17
|
+
- [Webpack 5](#webpack-5)
|
|
18
|
+
- [Server versions](#server-versions)
|
|
19
|
+
- [Reading and writing packets](#reading-and-writing-packets)
|
|
20
|
+
- [Reading video/audio packets](#reading-videoaudio-packets)
|
|
21
|
+
- [Sending control messages](#sending-control-messages)
|
|
22
|
+
- [Reading device messages](#reading-device-messages)
|
|
23
|
+
- [Always read all streams](#always-read-all-streams)
|
|
24
|
+
- [Video/audio stream](#videoaudio-stream)
|
|
25
|
+
- [Decode video stream](#decode-video-stream)
|
|
29
26
|
|
|
30
|
-
##
|
|
27
|
+
## How does Scrcpy work
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
Scrcpy has two parts: a client and a server.
|
|
33
30
|
|
|
34
|
-
|
|
31
|
+
The server is a Java application (but not an Android app) that runs on the device to capture the video and audio, and send them to the client.
|
|
35
32
|
|
|
36
|
-
|
|
33
|
+
The client receives captured video and audio data, and renders them on computer.
|
|
37
34
|
|
|
38
|
-
|
|
35
|
+
The official Scrcpy client also spawns Google ADB executable to set up the reverse tunnel, push the server binary to the device, and start the server.
|
|
39
36
|
|
|
40
|
-
|
|
37
|
+
## What does this package do
|
|
38
|
+
|
|
39
|
+
This package can't push nor start the server, nor render the video and audio. It only provides APIs to communicate with the server.
|
|
40
|
+
|
|
41
|
+
`@yume-chan/adb-scrcpy` package is a wrapper of this package, provides integration with `@yume-chan/adb` package, and can push, start, and stop the server.
|
|
41
42
|
|
|
42
43
|
## Prepare server binary
|
|
43
44
|
|
|
44
|
-
This package
|
|
45
|
+
This package is compatible with many versions of the official server binary, but it doesn't include the server binary itself.
|
|
45
46
|
|
|
46
|
-
You can download the server binary from official releases (https://github.com/Genymobile/scrcpy/releases), or use the
|
|
47
|
+
You can download the server binary from official releases (https://github.com/Genymobile/scrcpy/releases), or use the included `fetch-scrcpy-server` script to automate the process.
|
|
47
48
|
|
|
48
49
|
The server binary is subject to [Apache License 2.0](https://github.com/Genymobile/scrcpy/blob/master/LICENSE).
|
|
49
50
|
|
|
50
51
|
### `fetch-scrcpy-server`
|
|
51
52
|
|
|
52
|
-
This
|
|
53
|
+
This script downloads the server binary from official releases for you.
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
Before using this script, install `gh-release-fetch@3` package separately:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
npm install --save-dev gh-release-fetch@3
|
|
59
|
+
```
|
|
55
60
|
|
|
56
61
|
Usage:
|
|
57
62
|
|
|
58
63
|
```
|
|
59
|
-
|
|
64
|
+
npx fetch-scrcpy-server <version>
|
|
60
65
|
```
|
|
61
66
|
|
|
62
67
|
For example:
|
|
63
68
|
|
|
64
69
|
```
|
|
65
|
-
|
|
70
|
+
npx fetch-scrcpy-server 1.25
|
|
66
71
|
```
|
|
67
72
|
|
|
68
|
-
|
|
73
|
+
Add it to `scripts.postinstall` in your `package.json`, so running `npm install` automatically invokes the script:
|
|
69
74
|
|
|
70
75
|
```json
|
|
71
|
-
|
|
72
|
-
"
|
|
73
|
-
|
|
76
|
+
{
|
|
77
|
+
"scripts": {
|
|
78
|
+
"postinstall": "fetch-scrcpy-server 1.25"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
74
81
|
```
|
|
75
82
|
|
|
76
|
-
The server binary will be
|
|
83
|
+
The server binary will be saved to `bin/scrcpy-server` in this package's installation directory (usually in `node_modules`).
|
|
84
|
+
|
|
85
|
+
It will also save the version number to `bin/version.js`.
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import SCRCPY_SERVER_VERSION from "@yume-chan/scrcpy/bin/version.js";
|
|
89
|
+
|
|
90
|
+
console.log(SCRCPY_SERVER_VERSION); // "1.25"
|
|
91
|
+
```
|
|
77
92
|
|
|
78
93
|
### Use the server binary
|
|
79
94
|
|
|
@@ -91,6 +106,8 @@ const buffer: Buffer = fs.readFileSync(path);
|
|
|
91
106
|
|
|
92
107
|
#### Node.js ES module
|
|
93
108
|
|
|
109
|
+
Without the `import.meta.resolve` feature:
|
|
110
|
+
|
|
94
111
|
```ts
|
|
95
112
|
import fs from "node:fs/promises";
|
|
96
113
|
import { createRequire } from "node:module";
|
|
@@ -101,9 +118,7 @@ const path: string = createRequire(import.meta.url).resolve(
|
|
|
101
118
|
const buffer: Buffer = await fs.readFile(path);
|
|
102
119
|
```
|
|
103
120
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
Or with the `--experimental-import-meta-resolve` command line flag, you can use `import.meta.resolve`:
|
|
121
|
+
With `import.meta.resolve` feature (requires `--experimental-import-meta-resolve` command line flag for Node.js 12.6.0+):
|
|
107
122
|
|
|
108
123
|
```ts
|
|
109
124
|
import fs from "node:fs/promises";
|
|
@@ -139,143 +154,55 @@ const buffer: ArrayBuffer = await fetch(SCRCPY_SERVER_URL).then((response) =>
|
|
|
139
154
|
);
|
|
140
155
|
```
|
|
141
156
|
|
|
142
|
-
### Read the server version
|
|
143
|
-
|
|
144
|
-
The correct version number is required to launch the server, so `fetch-scrcpy-server` also writes the version number to `bin/version.js`.
|
|
145
|
-
|
|
146
|
-
```js
|
|
147
|
-
import SCRCPY_SERVER_VERSION from "@yume-chan/scrcpy/bin/version.js";
|
|
148
|
-
|
|
149
|
-
console.log(SCRCPY_SERVER_VERSION); // "1.25"
|
|
150
|
-
```
|
|
151
|
-
|
|
152
157
|
## Server versions
|
|
153
158
|
|
|
154
|
-
Scrcpy protocol
|
|
159
|
+
Scrcpy protocol changes over time, and are usually not backwards compatible. This package supports multiple server versions (ranges), and uses different option types to choose different behaviors. Using incorrect option version usually results in errors.
|
|
155
160
|
|
|
156
161
|
The latest one may continue to work for future server versions, but there is no guarantee.
|
|
157
162
|
|
|
158
163
|
| Version | Type |
|
|
159
164
|
| --------- | ------------------- |
|
|
160
|
-
| 1.16
|
|
165
|
+
| 1.16 | `ScrcpyOptions1_16` |
|
|
166
|
+
| 1.17 | `ScrcpyOptions1_17` |
|
|
161
167
|
| 1.18~1.20 | `ScrcpyOptions1_18` |
|
|
162
168
|
| 1.21 | `ScrcpyOptions1_21` |
|
|
163
169
|
| 1.22 | `ScrcpyOptions1_22` |
|
|
164
170
|
| 1.23 | `ScrcpyOptions1_23` |
|
|
165
171
|
| 1.24 | `ScrcpyOptions1_24` |
|
|
166
172
|
| 1.25 | `ScrcpyOptions1_25` |
|
|
173
|
+
| 2.0 | `ScrcpyOptions2_0` |
|
|
167
174
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
| Version | Type |
|
|
171
|
-
| --------- | ---------------------- |
|
|
172
|
-
| 1.16~1.21 | `AdbScrcpyOptions1_16` |
|
|
173
|
-
| 1.22~1.25 | `AdbScrcpyOptions1_22` |
|
|
174
|
-
|
|
175
|
-
## Use with `@yume-chan/adb`
|
|
175
|
+
## Reading and writing packets
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
This packets operates on Web Streams API streams.
|
|
178
178
|
|
|
179
|
-
|
|
179
|
+
**NOTE:** Web Streams API streams usually can't pipe between different implementations. This package by default uses the native implementation on `globalThis`, and `web-streams-polyfill` otherwise. If you are using another implementation, or simply not sure, wrap your streams using the `WrapReadableStream` and `WrapWritableStream` types from `@yume-chan/stream-extra` package.
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
### Reading video/audio packets
|
|
182
182
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
Example using a `ReadableStream`:
|
|
186
|
-
|
|
187
|
-
```ts
|
|
188
|
-
import { WrapReadableStream } from "@yume-chan/adb";
|
|
189
|
-
import { AdbScrcpyClient } from "@yume-chan/scrcpy";
|
|
190
|
-
|
|
191
|
-
await AdbScrcpyClient.pushServer(
|
|
192
|
-
adb,
|
|
193
|
-
await fetch(SCRCPY_SERVER_URL).then(
|
|
194
|
-
// `WrapReadableStream` is required because native `ReadableStream` (from `fetch`)
|
|
195
|
-
// doesn't support `pipeTo()` non-native `WritableStream`s
|
|
196
|
-
// (`@yume-chan/adb` is using `web-streams-polyfill`)
|
|
197
|
-
(response) => new WrapReadableStream(response.body)
|
|
198
|
-
)
|
|
199
|
-
);
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
Example using an `ArrayBuffer`:
|
|
183
|
+
Requires a `ReadableStream<Uint8Array>` that reads from the video socket.
|
|
203
184
|
|
|
204
185
|
```ts
|
|
205
|
-
import {
|
|
206
|
-
|
|
207
|
-
await AdbScrcpyClient.pushServer(
|
|
208
|
-
adb,
|
|
209
|
-
new ReadableStream({
|
|
210
|
-
start(controller) {
|
|
211
|
-
controller.enqueue(new Uint8Array(buffer));
|
|
212
|
-
controller.end();
|
|
213
|
-
},
|
|
214
|
-
})
|
|
215
|
-
);
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
### Start server on device
|
|
219
|
-
|
|
220
|
-
To start the server, use the `AdbScrcpyClient.start()` method. It automatically sets up port forwarding, launches the server, and connects to it.
|
|
221
|
-
|
|
222
|
-
```js
|
|
223
|
-
import {
|
|
224
|
-
AdbScrcpyClient,
|
|
225
|
-
AdbScrcpyOptions1_22,
|
|
226
|
-
DEFAULT_SERVER_PATH,
|
|
227
|
-
ScrcpyOptions1_24,
|
|
228
|
-
} from "@yume-chan/scrcpy";
|
|
229
|
-
import SCRCPY_SERVER_VERSION from "@yume-chan/scrcpy/bin/version.js";
|
|
230
|
-
|
|
231
|
-
const client: AdbScrcpyClient = await AdbScrcpyClient.start(
|
|
232
|
-
adb,
|
|
233
|
-
DEFAULT_SERVER_PATH,
|
|
234
|
-
// If server binary was downloaded manually, must provide the correct version
|
|
235
|
-
SCRCPY_SERVER_VERSION,
|
|
236
|
-
new AdbScrcpyOptions1_22(
|
|
237
|
-
ScrcpyOptions1_24({
|
|
238
|
-
// options
|
|
239
|
-
})
|
|
240
|
-
)
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
const stdout: ReadableStream<string> = client.stdout;
|
|
244
|
-
const videoPacketStream: ReadableStream<ScrcpyVideoStreamPacket> =
|
|
245
|
-
client.videoStream;
|
|
246
|
-
const controlMessageSerializer: ScrcpyControlMessageSerializer | undefined =
|
|
247
|
-
client.controlMessageSerializer;
|
|
248
|
-
const deviceMessageStream: ReadableStream<ScrcpyDeviceMessage> | undefined =
|
|
249
|
-
client.deviceMessageStream;
|
|
250
|
-
|
|
251
|
-
// to stop the server
|
|
252
|
-
client.close();
|
|
253
|
-
```
|
|
186
|
+
import { ScrcpyOptions1_25, ScrcpyVideoStreamPacket } from "@yume-chan/scrcpy";
|
|
254
187
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
### Parsing video packets
|
|
260
|
-
|
|
261
|
-
Requires a `ReadableStream<Uint8Array>` that reads from the video socket, preserving packet boundaries.
|
|
262
|
-
|
|
263
|
-
**NOTE:** Because this package uses `web-streams-polyfill` NPM package's Web Streams API implementation, the provided `ReadableStream` must also be from `web-streams-polyfill` (or another polyfill that doesn't check object prototype when piping).
|
|
264
|
-
|
|
265
|
-
```ts
|
|
266
|
-
import { ScrcpyOptions1_24, ScrcpyVideoStreamPacket } from "@yume-chan/scrcpy";
|
|
188
|
+
const options = new ScrcpyOptions1_25({
|
|
189
|
+
// use the same version and options when starting the server
|
|
190
|
+
});
|
|
267
191
|
|
|
268
192
|
const videoStream: ReadableStream<Uint8Array>; // get the stream yourself
|
|
269
193
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
194
|
+
// Parse video socket metadata
|
|
195
|
+
// Use `videoStream2` instead of `videoStream` from now on
|
|
196
|
+
const { metadata, stream: videoStream2 } =
|
|
197
|
+
await options.parseVideoStreamMetadata(videoStream);
|
|
273
198
|
|
|
274
|
-
const videoPacketStream: ReadableStream<
|
|
275
|
-
|
|
199
|
+
const videoPacketStream: ReadableStream<ScrcpyMediaStreamPacket> =
|
|
200
|
+
videoStream2.pipeThrough(options.createMediaStreamTransformer());
|
|
276
201
|
// Read from `videoPacketStream`
|
|
277
202
|
```
|
|
278
203
|
|
|
204
|
+
Read audio stream is similar, but uses `parseVideoStreamMetadata` instead.
|
|
205
|
+
|
|
279
206
|
### Sending control messages
|
|
280
207
|
|
|
281
208
|
Requires a `WritableStream<Uint8Array>` that writes to the control socket.
|
|
@@ -284,37 +211,36 @@ Control socket is optional if control is not enabled. Video socket and control s
|
|
|
284
211
|
|
|
285
212
|
```ts
|
|
286
213
|
import {
|
|
287
|
-
|
|
288
|
-
|
|
214
|
+
ScrcpyControlMessageWriter,
|
|
215
|
+
ScrcpyOptions1_25,
|
|
289
216
|
} from "@yume-chan/scrcpy";
|
|
290
217
|
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
const options = new ScrcpyOptions1_24({
|
|
294
|
-
// use the same version and options
|
|
218
|
+
const options = new ScrcpyOptions1_25({
|
|
219
|
+
// use the same version and options when starting the server
|
|
295
220
|
});
|
|
296
221
|
|
|
297
|
-
const
|
|
298
|
-
|
|
222
|
+
const controlStream: ReadableWritablePair<Uint8Array, Uint8Array>; // get the stream yourself
|
|
223
|
+
|
|
224
|
+
const controlMessageWriter = new ScrcpyControlMessageWriter(
|
|
225
|
+
controlStream.writable.getWriter(),
|
|
299
226
|
options
|
|
300
227
|
);
|
|
301
|
-
|
|
302
|
-
|
|
228
|
+
|
|
229
|
+
// Call methods on `controlMessageWriter`
|
|
230
|
+
controlMessageWriter.injectText("Hello World!");
|
|
303
231
|
```
|
|
304
232
|
|
|
305
233
|
### Reading device messages
|
|
306
234
|
|
|
307
235
|
Requires a `ReadableStream<Uint8Array>` that reads from the control socket.
|
|
308
236
|
|
|
309
|
-
**NOTE:** Because this package uses `web-streams-polyfill` NPM package's Web Streams API implementation, the provided `ReadableStream` must also be from `web-streams-polyfill` (or another polyfill that doesn't check object prototype when piping).
|
|
310
|
-
|
|
311
237
|
```ts
|
|
312
238
|
import {
|
|
313
239
|
ScrcpyDeviceMessageDeserializeStream,
|
|
314
240
|
ScrcpyOptions1_24,
|
|
315
241
|
} from "@yume-chan/scrcpy";
|
|
316
242
|
|
|
317
|
-
const controlStream: ReadableWritablePair<Uint8Array, Uint8Array
|
|
243
|
+
const controlStream: ReadableWritablePair<Uint8Array, Uint8Array>; // get the stream yourself
|
|
318
244
|
|
|
319
245
|
const deviceMessageStream: ReadableStream<ScrcpyDeviceMessage> =
|
|
320
246
|
controlStream.readable.pipeThrough(
|
|
@@ -322,11 +248,9 @@ const deviceMessageStream: ReadableStream<ScrcpyDeviceMessage> =
|
|
|
322
248
|
);
|
|
323
249
|
```
|
|
324
250
|
|
|
325
|
-
## Always read
|
|
251
|
+
## Always read all streams
|
|
326
252
|
|
|
327
|
-
In Web Streams API,
|
|
328
|
-
|
|
329
|
-
For Scrcpy, usually all streams are originated from the same ADB connection (either USB or TCP), so it's important to always read from all streams, even if you don't care about their data.
|
|
253
|
+
In Web Streams API, pipes will block its upstream when downstream's queue is full (back-pressure mechanism). If multiple streams are separated from the same source (for example, all Scrcpy streams are from the same USB or TCP connection), blocking one stream means blocking all of them, so it's important to always read from all streams, even if you don't care about their data.
|
|
330
254
|
|
|
331
255
|
```ts
|
|
332
256
|
// when using `AdbScrcpyClient`
|
|
@@ -364,31 +288,31 @@ deviceMessageStream
|
|
|
364
288
|
.catch(() => {});
|
|
365
289
|
```
|
|
366
290
|
|
|
367
|
-
## Video stream
|
|
291
|
+
## Video/audio stream
|
|
368
292
|
|
|
369
|
-
The data from `
|
|
293
|
+
The data from `createMediaStreamTransformer()` has two types: `configuration` and `data`.
|
|
370
294
|
|
|
371
295
|
```ts
|
|
372
|
-
export interface
|
|
296
|
+
export interface ScrcpyMediaStreamConfigurationPacket {
|
|
373
297
|
type: "configuration";
|
|
374
|
-
data:
|
|
298
|
+
data: Uint8Array;
|
|
375
299
|
}
|
|
376
300
|
|
|
377
|
-
export interface
|
|
378
|
-
type: "
|
|
379
|
-
keyframe?: boolean
|
|
380
|
-
pts?: bigint
|
|
301
|
+
export interface ScrcpyMediaStreamDataPacket {
|
|
302
|
+
type: "data";
|
|
303
|
+
keyframe?: boolean;
|
|
304
|
+
pts?: bigint;
|
|
381
305
|
data: Uint8Array;
|
|
382
306
|
}
|
|
383
307
|
```
|
|
384
308
|
|
|
385
|
-
When `sendFrameMeta: false` is set,
|
|
309
|
+
When `sendFrameMeta: false` is set, there will be no `configuration` packets, and no `keyframe` and `pts` fields in `data` packets. It's commonly used with decoders that can parse the media stream itself like FFmpeg, or saved unprocessed.
|
|
386
310
|
|
|
387
|
-
Otherwise, both `configuration` and `
|
|
311
|
+
Otherwise, both `configuration` and `data` packets are available.
|
|
388
312
|
|
|
389
|
-
- `configuration`
|
|
390
|
-
- `pts` (and `keyframe` field from server version 1.23) fields in `
|
|
313
|
+
- `configuration` packet will be the first packet, and contains codec information. It will occasionally be sent again if the stream configuration changes.
|
|
314
|
+
- `pts` (and `keyframe` field from server version 1.23) fields in `data` packets are available to help decode the stream.
|
|
391
315
|
|
|
392
316
|
## Decode video stream
|
|
393
317
|
|
|
394
|
-
`@yume-chan/scrcpy-decoder-tinyh264` and `@yume-chan/scrcpy-decoder-webcodecs` can be used to decode and render the video stream in
|
|
318
|
+
`@yume-chan/scrcpy-decoder-tinyh264` and `@yume-chan/scrcpy-decoder-webcodecs` can be used to decode and render the video stream in browsers. Refer to their README files for compatibility and usage information.
|
package/esm/codec/h264.d.ts
CHANGED
|
@@ -31,27 +31,7 @@ export declare enum AndroidAvcLevel {
|
|
|
31
31
|
Level61 = 262144,
|
|
32
32
|
Level62 = 524288
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
* Split NAL units from a H.264/H.265 Annex B stream.
|
|
36
|
-
*
|
|
37
|
-
* The input is not modified.
|
|
38
|
-
* The returned NAL units are views of the input (no memory allocation nor copy),
|
|
39
|
-
* and still contains emulation prevention bytes.
|
|
40
|
-
*
|
|
41
|
-
* This methods returns a generator, so it can be stopped immediately
|
|
42
|
-
* after the interested NAL unit is found.
|
|
43
|
-
*/
|
|
44
|
-
export declare function naluSplit(buffer: Uint8Array): Generator<Uint8Array>;
|
|
45
|
-
/**
|
|
46
|
-
* Remove emulation prevention bytes from a H.264/H.265 NAL Unit.
|
|
47
|
-
*
|
|
48
|
-
* The input is not modified.
|
|
49
|
-
* If the input doesn't contain any emulation prevention bytes,
|
|
50
|
-
* the input is returned as-is.
|
|
51
|
-
* Otherwise, a new `Uint8Array` is created and returned.
|
|
52
|
-
*/
|
|
53
|
-
export declare function naluRemoveEmulation(buffer: Uint8Array): Uint8Array;
|
|
54
|
-
export declare function h264ParseSequenceParameterSet(buffer: Uint8Array): {
|
|
34
|
+
export declare function h264ParseSequenceParameterSet(nalu: Uint8Array): {
|
|
55
35
|
profile_idc: number;
|
|
56
36
|
constraint_set: number;
|
|
57
37
|
constraint_set0_flag: boolean;
|
package/esm/codec/h264.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"h264.d.ts","sourceRoot":"","sources":["../../src/codec/h264.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"h264.d.ts","sourceRoot":"","sources":["../../src/codec/h264.ts"],"names":[],"mappings":"AAOA,oBAAY,iBAAiB;IACzB,QAAQ,IAAS;IACjB,IAAI,IAAS;IACb,QAAQ,IAAS;IACjB,IAAI,IAAS;IACb,MAAM,KAAS;IACf,OAAO,KAAS;IAChB,OAAO,KAAS;IAChB,mBAAmB,QAAU;IAC7B,eAAe,SAAU;CAC5B;AAED,oBAAY,eAAe;IACvB,MAAM,IAAS;IACf,OAAO,IAAS;IAChB,OAAO,IAAS;IAChB,OAAO,IAAS;IAChB,OAAO,KAAS;IAChB,MAAM,KAAS;IACf,OAAO,KAAS;IAChB,OAAO,MAAS;IAChB,MAAM,MAAS;IACf,OAAO,MAAS;IAChB,OAAO,OAAU;IACjB,MAAM,OAAU;IAChB,OAAO,OAAU;IACjB,OAAO,OAAU;IACjB,MAAM,QAAU;IAChB,OAAO,QAAU;IACjB,OAAO,QAAU;IACjB,MAAM,SAAU;IAChB,OAAO,SAAU;IACjB,OAAO,SAAU;CACpB;AAWD,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,UAAU;;;;;;;;;;;;;;;;;;;EAmK7D;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,UAAU;;;EAgCzD;AAED,MAAM,WAAW,iBAAiB;IAC9B,mBAAmB,EAAE,UAAU,CAAC;IAChC,oBAAoB,EAAE,UAAU,CAAC;IAEjC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IAEnB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IAEtB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,UAAU,GAAG,iBAAiB,CA2C1E"}
|