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 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // ii) For controlled side, | 184 // ii) For controlled side, |
185 // a) nomination state, | 185 // a) nomination state, |
186 // b) last data received time. | 186 // b) last data received time. |
187 // iii) Lower cost / higher priority. | 187 // iii) Lower cost / higher priority. |
188 // iv) rtt. | 188 // iv) rtt. |
189 // TODO(honghaiz): Stop the aggressive nomination on the controlling side and | 189 // TODO(honghaiz): Stop the aggressive nomination on the controlling side and |
190 // implement the ice-renomination option. | 190 // implement the ice-renomination option. |
191 bool P2PTransportChannel::ShouldSwitchSelectedConnection( | 191 bool P2PTransportChannel::ShouldSwitchSelectedConnection( |
192 Connection* new_connection, | 192 Connection* new_connection, |
193 bool* missed_receiving_unchanged_threshold) const { | 193 bool* missed_receiving_unchanged_threshold) const { |
194 if (!new_connection || selected_connection_ == new_connection) { | 194 if (!ReadyToSend(new_connection) || selected_connection_ == new_connection) { |
195 return false; | 195 return false; |
196 } | 196 } |
197 | 197 |
198 if (selected_connection_ == nullptr) { | 198 if (selected_connection_ == nullptr) { |
199 return true; | 199 return true; |
200 } | 200 } |
201 | 201 |
202 rtc::Optional<int64_t> receiving_unchanged_threshold( | 202 rtc::Optional<int64_t> receiving_unchanged_threshold( |
203 rtc::TimeMillis() - config_.receiving_switching_delay.value_or(0)); | 203 rtc::TimeMillis() - config_.receiving_switching_delay.value_or(0)); |
204 int cmp = CompareConnections(selected_connection_, new_connection, | 204 int cmp = CompareConnections(selected_connection_, new_connection, |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 int P2PTransportChannel::SendPacket(const char *data, size_t len, | 933 int P2PTransportChannel::SendPacket(const char *data, size_t len, |
934 const rtc::PacketOptions& options, | 934 const rtc::PacketOptions& options, |
935 int flags) { | 935 int flags) { |
936 ASSERT(worker_thread_ == rtc::Thread::Current()); | 936 ASSERT(worker_thread_ == rtc::Thread::Current()); |
937 if (flags != 0) { | 937 if (flags != 0) { |
938 error_ = EINVAL; | 938 error_ = EINVAL; |
939 return -1; | 939 return -1; |
940 } | 940 } |
941 // If we don't think the connection is working yet, return ENOTCONN | 941 // If we don't think the connection is working yet, return ENOTCONN |
942 // instead of sending a packet that will probably be dropped. | 942 // instead of sending a packet that will probably be dropped. |
943 if (!ReadyToSend()) { | 943 if (!ReadyToSend(selected_connection_)) { |
944 error_ = ENOTCONN; | 944 error_ = ENOTCONN; |
945 return -1; | 945 return -1; |
946 } | 946 } |
947 | 947 |
948 last_sent_packet_id_ = options.packet_id; | 948 last_sent_packet_id_ = options.packet_id; |
949 int sent = selected_connection_->Send(data, len, options); | 949 int sent = selected_connection_->Send(data, len, options); |
950 if (sent <= 0) { | 950 if (sent <= 0) { |
951 ASSERT(sent < 0); | 951 ASSERT(sent < 0); |
952 error_ = selected_connection_->GetError(); | 952 error_ = selected_connection_->GetError(); |
953 } | 953 } |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 // send; then it will only signal ready-to-send if the media channel | 1308 // send; then it will only signal ready-to-send if the media channel |
1309 // has been disallowed to send. | 1309 // has been disallowed to send. |
1310 if (selected_connection_->writable() || | 1310 if (selected_connection_->writable() || |
1311 PresumedWritable(selected_connection_)) { | 1311 PresumedWritable(selected_connection_)) { |
1312 SignalReadyToSend(this); | 1312 SignalReadyToSend(this); |
1313 } | 1313 } |
1314 } else { | 1314 } else { |
1315 LOG_J(LS_INFO, this) << "No selected connection"; | 1315 LOG_J(LS_INFO, this) << "No selected connection"; |
1316 } | 1316 } |
1317 SignalSelectedCandidatePairChanged(this, selected_connection_, | 1317 SignalSelectedCandidatePairChanged(this, selected_connection_, |
1318 last_sent_packet_id_, ReadyToSend()); | 1318 last_sent_packet_id_, |
| 1319 ReadyToSend(selected_connection_)); |
1319 } | 1320 } |
1320 | 1321 |
1321 // Warning: UpdateState should eventually be called whenever a connection | 1322 // Warning: UpdateState should eventually be called whenever a connection |
1322 // is added, deleted, or the write state of any connection changes so that the | 1323 // is added, deleted, or the write state of any connection changes so that the |
1323 // transport controller will get the up-to-date channel state. However it | 1324 // transport controller will get the up-to-date channel state. However it |
1324 // should not be called too often; in the case that multiple connection states | 1325 // should not be called too often; in the case that multiple connection states |
1325 // change, it should be called after all the connection states have changed. For | 1326 // change, it should be called after all the connection states have changed. For |
1326 // example, we call this at the end of SortConnectionsAndUpdateState. | 1327 // example, we call this at the end of SortConnectionsAndUpdateState. |
1327 void P2PTransportChannel::UpdateState() { | 1328 void P2PTransportChannel::UpdateState() { |
1328 TransportChannelState state = ComputeState(); | 1329 TransportChannelState state = ComputeState(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 void P2PTransportChannel::HandleAllTimedOut() { | 1403 void P2PTransportChannel::HandleAllTimedOut() { |
1403 for (Connection* connection : connections_) { | 1404 for (Connection* connection : connections_) { |
1404 connection->Destroy(); | 1405 connection->Destroy(); |
1405 } | 1406 } |
1406 } | 1407 } |
1407 | 1408 |
1408 bool P2PTransportChannel::weak() const { | 1409 bool P2PTransportChannel::weak() const { |
1409 return !selected_connection_ || selected_connection_->weak(); | 1410 return !selected_connection_ || selected_connection_->weak(); |
1410 } | 1411 } |
1411 | 1412 |
1412 bool P2PTransportChannel::ReadyToSend() const { | 1413 bool P2PTransportChannel::ReadyToSend(Connection* connection) const { |
1413 // Note that we allow sending on an unreliable connection, because it's | 1414 // Note that we allow sending on an unreliable connection, because it's |
1414 // possible that it became unreliable simply due to bad chance. | 1415 // possible that it became unreliable simply due to bad chance. |
1415 // So this shouldn't prevent attempting to send media. | 1416 // So this shouldn't prevent attempting to send media. |
1416 return selected_connection_ != nullptr && | 1417 return connection != nullptr && |
1417 (selected_connection_->writable() || | 1418 (connection->writable() || |
1418 PresumedWritable(selected_connection_) || | 1419 connection->write_state() == Connection::STATE_WRITE_UNRELIABLE || |
1419 selected_connection_->write_state() == | 1420 PresumedWritable(connection)); |
1420 Connection::STATE_WRITE_UNRELIABLE); | |
1421 } | 1421 } |
1422 | 1422 |
1423 // If we have a selected connection, return it, otherwise return top one in the | 1423 // If we have a selected connection, return it, otherwise return top one in the |
1424 // list (later we will mark it best). | 1424 // list (later we will mark it best). |
1425 Connection* P2PTransportChannel::GetBestConnectionOnNetwork( | 1425 Connection* P2PTransportChannel::GetBestConnectionOnNetwork( |
1426 rtc::Network* network) const { | 1426 rtc::Network* network) const { |
1427 // If the selected connection is on this network, then it wins. | 1427 // If the selected connection is on this network, then it wins. |
1428 if (selected_connection_ && | 1428 if (selected_connection_ && |
1429 (selected_connection_->port()->Network() == network)) { | 1429 (selected_connection_->port()->Network() == network)) { |
1430 return selected_connection_; | 1430 return selected_connection_; |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1932 | 1932 |
1933 // During the initial state when nothing has been pinged yet, return the first | 1933 // During the initial state when nothing has been pinged yet, return the first |
1934 // one in the ordered |connections_|. | 1934 // one in the ordered |connections_|. |
1935 return *(std::find_if(connections_.begin(), connections_.end(), | 1935 return *(std::find_if(connections_.begin(), connections_.end(), |
1936 [conn1, conn2](Connection* conn) { | 1936 [conn1, conn2](Connection* conn) { |
1937 return conn == conn1 || conn == conn2; | 1937 return conn == conn1 || conn == conn2; |
1938 })); | 1938 })); |
1939 } | 1939 } |
1940 | 1940 |
1941 } // namespace cricket | 1941 } // namespace cricket |
OLD | NEW |