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

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

Issue 1413603005: Reland of Add experiment on weak ping delay during call set up time (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 1 month 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/p2ptransportchannel.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
11 #include "webrtc/p2p/base/p2ptransportchannel.h" 11 #include "webrtc/p2p/base/p2ptransportchannel.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <set> 14 #include <set>
15 #include "webrtc/p2p/base/common.h" 15 #include "webrtc/p2p/base/common.h"
16 #include "webrtc/p2p/base/relayport.h" // For RELAY_PORT_TYPE. 16 #include "webrtc/p2p/base/relayport.h" // For RELAY_PORT_TYPE.
17 #include "webrtc/p2p/base/stunport.h" // For STUN_PORT_TYPE. 17 #include "webrtc/p2p/base/stunport.h" // For STUN_PORT_TYPE.
18 #include "webrtc/base/common.h" 18 #include "webrtc/base/common.h"
19 #include "webrtc/base/crc32.h" 19 #include "webrtc/base/crc32.h"
20 #include "webrtc/base/logging.h" 20 #include "webrtc/base/logging.h"
21 #include "webrtc/base/stringencode.h" 21 #include "webrtc/base/stringencode.h"
22 #include "webrtc/system_wrappers/interface/field_trial.h"
22 23
23 namespace { 24 namespace {
24 25
25 // messages for queuing up work for ourselves 26 // messages for queuing up work for ourselves
26 enum { MSG_SORT = 1, MSG_CHECK_AND_PING }; 27 enum { MSG_SORT = 1, MSG_CHECK_AND_PING };
27 28
28 // When the socket is unwritable, we will use 10 Kbps (ignoring IP+UDP headers)
29 // for pinging. When the socket is writable, we will use only 1 Kbps because
30 // we don't want to degrade the quality on a modem. These numbers should work
31 // well on a 28.8K modem, which is the slowest connection on which the voice
32 // quality is reasonable at all.
33 static const uint32_t PING_PACKET_SIZE = 60 * 8;
34 // STRONG_PING_DELAY (480ms) is applied when the best connection is both
35 // writable and receiving.
36 static const uint32_t STRONG_PING_DELAY = 1000 * PING_PACKET_SIZE / 1000;
37 // WEAK_PING_DELAY (48ms) is applied when the best connection is either not
38 // writable or not receiving.
39 static const uint32_t WEAK_PING_DELAY = 1000 * PING_PACKET_SIZE / 10000;
40
41 // If the current best connection is both writable and receiving, then we will
42 // also try hard to make sure it is pinged at this rate (a little less than
43 // 2 * STRONG_PING_DELAY).
44 static const uint32_t MAX_CURRENT_STRONG_DELAY = 900;
45
46 static const int MIN_CHECK_RECEIVING_DELAY = 50; // ms
47
48 // The minimum improvement in RTT that justifies a switch. 29 // The minimum improvement in RTT that justifies a switch.
49 static const double kMinImprovement = 10; 30 static const double kMinImprovement = 10;
50 31
51 cricket::PortInterface::CandidateOrigin GetOrigin(cricket::PortInterface* port, 32 cricket::PortInterface::CandidateOrigin GetOrigin(cricket::PortInterface* port,
52 cricket::PortInterface* origin_port) { 33 cricket::PortInterface* origin_port) {
53 if (!origin_port) 34 if (!origin_port)
54 return cricket::PortInterface::ORIGIN_MESSAGE; 35 return cricket::PortInterface::ORIGIN_MESSAGE;
55 else if (port == origin_port) 36 else if (port == origin_port)
56 return cricket::PortInterface::ORIGIN_THIS_PORT; 37 return cricket::PortInterface::ORIGIN_THIS_PORT;
57 else 38 else
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 return prefs_cmp < 0; 174 return prefs_cmp < 0;
194 } 175 }
195 176
196 return b_conn->rtt() <= a_conn->rtt() + kMinImprovement; 177 return b_conn->rtt() <= a_conn->rtt() + kMinImprovement;
197 } 178 }
198 179
199 } // unnamed namespace 180 } // unnamed namespace
200 181
201 namespace cricket { 182 namespace cricket {
202 183
184 // When the socket is unwritable, we will use 10 Kbps (ignoring IP+UDP headers)
185 // for pinging. When the socket is writable, we will use only 1 Kbps because
186 // we don't want to degrade the quality on a modem. These numbers should work
187 // well on a 28.8K modem, which is the slowest connection on which the voice
188 // quality is reasonable at all.
189 static const uint32_t PING_PACKET_SIZE = 60 * 8;
190 // STRONG_PING_DELAY (480ms) is applied when the best connection is both
191 // writable and receiving.
192 static const uint32_t STRONG_PING_DELAY = 1000 * PING_PACKET_SIZE / 1000;
193 // WEAK_PING_DELAY (48ms) is applied when the best connection is either not
194 // writable or not receiving.
195 const uint32_t WEAK_PING_DELAY = 1000 * PING_PACKET_SIZE / 10000;
196
197 // If the current best connection is both writable and receiving, then we will
198 // also try hard to make sure it is pinged at this rate (a little less than
199 // 2 * STRONG_PING_DELAY).
200 static const uint32_t MAX_CURRENT_STRONG_DELAY = 900;
201
202 static const int MIN_CHECK_RECEIVING_DELAY = 50; // ms
203
204
203 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, 205 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name,
204 int component, 206 int component,
205 P2PTransport* transport, 207 P2PTransport* transport,
206 PortAllocator* allocator) 208 PortAllocator* allocator)
207 : TransportChannelImpl(transport_name, component), 209 : TransportChannelImpl(transport_name, component),
208 transport_(transport), 210 transport_(transport),
209 allocator_(allocator), 211 allocator_(allocator),
210 worker_thread_(rtc::Thread::Current()), 212 worker_thread_(rtc::Thread::Current()),
211 incoming_only_(false), 213 incoming_only_(false),
212 error_(0), 214 error_(0),
213 best_connection_(NULL), 215 best_connection_(NULL),
214 pending_best_connection_(NULL), 216 pending_best_connection_(NULL),
215 sort_dirty_(false), 217 sort_dirty_(false),
216 was_writable_(false), 218 was_writable_(false),
217 remote_ice_mode_(ICEMODE_FULL), 219 remote_ice_mode_(ICEMODE_FULL),
218 ice_role_(ICEROLE_UNKNOWN), 220 ice_role_(ICEROLE_UNKNOWN),
219 tiebreaker_(0), 221 tiebreaker_(0),
220 remote_candidate_generation_(0), 222 remote_candidate_generation_(0),
221 gathering_state_(kIceGatheringNew), 223 gathering_state_(kIceGatheringNew),
222 check_receiving_delay_(MIN_CHECK_RECEIVING_DELAY * 5), 224 check_receiving_delay_(MIN_CHECK_RECEIVING_DELAY * 5),
223 receiving_timeout_(MIN_CHECK_RECEIVING_DELAY * 50) {} 225 receiving_timeout_(MIN_CHECK_RECEIVING_DELAY * 50) {
226 uint32_t weak_ping_delay = ::strtoul(
227 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(),
228 nullptr, 10);
229 if (weak_ping_delay) {
230 weak_ping_delay_ = weak_ping_delay;
231 }
232 }
224 233
225 P2PTransportChannel::~P2PTransportChannel() { 234 P2PTransportChannel::~P2PTransportChannel() {
226 ASSERT(worker_thread_ == rtc::Thread::Current()); 235 ASSERT(worker_thread_ == rtc::Thread::Current());
227 236
228 for (size_t i = 0; i < allocator_sessions_.size(); ++i) 237 for (size_t i = 0; i < allocator_sessions_.size(); ++i)
229 delete allocator_sessions_[i]; 238 delete allocator_sessions_[i];
230 } 239 }
231 240
232 // Add the allocator session to our list so that we know which sessions 241 // Add the allocator session to our list so that we know which sessions
233 // are still active. 242 // are still active.
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 SortConnections(); 1159 SortConnections();
1151 } 1160 }
1152 1161
1153 // Handle queued up check-and-ping request 1162 // Handle queued up check-and-ping request
1154 void P2PTransportChannel::OnCheckAndPing() { 1163 void P2PTransportChannel::OnCheckAndPing() {
1155 // Make sure the states of the connections are up-to-date (since this affects 1164 // Make sure the states of the connections are up-to-date (since this affects
1156 // which ones are pingable). 1165 // which ones are pingable).
1157 UpdateConnectionStates(); 1166 UpdateConnectionStates();
1158 // When the best connection is either not receiving or not writable, 1167 // When the best connection is either not receiving or not writable,
1159 // switch to weak ping delay. 1168 // switch to weak ping delay.
1160 int ping_delay = weak() ? WEAK_PING_DELAY : STRONG_PING_DELAY; 1169 int ping_delay = weak() ? weak_ping_delay_ : STRONG_PING_DELAY;
1161 if (rtc::Time() >= last_ping_sent_ms_ + ping_delay) { 1170 if (rtc::Time() >= last_ping_sent_ms_ + ping_delay) {
1162 Connection* conn = FindNextPingableConnection(); 1171 Connection* conn = FindNextPingableConnection();
1163 if (conn) { 1172 if (conn) {
1164 PingConnection(conn); 1173 PingConnection(conn);
1165 } 1174 }
1166 } 1175 }
1167 int check_delay = std::min(ping_delay, check_receiving_delay_); 1176 int check_delay = std::min(ping_delay, check_receiving_delay_);
1168 thread()->PostDelayed(check_delay, this, MSG_CHECK_AND_PING); 1177 thread()->PostDelayed(check_delay, this, MSG_CHECK_AND_PING);
1169 } 1178 }
1170 1179
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 SignalSentPacket(this, sent_packet); 1373 SignalSentPacket(this, sent_packet);
1365 } 1374 }
1366 1375
1367 void P2PTransportChannel::OnReadyToSend(Connection* connection) { 1376 void P2PTransportChannel::OnReadyToSend(Connection* connection) {
1368 if (connection == best_connection_ && writable()) { 1377 if (connection == best_connection_ && writable()) {
1369 SignalReadyToSend(this); 1378 SignalReadyToSend(this);
1370 } 1379 }
1371 } 1380 }
1372 1381
1373 } // namespace cricket 1382 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698