@appium/media-proxy 0.0.1 → 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.
- package/CHANGELOG.md +33 -0
- package/LICENSE +201 -0
- package/README.md +183 -2
- package/THIRD_PARTY_NOTICES.md +29 -0
- package/binding.gyp +90 -0
- package/lib/src/background.d.ts +5 -0
- package/lib/src/background.d.ts.map +1 -0
- package/lib/src/background.js +16 -0
- package/lib/src/background.js.map +1 -0
- package/lib/src/capabilities.d.ts +9 -0
- package/lib/src/capabilities.d.ts.map +1 -0
- package/lib/src/capabilities.js +11 -0
- package/lib/src/capabilities.js.map +1 -0
- package/lib/src/errors.d.ts +26 -0
- package/lib/src/errors.d.ts.map +1 -0
- package/lib/src/errors.js +40 -0
- package/lib/src/errors.js.map +1 -0
- package/lib/src/framing/apst.d.ts +43 -0
- package/lib/src/framing/apst.d.ts.map +1 -0
- package/lib/src/framing/apst.js +126 -0
- package/lib/src/framing/apst.js.map +1 -0
- package/lib/src/framing/mjpeg-http.d.ts +30 -0
- package/lib/src/framing/mjpeg-http.d.ts.map +1 -0
- package/lib/src/framing/mjpeg-http.js +148 -0
- package/lib/src/framing/mjpeg-http.js.map +1 -0
- package/lib/src/framing/mjpeg-multipart.d.ts +11 -0
- package/lib/src/framing/mjpeg-multipart.d.ts.map +1 -0
- package/lib/src/framing/mjpeg-multipart.js +26 -0
- package/lib/src/framing/mjpeg-multipart.js.map +1 -0
- package/lib/src/index.d.ts +10 -0
- package/lib/src/index.d.ts.map +1 -0
- package/lib/src/index.js +7 -0
- package/lib/src/index.js.map +1 -0
- package/lib/src/native.d.ts +12 -0
- package/lib/src/native.d.ts.map +1 -0
- package/lib/src/native.js +36 -0
- package/lib/src/native.js.map +1 -0
- package/lib/src/pkg-root.d.ts +6 -0
- package/lib/src/pkg-root.d.ts.map +1 -0
- package/lib/src/pkg-root.js +12 -0
- package/lib/src/pkg-root.js.map +1 -0
- package/lib/src/queue.d.ts +34 -0
- package/lib/src/queue.d.ts.map +1 -0
- package/lib/src/queue.js +123 -0
- package/lib/src/queue.js.map +1 -0
- package/lib/src/transcoder.d.ts +81 -0
- package/lib/src/transcoder.d.ts.map +1 -0
- package/lib/src/transcoder.js +422 -0
- package/lib/src/transcoder.js.map +1 -0
- package/lib/src/types.d.ts +147 -0
- package/lib/src/types.d.ts.map +1 -0
- package/lib/src/types.js +2 -0
- package/lib/src/types.js.map +1 -0
- package/package.json +53 -4
- package/prebuilds/darwin-arm64/@appium+media-proxy.node +0 -0
- package/prebuilds/darwin-arm64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
- package/prebuilds/darwin-arm64/ffmpeg-build-info.txt +3 -0
- package/prebuilds/darwin-arm64/libavcodec-appium.62.dylib +0 -0
- package/prebuilds/darwin-arm64/libavutil-appium.60.dylib +0 -0
- package/prebuilds/darwin-arm64/libswscale-appium.9.dylib +0 -0
- package/prebuilds/darwin-x64/@appium+media-proxy.node +0 -0
- package/prebuilds/darwin-x64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
- package/prebuilds/darwin-x64/ffmpeg-build-info.txt +3 -0
- package/prebuilds/darwin-x64/libavcodec-appium.62.dylib +0 -0
- package/prebuilds/darwin-x64/libavutil-appium.60.dylib +0 -0
- package/prebuilds/darwin-x64/libswscale-appium.9.dylib +0 -0
- package/prebuilds/linux-arm64/@appium+media-proxy.node +0 -0
- package/prebuilds/linux-arm64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
- package/prebuilds/linux-arm64/ffmpeg-build-info.txt +3 -0
- package/prebuilds/linux-arm64/libavcodec-appium.so.62 +0 -0
- package/prebuilds/linux-arm64/libavutil-appium.so.60 +0 -0
- package/prebuilds/linux-arm64/libswscale-appium.so.9 +0 -0
- package/prebuilds/linux-x64/@appium+media-proxy.node +0 -0
- package/prebuilds/linux-x64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
- package/prebuilds/linux-x64/ffmpeg-build-info.txt +3 -0
- package/prebuilds/linux-x64/libavcodec-appium.so.62 +0 -0
- package/prebuilds/linux-x64/libavutil-appium.so.60 +0 -0
- package/prebuilds/linux-x64/libswscale-appium.so.9 +0 -0
- package/prebuilds/win32-arm64/@appium+media-proxy.node +0 -0
- package/prebuilds/win32-arm64/avcodec-appium-62.dll +0 -0
- package/prebuilds/win32-arm64/avutil-appium-60.dll +0 -0
- package/prebuilds/win32-arm64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
- package/prebuilds/win32-arm64/ffmpeg-build-info.txt +3 -0
- package/prebuilds/win32-arm64/swscale-appium-9.dll +0 -0
- package/prebuilds/win32-x64/@appium+media-proxy.node +0 -0
- package/prebuilds/win32-x64/avcodec-appium-62.dll +0 -0
- package/prebuilds/win32-x64/avutil-appium-60.dll +0 -0
- package/prebuilds/win32-x64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
- package/prebuilds/win32-x64/ffmpeg-build-info.txt +3 -0
- package/prebuilds/win32-x64/swscale-appium-9.dll +0 -0
- package/scripts/install.mjs +29 -0
- package/src/background.ts +15 -0
- package/src/capabilities.ts +12 -0
- package/src/errors.ts +45 -0
- package/src/framing/apst.ts +158 -0
- package/src/framing/mjpeg-http.ts +186 -0
- package/src/framing/mjpeg-multipart.ts +38 -0
- package/src/index.ts +43 -0
- package/src/native/addon.cc +402 -0
- package/src/native/audio_pipeline.cc +426 -0
- package/src/native/audio_pipeline.h +63 -0
- package/src/native/ffmpeg_util.h +37 -0
- package/src/native/h264_encoder.cc +133 -0
- package/src/native/h264_encoder.h +48 -0
- package/src/native/mediafoundation_encoder.cc +442 -0
- package/src/native/mediafoundation_encoder.h +14 -0
- package/src/native/napi_util.h +20 -0
- package/src/native/openh264_encoder.cc +285 -0
- package/src/native/openh264_encoder.h +14 -0
- package/src/native/pipeline.cc +555 -0
- package/src/native/pipeline.h +108 -0
- package/src/native/vendor/openh264/LICENSE +23 -0
- package/src/native/vendor/openh264/codec_api.h +592 -0
- package/src/native/vendor/openh264/codec_app_def.h +820 -0
- package/src/native/vendor/openh264/codec_def.h +216 -0
- package/src/native/vendor/openh264/codec_ver.h +15 -0
- package/src/native/videotoolbox_encoder.cc +314 -0
- package/src/native/videotoolbox_encoder.h +13 -0
- package/src/native.ts +51 -0
- package/src/pkg-root.ts +14 -0
- package/src/queue.ts +133 -0
- package/src/transcoder.ts +480 -0
- package/src/types.ts +158 -0
package/lib/src/queue.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export 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 class UnitQueue {
|
|
8
|
+
opts;
|
|
9
|
+
buffer = [];
|
|
10
|
+
waiter;
|
|
11
|
+
ended = false;
|
|
12
|
+
draining = false;
|
|
13
|
+
error;
|
|
14
|
+
resyncing = false;
|
|
15
|
+
constructor(opts) {
|
|
16
|
+
this.opts = opts;
|
|
17
|
+
}
|
|
18
|
+
push(unit) {
|
|
19
|
+
if (this.ended) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (this.resyncing) {
|
|
23
|
+
if (this.opts.dropsDuringResync(unit)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (this.opts.endsResync(unit)) {
|
|
27
|
+
this.resyncing = false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (this.waiter) {
|
|
31
|
+
const { resolve } = this.waiter;
|
|
32
|
+
this.waiter = undefined;
|
|
33
|
+
resolve({ value: unit, done: false });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.buffer.push(unit);
|
|
37
|
+
const capacity = this.opts.capacity ?? MAX_BUFFERED_UNITS;
|
|
38
|
+
if (this.buffer.length > capacity) {
|
|
39
|
+
const { keepOnOverflow } = this.opts;
|
|
40
|
+
const kept = keepOnOverflow ? this.buffer.filter(keepOnOverflow) : [];
|
|
41
|
+
const dropped = kept.length < this.buffer.length;
|
|
42
|
+
// Kept units alone may still exceed the capacity: drop their oldest.
|
|
43
|
+
this.buffer.splice(0, this.buffer.length, ...kept.slice(-capacity));
|
|
44
|
+
if (dropped) {
|
|
45
|
+
this.resyncing = true;
|
|
46
|
+
this.opts.onOverflow?.();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
fail(err) {
|
|
51
|
+
if (this.ended) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.ended = true;
|
|
55
|
+
this.draining = false;
|
|
56
|
+
this.error = err;
|
|
57
|
+
this.buffer.length = 0;
|
|
58
|
+
if (this.waiter) {
|
|
59
|
+
const { reject } = this.waiter;
|
|
60
|
+
this.waiter = undefined;
|
|
61
|
+
reject(err);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Ends the queue. With `drain`, already buffered units are still delivered before `next()`
|
|
66
|
+
* resolves `done`; otherwise they are discarded (also if called again while draining).
|
|
67
|
+
*/
|
|
68
|
+
end(opts = {}) {
|
|
69
|
+
if (this.ended) {
|
|
70
|
+
// A non-draining end cancels a drain already in progress.
|
|
71
|
+
if (!opts.drain && this.draining) {
|
|
72
|
+
this.draining = false;
|
|
73
|
+
this.buffer.length = 0;
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.ended = true;
|
|
78
|
+
if (opts.drain && this.buffer.length > 0) {
|
|
79
|
+
this.draining = true;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this.buffer.length = 0;
|
|
83
|
+
if (this.waiter) {
|
|
84
|
+
const { resolve } = this.waiter;
|
|
85
|
+
this.waiter = undefined;
|
|
86
|
+
resolve({ value: undefined, done: true });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Resolves `done` if `signal` aborts or the queue has ended; never serves stale units after that. */
|
|
90
|
+
next(signal) {
|
|
91
|
+
if (signal.aborted) {
|
|
92
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
93
|
+
}
|
|
94
|
+
if (this.ended && !this.draining) {
|
|
95
|
+
return this.error ? Promise.reject(this.error) : Promise.resolve({ value: undefined, done: true });
|
|
96
|
+
}
|
|
97
|
+
const buffered = this.buffer.shift();
|
|
98
|
+
if (this.draining && this.buffer.length === 0) {
|
|
99
|
+
this.draining = false;
|
|
100
|
+
}
|
|
101
|
+
if (buffered !== undefined) {
|
|
102
|
+
return Promise.resolve({ value: buffered, done: false });
|
|
103
|
+
}
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
const onAbort = () => {
|
|
106
|
+
this.waiter = undefined;
|
|
107
|
+
resolve({ value: undefined, done: true });
|
|
108
|
+
};
|
|
109
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
110
|
+
this.waiter = {
|
|
111
|
+
resolve: (result) => {
|
|
112
|
+
signal.removeEventListener('abort', onAbort);
|
|
113
|
+
resolve(result);
|
|
114
|
+
},
|
|
115
|
+
reject: (err) => {
|
|
116
|
+
signal.removeEventListener('abort', onAbort);
|
|
117
|
+
reject(err);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../src/queue.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAErC;;;;GAIG;AACH,MAAM,OAAO,SAAS;IASD;IARF,MAAM,GAAQ,EAAE,CAAC;IAC1B,MAAM,CAAsF;IAC5F,KAAK,GAAG,KAAK,CAAC;IACd,QAAQ,GAAG,KAAK,CAAC;IACjB,KAA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OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,OAAO,GAAG,GAAG,EAAE;gBACnB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;gBACxB,OAAO,CAAC,EAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;YAC1C,CAAC,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAC,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;YACxD,IAAI,CAAC,MAAM,GAAG;gBACZ,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE;oBAClB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;oBAC7C,OAAO,CAAC,MAAM,CAAC,CAAC;gBAClB,CAAC;gBACD,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;oBACd,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;oBAC7C,MAAM,CAAC,GAAG,CAAC,CAAC;gBACd,CAAC;aACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { AudioAccessUnit, H264Options, JpegFrame, MjpegOptions, NalAccessUnit, NativeConfig, Rotation, TranscoderOptions, VideoAccessUnit } from './types.js';
|
|
2
|
+
export declare const DEFAULT_FPS = 60;
|
|
3
|
+
export declare const DEFAULT_BITRATE = 4000000;
|
|
4
|
+
export declare const DEFAULT_QUALITY = 80;
|
|
5
|
+
export declare const DEFAULT_SCALE = 100;
|
|
6
|
+
/** AAC-ELD, 48 kHz stereo, 480-sample frames: the device's stream as it really is (remotexpc `aac-eld.ts`). */
|
|
7
|
+
export declare const DEFAULT_AUDIO_SPECIFIC_CONFIG: Buffer<ArrayBuffer>;
|
|
8
|
+
/** Validates `opts` and fills in the defaults, with the same rules and error type as coresim. */
|
|
9
|
+
export declare function resolveOptions(opts: TranscoderOptions): NativeConfig;
|
|
10
|
+
/** Converts 32-bit RTP timestamps to microseconds since the first unit, unwrapping the counter. */
|
|
11
|
+
export declare class TimestampConverter {
|
|
12
|
+
private readonly clockRate;
|
|
13
|
+
private base;
|
|
14
|
+
private last;
|
|
15
|
+
private ticks;
|
|
16
|
+
constructor(clockRate?: number);
|
|
17
|
+
toMicros(timestamp: number): number;
|
|
18
|
+
}
|
|
19
|
+
type OutputUnit = VideoAccessUnit | JpegFrame;
|
|
20
|
+
/** A running transcoder. Single `units()` consumer at a time. */
|
|
21
|
+
export declare class Transcoder<U extends OutputUnit = OutputUnit> {
|
|
22
|
+
private readonly handle;
|
|
23
|
+
private readonly queue;
|
|
24
|
+
private readonly clock;
|
|
25
|
+
private readonly audioClock;
|
|
26
|
+
private readonly isVideo;
|
|
27
|
+
private readonly hasAudio;
|
|
28
|
+
private readonly stopController;
|
|
29
|
+
private sequence;
|
|
30
|
+
private audioSequence;
|
|
31
|
+
private originMs;
|
|
32
|
+
private videoOffset;
|
|
33
|
+
private audioOffset;
|
|
34
|
+
private closePromise;
|
|
35
|
+
private consuming;
|
|
36
|
+
/** Feeds one access unit (non-blocking; the native side queues and may drop to the next keyframe). */
|
|
37
|
+
push(au: NalAccessUnit): void;
|
|
38
|
+
/** Feeds one AAC-ELD access unit; needs `audio: true`. Timestamps are aligned with the video by arrival time. */
|
|
39
|
+
pushAudio(au: AudioAccessUnit): void;
|
|
40
|
+
/**
|
|
41
|
+
* Makes the next H.264 output a keyframe, e.g. for a consumer that joined a running stream. Takes
|
|
42
|
+
* effect with the next input unit, so it needs the source to keep sending. Requests made before that unit
|
|
43
|
+
* are one request (the native side only sets a flag), but each later one forces another keyframe, so
|
|
44
|
+
* callers that serve several consumers should coalesce them. A no-op for MJPEG (every frame is standalone)
|
|
45
|
+
* and after {@link end}/{@link close}.
|
|
46
|
+
*/
|
|
47
|
+
requestKeyFrame(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Changes the clockwise rotation that makes the picture upright, while streaming. The next frame is turned
|
|
50
|
+
* and, since the output changes shape, starts with a keyframe: a quarter turn swaps the output's width and
|
|
51
|
+
* height, so a new SPS (H.264) or a differently sized JPEG tells the consumer. A no-op after
|
|
52
|
+
* {@link end}/{@link close}.
|
|
53
|
+
*/
|
|
54
|
+
setRotation(degrees: Rotation): void;
|
|
55
|
+
/** Microseconds between the stream's first arrival (either track) and `receivedAt`. */
|
|
56
|
+
private offsetFrom;
|
|
57
|
+
units(signal?: AbortSignal): AsyncGenerator<U>;
|
|
58
|
+
/**
|
|
59
|
+
* Finishes the stream: flushes the pipeline, so `units()` yields everything already produced and
|
|
60
|
+
* then completes. Idempotent; a no-op after {@link close}.
|
|
61
|
+
*/
|
|
62
|
+
end(): Promise<void>;
|
|
63
|
+
/** Stops immediately, discarding unconsumed units. Idempotent; pending `units()` iterators complete. */
|
|
64
|
+
close(): Promise<void>;
|
|
65
|
+
private onUnit;
|
|
66
|
+
}
|
|
67
|
+
/** Creates a transcoder; throws `MediaProxyUnavailableError` if the addon can't be loaded here. */
|
|
68
|
+
export declare function createTranscoder(opts: H264Options): Transcoder<VideoAccessUnit>;
|
|
69
|
+
export declare function createTranscoder(opts: MjpegOptions): Transcoder<JpegFrame>;
|
|
70
|
+
export declare function createTranscoder(opts: TranscoderOptions): Transcoder<VideoAccessUnit> | Transcoder<JpegFrame>;
|
|
71
|
+
/**
|
|
72
|
+
* Pipes `source` (e.g. remotexpc's `ScreenStreamCapture.accessUnits()`) through a transcoder. When
|
|
73
|
+
* the source finishes, everything already produced is still yielded; if it fails, that error is
|
|
74
|
+
* thrown after the remaining units. Stopping early (`break`, `signal`) closes the transcoder and asks
|
|
75
|
+
* the source to stop via `return()`; a source blocked on an idle read can only finish once it
|
|
76
|
+
* yields or honours its own abort signal, which is not awaited.
|
|
77
|
+
*/
|
|
78
|
+
export declare function transcode(source: AsyncIterable<NalAccessUnit>, opts: H264Options, signal?: AbortSignal, audioSource?: AsyncIterable<AudioAccessUnit>): AsyncGenerator<VideoAccessUnit>;
|
|
79
|
+
export declare function transcode(source: AsyncIterable<NalAccessUnit>, opts: MjpegOptions, signal?: AbortSignal): AsyncGenerator<JpegFrame>;
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=transcoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcoder.d.ts","sourceRoot":"","sources":["../../src/transcoder.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,SAAS,EACT,YAAY,EACZ,aAAa,EACb,YAAY,EAIZ,QAAQ,EACR,iBAAiB,EACjB,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,WAAW,KAAK,CAAC;AAC9B,eAAO,MAAM,eAAe,UAAY,CAAC;AACzC,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,aAAa,MAAM,CAAC;AAGjC,+GAA+G;AAC/G,eAAO,MAAM,6BAA6B,qBAAwC,CAAC;AAanF,iGAAiG;AACjG,wBAAgB,cAAc,CAAC,IAAI,EAAE,iBAAiB,GAAG,YAAY,CA+DpE;AAQD,mGAAmG;AACnG,qBAAa,kBAAkB;IAKjB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAJtC,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,KAAK,CAAK;gBAEW,SAAS,GAAE,MAAiC;IAMzE,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAUpC;AAED,KAAK,UAAU,GAAG,eAAe,GAAG,SAAS,CAAC;AAE9C,iEAAiE;AACjE,qBAAa,UAAU,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IACvD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;IAChD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC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CAAC,EACpC,IAAI,EAAE,WAAW,EACjB,MAAM,CAAC,EAAE,WAAW,EACpB,WAAW,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,GAC3C,cAAc,CAAC,eAAe,CAAC,CAAC;AACnC,wBAAgB,SAAS,CACvB,MAAM,EAAE,aAAa,CAAC,aAAa,CAAC,EACpC,IAAI,EAAE,YAAY,EAClB,MAAM,CAAC,EAAE,WAAW,GACnB,cAAc,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { releaseQuietly } from './background.js';
|
|
2
|
+
import { MediaProxyOptionError, wrapNativeError } from './errors.js';
|
|
3
|
+
import { loadNative } from './native.js';
|
|
4
|
+
import { MAX_BUFFERED_UNITS, UnitQueue } from './queue.js';
|
|
5
|
+
export const DEFAULT_FPS = 60;
|
|
6
|
+
export const DEFAULT_BITRATE = 4_000_000;
|
|
7
|
+
export const DEFAULT_QUALITY = 80;
|
|
8
|
+
export const DEFAULT_SCALE = 100;
|
|
9
|
+
/** AAC-LC output rate per channel (coresim's setting). */
|
|
10
|
+
const AUDIO_BITRATE_PER_CHANNEL = 64_000;
|
|
11
|
+
/** AAC-ELD, 48 kHz stereo, 480-sample frames: the device's stream as it really is (remotexpc `aac-eld.ts`). */
|
|
12
|
+
export const DEFAULT_AUDIO_SPECIFIC_CONFIG = Buffer.from([0xf8, 0xe6, 0x50, 0x00]);
|
|
13
|
+
/**
|
|
14
|
+
* RTP video clock of the device's screen stream. Measured on an iPad (iPadOS 27.0.1): 400 ticks per frame at
|
|
15
|
+
* 60 fps, not the 90 kHz RFC 7798 suggests, so a wrong value slows the media timeline and starves the fps limiter.
|
|
16
|
+
* `videoClockRate` overrides it for a source that is known to differ.
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_VIDEO_CLOCK_RATE = 24_000;
|
|
19
|
+
const AUDIO_CLOCK_RATE = 48_000;
|
|
20
|
+
const MAX_BITRATE = 2 ** 31 - 1;
|
|
21
|
+
/** About 5 s of 10 ms audio units. */
|
|
22
|
+
const MAX_BUFFERED_AUDIO_UNITS = 500;
|
|
23
|
+
/** Validates `opts` and fills in the defaults, with the same rules and error type as coresim. */
|
|
24
|
+
export function resolveOptions(opts) {
|
|
25
|
+
if (opts?.codec !== 'h264' && opts?.codec !== 'mjpeg') {
|
|
26
|
+
throw new MediaProxyOptionError(`codec must be 'h264' or 'mjpeg', got ${String(opts?.codec)}`);
|
|
27
|
+
}
|
|
28
|
+
const fps = opts.fps ?? DEFAULT_FPS;
|
|
29
|
+
if (!Number.isFinite(fps) || fps < 1) {
|
|
30
|
+
throw new RangeError(`fps must be a finite number >= 1, got ${fps}`);
|
|
31
|
+
}
|
|
32
|
+
let bitrate = DEFAULT_BITRATE;
|
|
33
|
+
let quality = DEFAULT_QUALITY;
|
|
34
|
+
let scale = DEFAULT_SCALE;
|
|
35
|
+
let audio = false;
|
|
36
|
+
let audioSpecificConfig = DEFAULT_AUDIO_SPECIFIC_CONFIG;
|
|
37
|
+
if (opts.codec === 'h264') {
|
|
38
|
+
audio = opts.audio ?? false;
|
|
39
|
+
if (opts.audioSpecificConfig !== undefined) {
|
|
40
|
+
if (!Buffer.isBuffer(opts.audioSpecificConfig) || opts.audioSpecificConfig.length === 0) {
|
|
41
|
+
throw new RangeError('audioSpecificConfig must be a non-empty Buffer');
|
|
42
|
+
}
|
|
43
|
+
audioSpecificConfig = opts.audioSpecificConfig;
|
|
44
|
+
}
|
|
45
|
+
bitrate = opts.bitrate ?? DEFAULT_BITRATE;
|
|
46
|
+
if (!Number.isFinite(bitrate) || bitrate <= 0 || bitrate > MAX_BITRATE) {
|
|
47
|
+
throw new RangeError(`bitrate must be a positive number no greater than ${MAX_BITRATE}, got ${bitrate}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
quality = opts.quality ?? DEFAULT_QUALITY;
|
|
52
|
+
if (!Number.isFinite(quality) || quality < 0 || quality > 100) {
|
|
53
|
+
throw new RangeError(`quality must be a number between 0 and 100, got ${quality}`);
|
|
54
|
+
}
|
|
55
|
+
scale = opts.scale ?? DEFAULT_SCALE;
|
|
56
|
+
if (!Number.isFinite(scale) || scale <= 0 || scale > 100) {
|
|
57
|
+
throw new RangeError(`scale must be a number greater than 0 and no greater than 100, got ${scale}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const { crop } = opts;
|
|
61
|
+
if (crop !== undefined) {
|
|
62
|
+
for (const [side, value] of [
|
|
63
|
+
['width', crop.width],
|
|
64
|
+
['height', crop.height],
|
|
65
|
+
]) {
|
|
66
|
+
if (!Number.isInteger(value) || value <= 0 || value % 2 !== 0) {
|
|
67
|
+
throw new RangeError(`crop.${side} must be a positive even integer, got ${value}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const rotation = opts.rotation ?? 0;
|
|
72
|
+
assertRotation(rotation);
|
|
73
|
+
return {
|
|
74
|
+
outputCodec: opts.codec,
|
|
75
|
+
fps,
|
|
76
|
+
bitrate,
|
|
77
|
+
quality,
|
|
78
|
+
scale,
|
|
79
|
+
audio,
|
|
80
|
+
audioSpecificConfig,
|
|
81
|
+
audioBitratePerChannel: AUDIO_BITRATE_PER_CHANNEL,
|
|
82
|
+
cropWidth: crop?.width ?? 0,
|
|
83
|
+
cropHeight: crop?.height ?? 0,
|
|
84
|
+
rotation,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function assertRotation(degrees) {
|
|
88
|
+
if (degrees !== 0 && degrees !== 90 && degrees !== 180 && degrees !== 270) {
|
|
89
|
+
throw new RangeError(`rotation must be 0, 90, 180 or 270, got ${String(degrees)}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Converts 32-bit RTP timestamps to microseconds since the first unit, unwrapping the counter. */
|
|
93
|
+
export class TimestampConverter {
|
|
94
|
+
clockRate;
|
|
95
|
+
base;
|
|
96
|
+
last = 0;
|
|
97
|
+
ticks = 0;
|
|
98
|
+
constructor(clockRate = DEFAULT_VIDEO_CLOCK_RATE) {
|
|
99
|
+
this.clockRate = clockRate;
|
|
100
|
+
if (!Number.isFinite(clockRate) || clockRate <= 0) {
|
|
101
|
+
throw new RangeError(`videoClockRate must be a positive finite number, got ${clockRate}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
toMicros(timestamp) {
|
|
105
|
+
if (this.base === undefined) {
|
|
106
|
+
this.base = timestamp;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// Signed 32-bit delta handles wrap-around and small reorderings.
|
|
110
|
+
this.ticks += (timestamp - this.last) | 0;
|
|
111
|
+
}
|
|
112
|
+
this.last = timestamp;
|
|
113
|
+
return Math.max(0, Math.round((this.ticks * 1_000_000) / this.clockRate));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** A running transcoder. Single `units()` consumer at a time. */
|
|
117
|
+
export class Transcoder {
|
|
118
|
+
handle;
|
|
119
|
+
queue;
|
|
120
|
+
clock;
|
|
121
|
+
audioClock = new TimestampConverter(AUDIO_CLOCK_RATE);
|
|
122
|
+
isVideo;
|
|
123
|
+
hasAudio;
|
|
124
|
+
stopController = new AbortController();
|
|
125
|
+
sequence = 0;
|
|
126
|
+
audioSequence = 0;
|
|
127
|
+
// Arrival time of the very first unit (either track) and each track's offset from it, in µs.
|
|
128
|
+
originMs;
|
|
129
|
+
videoOffset;
|
|
130
|
+
audioOffset;
|
|
131
|
+
closePromise;
|
|
132
|
+
consuming = false;
|
|
133
|
+
/** @internal use {@link createTranscoder}; `backend` is injectable for tests. */
|
|
134
|
+
constructor(opts, backend) {
|
|
135
|
+
// Validate before touching the addon, so bad options are reported even where it's unavailable.
|
|
136
|
+
const config = resolveOptions(opts);
|
|
137
|
+
this.clock = new TimestampConverter(opts.videoClockRate ?? DEFAULT_VIDEO_CLOCK_RATE);
|
|
138
|
+
const native = backend ?? loadNative();
|
|
139
|
+
this.isVideo = config.outputCodec === 'h264';
|
|
140
|
+
this.hasAudio = config.audio;
|
|
141
|
+
// Audio units are never dropped and never end a resync: only video frames depend on each other.
|
|
142
|
+
this.queue = new UnitQueue(this.isVideo
|
|
143
|
+
? {
|
|
144
|
+
dropsDuringResync: (u) => u.track === 'video' && !u.isKeyFrame,
|
|
145
|
+
endsResync: (u) => u.track === 'video' && u.isKeyFrame,
|
|
146
|
+
keepOnOverflow: (u) => u.track === 'audio',
|
|
147
|
+
onOverflow: () => this.handle?.requestKeyFrame(),
|
|
148
|
+
capacity: MAX_BUFFERED_UNITS + (this.hasAudio ? MAX_BUFFERED_AUDIO_UNITS : 0),
|
|
149
|
+
}
|
|
150
|
+
: { dropsDuringResync: () => false, endsResync: () => true });
|
|
151
|
+
try {
|
|
152
|
+
this.handle = native.createTranscoder(config, (unit) => this.onUnit(unit),
|
|
153
|
+
// oxlint-disable-next-line promise/prefer-await-to-callbacks -- native error callback, not a promise API
|
|
154
|
+
(err) => this.queue.fail(wrapNativeError(err)));
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
throw wrapNativeError(err);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** Feeds one access unit (non-blocking; the native side queues and may drop to the next keyframe). */
|
|
161
|
+
push(au) {
|
|
162
|
+
if (this.closePromise) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
const micros = this.clock.toMicros(au.timestamp);
|
|
167
|
+
this.videoOffset ??= this.offsetFrom(au.receivedAt);
|
|
168
|
+
this.handle.push(au.nals, micros + this.videoOffset, au.isKeyFrame);
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
throw wrapNativeError(err);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** Feeds one AAC-ELD access unit; needs `audio: true`. Timestamps are aligned with the video by arrival time. */
|
|
175
|
+
pushAudio(au) {
|
|
176
|
+
if (!this.hasAudio) {
|
|
177
|
+
throw new MediaProxyOptionError("pushAudio() requires the 'audio' option");
|
|
178
|
+
}
|
|
179
|
+
if (this.closePromise) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const micros = this.audioClock.toMicros(au.timestamp);
|
|
184
|
+
this.audioOffset ??= this.offsetFrom(au.receivedAt);
|
|
185
|
+
this.handle.pushAudio(au.data, micros + this.audioOffset);
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
throw wrapNativeError(err);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Makes the next H.264 output a keyframe, e.g. for a consumer that joined a running stream. Takes
|
|
193
|
+
* effect with the next input unit, so it needs the source to keep sending. Requests made before that unit
|
|
194
|
+
* are one request (the native side only sets a flag), but each later one forces another keyframe, so
|
|
195
|
+
* callers that serve several consumers should coalesce them. A no-op for MJPEG (every frame is standalone)
|
|
196
|
+
* and after {@link end}/{@link close}.
|
|
197
|
+
*/
|
|
198
|
+
requestKeyFrame() {
|
|
199
|
+
if (!this.isVideo || this.closePromise) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
this.handle.requestKeyFrame();
|
|
204
|
+
}
|
|
205
|
+
catch (err) {
|
|
206
|
+
throw wrapNativeError(err);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Changes the clockwise rotation that makes the picture upright, while streaming. The next frame is turned
|
|
211
|
+
* and, since the output changes shape, starts with a keyframe: a quarter turn swaps the output's width and
|
|
212
|
+
* height, so a new SPS (H.264) or a differently sized JPEG tells the consumer. A no-op after
|
|
213
|
+
* {@link end}/{@link close}.
|
|
214
|
+
*/
|
|
215
|
+
setRotation(degrees) {
|
|
216
|
+
assertRotation(degrees);
|
|
217
|
+
if (this.closePromise) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
this.handle.setRotation(degrees);
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
throw wrapNativeError(err);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/** Microseconds between the stream's first arrival (either track) and `receivedAt`. */
|
|
228
|
+
offsetFrom(receivedAt) {
|
|
229
|
+
const now = receivedAt ?? performance.now();
|
|
230
|
+
this.originMs ??= now;
|
|
231
|
+
return Math.max(0, Math.round((now - this.originMs) * 1000));
|
|
232
|
+
}
|
|
233
|
+
async *units(signal) {
|
|
234
|
+
if (this.consuming) {
|
|
235
|
+
throw new MediaProxyOptionError('units() supports only one active consumer at a time');
|
|
236
|
+
}
|
|
237
|
+
this.consuming = true;
|
|
238
|
+
const combined = signal ? AbortSignal.any([signal, this.stopController.signal]) : this.stopController.signal;
|
|
239
|
+
try {
|
|
240
|
+
for (;;) {
|
|
241
|
+
const result = await this.queue.next(combined);
|
|
242
|
+
if (result.done) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
yield result.value;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
this.consuming = false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Finishes the stream: flushes the pipeline, so `units()` yields everything already produced and
|
|
254
|
+
* then completes. Idempotent; a no-op after {@link close}.
|
|
255
|
+
*/
|
|
256
|
+
end() {
|
|
257
|
+
this.closePromise ??= (async () => {
|
|
258
|
+
try {
|
|
259
|
+
await this.handle.close();
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
const wrapped = wrapNativeError(err);
|
|
263
|
+
this.queue.fail(wrapped);
|
|
264
|
+
throw wrapped;
|
|
265
|
+
}
|
|
266
|
+
this.queue.end({ drain: true });
|
|
267
|
+
})();
|
|
268
|
+
return this.closePromise;
|
|
269
|
+
}
|
|
270
|
+
/** Stops immediately, discarding unconsumed units. Idempotent; pending `units()` iterators complete. */
|
|
271
|
+
close() {
|
|
272
|
+
// Stop consumers first, even if end() already started: native close() may still flush units
|
|
273
|
+
// nobody wants, and a draining queue must be discarded.
|
|
274
|
+
this.stopController.abort();
|
|
275
|
+
this.queue.end();
|
|
276
|
+
this.closePromise ??= this.handle.close();
|
|
277
|
+
return this.closePromise;
|
|
278
|
+
}
|
|
279
|
+
onUnit(unit) {
|
|
280
|
+
const out = this.isVideo
|
|
281
|
+
? {
|
|
282
|
+
track: unit.audio ? 'audio' : 'video',
|
|
283
|
+
data: unit.data,
|
|
284
|
+
isKeyFrame: unit.isKeyFrame,
|
|
285
|
+
sequence: unit.audio ? this.audioSequence++ : this.sequence++,
|
|
286
|
+
timestampMicros: unit.timestampMicros,
|
|
287
|
+
}
|
|
288
|
+
: { data: unit.data, sequence: this.sequence++, timestampMicros: unit.timestampMicros };
|
|
289
|
+
this.queue.push(out);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
export function createTranscoder(opts) {
|
|
293
|
+
return new Transcoder(opts);
|
|
294
|
+
}
|
|
295
|
+
export async function* transcode(source, opts, signal, audioSource) {
|
|
296
|
+
if (audioSource && !(opts.codec === 'h264' && opts.audio)) {
|
|
297
|
+
throw new MediaProxyOptionError("audioSource requires codec 'h264' with audio: true");
|
|
298
|
+
}
|
|
299
|
+
yield* pipeThrough(createTranscoder(opts), source, signal, audioSource);
|
|
300
|
+
}
|
|
301
|
+
/** @internal `transcode()` with an already-created transcoder (injectable backend for tests). */
|
|
302
|
+
export async function* pipeThrough(transcoder, source, signal, audioSource) {
|
|
303
|
+
let iterator;
|
|
304
|
+
let audioIterator;
|
|
305
|
+
try {
|
|
306
|
+
iterator = source[Symbol.asyncIterator]();
|
|
307
|
+
audioIterator = audioSource?.[Symbol.asyncIterator]();
|
|
308
|
+
}
|
|
309
|
+
catch (err) {
|
|
310
|
+
await transcoder.close().catch(() => { });
|
|
311
|
+
throw err;
|
|
312
|
+
}
|
|
313
|
+
let stopped = false;
|
|
314
|
+
let exhausted = false;
|
|
315
|
+
let returned = false;
|
|
316
|
+
let failed = false;
|
|
317
|
+
let pumpError;
|
|
318
|
+
// Don't await: an idle source may not settle until its next item.
|
|
319
|
+
const releaseSource = () => {
|
|
320
|
+
if (!exhausted && !returned) {
|
|
321
|
+
returned = true;
|
|
322
|
+
releaseQuietly(iterator);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
let audioDone = false;
|
|
326
|
+
const releaseAudio = () => {
|
|
327
|
+
if (audioIterator && !audioDone) {
|
|
328
|
+
audioDone = true;
|
|
329
|
+
releaseQuietly(audioIterator);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
const fail = (err) => {
|
|
333
|
+
if (!failed) {
|
|
334
|
+
failed = true;
|
|
335
|
+
pumpError = err;
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
// Audio follows the video: it ends with it, and its failure ends the stream like a video failure.
|
|
339
|
+
// Never awaited: an idle audio read may not settle until its next item, and it can't fail the stream afterwards.
|
|
340
|
+
void (async () => {
|
|
341
|
+
if (!audioIterator) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
try {
|
|
345
|
+
for (;;) {
|
|
346
|
+
const result = await audioIterator.next();
|
|
347
|
+
if (result.done) {
|
|
348
|
+
audioDone = true;
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (stopped || audioDone) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
transcoder.pushAudio(result.value);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
catch (err) {
|
|
358
|
+
audioDone = true;
|
|
359
|
+
fail(err);
|
|
360
|
+
releaseSource();
|
|
361
|
+
if (!stopped) {
|
|
362
|
+
await transcoder.end().catch(() => { });
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
})();
|
|
366
|
+
const pump = (async () => {
|
|
367
|
+
try {
|
|
368
|
+
for (;;) {
|
|
369
|
+
let result;
|
|
370
|
+
try {
|
|
371
|
+
result = await iterator.next();
|
|
372
|
+
}
|
|
373
|
+
catch (err) {
|
|
374
|
+
exhausted = true;
|
|
375
|
+
throw err;
|
|
376
|
+
}
|
|
377
|
+
if (result.done) {
|
|
378
|
+
exhausted = true;
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
if (stopped) {
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
transcoder.push(result.value);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
catch (err) {
|
|
388
|
+
fail(err);
|
|
389
|
+
}
|
|
390
|
+
releaseSource();
|
|
391
|
+
releaseAudio();
|
|
392
|
+
if (!stopped) {
|
|
393
|
+
// A close failure reaches the consumer through the queue; keep the pump from rejecting.
|
|
394
|
+
await transcoder.end().catch(() => { });
|
|
395
|
+
}
|
|
396
|
+
})();
|
|
397
|
+
try {
|
|
398
|
+
yield* transcoder.units(signal);
|
|
399
|
+
}
|
|
400
|
+
finally {
|
|
401
|
+
stopped = true;
|
|
402
|
+
try {
|
|
403
|
+
await transcoder.close();
|
|
404
|
+
}
|
|
405
|
+
finally {
|
|
406
|
+
releaseSource();
|
|
407
|
+
releaseAudio();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (signal?.aborted) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
// A failure is reported without waiting for the pump: an idle video read may never settle.
|
|
414
|
+
if (failed) {
|
|
415
|
+
throw pumpError;
|
|
416
|
+
}
|
|
417
|
+
await pump;
|
|
418
|
+
if (failed) {
|
|
419
|
+
throw pumpError;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
//# sourceMappingURL=transcoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcoder.js","sourceRoot":"","sources":["../../src/transcoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAC,qBAAqB,EAAE,eAAe,EAAC,MAAM,aAAa,CAAC;AACnE,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,EAAC,k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