@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
@@ -0,0 +1,40 @@
1
+ /** Base error for every failure raised by this package. */
2
+ export class MediaProxyError extends Error {
3
+ name = 'MediaProxyError';
4
+ }
5
+ /** The native addon can't be used here (unsupported platform/arch or no matching prebuild). */
6
+ export class MediaProxyUnavailableError extends MediaProxyError {
7
+ platform;
8
+ arch;
9
+ name = 'MediaProxyUnavailableError';
10
+ constructor(message, platform, arch) {
11
+ super(message);
12
+ this.platform = platform;
13
+ this.arch = arch;
14
+ }
15
+ }
16
+ /** No encoder satisfying the request is available (e.g. H.264 with no HW encoder or OpenH264). */
17
+ export class MediaProxyEncoderUnavailableError extends MediaProxyError {
18
+ name = 'MediaProxyEncoderUnavailableError';
19
+ }
20
+ /** An option failed validation. */
21
+ export class MediaProxyOptionError extends MediaProxyError {
22
+ name = 'MediaProxyOptionError';
23
+ }
24
+ /** The stream or a framed payload was malformed (e.g. APST desynchronization). */
25
+ export class MediaProxyProtocolError extends MediaProxyError {
26
+ name = 'MediaProxyProtocolError';
27
+ }
28
+ /** Re-types an error thrown by the native addon by its `name`; others pass through. */
29
+ export function wrapNativeError(err) {
30
+ const e = err instanceof Error ? err : new Error(String(err));
31
+ switch (e.name) {
32
+ case 'MediaProxyEncoderUnavailableError':
33
+ return new MediaProxyEncoderUnavailableError(e.message);
34
+ case 'MediaProxyOptionError':
35
+ return new MediaProxyOptionError(e.message);
36
+ default:
37
+ return e instanceof MediaProxyError ? e : new MediaProxyError(e.message, { cause: e });
38
+ }
39
+ }
40
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxB,IAAI,GAAG,iBAAiB,CAAC;CAC1C;AAED,+FAA+F;AAC/F,MAAM,OAAO,0BAA2B,SAAQ,eAAe;IAK3C;IACA;IALF,IAAI,GAAG,4BAA4B,CAAC;IAEpD,YACE,OAAe,EACC,QAAgB,EAChB,IAAY;QAE5B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,aAAQ,GAAR,QAAQ,CAAQ;QAChB,SAAI,GAAJ,IAAI,CAAQ;IAG9B,CAAC;CACF;AAED,kGAAkG;AAClG,MAAM,OAAO,iCAAkC,SAAQ,eAAe;IACpD,IAAI,GAAG,mCAAmC,CAAC;CAC5D;AAED,mCAAmC;AACnC,MAAM,OAAO,qBAAsB,SAAQ,eAAe;IACxC,IAAI,GAAG,uBAAuB,CAAC;CAChD;AAED,kFAAkF;AAClF,MAAM,OAAO,uBAAwB,SAAQ,eAAe;IAC1C,IAAI,GAAG,yBAAyB,CAAC;CAClD;AAED,uFAAuF;AACvF,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,MAAM,CAAC,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9D,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,mCAAmC;YACtC,OAAO,IAAI,iCAAiC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC1D,KAAK,uBAAuB;YAC1B,OAAO,IAAI,qBAAqB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC9C;YACE,OAAO,CAAC,YAAY,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,OAAO,EAAE,EAAC,KAAK,EAAE,CAAC,EAAC,CAAC,CAAC;IACzF,CAAC;AACH,CAAC"}
@@ -0,0 +1,43 @@
1
+ import type { JpegFrame, VideoAccessUnit } from '../types.js';
2
+ /**
3
+ * APST wire framing, identical to the Android settings app's streaming protocol
4
+ * (`io.appium.settings.streaming.StreamProtocol`), so one client can consume both platforms.
5
+ * 28-byte big-endian header: magic "APST", version, track, flags, reserved, u64 sequence,
6
+ * u64 timestampMicros, u32 payloadLength; then the payload.
7
+ */
8
+ export declare enum ApstTrack {
9
+ Jpeg = 0,
10
+ Video = 1,
11
+ Audio = 2
12
+ }
13
+ export declare const APST_VERSION = 1;
14
+ export declare const APST_HEADER_SIZE = 28;
15
+ export interface ApstFrame {
16
+ track: ApstTrack;
17
+ sequence: number;
18
+ timestampMicros: number;
19
+ data: Buffer;
20
+ isConfig: boolean;
21
+ isKeyFrame: boolean;
22
+ isEndOfStream: boolean;
23
+ }
24
+ /** Returns `[header, payload]` so callers can `socket.write` both without concatenating. */
25
+ export declare function encodeApstFrame(unit: VideoAccessUnit | JpegFrame): [Buffer, Buffer];
26
+ /** Single concatenated buffer variant of {@link encodeApstFrame}. */
27
+ export declare function encodeApstFrameBuffer(unit: VideoAccessUnit | JpegFrame): Buffer;
28
+ export declare function encodeApstEndOfStream(track: ApstTrack, sequence: number, timestampMicros: number): Buffer;
29
+ /**
30
+ * Incremental parser; carries a trailing partial frame across `push` calls. Chunks are queued and
31
+ * the header is parsed once, so a large frame arriving in small chunks is copied once, not per chunk.
32
+ */
33
+ export declare class ApstParser {
34
+ private chunks;
35
+ private size;
36
+ private header;
37
+ /** @throws {MediaProxyProtocolError} on bad magic/version or an implausible payload length. */
38
+ push(chunk: Buffer): Generator<ApstFrame>;
39
+ private parseHeader;
40
+ /** Removes the first `n` queued bytes into one new buffer (a single copy). */
41
+ private take;
42
+ }
43
+ //# sourceMappingURL=apst.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apst.d.ts","sourceRoot":"","sources":["../../../src/framing/apst.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,SAAS,EAAE,eAAe,EAAC,MAAM,aAAa,CAAC;AAE5D;;;;;GAKG;AACH,oBAAY,SAAS;IACnB,IAAI,IAAI;IACR,KAAK,IAAI;IACT,KAAK,IAAI;CACV;AAED,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAQnC,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;CACxB;AAoBD,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,IAAI,EAAE,eAAe,GAAG,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAQnF;AAED,qEAAqE;AACrE,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,eAAe,GAAG,SAAS,GAAG,MAAM,CAE/E;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAEzG;AAUD;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,MAAM,CAA4B;IAE1C,+FAA+F;IAC9F,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC;IA6B1C,OAAO,CAAC,WAAW;IAoBnB,8EAA8E;IAC9E,OAAO,CAAC,IAAI;CAiBb"}
@@ -0,0 +1,126 @@
1
+ import { MediaProxyProtocolError } from '../errors.js';
2
+ /**
3
+ * APST wire framing, identical to the Android settings app's streaming protocol
4
+ * (`io.appium.settings.streaming.StreamProtocol`), so one client can consume both platforms.
5
+ * 28-byte big-endian header: magic "APST", version, track, flags, reserved, u64 sequence,
6
+ * u64 timestampMicros, u32 payloadLength; then the payload.
7
+ */
8
+ export var ApstTrack;
9
+ (function (ApstTrack) {
10
+ ApstTrack[ApstTrack["Jpeg"] = 0] = "Jpeg";
11
+ ApstTrack[ApstTrack["Video"] = 1] = "Video";
12
+ ApstTrack[ApstTrack["Audio"] = 2] = "Audio";
13
+ })(ApstTrack || (ApstTrack = {}));
14
+ export const APST_VERSION = 1;
15
+ export const APST_HEADER_SIZE = 28;
16
+ const MAGIC = Buffer.from('APST', 'ascii');
17
+ const FLAG_CONFIG = 0x01;
18
+ const FLAG_KEYFRAME = 0x02;
19
+ const FLAG_EOS = 0x04;
20
+ /** Sanity bound on a single payload; anything larger means the stream is desynchronized. */
21
+ const MAX_PAYLOAD = 64 * 1024 * 1024;
22
+ function writeHeader(track, flags, sequence, timestampMicros, payloadLength) {
23
+ const header = Buffer.alloc(APST_HEADER_SIZE);
24
+ MAGIC.copy(header, 0);
25
+ header.writeUInt8(APST_VERSION, 4);
26
+ header.writeUInt8(track, 5);
27
+ header.writeUInt8(flags, 6);
28
+ header.writeBigUInt64BE(BigInt(sequence), 8);
29
+ header.writeBigUInt64BE(BigInt(timestampMicros), 16);
30
+ header.writeUInt32BE(payloadLength, 24);
31
+ return header;
32
+ }
33
+ /** Returns `[header, payload]` so callers can `socket.write` both without concatenating. */
34
+ export function encodeApstFrame(unit) {
35
+ const isVideo = 'track' in unit;
36
+ const flags = isVideo && unit.isKeyFrame ? FLAG_KEYFRAME : 0;
37
+ let track = ApstTrack.Jpeg;
38
+ if (isVideo) {
39
+ track = unit.track === 'audio' ? ApstTrack.Audio : ApstTrack.Video;
40
+ }
41
+ return [writeHeader(track, flags, unit.sequence, unit.timestampMicros, unit.data.length), unit.data];
42
+ }
43
+ /** Single concatenated buffer variant of {@link encodeApstFrame}. */
44
+ export function encodeApstFrameBuffer(unit) {
45
+ return Buffer.concat(encodeApstFrame(unit));
46
+ }
47
+ export function encodeApstEndOfStream(track, sequence, timestampMicros) {
48
+ return writeHeader(track, FLAG_EOS, sequence, timestampMicros, 0);
49
+ }
50
+ /**
51
+ * Incremental parser; carries a trailing partial frame across `push` calls. Chunks are queued and
52
+ * the header is parsed once, so a large frame arriving in small chunks is copied once, not per chunk.
53
+ */
54
+ export class ApstParser {
55
+ chunks = [];
56
+ size = 0;
57
+ header;
58
+ /** @throws {MediaProxyProtocolError} on bad magic/version or an implausible payload length. */
59
+ *push(chunk) {
60
+ if (chunk.length > 0) {
61
+ this.chunks.push(chunk);
62
+ this.size += chunk.length;
63
+ }
64
+ for (;;) {
65
+ if (!this.header) {
66
+ if (this.size < APST_HEADER_SIZE) {
67
+ return;
68
+ }
69
+ this.header = this.parseHeader(this.take(APST_HEADER_SIZE));
70
+ }
71
+ if (this.size < this.header.payloadLength) {
72
+ return;
73
+ }
74
+ const { track, flags, sequence, timestampMicros, payloadLength } = this.header;
75
+ this.header = undefined;
76
+ yield {
77
+ track,
78
+ sequence,
79
+ timestampMicros,
80
+ data: this.take(payloadLength),
81
+ isConfig: (flags & FLAG_CONFIG) !== 0,
82
+ isKeyFrame: (flags & FLAG_KEYFRAME) !== 0,
83
+ isEndOfStream: (flags & FLAG_EOS) !== 0,
84
+ };
85
+ }
86
+ }
87
+ parseHeader(buf) {
88
+ if (!buf.subarray(0, 4).equals(MAGIC)) {
89
+ throw new MediaProxyProtocolError('Stream desynchronized: unexpected APST magic bytes');
90
+ }
91
+ if (buf.readUInt8(4) !== APST_VERSION) {
92
+ throw new MediaProxyProtocolError(`Unsupported APST version ${buf.readUInt8(4)}`);
93
+ }
94
+ const payloadLength = buf.readUInt32BE(24);
95
+ if (payloadLength > MAX_PAYLOAD) {
96
+ throw new MediaProxyProtocolError(`Implausible APST payload length ${payloadLength}`);
97
+ }
98
+ return {
99
+ track: buf.readUInt8(5),
100
+ flags: buf.readUInt8(6),
101
+ sequence: Number(buf.readBigUInt64BE(8)),
102
+ timestampMicros: Number(buf.readBigUInt64BE(16)),
103
+ payloadLength,
104
+ };
105
+ }
106
+ /** Removes the first `n` queued bytes into one new buffer (a single copy). */
107
+ take(n) {
108
+ const out = Buffer.allocUnsafe(n);
109
+ let offset = 0;
110
+ while (offset < n) {
111
+ const head = this.chunks[0];
112
+ const count = Math.min(head.length, n - offset);
113
+ head.copy(out, offset, 0, count);
114
+ offset += count;
115
+ if (count === head.length) {
116
+ this.chunks.shift();
117
+ }
118
+ else {
119
+ this.chunks[0] = head.subarray(count);
120
+ }
121
+ }
122
+ this.size -= n;
123
+ return out;
124
+ }
125
+ }
126
+ //# sourceMappingURL=apst.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apst.js","sourceRoot":"","sources":["../../../src/framing/apst.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,cAAc,CAAC;AAGrD;;;;;GAKG;AACH,MAAM,CAAN,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,yCAAQ,CAAA;IACR,2CAAS,CAAA;IACT,2CAAS,CAAA;AACX,CAAC,EAJW,SAAS,KAAT,SAAS,QAIpB;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAC9B,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AACnC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3C,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,aAAa,GAAG,IAAI,CAA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AAE,CAAC,CAAC;YAChD,aAAa;SACd,CAAC;IACJ,CAAC;IAED,8EAA8E;IACtE,IAAI,CAAC,CAAS;QACpB,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAClC,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,OAAO,MAAM,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC;YAChD,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC;YAChB,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;gBAC1B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;QACD,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;QACf,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
@@ -0,0 +1,30 @@
1
+ import type { JpegFrame } from '../types.js';
2
+ export interface MjpegServerOptions {
3
+ /** Defaults to 127.0.0.1. */
4
+ host?: string;
5
+ /** 0 (default) picks a free port. */
6
+ port?: number;
7
+ /** 1-70 chars of `[0-9A-Za-z'+_.-]`; invalid values throw `MediaProxyOptionError`. */
8
+ boundary?: string;
9
+ }
10
+ export interface MjpegServer {
11
+ readonly port: number;
12
+ readonly host: string;
13
+ /** URL clients (browsers, `<img>`, ffplay) can open. */
14
+ readonly url: string;
15
+ readonly clientCount: number;
16
+ /**
17
+ * Settles when the frame source ends (resolves) or fails (rejects with its error), or resolves
18
+ * on {@link close}. Already handled internally, so ignoring it never raises an unhandled rejection.
19
+ */
20
+ readonly done: Promise<void>;
21
+ close(): Promise<void>;
22
+ }
23
+ /**
24
+ * Serves `frames` as an MJPEG `multipart/x-mixed-replace` stream to any number of HTTP clients.
25
+ * Each client keeps only the newest unsent frame: a slow client skips frames (every JPEG is
26
+ * independently decodable) rather than building a backlog or stalling the others. Once the source
27
+ * has ended or failed, new requests get `410 Gone`.
28
+ */
29
+ export declare function serveMjpeg(frames: AsyncIterable<JpegFrame>, opts?: MjpegServerOptions): Promise<MjpegServer>;
30
+ //# sourceMappingURL=mjpeg-http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mjpeg-http.d.ts","sourceRoot":"","sources":["../../../src/framing/mjpeg-http.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAQ3C,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sFAAsF;IACtF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wDAAwD;IACxD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC,EAChC,IAAI,GAAE,kBAAuB,GAC5B,OAAO,CAAC,WAAW,CAAC,CA4FtB"}
@@ -0,0 +1,148 @@
1
+ import http from 'node:http';
2
+ import { ignoreRejection, releaseQuietly } from '../background.js';
3
+ import { assertValidMjpegBoundary, DEFAULT_MJPEG_BOUNDARY, formatMjpegPart, mjpegContentType, } from './mjpeg-multipart.js';
4
+ /**
5
+ * Serves `frames` as an MJPEG `multipart/x-mixed-replace` stream to any number of HTTP clients.
6
+ * Each client keeps only the newest unsent frame: a slow client skips frames (every JPEG is
7
+ * independently decodable) rather than building a backlog or stalling the others. Once the source
8
+ * has ended or failed, new requests get `410 Gone`.
9
+ */
10
+ export async function serveMjpeg(frames, opts = {}) {
11
+ const boundary = opts.boundary ?? DEFAULT_MJPEG_BOUNDARY;
12
+ assertValidMjpegBoundary(boundary);
13
+ // Open the source first so a throwing iterator never leaves a listening server behind.
14
+ const iterator = frames[Symbol.asyncIterator]();
15
+ const host = opts.host ?? '127.0.0.1';
16
+ const clients = new Set();
17
+ let sourceDone = false;
18
+ let closing = false;
19
+ const server = http.createServer((req, res) => {
20
+ if (req.method !== 'GET') {
21
+ res.writeHead(405).end();
22
+ return;
23
+ }
24
+ if (sourceDone) {
25
+ res.writeHead(410).end();
26
+ return;
27
+ }
28
+ res.writeHead(200, {
29
+ 'Content-Type': mjpegContentType(boundary),
30
+ 'Cache-Control': 'no-cache, no-store',
31
+ Connection: 'close',
32
+ });
33
+ res.flushHeaders();
34
+ const client = new Client(res, boundary);
35
+ clients.add(client);
36
+ res.on('close', () => clients.delete(client));
37
+ });
38
+ server.on('clientError', (_err, socket) => socket.destroy());
39
+ try {
40
+ await new Promise((resolve, reject) => {
41
+ server.once('error', reject);
42
+ server.listen(opts.port ?? 0, host, () => {
43
+ server.off('error', reject);
44
+ resolve();
45
+ });
46
+ });
47
+ }
48
+ catch (err) {
49
+ releaseQuietly(iterator);
50
+ throw err;
51
+ }
52
+ let signalClosed;
53
+ const closed = new Promise((resolve) => (signalClosed = resolve));
54
+ const pump = (async () => {
55
+ try {
56
+ for (;;) {
57
+ const result = await iterator.next();
58
+ if (result.done || closing) {
59
+ break;
60
+ }
61
+ for (const client of clients) {
62
+ client.offer(result.value);
63
+ }
64
+ }
65
+ }
66
+ finally {
67
+ // Source ended or failed: finish all responses so clients see a clean end.
68
+ sourceDone = true;
69
+ for (const client of clients) {
70
+ client.end();
71
+ }
72
+ }
73
+ })();
74
+ // Either the source settles, or close() was called while it is idle.
75
+ const done = Promise.race([pump, closed]);
76
+ // Surfaced through `done`; these keep an unobserved failure from becoming an unhandled rejection.
77
+ ignoreRejection(pump);
78
+ ignoreRejection(done);
79
+ const { port } = server.address();
80
+ return {
81
+ port,
82
+ host,
83
+ url: `http://${host.includes(':') ? `[${host}]` : host}:${port}/`,
84
+ get clientCount() {
85
+ return clients.size;
86
+ },
87
+ done,
88
+ async close() {
89
+ closing = true;
90
+ sourceDone = true;
91
+ signalClosed();
92
+ // Ask the source to stop; not awaited, as an idle source may not settle until its next item.
93
+ releaseQuietly(iterator);
94
+ for (const client of clients) {
95
+ client.end();
96
+ }
97
+ server.closeAllConnections();
98
+ await new Promise((resolve) => server.close(() => resolve()));
99
+ },
100
+ };
101
+ }
102
+ class Client {
103
+ res;
104
+ boundary;
105
+ pending;
106
+ writing = false;
107
+ constructor(res, boundary) {
108
+ this.res = res;
109
+ this.boundary = boundary;
110
+ }
111
+ offer(frame) {
112
+ this.pending = frame;
113
+ if (!this.writing) {
114
+ this.flush();
115
+ }
116
+ }
117
+ end() {
118
+ this.pending = undefined;
119
+ if (!this.res.writableEnded) {
120
+ this.res.end();
121
+ }
122
+ }
123
+ flush() {
124
+ const frame = this.pending;
125
+ if (!frame || this.res.writableEnded || this.res.destroyed) {
126
+ return;
127
+ }
128
+ this.pending = undefined;
129
+ this.writing = true;
130
+ const [head, body, tail] = formatMjpegPart(frame, this.boundary);
131
+ this.res.cork();
132
+ this.res.write(head);
133
+ this.res.write(body);
134
+ const ok = this.res.write(tail);
135
+ this.res.uncork();
136
+ const done = () => {
137
+ this.writing = false;
138
+ this.flush();
139
+ };
140
+ if (ok) {
141
+ done();
142
+ }
143
+ else {
144
+ this.res.once('drain', done);
145
+ }
146
+ }
147
+ }
148
+ //# sourceMappingURL=mjpeg-http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mjpeg-http.js","sourceRoot":"","sources":["../../../src/framing/mjpeg-http.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,OAAO,EAAC,eAAe,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEjE,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,eAAe,EACf,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAyB9B;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAgC,EAChC,OAA2B,EAAE;IAE7B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,sBAAsB,CAAC;IACzD,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IACnC,uFAAuF;IACvF,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;IAChD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,WAAW,CAAC;IACtC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC5C,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;YACzB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QACD,IAAI,UAAU,EAAE,CAAC;YACf,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QACD,GAAG,CAAC,SAAS,C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AAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrB,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,IAAI,GAAG,GAAG,EAAE;YAChB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC,CAAC;QACF,IAAI,EAAE,EAAE,CAAC;YACP,IAAI,EAAE,CAAC;QACT,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import type { JpegFrame } from '../types.js';
2
+ export declare const DEFAULT_MJPEG_BOUNDARY = "appium-mjpeg-frame";
3
+ /** Throws `MediaProxyOptionError` unless `boundary` is 1-70 chars of `[0-9A-Za-z'+_.-]`. */
4
+ export declare function assertValidMjpegBoundary(boundary: string): void;
5
+ /** `Content-Type` header value for an MJPEG HTTP response using `boundary`. */
6
+ export declare function mjpegContentType(boundary?: string): string;
7
+ /** Header preceding one JPEG in the multipart body. */
8
+ export declare function mjpegPartHeader(frame: JpegFrame, boundary?: string): Buffer;
9
+ /** `[header, jpeg, trailer]` for one multipart part; write them in order without concatenating. */
10
+ export declare function formatMjpegPart(frame: JpegFrame, boundary?: string): [Buffer, Buffer, Buffer];
11
+ //# sourceMappingURL=mjpeg-multipart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mjpeg-multipart.d.ts","sourceRoot":"","sources":["../../../src/framing/mjpeg-multipart.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAE3C,eAAO,MAAM,sBAAsB,uBAAuB,CAAC;AAK3D,4FAA4F;AAC5F,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAM/D;AAED,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAAC,QAAQ,GAAE,MAA+B,GAAG,MAAM,CAGlF;AAED,uDAAuD;AACvD,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,GAAE,MAA+B,GAAG,MAAM,CAMnG;AAID,mGAAmG;AACnG,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,GAAE,MAA+B,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAErH"}
@@ -0,0 +1,26 @@
1
+ import { MediaProxyOptionError } from '../errors.js';
2
+ export const DEFAULT_MJPEG_BOUNDARY = 'appium-mjpeg-frame';
3
+ // Safe in an unquoted `boundary=` parameter (a MIME token) and a valid RFC 2046 delimiter.
4
+ const BOUNDARY_PATTERN = /^[0-9A-Za-z'+_.-]{1,70}$/;
5
+ /** Throws `MediaProxyOptionError` unless `boundary` is 1-70 chars of `[0-9A-Za-z'+_.-]`. */
6
+ export function assertValidMjpegBoundary(boundary) {
7
+ if (typeof boundary !== 'string' || !BOUNDARY_PATTERN.test(boundary)) {
8
+ throw new MediaProxyOptionError(`boundary must be 1-70 characters of [0-9A-Za-z'+_.-], got ${JSON.stringify(boundary)}`);
9
+ }
10
+ }
11
+ /** `Content-Type` header value for an MJPEG HTTP response using `boundary`. */
12
+ export function mjpegContentType(boundary = DEFAULT_MJPEG_BOUNDARY) {
13
+ assertValidMjpegBoundary(boundary);
14
+ return `multipart/x-mixed-replace; boundary=${boundary}`;
15
+ }
16
+ /** Header preceding one JPEG in the multipart body. */
17
+ export function mjpegPartHeader(frame, boundary = DEFAULT_MJPEG_BOUNDARY) {
18
+ assertValidMjpegBoundary(boundary);
19
+ return Buffer.from(`--${boundary}\r\nContent-Type: image/jpeg\r\nContent-Length: ${frame.data.length}\r\n\r\n`, 'ascii');
20
+ }
21
+ const PART_TRAILER = Buffer.from('\r\n', 'ascii');
22
+ /** `[header, jpeg, trailer]` for one multipart part; write them in order without concatenating. */
23
+ export function formatMjpegPart(frame, boundary = DEFAULT_MJPEG_BOUNDARY) {
24
+ return [mjpegPartHeader(frame, boundary), frame.data, PART_TRAILER];
25
+ }
26
+ //# sourceMappingURL=mjpeg-multipart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mjpeg-multipart.js","sourceRoot":"","sources":["../../../src/framing/mjpeg-multipart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAC,MAAM,cAAc,CAAC;AAGnD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAE3D,2FAA2F;AAC3F,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAEpD,4FAA4F;AAC5F,MAAM,UAAU,wBAAwB,CAAC,QAAgB;IACvD,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,qBAAqB,CAC7B,6DAA6D,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CACxF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,gBAAgB,CAAC,WAAmB,sBAAsB;IACxE,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IACnC,OAAO,uCAAuC,QAAQ,EAAE,CAAC;AAC3D,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,eAAe,CAAC,KAAgB,EAAE,WAAmB,sBAAsB;IACzF,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IACnC,OAAO,MAAM,CAAC,IAAI,CAChB,KAAK,QAAQ,mDAAmD,KAAK,CAAC,IAAI,CAAC,MAAM,UAAU,EAC3F,OAAO,CACR,CAAC;AACJ,CAAC;AAED,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD,mGAAmG;AACnG,MAAM,UAAU,eAAe,CAAC,KAAgB,EAAE,WAAmB,sBAAsB;IACzF,OAAO,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AACtE,CAAC"}
@@ -0,0 +1,10 @@
1
+ export { listH264Encoders } from './capabilities.js';
2
+ export { MediaProxyEncoderUnavailableError, MediaProxyError, MediaProxyOptionError, MediaProxyProtocolError, MediaProxyUnavailableError, } from './errors.js';
3
+ export { DEFAULT_BITRATE, DEFAULT_FPS, DEFAULT_QUALITY, DEFAULT_SCALE, Transcoder, createTranscoder, transcode, } from './transcoder.js';
4
+ export { APST_HEADER_SIZE, APST_VERSION, ApstParser, ApstTrack, encodeApstEndOfStream, encodeApstFrame, encodeApstFrameBuffer, } from './framing/apst.js';
5
+ export type { ApstFrame } from './framing/apst.js';
6
+ export { DEFAULT_MJPEG_BOUNDARY, formatMjpegPart, mjpegContentType, mjpegPartHeader } from './framing/mjpeg-multipart.js';
7
+ export { serveMjpeg } from './framing/mjpeg-http.js';
8
+ export type { MjpegServer, MjpegServerOptions } from './framing/mjpeg-http.js';
9
+ export type { AudioAccessUnit, H264Options, InputOptions, JpegFrame, JpegStreamOptions, MjpegOptions, NalAccessUnit, Rotation, TranscoderOptions, VideoAccessUnit, VideoStreamOptions, } from './types.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EACL,iCAAiC,EACjC,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,WAAW,EACX,eAAe,EACf,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,SAAS,EACT,qBAAqB,EACrB,eAAe,EACf,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,sBAAsB,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAC,MAAM,8BAA8B,CAAC;AACxH,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAC;AACnD,YAAY,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,yBAAyB,CAAC;AAC7E,YAAY,EACV,eAAe,EACf,WAAW,EACX,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { listH264Encoders } from './capabilities.js';
2
+ export { MediaProxyEncoderUnavailableError, MediaProxyError, MediaProxyOptionError, MediaProxyProtocolError, MediaProxyUnavailableError, } from './errors.js';
3
+ export { DEFAULT_BITRATE, DEFAULT_FPS, DEFAULT_QUALITY, DEFAULT_SCALE, Transcoder, createTranscoder, transcode, } from './transcoder.js';
4
+ export { APST_HEADER_SIZE, APST_VERSION, ApstParser, ApstTrack, encodeApstEndOfStream, encodeApstFrame, encodeApstFrameBuffer, } from './framing/apst.js';
5
+ export { DEFAULT_MJPEG_BOUNDARY, formatMjpegPart, mjpegContentType, mjpegPartHeader } from './framing/mjpeg-multipart.js';
6
+ export { serveMjpeg } from './framing/mjpeg-http.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EACL,iCAAiC,EACjC,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,WAAW,EACX,eAAe,EACf,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,SAAS,EACT,qBAAqB,EACrB,eAAe,EACf,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAC,sBAAsB,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAC,MAAM,8BAA8B,CAAC;AACxH,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { NativeModule } from './types.js';
2
+ export declare const SUPPORTED_PLATFORMS: readonly ["darwin", "linux", "win32"];
3
+ export declare const SUPPORTED_ARCHS: readonly ["x64", "arm64"];
4
+ /** Throws {@link MediaProxyUnavailableError} unless this platform/arch has a build. */
5
+ export declare function assertSupportedPlatform(platform?: string, arch?: string): void;
6
+ /**
7
+ * Wraps `load` so nothing runs until the first call. A failure is re-typed as
8
+ * {@link MediaProxyUnavailableError} and not cached (retried on the next call); success is cached.
9
+ */
10
+ export declare function createNativeLoader(load: () => unknown): () => NativeModule;
11
+ export declare const loadNative: () => NativeModule;
12
+ //# sourceMappingURL=native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../src/native.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAI7C,eAAO,MAAM,mBAAmB,uCAAwC,CAAC;AACzE,eAAO,MAAM,eAAe,2BAA4B,CAAC;AAEzD,uFAAuF;AACvF,wBAAgB,uBAAuB,CAAC,QAAQ,GAAE,MAAyB,EAAE,IAAI,GAAE,MAAqB,GAAG,IAAI,CAW9G;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,OAAO,GAAG,MAAM,YAAY,CAkB1E;AAGD,eAAO,MAAM,UAAU,QArBwC,YAqB4B,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { createRequire } from 'node:module';
2
+ import { MediaProxyUnavailableError } from './errors.js';
3
+ import { PACKAGE_NAME, getPkgRoot } from './pkg-root.js';
4
+ const require = createRequire(import.meta.url);
5
+ export const SUPPORTED_PLATFORMS = ['darwin', 'linux', 'win32'];
6
+ export const SUPPORTED_ARCHS = ['x64', 'arm64'];
7
+ /** Throws {@link MediaProxyUnavailableError} unless this platform/arch has a build. */
8
+ export function assertSupportedPlatform(platform = process.platform, arch = process.arch) {
9
+ if (!SUPPORTED_PLATFORMS.includes(platform) ||
10
+ !SUPPORTED_ARCHS.includes(arch)) {
11
+ throw new MediaProxyUnavailableError(`${PACKAGE_NAME} supports darwin/linux/win32 on x64/arm64, not ${platform}-${arch}`, platform, arch);
12
+ }
13
+ }
14
+ /**
15
+ * Wraps `load` so nothing runs until the first call. A failure is re-typed as
16
+ * {@link MediaProxyUnavailableError} and not cached (retried on the next call); success is cached.
17
+ */
18
+ export function createNativeLoader(load) {
19
+ let native;
20
+ return () => {
21
+ if (native) {
22
+ return native;
23
+ }
24
+ assertSupportedPlatform();
25
+ try {
26
+ native = load();
27
+ }
28
+ catch (err) {
29
+ throw new MediaProxyUnavailableError(`No usable ${PACKAGE_NAME} addon for ${process.platform}-${process.arch}: ${err.message}`, process.platform, process.arch);
30
+ }
31
+ return native;
32
+ };
33
+ }
34
+ // Never invoked at import or install time, only by the first API call that needs the addon.
35
+ export const loadNative = createNativeLoader(() => require('node-gyp-build')(getPkgRoot()));
36
+ //# sourceMappingURL=native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.js","sourceRoot":"","sources":["../../src/native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,a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ChB,CAAC,CAAC;AACJ,CAAC;AAED,4FAA4F;AAC5F,MAAM,CAAC,MAAM,UAAU,GAAG,kBAAkB,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const PACKAGE_NAME = "@appium/media-proxy";
2
+ /** Package root (contains binding.gyp, prebuilds/, or build/ after compile). */
3
+ export declare const getPkgRoot: (() => string) & {
4
+ cache: Map<unknown, string>;
5
+ };
6
+ //# sourceMappingURL=pkg-root.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pkg-root.d.ts","sourceRoot":"","sources":["../../src/pkg-root.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY,wBAAwB,CAAC;AAElD,gFAAgF;AAChF,eAAO,MAAM,UAAU,SAA2C,MAAM;;CAMtE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { node, util } from '@appium/support';
3
+ export const PACKAGE_NAME = '@appium/media-proxy';
4
+ /** Package root (contains binding.gyp, prebuilds/, or build/ after compile). */
5
+ export const getPkgRoot = util.memoize(function resolvePkgRoot() {
6
+ const root = node.getModuleRootSync(PACKAGE_NAME, fileURLToPath(import.meta.url));
7
+ if (!root) {
8
+ throw new Error(`Could not locate the root of the '${PACKAGE_NAME}' package`);
9
+ }
10
+ return root;
11
+ });
12
+ //# sourceMappingURL=pkg-root.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pkg-root.js","sourceRoot":"","sources":["../../src/pkg-root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,UAAU,CAAC;AAEvC,OAAO,EAAC,IAAI,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAE3C,MAAM,CAAC,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAElD,gFAAgF;AAChF,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,cAAc;IAC5D,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAClF,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,qCAAqC,YAAY,WAAW,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC"}
@@ -0,0 +1,34 @@
1
+ export declare const MAX_BUFFERED_UNITS = 60;
2
+ /**
3
+ * Single-consumer FIFO between the native callback and `units()`. Bounded: on overflow the backlog
4
+ * is cleared (except units `keepOnOverflow` accepts) and, while `dropsDuringResync` says so, further units are discarded until `endsResync`
5
+ * sees a self-decodable one — dropping an arbitrary P-frame would corrupt every later one.
6
+ */
7
+ export declare class UnitQueue<T> {
8
+ private readonly opts;
9
+ private readonly buffer;
10
+ private waiter;
11
+ private ended;
12
+ private draining;
13
+ private error;
14
+ private resyncing;
15
+ constructor(opts: {
16
+ dropsDuringResync: (unit: T) => boolean;
17
+ endsResync: (unit: T) => boolean;
18
+ onOverflow?: () => void;
19
+ keepOnOverflow?: (unit: T) => boolean;
20
+ capacity?: number;
21
+ });
22
+ push(unit: T): void;
23
+ fail(err: unknown): void;
24
+ /**
25
+ * Ends the queue. With `drain`, already buffered units are still delivered before `next()`
26
+ * resolves `done`; otherwise they are discarded (also if called again while draining).
27
+ */
28
+ end(opts?: {
29
+ drain?: boolean;
30
+ }): void;
31
+ /** Resolves `done` if `signal` aborts or the queue has ended; never serves stale units after that. */
32
+ next(signal: AbortSignal): Promise<IteratorResult<T>>;
33
+ }
34
+ //# sourceMappingURL=queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../src/queue.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC;;;;GAIG;AACH,qBAAa,SAAS,CAAC,CAAC;IASpB,OAAO,CAAC,QAAQ,CAAC,IAAI;IARvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAW;IAClC,OAAO,CAAC,MAAM,CAAsF;IACpG,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,SAAS,CAAS;gBAGP,IAAI,EAAE;QACrB,iBAAiB,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;QACxC,UAAU,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;QACjC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;QACxB,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;QACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;IAGH,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAiCnB,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI;IAexB;;;OAGG;IACH,GAAG,CAAC,IAAI,GAAE;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAM,GAAG,IAAI;IAsBvC,sGAAsG;IACtG,IAAI,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;CAgCtD"}