diff --git a/skellycam/api/routes/websocket/websocket_server.py b/skellycam/api/routes/websocket/websocket_server.py index 735765a3..6c5b241f 100644 --- a/skellycam/api/routes/websocket/websocket_server.py +++ b/skellycam/api/routes/websocket/websocket_server.py @@ -1,7 +1,7 @@ import asyncio import logging -import pickle +import msgpack from fastapi import APIRouter, WebSocket from starlette.websockets import WebSocketDisconnect, WebSocketState @@ -57,7 +57,7 @@ async def websocket_relay(websocket: WebSocket): message = ipc_queue.get() if isinstance(message, AppStateDTO): logger.trace(f"Relaying AppStateDTO to frontend") - await websocket.send_bytes(pickle.dumps(message)) + await websocket.send_bytes(msgpack.dumps(message.model_dump_json())) elif isinstance(message, SubProcessStatus): pass # app_state.update_process_status(message) @@ -94,7 +94,7 @@ async def websocket_server_connect(websocket: WebSocket): await websocket.accept() await websocket.send_text(HELLO_CLIENT_TEXT_MESSAGE) - await websocket.send_bytes(HELLO_CLIENT_BYTES_MESSAGE) + await websocket.send_bytes(msgpack.dumps(HELLO_CLIENT_BYTES_MESSAGE)) await websocket.send_json(HELLO_CLIENT_JSON_MESSAGE) logger.success(f"Websocket connection established!") diff --git a/skellycam/core/frames/wrangling/frame_router_process.py b/skellycam/core/frames/wrangling/frame_router_process.py index 12932449..79344594 100644 --- a/skellycam/core/frames/wrangling/frame_router_process.py +++ b/skellycam/core/frames/wrangling/frame_router_process.py @@ -1,9 +1,10 @@ import logging import multiprocessing -import pickle import time from typing import Optional +import msgpack + from skellycam.core.cameras.camera.config.camera_config import CameraConfigs from skellycam.core.frames.payloads.frontend_image_payload import FrontendFramePayload from skellycam.core.frames.payloads.multi_frame_payload import MultiFramePayload @@ -57,7 +58,7 @@ def _run_process(camera_configs: CameraConfigs, try: while not kill_camera_group_flag.value: - if frame_escape_pipe_exit.poll(): + if frame_escape_pipe_exit.poll(): # TODO - Replace this with a 'new frames' flag from the listener process? # TODO - receive individual frames as bytes with `...recv_bytes()` and construct MultiFramePayload object here payload: MultiFramePayload = frame_escape_pipe_exit.recv() @@ -68,7 +69,7 @@ def _run_process(camera_configs: CameraConfigs, frontend_payload = FrontendFramePayload.from_multi_frame_payload(multi_frame_payload=payload, resize_image=.25) # TODO - might/shouild be possible to send straight to GUI websocket client from here without the relay pipe? Assuming the relay pipe isn't faster (and that the GUI can unpack the bytes) - frontend_relay_pipe.send_bytes(pickle.dumps(frontend_payload)) + frontend_relay_pipe.send_bytes(msgpack.dumps(frontend_payload.model_dump_json())) logger.loop(f"FrameExporter - Received multi-frame payload: {payload}") @@ -82,7 +83,7 @@ def _run_process(camera_configs: CameraConfigs, f"FrameExporter - Created FrameSaver for recording {video_recorder_manager.recording_name}") # send as bytes so it can use same ws/ relay as the frontend_payload's recording_info = video_recorder_manager.recording_info - frontend_relay_pipe.send_bytes(pickle.dumps(recording_info)) + frontend_relay_pipe.send_bytes(msgpack.dumps(recording_info)) # TODO - Decouple 'add_frame' from 'save_frame' and create a 'save_one_frame' method that saves a single frame from one camera, so we can check for new frames faster. We will need a mechanism to drain the buffers when recording ends video_recorder_manager.add_multi_frame(payload)