appium-xcuitest-driver 13.2.0 → 13.4.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 +12 -0
- package/build/lib/commands/automation-session.js +1 -1
- package/build/lib/commands/automation-session.js.map +1 -1
- package/build/lib/commands/bidi/helpers.d.ts +14 -0
- package/build/lib/commands/bidi/helpers.d.ts.map +1 -0
- package/build/lib/commands/bidi/helpers.js +24 -0
- package/build/lib/commands/bidi/helpers.js.map +1 -0
- package/build/lib/commands/bidi/syslog-level.d.ts +9 -0
- package/build/lib/commands/bidi/syslog-level.d.ts.map +1 -0
- package/build/lib/commands/bidi/syslog-level.js +42 -0
- package/build/lib/commands/bidi/syslog-level.js.map +1 -0
- package/build/lib/commands/constants.d.ts +2 -0
- package/build/lib/commands/constants.d.ts.map +1 -1
- package/build/lib/commands/constants.js +2 -0
- package/build/lib/commands/constants.js.map +1 -1
- package/build/lib/commands/context.d.ts +0 -1
- package/build/lib/commands/context.d.ts.map +1 -1
- package/build/lib/commands/context.js +12 -11
- package/build/lib/commands/context.js.map +1 -1
- package/build/lib/commands/log.d.ts +4 -2
- package/build/lib/commands/log.d.ts.map +1 -1
- package/build/lib/commands/log.js +19 -9
- package/build/lib/commands/log.js.map +1 -1
- package/build/lib/commands/media-stream.d.ts +34 -0
- package/build/lib/commands/media-stream.d.ts.map +1 -0
- package/build/lib/commands/media-stream.js +230 -0
- package/build/lib/commands/media-stream.js.map +1 -0
- package/build/lib/device/media-stream/batcher.d.ts +17 -0
- package/build/lib/device/media-stream/batcher.d.ts.map +1 -0
- package/build/lib/device/media-stream/batcher.js +48 -0
- package/build/lib/device/media-stream/batcher.js.map +1 -0
- package/build/lib/device/media-stream/constants.d.ts +20 -0
- package/build/lib/device/media-stream/constants.d.ts.map +1 -0
- package/build/lib/device/media-stream/constants.js +23 -0
- package/build/lib/device/media-stream/constants.js.map +1 -0
- package/build/lib/device/media-stream/device-source.d.ts +39 -0
- package/build/lib/device/media-stream/device-source.d.ts.map +1 -0
- package/build/lib/device/media-stream/device-source.js +229 -0
- package/build/lib/device/media-stream/device-source.js.map +1 -0
- package/build/lib/device/media-stream/jpeg.d.ts +6 -0
- package/build/lib/device/media-stream/jpeg.d.ts.map +1 -0
- package/build/lib/device/media-stream/jpeg.js +17 -0
- package/build/lib/device/media-stream/jpeg.js.map +1 -0
- package/build/lib/device/media-stream/media-proxy.d.ts +13 -0
- package/build/lib/device/media-stream/media-proxy.d.ts.map +1 -0
- package/build/lib/device/media-stream/media-proxy.js +33 -0
- package/build/lib/device/media-stream/media-proxy.js.map +1 -0
- package/build/lib/device/media-stream/orientation.d.ts +22 -0
- package/build/lib/device/media-stream/orientation.d.ts.map +1 -0
- package/build/lib/device/media-stream/orientation.js +35 -0
- package/build/lib/device/media-stream/orientation.js.map +1 -0
- package/build/lib/device/media-stream/simulator-source.d.ts +16 -0
- package/build/lib/device/media-stream/simulator-source.d.ts.map +1 -0
- package/build/lib/device/media-stream/simulator-source.js +45 -0
- package/build/lib/device/media-stream/simulator-source.js.map +1 -0
- package/build/lib/device/media-stream/sps.d.ts +12 -0
- package/build/lib/device/media-stream/sps.d.ts.map +1 -0
- package/build/lib/device/media-stream/sps.js +196 -0
- package/build/lib/device/media-stream/sps.js.map +1 -0
- package/build/lib/device/media-stream/stream.d.ts +70 -0
- package/build/lib/device/media-stream/stream.d.ts.map +1 -0
- package/build/lib/device/media-stream/stream.js +356 -0
- package/build/lib/device/media-stream/stream.js.map +1 -0
- package/build/lib/device/media-stream/types.d.ts +73 -0
- package/build/lib/device/media-stream/types.d.ts.map +1 -0
- package/build/lib/device/media-stream/types.js +2 -0
- package/build/lib/device/media-stream/types.js.map +1 -0
- package/build/lib/driver.d.ts +22 -0
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +17 -0
- package/build/lib/driver.js.map +1 -1
- package/build/lib/execute-method-map.d.ts +16 -0
- package/build/lib/execute-method-map.d.ts.map +1 -1
- package/build/lib/execute-method-map.js +16 -0
- package/build/lib/execute-method-map.js.map +1 -1
- package/lib/commands/automation-session.ts +1 -1
- package/lib/commands/bidi/helpers.ts +27 -0
- package/lib/commands/bidi/syslog-level.ts +46 -0
- package/lib/commands/constants.ts +2 -0
- package/lib/commands/context.ts +12 -11
- package/lib/commands/log.ts +21 -10
- package/lib/commands/media-stream.ts +315 -0
- package/lib/device/media-stream/batcher.ts +51 -0
- package/lib/device/media-stream/constants.ts +22 -0
- package/lib/device/media-stream/device-source.ts +265 -0
- package/lib/device/media-stream/jpeg.ts +16 -0
- package/lib/device/media-stream/media-proxy.ts +45 -0
- package/lib/device/media-stream/orientation.ts +55 -0
- package/lib/device/media-stream/simulator-source.ts +55 -0
- package/lib/device/media-stream/sps.ts +208 -0
- package/lib/device/media-stream/stream.ts +404 -0
- package/lib/device/media-stream/types.ts +83 -0
- package/lib/driver.ts +18 -0
- package/lib/execute-method-map.ts +16 -0
- package/node_modules/@appium/media-proxy/CHANGELOG.md +33 -0
- package/node_modules/@appium/media-proxy/LICENSE +201 -0
- package/node_modules/@appium/media-proxy/README.md +185 -0
- package/node_modules/@appium/media-proxy/THIRD_PARTY_NOTICES.md +29 -0
- package/node_modules/@appium/media-proxy/binding.gyp +90 -0
- package/node_modules/@appium/media-proxy/lib/src/background.d.ts +5 -0
- package/node_modules/@appium/media-proxy/lib/src/background.d.ts.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/background.js +16 -0
- package/node_modules/@appium/media-proxy/lib/src/background.js.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/capabilities.d.ts +9 -0
- package/node_modules/@appium/media-proxy/lib/src/capabilities.d.ts.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/capabilities.js +11 -0
- package/node_modules/@appium/media-proxy/lib/src/capabilities.js.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/errors.d.ts +26 -0
- package/node_modules/@appium/media-proxy/lib/src/errors.d.ts.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/errors.js +40 -0
- package/node_modules/@appium/media-proxy/lib/src/errors.js.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/framing/apst.d.ts +43 -0
- package/node_modules/@appium/media-proxy/lib/src/framing/apst.d.ts.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/framing/apst.js +126 -0
- package/node_modules/@appium/media-proxy/lib/src/framing/apst.js.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/framing/mjpeg-http.d.ts +30 -0
- package/node_modules/@appium/media-proxy/lib/src/framing/mjpeg-http.d.ts.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/framing/mjpeg-http.js +148 -0
- package/node_modules/@appium/media-proxy/lib/src/framing/mjpeg-http.js.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/framing/mjpeg-multipart.d.ts +11 -0
- package/node_modules/@appium/media-proxy/lib/src/framing/mjpeg-multipart.d.ts.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/framing/mjpeg-multipart.js +26 -0
- package/node_modules/@appium/media-proxy/lib/src/framing/mjpeg-multipart.js.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/index.d.ts +10 -0
- package/node_modules/@appium/media-proxy/lib/src/index.d.ts.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/index.js +7 -0
- package/node_modules/@appium/media-proxy/lib/src/index.js.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/native.d.ts +12 -0
- package/node_modules/@appium/media-proxy/lib/src/native.d.ts.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/native.js +36 -0
- package/node_modules/@appium/media-proxy/lib/src/native.js.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/pkg-root.d.ts +6 -0
- package/node_modules/@appium/media-proxy/lib/src/pkg-root.d.ts.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/pkg-root.js +12 -0
- package/node_modules/@appium/media-proxy/lib/src/pkg-root.js.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/queue.d.ts +34 -0
- package/node_modules/@appium/media-proxy/lib/src/queue.d.ts.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/queue.js +123 -0
- package/node_modules/@appium/media-proxy/lib/src/queue.js.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/transcoder.d.ts +81 -0
- package/node_modules/@appium/media-proxy/lib/src/transcoder.d.ts.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/transcoder.js +422 -0
- package/node_modules/@appium/media-proxy/lib/src/transcoder.js.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/types.d.ts +147 -0
- package/node_modules/@appium/media-proxy/lib/src/types.d.ts.map +1 -0
- package/node_modules/@appium/media-proxy/lib/src/types.js +2 -0
- package/node_modules/@appium/media-proxy/lib/src/types.js.map +1 -0
- package/node_modules/@appium/media-proxy/package.json +67 -0
- package/node_modules/@appium/media-proxy/prebuilds/darwin-arm64/@appium+media-proxy.node +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/darwin-arm64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
- package/node_modules/@appium/media-proxy/prebuilds/darwin-arm64/ffmpeg-build-info.txt +3 -0
- package/node_modules/@appium/media-proxy/prebuilds/darwin-arm64/libavcodec-appium.62.dylib +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/darwin-arm64/libavutil-appium.60.dylib +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/darwin-arm64/libswscale-appium.9.dylib +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/linux-arm64/@appium+media-proxy.node +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/linux-arm64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
- package/node_modules/@appium/media-proxy/prebuilds/linux-arm64/ffmpeg-build-info.txt +3 -0
- package/node_modules/@appium/media-proxy/prebuilds/linux-arm64/libavcodec-appium.so.62 +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/linux-arm64/libavutil-appium.so.60 +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/linux-arm64/libswscale-appium.so.9 +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/linux-x64/@appium+media-proxy.node +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/linux-x64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
- package/node_modules/@appium/media-proxy/prebuilds/linux-x64/ffmpeg-build-info.txt +3 -0
- package/node_modules/@appium/media-proxy/prebuilds/linux-x64/libavcodec-appium.so.62 +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/linux-x64/libavutil-appium.so.60 +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/linux-x64/libswscale-appium.so.9 +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/win32-x64/@appium+media-proxy.node +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/win32-x64/avcodec-appium-62.dll +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/win32-x64/avutil-appium-60.dll +0 -0
- package/node_modules/@appium/media-proxy/prebuilds/win32-x64/ffmpeg-LICENSE-LGPL-2.1.txt +502 -0
- package/node_modules/@appium/media-proxy/prebuilds/win32-x64/ffmpeg-build-info.txt +3 -0
- package/node_modules/@appium/media-proxy/prebuilds/win32-x64/swscale-appium-9.dll +0 -0
- package/node_modules/@appium/media-proxy/scripts/install.mjs +29 -0
- package/node_modules/@appium/media-proxy/src/background.ts +15 -0
- package/node_modules/@appium/media-proxy/src/capabilities.ts +12 -0
- package/node_modules/@appium/media-proxy/src/errors.ts +45 -0
- package/node_modules/@appium/media-proxy/src/framing/apst.ts +158 -0
- package/node_modules/@appium/media-proxy/src/framing/mjpeg-http.ts +186 -0
- package/node_modules/@appium/media-proxy/src/framing/mjpeg-multipart.ts +38 -0
- package/node_modules/@appium/media-proxy/src/index.ts +43 -0
- package/node_modules/@appium/media-proxy/src/native/addon.cc +402 -0
- package/node_modules/@appium/media-proxy/src/native/audio_pipeline.cc +426 -0
- package/node_modules/@appium/media-proxy/src/native/audio_pipeline.h +63 -0
- package/node_modules/@appium/media-proxy/src/native/ffmpeg_util.h +37 -0
- package/node_modules/@appium/media-proxy/src/native/h264_encoder.cc +133 -0
- package/node_modules/@appium/media-proxy/src/native/h264_encoder.h +48 -0
- package/node_modules/@appium/media-proxy/src/native/mediafoundation_encoder.cc +442 -0
- package/node_modules/@appium/media-proxy/src/native/mediafoundation_encoder.h +14 -0
- package/node_modules/@appium/media-proxy/src/native/napi_util.h +20 -0
- package/node_modules/@appium/media-proxy/src/native/openh264_encoder.cc +285 -0
- package/node_modules/@appium/media-proxy/src/native/openh264_encoder.h +14 -0
- package/node_modules/@appium/media-proxy/src/native/pipeline.cc +555 -0
- package/node_modules/@appium/media-proxy/src/native/pipeline.h +108 -0
- package/node_modules/@appium/media-proxy/src/native/vendor/openh264/LICENSE +23 -0
- package/node_modules/@appium/media-proxy/src/native/vendor/openh264/codec_api.h +592 -0
- package/node_modules/@appium/media-proxy/src/native/vendor/openh264/codec_app_def.h +820 -0
- package/node_modules/@appium/media-proxy/src/native/vendor/openh264/codec_def.h +216 -0
- package/node_modules/@appium/media-proxy/src/native/vendor/openh264/codec_ver.h +15 -0
- package/node_modules/@appium/media-proxy/src/native/videotoolbox_encoder.cc +314 -0
- package/node_modules/@appium/media-proxy/src/native/videotoolbox_encoder.h +13 -0
- package/node_modules/@appium/media-proxy/src/native.ts +51 -0
- package/node_modules/@appium/media-proxy/src/pkg-root.ts +14 -0
- package/node_modules/@appium/media-proxy/src/queue.ts +133 -0
- package/node_modules/@appium/media-proxy/src/transcoder.ts +480 -0
- package/node_modules/@appium/media-proxy/src/types.ts +158 -0
- package/node_modules/appium-ios-remotexpc/CHANGELOG.md +14 -0
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/audio/audio-stream-capture.d.ts.map +1 -1
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/audio/audio-stream-capture.js +1 -0
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/audio/audio-stream-capture.js.map +1 -1
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/transport/rtp.d.ts +19 -0
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/transport/rtp.d.ts.map +1 -1
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/transport/rtp.js +59 -1
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/transport/rtp.js.map +1 -1
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/video/access-unit-assembler.d.ts +9 -0
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/video/access-unit-assembler.d.ts.map +1 -1
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/video/access-unit-assembler.js +27 -0
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/video/access-unit-assembler.js.map +1 -1
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/video/hevc.d.ts +9 -0
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/video/hevc.d.ts.map +1 -1
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/video/hevc.js +22 -0
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/video/hevc.js.map +1 -1
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/video/screen-stream-capture.d.ts.map +1 -1
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/video/screen-stream-capture.js +1 -0
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/display/video/screen-stream-capture.js.map +1 -1
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/webinspector/index.d.ts +1 -0
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/webinspector/index.d.ts.map +1 -1
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/webinspector/index.js +7 -0
- package/node_modules/appium-ios-remotexpc/build/src/services/ios/webinspector/index.js.map +1 -1
- package/node_modules/appium-ios-remotexpc/package.json +2 -2
- package/node_modules/appium-ios-remotexpc/src/services/ios/display/audio/audio-stream-capture.ts +1 -0
- package/node_modules/appium-ios-remotexpc/src/services/ios/display/transport/rtp.ts +65 -2
- package/node_modules/appium-ios-remotexpc/src/services/ios/display/video/access-unit-assembler.ts +29 -0
- package/node_modules/appium-ios-remotexpc/src/services/ios/display/video/hevc.ts +24 -0
- package/node_modules/appium-ios-remotexpc/src/services/ios/display/video/screen-stream-capture.ts +1 -0
- package/node_modules/appium-ios-remotexpc/src/services/ios/webinspector/index.ts +8 -0
- package/node_modules/appium-remote-debugger/CHANGELOG.md +16 -0
- package/node_modules/appium-remote-debugger/package.json +3 -3
- package/node_modules/bare-fs/package.json +2 -2
- package/node_modules/bare-fs/prebuilds/darwin-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/linux-x64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/win32-x64/bare-fs.bare +0 -0
- package/node_modules/plist/dist/parse-binary.d.ts.map +1 -1
- package/node_modules/plist/dist/parse-binary.js +37 -9
- package/node_modules/plist/dist/parse-binary.js.map +1 -1
- package/node_modules/plist/package.json +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { errors } from 'appium/driver.js';
|
|
2
|
+
import { DEFAULT_BATCH_MS, DEFAULT_IDLE_HEARTBEAT_MS, MAX_BATCH_MS, MAX_BITRATE, MAX_DISPLAY_ID, MAX_FPS, MAX_IDLE_HEARTBEAT_MS, MEDIA_STREAM_MODULE, MEDIA_UNITS_EVENT, MIN_IDLE_HEARTBEAT_MS, MIN_SIMULATOR_XCODE_MAJOR, } from '../device/media-stream/constants.js';
|
|
3
|
+
import { DeviceMediaSource, isDeviceStreamingSupported } from '../device/media-stream/device-source.js';
|
|
4
|
+
import { describeMissingH264Encoder, loadMediaProxy } from '../device/media-stream/media-proxy.js';
|
|
5
|
+
import { SimulatorMediaSource } from '../device/media-stream/simulator-source.js';
|
|
6
|
+
import { MediaStream } from '../device/media-stream/stream.js';
|
|
7
|
+
import { supportsApiLevel27 } from '../utils/index.js';
|
|
8
|
+
import { BIDI_EVENT_NAME } from './bidi/constants.js';
|
|
9
|
+
/**
|
|
10
|
+
* Starts streaming the screen as `appium:mediaStream.*` BiDi events.
|
|
11
|
+
* Subscribe to `appium:mediaStream` before calling this.
|
|
12
|
+
* Simulators (Xcode 26+) encode the units themselves. Real devices (iOS/tvOS 27+, RemoteXPC tunnel) are
|
|
13
|
+
* captured as HEVC and transcoded to H.264 (with AAC audio) or MJPEG by `@appium/media-proxy`; HEVC is not available there yet.
|
|
14
|
+
*
|
|
15
|
+
* @param kind 'video' (H.264/HEVC, optionally with AAC audio) or 'jpeg'.
|
|
16
|
+
* @param codec Video codec, 'h264' by default.
|
|
17
|
+
* @param fps Maximum frames per second.
|
|
18
|
+
* @param bitrate Video bitrate in bits per second.
|
|
19
|
+
* @param quality JPEG quality, 0-100.
|
|
20
|
+
* @param scale JPEG scale in percent, 1-100.
|
|
21
|
+
* @param audio Whether to add an AAC audio track (video only).
|
|
22
|
+
* @param displayId The display to stream, the primary one by default.
|
|
23
|
+
* @param batchMs Units batching window for video/audio. 40 by default.
|
|
24
|
+
* @param idleHeartbeatMs Re-send the last JPEG after this idle time. 1000 by default, 0 disables.
|
|
25
|
+
*/
|
|
26
|
+
export async function mobileStartMediaStream(kind, codec, fps, bitrate, quality, scale, audio, displayId, batchMs = DEFAULT_BATCH_MS, idleHeartbeatMs = DEFAULT_IDLE_HEARTBEAT_MS) {
|
|
27
|
+
const opts = {
|
|
28
|
+
kind,
|
|
29
|
+
codec,
|
|
30
|
+
fps,
|
|
31
|
+
bitrate,
|
|
32
|
+
quality,
|
|
33
|
+
scale,
|
|
34
|
+
audio,
|
|
35
|
+
displayId,
|
|
36
|
+
batchMs,
|
|
37
|
+
idleHeartbeatMs,
|
|
38
|
+
};
|
|
39
|
+
validateOpts(opts);
|
|
40
|
+
if (!this.isSimulator() &&
|
|
41
|
+
displayId !== undefined &&
|
|
42
|
+
!(/^\d{1,10}$/.test(displayId) && Number(displayId) <= MAX_DISPLAY_ID)) {
|
|
43
|
+
throw new errors.InvalidArgumentError(`'displayId' must be a numeric display id, got '${displayId}'`);
|
|
44
|
+
}
|
|
45
|
+
const caps = await getCapabilities(this);
|
|
46
|
+
if (!caps.supported) {
|
|
47
|
+
throw new errors.InvalidArgumentError(`Media streaming is not available: ${caps.reason?.message}`);
|
|
48
|
+
}
|
|
49
|
+
if (!caps.kinds.includes(kind)) {
|
|
50
|
+
throw new errors.InvalidArgumentError(`Kind '${kind}' is not available for ${caps.source} streaming${caps.reason ? `: ${caps.reason.message}` : ''}`);
|
|
51
|
+
}
|
|
52
|
+
if (kind === 'video' && !caps.codecs.includes(codec ?? 'h264')) {
|
|
53
|
+
throw new errors.InvalidArgumentError(`Codec '${codec ?? 'h264'}' is not available for ${caps.source} streaming, use one of: ${caps.codecs.join(', ')}`);
|
|
54
|
+
}
|
|
55
|
+
if (audio && !caps.audio) {
|
|
56
|
+
throw new errors.InvalidArgumentError(`Audio is not available for ${caps.source} streaming yet`);
|
|
57
|
+
}
|
|
58
|
+
const source = this.isSimulator()
|
|
59
|
+
? new SimulatorMediaSource(this.device, opts)
|
|
60
|
+
: new DeviceMediaSource(this.remoteXPCFacade, opts, this.log);
|
|
61
|
+
const streams = (this._mediaStreams ??= new Map());
|
|
62
|
+
// Only streams that are still running stay here; ended ids move to `_endedMediaStreams`.
|
|
63
|
+
// Stopping a device capture stops everything streaming on the device, so streams must not overlap (a
|
|
64
|
+
// stream that is still tearing down is still registered)
|
|
65
|
+
if (!this.isSimulator() && streams.size > 0) {
|
|
66
|
+
throw new errors.InvalidArgumentError('A real device runs one media stream at a time, stop the running one first and retry');
|
|
67
|
+
}
|
|
68
|
+
if ([...streams.values()].some((s) => s.kind === kind && !s.isStopped)) {
|
|
69
|
+
throw new errors.InvalidArgumentError(`A ${kind} media stream is already running in this session`);
|
|
70
|
+
}
|
|
71
|
+
// No await between the check above and the registration below, or concurrent starts could both pass
|
|
72
|
+
let handedOut = false;
|
|
73
|
+
const stream = new MediaStream(source, opts, {
|
|
74
|
+
emit: (event) => {
|
|
75
|
+
if (hasSubscribers(this, event.method)) {
|
|
76
|
+
this.eventEmitter.emit(BIDI_EVENT_NAME, event);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
emitter: this.eventEmitter,
|
|
80
|
+
hasSubscribers: () => hasSubscribers(this, MEDIA_UNITS_EVENT),
|
|
81
|
+
log: this.log,
|
|
82
|
+
onEnded: (id) => {
|
|
83
|
+
// Only ids the client received need to stay known for a late stop
|
|
84
|
+
if (this._mediaStreams?.delete(id) && handedOut) {
|
|
85
|
+
(this._endedMediaStreams ??= new Set()).add(id);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
streams.set(stream.streamId, stream);
|
|
90
|
+
try {
|
|
91
|
+
const info = await stream.start();
|
|
92
|
+
handedOut = true;
|
|
93
|
+
return info;
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
// Stay registered until the teardown is done: it stops the whole device, so nothing may start meanwhile
|
|
97
|
+
await stream.stop('failed to start');
|
|
98
|
+
throw e instanceof TypeError || e instanceof RangeError ? new errors.InvalidArgumentError(e.message) : e;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Stops a media stream started by `mobile: startMediaStream`. Stopping an ended stream is a no-op. */
|
|
102
|
+
export async function mobileStopMediaStream(streamId) {
|
|
103
|
+
const stream = this._mediaStreams?.get(streamId);
|
|
104
|
+
if (!stream) {
|
|
105
|
+
if (this._endedMediaStreams?.has(streamId)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
throw new errors.InvalidArgumentError(`Unknown media stream id '${streamId}'`);
|
|
109
|
+
}
|
|
110
|
+
await stream.stop();
|
|
111
|
+
}
|
|
112
|
+
/** Reports whether media streaming works for the current session, and which kinds/codecs it offers. */
|
|
113
|
+
export async function mobileGetMediaStreamCapabilities() {
|
|
114
|
+
return await getCapabilities(this);
|
|
115
|
+
}
|
|
116
|
+
async function getCapabilities(driver) {
|
|
117
|
+
if (!driver.isSimulator()) {
|
|
118
|
+
return await getDeviceCapabilities(driver);
|
|
119
|
+
}
|
|
120
|
+
const base = {
|
|
121
|
+
source: 'simulator',
|
|
122
|
+
kinds: ['video', 'jpeg'],
|
|
123
|
+
codecs: ['h264', 'hevc'],
|
|
124
|
+
audio: true,
|
|
125
|
+
};
|
|
126
|
+
const major = driver.xcodeVersion?.major;
|
|
127
|
+
if (major !== undefined && major < MIN_SIMULATOR_XCODE_MAJOR) {
|
|
128
|
+
return unsupported(base.source, {
|
|
129
|
+
code: 'xcode_too_old',
|
|
130
|
+
message: `Simulator media streaming requires Xcode ${MIN_SIMULATOR_XCODE_MAJOR}+, found ${major}`,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return { ...base, supported: true };
|
|
134
|
+
}
|
|
135
|
+
async function getDeviceCapabilities(driver) {
|
|
136
|
+
const source = 'device';
|
|
137
|
+
if (!supportsApiLevel27(driver.opts.platformVersion)) {
|
|
138
|
+
return unsupported(source, {
|
|
139
|
+
code: 'os_too_old',
|
|
140
|
+
message: `Real device media streaming requires iOS/tvOS 27+, found ${driver.opts.platformVersion}`,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (!(await driver.remoteXPCFacade.isTunnelTier())) {
|
|
144
|
+
return unsupported(source, {
|
|
145
|
+
code: 'tunnel_required',
|
|
146
|
+
message: 'Real device media streaming requires a RemoteXPC tunnel',
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
if (!(await isDeviceStreamingSupported(driver.remoteXPCFacade))) {
|
|
151
|
+
return unsupported(source, {
|
|
152
|
+
code: 'device_streaming_unsupported',
|
|
153
|
+
message: 'The device does not support media streaming (requires iOS/tvOS 27+)',
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
return unsupported(source, {
|
|
159
|
+
code: 'device_unreachable',
|
|
160
|
+
message: `Cannot ask the device whether it supports media streaming: ${e.message}`,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
let noH264;
|
|
164
|
+
try {
|
|
165
|
+
noH264 = describeMissingH264Encoder(await loadMediaProxy());
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
return unsupported(source, { code: 'media_proxy_unavailable', message: e.message });
|
|
169
|
+
}
|
|
170
|
+
if (noH264) {
|
|
171
|
+
// Still usable as JPEG; the reason says what H.264 (and the audio that rides on it) needs
|
|
172
|
+
return {
|
|
173
|
+
supported: true,
|
|
174
|
+
source,
|
|
175
|
+
kinds: ['jpeg'],
|
|
176
|
+
codecs: [],
|
|
177
|
+
audio: false,
|
|
178
|
+
reason: { code: 'h264_encoder_unavailable', message: noH264 },
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
// media-proxy encodes H.264 only; the device's AAC-ELD audio is transcoded to AAC-LC
|
|
182
|
+
return { supported: true, source, kinds: ['video', 'jpeg'], codecs: ['h264'], audio: true };
|
|
183
|
+
}
|
|
184
|
+
function unsupported(source, reason) {
|
|
185
|
+
return { supported: false, reason, source, kinds: [], codecs: [], audio: false };
|
|
186
|
+
}
|
|
187
|
+
/** Stops all streams of the session; used on session deletion. */
|
|
188
|
+
export async function stopAllMediaStreams() {
|
|
189
|
+
await Promise.all([...(this._mediaStreams?.values() ?? [])].map((s) => s.stop('session ended')));
|
|
190
|
+
this._mediaStreams = undefined;
|
|
191
|
+
this._endedMediaStreams = undefined;
|
|
192
|
+
}
|
|
193
|
+
function hasSubscribers(driver, method) {
|
|
194
|
+
return [method, MEDIA_STREAM_MODULE].some((e) => (driver.bidiEventSubs[e]?.length ?? 0) > 0);
|
|
195
|
+
}
|
|
196
|
+
function validateOpts({ kind, codec, fps, bitrate, quality, scale, audio, batchMs, idleHeartbeatMs, }) {
|
|
197
|
+
if (kind !== 'video' && kind !== 'jpeg') {
|
|
198
|
+
throw new errors.InvalidArgumentError(`'kind' must be either 'video' or 'jpeg', got '${String(kind)}'`);
|
|
199
|
+
}
|
|
200
|
+
const wrongKind = kind === 'video' ? { quality, scale } : { codec, bitrate, audio };
|
|
201
|
+
const offending = Object.entries(wrongKind).filter(([, v]) => v !== undefined);
|
|
202
|
+
if (offending.length) {
|
|
203
|
+
throw new errors.InvalidArgumentError(`${offending.map(([k]) => `'${k}'`).join(', ')} not supported for kind '${kind}'`);
|
|
204
|
+
}
|
|
205
|
+
if (codec !== undefined && codec !== 'h264' && codec !== 'hevc') {
|
|
206
|
+
throw new errors.InvalidArgumentError(`'codec' must be either 'h264' or 'hevc', got '${String(codec)}'`);
|
|
207
|
+
}
|
|
208
|
+
if (audio !== undefined && typeof audio !== 'boolean') {
|
|
209
|
+
throw new errors.InvalidArgumentError(`'audio' must be a boolean, got '${String(audio)}'`);
|
|
210
|
+
}
|
|
211
|
+
const ranges = [
|
|
212
|
+
['fps', fps, 1, MAX_FPS],
|
|
213
|
+
['bitrate', bitrate, 1, MAX_BITRATE],
|
|
214
|
+
['quality', quality, 0, 100],
|
|
215
|
+
['scale', scale, 1, 100],
|
|
216
|
+
];
|
|
217
|
+
for (const [name, value, min, max] of ranges) {
|
|
218
|
+
if (value !== undefined && !(Number.isFinite(value) && value >= min && value <= max)) {
|
|
219
|
+
throw new errors.InvalidArgumentError(`'${name}' must be a number ${max === Infinity ? `>= ${min}` : `between ${min} and ${max}`}, got '${String(value)}'`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (!Number.isInteger(batchMs) || batchMs < 0 || batchMs > MAX_BATCH_MS) {
|
|
223
|
+
throw new errors.InvalidArgumentError(`'batchMs' must be an integer between 0 and ${MAX_BATCH_MS}, got '${String(batchMs)}'`);
|
|
224
|
+
}
|
|
225
|
+
if (!Number.isInteger(idleHeartbeatMs) ||
|
|
226
|
+
(idleHeartbeatMs !== 0 && (idleHeartbeatMs < MIN_IDLE_HEARTBEAT_MS || idleHeartbeatMs > MAX_IDLE_HEARTBEAT_MS))) {
|
|
227
|
+
throw new errors.InvalidArgumentError(`'idleHeartbeatMs' must be 0 or an integer between ${MIN_IDLE_HEARTBEAT_MS} and ${MAX_IDLE_HEARTBEAT_MS}, got '${String(idleHeartbeatMs)}'`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=media-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-stream.js","sourceRoot":"","sources":["../../../lib/commands/media-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAExC,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,YAAY,EACZ,WAAW,EACX,cAAc,EACd,OAAO,EACP,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAC,iBAAiB,EAAE,0BAA0B,EAAC,MAAM,yCAAyC,CAAC;AACtG,OAAO,EAAC,0BAA0B,EAAE,cAAc,EAAC,MAAM,uCAAuC,CAAC;AACjG,OAAO,EAAC,oBAAoB,EAAC,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAC,WAAW,EAAC,MAAM,kCAAkC,CAAC;AAU7D,OAAO,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAcpD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAE1C,IAAe,EACf,KAAkB,EAClB,GAAY,EACZ,OAAgB,EAChB,OAAgB,EAChB,KAAc,EACd,KAAe,EACf,SAAkB,EAClB,UAAkB,gBAAgB,EAClC,kBAA0B,yBAAyB;IAEnD,MAAM,IAAI,GAAyB;QACjC,IAAI;QACJ,KAAK;QACL,GAAG;QACH,OAAO;QACP,OAAO;QACP,KAAK;QACL,KAAK;QACL,SAAS;QACT,OAAO;QACP,eAAe;KAChB,CAAC;IACF,YAAY,CAAC,I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AAM,EAAE,CAAC;QAC7C,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,CAAC,EAAE,CAAC;YACrF,MAAM,IAAI,MAAM,CAAC,oBAAoB,CACnC,IAAI,IAAI,sBAAsB,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,WAAW,GAAG,QAAQ,GAAG,EAAE,UAAU,MAAM,CAAC,KAAK,CAAC,GAAG,CACrH,CAAC;QACJ,CAAC;IACH,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,OAAO,GAAG,YAAY,EAAE,CAAC;QACxE,MAAM,IAAI,MAAM,CAAC,oBAAoB,CACnC,8CAA8C,YAAY,UAAU,MAAM,CAAC,OAAO,CAAC,GAAG,CACvF,CAAC;IACJ,CAAC;IACD,IACE,CAAC,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC;QAClC,CAAC,eAAe,KAAK,CAAC,IAAI,CAAC,eAAe,GAAG,qBAAqB,IAAI,eAAe,GAAG,qBAAqB,CAAC,CAAC,EAC/G,CAAC;QACD,MAAM,IAAI,MAAM,CAAC,oBAAoB,CACnC,qDAAqD,qBAAqB,QAAQ,qBAAqB,UAAU,MAAM,CAAC,eAAe,CAAC,GAAG,CAC5I,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MediaUnit } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Groups units into events that are homogeneous by track, batching each track on its own
|
|
4
|
+
* (a video keyframe always starts a new batch).
|
|
5
|
+
*/
|
|
6
|
+
export declare class UnitBatcher {
|
|
7
|
+
private readonly batchMs;
|
|
8
|
+
private readonly onBatch;
|
|
9
|
+
private pending;
|
|
10
|
+
private timer?;
|
|
11
|
+
constructor(batchMs: number, onBatch: (units: MediaUnit[]) => void);
|
|
12
|
+
push(unit: MediaUnit): void;
|
|
13
|
+
flush(): void;
|
|
14
|
+
close(): void;
|
|
15
|
+
private flushTrack;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=batcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batcher.d.ts","sourceRoot":"","sources":["../../../../lib/device/media-stream/batcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,SAAS,EAAC,MAAM,YAAY,CAAC;AAEtD;;;GAGG;AACH,qBAAa,WAAW;IAKpB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL1B,OAAO,CAAC,OAAO,CAAsC;IACrD,OAAO,CAAC,KAAK,CAAC,CAAiB;gBAGZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI;IAGxD,IAAI,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAc3B,KAAK,IAAI,IAAI;IAQb,KAAK,IAAI,IAAI;IAMb,OAAO,CAAC,UAAU;CAOnB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Groups units into events that are homogeneous by track, batching each track on its own
|
|
3
|
+
* (a video keyframe always starts a new batch).
|
|
4
|
+
*/
|
|
5
|
+
export class UnitBatcher {
|
|
6
|
+
batchMs;
|
|
7
|
+
onBatch;
|
|
8
|
+
pending = new Map();
|
|
9
|
+
timer;
|
|
10
|
+
constructor(batchMs, onBatch) {
|
|
11
|
+
this.batchMs = batchMs;
|
|
12
|
+
this.onBatch = onBatch;
|
|
13
|
+
}
|
|
14
|
+
push(unit) {
|
|
15
|
+
if (unit.track === 'video' && unit.key) {
|
|
16
|
+
this.flushTrack(unit.track);
|
|
17
|
+
}
|
|
18
|
+
const units = this.pending.get(unit.track) ?? [];
|
|
19
|
+
units.push(unit);
|
|
20
|
+
this.pending.set(unit.track, units);
|
|
21
|
+
if (this.batchMs <= 0 || unit.track === 'jpeg') {
|
|
22
|
+
this.flushTrack(unit.track);
|
|
23
|
+
}
|
|
24
|
+
else if (!this.timer) {
|
|
25
|
+
this.timer = setTimeout(() => this.flush(), this.batchMs);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
flush() {
|
|
29
|
+
clearTimeout(this.timer);
|
|
30
|
+
this.timer = undefined;
|
|
31
|
+
for (const track of this.pending.keys()) {
|
|
32
|
+
this.flushTrack(track);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
close() {
|
|
36
|
+
clearTimeout(this.timer);
|
|
37
|
+
this.timer = undefined;
|
|
38
|
+
this.pending.clear();
|
|
39
|
+
}
|
|
40
|
+
flushTrack(track) {
|
|
41
|
+
const units = this.pending.get(track);
|
|
42
|
+
if (units?.length) {
|
|
43
|
+
this.pending.delete(track);
|
|
44
|
+
this.onBatch(units);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=batcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batcher.js","sourceRoot":"","sources":["../../../../lib/device/media-stream/batcher.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,OAAO,WAAW;IAKH;IACA;IALX,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC7C,KAAK,CAAkB;IAE/B,YACmB,OAAe,EACf,OAAqC;QADrC,YAAO,GAAP,OAAO,CAAQ;QACf,YAAO,GAAP,OAAO,CAA8B;IACrD,CAAC;IAEJ,IAAI,CAAC,IAAe;QAClB,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YACvC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;QACD,MAAM,KAAK,GAAG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;QACtB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const MEDIA_STREAM_MODULE = "appium:mediaStream";
|
|
2
|
+
export declare const MEDIA_UNITS_EVENT = "appium:mediaStream.units";
|
|
3
|
+
export declare const MEDIA_STARTED_EVENT = "appium:mediaStream.started";
|
|
4
|
+
export declare const MEDIA_FORMAT_CHANGED_EVENT = "appium:mediaStream.formatChanged";
|
|
5
|
+
export declare const MEDIA_ENDED_EVENT = "appium:mediaStream.ended";
|
|
6
|
+
export declare const BACKPRESSURE_EVENT_NAME = "bidiBackpressure";
|
|
7
|
+
export declare const KEYFRAME_REQUEST_MIN_INTERVAL_MS = 1000;
|
|
8
|
+
export declare const FIRST_UNIT_TIMEOUT_MS = 5000;
|
|
9
|
+
export declare const DEFAULT_BATCH_MS = 40;
|
|
10
|
+
export declare const DEFAULT_IDLE_HEARTBEAT_MS = 1000;
|
|
11
|
+
export declare const MIN_SIMULATOR_XCODE_MAJOR = 26;
|
|
12
|
+
export declare const MAX_FPS = 120;
|
|
13
|
+
export declare const MAX_BITRATE = 100000000;
|
|
14
|
+
export declare const MAX_BATCH_MS = 1000;
|
|
15
|
+
export declare const MIN_IDLE_HEARTBEAT_MS = 100;
|
|
16
|
+
export declare const MAX_IDLE_HEARTBEAT_MS = 60000;
|
|
17
|
+
export declare const MAX_DISPLAY_ID = 4294967295;
|
|
18
|
+
export declare const SOURCE_START_TIMEOUT_MS = 60000;
|
|
19
|
+
export declare const SOURCE_STOP_TIMEOUT_MS = 15000;
|
|
20
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../lib/device/media-stream/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,uBAAuB,CAAC;AACxD,eAAO,MAAM,iBAAiB,6BAAiC,CAAC;AAChE,eAAO,MAAM,mBAAmB,+BAAmC,CAAC;AACpE,eAAO,MAAM,0BAA0B,qCAAyC,CAAC;AACjF,eAAO,MAAM,iBAAiB,6BAAiC,CAAC;AAChE,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAC1D,eAAO,MAAM,gCAAgC,OAAO,CAAC;AAErD,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAC9C,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C,eAAO,MAAM,OAAO,MAAM,CAAC;AAC3B,eAAO,MAAM,WAAW,YAAc,CAAC;AACvC,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,qBAAqB,MAAM,CAAC;AACzC,eAAO,MAAM,qBAAqB,QAAS,CAAC;AAC5C,eAAO,MAAM,cAAc,aAAa,CAAC;AAEzC,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAC9C,eAAO,MAAM,sBAAsB,QAAS,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const MEDIA_STREAM_MODULE = 'appium:mediaStream';
|
|
2
|
+
export const MEDIA_UNITS_EVENT = `${MEDIA_STREAM_MODULE}.units`;
|
|
3
|
+
export const MEDIA_STARTED_EVENT = `${MEDIA_STREAM_MODULE}.started`;
|
|
4
|
+
export const MEDIA_FORMAT_CHANGED_EVENT = `${MEDIA_STREAM_MODULE}.formatChanged`;
|
|
5
|
+
export const MEDIA_ENDED_EVENT = `${MEDIA_STREAM_MODULE}.ended`;
|
|
6
|
+
export const BACKPRESSURE_EVENT_NAME = 'bidiBackpressure';
|
|
7
|
+
export const KEYFRAME_REQUEST_MIN_INTERVAL_MS = 1000;
|
|
8
|
+
// The encoder reports its first unit right after it starts, regardless of screen activity
|
|
9
|
+
export const FIRST_UNIT_TIMEOUT_MS = 5000;
|
|
10
|
+
export const DEFAULT_BATCH_MS = 40;
|
|
11
|
+
export const DEFAULT_IDLE_HEARTBEAT_MS = 1000;
|
|
12
|
+
export const MIN_SIMULATOR_XCODE_MAJOR = 26;
|
|
13
|
+
// Upper bounds for client-supplied options, so one request cannot overload the server
|
|
14
|
+
export const MAX_FPS = 120;
|
|
15
|
+
export const MAX_BITRATE = 100_000_000;
|
|
16
|
+
export const MAX_BATCH_MS = 1000;
|
|
17
|
+
export const MIN_IDLE_HEARTBEAT_MS = 100;
|
|
18
|
+
export const MAX_IDLE_HEARTBEAT_MS = 60_000;
|
|
19
|
+
export const MAX_DISPLAY_ID = 0xffffffff;
|
|
20
|
+
// Bounds the wait on the device/simulator, so a hung source cannot block the session teardown
|
|
21
|
+
export const SOURCE_START_TIMEOUT_MS = 60_000;
|
|
22
|
+
export const SOURCE_STOP_TIMEOUT_MS = 15_000;
|
|
23
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../lib/device/media-stream/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AACxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,mBAAmB,QAAQ,CAAC;AAChE,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,mBAAmB,UAAU,CAAC;AACpE,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,mBAAmB,gBAAgB,CAAC;AACjF,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,mBAAmB,QAAQ,CAAC;AAChE,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AAC1D,MAAM,CAAC,MAAM,gCAAgC,GAAG,IAAI,CAAC;AACrD,0FAA0F;AAC1F,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAC1C,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AACnC,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAC9C,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAC5C,sFAAsF;AACtF,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAC;AAC3B,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;AACvC,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC;AACjC,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AACzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAC5C,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;AACzC,8FAA8F;AAC9F,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAC9C,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AppiumLogger } from '@appium/types';
|
|
2
|
+
import type { RemoteXPCFacade } from '../remote-xpc/facade.js';
|
|
3
|
+
import type { MediaSource, SourceUnit, StartMediaStreamOpts } from './types.js';
|
|
4
|
+
/** Asks the device whether it can stream its screen; opens and closes a display service for that */
|
|
5
|
+
export declare function isDeviceStreamingSupported(facade: RemoteXPCFacade): Promise<boolean>;
|
|
6
|
+
/**
|
|
7
|
+
* Real device (iOS/tvOS 27+): remotexpc captures the HEVC screen stream over the tunnel and
|
|
8
|
+
* media-proxy transcodes it to H.264 or MJPEG.
|
|
9
|
+
*/
|
|
10
|
+
export declare class DeviceMediaSource implements MediaSource {
|
|
11
|
+
private readonly facade;
|
|
12
|
+
private readonly opts;
|
|
13
|
+
private readonly log;
|
|
14
|
+
private display?;
|
|
15
|
+
private capture?;
|
|
16
|
+
private audioCapture?;
|
|
17
|
+
private audioFeeder?;
|
|
18
|
+
private transcoder?;
|
|
19
|
+
private feeder?;
|
|
20
|
+
private orientationTimer?;
|
|
21
|
+
private infoService?;
|
|
22
|
+
private rotation;
|
|
23
|
+
private polling;
|
|
24
|
+
private failure?;
|
|
25
|
+
private starting?;
|
|
26
|
+
private stopping?;
|
|
27
|
+
constructor(facade: RemoteXPCFacade, opts: StartMediaStreamOpts, log: AppiumLogger);
|
|
28
|
+
start(): Promise<void>;
|
|
29
|
+
private open;
|
|
30
|
+
private readGeometry;
|
|
31
|
+
private pollOrientation;
|
|
32
|
+
units(): AsyncGenerator<SourceUnit>;
|
|
33
|
+
requestKeyFrame(): Promise<boolean>;
|
|
34
|
+
stop(): Promise<void>;
|
|
35
|
+
private teardown;
|
|
36
|
+
private feed;
|
|
37
|
+
private feedAudio;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=device-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device-source.d.ts","sourceRoot":"","sources":["../../../../lib/device/media-stream/device-source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAEhD,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAI7D,OAAO,KAAK,EAAC,WAAW,EAAE,UAAU,EAAE,oBAAoB,EAAC,MAAM,YAAY,CAAC;AA6B9E,oGAAoG;AACpG,wBAAsB,0BAA0B,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAS1F;AAED;;;GAGG;AACH,qBAAa,iBAAkB,YAAW,WAAW;IAgBjD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAjBtB,OAAO,CAAC,OAAO,CAAC,CAAU;IAC1B,OAAO,CAAC,OAAO,CAAC,CAAU;IAC1B,OAAO,CAAC,YAAY,CAAC,CAAe;IACpC,OAAO,CAAC,WAAW,CAAC,CAAgB;IACpC,OAAO,CAAC,UAAU,CAAC,CAAa;IAChC,OAAO,CAAC,MAAM,CAAC,CAAgB;IAC/B,OAAO,CAAC,gBAAgB,CAAC,CAAiB;IAC1C,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAC,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAC,CAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,CAAgB;gBAGd,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,oBAAoB,EAC1B,GAAG,EAAE,YAAY;IAG9B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAKd,IAAI;YAuEJ,YAAY;YAaZ,eAAe;IAoBtB,KAAK,IAAI,cAAc,CAAC,UAAU,CAAC;IAuBpC,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAInC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAMb,QAAQ;YAmBR,IAAI;YAiBJ,SAAS;CASxB"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { loadRemoteXPCModule } from '../remote-xpc/module-loader.js';
|
|
2
|
+
import { explainEncoderError, loadMediaProxy } from './media-proxy.js';
|
|
3
|
+
import { parseDisplayGeometry } from './orientation.js';
|
|
4
|
+
/** How often the display's orientation is read; a rotation shows up within this time (plus its animation) */
|
|
5
|
+
const ORIENTATION_POLL_MS = 1000;
|
|
6
|
+
/** The device sends one IDR and its picture drifts after large screen changes, so remotexpc asks for new ones */
|
|
7
|
+
const KEYFRAME_INTERVAL_MS = 2000;
|
|
8
|
+
/** The device's video RTP clock (400 ticks per frame at 60 fps), not the 90 kHz of RFC 7798 */
|
|
9
|
+
const VIDEO_CLOCK_RATE = 24_000;
|
|
10
|
+
/** Asks the device whether it can stream its screen; opens and closes a display service for that */
|
|
11
|
+
export async function isDeviceStreamingSupported(facade) {
|
|
12
|
+
const display = (await facade.requireTunnelService('media streaming', (services) => services.startDisplayService(facade.udid)));
|
|
13
|
+
try {
|
|
14
|
+
return await display.isStreamingSupported();
|
|
15
|
+
}
|
|
16
|
+
finally {
|
|
17
|
+
await display.close().catch(() => { });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Real device (iOS/tvOS 27+): remotexpc captures the HEVC screen stream over the tunnel and
|
|
22
|
+
* media-proxy transcodes it to H.264 or MJPEG.
|
|
23
|
+
*/
|
|
24
|
+
export class DeviceMediaSource {
|
|
25
|
+
facade;
|
|
26
|
+
opts;
|
|
27
|
+
log;
|
|
28
|
+
display;
|
|
29
|
+
capture;
|
|
30
|
+
audioCapture;
|
|
31
|
+
audioFeeder;
|
|
32
|
+
transcoder;
|
|
33
|
+
feeder;
|
|
34
|
+
orientationTimer;
|
|
35
|
+
infoService;
|
|
36
|
+
rotation = 0;
|
|
37
|
+
polling = false;
|
|
38
|
+
failure;
|
|
39
|
+
starting;
|
|
40
|
+
stopping;
|
|
41
|
+
constructor(facade, opts, log) {
|
|
42
|
+
this.facade = facade;
|
|
43
|
+
this.opts = opts;
|
|
44
|
+
this.log = log;
|
|
45
|
+
}
|
|
46
|
+
async start() {
|
|
47
|
+
this.starting = this.open();
|
|
48
|
+
await this.starting;
|
|
49
|
+
}
|
|
50
|
+
async open() {
|
|
51
|
+
const { opts } = this;
|
|
52
|
+
const mediaProxy = await loadMediaProxy();
|
|
53
|
+
const { ScreenStreamCapture, AudioStreamCapture, XPCUUID, AAC_ELD_FORMAT } = await loadRemoteXPCModule();
|
|
54
|
+
const withAudio = opts.kind === 'video' && Boolean(opts.audio);
|
|
55
|
+
const displayId = opts.displayId === undefined ? undefined : Number(opts.displayId);
|
|
56
|
+
const geometry = await this.readGeometry(displayId);
|
|
57
|
+
const input = {
|
|
58
|
+
videoClockRate: VIDEO_CLOCK_RATE,
|
|
59
|
+
// Without the size the padding stays; without the orientation a landscape UI stays turned
|
|
60
|
+
...(geometry && isEven(geometry.width) && isEven(geometry.height)
|
|
61
|
+
? { crop: { width: geometry.width, height: geometry.height } }
|
|
62
|
+
: {}),
|
|
63
|
+
rotation: geometry?.rotation ?? 0,
|
|
64
|
+
};
|
|
65
|
+
this.rotation = input.rotation;
|
|
66
|
+
// Fails here, before the device starts streaming, if the addon or an encoder is missing
|
|
67
|
+
let transcoder;
|
|
68
|
+
try {
|
|
69
|
+
transcoder =
|
|
70
|
+
opts.kind === 'video'
|
|
71
|
+
? mediaProxy.createTranscoder({
|
|
72
|
+
codec: 'h264',
|
|
73
|
+
fps: opts.fps,
|
|
74
|
+
bitrate: opts.bitrate,
|
|
75
|
+
...(withAudio ? { audio: true, audioSpecificConfig: AAC_ELD_FORMAT.audioSpecificConfig } : {}),
|
|
76
|
+
...input,
|
|
77
|
+
})
|
|
78
|
+
: mediaProxy.createTranscoder({
|
|
79
|
+
codec: 'mjpeg',
|
|
80
|
+
fps: opts.fps,
|
|
81
|
+
quality: opts.quality,
|
|
82
|
+
scale: opts.scale,
|
|
83
|
+
...input,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
throw explainEncoderError(e);
|
|
88
|
+
}
|
|
89
|
+
this.transcoder = transcoder;
|
|
90
|
+
try {
|
|
91
|
+
const display = (await this.facade.requireTunnelService('media streaming', (services) => services.startDisplayService(this.facade.udid)));
|
|
92
|
+
this.display = display;
|
|
93
|
+
if (!(await display.isStreamingSupported())) {
|
|
94
|
+
throw new Error('The device does not support media streaming (requires iOS/tvOS 27+)');
|
|
95
|
+
}
|
|
96
|
+
// One session id pairs the video and audio streams, as Xcode's mirror does
|
|
97
|
+
const clientSessionId = withAudio ? XPCUUID.random() : undefined;
|
|
98
|
+
this.capture = (await ScreenStreamCapture.start(display, {
|
|
99
|
+
displayId,
|
|
100
|
+
keyFrameIntervalMs: KEYFRAME_INTERVAL_MS,
|
|
101
|
+
...(clientSessionId ? { clientSessionId } : {}),
|
|
102
|
+
}));
|
|
103
|
+
if (clientSessionId) {
|
|
104
|
+
this.audioCapture = (await AudioStreamCapture.start(display, {
|
|
105
|
+
clientSessionId,
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
this.orientationTimer = setInterval(() => void this.pollOrientation(displayId), ORIENTATION_POLL_MS);
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
await this.teardown();
|
|
112
|
+
throw e;
|
|
113
|
+
}
|
|
114
|
+
this.feeder = this.feed(this.capture, transcoder);
|
|
115
|
+
if (this.audioCapture) {
|
|
116
|
+
this.audioFeeder = this.feedAudio(this.audioCapture, transcoder);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Optional: a device that cannot report its display still streams, just without crop and rotation
|
|
120
|
+
async readGeometry(displayId) {
|
|
121
|
+
try {
|
|
122
|
+
const service = (await this.facade.requireTunnelService('media streaming', (services) => services.startCoreDeviceInfoService(this.facade.udid)));
|
|
123
|
+
this.infoService = service;
|
|
124
|
+
return parseDisplayGeometry(await service.getDisplayInfo(), displayId);
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
this.log.warn(`Cannot read the display geometry, the stream is not cropped or rotated: ${e.message}`);
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async pollOrientation(displayId) {
|
|
132
|
+
const { infoService, transcoder } = this;
|
|
133
|
+
if (!infoService || !transcoder || this.polling) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.polling = true;
|
|
137
|
+
try {
|
|
138
|
+
const rotation = parseDisplayGeometry(await infoService.getDisplayInfo(), displayId)?.rotation;
|
|
139
|
+
if (rotation !== undefined && rotation !== this.rotation) {
|
|
140
|
+
this.log.debug(`The display rotated from ${this.rotation} to ${rotation} degrees`);
|
|
141
|
+
this.rotation = rotation;
|
|
142
|
+
transcoder.setRotation(rotation);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
this.log.debug(`Cannot read the display orientation: ${e.message}`);
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
this.polling = false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async *units() {
|
|
153
|
+
const { transcoder } = this;
|
|
154
|
+
if (!transcoder) {
|
|
155
|
+
throw new Error('The source has not been started');
|
|
156
|
+
}
|
|
157
|
+
const isVideo = this.opts.kind === 'video';
|
|
158
|
+
for await (const u of transcoder.units()) {
|
|
159
|
+
const { data, sequence, timestampMicros } = u;
|
|
160
|
+
yield isVideo
|
|
161
|
+
? {
|
|
162
|
+
track: u.track,
|
|
163
|
+
data,
|
|
164
|
+
isKeyFrame: u.isKeyFrame,
|
|
165
|
+
sequence,
|
|
166
|
+
timestampMicros,
|
|
167
|
+
}
|
|
168
|
+
: { track: 'jpeg', data, isKeyFrame: true, sequence, timestampMicros };
|
|
169
|
+
}
|
|
170
|
+
if (this.failure) {
|
|
171
|
+
throw this.failure;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async requestKeyFrame() {
|
|
175
|
+
return (await this.capture?.requestKeyFrame()) ?? false;
|
|
176
|
+
}
|
|
177
|
+
async stop() {
|
|
178
|
+
// A stop that arrives while start() is pending must not miss what it creates
|
|
179
|
+
await this.starting?.catch(() => { });
|
|
180
|
+
await this.teardown();
|
|
181
|
+
}
|
|
182
|
+
async teardown() {
|
|
183
|
+
this.stopping ??= (async () => {
|
|
184
|
+
clearInterval(this.orientationTimer);
|
|
185
|
+
// The capture's own stop() also tells the device to stop streaming
|
|
186
|
+
await this.capture?.stop().catch((e) => this.log.debug(`Cannot stop the capture: ${e.message}`));
|
|
187
|
+
await this.audioCapture
|
|
188
|
+
?.stop()
|
|
189
|
+
.catch((e) => this.log.debug(`Cannot stop the audio capture: ${e.message}`));
|
|
190
|
+
await this.transcoder?.close().catch((e) => this.log.debug(`Cannot close the transcoder: ${e.message}`));
|
|
191
|
+
await Promise.resolve(this.infoService?.close?.()).catch((e) => this.log.debug(`Cannot close the info service: ${e.message}`));
|
|
192
|
+
await this.display?.close().catch((e) => this.log.debug(`Cannot close the display service: ${e.message}`));
|
|
193
|
+
await this.feeder;
|
|
194
|
+
await this.audioFeeder;
|
|
195
|
+
})();
|
|
196
|
+
await this.stopping;
|
|
197
|
+
}
|
|
198
|
+
async feed(capture, transcoder) {
|
|
199
|
+
try {
|
|
200
|
+
for await (const au of capture.accessUnits()) {
|
|
201
|
+
if (au.isKeyFrame) {
|
|
202
|
+
// The device's IDR is a clean reference: start a new H.264 GOP from it
|
|
203
|
+
transcoder.requestKeyFrame();
|
|
204
|
+
}
|
|
205
|
+
transcoder.push(au);
|
|
206
|
+
}
|
|
207
|
+
await transcoder.end();
|
|
208
|
+
}
|
|
209
|
+
catch (e) {
|
|
210
|
+
this.failure = e;
|
|
211
|
+
await transcoder.close().catch(() => { });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// Audio is best effort: a failing audio stream must not end the video
|
|
215
|
+
async feedAudio(capture, transcoder) {
|
|
216
|
+
try {
|
|
217
|
+
for await (const au of capture.accessUnits()) {
|
|
218
|
+
transcoder.pushAudio(au);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
this.log.warn(`The audio stream ended: ${e.message}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function isEven(value) {
|
|
227
|
+
return value % 2 === 0;
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=device-source.js.map
|