Fix clippy lint and add back ALSA padding.

This commit is contained in:
JasonLG1979 2023-09-04 10:40:22 -05:00
parent b867ab2eab
commit 96f5a4d54d
2 changed files with 12 additions and 3 deletions

View file

@ -41,7 +41,7 @@ async fn main() {
exit(1);
}
let mut player = Player::new(player_config, session, Box::new(NoOpVolume), move || {
let player = Player::new(player_config, session, Box::new(NoOpVolume), move || {
backend(None, audio_format, sample_rate)
});

View file

@ -52,6 +52,9 @@ enum AlsaError {
#[error("<AlsaSink> Device {device} May be Invalid, Busy, or Already in Use, {e}")]
PcmSetUp { device: String, e: alsa::Error },
#[error("<AlsaSink> Failed to Drain PCM Buffer, {0}")]
DrainFailure(alsa::Error),
#[error("<AlsaSink> {0}")]
OnWrite(alsa::Error),
@ -236,8 +239,14 @@ impl Sink for AlsaSink {
}
fn stop(&mut self) -> SinkResult<()> {
self.period_buffer.clear();
self.pcm = None;
// Zero fill the remainder of the period buffer and
// write any leftover data before draining the actual PCM buffer.
self.period_buffer.resize(self.period_buffer.capacity(), 0);
self.write_buf()?;
if let Some(pcm) = self.pcm.take() {
pcm.drain().map_err(AlsaError::DrainFailure)?;
}
Ok(())
}