@@ -287,7 +287,26 @@ fn get_volume(unit: AudioUnit) -> Result<f32> {
287
287
288
288
fn set_input_mute ( unit : AudioUnit , mute : bool ) -> Result < ( ) > {
289
289
assert ! ( !unit. is_null( ) ) ;
290
- let mute: UInt32 = mute. into ( ) ;
290
+ let mute: u32 = mute. into ( ) ;
291
+ let mut old_mute: u32 = 0 ;
292
+ let r = audio_unit_get_property (
293
+ unit,
294
+ kAUVoiceIOProperty_MuteOutput,
295
+ kAudioUnitScope_Global,
296
+ AU_IN_BUS ,
297
+ & mut old_mute,
298
+ & mut mem:: size_of :: < u32 > ( ) ,
299
+ ) ;
300
+ if r != NO_ERR {
301
+ cubeb_log ! (
302
+ "AudioUnitGetProperty/kAUVoiceIOProperty_MuteOutput rv={}" ,
303
+ r
304
+ ) ;
305
+ return Err ( Error :: error ( ) ) ;
306
+ }
307
+ if old_mute == mute {
308
+ return Ok ( ( ) ) ;
309
+ }
291
310
let r = audio_unit_set_property (
292
311
unit,
293
312
kAUVoiceIOProperty_MuteOutput,
@@ -2547,6 +2566,7 @@ struct CoreStreamData<'ctx> {
2547
2566
input_device : device_info ,
2548
2567
output_device : device_info ,
2549
2568
input_processing_params : InputProcessingParams ,
2569
+ input_mute : bool ,
2550
2570
input_buffer_manager : Option < BufferManager > ,
2551
2571
// Listeners indicating what system events are monitored.
2552
2572
default_input_listener : Option < device_property_listener > ,
@@ -2586,6 +2606,7 @@ impl<'ctx> Default for CoreStreamData<'ctx> {
2586
2606
input_device : device_info:: default ( ) ,
2587
2607
output_device : device_info:: default ( ) ,
2588
2608
input_processing_params : InputProcessingParams :: NONE ,
2609
+ input_mute : false ,
2589
2610
input_buffer_manager : None ,
2590
2611
default_input_listener : None ,
2591
2612
default_output_listener : None ,
@@ -2631,6 +2652,7 @@ impl<'ctx> CoreStreamData<'ctx> {
2631
2652
input_device : in_dev,
2632
2653
output_device : out_dev,
2633
2654
input_processing_params : InputProcessingParams :: NONE ,
2655
+ input_mute : false ,
2634
2656
input_buffer_manager : None ,
2635
2657
default_input_listener : None ,
2636
2658
default_output_listener : None ,
@@ -3451,6 +3473,18 @@ impl<'ctx> CoreStreamData<'ctx> {
3451
3473
) ;
3452
3474
}
3453
3475
3476
+ // Always try to remember the applied input mute state. If it cannot be applied
3477
+ // to the new device pair, we notify the client of an error and it will have to
3478
+ // open a new stream.
3479
+ if let Err ( r) = set_input_mute ( self . input_unit , self . input_mute ) {
3480
+ cubeb_log ! (
3481
+ "({:p}) Failed to set mute state of voiceprocessing. Error: {}" ,
3482
+ self . stm_ptr,
3483
+ r
3484
+ ) ;
3485
+ return Err ( r) ;
3486
+ }
3487
+
3454
3488
// Always try to remember the applied input processing params. If they cannot
3455
3489
// be applied in the new device pair, we notify the client of an error and it
3456
3490
// will have to open a new stream.
@@ -4297,6 +4331,7 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> {
4297
4331
self as * const AudioUnitStream ,
4298
4332
mute
4299
4333
) ;
4334
+ self . core_stream_data . input_mute = mute;
4300
4335
Ok ( ( ) )
4301
4336
}
4302
4337
fn set_input_processing_params ( & mut self , params : InputProcessingParams ) -> Result < ( ) > {
0 commit comments