44import os
55import socket
66import struct
7+ from pathlib import Path
78from typing import Optional
89
910import 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