mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
simplify buffer resizing
This way is less verbose, much more simple and less brittle.
This commit is contained in:
parent
095536f100
commit
9ef53f5ffb
1 changed files with 2 additions and 11 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue