@@ -7,6 +7,7 @@ use alsa::device_name::HintIter;
77use alsa:: pcm:: { Access , Format , HwParams , PCM } ;
88use alsa:: { Direction , ValueOr } ;
99use std:: cmp:: min;
10+ use std:: cmp:: Ordering ;
1011use std:: process:: exit;
1112use std:: time:: Duration ;
1213use thiserror:: Error ;
@@ -92,7 +93,7 @@ fn list_outputs() -> SinkResult<()> {
9293 for t in & [ "pcm" , "ctl" , "hwdep" ] {
9394 println ! ( "{} devices:" , t) ;
9495
95- let i = HintIter :: new_str ( None , & t) . map_err ( |_| AlsaError :: Parsing ) ?;
96+ let i = HintIter :: new_str ( None , t) . map_err ( |_| AlsaError :: Parsing ) ?;
9697
9798 for a in i {
9899 if let Some ( Direction :: Playback ) = a. direction {
@@ -225,14 +226,16 @@ impl Sink for AlsaSink {
225226 let ( pcm, bytes_per_period) = open_device ( & self . device , self . format ) ?;
226227 self . pcm = Some ( pcm) ;
227228
228- let current_capacity = self . period_buffer . capacity ( ) ;
229-
230- if current_capacity > bytes_per_period {
231- self . period_buffer . truncate ( bytes_per_period) ;
232- self . period_buffer . shrink_to_fit ( ) ;
233- } else if current_capacity < bytes_per_period {
234- let extra = bytes_per_period - self . period_buffer . len ( ) ;
235- self . period_buffer . reserve_exact ( extra) ;
229+ match self . period_buffer . capacity ( ) . cmp ( & bytes_per_period) {
230+ Ordering :: Greater => {
231+ self . period_buffer . truncate ( bytes_per_period) ;
232+ self . period_buffer . shrink_to_fit ( ) ;
233+ }
234+ Ordering :: Less => {
235+ let extra = bytes_per_period - self . period_buffer . len ( ) ;
236+ self . period_buffer . reserve_exact ( extra) ;
237+ }
238+ Ordering :: Equal => ( ) ,
236239 }
237240
238241 // Should always match the "Period Buffer size in bytes: " trace! message.
@@ -251,11 +254,10 @@ impl Sink for AlsaSink {
251254 self . period_buffer . resize ( self . period_buffer . capacity ( ) , 0 ) ;
252255 self . write_buf ( ) ?;
253256
254- let pcm = self . pcm . as_mut ( ) . ok_or ( AlsaError :: NotConnected ) ?;
257+ let pcm = self . pcm . take ( ) . ok_or ( AlsaError :: NotConnected ) ?;
255258
256259 pcm. drain ( ) . map_err ( AlsaError :: DrainFailure ) ?;
257260
258- self . pcm = None ;
259261 Ok ( ( ) )
260262 }
261263
0 commit comments