Skip to content

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

TypeScript

realtime ui panel mostly working

jonmatthis3ecea0ccfa96
diff --git a/freemocap-ui/src/components/control-panels/realtime-panel/RealtimePipelineConnectionToggle.tsx b/freemocap-ui/src/components/control-panels/realtime-panel/RealtimePipelineConnectionToggle.tsx
index 5817b0bb..79d9389b 100644
--- a/freemocap-ui/src/components/control-panels/realtime-panel/RealtimePipelineConnectionToggle.tsx
+++ b/freemocap-ui/src/components/control-panels/realtime-panel/RealtimePipelineConnectionToggle.tsx
@@ -3,12 +3,13 @@ import {CircularProgress, IconButton, Tooltip, useTheme} from "@mui/material";
import PowerSettingsNewIcon from "@mui/icons-material/PowerSettingsNew";
import {useAppDispatch, useAppSelector} from "@/store/hooks";
import {
+ applyRealtimePipeline,
closePipeline,
- connectRealtimePipeline,
selectCanConnectPipeline,
selectCanDisconnectPipeline,
selectIsPipelineConnected,
selectIsPipelineLoading,
+ selectPipelineConfig,
} from "@/store/slices/realtime";
export const RealtimePipelineConnectionToggle: React.FC = () => {
@@ -19,6 +20,7 @@ export const RealtimePipelineConnectionToggle: React.FC = () => {
const isLoading = useAppSelector(selectIsPipelineLoading);
const canConnect = useAppSelector(selectCanConnectPipeline);
const canDisconnect = useAppSelector(selectCanDisconnectPipeline);
+ const pipelineConfig = useAppSelector(selectPipelineConfig);
const isClickable = canConnect || canDisconnect;
@@ -29,7 +31,7 @@ export const RealtimePipelineConnectionToggle: React.FC = () => {
if (isConnected) {
await dispatch(closePipeline());
} else {
- await dispatch(connectRealtimePipeline(undefined));
+ await dispatch(applyRealtimePipeline(pipelineConfig));
}
};
diff --git a/freemocap-ui/src/components/control-panels/realtime-panel/RealtimePipelinePanel.tsx b/freemocap-ui/src/components/control-panels/realtime-panel/RealtimePipelinePanel.tsx
index c37800a3..818a080f 100644
--- a/freemocap-ui/src/components/control-panels/realtime-panel/RealtimePipelinePanel.tsx
+++ b/freemocap-ui/src/components/control-panels/realtime-panel/RealtimePipelinePanel.tsx
@@ -1,60 +1,66 @@
-import React, {useState} from "react";
+import React from "react";
import {Box} from "@mui/material";
import LanIcon from "@mui/icons-material/Lan";
import {CollapsibleSidebarSection} from "@/components/common/CollapsibleSidebarSection";
-import {useAppSelector} from "@/store/hooks";
-import {selectBackendPipeline} from "@/store/slices/settings";
-import {useServer} from "@/services";
+import {useAppDispatch, useAppSelector} from "@/store/hooks";
import {RealtimePipelineSummary} from "@/components/control-panels/realtime-panel/RealtimePipelineSummary";
-import {
- RealtimePipelineConnectionToggle
-} from "@/components/control-panels/realtime-panel/RealtimePipelineConnectionToggle";
+import {RealtimePipelineConnectionToggle} from "@/components/control-panels/realtime-panel/RealtimePipelineConnectionToggle";
import {RealtimePipelineConfigTree} from "@/components/control-panels/realtime-panel/RealtimePipelineConfigTree";
+import {
+ applyRealtimePipeline,
+ pipelineConfigUpdated,
+ selectAggregatorConfig,
+ selectCameraNodeConfig,
+ selectIsPipelineConnected,
+ selectPipelineConfig,
+} from "@/store/slices/realtime";
+import {RealtimePipelineConfig} from "@/store/slices/realtime/realtime-types";
export const RealtimePipelinePanel: React.FC = () => {
- const {sendWebsocketMessage, isConnected: serverConnected} = useServer();
- const backendPipeline = useAppSelector(selectBackendPipeline);
- const pipelineConfig = backendPipeline?.config;
+ const dispatch = useAppDispatch();
- // ── 2D Tracking: optimistic local state ───────────────────────────────────
- // Local state is the source of truth for the UI. When the backend is
- // connected and echoes a value back via Redux, we sync local state to it.
- // When the backend is disconnected, clicks still work β€” send() is just a
- // no-op side effect.
- const [charucoEnabled, setCharucoEnabled] = useState(false);
- const [skeletonEnabled, setSkeletonEnabled] = useState(false);
+ const isConnected = useAppSelector(selectIsPipelineConnected);
+ const pipelineConfig = useAppSelector(selectPipelineConfig);
+ const cameraNodeConfig = useAppSelector(selectCameraNodeConfig);
+ const aggregatorConfig = useAppSelector(selectAggregatorConfig);
- // Sync from backend when it comes online (or when config changes)
- React.useEffect(() => {
- if (pipelineConfig == null) return;
- setCharucoEnabled(pipelineConfig.calibration_detection_enabled ?? false);
- setSkeletonEnabled(pipelineConfig.mocap_detection_enabled ?? false);
- }, [pipelineConfig]);
-
- const handleCharucoToggle = (newValue: boolean) => {
- setCharucoEnabled(newValue); // update UI immediately
- if (serverConnected) {
- sendWebsocketMessage({
- message_type: "settings/patch",
- patch: {pipeline: {config: {calibration_detection_enabled: newValue}}},
- });
+ const handleConfigChange = (newConfig: RealtimePipelineConfig) => {
+ if (isConnected) {
+ dispatch(applyRealtimePipeline(newConfig));
+ } else {
+ dispatch(pipelineConfigUpdated(newConfig));
}
};
- const handleSkeletonToggle = (newValue: boolean) => {
- setSkeletonEnabled(newValue); // update UI immediately
- if (serverConnected) {
- sendWebsocketMessage({
- message_type: "settings/patch",
- patch: {pipeline: {config: {mocap_detection_enabled: newValue}}},
- });
- }
- };
+ const handleCharucoToggle = (value: boolean) =>
+ handleConfigChange({
+ ...pipelineConfig,
+ camera_node_config: {...cameraNodeConfig, charuco_tracking_enabled: value},
+ });
+
+ const handleSkeletonToggle = (value: boolean) =>
+ handleConfigChange({
+ ...pipelineConfig,
+ camera_node_config: {...cameraNodeConfig, skeleton_tracking_enabled: value},
+ });
+
+ const handleTriangulateToggle = (value: boolean) =>
+ handleConfigChange({
+ ...pipelineConfig,
+ aggregator_config: {...aggregatorConfig, triangulation_enabled: value},
+ });
+
+ const handleFilterToggle = (value: boolean) =>
+ handleConfigChange({
+ ...pipelineConfig,
+ aggregator_config: {...aggregatorConfig, filter_enabled: value},
+ });
- // ── 3D Reconstruction: local state (backend doesn't have these yet) ───────
- const [triangulateEnabled, setTriangulateEnabled] = useState(false);
- const [filterEnabled, setFilterEnabled] = useState(false);
- const [rigidBodyEnabled, setRigidBodyEnabled] = useState(false);
+ const handleRigidBodyToggle = (value: boolean) =>
+ handleConfigChange({
+ ...pipelineConfig,
+ aggregator_config: {...aggregatorConfig, skeleton_enabled: value},
+ });
return (
<CollapsibleSidebarSection
@@ -67,16 +73,16 @@ export const RealtimePipelinePanel: React.FC = () => {
<Box sx={{p: 2}}>
<RealtimePipelineConfigTree
context="realtime"
- charucoEnabled={charucoEnabled}
+ charucoEnabled={cameraNodeConfig.charuco_tracking_enabled}
onCharucoToggle={handleCharucoToggle}
- skeletonEnabled={skeletonEnabled}
+ skeletonEnabled={cameraNodeConfig.skeleton_tracking_enabled}
onSkeletonToggle={handleSkeletonToggle}
- triangulateEnabled={triangulateEnabled}
- onTriangulateToggle={setTriangulateEnabled}
- filterEnabled={filterEnabled}
- onFilterToggle={setFilterEnabled}
- rigidBodyEnabled={rigidBodyEnabled}
- onRigidBodyToggle={setRigidBodyEnabled}
+ triangulateEnabled={aggregatorConfig.triangulation_enabled}
+ onTriangulateToggle={handleTriangulateToggle}
+ filterEnabled={aggregatorConfig.filter_enabled}
+ onFilterToggle={handleFilterToggle}
+ rigidBodyEnabled={aggregatorConfig.skeleton_enabled}
+ onRigidBodyToggle={handleRigidBodyToggle}
/>
</Box>
</CollapsibleSidebarSection>
diff --git a/freemocap-ui/src/components/old-viewport3d/RigidBodyRenderer.tsx b/freemocap-ui/src/components/viewport3d-old/RigidBodyRenderer.tsx
similarity index 100%
rename from freemocap-ui/src/components/old-viewport3d/RigidBodyRenderer.tsx
rename to freemocap-ui/src/components/viewport3d-old/RigidBodyRenderer.tsx
diff --git a/freemocap-ui/src/components/old-viewport3d/SceneEnvironment.tsx b/freemocap-ui/src/components/viewport3d-old/SceneEnvironment.tsx
similarity index 100%
rename from freemocap-ui/src/components/old-viewport3d/SceneEnvironment.tsx
rename to freemocap-ui/src/components/viewport3d-old/SceneEnvironment.tsx
diff --git a/freemocap-ui/src/components/old-viewport3d/SkeletonRenderer.tsx b/freemocap-ui/src/components/viewport3d-old/SkeletonRenderer.tsx
similarity index 100%
rename from freemocap-ui/src/components/old-viewport3d/SkeletonRenderer.tsx
rename to freemocap-ui/src/components/viewport3d-old/SkeletonRenderer.tsx
diff --git a/freemocap-ui/src/components/old-viewport3d/ThreeJsCanvas.tsx b/freemocap-ui/src/components/viewport3d-old/ThreeJsCanvas.tsx
similarity index 100%
rename from freemocap-ui/src/components/old-viewport3d/ThreeJsCanvas.tsx
rename to freemocap-ui/src/components/viewport3d-old/ThreeJsCanvas.tsx
diff --git a/freemocap-ui/src/components/old-viewport3d/ThreeJsScene.tsx b/freemocap-ui/src/components/viewport3d-old/ThreeJsScene.tsx
similarity index 100%
rename from freemocap-ui/src/components/old-viewport3d/ThreeJsScene.tsx
rename to freemocap-ui/src/components/viewport3d-old/ThreeJsScene.tsx
diff --git a/freemocap-ui/src/components/old-viewport3d/face-contours.ts b/freemocap-ui/src/components/viewport3d-old/face-contours.ts
similarity index 100%
rename from freemocap-ui/src/components/old-viewport3d/face-contours.ts
rename to freemocap-ui/src/components/viewport3d-old/face-contours.ts
diff --git a/freemocap-ui/src/components/old-viewport3d/fit-camera.ts b/freemocap-ui/src/components/viewport3d-old/fit-camera.ts
similarity index 100%
rename from freemocap-ui/src/components/old-viewport3d/fit-camera.ts
rename to freemocap-ui/src/components/viewport3d-old/fit-camera.ts
diff --git a/freemocap-ui/src/components/old-viewport3d/skeleton-colors.ts b/freemocap-ui/src/components/viewport3d-old/skeleton-colors.ts
similarity index 100%
rename from freemocap-ui/src/components/old-viewport3d/skeleton-colors.ts
rename to freemocap-ui/src/components/viewport3d-old/skeleton-colors.ts
diff --git a/freemocap-ui/src/components/old-viewport3d/skeleton-config.ts b/freemocap-ui/src/components/viewport3d-old/skeleton-config.ts
similarity index 100%
rename from freemocap-ui/src/components/old-viewport3d/skeleton-config.ts
rename to freemocap-ui/src/components/viewport3d-old/skeleton-config.ts
diff --git a/freemocap-ui/src/components/old-viewport3d/viewport3d-types.ts b/freemocap-ui/src/components/viewport3d-old/viewport3d-types.ts
similarity index 100%
rename from freemocap-ui/src/components/old-viewport3d/viewport3d-types.ts
rename to freemocap-ui/src/components/viewport3d-old/viewport3d-types.ts
diff --git a/freemocap-ui/src/components/old-viewport3d/virtual-points.ts b/freemocap-ui/src/components/viewport3d-old/virtual-points.ts
similarity index 100%
rename from freemocap-ui/src/components/old-viewport3d/virtual-points.ts
rename to freemocap-ui/src/components/viewport3d-old/virtual-points.ts
diff --git a/freemocap-ui/src/constants/server-urls.ts b/freemocap-ui/src/constants/server-urls.ts
index 5a3c097c..27c9238a 100644
--- a/freemocap-ui/src/constants/server-urls.ts
+++ b/freemocap-ui/src/constants/server-urls.ts
@@ -55,20 +55,9 @@ class ServerUrls {
startRecording: `${baseUrl}/skellycam/camera/group/all/record/start`,
stopRecording: `${baseUrl}/skellycam/camera/group/all/record/stop`,
- // Playback endpoints
- playbackRecordings: `${baseUrl}/skellycam/playback/recordings`,
- playbackLoad: `${baseUrl}/skellycam/playback/load`,
- playbackVideos: `${baseUrl}/skellycam/playback/videos`,
- playbackVideoStream: (videoId: string) => `${baseUrl}/skellycam/playback/video/${videoId}`,
- playbackTimestamps: (videoId: string) => `${baseUrl}/skellycam/playback/timestamps/${videoId}`,
- playbackAllTimestamps: `${baseUrl}/skellycam/playback/timestamps`,
-
- // Pipeline endpoints
- pipelineConnectOrUpdate: `${baseUrl}/freemocap/pipeline/connect`,
- pipelineClose: `${baseUrl}/freemocap/pipeline/all/close`,
- pipelinePauseUnpause: `${baseUrl}/freemocap/pipeline/all/pause_unpause`,
- pipelineRecordStart: `${baseUrl}/freemocap/pipeline/all/record/start`,
- pipelineRecordStop: `${baseUrl}/freemocap/pipeline/all/record/stop`,
+ // Realtime pipeline endpoints
+ realtimeConnectOrUpdate: `${baseUrl}/freemocap/realtime/apply`,
+ realtimeClose: `${baseUrl}/freemocap/realtime/all/close`,
// Calibration endpoints
calibrationStartRecording: `${baseUrl}/freemocap/calibration/recording/start`,
diff --git a/freemocap-ui/src/store/index.ts b/freemocap-ui/src/store/index.ts
index aa1eda8e..4b1bbaee 100644
--- a/freemocap-ui/src/store/index.ts
+++ b/freemocap-ui/src/store/index.ts
@@ -10,4 +10,3 @@ export * from './slices/theme';
export * from './slices/videos';
export * from './slices/realtime';
export * from './slices/mocap';
-export * from './slices/settings';
diff --git a/freemocap-ui/src/store/slices/realtime/realtime-selectors.ts b/freemocap-ui/src/store/slices/realtime/realtime-selectors.ts
index 3bbf4839..c6c31e84 100644
--- a/freemocap-ui/src/store/slices/realtime/realtime-selectors.ts
+++ b/freemocap-ui/src/store/slices/realtime/realtime-selectors.ts
@@ -1,23 +1,19 @@
-// basic selectors
import {RootState} from "@/store";
import {createSelector} from "@reduxjs/toolkit";
+// ==================== Primitive Selectors ====================
+
export const selectPipelineState = (state: RootState) => state.realtime;
export const selectIsPipelineConnected = (state: RootState) => state.realtime.isConnected;
export const selectPipelineId = (state: RootState) => state.realtime.pipelineId;
export const selectCameraGroupId = (state: RootState) => state.realtime.cameraGroupId;
export const selectIsPipelineLoading = (state: RootState) => state.realtime.isLoading;
export const selectPipelineError = (state: RootState) => state.realtime.error;
+export const selectPipelineConfig = (state: RootState) => state.realtime.pipelineConfig;
+export const selectCameraNodeConfig = (state: RootState) => state.realtime.pipelineConfig.camera_node_config;
+export const selectAggregatorConfig = (state: RootState) => state.realtime.pipelineConfig.aggregator_config;
-// derived selectors
-export const selectPipelineInfo = createSelector(
- [selectIsPipelineConnected, selectPipelineId, selectCameraGroupId],
- (isConnected, pipelineId, cameraGroupId) => ({
- isConnected,
- pipelineId,
- cameraGroupId,
- })
-);
+// ==================== Derived Selectors ====================
export const selectCanConnectPipeline = createSelector(
[selectIsPipelineConnected, selectIsPipelineLoading, (state: RootState) => state.cameras.cameras],
diff --git a/freemocap-ui/src/store/slices/realtime/realtime-slice.ts b/freemocap-ui/src/store/slices/realtime/realtime-slice.ts
index 7cf6f1ba..6e2e8f0d 100644
--- a/freemocap-ui/src/store/slices/realtime/realtime-slice.ts
+++ b/freemocap-ui/src/store/slices/realtime/realtime-slice.ts
@@ -1,47 +1,46 @@
-import {createSlice} from "@reduxjs/toolkit";
-import {PipelineState} from "@/store/slices/realtime/realtime-types";
-import {closePipeline, connectRealtimePipeline} from "@/store/slices/realtime/realtime-thunks";
-import {serverSettingsCleared, serverSettingsUpdated} from "@/store/slices/settings/settings-slice";
+import {createSlice, PayloadAction} from "@reduxjs/toolkit";
+import {defaultRealtimePipelineConfig, PipelineState, RealtimePipelineConfig} from "@/store/slices/realtime/realtime-types";
+import {applyRealtimePipeline, closePipeline} from "@/store/slices/realtime/realtime-thunks";
const initialState: PipelineState = {
+ pipelineConfig: defaultRealtimePipelineConfig,
cameraGroupId: null,
pipelineId: null,
isConnected: false,
isLoading: false,
error: null,
-}
+};
export const realtimeSlice = createSlice({
name: 'pipeline',
initialState,
reducers: {
- pipelineStateReset: (state) => {
- state.cameraGroupId = null;
- state.pipelineId = null;
- state.isConnected = false;
- state.isLoading = false;
- state.error = null;
- }
+ pipelineStateReset: () => initialState,
+
+ pipelineConfigUpdated: (state, action: PayloadAction<RealtimePipelineConfig>) => {
+ state.pipelineConfig = action.payload;
+ },
},
extraReducers: (builder) => {
builder
- // ========== Connect Pipeline (HTTP) ==========
- .addCase(connectRealtimePipeline.pending, (state) => {
+ // ========== Apply Pipeline (POST /realtime/apply) ==========
+ .addCase(applyRealtimePipeline.pending, (state) => {
state.isLoading = true;
state.error = null;
})
- .addCase(connectRealtimePipeline.fulfilled, (state, action) => {
+ .addCase(applyRealtimePipeline.fulfilled, (state, action) => {
state.cameraGroupId = action.payload.camera_group_id;
state.pipelineId = action.payload.pipeline_id;
+ state.pipelineConfig = action.meta.arg;
state.isConnected = true;
state.isLoading = false;
})
- .addCase(connectRealtimePipeline.rejected, (state, action) => {
+ .addCase(applyRealtimePipeline.rejected, (state, action) => {
state.isLoading = false;
- state.error = action.error.message || 'Failed to connect pipeline';
+ state.error = action.error.message || 'Failed to apply pipeline';
})
- // ========== Close Pipeline (HTTP) ==========
+ // ========== Close Pipeline (DELETE /realtime/all/close) ==========
.addCase(closePipeline.pending, (state) => {
state.isLoading = true;
state.error = null;
@@ -54,29 +53,9 @@ export const realtimeSlice = createSlice({
})
.addCase(closePipeline.rejected, (state, action) => {
state.isLoading = false;
- state.error = action.error.message || 'Failed to disconnect pipeline';
- })
-
- // ========== WebSocket settings/state β€” sync pipeline status ==========
- .addCase(serverSettingsUpdated, (state, action) => {
- const backendPipeline = action.payload.settings.pipeline;
- // Only overwrite if not mid-HTTP-request (isLoading guards against races)
- if (!state.isLoading) {
- state.isConnected = backendPipeline.is_connected;
- state.pipelineId = backendPipeline.pipeline_id;
- state.cameraGroupId = backendPipeline.camera_group_id;
- }
- })
-
- // ========== WebSocket disconnected β€” clear pipeline state ==========
- .addCase(serverSettingsCleared, (state) => {
- state.cameraGroupId = null;
- state.pipelineId = null;
- state.isConnected = false;
- state.isLoading = false;
- state.error = null;
+ state.error = action.error.message || 'Failed to close pipeline';
});
},
});
-export const {pipelineStateReset} = realtimeSlice.actions;
+export const {pipelineStateReset, pipelineConfigUpdated} = realtimeSlice.actions;
diff --git a/freemocap-ui/src/store/slices/realtime/realtime-thunks.ts b/freemocap-ui/src/store/slices/realtime/realtime-thunks.ts
index b32c99a9..9c8d2d7e 100644
--- a/freemocap-ui/src/store/slices/realtime/realtime-thunks.ts
+++ b/freemocap-ui/src/store/slices/realtime/realtime-thunks.ts
@@ -1,56 +1,45 @@
-import {createAsyncThunk} from "@reduxjs/toolkit";
+import {createAsyncThunk, createSelector} from "@reduxjs/toolkit";
import {RootState, selectSelectedCameraConfigs} from "@/store";
import {serverUrls} from "@/services";
-import {PipelineConnectRequest, PipelineConnectResponse,} from "@/store/slices/realtime/realtime-types";
+import {PipelineApplyResponse, RealtimePipelineConfig} from "@/store/slices/realtime/realtime-types";
-export const connectRealtimePipeline = createAsyncThunk<
- PipelineConnectResponse,
- PipelineConnectRequest | undefined,
- { state: RootState }>(
- 'pipeline/connect',
- async (request={}, {getState}) => {
- const state = getState();
+export const applyRealtimePipeline = createAsyncThunk<
+ PipelineApplyResponse,
+ RealtimePipelineConfig,
+ { state: RootState }
+>(
+ 'realtime/apply',
+ async (realtimeConfig, {getState}) => {
+ const cameraConfigs = selectSelectedCameraConfigs(getState());
- const cameraConfigs = selectSelectedCameraConfigs(state);
- const response = await fetch(serverUrls.endpoints.pipelineConnectOrUpdate, {
+
+ const response = await fetch(serverUrls.endpoints.realtimeConnectOrUpdate, {
method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ camera_configs: cameraConfigs, ...request }),
+ headers: {'Content-Type': 'application/json'},
+ body: JSON.stringify({
+ realtimeConfig,
+ cameraConfigs
+ }),
});
if (!response.ok) {
- const error = await response.json()
- throw new Error(`Failed to connect pipeline: ${error.message || response.statusText}`);
+ const error = await response.json();
+ throw new Error(`Failed to apply realtime: ${error.detail || response.statusText}`);
}
- return await response.json() as Promise<PipelineConnectResponse>;
- })
-
-
-export const closePipeline = createAsyncThunk<void, void, { state: RootState }>(
- 'pipeline/close',
- async () => {
- const response = await fetch(serverUrls.endpoints.pipelineClose, {
- method: 'DELETE',
- });
- if (!response.ok) {
- console.error(`Failed to close pipeline: ${response.statusText}`);
- }
+ return response.json() as Promise<PipelineApplyResponse>;
}
);
-
-
-
-export const pauseUnpausePipeline = createAsyncThunk<void, void, { state: RootState }>(
- 'cameras/pause',
+export const closePipeline = createAsyncThunk<void, void, { state: RootState }>(
+ 'realtime/close',
async () => {
- const response = await fetch(serverUrls.endpoints.pipelinePauseUnpause, {
- method: 'GET',
+ const response = await fetch(serverUrls.endpoints.realtimeClose, {
+ method: 'DELETE',
});
if (!response.ok) {
- throw new Error(`Failed to pause/unpause cameras: ${response.statusText}`);
+ throw new Error(`Failed to close realtime: ${response.statusText}`);
}
}
);
diff --git a/freemocap-ui/src/store/slices/realtime/realtime-types.ts b/freemocap-ui/src/store/slices/realtime/realtime-types.ts
index 52b3b119..a069356b 100644
--- a/freemocap-ui/src/store/slices/realtime/realtime-types.ts
+++ b/freemocap-ui/src/store/slices/realtime/realtime-types.ts
@@ -1,44 +1,55 @@
-import {z} from 'zod';
-import {CameraConfig} from "@/store";
+export type CalibrationSource = 'most_recent' | 'specified';
-// ==================== API Request/Response Types ====================
-export interface PipelineConnectRequest {
- camera_configs?: string[];
+export interface CameraNodeConfig {
+ charuco_tracking_enabled: boolean;
+ skeleton_tracking_enabled: boolean;
}
-export interface PipelineConnectResponse {
+export interface RealtimeAggregatorNodeConfig {
+ calibration_toml_source: CalibrationSource;
+ calibration_toml_path: string | null;
+ triangulation_enabled: boolean;
+ filter_enabled: boolean;
+ skeleton_enabled: boolean;
+}
+
+export interface RealtimePipelineConfig {
+ camera_node_config: CameraNodeConfig;
+ aggregator_config: RealtimeAggregatorNodeConfig;
+}
+
+export const defaultRealtimePipelineConfig: RealtimePipelineConfig = {
+ camera_node_config: {
+ charuco_tracking_enabled: true,
+ skeleton_tracking_enabled: true,
+ },
+ aggregator_config: {
+ calibration_toml_source: 'most_recent',
+ calibration_toml_path: null,
+ triangulation_enabled: true,
+ filter_enabled: false,
+ skeleton_enabled: true,
+ },
+};
+
+// ==================== API Request/Response ====================
+
+export interface PipelineApplyRequest {
+ realtime_config: RealtimePipelineConfig;
+}
+
+export interface PipelineApplyResponse {
camera_group_id: string;
pipeline_id: string;
- camera_configs: Record<string, CameraConfig>;
}
-// ==================== Pipeline State ====================
+// ==================== Redux State ====================
+
export interface PipelineState {
+ pipelineConfig: RealtimePipelineConfig;
cameraGroupId: string | null;
pipelineId: string | null;
isConnected: boolean;
isLoading: boolean;
error: string | null;
}
-
-
-const RealtimePipelineConfigSchema = z.object({
- pipeline_id: z.string(),
- parameters: z.record(z.string(), z.any()),
-})
-
-
-export type RealtimePipelineConfig = z.infer<typeof RealtimePipelineConfigSchema>;
-export interface ProcessingPipeline {
- id: string;
- name: string;
- isActive: boolean;
- config: RealtimePipelineConfig
-}
-
-export interface ProcessingPipelineState {
- pipelines: ProcessingPipeline[];
- isLoading: boolean;
- isActive: boolean;
- error: string | null;
-}
diff --git a/freemocap-ui/src/store/slices/settings/index.ts b/freemocap-ui/src/store/slices/settings/index.ts
deleted file mode 100644
index 1d68c6f4..00000000
--- a/freemocap-ui/src/store/slices/settings/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export * from "./settings-slice";
-export * from "./settings-selectors";
-export * from "./settings-types";
diff --git a/freemocap-ui/src/store/slices/settings/settings-selectors.ts b/freemocap-ui/src/store/slices/settings/settings-selectors.ts
deleted file mode 100644
index e22616d6..00000000
--- a/freemocap-ui/src/store/slices/settings/settings-selectors.ts
+++ /dev/null
@@ -1,116 +0,0 @@
-import {createSelector} from "@reduxjs/toolkit";
-import {RootState} from "@/store/types";
-import {
- BackendCalibrationConfig,
- BackendCalibrationSettings,
- BackendCameraState,
- BackendMocapConfig,
- BackendMocapSettings,
- BackendPipelineSettings,
- FreeMoCapSettings,
-} from "./settings-types";
-
-// ---------------------------------------------------------------------------
-// Root selectors
-// ---------------------------------------------------------------------------
-
-export const selectServerSettings = (state: RootState): FreeMoCapSettings | null =>
- state.settings.settings;
-
-export const selectServerSettingsVersion = (state: RootState): number =>
- state.settings.version;
-
-export const selectServerSettingsInitialized = (state: RootState): boolean =>
- state.settings.isInitialized;
-
-// ---------------------------------------------------------------------------
-// Camera selectors
-// ---------------------------------------------------------------------------
-
-export const selectBackendCameras = createSelector(
- [selectServerSettings],
- (settings): Record<string, BackendCameraState> => settings?.cameras ?? {},
-);
-
-export const selectBackendCameraIds = createSelector(
- [selectBackendCameras],
- (cameras): string[] => Object.keys(cameras),
-);
-
-export const selectBackendConnectedCameraCount = createSelector(
- [selectBackendCameras],
- (cameras): number =>
- Object.values(cameras).filter((c) => c.status === "connected").length,
-);
-
-// ---------------------------------------------------------------------------
-// Pipeline selectors
-// ---------------------------------------------------------------------------
-
-export const selectBackendPipeline = createSelector(
- [selectServerSettings],
- (settings): BackendPipelineSettings | null => settings?.pipeline ?? null,
-);
-
-export const selectBackendPipelineIsConnected = createSelector(
- [selectBackendPipeline],
- (pipeline): boolean => pipeline?.is_connected ?? false,
-);
-
-export const selectBackendPipelineId = createSelector(
- [selectBackendPipeline],
- (pipeline): string | null => pipeline?.pipeline_id ?? null,
-);
-
-// ---------------------------------------------------------------------------
-// Calibration selectors
-// ---------------------------------------------------------------------------
-
-export const selectBackendCalibration = createSelector(
- [selectServerSettings],
- (settings): BackendCalibrationSettings | null => settings?.calibration ?? null,
-);
-
-export const selectBackendCalibrationConfig = createSelector(
- [selectBackendCalibration],
- (cal): BackendCalibrationConfig | null => cal?.config ?? null,
-);
-
-export const selectBackendCalibrationIsRecording = createSelector(
- [selectBackendCalibration],
- (cal): boolean => cal?.is_recording ?? false,
-);
-
-export const selectBackendCalibrationProgress = createSelector(
- [selectBackendCalibration],
- (cal): number => cal?.recording_progress ?? 0,
-);
-
-export const selectBackendHasCalibrationToml = createSelector(
- [selectBackendCalibration],
- (cal): boolean => cal?.has_calibration_toml ?? false,
-);
-
-// ---------------------------------------------------------------------------
-// MoCap selectors
-// ---------------------------------------------------------------------------
-
-export const selectBackendMocap = createSelector(
- [selectServerSettings],
- (settings): BackendMocapSettings | null => settings?.mocap ?? null,
-);
-
-export const selectBackendMocapConfig = createSelector(
- [selectBackendMocap],
- (moc): BackendMocapConfig | null => moc?.config ?? null,
-);
-
-export const selectBackendMocapIsRecording = createSelector(
- [selectBackendMocap],
- (moc): boolean => moc?.is_recording ?? false,
-);
-
-export const selectBackendMocapProgress = createSelector(
- [selectBackendMocap],
- (moc): number => moc?.recording_progress ?? 0,
-);
diff --git a/freemocap-ui/src/store/slices/settings/settings-slice.ts b/freemocap-ui/src/store/slices/settings/settings-slice.ts
deleted file mode 100644
index ba661a4c..00000000
--- a/freemocap-ui/src/store/slices/settings/settings-slice.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import {createSlice, PayloadAction} from "@reduxjs/toolkit";
-import {FreeMoCapSettings, SettingsStateMessage} from "./settings-types";
-
-export interface ServerSettingsState {
- settings: FreeMoCapSettings | null;
- version: number;
- lastUpdated: string | null;
- isInitialized: boolean;
-}
-
-const initialState: ServerSettingsState = {
- settings: null,
- version: -1,
- lastUpdated: null,
- isInitialized: false,
-};
-
-export const settingsSlice = createSlice({
- name: "serverSettings",
- initialState,
- reducers: {
- /**
- * Replace the entire settings blob from a backend settings/state message.
- * Only applies if the incoming version is newer than what we have.
- */
- serverSettingsUpdated: (state, action: PayloadAction<SettingsStateMessage>) => {
- const {settings, version} = action.payload;
- if (version <= state.version) {
- return; // Stale message β€” ignore
- }
- state.settings = settings;
- state.version = version;
- state.lastUpdated = new Date().toISOString();
- state.isInitialized = true;
- },
-
- /**
- * Reset to initial state (e.g., on WebSocket disconnect).
- */
- serverSettingsCleared: (state) => {
- state.settings = null;
- state.version = -1;
- state.lastUpdated = null;
- state.isInitialized = false;
- },
- },
-});
-
-export const {
- serverSettingsUpdated,
- serverSettingsCleared,
-} = settingsSlice.actions;
diff --git a/freemocap-ui/src/store/slices/settings/settings-types.ts b/freemocap-ui/src/store/slices/settings/settings-types.ts
deleted file mode 100644
index 69675a7f..00000000
--- a/freemocap-ui/src/store/slices/settings/settings-types.ts
+++ /dev/null
@@ -1,165 +0,0 @@
-/**
- * TypeScript types mirroring the backend FreeMoCapSettings Pydantic models.
- *
- * These represent the authoritative backend state pushed over WebSocket.
- * Field names use snake_case to match the JSON the backend sends.
- */
-
-// ---------------------------------------------------------------------------
-// Camera layer (mirrors skellycam CameraConfig + runtime status)
-// ---------------------------------------------------------------------------
-
-export interface BackendImageResolution {
- height: number;
- width: number;
-}
-
-export interface BackendCameraConfig {
- camera_id: string;
- camera_index: number;
- camera_name: string;
- use_this_camera: boolean;
- resolution: BackendImageResolution;
- color_channels: number;
- pixel_format: string;
- exposure_mode: string;
- exposure: number;
- framerate: number;
- rotation: number;
- capture_fourcc: string;
- writer_fourcc: string;
-}
-
-export type BackendCameraStatus = "disconnected" | "connected" | "error";
-
-export interface BackendCameraState {
- config: BackendCameraConfig;
- status: BackendCameraStatus;
-}
-
-// ---------------------------------------------------------------------------
-// Calibration config (mirrors CalibrationPipelineConfig)
-// ---------------------------------------------------------------------------
-
-export type CalibrationSolverMethod = "anipose" | "pyceres";
-
-export interface BackendCalibrationConfig {
- calibration_recording_folder: string | null;
- charuco_board_x_squares: number;
- charuco_board_y_squares: number;
- charuco_square_length: number;
- solver_method: CalibrationSolverMethod;
- use_groundplane: boolean;
- pyceres_solver_config: Record<string, unknown>;
-}
-
-export interface BackendCalibrationSettings {
- config: BackendCalibrationConfig;
- is_recording: boolean;
- recording_progress: number;
- last_recording_path: string | null;
- has_calibration_toml: boolean;
-}
-
-// ---------------------------------------------------------------------------
-// MoCap config (mirrors MocapPipelineConfig)
-// ---------------------------------------------------------------------------
-
-export interface BackendEstimatorConfig {
- max_samples: number;
- min_samples_for_full_confidence: number;
- iqr_confidence_sensitivity: number;
-}
-
-export interface BackendRealtimeFilterConfig {
- min_cutoff: number;
- beta: number;
- d_cutoff: number;
- fabrik_tolerance: number;
- fabrik_max_iterations: number;
- height_meters: number;
- noise_sigma: number;
- estimator_config: BackendEstimatorConfig;
- max_reprojection_error_px: number;
- max_velocity_m_per_s: number;
- max_rejected_streak: number;
- max_prediction_frames: number;
- prediction_velocity_decay: number;
-}
-
-export interface BackendMocapConfig {
- detector: Record<string, unknown>;
- skeleton_filter: BackendRealtimeFilterConfig;
-}
-
-export interface BackendMocapSettings {
- config: BackendMocapConfig;
- is_recording: boolean;
- recording_progress: number;
- last_recording_path: string | null;
-}
-
-// ---------------------------------------------------------------------------
-// Pipeline config (mirrors RealtimePipelineConfig + runtime status)
-// ---------------------------------------------------------------------------
-
-export interface BackendRealtimePipelineConfig {
- camera_configs: Record<string, BackendCameraConfig>;
- calibration_config: BackendCalibrationConfig;
- mocap_config: BackendMocapConfig;
- calibration_detection_enabled: boolean;
- mocap_detection_enabled: boolean;
-}
-
-export interface BackendPipelineSettings {
- config: BackendRealtimePipelineConfig | null;
- is_connected: boolean;
- pipeline_id: string | null;
- camera_group_id: string | null;
- is_paused: boolean;
-}
-
-
-
-// ---------------------------------------------------------------------------
-// Top-level settings blob
-// ---------------------------------------------------------------------------
-
-export interface FreeMoCapSettings {
- cameras: Record<string, BackendCameraState>;
- pipeline: BackendPipelineSettings;
- calibration: BackendCalibrationSettings;
- mocap: BackendMocapSettings;
-}
-
-// ---------------------------------------------------------------------------
-// WebSocket message types
-// ---------------------------------------------------------------------------
-
-export interface SettingsStateMessage {
- message_type: "settings/state";
- settings: FreeMoCapSettings;
- version: number;
-}
-
-export interface SettingsPatchMessage {
- message_type: "settings/patch";
- patch: DeepPartial<FreeMoCapSettings>;
-}
-
-export interface SettingsRequestMessage {
- message_type: "settings/request";
-}
-
-export type SettingsMessage =
- | SettingsStateMessage
- | SettingsPatchMessage
- | SettingsRequestMessage;
-
-// ---------------------------------------------------------------------------
-// Utility: deep partial for patch payloads
-// ---------------------------------------------------------------------------
-
-export type DeepPartial<T> = {
- [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
-};
diff --git a/freemocap-ui/src/store/store.ts b/freemocap-ui/src/store/store.ts
index 1fb8649e..982262ad 100644
--- a/freemocap-ui/src/store/store.ts
+++ b/freemocap-ui/src/store/store.ts
@@ -6,7 +6,6 @@ import {videosSlice} from "@/store/slices/videos";
import {realtimeSlice} from "@/store/slices/realtime";
import {calibrationSlice} from "@/store/slices/calibration/calibration-slice";
import {mocapSlice} from "@/store/slices/mocap/mocap-slice";
-import {settingsSlice} from "@/store/slices/settings/settings-slice";
import {localeSlice} from "@/store/slices/locale";
export const store = configureStore({
@@ -18,7 +17,6 @@ export const store = configureStore({
realtime: realtimeSlice.reducer,
calibration: calibrationSlice.reducer,
mocap: mocapSlice.reducer,
- settings: settingsSlice.reducer,
locale: localeSlice.reducer
},
});
diff --git a/freemocap/api/http/app/debug.py b/freemocap/api/http/app/debug.py
deleted file mode 100644
index f67082ef..00000000
--- a/freemocap/api/http/app/debug.py
+++ /dev/null
@@ -1,467 +0,0 @@
-"""
-Debug endpoint: serves an HTML page that displays raw settings JSON
-from both the HTTP GET /settings endpoint and the WebSocket settings/state
-push, side by side, for visual confirmation of backend/frontend sync.
-
-Access at: /debug/settings-sync
-"""
-import logging
-
-from fastapi import APIRouter
-from fastapi.responses import HTMLResponse
-
-logger = logging.getLogger(__name__)
-
-debug_router = APIRouter(prefix="/debug", tags=["Debug"])
-
-_DEBUG_PAGE_HTML = r"""<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>FreeMoCap Settings Sync Debug</title>
- <style>
- @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&family=DM+Sans:wght@400;500;700&display=swap');
-
- * { margin: 0; padding: 0; box-sizing: border-box; }
-
- :root {
- --bg: #0d1117;
- --surface: #161b22;
- --border: #30363d;
- --text: #c9d1d9;
- --text-dim: #8b949e;
- --green: #3fb950;
- --red: #f85149;
- --yellow: #d29922;
- --blue: #58a6ff;
- --orange: #d18616;
- --mono: 'JetBrains Mono', monospace;
- --sans: 'DM Sans', sans-serif;
- }
-
- body {
- background: var(--bg);
- color: var(--text);
- font-family: var(--sans);
- padding: 24px;
- min-height: 100vh;
- }
-
- header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 20px;
- padding-bottom: 16px;
- border-bottom: 1px solid var(--border);
- }
-
- h1 {
- font-family: var(--mono);
- font-size: 18px;
- font-weight: 700;
- color: #f0f6fc;
- letter-spacing: -0.5px;
- }
-
- h1 span { color: var(--blue); }
-
- .controls {
- display: flex;
- gap: 12px;
- align-items: center;
- }
-
- label {
- font-family: var(--mono);
- font-size: 12px;
- color: var(--text-dim);
- }
-
- input[type="number"] {
- background: var(--surface);
- border: 1px solid var(--border);
- color: var(--text);
- font-family: var(--mono);
- font-size: 13px;
- padding: 6px 10px;
- border-radius: 6px;
- width: 80px;
- }
-
- button {
- background: var(--surface);
- border: 1px solid var(--border);
- color: var(--text);
- font-family: var(--mono);
- font-size: 12px;
- padding: 6px 14px;
- border-radius: 6px;
- cursor: pointer;
- transition: border-color 0.15s;
- }
-
- button:hover { border-color: var(--blue); color: var(--blue); }
-
- .status-bar {
- display: flex;
- gap: 24px;
- margin-bottom: 16px;
- font-family: var(--mono);
- font-size: 12px;
- }
-
- .status-item {
- display: flex;
- align-items: center;
- gap: 6px;
- }
-
- .dot {
- width: 8px;
- height: 8px;
- border-radius: 50%;
- background: var(--text-dim);
- }
-
- .dot.connected { background: var(--green); box-shadow: 0 0 6px var(--green); }
- .dot.error { background: var(--red); box-shadow: 0 0 6px var(--red); }
-
- .sync-verdict {
- margin-left: auto;
- padding: 4px 12px;
- border-radius: 4px;
- font-weight: 600;
- font-size: 13px;
- }
-
- .sync-verdict.synced { background: rgba(63,185,80,0.15); color: var(--green); }
- .sync-verdict.desynced { background: rgba(248,81,73,0.15); color: var(--red); }
- .sync-verdict.pending { background: rgba(210,153,34,0.15); color: var(--yellow); }
-
- .panels {
- display: grid;
- grid-template-columns: 1fr 1fr;
- gap: 16px;
- }
-
- .panel {
- background: var(--surface);
- border: 1px solid var(--border);
- border-radius: 8px;
- display: flex;
- flex-direction: column;
- overflow: hidden;
- }
-
- .panel-header {
- padding: 10px 16px;
- border-bottom: 1px solid var(--border);
- display: flex;
- align-items: center;
- justify-content: space-between;
- font-family: var(--mono);
- font-size: 13px;
- font-weight: 600;
- }
-
- .panel-header .source { color: var(--blue); }
- .panel-header .meta { color: var(--text-dim); font-weight: 400; font-size: 11px; }
-
- .panel-body {
- padding: 12px 16px;
- overflow: auto;
- max-height: calc(100vh - 200px);
- }
-
- pre {
- font-family: var(--mono);
- font-size: 12px;
- line-height: 1.6;
- white-space: pre-wrap;
- word-break: break-word;
- color: var(--text);
- }
-
- pre .key { color: var(--blue); }
- pre .string { color: #a5d6ff; }
- pre .number { color: #79c0ff; }
- pre .boolean { color: var(--orange); }
- pre .null { color: var(--text-dim); }
-
- .empty-state {
- color: var(--text-dim);
- font-family: var(--mono);
- font-size: 13px;
- padding: 40px 0;
- text-align: center;
- }
-
- .diff-summary {
- margin-top: 16px;
- background: var(--surface);
- border: 1px solid var(--border);
- border-radius: 8px;
- padding: 12px 16px;
- }
-
- .diff-summary h3 {
- font-family: var(--mono);
- font-size: 13px;
- font-weight: 600;
- margin-bottom: 8px;
- color: var(--text-dim);
- }
-
- .diff-entry {
- font-family: var(--mono);
- font-size: 12px;
- padding: 4px 0;
- border-bottom: 1px solid var(--border);
- }
-
- .diff-entry:last-child { border-bottom: none; }
- .diff-path { color: var(--yellow); }
- .diff-val-http { color: var(--red); }
- .diff-val-ws { color: var(--green); }
- </style>
-</head>
-<body>
-
-<header>
- <h1>πŸ’€ FreeMoCap <span>Settings Sync Debug</span></h1>
- <div class="controls">
- <label>Poll (ms)
- <input type="number" id="poll-interval" value="2000" />
- </label>
- <button id="btn-connect">Connect</button>
- <button id="btn-disconnect" style="display:none;">Disconnect</button>
- <button id="btn-fetch-once">Fetch HTTP Once</button>
- </div>
-</header>
-
-<div class="status-bar">
- <div class="status-item">
- <div class="dot" id="dot-ws"></div>
- <span>WebSocket: <span id="ws-status">disconnected</span></span>
- </div>
- <div class="status-item">
- <div class="dot" id="dot-http"></div>
- <span>HTTP: <span id="http-status">idle</span></span>
- </div>
- <div class="status-item">
- <div class="dot" id="dot-http-version"></div>
- <span>HTTP v<span id="http-version">β€”</span></span>
- </div>
- <div class="status-item">
- <div class="dot" id="dot-ws-version"></div>
- <span>WS v<span id="ws-version">β€”</span></span>
- </div>
- <div class="sync-verdict pending" id="sync-verdict">waiting for data</div>
-</div>
-
-<div class="panels">
- <div class="panel">
- <div class="panel-header">
- <span><span class="source">GET /settings</span> β€” Backend (HTTP)</span>
- <span class="meta" id="http-timestamp">β€”</span>
- </div>
- <div class="panel-body">
- <pre id="http-json"><div class="empty-state">Click "Connect" or "Fetch HTTP Once"</div></pre>
- </div>
- </div>
- <div class="panel">
- <div class="panel-header">
- <span><span class="source">ws://…/websocket/connect</span> β€” Frontend (WebSocket)</span>
- <span class="meta" id="ws-timestamp">β€”</span>
- </div>
- <div class="panel-body">
- <pre id="ws-json"><div class="empty-state">Click "Connect" to open WebSocket</div></pre>
- </div>
- </div>
-</div>
-
-<div class="diff-summary" id="diff-section" style="display:none;">
- <h3>⚠ Differences (HTTP settings ↔ WebSocket settings)</h3>
- <div id="diff-entries"></div>
-</div>
-
-<script>
- let ws = null;
- let pollTimer = null;
- let httpData = null;
- let wsData = null;
-
- const $ = (id) => document.getElementById(id);
-
- // Derive HTTP and WS base URLs from the page's own origin,
- // since this page is served by the same FastAPI app.
- const HTTP_BASE = window.location.origin;
- const WS_BASE = HTTP_BASE.replace(/^http/, 'ws');
-
- function highlightJson(obj) {
- const raw = JSON.stringify(obj, null, 2);
- return raw
- .replace(/("(?:[^"\\\\]|\\\\.)*")\s*:/g, (_, key) => `<span class="key">${key}</span>:`)
- .replace(/:\s*("(?:[^"\\\\]|\\\\.)*")/g, (m, v) => m.replace(v, `<span class="string">${v}</span>`))
- .replace(/:\s*(\d+\.?\d*)/g, (m, v) => m.replace(v, `<span class="number">${v}</span>`))
- .replace(/:\s*(true|false)/g, (m, v) => m.replace(v, `<span class="boolean">${v}</span>`))
- .replace(/:\s*(null)/g, (m, v) => m.replace(v, `<span class="null">${v}</span>`));
- }
-
- function deepDiff(a, b, path) {
- path = path || '';
- const diffs = [];
- if (a === b) return diffs;
- if (a === null || b === null || typeof a !== 'object' || typeof b !== 'object') {
- diffs.push({ path: path || '(root)', httpVal: a, wsVal: b });
- return diffs;
- }
- const allKeys = new Set([...Object.keys(a), ...Object.keys(b)]);
- for (const key of allKeys) {
- const sub = path ? path + '.' + key : key;
- if (!(key in a)) {
- diffs.push({ path: sub, httpVal: undefined, wsVal: b[key] });
- } else if (!(key in b)) {
- diffs.push({ path: sub, httpVal: a[key], wsVal: undefined });
- } else {
- diffs.push(...deepDiff(a[key], b[key], sub));
- }
- }
- return diffs;
- }
-
- function truncVal(v) {
- const s = JSON.stringify(v);
- return s && s.length > 80 ? s.substring(0, 77) + '...' : s;
- }
-
- function updateSyncVerdict() {
- if (!httpData || !wsData) {
- $('sync-verdict').className = 'sync-verdict pending';
- $('sync-verdict').textContent = 'waiting for data';
- $('diff-section').style.display = 'none';
- return;
- }
-
- const diffs = deepDiff(httpData.settings, wsData.settings);
-
- if (diffs.length === 0) {
- $('sync-verdict').className = 'sync-verdict synced';
- const vDiff = (httpData.version || 0) - (wsData.version || 0);
- $('sync-verdict').textContent = '\u2713 IN SYNC' + (vDiff !== 0 ? ' (version diff: ' + vDiff + ')' : '');
- $('diff-section').style.display = 'none';
- } else {
- $('sync-verdict').className = 'sync-verdict desynced';
- $('sync-verdict').textContent = '\u2717 ' + diffs.length + ' DIFFERENCE' + (diffs.length > 1 ? 'S' : '') + ' DETECTED';
- $('diff-section').style.display = 'block';
- $('diff-entries').innerHTML = diffs.map(function(d) {
- return '<div class="diff-entry">' +
- '<span class="diff-path">' + d.path + '</span>: ' +
- '<span class="diff-val-http">HTTP=' + truncVal(d.httpVal) + '</span> \u2194 ' +
- '<span class="diff-val-ws">WS=' + truncVal(d.wsVal) + '</span>' +
- '</div>';
- }).join('');
- }
- }
-
- async function fetchHttp() {
- $('http-status').textContent = 'fetching\u2026';
- $('dot-http').className = 'dot';
- try {
- const resp = await fetch(HTTP_BASE + '/settings');
- if (!resp.ok) throw new Error('HTTP ' + resp.status + ': ' + resp.statusText);
- httpData = await resp.json();
- $('http-json').innerHTML = highlightJson(httpData);
- $('http-timestamp').textContent = new Date().toLocaleTimeString();
- $('http-version').textContent = httpData.version != null ? httpData.version : '\u2014';
- $('http-status').textContent = 'ok';
- $('dot-http').className = 'dot connected';
- updateSyncVerdict();
- } catch (err) {
- $('http-status').textContent = 'error: ' + err.message;
- $('dot-http').className = 'dot error';
- }
- }
-
- function connectWs() {
- const url = WS_BASE + '/websocket/connect';
- ws = new WebSocket(url);
-
- ws.onopen = function() {
- $('ws-status').textContent = 'connected';
- $('dot-ws').className = 'dot connected';
- };
-
- ws.onmessage = function(event) {
- if (typeof event.data !== 'string') return;
- try {
- var data = JSON.parse(event.data);
- if (data.message_type === 'settings/state') {
- wsData = data;
- $('ws-json').innerHTML = highlightJson(data);
- $('ws-timestamp').textContent = new Date().toLocaleTimeString();
- $('ws-version').textContent = data.version != null ? data.version : '\u2014';
- updateSyncVerdict();
- }
- } catch (e) {
- // Non-JSON or non-settings message β€” ignore
- }
- };
-
- ws.onclose = function(event) {
- $('ws-status').textContent = 'closed (code ' + event.code + ')';
- $('dot-ws').className = 'dot';
- ws = null;
- };
-
- ws.onerror = function() {
- $('ws-status').textContent = 'error';
- $('dot-ws').className = 'dot error';
- };
- }
-
- function disconnectAll() {
- if (ws) { ws.close(); ws = null; }
- if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
- $('btn-connect').style.display = '';
- $('btn-disconnect').style.display = 'none';
- $('ws-status').textContent = 'disconnected';
- $('dot-ws').className = 'dot';
- $('http-status').textContent = 'idle';
- $('dot-http').className = 'dot';
- }
-
- $('btn-connect').addEventListener('click', function() {
- connectWs();
- fetchHttp();
- var interval = parseInt($('poll-interval').value, 10) || 2000;
- pollTimer = setInterval(fetchHttp, interval);
- $('btn-connect').style.display = 'none';
- $('btn-disconnect').style.display = '';
- });
-
- $('btn-disconnect').addEventListener('click', disconnectAll);
- $('btn-fetch-once').addEventListener('click', fetchHttp);
-</script>
-
-</body>
-</html>"""
-
-
-@debug_router.get(
- "/settings-sync",
- summary="Settings Sync Debug Page",
- tags=["Debug"],
- response_class=HTMLResponse,
-)
-def settings_sync_debug_page() -> HTMLResponse:
- """
- Serve the settings sync debug page.
-
- Displays raw JSON from both GET /settings (HTTP) and the
- WebSocket settings/state push side-by-side, with a live diff
- showing any discrepancies between the two.
- """
- return HTMLResponse(content=_DEBUG_PAGE_HTML)
diff --git a/freemocap/api/http/app/settings.py b/freemocap/api/http/app/settings.py
deleted file mode 100644
index 49588e82..00000000
--- a/freemocap/api/http/app/settings.py
+++ /dev/null
@@ -1,263 +0,0 @@
-"""
-Unified application settings: the single serializable state blob
-shared between frontend and backend over WebSocket.
-
-Frontend can patch `config` sub-objects via `settings/patch` messages.
-Runtime status fields are read-only from the frontend's perspective β€”
-they are set by commands and hardware state changes on the backend.
-"""
-import asyncio
-import logging
-from enum import Enum
-
-from pydantic import BaseModel, Field
-from skellycam.core.camera.config.camera_config import CameraConfig
-from skellycam.core.types.type_overloads import CameraIdString
-
-from freemocap.core.pipeline.realtime import RealtimePipelineConfig
-from freemocap.core.tasks.calibration.calibration_task_config import PosthocCalibrationPipelineConfig
-from freemocap.core.tasks.mocap.mocap_task_config import PosthocMocapPipelineConfig
-
-logger = logging.getLogger(__name__)
-
-
-# ---------------------------------------------------------------------------
-# Sub-models: compose existing configs with runtime status
-# ---------------------------------------------------------------------------
-
-
-class CameraStatus(str, Enum):
- DISCONNECTED = "disconnected"
- CONNECTED = "connected"
- ERROR = "error"
-
-
-class CameraState(BaseModel):
- """Per-camera config + runtime status."""
- config: CameraConfig
- status: CameraStatus = CameraStatus.DISCONNECTED
-
-
-class PipelineSettings(BaseModel):
- """Realtime pipeline config + runtime status."""
- config: RealtimePipelineConfig | None = None
- is_connected: bool = False
- pipeline_id: str | None = None
- camera_group_id: str | None = None
- is_paused: bool = False
-
-
-class CalibrationSettings(BaseModel):
- """Calibration config + runtime status."""
- config: PosthocCalibrationPipelineConfig = Field(default_factory=PosthocCalibrationPipelineConfig)
- is_recording: bool = False
- recording_progress: float = 0.0
- last_recording_path: str | None = None
- has_calibration_toml: bool = False
-
-
-class MocapSettings(BaseModel):
- """Motion capture config + runtime status."""
- config: PosthocMocapPipelineConfig = Field(default_factory=PosthocMocapPipelineConfig.default_realtime)
- is_recording: bool = False
- recording_progress: float = 0.0
- last_recording_path: str | None = None
-
-
-# ---------------------------------------------------------------------------
-# Top-level settings blob
-# ---------------------------------------------------------------------------
-
-
-class FreeMoCapSettings(BaseModel):
- """
- The authoritative, serializable application state.
-
- Sent in full over WebSocket as a `settings/state` message
- whenever any setting or runtime status changes.
- """
- cameras: dict[CameraIdString, CameraState] = Field(default_factory=dict)
- pipeline: PipelineSettings = Field(default_factory=PipelineSettings)
- calibration: CalibrationSettings = Field(default_factory=CalibrationSettings)
- mocap: MocapSettings = Field(default_factory=MocapSettings)
-
-
-# ---------------------------------------------------------------------------
-# Settings Manager: owns the state, handles patches, notifies on change
-# ---------------------------------------------------------------------------
-
-
-def _deep_merge(base: dict, patch: dict) -> dict:
- """
- RFC 7396 JSON Merge Patch: recursively merge patch into base.
- Keys in patch overwrite base. Nested dicts merge recursively.
- """
- result = base.copy()
- for key, value in patch.items():
- if isinstance(value, dict) and isinstance(result.get(key), dict):
- result[key] = _deep_merge(result[key], value)
- else:
- result[key] = value
- return result
-
-
-class SettingsManager:
- """
- Owns the authoritative FreeMoCapSettings instance.
-
- - Assembles current state from FreemocapApplication on demand.
- - Accepts patches from the frontend, validates, and applies them.
- - Provides an asyncio.Event for WebSocket tasks to await state changes.
- - Maintains a monotonic version counter for ordering.
- """
-
- def __init__(self) -> None:
- self._settings = FreeMoCapSettings()
- self._version: int = 0
- self._changed = asyncio.Event()
-
- @property
- def version(self) -> int:
- return self._version
-
- @property
- def settings(self) -> FreeMoCapSettings:
- return self._settings
-
- def get_state_message(self) -> dict:
- """Build a `settings/state` WebSocket message."""
- return {
- "message_type": "settings/state",
- "settings": self._settings.model_dump(),
- "version": self._version,
- }
-
- def notify_changed(self) -> None:
- """Bump version and wake any waiters."""
- self._version += 1
- self._changed.set()
-
- async def wait_for_change(self) -> None:
- """Block until notify_changed() is called. Clears the event after waking."""
- await self._changed.wait()
- self._changed.clear()
-
- def apply_patch(self, patch: dict) -> FreeMoCapSettings:
- """
- Apply a partial update (JSON merge-patch) to the current settings.
-
- Validates the result via Pydantic. If validation fails,
- the settings are left unchanged and the error is raised.
- """
- current = self._settings.model_dump()
- merged = _deep_merge(base=current, patch=patch)
- # Pydantic validates on construction β€” if this raises, settings are unchanged
- new_settings = FreeMoCapSettings.model_validate(merged)
- self._settings = new_settings
- self.notify_changed()
- logger.info(f"Settings patched (v{self._version}): {list(patch.keys())}")
- return self._settings
-
- def update_from_app(self, app: "FreemocapApplication") -> None:
- """
- Rebuild settings from the current application state.
-
- All config values are read from the live application objects
- (pipeline, camera groups) so the settings blob is always
- the single source of truth. Runtime status fields (is_recording,
- recording_progress, etc.) are preserved from the internal state
- since they are only tracked here, not on the pipeline.
- """
- # Camera state β€” read from live camera groups
- cameras: dict[CameraIdString, CameraState] = {}
- for camera_group in app.camera_group_manager.camera_groups.values():
- for cam_id, cam_config in camera_group.configs.items():
- cameras[cam_id] = CameraState(
- config=cam_config,
- status=CameraStatus.CONNECTED,
- )
-
- # Pipeline state β€” read from live pipeline
- pipeline = PipelineSettings()
- realtime_pipelines = app.realtime_pipeline_manager.pipelines
- first_pipeline = None
- if realtime_pipelines:
- first_pipeline = next(iter(realtime_pipelines.values()))
- pipeline = PipelineSettings(
- config=first_pipeline.config,
- is_connected=first_pipeline.alive,
- pipeline_id=first_pipeline.id,
- camera_group_id=first_pipeline.camera_group.id,
- )
-
- # Calibration β€” read config from the live pipeline when available,
- # fall back to internal state when no pipeline exists.
- # Runtime status fields are always from internal state.
- calibration_config = (
- first_pipeline.config.calibration_config
- if first_pipeline is not None
- else self._settings.calibration.config
- )
- calibration = CalibrationSettings(
- config=calibration_config,
- is_recording=self._settings.calibration.is_recording,
- recording_progress=self._settings.calibration.recording_progress,
- last_recording_path=self._settings.calibration.last_recording_path,
- has_calibration_toml=self._settings.calibration.has_calibration_toml,
- )
-
- # Mocap β€” same pattern: read config from live pipeline when available.
- mocap_config = (
- first_pipeline.config.mocap_config
- if first_pipeline is not None
- else self._settings.mocap.config
- )
- mocap = MocapSettings(
- config=mocap_config,
- is_recording=self._settings.mocap.is_recording,
- recording_progress=self._settings.mocap.recording_progress,
- last_recording_path=self._settings.mocap.last_recording_path,
- )
-
- self._settings = FreeMoCapSettings(
- cameras=cameras,
- pipeline=pipeline,
- calibration=calibration,
- mocap=mocap,
- )
- self.notify_changed()
-
- def update_calibration_status(
- self,
- is_recording: bool | None = None,
- recording_progress: float | None = None,
- last_recording_path: str | None = None,
- has_calibration_toml: bool | None = None,
- ) -> None:
- """Update calibration runtime status fields and notify."""
- cal = self._settings.calibration
- if is_recording is not None:
- cal.is_recording = is_recording
- if recording_progress is not None:
- cal.recording_progress = recording_progress
- if last_recording_path is not None:
- cal.last_recording_path = last_recording_path
- if has_calibration_toml is not None:
- cal.has_calibration_toml = has_calibration_toml
- self.notify_changed()
-
- def update_mocap_status(
- self,
- is_recording: bool | None = None,
- recording_progress: float | None = None,
- last_recording_path: str | None = None,
- ) -> None:
- """Update mocap runtime status fields and notify."""
- moc = self._settings.mocap
- if is_recording is not None:
- moc.is_recording = is_recording
- if recording_progress is not None:
- moc.recording_progress = recording_progress
- if last_recording_path is not None:
- moc.last_recording_path = last_recording_path
- self.notify_changed()
diff --git a/freemocap/api/http/app/state.py b/freemocap/api/http/app/state.py
deleted file mode 100644
index 4a582a60..00000000
--- a/freemocap/api/http/app/state.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-HTTP endpoint serving the current FreeMoCapSettings from SettingsManager.
-
-Useful for initial hydration before the WebSocket connects, and
-as a polling fallback for clients that don't use WebSocket.
-"""
-import logging
-
-from fastapi import APIRouter
-
-from freemocap.app.freemocap_application import get_freemocap_app
-
-logger = logging.getLogger(__name__)
-state_router = APIRouter()
-
-
-@state_router.get("/settings", summary="Current Settings State", tags=["App"])
-def settings_state_endpoint() -> dict:
- """
- Serve the current settings blob (same payload shape as
- the `settings/state` WebSocket message).
- """
- logger.api("Serving settings state from `/settings` endpoint...")
- app = get_freemocap_app()
- app.settings_manager.update_from_app(app)
- return app.settings_manager.get_state_message()
diff --git a/freemocap/api/http/calibration/calibration_router.py b/freemocap/api/http/calibration/calibration_router.py
index 756b4cac..e0b53e08 100644
--- a/freemocap/api/http/calibration/calibration_router.py
+++ b/freemocap/api/http/calibration/calibration_router.py
@@ -12,7 +12,7 @@ from freemocap.system.default_paths import FREEMOCAP_TEST_DATA_PATH
logger = logging.getLogger(__name__)
-calibration_router = APIRouter(prefix="/calibration", tags=["Calibration"])
+calibration_router = APIRouter(prefix="/calibration", tags=["Capture Volume Calibration"])
# ==================== Request/Response Models ====================
@@ -26,6 +26,7 @@ class CalibrationConfigResponse(BaseModel):
success: bool
message: str | None = None
+
def _calibrate_request_schema_extra(schema: dict) -> None:
schema["examples"] = [CalibrateRecordingRequest.create_test_data_request().model_dump(by_alias=True)]
@@ -41,7 +42,7 @@ class CalibrateRecordingRequest(BaseModel):
)
calibration_recording_directory: str | None = Field(
alias="calibrationRecordingDirectory",
- description="Optional directory for calibration recording.")
+ description="Optional directory for calibration recording, if None/null use most recent successful recording", )
def to_recording_info(self) -> RecordingInfo:
if self.calibration_recording_directory is None:
@@ -57,22 +58,17 @@ class CalibrateRecordingRequest(BaseModel):
def create_test_data_request(cls) -> "CalibrateRecordingRequest":
config = PosthocCalibrationPipelineConfig()
- config.charuco_board_x_squares = 7
- config.charuco_board_y_squares = 5
- config.charuco_square_length = 54
+ config.charuco_board.squares_x = 7
+ config.charuco_board.squares_y = 5
+ config.charuco_board.square_length_mm = 54
return cls(calibration_config=config,
- calibration_recording_directory = FREEMOCAP_TEST_DATA_PATH)
-
-
+ calibration_recording_directory=FREEMOCAP_TEST_DATA_PATH)
class StopCalibrationRecordingRequest(BaseModel):
calibration_config: PosthocCalibrationPipelineConfig = Field(alias="calibrationTaskConfig")
-
-
-
class StartCalibrationRecordingResponse(BaseModel):
success: bool
message: str | None = None
@@ -113,7 +109,7 @@ def update_all_calibration_config(request: CalibrationConfigRequest) -> Calibrat
@calibration_router.post("/recording/start")
async def start_calibration_recording(
- request: CalibrateRecordingRequest,
+ request: CalibrateRecordingRequest,
) -> StartCalibrationRecordingResponse:
"""Start calibration recording with given config."""
try:
@@ -128,7 +124,7 @@ async def start_calibration_recording(
@calibration_router.post("/recording/stop")
async def stop_calibration_recording(
- request: StopCalibrationRecordingRequest,
+ request: StopCalibrationRecordingRequest,
) -> dict[str, bool]:
"""Stop current calibration recording and launch posthoc calibration pipeline."""
app = get_freemocap_app()
@@ -184,7 +180,6 @@ class ApplyFeetGroundplaneResponse(BaseModel):
message: str | None = None
method: str | None = None
-
# @calibration_router.post("/apply-feet-groundplane")
# def apply_feet_groundplane(
# request: ApplyFeetGroundplaneRequest,
diff --git a/freemocap/api/http/pipelines/pipeline_router.py b/freemocap/api/http/pipelines/pipeline_router.py
deleted file mode 100644
index 42859671..00000000
--- a/freemocap/api/http/pipelines/pipeline_router.py
+++ /dev/null
@@ -1,165 +0,0 @@
-import logging
-from pathlib import Path
-
-from fastapi import APIRouter, Body, HTTPException, Request
-from pydantic import BaseModel, Field
-from skellycam.core.camera.config.camera_config import CameraConfig
-from skellycam.core.camera_group.camera_group import CameraConfigs
-from skellycam.core.recorders.videos.recording_info import RecordingInfo
-from skellycam.core.types.type_overloads import CameraGroupIdString, CameraIdString
-
-from freemocap.app.freemocap_application import get_freemocap_app
-from freemocap.core.pipeline.realtime.realtime_aggregator_node import RealtimePipelineConfig
-from freemocap.system.default_paths import default_recording_name, get_default_recording_folder_path
-
-logger = logging.getLogger(__name__)
-
-pipeline_router = APIRouter(prefix="/pipeline", tags=["Processing Pipelines"])
-
-
-class PipelineConnectRequest(BaseModel):
- camera_configs: CameraConfigs = Field(
- ...,
- description="Camera configurations for the CameraGroup we're attaching a pipeline to",
- )
- pipeline_config: RealtimePipelineConfig | None = None
-
- @property
- def camera_ids(self) -> list[CameraIdString] | None:
- if self.camera_configs:
- return list(self.camera_configs.keys())
- return None
-
-
-class PipelineCreateResponse(BaseModel):
- camera_group_id: CameraGroupIdString = Field(
- ...,
- description="ID of the camera group attached to the pipeline",
- )
- pipeline_id: str = Field(
- ...,
- description="ID of the processing pipeline",
- )
- camera_configs: CameraConfigs = Field(
- ...,
- description="Camera configurations for the cameras in the camera group",
- )
-
- @classmethod
- def from_pipeline(cls, pipeline: "RealtimePipeline") -> "PipelineCreateResponse":
- return cls(
- camera_group_id=pipeline.camera_group.id,
- pipeline_id=pipeline.id,
- camera_configs=pipeline.camera_configs,
- )
-
-
-class StartRecordingRequest(BaseModel):
- recording_name: str = Field(
- default_factory=default_recording_name,
- description="Name of the recording",
- )
- recording_directory: str = Field(
- default_factory=get_default_recording_folder_path,
- description="Path to save the recording",
- )
- mic_device_index: int = Field(
- default=-1,
- description="Index of the microphone device",
- )
-
- def recording_full_path(self) -> str:
- return str(Path(self.recording_directory) / self.recording_name)
-
-
-@pipeline_router.post(
- "/connect",
- summary="Create a processing pipeline and attach it to a camera group",
-)
-async def pipeline_connect_endpoint(
- request: PipelineConnectRequest = Body(
- ...,
- description="Request body containing desired camera configuration",
- examples=[
- PipelineConnectRequest(
- camera_configs={"0": CameraConfig(camera_id="0")},
- ),
- ],
- ),
-) -> PipelineCreateResponse:
- logger.api(f"Received `pipeline/connect` POST request - \n {request.model_dump_json(indent=2)}")
- try:
- pipeline_config = request.pipeline_config or RealtimePipelineConfig.from_camera_configs(
- camera_configs=request.camera_configs,
- )
- pipeline = await get_freemocap_app().create_or_update_realtime_pipeline(
- pipeline_config=pipeline_config,
- )
- response = PipelineCreateResponse.from_pipeline(pipeline=pipeline)
- logger.api(f"`pipeline/connect` POST request handled successfully - \n {response.model_dump_json(indent=2)}")
- return response
- except Exception as e:
- logger.error(f"Error when processing `pipeline/connect` request: {type(e).__name__} - {e}")
- logger.exception(e)
- raise HTTPException(
- status_code=500,
- detail=f"Error when processing `pipeline/connect` request: {type(e).__name__} - {e}",
- )
-
-
-@pipeline_router.delete(
- "/all/close",
- summary="Disconnect/shutdown all processing pipelines",
-)
-async def pipeline_close_endpoint() -> None:
- logger.api("Received `pipeline/close` DELETE request")
- try:
- get_freemocap_app().close_pipelines()
- logger.api("`pipeline/close` DELETE request handled successfully")
- except Exception as e:
- logger.error(f"Error when processing `pipeline/close` request: {type(e).__name__} - {e}")
- logger.exception(e)
- raise HTTPException(
- status_code=500,
- detail=f"Error when processing `pipeline/close` request: {type(e).__name__} - {e}",
- )
-
-
-@pipeline_router.get("/all/pause_unpause", summary="Pause/unpause cameras")
-def pause_camera_groups(request: Request) -> bool:
- try:
- get_freemocap_app().pause_unpause_pipelines()
- return True
- except Exception as e:
- logger.error(f"Error in {request.url}: {type(e).__name__} - {e}", exc_info=True)
- raise HTTPException(status_code=500, detail=str(e))
-
-
-@pipeline_router.post("/all/record/start", summary="Start recording")
-async def start_recording(
- request: Request,
- request_body: StartRecordingRequest = Body(..., examples=[StartRecordingRequest()]),
-) -> bool:
- try:
- if request_body.recording_directory.startswith("~"):
- request_body.recording_directory = str(
- Path(request_body.recording_directory.replace("~", str(Path.home()), 1))
- )
- Path(request_body.recording_directory).mkdir(parents=True, exist_ok=True)
- await get_freemocap_app().start_recording_all(
- recording_info=RecordingInfo(**request_body.model_dump()),
- )
- return True
- except Exception as e:
- logger.error(f"Error in {request.url}: {type(e).__name__} - {e}", exc_info=True)
- raise HTTPException(status_code=500, detail=str(e))
-
-
-@pipeline_router.get("/all/record/stop", summary="Stop recording")
-async def stop_recording(request: Request) -> bool:
- try:
- await get_freemocap_app().stop_recording_all()
- return True
- except Exception as e:
- logger.error(f"Error in {request.url}: {type(e).__name__} - {e}", exc_info=True)
- raise HTTPException(status_code=500, detail=str(e))
diff --git a/freemocap/api/http/pipelines/__init__.py b/freemocap/api/http/realtime/__init__.py
similarity index 100%
rename from freemocap/api/http/pipelines/__init__.py
rename to freemocap/api/http/realtime/__init__.py
diff --git a/freemocap/api/http/realtime/realtime_router.py b/freemocap/api/http/realtime/realtime_router.py
new file mode 100644
index 00000000..fc6dcd4a
--- /dev/null
+++ b/freemocap/api/http/realtime/realtime_router.py
@@ -0,0 +1,111 @@
+import logging
+from pathlib import Path
+
+from fastapi import APIRouter, Body, HTTPException, Request
+from pydantic import BaseModel, Field
+from skellycam.core.camera.config import camera_config
+from skellycam.core.camera.config.camera_config import CameraConfig
+from skellycam.core.camera_group.camera_group import CameraConfigs
+from skellycam.core.recorders.videos.recording_info import RecordingInfo
+from skellycam.core.types.type_overloads import CameraGroupIdString, CameraIdString
+
+from freemocap.app.freemocap_application import get_freemocap_app
+from freemocap.core.pipeline.realtime.realtime_aggregator_node import RealtimePipelineConfig
+from freemocap.system.default_paths import default_recording_name, get_default_recording_folder_path
+
+logger = logging.getLogger(__name__)
+
+realtime_router = APIRouter(prefix="/realtime", tags=["Realtime Processing Pipeline"])
+
+
+class RealtimePipelineConnectRequest(BaseModel):
+ camera_configs: CameraConfigs|None = Field(default=None,
+ alias="cameraConfigs",
+ description="Camera configurations for the CameraGroup we're attaching a pipeline to. If None, use existing camera group (or throw if no camera group connected)")
+ realtime_config: RealtimePipelineConfig = Field(
+ default_factory=RealtimePipelineConfig,
+ description="Configuration for the realtime processing pipeline",
+ alias="realtimeConfig",
+ examples=[RealtimePipelineConfig()],
+ )
+
+class RealtimePipelineCreateResponse(BaseModel):
+ camera_group_id: CameraGroupIdString = Field(
+ description="ID of the camera group attached to the pipeline",
+ )
+ pipeline_id: str = Field(
+ description="ID of the processing pipeline",
+ )
+ @classmethod
+ def from_pipeline(cls, pipeline: "RealtimePipeline") -> "RealtimePipelineCreateResponse":
+ return cls(
+ camera_group_id=pipeline.camera_group.id,
+ pipeline_id=pipeline.id,
+ )
+
+class RealtimePipelineCloseResponse(BaseModel):
+ success: bool
+ message: str | None = None
+
+class RealtimePipelineUpdateRequest(BaseModel):
+ config: RealtimePipelineConfig = Field(default_factory=RealtimePipelineConfig, examples=[RealtimePipelineConfig()])
+
+
+@realtime_router.post(
+ "/apply",
+ summary="Create/update a processing pipeline and attach it to a camera group",
+)
+async def pipeline_apply_endpoint(
+ request: RealtimePipelineConnectRequest = Body(
+ description="Configuration for the realtime processing pipeline",
+ examples=[
+ RealtimePipelineConnectRequest(),
+ ],
+ ),
+) -> RealtimePipelineCreateResponse:
+ logger.api(f"Received `realtime/apply` POST request - \n {request.model_dump_json(indent=2)}")
+ try:
+ app = get_freemocap_app()
+ if request.camera_configs is None:
+ camera_groups = app.camera_group_manager.camera_groups
+ if len(camera_groups) == 0:
+ raise RuntimeError("No camera groups currently connected - must provide camera configs to create a new camera group and attach a pipeline")
+ elif len(camera_groups) > 1:
+ raise NotImplementedError("Multiple camera groups not yet supported")
+ camera_configs = next(iter(camera_groups.values())).configs
+ else:
+ camera_configs = request.camera_configs
+
+ if camera_configs is None or len(camera_configs) == 0:
+ raise RuntimeError("No valid camera configs found in request or current server state")
+
+ pipeline = await app.create_or_update_realtime_pipeline(pipeline_config=request.realtime_config,
+ camera_configs=camera_configs,)
+ response = RealtimePipelineCreateResponse.from_pipeline(pipeline=pipeline)
+ logger.api(f"`pipeline/connect` POST request handled successfully - \n {response.model_dump_json(indent=2)}")
+ return response
+ except Exception as e:
+ logger.error(f"Error when processing `pipeline/connect` request: {type(e).__name__} - {e}")
+ logger.exception(e)
+ raise HTTPException(
+ status_code=500,
+ detail=f"Error when processing `pipeline/connect` request: {type(e).__name__} - {e}",
+ )
+
+
+@realtime_router.delete(
+ "/all/close",
+ summary="Disconnect/shutdown all processing pipelines",
+)
+async def pipeline_close_endpoint() -> None:
+ logger.api("Received `pipeline/close` DELETE request")
+ try:
+ get_freemocap_app().close_pipelines()
+ logger.api("`pipeline/close` DELETE request handled successfully")
+ except Exception as e:
+ logger.error(f"Error when processing `pipeline/close` request: {type(e).__name__} - {e}")
+ logger.exception(e)
+ raise HTTPException(
+ status_code=500,
+ detail=f"Error when processing `pipeline/close` request: {type(e).__name__} - {e}",
+ )
diff --git a/freemocap/api/routers.py b/freemocap/api/routers.py
index 96720e6a..7c841835 100644
--- a/freemocap/api/routers.py
+++ b/freemocap/api/routers.py
@@ -1,24 +1,20 @@
from skellycam.api.http.cameras.camera_router import camera_router
-from freemocap.api.http.app.debug import debug_router
from freemocap.api.http.app.health import health_router
from freemocap.api.http.app.shutdown import shutdown_router
-from freemocap.api.http.app.state import state_router
from freemocap.api.http.blender.blender_router import blender_router
from freemocap.api.http.calibration.calibration_router import calibration_router
from freemocap.api.http.mocap.mocap_router import mocap_router
-from freemocap.api.http.pipelines.pipeline_router import pipeline_router
+from freemocap.api.http.realtime.realtime_router import realtime_router
APP_ROUTERS = [health_router,
- shutdown_router,
- state_router,
- debug_router]
+ shutdown_router]
SKELLYCAM_ROUTERS = [
camera_router,
]
-FREEMOCAP_ROUTERS = [pipeline_router,
+FREEMOCAP_ROUTERS = [realtime_router,
calibration_router,
mocap_router,
blender_router,
diff --git a/freemocap/api/websocket/websocket_server.py b/freemocap/api/websocket/websocket_server.py
index 6e924560..a456bd7e 100644
--- a/freemocap/api/websocket/websocket_server.py
+++ b/freemocap/api/websocket/websocket_server.py
@@ -15,12 +15,6 @@ from fastapi import FastAPI
from starlette.websockets import WebSocket, WebSocketState, WebSocketDisconnect
from freemocap.app.freemocap_application import FreemocapApplication, get_freemocap_app
-from freemocap.app.settings_protocol import (
- handle_settings_message,
- settings_state_relay,
-)
-from freemocap.core.viz import image_overlay
-from freemocap.core.viz.frontend_payload import FrontendPayload
from freemocap.system.logging_configuration.handlers.websocket_log_queue_handler import (
get_websocket_log_queue,
MIN_LOG_LEVEL_FOR_WEBSOCKET,
@@ -28,7 +22,6 @@ from freemocap.system.logging_configuration.handlers.websocket_log_queue_handler
from freemocap.utilities.wait_functions import await_10ms
if TYPE_CHECKING:
- from freemocap.app.settings import SettingsManager
from skellycam.core.types.type_overloads import CameraGroupIdString
from skellycam.core.recorders.framerate_tracker import FramerateTracker
@@ -46,7 +39,6 @@ class WebsocketServer:
)
self._global_kill_flag = fastapi_app.state.global_kill_flag
self._app: FreemocapApplication = get_freemocap_app()
- self._settings_manager: SettingsManager = self._app.settings_manager
self._websocket_should_continue = True
self.ws_tasks: list[asyncio.Task] = []
@@ -61,8 +53,6 @@ class WebsocketServer:
async def __aenter__(self):
logger.debug("Entering WebsocketRunner context manager...")
self._websocket_should_continue = True
- # Sync settings from app state on connection
- self._settings_manager.update_from_app(self._app)
return self
async def __aexit__(self, exc_type, exc_val, exc_tb):
@@ -102,15 +92,6 @@ class WebsocketServer:
self._client_message_handler(),
name="WebsocketClientMessageHandler",
),
- asyncio.create_task(
- settings_state_relay(
- websocket=self.websocket,
- settings_manager=self._settings_manager,
- should_continue=lambda: self.should_continue,
- send_lock=self._send_lock,
- ),
- name="WebsocketSettingsStateRelay",
- ),
]
try:
@@ -228,14 +209,8 @@ class WebsocketServer:
# Route settings messages to the settings protocol
data_message_type = data.get("message_type", "")
- if data_message_type.startswith("settings/"):
- logger.trace(f"Received settings message: {json.dumps(data, indent=2)}")
- handle_settings_message(
- data=data,
- settings_manager=self._settings_manager,
- app=self._app,
- )
- elif "frameNumber" in data:
+
+ if "frameNumber" in data:
# Existing frame acknowledgment handling
self.last_received_frontend_confirmation = data["frameNumber"]
self._display_image_sizes = data.get("displayImageSizes", None)
diff --git a/freemocap/app/app.py b/freemocap/app/app.py
index 13deeefa..7bd13b03 100644
--- a/freemocap/app/app.py
+++ b/freemocap/app/app.py
@@ -116,7 +116,7 @@ def _register_routes(app: FastAPI) -> None:
logger.api(
f"\tRegistering route: `/{freemocap.__package_name__}{route.path}` with methods: [{', '.join(route.methods)}]")
- logger.api("\nRegistering FreeMoCap endpoints:")
+ logger.api("\nRegistering SkellyCam endpoints:")
for router in SKELLYCAM_ROUTERS:
for route in router.routes:
logger.api(
diff --git a/freemocap/app/freemocap_application.py b/freemocap/app/freemocap_application.py
index 10da7cae..e4693e59 100644
--- a/freemocap/app/freemocap_application.py
+++ b/freemocap/app/freemocap_application.py
@@ -7,12 +7,11 @@ import multiprocessing
from dataclasses import dataclass, field
from fastapi import FastAPI
+from skellycam.core.camera.config.camera_config import CameraConfigs
from skellycam.core.camera_group.camera_group_manager import CameraGroupManager, get_or_create_camera_group_manager
from skellycam.core.ipc.process_management.worker_registry import WorkerRegistry
from skellycam.core.recorders.videos.recording_info import RecordingInfo
-from skellycam.core.types.type_overloads import CameraGroupIdString
-from freemocap.app.settings import SettingsManager
from freemocap.core.pipeline.posthoc.posthoc_pipeline import PosthocPipeline
from freemocap.core.pipeline.posthoc.posthoc_pipeline_manager import PosthocPipelineManager
from freemocap.core.pipeline.realtime.realtime_aggregator_node import RealtimePipelineConfig
@@ -20,8 +19,8 @@ from freemocap.core.pipeline.realtime.realtime_pipeline import RealtimePipeline
from freemocap.core.pipeline.realtime.realtime_pipeline_manager import RealtimePipelineManager
from freemocap.core.tasks.calibration.calibration_task_config import PosthocCalibrationPipelineConfig
from freemocap.core.tasks.mocap.mocap_task_config import PosthocMocapPipelineConfig
-from freemocap.core.types.type_overloads import PipelineIdString, FrameNumberInt
-from freemocap.core.viz.frontend_payload import FrontendPayload, FrontendImagePacket
+from freemocap.core.types.type_overloads import FrameNumberInt
+from freemocap.core.viz.frontend_payload import FrontendImagePacket
logger = logging.getLogger(__name__)
@@ -33,7 +32,6 @@ class FreemocapApplication:
realtime_pipeline_manager: RealtimePipelineManager
posthoc_pipeline_manager: PosthocPipelineManager
camera_group_manager: CameraGroupManager
- settings_manager: SettingsManager = field(default_factory=SettingsManager)
@classmethod
def create(cls, fastapi_app: FastAPI) -> "FreemocapApplication":
@@ -51,7 +49,6 @@ class FreemocapApplication:
worker_registry=worker_registry,
),
camera_group_manager=get_or_create_camera_group_manager(app=fastapi_app),
- settings_manager=SettingsManager(),
)
@property
@@ -64,24 +61,21 @@ class FreemocapApplication:
async def create_or_update_realtime_pipeline(
self,
+ camera_configs:CameraConfigs,
pipeline_config: RealtimePipelineConfig,
) -> RealtimePipeline:
- existing = self.realtime_pipeline_manager.get_pipeline_by_camera_ids(
- camera_ids=pipeline_config.camera_ids,
- )
- if existing is not None:
- existing.update_config(new_config=pipeline_config)
- self.settings_manager.update_from_app(self)
- return existing
+
+ for pipeline in self.realtime_pipeline_manager.pipelines.values():
+ pipeline.update_config(new_config=pipeline_config)
+ return pipeline
camera_group = await self.camera_group_manager.create_or_update_camera_group(
- camera_configs=pipeline_config.camera_configs,
+ camera_configs=camera_configs,
)
pipeline = self.realtime_pipeline_manager.create_pipeline(
camera_group=camera_group,
pipeline_config=pipeline_config,
)
- self.settings_manager.update_from_app(self)
return pipeline
# ------------------------------------------------------------------
@@ -97,7 +91,6 @@ class FreemocapApplication:
recording_info=recording_info,
calibration_config=calibration_config,
)
- self.settings_manager.update_from_app(self)
return pipeline
async def create_posthoc_mocap_pipeline(
@@ -109,7 +102,6 @@ class FreemocapApplication:
recording_info=recording_info,
mocap_config=mocap_config,
)
- self.settings_manager.update_from_app(self)
return pipeline
# ------------------------------------------------------------------
@@ -120,11 +112,9 @@ class FreemocapApplication:
await self.camera_group_manager.start_recording_all_groups(
recording_info=recording_info,
)
- self.settings_manager.update_from_app(self)
async def stop_recording_all(self) -> RecordingInfo | None:
recording_infos = await self.camera_group_manager.stop_recording_all_groups()
- self.settings_manager.update_from_app(self)
if len(recording_infos) == 0:
logger.warning("No recordings were stopped.")
return None
@@ -173,11 +163,9 @@ class FreemocapApplication:
def close_pipelines(self) -> None:
self.realtime_pipeline_manager.shutdown()
self.posthoc_pipeline_manager.shutdown()
- self.settings_manager.update_from_app(self)
def pause_unpause_pipelines(self) -> None:
self.realtime_pipeline_manager.pause_unpause_all()
- self.settings_manager.update_from_app(self)
def close(self) -> None:
self.global_kill_flag.value = True
diff --git a/freemocap/app/settings.py b/freemocap/app/settings.py
deleted file mode 100644
index 6313c5f0..00000000
--- a/freemocap/app/settings.py
+++ /dev/null
@@ -1,249 +0,0 @@
-"""
-Unified application settings: the single serializable state blob
-shared between frontend and backend over WebSocket.
-
-Frontend can patch `config` sub-objects via `settings/patch` messages.
-Runtime status fields are read-only from the frontend's perspective β€”
-they are set by commands and hardware state changes on the backend.
-"""
-import asyncio
-import logging
-from enum import Enum
-
-from pydantic import BaseModel, Field
-from skellycam.core.camera.config.camera_config import CameraConfig
-from skellycam.core.types.type_overloads import CameraIdString
-
-from freemocap.core.pipeline.realtime.realtime_aggregator_node import RealtimePipelineConfig
-from freemocap.core.tasks.calibration.calibration_task_config import PosthocCalibrationPipelineConfig
-from freemocap.core.tasks.mocap.mocap_task_config import PosthocMocapPipelineConfig
-
-logger = logging.getLogger(__name__)
-
-
-# ---------------------------------------------------------------------------
-# Sub-models: compose existing configs with runtime status
-# ---------------------------------------------------------------------------
-
-
-class CameraStatus(str, Enum):
- DISCONNECTED = "disconnected"
- CONNECTED = "connected"
- ERROR = "error"
-
-
-class CameraState(BaseModel):
- """Per-camera config + runtime status."""
- config: CameraConfig
- status: CameraStatus = CameraStatus.DISCONNECTED
-
-
-class PipelineSettings(BaseModel):
- """Realtime pipeline config + runtime status."""
- config: RealtimePipelineConfig | None = None
- is_connected: bool = False
- pipeline_id: str | None = None
- camera_group_id: str | None = None
- is_paused: bool = False
-
-
-class CalibrationSettings(BaseModel):
- """Calibration config + runtime status."""
- config: PosthocCalibrationPipelineConfig = Field(default_factory=PosthocCalibrationPipelineConfig)
- is_recording: bool = False
- recording_progress: float = 0.0
- last_recording_path: str | None = None
- has_calibration_toml: bool = False
-
-
-class MocapSettings(BaseModel):
- """Motion capture config + runtime status."""
- config: PosthocMocapPipelineConfig = Field(default_factory=PosthocMocapPipelineConfig.default_realtime)
- is_recording: bool = False
- recording_progress: float = 0.0
- last_recording_path: str | None = None
-
-
-
-# ---------------------------------------------------------------------------
-# Top-level settings blob
-# ---------------------------------------------------------------------------
-
-
-class FreeMoCapSettings(BaseModel):
- """
- The authoritative, serializable application state.
-
- Sent in full over WebSocket as a `settings/state` message
- whenever any setting or runtime status changes.
- """
- cameras: dict[CameraIdString, CameraState] = Field(default_factory=dict)
- pipeline: PipelineSettings = Field(default_factory=PipelineSettings)
- calibration: CalibrationSettings = Field(default_factory=CalibrationSettings)
- mocap: MocapSettings = Field(default_factory=MocapSettings)
-
-
-# ---------------------------------------------------------------------------
-# Settings Manager: owns the state, handles patches, notifies on change
-# ---------------------------------------------------------------------------
-
-
-def _deep_merge(base: dict, patch: dict) -> dict:
- """
- RFC 7396 JSON Merge Patch: recursively merge patch into base.
- Keys in patch overwrite base. Nested dicts merge recursively.
- """
- result = base.copy()
- for key, value in patch.items():
- if isinstance(value, dict) and isinstance(result.get(key), dict):
- result[key] = _deep_merge(result[key], value)
- else:
- result[key] = value
- return result
-
-
-class SettingsManager:
- """
- Owns the authoritative FreeMoCapSettings instance.
-
- - Assembles current state from FreemocapApplication on demand.
- - Accepts patches from the frontend, validates, and applies them.
- - Provides an asyncio.Event for WebSocket tasks to await state changes.
- - Maintains a monotonic version counter for ordering.
- """
-
- def __init__(self) -> None:
- self._settings = FreeMoCapSettings()
- self._version: int = 0
- self._changed = asyncio.Event()
-
- @property
- def version(self) -> int:
- return self._version
-
- @property
- def settings(self) -> FreeMoCapSettings:
- return self._settings
-
- def get_state_message(self) -> dict:
- """Build a `settings/state` WebSocket message."""
- return {
- "message_type": "settings/state",
- "settings": self._settings.model_dump(),
- "version": self._version,
- }
-
- def notify_changed(self) -> None:
- """Bump version and wake any waiters."""
- self._version += 1
- self._changed.set()
-
- async def wait_for_change(self) -> None:
- """Block until notify_changed() is called. Clears the event after waking."""
- await self._changed.wait()
- self._changed.clear()
-
- def apply_patch(self, patch: dict) -> FreeMoCapSettings:
- """
- Apply a partial update (JSON merge-patch) to the current settings.
-
- Validates the result via Pydantic. If validation fails,
- the settings are left unchanged and the error is raised.
- """
- #TODO - Replace this raw dict intput with a Pydantic model
- current = self._settings.model_dump()
- merged = _deep_merge(base=current, patch=patch)
- # Pydantic validates on construction β€” if this raises, settings are unchanged
- new_settings = FreeMoCapSettings.model_validate(merged)
- self._settings = new_settings
- self.notify_changed()
- logger.info(f"Settings patched (v{self._version}): {list(patch.keys())}")
- return self._settings
-
- def update_from_app(self, app: "FreemocapApplication") -> None:
- """
- Rebuild settings from the current application state.
-
- Call this after any command that changes runtime state
- (start recording, connect pipeline, etc.).
- """
- # Camera state
- cameras: dict[CameraIdString, CameraState] = {}
- for camera_group in app.camera_group_manager.camera_groups.values():
- for cam_id, cam_config in camera_group.configs.items():
- cameras[cam_id] = CameraState(
- config=cam_config,
- status=CameraStatus.CONNECTED,
- )
-
- # Pipeline state
- pipeline = PipelineSettings()
- realtime_pipelines = app.realtime_pipeline_manager.pipelines
- if realtime_pipelines:
- # Take the first active pipeline (single-pipeline assumption for now)
- first_pipeline = next(iter(realtime_pipelines.values()))
- pipeline = PipelineSettings(
- config=first_pipeline.config,
- is_connected=first_pipeline.alive,
- pipeline_id=first_pipeline.id,
- camera_group_id=first_pipeline.camera_group.id,
- )
-
- # Preserve user-set config values that aren't derived from runtime
- calibration = CalibrationSettings(
- config=self._settings.calibration.config,
- is_recording=self._settings.calibration.is_recording,
- recording_progress=self._settings.calibration.recording_progress,
- last_recording_path=self._settings.calibration.last_recording_path,
- has_calibration_toml=self._settings.calibration.has_calibration_toml,
- )
-
- mocap = MocapSettings(
- config=self._settings.mocap.config,
- is_recording=self._settings.mocap.is_recording,
- recording_progress=self._settings.mocap.recording_progress,
- last_recording_path=self._settings.mocap.last_recording_path,
- )
-
- self._settings = FreeMoCapSettings(
- cameras=cameras,
- pipeline=pipeline,
- calibration=calibration,
- mocap=mocap,
- )
- self.notify_changed()
-
- def update_calibration_status(
- self,
- is_recording: bool | None = None,
- recording_progress: float | None = None,
- last_recording_path: str | None = None,
- has_calibration_toml: bool | None = None,
- ) -> None:
- """Update calibration runtime status fields and notify."""
- cal = self._settings.calibration
- if is_recording is not None:
- cal.is_recording = is_recording
- if recording_progress is not None:
- cal.recording_progress = recording_progress
- if last_recording_path is not None:
- cal.last_recording_path = last_recording_path
- if has_calibration_toml is not None:
- cal.has_calibration_toml = has_calibration_toml
- self.notify_changed()
-
- def update_mocap_status(
- self,
- is_recording: bool | None = None,
- recording_progress: float | None = None,
- last_recording_path: str | None = None,
- ) -> None:
- """Update mocap runtime status fields and notify."""
- moc = self._settings.mocap
- if is_recording is not None:
- moc.is_recording = is_recording
- if recording_progress is not None:
- moc.recording_progress = recording_progress
- if last_recording_path is not None:
- moc.last_recording_path = last_recording_path
- self.notify_changed()
diff --git a/freemocap/app/settings_protocol.py b/freemocap/app/settings_protocol.py
deleted file mode 100644
index 26040629..00000000
--- a/freemocap/app/settings_protocol.py
+++ /dev/null
@@ -1,129 +0,0 @@
-"""
-WebSocket settings protocol: handles settings/patch, settings/request,
-and pushes settings/state on changes.
-
-Runs as a task in WebsocketServer.run() alongside the existing
-_frontend_image_relay, _logs_relay, and _client_message_handler tasks.
-"""
-import asyncio
-import logging
-from collections.abc import Callable
-from copy import deepcopy
-
-from starlette.websockets import WebSocket, WebSocketState
-
-from freemocap.app.freemocap_application import FreemocapApplication
-from freemocap.app.settings import SettingsManager
-
-logger = logging.getLogger(__name__)
-
-
-async def settings_state_relay(
- websocket: WebSocket,
- settings_manager: SettingsManager,
- should_continue: Callable[[], bool],
- send_lock: asyncio.Lock | None = None,
-) -> None:
- """
- Push `settings/state` to the frontend whenever settings change.
-
- Sends the full blob on startup (so the frontend gets initial state),
- then awaits the SettingsManager's change event and pushes again.
- """
- try:
- # Push initial state on connection
- async def _send_json(msg: dict) -> None:
- if send_lock is not None:
- async with send_lock:
- await websocket.send_json(msg)
- else:
- await websocket.send_json(msg)
-
- if websocket.client_state == WebSocketState.CONNECTED:
- state_msg = settings_manager.get_state_message()
- await _send_json(state_msg)
- logger.info("Sent initial settings/state")
-
- # Push on every subsequent change
- while should_continue():
- await settings_manager.wait_for_change()
- if websocket.client_state != WebSocketState.CONNECTED:
- break
- state_msg = settings_manager.get_state_message()
- await _send_json(state_msg)
- logger.debug("Pushed settings/state")
-
- except asyncio.CancelledError:
- logger.debug("Settings state relay task cancelled")
- except Exception as e:
- logger.exception(f"Error in settings state relay: {e.__class__.__name__}: {e}")
- raise
-
-
-def handle_settings_message(
- data: dict,
- settings_manager: SettingsManager,
- app: FreemocapApplication,
-) -> None:
- """
- Handle an incoming settings-related WebSocket message.
-
- Called from _client_message_handler when message_type starts with 'settings/'.
-
- Supported message_types:
- - settings/patch: apply a partial update to settings
- - settings/request: trigger a full state push (handled by notify)
- """
- message_type = data.get("message_type", "")
-
- if message_type == "settings/patch":
- patch = data.get("patch")
- if patch is None:
- raise ValueError("Received settings/patch with no 'patch' field")
- settings_manager.apply_patch(patch)
- # After applying config changes, sync relevant configs back
- # to the running pipelines/managers
- _sync_patch_to_app(patch=patch, settings_manager=settings_manager, app=app)
-
- elif message_type == "settings/request":
- # Frontend wants the full state β€” just notify so the relay task pushes it
- settings_manager.notify_changed()
-
- else:
- raise ValueError(f"Unknown settings message_type: {message_type}")
-
-
-def _sync_patch_to_app(
- patch: dict,
- settings_manager: SettingsManager,
- app: FreemocapApplication,
-) -> None:
- """
- After a settings patch is applied, push relevant config changes
- into the running application components.
-
- This bridges the gap between "settings blob updated" and
- "actual pipeline/camera behavior changed."
- """
- # If calibration config was patched, update active pipelines
- if "calibration" in patch and "config" in patch.get("calibration", {}):
- cal_config = settings_manager.settings.calibration.config
- with app.realtime_pipeline_manager.lock:
- for pipeline in app.realtime_pipeline_manager.pipelines.values():
- new_config = deepcopy(pipeline.config)
- new_config.calibration_config = cal_config
- pipeline.update_config(new_config=new_config)
- logger.info("Synced calibration config to active pipelines")
-
- # If mocap config was patched, update active pipelines
- if "mocap" in patch and "config" in patch.get("mocap", {}):
- mocap_config = settings_manager.settings.mocap.config
- with app.realtime_pipeline_manager.lock:
- for pipeline in app.realtime_pipeline_manager.pipelines.values():
- new_config = deepcopy(pipeline.config)
- new_config.mocap_config = mocap_config
- pipeline.update_config(new_config=new_config)
- logger.info("Synced mocap config to active pipelines")
-
- # Camera config changes still go through the REST
- # /camera/group/apply endpoint for now.
diff --git a/freemocap/core/pipeline/realtime/camera_node.py b/freemocap/core/pipeline/realtime/camera_node.py
index 8966ac5b..470a9efc 100644
--- a/freemocap/core/pipeline/realtime/camera_node.py
+++ b/freemocap/core/pipeline/realtime/camera_node.py
@@ -136,7 +136,7 @@ class CameraNode(SourceNode):
mediapipe_detector = LegacyMediapipeDetector.create(
config=new_config.skeleton_detector_config,
)
- elif not new_config.mocap_detection_enabled:
+ elif not new_config.skeleton_tracking_enabled:
mediapipe_detector = None
config = new_config
@@ -187,8 +187,7 @@ class CameraNode(SourceNode):
frame_number=actual_frame_number,
image=image,
)
- if mediapipe_detector is None and charuco_detector is None:
- continue
+
camera_output_pub.put(
CameraNodeOutputMessage(
camera_id=actual_camera_id,
diff --git a/freemocap/core/pipeline/realtime/realtime_aggregator_node.py b/freemocap/core/pipeline/realtime/realtime_aggregator_node.py
index f53f94bc..abf179ab 100644
--- a/freemocap/core/pipeline/realtime/realtime_aggregator_node.py
+++ b/freemocap/core/pipeline/realtime/realtime_aggregator_node.py
@@ -157,6 +157,7 @@ class RealtimeAggregatorNode(AggregatorNode):
*,
config: RealtimePipelineConfig,
camera_group_id: CameraGroupIdString,
+ camera_ids: list[CameraGroupIdString],
worker_registry: WorkerRegistry,
camera_group_shm_dto: CameraGroupSharedMemoryDTO,
ipc: PipelineIPC,
@@ -170,6 +171,7 @@ class RealtimeAggregatorNode(AggregatorNode):
kwargs=dict(
pipeline_config=config,
camera_group_id=camera_group_id,
+ camera_ids=camera_ids,
ipc=ipc,
camera_group_shm_dto=camera_group_shm_dto,
camera_node_sub=pubsub.get_subscription(
@@ -196,6 +198,7 @@ class RealtimeAggregatorNode(AggregatorNode):
*,
pipeline_config: RealtimePipelineConfig,
camera_group_id: CameraGroupIdString,
+ camera_ids: list[CameraGroupIdString],
ipc: PipelineIPC,
shutdown_self_flag: multiprocessing.Value,
camera_group_shm_dto: CameraGroupSharedMemoryDTO,
@@ -205,7 +208,6 @@ class RealtimeAggregatorNode(AggregatorNode):
aggregation_output_pub: TopicPublicationQueue,
) -> None:
logger.debug(f"RealtimeAggregationNode [{camera_group_id}] initializing")
- camera_ids = pipeline_config.camera_ids
aggregator_config = pipeline_config.aggregator_config
camera_group_shm = CameraGroupSharedMemory.recreate(
shm_dto=camera_group_shm_dto,
@@ -410,7 +412,7 @@ class RealtimeAggregatorNode(AggregatorNode):
),
)
- camera_node_outputs = {cam_id: None for cam_id in pipeline_config.camera_configs.keys()}
+ camera_node_outputs = {cam_id: None for cam_id in camera_ids}
except Exception as e:
logger.error(
diff --git a/freemocap/core/pipeline/realtime/realtime_pipeline.py b/freemocap/core/pipeline/realtime/realtime_pipeline.py
index 3afb353f..f50c046e 100644
--- a/freemocap/core/pipeline/realtime/realtime_pipeline.py
+++ b/freemocap/core/pipeline/realtime/realtime_pipeline.py
@@ -110,6 +110,7 @@ class RealtimePipeline:
aggregation_node = RealtimeAggregatorNode.create(
camera_group_id=camera_group.id,
+ camera_ids=camera_group.camera_ids,
worker_registry=worker_registry,
camera_group_shm_dto=camera_group.shm.to_dto(),
config=pipeline_config,
@@ -213,18 +214,3 @@ class RealtimePipeline:
frame_number=aggregation_output.frame_number,
frontend_payload=FrontendPayload.from_aggregation_output(aggregation_output),
)
- aggregation_output: AggregationNodeOutputMessage | None = None
- while not self.aggregation_output_subscription.empty():
- aggregation_output = self.aggregation_output_subscription.get()
-
- if aggregation_output is None:
- return None, None
-
- frames_bytes = self.camera_group.get_frontend_payload_by_frame_number(
- frame_number=aggregation_output.frame_number,
- )
-
- return (
- frames_bytes,
- FrontendPayload.from_aggregation_output(aggregation_output=aggregation_output),
- )
diff --git a/freemocap/core/pipeline/realtime/realtime_pipeline_config.py b/freemocap/core/pipeline/realtime/realtime_pipeline_config.py
index 75543791..a3d4b86b 100644
--- a/freemocap/core/pipeline/realtime/realtime_pipeline_config.py
+++ b/freemocap/core/pipeline/realtime/realtime_pipeline_config.py
@@ -7,19 +7,9 @@ from freemocap.core.pipeline.realtime.realtime_aggregator_node_config import Rea
class RealtimePipelineConfig(BaseModel):
- camera_configs: CameraConfigs
-
camera_node_config: CameraNodeConfig = Field(
default_factory=CameraNodeConfig,
)
aggregator_config: RealtimeAggregatorNodeConfig = Field(
default_factory=RealtimeAggregatorNodeConfig,
)
-
- @property
- def camera_ids(self) -> list[CameraIdString]:
- return list(self.camera_configs.keys())
-
- @classmethod
- def from_camera_configs(cls, *, camera_configs: CameraConfigs) -> "RealtimePipelineConfig":
- return cls(camera_configs=camera_configs)
diff --git a/freemocap/core/tasks/calibration/shared/calibration_models.py b/freemocap/core/tasks/calibration/shared/calibration_models.py
index 4736722d..80848511 100644
--- a/freemocap/core/tasks/calibration/shared/calibration_models.py
+++ b/freemocap/core/tasks/calibration/shared/calibration_models.py
@@ -29,7 +29,7 @@ class CharucoBoardDefinition(BaseModel, TomlMixin):
construct their solver-specific board representations from this.
"""
- model_config = ConfigDict(extra="forbid", frozen=True)
+ model_config = ConfigDict(extra="forbid")
squares_x: int
squares_y: int
diff --git a/freemocap/pubsub/pubsub_topics.py b/freemocap/pubsub/pubsub_topics.py
index 15cc3a29..e710f7e3 100644
--- a/freemocap/pubsub/pubsub_topics.py
+++ b/freemocap/pubsub/pubsub_topics.py
@@ -84,13 +84,6 @@ class AggregationNodeOutputMessage(TopicMessageABC):
@model_validator(mode='after')
def validate(self) -> 'AggregationNodeOutputMessage':
- expected_camera_ids = set(self.pipeline_config.camera_configs.keys())
- actual_camera_ids = set(self.camera_node_outputs.keys())
- if sorted(expected_camera_ids) != sorted(actual_camera_ids):
- raise ValueError(
- f"Camera IDs in camera_node_outputs {actual_camera_ids} "
- f"do not match expected camera IDs from pipeline_config {expected_camera_ids}"
- )
for cam_output in self.camera_node_outputs.values():
if cam_output.frame_number != self.frame_number:
raise ValueError(