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

Side by Side Diff: webrtc/api/peerconnection.cc

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

Powered by Google App Engine
This is Rietveld 408576698