Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 #include "modules/peerconnection/RTCConfiguration.h" | 63 #include "modules/peerconnection/RTCConfiguration.h" |
| 64 #include "modules/peerconnection/RTCDTMFSender.h" | 64 #include "modules/peerconnection/RTCDTMFSender.h" |
| 65 #include "modules/peerconnection/RTCDataChannel.h" | 65 #include "modules/peerconnection/RTCDataChannel.h" |
| 66 #include "modules/peerconnection/RTCDataChannelEvent.h" | 66 #include "modules/peerconnection/RTCDataChannelEvent.h" |
| 67 #include "modules/peerconnection/RTCDataChannelInit.h" | 67 #include "modules/peerconnection/RTCDataChannelInit.h" |
| 68 #include "modules/peerconnection/RTCIceServer.h" | 68 #include "modules/peerconnection/RTCIceServer.h" |
| 69 #include "modules/peerconnection/RTCOfferOptions.h" | 69 #include "modules/peerconnection/RTCOfferOptions.h" |
| 70 #include "modules/peerconnection/RTCPeerConnectionErrorCallback.h" | 70 #include "modules/peerconnection/RTCPeerConnectionErrorCallback.h" |
| 71 #include "modules/peerconnection/RTCPeerConnectionIceEvent.h" | 71 #include "modules/peerconnection/RTCPeerConnectionIceEvent.h" |
| 72 #include "modules/peerconnection/RTCRtpReceiver.h" | 72 #include "modules/peerconnection/RTCRtpReceiver.h" |
| 73 #include "modules/peerconnection/RTCRtpSender.h" | |
| 73 #include "modules/peerconnection/RTCSessionDescription.h" | 74 #include "modules/peerconnection/RTCSessionDescription.h" |
| 74 #include "modules/peerconnection/RTCSessionDescriptionCallback.h" | 75 #include "modules/peerconnection/RTCSessionDescriptionCallback.h" |
| 75 #include "modules/peerconnection/RTCSessionDescriptionInit.h" | 76 #include "modules/peerconnection/RTCSessionDescriptionInit.h" |
| 76 #include "modules/peerconnection/RTCSessionDescriptionRequestImpl.h" | 77 #include "modules/peerconnection/RTCSessionDescriptionRequestImpl.h" |
| 77 #include "modules/peerconnection/RTCSessionDescriptionRequestPromiseImpl.h" | 78 #include "modules/peerconnection/RTCSessionDescriptionRequestPromiseImpl.h" |
| 78 #include "modules/peerconnection/RTCStatsCallback.h" | 79 #include "modules/peerconnection/RTCStatsCallback.h" |
| 79 #include "modules/peerconnection/RTCStatsReport.h" | 80 #include "modules/peerconnection/RTCStatsReport.h" |
| 80 #include "modules/peerconnection/RTCStatsRequestImpl.h" | 81 #include "modules/peerconnection/RTCStatsRequestImpl.h" |
| 81 #include "modules/peerconnection/RTCVoidRequestImpl.h" | 82 #include "modules/peerconnection/RTCVoidRequestImpl.h" |
| 82 #include "modules/peerconnection/RTCVoidRequestPromiseImpl.h" | 83 #include "modules/peerconnection/RTCVoidRequestPromiseImpl.h" |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1117 return; | 1118 return; |
| 1118 } | 1119 } |
| 1119 | 1120 |
| 1120 size_t pos = local_streams_.Find(stream); | 1121 size_t pos = local_streams_.Find(stream); |
| 1121 if (pos == kNotFound) | 1122 if (pos == kNotFound) |
| 1122 return; | 1123 return; |
| 1123 | 1124 |
| 1124 local_streams_.erase(pos); | 1125 local_streams_.erase(pos); |
| 1125 | 1126 |
| 1126 peer_handler_->RemoveStream(stream->Descriptor()); | 1127 peer_handler_->RemoveStream(stream->Descriptor()); |
| 1128 | |
| 1129 // The senders of removed tracks will have become inactive. | |
| 1130 RemoveInactiveSenders(); | |
| 1127 } | 1131 } |
| 1128 | 1132 |
| 1129 MediaStreamVector RTCPeerConnection::getLocalStreams() const { | 1133 MediaStreamVector RTCPeerConnection::getLocalStreams() const { |
| 1130 return local_streams_; | 1134 return local_streams_; |
| 1131 } | 1135 } |
| 1132 | 1136 |
| 1133 MediaStreamVector RTCPeerConnection::getRemoteStreams() const { | 1137 MediaStreamVector RTCPeerConnection::getRemoteStreams() const { |
| 1134 return remote_streams_; | 1138 return remote_streams_; |
| 1135 } | 1139 } |
| 1136 | 1140 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1172 ExecutionContext* context = ExecutionContext::From(script_state); | 1176 ExecutionContext* context = ExecutionContext::From(script_state); |
| 1173 UseCounter::Count(context, UseCounter::kRTCPeerConnectionGetStats); | 1177 UseCounter::Count(context, UseCounter::kRTCPeerConnectionGetStats); |
| 1174 | 1178 |
| 1175 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 1179 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 1176 ScriptPromise promise = resolver->Promise(); | 1180 ScriptPromise promise = resolver->Promise(); |
| 1177 peer_handler_->GetStats(WebRTCStatsReportCallbackResolver::Create(resolver)); | 1181 peer_handler_->GetStats(WebRTCStatsReportCallbackResolver::Create(resolver)); |
| 1178 | 1182 |
| 1179 return promise; | 1183 return promise; |
| 1180 } | 1184 } |
| 1181 | 1185 |
| 1186 HeapVector<Member<RTCRtpSender>> RTCPeerConnection::getSenders() { | |
| 1187 WebVector<std::unique_ptr<WebRTCRtpSender>> web_rtp_senders = | |
| 1188 peer_handler_->GetSenders(); | |
| 1189 HeapVector<Member<RTCRtpSender>> rtp_senders(web_rtp_senders.size()); | |
| 1190 for (size_t i = 0; i < web_rtp_senders.size(); ++i) { | |
| 1191 uintptr_t id = web_rtp_senders[i]->Id(); | |
| 1192 const auto it = rtp_senders_.find(id); | |
| 1193 if (it != rtp_senders_.end()) { | |
| 1194 rtp_senders[i] = it->value; | |
| 1195 } else { | |
| 1196 // There does not exist a |RTCRtpSender| for this |WebRTCRtpSender| | |
|
Guido Urdaneta
2017/05/02 12:31:48
nit/typo: a -> an
hbos_chromium
2017/05/03 09:54:23
Done.
| |
| 1197 // yet, create it. | |
| 1198 MediaStreamTrack* track; | |
|
Guido Urdaneta
2017/05/02 12:31:48
nit: Initialize track to nullptr and remove the el
hbos_chromium
2017/05/03 09:54:23
Done.
| |
| 1199 if (web_rtp_senders[i]->Track()) { | |
| 1200 track = GetLocalTrackById(web_rtp_senders[i]->Track()->Id()); | |
| 1201 DCHECK(track); | |
| 1202 } else { | |
| 1203 track = nullptr; | |
| 1204 } | |
| 1205 RTCRtpSender* rtp_sender = | |
| 1206 new RTCRtpSender(std::move(web_rtp_senders[i]), track); | |
| 1207 rtp_senders_.insert(id, rtp_sender); | |
| 1208 rtp_senders[i] = rtp_sender; | |
| 1209 } | |
| 1210 } | |
| 1211 return rtp_senders; | |
| 1212 } | |
| 1213 | |
| 1182 HeapVector<Member<RTCRtpReceiver>> RTCPeerConnection::getReceivers() { | 1214 HeapVector<Member<RTCRtpReceiver>> RTCPeerConnection::getReceivers() { |
| 1183 WebVector<std::unique_ptr<WebRTCRtpReceiver>> web_rtp_receivers = | 1215 WebVector<std::unique_ptr<WebRTCRtpReceiver>> web_rtp_receivers = |
| 1184 peer_handler_->GetReceivers(); | 1216 peer_handler_->GetReceivers(); |
| 1185 HeapVector<Member<RTCRtpReceiver>> rtp_receivers(web_rtp_receivers.size()); | 1217 HeapVector<Member<RTCRtpReceiver>> rtp_receivers(web_rtp_receivers.size()); |
| 1186 for (size_t i = 0; i < web_rtp_receivers.size(); ++i) { | 1218 for (size_t i = 0; i < web_rtp_receivers.size(); ++i) { |
| 1187 uintptr_t id = web_rtp_receivers[i]->Id(); | 1219 uintptr_t id = web_rtp_receivers[i]->Id(); |
| 1188 const auto it = rtp_receivers_.find(id); | 1220 const auto it = rtp_receivers_.find(id); |
| 1189 if (it != rtp_receivers_.end()) { | 1221 if (it != rtp_receivers_.end()) { |
| 1190 rtp_receivers[i] = it->value; | 1222 rtp_receivers[i] = it->value; |
| 1191 } else { | 1223 } else { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1237 RTCDataChannel::ReadyState handler_state = channel->GetHandlerState(); | 1269 RTCDataChannel::ReadyState handler_state = channel->GetHandlerState(); |
| 1238 if (handler_state != RTCDataChannel::kReadyStateConnecting) { | 1270 if (handler_state != RTCDataChannel::kReadyStateConnecting) { |
| 1239 // There was an early state transition. Don't miss it! | 1271 // There was an early state transition. Don't miss it! |
| 1240 channel->DidChangeReadyState(handler_state); | 1272 channel->DidChangeReadyState(handler_state); |
| 1241 } | 1273 } |
| 1242 has_data_channels_ = true; | 1274 has_data_channels_ = true; |
| 1243 | 1275 |
| 1244 return channel; | 1276 return channel; |
| 1245 } | 1277 } |
| 1246 | 1278 |
| 1247 bool RTCPeerConnection::HasLocalStreamWithTrackId(const String& track_id) { | 1279 MediaStreamTrack* RTCPeerConnection::GetLocalTrackById( |
| 1248 for (MediaStreamVector::iterator iter = local_streams_.begin(); | 1280 const String& track_id) const { |
| 1249 iter != local_streams_.end(); ++iter) { | 1281 for (const auto& local_stream : local_streams_) { |
| 1250 if ((*iter)->getTrackById(track_id)) | 1282 MediaStreamTrack* track = local_stream->getTrackById(track_id); |
| 1251 return true; | 1283 if (track) |
| 1284 return track; | |
| 1252 } | 1285 } |
| 1253 return false; | 1286 return nullptr; |
| 1254 } | 1287 } |
| 1255 | 1288 |
| 1256 MediaStreamTrack* RTCPeerConnection::GetRemoteTrackById( | 1289 MediaStreamTrack* RTCPeerConnection::GetRemoteTrackById( |
| 1257 const String& track_id) const { | 1290 const String& track_id) const { |
| 1258 for (const auto& remote_stream : remote_streams_) { | 1291 for (const auto& remote_stream : remote_streams_) { |
| 1259 MediaStreamTrack* track = remote_stream->getTrackById(track_id); | 1292 MediaStreamTrack* track = remote_stream->getTrackById(track_id); |
| 1260 if (track) | 1293 if (track) |
| 1261 return track; | 1294 return track; |
| 1262 } | 1295 } |
| 1263 return nullptr; | 1296 return nullptr; |
| 1264 } | 1297 } |
| 1265 | 1298 |
| 1299 void RTCPeerConnection::RemoveInactiveSenders() { | |
| 1300 std::set<uintptr_t> inactive_sender_ids; | |
| 1301 for (uintptr_t id : rtp_senders_.Keys()) { | |
| 1302 inactive_sender_ids.insert(id); | |
| 1303 } | |
| 1304 for (const auto& web_rtp_sender : peer_handler_->GetSenders()) { | |
| 1305 inactive_sender_ids.erase(web_rtp_sender->Id()); | |
| 1306 } | |
| 1307 for (uintptr_t id : inactive_sender_ids) { | |
| 1308 rtp_senders_.erase(id); | |
| 1309 } | |
| 1310 } | |
| 1311 | |
| 1266 void RTCPeerConnection::RemoveInactiveReceivers() { | 1312 void RTCPeerConnection::RemoveInactiveReceivers() { |
| 1267 std::set<uintptr_t> inactive_receiver_ids; | 1313 std::set<uintptr_t> inactive_receiver_ids; |
| 1268 for (uintptr_t id : rtp_receivers_.Keys()) { | 1314 for (uintptr_t id : rtp_receivers_.Keys()) { |
| 1269 inactive_receiver_ids.insert(id); | 1315 inactive_receiver_ids.insert(id); |
| 1270 } | 1316 } |
| 1271 for (const auto& web_rtp_receiver : peer_handler_->GetReceivers()) { | 1317 for (const auto& web_rtp_receiver : peer_handler_->GetReceivers()) { |
| 1272 inactive_receiver_ids.erase(web_rtp_receiver->Id()); | 1318 inactive_receiver_ids.erase(web_rtp_receiver->Id()); |
| 1273 } | 1319 } |
| 1274 for (uintptr_t id : inactive_receiver_ids) { | 1320 for (uintptr_t id : inactive_receiver_ids) { |
| 1275 rtp_receivers_.erase(id); | 1321 rtp_receivers_.erase(id); |
| 1276 } | 1322 } |
| 1277 } | 1323 } |
| 1278 | 1324 |
| 1279 RTCDTMFSender* RTCPeerConnection::createDTMFSender( | 1325 RTCDTMFSender* RTCPeerConnection::createDTMFSender( |
| 1280 MediaStreamTrack* track, | 1326 MediaStreamTrack* track, |
| 1281 ExceptionState& exception_state) { | 1327 ExceptionState& exception_state) { |
| 1282 if (ThrowExceptionIfSignalingStateClosed(signaling_state_, exception_state)) | 1328 if (ThrowExceptionIfSignalingStateClosed(signaling_state_, exception_state)) |
| 1283 return nullptr; | 1329 return nullptr; |
| 1284 | 1330 |
| 1285 DCHECK(track); | 1331 DCHECK(track); |
| 1286 | 1332 |
| 1287 if (!HasLocalStreamWithTrackId(track->id())) { | 1333 if (!GetLocalTrackById(track->id())) { |
| 1288 exception_state.ThrowDOMException( | 1334 exception_state.ThrowDOMException( |
| 1289 kSyntaxError, "No local stream is available for the track provided."); | 1335 kSyntaxError, "No local stream is available for the track provided."); |
| 1290 return nullptr; | 1336 return nullptr; |
| 1291 } | 1337 } |
| 1292 | 1338 |
| 1293 RTCDTMFSender* dtmf_sender = RTCDTMFSender::Create( | 1339 RTCDTMFSender* dtmf_sender = RTCDTMFSender::Create( |
| 1294 GetExecutionContext(), peer_handler_.get(), track, exception_state); | 1340 GetExecutionContext(), peer_handler_.get(), track, exception_state); |
| 1295 if (exception_state.HadException()) | 1341 if (exception_state.HadException()) |
| 1296 return nullptr; | 1342 return nullptr; |
| 1297 return dtmf_sender; | 1343 return dtmf_sender; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1545 } | 1591 } |
| 1546 | 1592 |
| 1547 if (has_data_channels_) | 1593 if (has_data_channels_) |
| 1548 HostsUsingFeatures::CountAnyWorld( | 1594 HostsUsingFeatures::CountAnyWorld( |
| 1549 *document, HostsUsingFeatures::Feature::kRTCPeerConnectionDataChannel); | 1595 *document, HostsUsingFeatures::Feature::kRTCPeerConnectionDataChannel); |
| 1550 } | 1596 } |
| 1551 | 1597 |
| 1552 DEFINE_TRACE(RTCPeerConnection) { | 1598 DEFINE_TRACE(RTCPeerConnection) { |
| 1553 visitor->Trace(local_streams_); | 1599 visitor->Trace(local_streams_); |
| 1554 visitor->Trace(remote_streams_); | 1600 visitor->Trace(remote_streams_); |
| 1601 visitor->Trace(rtp_senders_); | |
| 1555 visitor->Trace(rtp_receivers_); | 1602 visitor->Trace(rtp_receivers_); |
| 1556 visitor->Trace(dispatch_scheduled_event_runner_); | 1603 visitor->Trace(dispatch_scheduled_event_runner_); |
| 1557 visitor->Trace(scheduled_events_); | 1604 visitor->Trace(scheduled_events_); |
| 1558 EventTargetWithInlineData::Trace(visitor); | 1605 EventTargetWithInlineData::Trace(visitor); |
| 1559 SuspendableObject::Trace(visitor); | 1606 SuspendableObject::Trace(visitor); |
| 1560 } | 1607 } |
| 1561 | 1608 |
| 1562 } // namespace blink | 1609 } // namespace blink |
| OLD | NEW |