Skip to content

Commit 7b9b8d6

Browse files
committed
add support of scrcpy 3.3.3
1 parent 8ac4a75 commit 7b9b8d6

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

uiautodev/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,13 @@ async def handle_android_ws(websocket: WebSocket, serial: str):
155155
serial: device serial
156156
websocket: WebSocket
157157
"""
158+
scrcpy_version = websocket.query_params.get("version", "2.7")
158159
await websocket.accept()
159160

160161
try:
161162
logger.info(f"WebSocket serial: {serial}")
162163
device = adbutils.device(serial)
163-
server = ScrcpyServer(device)
164+
server = ScrcpyServer(device, version=scrcpy_version)
164165
await server.handle_unified_websocket(websocket, serial)
165166
except WebSocketDisconnect:
166167
logger.info(f"WebSocket disconnected by client.")
File renamed without changes.
88.1 KB
Binary file not shown.

uiautodev/remote/scrcpy.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import socket
66
import struct
7+
from pathlib import Path
78
from typing import Optional
89

910
import retry
@@ -24,16 +25,18 @@ class ScrcpyServer:
2425
including video streaming and touch control.
2526
"""
2627

27-
def __init__(self, device: AdbDevice, scrcpy_jar_path: Optional[str] = None):
28+
def __init__(self, device: AdbDevice, version: Optional[str] = "2.7"):
2829
"""
2930
Initializes the ScrcpyServer instance.
3031
3132
Args:
3233
scrcpy_jar_path (str, optional): Path to the scrcpy server JAR file. Defaults to None.
3334
"""
34-
self.scrcpy_jar_path = scrcpy_jar_path or os.path.join(os.path.dirname(__file__),
35-
'../binaries/scrcpy_server.jar')
35+
self.scrcpy_jar_path = Path(__file__).parent.joinpath(f'../binaries/scrcpy-server-v{version}.jar')
36+
if self.scrcpy_jar_path.exists() is False:
37+
raise FileNotFoundError(f"Scrcpy server JAR not found: {self.scrcpy_jar_path}")
3638
self.device = device
39+
self.version = version
3740
self.resolution_width = 0 # scrcpy 投屏转换宽度
3841
self.resolution_height = 0 # scrcpy 投屏转换高度
3942

@@ -59,6 +62,9 @@ def _parse_scrcpy_info(self, conn: socket.socket):
5962
if not dummy_byte or dummy_byte != b"\x00":
6063
raise ConnectionError("Did not receive Dummy Byte!")
6164
logger.debug('Received Dummy Byte!')
65+
# print('Received Dummy Byte!')
66+
if self.version == '3.3.3': # 临时处理一下, 3.3.3使用WebCodec来接码,前端解析分辨率
67+
return
6268
device_name = conn.recv(64).decode('utf-8').rstrip('\x00')
6369
logger.debug(f'Device name: {device_name}')
6470
codec = conn.recv(4)
@@ -100,10 +106,10 @@ def _start_scrcpy_server(self, control: bool = True) -> AdbConnection:
100106
start_command = (
101107
'CLASSPATH=/data/local/tmp/scrcpy_server.jar '
102108
'app_process / '
103-
'com.genymobile.scrcpy.Server 2.7 '
109+
f'com.genymobile.scrcpy.Server {self.version} '
104110
'log_level=info max_size=1024 max_fps=30 '
105111
'video_bit_rate=8000000 tunnel_forward=true '
106-
'send_frame_meta=false '
112+
'send_frame_meta=true '
107113
f'control={"true" if control else "false"} '
108114
'audio=false show_touches=false stay_awake=false '
109115
'power_off_on_close=false clipboard_autosync=false'

0 commit comments

Comments
 (0)