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 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1103 stream->RegisterObserver(this); | 1103 stream->RegisterObserver(this); |
1104 for (auto& track : stream->getTracks()) { | 1104 for (auto& track : stream->getTracks()) { |
1105 DCHECK(track->Component()); | 1105 DCHECK(track->Component()); |
1106 tracks_.insert(track->Component(), track); | 1106 tracks_.insert(track->Component(), track); |
1107 } | 1107 } |
1108 | 1108 |
1109 bool valid = peer_handler_->AddStream(stream->Descriptor(), constraints); | 1109 bool valid = peer_handler_->AddStream(stream->Descriptor(), constraints); |
1110 if (!valid) | 1110 if (!valid) |
1111 exception_state.ThrowDOMException(kSyntaxError, | 1111 exception_state.ThrowDOMException(kSyntaxError, |
1112 "Unable to add the provided stream."); | 1112 "Unable to add the provided stream."); |
1113 // Ensure |rtp_senders_| is up-to-date. | |
1114 getSenders(); | |
1113 } | 1115 } |
1114 | 1116 |
1115 void RTCPeerConnection::removeStream(MediaStream* stream, | 1117 void RTCPeerConnection::removeStream(MediaStream* stream, |
1116 ExceptionState& exception_state) { | 1118 ExceptionState& exception_state) { |
1117 if (ThrowExceptionIfSignalingStateClosed(signaling_state_, exception_state)) | 1119 if (ThrowExceptionIfSignalingStateClosed(signaling_state_, exception_state)) |
1118 return; | 1120 return; |
1119 | 1121 |
1120 if (!stream) { | 1122 if (!stream) { |
1121 exception_state.ThrowDOMException( | 1123 exception_state.ThrowDOMException( |
1122 kTypeMismatchError, | 1124 kTypeMismatchError, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1229 DCHECK(track); | 1231 DCHECK(track); |
1230 RTCRtpReceiver* rtp_receiver = | 1232 RTCRtpReceiver* rtp_receiver = |
1231 new RTCRtpReceiver(std::move(web_rtp_receivers[i]), track); | 1233 new RTCRtpReceiver(std::move(web_rtp_receivers[i]), track); |
1232 rtp_receivers_.insert(id, rtp_receiver); | 1234 rtp_receivers_.insert(id, rtp_receiver); |
1233 rtp_receivers[i] = rtp_receiver; | 1235 rtp_receivers[i] = rtp_receiver; |
1234 } | 1236 } |
1235 } | 1237 } |
1236 return rtp_receivers; | 1238 return rtp_receivers; |
1237 } | 1239 } |
1238 | 1240 |
1241 RTCRtpSender* RTCPeerConnection::addTrack(MediaStreamTrack* track, | |
1242 MediaStreamVector streams, | |
1243 ExceptionState& exception_state) { | |
1244 DCHECK(track); | |
1245 DCHECK(track->Component()); | |
1246 if (ThrowExceptionIfSignalingStateClosed(signaling_state_, exception_state)) | |
1247 return nullptr; | |
1248 if (streams.size() >= 2) { | |
1249 // TODO(hbos): Don't throw an exception when this is supported by the lower | |
1250 // layers. https://crbug.com/webrtc/7932 | |
1251 exception_state.ThrowDOMException( | |
1252 kNotSupportedError, | |
1253 "Adding a track to multiple streams is not supported."); | |
1254 return nullptr; | |
1255 } | |
1256 for (const auto sender_entry : rtp_senders_) { | |
1257 RTCRtpSender* sender = sender_entry.value; | |
1258 if (sender->track() == track) { | |
1259 exception_state.ThrowDOMException( | |
1260 kInvalidAccessError, "A sender already exists for the track."); | |
1261 return nullptr; | |
1262 } | |
1263 } | |
1264 | |
1265 WebVector<WebMediaStream> web_streams(streams.size()); | |
1266 for (size_t i = 0; i < streams.size(); ++i) { | |
1267 web_streams[i] = streams[i]->Descriptor(); | |
1268 } | |
1269 std::unique_ptr<WebRTCRtpSender> web_rtp_sender = | |
1270 peer_handler_->AddTrack(track->Component(), web_streams); | |
1271 if (!web_rtp_sender) { | |
1272 exception_state.ThrowDOMException( | |
1273 kNotSupportedError, "A sender could not be created for this track."); | |
1274 return nullptr; | |
1275 } | |
1276 | |
1277 uintptr_t id = web_rtp_sender->Id(); | |
1278 DCHECK(rtp_senders_.find(id) == rtp_senders_.end()); | |
1279 RTCRtpSender* rtp_sender = new RTCRtpSender(std::move(web_rtp_sender), track); | |
Guido Urdaneta
2017/07/05 15:37:06
nit: I think the preferred style in Blink is to ha
hbos_chromium
2017/07/06 12:31:37
Yes, done. I didn't make it Create because unlike
| |
1280 tracks_.insert(track->Component(), track); | |
1281 rtp_senders_.insert(id, rtp_sender); | |
1282 return rtp_sender; | |
1283 } | |
1284 | |
1285 void RTCPeerConnection::removeTrack(RTCRtpSender* sender, | |
1286 ExceptionState& exception_state) { | |
1287 DCHECK(sender); | |
Guido Urdaneta
2017/07/05 15:37:06
Is this DCHECK right? What prevents the applicatio
hbos_chromium
2017/07/06 12:31:38
Yes, it's non-optional in the IDL so null should a
| |
1288 if (ThrowExceptionIfSignalingStateClosed(signaling_state_, exception_state)) | |
1289 return; | |
1290 if (rtp_senders_.find(sender->web_rtp_sender()->Id()) == rtp_senders_.end()) { | |
1291 exception_state.ThrowDOMException( | |
1292 kInvalidAccessError, | |
1293 "The sender was not created by this peer connection."); | |
1294 } | |
1295 | |
1296 if (!peer_handler_->RemoveTrack(sender->web_rtp_sender())) { | |
1297 // Operation aborted. This indicates that the sender is no longer used by | |
1298 // the peer connection, i.e. that it was removed due to setting a remote | |
1299 // description of type "rollback". | |
1300 // Note: until re-using senders is supported these are also removed by | |
Guido Urdaneta
2017/07/05 15:37:06
Is reusing senders not supported by the WebRTC lib
hbos_chromium
2017/07/06 12:31:37
Yes I was referring to the WebRTC library limitati
Guido Urdaneta
2017/07/06 12:43:42
Add crbug.com reference.
| |
1301 // |RemoveTrack|. | |
1302 return; | |
1303 } | |
1304 // Successfully removing the track results in the sender's track property | |
1305 // being nulled. | |
1306 DCHECK(!sender->web_rtp_sender()->Track()); | |
1307 sender->SetTrack(nullptr); | |
1308 } | |
1309 | |
1239 RTCDataChannel* RTCPeerConnection::createDataChannel( | 1310 RTCDataChannel* RTCPeerConnection::createDataChannel( |
1240 ScriptState* script_state, | 1311 ScriptState* script_state, |
1241 String label, | 1312 String label, |
1242 const RTCDataChannelInit& data_channel_dict, | 1313 const RTCDataChannelInit& data_channel_dict, |
1243 ExceptionState& exception_state) { | 1314 ExceptionState& exception_state) { |
1244 if (ThrowExceptionIfSignalingStateClosed(signaling_state_, exception_state)) | 1315 if (ThrowExceptionIfSignalingStateClosed(signaling_state_, exception_state)) |
1245 return nullptr; | 1316 return nullptr; |
1246 | 1317 |
1247 WebRTCDataChannelInit init; | 1318 WebRTCDataChannelInit init; |
1248 init.ordered = data_channel_dict.ordered(); | 1319 init.ordered = data_channel_dict.ordered(); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1584 visitor->Trace(rtp_senders_); | 1655 visitor->Trace(rtp_senders_); |
1585 visitor->Trace(rtp_receivers_); | 1656 visitor->Trace(rtp_receivers_); |
1586 visitor->Trace(dispatch_scheduled_event_runner_); | 1657 visitor->Trace(dispatch_scheduled_event_runner_); |
1587 visitor->Trace(scheduled_events_); | 1658 visitor->Trace(scheduled_events_); |
1588 EventTargetWithInlineData::Trace(visitor); | 1659 EventTargetWithInlineData::Trace(visitor); |
1589 SuspendableObject::Trace(visitor); | 1660 SuspendableObject::Trace(visitor); |
1590 MediaStreamObserver::Trace(visitor); | 1661 MediaStreamObserver::Trace(visitor); |
1591 } | 1662 } |
1592 | 1663 |
1593 } // namespace blink | 1664 } // namespace blink |
OLD | NEW |