Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/polymeilex/ripewire

PipeWire client liblary in idiomatic Rust
https://github.com/polymeilex/ripewire

Last synced: 1 day ago
JSON representation

PipeWire client liblary in idiomatic Rust

Awesome Lists containing this project

README

        



RipeWire


PipeWire client library in idiomatic Rust

## WIP...

Real proof of concept: [helvum ported to RipeWire](https://github.com/PolyMeilex/helvum-ripewire)

And simpler example (definitely not final API):
```rs
#[derive(Default)]
struct State {
globals: GlobalList,
}

impl State {
pub fn core_event(
&mut self,
context: &mut Context,
core: PwCore,
event: pw_core::Event,
) {
match event {
pw_core::Event::Done(done) => {
if done.id == 0 && done.seq == 0 {
// Let's print globals advertised by the registry
dbg!(&self.globals)
}
}
_ => {}
}
}

pub fn registry_event(
&mut self,
context: &mut Context,
registry: PwRegistry,
event: pw_registry::Event,
) {
self.globals.handle_event(&event);
}
}

let mut ctx = Context::connect("/run/user/1000/pipewire-0").unwrap();
let core = ctx.core();
let client = ctx.client();

core.hello(&mut ctx);

client.update_properties(
&mut ctx,
Dictionary::from([
("application.name", "RipeWire"),
("application.process.binary", "ripewire"),
]),
);

let registry = core.get_registry(&mut ctx);

core.sync(&mut ctx, 0, 0);

ctx.set_object_callback(&core, State::core_event);
ctx.set_object_callback(&registry, State::registry_event);

ctx.set_object_callback(&client, |state, client, event| {
println!("You can use closures as well: {:?}", event);
});

let mut state = State::default();

loop { // any event loop or async runtime of your choice
let (messages, fds) = ctx.rcv_msg();

for msg in messages {
ctx.dispatch_event(&mut state, msg, &fds);
}
}
```