Update the call when the network route changes

so that BWE can be updated promptly.

BUG=webrtc:5726
R=mflodman@webrtc.org, pbos@webrtc.org, pthatcher@google.com, pthatcher@webrtc.org, stefan@webrtc.org

Review URL: https://codereview.webrtc.org/1844773002 .

Cr-Commit-Position: refs/heads/master@{#12432}
This commit is contained in:
Honghai Zhang 2016-04-19 15:41:36 -07:00
parent 8b577ed531
commit 0e533ef487
12 changed files with 65 additions and 24 deletions

View File

@ -15,7 +15,7 @@
// the media code can rely on and the network code can implement, and both can
// depend on that, but not depend on each other. Then, move this file to that
// directory.
namespace cricket {
namespace rtc {
struct NetworkRoute {
bool connected;
@ -47,6 +47,6 @@ struct NetworkRoute {
bool operator!=(const NetworkRoute& nr) const { return !(*this == nr); }
};
} // namespace cricket
} // namespace rtc
#endif // WEBRTC_BASE_NETWORKROUTE_H_

View File

@ -17,6 +17,7 @@
#include "webrtc/audio_receive_stream.h"
#include "webrtc/audio_send_stream.h"
#include "webrtc/audio_state.h"
#include "webrtc/base/networkroute.h"
#include "webrtc/base/socket.h"
#include "webrtc/video_receive_stream.h"
#include "webrtc/video_send_stream.h"
@ -140,6 +141,10 @@ class Call {
virtual void SignalChannelNetworkState(MediaType media,
NetworkState state) = 0;
virtual void OnNetworkRouteChanged(
const std::string& transport_name,
const rtc::NetworkRoute& network_route) = 0;
virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
virtual ~Call() {}

View File

@ -89,6 +89,9 @@ class Call : public webrtc::Call, public PacketReceiver,
void SignalChannelNetworkState(MediaType media, NetworkState state) override;
void OnNetworkRouteChanged(const std::string& transport_name,
const rtc::NetworkRoute& network_route) override;
void OnSentPacket(const rtc::SentPacket& sent_packet) override;
// Implements BitrateObserver.
@ -102,7 +105,6 @@ class Call : public webrtc::Call, public PacketReceiver,
const uint8_t* packet,
size_t length,
const PacketTime& packet_time);
void ConfigureSync(const std::string& sync_group)
EXCLUSIVE_LOCKS_REQUIRED(receive_crit_);
@ -170,6 +172,8 @@ class Call : public webrtc::Call, public PacketReceiver,
int64_t pacer_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_);
int64_t num_bitrate_updates_ GUARDED_BY(&bitrate_crit_);
std::map<std::string, rtc::NetworkRoute> network_routes_;
VieRemb remb_;
const std::unique_ptr<CongestionController> congestion_controller_;
@ -591,6 +595,37 @@ void Call::SignalChannelNetworkState(MediaType media, NetworkState state) {
}
}
// TODO(honghaiz): Add tests for this method.
void Call::OnNetworkRouteChanged(const std::string& transport_name,
const rtc::NetworkRoute& network_route) {
RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
// Check if the network route is connected.
if (!network_route.connected) {
LOG(LS_INFO) << "Transport " << transport_name << " is disconnected";
// TODO(honghaiz): Perhaps handle this in SignalChannelNetworkState and
// consider merging these two methods.
return;
}
// Check whether the network route has changed on each transport.
auto result =
network_routes_.insert(std::make_pair(transport_name, network_route));
auto kv = result.first;
bool inserted = result.second;
if (inserted) {
// No need to reset BWE if this is the first time the network connects.
return;
}
if (kv->second != network_route) {
kv->second = network_route;
LOG(LS_INFO) << "Network route changed on transport " << transport_name
<< ": new local network id " << network_route.local_network_id
<< " new remote network id "
<< network_route.remote_network_id;
// TODO(holmer): Update the BWE bitrates.
}
}
void Call::UpdateAggregateNetworkState() {
RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());

View File

@ -179,7 +179,7 @@ template <class Base> class RtpHelper : public Base {
return ready_to_send_;
}
NetworkRoute last_network_route() const { return last_network_route_; }
rtc::NetworkRoute last_network_route() const { return last_network_route_; }
int num_network_route_changes() const { return num_network_route_changes_; }
void set_num_network_route_changes(int changes) {
num_network_route_changes_ = changes;
@ -224,7 +224,7 @@ template <class Base> class RtpHelper : public Base {
ready_to_send_ = ready;
}
virtual void OnNetworkRouteChanged(const std::string& transport_name,
const NetworkRoute& network_route) {
const rtc::NetworkRoute& network_route) {
last_network_route_ = network_route;
++num_network_route_changes_;
}
@ -247,7 +247,7 @@ template <class Base> class RtpHelper : public Base {
uint32_t send_ssrc_;
std::string rtcp_cname_;
bool ready_to_send_;
NetworkRoute last_network_route_;
rtc::NetworkRoute last_network_route_;
int num_network_route_changes_ = 0;
};

View File

@ -392,8 +392,9 @@ class MediaChannel : public sigslot::has_slots<> {
// Called when the socket's ability to send has changed.
virtual void OnReadyToSend(bool ready) = 0;
// Called when the network route used for sending packets changed.
virtual void OnNetworkRouteChanged(const std::string& transport_name,
const NetworkRoute& network_route) = 0;
virtual void OnNetworkRouteChanged(
const std::string& transport_name,
const rtc::NetworkRoute& network_route) = 0;
// Creates a new outgoing media stream with SSRCs and CNAME as described
// by sp.
virtual bool AddSendStream(const StreamParams& sp) = 0;
@ -1112,7 +1113,7 @@ class DataMediaChannel : public MediaChannel {
virtual bool SetReceive(bool receive) = 0;
virtual void OnNetworkRouteChanged(const std::string& transport_name,
const NetworkRoute& network_route) {}
const rtc::NetworkRoute& network_route) {}
virtual bool SendData(
const SendDataParams& params,

View File

@ -239,6 +239,8 @@ class FakeCall final : public webrtc::Call, public webrtc::PacketReceiver {
void SetBitrateConfig(
const webrtc::Call::Config::BitrateConfig& bitrate_config) override;
void OnNetworkRouteChanged(const std::string& transport_name,
const rtc::NetworkRoute& network_route) override {}
void SignalChannelNetworkState(webrtc::MediaType media,
webrtc::NetworkState state) override;
void OnSentPacket(const rtc::SentPacket& sent_packet) override;

View File

@ -1410,9 +1410,8 @@ void WebRtcVideoChannel2::OnReadyToSend(bool ready) {
void WebRtcVideoChannel2::OnNetworkRouteChanged(
const std::string& transport_name,
const NetworkRoute& network_route) {
// TODO(honghaiz): uncomment this once the function in call is implemented.
// call_->OnNetworkRouteChanged(transport_name, network_route);
const rtc::NetworkRoute& network_route) {
call_->OnNetworkRouteChanged(transport_name, network_route);
}
// TODO(pbos): Remove SetOptions in favor of SetSendParameters.

View File

@ -171,7 +171,7 @@ class WebRtcVideoChannel2 : public VideoMediaChannel, public webrtc::Transport {
const rtc::PacketTime& packet_time) override;
void OnReadyToSend(bool ready) override;
void OnNetworkRouteChanged(const std::string& transport_name,
const NetworkRoute& network_route) override;
const rtc::NetworkRoute& network_route) override;
void SetInterface(NetworkInterface* iface) override;
// Implemented for VideoMediaChannelTest.

View File

@ -2335,9 +2335,8 @@ void WebRtcVoiceMediaChannel::OnRtcpReceived(
void WebRtcVoiceMediaChannel::OnNetworkRouteChanged(
const std::string& transport_name,
const NetworkRoute& network_route) {
// TODO(honghaiz): uncomment this once the function in call is implemented.
// call_->OnNetworkRouteChanged(transport_name, network_route);
const rtc::NetworkRoute& network_route) {
call_->OnNetworkRouteChanged(transport_name, network_route);
}
bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) {

View File

@ -181,7 +181,7 @@ class WebRtcVoiceMediaChannel final : public VoiceMediaChannel,
void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
const rtc::PacketTime& packet_time) override;
void OnNetworkRouteChanged(const std::string& transport_name,
const NetworkRoute& network_route) override;
const rtc::NetworkRoute& network_route) override;
void OnReadyToSend(bool ready) override;
bool GetStats(VoiceMediaInfo* info) override;

View File

@ -512,12 +512,12 @@ void BaseChannel::OnSelectedCandidatePairChanged(
CandidatePairInterface* selected_candidate_pair,
int last_sent_packet_id) {
ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
NetworkRoute network_route;
rtc::NetworkRoute network_route;
if (selected_candidate_pair) {
network_route =
NetworkRoute(selected_candidate_pair->local_candidate().network_id(),
selected_candidate_pair->remote_candidate().network_id(),
last_sent_packet_id);
network_route = rtc::NetworkRoute(
selected_candidate_pair->local_candidate().network_id(),
selected_candidate_pair->remote_candidate().network_id(),
last_sent_packet_id);
}
media_channel()->OnNetworkRouteChanged(channel->transport_name(),
network_route);

View File

@ -987,8 +987,8 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
transport_channel1->SignalSelectedCandidatePairChanged(
transport_channel1, candidate_pair.get(), last_packet_id);
EXPECT_EQ(1, media_channel1_->num_network_route_changes());
cricket::NetworkRoute expected_network_route(local_net_id, remote_net_id,
last_packet_id);
rtc::NetworkRoute expected_network_route(local_net_id, remote_net_id,
last_packet_id);
EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
EXPECT_EQ(last_packet_id,
media_channel1->last_network_route().last_sent_packet_id);