Index: webrtc/api/peerconnection.cc |
diff --git a/webrtc/api/peerconnection.cc b/webrtc/api/peerconnection.cc |
index b9cb83e724de78db6683bd0dc242afb6d80a928a..ac08d6c7cb672575355b5144ea218f3b8af73c48 100644 |
--- a/webrtc/api/peerconnection.cc |
+++ b/webrtc/api/peerconnection.cc |
@@ -396,6 +396,34 @@ uint32_t ConvertIceTransportTypeToCandidateFilter( |
return cricket::CF_NONE; |
} |
+// Helper method to set a voice/video channel on all applicable senders |
+// and receivers when one is created/destroyed by WebRtcSession. |
+// |
+// Used by On(Voice|Video)Channel(Created|Destroyed) |
+template <class SENDER, |
+ class RECEIVER, |
+ class CHANNEL, |
+ class SENDERS, |
+ class RECEIVERS> |
+void SetChannelOnSendersAndReceivers(CHANNEL* channel, |
+ SENDERS& senders, |
+ RECEIVERS& receivers, |
+ cricket::MediaType media_type) { |
+ for (auto& sender : senders) { |
+ if (sender->media_type() == media_type) { |
+ static_cast<SENDER*>(sender->internal())->SetChannel(channel); |
+ } |
+ } |
+ for (auto& receiver : receivers) { |
+ if (receiver->media_type() == media_type) { |
+ if (!channel) { |
+ receiver->internal()->Stop(); |
+ } |
+ static_cast<RECEIVER*>(receiver->internal())->SetChannel(channel); |
+ } |
+ } |
+} |
+ |
} // namespace |
namespace webrtc { |
@@ -608,8 +636,12 @@ bool PeerConnection::Initialize( |
// All the callbacks will be posted to the application from PeerConnection. |
session_->RegisterIceObserver(this); |
session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); |
+ session_->SignalVoiceChannelCreated.connect( |
+ this, &PeerConnection::OnVoiceChannelCreated); |
session_->SignalVoiceChannelDestroyed.connect( |
this, &PeerConnection::OnVoiceChannelDestroyed); |
+ session_->SignalVideoChannelCreated.connect( |
+ this, &PeerConnection::OnVideoChannelCreated); |
session_->SignalVideoChannelDestroyed.connect( |
this, &PeerConnection::OnVideoChannelDestroyed); |
session_->SignalDataChannelCreated.connect( |
@@ -713,7 +745,7 @@ rtc::scoped_refptr<RtpSenderInterface> PeerConnection::AddTrack( |
new_sender = RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
signaling_thread(), |
new AudioRtpSender(static_cast<AudioTrackInterface*>(track), |
- session_.get(), stats_.get())); |
+ session_->voice_channel(), stats_.get())); |
if (!streams.empty()) { |
new_sender->internal()->set_stream_id(streams[0]->label()); |
} |
@@ -726,7 +758,7 @@ rtc::scoped_refptr<RtpSenderInterface> PeerConnection::AddTrack( |
new_sender = RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
signaling_thread(), |
new VideoRtpSender(static_cast<VideoTrackInterface*>(track), |
- session_.get())); |
+ session_->video_channel())); |
if (!streams.empty()) { |
new_sender->internal()->set_stream_id(streams[0]->label()); |
} |
@@ -791,10 +823,11 @@ rtc::scoped_refptr<RtpSenderInterface> PeerConnection::CreateSender( |
rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> new_sender; |
if (kind == MediaStreamTrackInterface::kAudioKind) { |
new_sender = RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
- signaling_thread(), new AudioRtpSender(session_.get(), stats_.get())); |
+ signaling_thread(), |
+ new AudioRtpSender(session_->voice_channel(), stats_.get())); |
} else if (kind == MediaStreamTrackInterface::kVideoKind) { |
new_sender = RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
- signaling_thread(), new VideoRtpSender(session_.get())); |
+ signaling_thread(), new VideoRtpSender(session_->video_channel())); |
} else { |
LOG(LS_ERROR) << "CreateSender called with invalid kind: " << kind; |
return new_sender; |
@@ -1322,8 +1355,8 @@ void PeerConnection::CreateAudioReceiver(MediaStreamInterface* stream, |
uint32_t ssrc) { |
receivers_.push_back( |
RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create( |
- signaling_thread(), |
- new AudioRtpReceiver(stream, track_id, ssrc, session_.get()))); |
+ signaling_thread(), new AudioRtpReceiver(stream, track_id, ssrc, |
+ session_->voice_channel()))); |
} |
void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, |
@@ -1333,7 +1366,7 @@ void PeerConnection::CreateVideoReceiver(MediaStreamInterface* stream, |
RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create( |
signaling_thread(), |
new VideoRtpReceiver(stream, track_id, factory_->worker_thread(), |
- ssrc, session_.get()))); |
+ ssrc, session_->video_channel()))); |
} |
// TODO(deadbeef): Keep RtpReceivers around even if track goes away in remote |
@@ -1349,19 +1382,6 @@ void PeerConnection::DestroyReceiver(const std::string& track_id) { |
} |
} |
-void PeerConnection::StopReceivers(cricket::MediaType media_type) { |
- TrackInfos* current_tracks = GetRemoteTracks(media_type); |
- for (const auto& track_info : *current_tracks) { |
- auto it = FindReceiverForTrack(track_info.track_id); |
- if (it == receivers_.end()) { |
- LOG(LS_WARNING) << "RtpReceiver for track with id " << track_info.track_id |
- << " doesn't exist."; |
- } else { |
- (*it)->internal()->Stop(); |
- } |
- } |
-} |
- |
void PeerConnection::OnIceConnectionChange( |
PeerConnectionInterface::IceConnectionState new_state) { |
RTC_DCHECK(signaling_thread()->IsCurrent()); |
@@ -1427,8 +1447,9 @@ void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track, |
// Normal case; we've never seen this track before. |
rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> new_sender = |
RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
- signaling_thread(), new AudioRtpSender(track, stream->label(), |
- session_.get(), stats_.get())); |
+ signaling_thread(), |
+ new AudioRtpSender(track, stream->label(), session_->voice_channel(), |
+ stats_.get())); |
senders_.push_back(new_sender); |
// If the sender has already been configured in SDP, we call SetSsrc, |
// which will connect the sender to the underlying transport. This can |
@@ -1470,8 +1491,8 @@ void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track, |
// Normal case; we've never seen this track before. |
rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> new_sender = |
RtpSenderProxyWithInternal<RtpSenderInternal>::Create( |
- signaling_thread(), |
- new VideoRtpSender(track, stream->label(), session_.get())); |
+ signaling_thread(), new VideoRtpSender(track, stream->label(), |
+ session_->video_channel())); |
senders_.push_back(new_sender); |
const TrackInfo* track_info = |
FindTrackInfo(local_video_tracks_, stream->label(), track->id()); |
@@ -2013,12 +2034,28 @@ void PeerConnection::OnSctpDataChannelClosed(DataChannel* channel) { |
} |
} |
+void PeerConnection::OnVoiceChannelCreated() { |
+ SetChannelOnSendersAndReceivers<AudioRtpSender, AudioRtpReceiver>( |
+ session_->voice_channel(), senders_, receivers_, |
+ cricket::MEDIA_TYPE_AUDIO); |
+} |
+ |
void PeerConnection::OnVoiceChannelDestroyed() { |
- StopReceivers(cricket::MEDIA_TYPE_AUDIO); |
+ SetChannelOnSendersAndReceivers<AudioRtpSender, AudioRtpReceiver, |
+ cricket::VoiceChannel>( |
+ nullptr, senders_, receivers_, cricket::MEDIA_TYPE_AUDIO); |
+} |
+ |
+void PeerConnection::OnVideoChannelCreated() { |
+ SetChannelOnSendersAndReceivers<VideoRtpSender, VideoRtpReceiver>( |
+ session_->video_channel(), senders_, receivers_, |
+ cricket::MEDIA_TYPE_VIDEO); |
} |
void PeerConnection::OnVideoChannelDestroyed() { |
- StopReceivers(cricket::MEDIA_TYPE_VIDEO); |
+ SetChannelOnSendersAndReceivers<VideoRtpSender, VideoRtpReceiver, |
+ cricket::VideoChannel>( |
+ nullptr, senders_, receivers_, cricket::MEDIA_TYPE_VIDEO); |
} |
void PeerConnection::OnDataChannelCreated() { |