OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 #include "webrtc/pc/channelmanager.h" | 42 #include "webrtc/pc/channelmanager.h" |
43 #include "webrtc/system_wrappers/include/clock.h" | 43 #include "webrtc/system_wrappers/include/clock.h" |
44 #include "webrtc/system_wrappers/include/field_trial.h" | 44 #include "webrtc/system_wrappers/include/field_trial.h" |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 using webrtc::DataChannel; | 48 using webrtc::DataChannel; |
49 using webrtc::MediaConstraintsInterface; | 49 using webrtc::MediaConstraintsInterface; |
50 using webrtc::MediaStreamInterface; | 50 using webrtc::MediaStreamInterface; |
51 using webrtc::PeerConnectionInterface; | 51 using webrtc::PeerConnectionInterface; |
52 using webrtc::RtcError; | |
52 using webrtc::RtpSenderInternal; | 53 using webrtc::RtpSenderInternal; |
53 using webrtc::RtpSenderInterface; | 54 using webrtc::RtpSenderInterface; |
54 using webrtc::RtpSenderProxy; | 55 using webrtc::RtpSenderProxy; |
55 using webrtc::RtpSenderProxyWithInternal; | 56 using webrtc::RtpSenderProxyWithInternal; |
56 using webrtc::StreamCollection; | 57 using webrtc::StreamCollection; |
57 | 58 |
58 static const char kDefaultStreamLabel[] = "default"; | 59 static const char kDefaultStreamLabel[] = "default"; |
59 static const char kDefaultAudioTrackLabel[] = "defaulta0"; | 60 static const char kDefaultAudioTrackLabel[] = "defaulta0"; |
60 static const char kDefaultVideoTrackLabel[] = "defaultv0"; | 61 static const char kDefaultVideoTrackLabel[] = "defaultv0"; |
61 | 62 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 *host = in_str.substr(0, colonpos); | 202 *host = in_str.substr(0, colonpos); |
202 } else { | 203 } else { |
203 *host = in_str; | 204 *host = in_str; |
204 } | 205 } |
205 } | 206 } |
206 return !host->empty(); | 207 return !host->empty(); |
207 } | 208 } |
208 | 209 |
209 // Adds a STUN or TURN server to the appropriate list, | 210 // Adds a STUN or TURN server to the appropriate list, |
210 // by parsing |url| and using the username/password in |server|. | 211 // by parsing |url| and using the username/password in |server|. |
211 bool ParseIceServerUrl(const PeerConnectionInterface::IceServer& server, | 212 RtcError ParseIceServerUrl( |
212 const std::string& url, | 213 const PeerConnectionInterface::IceServer& server, |
213 cricket::ServerAddresses* stun_servers, | 214 const std::string& url, |
214 std::vector<cricket::RelayServerConfig>* turn_servers) { | 215 cricket::ServerAddresses* stun_servers, |
216 std::vector<cricket::RelayServerConfig>* turn_servers) { | |
215 // draft-nandakumar-rtcweb-stun-uri-01 | 217 // draft-nandakumar-rtcweb-stun-uri-01 |
216 // stunURI = scheme ":" stun-host [ ":" stun-port ] | 218 // stunURI = scheme ":" stun-host [ ":" stun-port ] |
217 // scheme = "stun" / "stuns" | 219 // scheme = "stun" / "stuns" |
218 // stun-host = IP-literal / IPv4address / reg-name | 220 // stun-host = IP-literal / IPv4address / reg-name |
219 // stun-port = *DIGIT | 221 // stun-port = *DIGIT |
220 | 222 |
221 // draft-petithuguenin-behave-turn-uris-01 | 223 // draft-petithuguenin-behave-turn-uris-01 |
222 // turnURI = scheme ":" turn-host [ ":" turn-port ] | 224 // turnURI = scheme ":" turn-host [ ":" turn-port ] |
223 // [ "?transport=" transport ] | 225 // [ "?transport=" transport ] |
224 // scheme = "turn" / "turns" | 226 // scheme = "turn" / "turns" |
225 // transport = "udp" / "tcp" / transport-ext | 227 // transport = "udp" / "tcp" / transport-ext |
226 // transport-ext = 1*unreserved | 228 // transport-ext = 1*unreserved |
227 // turn-host = IP-literal / IPv4address / reg-name | 229 // turn-host = IP-literal / IPv4address / reg-name |
228 // turn-port = *DIGIT | 230 // turn-port = *DIGIT |
229 RTC_DCHECK(stun_servers != nullptr); | 231 RTC_DCHECK(stun_servers != nullptr); |
230 RTC_DCHECK(turn_servers != nullptr); | 232 RTC_DCHECK(turn_servers != nullptr); |
231 std::vector<std::string> tokens; | 233 std::vector<std::string> tokens; |
232 cricket::ProtocolType turn_transport_type = cricket::PROTO_UDP; | 234 cricket::ProtocolType turn_transport_type = cricket::PROTO_UDP; |
233 RTC_DCHECK(!url.empty()); | 235 RTC_DCHECK(!url.empty()); |
234 rtc::tokenize_with_empty_tokens(url, '?', &tokens); | 236 rtc::tokenize_with_empty_tokens(url, '?', &tokens); |
235 std::string uri_without_transport = tokens[0]; | 237 std::string uri_without_transport = tokens[0]; |
236 // Let's look into transport= param, if it exists. | 238 // Let's look into transport= param, if it exists. |
237 if (tokens.size() == kTurnTransportTokensNum) { // ?transport= is present. | 239 if (tokens.size() == kTurnTransportTokensNum) { // ?transport= is present. |
238 std::string uri_transport_param = tokens[1]; | 240 std::string uri_transport_param = tokens[1]; |
239 rtc::tokenize_with_empty_tokens(uri_transport_param, '=', &tokens); | 241 rtc::tokenize_with_empty_tokens(uri_transport_param, '=', &tokens); |
240 if (tokens[0] != kTransport) { | 242 if (tokens[0] != kTransport) { |
241 LOG(LS_WARNING) << "Invalid transport parameter key."; | 243 LOG(LS_WARNING) << "Invalid transport parameter key."; |
242 return false; | 244 return RtcError::SYNTAX_ERROR; |
243 } | 245 } |
244 if (tokens.size() < 2 || | 246 if (tokens.size() < 2 || |
245 !cricket::StringToProto(tokens[1].c_str(), &turn_transport_type) || | 247 !cricket::StringToProto(tokens[1].c_str(), &turn_transport_type) || |
246 (turn_transport_type != cricket::PROTO_UDP && | 248 (turn_transport_type != cricket::PROTO_UDP && |
247 turn_transport_type != cricket::PROTO_TCP)) { | 249 turn_transport_type != cricket::PROTO_TCP)) { |
248 LOG(LS_WARNING) << "Transport param should always be udp or tcp."; | 250 LOG(LS_WARNING) << "Transport param should always be udp or tcp."; |
249 return false; | 251 return RtcError::SYNTAX_ERROR; |
250 } | 252 } |
251 } | 253 } |
252 | 254 |
253 std::string hoststring; | 255 std::string hoststring; |
254 ServiceType service_type; | 256 ServiceType service_type; |
255 if (!GetServiceTypeAndHostnameFromUri(uri_without_transport, | 257 if (!GetServiceTypeAndHostnameFromUri(uri_without_transport, |
256 &service_type, | 258 &service_type, |
257 &hoststring)) { | 259 &hoststring)) { |
258 LOG(LS_WARNING) << "Invalid transport parameter in ICE URI: " << url; | 260 LOG(LS_WARNING) << "Invalid transport parameter in ICE URI: " << url; |
259 return false; | 261 return RtcError::SYNTAX_ERROR; |
260 } | 262 } |
261 | 263 |
262 // GetServiceTypeAndHostnameFromUri should never give an empty hoststring | 264 // GetServiceTypeAndHostnameFromUri should never give an empty hoststring |
263 RTC_DCHECK(!hoststring.empty()); | 265 RTC_DCHECK(!hoststring.empty()); |
264 | 266 |
265 // Let's break hostname. | 267 // Let's break hostname. |
266 tokens.clear(); | 268 tokens.clear(); |
267 rtc::tokenize_with_empty_tokens(hoststring, '@', &tokens); | 269 rtc::tokenize_with_empty_tokens(hoststring, '@', &tokens); |
268 | 270 |
269 std::string username(server.username); | 271 std::string username(server.username); |
270 if (tokens.size() > kTurnHostTokensNum) { | 272 if (tokens.size() > kTurnHostTokensNum) { |
271 LOG(LS_WARNING) << "Invalid user@hostname format: " << hoststring; | 273 LOG(LS_WARNING) << "Invalid user@hostname format: " << hoststring; |
272 return false; | 274 return RtcError::SYNTAX_ERROR; |
273 } | 275 } |
274 if (tokens.size() == kTurnHostTokensNum) { | 276 if (tokens.size() == kTurnHostTokensNum) { |
275 if (tokens[0].empty() || tokens[1].empty()) { | 277 if (tokens[0].empty() || tokens[1].empty()) { |
276 LOG(LS_WARNING) << "Invalid user@hostname format: " << hoststring; | 278 LOG(LS_WARNING) << "Invalid user@hostname format: " << hoststring; |
277 return false; | 279 return RtcError::SYNTAX_ERROR; |
278 } | 280 } |
279 username.assign(rtc::s_url_decode(tokens[0])); | 281 username.assign(rtc::s_url_decode(tokens[0])); |
280 hoststring = tokens[1]; | 282 hoststring = tokens[1]; |
281 } else { | 283 } else { |
282 hoststring = tokens[0]; | 284 hoststring = tokens[0]; |
283 } | 285 } |
284 | 286 |
285 int port = kDefaultStunPort; | 287 int port = kDefaultStunPort; |
286 if (service_type == TURNS) { | 288 if (service_type == TURNS) { |
287 port = kDefaultStunTlsPort; | 289 port = kDefaultStunTlsPort; |
288 turn_transport_type = cricket::PROTO_TLS; | 290 turn_transport_type = cricket::PROTO_TLS; |
289 } | 291 } |
290 | 292 |
291 std::string address; | 293 std::string address; |
292 if (!ParseHostnameAndPortFromString(hoststring, &address, &port)) { | 294 if (!ParseHostnameAndPortFromString(hoststring, &address, &port)) { |
293 LOG(WARNING) << "Invalid hostname format: " << uri_without_transport; | 295 LOG(WARNING) << "Invalid hostname format: " << uri_without_transport; |
294 return false; | 296 return RtcError::SYNTAX_ERROR; |
295 } | 297 } |
296 | 298 |
297 if (port <= 0 || port > 0xffff) { | 299 if (port <= 0 || port > 0xffff) { |
298 LOG(WARNING) << "Invalid port: " << port; | 300 LOG(WARNING) << "Invalid port: " << port; |
299 return false; | 301 return RtcError::SYNTAX_ERROR; |
300 } | 302 } |
301 | 303 |
302 switch (service_type) { | 304 switch (service_type) { |
303 case STUN: | 305 case STUN: |
304 case STUNS: | 306 case STUNS: |
305 stun_servers->insert(rtc::SocketAddress(address, port)); | 307 stun_servers->insert(rtc::SocketAddress(address, port)); |
306 break; | 308 break; |
307 case TURN: | 309 case TURN: |
308 case TURNS: { | 310 case TURNS: { |
311 if (username.empty() || server.password.empty()) { | |
312 // The WebRTC spec requires throwing an InvalidAccessError when username | |
313 // or | |
314 // credential are ommitted; this is the native equivalent. | |
315 return RtcError::INVALID_PARAMETER; | |
316 } | |
309 turn_servers->push_back(cricket::RelayServerConfig( | 317 turn_servers->push_back(cricket::RelayServerConfig( |
310 address, port, username, server.password, turn_transport_type)); | 318 address, port, username, server.password, turn_transport_type)); |
311 break; | 319 break; |
312 } | 320 } |
313 case INVALID: | |
314 default: | 321 default: |
315 LOG(WARNING) << "Configuration not supported: " << url; | 322 // We shouldn't get to this point with an invalid service_type, we should |
316 return false; | 323 // have returned an error already. |
324 RTC_DCHECK(false) << "Unexpected service type"; | |
325 return RtcError::INTERNAL_ERROR; | |
317 } | 326 } |
318 return true; | 327 return RtcError::NONE; |
319 } | 328 } |
320 | 329 |
321 // Check if we can send |new_stream| on a PeerConnection. | 330 // Check if we can send |new_stream| on a PeerConnection. |
322 bool CanAddLocalMediaStream(webrtc::StreamCollectionInterface* current_streams, | 331 bool CanAddLocalMediaStream(webrtc::StreamCollectionInterface* current_streams, |
323 webrtc::MediaStreamInterface* new_stream) { | 332 webrtc::MediaStreamInterface* new_stream) { |
324 if (!new_stream || !current_streams) { | 333 if (!new_stream || !current_streams) { |
325 return false; | 334 return false; |
326 } | 335 } |
327 if (current_streams->find(new_stream->label()) != nullptr) { | 336 if (current_streams->find(new_stream->label()) != nullptr) { |
328 LOG(LS_ERROR) << "MediaStream with label " << new_stream->label() | 337 LOG(LS_ERROR) << "MediaStream with label " << new_stream->label() |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 for (auto& receiver : receivers) { | 429 for (auto& receiver : receivers) { |
421 if (receiver->media_type() == media_type) { | 430 if (receiver->media_type() == media_type) { |
422 if (!channel) { | 431 if (!channel) { |
423 receiver->internal()->Stop(); | 432 receiver->internal()->Stop(); |
424 } | 433 } |
425 static_cast<RECEIVER*>(receiver->internal())->SetChannel(channel); | 434 static_cast<RECEIVER*>(receiver->internal())->SetChannel(channel); |
426 } | 435 } |
427 } | 436 } |
428 } | 437 } |
429 | 438 |
439 // Helper to set an error and return from a method. | |
440 bool SafeSetError(webrtc::RtcError error, webrtc::RtcError* error_output) { | |
441 if (error_output) { | |
442 *error_output = error; | |
443 } | |
444 return error == webrtc::RtcError::NONE; | |
445 } | |
446 | |
430 } // namespace | 447 } // namespace |
431 | 448 |
432 namespace webrtc { | 449 namespace webrtc { |
433 | 450 |
434 static const char* const kRtcErrorNames[] = { | 451 static const char* const kRtcErrorNames[] = { |
435 "NONE", | 452 "NONE", |
436 "UNSUPPORTED_PARAMETER", | 453 "UNSUPPORTED_PARAMETER", |
437 "INVALID_PARAMETER", | 454 "INVALID_PARAMETER", |
438 "INVALID_RANGE", | 455 "INVALID_RANGE", |
439 "SYNTAX_ERROR", | 456 "SYNTAX_ERROR", |
440 "INVALID_STATE", | 457 "INVALID_STATE", |
441 "INVALID_MODIFICATION", | 458 "INVALID_MODIFICATION", |
442 "NETWORK_ERROR", | 459 "NETWORK_ERROR", |
443 "INTERNAL_ERROR", | 460 "INTERNAL_ERROR", |
444 }; | 461 }; |
462 static_assert(static_cast<int>(RtcError::INTERNAL_ERROR) == | |
463 (arraysize(kRtcErrorNames) - 1), | |
464 "kRtcErrorNames must have as many strings as RtcError " | |
465 "has values."); | |
445 | 466 |
446 std::ostream& operator<<(std::ostream& stream, RtcError error) { | 467 std::ostream& operator<<(std::ostream& stream, RtcError error) { |
447 int index = static_cast<int>(error); | 468 int index = static_cast<int>(error); |
448 RTC_CHECK(index < static_cast<int>(sizeof(kRtcErrorNames) / | |
449 sizeof(kRtcErrorNames[0]))); | |
450 return stream << kRtcErrorNames[index]; | 469 return stream << kRtcErrorNames[index]; |
451 } | 470 } |
452 | 471 |
472 bool PeerConnectionInterface::RTCConfiguration::operator==( | |
473 const PeerConnectionInterface::RTCConfiguration& o) const { | |
474 // This static_assert prevents us from accidentally breaking operator==. | |
475 struct stuff_being_tested_for_equality { | |
476 IceTransportsType type; | |
477 IceServers servers; | |
478 BundlePolicy bundle_policy; | |
479 RtcpMuxPolicy rtcp_mux_policy; | |
480 TcpCandidatePolicy tcp_candidate_policy; | |
481 CandidateNetworkPolicy candidate_network_policy; | |
482 int audio_jitter_buffer_max_packets; | |
483 bool audio_jitter_buffer_fast_accelerate; | |
484 int ice_connection_receiving_timeout; | |
485 int ice_backup_candidate_pair_ping_interval; | |
486 ContinualGatheringPolicy continual_gathering_policy; | |
487 std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates; | |
488 bool prioritize_most_likely_ice_candidate_pairs; | |
489 struct cricket::MediaConfig media_config; | |
490 bool disable_ipv6; | |
491 bool enable_rtp_data_channel; | |
492 bool enable_quic; | |
493 rtc::Optional<int> screencast_min_bitrate; | |
494 rtc::Optional<bool> combined_audio_video_bwe; | |
495 rtc::Optional<bool> enable_dtls_srtp; | |
496 int ice_candidate_pool_size; | |
497 bool prune_turn_ports; | |
498 bool presume_writable_when_fully_relayed; | |
499 bool enable_ice_renomination; | |
500 bool redetermine_role_on_ice_restart; | |
501 }; | |
502 static_assert(sizeof(stuff_being_tested_for_equality) == sizeof(*this), | |
503 "Did you add something to RTCConfiguration and forget to " | |
504 "update operator==?"); | |
Taylor Brandstetter
2016/12/20 02:04:39
This may seem like overkill, but I think there's a
| |
505 return type == o.type && servers == o.servers && | |
506 bundle_policy == o.bundle_policy && | |
507 rtcp_mux_policy == o.rtcp_mux_policy && | |
508 tcp_candidate_policy == o.tcp_candidate_policy && | |
509 candidate_network_policy == o.candidate_network_policy && | |
510 audio_jitter_buffer_max_packets == o.audio_jitter_buffer_max_packets && | |
511 audio_jitter_buffer_fast_accelerate == | |
512 o.audio_jitter_buffer_fast_accelerate && | |
513 ice_connection_receiving_timeout == | |
514 o.ice_connection_receiving_timeout && | |
515 ice_backup_candidate_pair_ping_interval == | |
516 o.ice_backup_candidate_pair_ping_interval && | |
517 continual_gathering_policy == o.continual_gathering_policy && | |
518 certificates == o.certificates && | |
519 prioritize_most_likely_ice_candidate_pairs == | |
520 o.prioritize_most_likely_ice_candidate_pairs && | |
521 media_config == o.media_config && disable_ipv6 == o.disable_ipv6 && | |
522 enable_rtp_data_channel == o.enable_rtp_data_channel && | |
523 enable_quic == o.enable_quic && | |
524 screencast_min_bitrate == o.screencast_min_bitrate && | |
525 combined_audio_video_bwe == o.combined_audio_video_bwe && | |
526 enable_dtls_srtp == o.enable_dtls_srtp && | |
527 ice_candidate_pool_size == o.ice_candidate_pool_size && | |
528 prune_turn_ports == o.prune_turn_ports && | |
529 presume_writable_when_fully_relayed == | |
530 o.presume_writable_when_fully_relayed && | |
531 enable_ice_renomination == o.enable_ice_renomination && | |
532 redetermine_role_on_ice_restart == o.redetermine_role_on_ice_restart; | |
533 } | |
534 | |
535 bool PeerConnectionInterface::RTCConfiguration::operator!=( | |
536 const PeerConnectionInterface::RTCConfiguration& o) const { | |
537 return !(*this == o); | |
538 } | |
539 | |
453 // Generate a RTCP CNAME when a PeerConnection is created. | 540 // Generate a RTCP CNAME when a PeerConnection is created. |
454 std::string GenerateRtcpCname() { | 541 std::string GenerateRtcpCname() { |
455 std::string cname; | 542 std::string cname; |
456 if (!rtc::CreateRandomString(kRtcpCnameLength, &cname)) { | 543 if (!rtc::CreateRandomString(kRtcpCnameLength, &cname)) { |
457 LOG(LS_ERROR) << "Failed to generate CNAME."; | 544 LOG(LS_ERROR) << "Failed to generate CNAME."; |
458 RTC_DCHECK(false); | 545 RTC_DCHECK(false); |
459 } | 546 } |
460 return cname; | 547 return cname; |
461 } | 548 } |
462 | 549 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 for (auto& kv : session_options->transport_options) { | 629 for (auto& kv : session_options->transport_options) { |
543 kv.second.ice_restart = ice_restart; | 630 kv.second.ice_restart = ice_restart; |
544 } | 631 } |
545 | 632 |
546 if (!constraints) { | 633 if (!constraints) { |
547 return true; | 634 return true; |
548 } | 635 } |
549 return mandatory_constraints_satisfied == constraints->GetMandatory().size(); | 636 return mandatory_constraints_satisfied == constraints->GetMandatory().size(); |
550 } | 637 } |
551 | 638 |
552 bool ParseIceServers(const PeerConnectionInterface::IceServers& servers, | 639 RtcError ParseIceServers( |
553 cricket::ServerAddresses* stun_servers, | 640 const PeerConnectionInterface::IceServers& servers, |
554 std::vector<cricket::RelayServerConfig>* turn_servers) { | 641 cricket::ServerAddresses* stun_servers, |
642 std::vector<cricket::RelayServerConfig>* turn_servers) { | |
555 for (const webrtc::PeerConnectionInterface::IceServer& server : servers) { | 643 for (const webrtc::PeerConnectionInterface::IceServer& server : servers) { |
556 if (!server.urls.empty()) { | 644 if (!server.urls.empty()) { |
557 for (const std::string& url : server.urls) { | 645 for (const std::string& url : server.urls) { |
558 if (url.empty()) { | 646 if (url.empty()) { |
559 LOG(LS_ERROR) << "Empty uri."; | 647 LOG(LS_ERROR) << "Empty uri."; |
560 return false; | 648 return RtcError::SYNTAX_ERROR; |
561 } | 649 } |
562 if (!ParseIceServerUrl(server, url, stun_servers, turn_servers)) { | 650 RtcError err = |
563 return false; | 651 ParseIceServerUrl(server, url, stun_servers, turn_servers); |
652 if (err != RtcError::NONE) { | |
653 return err; | |
564 } | 654 } |
565 } | 655 } |
566 } else if (!server.uri.empty()) { | 656 } else if (!server.uri.empty()) { |
567 // Fallback to old .uri if new .urls isn't present. | 657 // Fallback to old .uri if new .urls isn't present. |
568 if (!ParseIceServerUrl(server, server.uri, stun_servers, turn_servers)) { | 658 RtcError err = |
569 return false; | 659 ParseIceServerUrl(server, server.uri, stun_servers, turn_servers); |
660 if (err != RtcError::NONE) { | |
661 return err; | |
570 } | 662 } |
571 } else { | 663 } else { |
572 LOG(LS_ERROR) << "Empty uri."; | 664 LOG(LS_ERROR) << "Empty uri."; |
573 return false; | 665 return RtcError::SYNTAX_ERROR; |
574 } | 666 } |
575 } | 667 } |
576 // Candidates must have unique priorities, so that connectivity checks | 668 // Candidates must have unique priorities, so that connectivity checks |
577 // are performed in a well-defined order. | 669 // are performed in a well-defined order. |
578 int priority = static_cast<int>(turn_servers->size() - 1); | 670 int priority = static_cast<int>(turn_servers->size() - 1); |
579 for (cricket::RelayServerConfig& turn_server : *turn_servers) { | 671 for (cricket::RelayServerConfig& turn_server : *turn_servers) { |
580 // First in the list gets highest priority. | 672 // First in the list gets highest priority. |
581 turn_server.priority = priority--; | 673 turn_server.priority = priority--; |
582 } | 674 } |
583 return true; | 675 return RtcError::NONE; |
584 } | 676 } |
585 | 677 |
586 PeerConnection::PeerConnection(PeerConnectionFactory* factory) | 678 PeerConnection::PeerConnection(PeerConnectionFactory* factory) |
587 : factory_(factory), | 679 : factory_(factory), |
588 observer_(NULL), | 680 observer_(NULL), |
589 uma_observer_(NULL), | 681 uma_observer_(NULL), |
590 signaling_state_(kStable), | 682 signaling_state_(kStable), |
591 ice_connection_state_(kIceConnectionNew), | 683 ice_connection_state_(kIceConnectionNew), |
592 ice_gathering_state_(kIceGatheringNew), | 684 ice_gathering_state_(kIceGatheringNew), |
593 event_log_(RtcEventLog::Create(webrtc::Clock::GetRealTimeClock())), | 685 event_log_(RtcEventLog::Create(webrtc::Clock::GetRealTimeClock())), |
(...skipping 22 matching lines...) Expand all Loading... | |
616 network_thread()->Invoke<void>(RTC_FROM_HERE, | 708 network_thread()->Invoke<void>(RTC_FROM_HERE, |
617 [this] { port_allocator_.reset(nullptr); }); | 709 [this] { port_allocator_.reset(nullptr); }); |
618 } | 710 } |
619 | 711 |
620 bool PeerConnection::Initialize( | 712 bool PeerConnection::Initialize( |
621 const PeerConnectionInterface::RTCConfiguration& configuration, | 713 const PeerConnectionInterface::RTCConfiguration& configuration, |
622 std::unique_ptr<cricket::PortAllocator> allocator, | 714 std::unique_ptr<cricket::PortAllocator> allocator, |
623 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, | 715 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
624 PeerConnectionObserver* observer) { | 716 PeerConnectionObserver* observer) { |
625 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); | 717 TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); |
626 RTC_DCHECK(observer != nullptr); | 718 if (!allocator) { |
719 LOG(LS_ERROR) << "PeerConnection initialized without a PortAllocator? " | |
720 << "This shouldn't happen if using PeerConnectionFactory."; | |
721 return false; | |
Taylor Brandstetter
2016/12/20 02:04:39
There's no code path in which passing a null PortA
| |
722 } | |
627 if (!observer) { | 723 if (!observer) { |
724 // TODO(deadbeef): Why do we do this? | |
725 LOG(LS_ERROR) << "PeerConnection initialized without a " | |
726 << "PeerConnectionObserver"; | |
628 return false; | 727 return false; |
629 } | 728 } |
630 observer_ = observer; | 729 observer_ = observer; |
631 | |
632 port_allocator_ = std::move(allocator); | 730 port_allocator_ = std::move(allocator); |
633 | 731 |
634 // The port allocator lives on the network thread and should be initialized | 732 // The port allocator lives on the network thread and should be initialized |
635 // there. | 733 // there. |
636 if (!network_thread()->Invoke<bool>( | 734 if (!network_thread()->Invoke<bool>( |
637 RTC_FROM_HERE, rtc::Bind(&PeerConnection::InitializePortAllocator_n, | 735 RTC_FROM_HERE, rtc::Bind(&PeerConnection::InitializePortAllocator_n, |
638 this, configuration))) { | 736 this, configuration))) { |
639 return false; | 737 return false; |
640 } | 738 } |
641 | 739 |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1277 | 1375 |
1278 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); | 1376 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
1279 signaling_thread()->Post(RTC_FROM_HERE, this, | 1377 signaling_thread()->Post(RTC_FROM_HERE, this, |
1280 MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); | 1378 MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); |
1281 } | 1379 } |
1282 | 1380 |
1283 PeerConnectionInterface::RTCConfiguration PeerConnection::GetConfiguration() { | 1381 PeerConnectionInterface::RTCConfiguration PeerConnection::GetConfiguration() { |
1284 return configuration_; | 1382 return configuration_; |
1285 } | 1383 } |
1286 | 1384 |
1287 bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration) { | 1385 bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration, |
1386 RtcError* error) { | |
1288 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); | 1387 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); |
1289 | 1388 |
1290 if (session_->local_description() && | 1389 if (session_->local_description() && |
1291 configuration.ice_candidate_pool_size != | 1390 configuration.ice_candidate_pool_size != |
1292 configuration_.ice_candidate_pool_size) { | 1391 configuration_.ice_candidate_pool_size) { |
1293 LOG(LS_ERROR) << "Can't change candidate pool size after calling " | 1392 LOG(LS_ERROR) << "Can't change candidate pool size after calling " |
1294 "SetLocalDescription."; | 1393 "SetLocalDescription."; |
1295 return false; | 1394 return SafeSetError(RtcError::INVALID_MODIFICATION, error); |
1296 } | |
1297 // TODO(deadbeef): Return false and log an error if there are any unsupported | |
1298 // modifications. | |
1299 if (port_allocator_) { | |
1300 if (!network_thread()->Invoke<bool>( | |
1301 RTC_FROM_HERE, | |
1302 rtc::Bind(&PeerConnection::ReconfigurePortAllocator_n, this, | |
1303 configuration))) { | |
1304 LOG(LS_ERROR) << "Failed to apply configuration to PortAllocator."; | |
1305 return false; | |
1306 } | |
1307 } | 1395 } |
1308 | 1396 |
1309 // TODO(deadbeef): Shouldn't have to hop to the network thread twice... | 1397 // The simplest (and most future-compatible) way to tell if the config was |
1310 session_->SetIceConfig(session_->ParseIceConfig(configuration)); | 1398 // modified in an invalid way is to copy each property we do support |
1399 // modifying, then use operator==. There are far more properties we don't | |
1400 // support modifying than those we do, and more could be added. | |
1401 RTCConfiguration modified_config = configuration_; | |
1402 modified_config.servers = configuration.servers; | |
1403 modified_config.type = configuration.type; | |
1404 modified_config.ice_candidate_pool_size = | |
1405 configuration.ice_candidate_pool_size; | |
1406 modified_config.prune_turn_ports = configuration.prune_turn_ports; | |
1407 if (configuration != modified_config) { | |
1408 LOG(LS_ERROR) << "Modifying the configuration in an unsupported way."; | |
1409 return SafeSetError(RtcError::INVALID_MODIFICATION, error); | |
1410 } | |
1411 | |
1412 // Note that this isn't possible through chromium, since it's an unsigned | |
1413 // short in WebIDL. | |
1414 if (configuration.ice_candidate_pool_size < 0 || | |
1415 configuration.ice_candidate_pool_size > UINT16_MAX) { | |
1416 return SafeSetError(RtcError::INVALID_RANGE, error); | |
1417 } | |
1418 | |
1419 // Parse ICE servers before hopping to network thread. | |
1420 cricket::ServerAddresses stun_servers; | |
1421 std::vector<cricket::RelayServerConfig> turn_servers; | |
1422 RtcError parse_error = | |
1423 ParseIceServers(configuration.servers, &stun_servers, &turn_servers); | |
1424 if (parse_error != RtcError::NONE) { | |
1425 return SafeSetError(parse_error, error); | |
1426 } | |
1427 | |
1428 // In theory this shouldn't fail. | |
1429 if (!network_thread()->Invoke<bool>( | |
1430 RTC_FROM_HERE, | |
1431 rtc::Bind(&PeerConnection::ReconfigurePortAllocator_n, this, | |
1432 stun_servers, turn_servers, modified_config.type, | |
1433 modified_config.ice_candidate_pool_size, | |
1434 modified_config.prune_turn_ports))) { | |
1435 LOG(LS_ERROR) << "Failed to apply configuration to PortAllocator."; | |
1436 return SafeSetError(RtcError::INTERNAL_ERROR, error); | |
1437 } | |
1311 | 1438 |
1312 // As described in JSEP, calling setConfiguration with new ICE servers or | 1439 // As described in JSEP, calling setConfiguration with new ICE servers or |
1313 // candidate policy must set a "needs-ice-restart" bit so that the next offer | 1440 // candidate policy must set a "needs-ice-restart" bit so that the next offer |
1314 // triggers an ICE restart which will pick up the changes. | 1441 // triggers an ICE restart which will pick up the changes. |
1315 if (configuration.servers != configuration_.servers || | 1442 if (modified_config.servers != configuration_.servers || |
1316 configuration.type != configuration_.type) { | 1443 modified_config.type != configuration_.type || |
1444 modified_config.prune_turn_ports != configuration_.prune_turn_ports) { | |
1317 session_->SetNeedsIceRestartFlag(); | 1445 session_->SetNeedsIceRestartFlag(); |
1318 } | 1446 } |
1319 configuration_ = configuration; | 1447 configuration_ = modified_config; |
1320 return true; | 1448 return SafeSetError(RtcError::NONE, error); |
1321 } | 1449 } |
1322 | 1450 |
1323 bool PeerConnection::AddIceCandidate( | 1451 bool PeerConnection::AddIceCandidate( |
1324 const IceCandidateInterface* ice_candidate) { | 1452 const IceCandidateInterface* ice_candidate) { |
1325 TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); | 1453 TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); |
1326 if (IsClosed()) { | 1454 if (IsClosed()) { |
1327 return false; | 1455 return false; |
1328 } | 1456 } |
1329 return session_->ProcessIceMessage(ice_candidate); | 1457 return session_->ProcessIceMessage(ice_candidate); |
1330 } | 1458 } |
1331 | 1459 |
1332 bool PeerConnection::RemoveIceCandidates( | 1460 bool PeerConnection::RemoveIceCandidates( |
1333 const std::vector<cricket::Candidate>& candidates) { | 1461 const std::vector<cricket::Candidate>& candidates) { |
1334 TRACE_EVENT0("webrtc", "PeerConnection::RemoveIceCandidates"); | 1462 TRACE_EVENT0("webrtc", "PeerConnection::RemoveIceCandidates"); |
1335 return session_->RemoveRemoteIceCandidates(candidates); | 1463 return session_->RemoveRemoteIceCandidates(candidates); |
1336 } | 1464 } |
1337 | 1465 |
1338 void PeerConnection::RegisterUMAObserver(UMAObserver* observer) { | 1466 void PeerConnection::RegisterUMAObserver(UMAObserver* observer) { |
1339 TRACE_EVENT0("webrtc", "PeerConnection::RegisterUmaObserver"); | 1467 TRACE_EVENT0("webrtc", "PeerConnection::RegisterUmaObserver"); |
1340 uma_observer_ = observer; | 1468 uma_observer_ = observer; |
1341 | 1469 |
1342 if (session_) { | 1470 if (session_) { |
1343 session_->set_metrics_observer(uma_observer_); | 1471 session_->set_metrics_observer(uma_observer_); |
1344 } | 1472 } |
1345 | 1473 |
1346 // Send information about IPv4/IPv6 status. | 1474 // Send information about IPv4/IPv6 status. |
1347 if (uma_observer_ && port_allocator_) { | 1475 if (uma_observer_) { |
1348 port_allocator_->SetMetricsObserver(uma_observer_); | 1476 port_allocator_->SetMetricsObserver(uma_observer_); |
1349 if (port_allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6) { | 1477 if (port_allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6) { |
1350 uma_observer_->IncrementEnumCounter( | 1478 uma_observer_->IncrementEnumCounter( |
1351 kEnumCounterAddressFamily, kPeerConnection_IPv6, | 1479 kEnumCounterAddressFamily, kPeerConnection_IPv6, |
1352 kPeerConnectionAddressFamilyCounter_Max); | 1480 kPeerConnectionAddressFamilyCounter_Max); |
1353 } else { | 1481 } else { |
1354 uma_observer_->IncrementEnumCounter( | 1482 uma_observer_->IncrementEnumCounter( |
1355 kEnumCounterAddressFamily, kPeerConnection_IPv4, | 1483 kEnumCounterAddressFamily, kPeerConnection_IPv4, |
1356 kPeerConnectionAddressFamilyCounter_Max); | 1484 kPeerConnectionAddressFamilyCounter_Max); |
1357 } | 1485 } |
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2330 return channel; | 2458 return channel; |
2331 } | 2459 } |
2332 } | 2460 } |
2333 return nullptr; | 2461 return nullptr; |
2334 } | 2462 } |
2335 | 2463 |
2336 bool PeerConnection::InitializePortAllocator_n( | 2464 bool PeerConnection::InitializePortAllocator_n( |
2337 const RTCConfiguration& configuration) { | 2465 const RTCConfiguration& configuration) { |
2338 cricket::ServerAddresses stun_servers; | 2466 cricket::ServerAddresses stun_servers; |
2339 std::vector<cricket::RelayServerConfig> turn_servers; | 2467 std::vector<cricket::RelayServerConfig> turn_servers; |
2340 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { | 2468 if (ParseIceServers(configuration.servers, &stun_servers, &turn_servers) != |
2469 RtcError::NONE) { | |
2341 return false; | 2470 return false; |
2342 } | 2471 } |
2343 | 2472 |
2344 port_allocator_->Initialize(); | 2473 port_allocator_->Initialize(); |
2345 | 2474 |
2346 // To handle both internal and externally created port allocator, we will | 2475 // To handle both internal and externally created port allocator, we will |
2347 // enable BUNDLE here. | 2476 // enable BUNDLE here. |
2348 int portallocator_flags = port_allocator_->flags(); | 2477 int portallocator_flags = port_allocator_->flags(); |
2349 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 2478 portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
2350 cricket::PORTALLOCATOR_ENABLE_IPV6; | 2479 cricket::PORTALLOCATOR_ENABLE_IPV6; |
(...skipping 25 matching lines...) Expand all Loading... | |
2376 | 2505 |
2377 // Call this last since it may create pooled allocator sessions using the | 2506 // Call this last since it may create pooled allocator sessions using the |
2378 // properties set above. | 2507 // properties set above. |
2379 port_allocator_->SetConfiguration(stun_servers, turn_servers, | 2508 port_allocator_->SetConfiguration(stun_servers, turn_servers, |
2380 configuration.ice_candidate_pool_size, | 2509 configuration.ice_candidate_pool_size, |
2381 configuration.prune_turn_ports); | 2510 configuration.prune_turn_ports); |
2382 return true; | 2511 return true; |
2383 } | 2512 } |
2384 | 2513 |
2385 bool PeerConnection::ReconfigurePortAllocator_n( | 2514 bool PeerConnection::ReconfigurePortAllocator_n( |
2386 const RTCConfiguration& configuration) { | 2515 const cricket::ServerAddresses& stun_servers, |
2387 cricket::ServerAddresses stun_servers; | 2516 const std::vector<cricket::RelayServerConfig>& turn_servers, |
2388 std::vector<cricket::RelayServerConfig> turn_servers; | 2517 IceTransportsType type, |
2389 if (!ParseIceServers(configuration.servers, &stun_servers, &turn_servers)) { | 2518 int candidate_pool_size, |
2390 return false; | 2519 bool prune_turn_ports) { |
2391 } | |
2392 port_allocator_->set_candidate_filter( | 2520 port_allocator_->set_candidate_filter( |
2393 ConvertIceTransportTypeToCandidateFilter(configuration.type)); | 2521 ConvertIceTransportTypeToCandidateFilter(type)); |
2394 // Call this last since it may create pooled allocator sessions using the | 2522 // Call this last since it may create pooled allocator sessions using the |
2395 // candidate filter set above. | 2523 // candidate filter set above. |
2396 return port_allocator_->SetConfiguration( | 2524 return port_allocator_->SetConfiguration( |
2397 stun_servers, turn_servers, configuration.ice_candidate_pool_size, | 2525 stun_servers, turn_servers, candidate_pool_size, prune_turn_ports); |
2398 configuration.prune_turn_ports); | |
2399 } | 2526 } |
2400 | 2527 |
2401 bool PeerConnection::StartRtcEventLog_w(rtc::PlatformFile file, | 2528 bool PeerConnection::StartRtcEventLog_w(rtc::PlatformFile file, |
2402 int64_t max_size_bytes) { | 2529 int64_t max_size_bytes) { |
2403 return event_log_->StartLogging(file, max_size_bytes); | 2530 return event_log_->StartLogging(file, max_size_bytes); |
2404 } | 2531 } |
2405 | 2532 |
2406 void PeerConnection::StopRtcEventLog_w() { | 2533 void PeerConnection::StopRtcEventLog_w() { |
2407 event_log_->StopLogging(); | 2534 event_log_->StopLogging(); |
2408 } | 2535 } |
2409 } // namespace webrtc | 2536 } // namespace webrtc |
OLD | NEW |