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,9 +38,7 @@ 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()
.expect("Sample sender disconnected unexpectedly");
if next_samples.len() > sample_buf.len() { if next_samples.len() > sample_buf.len() {
panic!("Buffer too small for given sample chunks"); panic!("Buffer too small for given sample chunks");
} }
@ -49,6 +47,9 @@ pub fn init(
slice.len() slice.len()
} else { } else {
0 0
}
} else {
0
}; };
let chunk = data.chunk_mut(); let chunk = data.chunk_mut();
*chunk.offset_mut() = 0; *chunk.offset_mut() = 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,