add modify human render
This commit is contained in:
parent
e9691dbc81
commit
2a2a3cd349
@ -48,7 +48,7 @@ class HumanRender(AudioHandler):
|
||||
logging.info('human render run')
|
||||
while self._exit_event.is_set() and self._is_running:
|
||||
self._run_step()
|
||||
delay = 0.04
|
||||
delay = 0.075
|
||||
time.sleep(delay)
|
||||
|
||||
logging.info('human render exit')
|
||||
|
BIN
ipc/ipc.dll
BIN
ipc/ipc.dll
Binary file not shown.
BIN
ipc/ipc.exp
BIN
ipc/ipc.exp
Binary file not shown.
BIN
ipc/ipc.lib
BIN
ipc/ipc.lib
Binary file not shown.
BIN
ipc/ipc.pdb
BIN
ipc/ipc.pdb
Binary file not shown.
@ -38,12 +38,13 @@ class IPCUtil:
|
||||
self.__ipc_obj.send.restype = c_bool
|
||||
send_data = data.encode('utf-8')
|
||||
send_len = len(send_data) + 1
|
||||
return self.__ipc_obj.send(send_data, send_len)
|
||||
if not self.__ipc_obj.send(send_data, send_len):
|
||||
self.__ipc_obj.reConnect()
|
||||
return True
|
||||
|
||||
def send_binary(self, data, size):
|
||||
if not self.__init:
|
||||
return False
|
||||
print('send_binary', size)
|
||||
self.__ipc_obj.send.argtypes = [c_char_p, c_uint]
|
||||
self.__ipc_obj.send.restype = c_bool
|
||||
data_ptr = cast(data, c_char_p)
|
||||
@ -58,9 +59,9 @@ class IPCUtil:
|
||||
self.__ipc_obj.setReaderCallback.restype = c_bool
|
||||
return self.__ipc_obj.setReaderCallback(self.c_callback)
|
||||
|
||||
#
|
||||
|
||||
# def ipc_log_callback(log, size):
|
||||
# print(f'log={log}, len={size}')
|
||||
# print(f'log={log.decode("utf-8")}, len={size}')
|
||||
#
|
||||
#
|
||||
# util = IPCUtil('ipc_sender', 'ipc_sender')
|
||||
|
5
main.py
5
main.py
@ -3,6 +3,7 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from ui import IpcRender
|
||||
from utils import config_logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -12,6 +13,6 @@ if __name__ == '__main__':
|
||||
config_logging('./logs/info.log', logging.INFO, logging.INFO)
|
||||
|
||||
logger.info('------------start------------')
|
||||
ui = PyGameUI()
|
||||
ui.run()
|
||||
render = IpcRender()
|
||||
render.run()
|
||||
logger.info('------------finish------------')
|
@ -1,3 +1,3 @@
|
||||
#encoding = utf8
|
||||
|
||||
|
||||
from .ipc_render import IpcRender
|
||||
|
@ -2,10 +2,12 @@
|
||||
|
||||
import os
|
||||
import logging
|
||||
import time
|
||||
from queue import Queue
|
||||
|
||||
from human import HumanContext
|
||||
from ipc import IPCUtil
|
||||
from utils import render_image
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
current_file_path = os.path.dirname(os.path.abspath(__file__))
|
||||
@ -15,35 +17,55 @@ class IpcRender:
|
||||
def __init__(self):
|
||||
self._human_context = None
|
||||
self._queue = None
|
||||
self._ipc = IPCUtil('ipc_sender', 'ipc_sender')
|
||||
self._exit = False
|
||||
self._ipc = None
|
||||
|
||||
def _send_image(self, identifier, image):
|
||||
height, width, channels = image.shape
|
||||
|
||||
width_bytes = width.to_bytes(4, byteorder='little')
|
||||
height_bytes = height.to_bytes(4, byteorder='little')
|
||||
bit_depth_bytes = channels.to_bytes(4, byteorder='little')
|
||||
|
||||
img_bytes = image.tobytes()
|
||||
data = identifier + width_bytes + height_bytes + bit_depth_bytes + img_bytes
|
||||
self._ipc.send_binary(data, len(data))
|
||||
|
||||
def _on_reader_callback(self, data_str, size):
|
||||
data_str = data_str.decode('utf-8')
|
||||
print(f'on_reader_callback: {data_str}, size:{size}')
|
||||
if 'quit' == data_str:
|
||||
self._exit = True
|
||||
elif 'heartbeat' == data_str:
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
self._queue = Queue()
|
||||
self._human_context = HumanContext()
|
||||
self._human_context.build()
|
||||
self._ipc = IPCUtil('human_product', 'human_render')
|
||||
self._ipc.set_reader_callback(self._on_reader_callback)
|
||||
logger.info(f'ipc listen:{self._ipc.listen()}')
|
||||
|
||||
render = self._human_context.render_handler
|
||||
render.set_image_render(self)
|
||||
|
||||
while not self._exit:
|
||||
if not self._queue.empty():
|
||||
while self._queue.qsize() > 5:
|
||||
self._queue.get()
|
||||
print('render queue is slower')
|
||||
|
||||
image = self._queue.get()
|
||||
image = render_image(self._human_context, image)
|
||||
self._send_image(b'\x01', image)
|
||||
else:
|
||||
time.sleep(0.02)
|
||||
logger.info('ipc render exit')
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
def get_image(self):
|
||||
pass
|
||||
def on_render(self, image):
|
||||
self._queue.put(image)
|
||||
|
||||
def get_audio(self):
|
||||
pass
|
||||
|
||||
def send_audio(self, audio):
|
||||
pass
|
||||
|
||||
def send_image(self, image):
|
||||
pass
|
||||
|
||||
def send_text(self, text):
|
||||
pass
|
||||
|
||||
def send_command(self, command):
|
||||
pass
|
||||
|
||||
def send_binary(self, data, length):
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user