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; |
257 case blink::WebRTCIceTransportPolicy::kAll: | 259 case blink::WebRTCIceTransportPolicy::kAll: |
258 webrtc_config->type = webrtc::PeerConnectionInterface::kAll; | 260 webrtc_config->type = webrtc::PeerConnectionInterface::kAll; |
259 break; | 261 break; |
260 default: | |
261 NOTREACHED(); | |
262 } | 262 } |
263 | 263 |
264 switch (blink_config.bundlePolicy) { | 264 switch (blink_config.bundlePolicy) { |
265 case blink::WebRTCBundlePolicy::kBalanced: | 265 case blink::WebRTCBundlePolicy::kBalanced: |
266 webrtc_config->bundle_policy = | 266 webrtc_config->bundle_policy = |
267 webrtc::PeerConnectionInterface::kBundlePolicyBalanced; | 267 webrtc::PeerConnectionInterface::kBundlePolicyBalanced; |
268 break; | 268 break; |
269 case blink::WebRTCBundlePolicy::kMaxBundle: | 269 case blink::WebRTCBundlePolicy::kMaxBundle: |
270 webrtc_config->bundle_policy = | 270 webrtc_config->bundle_policy = |
271 webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle; | 271 webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle; |
272 break; | 272 break; |
273 case blink::WebRTCBundlePolicy::kMaxCompat: | 273 case blink::WebRTCBundlePolicy::kMaxCompat: |
274 webrtc_config->bundle_policy = | 274 webrtc_config->bundle_policy = |
275 webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat; | 275 webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat; |
276 break; | 276 break; |
277 default: | |
278 NOTREACHED(); | |
279 } | 277 } |
280 | 278 |
281 switch (blink_config.rtcpMuxPolicy) { | 279 switch (blink_config.rtcpMuxPolicy) { |
282 case blink::WebRTCRtcpMuxPolicy::kNegotiate: | 280 case blink::WebRTCRtcpMuxPolicy::kNegotiate: |
283 webrtc_config->rtcp_mux_policy = | 281 webrtc_config->rtcp_mux_policy = |
284 webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate; | 282 webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate; |
285 break; | 283 break; |
286 case blink::WebRTCRtcpMuxPolicy::kRequire: | 284 case blink::WebRTCRtcpMuxPolicy::kRequire: |
287 webrtc_config->rtcp_mux_policy = | 285 webrtc_config->rtcp_mux_policy = |
288 webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire; | 286 webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire; |
289 break; | 287 break; |
290 default: | |
291 NOTREACHED(); | |
292 } | 288 } |
293 | 289 |
294 webrtc_config->certificates.clear(); | 290 webrtc_config->certificates.clear(); |
295 for (const std::unique_ptr<blink::WebRTCCertificate>& blink_certificate : | 291 for (const std::unique_ptr<blink::WebRTCCertificate>& blink_certificate : |
296 blink_config.certificates) { | 292 blink_config.certificates) { |
297 webrtc_config->certificates.push_back( | 293 webrtc_config->certificates.push_back( |
298 static_cast<RTCCertificate*>(blink_certificate.get()) | 294 static_cast<RTCCertificate*>(blink_certificate.get()) |
299 ->rtcCertificate()); | 295 ->rtcCertificate()); |
300 } | 296 } |
301 | 297 |
302 webrtc_config->ice_candidate_pool_size = blink_config.iceCandidatePoolSize; | 298 webrtc_config->ice_candidate_pool_size = blink_config.iceCandidatePoolSize; |
303 } | 299 } |
304 | 300 |
| 301 blink::WebRTCConfiguration ToBlinkRtcConfiguration( |
| 302 const webrtc::PeerConnectionInterface::RTCConfiguration& webrtc_config) { |
| 303 blink::WebRTCConfiguration blink_config; |
| 304 blink::WebVector<blink::WebRTCIceServer> iceServers( |
| 305 webrtc_config.servers.size()); |
| 306 for (size_t i = 0; i < webrtc_config.servers.size(); ++i) { |
| 307 const webrtc::PeerConnectionInterface::IceServer& ice_server = |
| 308 webrtc_config.servers[i]; |
| 309 blink::WebRTCIceServer blink_server; |
| 310 blink::WebVector<blink::WebURL> blink_urls(ice_server.urls.size()); |
| 311 for (size_t j = 0; j < ice_server.urls.size(); ++j) |
| 312 blink_urls[j] = GURL(ice_server.urls[j]); |
| 313 blink_server.urls = std::move(blink_urls); |
| 314 blink_server.username = blink::WebString::fromUTF8(ice_server.username); |
| 315 blink_server.credential = blink::WebString::fromUTF8(ice_server.password); |
| 316 iceServers[i] = blink_server; |
| 317 } |
| 318 blink_config.iceServers = std::move(iceServers); |
| 319 |
| 320 switch (webrtc_config.type) { |
| 321 case webrtc::PeerConnectionInterface::kNone: |
| 322 blink_config.iceTransportPolicy = blink::WebRTCIceTransportPolicy::kNone; |
| 323 break; |
| 324 case webrtc::PeerConnectionInterface::kRelay: |
| 325 blink_config.iceTransportPolicy = blink::WebRTCIceTransportPolicy::kRelay; |
| 326 break; |
| 327 case webrtc::PeerConnectionInterface::kAll: |
| 328 blink_config.iceTransportPolicy = blink::WebRTCIceTransportPolicy::kAll; |
| 329 break; |
| 330 case webrtc::PeerConnectionInterface::kNoHost: |
| 331 NOTREACHED(); |
| 332 } |
| 333 |
| 334 switch (webrtc_config.bundle_policy) { |
| 335 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced: |
| 336 blink_config.bundlePolicy = blink::WebRTCBundlePolicy::kBalanced; |
| 337 break; |
| 338 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle: |
| 339 blink_config.bundlePolicy = blink::WebRTCBundlePolicy::kMaxBundle; |
| 340 break; |
| 341 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat: |
| 342 blink_config.bundlePolicy = blink::WebRTCBundlePolicy::kMaxCompat; |
| 343 break; |
| 344 } |
| 345 |
| 346 switch (webrtc_config.rtcp_mux_policy) { |
| 347 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate: |
| 348 blink_config.rtcpMuxPolicy = blink::WebRTCRtcpMuxPolicy::kNegotiate; |
| 349 break; |
| 350 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire: |
| 351 blink_config.rtcpMuxPolicy = blink::WebRTCRtcpMuxPolicy::kRequire; |
| 352 break; |
| 353 } |
| 354 |
| 355 blink::WebVector<std::unique_ptr<blink::WebRTCCertificate>> certificates( |
| 356 webrtc_config.certificates.size()); |
| 357 for (size_t i = 0; i < webrtc_config.certificates.size(); ++i) { |
| 358 certificates[i] = |
| 359 base::MakeUnique<RTCCertificate>(webrtc_config.certificates[i]); |
| 360 } |
| 361 blink_config.certificates = std::move(certificates); |
| 362 return blink_config; |
| 363 } |
| 364 |
305 void CopyConstraintsIntoRtcConfiguration( | 365 void CopyConstraintsIntoRtcConfiguration( |
306 const blink::WebMediaConstraints constraints, | 366 const blink::WebMediaConstraints constraints, |
307 webrtc::PeerConnectionInterface::RTCConfiguration* configuration) { | 367 webrtc::PeerConnectionInterface::RTCConfiguration* configuration) { |
308 // Copy info from constraints into configuration, if present. | 368 // Copy info from constraints into configuration, if present. |
309 if (constraints.isEmpty()) { | 369 if (constraints.isEmpty()) { |
310 return; | 370 return; |
311 } | 371 } |
312 | 372 |
313 bool the_value; | 373 bool the_value; |
314 if (GetConstraintValueAsBoolean( | 374 if (GetConstraintValueAsBoolean( |
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1450 blink::WebRTCError blink_error; | 1510 blink::WebRTCError blink_error; |
1451 bool ret = | 1511 bool ret = |
1452 native_peer_connection_->SetConfiguration(configuration_, &webrtc_error); | 1512 native_peer_connection_->SetConfiguration(configuration_, &webrtc_error); |
1453 // The boolean return value is made redundant by the error output param; just | 1513 // The boolean return value is made redundant by the error output param; just |
1454 // DCHECK that they're consistent. | 1514 // DCHECK that they're consistent. |
1455 DCHECK_EQ(ret, webrtc_error.type() == webrtc::RTCErrorType::NONE); | 1515 DCHECK_EQ(ret, webrtc_error.type() == webrtc::RTCErrorType::NONE); |
1456 ConvertToWebKitRTCError(webrtc_error, &blink_error); | 1516 ConvertToWebKitRTCError(webrtc_error, &blink_error); |
1457 return blink_error.type(); | 1517 return blink_error.type(); |
1458 } | 1518 } |
1459 | 1519 |
| 1520 blink::WebRTCConfiguration RTCPeerConnectionHandler::getConfiguration() { |
| 1521 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1522 webrtc::PeerConnectionInterface::RTCConfiguration webrtc_config = |
| 1523 native_peer_connection_->GetConfiguration(); |
| 1524 return ToBlinkRtcConfiguration(webrtc_config); |
| 1525 } |
| 1526 |
1460 bool RTCPeerConnectionHandler::addICECandidate( | 1527 bool RTCPeerConnectionHandler::addICECandidate( |
1461 const blink::WebRTCVoidRequest& request, | 1528 const blink::WebRTCVoidRequest& request, |
1462 const blink::WebRTCICECandidate& candidate) { | 1529 const blink::WebRTCICECandidate& candidate) { |
1463 DCHECK(thread_checker_.CalledOnValidThread()); | 1530 DCHECK(thread_checker_.CalledOnValidThread()); |
1464 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); | 1531 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); |
1465 // Libjingle currently does not accept callbacks for addICECandidate. | 1532 // Libjingle currently does not accept callbacks for addICECandidate. |
1466 // For that reason we are going to call callbacks from here. | 1533 // For that reason we are going to call callbacks from here. |
1467 | 1534 |
1468 // TODO(tommi): Instead of calling addICECandidate here, we can do a | 1535 // TODO(tommi): Instead of calling addICECandidate here, we can do a |
1469 // PostTaskAndReply kind of a thing. | 1536 // PostTaskAndReply kind of a thing. |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2005 } | 2072 } |
2006 | 2073 |
2007 void RTCPeerConnectionHandler::ResetUMAStats() { | 2074 void RTCPeerConnectionHandler::ResetUMAStats() { |
2008 DCHECK(thread_checker_.CalledOnValidThread()); | 2075 DCHECK(thread_checker_.CalledOnValidThread()); |
2009 num_local_candidates_ipv6_ = 0; | 2076 num_local_candidates_ipv6_ = 0; |
2010 num_local_candidates_ipv4_ = 0; | 2077 num_local_candidates_ipv4_ = 0; |
2011 ice_connection_checking_start_ = base::TimeTicks(); | 2078 ice_connection_checking_start_ = base::TimeTicks(); |
2012 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); | 2079 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); |
2013 } | 2080 } |
2014 } // namespace content | 2081 } // namespace content |
OLD | NEW |