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