Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: webrtc/p2p/base/port.cc

Issue 2722933002: Measure packet loss so we can use it to select ICE candidate pairs. (Closed)
Patch Set: Append ForTesting to TrackedPacketsString method name. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/port.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 inline int ConservativeRTTEstimate(int rtt) { 70 inline int ConservativeRTTEstimate(int rtt) {
71 return std::max(MINIMUM_RTT, std::min(MAXIMUM_RTT, 2 * rtt)); 71 return std::max(MINIMUM_RTT, std::min(MAXIMUM_RTT, 2 * rtt));
72 } 72 }
73 73
74 // Weighting of the old rtt value to new data. 74 // Weighting of the old rtt value to new data.
75 const int RTT_RATIO = 3; // 3 : 1 75 const int RTT_RATIO = 3; // 3 : 1
76 76
77 // The delay before we begin checking if this port is useless. We set 77 // The delay before we begin checking if this port is useless. We set
78 // it to a little higher than a total STUN timeout. 78 // it to a little higher than a total STUN timeout.
79 const int kPortTimeoutDelay = cricket::STUN_TOTAL_TIMEOUT + 5000; 79 const int kPortTimeoutDelay = cricket::STUN_TOTAL_TIMEOUT + 5000;
80
81 // For packet loss estimation.
82 const int64_t kConsiderPacketLostAfter = 3000; // 3 seconds
83
84 // For packet loss estimation.
85 const int64_t kForgetPacketAfter = 30000; // 30 seconds
86
80 } // namespace 87 } // namespace
81 88
82 namespace cricket { 89 namespace cricket {
83 90
84 // TODO(ronghuawu): Use "host", "srflx", "prflx" and "relay". But this requires 91 // TODO(ronghuawu): Use "host", "srflx", "prflx" and "relay". But this requires
85 // the signaling part be updated correspondingly as well. 92 // the signaling part be updated correspondingly as well.
86 const char LOCAL_PORT_TYPE[] = "local"; 93 const char LOCAL_PORT_TYPE[] = "local";
87 const char STUN_PORT_TYPE[] = "stun"; 94 const char STUN_PORT_TYPE[] = "stun";
88 const char PRFLX_PORT_TYPE[] = "prflx"; 95 const char PRFLX_PORT_TYPE[] = "prflx";
89 const char RELAY_PORT_TYPE[] = "relay"; 96 const char RELAY_PORT_TYPE[] = "relay";
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 connected_(true), 885 connected_(true),
879 pruned_(false), 886 pruned_(false),
880 use_candidate_attr_(false), 887 use_candidate_attr_(false),
881 remote_ice_mode_(ICEMODE_FULL), 888 remote_ice_mode_(ICEMODE_FULL),
882 requests_(port->thread()), 889 requests_(port->thread()),
883 rtt_(DEFAULT_RTT), 890 rtt_(DEFAULT_RTT),
884 last_ping_sent_(0), 891 last_ping_sent_(0),
885 last_ping_received_(0), 892 last_ping_received_(0),
886 last_data_received_(0), 893 last_data_received_(0),
887 last_ping_response_received_(0), 894 last_ping_response_received_(0),
895 packet_loss_estimator_(kConsiderPacketLostAfter, kForgetPacketAfter),
888 reported_(false), 896 reported_(false),
889 state_(IceCandidatePairState::WAITING), 897 state_(IceCandidatePairState::WAITING),
890 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), 898 receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT),
891 time_created_ms_(rtc::TimeMillis()) { 899 time_created_ms_(rtc::TimeMillis()) {
892 // All of our connections start in WAITING state. 900 // All of our connections start in WAITING state.
893 // TODO(mallinath) - Start connections from STATE_FROZEN. 901 // TODO(mallinath) - Start connections from STATE_FROZEN.
894 // Wire up to send stun packets 902 // Wire up to send stun packets
895 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); 903 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket);
896 LOG_J(LS_INFO, this) << "Connection created"; 904 LOG_J(LS_INFO, this) << "Connection created";
897 } 905 }
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 UpdateReceiving(now); 1238 UpdateReceiving(now);
1231 if (dead(now)) { 1239 if (dead(now)) {
1232 Destroy(); 1240 Destroy();
1233 } 1241 }
1234 } 1242 }
1235 1243
1236 void Connection::Ping(int64_t now) { 1244 void Connection::Ping(int64_t now) {
1237 last_ping_sent_ = now; 1245 last_ping_sent_ = now;
1238 ConnectionRequest *req = new ConnectionRequest(this); 1246 ConnectionRequest *req = new ConnectionRequest(this);
1239 pings_since_last_response_.push_back(SentPing(req->id(), now, nomination_)); 1247 pings_since_last_response_.push_back(SentPing(req->id(), now, nomination_));
1248 packet_loss_estimator_.ExpectResponse(req->id(), now);
1240 LOG_J(LS_VERBOSE, this) << "Sending STUN ping " 1249 LOG_J(LS_VERBOSE, this) << "Sending STUN ping "
1241 << ", id=" << rtc::hex_encode(req->id()) 1250 << ", id=" << rtc::hex_encode(req->id())
1242 << ", nomination=" << nomination_; 1251 << ", nomination=" << nomination_;
1243 requests_.Send(req); 1252 requests_.Send(req);
1244 state_ = IceCandidatePairState::IN_PROGRESS; 1253 state_ = IceCandidatePairState::IN_PROGRESS;
1245 num_pings_sent_++; 1254 num_pings_sent_++;
1246 } 1255 }
1247 1256
1248 void Connection::ReceivedPing() { 1257 void Connection::ReceivedPing() {
1249 last_ping_received_ = rtc::TimeMillis(); 1258 last_ping_received_ = rtc::TimeMillis();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 std::string pings; 1393 std::string pings;
1385 PrintPingsSinceLastResponse(&pings, 5); 1394 PrintPingsSinceLastResponse(&pings, 5);
1386 LOG_JV(sev, this) << "Received STUN ping response" 1395 LOG_JV(sev, this) << "Received STUN ping response"
1387 << ", id=" << rtc::hex_encode(request->id()) 1396 << ", id=" << rtc::hex_encode(request->id())
1388 << ", code=0" // Makes logging easier to parse. 1397 << ", code=0" // Makes logging easier to parse.
1389 << ", rtt=" << rtt 1398 << ", rtt=" << rtt
1390 << ", pings_since_last_response=" << pings; 1399 << ", pings_since_last_response=" << pings;
1391 } 1400 }
1392 ReceivedPingResponse(rtt, request->id()); 1401 ReceivedPingResponse(rtt, request->id());
1393 1402
1403 int64_t time_received = rtc::TimeMillis();
1404 packet_loss_estimator_.ReceivedResponse(request->id(), time_received);
1405
1394 stats_.recv_ping_responses++; 1406 stats_.recv_ping_responses++;
1395 1407
1396 MaybeUpdateLocalCandidate(request, response); 1408 MaybeUpdateLocalCandidate(request, response);
1397 } 1409 }
1398 1410
1399 void Connection::OnConnectionRequestErrorResponse(ConnectionRequest* request, 1411 void Connection::OnConnectionRequestErrorResponse(ConnectionRequest* request,
1400 StunMessage* response) { 1412 StunMessage* response) {
1401 const StunErrorCodeAttribute* error_attr = response->GetErrorCode(); 1413 const StunErrorCodeAttribute* error_attr = response->GetErrorCode();
1402 int error_code = STUN_ERROR_GLOBAL_FAILURE; 1414 int error_code = STUN_ERROR_GLOBAL_FAILURE;
1403 if (error_attr) { 1415 if (error_attr) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 RTC_DCHECK(sent < 0); 1624 RTC_DCHECK(sent < 0);
1613 error_ = port_->GetError(); 1625 error_ = port_->GetError();
1614 stats_.sent_discarded_packets++; 1626 stats_.sent_discarded_packets++;
1615 } else { 1627 } else {
1616 send_rate_tracker_.AddSamples(sent); 1628 send_rate_tracker_.AddSamples(sent);
1617 } 1629 }
1618 return sent; 1630 return sent;
1619 } 1631 }
1620 1632
1621 } // namespace cricket 1633 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/port.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698