Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

things run at least! ...realized I can replace the ring buffer with a single-slot, just need to add an option to 'wait' or 'overwrite'

jonmatthis65298002bfa8
diff --git a/freemocap/api/websocket/websocket_server.py b/freemocap/api/websocket/websocket_server.py
index 281c9df8..5772c780 100644
--- a/freemocap/api/websocket/websocket_server.py
+++ b/freemocap/api/websocket/websocket_server.py
@@ -122,7 +122,7 @@ class FreemocapWebsocketServer:
mf_payload: MultiFramePayload = self._freemocap_app_state.skellycam_app_state.frame_escape_shm.get_multi_frame_payload(
camera_configs=self._freemocap_app_state.skellycam_app_state.camera_group.camera_configs,
- retrieve_type=ReadTypes.LATEST.value)
+ retrieve_type=ReadTypes.LATEST_READ_ONLY.value)
await self._send_frontend_payload(mf_payload)
if processing_server:
processing_server.intake_data(mf_payload)
diff --git a/freemocap/pipelines/dummy_pipeline.py b/freemocap/pipelines/dummy_pipeline.py
index 9183d68c..d63ec5f9 100644
--- a/freemocap/pipelines/dummy_pipeline.py
+++ b/freemocap/pipelines/dummy_pipeline.py
@@ -32,19 +32,20 @@ class DummyPipelineConfig(PipelineConfig):
class DummyCameraProcessingNode(CameraProcessingNode):
@classmethod
def create(cls,
- config: DummyCameraPipelineConfig,
camera_id: CameraId,
+ config: DummyCameraPipelineConfig,
camera_ring_shm_dto: RingBufferCameraSharedMemoryDTO,
output_queue: Queue,
shutdown_event: multiprocessing.Event,
read_type: ReadTypes = ReadTypes.LATEST_AND_INCREMENT
):
- return cls(config=config,
- camera_id=camera_id,
+ return cls(camera_id=camera_id,
+ config=config,
camera_ring_shm=RingBufferCameraSharedMemory.recreate(dto=camera_ring_shm_dto,
read_only=False),
process=Process(target=cls._run,
- kwargs=dict(config=config,
+ kwargs=dict(camera_id=camera_id,
+ config=config,
camera_ring_shm_dto=camera_ring_shm_dto,
output_queue=output_queue,
read_type=read_type,
@@ -56,31 +57,39 @@ class DummyCameraProcessingNode(CameraProcessingNode):
)
@staticmethod
- def _run(config: DummyPipelineConfig,
+ def _run(camera_id: CameraId,
+ config: DummyPipelineConfig,
camera_ring_shm_dto: RingBufferCameraSharedMemory,
output_queue: Queue,
shutdown_event: multiprocessing.Event,
read_type: ReadTypes = ReadTypes.LATEST_AND_INCREMENT
):
- logger.trace(f"Starting camera processing node for camera {camera_ring_shm_dto.camera_id}")
+ logger.trace(f"Starting camera processing node for camera {camera_id}")
camera_ring_shm = RingBufferCameraSharedMemory.recreate(dto=camera_ring_shm_dto,
- read_only=False)
- while not shutdown_event.is_set():
- time.sleep(0.001)
- if camera_ring_shm.ready_to_read:
-
- if read_type == ReadTypes.LATEST_AND_INCREMENT:
- image = camera_ring_shm.retrieve_latest_frame(increment=True)
- elif read_type == ReadTypes.LATEST_READ_ONLY:
- image = camera_ring_shm.retrieve_latest_frame(increment=False)
- elif read_type == ReadTypes.NEXT:
- image = camera_ring_shm.retrieve_next_frame()
- else:
- raise ValueError(f"Invalid read_type: {read_type}")
-
- logger.trace(f"Processing image from camera {camera_ring_shm.camera_id}")
- # TODO - process image
- output_queue.put(PipelineData(data=image))
+ read_only=False)
+ try:
+ while not shutdown_event.is_set():
+ time.sleep(0.001)
+ if camera_ring_shm.ready_to_read:
+
+ if read_type == ReadTypes.LATEST_AND_INCREMENT:
+ image = camera_ring_shm.retrieve_latest_frame(increment=True)
+ elif read_type == ReadTypes.LATEST_READ_ONLY:
+ image = camera_ring_shm.retrieve_latest_frame(increment=False)
+ elif read_type == ReadTypes.NEXT:
+ image = camera_ring_shm.retrieve_next_frame()
+ else:
+ raise ValueError(f"Invalid read_type: {read_type}")
+
+ # TODO - process image
+ output_queue.put(PipelineData(data=image))
+ except Exception as e:
+ logger.exception(f"Error in camera processing node for camera {camera_id}", exc_info=e)
+ raise
+ finally:
+ logger.trace(f"Shutting down camera processing node for camera {camera_id}")
+ shutdown_event.set()
+ camera_ring_shm.close()
class DummyAggregationProcessNode(AggregationProcessNode):
@@ -104,19 +113,24 @@ class DummyAggregationProcessNode(AggregationProcessNode):
@staticmethod
def _run(config: PipelineConfig, input_queues: Dict[CameraId, Queue], output_queue: Queue,
shutdown_event: multiprocessing.Event):
- while not shutdown_event.is_set():
- data_by_camera_id = {camera_id: None for camera_id in input_queues.keys()}
- while any([input_queues[camera_id].empty() for camera_id in input_queues.keys()]):
- time.sleep(0.001)
- for camera_id in input_queues.keys():
- if not input_queues[camera_id] is None:
- if not input_queues[camera_id].empty():
- data_by_camera_id[camera_id] = input_queues[camera_id].get()
- if len(data_by_camera_id) == len(input_queues):
- logger.trace(f"Processing aggregated data from cameras {data_by_camera_id.keys()}")
- # TODO - process aggregated data
- output_queue.put(PipelineData(data=data_by_camera_id))
-
+ try:
+ while not shutdown_event.is_set():
+ data_by_camera_id = {camera_id: None for camera_id in input_queues.keys()}
+ while any([input_queues[camera_id].empty() for camera_id in input_queues.keys()]):
+ time.sleep(0.001)
+ for camera_id in input_queues.keys():
+ if not input_queues[camera_id] is None:
+ if not input_queues[camera_id].empty():
+ data_by_camera_id[camera_id] = input_queues[camera_id].get()
+ if len(data_by_camera_id) == len(input_queues):
+ # TODO - process aggregated data
+ output_queue.put(PipelineData(data=data_by_camera_id))
+ except Exception as e:
+ logger.exception(f"Error in aggregation processing node", exc_info=e)
+ raise
+ finally:
+ logger.trace(f"Shutting down aggregation processing node")
+ shutdown_event.set()
class DummyProcessingPipeline(CameraGroupProcessingPipeline):
config: DummyPipelineConfig