diff --git a/api/audio/audio_device.h b/api/audio/audio_device.h index 07226fc096..5670c2bebf 100644 --- a/api/audio/audio_device.h +++ b/api/audio/audio_device.h @@ -181,6 +181,9 @@ class AudioDeviceModule : public webrtc::RefCountInterface { // not be present in the stats. virtual std::optional GetStats() const { return std::nullopt; } + // Whether to stop recording when all streams are muted. + virtual bool IsStopOnMuteModeEnabled() const { return true; } + // Only supported on iOS. #if defined(WEBRTC_IOS) virtual int GetPlayoutAudioParameters(AudioParameters* params) const = 0; diff --git a/media/engine/webrtc_voice_engine.cc b/media/engine/webrtc_voice_engine.cc index aa10e86414..2fce04e29a 100644 --- a/media/engine/webrtc_voice_engine.cc +++ b/media/engine/webrtc_voice_engine.cc @@ -1759,7 +1759,18 @@ bool WebRtcVoiceSendChannel::MuteStream(uint32_t ssrc, bool muted) { if (adm) { RTC_LOG(LS_INFO) << "WebRtcVoiceSendChannel::MuteStream: ADM:" << is_all_muted; - adm->SetMicrophoneMute(is_all_muted); + + if (adm->IsStopOnMuteModeEnabled()) { + if (!is_all_muted && !adm->Recording()) { + if (adm->InitRecording() == 0) { + adm->StartRecording(); + } + } else if (is_all_muted && adm->Recording()) { + adm->StopRecording(); + } + } else { + adm->SetMicrophoneMute(is_all_muted); + } } } } diff --git a/modules/audio_device/audio_engine_device.h b/modules/audio_device/audio_engine_device.h index 4193f846ed..173c0cce18 100644 --- a/modules/audio_device/audio_engine_device.h +++ b/modules/audio_device/audio_engine_device.h @@ -372,6 +372,8 @@ class AudioEngineDevice : public AudioDeviceModule, public AudioSessionObserver int32_t InitAndStartRecording(); + bool IsStopOnMuteModeEnabled() const override; + private: struct EngineStateUpdate { EngineState prev; diff --git a/modules/audio_device/audio_engine_device.mm b/modules/audio_device/audio_engine_device.mm index 85f726a91e..4bf2380028 100644 --- a/modules/audio_device/audio_engine_device.mm +++ b/modules/audio_device/audio_engine_device.mm @@ -88,6 +88,10 @@ engine_state_.voice_processing_bypassed = voice_processing_bypassed; } +bool AudioEngineDevice::IsStopOnMuteModeEnabled() const { + return false; +} + AudioEngineDevice::~AudioEngineDevice() { RTC_DCHECK_RUN_ON(thread_);