Skip to content

Commit

Permalink
trying to get the ui to display received images
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmatthis committed Sep 2, 2024
1 parent 75504eb commit c8859db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions skellycam/api/routes/websocket/websocket_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import logging
import pickle

import msgpack
from fastapi import APIRouter, WebSocket
from starlette.websockets import WebSocketDisconnect, WebSocketState

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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!")

Expand Down
9 changes: 5 additions & 4 deletions skellycam/core/frames/wrangling/frame_router_process.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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}")

Expand All @@ -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)
Expand Down

0 comments on commit c8859db

Please sign in to comment.