host/audio: per-stream routing via libpipewire (session 3 of 4)
When opts.app is set, a dedicated OS thread runs a libpipewire MainLoop, subscribes to the registry, and writes target.object to the "default" metadata so WirePlumber reroutes matching streams to our per-PID null-sink. Activation is now opts.app.is_some() OR the existing PIXELPASS_AUDIO_VIA_NULL_SINK env var (kept for no-filter dogfooding). Threading: tokio side spawns a std::thread; the two sides bridge via pipewire::channel for cmd→thread (Shutdown) and tokio::sync::mpsc for event→tokio (FirstRoutedStream). Cross-thread quit goes through the libpipewire channel so MainLoop is only mutated from its own thread. Shutdown clears target.object on every routed stream before quitting so WirePlumber doesn't log orphans. Routing decisions: - Filter is case-insensitive equality on application.name (predictable; no surprise matches from substring). - target.object is written as Spa:Id with the sink's object.serial. - Default-sink loopback stays loaded until the first stream is actually routed — avoids viewer silence if the user picks an app that isn't producing sound yet. On first route, the event task takes() the loopback module ID and unloads it. Session 2 picker explainer + (app pick saved: ...) banner softening both removed; banner is back to plain app-audio=NAME. Verified end-to-end cross-machine: desktop host with Strawberry selected, laptop viewer over mpv. Strawberry audible on the laptop; YouTube playback started on the desktop was NOT audible on the laptop. Routing isolates the filtered app. Session 4 still open: recreate loopback when the last filtered stream disappears (avoid silence), handle app-disappears-mid-session, multi-instance, --repair coupling for orphan sink cleanup. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+1
-4
@@ -317,11 +317,8 @@ fn copy_to_clipboard(text: &str) -> bool {
|
||||
|
||||
fn capture_summary(opts: &HostOpts) -> String {
|
||||
let mut bits = vec![if opts.window { "window" } else { "fullscreen" }.to_string()];
|
||||
// Per-stream routing isn't wired yet (session 3 owns activation), so
|
||||
// even when an app is selected the audio capture is system-wide. Keep
|
||||
// the choice visible in the banner but label it honestly.
|
||||
if let Some(app) = &opts.app {
|
||||
bits.push(format!("system-audio (app pick saved: {app})"));
|
||||
bits.push(format!("app-audio={app}"));
|
||||
} else {
|
||||
bits.push("system-audio".to_string());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user