Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Pbatch committed Jun 23, 2024
1 parent ec18c59 commit bd61a3b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
36 changes: 25 additions & 11 deletions clashroyalebuildabot/emulator/adbblitz.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import atexit
from collections import deque
import os
import socket
import subprocess
from collections import deque

import av
import kthread
import numpy as np
from get_free_port import get_dynamic_ports
import kthread
from kthread_sleep import sleep
from loguru import logger
from subprocesskiller import kill_process_children_parents, kill_pid, kill_subprocs
import numpy as np
from subprocesskiller import kill_pid
from subprocesskiller import kill_process_children_parents
from subprocesskiller import kill_subprocs

startupinfo = subprocess.STARTUPINFO()
creationflags = 0 | subprocess.CREATE_NO_WINDOW
Expand Down Expand Up @@ -109,7 +111,9 @@ def __init__(

self.scrcpy_server_version = scrcpy_server_version
self.forward_port = forward_port
self.folder_here = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
self.folder_here = os.path.normpath(
os.path.abspath(os.path.dirname(__file__))
)
self.scrcpy_path = os.path.normpath(
os.path.join(self.folder_here, "scrcpy-server.jar")
)
Expand Down Expand Up @@ -139,7 +143,7 @@ def __init__(
"downsize_on_error=false",
"send_dummy_byte=true",
"raw_video_stream=true",
f"max_size={self.max_video_width}"
f"max_size={self.max_video_width}",
]
self.video_socket = None
self.t = None
Expand Down Expand Up @@ -278,7 +282,9 @@ def _connect_to_server(self):
cont += 1
if self.stop_capturing:
break
self.video_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.video_socket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM
)
self.video_socket.connect((self.ip, self.forward_port))

self.video_socket.setblocking(False)
Expand All @@ -293,16 +299,22 @@ def _connect_to_server(self):
logger.info(fe)

def _start_capturing(self):
self.t = kthread.KThread(target=self._all_raw_data, name="all_raw_data_thread")
self.t = kthread.KThread(
target=self._all_raw_data, name="all_raw_data_thread"
)
self.t.start()

self.t2 = kthread.KThread(target=self._parse_frames, name="parse_frames_thread")
self.t2 = kthread.KThread(
target=self._parse_frames, name="parse_frames_thread"
)
self.t2.start()

def _get_infos2(self):
while True:
try:
self.real_height, self.real_width, *_ = self.lastframes[-1].shape
self.real_height, self.real_width, *_ = self.lastframes[
-1
].shape
logger.info(self.real_width, self.real_height)
break
except Exception:
Expand Down Expand Up @@ -392,7 +404,9 @@ def _parse_frames(self):
continue
for frame in frames:
new_frame = frame.to_rgb().reformat(
width=frame.width, height=frame.height, format="bgr24"
width=frame.width,
height=frame.height,
format="bgr24",
)
self.lastframes.append(new_frame.to_ndarray())
except Exception as fa:
Expand Down
12 changes: 7 additions & 5 deletions clashroyalebuildabot/emulator/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ def __init__(self):
device_serial=f"localhost:{device_port}",
adb_path=self._adb_path(),
ip=device_ip,
max_video_width=self.size[0]
max_video_width=self.size[0],
)

@staticmethod
def _adb_path():
p = subprocess.run(["which", "adb"], capture_output=True, text=True, check=True)
p = subprocess.run(
["which", "adb"], capture_output=True, text=True, check=True
)
path = p.stdout.strip()
path = path.replace('/', '\\')
if path.startswith('\\'):
path = f'{path[1].upper()}:{path[2:]}'
path = path.replace("/", "\\")
if path.startswith("\\"):
path = f"{path[1].upper()}:{path[2:]}"

return path

Expand Down

0 comments on commit bd61a3b

Please sign in to comment.