@yume-chan/scrcpy 0.0.16 → 0.0.18

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 (292) hide show
  1. package/CHANGELOG.json +36 -3
  2. package/CHANGELOG.md +21 -4
  3. package/LICENSE +1 -1
  4. package/README.md +291 -37
  5. package/bin/scrcpy-server +0 -0
  6. package/bin/version.d.ts +1 -1
  7. package/bin/version.js +1 -1
  8. package/esm/adb/client.d.ts +41 -0
  9. package/esm/adb/client.d.ts.map +1 -0
  10. package/esm/adb/client.js +243 -0
  11. package/esm/adb/client.js.map +1 -0
  12. package/esm/adb/connection.d.ts +47 -0
  13. package/esm/adb/connection.d.ts.map +1 -0
  14. package/esm/{connection.js → adb/connection.js} +35 -31
  15. package/esm/adb/connection.js.map +1 -0
  16. package/esm/adb/index.d.ts +4 -0
  17. package/esm/adb/index.d.ts.map +1 -0
  18. package/esm/adb/index.js +4 -0
  19. package/esm/adb/index.js.map +1 -0
  20. package/esm/adb/options/1_16.d.ts +8 -0
  21. package/esm/adb/options/1_16.d.ts.map +1 -0
  22. package/esm/adb/options/1_16.js +20 -0
  23. package/esm/adb/options/1_16.js.map +1 -0
  24. package/esm/adb/options/1_22.d.ts +8 -0
  25. package/esm/adb/options/1_22.d.ts.map +1 -0
  26. package/esm/adb/options/1_22.js +17 -0
  27. package/esm/adb/options/1_22.js.map +1 -0
  28. package/esm/adb/options/index.d.ts +4 -0
  29. package/esm/adb/options/index.d.ts.map +1 -0
  30. package/esm/adb/options/index.js +4 -0
  31. package/esm/adb/options/index.js.map +1 -0
  32. package/esm/adb/options/types.d.ts +24 -0
  33. package/esm/adb/options/types.d.ts.map +1 -0
  34. package/esm/adb/options/types.js +37 -0
  35. package/esm/adb/options/types.js.map +1 -0
  36. package/esm/codec.js +2 -2
  37. package/esm/codec.js.map +1 -1
  38. package/esm/control/back-or-screen-on.d.ts +3 -0
  39. package/esm/control/back-or-screen-on.d.ts.map +1 -0
  40. package/esm/control/back-or-screen-on.js +2 -0
  41. package/esm/control/back-or-screen-on.js.map +1 -0
  42. package/esm/control/hover-helper.d.ts +18 -0
  43. package/esm/control/hover-helper.d.ts.map +1 -0
  44. package/esm/control/hover-helper.js +44 -0
  45. package/esm/control/hover-helper.js.map +1 -0
  46. package/esm/control/index.d.ts +12 -0
  47. package/esm/control/index.d.ts.map +1 -0
  48. package/esm/control/index.js +12 -0
  49. package/esm/control/index.js.map +1 -0
  50. package/esm/control/inject-keycode.d.ts +61 -0
  51. package/esm/control/inject-keycode.d.ts.map +1 -0
  52. package/esm/control/inject-keycode.js +62 -0
  53. package/esm/control/inject-keycode.js.map +1 -0
  54. package/esm/control/inject-scroll.d.ts +3 -0
  55. package/esm/control/inject-scroll.d.ts.map +1 -0
  56. package/esm/control/inject-scroll.js +2 -0
  57. package/esm/control/inject-scroll.js.map +1 -0
  58. package/esm/control/inject-text.d.ts +9 -0
  59. package/esm/control/inject-text.d.ts.map +1 -0
  60. package/esm/control/inject-text.js +7 -0
  61. package/esm/control/inject-text.js.map +1 -0
  62. package/esm/control/inject-touch.d.ts +38 -0
  63. package/esm/control/inject-touch.d.ts.map +1 -0
  64. package/esm/control/inject-touch.js +63 -0
  65. package/esm/control/inject-touch.js.map +1 -0
  66. package/esm/control/rotate-device.d.ts +7 -0
  67. package/esm/control/rotate-device.d.ts.map +1 -0
  68. package/esm/control/rotate-device.js +5 -0
  69. package/esm/control/rotate-device.js.map +1 -0
  70. package/esm/control/serializer.d.ts +34 -0
  71. package/esm/control/serializer.d.ts.map +1 -0
  72. package/esm/control/serializer.js +79 -0
  73. package/esm/control/serializer.js.map +1 -0
  74. package/esm/control/set-clipboard.d.ts +3 -0
  75. package/esm/control/set-clipboard.d.ts.map +1 -0
  76. package/esm/control/set-clipboard.js +2 -0
  77. package/esm/control/set-clipboard.js.map +1 -0
  78. package/esm/control/set-screen-power-mode.d.ts +12 -0
  79. package/esm/control/set-screen-power-mode.d.ts.map +1 -0
  80. package/esm/control/set-screen-power-mode.js +12 -0
  81. package/esm/control/set-screen-power-mode.js.map +1 -0
  82. package/esm/control/type.d.ts +15 -0
  83. package/esm/control/type.d.ts.map +1 -0
  84. package/esm/control/type.js +19 -0
  85. package/esm/control/type.js.map +1 -0
  86. package/esm/device-message/ack-clipboard.d.ts +9 -0
  87. package/esm/device-message/ack-clipboard.d.ts.map +1 -0
  88. package/esm/device-message/ack-clipboard.js +6 -0
  89. package/esm/device-message/ack-clipboard.js.map +1 -0
  90. package/esm/device-message/clipboard.d.ts +10 -0
  91. package/esm/device-message/clipboard.d.ts.map +1 -0
  92. package/esm/device-message/clipboard.js +7 -0
  93. package/esm/device-message/clipboard.js.map +1 -0
  94. package/esm/device-message/index.d.ts +5 -0
  95. package/esm/device-message/index.d.ts.map +1 -0
  96. package/esm/device-message/index.js +5 -0
  97. package/esm/device-message/index.js.map +1 -0
  98. package/esm/device-message/stream.d.ts +8 -0
  99. package/esm/device-message/stream.d.ts.map +1 -0
  100. package/esm/device-message/stream.js +20 -0
  101. package/esm/device-message/stream.js.map +1 -0
  102. package/esm/device-message/type.d.ts +5 -0
  103. package/esm/device-message/type.d.ts.map +1 -0
  104. package/esm/device-message/type.js +7 -0
  105. package/esm/device-message/type.js.map +1 -0
  106. package/esm/index.d.ts +3 -6
  107. package/esm/index.d.ts.map +1 -1
  108. package/esm/index.js +3 -6
  109. package/esm/index.js.map +1 -1
  110. package/esm/options/1_16/codec-options.d.ts +20 -0
  111. package/esm/options/1_16/codec-options.d.ts.map +1 -0
  112. package/esm/options/1_16/codec-options.js +26 -0
  113. package/esm/options/1_16/codec-options.js.map +1 -0
  114. package/esm/options/1_16/h264-configuration.d.ts +49 -0
  115. package/esm/options/1_16/h264-configuration.d.ts.map +1 -0
  116. package/esm/options/1_16/h264-configuration.js +414 -0
  117. package/esm/options/1_16/h264-configuration.js.map +1 -0
  118. package/esm/options/1_16/index.d.ts +4 -110
  119. package/esm/options/1_16/index.d.ts.map +1 -1
  120. package/esm/options/1_16/index.js +4 -226
  121. package/esm/options/1_16/index.js.map +1 -1
  122. package/esm/options/1_16/options.d.ts +94 -0
  123. package/esm/options/1_16/options.d.ts.map +1 -0
  124. package/esm/options/1_16/options.js +190 -0
  125. package/esm/options/1_16/options.js.map +1 -0
  126. package/esm/options/1_16/scroll.d.ts +27 -0
  127. package/esm/options/1_16/scroll.d.ts.map +1 -0
  128. package/esm/options/1_16/scroll.js +56 -0
  129. package/esm/options/1_16/scroll.js.map +1 -0
  130. package/esm/options/1_16/sps.d.ts +1 -1
  131. package/esm/options/1_16/sps.d.ts.map +1 -1
  132. package/esm/options/1_16/sps.js +25 -17
  133. package/esm/options/1_16/sps.js.map +1 -1
  134. package/esm/options/1_18.d.ts +8 -8
  135. package/esm/options/1_18.d.ts.map +1 -1
  136. package/esm/options/1_18.js +7 -7
  137. package/esm/options/1_18.js.map +1 -1
  138. package/esm/options/1_21.d.ts +13 -2
  139. package/esm/options/1_21.d.ts.map +1 -1
  140. package/esm/options/1_21.js +14 -3
  141. package/esm/options/1_21.js.map +1 -1
  142. package/esm/options/1_22/index.d.ts +3 -0
  143. package/esm/options/1_22/index.d.ts.map +1 -0
  144. package/esm/options/1_22/index.js +3 -0
  145. package/esm/options/1_22/index.js.map +1 -0
  146. package/esm/options/1_22/options.d.ts +29 -0
  147. package/esm/options/1_22/options.d.ts.map +1 -0
  148. package/esm/options/1_22/options.js +26 -0
  149. package/esm/options/1_22/options.js.map +1 -0
  150. package/esm/options/1_22/scroll.d.ts +17 -0
  151. package/esm/options/1_22/scroll.d.ts.map +1 -0
  152. package/esm/options/1_22/scroll.js +15 -0
  153. package/esm/options/1_22/scroll.js.map +1 -0
  154. package/esm/options/1_23.d.ts +5 -5
  155. package/esm/options/1_23.d.ts.map +1 -1
  156. package/esm/options/1_23.js +7 -6
  157. package/esm/options/1_23.js.map +1 -1
  158. package/esm/options/1_24.d.ts +1 -1
  159. package/esm/options/1_24.d.ts.map +1 -1
  160. package/esm/options/1_24.js.map +1 -1
  161. package/esm/options/1_25/index.d.ts +3 -0
  162. package/esm/options/1_25/index.d.ts.map +1 -0
  163. package/esm/options/1_25/index.js +3 -0
  164. package/esm/options/1_25/index.js.map +1 -0
  165. package/esm/options/1_25/options.d.ts +6 -0
  166. package/esm/options/1_25/options.d.ts.map +1 -0
  167. package/esm/options/1_25/options.js +8 -0
  168. package/esm/options/1_25/options.js.map +1 -0
  169. package/esm/options/1_25/scroll.d.ts +19 -0
  170. package/esm/options/1_25/scroll.d.ts.map +1 -0
  171. package/esm/options/1_25/scroll.js +33 -0
  172. package/esm/options/1_25/scroll.js.map +1 -0
  173. package/esm/options/index.d.ts +5 -4
  174. package/esm/options/index.d.ts.map +1 -1
  175. package/esm/options/index.js +5 -4
  176. package/esm/options/index.js.map +1 -1
  177. package/esm/options/types.d.ts +47 -0
  178. package/esm/options/types.d.ts.map +1 -0
  179. package/esm/options/types.js +18 -0
  180. package/esm/options/types.js.map +1 -0
  181. package/package.json +32 -25
  182. package/scripts/fetch-server.cjs +19 -9
  183. package/src/adb/client.ts +345 -0
  184. package/src/adb/connection.ts +192 -0
  185. package/src/adb/index.ts +3 -0
  186. package/src/adb/options/1_16.ts +30 -0
  187. package/src/adb/options/1_22.ts +26 -0
  188. package/src/adb/options/index.ts +3 -0
  189. package/src/adb/options/types.ts +75 -0
  190. package/src/control/back-or-screen-on.ts +4 -0
  191. package/src/control/hover-helper.ts +56 -0
  192. package/src/control/index.ts +11 -0
  193. package/src/control/inject-keycode.ts +72 -0
  194. package/src/control/inject-scroll.ts +4 -0
  195. package/src/control/inject-text.ts +12 -0
  196. package/src/control/inject-touch.ts +78 -0
  197. package/src/control/rotate-device.ts +10 -0
  198. package/src/control/serializer.ts +151 -0
  199. package/src/control/set-clipboard.ts +4 -0
  200. package/src/control/set-screen-power-mode.ts +17 -0
  201. package/src/control/type.ts +17 -0
  202. package/src/device-message/ack-clipboard.ts +10 -0
  203. package/src/device-message/clipboard.ts +11 -0
  204. package/src/device-message/index.ts +4 -0
  205. package/src/device-message/stream.ts +29 -0
  206. package/src/device-message/type.ts +5 -0
  207. package/src/index.ts +3 -6
  208. package/src/options/1_16/codec-options.ts +55 -0
  209. package/src/options/1_16/h264-configuration.ts +485 -0
  210. package/src/options/1_16/index.ts +4 -345
  211. package/src/options/1_16/options.ts +339 -0
  212. package/src/options/1_16/scroll.ts +76 -0
  213. package/src/options/1_18.ts +24 -12
  214. package/src/options/1_21.ts +34 -6
  215. package/src/options/1_22/index.ts +2 -0
  216. package/src/options/1_22/options.ts +58 -0
  217. package/src/options/1_22/scroll.ts +26 -0
  218. package/src/options/1_23.ts +33 -19
  219. package/src/options/1_24.ts +3 -2
  220. package/src/options/1_25/index.ts +2 -0
  221. package/src/options/1_25/options.ts +12 -0
  222. package/src/options/1_25/scroll.ts +52 -0
  223. package/src/options/index.ts +5 -4
  224. package/src/options/types.ts +102 -0
  225. package/tsconfig.build.json +3 -0
  226. package/tsconfig.build.tsbuildinfo +1 -0
  227. package/esm/client.d.ts +0 -48
  228. package/esm/client.d.ts.map +0 -1
  229. package/esm/client.js +0 -341
  230. package/esm/client.js.map +0 -1
  231. package/esm/connection.d.ts +0 -37
  232. package/esm/connection.d.ts.map +0 -1
  233. package/esm/connection.js.map +0 -1
  234. package/esm/decoder/index.d.ts +0 -4
  235. package/esm/decoder/index.d.ts.map +0 -1
  236. package/esm/decoder/index.js +0 -4
  237. package/esm/decoder/index.js.map +0 -1
  238. package/esm/decoder/tinyh264/index.d.ts +0 -20
  239. package/esm/decoder/tinyh264/index.d.ts.map +0 -1
  240. package/esm/decoder/tinyh264/index.js +0 -86
  241. package/esm/decoder/tinyh264/index.js.map +0 -1
  242. package/esm/decoder/tinyh264/worker.d.ts +0 -2
  243. package/esm/decoder/tinyh264/worker.d.ts.map +0 -1
  244. package/esm/decoder/tinyh264/worker.js +0 -3
  245. package/esm/decoder/tinyh264/worker.js.map +0 -1
  246. package/esm/decoder/tinyh264/wrapper.d.ts +0 -21
  247. package/esm/decoder/tinyh264/wrapper.d.ts.map +0 -1
  248. package/esm/decoder/tinyh264/wrapper.js +0 -68
  249. package/esm/decoder/tinyh264/wrapper.js.map +0 -1
  250. package/esm/decoder/types.d.ts +0 -28
  251. package/esm/decoder/types.d.ts.map +0 -1
  252. package/esm/decoder/types.js +0 -2
  253. package/esm/decoder/types.js.map +0 -1
  254. package/esm/decoder/web-codecs/index.d.ts +0 -22
  255. package/esm/decoder/web-codecs/index.d.ts.map +0 -1
  256. package/esm/decoder/web-codecs/index.js +0 -81
  257. package/esm/decoder/web-codecs/index.js.map +0 -1
  258. package/esm/message.d.ts +0 -98
  259. package/esm/message.d.ts.map +0 -1
  260. package/esm/message.js +0 -98
  261. package/esm/message.js.map +0 -1
  262. package/esm/options/1_22.d.ts +0 -43
  263. package/esm/options/1_22.d.ts.map +0 -1
  264. package/esm/options/1_22.js +0 -43
  265. package/esm/options/1_22.js.map +0 -1
  266. package/esm/options/common.d.ts +0 -34
  267. package/esm/options/common.d.ts.map +0 -1
  268. package/esm/options/common.js +0 -16
  269. package/esm/options/common.js.map +0 -1
  270. package/esm/push-server.d.ts +0 -6
  271. package/esm/push-server.d.ts.map +0 -1
  272. package/esm/push-server.js +0 -16
  273. package/esm/push-server.js.map +0 -1
  274. package/esm/utils.d.ts +0 -2
  275. package/esm/utils.d.ts.map +0 -1
  276. package/esm/utils.js +0 -6
  277. package/esm/utils.js.map +0 -1
  278. package/src/client.ts +0 -435
  279. package/src/connection.ts +0 -148
  280. package/src/decoder/index.ts +0 -3
  281. package/src/decoder/tinyh264/index.ts +0 -112
  282. package/src/decoder/tinyh264/types.d.ts +0 -137
  283. package/src/decoder/tinyh264/worker.ts +0 -2
  284. package/src/decoder/tinyh264/wrapper.ts +0 -89
  285. package/src/decoder/types.ts +0 -35
  286. package/src/decoder/web-codecs/index.ts +0 -99
  287. package/src/message.ts +0 -113
  288. package/src/options/1_16/sps.ts +0 -300
  289. package/src/options/1_22.ts +0 -78
  290. package/src/options/common.ts +0 -66
  291. package/src/push-server.ts +0 -24
  292. package/src/utils.ts +0 -5
package/src/message.ts DELETED
@@ -1,113 +0,0 @@
1
- import Struct, { placeholder } from '@yume-chan/struct';
2
-
3
- // https://github.com/Genymobile/scrcpy/blob/fa5b2a29e983a46b49531def9cf3d80c40c3de37/app/src/control_msg.h#L23
4
- // For their message bodies, see https://github.com/Genymobile/scrcpy/blob/5c62f3419d252d10cd8c9cbb7c918b358b81f2d0/app/src/control_msg.c#L92
5
- export enum ScrcpyControlMessageType {
6
- InjectKeycode,
7
- InjectText,
8
- InjectTouch,
9
- InjectScroll,
10
- BackOrScreenOn,
11
- ExpandNotificationPanel,
12
- ExpandSettingPanel,
13
- CollapseNotificationPanel,
14
- GetClipboard,
15
- SetClipboard,
16
- SetScreenPowerMode,
17
- RotateDevice,
18
- }
19
-
20
- // https://developer.android.com/reference/android/view/MotionEvent#constants_1
21
- export enum AndroidMotionEventAction {
22
- Down,
23
- Up,
24
- Move,
25
- Cancel,
26
- Outside,
27
- PointerDown,
28
- PointerUp,
29
- HoverMove,
30
- Scroll,
31
- HoverEnter,
32
- HoverExit,
33
- ButtonPress,
34
- ButtonRelease,
35
- }
36
-
37
- export const ScrcpySimpleControlMessage =
38
- new Struct()
39
- .uint8('type');
40
-
41
- export const ScrcpyInjectTouchControlMessage =
42
- new Struct()
43
- .fields(ScrcpySimpleControlMessage)
44
- .uint8('action', placeholder<AndroidMotionEventAction>())
45
- .uint64('pointerId')
46
- .uint32('pointerX')
47
- .uint32('pointerY')
48
- .uint16('screenWidth')
49
- .uint16('screenHeight')
50
- .uint16('pressure')
51
- .uint32('buttons');
52
-
53
- export type ScrcpyInjectTouchControlMessage = typeof ScrcpyInjectTouchControlMessage['TInit'];
54
-
55
- export const ScrcpyInjectTextControlMessage =
56
- new Struct()
57
- .fields(ScrcpySimpleControlMessage)
58
- .uint32('length')
59
- .string('text', { lengthField: 'length' });
60
-
61
- export type ScrcpyInjectTextControlMessage =
62
- typeof ScrcpyInjectTextControlMessage['TInit'];
63
-
64
- export enum AndroidKeyEventAction {
65
- Down = 0,
66
- Up = 1,
67
- }
68
-
69
- export enum AndroidKeyCode {
70
- Home = 3,
71
- Back = 4,
72
- A = 29,
73
- B,
74
- C,
75
- D,
76
- E,
77
- F,
78
- G,
79
- H,
80
- I,
81
- J,
82
- K,
83
- L,
84
- M,
85
- N,
86
- O,
87
- P,
88
- Q,
89
- R,
90
- S,
91
- T,
92
- U,
93
- V,
94
- W,
95
- X,
96
- Y,
97
- Z,
98
- Space = 62,
99
- Enter = 66,
100
- Delete = 67,
101
- AppSwitch = 187,
102
- }
103
-
104
- export const ScrcpyInjectKeyCodeControlMessage =
105
- new Struct()
106
- .fields(ScrcpySimpleControlMessage)
107
- .uint8('action', placeholder<AndroidKeyEventAction>())
108
- .uint32('keyCode')
109
- .uint32('repeat')
110
- .uint32('metaState');
111
-
112
- export type ScrcpyInjectKeyCodeControlMessage =
113
- typeof ScrcpyInjectKeyCodeControlMessage['TInit'];
@@ -1,300 +0,0 @@
1
- // cspell: ignore golomb
2
- // cspell: ignore qpprime
3
-
4
- class BitReader {
5
- private buffer: Uint8Array;
6
-
7
- private bytePosition = 0;
8
-
9
- private bitPosition = 0;
10
-
11
- public constructor(buffer: Uint8Array) {
12
- this.buffer = buffer;
13
- }
14
-
15
- public read(length: number): number {
16
- let result = 0;
17
- for (let i = 0; i < length; i += 1) {
18
- result = (result << 1) | this.next();
19
- }
20
- return result;
21
- }
22
-
23
- public next(): number {
24
- const value = (this.buffer[this.bytePosition]! >> (7 - this.bitPosition)) & 1;
25
- this.bitPosition += 1;
26
- if (this.bitPosition === 8) {
27
- this.bytePosition += 1;
28
- this.bitPosition = 0;
29
- }
30
- return value;
31
- }
32
-
33
- public decodeExponentialGolombNumber(): number {
34
- let length = 0;
35
- while (this.next() === 0) {
36
- length += 1;
37
- }
38
- if (length === 0) {
39
- return 0;
40
- }
41
- return (1 << length | this.read(length)) - 1;
42
- }
43
- }
44
-
45
- function* iterateNalu(buffer: Uint8Array): Generator<Uint8Array> {
46
- // -1 means we haven't found the first start code
47
- let start = -1;
48
- let writeIndex = 0;
49
-
50
- // How many `0x00`s in a row we have counted
51
- let zeroCount = 0;
52
-
53
- let inEmulation = false;
54
-
55
- for (const byte of buffer) {
56
- buffer[writeIndex] = byte;
57
- writeIndex += 1;
58
-
59
- if (inEmulation) {
60
- if (byte > 0x03) {
61
- // `0x00000304` or larger are invalid
62
- throw new Error('Invalid data');
63
- }
64
-
65
- inEmulation = false;
66
- continue;
67
- }
68
-
69
- if (byte == 0x00) {
70
- zeroCount += 1;
71
- continue;
72
- }
73
-
74
- const lastZeroCount = zeroCount;
75
- zeroCount = 0;
76
-
77
- if (start === -1) {
78
- // 0x000001 is the start code
79
- // But it can be preceded by any number of zeros
80
- // So 2 is the minimal
81
- if (lastZeroCount >= 2 && byte === 0x01) {
82
- // Found start of first NAL unit
83
- writeIndex = 0;
84
- start = 0;
85
- continue;
86
- }
87
-
88
- // Not begin with start code
89
- throw new Error('Invalid data');
90
- }
91
-
92
- if (lastZeroCount < 2) {
93
- // zero or one `0x00`s are acceptable
94
- continue;
95
- }
96
-
97
- if (byte === 0x01) {
98
- // Remove all leading `0x00`s and this `0x01`
99
- writeIndex -= lastZeroCount + 1;
100
-
101
- // Found another NAL unit
102
- yield buffer.subarray(start, writeIndex);
103
-
104
- start = writeIndex;
105
- continue;
106
- }
107
-
108
- if (lastZeroCount > 2) {
109
- // Too much `0x00`s
110
- throw new Error('Invalid data');
111
- }
112
-
113
- switch (byte) {
114
- case 0x02:
115
- // Didn't find why, but 7.4.1 NAL unit semantics forbids `0x000002` appearing in NAL units
116
- throw new Error('Invalid data');
117
- case 0x03:
118
- // `0x000003` is the "emulation_prevention_three_byte"
119
- // `0x00000300`, `0x00000301`, `0x00000302` and `0x00000303` represent
120
- // `0x000000`, `0x000001`, `0x000002` and `0x000003` respectively
121
-
122
- // Remove current byte
123
- writeIndex -= 1;
124
-
125
- inEmulation = true;
126
- break;
127
- default:
128
- // `0x000004` or larger are ok
129
- break;
130
- }
131
- }
132
-
133
- if (inEmulation || zeroCount !== 0) {
134
- throw new Error('Invalid data');
135
- }
136
-
137
- yield buffer.subarray(start, writeIndex);
138
- }
139
-
140
- // 7.3.2.1.1 Sequence parameter set data syntax
141
- export function parse_sequence_parameter_set(buffer: ArrayBuffer) {
142
- for (const nalu of iterateNalu(new Uint8Array(buffer))) {
143
- const reader = new BitReader(nalu);
144
- if (reader.next() !== 0) {
145
- throw new Error('Invalid data');
146
- }
147
-
148
- const nal_ref_idc = reader.read(2);
149
- const nal_unit_type = reader.read(5);
150
-
151
- if (nal_unit_type !== 7) {
152
- continue;
153
- }
154
-
155
- if (nal_ref_idc === 0) {
156
- throw new Error('Invalid data');
157
- }
158
-
159
- const profile_idc = reader.read(8);
160
- const constraint_set = reader.read(8);
161
-
162
- const constraint_set_reader = new BitReader(new Uint8Array([constraint_set]));
163
- const constraint_set0_flag = !!constraint_set_reader.next();
164
- const constraint_set1_flag = !!constraint_set_reader.next();
165
- const constraint_set2_flag = !!constraint_set_reader.next();
166
- const constraint_set3_flag = !!constraint_set_reader.next();
167
- const constraint_set4_flag = !!constraint_set_reader.next();
168
- const constraint_set5_flag = !!constraint_set_reader.next();
169
-
170
- // reserved_zero_2bits
171
- if (constraint_set_reader.read(2) !== 0) {
172
- throw new Error('Invalid data');
173
- }
174
-
175
- const level_idc = reader.read(8);
176
- const seq_parameter_set_id = reader.decodeExponentialGolombNumber();
177
-
178
- if (profile_idc === 100 || profile_idc === 110 ||
179
- profile_idc === 122 || profile_idc === 244 || profile_idc === 44 ||
180
- profile_idc === 83 || profile_idc === 86 || profile_idc === 118 ||
181
- profile_idc === 128 || profile_idc === 138 || profile_idc === 139 ||
182
- profile_idc === 134) {
183
- const chroma_format_idc = reader.decodeExponentialGolombNumber();
184
- if (chroma_format_idc === 3) {
185
- // separate_colour_plane_flag
186
- reader.next();
187
- }
188
-
189
- // bit_depth_luma_minus8
190
- reader.decodeExponentialGolombNumber();
191
- // bit_depth_chroma_minus8
192
- reader.decodeExponentialGolombNumber();
193
-
194
- // qpprime_y_zero_transform_bypass_flag
195
- reader.next();
196
-
197
- const seq_scaling_matrix_present_flag = !!reader.next();
198
- if (seq_scaling_matrix_present_flag) {
199
- const seq_scaling_list_present_flag: boolean[] = [];
200
- for (let i = 0; i < ((chroma_format_idc !== 3) ? 8 : 12); i++) {
201
- seq_scaling_list_present_flag[i] = !!reader.next();
202
- if (seq_scaling_list_present_flag[i])
203
- if (i < 6) {
204
- // TODO
205
- // scaling_list( ScalingList4x4[ i ], 16,
206
- // UseDefaultScalingMatrix4x4Flag[ i ])
207
- } else {
208
- // TODO
209
- // scaling_list( ScalingList8x8[ i − 6 ], 64,
210
- // UseDefaultScalingMatrix8x8Flag[ i − 6 ] )
211
- }
212
- }
213
- }
214
- }
215
-
216
- // log2_max_frame_num_minus4
217
- reader.decodeExponentialGolombNumber();
218
- const pic_order_cnt_type = reader.decodeExponentialGolombNumber();
219
- if (pic_order_cnt_type === 0) {
220
- // log2_max_pic_order_cnt_lsb_minus4
221
- reader.decodeExponentialGolombNumber();
222
- } else if (pic_order_cnt_type === 1) {
223
- // delta_pic_order_always_zero_flag
224
- reader.next();
225
- // offset_for_non_ref_pic
226
- reader.decodeExponentialGolombNumber();
227
- // offset_for_top_to_bottom_field
228
- reader.decodeExponentialGolombNumber();
229
- const num_ref_frames_in_pic_order_cnt_cycle = reader.decodeExponentialGolombNumber();
230
- const offset_for_ref_frame: number[] = [];
231
- for (let i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) {
232
- offset_for_ref_frame[i] = reader.decodeExponentialGolombNumber();
233
- }
234
- }
235
-
236
- // max_num_ref_frames
237
- reader.decodeExponentialGolombNumber();
238
- // gaps_in_frame_num_value_allowed_flag
239
- reader.next();
240
- const pic_width_in_mbs_minus1 = reader.decodeExponentialGolombNumber();
241
- const pic_height_in_map_units_minus1 = reader.decodeExponentialGolombNumber();
242
-
243
- const frame_mbs_only_flag = reader.next();
244
- if (!frame_mbs_only_flag) {
245
- // mb_adaptive_frame_field_flag
246
- reader.next();
247
- }
248
-
249
- // direct_8x8_inference_flag
250
- reader.next();
251
-
252
- const frame_cropping_flag = !!reader.next();
253
- let frame_crop_left_offset: number;
254
- let frame_crop_right_offset: number;
255
- let frame_crop_top_offset: number;
256
- let frame_crop_bottom_offset: number;
257
- if (frame_cropping_flag) {
258
- frame_crop_left_offset = reader.decodeExponentialGolombNumber();
259
- frame_crop_right_offset = reader.decodeExponentialGolombNumber();
260
- frame_crop_top_offset = reader.decodeExponentialGolombNumber();
261
- frame_crop_bottom_offset = reader.decodeExponentialGolombNumber();
262
- } else {
263
- frame_crop_left_offset = 0;
264
- frame_crop_right_offset = 0;
265
- frame_crop_top_offset = 0;
266
- frame_crop_bottom_offset = 0;
267
- }
268
-
269
- const vui_parameters_present_flag = !!reader.next();
270
- if (vui_parameters_present_flag) {
271
- // TODO
272
- // vui_parameters( )
273
- }
274
-
275
- return {
276
- profile_idc,
277
- constraint_set,
278
- constraint_set0_flag,
279
- constraint_set1_flag,
280
- constraint_set2_flag,
281
- constraint_set3_flag,
282
- constraint_set4_flag,
283
- constraint_set5_flag,
284
- level_idc,
285
- seq_parameter_set_id,
286
- pic_width_in_mbs_minus1,
287
- pic_height_in_map_units_minus1,
288
- frame_mbs_only_flag,
289
- frame_cropping_flag,
290
- frame_crop_left_offset,
291
- frame_crop_right_offset,
292
- frame_crop_top_offset,
293
- frame_crop_bottom_offset,
294
- };
295
- }
296
-
297
- throw new Error('Invalid data');
298
- }
299
-
300
- export type SequenceParameterSet = ReturnType<typeof parse_sequence_parameter_set>;
@@ -1,78 +0,0 @@
1
- import type { Adb } from "@yume-chan/adb";
2
- import Struct from "@yume-chan/struct";
3
- import { ScrcpyClientForwardConnection, ScrcpyClientReverseConnection, type ScrcpyClientConnection } from "../connection.js";
4
- import { ScrcpyInjectScrollControlMessage1_16 } from "./1_16/index.js";
5
- import { ScrcpyOptions1_21, type ScrcpyOptionsInit1_21 } from "./1_21.js";
6
-
7
- export interface ScrcpyOptionsInit1_22 extends ScrcpyOptionsInit1_21 {
8
- downsizeOnError: boolean;
9
-
10
- /**
11
- * Send device name and size at start of video stream.
12
- *
13
- * @default true
14
- */
15
- sendDeviceMeta: boolean;
16
-
17
- /**
18
- * Send a `0` byte on start of video stream to detect connection issues
19
- *
20
- * @default true
21
- */
22
- sendDummyByte: boolean;
23
-
24
- /**
25
- * Implies `sendDeviceMeta: false`, `sendFrameMeta: false` and `sendDummyByte: false`
26
- *
27
- * @default false
28
- */
29
- rawVideoStream: boolean;
30
- }
31
-
32
- export const ScrcpyInjectScrollControlMessage1_22 =
33
- new Struct()
34
- .fields(ScrcpyInjectScrollControlMessage1_16)
35
- .int32("buttons");
36
-
37
- export type ScrcpyInjectScrollControlMessage1_22 = typeof ScrcpyInjectScrollControlMessage1_22["TInit"];
38
-
39
- export class ScrcpyOptions1_22<T extends ScrcpyOptionsInit1_22 = ScrcpyOptionsInit1_22> extends ScrcpyOptions1_21<T> {
40
- public constructor(init: Partial<ScrcpyOptionsInit1_22>) {
41
- if (init.rawVideoStream) {
42
- // Set implied options for client-side processing
43
- init.sendDeviceMeta = false;
44
- init.sendFrameMeta = false;
45
- init.sendDummyByte = false;
46
- }
47
-
48
- super(init);
49
- }
50
-
51
- protected override getDefaultValue(): T {
52
- return {
53
- ...super.getDefaultValue(),
54
- downsizeOnError: true,
55
- sendDeviceMeta: true,
56
- sendDummyByte: true,
57
- rawVideoStream: false,
58
- };
59
- }
60
-
61
- public override createConnection(device: Adb): ScrcpyClientConnection {
62
- const options = {
63
- ...this.getDefaultValue(),
64
- ...this.value,
65
- };
66
- if (this.value.tunnelForward) {
67
- return new ScrcpyClientForwardConnection(device, options);
68
- } else {
69
- return new ScrcpyClientReverseConnection(device, options);
70
- }
71
- }
72
-
73
- public override serializeInjectScrollControlMessage(
74
- message: ScrcpyInjectScrollControlMessage1_22,
75
- ): Uint8Array {
76
- return ScrcpyInjectScrollControlMessage1_22.serialize(message);
77
- }
78
- }
@@ -1,66 +0,0 @@
1
- import type { Adb, TransformStream } from "@yume-chan/adb";
2
- import type { ScrcpyClientConnection } from "../connection.js";
3
- import type { H264Configuration } from "../decoder/index.js";
4
- import type { ScrcpyControlMessageType } from "../message.js";
5
- import type { ScrcpyBackOrScreenOnEvent1_18 } from "./1_18.js";
6
- import type { ScrcpyInjectScrollControlMessage1_22 } from "./1_22.js";
7
-
8
- export const DEFAULT_SERVER_PATH = '/data/local/tmp/scrcpy-server.jar';
9
-
10
- export interface ScrcpyOptionValue {
11
- toOptionValue(): string | undefined;
12
- }
13
-
14
- export function isScrcpyOptionValue(value: any): value is ScrcpyOptionValue {
15
- return typeof value === 'object' &&
16
- value !== null &&
17
- typeof value.toOptionValue === 'function';
18
- }
19
-
20
- export function toScrcpyOptionValue<T>(value: any, empty: T): string | T {
21
- if (isScrcpyOptionValue(value)) {
22
- value = value.toOptionValue();
23
- }
24
-
25
- if (value === undefined) {
26
- return empty;
27
- }
28
-
29
- return `${value}`;
30
- }
31
-
32
- export interface VideoStreamConfigurationPacket {
33
- type: 'configuration';
34
- data: H264Configuration;
35
- }
36
-
37
- export interface VideoStreamFramePacket {
38
- type: 'frame';
39
- keyframe?: boolean | undefined;
40
- pts?: bigint | undefined;
41
- data: Uint8Array;
42
- }
43
-
44
- export type VideoStreamPacket = VideoStreamConfigurationPacket | VideoStreamFramePacket;
45
-
46
- export interface ScrcpyOptions<T> {
47
- value: Partial<T>;
48
-
49
- formatServerArguments(): string[];
50
-
51
- getOutputEncoderNameRegex(): RegExp;
52
-
53
- createConnection(adb: Adb): ScrcpyClientConnection;
54
-
55
- createVideoStreamTransformer(): TransformStream<Uint8Array, VideoStreamPacket>;
56
-
57
- getControlMessageTypes(): ScrcpyControlMessageType[];
58
-
59
- serializeBackOrScreenOnControlMessage(
60
- message: ScrcpyBackOrScreenOnEvent1_18,
61
- ): Uint8Array | undefined;
62
-
63
- serializeInjectScrollControlMessage(
64
- message: ScrcpyInjectScrollControlMessage1_22,
65
- ): Uint8Array;
66
- }
@@ -1,24 +0,0 @@
1
- import { WrapWritableStream, type Adb, type AdbSync } from "@yume-chan/adb";
2
- import { DEFAULT_SERVER_PATH } from "./options/index.js";
3
-
4
- export interface PushServerOptions {
5
- path?: string;
6
- }
7
-
8
- export function pushServer(
9
- device: Adb,
10
- options: PushServerOptions = {}
11
- ) {
12
- const { path = DEFAULT_SERVER_PATH } = options;
13
-
14
- let sync!: AdbSync;
15
- return new WrapWritableStream<Uint8Array>({
16
- async start() {
17
- sync = await device.sync();
18
- return sync.write(path);
19
- },
20
- async close() {
21
- await sync.dispose();
22
- },
23
- });
24
- }
package/src/utils.ts DELETED
@@ -1,5 +0,0 @@
1
- export function delay(time: number): Promise<void> {
2
- return new Promise(resolve => {
3
- (globalThis as any).setTimeout(resolve, time);
4
- });
5
- }