Skip to content

Commit 0434389

Browse files
committed
pipewire stream: pass callback directly
..instead of sending it through a command channel. I haven't found the reason to do this the more complicated way..?
1 parent 2df584b commit 0434389

1 file changed

Lines changed: 2 additions & 10 deletions

File tree

src/backends/pipewire/stream.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ use std::fmt::Formatter;
2424
use std::thread::JoinHandle;
2525

2626
enum StreamCommands<Callback> {
27-
ReceiveCallback(Callback),
2827
Eject(oneshot::Sender<Callback>),
2928
}
3029

3130
impl<Callback> fmt::Debug for StreamCommands<Callback> {
3231
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
3332
match self {
34-
Self::ReceiveCallback(_) => write!(f, "ReceiveCallback"),
3533
Self::Eject(_) => write!(f, "Eject"),
3634
}
3735
}
@@ -50,10 +48,6 @@ impl<Callback> StreamInner<Callback> {
5048
fn handle_command(&mut self, command: StreamCommands<Callback>) {
5149
log::debug!("Handling command: {command:?}");
5250
match command {
53-
StreamCommands::ReceiveCallback(callback) => {
54-
debug_assert!(self.callback.is_none());
55-
self.callback = Some(callback);
56-
}
5751
StreamCommands::Eject(reply) => {
5852
if let Some(callback) = self.callback.take() {
5953
reply.send(callback).unwrap();
@@ -158,7 +152,7 @@ impl<Callback: 'static + Send> StreamHandle<Callback> {
158152
+ Send
159153
+ 'static,
160154
) -> Result<Self, PipewireError> {
161-
let (mut tx, rx) = rtrb::RingBuffer::new(16);
155+
let (tx, rx) = rtrb::RingBuffer::new(16);
162156
let handle = std::thread::spawn(move || {
163157
let main_loop = MainLoop::new(None)?;
164158
let context = Context::new(&main_loop)?;
@@ -187,7 +181,7 @@ impl<Callback: 'static + Send> StreamHandle<Callback> {
187181
config.samplerate = config.samplerate.round();
188182
let _listener = stream
189183
.add_local_listener_with_user_data(StreamInner {
190-
callback: None,
184+
callback: Some(callback),
191185
commands: rx,
192186
scratch_buffer: vec![0.0; MAX_FRAMES * channels].into_boxed_slice(),
193187
loop_ref: main_loop.downgrade(),
@@ -242,8 +236,6 @@ impl<Callback: 'static + Send> StreamHandle<Callback> {
242236
main_loop.run();
243237
Ok::<_, PipewireError>(())
244238
});
245-
log::debug!("Sending callback to stream");
246-
tx.push(StreamCommands::ReceiveCallback(callback)).unwrap();
247239
Ok(Self {
248240
commands: tx,
249241
handle,

0 commit comments

Comments
 (0)