Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: talk/app/webrtc/peerconnection.cc

Issue 1424803004: Revert of Adding the ability to change ICE servers through SetConfiguration. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/app/webrtc/peerconnection.h ('k') | talk/app/webrtc/peerconnectioninterface_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
367 // Check if we can send |new_stream| on a PeerConnection. 333 // Check if we can send |new_stream| on a PeerConnection.
368 bool CanAddLocalMediaStream(webrtc::StreamCollectionInterface* current_streams, 334 bool CanAddLocalMediaStream(webrtc::StreamCollectionInterface* current_streams,
369 webrtc::MediaStreamInterface* new_stream) { 335 webrtc::MediaStreamInterface* new_stream) {
370 if (!new_stream || !current_streams) { 336 if (!new_stream || !current_streams) {
371 return false; 337 return false;
372 } 338 }
373 if (current_streams->find(new_stream->label()) != nullptr) { 339 if (current_streams->find(new_stream->label()) != nullptr) {
374 LOG(LS_ERROR) << "MediaStream with label " << new_stream->label() 340 LOG(LS_ERROR) << "MediaStream with label " << new_stream->label()
375 << " is already added."; 341 << " is already added.";
376 return false; 342 return false;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 bool PeerConnection::Initialize( 582 bool PeerConnection::Initialize(
617 const PeerConnectionInterface::RTCConfiguration& configuration, 583 const PeerConnectionInterface::RTCConfiguration& configuration,
618 const MediaConstraintsInterface* constraints, 584 const MediaConstraintsInterface* constraints,
619 PortAllocatorFactoryInterface* allocator_factory, 585 PortAllocatorFactoryInterface* allocator_factory,
620 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, 586 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
621 PeerConnectionObserver* observer) { 587 PeerConnectionObserver* observer) {
622 RTC_DCHECK(observer != nullptr); 588 RTC_DCHECK(observer != nullptr);
623 if (!observer) { 589 if (!observer) {
624 return false; 590 return false;
625 } 591 }
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 }
650 observer_ = observer; 592 observer_ = observer;
651 593
652 port_allocator_ = allocator.Pass();
653
654 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config; 594 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config;
655 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config; 595 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config;
656 if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) { 596 if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) {
657 return false; 597 return false;
658 } 598 }
659 599 port_allocator_.reset(
660 cricket::ServerAddresses cricket_stuns; 600 allocator_factory->CreatePortAllocator(stun_config, turn_config));
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);
665 601
666 // To handle both internal and externally created port allocator, we will 602 // To handle both internal and externally created port allocator, we will
667 // enable BUNDLE here. 603 // enable BUNDLE here.
668 int portallocator_flags = port_allocator_->flags(); 604 int portallocator_flags = port_allocator_->flags();
669 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 605 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
670 cricket::PORTALLOCATOR_ENABLE_IPV6; 606 cricket::PORTALLOCATOR_ENABLE_IPV6;
671 bool value; 607 bool value;
672 // If IPv6 flag was specified, we'll not override it by experiment. 608 // If IPv6 flag was specified, we'll not override it by experiment.
673 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, 609 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6,
674 &value, nullptr)) { 610 &value, nullptr)) {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 } 1079 }
1144 1080
1145 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { 1081 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) {
1146 if (port_allocator_) { 1082 if (port_allocator_) {
1147 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stuns; 1083 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stuns;
1148 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turns; 1084 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turns;
1149 if (!ParseIceServers(config.servers, &stuns, &turns)) { 1085 if (!ParseIceServers(config.servers, &stuns, &turns)) {
1150 return false; 1086 return false;
1151 } 1087 }
1152 1088
1153 cricket::ServerAddresses cricket_stuns; 1089 std::vector<rtc::SocketAddress> stun_hosts;
1154 std::vector<cricket::RelayServerConfig> cricket_turns; 1090 typedef std::vector<StunConfiguration>::const_iterator StunIt;
1155 ConvertToCricketIceServers(stuns, turns, &cricket_stuns, &cricket_turns); 1091 for (StunIt stun_it = stuns.begin(); stun_it != stuns.end(); ++stun_it) {
1156 port_allocator_->SetIceServers(cricket_stuns, cricket_turns); 1092 stun_hosts.push_back(stun_it->server);
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 }
1157 } 1119 }
1158 session_->SetIceConfig(session_->ParseIceConfig(config)); 1120 session_->SetIceConfig(session_->ParseIceConfig(config));
1159 return session_->SetIceTransports(config.type); 1121 return session_->SetIceTransports(config.type);
1160 } 1122 }
1161 1123
1162 bool PeerConnection::AddIceCandidate( 1124 bool PeerConnection::AddIceCandidate(
1163 const IceCandidateInterface* ice_candidate) { 1125 const IceCandidateInterface* ice_candidate) {
1164 return session_->ProcessIceMessage(ice_candidate); 1126 return session_->ProcessIceMessage(ice_candidate);
1165 } 1127 }
1166 1128
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 1966 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2005 for (const auto& channel : sctp_data_channels_) { 1967 for (const auto& channel : sctp_data_channels_) {
2006 if (channel->id() == sid) { 1968 if (channel->id() == sid) {
2007 return channel; 1969 return channel;
2008 } 1970 }
2009 } 1971 }
2010 return nullptr; 1972 return nullptr;
2011 } 1973 }
2012 1974
2013 } // namespace webrtc 1975 } // namespace webrtc
OLDNEW
« no previous file with comments | « talk/app/webrtc/peerconnection.h ('k') | talk/app/webrtc/peerconnectioninterface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698