cleaner handling, remove unneeded Box on audio info

This commit is contained in:
Muaz Ahmad 2024-12-03 14:52:20 +05:00
parent 2c66db4205
commit 7e56d50898
3 changed files with 12 additions and 11 deletions

View file

@ -22,7 +22,7 @@ pub struct SoundManager {
audio_controls: Receiver<AudioEvent>, audio_controls: Receiver<AudioEvent>,
player_chan: Sender<PlayerEvent>, player_chan: Sender<PlayerEvent>,
sample_in: Sender<Vec<u8>>, sample_in: Sender<Vec<u8>>,
pw_signal_in: pipewire::channel::Sender<Box<Vec<u8>>>, pw_signal_in: pipewire::channel::Sender<Vec<u8>>,
} }
pub fn init( pub fn init(

View file

@ -15,7 +15,7 @@ use crate::utils::Error;
pub fn init( pub fn init(
samples: std::sync::mpsc::Receiver<Vec<u8>>, samples: std::sync::mpsc::Receiver<Vec<u8>>,
pw_signal: Receiver<Box<Vec<u8>>>, pw_signal: Receiver<Vec<u8>>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let mainloop = MainLoop::new(None)?; let mainloop = MainLoop::new(None)?;
let context = Context::new(&mainloop)?; let context = Context::new(&mainloop)?;
@ -38,15 +38,16 @@ pub fn init(
Some(mut buf) => { Some(mut buf) => {
let data = &mut (buf.datas_mut()[0]); let data = &mut (buf.datas_mut()[0]);
let n_iter = if let Some(sample_buf) = data.data() { let n_iter = if let Some(sample_buf) = data.data() {
let next_samples = samples if let Ok(next_samples) = samples.try_recv() {
.recv() if next_samples.len() > sample_buf.len() {
.expect("Sample sender disconnected unexpectedly"); panic!("Buffer too small for given sample chunks");
if next_samples.len() > sample_buf.len() { }
panic!("Buffer too small for given sample chunks"); let slice = &mut sample_buf[0..next_samples.len()];
slice.copy_from_slice(&next_samples);
slice.len()
} else {
0
} }
let slice = &mut sample_buf[0..next_samples.len()];
slice.copy_from_slice(&next_samples);
slice.len()
} else { } else {
0 0
}; };

View file

@ -58,7 +58,7 @@ impl SoundManager {
.unwrap() .unwrap()
.0 .0
.into_inner(); .into_inner();
pw_signal_in.send(Box::new(test_pod)).unwrap(); pw_signal_in.send(test_pod).unwrap();
Ok(SoundManager { Ok(SoundManager {
settings, settings,
error_chan, error_chan,