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

Side by Side Diff: webrtc/api/peerconnection.cc

Issue 1975453002: Add PeerConnection IsClosed check. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Modified the checks. Modified the peerconnectioninterface unit test. Created 4 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 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 (*it)->Stop(); 751 (*it)->Stop();
752 senders_.erase(it); 752 senders_.erase(it);
753 753
754 observer_->OnRenegotiationNeeded(); 754 observer_->OnRenegotiationNeeded();
755 return true; 755 return true;
756 } 756 }
757 757
758 rtc::scoped_refptr<DtmfSenderInterface> PeerConnection::CreateDtmfSender( 758 rtc::scoped_refptr<DtmfSenderInterface> PeerConnection::CreateDtmfSender(
759 AudioTrackInterface* track) { 759 AudioTrackInterface* track) {
760 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender"); 760 TRACE_EVENT0("webrtc", "PeerConnection::CreateDtmfSender");
761 if (IsClosed()) {
762 return nullptr;
763 }
761 if (!track) { 764 if (!track) {
762 LOG(LS_ERROR) << "CreateDtmfSender - track is NULL."; 765 LOG(LS_ERROR) << "CreateDtmfSender - track is NULL.";
763 return NULL; 766 return NULL;
764 } 767 }
765 if (!local_streams_->FindAudioTrack(track->id())) { 768 if (!local_streams_->FindAudioTrack(track->id())) {
766 LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track."; 769 LOG(LS_ERROR) << "CreateDtmfSender is called with a non local audio track.";
767 return NULL; 770 return NULL;
768 } 771 }
769 772
770 rtc::scoped_refptr<DtmfSenderInterface> sender( 773 rtc::scoped_refptr<DtmfSenderInterface> sender(
771 DtmfSender::Create(track, signaling_thread(), session_.get())); 774 DtmfSender::Create(track, signaling_thread(), session_.get()));
772 if (!sender.get()) { 775 if (!sender.get()) {
773 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create."; 776 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create.";
774 return NULL; 777 return NULL;
775 } 778 }
776 return DtmfSenderProxy::Create(signaling_thread(), sender.get()); 779 return DtmfSenderProxy::Create(signaling_thread(), sender.get());
777 } 780 }
778 781
779 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender( 782 rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender(
780 const std::string& kind, 783 const std::string& kind,
781 const std::string& stream_id) { 784 const std::string& stream_id) {
782 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender"); 785 TRACE_EVENT0("webrtc", "PeerConnection::CreateSender");
786 if (IsClosed()) {
787 return nullptr;
788 }
783 rtc::scoped_refptr<RtpSenderInterface> new_sender; 789 rtc::scoped_refptr<RtpSenderInterface> new_sender;
784 if (kind == MediaStreamTrackInterface::kAudioKind) { 790 if (kind == MediaStreamTrackInterface::kAudioKind) {
785 new_sender = RtpSenderProxy::Create( 791 new_sender = RtpSenderProxy::Create(
786 signaling_thread(), new AudioRtpSender(session_.get(), stats_.get())); 792 signaling_thread(), new AudioRtpSender(session_.get(), stats_.get()));
787 } else if (kind == MediaStreamTrackInterface::kVideoKind) { 793 } else if (kind == MediaStreamTrackInterface::kVideoKind) {
788 new_sender = RtpSenderProxy::Create(signaling_thread(), 794 new_sender = RtpSenderProxy::Create(signaling_thread(),
789 new VideoRtpSender(session_.get())); 795 new VideoRtpSender(session_.get()));
790 } else { 796 } else {
791 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind; 797 LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind;
792 return new_sender; 798 return new_sender;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 return; 981 return;
976 } 982 }
977 983
978 session_->CreateAnswer(observer, session_options); 984 session_->CreateAnswer(observer, session_options);
979 } 985 }
980 986
981 void PeerConnection::SetLocalDescription( 987 void PeerConnection::SetLocalDescription(
982 SetSessionDescriptionObserver* observer, 988 SetSessionDescriptionObserver* observer,
983 SessionDescriptionInterface* desc) { 989 SessionDescriptionInterface* desc) {
984 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription"); 990 TRACE_EVENT0("webrtc", "PeerConnection::SetLocalDescription");
991 if (IsClosed()) {
992 return;
993 }
985 if (!VERIFY(observer != nullptr)) { 994 if (!VERIFY(observer != nullptr)) {
986 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL."; 995 LOG(LS_ERROR) << "SetLocalDescription - observer is NULL.";
987 return; 996 return;
988 } 997 }
989 if (!desc) { 998 if (!desc) {
990 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); 999 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL.");
991 return; 1000 return;
992 } 1001 }
993 // Update stats here so that we have the most recent stats for tracks and 1002 // Update stats here so that we have the most recent stats for tracks and
994 // streams that might be removed by updating the session description. 1003 // streams that might be removed by updating the session description.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 // MaybeStartGathering needs to be called after posting 1062 // MaybeStartGathering needs to be called after posting
1054 // MSG_SET_SESSIONDESCRIPTION_SUCCESS, so that we don't signal any candidates 1063 // MSG_SET_SESSIONDESCRIPTION_SUCCESS, so that we don't signal any candidates
1055 // before signaling that SetLocalDescription completed. 1064 // before signaling that SetLocalDescription completed.
1056 session_->MaybeStartGathering(); 1065 session_->MaybeStartGathering();
1057 } 1066 }
1058 1067
1059 void PeerConnection::SetRemoteDescription( 1068 void PeerConnection::SetRemoteDescription(
1060 SetSessionDescriptionObserver* observer, 1069 SetSessionDescriptionObserver* observer,
1061 SessionDescriptionInterface* desc) { 1070 SessionDescriptionInterface* desc) {
1062 TRACE_EVENT0("webrtc", "PeerConnection::SetRemoteDescription"); 1071 TRACE_EVENT0("webrtc", "PeerConnection::SetRemoteDescription");
1072 if (IsClosed()) {
1073 return;
1074 }
1063 if (!VERIFY(observer != nullptr)) { 1075 if (!VERIFY(observer != nullptr)) {
1064 LOG(LS_ERROR) << "SetRemoteDescription - observer is NULL."; 1076 LOG(LS_ERROR) << "SetRemoteDescription - observer is NULL.";
1065 return; 1077 return;
1066 } 1078 }
1067 if (!desc) { 1079 if (!desc) {
1068 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL."); 1080 PostSetSessionDescriptionFailure(observer, "SessionDescription is NULL.");
1069 return; 1081 return;
1070 } 1082 }
1071 // Update stats here so that we have the most recent stats for tracks and 1083 // Update stats here so that we have the most recent stats for tracks and
1072 // streams that might be removed by updating the session description. 1084 // streams that might be removed by updating the session description.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 } 1180 }
1169 port_allocator_->SetIceServers(stun_servers, turn_servers); 1181 port_allocator_->SetIceServers(stun_servers, turn_servers);
1170 } 1182 }
1171 session_->SetIceConfig(session_->ParseIceConfig(config)); 1183 session_->SetIceConfig(session_->ParseIceConfig(config));
1172 return session_->SetIceTransports(config.type); 1184 return session_->SetIceTransports(config.type);
1173 } 1185 }
1174 1186
1175 bool PeerConnection::AddIceCandidate( 1187 bool PeerConnection::AddIceCandidate(
1176 const IceCandidateInterface* ice_candidate) { 1188 const IceCandidateInterface* ice_candidate) {
1177 TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); 1189 TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate");
1190 if (IsClosed()) {
1191 return false;
1192 }
1178 return session_->ProcessIceMessage(ice_candidate); 1193 return session_->ProcessIceMessage(ice_candidate);
1179 } 1194 }
1180 1195
1181 bool PeerConnection::RemoveIceCandidates( 1196 bool PeerConnection::RemoveIceCandidates(
1182 const std::vector<cricket::Candidate>& candidates) { 1197 const std::vector<cricket::Candidate>& candidates) {
1183 TRACE_EVENT0("webrtc", "PeerConnection::RemoveIceCandidates"); 1198 TRACE_EVENT0("webrtc", "PeerConnection::RemoveIceCandidates");
1184 return session_->RemoveRemoteIceCandidates(candidates); 1199 return session_->RemoveRemoteIceCandidates(candidates);
1185 } 1200 }
1186 1201
1187 void PeerConnection::RegisterUMAObserver(UMAObserver* observer) { 1202 void PeerConnection::RegisterUMAObserver(UMAObserver* observer) {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 RTC_DCHECK(signaling_thread()->IsCurrent()); 1368 RTC_DCHECK(signaling_thread()->IsCurrent());
1354 if (IsClosed()) { 1369 if (IsClosed()) {
1355 return; 1370 return;
1356 } 1371 }
1357 ice_gathering_state_ = new_state; 1372 ice_gathering_state_ = new_state;
1358 observer_->OnIceGatheringChange(ice_gathering_state_); 1373 observer_->OnIceGatheringChange(ice_gathering_state_);
1359 } 1374 }
1360 1375
1361 void PeerConnection::OnIceCandidate(const IceCandidateInterface* candidate) { 1376 void PeerConnection::OnIceCandidate(const IceCandidateInterface* candidate) {
1362 RTC_DCHECK(signaling_thread()->IsCurrent()); 1377 RTC_DCHECK(signaling_thread()->IsCurrent());
1378 if (IsClosed()) {
1379 return;
1380 }
1363 observer_->OnIceCandidate(candidate); 1381 observer_->OnIceCandidate(candidate);
1364 } 1382 }
1365 1383
1366 void PeerConnection::OnIceCandidatesRemoved( 1384 void PeerConnection::OnIceCandidatesRemoved(
1367 const std::vector<cricket::Candidate>& candidates) { 1385 const std::vector<cricket::Candidate>& candidates) {
1368 RTC_DCHECK(signaling_thread()->IsCurrent()); 1386 RTC_DCHECK(signaling_thread()->IsCurrent());
1387 if (IsClosed()) {
1388 return;
1389 }
1369 observer_->OnIceCandidatesRemoved(candidates); 1390 observer_->OnIceCandidatesRemoved(candidates);
1370 } 1391 }
1371 1392
1372 void PeerConnection::OnIceConnectionReceivingChange(bool receiving) { 1393 void PeerConnection::OnIceConnectionReceivingChange(bool receiving) {
1373 RTC_DCHECK(signaling_thread()->IsCurrent()); 1394 RTC_DCHECK(signaling_thread()->IsCurrent());
1395 if (IsClosed()) {
1396 return;
1397 }
1374 observer_->OnIceConnectionReceivingChange(receiving); 1398 observer_->OnIceConnectionReceivingChange(receiving);
1375 } 1399 }
1376 1400
1377 void PeerConnection::ChangeSignalingState( 1401 void PeerConnection::ChangeSignalingState(
1378 PeerConnectionInterface::SignalingState signaling_state) { 1402 PeerConnectionInterface::SignalingState signaling_state) {
1379 signaling_state_ = signaling_state; 1403 signaling_state_ = signaling_state;
1380 if (signaling_state == kClosed) { 1404 if (signaling_state == kClosed) {
1381 ice_connection_state_ = kIceConnectionClosed; 1405 ice_connection_state_ = kIceConnectionClosed;
1382 observer_->OnIceConnectionChange(ice_connection_state_); 1406 observer_->OnIceConnectionChange(ice_connection_state_);
1383 if (ice_gathering_state_ != kIceGatheringComplete) { 1407 if (ice_gathering_state_ != kIceGatheringComplete) {
1384 ice_gathering_state_ = kIceGatheringComplete; 1408 ice_gathering_state_ = kIceGatheringComplete;
1385 observer_->OnIceGatheringChange(ice_gathering_state_); 1409 observer_->OnIceGatheringChange(ice_gathering_state_);
1386 } 1410 }
1387 } 1411 }
1388 observer_->OnSignalingChange(signaling_state_); 1412 observer_->OnSignalingChange(signaling_state_);
1389 } 1413 }
1390 1414
1391 void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track, 1415 void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track,
1392 MediaStreamInterface* stream) { 1416 MediaStreamInterface* stream) {
1417 if (IsClosed()) {
1418 return;
1419 }
1393 auto sender = FindSenderForTrack(track); 1420 auto sender = FindSenderForTrack(track);
1394 if (sender != senders_.end()) { 1421 if (sender != senders_.end()) {
1395 // We already have a sender for this track, so just change the stream_id 1422 // We already have a sender for this track, so just change the stream_id
1396 // so that it's correct in the next call to CreateOffer. 1423 // so that it's correct in the next call to CreateOffer.
1397 (*sender)->set_stream_id(stream->label()); 1424 (*sender)->set_stream_id(stream->label());
1398 return; 1425 return;
1399 } 1426 }
1400 1427
1401 // Normal case; we've never seen this track before. 1428 // Normal case; we've never seen this track before.
1402 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( 1429 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create(
(...skipping 10 matching lines...) Expand all
1413 FindTrackInfo(local_audio_tracks_, stream->label(), track->id()); 1440 FindTrackInfo(local_audio_tracks_, stream->label(), track->id());
1414 if (track_info) { 1441 if (track_info) {
1415 new_sender->SetSsrc(track_info->ssrc); 1442 new_sender->SetSsrc(track_info->ssrc);
1416 } 1443 }
1417 } 1444 }
1418 1445
1419 // TODO(deadbeef): Don't destroy RtpSenders here; they should be kept around 1446 // TODO(deadbeef): Don't destroy RtpSenders here; they should be kept around
1420 // indefinitely, when we have unified plan SDP. 1447 // indefinitely, when we have unified plan SDP.
1421 void PeerConnection::OnAudioTrackRemoved(AudioTrackInterface* track, 1448 void PeerConnection::OnAudioTrackRemoved(AudioTrackInterface* track,
1422 MediaStreamInterface* stream) { 1449 MediaStreamInterface* stream) {
1450 if (IsClosed()) {
1451 return;
1452 }
1423 auto sender = FindSenderForTrack(track); 1453 auto sender = FindSenderForTrack(track);
1424 if (sender == senders_.end()) { 1454 if (sender == senders_.end()) {
1425 LOG(LS_WARNING) << "RtpSender for track with id " << track->id() 1455 LOG(LS_WARNING) << "RtpSender for track with id " << track->id()
1426 << " doesn't exist."; 1456 << " doesn't exist.";
1427 return; 1457 return;
1428 } 1458 }
1429 (*sender)->Stop(); 1459 (*sender)->Stop();
1430 senders_.erase(sender); 1460 senders_.erase(sender);
1431 } 1461 }
1432 1462
1433 void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track, 1463 void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track,
1434 MediaStreamInterface* stream) { 1464 MediaStreamInterface* stream) {
1465 if (IsClosed()) {
1466 return;
1467 }
1435 auto sender = FindSenderForTrack(track); 1468 auto sender = FindSenderForTrack(track);
1436 if (sender != senders_.end()) { 1469 if (sender != senders_.end()) {
1437 // We already have a sender for this track, so just change the stream_id 1470 // We already have a sender for this track, so just change the stream_id
1438 // so that it's correct in the next call to CreateOffer. 1471 // so that it's correct in the next call to CreateOffer.
1439 (*sender)->set_stream_id(stream->label()); 1472 (*sender)->set_stream_id(stream->label());
1440 return; 1473 return;
1441 } 1474 }
1442 1475
1443 // Normal case; we've never seen this track before. 1476 // Normal case; we've never seen this track before.
1444 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create( 1477 rtc::scoped_refptr<RtpSenderInterface> new_sender = RtpSenderProxy::Create(
1445 signaling_thread(), 1478 signaling_thread(),
1446 new VideoRtpSender(track, stream->label(), session_.get())); 1479 new VideoRtpSender(track, stream->label(), session_.get()));
1447 senders_.push_back(new_sender); 1480 senders_.push_back(new_sender);
1448 const TrackInfo* track_info = 1481 const TrackInfo* track_info =
1449 FindTrackInfo(local_video_tracks_, stream->label(), track->id()); 1482 FindTrackInfo(local_video_tracks_, stream->label(), track->id());
1450 if (track_info) { 1483 if (track_info) {
1451 new_sender->SetSsrc(track_info->ssrc); 1484 new_sender->SetSsrc(track_info->ssrc);
1452 } 1485 }
1453 } 1486 }
1454 1487
1455 void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track, 1488 void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track,
1456 MediaStreamInterface* stream) { 1489 MediaStreamInterface* stream) {
1490 if (IsClosed()) {
1491 return;
1492 }
1457 auto sender = FindSenderForTrack(track); 1493 auto sender = FindSenderForTrack(track);
1458 if (sender == senders_.end()) { 1494 if (sender == senders_.end()) {
1459 LOG(LS_WARNING) << "RtpSender for track with id " << track->id() 1495 LOG(LS_WARNING) << "RtpSender for track with id " << track->id()
1460 << " doesn't exist."; 1496 << " doesn't exist.";
1461 return; 1497 return;
1462 } 1498 }
1463 (*sender)->Stop(); 1499 (*sender)->Stop();
1464 senders_.erase(sender); 1500 senders_.erase(sender);
1465 } 1501 }
1466 1502
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 2114 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2079 for (const auto& channel : sctp_data_channels_) { 2115 for (const auto& channel : sctp_data_channels_) {
2080 if (channel->id() == sid) { 2116 if (channel->id() == sid) {
2081 return channel; 2117 return channel;
2082 } 2118 }
2083 } 2119 }
2084 return nullptr; 2120 return nullptr;
2085 } 2121 }
2086 2122
2087 } // namespace webrtc 2123 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/api/peerconnectioninterface_unittest.cc » ('j') | webrtc/api/peerconnectioninterface_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698