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> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 99 } |
100 | 100 |
101 description.initialize(UTF8ToUTF16(native_desc->type()), UTF8ToUTF16(sdp)); | 101 description.initialize(UTF8ToUTF16(native_desc->type()), UTF8ToUTF16(sdp)); |
102 return description; | 102 return description; |
103 } | 103 } |
104 | 104 |
105 // Converter functions from WebKit types to libjingle types. | 105 // Converter functions from WebKit types to libjingle types. |
106 | 106 |
107 static void GetNativeIceServers( | 107 static void GetNativeIceServers( |
108 const WebKit::WebRTCConfiguration& server_configuration, | 108 const WebKit::WebRTCConfiguration& server_configuration, |
109 webrtc::JsepInterface::IceServers* servers) { | 109 webrtc::PeerConnectionInterface::IceServers* servers) { |
110 if (server_configuration.isNull() || !servers) | 110 if (server_configuration.isNull() || !servers) |
111 return; | 111 return; |
112 for (size_t i = 0; i < server_configuration.numberOfServers(); ++i) { | 112 for (size_t i = 0; i < server_configuration.numberOfServers(); ++i) { |
113 webrtc::JsepInterface::IceServer server; | 113 webrtc::PeerConnectionInterface::IceServer server; |
114 const WebKit::WebRTCICEServer& webkit_server = | 114 const WebKit::WebRTCICEServer& webkit_server = |
115 server_configuration.server(i); | 115 server_configuration.server(i); |
116 server.password = UTF16ToUTF8(webkit_server.credential()); | 116 server.password = UTF16ToUTF8(webkit_server.credential()); |
117 server.uri = webkit_server.uri().spec(); | 117 server.uri = webkit_server.uri().spec(); |
118 servers->push_back(server); | 118 servers->push_back(server); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 class SessionDescriptionRequestTracker { | 122 class SessionDescriptionRequestTracker { |
123 public: | 123 public: |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 328 } |
329 | 329 |
330 bool RTCPeerConnectionHandler::initialize( | 330 bool RTCPeerConnectionHandler::initialize( |
331 const WebKit::WebRTCConfiguration& server_configuration, | 331 const WebKit::WebRTCConfiguration& server_configuration, |
332 const WebKit::WebMediaConstraints& options) { | 332 const WebKit::WebMediaConstraints& options) { |
333 DCHECK(frame_); | 333 DCHECK(frame_); |
334 | 334 |
335 peer_connection_tracker_ = | 335 peer_connection_tracker_ = |
336 RenderThreadImpl::current()->peer_connection_tracker(); | 336 RenderThreadImpl::current()->peer_connection_tracker(); |
337 | 337 |
338 webrtc::JsepInterface::IceServers servers; | 338 webrtc::PeerConnectionInterface::IceServers servers; |
339 GetNativeIceServers(server_configuration, &servers); | 339 GetNativeIceServers(server_configuration, &servers); |
340 | 340 |
341 RTCMediaConstraints constraints(options); | 341 RTCMediaConstraints constraints(options); |
342 native_peer_connection_ = | 342 native_peer_connection_ = |
343 dependency_factory_->CreatePeerConnection( | 343 dependency_factory_->CreatePeerConnection( |
344 servers, &constraints, frame_, this); | 344 servers, &constraints, frame_, this); |
345 if (!native_peer_connection_) { | 345 if (!native_peer_connection_) { |
346 LOG(ERROR) << "Failed to initialize native PeerConnection."; | 346 LOG(ERROR) << "Failed to initialize native PeerConnection."; |
347 return false; | 347 return false; |
348 } | 348 } |
349 if (peer_connection_tracker_) | 349 if (peer_connection_tracker_) |
350 peer_connection_tracker_->RegisterPeerConnection( | 350 peer_connection_tracker_->RegisterPeerConnection( |
351 this, servers, constraints, frame_); | 351 this, servers, constraints, frame_); |
352 | 352 |
353 return true; | 353 return true; |
354 } | 354 } |
355 | 355 |
356 bool RTCPeerConnectionHandler::InitializeForTest( | 356 bool RTCPeerConnectionHandler::InitializeForTest( |
357 const WebKit::WebRTCConfiguration& server_configuration, | 357 const WebKit::WebRTCConfiguration& server_configuration, |
358 const WebKit::WebMediaConstraints& options, | 358 const WebKit::WebMediaConstraints& options, |
359 PeerConnectionTracker* peer_connection_tracker) { | 359 PeerConnectionTracker* peer_connection_tracker) { |
360 webrtc::JsepInterface::IceServers servers; | 360 webrtc::PeerConnectionInterface::IceServers servers; |
361 GetNativeIceServers(server_configuration, &servers); | 361 GetNativeIceServers(server_configuration, &servers); |
362 | 362 |
363 RTCMediaConstraints constraints(options); | 363 RTCMediaConstraints constraints(options); |
364 native_peer_connection_ = | 364 native_peer_connection_ = |
365 dependency_factory_->CreatePeerConnection( | 365 dependency_factory_->CreatePeerConnection( |
366 servers, &constraints, NULL, this); | 366 servers, &constraints, NULL, this); |
367 if (!native_peer_connection_) { | 367 if (!native_peer_connection_) { |
368 LOG(ERROR) << "Failed to initialize native PeerConnection."; | 368 LOG(ERROR) << "Failed to initialize native PeerConnection."; |
369 return false; | 369 return false; |
370 } | 370 } |
(...skipping 23 matching lines...) Expand all Loading... |
394 RTCMediaConstraints constraints(options); | 394 RTCMediaConstraints constraints(options); |
395 native_peer_connection_->CreateAnswer(description_request, &constraints); | 395 native_peer_connection_->CreateAnswer(description_request, &constraints); |
396 | 396 |
397 if (peer_connection_tracker_) | 397 if (peer_connection_tracker_) |
398 peer_connection_tracker_->TrackCreateAnswer(this, constraints); | 398 peer_connection_tracker_->TrackCreateAnswer(this, constraints); |
399 } | 399 } |
400 | 400 |
401 void RTCPeerConnectionHandler::setLocalDescription( | 401 void RTCPeerConnectionHandler::setLocalDescription( |
402 const WebKit::WebRTCVoidRequest& request, | 402 const WebKit::WebRTCVoidRequest& request, |
403 const WebKit::WebRTCSessionDescription& description) { | 403 const WebKit::WebRTCSessionDescription& description) { |
| 404 webrtc::SdpParseError error; |
404 webrtc::SessionDescriptionInterface* native_desc = | 405 webrtc::SessionDescriptionInterface* native_desc = |
405 CreateNativeSessionDescription(description); | 406 CreateNativeSessionDescription(description, &error); |
406 if (!native_desc) { | 407 if (!native_desc) { |
407 const char kReason[] = "Failed to parse SessionDescription."; | 408 std::string reason_str = "Failed to parse SessionDescription. "; |
408 LOG(ERROR) << kReason; | 409 reason_str.append(error.line); |
409 WebKit::WebString reason(kReason); | 410 reason_str.append(" "); |
410 request.requestFailed(reason); | 411 reason_str.append(error.description); |
| 412 LOG(ERROR) << reason_str; |
| 413 request.requestFailed(WebKit::WebString::fromUTF8(reason_str)); |
411 return; | 414 return; |
412 } | 415 } |
413 if (peer_connection_tracker_) | 416 if (peer_connection_tracker_) |
414 peer_connection_tracker_->TrackSetSessionDescription( | 417 peer_connection_tracker_->TrackSetSessionDescription( |
415 this, native_desc, PeerConnectionTracker::SOURCE_LOCAL); | 418 this, native_desc, PeerConnectionTracker::SOURCE_LOCAL); |
416 | 419 |
417 scoped_refptr<SetSessionDescriptionRequest> set_request( | 420 scoped_refptr<SetSessionDescriptionRequest> set_request( |
418 new talk_base::RefCountedObject<SetSessionDescriptionRequest>( | 421 new talk_base::RefCountedObject<SetSessionDescriptionRequest>( |
419 request, this, PeerConnectionTracker::ACTION_SET_LOCAL_DESCRIPTION)); | 422 request, this, PeerConnectionTracker::ACTION_SET_LOCAL_DESCRIPTION)); |
420 native_peer_connection_->SetLocalDescription(set_request, native_desc); | 423 native_peer_connection_->SetLocalDescription(set_request, native_desc); |
421 } | 424 } |
422 | 425 |
423 void RTCPeerConnectionHandler::setRemoteDescription( | 426 void RTCPeerConnectionHandler::setRemoteDescription( |
424 const WebKit::WebRTCVoidRequest& request, | 427 const WebKit::WebRTCVoidRequest& request, |
425 const WebKit::WebRTCSessionDescription& description) { | 428 const WebKit::WebRTCSessionDescription& description) { |
| 429 webrtc::SdpParseError error; |
426 webrtc::SessionDescriptionInterface* native_desc = | 430 webrtc::SessionDescriptionInterface* native_desc = |
427 CreateNativeSessionDescription(description); | 431 CreateNativeSessionDescription(description, &error); |
428 if (!native_desc) { | 432 if (!native_desc) { |
429 const char kReason[] = "Failed to parse SessionDescription."; | 433 std::string reason_str = "Failed to parse SessionDescription. "; |
430 LOG(ERROR) << kReason; | 434 reason_str.append(error.line); |
431 WebKit::WebString reason(kReason); | 435 reason_str.append(" "); |
432 request.requestFailed(reason); | 436 reason_str.append(error.description); |
| 437 LOG(ERROR) << reason_str; |
| 438 request.requestFailed(WebKit::WebString::fromUTF8(reason_str)); |
433 return; | 439 return; |
434 } | 440 } |
435 if (peer_connection_tracker_) | 441 if (peer_connection_tracker_) |
436 peer_connection_tracker_->TrackSetSessionDescription( | 442 peer_connection_tracker_->TrackSetSessionDescription( |
437 this, native_desc, PeerConnectionTracker::SOURCE_REMOTE); | 443 this, native_desc, PeerConnectionTracker::SOURCE_REMOTE); |
438 | 444 |
439 scoped_refptr<SetSessionDescriptionRequest> set_request( | 445 scoped_refptr<SetSessionDescriptionRequest> set_request( |
440 new talk_base::RefCountedObject<SetSessionDescriptionRequest>( | 446 new talk_base::RefCountedObject<SetSessionDescriptionRequest>( |
441 request, this, PeerConnectionTracker::ACTION_SET_REMOTE_DESCRIPTION)); | 447 request, this, PeerConnectionTracker::ACTION_SET_REMOTE_DESCRIPTION)); |
442 native_peer_connection_->SetRemoteDescription(set_request, native_desc); | 448 native_peer_connection_->SetRemoteDescription(set_request, native_desc); |
(...skipping 13 matching lines...) Expand all Loading... |
456 const webrtc::SessionDescriptionInterface* native_desc = | 462 const webrtc::SessionDescriptionInterface* native_desc = |
457 native_peer_connection_->remote_description(); | 463 native_peer_connection_->remote_description(); |
458 WebKit::WebRTCSessionDescription description = | 464 WebKit::WebRTCSessionDescription description = |
459 CreateWebKitSessionDescription(native_desc); | 465 CreateWebKitSessionDescription(native_desc); |
460 return description; | 466 return description; |
461 } | 467 } |
462 | 468 |
463 bool RTCPeerConnectionHandler::updateICE( | 469 bool RTCPeerConnectionHandler::updateICE( |
464 const WebKit::WebRTCConfiguration& server_configuration, | 470 const WebKit::WebRTCConfiguration& server_configuration, |
465 const WebKit::WebMediaConstraints& options) { | 471 const WebKit::WebMediaConstraints& options) { |
466 webrtc::JsepInterface::IceServers servers; | 472 webrtc::PeerConnectionInterface::IceServers servers; |
467 GetNativeIceServers(server_configuration, &servers); | 473 GetNativeIceServers(server_configuration, &servers); |
468 RTCMediaConstraints constraints(options); | 474 RTCMediaConstraints constraints(options); |
469 | 475 |
470 if (peer_connection_tracker_) | 476 if (peer_connection_tracker_) |
471 peer_connection_tracker_->TrackUpdateIce(this, servers, constraints); | 477 peer_connection_tracker_->TrackUpdateIce(this, servers, constraints); |
472 | 478 |
473 return native_peer_connection_->UpdateIce(servers, | 479 return native_peer_connection_->UpdateIce(servers, |
474 &constraints); | 480 &constraints); |
475 } | 481 } |
476 | 482 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 void RTCPeerConnectionHandler::OnRenegotiationNeeded() { | 727 void RTCPeerConnectionHandler::OnRenegotiationNeeded() { |
722 client_->negotiationNeeded(); | 728 client_->negotiationNeeded(); |
723 } | 729 } |
724 | 730 |
725 PeerConnectionTracker* RTCPeerConnectionHandler::peer_connection_tracker() { | 731 PeerConnectionTracker* RTCPeerConnectionHandler::peer_connection_tracker() { |
726 return peer_connection_tracker_; | 732 return peer_connection_tracker_; |
727 } | 733 } |
728 | 734 |
729 webrtc::SessionDescriptionInterface* | 735 webrtc::SessionDescriptionInterface* |
730 RTCPeerConnectionHandler::CreateNativeSessionDescription( | 736 RTCPeerConnectionHandler::CreateNativeSessionDescription( |
731 const WebKit::WebRTCSessionDescription& description) { | 737 const WebKit::WebRTCSessionDescription& description, |
| 738 webrtc::SdpParseError* error) { |
732 std::string sdp = UTF16ToUTF8(description.sdp()); | 739 std::string sdp = UTF16ToUTF8(description.sdp()); |
733 std::string type = UTF16ToUTF8(description.type()); | 740 std::string type = UTF16ToUTF8(description.type()); |
734 webrtc::SessionDescriptionInterface* native_desc = | 741 webrtc::SessionDescriptionInterface* native_desc = |
735 dependency_factory_->CreateSessionDescription(type, sdp); | 742 dependency_factory_->CreateSessionDescription(type, sdp, error); |
736 | 743 |
737 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." | 744 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." |
738 << " Type: " << type << " SDP: " << sdp; | 745 << " Type: " << type << " SDP: " << sdp; |
739 | 746 |
740 return native_desc; | 747 return native_desc; |
741 } | 748 } |
742 | 749 |
743 } // namespace content | 750 } // namespace content |
OLD | NEW |