diff --git a/controller/cuda_grid_controller/config.py b/controller/cuda_grid_controller/config.py index 219d81f..bffd9cc 100644 --- a/controller/cuda_grid_controller/config.py +++ b/controller/cuda_grid_controller/config.py @@ -92,6 +92,17 @@ class InstanceCfg(BaseModel): default="volume@music", description="Target filter для управления громкостью music chain (Phase 5c ducking)", ) + audio_output_volume_target: str = Field( + default="volume@output_audio", + description="ZMQ target volume filter в video pipeline (после astreamselect) для UI-mute audio. " + "0 = mute, 1 = unmute. Phase 7 filter pipeline.", + ) + audio_input_select_target: str = Field( + default="astreamselect@audio_input", + description="ZMQ target astreamselect filter — выбор audio source в video pipeline. " + "map=0 → live-audio (sidecar), map=1 → anullsrc (decouple от jittery RTSP). " + "UI mute → map=1 + volume=0; unmute → map=0 + volume=1.", + ) intercom_volume_target: str = Field( default="volume@intercom", description="Target filter для управления громкостью intercom (Phase 5c)", diff --git a/controller/cuda_grid_controller/dispatch.py b/controller/cuda_grid_controller/dispatch.py index 0b99e4f..edc6221 100644 --- a/controller/cuda_grid_controller/dispatch.py +++ b/controller/cuda_grid_controller/dispatch.py @@ -218,6 +218,39 @@ class CommandDispatcher: использует cell 0 как main slot. Семантика идентична: cell_map 0 = cam_index.""" await self.set_main_cam(instance, cam_index) + async def set_audio_output_enabled(self, instance: str, enabled: bool) -> bool: + """Phase 7 Вариант 2: mute = astreamselect map=1 (anullsrc) + volume=0. + unmute = astreamselect map=0 (live-audio) + volume=1. astreamselect + decouples downstream от jittery live-audio RTSP — при mute frames + идут только через anullsrc chain, video не зависит от audio sidecar.""" + inst = self._find_instance(instance) + if inst is None: + return False + client = self._client(inst) + input_map = "0" if enabled else "1" + volume = "1.0" if enabled else "0.0" + try: + reply1 = await client.send_command( + inst.audio_input_select_target, "map", input_map + ) + reply2 = await client.send_command( + inst.audio_output_volume_target, "volume", volume + ) + log.info("dispatch.audio_output_set", + instance=instance, enabled=enabled, + input_map=input_map, volume=volume, + select_reply=reply1, volume_reply=reply2) + except (TimeoutError, Exception) as e: + log.warning("dispatch.audio_output_fail", + instance=instance, error=str(e)) + return False + await self.state.set_audio_output_enabled(instance, enabled) + if self.on_state_change: + await self.on_state_change(instance, "audio_output", "on" if enabled else "off") + if self.on_event: + await self.on_event(instance, "audio_output_changed", {"enabled": enabled}) + return True + async def _reload_icon(self, instance: str, icon_name: str) -> None: """Invalidate cached icon atlas во всех cuda_grid instances — каждый имеет свой кеш.""" diff --git a/controller/cuda_grid_controller/http_api.py b/controller/cuda_grid_controller/http_api.py index 2576688..5b04c84 100644 --- a/controller/cuda_grid_controller/http_api.py +++ b/controller/cuda_grid_controller/http_api.py @@ -34,6 +34,10 @@ class AutoLayoutReq(BaseModel): enabled: bool +class AudioOutputReq(BaseModel): + enabled: bool + + def create_app( cfg: Config, state: ControllerState, dispatcher: CommandDispatcher, snapshot_history: SnapshotHistory | None = None, @@ -80,6 +84,22 @@ def create_app( } return {"instances": out} + @app.get("/audio-output/{instance}") + async def audio_output_get(instance: str) -> dict[str, Any]: + _check_instance(instance) + return { + "instance": instance, + "enabled": await state.get_audio_output_enabled(instance), + } + + @app.post("/audio-output/{instance}") + async def audio_output_set(instance: str, req: AudioOutputReq) -> dict[str, Any]: + _check_instance(instance) + ok = await dispatcher.set_audio_output_enabled(instance, req.enabled) + if not ok: + raise HTTPException(500, "audio output ZMQ command failed (см. logs)") + return {"ok": True, "instance": instance, "enabled": req.enabled} + @app.post("/layout/{instance}/set") async def set_layout(instance: str, req: LayoutSetReq) -> dict[str, Any]: _check_instance(instance) diff --git a/controller/cuda_grid_controller/state.py b/controller/cuda_grid_controller/state.py index 94243ee..8cdff5c 100644 --- a/controller/cuda_grid_controller/state.py +++ b/controller/cuda_grid_controller/state.py @@ -13,6 +13,7 @@ class InstanceState: name: str active_layout: str overlays: dict[str, Overlay] = field(default_factory=dict) + audio_output_enabled: bool = True # Future: fps_out, dropped_frames, motion_cameras, last_event_ts @@ -66,6 +67,19 @@ class ControllerState: st = self.instances.get(instance) return list(st.overlays.values()) if st else [] + # ─── Audio output mute ────────────────────────────────────────── + + async def set_audio_output_enabled(self, instance: str, enabled: bool) -> None: + async with self._lock: + st = self.instances.get(instance) + if st is not None: + st.audio_output_enabled = enabled + + async def get_audio_output_enabled(self, instance: str) -> bool: + async with self._lock: + st = self.instances.get(instance) + return st.audio_output_enabled if st else True + async def clear_overlays(self, instance: str) -> int: async with self._lock: st = self.instances.get(instance) diff --git a/controller/cuda_grid_controller/static/index.html b/controller/cuda_grid_controller/static/index.html index 6468b91..a719c4c 100644 --- a/controller/cuda_grid_controller/static/index.html +++ b/controller/cuda_grid_controller/static/index.html @@ -57,7 +57,7 @@ pre { background:#0f0f12; padding:8px; border-radius:4px; font-size:11px; overfl