@@ -285,7 +285,26 @@ fn get_volume(unit: AudioUnit) -> Result<f32> {
285
285
286
286
fn set_input_mute ( unit : AudioUnit , mute : bool ) -> Result < ( ) > {
287
287
assert ! ( !unit. is_null( ) ) ;
288
- let mute: UInt32 = mute. into ( ) ;
288
+ let mute: u32 = mute. into ( ) ;
289
+ let mut old_mute: u32 = 0 ;
290
+ let r = audio_unit_get_property (
291
+ unit,
292
+ kAUVoiceIOProperty_MuteOutput,
293
+ kAudioUnitScope_Global,
294
+ AU_IN_BUS ,
295
+ & mut old_mute,
296
+ & mut mem:: size_of :: < u32 > ( ) ,
297
+ ) ;
298
+ if r != NO_ERR {
299
+ cubeb_log ! (
300
+ "AudioUnitGetProperty/kAUVoiceIOProperty_MuteOutput rv={}" ,
301
+ r
302
+ ) ;
303
+ return Err ( Error :: error ( ) ) ;
304
+ }
305
+ if old_mute == mute {
306
+ return Ok ( ( ) ) ;
307
+ }
289
308
let r = audio_unit_set_property (
290
309
unit,
291
310
kAUVoiceIOProperty_MuteOutput,
@@ -2536,6 +2555,7 @@ struct CoreStreamData<'ctx> {
2536
2555
input_device : device_info ,
2537
2556
output_device : device_info ,
2538
2557
input_processing_params : InputProcessingParams ,
2558
+ input_mute : bool ,
2539
2559
input_buffer_manager : Option < BufferManager > ,
2540
2560
// Listeners indicating what system events are monitored.
2541
2561
default_input_listener : Option < device_property_listener > ,
@@ -2575,6 +2595,7 @@ impl<'ctx> Default for CoreStreamData<'ctx> {
2575
2595
input_device : device_info:: default ( ) ,
2576
2596
output_device : device_info:: default ( ) ,
2577
2597
input_processing_params : InputProcessingParams :: NONE ,
2598
+ input_mute : false ,
2578
2599
input_buffer_manager : None ,
2579
2600
default_input_listener : None ,
2580
2601
default_output_listener : None ,
@@ -2620,6 +2641,7 @@ impl<'ctx> CoreStreamData<'ctx> {
2620
2641
input_device : in_dev,
2621
2642
output_device : out_dev,
2622
2643
input_processing_params : InputProcessingParams :: NONE ,
2644
+ input_mute : false ,
2623
2645
input_buffer_manager : None ,
2624
2646
default_input_listener : None ,
2625
2647
default_output_listener : None ,
@@ -3441,6 +3463,18 @@ impl<'ctx> CoreStreamData<'ctx> {
3441
3463
) ;
3442
3464
}
3443
3465
3466
+ // Always try to remember the applied input mute state. If it cannot be applied
3467
+ // to the new device pair, we notify the client of an error and it will have to
3468
+ // open a new stream.
3469
+ if let Err ( r) = set_input_mute ( self . input_unit , self . input_mute ) {
3470
+ cubeb_log ! (
3471
+ "({:p}) Failed to set mute state of voiceprocessing. Error: {}" ,
3472
+ self . stm_ptr,
3473
+ r
3474
+ ) ;
3475
+ return Err ( r) ;
3476
+ }
3477
+
3444
3478
// Always try to remember the applied input processing params. If they cannot
3445
3479
// be applied in the new device pair, we notify the client of an error and it
3446
3480
// will have to open a new stream.
@@ -4287,6 +4321,7 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> {
4287
4321
self as * const AudioUnitStream ,
4288
4322
mute
4289
4323
) ;
4324
+ self . core_stream_data . input_mute = mute;
4290
4325
Ok ( ( ) )
4291
4326
}
4292
4327
fn set_input_processing_params ( & mut self , params : InputProcessingParams ) -> Result < ( ) > {
0 commit comments