Run pwire loop on separate thread
This commit is contained in:
parent
6656727021
commit
60b5f2ed60
2 changed files with 33 additions and 11 deletions
|
@ -8,8 +8,6 @@ use std::{
|
|||
|
||||
use std::sync::mpsc::Receiver;
|
||||
|
||||
use pipewire::PipewireContext;
|
||||
|
||||
use crate::{config::Settings, player::PlayerEvent, utils::Error};
|
||||
|
||||
pub enum AudioEvent {
|
||||
|
@ -21,7 +19,6 @@ pub struct SoundManager {
|
|||
error_chan: Sender<Error>,
|
||||
audio_controls: Receiver<AudioEvent>,
|
||||
player_chan: Sender<PlayerEvent>,
|
||||
pwire: PipewireContext,
|
||||
}
|
||||
|
||||
pub fn init(
|
||||
|
@ -44,7 +41,14 @@ pub fn init(
|
|||
}
|
||||
Ok(x) => x,
|
||||
};
|
||||
sound_mgr.begin()
|
||||
match sound_mgr.begin() {
|
||||
Err(err) => {
|
||||
error_chan.send(err).unwrap();
|
||||
thread::park();
|
||||
return;
|
||||
}
|
||||
Ok(_) => (),
|
||||
};
|
||||
});
|
||||
Ok(audio_control_in)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use std::sync::{
|
||||
use std::{
|
||||
sync::{
|
||||
mpsc::{Receiver, Sender},
|
||||
Arc,
|
||||
},
|
||||
thread,
|
||||
};
|
||||
|
||||
use crate::{config::Settings, player::PlayerEvent, utils::Error};
|
||||
|
@ -14,16 +17,31 @@ impl SoundManager {
|
|||
audio_control_chan: Receiver<AudioEvent>,
|
||||
player_chan: Sender<PlayerEvent>,
|
||||
) -> Result<SoundManager, Error> {
|
||||
let pwire_context = pipewire::init()?;
|
||||
let error_chan_clone = error_chan.clone();
|
||||
thread::spawn(move || {
|
||||
let pwire_context = match pipewire::init() {
|
||||
Err(err) => {
|
||||
error_chan_clone.send(err).unwrap();
|
||||
thread::park();
|
||||
return;
|
||||
}
|
||||
Ok(x) => x,
|
||||
};
|
||||
pwire_context.mainloop.run();
|
||||
});
|
||||
Ok(SoundManager {
|
||||
settings,
|
||||
error_chan,
|
||||
audio_controls: audio_control_chan,
|
||||
player_chan,
|
||||
pwire: pwire_context,
|
||||
})
|
||||
}
|
||||
pub fn begin(&mut self) {
|
||||
self.pwire.mainloop.run();
|
||||
pub fn begin(&mut self) -> Result<(), Error> {
|
||||
loop {
|
||||
match self.audio_controls.recv()? {
|
||||
AudioEvent::DecodeChunk(chunk) => (),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue