diff --git a/src/host/pipewire/conn.rs b/src/host/pipewire/conn.rs index 2586dec2a..f83db4f05 100644 --- a/src/host/pipewire/conn.rs +++ b/src/host/pipewire/conn.rs @@ -1,8 +1,10 @@ extern crate pipewire; use self::pipewire::{ + filter::{Filter, FilterFlags, FilterListener, FilterPortFlags, ListenerBuilderT, PortData}, metadata::{Metadata, MetadataListener}, node::{Node, NodeListener}, + port::{Port, PortListener}, prelude::*, proxy::Listener, registry::{GlobalObject, Registry}, @@ -107,6 +109,11 @@ pub struct Settings { pub default_buffer_size: u32, } +#[derive(Default)] +struct FilterData<'f> { + ports: Vec<PortData<'f, Rc<FilterData<'f>>, ()>> +} + enum ProxyItem { Metadata { _proxy: Metadata, @@ -116,6 +123,11 @@ enum ProxyItem { _proxy: Node, _listener: NodeListener, }, + Filter { + _proxy: Filter<()>, + _listener: FilterListener<()>, + // ports: Vec<PortData<(), ()>>, + }, } fn pw_thread( @@ -155,45 +167,110 @@ fn pw_thread( device_type, autoconnect, } => { - let node: Node = core - .create_object( - "adapter", //node_factory.get().expect("No node factory found"), - &pipewire::properties! { - *pipewire::keys::NODE_NAME => name.clone(), - *pipewire::keys::FACTORY_NAME => "support.null-audio-sink", - *pipewire::keys::MEDIA_TYPE => "Audio", - *pipewire::keys::MEDIA_CATEGORY => match device_type { - DeviceType::InputDevice => "Capture", - DeviceType::OutputDevice => "Playback" - }, - *pipewire::keys::NODE_AUTOCONNECT => match autoconnect { - false => "false", - true => "true", - }, - // Don't remove the object on the remote when we destroy our proxy. - // *pipewire::keys::OBJECT_LINGER => "1" + // let node: Node = core + // .create_object( + // "adapter", //node_factory.get().expect("No node factory found"), + // &pipewire::properties! { + // *pipewire::keys::NODE_NAME => name.clone(), + // *pipewire::keys::FACTORY_NAME => "support.null-audio-sink", + // *pipewire::keys::MEDIA_TYPE => "Audio", + // *pipewire::keys::MEDIA_CATEGORY => match device_type { + // DeviceType::InputDevice => "Capture", + // DeviceType::OutputDevice => "Playback" + // }, + // *pipewire::keys::NODE_AUTOCONNECT => match autoconnect { + // false => "false", + // true => "true", + // }, + // // Don't remove the object on the remote when we destroy our proxy. + // // *pipewire::keys::OBJECT_LINGER => "1" + // }, + // ) + // .expect("Failed to create object"); + let data = Rc::new(FilterData::default()); + let mut filter = Filter::new( + &core, + &name.clone(), + pipewire::properties! { + *pipewire::keys::MEDIA_TYPE => "Audio", + *pipewire::keys::MEDIA_CATEGORY => match device_type { + DeviceType::InputDevice => "Sink", + DeviceType::OutputDevice => "Source" }, - ) - .expect("Failed to create object"); - - let _listener = node - .add_listener_local() - .info(|info| { - // println!("{:?}", info); - }) - .param(|a, b, c, d| { - println!("{}, {}, {}, {}", a, b, c, d); + *pipewire::keys::NODE_AUTOCONNECT => match autoconnect { + false => "false", + true => "true", + }, + // Don't remove the object on the remote when we destroy our proxy. + // *pipewire::keys::OBJECT_LINGER => "1" + }, + ) + .expect("Failed to create object"); + + // let mut ports = Vec::new(); + + // let port = match device_type { + // DeviceType::InputDevice => filter.add_port( + // Direction::Input, + // FilterPortFlags::MAP_BUFFERS, + // (), + // pipewire::properties! { + // *pipewire::keys::PORT_NAME => "blep" + // }, + // &mut [], + // ), + // DeviceType::OutputDevice => filter.add_port( + // Direction::Output, + // FilterPortFlags::MAP_BUFFERS, + // (), + // pipewire::properties! { + // *pipewire::keys::PORT_NAME => "blep_out" + // }, + // &mut [], + // ), + // }; + + // ports.push(port); + + let _listener = filter + .add_local_listener() + .state_changed(|old_state, state| { + println!("{:?}, {:?}", old_state, state); }) - .register(); - - println!("{:?}", node); - - state.as_ref().borrow_mut().nodes.push(ProxyItem::Node { - _proxy: node, - _listener, - }); - - main_sender.send(MessageRepl::NodeInfo(NodeInfo { name })); + .process(|_, position, d| {}) + .register() + .expect(""); + // .add_listener_local() + // .info({ + // let main_sender = main_sender.clone(); + // move |info| { + // main_sender + // .send(MessageRepl::NodeInfo(NodeInfo { name: name.clone() })); + // } + // }) + // .param(|a, b, c, d| { + // println!("{}, {}, {}, {}", a, b, c, d); + // }) + // .register(); + // println!("{:?}", filter); + + filter.connect(FilterFlags::RT_PROCESS, &mut []); + + proxies.as_ref().borrow_mut().insert( + filter.node_id(), + ProxyItem::Filter { + _proxy: filter, + _listener, + }, + ); + + // state.as_ref().borrow_mut().nodes.push(ProxyItem::Filter { + // _proxy: filter, + // _listener, + // // ports, + // }); + + main_sender.send(MessageRepl::NodeInfo(NodeInfo { name: name.clone() })); } } });