@appium/media-proxy 0.0.0-stage → 1.1.0

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 (123) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +201 -0
  3. package/README.md +184 -2
  4. package/THIRD_PARTY_NOTICES.md +29 -0
  5. package/binding.gyp +90 -0
  6. package/lib/src/background.d.ts +5 -0
  7. package/lib/src/background.d.ts.map +1 -0
  8. package/lib/src/background.js +16 -0
  9. package/lib/src/background.js.map +1 -0
  10. package/lib/src/capabilities.d.ts +9 -0
  11. package/lib/src/capabilities.d.ts.map +1 -0
  12. package/lib/src/capabilities.js +11 -0
  13. package/lib/src/capabilities.js.map +1 -0
  14. package/lib/src/errors.d.ts +26 -0
  15. package/lib/src/errors.d.ts.map +1 -0
  16. package/lib/src/errors.js +40 -0
  17. package/lib/src/errors.js.map +1 -0
  18. package/lib/src/framing/apst.d.ts +43 -0
  19. package/lib/src/framing/apst.d.ts.map +1 -0
  20. package/lib/src/framing/apst.js +126 -0
  21. package/lib/src/framing/apst.js.map +1 -0
  22. package/lib/src/framing/mjpeg-http.d.ts +30 -0
  23. package/lib/src/framing/mjpeg-http.d.ts.map +1 -0
  24. package/lib/src/framing/mjpeg-http.js +148 -0
  25. package/lib/src/framing/mjpeg-http.js.map +1 -0
  26. package/lib/src/framing/mjpeg-multipart.d.ts +11 -0
  27. package/lib/src/framing/mjpeg-multipart.d.ts.map +1 -0
  28. package/lib/src/framing/mjpeg-multipart.js +26 -0
  29. package/lib/src/framing/mjpeg-multipart.js.map +1 -0
  30. package/lib/src/index.d.ts +10 -0
  31. package/lib/src/index.d.ts.map +1 -0
  32. package/lib/src/index.js +7 -0
  33. package/lib/src/index.js.map +1 -0
  34. package/lib/src/native.d.ts +12 -0
  35. package/lib/src/native.d.ts.map +1 -0
  36. package/lib/src/native.js +36 -0
  37. package/lib/src/native.js.map +1 -0
  38. package/lib/src/pkg-root.d.ts +6 -0
  39. package/lib/src/pkg-root.d.ts.map +1 -0
  40. package/lib/src/pkg-root.js +12 -0
  41. package/lib/src/pkg-root.js.map +1 -0
  42. package/lib/src/queue.d.ts +34 -0
  43. package/lib/src/queue.d.ts.map +1 -0
  44. package/lib/src/queue.js +123 -0
  45. package/lib/src/queue.js.map +1 -0
  46. package/lib/src/transcoder.d.ts +81 -0
  47. package/lib/src/transcoder.d.ts.map +1 -0
  48. package/lib/src/transcoder.js +422 -0
  49. package/lib/src/transcoder.js.map +1 -0
  50. package/lib/src/types.d.ts +147 -0
  51. package/lib/src/types.d.ts.map +1 -0
  52. package/lib/src/types.js +2 -0
  53. package/lib/src/types.js.map +1 -0
  54. package/package.json +65 -4
  55. package/prebuilds/darwin-arm64/@appium+media-proxy.node +0 -0
  56. package/prebuilds/darwin-arm64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
  57. package/prebuilds/darwin-arm64/ffmpeg-build-info.txt +3 -0
  58. package/prebuilds/darwin-arm64/libavcodec-appium.62.dylib +0 -0
  59. package/prebuilds/darwin-arm64/libavutil-appium.60.dylib +0 -0
  60. package/prebuilds/darwin-arm64/libswscale-appium.9.dylib +0 -0
  61. package/prebuilds/darwin-x64/@appium+media-proxy.node +0 -0
  62. package/prebuilds/darwin-x64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
  63. package/prebuilds/darwin-x64/ffmpeg-build-info.txt +3 -0
  64. package/prebuilds/darwin-x64/libavcodec-appium.62.dylib +0 -0
  65. package/prebuilds/darwin-x64/libavutil-appium.60.dylib +0 -0
  66. package/prebuilds/darwin-x64/libswscale-appium.9.dylib +0 -0
  67. package/prebuilds/linux-arm64/@appium+media-proxy.node +0 -0
  68. package/prebuilds/linux-arm64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
  69. package/prebuilds/linux-arm64/ffmpeg-build-info.txt +3 -0
  70. package/prebuilds/linux-arm64/libavcodec-appium.so.62 +0 -0
  71. package/prebuilds/linux-arm64/libavutil-appium.so.60 +0 -0
  72. package/prebuilds/linux-arm64/libswscale-appium.so.9 +0 -0
  73. package/prebuilds/linux-x64/@appium+media-proxy.node +0 -0
  74. package/prebuilds/linux-x64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
  75. package/prebuilds/linux-x64/ffmpeg-build-info.txt +3 -0
  76. package/prebuilds/linux-x64/libavcodec-appium.so.62 +0 -0
  77. package/prebuilds/linux-x64/libavutil-appium.so.60 +0 -0
  78. package/prebuilds/linux-x64/libswscale-appium.so.9 +0 -0
  79. package/prebuilds/win32-arm64/@appium+media-proxy.node +0 -0
  80. package/prebuilds/win32-arm64/avcodec-appium-62.dll +0 -0
  81. package/prebuilds/win32-arm64/avutil-appium-60.dll +0 -0
  82. package/prebuilds/win32-arm64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
  83. package/prebuilds/win32-arm64/ffmpeg-build-info.txt +3 -0
  84. package/prebuilds/win32-arm64/swscale-appium-9.dll +0 -0
  85. package/prebuilds/win32-x64/@appium+media-proxy.node +0 -0
  86. package/prebuilds/win32-x64/avcodec-appium-62.dll +0 -0
  87. package/prebuilds/win32-x64/avutil-appium-60.dll +0 -0
  88. package/prebuilds/win32-x64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
  89. package/prebuilds/win32-x64/ffmpeg-build-info.txt +3 -0
  90. package/prebuilds/win32-x64/swscale-appium-9.dll +0 -0
  91. package/scripts/install.mjs +29 -0
  92. package/src/background.ts +15 -0
  93. package/src/capabilities.ts +12 -0
  94. package/src/errors.ts +45 -0
  95. package/src/framing/apst.ts +158 -0
  96. package/src/framing/mjpeg-http.ts +186 -0
  97. package/src/framing/mjpeg-multipart.ts +38 -0
  98. package/src/index.ts +43 -0
  99. package/src/native/addon.cc +402 -0
  100. package/src/native/audio_pipeline.cc +426 -0
  101. package/src/native/audio_pipeline.h +63 -0
  102. package/src/native/ffmpeg_util.h +37 -0
  103. package/src/native/h264_encoder.cc +133 -0
  104. package/src/native/h264_encoder.h +48 -0
  105. package/src/native/mediafoundation_encoder.cc +442 -0
  106. package/src/native/mediafoundation_encoder.h +14 -0
  107. package/src/native/napi_util.h +20 -0
  108. package/src/native/openh264_encoder.cc +285 -0
  109. package/src/native/openh264_encoder.h +14 -0
  110. package/src/native/pipeline.cc +555 -0
  111. package/src/native/pipeline.h +108 -0
  112. package/src/native/vendor/openh264/LICENSE +23 -0
  113. package/src/native/vendor/openh264/codec_api.h +592 -0
  114. package/src/native/vendor/openh264/codec_app_def.h +820 -0
  115. package/src/native/vendor/openh264/codec_def.h +216 -0
  116. package/src/native/vendor/openh264/codec_ver.h +15 -0
  117. package/src/native/videotoolbox_encoder.cc +314 -0
  118. package/src/native/videotoolbox_encoder.h +13 -0
  119. package/src/native.ts +51 -0
  120. package/src/pkg-root.ts +14 -0
  121. package/src/queue.ts +133 -0
  122. package/src/transcoder.ts +480 -0
  123. package/src/types.ts +158 -0
package/src/types.ts ADDED
@@ -0,0 +1,158 @@
1
+ /**
2
+ * One native HEVC access unit as produced by `appium-ios-remotexpc`'s `ScreenStreamCapture`
3
+ * (structural, so this package has no dependency on it): bare NAL units, no start codes.
4
+ */
5
+ export interface NalAccessUnit {
6
+ nals: Buffer[];
7
+ isKeyFrame: boolean;
8
+ /** Raw 32-bit RTP media-clock timestamp (24 kHz on the device, see `videoClockRate`). */
9
+ timestamp: number;
10
+ /** `performance.now()` when the unit arrived; aligns video with audio. Defaults to the push time. */
11
+ receivedAt?: number;
12
+ }
13
+
14
+ /**
15
+ * One native AAC-ELD access unit as produced by `appium-ios-remotexpc`'s `AudioStreamCapture`
16
+ * (structural): 480 samples (10 ms) of 48 kHz stereo.
17
+ */
18
+ export interface AudioAccessUnit {
19
+ data: Buffer;
20
+ /** Raw 32-bit RTP media-clock timestamp (48 kHz). */
21
+ timestamp: number;
22
+ /** `performance.now()` when the unit arrived; aligns audio with video. Defaults to the push time. */
23
+ receivedAt?: number;
24
+ }
25
+
26
+ /** Mirrors coresim's `VideoStreamOptions` (minus `displayId`/`codec`/`audio`). */
27
+ export interface VideoStreamOptions {
28
+ /**
29
+ * Max frames/sec — the input is variable-rate, so this is an upper bound, not a guarantee.
30
+ * Must be a finite number >= 1. Defaults to 60.
31
+ */
32
+ fps?: number;
33
+ /** Target average bitrate, in bits/sec. Defaults to 4,000,000 (4 Mbps). */
34
+ bitrate?: number;
35
+ }
36
+
37
+ /** Mirrors coresim's `JpegStreamOptions` (minus `displayId`). */
38
+ export interface JpegStreamOptions {
39
+ /** Max frames/sec; must be a finite number >= 1. Defaults to 60. */
40
+ fps?: number;
41
+ /** JPEG quality as a percentage, 0 (smallest) to 100 (largest). Defaults to 80. */
42
+ quality?: number;
43
+ /** Frame scale as a percentage of the source, greater than 0 and at most 100. Defaults to 100. */
44
+ scale?: number;
45
+ }
46
+
47
+ /** Input-side options shared by both outputs (not part of coresim's, which has no RTP input). */
48
+ export interface InputOptions {
49
+ /**
50
+ * Clock rate in Hz of the RTP timestamps in the pushed `NalAccessUnit`s. Defaults to 24,000, which is what the
51
+ * device's screen stream uses (400 ticks per frame at 60 fps).
52
+ */
53
+ videoClockRate?: number;
54
+ /**
55
+ * The visible part of the decoded picture, in pixels, taken from its top-left corner; the whole picture by
56
+ * default. The device pads its stream to a multiple of 16 with black (1632x2176 for a 1620x2160 display), so
57
+ * pass the display's size from CoreDevice's `getDisplayInfo()`. Both sides must be positive even integers.
58
+ */
59
+ crop?: {width: number; height: number};
60
+ /**
61
+ * Clockwise degrees (0, 90, 180 or 270) that make the decoded picture upright, 0 by default. The device
62
+ * always streams the display's native orientation, so a landscape UI arrives turned. Change it while
63
+ * streaming with `Transcoder.setRotation()`.
64
+ */
65
+ rotation?: Rotation;
66
+ }
67
+
68
+ /** Clockwise degrees that make a picture upright. */
69
+ export type Rotation = 0 | 90 | 180 | 270;
70
+
71
+ export interface H264Options extends VideoStreamOptions, InputOptions {
72
+ codec: 'h264';
73
+ /**
74
+ * Also transcode the device audio (AAC-ELD, fed through `pushAudio()` or the `audioSource` of
75
+ * `transcode()`) to ADTS-framed AAC-LC units interleaved into `units()`, like coresim. Defaults to false.
76
+ */
77
+ audio?: boolean;
78
+ /**
79
+ * `AudioSpecificConfig` of the pushed audio. Defaults to the device's stream, which must be given
80
+ * its true 480-sample frame length (remotexpc's `AudioStreamCapture.format.audioSpecificConfig`).
81
+ */
82
+ audioSpecificConfig?: Buffer;
83
+ }
84
+
85
+ export interface MjpegOptions extends JpegStreamOptions, InputOptions {
86
+ codec: 'mjpeg';
87
+ }
88
+
89
+ export type TranscoderOptions = H264Options | MjpegOptions;
90
+
91
+ /**
92
+ * One H.264 unit; same shape as coresim's `VideoAccessUnit` (video track only). Annex-B, 4-byte
93
+ * start codes; a keyframe carries SPS/PPS inline, so it is self-decodable alone.
94
+ */
95
+ export interface VideoAccessUnit {
96
+ track: 'video' | 'audio';
97
+ data: Buffer;
98
+ /** Always true for audio: every ADTS unit decodes on its own. */
99
+ isKeyFrame: boolean;
100
+ /** Monotonically increasing per track, starting at 0. */
101
+ sequence: number;
102
+ /** Microseconds since the stream started, on one clock shared by both tracks. */
103
+ timestampMicros: number;
104
+ }
105
+
106
+ /** One standalone JPEG; same shape as coresim's `JpegFrame`. */
107
+ export interface JpegFrame {
108
+ data: Buffer;
109
+ sequence: number;
110
+ timestampMicros: number;
111
+ }
112
+
113
+ /** Raw unit from the native side, before the JS layer assigns `sequence`. */
114
+ export interface NativeUnit {
115
+ data: Buffer;
116
+ isKeyFrame: boolean;
117
+ timestampMicros: number;
118
+ /** Set on audio units. */
119
+ audio?: boolean;
120
+ }
121
+
122
+ export interface NativeConfig {
123
+ outputCodec: 'h264' | 'mjpeg';
124
+ fps: number;
125
+ bitrate: number;
126
+ quality: number;
127
+ scale: number;
128
+ audio: boolean;
129
+ audioSpecificConfig: Buffer;
130
+ audioBitratePerChannel: number;
131
+ /** 0 keeps the whole picture. */
132
+ cropWidth: number;
133
+ cropHeight: number;
134
+ rotation: Rotation;
135
+ }
136
+
137
+ export interface NativeTranscoderHandle {
138
+ /** Each chunk is one bare HEVC NAL unit (no start code). */
139
+ push(chunks: Buffer[], timestampMicros: number, isKeyFrame: boolean): void;
140
+ /** One AAC-ELD access unit (only with `audio`). */
141
+ pushAudio(data: Buffer, timestampMicros: number): void;
142
+ /** Forces the next H.264 output to be an IDR frame (used to resync after an overflow). */
143
+ requestKeyFrame(): void;
144
+ /** Changes the clockwise rotation that makes the picture upright. */
145
+ setRotation(degrees: Rotation): void;
146
+ /** Flushes pending frames through `onUnit`, releases resources, then resolves (no callbacks after). */
147
+ close(): Promise<void>;
148
+ }
149
+
150
+ export interface NativeModule {
151
+ createTranscoder(
152
+ config: NativeConfig,
153
+ onUnit: (unit: NativeUnit) => void,
154
+ onError: (err: Error) => void,
155
+ ): NativeTranscoderHandle;
156
+ /** Encoders/decoders compiled into this build, e.g. `['h264_videotoolbox', 'mjpeg']`. */
157
+ capabilities(): {decoders: string[]; encoders: string[]};
158
+ }