44import os
55import socket
66import struct
7+ from pathlib import Path
78from typing import Optional
89
910import retry
@@ -24,16 +25,19 @@ 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:
32- scrcpy_jar_path (str, optional): Path to the scrcpy server JAR file. Defaults to None.
33+ device (AdbDevice): The ADB device instance to use.
34+ version (str, optional): Scrcpy server version to use. Defaults to "2.7".
3335 """
34- self .scrcpy_jar_path = scrcpy_jar_path or os .path .join (os .path .dirname (__file__ ),
35- '../binaries/scrcpy_server.jar' )
36+ self .scrcpy_jar_path = Path (__file__ ).parent .joinpath (f'../binaries/scrcpy-server-v{ version } .jar' )
37+ if self .scrcpy_jar_path .exists () is False :
38+ raise FileNotFoundError (f"Scrcpy server JAR not found: { self .scrcpy_jar_path } " )
3639 self .device = device
40+ self .version = version
3741 self .resolution_width = 0 # scrcpy 投屏转换宽度
3842 self .resolution_height = 0 # scrcpy 投屏转换高度
3943
@@ -59,6 +63,9 @@ def _parse_scrcpy_info(self, conn: socket.socket):
5963 if not dummy_byte or dummy_byte != b"\x00 " :
6064 raise ConnectionError ("Did not receive Dummy Byte!" )
6165 logger .debug ('Received Dummy Byte!' )
66+ # print('Received Dummy Byte!')
67+ if self .version == '3.3.3' : # 临时处理一下, 3.3.3使用WebCodec来接码,前端解析分辨率
68+ return
6269 device_name = conn .recv (64 ).decode ('utf-8' ).rstrip ('\x00 ' )
6370 logger .debug (f'Device name: { device_name } ' )
6471 codec = conn .recv (4 )
@@ -100,10 +107,10 @@ def _start_scrcpy_server(self, control: bool = True) -> AdbConnection:
100107 start_command = (
101108 'CLASSPATH=/data/local/tmp/scrcpy_server.jar '
102109 'app_process / '
103- 'com.genymobile.scrcpy.Server 2.7 '
110+ f 'com.genymobile.scrcpy.Server { self . version } '
104111 'log_level=info max_size=1024 max_fps=30 '
105112 'video_bit_rate=8000000 tunnel_forward=true '
106- 'send_frame_meta=false '
113+ 'send_frame_meta=true '
107114 f'control={ "true" if control else "false" } '
108115 'audio=false show_touches=false stay_awake=false '
109116 'power_off_on_close=false clipboard_autosync=false'
0 commit comments