Implement MuteMicrophone to enable muted speech listener on iOS 15 and 16.
Bug: webrtc:15233 Change-Id: I73e553f0c0a2258941d75b35d2475168c99ceba2 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/358723 Reviewed-by: Peter Hanspers <peterhanspers@webrtc.org> Commit-Queue: Abby Yeh <abbyyeh@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42747}
This commit is contained in:
parent
723ea45075
commit
cae0aeb2b6
@ -1045,13 +1045,17 @@ bool AudioDeviceIOS::MicrophoneIsInitialized() const {
|
||||
}
|
||||
|
||||
int32_t AudioDeviceIOS::MicrophoneMuteIsAvailable(bool& available) {
|
||||
available = false;
|
||||
available = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AudioDeviceIOS::SetMicrophoneMute(bool enable) {
|
||||
RTC_DCHECK_NOTREACHED() << "Not implemented";
|
||||
return -1;
|
||||
OSStatus result = audio_unit_->SetMicrophoneMute(enable);
|
||||
if (result != noErr) {
|
||||
RTCLogError(@"Set microphone %s failed, reason %d", enable ? "mute" : "unmute", result);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AudioDeviceIOS::MicrophoneMute(bool& enabled) const {
|
||||
|
||||
@ -92,6 +92,9 @@ class VoiceProcessingAudioUnit {
|
||||
// Uninitializes the underlying audio unit.
|
||||
bool Uninitialize();
|
||||
|
||||
// Mutes the microphone.
|
||||
bool SetMicrophoneMute(bool enable);
|
||||
|
||||
// Calls render on the underlying audio unit.
|
||||
OSStatus Render(AudioUnitRenderActionFlags* flags,
|
||||
const AudioTimeStamp* time_stamp,
|
||||
|
||||
@ -398,6 +398,39 @@ bool VoiceProcessingAudioUnit::Uninitialize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VoiceProcessingAudioUnit::SetMicrophoneMute(bool enable) {
|
||||
RTC_DCHECK_GE(state_, kUninitialized);
|
||||
|
||||
RTCLog(@"Setting microphone %s.", enable ? "mute" : "unmute");
|
||||
|
||||
OSStatus result = noErr;
|
||||
if (detect_mute_speech_) {
|
||||
UInt32 muteUplinkOutput = enable ? 1 : 0;
|
||||
result = AudioUnitSetProperty(vpio_unit_,
|
||||
kAUVoiceIOProperty_MuteOutput,
|
||||
kAudioUnitScope_Global,
|
||||
kInputBus,
|
||||
&muteUplinkOutput,
|
||||
sizeof(muteUplinkOutput));
|
||||
} else {
|
||||
UInt32 enableInput = enable ? 0 : 1;
|
||||
result = AudioUnitSetProperty(vpio_unit_,
|
||||
kAudioOutputUnitProperty_EnableIO,
|
||||
kAudioUnitScope_Input,
|
||||
kInputBus,
|
||||
&enableInput,
|
||||
sizeof(enableInput));
|
||||
}
|
||||
|
||||
if (result != noErr) {
|
||||
RTCLogError(@"Failed to %s microphone. Error=%ld", (enable ? "mute" : "unmute"), (long)result);
|
||||
return false;
|
||||
}
|
||||
|
||||
RTCLog(@"Set microphone %s.", enable ? "mute" : "unmute");
|
||||
return true;
|
||||
}
|
||||
|
||||
OSStatus VoiceProcessingAudioUnit::Render(AudioUnitRenderActionFlags* flags,
|
||||
const AudioTimeStamp* time_stamp,
|
||||
UInt32 output_bus_number,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user