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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 break; | 295 break; |
296 } | 296 } |
297 case INVALID: | 297 case INVALID: |
298 default: | 298 default: |
299 LOG(WARNING) << "Configuration not supported: " << url; | 299 LOG(WARNING) << "Configuration not supported: " << url; |
300 return false; | 300 return false; |
301 } | 301 } |
302 return true; | 302 return true; |
303 } | 303 } |
304 | 304 |
305 void ConvertToCricketIceServers( | |
306 const std::vector<StunConfiguration>& stuns, | |
307 const std::vector<TurnConfiguration>& turns, | |
308 cricket::ServerAddresses* cricket_stuns, | |
309 std::vector<cricket::RelayServerConfig>* cricket_turns) { | |
pthatcher1
2015/10/15 05:36:58
How feasible is it to simply put StunConfiguration
Taylor Brandstetter
2015/10/15 17:13:37
Right now, the Chromium "PortAllocator factories"
| |
310 RTC_DCHECK(cricket_stuns && cricket_turns); | |
311 for (const StunConfiguration& stun : stuns) { | |
312 cricket_stuns->insert(stun.server); | |
313 } | |
314 | |
315 int priority = static_cast<int>(turns.size() - 1); | |
316 for (const TurnConfiguration& turn : turns) { | |
317 cricket::RelayCredentials credentials(turn.username, turn.password); | |
318 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); | |
319 cricket::ProtocolType protocol; | |
320 // Using VERIFY because ParseIceServers should have already caught an | |
321 // invalid transport type. | |
322 if (!VERIFY( | |
323 cricket::StringToProto(turn.transport_type.c_str(), &protocol))) { | |
324 LOG(LS_WARNING) << "Ignoring TURN server " << turn.server << ". " | |
325 << "Reason= Incorrect " << turn.transport_type | |
326 << " transport parameter."; | |
327 } else { | |
328 relay_server.ports.push_back( | |
329 cricket::ProtocolAddress(turn.server, protocol, turn.secure)); | |
330 relay_server.credentials = credentials; | |
331 relay_server.priority = priority; | |
332 cricket_turns->push_back(relay_server); | |
333 } | |
334 // First in the list gets highest priority. | |
335 --priority; | |
336 } | |
337 } | |
338 | |
305 } // namespace | 339 } // namespace |
306 | 340 |
307 namespace webrtc { | 341 namespace webrtc { |
308 | 342 |
309 bool ParseIceServers(const PeerConnectionInterface::IceServers& servers, | 343 bool ParseIceServers(const PeerConnectionInterface::IceServers& servers, |
310 StunConfigurations* stun_config, | 344 StunConfigurations* stun_config, |
311 TurnConfigurations* turn_config) { | 345 TurnConfigurations* turn_config) { |
312 for (const webrtc::PeerConnectionInterface::IceServer& server : servers) { | 346 for (const webrtc::PeerConnectionInterface::IceServer& server : servers) { |
313 if (!server.urls.empty()) { | 347 if (!server.urls.empty()) { |
314 for (const std::string& url : server.urls) { | 348 for (const std::string& url : server.urls) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 receiver->Stop(); | 407 receiver->Stop(); |
374 } | 408 } |
375 } | 409 } |
376 | 410 |
377 bool PeerConnection::Initialize( | 411 bool PeerConnection::Initialize( |
378 const PeerConnectionInterface::RTCConfiguration& configuration, | 412 const PeerConnectionInterface::RTCConfiguration& configuration, |
379 const MediaConstraintsInterface* constraints, | 413 const MediaConstraintsInterface* constraints, |
380 PortAllocatorFactoryInterface* allocator_factory, | 414 PortAllocatorFactoryInterface* allocator_factory, |
381 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 415 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
382 PeerConnectionObserver* observer) { | 416 PeerConnectionObserver* observer) { |
383 RTC_DCHECK(observer != NULL); | 417 RTC_DCHECK(observer != nullptr); |
pthatcher1
2015/10/15 05:36:58
Can it just be RTC_DCHECK(observer)?
Taylor Brandstetter
2015/10/15 17:13:37
"observer != nullptr" is used everywhere else in t
| |
384 if (!observer) | 418 if (!observer) { |
385 return false; | 419 return false; |
386 observer_ = observer; | 420 } |
387 | 421 |
388 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config; | 422 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config; |
389 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config; | 423 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config; |
390 if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) { | 424 if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) { |
391 return false; | 425 return false; |
392 } | 426 } |
393 port_allocator_.reset( | 427 rtc::scoped_ptr<cricket::PortAllocator> allocator( |
394 allocator_factory->CreatePortAllocator(stun_config, turn_config)); | 428 allocator_factory->CreatePortAllocator(stun_config, turn_config)); |
429 return Initialize(configuration, constraints, allocator.Pass(), | |
430 dtls_identity_store.Pass(), observer); | |
pthatcher1
2015/10/15 05:36:58
Does this mean the ice servers are passed twice an
Taylor Brandstetter
2015/10/15 17:13:37
Right now the Chromium P2PPortAllocator doesn't su
pthatcher1
2015/10/20 18:31:26
Can you put a comment, then, that says "this Initi
Taylor Brandstetter
2015/10/20 22:01:33
Done.
| |
431 } | |
432 | |
433 bool PeerConnection::Initialize( | |
434 const PeerConnectionInterface::RTCConfiguration& configuration, | |
435 const MediaConstraintsInterface* constraints, | |
436 rtc::scoped_ptr<cricket::PortAllocator> allocator, | |
437 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | |
438 PeerConnectionObserver* observer) { | |
439 RTC_DCHECK(observer != nullptr); | |
440 if (!observer) { | |
441 return false; | |
442 } | |
443 observer_ = observer; | |
444 | |
445 port_allocator_ = allocator.Pass(); | |
446 | |
447 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stun_config; | |
448 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turn_config; | |
449 if (!ParseIceServers(configuration.servers, &stun_config, &turn_config)) { | |
450 return false; | |
451 } | |
452 | |
453 cricket::ServerAddresses cricket_stuns; | |
454 std::vector<cricket::RelayServerConfig> cricket_turns; | |
455 ConvertToCricketIceServers(stun_config, turn_config, &cricket_stuns, | |
456 &cricket_turns); | |
457 port_allocator_->SetIceServers(cricket_stuns, cricket_turns); | |
395 | 458 |
396 // To handle both internal and externally created port allocator, we will | 459 // To handle both internal and externally created port allocator, we will |
397 // enable BUNDLE here. | 460 // enable BUNDLE here. |
398 int portallocator_flags = port_allocator_->flags(); | 461 int portallocator_flags = port_allocator_->flags(); |
399 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 462 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
400 cricket::PORTALLOCATOR_ENABLE_IPV6; | 463 cricket::PORTALLOCATOR_ENABLE_IPV6; |
401 bool value; | 464 bool value; |
402 // If IPv6 flag was specified, we'll not override it by experiment. | 465 // If IPv6 flag was specified, we'll not override it by experiment. |
403 if (FindConstraint( | 466 if (FindConstraint( |
404 constraints, MediaConstraintsInterface::kEnableIPv6, &value, NULL)) { | 467 constraints, MediaConstraintsInterface::kEnableIPv6, &value, NULL)) { |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 } | 765 } |
703 | 766 |
704 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { | 767 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { |
705 if (port_allocator_) { | 768 if (port_allocator_) { |
706 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stuns; | 769 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stuns; |
707 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turns; | 770 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turns; |
708 if (!ParseIceServers(config.servers, &stuns, &turns)) { | 771 if (!ParseIceServers(config.servers, &stuns, &turns)) { |
709 return false; | 772 return false; |
710 } | 773 } |
711 | 774 |
712 std::vector<rtc::SocketAddress> stun_hosts; | 775 cricket::ServerAddresses cricket_stuns; |
713 typedef std::vector<StunConfiguration>::const_iterator StunIt; | 776 std::vector<cricket::RelayServerConfig> cricket_turns; |
714 for (StunIt stun_it = stuns.begin(); stun_it != stuns.end(); ++stun_it) { | 777 ConvertToCricketIceServers(stuns, turns, &cricket_stuns, &cricket_turns); |
715 stun_hosts.push_back(stun_it->server); | 778 port_allocator_->SetIceServers(cricket_stuns, cricket_turns); |
716 } | |
717 | |
718 rtc::SocketAddress stun_addr; | |
719 if (!stun_hosts.empty()) { | |
720 stun_addr = stun_hosts.front(); | |
721 LOG(LS_INFO) << "SetConfiguration: StunServer Address: " | |
722 << stun_addr.ToString(); | |
723 } | |
724 | |
725 for (size_t i = 0; i < turns.size(); ++i) { | |
726 cricket::RelayCredentials credentials(turns[i].username, | |
727 turns[i].password); | |
728 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); | |
729 cricket::ProtocolType protocol; | |
730 if (cricket::StringToProto(turns[i].transport_type.c_str(), &protocol)) { | |
731 relay_server.ports.push_back(cricket::ProtocolAddress( | |
732 turns[i].server, protocol, turns[i].secure)); | |
733 relay_server.credentials = credentials; | |
734 LOG(LS_INFO) << "SetConfiguration: TurnServer Address: " | |
735 << turns[i].server.ToString(); | |
736 } else { | |
737 LOG(LS_WARNING) << "Ignoring TURN server " << turns[i].server << ". " | |
738 << "Reason= Incorrect " << turns[i].transport_type | |
739 << " transport parameter."; | |
740 } | |
741 } | |
742 } | 779 } |
743 session_->SetIceConfig(session_->ParseIceConfig(config)); | 780 session_->SetIceConfig(session_->ParseIceConfig(config)); |
744 return session_->SetIceTransports(config.type); | 781 return session_->SetIceTransports(config.type); |
745 } | 782 } |
746 | 783 |
747 bool PeerConnection::AddIceCandidate( | 784 bool PeerConnection::AddIceCandidate( |
748 const IceCandidateInterface* ice_candidate) { | 785 const IceCandidateInterface* ice_candidate) { |
749 return session_->ProcessIceMessage(ice_candidate); | 786 return session_->ProcessIceMessage(ice_candidate); |
750 } | 787 } |
751 | 788 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1010 std::vector<rtc::scoped_refptr<RtpReceiverInterface>>::iterator | 1047 std::vector<rtc::scoped_refptr<RtpReceiverInterface>>::iterator |
1011 PeerConnection::FindReceiverForTrack(MediaStreamTrackInterface* track) { | 1048 PeerConnection::FindReceiverForTrack(MediaStreamTrackInterface* track) { |
1012 return std::find_if( | 1049 return std::find_if( |
1013 receivers_.begin(), receivers_.end(), | 1050 receivers_.begin(), receivers_.end(), |
1014 [track](const rtc::scoped_refptr<RtpReceiverInterface>& receiver) { | 1051 [track](const rtc::scoped_refptr<RtpReceiverInterface>& receiver) { |
1015 return receiver->track() == track; | 1052 return receiver->track() == track; |
1016 }); | 1053 }); |
1017 } | 1054 } |
1018 | 1055 |
1019 } // namespace webrtc | 1056 } // namespace webrtc |
OLD | NEW |