Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/rtc_peer_connection_handler.h" | 5 #include "content/renderer/media/rtc_peer_connection_handler.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 void GetNativeRtcConfiguration( | 236 void GetNativeRtcConfiguration( |
| 237 const blink::WebRTCConfiguration& blink_config, | 237 const blink::WebRTCConfiguration& blink_config, |
| 238 webrtc::PeerConnectionInterface::RTCConfiguration* webrtc_config) { | 238 webrtc::PeerConnectionInterface::RTCConfiguration* webrtc_config) { |
| 239 DCHECK(webrtc_config); | 239 DCHECK(webrtc_config); |
| 240 | 240 |
| 241 webrtc_config->servers.clear(); | 241 webrtc_config->servers.clear(); |
| 242 for (const blink::WebRTCIceServer& blink_server : blink_config.iceServers) { | 242 for (const blink::WebRTCIceServer& blink_server : blink_config.iceServers) { |
| 243 webrtc::PeerConnectionInterface::IceServer server; | 243 webrtc::PeerConnectionInterface::IceServer server; |
| 244 server.username = blink_server.username.utf8(); | 244 server.username = blink_server.username.utf8(); |
| 245 server.password = blink_server.credential.utf8(); | 245 server.password = blink_server.credential.utf8(); |
| 246 server.uri = blink_server.url.string().utf8(); | 246 for (const blink::WebURL& url : blink_server.urls) { |
| 247 server.urls.push_back(url.string().utf8()); | |
| 248 } | |
| 247 webrtc_config->servers.push_back(server); | 249 webrtc_config->servers.push_back(server); |
| 248 } | 250 } |
| 249 | 251 |
| 250 switch (blink_config.iceTransportPolicy) { | 252 switch (blink_config.iceTransportPolicy) { |
| 251 case blink::WebRTCIceTransportPolicy::kNone: | 253 case blink::WebRTCIceTransportPolicy::kNone: |
| 252 webrtc_config->type = webrtc::PeerConnectionInterface::kNone; | 254 webrtc_config->type = webrtc::PeerConnectionInterface::kNone; |
| 253 break; | 255 break; |
| 254 case blink::WebRTCIceTransportPolicy::kRelay: | 256 case blink::WebRTCIceTransportPolicy::kRelay: |
| 255 webrtc_config->type = webrtc::PeerConnectionInterface::kRelay; | 257 webrtc_config->type = webrtc::PeerConnectionInterface::kRelay; |
| 256 break; | 258 break; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 | 295 |
| 294 webrtc_config->certificates.clear(); | 296 webrtc_config->certificates.clear(); |
| 295 for (const std::unique_ptr<blink::WebRTCCertificate>& blink_certificate : | 297 for (const std::unique_ptr<blink::WebRTCCertificate>& blink_certificate : |
| 296 blink_config.certificates) { | 298 blink_config.certificates) { |
| 297 webrtc_config->certificates.push_back( | 299 webrtc_config->certificates.push_back( |
| 298 static_cast<RTCCertificate*>(blink_certificate.get()) | 300 static_cast<RTCCertificate*>(blink_certificate.get()) |
| 299 ->rtcCertificate()); | 301 ->rtcCertificate()); |
| 300 } | 302 } |
| 301 } | 303 } |
| 302 | 304 |
| 305 void GetBlinkRtcConfiguration( | |
| 306 const webrtc::PeerConnectionInterface::RTCConfiguration& webrtc_config, | |
| 307 blink::WebRTCConfiguration* blink_config) { | |
| 308 blink::WebVector<blink::WebRTCIceServer> iceServers( | |
| 309 webrtc_config.servers.size()); | |
| 310 for (size_t i = 0; i < webrtc_config.servers.size(); i++) { | |
| 311 webrtc::PeerConnectionInterface::IceServer ice_server = | |
|
Taylor_Brandstetter
2017/03/02 22:30:45
Can use a const ref here instead of making a copy.
zhihuang1
2017/03/09 19:13:31
Done.
| |
| 312 webrtc_config.servers[i]; | |
| 313 blink::WebRTCIceServer blink_server; | |
| 314 blink::WebVector<blink::WebURL> blink_urls(ice_server.urls.size()); | |
| 315 for (size_t j = 0; j < ice_server.urls.size(); j++) { | |
| 316 blink_urls[j] = (GURL(ice_server.urls[j])); | |
| 317 } | |
| 318 blink_server.urls = std::move(blink_urls); | |
| 319 blink_server.username = blink::WebString::fromUTF8(ice_server.username); | |
| 320 blink_server.credential = blink::WebString::fromUTF8(ice_server.password); | |
| 321 iceServers[i] = blink_server; | |
| 322 } | |
| 323 blink_config->iceServers = std::move(iceServers); | |
| 324 | |
| 325 switch (webrtc_config.type) { | |
| 326 case webrtc::PeerConnectionInterface::kNone: | |
| 327 blink_config->iceTransportPolicy = blink::WebRTCIceTransportPolicy::kNone; | |
| 328 break; | |
| 329 case webrtc::PeerConnectionInterface::kRelay: | |
| 330 blink_config->iceTransportPolicy = | |
| 331 blink::WebRTCIceTransportPolicy::kRelay; | |
| 332 break; | |
| 333 case webrtc::PeerConnectionInterface::kAll: | |
| 334 blink_config->iceTransportPolicy = blink::WebRTCIceTransportPolicy::kAll; | |
| 335 break; | |
| 336 default: | |
| 337 NOTREACHED(); | |
| 338 } | |
| 339 | |
| 340 switch (webrtc_config.bundle_policy) { | |
| 341 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced: | |
| 342 blink_config->bundlePolicy = blink::WebRTCBundlePolicy::kBalanced; | |
| 343 break; | |
| 344 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle: | |
| 345 blink_config->bundlePolicy = blink::WebRTCBundlePolicy::kMaxBundle; | |
| 346 break; | |
| 347 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat: | |
| 348 blink_config->bundlePolicy = blink::WebRTCBundlePolicy::kMaxCompat; | |
| 349 break; | |
| 350 default: | |
| 351 NOTREACHED(); | |
|
Taylor_Brandstetter
2017/03/02 22:30:45
nit: Don't need default case here.
zhihuang1
2017/03/09 19:13:31
Done.
| |
| 352 } | |
| 353 | |
| 354 switch (webrtc_config.rtcp_mux_policy) { | |
| 355 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate: | |
| 356 blink_config->rtcpMuxPolicy = blink::WebRTCRtcpMuxPolicy::kNegotiate; | |
| 357 break; | |
| 358 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire: | |
| 359 blink_config->rtcpMuxPolicy = blink::WebRTCRtcpMuxPolicy::kRequire; | |
| 360 break; | |
| 361 default: | |
|
Taylor_Brandstetter
2017/03/02 22:30:45
nit: Don't need default case here.
zhihuang1
2017/03/09 19:13:33
Done.
| |
| 362 NOTREACHED(); | |
| 363 } | |
| 364 | |
| 365 blink::WebVector<std::unique_ptr<blink::WebRTCCertificate>> certificates( | |
| 366 webrtc_config.certificates.size()); | |
| 367 for (size_t i = 0; i < webrtc_config.certificates.size(); i++) { | |
| 368 certificates[i] = std::unique_ptr<blink::WebRTCCertificate>( | |
| 369 new RTCCertificate(webrtc_config.certificates[i])); | |
| 370 } | |
| 371 blink_config->certificates = std::move(certificates); | |
| 372 } | |
| 373 | |
| 303 void CopyConstraintsIntoRtcConfiguration( | 374 void CopyConstraintsIntoRtcConfiguration( |
| 304 const blink::WebMediaConstraints constraints, | 375 const blink::WebMediaConstraints constraints, |
| 305 webrtc::PeerConnectionInterface::RTCConfiguration* configuration) { | 376 webrtc::PeerConnectionInterface::RTCConfiguration* configuration) { |
| 306 // Copy info from constraints into configuration, if present. | 377 // Copy info from constraints into configuration, if present. |
| 307 if (constraints.isEmpty()) { | 378 if (constraints.isEmpty()) { |
| 308 return; | 379 return; |
| 309 } | 380 } |
| 310 | 381 |
| 311 bool the_value; | 382 bool the_value; |
| 312 if (GetConstraintValueAsBoolean( | 383 if (GetConstraintValueAsBoolean( |
| (...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1448 blink::WebRTCError blink_error; | 1519 blink::WebRTCError blink_error; |
| 1449 bool ret = | 1520 bool ret = |
| 1450 native_peer_connection_->SetConfiguration(configuration_, &webrtc_error); | 1521 native_peer_connection_->SetConfiguration(configuration_, &webrtc_error); |
| 1451 // The boolean return value is made redundant by the error output param; just | 1522 // The boolean return value is made redundant by the error output param; just |
| 1452 // DCHECK that they're consistent. | 1523 // DCHECK that they're consistent. |
| 1453 DCHECK_EQ(ret, webrtc_error.type() == webrtc::RTCErrorType::NONE); | 1524 DCHECK_EQ(ret, webrtc_error.type() == webrtc::RTCErrorType::NONE); |
| 1454 ConvertToWebKitRTCError(webrtc_error, &blink_error); | 1525 ConvertToWebKitRTCError(webrtc_error, &blink_error); |
| 1455 return blink_error.type(); | 1526 return blink_error.type(); |
| 1456 } | 1527 } |
| 1457 | 1528 |
| 1529 blink::WebRTCConfiguration RTCPeerConnectionHandler::getConfiguration() { | |
| 1530 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1531 webrtc::PeerConnectionInterface::RTCConfiguration webrtc_config = | |
| 1532 native_peer_connection_->GetConfiguration(); | |
| 1533 blink::WebRTCConfiguration blink_config; | |
| 1534 GetBlinkRtcConfiguration(webrtc_config, &blink_config); | |
| 1535 return blink_config; | |
| 1536 } | |
| 1537 | |
| 1458 bool RTCPeerConnectionHandler::addICECandidate( | 1538 bool RTCPeerConnectionHandler::addICECandidate( |
| 1459 const blink::WebRTCVoidRequest& request, | 1539 const blink::WebRTCVoidRequest& request, |
| 1460 const blink::WebRTCICECandidate& candidate) { | 1540 const blink::WebRTCICECandidate& candidate) { |
| 1461 DCHECK(thread_checker_.CalledOnValidThread()); | 1541 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1462 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); | 1542 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); |
| 1463 // Libjingle currently does not accept callbacks for addICECandidate. | 1543 // Libjingle currently does not accept callbacks for addICECandidate. |
| 1464 // For that reason we are going to call callbacks from here. | 1544 // For that reason we are going to call callbacks from here. |
| 1465 | 1545 |
| 1466 // TODO(tommi): Instead of calling addICECandidate here, we can do a | 1546 // TODO(tommi): Instead of calling addICECandidate here, we can do a |
| 1467 // PostTaskAndReply kind of a thing. | 1547 // PostTaskAndReply kind of a thing. |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2005 } | 2085 } |
| 2006 | 2086 |
| 2007 void RTCPeerConnectionHandler::ResetUMAStats() { | 2087 void RTCPeerConnectionHandler::ResetUMAStats() { |
| 2008 DCHECK(thread_checker_.CalledOnValidThread()); | 2088 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2009 num_local_candidates_ipv6_ = 0; | 2089 num_local_candidates_ipv6_ = 0; |
| 2010 num_local_candidates_ipv4_ = 0; | 2090 num_local_candidates_ipv4_ = 0; |
| 2011 ice_connection_checking_start_ = base::TimeTicks(); | 2091 ice_connection_checking_start_ = base::TimeTicks(); |
| 2012 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); | 2092 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); |
| 2013 } | 2093 } |
| 2014 } // namespace content | 2094 } // namespace content |
| OLD | NEW |