Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "talk/app/webrtc/peerconnection.h" | 28 #include "talk/app/webrtc/peerconnection.h" |
| 29 | 29 |
| 30 #include <vector> | 30 #include <vector> |
| 31 | 31 |
| 32 #include "talk/app/webrtc/dtmfsender.h" | 32 #include "talk/app/webrtc/dtmfsender.h" |
| 33 #include "talk/app/webrtc/jsepicecandidate.h" | 33 #include "talk/app/webrtc/jsepicecandidate.h" |
| 34 #include "talk/app/webrtc/jsepsessiondescription.h" | 34 #include "talk/app/webrtc/jsepsessiondescription.h" |
| 35 #include "talk/app/webrtc/mediaconstraintsinterface.h" | 35 #include "talk/app/webrtc/mediaconstraintsinterface.h" |
| 36 #include "talk/app/webrtc/mediastreamhandler.h" | 36 #include "talk/app/webrtc/rtpreceiver.h" |
| 37 #include "talk/app/webrtc/rtpsender.h" | |
| 37 #include "talk/app/webrtc/streamcollection.h" | 38 #include "talk/app/webrtc/streamcollection.h" |
| 38 #include "webrtc/p2p/client/basicportallocator.h" | 39 #include "webrtc/p2p/client/basicportallocator.h" |
| 39 #include "talk/session/media/channelmanager.h" | 40 #include "talk/session/media/channelmanager.h" |
| 40 #include "webrtc/base/logging.h" | 41 #include "webrtc/base/logging.h" |
| 41 #include "webrtc/base/stringencode.h" | 42 #include "webrtc/base/stringencode.h" |
| 42 #include "webrtc/system_wrappers/interface/field_trial.h" | 43 #include "webrtc/system_wrappers/interface/field_trial.h" |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| 45 | 46 |
| 46 using webrtc::PeerConnectionInterface; | 47 using webrtc::PeerConnectionInterface; |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 observer_(NULL), | 333 observer_(NULL), |
| 333 uma_observer_(NULL), | 334 uma_observer_(NULL), |
| 334 signaling_state_(kStable), | 335 signaling_state_(kStable), |
| 335 ice_state_(kIceNew), | 336 ice_state_(kIceNew), |
| 336 ice_connection_state_(kIceConnectionNew), | 337 ice_connection_state_(kIceConnectionNew), |
| 337 ice_gathering_state_(kIceGatheringNew) { | 338 ice_gathering_state_(kIceGatheringNew) { |
| 338 } | 339 } |
| 339 | 340 |
| 340 PeerConnection::~PeerConnection() { | 341 PeerConnection::~PeerConnection() { |
| 341 ASSERT(signaling_thread()->IsCurrent()); | 342 ASSERT(signaling_thread()->IsCurrent()); |
| 342 if (mediastream_signaling_) | 343 if (mediastream_signaling_) { |
| 343 mediastream_signaling_->TearDown(); | 344 mediastream_signaling_->TearDown(); |
| 344 if (stream_handler_container_) | 345 } |
| 345 stream_handler_container_->TearDown(); | 346 // Need to detach RTP senders/receivers from WebRtcSession, |
| 347 // since it's about to be destroyed. | |
| 348 for (const auto& sender : rtp_senders_) { | |
| 349 sender->Stop(); | |
| 350 } | |
| 351 for (const auto& receiver : rtp_receivers_) { | |
| 352 receiver->Stop(); | |
| 353 } | |
| 346 } | 354 } |
| 347 | 355 |
| 348 bool PeerConnection::Initialize( | 356 bool PeerConnection::Initialize( |
| 349 const PeerConnectionInterface::RTCConfiguration& configuration, | 357 const PeerConnectionInterface::RTCConfiguration& configuration, |
| 350 const MediaConstraintsInterface* constraints, | 358 const MediaConstraintsInterface* constraints, |
| 351 PortAllocatorFactoryInterface* allocator_factory, | 359 PortAllocatorFactoryInterface* allocator_factory, |
| 352 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 360 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 353 PeerConnectionObserver* observer) { | 361 PeerConnectionObserver* observer) { |
| 354 ASSERT(observer != NULL); | 362 ASSERT(observer != NULL); |
| 355 if (!observer) | 363 if (!observer) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); | 400 port_allocator_->set_step_delay(cricket::kMinimumStepDelay); |
| 393 | 401 |
| 394 mediastream_signaling_.reset(new MediaStreamSignaling( | 402 mediastream_signaling_.reset(new MediaStreamSignaling( |
| 395 factory_->signaling_thread(), this, factory_->channel_manager())); | 403 factory_->signaling_thread(), this, factory_->channel_manager())); |
| 396 | 404 |
| 397 session_.reset(new WebRtcSession(factory_->channel_manager(), | 405 session_.reset(new WebRtcSession(factory_->channel_manager(), |
| 398 factory_->signaling_thread(), | 406 factory_->signaling_thread(), |
| 399 factory_->worker_thread(), | 407 factory_->worker_thread(), |
| 400 port_allocator_.get(), | 408 port_allocator_.get(), |
| 401 mediastream_signaling_.get())); | 409 mediastream_signaling_.get())); |
| 402 stream_handler_container_.reset(new MediaStreamHandlerContainer( | |
| 403 session_.get(), session_.get())); | |
| 404 stats_.reset(new StatsCollector(session_.get())); | 410 stats_.reset(new StatsCollector(session_.get())); |
| 405 | 411 |
| 406 // Initialize the WebRtcSession. It creates transport channels etc. | 412 // Initialize the WebRtcSession. It creates transport channels etc. |
| 407 if (!session_->Initialize(factory_->options(), constraints, | 413 if (!session_->Initialize(factory_->options(), constraints, |
| 408 dtls_identity_store.Pass(), configuration)) | 414 dtls_identity_store.Pass(), configuration)) |
| 409 return false; | 415 return false; |
| 410 | 416 |
| 411 // Register PeerConnection as receiver of local ice candidates. | 417 // Register PeerConnection as receiver of local ice candidates. |
| 412 // All the callbacks will be posted to the application from PeerConnection. | 418 // All the callbacks will be posted to the application from PeerConnection. |
| 413 session_->RegisterIceObserver(this); | 419 session_->RegisterIceObserver(this); |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 break; | 805 break; |
| 800 } | 806 } |
| 801 } | 807 } |
| 802 | 808 |
| 803 void PeerConnection::OnAddRemoteStream(MediaStreamInterface* stream) { | 809 void PeerConnection::OnAddRemoteStream(MediaStreamInterface* stream) { |
| 804 stats_->AddStream(stream); | 810 stats_->AddStream(stream); |
| 805 observer_->OnAddStream(stream); | 811 observer_->OnAddStream(stream); |
| 806 } | 812 } |
| 807 | 813 |
| 808 void PeerConnection::OnRemoveRemoteStream(MediaStreamInterface* stream) { | 814 void PeerConnection::OnRemoveRemoteStream(MediaStreamInterface* stream) { |
| 809 stream_handler_container_->RemoveRemoteStream(stream); | |
| 810 observer_->OnRemoveStream(stream); | 815 observer_->OnRemoveStream(stream); |
| 811 } | 816 } |
| 812 | 817 |
| 813 void PeerConnection::OnAddDataChannel(DataChannelInterface* data_channel) { | 818 void PeerConnection::OnAddDataChannel(DataChannelInterface* data_channel) { |
| 814 observer_->OnDataChannel(DataChannelProxy::Create(signaling_thread(), | 819 observer_->OnDataChannel(DataChannelProxy::Create(signaling_thread(), |
| 815 data_channel)); | 820 data_channel)); |
| 816 } | 821 } |
| 817 | 822 |
| 818 void PeerConnection::OnAddRemoteAudioTrack(MediaStreamInterface* stream, | 823 void PeerConnection::OnAddRemoteAudioTrack(MediaStreamInterface* stream, |
| 819 AudioTrackInterface* audio_track, | 824 AudioTrackInterface* audio_track, |
| 820 uint32 ssrc) { | 825 uint32 ssrc, |
| 821 stream_handler_container_->AddRemoteAudioTrack(stream, audio_track, ssrc); | 826 const std::string& mid) { |
| 827 rtp_receivers_.push_back(rtc::scoped_refptr<RtpReceiverInterface>( | |
| 828 new rtc::RefCountedObject<AudioRtpReceiver>(audio_track, ssrc, mid, | |
| 829 session_.get()))); | |
| 822 } | 830 } |
| 823 | 831 |
| 824 void PeerConnection::OnAddRemoteVideoTrack(MediaStreamInterface* stream, | 832 void PeerConnection::OnAddRemoteVideoTrack(MediaStreamInterface* stream, |
| 825 VideoTrackInterface* video_track, | 833 VideoTrackInterface* video_track, |
| 826 uint32 ssrc) { | 834 uint32 ssrc, |
| 827 stream_handler_container_->AddRemoteVideoTrack(stream, video_track, ssrc); | 835 const std::string& mid) { |
| 836 rtp_receivers_.push_back(rtc::scoped_refptr<RtpReceiverInterface>( | |
| 837 new rtc::RefCountedObject<VideoRtpReceiver>(video_track, ssrc, mid, | |
| 838 session_.get()))); | |
| 828 } | 839 } |
| 829 | 840 |
| 830 void PeerConnection::OnRemoveRemoteAudioTrack( | 841 void PeerConnection::OnRemoveRemoteAudioTrack( |
| 831 MediaStreamInterface* stream, | 842 MediaStreamInterface* stream, |
| 832 AudioTrackInterface* audio_track) { | 843 AudioTrackInterface* audio_track) { |
| 833 stream_handler_container_->RemoveRemoteTrack(stream, audio_track); | 844 auto it = FindRtpReceiverForTrack(audio_track); |
| 845 if (it == rtp_receivers_.end()) { | |
| 846 LOG(LS_WARNING) << "RtpReceiver for track with id " << audio_track->id() | |
| 847 << " doesn't exist."; | |
| 848 } else { | |
| 849 (*it)->Stop(); | |
| 850 rtp_receivers_.erase(it); | |
|
pthatcher1
2015/09/17 04:25:46
Long-term, I think we want to keep senders and rec
Taylor Brandstetter
2015/09/23 00:10:45
Can't an m-line go away if someone calls "stop" on
pthatcher1
2015/09/23 14:47:39
No, an m-line can never go away.
| |
| 851 } | |
| 834 } | 852 } |
| 835 | 853 |
| 836 void PeerConnection::OnRemoveRemoteVideoTrack( | 854 void PeerConnection::OnRemoveRemoteVideoTrack( |
| 837 MediaStreamInterface* stream, | 855 MediaStreamInterface* stream, |
| 838 VideoTrackInterface* video_track) { | 856 VideoTrackInterface* video_track) { |
| 839 stream_handler_container_->RemoveRemoteTrack(stream, video_track); | 857 auto it = FindRtpReceiverForTrack(video_track); |
| 858 if (it == rtp_receivers_.end()) { | |
| 859 LOG(LS_WARNING) << "RtpReceiver for track with id " << video_track->id() | |
| 860 << " doesn't exist."; | |
| 861 } else { | |
| 862 (*it)->Stop(); | |
| 863 rtp_receivers_.erase(it); | |
| 864 } | |
| 840 } | 865 } |
| 866 | |
| 841 void PeerConnection::OnAddLocalAudioTrack(MediaStreamInterface* stream, | 867 void PeerConnection::OnAddLocalAudioTrack(MediaStreamInterface* stream, |
| 842 AudioTrackInterface* audio_track, | 868 AudioTrackInterface* audio_track, |
| 843 uint32 ssrc) { | 869 uint32 ssrc, |
| 844 stream_handler_container_->AddLocalAudioTrack(stream, audio_track, ssrc); | 870 const std::string& mid) { |
| 871 rtp_senders_.push_back(rtc::scoped_refptr<RtpSenderInterface>( | |
| 872 new rtc::RefCountedObject<AudioRtpSender>(audio_track, ssrc, mid, | |
| 873 session_.get()))); | |
| 845 stats_->AddLocalAudioTrack(audio_track, ssrc); | 874 stats_->AddLocalAudioTrack(audio_track, ssrc); |
| 846 } | 875 } |
| 876 | |
| 847 void PeerConnection::OnAddLocalVideoTrack(MediaStreamInterface* stream, | 877 void PeerConnection::OnAddLocalVideoTrack(MediaStreamInterface* stream, |
| 848 VideoTrackInterface* video_track, | 878 VideoTrackInterface* video_track, |
| 849 uint32 ssrc) { | 879 uint32 ssrc, |
| 850 stream_handler_container_->AddLocalVideoTrack(stream, video_track, ssrc); | 880 const std::string& mid) { |
| 881 rtp_senders_.push_back(rtc::scoped_refptr<RtpSenderInterface>( | |
| 882 new rtc::RefCountedObject<VideoRtpSender>(video_track, ssrc, mid, | |
| 883 session_.get()))); | |
| 851 } | 884 } |
| 852 | 885 |
| 853 void PeerConnection::OnRemoveLocalAudioTrack(MediaStreamInterface* stream, | 886 void PeerConnection::OnRemoveLocalAudioTrack(MediaStreamInterface* stream, |
| 854 AudioTrackInterface* audio_track, | 887 AudioTrackInterface* audio_track, |
| 855 uint32 ssrc) { | 888 uint32 ssrc) { |
| 856 stream_handler_container_->RemoveLocalTrack(stream, audio_track); | 889 auto it = FindRtpSenderForTrack(audio_track); |
| 890 if (it == rtp_senders_.end()) { | |
| 891 LOG(LS_WARNING) << "RtpSender for track with id " << audio_track->id() | |
| 892 << " doesn't exist."; | |
| 893 return; | |
| 894 } else { | |
| 895 (*it)->Stop(); | |
| 896 rtp_senders_.erase(it); | |
| 897 } | |
| 857 stats_->RemoveLocalAudioTrack(audio_track, ssrc); | 898 stats_->RemoveLocalAudioTrack(audio_track, ssrc); |
| 858 } | 899 } |
| 859 | 900 |
| 860 void PeerConnection::OnRemoveLocalVideoTrack(MediaStreamInterface* stream, | 901 void PeerConnection::OnRemoveLocalVideoTrack(MediaStreamInterface* stream, |
| 861 VideoTrackInterface* video_track) { | 902 VideoTrackInterface* video_track) { |
| 862 stream_handler_container_->RemoveLocalTrack(stream, video_track); | 903 auto it = FindRtpSenderForTrack(video_track); |
| 904 if (it == rtp_senders_.end()) { | |
| 905 LOG(LS_WARNING) << "RtpSender for track with id " << video_track->id() | |
| 906 << " doesn't exist."; | |
| 907 return; | |
| 908 } else { | |
| 909 (*it)->Stop(); | |
| 910 rtp_senders_.erase(it); | |
| 911 } | |
| 863 } | 912 } |
| 864 | 913 |
| 865 void PeerConnection::OnRemoveLocalStream(MediaStreamInterface* stream) { | 914 void PeerConnection::OnRemoveLocalStream(MediaStreamInterface* stream) { |
| 866 stream_handler_container_->RemoveLocalStream(stream); | |
| 867 } | 915 } |
| 868 | 916 |
| 869 void PeerConnection::OnIceConnectionChange( | 917 void PeerConnection::OnIceConnectionChange( |
| 870 PeerConnectionInterface::IceConnectionState new_state) { | 918 PeerConnectionInterface::IceConnectionState new_state) { |
| 871 ASSERT(signaling_thread()->IsCurrent()); | 919 ASSERT(signaling_thread()->IsCurrent()); |
| 872 ice_connection_state_ = new_state; | 920 ice_connection_state_ = new_state; |
| 873 observer_->OnIceConnectionChange(ice_connection_state_); | 921 observer_->OnIceConnectionChange(ice_connection_state_); |
| 874 } | 922 } |
| 875 | 923 |
| 876 void PeerConnection::OnIceGatheringChange( | 924 void PeerConnection::OnIceGatheringChange( |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 906 observer_->OnIceConnectionChange(ice_connection_state_); | 954 observer_->OnIceConnectionChange(ice_connection_state_); |
| 907 if (ice_gathering_state_ != kIceGatheringComplete) { | 955 if (ice_gathering_state_ != kIceGatheringComplete) { |
| 908 ice_gathering_state_ = kIceGatheringComplete; | 956 ice_gathering_state_ = kIceGatheringComplete; |
| 909 observer_->OnIceGatheringChange(ice_gathering_state_); | 957 observer_->OnIceGatheringChange(ice_gathering_state_); |
| 910 } | 958 } |
| 911 } | 959 } |
| 912 observer_->OnSignalingChange(signaling_state_); | 960 observer_->OnSignalingChange(signaling_state_); |
| 913 observer_->OnStateChange(PeerConnectionObserver::kSignalingState); | 961 observer_->OnStateChange(PeerConnectionObserver::kSignalingState); |
| 914 } | 962 } |
| 915 | 963 |
| 964 PeerConnectionInterface::RtpSenders::iterator | |
| 965 PeerConnection::FindRtpSenderForTrack(MediaStreamTrackInterface* track) { | |
| 966 return std::find_if( | |
| 967 rtp_senders_.begin(), rtp_senders_.end(), | |
| 968 [track](const rtc::scoped_refptr<RtpSenderInterface>& sender) | |
| 969 -> bool { return sender->track() == track; }); | |
|
pthatcher1
2015/09/17 04:25:46
Is the "-> bool" necessary? I thought it could in
Taylor Brandstetter
2015/09/23 00:10:45
Oh, I guess so. Removed.
| |
| 970 } | |
| 971 PeerConnectionInterface::RtpReceivers::iterator | |
| 972 PeerConnection::FindRtpReceiverForTrack(MediaStreamTrackInterface* track) { | |
| 973 return std::find_if( | |
| 974 rtp_receivers_.begin(), rtp_receivers_.end(), | |
| 975 [track](const rtc::scoped_refptr<RtpReceiverInterface>& receiver) | |
| 976 -> bool { return receiver->track() == track; }); | |
| 977 } | |
| 978 | |
| 916 } // namespace webrtc | 979 } // namespace webrtc |
| OLD | NEW |