| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 LOG(ERROR) << "Native session description is null."; | 114 LOG(ERROR) << "Native session description is null."; |
| 115 return description; | 115 return description; |
| 116 } | 116 } |
| 117 | 117 |
| 118 std::string sdp; | 118 std::string sdp; |
| 119 if (!native_desc->ToString(&sdp)) { | 119 if (!native_desc->ToString(&sdp)) { |
| 120 LOG(ERROR) << "Failed to get SDP string of native session description."; | 120 LOG(ERROR) << "Failed to get SDP string of native session description."; |
| 121 return description; | 121 return description; |
| 122 } | 122 } |
| 123 | 123 |
| 124 description.initialize(UTF8ToUTF16(native_desc->type()), UTF8ToUTF16(sdp)); | 124 description.initialize(base::UTF8ToUTF16(native_desc->type()), |
| 125 base::UTF8ToUTF16(sdp)); |
| 125 return description; | 126 return description; |
| 126 } | 127 } |
| 127 | 128 |
| 128 // Converter functions from WebKit types to libjingle types. | 129 // Converter functions from WebKit types to libjingle types. |
| 129 | 130 |
| 130 static void GetNativeIceServers( | 131 static void GetNativeIceServers( |
| 131 const blink::WebRTCConfiguration& server_configuration, | 132 const blink::WebRTCConfiguration& server_configuration, |
| 132 webrtc::PeerConnectionInterface::IceServers* servers) { | 133 webrtc::PeerConnectionInterface::IceServers* servers) { |
| 133 if (server_configuration.isNull() || !servers) | 134 if (server_configuration.isNull() || !servers) |
| 134 return; | 135 return; |
| 135 for (size_t i = 0; i < server_configuration.numberOfServers(); ++i) { | 136 for (size_t i = 0; i < server_configuration.numberOfServers(); ++i) { |
| 136 webrtc::PeerConnectionInterface::IceServer server; | 137 webrtc::PeerConnectionInterface::IceServer server; |
| 137 const blink::WebRTCICEServer& webkit_server = | 138 const blink::WebRTCICEServer& webkit_server = |
| 138 server_configuration.server(i); | 139 server_configuration.server(i); |
| 139 server.username = UTF16ToUTF8(webkit_server.username()); | 140 server.username = base::UTF16ToUTF8(webkit_server.username()); |
| 140 server.password = UTF16ToUTF8(webkit_server.credential()); | 141 server.password = base::UTF16ToUTF8(webkit_server.credential()); |
| 141 server.uri = webkit_server.uri().spec(); | 142 server.uri = webkit_server.uri().spec(); |
| 142 servers->push_back(server); | 143 servers->push_back(server); |
| 143 } | 144 } |
| 144 } | 145 } |
| 145 | 146 |
| 146 class SessionDescriptionRequestTracker { | 147 class SessionDescriptionRequestTracker { |
| 147 public: | 148 public: |
| 148 SessionDescriptionRequestTracker(RTCPeerConnectionHandler* handler, | 149 SessionDescriptionRequestTracker(RTCPeerConnectionHandler* handler, |
| 149 PeerConnectionTracker::Action action) | 150 PeerConnectionTracker::Action action) |
| 150 : handler_(handler), action_(action) {} | 151 : handler_(handler), action_(action) {} |
| (...skipping 30 matching lines...) Expand all Loading... |
| 181 RTCPeerConnectionHandler* handler, | 182 RTCPeerConnectionHandler* handler, |
| 182 PeerConnectionTracker::Action action) | 183 PeerConnectionTracker::Action action) |
| 183 : webkit_request_(request), tracker_(handler, action) {} | 184 : webkit_request_(request), tracker_(handler, action) {} |
| 184 | 185 |
| 185 virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc) OVERRIDE { | 186 virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc) OVERRIDE { |
| 186 tracker_.TrackOnSuccess(desc); | 187 tracker_.TrackOnSuccess(desc); |
| 187 webkit_request_.requestSucceeded(CreateWebKitSessionDescription(desc)); | 188 webkit_request_.requestSucceeded(CreateWebKitSessionDescription(desc)); |
| 188 } | 189 } |
| 189 virtual void OnFailure(const std::string& error) OVERRIDE { | 190 virtual void OnFailure(const std::string& error) OVERRIDE { |
| 190 tracker_.TrackOnFailure(error); | 191 tracker_.TrackOnFailure(error); |
| 191 webkit_request_.requestFailed(UTF8ToUTF16(error)); | 192 webkit_request_.requestFailed(base::UTF8ToUTF16(error)); |
| 192 } | 193 } |
| 193 | 194 |
| 194 protected: | 195 protected: |
| 195 virtual ~CreateSessionDescriptionRequest() {} | 196 virtual ~CreateSessionDescriptionRequest() {} |
| 196 | 197 |
| 197 private: | 198 private: |
| 198 blink::WebRTCSessionDescriptionRequest webkit_request_; | 199 blink::WebRTCSessionDescriptionRequest webkit_request_; |
| 199 SessionDescriptionRequestTracker tracker_; | 200 SessionDescriptionRequestTracker tracker_; |
| 200 }; | 201 }; |
| 201 | 202 |
| 202 // Class mapping responses from calls to libjingle | 203 // Class mapping responses from calls to libjingle |
| 203 // SetLocalDescription/SetRemoteDescription and a blink::WebRTCVoidRequest. | 204 // SetLocalDescription/SetRemoteDescription and a blink::WebRTCVoidRequest. |
| 204 class SetSessionDescriptionRequest | 205 class SetSessionDescriptionRequest |
| 205 : public webrtc::SetSessionDescriptionObserver { | 206 : public webrtc::SetSessionDescriptionObserver { |
| 206 public: | 207 public: |
| 207 explicit SetSessionDescriptionRequest( | 208 explicit SetSessionDescriptionRequest( |
| 208 const blink::WebRTCVoidRequest& request, | 209 const blink::WebRTCVoidRequest& request, |
| 209 RTCPeerConnectionHandler* handler, | 210 RTCPeerConnectionHandler* handler, |
| 210 PeerConnectionTracker::Action action) | 211 PeerConnectionTracker::Action action) |
| 211 : webkit_request_(request), tracker_(handler, action) {} | 212 : webkit_request_(request), tracker_(handler, action) {} |
| 212 | 213 |
| 213 virtual void OnSuccess() OVERRIDE { | 214 virtual void OnSuccess() OVERRIDE { |
| 214 tracker_.TrackOnSuccess(NULL); | 215 tracker_.TrackOnSuccess(NULL); |
| 215 webkit_request_.requestSucceeded(); | 216 webkit_request_.requestSucceeded(); |
| 216 } | 217 } |
| 217 virtual void OnFailure(const std::string& error) OVERRIDE { | 218 virtual void OnFailure(const std::string& error) OVERRIDE { |
| 218 tracker_.TrackOnFailure(error); | 219 tracker_.TrackOnFailure(error); |
| 219 webkit_request_.requestFailed(UTF8ToUTF16(error)); | 220 webkit_request_.requestFailed(base::UTF8ToUTF16(error)); |
| 220 } | 221 } |
| 221 | 222 |
| 222 protected: | 223 protected: |
| 223 virtual ~SetSessionDescriptionRequest() {} | 224 virtual ~SetSessionDescriptionRequest() {} |
| 224 | 225 |
| 225 private: | 226 private: |
| 226 blink::WebRTCVoidRequest webkit_request_; | 227 blink::WebRTCVoidRequest webkit_request_; |
| 227 SessionDescriptionRequestTracker tracker_; | 228 SessionDescriptionRequestTracker tracker_; |
| 228 }; | 229 }; |
| 229 | 230 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 base::Bind(&RTCPeerConnectionHandler::OnaddICECandidateResult, | 501 base::Bind(&RTCPeerConnectionHandler::OnaddICECandidateResult, |
| 501 base::Unretained(this), request, result)); | 502 base::Unretained(this), request, result)); |
| 502 // On failure callback will be triggered. | 503 // On failure callback will be triggered. |
| 503 return true; | 504 return true; |
| 504 } | 505 } |
| 505 | 506 |
| 506 bool RTCPeerConnectionHandler::addICECandidate( | 507 bool RTCPeerConnectionHandler::addICECandidate( |
| 507 const blink::WebRTCICECandidate& candidate) { | 508 const blink::WebRTCICECandidate& candidate) { |
| 508 scoped_ptr<webrtc::IceCandidateInterface> native_candidate( | 509 scoped_ptr<webrtc::IceCandidateInterface> native_candidate( |
| 509 dependency_factory_->CreateIceCandidate( | 510 dependency_factory_->CreateIceCandidate( |
| 510 UTF16ToUTF8(candidate.sdpMid()), | 511 base::UTF16ToUTF8(candidate.sdpMid()), |
| 511 candidate.sdpMLineIndex(), | 512 candidate.sdpMLineIndex(), |
| 512 UTF16ToUTF8(candidate.candidate()))); | 513 base::UTF16ToUTF8(candidate.candidate()))); |
| 513 if (!native_candidate) { | 514 if (!native_candidate) { |
| 514 LOG(ERROR) << "Could not create native ICE candidate."; | 515 LOG(ERROR) << "Could not create native ICE candidate."; |
| 515 return false; | 516 return false; |
| 516 } | 517 } |
| 517 | 518 |
| 518 bool return_value = | 519 bool return_value = |
| 519 native_peer_connection_->AddIceCandidate(native_candidate.get()); | 520 native_peer_connection_->AddIceCandidate(native_candidate.get()); |
| 520 LOG_IF(ERROR, !return_value) << "Error processing ICE candidate."; | 521 LOG_IF(ERROR, !return_value) << "Error processing ICE candidate."; |
| 521 | 522 |
| 522 if (peer_connection_tracker_) | 523 if (peer_connection_tracker_) |
| 523 peer_connection_tracker_->TrackAddIceCandidate( | 524 peer_connection_tracker_->TrackAddIceCandidate( |
| 524 this, candidate, PeerConnectionTracker::SOURCE_REMOTE); | 525 this, candidate, PeerConnectionTracker::SOURCE_REMOTE); |
| 525 | 526 |
| 526 return return_value; | 527 return return_value; |
| 527 } | 528 } |
| 528 | 529 |
| 529 void RTCPeerConnectionHandler::OnaddICECandidateResult( | 530 void RTCPeerConnectionHandler::OnaddICECandidateResult( |
| 530 const blink::WebRTCVoidRequest& webkit_request, bool result) { | 531 const blink::WebRTCVoidRequest& webkit_request, bool result) { |
| 531 if (!result) { | 532 if (!result) { |
| 532 // We don't have the actual error code from the libjingle, so for now | 533 // We don't have the actual error code from the libjingle, so for now |
| 533 // using a generic error string. | 534 // using a generic error string. |
| 534 return webkit_request.requestFailed( | 535 return webkit_request.requestFailed( |
| 535 UTF8ToUTF16("Error processing ICE candidate")); | 536 base::UTF8ToUTF16("Error processing ICE candidate")); |
| 536 } | 537 } |
| 537 | 538 |
| 538 return webkit_request.requestSucceeded(); | 539 return webkit_request.requestSucceeded(); |
| 539 } | 540 } |
| 540 | 541 |
| 541 bool RTCPeerConnectionHandler::addStream( | 542 bool RTCPeerConnectionHandler::addStream( |
| 542 const blink::WebMediaStream& stream, | 543 const blink::WebMediaStream& stream, |
| 543 const blink::WebMediaConstraints& options) { | 544 const blink::WebMediaConstraints& options) { |
| 544 RTCMediaConstraints constraints(options); | 545 RTCMediaConstraints constraints(options); |
| 545 | 546 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 DVLOG(1) << "GetStats failed."; | 601 DVLOG(1) << "GetStats failed."; |
| 601 // TODO(hta): Consider how to get an error back. | 602 // TODO(hta): Consider how to get an error back. |
| 602 std::vector<webrtc::StatsReport> no_reports; | 603 std::vector<webrtc::StatsReport> no_reports; |
| 603 observer->OnComplete(no_reports); | 604 observer->OnComplete(no_reports); |
| 604 return; | 605 return; |
| 605 } | 606 } |
| 606 } | 607 } |
| 607 | 608 |
| 608 blink::WebRTCDataChannelHandler* RTCPeerConnectionHandler::createDataChannel( | 609 blink::WebRTCDataChannelHandler* RTCPeerConnectionHandler::createDataChannel( |
| 609 const blink::WebString& label, const blink::WebRTCDataChannelInit& init) { | 610 const blink::WebString& label, const blink::WebRTCDataChannelInit& init) { |
| 610 DVLOG(1) << "createDataChannel label " << UTF16ToUTF8(label); | 611 DVLOG(1) << "createDataChannel label " << base::UTF16ToUTF8(label); |
| 611 | 612 |
| 612 webrtc::DataChannelInit config; | 613 webrtc::DataChannelInit config; |
| 613 // TODO(jiayl): remove the deprecated reliable field once Libjingle is updated | 614 // TODO(jiayl): remove the deprecated reliable field once Libjingle is updated |
| 614 // to handle that. | 615 // to handle that. |
| 615 config.reliable = false; | 616 config.reliable = false; |
| 616 config.id = init.id; | 617 config.id = init.id; |
| 617 config.ordered = init.ordered; | 618 config.ordered = init.ordered; |
| 618 config.negotiated = init.negotiated; | 619 config.negotiated = init.negotiated; |
| 619 config.maxRetransmits = init.maxRetransmits; | 620 config.maxRetransmits = init.maxRetransmits; |
| 620 config.maxRetransmitTime = init.maxRetransmitTime; | 621 config.maxRetransmitTime = init.maxRetransmitTime; |
| 621 config.protocol = UTF16ToUTF8(init.protocol); | 622 config.protocol = base::UTF16ToUTF8(init.protocol); |
| 622 | 623 |
| 623 talk_base::scoped_refptr<webrtc::DataChannelInterface> webrtc_channel( | 624 talk_base::scoped_refptr<webrtc::DataChannelInterface> webrtc_channel( |
| 624 native_peer_connection_->CreateDataChannel(UTF16ToUTF8(label), &config)); | 625 native_peer_connection_->CreateDataChannel(base::UTF16ToUTF8(label), |
| 626 &config)); |
| 625 if (!webrtc_channel) { | 627 if (!webrtc_channel) { |
| 626 DLOG(ERROR) << "Could not create native data channel."; | 628 DLOG(ERROR) << "Could not create native data channel."; |
| 627 return NULL; | 629 return NULL; |
| 628 } | 630 } |
| 629 if (peer_connection_tracker_) | 631 if (peer_connection_tracker_) |
| 630 peer_connection_tracker_->TrackCreateDataChannel( | 632 peer_connection_tracker_->TrackCreateDataChannel( |
| 631 this, webrtc_channel.get(), PeerConnectionTracker::SOURCE_LOCAL); | 633 this, webrtc_channel.get(), PeerConnectionTracker::SOURCE_LOCAL); |
| 632 | 634 |
| 633 return new RtcDataChannelHandler(webrtc_channel); | 635 return new RtcDataChannelHandler(webrtc_channel); |
| 634 } | 636 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 | 751 |
| 750 void RTCPeerConnectionHandler::OnIceCandidate( | 752 void RTCPeerConnectionHandler::OnIceCandidate( |
| 751 const webrtc::IceCandidateInterface* candidate) { | 753 const webrtc::IceCandidateInterface* candidate) { |
| 752 DCHECK(candidate); | 754 DCHECK(candidate); |
| 753 std::string sdp; | 755 std::string sdp; |
| 754 if (!candidate->ToString(&sdp)) { | 756 if (!candidate->ToString(&sdp)) { |
| 755 NOTREACHED() << "OnIceCandidate: Could not get SDP string."; | 757 NOTREACHED() << "OnIceCandidate: Could not get SDP string."; |
| 756 return; | 758 return; |
| 757 } | 759 } |
| 758 blink::WebRTCICECandidate web_candidate; | 760 blink::WebRTCICECandidate web_candidate; |
| 759 web_candidate.initialize(UTF8ToUTF16(sdp), | 761 web_candidate.initialize(base::UTF8ToUTF16(sdp), |
| 760 UTF8ToUTF16(candidate->sdp_mid()), | 762 base::UTF8ToUTF16(candidate->sdp_mid()), |
| 761 candidate->sdp_mline_index()); | 763 candidate->sdp_mline_index()); |
| 762 if (peer_connection_tracker_) | 764 if (peer_connection_tracker_) |
| 763 peer_connection_tracker_->TrackAddIceCandidate( | 765 peer_connection_tracker_->TrackAddIceCandidate( |
| 764 this, web_candidate, PeerConnectionTracker::SOURCE_LOCAL); | 766 this, web_candidate, PeerConnectionTracker::SOURCE_LOCAL); |
| 765 | 767 |
| 766 client_->didGenerateICECandidate(web_candidate); | 768 client_->didGenerateICECandidate(web_candidate); |
| 767 } | 769 } |
| 768 | 770 |
| 769 void RTCPeerConnectionHandler::OnDataChannel( | 771 void RTCPeerConnectionHandler::OnDataChannel( |
| 770 webrtc::DataChannelInterface* data_channel) { | 772 webrtc::DataChannelInterface* data_channel) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 784 } | 786 } |
| 785 | 787 |
| 786 PeerConnectionTracker* RTCPeerConnectionHandler::peer_connection_tracker() { | 788 PeerConnectionTracker* RTCPeerConnectionHandler::peer_connection_tracker() { |
| 787 return peer_connection_tracker_; | 789 return peer_connection_tracker_; |
| 788 } | 790 } |
| 789 | 791 |
| 790 webrtc::SessionDescriptionInterface* | 792 webrtc::SessionDescriptionInterface* |
| 791 RTCPeerConnectionHandler::CreateNativeSessionDescription( | 793 RTCPeerConnectionHandler::CreateNativeSessionDescription( |
| 792 const blink::WebRTCSessionDescription& description, | 794 const blink::WebRTCSessionDescription& description, |
| 793 webrtc::SdpParseError* error) { | 795 webrtc::SdpParseError* error) { |
| 794 std::string sdp = UTF16ToUTF8(description.sdp()); | 796 std::string sdp = base::UTF16ToUTF8(description.sdp()); |
| 795 std::string type = UTF16ToUTF8(description.type()); | 797 std::string type = base::UTF16ToUTF8(description.type()); |
| 796 webrtc::SessionDescriptionInterface* native_desc = | 798 webrtc::SessionDescriptionInterface* native_desc = |
| 797 dependency_factory_->CreateSessionDescription(type, sdp, error); | 799 dependency_factory_->CreateSessionDescription(type, sdp, error); |
| 798 | 800 |
| 799 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." | 801 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." |
| 800 << " Type: " << type << " SDP: " << sdp; | 802 << " Type: " << type << " SDP: " << sdp; |
| 801 | 803 |
| 802 return native_desc; | 804 return native_desc; |
| 803 } | 805 } |
| 804 | 806 |
| 805 } // namespace content | 807 } // namespace content |
| OLD | NEW |