| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 174 |
| 175 void GetNativeRtcConfiguration( | 175 void GetNativeRtcConfiguration( |
| 176 const blink::WebRTCConfiguration& blink_config, | 176 const blink::WebRTCConfiguration& blink_config, |
| 177 webrtc::PeerConnectionInterface::RTCConfiguration* webrtc_config) { | 177 webrtc::PeerConnectionInterface::RTCConfiguration* webrtc_config) { |
| 178 if (blink_config.isNull() || !webrtc_config) | 178 if (blink_config.isNull() || !webrtc_config) |
| 179 return; | 179 return; |
| 180 for (size_t i = 0; i < blink_config.numberOfServers(); ++i) { | 180 for (size_t i = 0; i < blink_config.numberOfServers(); ++i) { |
| 181 webrtc::PeerConnectionInterface::IceServer server; | 181 webrtc::PeerConnectionInterface::IceServer server; |
| 182 const blink::WebRTCICEServer& webkit_server = | 182 const blink::WebRTCICEServer& webkit_server = |
| 183 blink_config.server(i); | 183 blink_config.server(i); |
| 184 server.username = base::UTF16ToUTF8(webkit_server.username()); | 184 server.username = |
| 185 server.password = base::UTF16ToUTF8(webkit_server.credential()); | 185 base::UTF16ToUTF8(base::StringPiece16(webkit_server.username())); |
| 186 server.password = |
| 187 base::UTF16ToUTF8(base::StringPiece16(webkit_server.credential())); |
| 186 server.uri = webkit_server.uri().spec(); | 188 server.uri = webkit_server.uri().spec(); |
| 187 webrtc_config->servers.push_back(server); | 189 webrtc_config->servers.push_back(server); |
| 188 } | 190 } |
| 189 | 191 |
| 190 switch (blink_config.iceTransports()) { | 192 switch (blink_config.iceTransports()) { |
| 191 case blink::WebRTCIceTransportsNone: | 193 case blink::WebRTCIceTransportsNone: |
| 192 webrtc_config->type = webrtc::PeerConnectionInterface::kNone; | 194 webrtc_config->type = webrtc::PeerConnectionInterface::kNone; |
| 193 break; | 195 break; |
| 194 case blink::WebRTCIceTransportsRelay: | 196 case blink::WebRTCIceTransportsRelay: |
| 195 webrtc_config->type = webrtc::PeerConnectionInterface::kRelay; | 197 webrtc_config->type = webrtc::PeerConnectionInterface::kRelay; |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 if (peer_connection_tracker_) | 900 if (peer_connection_tracker_) |
| 899 peer_connection_tracker_->TrackCreateAnswer(this, constraints); | 901 peer_connection_tracker_->TrackCreateAnswer(this, constraints); |
| 900 } | 902 } |
| 901 | 903 |
| 902 void RTCPeerConnectionHandler::setLocalDescription( | 904 void RTCPeerConnectionHandler::setLocalDescription( |
| 903 const blink::WebRTCVoidRequest& request, | 905 const blink::WebRTCVoidRequest& request, |
| 904 const blink::WebRTCSessionDescription& description) { | 906 const blink::WebRTCSessionDescription& description) { |
| 905 DCHECK(thread_checker_.CalledOnValidThread()); | 907 DCHECK(thread_checker_.CalledOnValidThread()); |
| 906 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::setLocalDescription"); | 908 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::setLocalDescription"); |
| 907 | 909 |
| 908 std::string sdp = base::UTF16ToUTF8(description.sdp()); | 910 std::string sdp = base::UTF16ToUTF8(base::StringPiece16(description.sdp())); |
| 909 std::string type = base::UTF16ToUTF8(description.type()); | 911 std::string type = |
| 912 base::UTF16ToUTF8(base::StringPiece16(description.type())); |
| 910 | 913 |
| 911 webrtc::SdpParseError error; | 914 webrtc::SdpParseError error; |
| 912 // Since CreateNativeSessionDescription uses the dependency factory, we need | 915 // Since CreateNativeSessionDescription uses the dependency factory, we need |
| 913 // to make this call on the current thread to be safe. | 916 // to make this call on the current thread to be safe. |
| 914 webrtc::SessionDescriptionInterface* native_desc = | 917 webrtc::SessionDescriptionInterface* native_desc = |
| 915 CreateNativeSessionDescription(sdp, type, &error); | 918 CreateNativeSessionDescription(sdp, type, &error); |
| 916 if (!native_desc) { | 919 if (!native_desc) { |
| 917 std::string reason_str = "Failed to parse SessionDescription. "; | 920 std::string reason_str = "Failed to parse SessionDescription. "; |
| 918 reason_str.append(error.line); | 921 reason_str.append(error.line); |
| 919 reason_str.append(" "); | 922 reason_str.append(" "); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 940 native_peer_connection_, set_request, | 943 native_peer_connection_, set_request, |
| 941 base::Unretained(native_desc)), | 944 base::Unretained(native_desc)), |
| 942 "SetLocalDescription")); | 945 "SetLocalDescription")); |
| 943 } | 946 } |
| 944 | 947 |
| 945 void RTCPeerConnectionHandler::setRemoteDescription( | 948 void RTCPeerConnectionHandler::setRemoteDescription( |
| 946 const blink::WebRTCVoidRequest& request, | 949 const blink::WebRTCVoidRequest& request, |
| 947 const blink::WebRTCSessionDescription& description) { | 950 const blink::WebRTCSessionDescription& description) { |
| 948 DCHECK(thread_checker_.CalledOnValidThread()); | 951 DCHECK(thread_checker_.CalledOnValidThread()); |
| 949 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::setRemoteDescription"); | 952 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::setRemoteDescription"); |
| 950 std::string sdp = base::UTF16ToUTF8(description.sdp()); | 953 std::string sdp = base::UTF16ToUTF8(base::StringPiece16(description.sdp())); |
| 951 std::string type = base::UTF16ToUTF8(description.type()); | 954 std::string type = |
| 955 base::UTF16ToUTF8(base::StringPiece16(description.type())); |
| 952 | 956 |
| 953 webrtc::SdpParseError error; | 957 webrtc::SdpParseError error; |
| 954 // Since CreateNativeSessionDescription uses the dependency factory, we need | 958 // Since CreateNativeSessionDescription uses the dependency factory, we need |
| 955 // to make this call on the current thread to be safe. | 959 // to make this call on the current thread to be safe. |
| 956 webrtc::SessionDescriptionInterface* native_desc = | 960 webrtc::SessionDescriptionInterface* native_desc = |
| 957 CreateNativeSessionDescription(sdp, type, &error); | 961 CreateNativeSessionDescription(sdp, type, &error); |
| 958 if (!native_desc) { | 962 if (!native_desc) { |
| 959 std::string reason_str = "Failed to parse SessionDescription. "; | 963 std::string reason_str = "Failed to parse SessionDescription. "; |
| 960 reason_str.append(error.line); | 964 reason_str.append(error.line); |
| 961 reason_str.append(" "); | 965 reason_str.append(" "); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 // On failure callback will be triggered. | 1060 // On failure callback will be triggered. |
| 1057 return true; | 1061 return true; |
| 1058 } | 1062 } |
| 1059 | 1063 |
| 1060 bool RTCPeerConnectionHandler::addICECandidate( | 1064 bool RTCPeerConnectionHandler::addICECandidate( |
| 1061 const blink::WebRTCICECandidate& candidate) { | 1065 const blink::WebRTCICECandidate& candidate) { |
| 1062 DCHECK(thread_checker_.CalledOnValidThread()); | 1066 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1063 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); | 1067 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); |
| 1064 scoped_ptr<webrtc::IceCandidateInterface> native_candidate( | 1068 scoped_ptr<webrtc::IceCandidateInterface> native_candidate( |
| 1065 dependency_factory_->CreateIceCandidate( | 1069 dependency_factory_->CreateIceCandidate( |
| 1066 base::UTF16ToUTF8(candidate.sdpMid()), | 1070 base::UTF16ToUTF8(base::StringPiece16(candidate.sdpMid())), |
| 1067 candidate.sdpMLineIndex(), | 1071 candidate.sdpMLineIndex(), |
| 1068 base::UTF16ToUTF8(candidate.candidate()))); | 1072 base::UTF16ToUTF8(base::StringPiece16(candidate.candidate())))); |
| 1069 bool return_value = false; | 1073 bool return_value = false; |
| 1070 | 1074 |
| 1071 if (native_candidate) { | 1075 if (native_candidate) { |
| 1072 return_value = | 1076 return_value = |
| 1073 native_peer_connection_->AddIceCandidate(native_candidate.get()); | 1077 native_peer_connection_->AddIceCandidate(native_candidate.get()); |
| 1074 LOG_IF(ERROR, !return_value) << "Error processing ICE candidate."; | 1078 LOG_IF(ERROR, !return_value) << "Error processing ICE candidate."; |
| 1075 } else { | 1079 } else { |
| 1076 LOG(ERROR) << "Could not create native ICE candidate."; | 1080 LOG(ERROR) << "Could not create native ICE candidate."; |
| 1077 } | 1081 } |
| 1078 | 1082 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 void RTCPeerConnectionHandler::CloseClientPeerConnection() { | 1216 void RTCPeerConnectionHandler::CloseClientPeerConnection() { |
| 1213 DCHECK(thread_checker_.CalledOnValidThread()); | 1217 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1214 if (client_) | 1218 if (client_) |
| 1215 client_->closePeerConnection(); | 1219 client_->closePeerConnection(); |
| 1216 } | 1220 } |
| 1217 | 1221 |
| 1218 blink::WebRTCDataChannelHandler* RTCPeerConnectionHandler::createDataChannel( | 1222 blink::WebRTCDataChannelHandler* RTCPeerConnectionHandler::createDataChannel( |
| 1219 const blink::WebString& label, const blink::WebRTCDataChannelInit& init) { | 1223 const blink::WebString& label, const blink::WebRTCDataChannelInit& init) { |
| 1220 DCHECK(thread_checker_.CalledOnValidThread()); | 1224 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1221 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createDataChannel"); | 1225 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createDataChannel"); |
| 1222 DVLOG(1) << "createDataChannel label " << base::UTF16ToUTF8(label); | 1226 DVLOG(1) << "createDataChannel label " |
| 1227 << base::UTF16ToUTF8(base::StringPiece16(label)); |
| 1223 | 1228 |
| 1224 webrtc::DataChannelInit config; | 1229 webrtc::DataChannelInit config; |
| 1225 // TODO(jiayl): remove the deprecated reliable field once Libjingle is updated | 1230 // TODO(jiayl): remove the deprecated reliable field once Libjingle is updated |
| 1226 // to handle that. | 1231 // to handle that. |
| 1227 config.reliable = false; | 1232 config.reliable = false; |
| 1228 config.id = init.id; | 1233 config.id = init.id; |
| 1229 config.ordered = init.ordered; | 1234 config.ordered = init.ordered; |
| 1230 config.negotiated = init.negotiated; | 1235 config.negotiated = init.negotiated; |
| 1231 config.maxRetransmits = init.maxRetransmits; | 1236 config.maxRetransmits = init.maxRetransmits; |
| 1232 config.maxRetransmitTime = init.maxRetransmitTime; | 1237 config.maxRetransmitTime = init.maxRetransmitTime; |
| 1233 config.protocol = base::UTF16ToUTF8(init.protocol); | 1238 config.protocol = base::UTF16ToUTF8(base::StringPiece16(init.protocol)); |
| 1234 | 1239 |
| 1235 rtc::scoped_refptr<webrtc::DataChannelInterface> webrtc_channel( | 1240 rtc::scoped_refptr<webrtc::DataChannelInterface> webrtc_channel( |
| 1236 native_peer_connection_->CreateDataChannel(base::UTF16ToUTF8(label), | 1241 native_peer_connection_->CreateDataChannel( |
| 1237 &config)); | 1242 base::UTF16ToUTF8(base::StringPiece16(label)), &config)); |
| 1238 if (!webrtc_channel) { | 1243 if (!webrtc_channel) { |
| 1239 DLOG(ERROR) << "Could not create native data channel."; | 1244 DLOG(ERROR) << "Could not create native data channel."; |
| 1240 return NULL; | 1245 return NULL; |
| 1241 } | 1246 } |
| 1242 if (peer_connection_tracker_) { | 1247 if (peer_connection_tracker_) { |
| 1243 peer_connection_tracker_->TrackCreateDataChannel( | 1248 peer_connection_tracker_->TrackCreateDataChannel( |
| 1244 this, webrtc_channel.get(), PeerConnectionTracker::SOURCE_LOCAL); | 1249 this, webrtc_channel.get(), PeerConnectionTracker::SOURCE_LOCAL); |
| 1245 } | 1250 } |
| 1246 | 1251 |
| 1247 ++num_data_channels_created_; | 1252 ++num_data_channels_created_; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1515 base::WaitableEvent event(false, false); | 1520 base::WaitableEvent event(false, false); |
| 1516 thread->PostTask(FROM_HERE, | 1521 thread->PostTask(FROM_HERE, |
| 1517 base::Bind(&RunSynchronousClosure, closure, | 1522 base::Bind(&RunSynchronousClosure, closure, |
| 1518 base::Unretained(trace_event_name), | 1523 base::Unretained(trace_event_name), |
| 1519 base::Unretained(&event))); | 1524 base::Unretained(&event))); |
| 1520 event.Wait(); | 1525 event.Wait(); |
| 1521 } | 1526 } |
| 1522 } | 1527 } |
| 1523 | 1528 |
| 1524 } // namespace content | 1529 } // namespace content |
| OLD | NEW |