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

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

Issue 2759953003: Interface RTCRtpReceiver and RTCPeerConnection.getReceivers() added. (Closed)
Patch Set: Addressed/added comments 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 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 ExecutionContext* context = scriptState->getExecutionContext(); 1169 ExecutionContext* context = scriptState->getExecutionContext();
1168 UseCounter::count(context, UseCounter::RTCPeerConnectionGetStats); 1170 UseCounter::count(context, UseCounter::RTCPeerConnectionGetStats);
1169 1171
1170 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 1172 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
1171 ScriptPromise promise = resolver->promise(); 1173 ScriptPromise promise = resolver->promise();
1172 m_peerHandler->getStats(WebRTCStatsReportCallbackResolver::create(resolver)); 1174 m_peerHandler->getStats(WebRTCStatsReportCallbackResolver::create(resolver));
1173 1175
1174 return promise; 1176 return promise;
1175 } 1177 }
1176 1178
1179 HeapVector<Member<RTCRtpReceiver>> RTCPeerConnection::getReceivers() {
1180 WebVector<std::unique_ptr<WebRTCRtpReceiver>> webRtpReceivers =
1181 m_peerHandler->getReceivers();
1182 HeapVector<Member<RTCRtpReceiver>> rtpReceivers(webRtpReceivers.size());
1183 for (size_t i = 0; i < webRtpReceivers.size(); ++i) {
1184 uintptr_t id = webRtpReceivers[i]->id();
1185 const auto it = m_rtpReceivers.find(id);
1186 if (it != m_rtpReceivers.end()) {
1187 rtpReceivers[i] = it->value;
1188 } else {
1189 // There does not exist a JavaScript |RTCRtpReceiver| for this
1190 // |WebRTCRtpReceiver| yet, create it.
1191 MediaStreamTrack* track =
1192 getRemoteTrackById(webRtpReceivers[i]->track().id());
1193 DCHECK(track);
1194 RTCRtpReceiver* rtpReceiver =
1195 new RTCRtpReceiver(std::move(webRtpReceivers[i]), track);
1196 m_rtpReceivers.insert(id, rtpReceiver);
1197 rtpReceivers[i] = rtpReceiver;
1198 }
1199 }
1200 return rtpReceivers;
1201 }
1202
1177 RTCDataChannel* RTCPeerConnection::createDataChannel( 1203 RTCDataChannel* RTCPeerConnection::createDataChannel(
1178 ScriptState* scriptState, 1204 ScriptState* scriptState,
1179 String label, 1205 String label,
1180 const Dictionary& options, 1206 const Dictionary& options,
1181 ExceptionState& exceptionState) { 1207 ExceptionState& exceptionState) {
1182 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 1208 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
1183 return nullptr; 1209 return nullptr;
1184 1210
1185 WebRTCDataChannelInit init; 1211 WebRTCDataChannelInit init;
1186 DictionaryHelper::get(options, "ordered", init.ordered); 1212 DictionaryHelper::get(options, "ordered", init.ordered);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 1248
1223 bool RTCPeerConnection::hasLocalStreamWithTrackId(const String& trackId) { 1249 bool RTCPeerConnection::hasLocalStreamWithTrackId(const String& trackId) {
1224 for (MediaStreamVector::iterator iter = m_localStreams.begin(); 1250 for (MediaStreamVector::iterator iter = m_localStreams.begin();
1225 iter != m_localStreams.end(); ++iter) { 1251 iter != m_localStreams.end(); ++iter) {
1226 if ((*iter)->getTrackById(trackId)) 1252 if ((*iter)->getTrackById(trackId))
1227 return true; 1253 return true;
1228 } 1254 }
1229 return false; 1255 return false;
1230 } 1256 }
1231 1257
1258 MediaStreamTrack* RTCPeerConnection::getRemoteTrackById(
1259 const String& trackId) const {
1260 for (const auto& remoteStream : m_remoteStreams) {
1261 MediaStreamTrack* track = remoteStream->getTrackById(trackId);
1262 if (track)
1263 return track;
1264 }
1265 return nullptr;
1266 }
1267
1268 void RTCPeerConnection::removeInactiveReceivers() {
1269 std::set<uintptr_t> inactiveReceiverIds;
1270 for (uintptr_t id : m_rtpReceivers.keys()) {
1271 inactiveReceiverIds.insert(id);
1272 }
1273 for (const auto& webRtpReceiver : m_peerHandler->getReceivers()) {
1274 inactiveReceiverIds.erase(webRtpReceiver->id());
1275 }
1276 for (uintptr_t id : inactiveReceiverIds) {
1277 m_rtpReceivers.erase(id);
1278 }
1279 }
1280
1232 RTCDTMFSender* RTCPeerConnection::createDTMFSender( 1281 RTCDTMFSender* RTCPeerConnection::createDTMFSender(
1233 MediaStreamTrack* track, 1282 MediaStreamTrack* track,
1234 ExceptionState& exceptionState) { 1283 ExceptionState& exceptionState) {
1235 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 1284 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
1236 return nullptr; 1285 return nullptr;
1237 1286
1238 DCHECK(track); 1287 DCHECK(track);
1239 1288
1240 if (!hasLocalStreamWithTrackId(track->id())) { 1289 if (!hasLocalStreamWithTrackId(track->id())) {
1241 exceptionState.throwDOMException( 1290 exceptionState.throwDOMException(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 MediaStream* stream = static_cast<MediaStream*>(streamDescriptor->client()); 1370 MediaStream* stream = static_cast<MediaStream*>(streamDescriptor->client());
1322 stream->streamEnded(); 1371 stream->streamEnded();
1323 1372
1324 if (m_signalingState == SignalingStateClosed) 1373 if (m_signalingState == SignalingStateClosed)
1325 return; 1374 return;
1326 1375
1327 size_t pos = m_remoteStreams.find(stream); 1376 size_t pos = m_remoteStreams.find(stream);
1328 DCHECK(pos != kNotFound); 1377 DCHECK(pos != kNotFound);
1329 m_remoteStreams.remove(pos); 1378 m_remoteStreams.remove(pos);
1330 1379
1380 // The receivers of removed tracks will have become inactive.
1381 removeInactiveReceivers();
1382
1331 scheduleDispatchEvent( 1383 scheduleDispatchEvent(
1332 MediaStreamEvent::create(EventTypeNames::removestream, stream)); 1384 MediaStreamEvent::create(EventTypeNames::removestream, stream));
1333 } 1385 }
1334 1386
1335 void RTCPeerConnection::didAddRemoteDataChannel( 1387 void RTCPeerConnection::didAddRemoteDataChannel(
1336 WebRTCDataChannelHandler* handler) { 1388 WebRTCDataChannelHandler* handler) {
1337 DCHECK(!m_closed); 1389 DCHECK(!m_closed);
1338 DCHECK(getExecutionContext()->isContextThread()); 1390 DCHECK(getExecutionContext()->isContextThread());
1339 1391
1340 if (m_signalingState == SignalingStateClosed) 1392 if (m_signalingState == SignalingStateClosed)
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 } 1545 }
1494 1546
1495 if (m_hasDataChannels) 1547 if (m_hasDataChannels)
1496 HostsUsingFeatures::countAnyWorld( 1548 HostsUsingFeatures::countAnyWorld(
1497 *document, HostsUsingFeatures::Feature::RTCPeerConnectionDataChannel); 1549 *document, HostsUsingFeatures::Feature::RTCPeerConnectionDataChannel);
1498 } 1550 }
1499 1551
1500 DEFINE_TRACE(RTCPeerConnection) { 1552 DEFINE_TRACE(RTCPeerConnection) {
1501 visitor->trace(m_localStreams); 1553 visitor->trace(m_localStreams);
1502 visitor->trace(m_remoteStreams); 1554 visitor->trace(m_remoteStreams);
1555 visitor->trace(m_rtpReceivers);
1503 visitor->trace(m_dispatchScheduledEventRunner); 1556 visitor->trace(m_dispatchScheduledEventRunner);
1504 visitor->trace(m_scheduledEvents); 1557 visitor->trace(m_scheduledEvents);
1505 EventTargetWithInlineData::trace(visitor); 1558 EventTargetWithInlineData::trace(visitor);
1506 SuspendableObject::trace(visitor); 1559 SuspendableObject::trace(visitor);
1507 } 1560 }
1508 1561
1509 } // namespace blink 1562 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698