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

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

Issue 2759953003: Interface RTCRtpReceiver and RTCPeerConnection.getReceivers() added. (Closed)
Patch Set: DISALLOW_COPY_AND_ASSIGN Created 3 years, 8 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 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "modules/peerconnection/RTCPeerConnection.h" 31 #include "modules/peerconnection/RTCPeerConnection.h"
32 32
33 #include <algorithm> 33 #include <algorithm>
34 #include <memory> 34 #include <memory>
35 #include <set>
35 #include "bindings/core/v8/ExceptionMessages.h" 36 #include "bindings/core/v8/ExceptionMessages.h"
36 #include "bindings/core/v8/ExceptionState.h" 37 #include "bindings/core/v8/ExceptionState.h"
37 #include "bindings/core/v8/Microtask.h" 38 #include "bindings/core/v8/Microtask.h"
38 #include "bindings/core/v8/Nullable.h" 39 #include "bindings/core/v8/Nullable.h"
39 #include "bindings/core/v8/ScriptPromiseResolver.h" 40 #include "bindings/core/v8/ScriptPromiseResolver.h"
40 #include "bindings/core/v8/ScriptState.h" 41 #include "bindings/core/v8/ScriptState.h"
41 #include "bindings/core/v8/ScriptValue.h" 42 #include "bindings/core/v8/ScriptValue.h"
42 #include "bindings/core/v8/V8ThrowException.h" 43 #include "bindings/core/v8/V8ThrowException.h"
43 #include "bindings/modules/v8/RTCIceCandidateInitOrRTCIceCandidate.h" 44 #include "bindings/modules/v8/RTCIceCandidateInitOrRTCIceCandidate.h"
44 #include "bindings/modules/v8/V8MediaStreamTrack.h" 45 #include "bindings/modules/v8/V8MediaStreamTrack.h"
(...skipping 15 matching lines...) Expand all
60 #include "modules/mediastream/MediaStreamEvent.h" 61 #include "modules/mediastream/MediaStreamEvent.h"
61 #include "modules/peerconnection/RTCAnswerOptions.h" 62 #include "modules/peerconnection/RTCAnswerOptions.h"
62 #include "modules/peerconnection/RTCConfiguration.h" 63 #include "modules/peerconnection/RTCConfiguration.h"
63 #include "modules/peerconnection/RTCDTMFSender.h" 64 #include "modules/peerconnection/RTCDTMFSender.h"
64 #include "modules/peerconnection/RTCDataChannel.h" 65 #include "modules/peerconnection/RTCDataChannel.h"
65 #include "modules/peerconnection/RTCDataChannelEvent.h" 66 #include "modules/peerconnection/RTCDataChannelEvent.h"
66 #include "modules/peerconnection/RTCIceServer.h" 67 #include "modules/peerconnection/RTCIceServer.h"
67 #include "modules/peerconnection/RTCOfferOptions.h" 68 #include "modules/peerconnection/RTCOfferOptions.h"
68 #include "modules/peerconnection/RTCPeerConnectionErrorCallback.h" 69 #include "modules/peerconnection/RTCPeerConnectionErrorCallback.h"
69 #include "modules/peerconnection/RTCPeerConnectionIceEvent.h" 70 #include "modules/peerconnection/RTCPeerConnectionIceEvent.h"
71 #include "modules/peerconnection/RTCRtpReceiver.h"
70 #include "modules/peerconnection/RTCSessionDescription.h" 72 #include "modules/peerconnection/RTCSessionDescription.h"
71 #include "modules/peerconnection/RTCSessionDescriptionCallback.h" 73 #include "modules/peerconnection/RTCSessionDescriptionCallback.h"
72 #include "modules/peerconnection/RTCSessionDescriptionInit.h" 74 #include "modules/peerconnection/RTCSessionDescriptionInit.h"
73 #include "modules/peerconnection/RTCSessionDescriptionRequestImpl.h" 75 #include "modules/peerconnection/RTCSessionDescriptionRequestImpl.h"
74 #include "modules/peerconnection/RTCSessionDescriptionRequestPromiseImpl.h" 76 #include "modules/peerconnection/RTCSessionDescriptionRequestPromiseImpl.h"
75 #include "modules/peerconnection/RTCStatsCallback.h" 77 #include "modules/peerconnection/RTCStatsCallback.h"
76 #include "modules/peerconnection/RTCStatsReport.h" 78 #include "modules/peerconnection/RTCStatsReport.h"
77 #include "modules/peerconnection/RTCStatsRequestImpl.h" 79 #include "modules/peerconnection/RTCStatsRequestImpl.h"
78 #include "modules/peerconnection/RTCVoidRequestImpl.h" 80 #include "modules/peerconnection/RTCVoidRequestImpl.h"
79 #include "modules/peerconnection/RTCVoidRequestPromiseImpl.h" 81 #include "modules/peerconnection/RTCVoidRequestPromiseImpl.h"
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 ExecutionContext* context = scriptState->getExecutionContext(); 1174 ExecutionContext* context = scriptState->getExecutionContext();
1173 UseCounter::count(context, UseCounter::RTCPeerConnectionGetStats); 1175 UseCounter::count(context, UseCounter::RTCPeerConnectionGetStats);
1174 1176
1175 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 1177 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
1176 ScriptPromise promise = resolver->promise(); 1178 ScriptPromise promise = resolver->promise();
1177 m_peerHandler->getStats(WebRTCStatsReportCallbackResolver::create(resolver)); 1179 m_peerHandler->getStats(WebRTCStatsReportCallbackResolver::create(resolver));
1178 1180
1179 return promise; 1181 return promise;
1180 } 1182 }
1181 1183
1184 HeapVector<Member<RTCRtpReceiver>> RTCPeerConnection::getReceivers() {
1185 WebVector<std::unique_ptr<WebRTCRtpReceiver>> webRtpReceivers =
1186 m_peerHandler->getReceivers();
1187 HeapVector<Member<RTCRtpReceiver>> rtpReceivers(webRtpReceivers.size());
1188 for (size_t i = 0; i < webRtpReceivers.size(); ++i) {
1189 uintptr_t id = webRtpReceivers[i]->id();
1190 const auto it = m_rtpReceivers.find(id);
1191 if (it != m_rtpReceivers.end()) {
1192 rtpReceivers[i] = it->value;
1193 } else {
1194 // There does not exist a |RTCRtpReceiver| for this |WebRTCRtpReceiver|
1195 // yet, create it.
1196 MediaStreamTrack* track =
1197 getRemoteTrackById(webRtpReceivers[i]->track().id());
1198 DCHECK(track);
1199 RTCRtpReceiver* rtpReceiver =
1200 new RTCRtpReceiver(std::move(webRtpReceivers[i]), track);
1201 m_rtpReceivers.insert(id, rtpReceiver);
1202 rtpReceivers[i] = rtpReceiver;
1203 }
1204 }
1205 return rtpReceivers;
1206 }
1207
1182 RTCDataChannel* RTCPeerConnection::createDataChannel( 1208 RTCDataChannel* RTCPeerConnection::createDataChannel(
1183 ScriptState* scriptState, 1209 ScriptState* scriptState,
1184 String label, 1210 String label,
1185 const Dictionary& options, 1211 const Dictionary& options,
1186 ExceptionState& exceptionState) { 1212 ExceptionState& exceptionState) {
1187 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 1213 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
1188 return nullptr; 1214 return nullptr;
1189 1215
1190 WebRTCDataChannelInit init; 1216 WebRTCDataChannelInit init;
1191 DictionaryHelper::get(options, "ordered", init.ordered); 1217 DictionaryHelper::get(options, "ordered", init.ordered);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 1253
1228 bool RTCPeerConnection::hasLocalStreamWithTrackId(const String& trackId) { 1254 bool RTCPeerConnection::hasLocalStreamWithTrackId(const String& trackId) {
1229 for (MediaStreamVector::iterator iter = m_localStreams.begin(); 1255 for (MediaStreamVector::iterator iter = m_localStreams.begin();
1230 iter != m_localStreams.end(); ++iter) { 1256 iter != m_localStreams.end(); ++iter) {
1231 if ((*iter)->getTrackById(trackId)) 1257 if ((*iter)->getTrackById(trackId))
1232 return true; 1258 return true;
1233 } 1259 }
1234 return false; 1260 return false;
1235 } 1261 }
1236 1262
1263 MediaStreamTrack* RTCPeerConnection::getRemoteTrackById(
1264 const String& trackId) const {
1265 for (const auto& remoteStream : m_remoteStreams) {
1266 MediaStreamTrack* track = remoteStream->getTrackById(trackId);
1267 if (track)
1268 return track;
1269 }
1270 return nullptr;
1271 }
1272
1273 void RTCPeerConnection::removeInactiveReceivers() {
1274 std::set<uintptr_t> inactiveReceiverIds;
1275 for (uintptr_t id : m_rtpReceivers.keys()) {
1276 inactiveReceiverIds.insert(id);
1277 }
1278 for (const auto& webRtpReceiver : m_peerHandler->getReceivers()) {
1279 inactiveReceiverIds.erase(webRtpReceiver->id());
1280 }
1281 for (uintptr_t id : inactiveReceiverIds) {
1282 m_rtpReceivers.erase(id);
1283 }
1284 }
1285
1237 RTCDTMFSender* RTCPeerConnection::createDTMFSender( 1286 RTCDTMFSender* RTCPeerConnection::createDTMFSender(
1238 MediaStreamTrack* track, 1287 MediaStreamTrack* track,
1239 ExceptionState& exceptionState) { 1288 ExceptionState& exceptionState) {
1240 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 1289 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
1241 return nullptr; 1290 return nullptr;
1242 1291
1243 DCHECK(track); 1292 DCHECK(track);
1244 1293
1245 if (!hasLocalStreamWithTrackId(track->id())) { 1294 if (!hasLocalStreamWithTrackId(track->id())) {
1246 exceptionState.throwDOMException( 1295 exceptionState.throwDOMException(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 MediaStream* stream = static_cast<MediaStream*>(streamDescriptor->client()); 1375 MediaStream* stream = static_cast<MediaStream*>(streamDescriptor->client());
1327 stream->streamEnded(); 1376 stream->streamEnded();
1328 1377
1329 if (m_signalingState == SignalingStateClosed) 1378 if (m_signalingState == SignalingStateClosed)
1330 return; 1379 return;
1331 1380
1332 size_t pos = m_remoteStreams.find(stream); 1381 size_t pos = m_remoteStreams.find(stream);
1333 DCHECK(pos != kNotFound); 1382 DCHECK(pos != kNotFound);
1334 m_remoteStreams.erase(pos); 1383 m_remoteStreams.erase(pos);
1335 1384
1385 // The receivers of removed tracks will have become inactive.
1386 removeInactiveReceivers();
1387
1336 scheduleDispatchEvent( 1388 scheduleDispatchEvent(
1337 MediaStreamEvent::create(EventTypeNames::removestream, stream)); 1389 MediaStreamEvent::create(EventTypeNames::removestream, stream));
1338 } 1390 }
1339 1391
1340 void RTCPeerConnection::didAddRemoteDataChannel( 1392 void RTCPeerConnection::didAddRemoteDataChannel(
1341 WebRTCDataChannelHandler* handler) { 1393 WebRTCDataChannelHandler* handler) {
1342 DCHECK(!m_closed); 1394 DCHECK(!m_closed);
1343 DCHECK(getExecutionContext()->isContextThread()); 1395 DCHECK(getExecutionContext()->isContextThread());
1344 1396
1345 if (m_signalingState == SignalingStateClosed) 1397 if (m_signalingState == SignalingStateClosed)
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 } 1550 }
1499 1551
1500 if (m_hasDataChannels) 1552 if (m_hasDataChannels)
1501 HostsUsingFeatures::countAnyWorld( 1553 HostsUsingFeatures::countAnyWorld(
1502 *document, HostsUsingFeatures::Feature::RTCPeerConnectionDataChannel); 1554 *document, HostsUsingFeatures::Feature::RTCPeerConnectionDataChannel);
1503 } 1555 }
1504 1556
1505 DEFINE_TRACE(RTCPeerConnection) { 1557 DEFINE_TRACE(RTCPeerConnection) {
1506 visitor->trace(m_localStreams); 1558 visitor->trace(m_localStreams);
1507 visitor->trace(m_remoteStreams); 1559 visitor->trace(m_remoteStreams);
1560 visitor->trace(m_rtpReceivers);
1508 visitor->trace(m_dispatchScheduledEventRunner); 1561 visitor->trace(m_dispatchScheduledEventRunner);
1509 visitor->trace(m_scheduledEvents); 1562 visitor->trace(m_scheduledEvents);
1510 EventTargetWithInlineData::trace(visitor); 1563 EventTargetWithInlineData::trace(visitor);
1511 SuspendableObject::trace(visitor); 1564 SuspendableObject::trace(visitor);
1512 } 1565 }
1513 1566
1514 } // namespace blink 1567 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698