diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc index fc901ae1e6..99369a2547 100644 --- a/webrtc/media/engine/webrtcvoiceengine.cc +++ b/webrtc/media/engine/webrtcvoiceengine.cc @@ -1801,6 +1801,12 @@ bool WebRtcVoiceMediaChannel::SetRecvCodecs( return true; } + if (playout_) { + // Receive codecs can not be changed while playing. So we temporarily + // pause playout. + ChangePlayout(false); + } + bool result = true; for (const AudioCodec& codec : new_codecs) { webrtc::CodecInst voe_codec = {0}; @@ -1825,6 +1831,9 @@ bool WebRtcVoiceMediaChannel::SetRecvCodecs( recv_codecs_ = codecs; } + if (desired_playout_ && !playout_) { + ChangePlayout(desired_playout_); + } return result; } @@ -1953,7 +1962,12 @@ bool WebRtcVoiceMediaChannel::SetSendCodecs( } void WebRtcVoiceMediaChannel::SetPlayout(bool playout) { - TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::SetPlayout"); + desired_playout_ = playout; + return ChangePlayout(desired_playout_); +} + +void WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { + TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::ChangePlayout"); RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); if (playout_ == playout) { return; diff --git a/webrtc/media/engine/webrtcvoiceengine.h b/webrtc/media/engine/webrtcvoiceengine.h index cd832a1c08..df2f64d53e 100644 --- a/webrtc/media/engine/webrtcvoiceengine.h +++ b/webrtc/media/engine/webrtcvoiceengine.h @@ -226,6 +226,7 @@ class WebRtcVoiceMediaChannel final : public VoiceMediaChannel, WebRtcVoiceEngine* engine() { return engine_; } int GetLastEngineError() { return engine()->GetLastEngineError(); } int GetOutputLevel(int channel); + void ChangePlayout(bool playout); int CreateVoEChannel(); bool DeleteVoEChannel(int channel); bool IsDefaultRecvStream(uint32_t ssrc) { @@ -243,6 +244,7 @@ class WebRtcVoiceMediaChannel final : public VoiceMediaChannel, int max_send_bitrate_bps_ = 0; AudioOptions options_; rtc::Optional dtmf_payload_type_; + bool desired_playout_ = false; bool recv_transport_cc_enabled_ = false; bool recv_nack_enabled_ = false; bool playout_ = false;