@@ -4579,6 +4579,7 @@ struct AudioUnitStream<'ctx> {
4579
4579
stopped : AtomicBool ,
4580
4580
draining : AtomicBool ,
4581
4581
reinit_pending : AtomicBool ,
4582
+ delayed_reinit : AtomicBool ,
4582
4583
destroy_pending : AtomicBool ,
4583
4584
// Latency requested by the user.
4584
4585
latency_frames : u32 ,
@@ -4626,6 +4627,7 @@ impl<'ctx> AudioUnitStream<'ctx> {
4626
4627
stopped : AtomicBool :: new ( true ) ,
4627
4628
draining : AtomicBool :: new ( false ) ,
4628
4629
reinit_pending : AtomicBool :: new ( false ) ,
4630
+ delayed_reinit : AtomicBool :: new ( false ) ,
4629
4631
destroy_pending : AtomicBool :: new ( false ) ,
4630
4632
latency_frames,
4631
4633
output_device_latency_frames : AtomicU32 :: new ( 0 ) ,
@@ -4685,7 +4687,8 @@ impl<'ctx> AudioUnitStream<'ctx> {
4685
4687
}
4686
4688
4687
4689
if self . stopped . load ( Ordering :: SeqCst ) {
4688
- // Something stopped the stream, we must not reinit.
4690
+ // Something stopped the stream, reinit on next start
4691
+ self . delayed_reinit . store ( true , Ordering :: SeqCst ) ;
4689
4692
return Ok ( ( ) ) ;
4690
4693
}
4691
4694
@@ -4877,6 +4880,12 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> {
4877
4880
self . stopped . store ( false , Ordering :: SeqCst ) ;
4878
4881
self . draining . store ( false , Ordering :: SeqCst ) ;
4879
4882
4883
+ if self . delayed_reinit . load ( Ordering :: SeqCst ) {
4884
+ // Need reinitialization: device was changed when paused
4885
+ let result = self . queue . clone ( ) . run_sync ( || self . reinit ( ) ) . unwrap ( ) ;
4886
+ result?;
4887
+ }
4888
+
4880
4889
// Execute start in serial queue to avoid racing with destroy or reinit.
4881
4890
let result = self
4882
4891
. queue
0 commit comments