Skip to content

Control a real USB-connected iPhone from Linux (no Mac, no paid developer account) and expose it to AI agents as MCP tools

fix(wda): stop WDA re-encoding the viewer picture so iOS doesn't kill it for CPU (#55)

Qinghe Li75c9cbd39dba
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a64c66b..c2f10ad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ All notable changes to this project are documented here. The format is based on
### Fixed
+- With the control page open in a browser that can't decode HEVC (Firefox, Chrome on most Linux) or on a device below iOS 27, WDA is no longer killed by iOS every 1–2 minutes: the picture is taken at full size and turned upright on the page in landscape, so WDA passes on the screenshot the phone encodes in hardware instead of scaling, rotating and re-encoding every frame, which took more CPU than iOS allows.
- Piping output into a program that exits early, such as `iphone-control status | head -1`, no longer crashes with "Broken pipe"; the command ends quietly like other command-line tools.
- Touches on the control page respond faster again: a press no longer measures the screen size on WDA each time (about 0.1–0.2 s, new in 0.2.2); the size is measured on rotation and at most once a minute. Moving the mouse over the picture also keeps the touch session open, so the first press after a pause doesn't wait about 0.5 s for it to reopen.
diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md
index 45406e0..51daf2b 100644
--- a/CHANGELOG.zh-CN.md
+++ b/CHANGELOG.zh-CN.md
@@ -19,6 +19,7 @@
### 修复
+- 控制台开着、浏览器解不了 HEVC(Firefox、多数 Linux 上的 Chrome)或设备低于 iOS 27 时,WDA 不再每 1~2 分钟被 iOS 杀掉一次:画面改成原尺寸、横屏时由页面转正,WDA 直接转发手机硬件编好的截图,不再逐帧缩放、旋转、重新编码,CPU 不再超出 iOS 的上限。
- `iphone-control status | head -1` 这类把输出接给提前退出的程序的用法,不再报 “Broken pipe” 崩溃,而是像其他命令行工具一样直接结束。
- 控制台的触控恢复灵敏:按下时不再每次都向 WDA 量屏幕尺寸(每次约 0.1~0.2 秒,0.2.2 引入),只在转屏时和最多每分钟量一次。鼠标在画面上移动时也保持触控会话打开,停顿后的第一下不用再等约 0.5 秒重开。
diff --git a/apps/iphone-control/src/video/ffmpeg.rs b/apps/iphone-control/src/video/ffmpeg.rs
index ee5bc87..1ca7be0 100644
--- a/apps/iphone-control/src/video/ffmpeg.rs
+++ b/apps/iphone-control/src/video/ffmpeg.rs
@@ -184,7 +184,8 @@ fn bitrate(qp: u8) -> String {
/// The full ffmpeg command line (without the program) for frames of `w`×`h`. `old`: ffmpeg before 5.1
pub fn args(kind: &Kind, w: u32, h: u32, qp: u8, old: bool) -> Vec<String> {
- // 4:2:0 needs even sizes (the phone's frames are 968×2097 at 75%): stretched by at most one pixel
+ // 4:2:0 needs even sizes (an odd one comes from a phone whose screen has one, or WDA scaling): stretched by at
+ // most one pixel
let (w, h) = (w + (w & 1), h + (h & 1));
let qp_s = qp.to_string();
let sw_scale = format!("scale={w}:{h},format=nv12");
diff --git a/apps/iphone-control/src/viewer.html b/apps/iphone-control/src/viewer.html
index a02e034..961a1d1 100644
--- a/apps/iphone-control/src/viewer.html
+++ b/apps/iphone-control/src/viewer.html
@@ -1326,9 +1326,19 @@ const turnsEl = $('#turns'), stopDialog = $('#stop-dialog'), deviceEl = $('#devi
/* 实时画面:H.264 画在 canvas 上(见「H.264 画面」),否则是 MJPEG 的 img */
const cv = $('#live-v'), cvx = cv.getContext('2d');
const V = { on: false, off: false, noDevice: false, device: false, crop: false, rot: null, frameRotation: null, codecName: '', ctrl: null, dec: null, got: false, label: '', ts: 0, bytes: 0, rate: null, stream: '', recv: 0, acked: 0, acking: false };
-const picEl = () => V.on ? cv : live;
-const picW = () => V.on ? cv.width : live.naturalWidth;
-const picH = () => V.on ? cv.height : live.naturalHeight;
+/* MJPEG 画面横屏时也画在 canvas 上转正(见 mjpegTurn) */
+const M = { on: false, raf: 0 };
+const onCanvas = () => V.on || M.on;
+const picEl = () => onCanvas() ? cv : live;
+const picW = () => onCanvas() ? cv.width : live.naturalWidth;
+const picH = () => onCanvas() ? cv.height : live.naturalHeight;
+/* WDA 的画面(本机编码的 H.264、MJPEG)不在手机上转正:WDA 逐帧旋转、重新编码会让 CPU 超出 iOS 的上限,WDA 被杀。
+ * iPhone 横屏时帧还是竖的、内容侧着,这里按界面方向转正(同手机自己的视频);iPad 的帧横屏时本来就是横的,不转。
+ * 转屏后视图 id 会变,页面重连画面,所以按出帧时的方向判断就够了 */
+function wdaTurn(w, h) {
+ const r = S.display?.rotation;
+ return (r === 90 || r === 270) && w < h ? r : 0;
+}
let live = $('#live');
let feedId = '', feedEpoch = 0, retryTimer = 0, infoSequence = 0;
@@ -2114,7 +2124,7 @@ function feedError() {
if (S.stream === 'error') return;
cancelGestures(); ++feedEpoch;
clearTimeout(firstFrameTimer); S.stream = 'error'; S.rtt = null;
- stopVideo(); cv.hidden = true; live.style.visibility = 'hidden'; live.removeAttribute('src');
+ stopMjpegTurn(); stopVideo(); cv.hidden = true; live.style.visibility = 'hidden'; live.removeAttribute('src');
marks.replaceChildren(); hoverDot = null; S.elements = []; S.elState = 'idle'; renderElements();
applyZoom(); showStageNote(); renderFeed(); renderChips();
const epoch = feedEpoch;
@@ -2135,7 +2145,28 @@ function refreshFrame(reoriented = false) {
frameWidth = picW(); frameHeight = picH();
setRatio(frameWidth, frameHeight); syncMarksBox(); renderElements(); renderFeed(); renderChips();
}
+/* MJPEG 帧是竖的而界面是横的:img 照常接收(透明),每个动画帧把它转正画到 canvas 上。iPhone 的截图带 EXIF 方向,
+ * 浏览器显示 img 时已经按它转正(naturalWidth 已是横的),这里就不转;没有方向标记的帧才用得上 */
+function mjpegTurn() {
+ const sw = live.naturalWidth, sh = live.naturalHeight, r = wdaTurn(sw, sh);
+ if (!r) { stopMjpegTurn(); return; }
+ M.on = true; cv.width = sh; cv.height = sw; cv.hidden = false; live.style.opacity = '0';
+ cancelAnimationFrame(M.raf);
+ const draw = () => {
+ if (!M.on) return;
+ cvx.save(); cvx.translate(sh / 2, sw / 2); cvx.rotate(r * Math.PI / 180);
+ cvx.drawImage(live, -sw / 2, -sh / 2, sw, sh); cvx.restore();
+ M.raf = requestAnimationFrame(draw);
+ };
+ draw();
+}
+function stopMjpegTurn() {
+ if (!M.on) return;
+ M.on = false; cancelAnimationFrame(M.raf); live.style.opacity = '';
+ if (!V.on) cv.hidden = true;
+}
function connect() {
+ stopMjpegTurn();
cancelGestures(); const epoch = ++feedEpoch;
clearTimeout(firstFrameTimer); clearTimeout(retryTimer);
stopVideo(); cv.hidden = true;
@@ -2152,7 +2183,7 @@ function connect() {
V.on = true; next.hidden = true; cv.style.visibility = 'hidden'; cv.hidden = false;
startVideo(q, dev);
} else {
- next.onload = () => { if (epoch === feedEpoch) refreshFrame(); };
+ next.onload = () => { if (epoch === feedEpoch) { mjpegTurn(); refreshFrame(); } };
next.onerror = () => { if (epoch === feedEpoch) feedError(); };
next.src = '/stream?' + q;
}
@@ -2193,7 +2224,7 @@ async function startVideo(q, dev) {
const pw = Math.min(S.size.w, S.size.h), ph = Math.max(S.size.w, S.size.h), k = Math.round(sw / pw) || 1;
sw = Math.min(sw, Math.round(pw * k)); sh = Math.min(sh, Math.round(ph * k));
}
- const r = V.crop ? (V.rot ?? S.display?.rotation ?? 0) : 0, turned = r === 90 || r === 270;
+ const r = V.crop ? (V.rot ?? S.display?.rotation ?? 0) : wdaTurn(sw, sh), turned = r === 90 || r === 270;
const W = turned ? sh : sw, H = turned ? sw : sh;
const resized = cv.width !== W || cv.height !== H;
if (resized) { cv.width = W; cv.height = H; }
diff --git a/crates/ictl-daemon/src/supervise.rs b/crates/ictl-daemon/src/supervise.rs
index 2309e5d..b81ff90 100644
--- a/crates/ictl-daemon/src/supervise.rs
+++ b/crates/ictl-daemon/src/supervise.rs
@@ -461,10 +461,6 @@ impl Daemon {
}
g.dev.ddi_failures = 0;
g.runner = Some(runner);
- // verified on an iPhone only; iPads keep what they did
- if g.info.as_ref().is_some_and(|i| i.product_type.starts_with("iPhone")) {
- client.keep_stream_upright();
- }
// the live viewer's picture at 60 fps, so it follows the pointer (see `WdaClient::fast_stream`)
client.fast_stream();
g.wda = Some(client);
diff --git a/crates/ictl-wda/src/client.rs b/crates/ictl-wda/src/client.rs
index c883f35..fa14729 100644
--- a/crates/ictl-wda/src/client.rs
+++ b/crates/ictl-wda/src/client.rs
@@ -73,9 +73,16 @@ impl IdleSettings {
pub const NO_COOL_OFF: Self = Self { wait_for_idle_timeout: 1.0, animation_cool_off_timeout: 0.0 };
}
-/// Frames a second and size (percent) of WDA's MJPEG stream with [`WdaClient::fast_stream`]
+/// Frames a second and size (percent) of WDA's MJPEG stream with [`WdaClient::fast_stream`].
+///
+/// Full size, so WDA passes on the JPEG that testmanagerd encodes in hardware. Any other size makes WDA decode,
+/// scale (CoreGraphics) and re-encode every frame: at 75 % that was 86–93 % of a core on an iPhone 15 Pro Max
+/// (iOS 27.0.1), and iOS kills a process above 80 % over 60 s (`cpu_resource_fatal`), so with the picture open WDA
+/// was killed every 1.5–2.5 minutes. At 100 % it delivers the same ~34 fps there, with smaller frames
+/// (1290×2796, about 80 KB against 104 KB), and ran 15 minutes without being killed. Set explicitly: a WDA left
+/// running in the background (`ICTL_WDA_DETACHED`) keeps the value an older version set
const MJPEG_FPS: u32 = 60;
-const MJPEG_SCALE: u32 = 75;
+const MJPEG_SCALE: u32 = 100;
/// 主屏、锁屏、系统弹窗所属的进程
pub const SPRINGBOARD: &str = "com.apple.springboard";
@@ -124,7 +131,6 @@ pub struct WdaClient<T> {
idle_baseline: Option<IdleSettings>,
/// What WDA has now, as far as we know: sending the same again is a wasted round trip
idle_current: Option<IdleSettings>,
- upright_stream: bool,
/// See [`Self::fast_stream`]
fast_stream: bool,
}
@@ -140,7 +146,6 @@ impl<T: Transport> WdaClient<T> {
lock_state_trusted: false,
idle_baseline: None,
idle_current: None,
- upright_stream: false,
fast_stream: false,
}
}
@@ -197,15 +202,14 @@ impl<T: Transport> WdaClient<T> {
.to_owned();
self.session = Some(id.clone());
self.idle_current = None;
- if self.upright_stream || self.fast_stream {
- let mut settings = serde_json::Map::new();
- if self.fast_stream {
- settings.insert("mjpegServerFramerate".into(), MJPEG_FPS.into());
- settings.insert("mjpegScalingFactor".into(), MJPEG_SCALE.into());
- }
- if self.upright_stream {
- settings.insert("mjpegFixOrientation".into(), true.into());
- }
+ if self.fast_stream {
+ // fixOrientation explicitly off: a WDA left running in the background (`ICTL_WDA_DETACHED`) keeps what an
+ // older version set
+ let settings = json!({
+ "mjpegServerFramerate": MJPEG_FPS,
+ "mjpegScalingFactor": MJPEG_SCALE,
+ "mjpegFixOrientation": false,
+ });
let path = format!("/session/{id}/appium/settings");
if let Err(e) = self.call("POST", &path, Some(json!({"settings": settings})), DEFAULT_TIMEOUT).await {
tracing::debug!("MJPEG settings: {e}");
@@ -494,16 +498,12 @@ impl<T: Transport> WdaClient<T> {
self.quick_gesture(&swipe_steps(from, to, ms), IdleSettings::NO_COOL_OFF).await
}
- /// Ask WDA to turn the MJPEG frames with the interface, set with each new session. On an iPhone they otherwise stay
- /// portrait with sideways content when the screen is landscape, so the live viewer shows them wrong
- pub fn keep_stream_upright(&mut self) {
- self.upright_stream = true;
- }
-
- /// The MJPEG stream (the live viewer) at [`MJPEG_FPS`] frames a second and [`MJPEG_SCALE`]% of the screen's
- /// pixels instead of WDA's 10 at full size, set with each new session: the picture follows a drag closely.
- /// Measured on an iPhone 18 Pro Max (iOS 27.2.1): about 50 fps at 34 KB a frame, and element-tree reads no slower
- /// while it streams. WDA only captures while a client is connected
+ /// The MJPEG stream (the live viewer) at up to [`MJPEG_FPS`] frames a second instead of WDA's 10, at full size
+ /// ([`MJPEG_SCALE`], why not smaller) and never turned upright, set with each new session: the picture follows a
+ /// drag closely. In landscape the frames stay portrait with the content sideways (on an iPhone; an iPad's are
+ /// already landscape) and the viewer page turns them by the interface rotation, as it does the phone's own video:
+ /// `mjpegFixOrientation` makes WDA decode, rotate and re-encode every frame, 92 % of a core on an iPhone 15 Pro Max
+ /// in landscape, and iOS killed it within two minutes. WDA only captures while a client is connected
pub fn fast_stream(&mut self) {
self.fast_stream = true;
}
diff --git a/docs/architecture.md b/docs/architecture.md
index e2f1526..d5588cc 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -45,7 +45,7 @@
- MCP 进程由 AI 客户端直接调用二进制拉起,短命且可能同时有多个;设备连接(尤其是 HID 需要的显示媒体流、WDA 的 XCTest 会话)只能有一个持有者。
- 不开 TCP 端口,避免重蹈 `ios forward` 监听所有网卡的覆辙。WDA 本身也通过 idevice 的 provider 直连设备端口,**本机不再监听 8100**。如需给外部工具用,`iphone-control wda-bridge` 显式开启,只绑 127.0.0.1,且只转发 Host 头是 `localhost`/`127.0.0.1`/`[::1]` 的请求(挡住 DNS rebinding)。注意**本机的任何用户都能连上 bridge**,而 WDA 没有认证,用完就停。
- `iphone-control viewer` 同样显式开启、只绑 127.0.0.1、检查 Host 头:页面看 WDA 的 MJPEG 流(手机上的 9100 端口,经 usbmuxd,只读);点击、滑动、输入、按键是 POST,还要检查 `Origin` 是页面本身、内容类型是 JSON,然后作为普通请求发给守护进程,和 agent 的调用排队、自动解锁。它跟着守护进程控制的设备:在本页、别的页面、`iphone-control select`、MCP 工具里切换,或拔掉后自动换了一台,`/api/info` 的 `udid` 都会变,页面最迟在下一次 10 秒轮询时发现,把画面(`/stream?udid=`)和各面板换过去。每个操作带上页面显示的那台的 UDID(`X-Ictl-Device`),守护进程控制的不是这台就拒绝,不会发到用户没在看的手机上。还没装 WDA 的设备,登录了 Apple ID 时页面上可以直接签名安装(`/api/sign`,即 `Request::Resign { force: true }`,时限 16 分钟)。AI 任务执行中不能切换设备,设了 `IPHONE_UDID` 时也不能。
-- viewer 的画面像触摸屏:iOS 27 起按下、移动、松开各发一个 `Request::Touch`(`prepare`/`down`/`move`/`up`),守护进程在已开的 HID 会话上发一个 touchscreen 报告(约 2 毫秒);解锁、核对方向只在 `down` 时做一次。页面一次只发一个请求,没发出去的移动只留最新的一个,按住不动时每 100 毫秒再报一次位置。滚轮、触控板换成同样的手指拖动。iOS 27 以下松开后发整段手势(WDA)。画面的 MJPEG 流在 `WdaClient::fast_stream` 下是每秒 60 帧、75% 尺寸。页面的文字中英两套,请求带 `X-Ictl-Lang`,viewer 在这种语言下处理,AI 任务记下开始时的语言。
+- viewer 的画面像触摸屏:iOS 27 起按下、移动、松开各发一个 `Request::Touch`(`prepare`/`down`/`move`/`up`),守护进程在已开的 HID 会话上发一个 touchscreen 报告(约 2 毫秒);解锁、核对方向只在 `down` 时做一次。页面一次只发一个请求,没发出去的移动只留最新的一个,按住不动时每 100 毫秒再报一次位置。滚轮、触控板换成同样的手指拖动。iOS 27 以下松开后发整段手势(WDA)。画面的 MJPEG 流在 `WdaClient::fast_stream` 下最多每秒 60 帧、原尺寸、不转正:缩放或转正时 WDA 要逐帧解码、处理、重新编码,CPU 超过 iOS 的上限(60 秒内平均 80%)会被杀掉;这样设置时它直接转发 testmanagerd 用硬件编好的 JPEG。iPhone 横屏时这些帧仍是竖的:JPEG 带 EXIF 方向,浏览器显示 MJPEG 的 img 时自己转正;本机编码的 H.264 不带方向,页面按界面方向(`/api/info` 的 `display.rotation`)在 canvas 上转正,和手机自己的视频一样。页面的文字中英两套,请求带 `X-Ictl-Lang`,viewer 在这种语言下处理,AI 任务记下开始时的语言。
- viewer 的画面编码(`video/`):macOS 上和装了 ffmpeg 时页面拉 `/video`,是 H.264。每个连接读手机的 MJPEG,丢掉和上一帧相同的(静止时 WDA 每秒重复约 25 次),交给一个 ffmpeg 子进程(`mpjpeg` 进,FLV 出;FLV 每帧带长度,收完最后一个字节就能发,裸 H.264 要等下一帧开头才知道这一帧结束),再按「1 字节类型 + 4 字节长度 + 内容」发给页面,页面用 WebCodecs 解码画到 canvas。发出去的解码配置先改写 SPS,写明不重排帧(`video/sps.rs`):没写的话 Chrome 的硬件解码器按级别的最坏情况扣着几帧不出(990×2151 时 4 帧),画面滞后,静止后停在动作中间。macOS 上先用本程序直接调的 VideoToolbox(`video/vt.rs`,每个连接一个线程:VideoToolbox 的 JPEG 解码器把 JPEG 解成 NV12,奇数尺寸顺带拉成偶数,直接交给 H.264 编码器;不重排、不扣帧,每帧编完才取下一帧,不用补帧;输出本来就是 avcC 格式,avcC 取自格式描述;qp 用 `MinAllowedFrameQP`/`MaxAllowedFrameQP` 定住,macOS 12 以前的系统按 `Quality` 近似;macOS 11 以后才有的键运行时用 `dlsym` 找,免得在旧系统上起不来),不需要 ffmpeg。其余编码器在 `viewer` 启动时按顺序试(NVENC、各渲染节点上的 VAAPI(先显卡解 JPEG,再 CPU 解)、QSV、V4L2 M2M、ffmpeg 的 VideoToolbox(原生的备用)、x264),处理真实画面失败就换下一个。ffmpeg 会扣住最新的一帧等下一帧来(AMD 780M 的 VAAPI 是 1 帧),画面静止时最后一次变化就出不来,所以每帧后面紧跟着把它再写 K 遍,K 在探测时测出(写入的帧数减去出来的帧数),这几份副本各编成约 100 字节。流量控制:系统和 SSH 隧道的缓冲能吞下几 MB,光看队列满不满判断不了页面跟不跟得上(每秒读 30 KB 的客户端曾落后 40 秒),所以页面每 100 毫秒 `POST /api/video/ack` 报告收到多少字节;最早一个没确认的消息比平常的往返时间晚 300 毫秒以上,或者在路上的字节超过「链路速度 ×(往返时间 + 300 毫秒)」时,新画面先不交给编码器,追上后只交最新一张。编好的帧一个不丢,帧链完整,不需要关键帧。没有 ffmpeg 或浏览器不支持 WebCodecs 时用 `/stream`:同样丢掉重复帧、只发最新一张,每帧后面紧跟下一部分的分隔线和头部(Chrome 要看到这些才显示上一帧)。
- 手机自己的视频(iOS 27 及以上,页面优先用它):CoreDevice 屏幕媒体流本来就由 HID 会话持有(HID 事件要它在才生效)。`ictl-device` 的 `media.rs` 不再丢掉 RTP:用上游的 `HevcDepacketizer` 还原成 Annex-B,按 RTP marker 组成一帧,记下 VPS/SPS/PPS 补到手机按请求发来、不带参数集的关键帧前面,经 broadcast 发给订阅者(`ScreenFeed`);并照 Device Hub 回传 RTCP(每帧一个帧确认、每 50 毫秒一个 RCTL、每秒一个接收报告),按需发 PLI+FIR 要关键帧(最多每 300 毫秒一次)。守护进程的 `screen.rs` 处理流式请求 `ScreenStream`:先回一行 JSON,之后在同一连接上发「类型 + 长度 + 内容」的消息(0 解码配置、1 关键帧、2 其他帧、3 界面方向),客户端写 `K` 要关键帧;还没收到关键帧时每 250 毫秒再要一次(刚开流时要的那次手机可能不理);界面方向每秒问一次 WDA。有页面在看时(`screen_viewers`),HID 会话不因空闲关闭。viewer 的 `video/device.rs` 转发到 `/video?src=device`,流量控制沿用页面的回报:落后时丢掉非关键帧、再要一个关键帧。页面不带 description 配置 HEVC 解码器(Annex-B),按 `/api/info` 的屏幕尺寸裁掉宽高补到 16 倍数的边(1320×2868 编成 1328×2896),按方向转正;`isConfigSupported` 不支持或从没出过画面就退回 H.264,再退回 MJPEG。
- viewer 的 AI 任务(`agent.rs`):页面上写的任务交给本机的 Claude Code(`claude -p --output-format stream-json`,`--tools ""`、`--strict-mcp-config`,只有 iphone 的 MCP 工具)或 Codex(`codex exec --json`,只读沙箱,`-c` 挂上 iphone 的 MCP 服务),作为子进程(单独的进程组,停止时整组结束)。它的 MCP 服务带上环境变量 `ICTL_AGENT_GATE`(viewer 在控制接口旁边监听的 Unix socket `viewer-<端口>.sock`,0600)和 `ICTL_AGENT_TOKEN`(这个任务的口令),于是每次工具调用前先问 viewer(`ictl_mcp::gate`):记成任务的一步、暂停或用户接管时挂住、任务停了就拒绝;调用后把结果和截图报回去;另外多列一个 `iphone_confirm`,等用户在页面上同意或拒绝。所以步骤、暂停、接管、确认都在 iphone-control 这一层,和用哪种 agent 无关;agent 自己的输出只取它说的话(挂到下一步上)和最后的总结。Codex 对标了 destructive 的 MCP 工具默认要审批,非交互运行时会全部拒绝,所以给这个服务设 `default_tools_approval_mode="approve"`,由 `iphone_confirm` 把关。页面按 SSE 收任务事件(`step`/`confirm`/`state`/`done`),重连时先重放;同一时间只有一个任务,任务执行中(没有接管时)viewer 拒绝页面的手动操作。
diff --git a/docs/decisions.md b/docs/decisions.md
index f72e2f4..cdc90c1 100644
--- a/docs/decisions.md
+++ b/docs/decisions.md
@@ -136,3 +136,4 @@
- 视频总是竖的:界面方向要另外问 WDA(每秒一次),转屏后约 1~2 秒画面才转正;WDA 不可用时按最后知道的方向。
- 依赖苹果没公开的协议:RTCP 反馈照上游对 Device Hub 的抓包;上游提醒不回 RCTL 时剧烈运动会花屏,回了之后的长时间表现还没测过。
- **重新评估**:长时间运行出现花屏或断流时;浏览器普遍能软解 HEVC 时,可以去掉对硬件解码的依赖。
+- **补充(2026-11-13)**:背景里说“改缩放没有明显改善”,指的是缩小。WDA 的截图由 testmanagerd 用硬件编成 JPEG(质量 0.25)交给它;缩放不是 100% 时,WDA 要逐帧解码、用 CoreGraphics 缩放、再重新编码,这正是 CPU 超限的来源(`cpu_resource_fatal` 报告里 13 个采样有 11 个在这条调用栈上)。改成原尺寸后 WDA 直接转发那张 JPEG:iPhone 15 Pro Max(iOS 27.0.1)上帧率不变(约 34 fps),每帧更小(约 80 KB 对 104 KB);拉本机编码的画面时,原来每 1.5~2.5 分钟被杀一次,改后竖屏连拉 15 分钟没再被杀。横屏同理:`mjpegFixOrientation` 让 WDA 逐帧旋转、重新编码,横屏 2 分钟就被杀(92%),所以也关掉,改由页面转正(MJPEG 的 img 由浏览器按 EXIF 方向转正)。所以 D15 那条路(浏览器解不了 HEVC、设备低于 iOS 27)不再需要“不看就关页面”。手机自己的视频仍是 iOS 27 上的首选:帧率更高,主机不用编码。
diff --git a/docs/dev/regression-cases.md b/docs/dev/regression-cases.md
index 201995d..59cc99b 100644
--- a/docs/dev/regression-cases.md
+++ b/docs/dev/regression-cases.md
@@ -104,3 +104,4 @@
| 98 | 发布清单只允许从声明过的某一个版本升级,其他版本一律“需要手动迁移” | 去掉回滚兼容标记和 `update rollback`;任何更新的签名稳定版都能升级,新版本起不来时仍自动换回旧版本;清单保留两个旧字段让 0.2.2 还能升级 | 单测 verifies_publisher_signed_bytes_before_staging_an_executable、unhealthy_daemon_restores_last_verified_executable_and_service;`test_installer.py` test_archive_manifest_still_lets_0_2_2_upgrade |
| 99 | `iphone-control status \| head -1`:读者先退出,后面的 `println!` 遇到 EPIPE 就 panic(退出码 101,打出崩溃信息)。Rust 启动时把 SIGPIPE 设成了忽略 | 只打印结果就结束的命令恢复 SIGPIPE 默认行为,安静退出;守护进程、MCP、viewer、wda-bridge 和跨守护进程重启的 update、service、setup 保持忽略 | 单测 sigpipe_default_only_for_commands_that_print_and_end、集成测试 a_closed_stdout_ends_printing_commands_quietly |
| 100 | 0.2.2 起控制台每次按下都先请求 `/wda/screen`(约 0.1~0.2 秒),HID 会话空闲 30 秒关掉后,鼠标一直停在画面里时第一下还要等约 0.5 秒重开 | 按下只问方向,尺寸在转屏时和距上次测量满 60 秒后才重量;鼠标在画面上移动时每 20 秒最多预热一次 HID 会话 | 单测 display_poll_remeasures_size_only_when_needed;页面测试 hovering keeps the HID session warm at most every 20 seconds;真机:控制台连按,按下往返在几十毫秒内 |
+| 101 | 控制台开着、页面走 WDA 截图的画面(浏览器解不了 HEVC,或低于 iOS 27)时,WDA 每 1.5~2.5 分钟被 iOS 杀掉(`cpu_resource_fatal`:60 秒内平均 86%~93% CPU,上限 80%)。MJPEG 缩到 75% 让 WDA 逐帧解码、缩放(CoreGraphics)、重新编码;横屏时 `mjpegFixOrientation` 让它逐帧旋转、重新编码,同样超限 | MJPEG 原尺寸、不转正(`MJPEG_SCALE` = 100,`mjpegFixOrientation` = false):WDA 直接转发 testmanagerd 硬件编好的 JPEG,帧率不变(约 34 fps)。横屏的竖帧由页面转正(H.264 按 `display.rotation`,MJPEG 的 img 由浏览器按 EXIF) | 真机(iPhone 15 Pro Max,iOS 27.0.1):拉本机编码的 `/video`,竖屏 25 分钟、横屏 5 分钟不再被杀(开着转正时横屏 2 分钟被杀);无头 Chrome:横屏下 H.264 和 MJPEG 画面方向正确、坐标换算正确 |
diff --git a/website/en/troubleshoot/faq.md b/website/en/troubleshoot/faq.md
index b0ef18c..6673c80 100644
--- a/website/en/troubleshoot/faq.md
+++ b/website/en/troubleshoot/faq.md
@@ -68,7 +68,9 @@ On iOS 27 and later with a browser that decodes HEVC, the line under the picture
## WDA restarts every few minutes while the control page is open
-Below iOS 27 (or when the browser can't decode HEVC and gets H.264 or MJPEG), the picture comes from WDA capturing the screen all the time, which takes WDA over one CPU core. iOS kills a process that averages more than 80 % over a minute: the phone keeps a `WebDriverAgentRunner-Runner.cpu_resource_fatal` crash report, the daemon logs "WDA unavailable" and starts it again about 10 seconds later, and actions fail meanwhile. Close the control page when you aren't watching; on iOS 27 and later the phone's own video avoids this (WDA stays around 3 %).
+Version 0.2.2 and earlier did this when the picture came from WDA's screenshots (below iOS 27, or a browser that can't decode HEVC and gets H.264 or MJPEG): WDA scaled down and re-encoded every frame, used more CPU than iOS allows a process (80 % averaged over a minute) and was killed. The daemon logs "WDA unavailable" and starts it again about 10 seconds later, and actions fail meanwhile. Later versions take the picture at full size, so WDA passes on the screenshot the phone encodes in hardware and stays under the limit. On an older version, close the control page when you aren't watching; on iOS 27 and later with a browser that decodes HEVC, the phone's own video never had this problem.
+
+If it still happens on a newer version, look on the phone under Settings → Privacy & Security → Analytics & Improvements → Analytics Data for reports starting with `WebDriverAgentRunner-Runner.cpu_resource_fatal` (with the developer tools on, `iphone_crash_reports` reads them too) and [open an issue](https://github.com/Derrors/iphone-control/issues) with the phone model, iOS version and the encoding shown under the picture.
## "Paired computer" icon stays and the phone won't auto-lock
diff --git a/website/troubleshoot/faq.md b/website/troubleshoot/faq.md
index f24ec1f..6e91186 100644
--- a/website/troubleshoot/faq.md
+++ b/website/troubleshoot/faq.md
@@ -66,7 +66,9 @@ iphone-control doctor # 逐层检查,每项失败都给出修复办法
## 控制台开着时 WDA 每隔几分钟重启一次
-iOS 27 以下(或浏览器解不了 HEVC、改用 H.264/MJPEG)时,画面靠 WDA 一直截图,WDA 的 CPU 占到一个核以上。iOS 对一个进程的限额是一分钟平均 80%,超过就把它杀掉:手机上会有 `WebDriverAgentRunner-Runner.cpu_resource_fatal` 崩溃报告,守护进程记「WDA 不可用」,约 10 秒后重新拉起。期间操作会失败。不看的时候关掉控制台页面;iOS 27 及以上用手机自己的视频就没有这个问题(WDA 的 CPU 约 3%)。
+0.2.2 及以前的版本会这样:画面来自 WDA 截图时(iOS 27 以下,或浏览器解不了 HEVC、改用 H.264/MJPEG),WDA 要把每一帧缩小、重新编码,CPU 超过 iOS 给一个进程的限额(一分钟平均 80%),被 iOS 杀掉。守护进程记「WDA 不可用」,约 10 秒后重新拉起,期间操作会失败。之后的版本画面改用原尺寸,WDA 直接转发手机用硬件编好的截图,不再超限。旧版本上不看的时候关掉控制台页面就能避开;iOS 27 及以上、浏览器能解 HEVC 时用手机自己的视频,本来就没有这个问题。
+
+新版本上还这样的话,在手机的 设置 → 隐私与安全性 → 分析与改进 → 分析数据 里找 `WebDriverAgentRunner-Runner.cpu_resource_fatal` 开头的报告(开着开发者工具时也可以用 `iphone_crash_reports` 读),连同手机型号、iOS 版本、画面下方写的编码方式一起[提 issue](https://github.com/Derrors/iphone-control/issues)。
## 灵动岛一直显示「配对的电脑」、手机不自动锁屏