Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Side by Side Diff: third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp

Issue 2749703005: RTCRtpSender with track behind RuntimeEnabled flag (Closed)
Patch Set: external/wpt/webrtc/RTCPeerConnection-idl-expected.txt updated passing 2 more tests Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "modules/peerconnection/RTCConfiguration.h" 61 #include "modules/peerconnection/RTCConfiguration.h"
62 #include "modules/peerconnection/RTCDTMFSender.h" 62 #include "modules/peerconnection/RTCDTMFSender.h"
63 #include "modules/peerconnection/RTCDataChannel.h" 63 #include "modules/peerconnection/RTCDataChannel.h"
64 #include "modules/peerconnection/RTCDataChannelEvent.h" 64 #include "modules/peerconnection/RTCDataChannelEvent.h"
65 #include "modules/peerconnection/RTCDataChannelInit.h" 65 #include "modules/peerconnection/RTCDataChannelInit.h"
66 #include "modules/peerconnection/RTCIceServer.h" 66 #include "modules/peerconnection/RTCIceServer.h"
67 #include "modules/peerconnection/RTCOfferOptions.h" 67 #include "modules/peerconnection/RTCOfferOptions.h"
68 #include "modules/peerconnection/RTCPeerConnectionErrorCallback.h" 68 #include "modules/peerconnection/RTCPeerConnectionErrorCallback.h"
69 #include "modules/peerconnection/RTCPeerConnectionIceEvent.h" 69 #include "modules/peerconnection/RTCPeerConnectionIceEvent.h"
70 #include "modules/peerconnection/RTCRtpReceiver.h" 70 #include "modules/peerconnection/RTCRtpReceiver.h"
71 #include "modules/peerconnection/RTCRtpSender.h"
71 #include "modules/peerconnection/RTCSessionDescription.h" 72 #include "modules/peerconnection/RTCSessionDescription.h"
72 #include "modules/peerconnection/RTCSessionDescriptionCallback.h" 73 #include "modules/peerconnection/RTCSessionDescriptionCallback.h"
73 #include "modules/peerconnection/RTCSessionDescriptionInit.h" 74 #include "modules/peerconnection/RTCSessionDescriptionInit.h"
74 #include "modules/peerconnection/RTCSessionDescriptionRequestImpl.h" 75 #include "modules/peerconnection/RTCSessionDescriptionRequestImpl.h"
75 #include "modules/peerconnection/RTCSessionDescriptionRequestPromiseImpl.h" 76 #include "modules/peerconnection/RTCSessionDescriptionRequestPromiseImpl.h"
76 #include "modules/peerconnection/RTCStatsCallback.h" 77 #include "modules/peerconnection/RTCStatsCallback.h"
77 #include "modules/peerconnection/RTCStatsReport.h" 78 #include "modules/peerconnection/RTCStatsReport.h"
78 #include "modules/peerconnection/RTCStatsRequestImpl.h" 79 #include "modules/peerconnection/RTCStatsRequestImpl.h"
79 #include "modules/peerconnection/RTCVoidRequestImpl.h" 80 #include "modules/peerconnection/RTCVoidRequestImpl.h"
80 #include "modules/peerconnection/RTCVoidRequestPromiseImpl.h" 81 #include "modules/peerconnection/RTCVoidRequestPromiseImpl.h"
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 return; 1117 return;
1117 } 1118 }
1118 1119
1119 size_t pos = local_streams_.Find(stream); 1120 size_t pos = local_streams_.Find(stream);
1120 if (pos == kNotFound) 1121 if (pos == kNotFound)
1121 return; 1122 return;
1122 1123
1123 local_streams_.erase(pos); 1124 local_streams_.erase(pos);
1124 1125
1125 peer_handler_->RemoveStream(stream->Descriptor()); 1126 peer_handler_->RemoveStream(stream->Descriptor());
1127
1128 // The senders of removed tracks will have become inactive.
1129 RemoveInactiveSenders();
1126 } 1130 }
1127 1131
1128 MediaStreamVector RTCPeerConnection::getLocalStreams() const { 1132 MediaStreamVector RTCPeerConnection::getLocalStreams() const {
1129 return local_streams_; 1133 return local_streams_;
1130 } 1134 }
1131 1135
1132 MediaStreamVector RTCPeerConnection::getRemoteStreams() const { 1136 MediaStreamVector RTCPeerConnection::getRemoteStreams() const {
1133 return remote_streams_; 1137 return remote_streams_;
1134 } 1138 }
1135 1139
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 ExecutionContext* context = ExecutionContext::From(script_state); 1175 ExecutionContext* context = ExecutionContext::From(script_state);
1172 UseCounter::Count(context, UseCounter::kRTCPeerConnectionGetStats); 1176 UseCounter::Count(context, UseCounter::kRTCPeerConnectionGetStats);
1173 1177
1174 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); 1178 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
1175 ScriptPromise promise = resolver->Promise(); 1179 ScriptPromise promise = resolver->Promise();
1176 peer_handler_->GetStats(WebRTCStatsReportCallbackResolver::Create(resolver)); 1180 peer_handler_->GetStats(WebRTCStatsReportCallbackResolver::Create(resolver));
1177 1181
1178 return promise; 1182 return promise;
1179 } 1183 }
1180 1184
1185 HeapVector<Member<RTCRtpSender>> RTCPeerConnection::getSenders() {
1186 WebVector<std::unique_ptr<WebRTCRtpSender>> web_rtp_senders =
1187 peer_handler_->GetSenders();
1188 HeapVector<Member<RTCRtpSender>> rtp_senders(web_rtp_senders.size());
1189 for (size_t i = 0; i < web_rtp_senders.size(); ++i) {
1190 uintptr_t id = web_rtp_senders[i]->Id();
1191 const auto it = rtp_senders_.find(id);
1192 if (it != rtp_senders_.end()) {
1193 rtp_senders[i] = it->value;
1194 } else {
1195 // There does not exist an |RTCRtpSender| for this |WebRTCRtpSender|
1196 // yet, create it.
1197 MediaStreamTrack* track = nullptr;
1198 if (web_rtp_senders[i]->Track()) {
1199 track = GetLocalTrackById(web_rtp_senders[i]->Track()->Id());
1200 DCHECK(track);
1201 }
1202 RTCRtpSender* rtp_sender =
1203 new RTCRtpSender(std::move(web_rtp_senders[i]), track);
1204 rtp_senders_.insert(id, rtp_sender);
1205 rtp_senders[i] = rtp_sender;
1206 }
1207 }
1208 return rtp_senders;
1209 }
1210
1181 HeapVector<Member<RTCRtpReceiver>> RTCPeerConnection::getReceivers() { 1211 HeapVector<Member<RTCRtpReceiver>> RTCPeerConnection::getReceivers() {
1182 WebVector<std::unique_ptr<WebRTCRtpReceiver>> web_rtp_receivers = 1212 WebVector<std::unique_ptr<WebRTCRtpReceiver>> web_rtp_receivers =
1183 peer_handler_->GetReceivers(); 1213 peer_handler_->GetReceivers();
1184 HeapVector<Member<RTCRtpReceiver>> rtp_receivers(web_rtp_receivers.size()); 1214 HeapVector<Member<RTCRtpReceiver>> rtp_receivers(web_rtp_receivers.size());
1185 for (size_t i = 0; i < web_rtp_receivers.size(); ++i) { 1215 for (size_t i = 0; i < web_rtp_receivers.size(); ++i) {
1186 uintptr_t id = web_rtp_receivers[i]->Id(); 1216 uintptr_t id = web_rtp_receivers[i]->Id();
1187 const auto it = rtp_receivers_.find(id); 1217 const auto it = rtp_receivers_.find(id);
1188 if (it != rtp_receivers_.end()) { 1218 if (it != rtp_receivers_.end()) {
1189 rtp_receivers[i] = it->value; 1219 rtp_receivers[i] = it->value;
1190 } else { 1220 } else {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 RTCDataChannel::ReadyState handler_state = channel->GetHandlerState(); 1266 RTCDataChannel::ReadyState handler_state = channel->GetHandlerState();
1237 if (handler_state != RTCDataChannel::kReadyStateConnecting) { 1267 if (handler_state != RTCDataChannel::kReadyStateConnecting) {
1238 // There was an early state transition. Don't miss it! 1268 // There was an early state transition. Don't miss it!
1239 channel->DidChangeReadyState(handler_state); 1269 channel->DidChangeReadyState(handler_state);
1240 } 1270 }
1241 has_data_channels_ = true; 1271 has_data_channels_ = true;
1242 1272
1243 return channel; 1273 return channel;
1244 } 1274 }
1245 1275
1246 bool RTCPeerConnection::HasLocalStreamWithTrackId(const String& track_id) { 1276 MediaStreamTrack* RTCPeerConnection::GetLocalTrackById(
1247 for (MediaStreamVector::iterator iter = local_streams_.begin(); 1277 const String& track_id) const {
1248 iter != local_streams_.end(); ++iter) { 1278 for (const auto& local_stream : local_streams_) {
1249 if ((*iter)->getTrackById(track_id)) 1279 MediaStreamTrack* track = local_stream->getTrackById(track_id);
1250 return true; 1280 if (track)
1281 return track;
1251 } 1282 }
1252 return false; 1283 return nullptr;
1253 } 1284 }
1254 1285
1255 MediaStreamTrack* RTCPeerConnection::GetRemoteTrackById( 1286 MediaStreamTrack* RTCPeerConnection::GetRemoteTrackById(
1256 const String& track_id) const { 1287 const String& track_id) const {
1257 for (const auto& remote_stream : remote_streams_) { 1288 for (const auto& remote_stream : remote_streams_) {
1258 MediaStreamTrack* track = remote_stream->getTrackById(track_id); 1289 MediaStreamTrack* track = remote_stream->getTrackById(track_id);
1259 if (track) 1290 if (track)
1260 return track; 1291 return track;
1261 } 1292 }
1262 return nullptr; 1293 return nullptr;
1263 } 1294 }
1264 1295
1296 void RTCPeerConnection::RemoveInactiveSenders() {
1297 std::set<uintptr_t> inactive_sender_ids;
1298 for (uintptr_t id : rtp_senders_.Keys()) {
1299 inactive_sender_ids.insert(id);
1300 }
1301 for (const auto& web_rtp_sender : peer_handler_->GetSenders()) {
1302 inactive_sender_ids.erase(web_rtp_sender->Id());
1303 }
1304 for (uintptr_t id : inactive_sender_ids) {
1305 rtp_senders_.erase(id);
1306 }
1307 }
1308
1265 void RTCPeerConnection::RemoveInactiveReceivers() { 1309 void RTCPeerConnection::RemoveInactiveReceivers() {
1266 std::set<uintptr_t> inactive_receiver_ids; 1310 std::set<uintptr_t> inactive_receiver_ids;
1267 for (uintptr_t id : rtp_receivers_.Keys()) { 1311 for (uintptr_t id : rtp_receivers_.Keys()) {
1268 inactive_receiver_ids.insert(id); 1312 inactive_receiver_ids.insert(id);
1269 } 1313 }
1270 for (const auto& web_rtp_receiver : peer_handler_->GetReceivers()) { 1314 for (const auto& web_rtp_receiver : peer_handler_->GetReceivers()) {
1271 inactive_receiver_ids.erase(web_rtp_receiver->Id()); 1315 inactive_receiver_ids.erase(web_rtp_receiver->Id());
1272 } 1316 }
1273 for (uintptr_t id : inactive_receiver_ids) { 1317 for (uintptr_t id : inactive_receiver_ids) {
1274 rtp_receivers_.erase(id); 1318 rtp_receivers_.erase(id);
1275 } 1319 }
1276 } 1320 }
1277 1321
1278 RTCDTMFSender* RTCPeerConnection::createDTMFSender( 1322 RTCDTMFSender* RTCPeerConnection::createDTMFSender(
1279 MediaStreamTrack* track, 1323 MediaStreamTrack* track,
1280 ExceptionState& exception_state) { 1324 ExceptionState& exception_state) {
1281 if (ThrowExceptionIfSignalingStateClosed(signaling_state_, exception_state)) 1325 if (ThrowExceptionIfSignalingStateClosed(signaling_state_, exception_state))
1282 return nullptr; 1326 return nullptr;
1283 1327
1284 DCHECK(track); 1328 DCHECK(track);
1285 1329
1286 if (!HasLocalStreamWithTrackId(track->id())) { 1330 if (!GetLocalTrackById(track->id())) {
1287 exception_state.ThrowDOMException( 1331 exception_state.ThrowDOMException(
1288 kSyntaxError, "No local stream is available for the track provided."); 1332 kSyntaxError, "No local stream is available for the track provided.");
1289 return nullptr; 1333 return nullptr;
1290 } 1334 }
1291 1335
1292 RTCDTMFSender* dtmf_sender = RTCDTMFSender::Create( 1336 RTCDTMFSender* dtmf_sender = RTCDTMFSender::Create(
1293 GetExecutionContext(), peer_handler_.get(), track, exception_state); 1337 GetExecutionContext(), peer_handler_.get(), track, exception_state);
1294 if (exception_state.HadException()) 1338 if (exception_state.HadException())
1295 return nullptr; 1339 return nullptr;
1296 return dtmf_sender; 1340 return dtmf_sender;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 } 1588 }
1545 1589
1546 if (has_data_channels_) 1590 if (has_data_channels_)
1547 HostsUsingFeatures::CountAnyWorld( 1591 HostsUsingFeatures::CountAnyWorld(
1548 *document, HostsUsingFeatures::Feature::kRTCPeerConnectionDataChannel); 1592 *document, HostsUsingFeatures::Feature::kRTCPeerConnectionDataChannel);
1549 } 1593 }
1550 1594
1551 DEFINE_TRACE(RTCPeerConnection) { 1595 DEFINE_TRACE(RTCPeerConnection) {
1552 visitor->Trace(local_streams_); 1596 visitor->Trace(local_streams_);
1553 visitor->Trace(remote_streams_); 1597 visitor->Trace(remote_streams_);
1598 visitor->Trace(rtp_senders_);
1554 visitor->Trace(rtp_receivers_); 1599 visitor->Trace(rtp_receivers_);
1555 visitor->Trace(dispatch_scheduled_event_runner_); 1600 visitor->Trace(dispatch_scheduled_event_runner_);
1556 visitor->Trace(scheduled_events_); 1601 visitor->Trace(scheduled_events_);
1557 EventTargetWithInlineData::Trace(visitor); 1602 EventTargetWithInlineData::Trace(visitor);
1558 SuspendableObject::Trace(visitor); 1603 SuspendableObject::Trace(visitor);
1559 } 1604 }
1560 1605
1561 } // namespace blink 1606 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698