@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.
Files changed (288) hide show
  1. package/CHANGELOG.json +33 -0
  2. package/CHANGELOG.md +18 -1
  3. package/README.md +157 -183
  4. package/bin/scrcpy-server +0 -0
  5. package/bin/version.d.ts +1 -1
  6. package/bin/version.js +1 -1
  7. package/esm/codec/av1.d.ts +33 -0
  8. package/esm/codec/av1.d.ts.map +1 -0
  9. package/esm/codec/av1.js +35 -0
  10. package/esm/codec/av1.js.map +1 -0
  11. package/esm/codec/h264.d.ts +78 -0
  12. package/esm/codec/h264.d.ts.map +1 -0
  13. package/esm/codec/h264.js +256 -0
  14. package/esm/codec/h264.js.map +1 -0
  15. package/esm/codec/h265.d.ts +490 -0
  16. package/esm/codec/h265.d.ts.map +1 -0
  17. package/esm/codec/h265.js +1098 -0
  18. package/esm/codec/h265.js.map +1 -0
  19. package/esm/codec/index.d.ts +5 -0
  20. package/esm/codec/index.d.ts.map +1 -0
  21. package/esm/codec/index.js +5 -0
  22. package/esm/codec/index.js.map +1 -0
  23. package/esm/codec/nalu.d.ts +44 -0
  24. package/esm/codec/nalu.d.ts.map +1 -0
  25. package/esm/codec/nalu.js +310 -0
  26. package/esm/codec/nalu.js.map +1 -0
  27. package/esm/control/back-or-screen-on.d.ts +2 -2
  28. package/esm/control/back-or-screen-on.d.ts.map +1 -1
  29. package/esm/control/back-or-screen-on.js +1 -1
  30. package/esm/control/basic.d.ts +5 -0
  31. package/esm/control/basic.d.ts.map +1 -0
  32. package/esm/control/basic.js +3 -0
  33. package/esm/control/basic.js.map +1 -0
  34. package/esm/control/hover-helper.d.ts +17 -17
  35. package/esm/control/hover-helper.d.ts.map +1 -1
  36. package/esm/control/hover-helper.js +43 -43
  37. package/esm/control/hover-helper.js.map +1 -1
  38. package/esm/control/index.d.ts +13 -11
  39. package/esm/control/index.d.ts.map +1 -1
  40. package/esm/control/index.js +13 -11
  41. package/esm/control/index.js.map +1 -1
  42. package/esm/control/inject-keycode.d.ts +193 -60
  43. package/esm/control/inject-keycode.d.ts.map +1 -1
  44. package/esm/control/inject-keycode.js +198 -61
  45. package/esm/control/inject-keycode.js.map +1 -1
  46. package/esm/control/inject-scroll.d.ts +2 -2
  47. package/esm/control/inject-scroll.d.ts.map +1 -1
  48. package/esm/control/inject-scroll.js +1 -1
  49. package/esm/control/inject-text.d.ts +7 -8
  50. package/esm/control/inject-text.d.ts.map +1 -1
  51. package/esm/control/inject-text.js +5 -6
  52. package/esm/control/inject-text.js.map +1 -1
  53. package/esm/control/inject-touch.d.ts +32 -37
  54. package/esm/control/inject-touch.d.ts.map +1 -1
  55. package/esm/control/inject-touch.js +35 -62
  56. package/esm/control/inject-touch.js.map +1 -1
  57. package/esm/control/rotate-device.d.ts +4 -6
  58. package/esm/control/rotate-device.d.ts.map +1 -1
  59. package/esm/control/rotate-device.js +2 -4
  60. package/esm/control/rotate-device.js.map +1 -1
  61. package/esm/control/serializer.d.ts +25 -33
  62. package/esm/control/serializer.d.ts.map +1 -1
  63. package/esm/control/serializer.js +53 -78
  64. package/esm/control/serializer.js.map +1 -1
  65. package/esm/control/set-clipboard.d.ts +2 -2
  66. package/esm/control/set-clipboard.d.ts.map +1 -1
  67. package/esm/control/set-clipboard.js +1 -1
  68. package/esm/control/set-screen-power-mode.d.ts +10 -11
  69. package/esm/control/set-screen-power-mode.d.ts.map +1 -1
  70. package/esm/control/set-screen-power-mode.js +10 -11
  71. package/esm/control/set-screen-power-mode.js.map +1 -1
  72. package/esm/control/type.d.ts +28 -14
  73. package/esm/control/type.d.ts.map +1 -1
  74. package/esm/control/type.js +40 -18
  75. package/esm/control/type.js.map +1 -1
  76. package/esm/control/writer.d.ts +28 -0
  77. package/esm/control/writer.d.ts.map +1 -0
  78. package/esm/control/writer.js +53 -0
  79. package/esm/control/writer.js.map +1 -0
  80. package/esm/device-message/ack-clipboard.d.ts +8 -8
  81. package/esm/device-message/ack-clipboard.d.ts.map +1 -1
  82. package/esm/device-message/ack-clipboard.js +5 -5
  83. package/esm/device-message/clipboard.d.ts +9 -9
  84. package/esm/device-message/clipboard.d.ts.map +1 -1
  85. package/esm/device-message/clipboard.js +6 -6
  86. package/esm/device-message/index.d.ts +4 -4
  87. package/esm/device-message/index.js +4 -4
  88. package/esm/device-message/stream.d.ts +7 -7
  89. package/esm/device-message/stream.d.ts.map +1 -1
  90. package/esm/device-message/stream.js +34 -19
  91. package/esm/device-message/stream.js.map +1 -1
  92. package/esm/device-message/type.d.ts +4 -4
  93. package/esm/device-message/type.js +6 -6
  94. package/esm/index.d.ts +4 -5
  95. package/esm/index.d.ts.map +1 -1
  96. package/esm/index.js +4 -5
  97. package/esm/index.js.map +1 -1
  98. package/esm/options/1_16/codec-options.d.ts +19 -19
  99. package/esm/options/1_16/codec-options.d.ts.map +1 -1
  100. package/esm/options/1_16/codec-options.js +25 -25
  101. package/esm/options/1_16/codec-options.js.map +1 -1
  102. package/esm/options/1_16/float-to-uint16.d.ts +5 -0
  103. package/esm/options/1_16/float-to-uint16.d.ts.map +1 -0
  104. package/esm/options/1_16/float-to-uint16.js +27 -0
  105. package/esm/options/1_16/float-to-uint16.js.map +1 -0
  106. package/esm/options/1_16/index.d.ts +6 -4
  107. package/esm/options/1_16/index.d.ts.map +1 -1
  108. package/esm/options/1_16/index.js +6 -4
  109. package/esm/options/1_16/index.js.map +1 -1
  110. package/esm/options/1_16/init.d.ts +66 -0
  111. package/esm/options/1_16/init.d.ts.map +1 -0
  112. package/esm/options/1_16/init.js +16 -0
  113. package/esm/options/1_16/init.js.map +1 -0
  114. package/esm/options/1_16/message.d.ts +32 -0
  115. package/esm/options/1_16/message.d.ts.map +1 -0
  116. package/esm/options/1_16/message.js +37 -0
  117. package/esm/options/1_16/message.js.map +1 -0
  118. package/esm/options/1_16/options.d.ts +48 -93
  119. package/esm/options/1_16/options.d.ts.map +1 -1
  120. package/esm/options/1_16/options.js +152 -189
  121. package/esm/options/1_16/options.js.map +1 -1
  122. package/esm/options/1_16/scroll.d.ts +26 -26
  123. package/esm/options/1_16/scroll.d.ts.map +1 -1
  124. package/esm/options/1_16/scroll.js +54 -55
  125. package/esm/options/1_16/scroll.js.map +1 -1
  126. package/esm/options/1_17.d.ts +33 -0
  127. package/esm/options/1_17.d.ts.map +1 -0
  128. package/esm/options/1_17.js +42 -0
  129. package/esm/options/1_17.js.map +1 -0
  130. package/esm/options/1_18.d.ts +59 -19
  131. package/esm/options/1_18.d.ts.map +1 -1
  132. package/esm/options/1_18.js +78 -45
  133. package/esm/options/1_18.js.map +1 -1
  134. package/esm/options/1_21.d.ts +41 -20
  135. package/esm/options/1_21.d.ts.map +1 -1
  136. package/esm/options/1_21.js +51 -36
  137. package/esm/options/1_21.js.map +1 -1
  138. package/esm/options/1_22/index.d.ts +3 -2
  139. package/esm/options/1_22/index.d.ts.map +1 -1
  140. package/esm/options/1_22/index.js +3 -2
  141. package/esm/options/1_22/index.js.map +1 -1
  142. package/esm/options/1_22/init.d.ts +17 -0
  143. package/esm/options/1_22/init.d.ts.map +1 -0
  144. package/esm/options/1_22/init.js +2 -0
  145. package/esm/options/1_22/init.js.map +1 -0
  146. package/esm/options/1_22/options.d.ts +35 -28
  147. package/esm/options/1_22/options.d.ts.map +1 -1
  148. package/esm/options/1_22/options.js +36 -25
  149. package/esm/options/1_22/options.js.map +1 -1
  150. package/esm/options/1_22/scroll.d.ts +16 -16
  151. package/esm/options/1_22/scroll.d.ts.map +1 -1
  152. package/esm/options/1_22/scroll.js +14 -14
  153. package/esm/options/1_23.d.ts +36 -11
  154. package/esm/options/1_23.d.ts.map +1 -1
  155. package/esm/options/1_23.js +44 -34
  156. package/esm/options/1_23.js.map +1 -1
  157. package/esm/options/1_24.d.ts +34 -8
  158. package/esm/options/1_24.d.ts.map +1 -1
  159. package/esm/options/1_24.js +22 -12
  160. package/esm/options/1_24.js.map +1 -1
  161. package/esm/options/1_25/index.d.ts +2 -2
  162. package/esm/options/1_25/index.js +2 -2
  163. package/esm/options/1_25/options.d.ts +10 -5
  164. package/esm/options/1_25/options.d.ts.map +1 -1
  165. package/esm/options/1_25/options.js +21 -7
  166. package/esm/options/1_25/options.js.map +1 -1
  167. package/esm/options/1_25/scroll.d.ts +19 -18
  168. package/esm/options/1_25/scroll.d.ts.map +1 -1
  169. package/esm/options/1_25/scroll.js +33 -32
  170. package/esm/options/1_25/scroll.js.map +1 -1
  171. package/esm/options/2_0.d.ts +91 -0
  172. package/esm/options/2_0.d.ts.map +1 -0
  173. package/esm/options/2_0.js +244 -0
  174. package/esm/options/2_0.js.map +1 -0
  175. package/esm/options/codec.d.ts +52 -0
  176. package/esm/options/codec.d.ts.map +1 -0
  177. package/esm/options/codec.js +26 -0
  178. package/esm/options/codec.js.map +1 -0
  179. package/esm/options/index.d.ts +12 -8
  180. package/esm/options/index.d.ts.map +1 -1
  181. package/esm/options/index.js +12 -8
  182. package/esm/options/index.js.map +1 -1
  183. package/esm/options/latest.d.ts +12 -0
  184. package/esm/options/latest.d.ts.map +1 -0
  185. package/esm/options/latest.js +8 -0
  186. package/esm/options/latest.js.map +1 -0
  187. package/esm/options/types.d.ts +86 -46
  188. package/esm/options/types.d.ts.map +1 -1
  189. package/esm/options/types.js +69 -17
  190. package/esm/options/types.js.map +1 -1
  191. package/package.json +10 -16
  192. package/src/codec/av1.ts +33 -0
  193. package/src/codec/h264.ts +317 -0
  194. package/src/codec/h265.ts +1375 -0
  195. package/src/codec/index.ts +4 -0
  196. package/src/codec/nalu.ts +373 -0
  197. package/src/control/back-or-screen-on.ts +1 -1
  198. package/src/control/basic.ts +3 -0
  199. package/src/control/hover-helper.ts +2 -4
  200. package/src/control/index.ts +2 -0
  201. package/src/control/inject-keycode.ts +194 -51
  202. package/src/control/inject-scroll.ts +1 -1
  203. package/src/control/inject-text.ts +6 -9
  204. package/src/control/inject-touch.ts +16 -55
  205. package/src/control/rotate-device.ts +3 -7
  206. package/src/control/serializer.ts +49 -105
  207. package/src/control/set-clipboard.ts +1 -1
  208. package/src/control/set-screen-power-mode.ts +6 -9
  209. package/src/control/type.ts +32 -0
  210. package/src/control/writer.ts +87 -0
  211. package/src/device-message/ack-clipboard.ts +1 -1
  212. package/src/device-message/clipboard.ts +1 -1
  213. package/src/device-message/stream.ts +32 -12
  214. package/src/index.ts +4 -5
  215. package/src/options/1_16/codec-options.ts +5 -8
  216. package/src/options/1_16/float-to-uint16.ts +33 -0
  217. package/src/options/1_16/index.ts +3 -1
  218. package/src/options/1_16/init.ts +80 -0
  219. package/src/options/1_16/message.ts +55 -0
  220. package/src/options/1_16/options.ts +152 -256
  221. package/src/options/1_16/scroll.ts +2 -5
  222. package/src/options/1_17.ts +66 -0
  223. package/src/options/1_18.ts +106 -42
  224. package/src/options/1_21.ts +51 -30
  225. package/src/options/1_22/index.ts +1 -0
  226. package/src/options/1_22/init.ts +19 -0
  227. package/src/options/1_22/options.ts +40 -46
  228. package/src/options/1_22/scroll.ts +2 -2
  229. package/src/options/1_23.ts +33 -23
  230. package/src/options/1_24.ts +25 -11
  231. package/src/options/1_25/options.ts +25 -6
  232. package/src/options/1_25/scroll.ts +5 -7
  233. package/src/options/2_0.ts +342 -0
  234. package/src/options/codec.ts +98 -0
  235. package/src/options/index.ts +7 -3
  236. package/src/options/latest.ts +14 -0
  237. package/src/options/types.ts +158 -48
  238. package/tsconfig.build.json +9 -1
  239. package/tsconfig.build.tsbuildinfo +1 -1
  240. package/esm/adb/client.d.ts +0 -41
  241. package/esm/adb/client.d.ts.map +0 -1
  242. package/esm/adb/client.js +0 -243
  243. package/esm/adb/client.js.map +0 -1
  244. package/esm/adb/connection.d.ts +0 -47
  245. package/esm/adb/connection.d.ts.map +0 -1
  246. package/esm/adb/connection.js +0 -110
  247. package/esm/adb/connection.js.map +0 -1
  248. package/esm/adb/index.d.ts +0 -4
  249. package/esm/adb/index.d.ts.map +0 -1
  250. package/esm/adb/index.js +0 -4
  251. package/esm/adb/index.js.map +0 -1
  252. package/esm/adb/options/1_16.d.ts +0 -8
  253. package/esm/adb/options/1_16.d.ts.map +0 -1
  254. package/esm/adb/options/1_16.js +0 -20
  255. package/esm/adb/options/1_16.js.map +0 -1
  256. package/esm/adb/options/1_22.d.ts +0 -8
  257. package/esm/adb/options/1_22.d.ts.map +0 -1
  258. package/esm/adb/options/1_22.js +0 -17
  259. package/esm/adb/options/1_22.js.map +0 -1
  260. package/esm/adb/options/index.d.ts +0 -4
  261. package/esm/adb/options/index.d.ts.map +0 -1
  262. package/esm/adb/options/index.js +0 -4
  263. package/esm/adb/options/index.js.map +0 -1
  264. package/esm/adb/options/types.d.ts +0 -24
  265. package/esm/adb/options/types.d.ts.map +0 -1
  266. package/esm/adb/options/types.js +0 -37
  267. package/esm/adb/options/types.js.map +0 -1
  268. package/esm/codec.d.ts +0 -34
  269. package/esm/codec.d.ts.map +0 -1
  270. package/esm/codec.js +0 -37
  271. package/esm/codec.js.map +0 -1
  272. package/esm/options/1_16/h264-configuration.d.ts +0 -49
  273. package/esm/options/1_16/h264-configuration.d.ts.map +0 -1
  274. package/esm/options/1_16/h264-configuration.js +0 -414
  275. package/esm/options/1_16/h264-configuration.js.map +0 -1
  276. package/esm/options/1_16/sps.d.ts +0 -22
  277. package/esm/options/1_16/sps.d.ts.map +0 -1
  278. package/esm/options/1_16/sps.js +0 -263
  279. package/esm/options/1_16/sps.js.map +0 -1
  280. package/src/adb/client.ts +0 -345
  281. package/src/adb/connection.ts +0 -192
  282. package/src/adb/index.ts +0 -3
  283. package/src/adb/options/1_16.ts +0 -30
  284. package/src/adb/options/1_22.ts +0 -26
  285. package/src/adb/options/index.ts +0 -3
  286. package/src/adb/options/types.ts +0 -75
  287. package/src/codec.ts +0 -35
  288. package/src/options/1_16/h264-configuration.ts +0 -485
@@ -0,0 +1,4 @@
1
+ export * from "./av1.js";
2
+ export * from "./h264.js";
3
+ export * from "./h265.js";
4
+ export * from "./nalu.js";
@@ -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,4 +1,4 @@
1
- import { type ScrcpyBackOrScreenOnControlMessage1_18 } from "../index.js";
1
+ import type { ScrcpyBackOrScreenOnControlMessage1_18 } from "../options/index.js";
2
2
 
3
3
  export type ScrcpyBackOrScreenOnControlMessage =
4
4
  ScrcpyBackOrScreenOnControlMessage1_18;
@@ -0,0 +1,3 @@
1
+ import { Struct } from "@yume-chan/struct";
2
+
3
+ export const BasicControlMessage = new Struct().uint8("type");
@@ -1,7 +1,5 @@
1
- import {
2
- AndroidMotionEventAction,
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
  /**
@@ -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://github.com/Genymobile/scrcpy/blob/cabb102a04153f9c237b18257d3269a058558c63/app/src/android/keycodes.h#L26
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
- Home = 3,
13
- Back = 4,
14
-
15
- DPadUp = 19,
16
- DPadDown,
17
- DPadLeft,
18
- DPadRight,
19
-
20
- VolumeUp = 24,
21
- VolumeDown,
22
-
23
- A = 29,
24
- B,
25
- C,
26
- D,
27
- E,
28
- F,
29
- G,
30
- H,
31
- I,
32
- J,
33
- K,
34
- L,
35
- M,
36
- N,
37
- O,
38
- P,
39
- Q,
40
- R,
41
- S,
42
- T,
43
- U,
44
- V,
45
- W,
46
- X,
47
- Y,
48
- Z,
49
-
50
- Tab = 61,
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
- Enter = 66,
53
- Delete,
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
- ForwardDelete,
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
- MoveHome = 122,
58
- MoveEnd = 123,
199
+ VolumeMute = 164, // Name not verified
200
+ AndroidAppSwitch = 187,
59
201
 
60
- VolumeMute = 164,
61
- AppSwitch = 187,
202
+ AndroidCut = 277,
203
+ AndroidCopy,
204
+ AndroidPaste,
62
205
  }
63
206
 
64
207
  export const ScrcpyInjectKeyCodeControlMessage = new Struct()
65
- .uint8("type", ScrcpyControlMessageType.InjectKeyCode as const)
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,4 +1,4 @@
1
- import { type ScrcpyInjectScrollControlMessage1_25 } from "../options/index.js";
1
+ import type { ScrcpyInjectScrollControlMessage1_25 } from "../options/index.js";
2
2
 
3
3
  export type ScrcpyInjectScrollControlMessage =
4
4
  ScrcpyInjectScrollControlMessage1_25;
@@ -1,12 +1,9 @@
1
- import Struct from '@yume-chan/struct';
1
+ import Struct from "@yume-chan/struct";
2
2
 
3
- import { ScrcpyControlMessageType } from './type.js';
4
-
5
- export const ScrcpyInjectTextControlMessage =
6
- new Struct()
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['TInit'];
9
+ (typeof ScrcpyInjectTextControlMessage)["TInit"];