Merge pull request #860 from JasonLG1979/simplify-buffer-resizing

Simplify Alsa buffer resizing
This commit is contained in:
Roderick van Domburg 2021-10-08 15:49:05 +02:00 committed by GitHub
commit 2c9564570c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,7 +7,6 @@ use alsa::device_name::HintIter;
use alsa::pcm::{Access, Format, HwParams, PCM};
use alsa::{Direction, ValueOr};
use std::cmp::min;
use std::cmp::Ordering;
use std::process::exit;
use std::time::Duration;
use thiserror::Error;
@ -226,16 +225,8 @@ impl Sink for AlsaSink {
let (pcm, bytes_per_period) = open_device(&self.device, self.format)?;
self.pcm = Some(pcm);
match self.period_buffer.capacity().cmp(&bytes_per_period) {
Ordering::Greater => {
self.period_buffer.truncate(bytes_per_period);
self.period_buffer.shrink_to_fit();
}
Ordering::Less => {
let extra = bytes_per_period - self.period_buffer.len();
self.period_buffer.reserve_exact(extra);
}
Ordering::Equal => (),
if self.period_buffer.capacity() != bytes_per_period {
self.period_buffer = Vec::with_capacity(bytes_per_period);
}
// Should always match the "Period Buffer size in bytes: " trace! message.