mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-26 12:47:53 +08:00
Fix: Locking scrcpy screenshot and control
This commit is contained in:
@@ -192,6 +192,7 @@ class ScrcpyCore(Connection):
|
|||||||
for packet in packets:
|
for packet in packets:
|
||||||
frames = codec.decode(packet)
|
frames = codec.decode(packet)
|
||||||
for frame in frames:
|
for frame in frames:
|
||||||
|
# logger.info('frame received')
|
||||||
frame = frame.to_ndarray(format="rgb24")
|
frame = frame.to_ndarray(format="rgb24")
|
||||||
self._scrcpy_last_frame = frame
|
self._scrcpy_last_frame = frame
|
||||||
self._scrcpy_last_frame_time = time.time()
|
self._scrcpy_last_frame_time = time.time()
|
||||||
|
|||||||
@@ -77,21 +77,20 @@ class Scrcpy(ScrcpyCore):
|
|||||||
def screenshot_scrcpy(self):
|
def screenshot_scrcpy(self):
|
||||||
self.scrcpy_ensure_running()
|
self.scrcpy_ensure_running()
|
||||||
|
|
||||||
# Wait new frame
|
|
||||||
with self._scrcpy_control_socket_lock:
|
with self._scrcpy_control_socket_lock:
|
||||||
|
# Wait new frame
|
||||||
|
now = time.time()
|
||||||
while 1:
|
while 1:
|
||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
if self._scrcpy_last_frame_time > 0:
|
if self._scrcpy_last_frame_time > now:
|
||||||
break
|
|
||||||
|
|
||||||
screenshot = self._scrcpy_last_frame.copy()
|
screenshot = self._scrcpy_last_frame.copy()
|
||||||
self._scrcpy_last_frame_time = 0.
|
|
||||||
return screenshot
|
return screenshot
|
||||||
|
|
||||||
@retry
|
@retry
|
||||||
def click_scrcpy(self, x, y):
|
def click_scrcpy(self, x, y):
|
||||||
self.scrcpy_ensure_running()
|
self.scrcpy_ensure_running()
|
||||||
|
|
||||||
|
with self._scrcpy_control_socket_lock:
|
||||||
self._scrcpy_control.touch(x, y, const.ACTION_DOWN)
|
self._scrcpy_control.touch(x, y, const.ACTION_DOWN)
|
||||||
self._scrcpy_control.touch(x, y, const.ACTION_UP)
|
self._scrcpy_control.touch(x, y, const.ACTION_UP)
|
||||||
self.sleep(0.05)
|
self.sleep(0.05)
|
||||||
@@ -100,6 +99,7 @@ class Scrcpy(ScrcpyCore):
|
|||||||
def long_click_scrcpy(self, x, y, duration=1.0):
|
def long_click_scrcpy(self, x, y, duration=1.0):
|
||||||
self.scrcpy_ensure_running()
|
self.scrcpy_ensure_running()
|
||||||
|
|
||||||
|
with self._scrcpy_control_socket_lock:
|
||||||
self._scrcpy_control.touch(x, y, const.ACTION_DOWN)
|
self._scrcpy_control.touch(x, y, const.ACTION_DOWN)
|
||||||
self.sleep(duration)
|
self.sleep(duration)
|
||||||
self._scrcpy_control.touch(x, y, const.ACTION_UP)
|
self._scrcpy_control.touch(x, y, const.ACTION_UP)
|
||||||
@@ -109,6 +109,7 @@ class Scrcpy(ScrcpyCore):
|
|||||||
def swipe_scrcpy(self, p1, p2):
|
def swipe_scrcpy(self, p1, p2):
|
||||||
self.scrcpy_ensure_running()
|
self.scrcpy_ensure_running()
|
||||||
|
|
||||||
|
with self._scrcpy_control_socket_lock:
|
||||||
# Unlike minitouch, scrcpy swipes needs to be continuous
|
# Unlike minitouch, scrcpy swipes needs to be continuous
|
||||||
# So 5 times smother
|
# So 5 times smother
|
||||||
points = insert_swipe(p0=p1, p3=p2, speed=4, min_distance=2)
|
points = insert_swipe(p0=p1, p3=p2, speed=4, min_distance=2)
|
||||||
@@ -126,6 +127,7 @@ class Scrcpy(ScrcpyCore):
|
|||||||
def drag_scrcpy(self, p1, p2, point_random=(-10, -10, 10, 10)):
|
def drag_scrcpy(self, p1, p2, point_random=(-10, -10, 10, 10)):
|
||||||
self.scrcpy_ensure_running()
|
self.scrcpy_ensure_running()
|
||||||
|
|
||||||
|
with self._scrcpy_control_socket_lock:
|
||||||
p1 = np.array(p1) - random_rectangle_point(point_random)
|
p1 = np.array(p1) - random_rectangle_point(point_random)
|
||||||
p2 = np.array(p2) - random_rectangle_point(point_random)
|
p2 = np.array(p2) - random_rectangle_point(point_random)
|
||||||
points = insert_swipe(p0=p1, p3=p2, speed=4, min_distance=2)
|
points = insert_swipe(p0=p1, p3=p2, speed=4, min_distance=2)
|
||||||
|
|||||||
Reference in New Issue
Block a user