Skip to content

Commit 68ef845

Browse files
committed
Don't mute when removing audio stream
1 parent 081cc0f commit 68ef845

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

media/engine/webrtc_voice_engine.cc

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ class WebRtcVoiceSendChannel::WebRtcAudioSendStream : public AudioSource::Sink {
921921
muted_ = muted;
922922
}
923923

924-
bool muted() const {
924+
bool IsMuted() const {
925925
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
926926
return muted_;
927927
}
@@ -948,6 +948,11 @@ class WebRtcVoiceSendChannel::WebRtcAudioSendStream : public AudioSource::Sink {
948948
UpdateSendState();
949949
}
950950

951+
bool HasSource() const {
952+
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
953+
return source_ != nullptr;
954+
}
955+
951956
// Stops sending by setting the sink of the AudioSource to nullptr. No data
952957
// callback will be received after this method.
953958
// This method is called on the libjingle worker thread.
@@ -1668,18 +1673,35 @@ bool WebRtcVoiceSendChannel::MuteStream(uint32_t ssrc, bool muted) {
16681673
// This implementation is not ideal, instead we should signal the AGC when
16691674
// the mic channel is muted/unmuted. We can't do it today because there
16701675
// is no good way to know which stream is mapping to the mic channel.
1671-
bool all_muted = muted;
1672-
for (const auto& kv : send_streams_) {
1673-
all_muted = all_muted && kv.second->muted();
1674-
}
1675-
webrtc::AudioProcessing* ap = engine()->apm();
1676-
if (ap) {
1677-
ap->set_output_will_be_muted(all_muted);
1678-
}
1676+
if (send_streams_.size() > 0) {
1677+
// This will be true if MuteStream is called from
1678+
// AudioRtpSender::ClearSend().
1679+
bool is_all_no_source =
1680+
std::none_of(send_streams_.begin(), send_streams_.end(),
1681+
[](const auto& kv) { return kv.second->HasSource(); });
1682+
1683+
bool is_all_muted =
1684+
std::all_of(send_streams_.begin(), send_streams_.end(),
1685+
[](const auto& kv) { return kv.second->IsMuted(); });
1686+
1687+
// Only mute the microphone if we're not in cleanup state
1688+
// (i.e. if we have active send streams)
1689+
webrtc::AudioProcessing* ap = engine()->apm();
1690+
if (ap) {
1691+
bool v = !is_all_no_source && is_all_muted;
1692+
RTC_LOG(LS_INFO) << "WebRtcVoiceSendChannel::MuteStream: APM:" << v;
1693+
ap->set_output_will_be_muted(v);
1694+
}
16791695

1680-
webrtc::AudioDeviceModule* adm = engine()->adm();
1681-
if (adm) {
1682-
adm->SetMicrophoneMute(all_muted);
1696+
if (!is_all_no_source) {
1697+
// We don't mute when ClearSend() is called.
1698+
webrtc::AudioDeviceModule* adm = engine()->adm();
1699+
if (adm) {
1700+
RTC_LOG(LS_INFO) << "WebRtcVoiceSendChannel::MuteStream: ADM:"
1701+
<< is_all_muted;
1702+
adm->SetMicrophoneMute(is_all_muted);
1703+
}
1704+
}
16831705
}
16841706

16851707
return true;

0 commit comments

Comments
 (0)