2024-05-12 01:15:52 -04:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
|
|
|
use pipewire::keys;
|
|
|
|
use pipewire::properties::properties;
|
|
|
|
use pipewire::{context::Context, main_loop::MainLoop};
|
|
|
|
|
|
|
|
use self::client::State;
|
|
|
|
|
|
|
|
mod client;
|
|
|
|
|
2024-05-10 21:30:50 -04:00
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2024-05-12 01:15:52 -04:00
|
|
|
let proplist = properties! {*keys::APP_NAME => env!("CARGO_PKG_NAME")};
|
|
|
|
|
|
|
|
let mainloop = MainLoop::new(None)?;
|
|
|
|
let context = Context::with_properties(&mainloop, proplist)?;
|
|
|
|
let core = context.connect(None)?;
|
|
|
|
let registry = core.get_registry()?;
|
|
|
|
let state = Rc::new(RefCell::new(State::default()));
|
|
|
|
let state2 = state.clone();
|
|
|
|
|
|
|
|
let _listener = registry
|
|
|
|
.add_listener_local()
|
|
|
|
.global(move |global| {
|
|
|
|
let mut state = state.borrow_mut();
|
|
|
|
match &global.type_ {
|
|
|
|
pipewire::types::ObjectType::Node => {
|
|
|
|
if let Some(global_props) = global.props {
|
|
|
|
let node_id = global.id;
|
|
|
|
let name = global_props.get(&keys::NODE_NAME);
|
|
|
|
state.add_node(node_id, name);
|
|
|
|
} else {
|
|
|
|
eprintln!("Global Node Add without props {:?}", global);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pipewire::types::ObjectType::Link => {
|
|
|
|
if let Some(global_props) = global.props {
|
|
|
|
let link_id = global.id;
|
|
|
|
let input = global_props
|
|
|
|
.get(&keys::LINK_INPUT_NODE)
|
|
|
|
.map(|x| x.parse())
|
|
|
|
.map_or(Ok(None), |v| v.map(Some))
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
|
|
|
let output = global_props
|
|
|
|
.get(&keys::LINK_OUTPUT_NODE)
|
|
|
|
.map(|x| x.parse())
|
|
|
|
.map_or(Ok(None), |v| v.map(Some))
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
|
|
|
state.add_link(link_id, input, output);
|
|
|
|
} else {
|
|
|
|
eprintln!("Global Link Add without props {:?}", global);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.global_remove(move |id| {
|
|
|
|
let mut state = state2.borrow_mut();
|
|
|
|
state.remove_id(id);
|
|
|
|
})
|
|
|
|
.register();
|
|
|
|
|
|
|
|
mainloop.run();
|
|
|
|
|
2024-05-10 21:30:50 -04:00
|
|
|
Ok(())
|
|
|
|
}
|