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/transport.h" | 11 #include "webrtc/p2p/base/transport.h" |
12 | 12 |
13 #include "webrtc/p2p/base/candidate.h" | 13 #include "webrtc/p2p/base/candidate.h" |
14 #include "webrtc/p2p/base/constants.h" | 14 #include "webrtc/p2p/base/constants.h" |
15 #include "webrtc/p2p/base/port.h" | 15 #include "webrtc/p2p/base/port.h" |
16 #include "webrtc/p2p/base/transportchannelimpl.h" | 16 #include "webrtc/p2p/base/transportchannelimpl.h" |
17 #include "webrtc/base/bind.h" | 17 #include "webrtc/base/bind.h" |
18 #include "webrtc/base/common.h" | 18 #include "webrtc/base/common.h" |
19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
20 | 20 |
21 namespace cricket { | 21 namespace cricket { |
22 | 22 |
23 using rtc::Bind; | 23 using rtc::Bind; |
24 | 24 |
25 enum { | 25 enum { |
26 MSG_ONSIGNALINGREADY = 1, | 26 MSG_ONSIGNALINGREADY = 1, |
27 MSG_ONREMOTECANDIDATE, | 27 MSG_ONREMOTECANDIDATE, |
| 28 MSG_READSTATE, |
28 MSG_WRITESTATE, | 29 MSG_WRITESTATE, |
29 MSG_REQUESTSIGNALING, | 30 MSG_REQUESTSIGNALING, |
30 MSG_CANDIDATEREADY, | 31 MSG_CANDIDATEREADY, |
31 MSG_ROUTECHANGE, | 32 MSG_ROUTECHANGE, |
32 MSG_CONNECTING, | 33 MSG_CONNECTING, |
33 MSG_CANDIDATEALLOCATIONCOMPLETE, | 34 MSG_CANDIDATEALLOCATIONCOMPLETE, |
34 MSG_ROLECONFLICT, | 35 MSG_ROLECONFLICT, |
35 MSG_COMPLETED, | 36 MSG_COMPLETED, |
36 MSG_FAILED, | 37 MSG_FAILED, |
37 MSG_RECEIVINGSTATE, | 38 MSG_RECEIVINGSTATE, |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 impl->SetReceivingTimeout(channel_receiving_timeout_); | 231 impl->SetReceivingTimeout(channel_receiving_timeout_); |
231 // TODO(ronghuawu): Change CreateChannel_w to be able to return error since | 232 // TODO(ronghuawu): Change CreateChannel_w to be able to return error since |
232 // below Apply**Description_w calls can fail. | 233 // below Apply**Description_w calls can fail. |
233 if (local_description_) | 234 if (local_description_) |
234 ApplyLocalTransportDescription_w(impl, NULL); | 235 ApplyLocalTransportDescription_w(impl, NULL); |
235 if (remote_description_) | 236 if (remote_description_) |
236 ApplyRemoteTransportDescription_w(impl, NULL); | 237 ApplyRemoteTransportDescription_w(impl, NULL); |
237 if (local_description_ && remote_description_) | 238 if (local_description_ && remote_description_) |
238 ApplyNegotiatedTransportDescription_w(impl, NULL); | 239 ApplyNegotiatedTransportDescription_w(impl, NULL); |
239 | 240 |
| 241 impl->SignalReadableState.connect(this, &Transport::OnChannelReadableState); |
240 impl->SignalWritableState.connect(this, &Transport::OnChannelWritableState); | 242 impl->SignalWritableState.connect(this, &Transport::OnChannelWritableState); |
241 impl->SignalReceivingState.connect(this, &Transport::OnChannelReceivingState); | 243 impl->SignalReceivingState.connect(this, &Transport::OnChannelReceivingState); |
242 impl->SignalRequestSignaling.connect( | 244 impl->SignalRequestSignaling.connect( |
243 this, &Transport::OnChannelRequestSignaling); | 245 this, &Transport::OnChannelRequestSignaling); |
244 impl->SignalCandidateReady.connect(this, &Transport::OnChannelCandidateReady); | 246 impl->SignalCandidateReady.connect(this, &Transport::OnChannelCandidateReady); |
245 impl->SignalRouteChange.connect(this, &Transport::OnChannelRouteChange); | 247 impl->SignalRouteChange.connect(this, &Transport::OnChannelRouteChange); |
246 impl->SignalCandidatesAllocationDone.connect( | 248 impl->SignalCandidatesAllocationDone.connect( |
247 this, &Transport::OnChannelCandidatesAllocationDone); | 249 this, &Transport::OnChannelCandidatesAllocationDone); |
248 impl->SignalRoleConflict.connect(this, &Transport::OnRoleConflict); | 250 impl->SignalRoleConflict.connect(this, &Transport::OnRoleConflict); |
249 impl->SignalConnectionRemoved.connect( | 251 impl->SignalConnectionRemoved.connect( |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 486 |
485 void Transport::OnRemoteCandidate_w(const Candidate& candidate) { | 487 void Transport::OnRemoteCandidate_w(const Candidate& candidate) { |
486 ASSERT(worker_thread()->IsCurrent()); | 488 ASSERT(worker_thread()->IsCurrent()); |
487 ChannelMap::iterator iter = channels_.find(candidate.component()); | 489 ChannelMap::iterator iter = channels_.find(candidate.component()); |
488 // It's ok for a channel to go away while this message is in transit. | 490 // It's ok for a channel to go away while this message is in transit. |
489 if (iter != channels_.end()) { | 491 if (iter != channels_.end()) { |
490 iter->second->OnCandidate(candidate); | 492 iter->second->OnCandidate(candidate); |
491 } | 493 } |
492 } | 494 } |
493 | 495 |
| 496 void Transport::OnChannelReadableState(TransportChannel* channel) { |
| 497 ASSERT(worker_thread()->IsCurrent()); |
| 498 signaling_thread()->Post(this, MSG_READSTATE, NULL); |
| 499 } |
| 500 |
| 501 void Transport::OnChannelReadableState_s() { |
| 502 ASSERT(signaling_thread()->IsCurrent()); |
| 503 TransportState readable = GetTransportState_s(TRANSPORT_READABLE_STATE); |
| 504 if (readable_ != readable) { |
| 505 readable_ = readable; |
| 506 SignalReadableState(this); |
| 507 } |
| 508 } |
| 509 |
494 void Transport::OnChannelWritableState(TransportChannel* channel) { | 510 void Transport::OnChannelWritableState(TransportChannel* channel) { |
495 ASSERT(worker_thread()->IsCurrent()); | 511 ASSERT(worker_thread()->IsCurrent()); |
496 signaling_thread()->Post(this, MSG_WRITESTATE, NULL); | 512 signaling_thread()->Post(this, MSG_WRITESTATE, NULL); |
497 | 513 |
498 MaybeCompleted_w(); | 514 MaybeCompleted_w(); |
499 } | 515 } |
500 | 516 |
501 void Transport::OnChannelWritableState_s() { | 517 void Transport::OnChannelWritableState_s() { |
502 ASSERT(signaling_thread()->IsCurrent()); | 518 ASSERT(signaling_thread()->IsCurrent()); |
503 TransportState writable = GetTransportState_s(TRANSPORT_WRITABLE_STATE); | 519 TransportState writable = GetTransportState_s(TRANSPORT_WRITABLE_STATE); |
(...skipping 20 matching lines...) Expand all Loading... |
524 | 540 |
525 TransportState Transport::GetTransportState_s(TransportStateType state_type) { | 541 TransportState Transport::GetTransportState_s(TransportStateType state_type) { |
526 ASSERT(signaling_thread()->IsCurrent()); | 542 ASSERT(signaling_thread()->IsCurrent()); |
527 | 543 |
528 rtc::CritScope cs(&crit_); | 544 rtc::CritScope cs(&crit_); |
529 bool any = false; | 545 bool any = false; |
530 bool all = !channels_.empty(); | 546 bool all = !channels_.empty(); |
531 for (const auto iter : channels_) { | 547 for (const auto iter : channels_) { |
532 bool b = false; | 548 bool b = false; |
533 switch (state_type) { | 549 switch (state_type) { |
| 550 case TRANSPORT_READABLE_STATE: |
| 551 b = iter.second->readable(); |
| 552 break; |
534 case TRANSPORT_WRITABLE_STATE: | 553 case TRANSPORT_WRITABLE_STATE: |
535 b = iter.second->writable(); | 554 b = iter.second->writable(); |
536 break; | 555 break; |
537 case TRANSPORT_RECEIVING_STATE: | 556 case TRANSPORT_RECEIVING_STATE: |
538 b = iter.second->receiving(); | 557 b = iter.second->receiving(); |
539 break; | 558 break; |
540 default: | 559 default: |
541 ASSERT(false); | 560 ASSERT(false); |
542 } | 561 } |
543 any |= b; | 562 any |= b; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 break; | 863 break; |
845 case MSG_ONREMOTECANDIDATE: { | 864 case MSG_ONREMOTECANDIDATE: { |
846 ChannelParams* params = static_cast<ChannelParams*>(msg->pdata); | 865 ChannelParams* params = static_cast<ChannelParams*>(msg->pdata); |
847 OnRemoteCandidate_w(*params->candidate); | 866 OnRemoteCandidate_w(*params->candidate); |
848 delete params; | 867 delete params; |
849 } | 868 } |
850 break; | 869 break; |
851 case MSG_CONNECTING: | 870 case MSG_CONNECTING: |
852 OnConnecting_s(); | 871 OnConnecting_s(); |
853 break; | 872 break; |
| 873 case MSG_READSTATE: |
| 874 OnChannelReadableState_s(); |
| 875 break; |
854 case MSG_WRITESTATE: | 876 case MSG_WRITESTATE: |
855 OnChannelWritableState_s(); | 877 OnChannelWritableState_s(); |
856 break; | 878 break; |
857 case MSG_RECEIVINGSTATE: | 879 case MSG_RECEIVINGSTATE: |
858 OnChannelReceivingState_s(); | 880 OnChannelReceivingState_s(); |
859 break; | 881 break; |
860 case MSG_REQUESTSIGNALING: | 882 case MSG_REQUESTSIGNALING: |
861 OnChannelRequestSignaling_s(); | 883 OnChannelRequestSignaling_s(); |
862 break; | 884 break; |
863 case MSG_CANDIDATEREADY: | 885 case MSG_CANDIDATEREADY: |
(...skipping 14 matching lines...) Expand all Loading... |
878 case MSG_COMPLETED: | 900 case MSG_COMPLETED: |
879 SignalCompleted(this); | 901 SignalCompleted(this); |
880 break; | 902 break; |
881 case MSG_FAILED: | 903 case MSG_FAILED: |
882 SignalFailed(this); | 904 SignalFailed(this); |
883 break; | 905 break; |
884 } | 906 } |
885 } | 907 } |
886 | 908 |
887 } // namespace cricket | 909 } // namespace cricket |
OLD | NEW |