diff --git a/talk/media/webrtc/webrtcvoiceengine.cc b/talk/media/webrtc/webrtcvoiceengine.cc index 3fae1a742d..17acd1be0e 100644 --- a/talk/media/webrtc/webrtcvoiceengine.cc +++ b/talk/media/webrtc/webrtcvoiceengine.cc @@ -1390,7 +1390,7 @@ WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine, const AudioOptions& options, webrtc::Call* call) : engine_(engine), - voe_channel_(engine->CreateMediaVoiceChannel()), + default_send_channel_id_(engine->CreateMediaVoiceChannel()), send_bitrate_setting_(false), send_bitrate_bps_(0), options_(), @@ -1406,16 +1406,16 @@ WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine, RTC_DCHECK(thread_checker_.CalledOnValidThread()); engine->RegisterChannel(this); LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::WebRtcVoiceMediaChannel " - << voe_channel(); + << default_send_channel_id(); RTC_DCHECK(nullptr != call); - ConfigureSendChannel(voe_channel()); + ConfigureSendChannel(default_send_channel_id()); SetOptions(options); } WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel() { RTC_DCHECK(thread_checker_.CalledOnValidThread()); LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel " - << voe_channel(); + << default_send_channel_id(); // Remove any remaining send streams, the default channel will be deleted // later. @@ -1433,7 +1433,7 @@ WebRtcVoiceMediaChannel::~WebRtcVoiceMediaChannel() { RTC_DCHECK(receive_streams_.empty()); // Delete the default channel. - DeleteChannel(voe_channel()); + DeleteChannel(default_send_channel_id()); } bool WebRtcVoiceMediaChannel::SetSendParameters( @@ -1485,7 +1485,9 @@ bool WebRtcVoiceMediaChannel::SetOptions(const AudioOptions& options) { LOG(LS_WARNING) << "Failed to set DSCP settings for audio channel"; } } + RecreateAudioReceiveStreams(); + LOG(LS_INFO) << "Set voice channel options. Current options: " << options_.ToString(); return true; @@ -1493,9 +1495,10 @@ bool WebRtcVoiceMediaChannel::SetOptions(const AudioOptions& options) { bool WebRtcVoiceMediaChannel::SetRecvCodecs( const std::vector& codecs) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + // Set the payload types to be used for incoming media. LOG(LS_INFO) << "Setting receive voice codecs."; - RTC_DCHECK(thread_checker_.CalledOnValidThread()); if (!VerifyUniquePayloadTypes(codecs)) { LOG(LS_ERROR) << "Codec payload types overlap."; @@ -1830,7 +1833,8 @@ bool WebRtcVoiceMediaChannel::SetRecvRtpHeaderExtensions( // The default channel may or may not be in |receive_channels_|. Set the rtp // header extensions for default channel regardless. - if (!SetChannelRecvRtpHeaderExtensions(voe_channel(), extensions)) { + if (!SetChannelRecvRtpHeaderExtensions(default_send_channel_id(), + extensions)) { return false; } @@ -1899,7 +1903,8 @@ bool WebRtcVoiceMediaChannel::SetSendRtpHeaderExtensions( // The default channel may or may not be in |send_channels_|. Set the rtp // header extensions for default channel regardless. - if (!SetChannelSendRtpHeaderExtensions(voe_channel(), extensions)) { + if (!SetChannelSendRtpHeaderExtensions(default_send_channel_id(), + extensions)) { return false; } @@ -1959,7 +1964,7 @@ bool WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { bool result = true; if (receive_channels_.empty()) { // Only toggle the default channel if we don't have any other channels. - result = SetPlayout(voe_channel(), playout); + result = SetPlayout(default_send_channel_id(), playout); } for (const auto& ch : receive_channels_) { if (!SetPlayout(ch.second->channel(), playout)) { @@ -2103,7 +2108,7 @@ bool WebRtcVoiceMediaChannel::AddSendStream(const StreamParams& sp) { } } if (default_channel_is_available) { - channel = voe_channel(); + channel = default_send_channel_id(); } else { // Create a new channel for sending audio data. channel = engine()->CreateMediaVoiceChannel(); @@ -2226,11 +2231,12 @@ bool WebRtcVoiceMediaChannel::AddRecvStream(const StreamParams& sp) { LOG(LS_INFO) << "Recv stream " << ssrc << " reuse default channel"; default_receive_ssrc_ = ssrc; WebRtcVoiceChannelRenderer* channel_renderer = - new WebRtcVoiceChannelRenderer(voe_channel(), audio_transport); + new WebRtcVoiceChannelRenderer(default_send_channel_id(), + audio_transport); receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); receive_stream_params_[ssrc] = sp; AddAudioReceiveStream(ssrc); - return SetPlayout(voe_channel(), playout_); + return SetPlayout(default_send_channel_id(), playout_); } // Create a new channel for receiving audio data. @@ -2239,7 +2245,6 @@ bool WebRtcVoiceMediaChannel::AddRecvStream(const StreamParams& sp) { LOG_RTCERR0(CreateChannel); return false; } - if (!ConfigureRecvChannel(channel)) { DeleteChannel(channel); return false; @@ -2259,17 +2264,18 @@ bool WebRtcVoiceMediaChannel::AddRecvStream(const StreamParams& sp) { bool WebRtcVoiceMediaChannel::ConfigureRecvChannel(int channel) { RTC_DCHECK(thread_checker_.CalledOnValidThread()); - // Configure to use external transport, like our default channel. + // Configure to use external transport. if (engine()->voe()->network()->RegisterExternalTransport( channel, *this) == -1) { LOG_RTCERR2(SetExternalTransport, channel, this); return false; } - // Use the same SSRC as our default channel (so the RTCP reports are correct). + // Use the same SSRC as our default send channel, so the RTCP reports are + // correct. unsigned int send_ssrc = 0; webrtc::VoERTP_RTCP* rtp = engine()->voe()->rtp(); - if (rtp->GetLocalSSRC(voe_channel(), send_ssrc) == -1) { + if (rtp->GetLocalSSRC(default_send_channel_id(), send_ssrc) == -1) { LOG_RTCERR1(GetSendSSRC, channel); return false; } @@ -2278,12 +2284,13 @@ bool WebRtcVoiceMediaChannel::ConfigureRecvChannel(int channel) { return false; } - // Associate receive channel to default channel (so the receive channel can - // obtain RTT from the send channel) - engine()->voe()->base()->AssociateSendChannel(channel, voe_channel()); + // Associate receive channel to default send channel (so the receive channel + // can obtain RTT from the send channel). + engine()->voe()->base()->AssociateSendChannel(channel, + default_send_channel_id()); LOG(LS_INFO) << "VoiceEngine channel #" << channel << " is associated with channel #" - << voe_channel() << "."; + << default_send_channel_id() << "."; // Use the same recv payload types as our default channel. ResetRecvCodecs(channel); @@ -2294,7 +2301,7 @@ bool WebRtcVoiceMediaChannel::ConfigureRecvChannel(int channel) { voe_codec.pltype = codec.id; voe_codec.rate = 0; // Needed to make GetRecPayloadType work for ISAC if (engine()->voe()->codec()->GetRecPayloadType( - voe_channel(), voe_codec) != -1) { + default_send_channel_id(), voe_codec) != -1) { if (engine()->voe()->codec()->SetRecPayloadType( channel, voe_codec) == -1) { LOG_RTCERR2(SetRecPayloadType, channel, ToString(voe_codec)); @@ -2306,8 +2313,8 @@ bool WebRtcVoiceMediaChannel::ConfigureRecvChannel(int channel) { } if (InConferenceMode()) { - // To be in par with the video, voe_channel() is not used for receiving in - // a conference call. + // To be in par with the video, default_send_channel_id() is not used for + // receiving in a conference call. if (receive_channels_.empty() && default_receive_ssrc_ == 0 && playout_) { // This is the first stream in a multi user meeting. We can now // disable playback of the default stream. This since the default @@ -2316,9 +2323,10 @@ bool WebRtcVoiceMediaChannel::ConfigureRecvChannel(int channel) { // the default channel will be mixed in with the other streams // throughout the whole meeting, which might be disturbing. LOG(LS_INFO) << "Disabling playback on the default voice channel"; - SetPlayout(voe_channel(), false); + SetPlayout(default_send_channel_id(), false); } } + SetNack(channel, nack_enabled_); // Set RTP header extension for the new channel. @@ -2355,7 +2363,7 @@ bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32_t ssrc) { RTC_DCHECK(IsDefaultChannel(channel)); // Recycle the default channel is for recv stream. if (playout_) - SetPlayout(voe_channel(), false); + SetPlayout(default_send_channel_id(), false); default_receive_ssrc_ = 0; return true; @@ -2383,7 +2391,7 @@ bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32_t ssrc) { } if (enable_default_channel_playout && playout_) { LOG(LS_INFO) << "Enabling playback on the default voice channel"; - SetPlayout(voe_channel(), true); + SetPlayout(default_send_channel_id(), true); } return true; @@ -2429,10 +2437,9 @@ bool WebRtcVoiceMediaChannel::GetActiveStreams( int WebRtcVoiceMediaChannel::GetOutputLevel() { RTC_DCHECK(thread_checker_.CalledOnValidThread()); // return the highest output level of all streams - int highest = GetOutputLevel(voe_channel()); + int highest = GetOutputLevel(default_send_channel_id()); for (const auto& ch : receive_channels_) { - int level = GetOutputLevel(ch.second->channel()); - highest = std::max(level, highest); + highest = std::max(GetOutputLevel(ch.second->channel()), highest); } return highest; } @@ -2471,7 +2478,7 @@ bool WebRtcVoiceMediaChannel::SetOutputVolume(uint32_t ssrc, double volume) { // Default channel is not in receive_channels_ if it is not being used for // playout. if (default_receive_ssrc_ == 0) - channels.push_back(voe_channel()); + channels.push_back(default_send_channel_id()); for (const auto& ch : receive_channels_) { channels.push_back(ch.second->channel()); } @@ -2520,7 +2527,7 @@ bool WebRtcVoiceMediaChannel::InsertDtmf(uint32_t ssrc, } } if (default_channel_is_inuse) { - channel = voe_channel(); + channel = default_send_channel_id(); } else if (!send_channels_.empty()) { channel = send_channels_.begin()->second->channel(); } @@ -2569,7 +2576,7 @@ void WebRtcVoiceMediaChannel::OnPacketReceived( int which_channel = GetReceiveChannelId(ParseSsrc(packet->data(), packet->size(), false)); if (which_channel == -1) { - which_channel = voe_channel(); + which_channel = default_send_channel_id(); } // Pass it off to the decoder. @@ -2631,7 +2638,8 @@ void WebRtcVoiceMediaChannel::OnRtcpReceived( } bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) { - int channel = (ssrc == 0) ? voe_channel() : GetSendChannelId(ssrc); + int channel = + (ssrc == 0) ? default_send_channel_id() : GetSendChannelId(ssrc); if (channel == -1) { LOG(LS_WARNING) << "The specified ssrc " << ssrc << " is not in use."; return false; @@ -2825,7 +2833,7 @@ bool WebRtcVoiceMediaChannel::GetStats(VoiceMediaInfo* info) { channels.push_back(ch.second->channel()); } if (channels.empty()) { - channels.push_back(voe_channel()); + channels.push_back(default_send_channel_id()); } // Get the SSRC and stats for each receiver, based on our own calculations. @@ -2923,17 +2931,18 @@ int WebRtcVoiceMediaChannel::GetOutputLevel(int channel) { int WebRtcVoiceMediaChannel::GetReceiveChannelId(uint32_t ssrc) const { RTC_DCHECK(thread_checker_.CalledOnValidThread()); ChannelMap::const_iterator it = receive_channels_.find(ssrc); - if (it != receive_channels_.end()) + if (it != receive_channels_.end()) { return it->second->channel(); - return (ssrc == default_receive_ssrc_) ? voe_channel() : -1; + } + return (ssrc == default_receive_ssrc_) ? default_send_channel_id() : -1; } int WebRtcVoiceMediaChannel::GetSendChannelId(uint32_t ssrc) const { RTC_DCHECK(thread_checker_.CalledOnValidThread()); ChannelMap::const_iterator it = send_channels_.find(ssrc); - if (it != send_channels_.end()) + if (it != send_channels_.end()) { return it->second->channel(); - + } return -1; } @@ -2988,8 +2997,8 @@ bool WebRtcVoiceMediaChannel::EnableRtcp(int channel) { } // TODO(juberti): Enable VQMon and RTCP XR reports, once we know what // what we want to do with them. - // engine()->voe().EnableVQMon(voe_channel(), true); - // engine()->voe().EnableRTCP_XR(voe_channel(), true); + // engine()->voe().EnableVQMon(default_send_channel_id(), true); + // engine()->voe().EnableRTCP_XR(default_send_channel_id(), true); return true; } @@ -3136,8 +3145,9 @@ bool WebRtcVoiceMediaChannel::SetRecvCodecsInternal( // TODO(xians): Figure out how we use the default channel in conference // mode. if (engine()->voe()->codec()->SetRecPayloadType( - voe_channel(), voe_codec) == -1) { - LOG_RTCERR2(SetRecPayloadType, voe_channel(), ToString(voe_codec)); + default_send_channel_id(), voe_codec) == -1) { + LOG_RTCERR2(SetRecPayloadType, default_send_channel_id(), + ToString(voe_codec)); return false; } } diff --git a/talk/media/webrtc/webrtcvoiceengine.h b/talk/media/webrtc/webrtcvoiceengine.h index 8527cdb930..4250741e05 100644 --- a/talk/media/webrtc/webrtcvoiceengine.h +++ b/talk/media/webrtc/webrtcvoiceengine.h @@ -180,8 +180,8 @@ class WebRtcVoiceMediaChannel : public VoiceMediaChannel, webrtc::Call* call); ~WebRtcVoiceMediaChannel() override; - int voe_channel() const { return voe_channel_; } - bool valid() const { return voe_channel_ != -1; } + int default_send_channel_id() const { return default_send_channel_id_; } + bool valid() const { return default_send_channel_id_ != -1; } const AudioOptions& options() const { return options_; } bool SetSendParameters(const AudioSendParameters& params) override; @@ -286,7 +286,7 @@ class WebRtcVoiceMediaChannel : public VoiceMediaChannel, return options_.conference_mode.GetWithDefaultIfUnset(false); } bool IsDefaultChannel(int channel_id) const { - return channel_id == voe_channel(); + return channel_id == default_send_channel_id_; } bool SetSendCodecs(int channel, const std::vector& codecs); bool SetSendBitrateInternal(int bps); @@ -308,7 +308,7 @@ class WebRtcVoiceMediaChannel : public VoiceMediaChannel, rtc::ThreadChecker thread_checker_; WebRtcVoiceEngine* const engine_; - const int voe_channel_; + const int default_send_channel_id_; std::vector recv_codecs_; std::vector send_codecs_; rtc::scoped_ptr send_codec_; @@ -325,12 +325,12 @@ class WebRtcVoiceMediaChannel : public VoiceMediaChannel, webrtc::Call* const call_; // send_channels_ contains the channels which are being used for sending. - // When the default channel (voe_channel) is used for sending, it is - // contained in send_channels_, otherwise not. + // When the default channel (default_send_channel_id) is used for sending, it + // is contained in send_channels_, otherwise not. ChannelMap send_channels_; std::vector send_extensions_; uint32_t default_receive_ssrc_; - // Note the default channel (voe_channel()) can reside in both + // Note the default channel (default_send_channel_id()) can reside in both // receive_channels_ and send_channels_ in non-conference mode and in that // case it will only be there if a non-zero default_receive_ssrc_ is set. ChannelMap receive_channels_; // for multiple sources diff --git a/talk/media/webrtc/webrtcvoiceengine_unittest.cc b/talk/media/webrtc/webrtcvoiceengine_unittest.cc index 3801a208e1..6300f1df58 100644 --- a/talk/media/webrtc/webrtcvoiceengine_unittest.cc +++ b/talk/media/webrtc/webrtcvoiceengine_unittest.cc @@ -2856,12 +2856,12 @@ TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelIdIn1To1Calls) { cricket::WebRtcVoiceMediaChannel* media_channel = static_cast(channel_); // Test that GetChannelNum returns the default channel if the SSRC is unknown. - EXPECT_EQ(media_channel->voe_channel(), + EXPECT_EQ(media_channel->default_send_channel_id(), media_channel->GetReceiveChannelId(0)); cricket::StreamParams stream; stream.ssrcs.push_back(kSsrc2); EXPECT_TRUE(channel_->AddRecvStream(stream)); - EXPECT_EQ(media_channel->voe_channel(), + EXPECT_EQ(media_channel->default_send_channel_id(), media_channel->GetReceiveChannelId(kSsrc2)); } @@ -2876,7 +2876,7 @@ TEST_F(WebRtcVoiceEngineTestFake, TestGetChannelNumInConferenceCalls) { EXPECT_TRUE(channel_->AddRecvStream(stream)); cricket::WebRtcVoiceMediaChannel* media_channel = static_cast(channel_); - EXPECT_LT(media_channel->voe_channel(), + EXPECT_LT(media_channel->default_send_channel_id(), media_channel->GetReceiveChannelId(kSsrc2)); } @@ -3081,9 +3081,7 @@ TEST_F(WebRtcVoiceEngineTestFake, AssociateChannelUnset1On1) { // does not send RTCP SR. TEST_F(WebRtcVoiceEngineTestFake, AssociateDefaultChannelOnSecondRecvChannel) { EXPECT_TRUE(SetupEngine()); - cricket::WebRtcVoiceMediaChannel* media_channel = - static_cast(channel_); - int default_channel = media_channel->voe_channel(); + int default_channel = voe_.GetLastChannel(); EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); int recv_ch_1 = voe_.GetLastChannel(); EXPECT_EQ(recv_ch_1, default_channel); @@ -3103,9 +3101,7 @@ TEST_F(WebRtcVoiceEngineTestFake, AssociateDefaultChannelOnConference) { EXPECT_TRUE(SetupEngine()); send_parameters_.options = options_conference_; EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); - cricket::WebRtcVoiceMediaChannel* media_channel = - static_cast(channel_); - int default_channel = media_channel->voe_channel(); + int default_channel = voe_.GetLastChannel(); EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); int recv_ch = voe_.GetLastChannel(); EXPECT_NE(recv_ch, default_channel);