Only mute microphone while audio_unit is started.

Bug: webrtc:15233
Change-Id: Id21f1a5b5642be6b511811f9b2f474152a313cb2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/360081
Reviewed-by: Peter Hanspers <peterhanspers@webrtc.org>
Commit-Queue: Abby Yeh <abbyyeh@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42884}
This commit is contained in:
Abby Yeh 2024-08-29 10:51:07 +02:00 committed by WebRTC LUCI CQ
parent 61a52146f5
commit a9ececd103

View File

@ -1050,10 +1050,13 @@ int32_t AudioDeviceIOS::MicrophoneMuteIsAvailable(bool& available) {
}
int32_t AudioDeviceIOS::SetMicrophoneMute(bool enable) {
OSStatus result = audio_unit_->SetMicrophoneMute(enable);
if (result != noErr) {
RTCLogError(@"Set microphone %s failed, reason %d", enable ? "mute" : "unmute", result);
return -1;
// Set microphone mute only if the audio unit is started.
if (audio_unit_ && audio_unit_->GetState() == VoiceProcessingAudioUnit::kStarted) {
BOOL result = audio_unit_->SetMicrophoneMute(enable);
if (!result) {
RTCLogError(@"Set microphone %s failed.", enable ? "mute" : "unmute");
return -1;
}
}
return 0;
}