Chromium Code Reviews| Index: webrtc/media/engine/webrtcvoiceengine.cc | 
| diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc | 
| index 28c50793aa3518cefa4fe35ca073e4f474022642..e0f1011457965136dccb9c3d1337244889381b26 100644 | 
| --- a/webrtc/media/engine/webrtcvoiceengine.cc | 
| +++ b/webrtc/media/engine/webrtcvoiceengine.cc | 
| @@ -1158,7 +1158,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream | 
| ~WebRtcAudioSendStream() override { | 
| RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 
| - Stop(); | 
| + StopRendering(); | 
| call_->DestroyAudioSendStream(stream_); | 
| } | 
| @@ -1188,11 +1188,16 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream | 
| return stream_->GetStats(); | 
| } | 
| + bool IsRendering() const { | 
| + RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 
| + return renderer_ != nullptr; | 
| + } | 
| + | 
| // Starts the rendering by setting a sink to the renderer to get data | 
| // callback. | 
| // This method is called on the libjingle worker thread. | 
| // TODO(xians): Make sure Start() is called only once. | 
| - void Start(AudioRenderer* renderer) { | 
| + void StartRendering(AudioRenderer* renderer) { | 
| RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 
| RTC_DCHECK(renderer); | 
| if (renderer_) { | 
| @@ -1206,7 +1211,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream | 
| // Stops rendering by setting the sink of the renderer to nullptr. No data | 
| // callback will be received after this method. | 
| // This method is called on the libjingle worker thread. | 
| - void Stop() { | 
| + void StopRendering() { | 
| RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 
| if (renderer_) { | 
| renderer_->SetSink(nullptr); | 
| @@ -1830,8 +1835,8 @@ bool WebRtcVoiceMediaChannel::ChangeSend(SendFlags send) { | 
| } | 
| // Change the settings on each send channel. | 
| - for (const auto& ch : send_streams_) { | 
| - if (!ChangeSend(ch.second->channel(), send)) { | 
| + for (const auto& kv : send_streams_) { | 
| + if (!UpdateChannelSendState(kv.first, send)) { | 
| return false; | 
| } | 
| } | 
| @@ -1840,14 +1845,23 @@ bool WebRtcVoiceMediaChannel::ChangeSend(SendFlags send) { | 
| return true; | 
| } | 
| -bool WebRtcVoiceMediaChannel::ChangeSend(int channel, SendFlags send) { | 
| - if (send == SEND_MICROPHONE) { | 
| +bool WebRtcVoiceMediaChannel::UpdateChannelSendState(uint32_t ssrc, | 
| + SendFlags send) { | 
| + RTC_DCHECK(send == SEND_NOTHING || send == SEND_MICROPHONE); | 
| + | 
| + auto it = send_streams_.find(ssrc); | 
| + if (it == send_streams_.end()) { | 
| + RTC_DCHECK(false && "UpdateChannelSendState called with invalid SSRC."); | 
| + return false; | 
| + } | 
| + | 
| + int channel = it->second->channel(); | 
| + if (send == SEND_MICROPHONE && it->second->IsRendering()) { | 
| if (engine()->voe()->base()->StartSend(channel) == -1) { | 
| LOG_RTCERR1(StartSend, channel); | 
| return false; | 
| } | 
| - } else { // SEND_NOTHING | 
| - RTC_DCHECK(send == SEND_NOTHING); | 
| + } else { // SEND_NOTHING || !it->second->IsRendering() | 
| if (engine()->voe()->base()->StopSend(channel) == -1) { | 
| LOG_RTCERR1(StopSend, channel); | 
| return false; | 
| @@ -1870,6 +1884,11 @@ bool WebRtcVoiceMediaChannel::SetAudioSend(uint32_t ssrc, | 
| if (!MuteStream(ssrc, !enable)) { | 
| return false; | 
| } | 
| + // If the renderer was set or unset we may need to update the sending | 
| + // state of the voe::Channel. | 
| + if (!UpdateChannelSendState(ssrc, send_)) { | 
| + return false; | 
| + } | 
| if (enable && options) { | 
| return SetOptions(*options); | 
| } | 
| @@ -1951,7 +1970,7 @@ bool WebRtcVoiceMediaChannel::AddSendStream(const StreamParams& sp) { | 
| } | 
| } | 
| - return ChangeSend(channel, desired_send_); | 
| 
 
Taylor Brandstetter
2016/03/02 21:53:53
I changed this from desired_send_ to send_, becaus
 
 | 
| + return UpdateChannelSendState(ssrc, send_); | 
| } | 
| bool WebRtcVoiceMediaChannel::RemoveSendStream(uint32_t ssrc) { | 
| @@ -1965,10 +1984,10 @@ bool WebRtcVoiceMediaChannel::RemoveSendStream(uint32_t ssrc) { | 
| return false; | 
| } | 
| - int channel = it->second->channel(); | 
| - ChangeSend(channel, SEND_NOTHING); | 
| + UpdateChannelSendState(ssrc, SEND_NOTHING); | 
| // Clean up and delete the send stream+channel. | 
| + int channel = it->second->channel(); | 
| LOG(LS_INFO) << "Removing audio send stream " << ssrc | 
| << " with VoiceEngine channel #" << channel << "."; | 
| delete it->second; | 
| @@ -2103,9 +2122,9 @@ bool WebRtcVoiceMediaChannel::SetLocalRenderer(uint32_t ssrc, | 
| } | 
| if (renderer) { | 
| - it->second->Start(renderer); | 
| + it->second->StartRendering(renderer); | 
| } else { | 
| - it->second->Stop(); | 
| + it->second->StopRendering(); | 
| } | 
| return true; |