controller: UI-toggle audio output + astreamselect decouple (Phase 7 Вариант 2)
Web UI checkbox в Audio source карточке: «вывод аудио в стрим». Off →
TV получает silence + downstream audio chain isolated от live-audio RTSP
(нестабильный sidecar поток больше не блокирует video pipeline).
Изменения:
state.InstanceState: + audio_output_enabled (default True)
config.InstanceCfg:
+ audio_output_volume_target (default volume@output_audio)
+ audio_input_select_target (default astreamselect@audio_input)
dispatch.set_audio_output_enabled(enabled):
enabled=False → astreamselect map=1 (anullsrc) + volume=0
enabled=True → astreamselect map=0 (live-audio) + volume=1
Двойная команда: select decouples upstream, volume гарантирует тишину
на случай если в anullsrc что-то не так.
http_api: + GET /audio-output/{instance}, POST /audio-output/{instance}
static/index.html: + checkbox в Audio source header + loadAudioOut/toggleAudioOut
ZMQ smoke test OK. HTTP roundtrip OK.
Сопутствующий pipeline change: docker-compose.phase7.yml — amix заменён
на astreamselect@audio_input (см. localhost-infra commit).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -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)",
|
||||
|
||||
@@ -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 — каждый
|
||||
имеет свой кеш."""
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -57,7 +57,7 @@ pre { background:#0f0f12; padding:8px; border-radius:4px; font-size:11px; overfl
|
||||
|
||||
<!-- Audio -->
|
||||
<div class="card">
|
||||
<h2>Audio source</h2>
|
||||
<h2>Audio source <span style="float:right; font-size:11px"><label><input id="audio-out-tog" type="checkbox" onchange="toggleAudioOut()"> вывод аудио в стрим</label></span></h2>
|
||||
<div class="row" id="audio-buttons"></div>
|
||||
</div>
|
||||
|
||||
@@ -181,6 +181,18 @@ async function toggleAuto() {
|
||||
await api('POST', `/auto-layout/${INSTANCE}`, {enabled}, 'auto ' + (enabled?'ON':'OFF'));
|
||||
}
|
||||
|
||||
// ── Audio output toggle (Phase 7 volume@output_audio) ─
|
||||
async function loadAudioOut() {
|
||||
const r = await fetch(`/audio-output/${INSTANCE}`);
|
||||
if (!r.ok) return;
|
||||
const d = await r.json();
|
||||
document.getElementById('audio-out-tog').checked = d.enabled;
|
||||
}
|
||||
async function toggleAudioOut() {
|
||||
const enabled = document.getElementById('audio-out-tog').checked;
|
||||
await api('POST', `/audio-output/${INSTANCE}`, {enabled}, 'audio out ' + (enabled?'ON':'OFF'));
|
||||
}
|
||||
|
||||
// ── Layout buttons ────────────────────────────────────
|
||||
async function loadLayouts() {
|
||||
const r = await fetch(`/layouts/${INSTANCE}`);
|
||||
|
||||
Reference in New Issue
Block a user