feat(audio): add --strict-audio + app_audio route-status events
With --app, pixelpass mirrors the default-sink monitor (whole desktop) until the
chosen app's streams route, and restores that loopback if the app's audio later
stops. That fallback captures everything playing — including a voice call the
sharer is in — so a caller watching the share can hear themselves echoed back
(peerspeak bug A23: the per-app pick alone is best-effort, not a guarantee).
- New --strict-audio flag (HostOpts.strict_audio): with --app, never load the
default-sink loopback (not at startup, not on LastRoutedStreamGone). The viewer
hears only the chosen app, and silence when it's quiet — never the rest of the
desktop. No effect without --app; standalone best-effort behavior is unchanged.
- New app_audio JSON event ({"event":"app_audio","state":"routed"|"lost"}),
emitted whenever --app is set, so a front-end (peerspeak) can tell when the
chosen app's audio is actually live vs. dropped and warn accordingly.
- Banner capture summary shows "(strict)" when active.
Unknown-event-tolerant: pixelpass's own --gui child parser skips lines it can't
deserialize, so app_audio doesn't disturb it. 10 tests (+2: wire-shape + banner),
clippy --all-targets clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,11 @@ pub enum Event<'a> {
|
||||
ViewerRefused { reason: &'a str },
|
||||
/// Viewer-side: the local player URL is ready to open.
|
||||
Connected { url: &'a str },
|
||||
/// Per-app audio routing state (only emitted when `--app` is set). `routed`
|
||||
/// = the chosen app's audio is now reaching viewers; `lost` = its last
|
||||
/// stream went away. Under `--strict-audio`, `lost` means viewers currently
|
||||
/// hear silence; without it, viewers fall back to whole-desktop audio.
|
||||
AppAudio { state: AppAudioState },
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -67,6 +72,13 @@ pub enum CaptureState {
|
||||
Stopped,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Copy)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum AppAudioState {
|
||||
Routed,
|
||||
Lost,
|
||||
}
|
||||
|
||||
/// Emit one event as a JSON line on stdout, flushed. No-op unless JSON
|
||||
/// output was enabled with [`set_json`], so call sites can sprinkle these
|
||||
/// unconditionally without branching.
|
||||
@@ -85,3 +97,25 @@ pub fn emit(event: Event) {
|
||||
Err(e) => tracing::warn!("failed to serialize event: {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// The app_audio event is the wire contract peerspeak parses to drive its
|
||||
// echo warning; pin the exact shape so a rename here is caught here.
|
||||
#[test]
|
||||
fn app_audio_event_wire_shape() {
|
||||
let routed = serde_json::to_string(&Event::AppAudio {
|
||||
state: AppAudioState::Routed,
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(routed, r#"{"event":"app_audio","state":"routed"}"#);
|
||||
|
||||
let lost = serde_json::to_string(&Event::AppAudio {
|
||||
state: AppAudioState::Lost,
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(lost, r#"{"event":"app_audio","state":"lost"}"#);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user