@yume-chan/scrcpy 0.0.18 → 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 +33 -0
- package/CHANGELOG.md +18 -1
- package/README.md +157 -183
- package/bin/scrcpy-server +0 -0
- package/bin/version.d.ts +1 -1
- package/bin/version.js +1 -1
- package/esm/codec/av1.d.ts +33 -0
- package/esm/codec/av1.d.ts.map +1 -0
- package/esm/codec/av1.js +35 -0
- package/esm/codec/av1.js.map +1 -0
- package/esm/codec/h264.d.ts +78 -0
- package/esm/codec/h264.d.ts.map +1 -0
- package/esm/codec/h264.js +256 -0
- package/esm/codec/h264.js.map +1 -0
- package/esm/codec/h265.d.ts +490 -0
- package/esm/codec/h265.d.ts.map +1 -0
- package/esm/codec/h265.js +1098 -0
- package/esm/codec/h265.js.map +1 -0
- package/esm/codec/index.d.ts +5 -0
- package/esm/codec/index.d.ts.map +1 -0
- package/esm/codec/index.js +5 -0
- package/esm/codec/index.js.map +1 -0
- 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 +2 -2
- package/esm/control/back-or-screen-on.d.ts.map +1 -1
- package/esm/control/back-or-screen-on.js +1 -1
- package/esm/control/basic.d.ts +5 -0
- package/esm/control/basic.d.ts.map +1 -0
- package/esm/control/basic.js +3 -0
- package/esm/control/basic.js.map +1 -0
- package/esm/control/hover-helper.d.ts +17 -17
- package/esm/control/hover-helper.d.ts.map +1 -1
- package/esm/control/hover-helper.js +43 -43
- package/esm/control/hover-helper.js.map +1 -1
- package/esm/control/index.d.ts +13 -11
- package/esm/control/index.d.ts.map +1 -1
- package/esm/control/index.js +13 -11
- package/esm/control/index.js.map +1 -1
- package/esm/control/inject-keycode.d.ts +193 -60
- package/esm/control/inject-keycode.d.ts.map +1 -1
- package/esm/control/inject-keycode.js +198 -61
- package/esm/control/inject-keycode.js.map +1 -1
- package/esm/control/inject-scroll.d.ts +2 -2
- package/esm/control/inject-scroll.d.ts.map +1 -1
- package/esm/control/inject-scroll.js +1 -1
- package/esm/control/inject-text.d.ts +7 -8
- package/esm/control/inject-text.d.ts.map +1 -1
- package/esm/control/inject-text.js +5 -6
- package/esm/control/inject-text.js.map +1 -1
- package/esm/control/inject-touch.d.ts +32 -37
- package/esm/control/inject-touch.d.ts.map +1 -1
- package/esm/control/inject-touch.js +35 -62
- package/esm/control/inject-touch.js.map +1 -1
- package/esm/control/rotate-device.d.ts +4 -6
- package/esm/control/rotate-device.d.ts.map +1 -1
- package/esm/control/rotate-device.js +2 -4
- package/esm/control/rotate-device.js.map +1 -1
- package/esm/control/serializer.d.ts +25 -33
- package/esm/control/serializer.d.ts.map +1 -1
- package/esm/control/serializer.js +53 -78
- package/esm/control/serializer.js.map +1 -1
- package/esm/control/set-clipboard.d.ts +2 -2
- package/esm/control/set-clipboard.d.ts.map +1 -1
- package/esm/control/set-clipboard.js +1 -1
- package/esm/control/set-screen-power-mode.d.ts +10 -11
- package/esm/control/set-screen-power-mode.d.ts.map +1 -1
- package/esm/control/set-screen-power-mode.js +10 -11
- package/esm/control/set-screen-power-mode.js.map +1 -1
- package/esm/control/type.d.ts +28 -14
- package/esm/control/type.d.ts.map +1 -1
- package/esm/control/type.js +40 -18
- 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/ack-clipboard.d.ts +8 -8
- package/esm/device-message/ack-clipboard.d.ts.map +1 -1
- package/esm/device-message/ack-clipboard.js +5 -5
- package/esm/device-message/clipboard.d.ts +9 -9
- package/esm/device-message/clipboard.d.ts.map +1 -1
- package/esm/device-message/clipboard.js +6 -6
- package/esm/device-message/index.d.ts +4 -4
- package/esm/device-message/index.js +4 -4
- package/esm/device-message/stream.d.ts +7 -7
- package/esm/device-message/stream.d.ts.map +1 -1
- package/esm/device-message/stream.js +34 -19
- package/esm/device-message/stream.js.map +1 -1
- package/esm/device-message/type.d.ts +4 -4
- package/esm/device-message/type.js +6 -6
- package/esm/index.d.ts +4 -5
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +4 -5
- package/esm/index.js.map +1 -1
- package/esm/options/1_16/codec-options.d.ts +19 -19
- package/esm/options/1_16/codec-options.d.ts.map +1 -1
- package/esm/options/1_16/codec-options.js +25 -25
- package/esm/options/1_16/codec-options.js.map +1 -1
- package/esm/options/1_16/float-to-uint16.d.ts +5 -0
- package/esm/options/1_16/float-to-uint16.d.ts.map +1 -0
- package/esm/options/1_16/float-to-uint16.js +27 -0
- package/esm/options/1_16/float-to-uint16.js.map +1 -0
- package/esm/options/1_16/index.d.ts +6 -4
- package/esm/options/1_16/index.d.ts.map +1 -1
- package/esm/options/1_16/index.js +6 -4
- package/esm/options/1_16/index.js.map +1 -1
- package/esm/options/1_16/init.d.ts +66 -0
- package/esm/options/1_16/init.d.ts.map +1 -0
- package/esm/options/1_16/init.js +16 -0
- package/esm/options/1_16/init.js.map +1 -0
- package/esm/options/1_16/message.d.ts +32 -0
- package/esm/options/1_16/message.d.ts.map +1 -0
- package/esm/options/1_16/message.js +37 -0
- package/esm/options/1_16/message.js.map +1 -0
- package/esm/options/1_16/options.d.ts +48 -93
- package/esm/options/1_16/options.d.ts.map +1 -1
- package/esm/options/1_16/options.js +152 -189
- package/esm/options/1_16/options.js.map +1 -1
- package/esm/options/1_16/scroll.d.ts +26 -26
- package/esm/options/1_16/scroll.d.ts.map +1 -1
- package/esm/options/1_16/scroll.js +54 -55
- package/esm/options/1_16/scroll.js.map +1 -1
- package/esm/options/1_17.d.ts +33 -0
- package/esm/options/1_17.d.ts.map +1 -0
- package/esm/options/1_17.js +42 -0
- package/esm/options/1_17.js.map +1 -0
- package/esm/options/1_18.d.ts +59 -19
- package/esm/options/1_18.d.ts.map +1 -1
- package/esm/options/1_18.js +78 -45
- package/esm/options/1_18.js.map +1 -1
- package/esm/options/1_21.d.ts +41 -20
- package/esm/options/1_21.d.ts.map +1 -1
- package/esm/options/1_21.js +51 -36
- package/esm/options/1_21.js.map +1 -1
- package/esm/options/1_22/index.d.ts +3 -2
- package/esm/options/1_22/index.d.ts.map +1 -1
- package/esm/options/1_22/index.js +3 -2
- package/esm/options/1_22/index.js.map +1 -1
- package/esm/options/1_22/init.d.ts +17 -0
- package/esm/options/1_22/init.d.ts.map +1 -0
- package/esm/options/1_22/init.js +2 -0
- package/esm/options/1_22/init.js.map +1 -0
- package/esm/options/1_22/options.d.ts +35 -28
- package/esm/options/1_22/options.d.ts.map +1 -1
- package/esm/options/1_22/options.js +36 -25
- package/esm/options/1_22/options.js.map +1 -1
- package/esm/options/1_22/scroll.d.ts +16 -16
- package/esm/options/1_22/scroll.d.ts.map +1 -1
- package/esm/options/1_22/scroll.js +14 -14
- package/esm/options/1_23.d.ts +36 -11
- package/esm/options/1_23.d.ts.map +1 -1
- package/esm/options/1_23.js +44 -34
- package/esm/options/1_23.js.map +1 -1
- package/esm/options/1_24.d.ts +34 -8
- package/esm/options/1_24.d.ts.map +1 -1
- package/esm/options/1_24.js +22 -12
- package/esm/options/1_24.js.map +1 -1
- package/esm/options/1_25/index.d.ts +2 -2
- package/esm/options/1_25/index.js +2 -2
- package/esm/options/1_25/options.d.ts +10 -5
- package/esm/options/1_25/options.d.ts.map +1 -1
- package/esm/options/1_25/options.js +21 -7
- package/esm/options/1_25/options.js.map +1 -1
- package/esm/options/1_25/scroll.d.ts +19 -18
- package/esm/options/1_25/scroll.d.ts.map +1 -1
- package/esm/options/1_25/scroll.js +33 -32
- package/esm/options/1_25/scroll.js.map +1 -1
- package/esm/options/2_0.d.ts +91 -0
- package/esm/options/2_0.d.ts.map +1 -0
- package/esm/options/2_0.js +244 -0
- package/esm/options/2_0.js.map +1 -0
- package/esm/options/codec.d.ts +52 -0
- package/esm/options/codec.d.ts.map +1 -0
- package/esm/options/codec.js +26 -0
- package/esm/options/codec.js.map +1 -0
- package/esm/options/index.d.ts +12 -8
- package/esm/options/index.d.ts.map +1 -1
- package/esm/options/index.js +12 -8
- package/esm/options/index.js.map +1 -1
- package/esm/options/latest.d.ts +12 -0
- package/esm/options/latest.d.ts.map +1 -0
- package/esm/options/latest.js +8 -0
- package/esm/options/latest.js.map +1 -0
- package/esm/options/types.d.ts +86 -46
- package/esm/options/types.d.ts.map +1 -1
- package/esm/options/types.js +69 -17
- package/esm/options/types.js.map +1 -1
- package/package.json +10 -16
- 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/src/control/basic.ts +3 -0
- package/src/control/hover-helper.ts +2 -4
- package/src/control/index.ts +2 -0
- package/src/control/inject-keycode.ts +194 -51
- package/src/control/inject-scroll.ts +1 -1
- package/src/control/inject-text.ts +6 -9
- package/src/control/inject-touch.ts +16 -55
- package/src/control/rotate-device.ts +3 -7
- package/src/control/serializer.ts +49 -105
- package/src/control/set-clipboard.ts +1 -1
- package/src/control/set-screen-power-mode.ts +6 -9
- package/src/control/type.ts +32 -0
- package/src/control/writer.ts +87 -0
- package/src/device-message/ack-clipboard.ts +1 -1
- package/src/device-message/clipboard.ts +1 -1
- package/src/device-message/stream.ts +32 -12
- package/src/index.ts +4 -5
- package/src/options/1_16/codec-options.ts +5 -8
- 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 +152 -256
- package/src/options/1_16/scroll.ts +2 -5
- package/src/options/1_17.ts +66 -0
- package/src/options/1_18.ts +106 -42
- package/src/options/1_21.ts +51 -30
- 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 +40 -46
- package/src/options/1_22/scroll.ts +2 -2
- package/src/options/1_23.ts +33 -23
- package/src/options/1_24.ts +25 -11
- package/src/options/1_25/options.ts +25 -6
- package/src/options/1_25/scroll.ts +5 -7
- package/src/options/2_0.ts +342 -0
- package/src/options/codec.ts +98 -0
- package/src/options/index.ts +7 -3
- package/src/options/latest.ts +14 -0
- package/src/options/types.ts +158 -48
- 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 -243
- package/esm/adb/client.js.map +0 -1
- package/esm/adb/connection.d.ts +0 -47
- package/esm/adb/connection.d.ts.map +0 -1
- package/esm/adb/connection.js +0 -110
- 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/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/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/src/adb/client.ts +0 -345
- package/src/adb/connection.ts +0 -192
- package/src/adb/index.ts +0 -3
- package/src/adb/options/1_16.ts +0 -30
- 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
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split NAL units from an H.264/H.265 Annex B stream.
|
|
3
|
+
*
|
|
4
|
+
* The input is not modified.
|
|
5
|
+
* The returned NAL units are views of the input (no memory allocation nor copy),
|
|
6
|
+
* and still contains emulation prevention bytes.
|
|
7
|
+
*
|
|
8
|
+
* This methods returns a generator, so it can be stopped immediately
|
|
9
|
+
* after the interested NAL unit is found.
|
|
10
|
+
*/
|
|
11
|
+
export function* annexBSplitNalu(buffer: Uint8Array): Generator<Uint8Array> {
|
|
12
|
+
// -1 means we haven't found the first start code
|
|
13
|
+
let start = -1;
|
|
14
|
+
// How many `0x00`s in a row we have counted
|
|
15
|
+
let zeroCount = 0;
|
|
16
|
+
let inEmulation = false;
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < buffer.length; i += 1) {
|
|
19
|
+
const byte = buffer[i]!;
|
|
20
|
+
|
|
21
|
+
if (inEmulation) {
|
|
22
|
+
if (byte > 0x03) {
|
|
23
|
+
// `0x00000304` or larger are invalid
|
|
24
|
+
throw new Error("Invalid data");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
inEmulation = false;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (byte === 0x00) {
|
|
32
|
+
zeroCount += 1;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const prevZeroCount = zeroCount;
|
|
37
|
+
zeroCount = 0;
|
|
38
|
+
|
|
39
|
+
if (start === -1) {
|
|
40
|
+
// 0x000001 is the start code
|
|
41
|
+
// But it can be preceded by any number of zeros
|
|
42
|
+
// So 2 is the minimal
|
|
43
|
+
if (prevZeroCount >= 2 && byte === 0x01) {
|
|
44
|
+
// Found start of first NAL unit
|
|
45
|
+
start = i + 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Not begin with start code
|
|
50
|
+
throw new Error("Invalid data");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (prevZeroCount < 2) {
|
|
54
|
+
// zero or one `0x00`s are acceptable
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (byte === 0x01) {
|
|
59
|
+
// Found another NAL unit
|
|
60
|
+
yield buffer.subarray(start, i - prevZeroCount);
|
|
61
|
+
|
|
62
|
+
start = i + 1;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (prevZeroCount > 2) {
|
|
67
|
+
// Too much `0x00`s
|
|
68
|
+
throw new Error("Invalid data");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
switch (byte) {
|
|
72
|
+
case 0x02:
|
|
73
|
+
// Didn't find why, but 7.4.1 NAL unit semantics forbids `0x000002` appearing in NAL units
|
|
74
|
+
throw new Error("Invalid data");
|
|
75
|
+
case 0x03:
|
|
76
|
+
// `0x000003` is the "emulation_prevention_three_byte"
|
|
77
|
+
// `0x00000300`, `0x00000301`, `0x00000302` and `0x00000303` represent
|
|
78
|
+
// `0x000000`, `0x000001`, `0x000002` and `0x000003` respectively
|
|
79
|
+
inEmulation = true;
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
// `0x000004` or larger are as-is
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (inEmulation) {
|
|
88
|
+
throw new Error("Invalid data");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
yield buffer.subarray(start, buffer.length);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Remove emulation prevention bytes from a H.264/H.265 NAL Unit.
|
|
96
|
+
*
|
|
97
|
+
* The input is not modified.
|
|
98
|
+
* If the input doesn't contain any emulation prevention bytes,
|
|
99
|
+
* the input is returned as-is.
|
|
100
|
+
* Otherwise, a new `Uint8Array` is created and returned.
|
|
101
|
+
*/
|
|
102
|
+
export function naluRemoveEmulation(buffer: Uint8Array) {
|
|
103
|
+
// output will be created when first emulation prevention byte is found
|
|
104
|
+
let output: Uint8Array | undefined;
|
|
105
|
+
let outputOffset = 0;
|
|
106
|
+
|
|
107
|
+
let zeroCount = 0;
|
|
108
|
+
let inEmulation = false;
|
|
109
|
+
|
|
110
|
+
let i = 0;
|
|
111
|
+
scan: for (; i < buffer.length; i += 1) {
|
|
112
|
+
const byte = buffer[i]!;
|
|
113
|
+
|
|
114
|
+
if (byte === 0x00) {
|
|
115
|
+
zeroCount += 1;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Current byte is not zero
|
|
120
|
+
const prevZeroCount = zeroCount;
|
|
121
|
+
zeroCount = 0;
|
|
122
|
+
|
|
123
|
+
if (prevZeroCount < 2) {
|
|
124
|
+
// zero or one `0x00`s are acceptable
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (byte === 0x01) {
|
|
129
|
+
// Unexpected start code
|
|
130
|
+
throw new Error("Invalid data");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (prevZeroCount > 2) {
|
|
134
|
+
// Too much `0x00`s
|
|
135
|
+
throw new Error("Invalid data");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
switch (byte) {
|
|
139
|
+
case 0x02:
|
|
140
|
+
// Didn't find why, but 7.4.1 NAL unit semantics forbids `0x000002` appearing in NAL units
|
|
141
|
+
throw new Error("Invalid data");
|
|
142
|
+
case 0x03:
|
|
143
|
+
// `0x000003` is the "emulation_prevention_three_byte"
|
|
144
|
+
// `0x00000300`, `0x00000301`, `0x00000302` and `0x00000303` represent
|
|
145
|
+
// `0x000000`, `0x000001`, `0x000002` and `0x000003` respectively
|
|
146
|
+
inEmulation = true;
|
|
147
|
+
|
|
148
|
+
// Create output and copy the data before the emulation prevention byte
|
|
149
|
+
// Output size is unknown, so we use the input size as an upper bound
|
|
150
|
+
output = new Uint8Array(buffer.length - 1);
|
|
151
|
+
output.set(buffer.subarray(0, i));
|
|
152
|
+
outputOffset = i;
|
|
153
|
+
i += 1;
|
|
154
|
+
break scan;
|
|
155
|
+
default:
|
|
156
|
+
// `0x000004` or larger are as-is
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!output) {
|
|
162
|
+
return buffer;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Continue at the byte after the emulation prevention byte
|
|
166
|
+
for (; i < buffer.length; i += 1) {
|
|
167
|
+
const byte = buffer[i]!;
|
|
168
|
+
|
|
169
|
+
output[outputOffset] = byte;
|
|
170
|
+
outputOffset += 1;
|
|
171
|
+
|
|
172
|
+
if (inEmulation) {
|
|
173
|
+
if (byte > 0x03) {
|
|
174
|
+
// `0x00000304` or larger are invalid
|
|
175
|
+
throw new Error("Invalid data");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// `00000300000300` results in `0000000000` (both `0x03` are removed)
|
|
179
|
+
// which means the `0x00` after `0x03` also counts
|
|
180
|
+
if (byte === 0x00) {
|
|
181
|
+
zeroCount += 1;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
inEmulation = false;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (byte === 0x00) {
|
|
189
|
+
zeroCount += 1;
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const prevZeroCount = zeroCount;
|
|
194
|
+
zeroCount = 0;
|
|
195
|
+
|
|
196
|
+
if (prevZeroCount < 2) {
|
|
197
|
+
// zero or one `0x00`s are acceptable
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (byte === 0x01) {
|
|
202
|
+
// Unexpected start code
|
|
203
|
+
throw new Error("Invalid data");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (prevZeroCount > 2) {
|
|
207
|
+
// Too much `0x00`s
|
|
208
|
+
throw new Error("Invalid data");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
switch (byte) {
|
|
212
|
+
case 0x02:
|
|
213
|
+
// Didn't find why, but 7.4.1 NAL unit semantics forbids `0x000002` appearing in NAL units
|
|
214
|
+
throw new Error("Invalid data");
|
|
215
|
+
case 0x03:
|
|
216
|
+
// `0x000003` is the "emulation_prevention_three_byte"
|
|
217
|
+
// `0x00000300`, `0x00000301`, `0x00000302` and `0x00000303` represent
|
|
218
|
+
// `0x000000`, `0x000001`, `0x000002` and `0x000003` respectively
|
|
219
|
+
inEmulation = true;
|
|
220
|
+
|
|
221
|
+
// Remove the emulation prevention byte
|
|
222
|
+
outputOffset -= 1;
|
|
223
|
+
break;
|
|
224
|
+
default:
|
|
225
|
+
// `0x000004` or larger are as-is
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return output.subarray(0, outputOffset);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export class NaluSodbBitReader {
|
|
234
|
+
private readonly _nalu: Uint8Array;
|
|
235
|
+
private readonly _byteLength: number;
|
|
236
|
+
private readonly _stopBitIndex: number;
|
|
237
|
+
|
|
238
|
+
private _zeroCount = 0;
|
|
239
|
+
private _bytePosition = -1;
|
|
240
|
+
private _bitPosition = -1;
|
|
241
|
+
private _byte = 0;
|
|
242
|
+
|
|
243
|
+
public get byteLength() {
|
|
244
|
+
return this._byteLength;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
public get stopBitIndex() {
|
|
248
|
+
return this._stopBitIndex;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
public get bytePosition() {
|
|
252
|
+
return this._bytePosition;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
public get bitPosition() {
|
|
256
|
+
return this._bitPosition;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
public get ended() {
|
|
260
|
+
return (
|
|
261
|
+
this._bytePosition === this._byteLength &&
|
|
262
|
+
this._bitPosition === this._stopBitIndex
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
public constructor(nalu: Uint8Array) {
|
|
267
|
+
this._nalu = nalu;
|
|
268
|
+
|
|
269
|
+
for (let i = nalu.length - 1; i >= 0; i -= 1) {
|
|
270
|
+
if (this._nalu[i] === 0) {
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const byte = nalu[i]!;
|
|
275
|
+
for (let j = 0; j < 8; j += 1) {
|
|
276
|
+
if (((byte >> j) & 1) === 1) {
|
|
277
|
+
this._byteLength = i;
|
|
278
|
+
this._stopBitIndex = j;
|
|
279
|
+
this.readByte();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
throw new Error("End bit not found");
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private readByte() {
|
|
289
|
+
this._byte = this._nalu[this._bytePosition]!;
|
|
290
|
+
if (this._zeroCount === 2 && this._byte === 3) {
|
|
291
|
+
this._zeroCount = 0;
|
|
292
|
+
this._bytePosition += 1;
|
|
293
|
+
this.readByte();
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (this._byte === 0) {
|
|
298
|
+
this._zeroCount += 1;
|
|
299
|
+
} else {
|
|
300
|
+
this._zeroCount = 0;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
public next() {
|
|
305
|
+
if (this._bitPosition === -1) {
|
|
306
|
+
this._bitPosition = 7;
|
|
307
|
+
this._bytePosition += 1;
|
|
308
|
+
this.readByte();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (
|
|
312
|
+
this._bytePosition === this._byteLength &&
|
|
313
|
+
this._bitPosition === this._stopBitIndex
|
|
314
|
+
) {
|
|
315
|
+
throw new Error("Bit index out of bounds");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const value = (this._byte >> this._bitPosition) & 1;
|
|
319
|
+
this._bitPosition -= 1;
|
|
320
|
+
return value;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
public read(length: number): number {
|
|
324
|
+
if (length > 32) {
|
|
325
|
+
throw new Error("Read length too large");
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
let result = 0;
|
|
329
|
+
for (let i = 0; i < length; i += 1) {
|
|
330
|
+
result = (result << 1) | this.next();
|
|
331
|
+
}
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
public skip(length: number) {
|
|
336
|
+
for (let i = 0; i < length; i += 1) {
|
|
337
|
+
this.next();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
public decodeExponentialGolombNumber(): number {
|
|
342
|
+
let length = 0;
|
|
343
|
+
while (this.next() === 0) {
|
|
344
|
+
length += 1;
|
|
345
|
+
}
|
|
346
|
+
if (length === 0) {
|
|
347
|
+
return 0;
|
|
348
|
+
}
|
|
349
|
+
return ((1 << length) | this.read(length)) - 1;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
public peek(length: number) {
|
|
353
|
+
const { _zeroCount, _bytePosition, _bitPosition, _byte } = this;
|
|
354
|
+
const result = this.read(length);
|
|
355
|
+
Object.assign(this, { _zeroCount, _bytePosition, _bitPosition, _byte });
|
|
356
|
+
return result;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
public readBytes(length: number): Uint8Array {
|
|
360
|
+
const result = new Uint8Array(length);
|
|
361
|
+
for (let i = 0; i < length; i += 1) {
|
|
362
|
+
result[i] = this.read(8);
|
|
363
|
+
}
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
public peekBytes(length: number): Uint8Array {
|
|
368
|
+
const { _zeroCount, _bytePosition, _bitPosition, _byte } = this;
|
|
369
|
+
const result = this.readBytes(length);
|
|
370
|
+
Object.assign(this, { _zeroCount, _bytePosition, _bitPosition, _byte });
|
|
371
|
+
return result;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type ScrcpyInjectTouchControlMessage,
|
|
4
|
-
} from "./inject-touch.js";
|
|
1
|
+
import type { ScrcpyInjectTouchControlMessage } from "./inject-touch.js";
|
|
2
|
+
import { AndroidMotionEventAction } from "./inject-touch.js";
|
|
5
3
|
import { ScrcpyControlMessageType } from "./type.js";
|
|
6
4
|
|
|
7
5
|
/**
|
package/src/control/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./back-or-screen-on.js";
|
|
2
|
+
export * from "./basic.js";
|
|
2
3
|
export * from "./hover-helper.js";
|
|
3
4
|
export * from "./inject-keycode.js";
|
|
4
5
|
export * from "./inject-scroll.js";
|
|
@@ -9,3 +10,4 @@ export * from "./serializer.js";
|
|
|
9
10
|
export * from "./set-clipboard.js";
|
|
10
11
|
export * from "./set-screen-power-mode.js";
|
|
11
12
|
export * from "./type.js";
|
|
13
|
+
export * from "./writer.js";
|
|
@@ -1,72 +1,215 @@
|
|
|
1
1
|
import Struct, { placeholder } from "@yume-chan/struct";
|
|
2
2
|
|
|
3
|
-
import { ScrcpyControlMessageType } from "./type.js";
|
|
4
|
-
|
|
5
3
|
export enum AndroidKeyEventAction {
|
|
6
4
|
Down = 0,
|
|
7
5
|
Up = 1,
|
|
8
6
|
}
|
|
9
7
|
|
|
10
|
-
// https://
|
|
8
|
+
// https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/view/KeyEvent.java;l=993;drc=95c1165bb895dd844e1793460710f7163dd330a3
|
|
9
|
+
export enum AndroidKeyEventMeta {
|
|
10
|
+
AltOn = 0x02,
|
|
11
|
+
AltLeftOn = 0x10,
|
|
12
|
+
AltRightOn = 0x20,
|
|
13
|
+
ShiftOn = 0x01,
|
|
14
|
+
ShiftLeftOn = 0x40,
|
|
15
|
+
ShiftRightOn = 0x80,
|
|
16
|
+
CtrlOn = 0x1000,
|
|
17
|
+
CtrlLeftOn = 0x2000,
|
|
18
|
+
CtrlRightOn = 0x4000,
|
|
19
|
+
MetaOn = 0x10000,
|
|
20
|
+
MetaLeftOn = 0x20000,
|
|
21
|
+
MetaRightOn = 0x40000,
|
|
22
|
+
CapsLockOn = 0x100000,
|
|
23
|
+
NumLockOn = 0x200000,
|
|
24
|
+
ScrollLockOn = 0x400000,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/view/KeyEvent.java;l=97;drc=95c1165bb895dd844e1793460710f7163dd330a3
|
|
28
|
+
// Most names follow Web API `KeyboardEvent.code`,
|
|
29
|
+
// Android-only (not exist in HID keyboard standard) keys are prefixed by `Android`.
|
|
11
30
|
export enum AndroidKeyCode {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
31
|
+
AndroidHome = 3,
|
|
32
|
+
AndroidBack = 4,
|
|
33
|
+
AndroidCall,
|
|
34
|
+
AndroidEndCall,
|
|
35
|
+
|
|
36
|
+
Digit0,
|
|
37
|
+
Digit1,
|
|
38
|
+
Digit2,
|
|
39
|
+
Digit3,
|
|
40
|
+
Digit4,
|
|
41
|
+
Digit5,
|
|
42
|
+
Digit6,
|
|
43
|
+
Digit7,
|
|
44
|
+
Digit8,
|
|
45
|
+
Digit9,
|
|
46
|
+
/**
|
|
47
|
+
* '*' key.
|
|
48
|
+
*/
|
|
49
|
+
Star, // Name not verified
|
|
50
|
+
/**
|
|
51
|
+
* '#' key.
|
|
52
|
+
*/
|
|
53
|
+
Pound, // Name not verified
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Directional Pad Up key.
|
|
57
|
+
*/
|
|
58
|
+
ArrowUp,
|
|
59
|
+
/**
|
|
60
|
+
* Directional Pad Down key.
|
|
61
|
+
*/
|
|
62
|
+
ArrowDown,
|
|
63
|
+
/**
|
|
64
|
+
* Directional Pad Left key.
|
|
65
|
+
*/
|
|
66
|
+
ArrowLeft,
|
|
67
|
+
/**
|
|
68
|
+
* Directional Pad Right key.
|
|
69
|
+
*/
|
|
70
|
+
ArrowRight,
|
|
71
|
+
/**
|
|
72
|
+
* Directional Pad Center key.
|
|
73
|
+
*/
|
|
74
|
+
AndroidDPadCenter,
|
|
75
|
+
|
|
76
|
+
VolumeUp, // Name not verified
|
|
77
|
+
VolumeDown, // Name not verified
|
|
78
|
+
Power, // Name not verified
|
|
79
|
+
AndroidCamera,
|
|
80
|
+
Clear, // Name not verified
|
|
81
|
+
|
|
82
|
+
KeyA,
|
|
83
|
+
KeyB,
|
|
84
|
+
KeyC,
|
|
85
|
+
KeyD,
|
|
86
|
+
KeyE,
|
|
87
|
+
KeyF,
|
|
88
|
+
KeyG,
|
|
89
|
+
KeyH,
|
|
90
|
+
KeyI,
|
|
91
|
+
KeyJ,
|
|
92
|
+
KeyK,
|
|
93
|
+
KeyL,
|
|
94
|
+
KeyM,
|
|
95
|
+
KeyN,
|
|
96
|
+
KeyO,
|
|
97
|
+
KeyP,
|
|
98
|
+
KeyQ,
|
|
99
|
+
KeyR,
|
|
100
|
+
KeyS,
|
|
101
|
+
KeyT,
|
|
102
|
+
KeyU,
|
|
103
|
+
KeyV,
|
|
104
|
+
KeyW,
|
|
105
|
+
KeyX,
|
|
106
|
+
KeyY,
|
|
107
|
+
KeyZ,
|
|
108
|
+
Comma,
|
|
109
|
+
Period,
|
|
110
|
+
AltLeft,
|
|
111
|
+
AltRight,
|
|
112
|
+
ShiftLeft,
|
|
113
|
+
ShiftRight,
|
|
114
|
+
Tab,
|
|
51
115
|
Space,
|
|
52
|
-
|
|
53
|
-
|
|
116
|
+
AndroidSymbol,
|
|
117
|
+
AndroidExplorer,
|
|
118
|
+
AndroidEnvelope,
|
|
119
|
+
Enter,
|
|
120
|
+
Backspace,
|
|
121
|
+
Backquote,
|
|
122
|
+
Minus,
|
|
123
|
+
Equal,
|
|
124
|
+
BracketLeft,
|
|
125
|
+
BracketRight,
|
|
126
|
+
Backslash,
|
|
127
|
+
Semicolon,
|
|
128
|
+
Quote,
|
|
129
|
+
Slash,
|
|
130
|
+
At, // Name not verified
|
|
131
|
+
|
|
132
|
+
AndroidNum,
|
|
133
|
+
AndroidHeadsetHook,
|
|
134
|
+
/**
|
|
135
|
+
* Camera Focus key。
|
|
136
|
+
*/
|
|
137
|
+
AndroidFocus,
|
|
138
|
+
|
|
139
|
+
Plus, // Name not verified
|
|
140
|
+
ContextMenu,
|
|
141
|
+
AndroidNotification,
|
|
142
|
+
AndroidSearch,
|
|
143
|
+
|
|
144
|
+
PageUp = 92,
|
|
145
|
+
PageDown,
|
|
146
|
+
|
|
54
147
|
Escape = 111,
|
|
55
|
-
|
|
148
|
+
Delete,
|
|
149
|
+
ControlLeft,
|
|
150
|
+
ControlRight,
|
|
151
|
+
CapsLock,
|
|
152
|
+
ScrollLock,
|
|
153
|
+
MetaLeft,
|
|
154
|
+
MetaRight,
|
|
155
|
+
AndroidFunction,
|
|
156
|
+
PrintScreen,
|
|
157
|
+
Pause,
|
|
158
|
+
|
|
159
|
+
Home,
|
|
160
|
+
End,
|
|
161
|
+
Insert,
|
|
162
|
+
AndroidForward,
|
|
163
|
+
|
|
164
|
+
F1 = 131,
|
|
165
|
+
F2,
|
|
166
|
+
F3,
|
|
167
|
+
F4,
|
|
168
|
+
F5,
|
|
169
|
+
F6,
|
|
170
|
+
F7,
|
|
171
|
+
F8,
|
|
172
|
+
F9,
|
|
173
|
+
F10,
|
|
174
|
+
F11,
|
|
175
|
+
F12,
|
|
176
|
+
|
|
177
|
+
NumLock,
|
|
178
|
+
Numpad0,
|
|
179
|
+
Numpad1,
|
|
180
|
+
Numpad2,
|
|
181
|
+
Numpad3,
|
|
182
|
+
Numpad4,
|
|
183
|
+
Numpad5,
|
|
184
|
+
Numpad6,
|
|
185
|
+
Numpad7,
|
|
186
|
+
Numpad8,
|
|
187
|
+
Numpad9,
|
|
188
|
+
NumpadDivide,
|
|
189
|
+
NumpadMultiply,
|
|
190
|
+
NumpadSubtract,
|
|
191
|
+
NumpadAdd,
|
|
192
|
+
NumpadDecimal,
|
|
193
|
+
NumpadComma, // Name not verified
|
|
194
|
+
NumpadEnter,
|
|
195
|
+
NumpadEquals, // Name not verified
|
|
196
|
+
NumpadLeftParen, // Name not verified
|
|
197
|
+
NumpadRightParen, // Name not verified
|
|
56
198
|
|
|
57
|
-
|
|
58
|
-
|
|
199
|
+
VolumeMute = 164, // Name not verified
|
|
200
|
+
AndroidAppSwitch = 187,
|
|
59
201
|
|
|
60
|
-
|
|
61
|
-
|
|
202
|
+
AndroidCut = 277,
|
|
203
|
+
AndroidCopy,
|
|
204
|
+
AndroidPaste,
|
|
62
205
|
}
|
|
63
206
|
|
|
64
207
|
export const ScrcpyInjectKeyCodeControlMessage = new Struct()
|
|
65
|
-
.uint8("type"
|
|
208
|
+
.uint8("type")
|
|
66
209
|
.uint8("action", placeholder<AndroidKeyEventAction>())
|
|
67
210
|
.uint32("keyCode")
|
|
68
211
|
.uint32("repeat")
|
|
69
212
|
.uint32("metaState");
|
|
70
213
|
|
|
71
214
|
export type ScrcpyInjectKeyCodeControlMessage =
|
|
72
|
-
typeof ScrcpyInjectKeyCodeControlMessage["TInit"];
|
|
215
|
+
(typeof ScrcpyInjectKeyCodeControlMessage)["TInit"];
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import Struct from
|
|
1
|
+
import Struct from "@yume-chan/struct";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
.uint8('type', ScrcpyControlMessageType.InjectText as const)
|
|
8
|
-
.uint32('length')
|
|
9
|
-
.string('text', { lengthField: 'length' });
|
|
3
|
+
export const ScrcpyInjectTextControlMessage = new Struct()
|
|
4
|
+
.uint8("type")
|
|
5
|
+
.uint32("length")
|
|
6
|
+
.string("text", { lengthField: "length" });
|
|
10
7
|
|
|
11
8
|
export type ScrcpyInjectTextControlMessage =
|
|
12
|
-
typeof ScrcpyInjectTextControlMessage[
|
|
9
|
+
(typeof ScrcpyInjectTextControlMessage)["TInit"];
|