| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 int priority = static_cast<int>(turn_servers->size() - 1); | 682 int priority = static_cast<int>(turn_servers->size() - 1); |
| 683 for (cricket::RelayServerConfig& turn_server : *turn_servers) { | 683 for (cricket::RelayServerConfig& turn_server : *turn_servers) { |
| 684 // First in the list gets highest priority. | 684 // First in the list gets highest priority. |
| 685 turn_server.priority = priority--; | 685 turn_server.priority = priority--; |
| 686 } | 686 } |
| 687 return RTCErrorType::NONE; | 687 return RTCErrorType::NONE; |
| 688 } | 688 } |
| 689 | 689 |
| 690 PeerConnection::PeerConnection(PeerConnectionFactory* factory) | 690 PeerConnection::PeerConnection(PeerConnectionFactory* factory) |
| 691 : factory_(factory), | 691 : factory_(factory), |
| 692 observer_(NULL), | 692 observer_(nullptr), |
| 693 uma_observer_(NULL), | 693 uma_observer_(nullptr), |
| 694 signaling_state_(kStable), | 694 signaling_state_(kStable), |
| 695 ice_connection_state_(kIceConnectionNew), | 695 ice_connection_state_(kIceConnectionNew), |
| 696 ice_gathering_state_(kIceGatheringNew), | 696 ice_gathering_state_(kIceGatheringNew), |
| 697 event_log_(RtcEventLog::Create()), | 697 event_log_(RtcEventLog::Create()), |
| 698 rtcp_cname_(GenerateRtcpCname()), | 698 rtcp_cname_(GenerateRtcpCname()), |
| 699 local_streams_(StreamCollection::Create()), | 699 local_streams_(StreamCollection::Create()), |
| 700 remote_streams_(StreamCollection::Create()) {} | 700 remote_streams_(StreamCollection::Create()) {} |
| 701 | 701 |
| 702 PeerConnection::~PeerConnection() { | 702 PeerConnection::~PeerConnection() { |
| 703 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); | 703 TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 return true; | 946 return true; |
| 947 } | 947 } |
| 948 | 948 |
| 949 rtc::scoped_refptr<DtmfSenderInterface> PeerConnection::CreateDtmfSender( | 949 rtc::scoped_refptr<DtmfSenderInterface> PeerConnection::CreateDtmfSender( |
| 950 AudioTrackInterface* track) { | 950 AudioTrackInterface* track) { |
| 951 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender"); | 951 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender"); |
| 952 if (IsClosed()) { | 952 if (IsClosed()) { |
| 953 return nullptr; | 953 return nullptr; |
| 954 } | 954 } |
| 955 if (!track) { | 955 if (!track) { |
| 956 LOG(LS_ERROR) << "CreateDtmfSender - track is NULL."; | 956 LOG(LS_ERROR) << "CreateDtmfSender - track is null."; |
| 957 return nullptr; | 957 return nullptr; |
| 958 } | 958 } |
| 959 auto it = FindSenderForTrack(track); | 959 auto it = FindSenderForTrack(track); |
| 960 if (it == senders_.end()) { | 960 if (it == senders_.end()) { |
| 961 LOG(LS_ERROR) << "CreateDtmfSender called with a non-added track."; | 961 LOG(LS_ERROR) << "CreateDtmfSender called with a non-added track."; |
| 962 return nullptr; | 962 return nullptr; |
| 963 } | 963 } |
| 964 | 964 |
| 965 return (*it)->GetDtmfSender(); | 965 return (*it)->GetDtmfSender(); |
| 966 } | 966 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 } | 1008 } |
| 1009 return ret; | 1009 return ret; |
| 1010 } | 1010 } |
| 1011 | 1011 |
| 1012 bool PeerConnection::GetStats(StatsObserver* observer, | 1012 bool PeerConnection::GetStats(StatsObserver* observer, |
| 1013 MediaStreamTrackInterface* track, | 1013 MediaStreamTrackInterface* track, |
| 1014 StatsOutputLevel level) { | 1014 StatsOutputLevel level) { |
| 1015 TRACE_EVENT0("webrtc", "PeerConnection::GetStats"); | 1015 TRACE_EVENT0("webrtc", "PeerConnection::GetStats"); |
| 1016 RTC_DCHECK(signaling_thread()->IsCurrent()); | 1016 RTC_DCHECK(signaling_thread()->IsCurrent()); |
| 1017 if (!observer) { | 1017 if (!observer) { |
| 1018 LOG(LS_ERROR) << "GetStats - observer is NULL."; | 1018 LOG(LS_ERROR) << "GetStats - observer is null."; |
| 1019 return false; | 1019 return false; |
| 1020 } | 1020 } |
| 1021 | 1021 |
| 1022 stats_->UpdateStats(level); | 1022 stats_->UpdateStats(level); |
| 1023 // The StatsCollector is used to tell if a track is valid because it may | 1023 // The StatsCollector is used to tell if a track is valid because it may |
| 1024 // remember tracks that the PeerConnection previously removed. | 1024 // remember tracks that the PeerConnection previously removed. |
| 1025 if (track && !stats_->IsValidTrack(track->id())) { | 1025 if (track && !stats_->IsValidTrack(track->id())) { |
| 1026 LOG(LS_WARNING) << "GetStats is called with an invalid track: " | 1026 LOG(LS_WARNING) << "GetStats is called with an invalid track: " |
| 1027 << track->id(); | 1027 << track->id(); |
| 1028 return false; | 1028 return false; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1051 return ice_gathering_state_; | 1051 return ice_gathering_state_; |
| 1052 } | 1052 } |
| 1053 | 1053 |
| 1054 rtc::scoped_refptr<DataChannelInterface> | 1054 rtc::scoped_refptr<DataChannelInterface> |
| 1055 PeerConnection::CreateDataChannel( | 1055 PeerConnection::CreateDataChannel( |
| 1056 const std::string& label, | 1056 const std::string& label, |
| 1057 const DataChannelInit* config) { | 1057 const DataChannelInit* config) { |
| 1058 TRACE_EVENT0("webrtc", "PeerConnection::CreateDataChannel"); | 1058 TRACE_EVENT0("webrtc", "PeerConnection::CreateDataChannel"); |
| 1059 #ifdef HAVE_QUIC | 1059 #ifdef HAVE_QUIC |
| 1060 if (session_->data_channel_type() == cricket::DCT_QUIC) { | 1060 if (session_->data_channel_type() == cricket::DCT_QUIC) { |
| 1061 // TODO(zhihuang): Handle case when config is NULL. | 1061 // TODO(zhihuang): Handle case when config is null. |
| 1062 if (!config) { | 1062 if (!config) { |
| 1063 LOG(LS_ERROR) << "Missing config for QUIC data channel."; | 1063 LOG(LS_ERROR) << "Missing config for QUIC data channel."; |
| 1064 return nullptr; | 1064 return nullptr; |
| 1065 } | 1065 } |
| 1066 // TODO(zhihuang): Allow unreliable or ordered QUIC data channels. | 1066 // TODO(zhihuang): Allow unreliable or ordered QUIC data channels. |
| 1067 if (!config->reliable || config->ordered) { | 1067 if (!config->reliable || config->ordered) { |
| 1068 LOG(LS_ERROR) << "QUIC data channel does not implement unreliable or " | 1068 LOG(LS_ERROR) << "QUIC data channel does not implement unreliable or " |
| 1069 "ordered delivery."; | 1069 "ordered delivery."; |
| 1070 return nullptr; | 1070 return nullptr; |
| 1071 } | 1071 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1091 observer_->OnRenegotiationNeeded(); | 1091 observer_->OnRenegotiationNeeded(); |
| 1092 } | 1092 } |
| 1093 | 1093 |
| 1094 return DataChannelProxy::Create(signaling_thread(), channel.get()); | 1094 return DataChannelProxy::Create(signaling_thread(), channel.get()); |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, | 1097 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, |
| 1098 const MediaConstraintsInterface* constraints) { | 1098 const MediaConstraintsInterface* constraints) { |
| 1099 TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer"); | 1099 TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer"); |
| 1100 if (!observer) { | 1100 if (!observer) { |
| 1101 LOG(LS_ERROR) << "CreateOffer - observer is NULL."; | 1101 LOG(LS_ERROR) << "CreateOffer - observer is null."; |
| 1102 return; | 1102 return; |
| 1103 } | 1103 } |
| 1104 RTCOfferAnswerOptions options; | 1104 RTCOfferAnswerOptions options; |
| 1105 | 1105 |
| 1106 bool value; | 1106 bool value; |
| 1107 size_t mandatory_constraints = 0; | 1107 size_t mandatory_constraints = 0; |
| 1108 | 1108 |
| 1109 if (FindConstraint(constraints, | 1109 if (FindConstraint(constraints, |
| 1110 MediaConstraintsInterface::kOfferToReceiveAudio, | 1110 MediaConstraintsInterface::kOfferToReceiveAudio, |
| 1111 &value, | 1111 &value, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 options.use_rtp_mux = value; | 1143 options.use_rtp_mux = value; |
| 1144 } | 1144 } |
| 1145 | 1145 |
| 1146 CreateOffer(observer, options); | 1146 CreateOffer(observer, options); |
| 1147 } | 1147 } |
| 1148 | 1148 |
| 1149 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, | 1149 void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, |
| 1150 const RTCOfferAnswerOptions& options) { | 1150 const RTCOfferAnswerOptions& options) { |
| 1151 TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer"); | 1151 TRACE_EVENT0("webrtc", "PeerConnection::CreateOffer"); |
| 1152 if (!observer) { | 1152 if (!observer) { |
| 1153 LOG(LS_ERROR) << "CreateOffer - observer is NULL."; | 1153 LOG(LS_ERROR) << "CreateOffer - observer is null."; |
| 1154 return; | 1154 return; |
| 1155 } | 1155 } |
| 1156 | 1156 |
| 1157 cricket::MediaSessionOptions session_options; | 1157 cricket::MediaSessionOptions session_options; |
| 1158 if (!GetOptionsForOffer(options, &session_options)) { | 1158 if (!GetOptionsForOffer(options, &session_options)) { |
| 1159 std::string error = "CreateOffer called with invalid options."; | 1159 std::string error = "CreateOffer called with invalid options."; |
| 1160 LOG(LS_ERROR) << error; | 1160 LOG(LS_ERROR) << error; |
| 1161 PostCreateSessionDescriptionFailure(observer, error); | 1161 PostCreateSessionDescriptionFailure(observer, error); |
| 1162 return; | 1162 return; |
| 1163 } | 1163 } |
| 1164 | 1164 |
| 1165 session_->CreateOffer(observer, options, session_options); | 1165 session_->CreateOffer(observer, options, session_options); |
| 1166 } | 1166 } |
| 1167 | 1167 |
| 1168 void PeerConnection::CreateAnswer( | 1168 void PeerConnection::CreateAnswer( |
| 1169 CreateSessionDescriptionObserver* observer, | 1169 CreateSessionDescriptionObserver* observer, |
| 1170 const MediaConstraintsInterface* constraints) { | 1170 const MediaConstraintsInterface* constraints) { |
| 1171 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); | 1171 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); |
| 1172 if (!observer) { | 1172 if (!observer) { |
| 1173 LOG(LS_ERROR) << "CreateAnswer - observer is NULL."; | 1173 LOG(LS_ERROR) << "CreateAnswer - observer is null."; |
| 1174 return; | 1174 return; |
| 1175 } | 1175 } |
| 1176 | 1176 |
| 1177 cricket::MediaSessionOptions session_options; | 1177 cricket::MediaSessionOptions session_options; |
| 1178 if (!GetOptionsForAnswer(constraints, &session_options)) { | 1178 if (!GetOptionsForAnswer(constraints, &session_options)) { |
| 1179 std::string error = "CreateAnswer called with invalid constraints."; | 1179 std::string error = "CreateAnswer called with invalid constraints."; |
| 1180 LOG(LS_ERROR) << error; | 1180 LOG(LS_ERROR) << error; |
| 1181 PostCreateSessionDescriptionFailure(observer, error); | 1181 PostCreateSessionDescriptionFailure(observer, error); |
| 1182 return; | 1182 return; |
| 1183 } | 1183 } |
| 1184 | 1184 |
| 1185 session_->CreateAnswer(observer, session_options); | 1185 session_->CreateAnswer(observer, session_options); |
| 1186 } | 1186 } |
| 1187 | 1187 |
| 1188 void PeerConnection::CreateAnswer(CreateSessionDescriptionObserver* observer, | 1188 void PeerConnection::CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 1189 const RTCOfferAnswerOptions& options) { | 1189 const RTCOfferAnswerOptions& options) { |
| 1190 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); | 1190 TRACE_EVENT0("webrtc", "PeerConnection::CreateAnswer"); |
| 1191 if (!observer) { | 1191 if (!observer) { |
| 1192 LOG(LS_ERROR) << "CreateAnswer - observer is NULL."; | 1192 LOG(LS_ERROR) << "CreateAnswer - observer is null."; |
| 1193 return; | 1193 return; |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 cricket::MediaSessionOptions session_options; | 1196 cricket::MediaSessionOptions session_options; |
| 1197 if (!GetOptionsForAnswer(options, &session_options)) { | 1197 if (!GetOptionsForAnswer(options, &session_options)) { |
| 1198 std::string error = "CreateAnswer called with invalid options."; | 1198 std::string error = "CreateAnswer called with invalid options."; |
| 1199 LOG(LS_ERROR) << error; | 1199 LOG(LS_ERROR) << error; |
| 1200 PostCreateSessionDescriptionFailure(observer, error); | 1200 PostCreateSessionDescriptionFailure(observer, error); |
| 1201 return; | 1201 return; |
| 1202 } | 1202 } |
| 1203 | 1203 |
| 1204 session_->CreateAnswer(observer, session_options); | 1204 session_->CreateAnswer(observer, session_options); |
| 1205 } | 1205 } |
| 1206 | 1206 |
| 1207 void PeerConnection::SetLocalDescription( | 1207 void PeerConnection::SetLocalDescription( |
| 1208 SetSessionDescriptionObserver* observer, | 1208 SetSessionDescriptionObserver* observer, |
| 1209 SessionDescriptionInterface* desc) { | 1209 SessionDescriptionInterface* desc) { |
| 1210 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); | 1210 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); |
| 1211 if (IsClosed()) { | 1211 if (IsClosed()) { |
| 1212 return; | 1212 return; |
| 1213 } | 1213 } |
| 1214 if (!observer) { | 1214 if (!observer) { |
| 1215 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; | 1215 LOG(LS_ERROR) << "SetLocalDescription - observer is null."; |
| 1216 return; | 1216 return; |
| 1217 } | 1217 } |
| 1218 if (!desc) { | 1218 if (!desc) { |
| 1219 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); | 1219 PostSetSessionDescriptionFailure(observer, "SessionDescription is null."); |
| 1220 return; | 1220 return; |
| 1221 } | 1221 } |
| 1222 // Update stats here so that we have the most recent stats for tracks and | 1222 // Update stats here so that we have the most recent stats for tracks and |
| 1223 // streams that might be removed by updating the session description. | 1223 // streams that might be removed by updating the session description. |
| 1224 stats_->UpdateStats(kStatsOutputLevelStandard); | 1224 stats_->UpdateStats(kStatsOutputLevelStandard); |
| 1225 std::string error; | 1225 std::string error; |
| 1226 if (!session_->SetLocalDescription(desc, &error)) { | 1226 if (!session_->SetLocalDescription(desc, &error)) { |
| 1227 PostSetSessionDescriptionFailure(observer, error); | 1227 PostSetSessionDescriptionFailure(observer, error); |
| 1228 return; | 1228 return; |
| 1229 } | 1229 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 } | 1287 } |
| 1288 | 1288 |
| 1289 void PeerConnection::SetRemoteDescription( | 1289 void PeerConnection::SetRemoteDescription( |
| 1290 SetSessionDescriptionObserver* observer, | 1290 SetSessionDescriptionObserver* observer, |
| 1291 SessionDescriptionInterface* desc) { | 1291 SessionDescriptionInterface* desc) { |
| 1292 TRACE_EVENT0("webrtc", "PeerConnection::SetRemoteDescription"); | 1292 TRACE_EVENT0("webrtc", "PeerConnection::SetRemoteDescription"); |
| 1293 if (IsClosed()) { | 1293 if (IsClosed()) { |
| 1294 return; | 1294 return; |
| 1295 } | 1295 } |
| 1296 if (!observer) { | 1296 if (!observer) { |
| 1297 LOG(LS_ERROR) << "SetRemoteDescription - observer is NULL."; | 1297 LOG(LS_ERROR) << "SetRemoteDescription - observer is null."; |
| 1298 return; | 1298 return; |
| 1299 } | 1299 } |
| 1300 if (!desc) { | 1300 if (!desc) { |
| 1301 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); | 1301 PostSetSessionDescriptionFailure(observer, "SessionDescription is null."); |
| 1302 return; | 1302 return; |
| 1303 } | 1303 } |
| 1304 // Update stats here so that we have the most recent stats for tracks and | 1304 // Update stats here so that we have the most recent stats for tracks and |
| 1305 // streams that might be removed by updating the session description. | 1305 // streams that might be removed by updating the session description. |
| 1306 stats_->UpdateStats(kStatsOutputLevelStandard); | 1306 stats_->UpdateStats(kStatsOutputLevelStandard); |
| 1307 std::string error; | 1307 std::string error; |
| 1308 if (!session_->SetRemoteDescription(desc, &error)) { | 1308 if (!session_->SetRemoteDescription(desc, &error)) { |
| 1309 PostSetSessionDescriptionFailure(observer, error); | 1309 PostSetSessionDescriptionFailure(observer, error); |
| 1310 return; | 1310 return; |
| 1311 } | 1311 } |
| (...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2579 } | 2579 } |
| 2580 return event_log_->StartLogging(file, max_size_bytes); | 2580 return event_log_->StartLogging(file, max_size_bytes); |
| 2581 } | 2581 } |
| 2582 | 2582 |
| 2583 void PeerConnection::StopRtcEventLog_w() { | 2583 void PeerConnection::StopRtcEventLog_w() { |
| 2584 if (event_log_) { | 2584 if (event_log_) { |
| 2585 event_log_->StopLogging(); | 2585 event_log_->StopLogging(); |
| 2586 } | 2586 } |
| 2587 } | 2587 } |
| 2588 } // namespace webrtc | 2588 } // namespace webrtc |
| OLD | NEW |