| 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 bool PeerConnection::Initialize( | 621 bool PeerConnection::Initialize( |
| 588 const PeerConnectionInterface::RTCConfiguration& configuration, | 622 const PeerConnectionInterface::RTCConfiguration& configuration, |
| 589 const MediaConstraintsInterface* constraints, | 623 const MediaConstraintsInterface* constraints, |
| 590 PortAllocatorFactoryInterface* allocator_factory, | 624 PortAllocatorFactoryInterface* allocator_factory, |
| 591 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 625 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 592 PeerConnectionObserver* observer) { | 626 PeerConnectionObserver* observer) { |
| 593 RTC_DCHECK(observer != nullptr); | 627 RTC_DCHECK(observer != nullptr); |
| 594 if (!observer) { | 628 if (!observer) { |
| 595 return false; | 629 return false; |
| 596 } | 630 } |
| 631 |
| 632 // This Initialize function parses ICE servers an extra time, but it will |
| 633 // be removed once all PortAllocaotrs support SetIceServers. |
| 634 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config; |
| 635 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config; |
| 636 if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) { |
| 637 return false; |
| 638 } |
| 639 rtc::scoped_ptr<cricket::PortAllocator> allocator( |
| 640 allocator_factory->CreatePortAllocator(stun_config, turn_config)); |
| 641 return Initialize(configuration, constraints, allocator.Pass(), |
| 642 dtls_identity_store.Pass(), observer); |
| 643 } |
| 644 |
| 645 bool PeerConnection::Initialize( |
| 646 const PeerConnectionInterface::RTCConfiguration& configuration, |
| 647 const MediaConstraintsInterface* constraints, |
| 648 rtc::scoped_ptr<cricket::PortAllocator> allocator, |
| 649 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 650 PeerConnectionObserver* observer) { |
| 651 RTC_DCHECK(observer != nullptr); |
| 652 if (!observer) { |
| 653 return false; |
| 654 } |
| 597 observer_ = observer; | 655 observer_ = observer; |
| 598 | 656 |
| 657 port_allocator_ = allocator.Pass(); |
| 658 |
| 599 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config; | 659 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config; |
| 600 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config; | 660 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config; |
| 601 if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) { | 661 if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) { |
| 602 return false; | 662 return false; |
| 603 } | 663 } |
| 604 port_allocator_.reset( | 664 |
| 605 allocator_factory->CreatePortAllocator(stun_config, turn_config)); | 665 cricket::ServerAddresses cricket_stuns; |
| 666 std::vector<cricket::RelayServerConfig> cricket_turns; |
| 667 ConvertToCricketIceServers(stun_config, turn_config, &cricket_stuns, |
| 668 &cricket_turns); |
| 669 port_allocator_->SetIceServers(cricket_stuns, cricket_turns); |
| 606 | 670 |
| 607 // To handle both internal and externally created port allocator, we will | 671 // To handle both internal and externally created port allocator, we will |
| 608 // enable BUNDLE here. | 672 // enable BUNDLE here. |
| 609 int portallocator_flags = port_allocator_->flags(); | 673 int portallocator_flags = port_allocator_->flags(); |
| 610 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 674 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 611 cricket::PORTALLOCATOR_ENABLE_IPV6; | 675 cricket::PORTALLOCATOR_ENABLE_IPV6; |
| 612 bool value; | 676 bool value; |
| 613 // If IPv6 flag was specified, we'll not override it by experiment. | 677 // If IPv6 flag was specified, we'll not override it by experiment. |
| 614 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, | 678 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, |
| 615 &value, nullptr)) { | 679 &value, nullptr)) { |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 } | 1148 } |
| 1085 | 1149 |
| 1086 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { | 1150 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { |
| 1087 if (port_allocator_) { | 1151 if (port_allocator_) { |
| 1088 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stuns; | 1152 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stuns; |
| 1089 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turns; | 1153 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turns; |
| 1090 if (!ParseIceServers(config.servers, &stuns, &turns)) { | 1154 if (!ParseIceServers(config.servers, &stuns, &turns)) { |
| 1091 return false; | 1155 return false; |
| 1092 } | 1156 } |
| 1093 | 1157 |
| 1094 std::vector<rtc::SocketAddress> stun_hosts; | 1158 cricket::ServerAddresses cricket_stuns; |
| 1095 typedef std::vector<StunConfiguration>::const_iterator StunIt; | 1159 std::vector<cricket::RelayServerConfig> cricket_turns; |
| 1096 for (StunIt stun_it = stuns.begin(); stun_it != stuns.end(); ++stun_it) { | 1160 ConvertToCricketIceServers(stuns, turns, &cricket_stuns, &cricket_turns); |
| 1097 stun_hosts.push_back(stun_it->server); | 1161 port_allocator_->SetIceServers(cricket_stuns, cricket_turns); |
| 1098 } | |
| 1099 | |
| 1100 rtc::SocketAddress stun_addr; | |
| 1101 if (!stun_hosts.empty()) { | |
| 1102 stun_addr = stun_hosts.front(); | |
| 1103 LOG(LS_INFO) << "SetConfiguration: StunServer Address: " | |
| 1104 << stun_addr.ToString(); | |
| 1105 } | |
| 1106 | |
| 1107 for (size_t i = 0; i < turns.size(); ++i) { | |
| 1108 cricket::RelayCredentials credentials(turns[i].username, | |
| 1109 turns[i].password); | |
| 1110 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); | |
| 1111 cricket::ProtocolType protocol; | |
| 1112 if (cricket::StringToProto(turns[i].transport_type.c_str(), &protocol)) { | |
| 1113 relay_server.ports.push_back(cricket::ProtocolAddress( | |
| 1114 turns[i].server, protocol, turns[i].secure)); | |
| 1115 relay_server.credentials = credentials; | |
| 1116 LOG(LS_INFO) << "SetConfiguration: TurnServer Address: " | |
| 1117 << turns[i].server.ToString(); | |
| 1118 } else { | |
| 1119 LOG(LS_WARNING) << "Ignoring TURN server " << turns[i].server << ". " | |
| 1120 << "Reason= Incorrect " << turns[i].transport_type | |
| 1121 << " transport parameter."; | |
| 1122 } | |
| 1123 } | |
| 1124 } | 1162 } |
| 1125 session_->SetIceConfig(session_->ParseIceConfig(config)); | 1163 session_->SetIceConfig(session_->ParseIceConfig(config)); |
| 1126 return session_->SetIceTransports(config.type); | 1164 return session_->SetIceTransports(config.type); |
| 1127 } | 1165 } |
| 1128 | 1166 |
| 1129 bool PeerConnection::AddIceCandidate( | 1167 bool PeerConnection::AddIceCandidate( |
| 1130 const IceCandidateInterface* ice_candidate) { | 1168 const IceCandidateInterface* ice_candidate) { |
| 1131 return session_->ProcessIceMessage(ice_candidate); | 1169 return session_->ProcessIceMessage(ice_candidate); |
| 1132 } | 1170 } |
| 1133 | 1171 |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1951 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { | 1989 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
| 1952 for (const auto& channel : sctp_data_channels_) { | 1990 for (const auto& channel : sctp_data_channels_) { |
| 1953 if (channel->id() == sid) { | 1991 if (channel->id() == sid) { |
| 1954 return channel; | 1992 return channel; |
| 1955 } | 1993 } |
| 1956 } | 1994 } |
| 1957 return nullptr; | 1995 return nullptr; |
| 1958 } | 1996 } |
| 1959 | 1997 |
| 1960 } // namespace webrtc | 1998 } // namespace webrtc |
| OLD | NEW |