OLD | NEW |
---|---|
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 // 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 // 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 // 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 // well on a 28.8K modem, which is the slowest connection on which the voice |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 best_connection_(NULL), | 214 best_connection_(NULL), |
214 pending_best_connection_(NULL), | 215 pending_best_connection_(NULL), |
215 sort_dirty_(false), | 216 sort_dirty_(false), |
216 was_writable_(false), | 217 was_writable_(false), |
217 remote_ice_mode_(ICEMODE_FULL), | 218 remote_ice_mode_(ICEMODE_FULL), |
218 ice_role_(ICEROLE_UNKNOWN), | 219 ice_role_(ICEROLE_UNKNOWN), |
219 tiebreaker_(0), | 220 tiebreaker_(0), |
220 remote_candidate_generation_(0), | 221 remote_candidate_generation_(0), |
221 gathering_state_(kIceGatheringNew), | 222 gathering_state_(kIceGatheringNew), |
222 check_receiving_delay_(MIN_CHECK_RECEIVING_DELAY * 5), | 223 check_receiving_delay_(MIN_CHECK_RECEIVING_DELAY * 5), |
223 receiving_timeout_(MIN_CHECK_RECEIVING_DELAY * 50) {} | 224 receiving_timeout_(MIN_CHECK_RECEIVING_DELAY * 50) { |
225 uint32_t weak_ping_delay = ::strtoul( | |
226 webrtc::field_trial::FindFullName("WebRTC-WeakPingDelay").c_str(), | |
pthatcher1
2015/10/16 21:30:31
While we call it "weak ping delay" internally, the
| |
227 nullptr, 10); | |
228 weak_ping_delay_ = weak_ping_delay ? weak_ping_delay : WEAK_PING_DELAY; | |
pthatcher1
2015/10/16 21:30:31
I think this would be more readable as:
if (weak_
| |
229 } | |
224 | 230 |
225 P2PTransportChannel::~P2PTransportChannel() { | 231 P2PTransportChannel::~P2PTransportChannel() { |
226 ASSERT(worker_thread_ == rtc::Thread::Current()); | 232 ASSERT(worker_thread_ == rtc::Thread::Current()); |
227 | 233 |
228 for (size_t i = 0; i < allocator_sessions_.size(); ++i) | 234 for (size_t i = 0; i < allocator_sessions_.size(); ++i) |
229 delete allocator_sessions_[i]; | 235 delete allocator_sessions_[i]; |
230 } | 236 } |
231 | 237 |
232 // Add the allocator session to our list so that we know which sessions | 238 // Add the allocator session to our list so that we know which sessions |
233 // are still active. | 239 // are still active. |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1149 SortConnections(); | 1155 SortConnections(); |
1150 } | 1156 } |
1151 | 1157 |
1152 // Handle queued up check-and-ping request | 1158 // Handle queued up check-and-ping request |
1153 void P2PTransportChannel::OnCheckAndPing() { | 1159 void P2PTransportChannel::OnCheckAndPing() { |
1154 // Make sure the states of the connections are up-to-date (since this affects | 1160 // Make sure the states of the connections are up-to-date (since this affects |
1155 // which ones are pingable). | 1161 // which ones are pingable). |
1156 UpdateConnectionStates(); | 1162 UpdateConnectionStates(); |
1157 // When the best connection is either not receiving or not writable, | 1163 // When the best connection is either not receiving or not writable, |
1158 // switch to weak ping delay. | 1164 // switch to weak ping delay. |
1159 int ping_delay = weak() ? WEAK_PING_DELAY : STRONG_PING_DELAY; | 1165 int ping_delay = weak() ? weak_ping_delay_ : STRONG_PING_DELAY; |
1160 if (rtc::Time() >= last_ping_sent_ms_ + ping_delay) { | 1166 if (rtc::Time() >= last_ping_sent_ms_ + ping_delay) { |
1161 Connection* conn = FindNextPingableConnection(); | 1167 Connection* conn = FindNextPingableConnection(); |
1162 if (conn) { | 1168 if (conn) { |
1163 PingConnection(conn); | 1169 PingConnection(conn); |
1164 } | 1170 } |
1165 } | 1171 } |
1166 int check_delay = std::min(ping_delay, check_receiving_delay_); | 1172 int check_delay = std::min(ping_delay, check_receiving_delay_); |
1167 thread()->PostDelayed(check_delay, this, MSG_CHECK_AND_PING); | 1173 thread()->PostDelayed(check_delay, this, MSG_CHECK_AND_PING); |
1168 } | 1174 } |
1169 | 1175 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1356 } | 1362 } |
1357 } | 1363 } |
1358 | 1364 |
1359 void P2PTransportChannel::OnReadyToSend(Connection* connection) { | 1365 void P2PTransportChannel::OnReadyToSend(Connection* connection) { |
1360 if (connection == best_connection_ && writable()) { | 1366 if (connection == best_connection_ && writable()) { |
1361 SignalReadyToSend(this); | 1367 SignalReadyToSend(this); |
1362 } | 1368 } |
1363 } | 1369 } |
1364 | 1370 |
1365 } // namespace cricket | 1371 } // namespace cricket |
OLD | NEW |