修复掉视频的bug

This commit is contained in:
2025-10-27 21:44:16 +08:00
parent 7b732aad62
commit 2254284625
11 changed files with 269 additions and 165 deletions

View File

@@ -161,8 +161,33 @@ class DeviceInfo:
time.sleep(1)
def _wait_wda_ready_on_port(self, udid: str, local_port: int, total_timeout_sec: float = None) -> bool:
"""在给定的本地映射端口上等待 /status 就绪。"""
import http.client, time
if total_timeout_sec is None:
total_timeout_sec = self.WDA_READY_TIMEOUT
deadline = _monotonic() + total_timeout_sec
attempt = 0
while _monotonic() < deadline:
attempt += 1
try:
conn = http.client.HTTPConnection("127.0.0.1", local_port, timeout=1.8)
conn.request("GET", "/status")
resp = conn.getresponse()
_ = resp.read(128)
code = getattr(resp, "status", 0)
ok = 200 <= code < 400
print(f"[WDA] /status@{local_port}{attempt}次 code={code}, ok={ok} {udid}")
if ok:
return True
except Exception as e:
print(f"[WDA] /status@{local_port} 异常({attempt}): {e}")
time.sleep(0.5)
print(f"[WDA] /status@{local_port} 等待超时 {udid}")
return False
def _add_device(self, udid: str):
method = "_add_device"
print(f"[Add] 开始新增设备 {udid}")
if not self._trusted(udid):
@@ -177,8 +202,13 @@ class DeviceInfo:
if not self._wda_http_status_ok_once(udid):
if major > 17:
print("进入iOS17设备的分支")
print(f"[WDA] iOS>17 调用 IOSActivator (port={wdaScreenPort})")
IOSActivator().activate(udid)
try:
IOSActivator().activate(udid)
print("wda启动完成")
except Exception as e:
print("错误信息:",e)
else:
print(f"[WDA] iOS<=17 启动 WDA app_start (port={wdaScreenPort})")
dev = tidevice.Device(udid)
@@ -196,7 +226,7 @@ class DeviceInfo:
if not (w and h and s):
# 再做几次快速重试(带超时)
for i in range(4):
print(f"[Screen] 第{i+1}次获取失败, 重试中... {udid}")
print(f"[Screen] 第{i + 1}次获取失败, 重试中... {udid}")
time.sleep(0.6)
w, h, s = self._screen_info_with_timeout(udid, timeout=3.5)
if w and h and s:
@@ -254,18 +284,24 @@ class DeviceInfo:
return False
def _wda_http_status_ok_once(self, udid: str, timeout_sec: float = 1.8) -> bool:
method = "_wda_http_status_ok_once"
tmp_port = self._alloc_port()
"""只做一次 /status 探测。任何异常都返回 False不让外层炸掉。"""
tmp_port = None
proc = None
try:
tmp_port = self._alloc_port() # 这里可能抛异常
print(f"[WDA] 启动临时 iproxy 以检测 /status {udid}")
proc = self._spawn_iproxy(udid, local_port=tmp_port, remote_port=wdaScreenPort)
if not proc:
print("[WDA] 启动临时 iproxy 失败")
return False
if not self._wait_until_listening(tmp_port, 3.0):
print(f"[WDA] 临时端口未监听 {tmp_port}")
self._release_port(tmp_port)
return False
# 最多两次快速探测
for i in (1, 2):
try:
import http.client
conn = http.client.HTTPConnection("127.0.0.1", tmp_port, timeout=timeout_sec)
conn.request("GET", "/status")
resp = conn.getresponse()
@@ -275,16 +311,21 @@ class DeviceInfo:
print(f"[WDA] /status 第{i}次 code={code}, ok={ok}")
if ok:
return True
time.sleep(0.25)
except Exception as e:
print(f"[WDA] /status 异常({i}): {e}")
time.sleep(0.25)
time.sleep(0.25)
return False
except Exception as e:
import traceback
print(f"[WDA][probe] 异常:{e}\n{traceback.format_exc()}")
return False
finally:
if proc:
self._kill(proc)
# 无论成功失败,都释放临时端口占用
self._release_port(tmp_port)
if tmp_port is not None:
self._release_port(tmp_port)
def _wait_wda_ready_http(self, udid: str, total_timeout_sec: float) -> bool:
print(f"[WDA] 等待 WDA Ready (超时 {total_timeout_sec}s) {udid}")