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: | |
tommi (sloooow) - chröme
2017/03/09 19:37:07
just checking - will compilation catch it for us i
Taylor_Brandstetter
2017/03/09 22:54:29
Yes, from the "Wswitch" warning. That way it's a c
| |
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 GetBlinkRtcConfiguration( | |
dcheng
2017/03/09 21:36:54
Nit: might be more clearly named ToBlinkRtcConfigu
zhihuang1
2017/03/10 03:20:43
Done.
| |
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++) { | |
tommi (sloooow) - chröme
2017/03/09 19:37:07
++i
zhihuang1
2017/03/10 03:20:42
Done.
| |
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++) { | |
tommi (sloooow) - chröme
2017/03/09 19:37:07
++j
Also, this code tends to not use {} for singl
zhihuang1
2017/03/10 03:20:43
Done.
| |
310 blink_urls[j] = (GURL(ice_server.urls[j])); | |
dcheng
2017/03/09 21:36:54
Nit: no () around GURL()
zhihuang1
2017/03/10 03:20:43
Done.
| |
311 } | |
312 blink_server.urls = std::move(blink_urls); | |
313 blink_server.username = blink::WebString::fromUTF8(ice_server.username); | |
314 blink_server.credential = blink::WebString::fromUTF8(ice_server.password); | |
315 iceServers[i] = blink_server; | |
316 } | |
317 blink_config->iceServers = std::move(iceServers); | |
318 | |
319 switch (webrtc_config.type) { | |
320 case webrtc::PeerConnectionInterface::kNone: | |
321 blink_config->iceTransportPolicy = blink::WebRTCIceTransportPolicy::kNone; | |
322 break; | |
323 case webrtc::PeerConnectionInterface::kRelay: | |
324 blink_config->iceTransportPolicy = | |
325 blink::WebRTCIceTransportPolicy::kRelay; | |
326 break; | |
327 case webrtc::PeerConnectionInterface::kAll: | |
328 blink_config->iceTransportPolicy = blink::WebRTCIceTransportPolicy::kAll; | |
329 break; | |
330 default: | |
tommi (sloooow) - chröme
2017/03/09 19:37:07
needed? (since similar cases were deleted above).
zhihuang1
2017/03/10 03:20:43
I'll remove these.
| |
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 default: | |
345 NOTREACHED(); | |
346 } | |
347 | |
348 switch (webrtc_config.rtcp_mux_policy) { | |
349 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate: | |
350 blink_config->rtcpMuxPolicy = blink::WebRTCRtcpMuxPolicy::kNegotiate; | |
351 break; | |
352 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire: | |
353 blink_config->rtcpMuxPolicy = blink::WebRTCRtcpMuxPolicy::kRequire; | |
354 break; | |
355 default: | |
356 NOTREACHED(); | |
357 } | |
358 | |
359 blink::WebVector<std::unique_ptr<blink::WebRTCCertificate>> certificates( | |
360 webrtc_config.certificates.size()); | |
361 for (size_t i = 0; i < webrtc_config.certificates.size(); i++) { | |
tommi (sloooow) - chröme
2017/03/09 19:37:07
++i
zhihuang1
2017/03/10 03:20:43
Done.
| |
362 certificates[i] = std::unique_ptr<blink::WebRTCCertificate>( | |
dcheng
2017/03/09 21:36:54
Nit: base::MakeUnique<WebRTCCertificate>(...)
zhihuang1
2017/03/10 03:20:43
Done.
| |
363 new RTCCertificate(webrtc_config.certificates[i])); | |
364 } | |
365 blink_config->certificates = std::move(certificates); | |
366 } | |
367 | |
303 void CopyConstraintsIntoRtcConfiguration( | 368 void CopyConstraintsIntoRtcConfiguration( |
304 const blink::WebMediaConstraints constraints, | 369 const blink::WebMediaConstraints constraints, |
305 webrtc::PeerConnectionInterface::RTCConfiguration* configuration) { | 370 webrtc::PeerConnectionInterface::RTCConfiguration* configuration) { |
306 // Copy info from constraints into configuration, if present. | 371 // Copy info from constraints into configuration, if present. |
307 if (constraints.isEmpty()) { | 372 if (constraints.isEmpty()) { |
308 return; | 373 return; |
309 } | 374 } |
310 | 375 |
311 bool the_value; | 376 bool the_value; |
312 if (GetConstraintValueAsBoolean( | 377 if (GetConstraintValueAsBoolean( |
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1448 blink::WebRTCError blink_error; | 1513 blink::WebRTCError blink_error; |
1449 bool ret = | 1514 bool ret = |
1450 native_peer_connection_->SetConfiguration(configuration_, &webrtc_error); | 1515 native_peer_connection_->SetConfiguration(configuration_, &webrtc_error); |
1451 // The boolean return value is made redundant by the error output param; just | 1516 // The boolean return value is made redundant by the error output param; just |
1452 // DCHECK that they're consistent. | 1517 // DCHECK that they're consistent. |
1453 DCHECK_EQ(ret, webrtc_error.type() == webrtc::RTCErrorType::NONE); | 1518 DCHECK_EQ(ret, webrtc_error.type() == webrtc::RTCErrorType::NONE); |
1454 ConvertToWebKitRTCError(webrtc_error, &blink_error); | 1519 ConvertToWebKitRTCError(webrtc_error, &blink_error); |
1455 return blink_error.type(); | 1520 return blink_error.type(); |
1456 } | 1521 } |
1457 | 1522 |
1523 blink::WebRTCConfiguration RTCPeerConnectionHandler::getConfiguration() { | |
1524 DCHECK(thread_checker_.CalledOnValidThread()); | |
1525 webrtc::PeerConnectionInterface::RTCConfiguration webrtc_config = | |
1526 native_peer_connection_->GetConfiguration(); | |
1527 blink::WebRTCConfiguration blink_config; | |
1528 GetBlinkRtcConfiguration(webrtc_config, &blink_config); | |
1529 return blink_config; | |
1530 } | |
1531 | |
1458 bool RTCPeerConnectionHandler::addICECandidate( | 1532 bool RTCPeerConnectionHandler::addICECandidate( |
1459 const blink::WebRTCVoidRequest& request, | 1533 const blink::WebRTCVoidRequest& request, |
1460 const blink::WebRTCICECandidate& candidate) { | 1534 const blink::WebRTCICECandidate& candidate) { |
1461 DCHECK(thread_checker_.CalledOnValidThread()); | 1535 DCHECK(thread_checker_.CalledOnValidThread()); |
1462 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); | 1536 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); |
1463 // Libjingle currently does not accept callbacks for addICECandidate. | 1537 // Libjingle currently does not accept callbacks for addICECandidate. |
1464 // For that reason we are going to call callbacks from here. | 1538 // For that reason we are going to call callbacks from here. |
1465 | 1539 |
1466 // TODO(tommi): Instead of calling addICECandidate here, we can do a | 1540 // TODO(tommi): Instead of calling addICECandidate here, we can do a |
1467 // PostTaskAndReply kind of a thing. | 1541 // PostTaskAndReply kind of a thing. |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2003 } | 2077 } |
2004 | 2078 |
2005 void RTCPeerConnectionHandler::ResetUMAStats() { | 2079 void RTCPeerConnectionHandler::ResetUMAStats() { |
2006 DCHECK(thread_checker_.CalledOnValidThread()); | 2080 DCHECK(thread_checker_.CalledOnValidThread()); |
2007 num_local_candidates_ipv6_ = 0; | 2081 num_local_candidates_ipv6_ = 0; |
2008 num_local_candidates_ipv4_ = 0; | 2082 num_local_candidates_ipv4_ = 0; |
2009 ice_connection_checking_start_ = base::TimeTicks(); | 2083 ice_connection_checking_start_ = base::TimeTicks(); |
2010 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); | 2084 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); |
2011 } | 2085 } |
2012 } // namespace content | 2086 } // namespace content |
OLD | NEW |