OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 break; | 323 break; |
324 } | 324 } |
325 case INVALID: | 325 case INVALID: |
326 default: | 326 default: |
327 LOG(WARNING) << "Configuration not supported: " << url; | 327 LOG(WARNING) << "Configuration not supported: " << url; |
328 return false; | 328 return false; |
329 } | 329 } |
330 return true; | 330 return true; |
331 } | 331 } |
332 | 332 |
| 333 void ConvertToCricketIceServers( |
| 334 const std::vector<StunConfiguration>& stuns, |
| 335 const std::vector<TurnConfiguration>& turns, |
| 336 cricket::ServerAddresses* cricket_stuns, |
| 337 std::vector<cricket::RelayServerConfig>* cricket_turns) { |
| 338 RTC_DCHECK(cricket_stuns && cricket_turns); |
| 339 for (const StunConfiguration& stun : stuns) { |
| 340 cricket_stuns->insert(stun.server); |
| 341 } |
| 342 |
| 343 int priority = static_cast<int>(turns.size() - 1); |
| 344 for (const TurnConfiguration& turn : turns) { |
| 345 cricket::RelayCredentials credentials(turn.username, turn.password); |
| 346 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); |
| 347 cricket::ProtocolType protocol; |
| 348 // Using VERIFY because ParseIceServers should have already caught an |
| 349 // invalid transport type. |
| 350 if (!VERIFY( |
| 351 cricket::StringToProto(turn.transport_type.c_str(), &protocol))) { |
| 352 LOG(LS_WARNING) << "Ignoring TURN server " << turn.server << ". " |
| 353 << "Reason= Incorrect " << turn.transport_type |
| 354 << " transport parameter."; |
| 355 } else { |
| 356 relay_server.ports.push_back( |
| 357 cricket::ProtocolAddress(turn.server, protocol, turn.secure)); |
| 358 relay_server.credentials = credentials; |
| 359 relay_server.priority = priority; |
| 360 cricket_turns->push_back(relay_server); |
| 361 } |
| 362 // First in the list gets highest priority. |
| 363 --priority; |
| 364 } |
| 365 } |
| 366 |
333 // Check if we can send |new_stream| on a PeerConnection. | 367 // Check if we can send |new_stream| on a PeerConnection. |
334 bool CanAddLocalMediaStream(webrtc::StreamCollectionInterface* current_streams, | 368 bool CanAddLocalMediaStream(webrtc::StreamCollectionInterface* current_streams, |
335 webrtc::MediaStreamInterface* new_stream) { | 369 webrtc::MediaStreamInterface* new_stream) { |
336 if (!new_stream || !current_streams) { | 370 if (!new_stream || !current_streams) { |
337 return false; | 371 return false; |
338 } | 372 } |
339 if (current_streams->find(new_stream->label()) != nullptr) { | 373 if (current_streams->find(new_stream->label()) != nullptr) { |
340 LOG(LS_ERROR) << "MediaStream with label " << new_stream->label() | 374 LOG(LS_ERROR) << "MediaStream with label " << new_stream->label() |
341 << " is already added."; | 375 << " is already added."; |
342 return false; | 376 return false; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 bool PeerConnection::Initialize( | 616 bool PeerConnection::Initialize( |
583 const PeerConnectionInterface::RTCConfiguration& configuration, | 617 const PeerConnectionInterface::RTCConfiguration& configuration, |
584 const MediaConstraintsInterface* constraints, | 618 const MediaConstraintsInterface* constraints, |
585 PortAllocatorFactoryInterface* allocator_factory, | 619 PortAllocatorFactoryInterface* allocator_factory, |
586 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 620 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
587 PeerConnectionObserver* observer) { | 621 PeerConnectionObserver* observer) { |
588 RTC_DCHECK(observer != nullptr); | 622 RTC_DCHECK(observer != nullptr); |
589 if (!observer) { | 623 if (!observer) { |
590 return false; | 624 return false; |
591 } | 625 } |
| 626 |
| 627 // This Initialize function parses ICE servers an extra time, but it will |
| 628 // be removed once all PortAllocaotrs support SetIceServers. |
| 629 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config; |
| 630 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config; |
| 631 if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) { |
| 632 return false; |
| 633 } |
| 634 rtc::scoped_ptr<cricket::PortAllocator> allocator( |
| 635 allocator_factory->CreatePortAllocator(stun_config, turn_config)); |
| 636 return Initialize(configuration, constraints, allocator.Pass(), |
| 637 dtls_identity_store.Pass(), observer); |
| 638 } |
| 639 |
| 640 bool PeerConnection::Initialize( |
| 641 const PeerConnectionInterface::RTCConfiguration& configuration, |
| 642 const MediaConstraintsInterface* constraints, |
| 643 rtc::scoped_ptr<cricket::PortAllocator> allocator, |
| 644 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 645 PeerConnectionObserver* observer) { |
| 646 RTC_DCHECK(observer != nullptr); |
| 647 if (!observer) { |
| 648 return false; |
| 649 } |
592 observer_ = observer; | 650 observer_ = observer; |
593 | 651 |
| 652 port_allocator_ = allocator.Pass(); |
| 653 |
594 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config; | 654 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config; |
595 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config; | 655 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config; |
596 if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) { | 656 if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) { |
597 return false; | 657 return false; |
598 } | 658 } |
599 port_allocator_.reset( | 659 |
600 allocator_factory->CreatePortAllocator(stun_config, turn_config)); | 660 cricket::ServerAddresses cricket_stuns; |
| 661 std::vector<cricket::RelayServerConfig> cricket_turns; |
| 662 ConvertToCricketIceServers(stun_config, turn_config, &cricket_stuns, |
| 663 &cricket_turns); |
| 664 port_allocator_->SetIceServers(cricket_stuns, cricket_turns); |
601 | 665 |
602 // To handle both internal and externally created port allocator, we will | 666 // To handle both internal and externally created port allocator, we will |
603 // enable BUNDLE here. | 667 // enable BUNDLE here. |
604 int portallocator_flags = port_allocator_->flags(); | 668 int portallocator_flags = port_allocator_->flags(); |
605 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 669 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
606 cricket::PORTALLOCATOR_ENABLE_IPV6; | 670 cricket::PORTALLOCATOR_ENABLE_IPV6; |
607 bool value; | 671 bool value; |
608 // If IPv6 flag was specified, we'll not override it by experiment. | 672 // If IPv6 flag was specified, we'll not override it by experiment. |
609 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, | 673 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, |
610 &value, nullptr)) { | 674 &value, nullptr)) { |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 } | 1143 } |
1080 | 1144 |
1081 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { | 1145 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { |
1082 if (port_allocator_) { | 1146 if (port_allocator_) { |
1083 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stuns; | 1147 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stuns; |
1084 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turns; | 1148 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turns; |
1085 if (!ParseIceServers(config.servers, &stuns, &turns)) { | 1149 if (!ParseIceServers(config.servers, &stuns, &turns)) { |
1086 return false; | 1150 return false; |
1087 } | 1151 } |
1088 | 1152 |
1089 std::vector<rtc::SocketAddress> stun_hosts; | 1153 cricket::ServerAddresses cricket_stuns; |
1090 typedef std::vector<StunConfiguration>::const_iterator StunIt; | 1154 std::vector<cricket::RelayServerConfig> cricket_turns; |
1091 for (StunIt stun_it = stuns.begin(); stun_it != stuns.end(); ++stun_it) { | 1155 ConvertToCricketIceServers(stuns, turns, &cricket_stuns, &cricket_turns); |
1092 stun_hosts.push_back(stun_it->server); | 1156 port_allocator_->SetIceServers(cricket_stuns, cricket_turns); |
1093 } | |
1094 | |
1095 rtc::SocketAddress stun_addr; | |
1096 if (!stun_hosts.empty()) { | |
1097 stun_addr = stun_hosts.front(); | |
1098 LOG(LS_INFO) << "SetConfiguration: StunServer Address: " | |
1099 << stun_addr.ToString(); | |
1100 } | |
1101 | |
1102 for (size_t i = 0; i < turns.size(); ++i) { | |
1103 cricket::RelayCredentials credentials(turns[i].username, | |
1104 turns[i].password); | |
1105 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); | |
1106 cricket::ProtocolType protocol; | |
1107 if (cricket::StringToProto(turns[i].transport_type.c_str(), &protocol)) { | |
1108 relay_server.ports.push_back(cricket::ProtocolAddress( | |
1109 turns[i].server, protocol, turns[i].secure)); | |
1110 relay_server.credentials = credentials; | |
1111 LOG(LS_INFO) << "SetConfiguration: TurnServer Address: " | |
1112 << turns[i].server.ToString(); | |
1113 } else { | |
1114 LOG(LS_WARNING) << "Ignoring TURN server " << turns[i].server << ". " | |
1115 << "Reason= Incorrect " << turns[i].transport_type | |
1116 << " transport parameter."; | |
1117 } | |
1118 } | |
1119 } | 1157 } |
1120 session_->SetIceConfig(session_->ParseIceConfig(config)); | 1158 session_->SetIceConfig(session_->ParseIceConfig(config)); |
1121 return session_->SetIceTransports(config.type); | 1159 return session_->SetIceTransports(config.type); |
1122 } | 1160 } |
1123 | 1161 |
1124 bool PeerConnection::AddIceCandidate( | 1162 bool PeerConnection::AddIceCandidate( |
1125 const IceCandidateInterface* ice_candidate) { | 1163 const IceCandidateInterface* ice_candidate) { |
1126 return session_->ProcessIceMessage(ice_candidate); | 1164 return session_->ProcessIceMessage(ice_candidate); |
1127 } | 1165 } |
1128 | 1166 |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1966 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { | 2004 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
1967 for (const auto& channel : sctp_data_channels_) { | 2005 for (const auto& channel : sctp_data_channels_) { |
1968 if (channel->id() == sid) { | 2006 if (channel->id() == sid) { |
1969 return channel; | 2007 return channel; |
1970 } | 2008 } |
1971 } | 2009 } |
1972 return nullptr; | 2010 return nullptr; |
1973 } | 2011 } |
1974 | 2012 |
1975 } // namespace webrtc | 2013 } // namespace webrtc |
OLD | NEW |