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

Side by Side Diff: talk/session/media/channel.cc

Issue 1246913005: TransportController refactoring (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Merging again Created 5 years, 3 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 * libjingle 2 * libjingle
3 * Copyright 2004 Google Inc. 3 * Copyright 2004 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 164
165 template <class Codec, class Options> 165 template <class Codec, class Options>
166 void RtpSendParametersFromMediaDescription( 166 void RtpSendParametersFromMediaDescription(
167 const MediaContentDescriptionImpl<Codec>* desc, 167 const MediaContentDescriptionImpl<Codec>* desc,
168 RtpSendParameters<Codec, Options>* send_params) { 168 RtpSendParameters<Codec, Options>* send_params) {
169 RtpParametersFromMediaDescription(desc, send_params); 169 RtpParametersFromMediaDescription(desc, send_params);
170 send_params->max_bandwidth_bps = desc->bandwidth(); 170 send_params->max_bandwidth_bps = desc->bandwidth();
171 } 171 }
172 172
173 BaseChannel::BaseChannel(rtc::Thread* thread, 173 BaseChannel::BaseChannel(rtc::Thread* thread,
174 MediaChannel* media_channel, BaseSession* session, 174 MediaChannel* media_channel,
175 const std::string& content_name, bool rtcp) 175 TransportController* transport_controller,
176 const std::string& content_name,
177 bool rtcp)
176 : worker_thread_(thread), 178 : worker_thread_(thread),
177 session_(session), 179 transport_controller_(transport_controller),
178 media_channel_(media_channel), 180 media_channel_(media_channel),
179 content_name_(content_name), 181 content_name_(content_name),
180 rtcp_(rtcp), 182 rtcp_transport_enabled_(rtcp),
181 transport_channel_(NULL), 183 transport_channel_(nullptr),
182 rtcp_transport_channel_(NULL), 184 rtcp_transport_channel_(nullptr),
183 enabled_(false), 185 enabled_(false),
184 writable_(false), 186 writable_(false),
185 rtp_ready_to_send_(false), 187 rtp_ready_to_send_(false),
186 rtcp_ready_to_send_(false), 188 rtcp_ready_to_send_(false),
187 was_ever_writable_(false), 189 was_ever_writable_(false),
188 local_content_direction_(MD_INACTIVE), 190 local_content_direction_(MD_INACTIVE),
189 remote_content_direction_(MD_INACTIVE), 191 remote_content_direction_(MD_INACTIVE),
190 has_received_packet_(false), 192 has_received_packet_(false),
191 dtls_keyed_(false), 193 dtls_keyed_(false),
192 secure_required_(false), 194 secure_required_(false),
193 rtp_abs_sendtime_extn_id_(-1) { 195 rtp_abs_sendtime_extn_id_(-1) {
194 ASSERT(worker_thread_ == rtc::Thread::Current()); 196 ASSERT(worker_thread_ == rtc::Thread::Current());
195 LOG(LS_INFO) << "Created channel for " << content_name; 197 LOG(LS_INFO) << "Created channel for " << content_name;
196 } 198 }
197 199
198 BaseChannel::~BaseChannel() { 200 BaseChannel::~BaseChannel() {
199 ASSERT(worker_thread_ == rtc::Thread::Current()); 201 ASSERT(worker_thread_ == rtc::Thread::Current());
200 Deinit(); 202 Deinit();
201 StopConnectionMonitor(); 203 StopConnectionMonitor();
202 FlushRtcpMessages(); // Send any outstanding RTCP packets. 204 FlushRtcpMessages(); // Send any outstanding RTCP packets.
203 worker_thread_->Clear(this); // eats any outstanding messages or packets 205 worker_thread_->Clear(this); // eats any outstanding messages or packets
204 // We must destroy the media channel before the transport channel, otherwise 206 // We must destroy the media channel before the transport channel, otherwise
205 // the media channel may try to send on the dead transport channel. NULLing 207 // the media channel may try to send on the dead transport channel. NULLing
206 // is not an effective strategy since the sends will come on another thread. 208 // is not an effective strategy since the sends will come on another thread.
207 delete media_channel_; 209 delete media_channel_;
208 set_transport_channel(nullptr); 210 // Note that we don't just call set_transport_channel(nullptr) because that
209 set_rtcp_transport_channel(nullptr); 211 // would call a pure virtual method which we can't do from a destructor.
212 if (transport_channel_) {
213 DisconnectFromTransportChannel(transport_channel_);
214 transport_controller_->DestroyTransportChannel_w(
215 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP);
216 }
217 if (rtcp_transport_channel_) {
218 DisconnectFromTransportChannel(rtcp_transport_channel_);
219 transport_controller_->DestroyTransportChannel_w(
220 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
221 }
210 LOG(LS_INFO) << "Destroyed channel"; 222 LOG(LS_INFO) << "Destroyed channel";
211 } 223 }
212 224
213 bool BaseChannel::Init() { 225 bool BaseChannel::Init() {
214 if (!SetTransportChannels(session(), rtcp())) { 226 if (!SetTransport(content_name())) {
215 return false; 227 return false;
216 } 228 }
217 229
218 if (!SetDtlsSrtpCiphers(transport_channel(), false)) { 230 if (!SetDtlsSrtpCiphers(transport_channel(), false)) {
219 return false; 231 return false;
220 } 232 }
221 if (rtcp() && !SetDtlsSrtpCiphers(rtcp_transport_channel(), true)) { 233 if (rtcp_transport_enabled() &&
234 !SetDtlsSrtpCiphers(rtcp_transport_channel(), true)) {
222 return false; 235 return false;
223 } 236 }
224 237
225 // Both RTP and RTCP channels are set, we can call SetInterface on 238 // Both RTP and RTCP channels are set, we can call SetInterface on
226 // media channel and it can set network options. 239 // media channel and it can set network options.
227 media_channel_->SetInterface(this); 240 media_channel_->SetInterface(this);
228 return true; 241 return true;
229 } 242 }
230 243
231 void BaseChannel::Deinit() { 244 void BaseChannel::Deinit() {
232 media_channel_->SetInterface(NULL); 245 media_channel_->SetInterface(NULL);
233 } 246 }
234 247
235 bool BaseChannel::SetTransportChannels(BaseSession* session, bool rtcp) { 248 bool BaseChannel::SetTransport(const std::string& transport_name) {
236 return worker_thread_->Invoke<bool>(Bind( 249 return worker_thread_->Invoke<bool>(
237 &BaseChannel::SetTransportChannels_w, this, session, rtcp)); 250 Bind(&BaseChannel::SetTransport_w, this, transport_name));
238 } 251 }
239 252
240 bool BaseChannel::SetTransportChannels_w(BaseSession* session, bool rtcp) { 253 bool BaseChannel::SetTransport_w(const std::string& transport_name) {
241 ASSERT(worker_thread_ == rtc::Thread::Current()); 254 ASSERT(worker_thread_ == rtc::Thread::Current());
242 255
243 set_transport_channel(session->CreateChannel( 256 if (transport_name == transport_name_) {
244 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP)); 257 // Nothing to do if transport name isn't changing
258 return true;
259 }
260
261 set_transport_channel(transport_controller_->CreateTransportChannel_w(
262 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP));
245 if (!transport_channel()) { 263 if (!transport_channel()) {
246 return false; 264 return false;
247 } 265 }
248 if (rtcp) { 266 if (rtcp_transport_enabled()) {
249 set_rtcp_transport_channel(session->CreateChannel( 267 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name()
250 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP)); 268 << " on " << transport_name << " transport ";
269 set_rtcp_transport_channel(transport_controller_->CreateTransportChannel_w(
270 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP));
251 if (!rtcp_transport_channel()) { 271 if (!rtcp_transport_channel()) {
252 return false; 272 return false;
253 } 273 }
254 } else {
255 set_rtcp_transport_channel(nullptr);
256 } 274 }
257 275
276 transport_name_ = transport_name;
258 return true; 277 return true;
259 } 278 }
260 279
261 void BaseChannel::set_transport_channel(TransportChannel* new_tc) { 280 void BaseChannel::set_transport_channel(TransportChannel* new_tc) {
262 ASSERT(worker_thread_ == rtc::Thread::Current()); 281 ASSERT(worker_thread_ == rtc::Thread::Current());
263 282
264 TransportChannel* old_tc = transport_channel_; 283 TransportChannel* old_tc = transport_channel_;
265 284 if (!old_tc && !new_tc) {
266 if (old_tc == new_tc) { 285 // Nothing to do
267 return; 286 return;
268 } 287 }
288 ASSERT(old_tc != new_tc);
289
269 if (old_tc) { 290 if (old_tc) {
270 DisconnectFromTransportChannel(old_tc); 291 DisconnectFromTransportChannel(old_tc);
271 session()->DestroyChannel( 292 transport_controller_->DestroyTransportChannel_w(
272 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP); 293 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP);
273 } 294 }
274 295
275 transport_channel_ = new_tc; 296 transport_channel_ = new_tc;
276 297
277 if (new_tc) { 298 if (new_tc) {
278 ConnectToTransportChannel(new_tc); 299 ConnectToTransportChannel(new_tc);
300 for (const auto& pair : socket_options_) {
301 new_tc->SetOption(pair.first, pair.second);
302 }
279 } 303 }
304
305 // Update aggregate writable/ready-to-send state between RTP and RTCP upon
306 // setting new channel
307 UpdateWritableState_w();
308 SetReadyToSend(false, new_tc && new_tc->writable());
280 } 309 }
281 310
282 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc) { 311 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc) {
283 ASSERT(worker_thread_ == rtc::Thread::Current()); 312 ASSERT(worker_thread_ == rtc::Thread::Current());
284 313
285 TransportChannel* old_tc = rtcp_transport_channel_; 314 TransportChannel* old_tc = rtcp_transport_channel_;
286 315 if (!old_tc && !new_tc) {
287 if (old_tc == new_tc) { 316 // Nothing to do
288 return; 317 return;
289 } 318 }
319 ASSERT(old_tc != new_tc);
320
290 if (old_tc) { 321 if (old_tc) {
291 DisconnectFromTransportChannel(old_tc); 322 DisconnectFromTransportChannel(old_tc);
292 session()->DestroyChannel( 323 transport_controller_->DestroyTransportChannel_w(
293 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP); 324 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
294 } 325 }
295 326
296 rtcp_transport_channel_ = new_tc; 327 rtcp_transport_channel_ = new_tc;
297 328
298 if (new_tc) { 329 if (new_tc) {
299 ConnectToTransportChannel(new_tc); 330 ConnectToTransportChannel(new_tc);
331 for (const auto& pair : rtcp_socket_options_) {
332 new_tc->SetOption(pair.first, pair.second);
333 }
300 } 334 }
335
336 // Update aggregate writable/ready-to-send state between RTP and RTCP upon
337 // setting new channel
338 UpdateWritableState_w();
339 SetReadyToSend(true, new_tc && new_tc->writable());
301 } 340 }
302 341
303 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { 342 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) {
304 ASSERT(worker_thread_ == rtc::Thread::Current()); 343 ASSERT(worker_thread_ == rtc::Thread::Current());
305 344
306 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); 345 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState);
307 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); 346 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead);
308 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); 347 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend);
309 } 348 }
310 349
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 rtc::DiffServCodePoint dscp) { 448 rtc::DiffServCodePoint dscp) {
410 return SendPacket(true, packet, dscp); 449 return SendPacket(true, packet, dscp);
411 } 450 }
412 451
413 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, 452 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt,
414 int value) { 453 int value) {
415 TransportChannel* channel = NULL; 454 TransportChannel* channel = NULL;
416 switch (type) { 455 switch (type) {
417 case ST_RTP: 456 case ST_RTP:
418 channel = transport_channel_; 457 channel = transport_channel_;
458 socket_options_.push_back(
459 std::pair<rtc::Socket::Option, int>(opt, value));
419 break; 460 break;
420 case ST_RTCP: 461 case ST_RTCP:
421 channel = rtcp_transport_channel_; 462 channel = rtcp_transport_channel_;
463 rtcp_socket_options_.push_back(
464 std::pair<rtc::Socket::Option, int>(opt, value));
422 break; 465 break;
423 } 466 }
424 return channel ? channel->SetOption(opt, value) : -1; 467 return channel ? channel->SetOption(opt, value) : -1;
425 } 468 }
426 469
427 void BaseChannel::OnWritableState(TransportChannel* channel) { 470 void BaseChannel::OnWritableState(TransportChannel* channel) {
428 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); 471 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
429 if (transport_channel_->writable() 472 UpdateWritableState_w();
430 && (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) {
431 ChannelWritable_w();
432 } else {
433 ChannelNotWritable_w();
434 }
435 } 473 }
436 474
437 void BaseChannel::OnChannelRead(TransportChannel* channel, 475 void BaseChannel::OnChannelRead(TransportChannel* channel,
438 const char* data, size_t len, 476 const char* data, size_t len,
439 const rtc::PacketTime& packet_time, 477 const rtc::PacketTime& packet_time,
440 int flags) { 478 int flags) {
441 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine 479 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine
442 ASSERT(worker_thread_ == rtc::Thread::Current()); 480 ASSERT(worker_thread_ == rtc::Thread::Current());
443 481
444 // When using RTCP multiplexing we might get RTCP packets on the RTP 482 // When using RTCP multiplexing we might get RTCP packets on the RTP
445 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. 483 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP.
446 bool rtcp = PacketIsRtcp(channel, data, len); 484 bool rtcp = PacketIsRtcp(channel, data, len);
447 rtc::Buffer packet(data, len); 485 rtc::Buffer packet(data, len);
448 HandlePacket(rtcp, &packet, packet_time); 486 HandlePacket(rtcp, &packet, packet_time);
449 } 487 }
450 488
451 void BaseChannel::OnReadyToSend(TransportChannel* channel) { 489 void BaseChannel::OnReadyToSend(TransportChannel* channel) {
452 SetReadyToSend(channel, true); 490 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
491 SetReadyToSend(channel == rtcp_transport_channel_, true);
453 } 492 }
454 493
455 void BaseChannel::SetReadyToSend(TransportChannel* channel, bool ready) { 494 void BaseChannel::SetReadyToSend(bool rtcp, bool ready) {
456 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); 495 if (rtcp) {
457 if (channel == transport_channel_) { 496 rtcp_ready_to_send_ = ready;
497 } else {
458 rtp_ready_to_send_ = ready; 498 rtp_ready_to_send_ = ready;
459 } 499 }
460 if (channel == rtcp_transport_channel_) {
461 rtcp_ready_to_send_ = ready;
462 }
463 500
464 if (!ready) { 501 if (rtp_ready_to_send_ &&
502 // In the case of rtcp mux |rtcp_transport_channel_| will be null.
503 (rtcp_ready_to_send_ || !rtcp_transport_channel_)) {
504 // Notify the MediaChannel when both rtp and rtcp channel can send.
505 media_channel_->OnReadyToSend(true);
506 } else {
465 // Notify the MediaChannel when either rtp or rtcp channel can't send. 507 // Notify the MediaChannel when either rtp or rtcp channel can't send.
466 media_channel_->OnReadyToSend(false); 508 media_channel_->OnReadyToSend(false);
467 } else if (rtp_ready_to_send_ &&
468 // In the case of rtcp mux |rtcp_transport_channel_| will be null.
469 (rtcp_ready_to_send_ || !rtcp_transport_channel_)) {
470 // Notify the MediaChannel when both rtp and rtcp channel can send.
471 media_channel_->OnReadyToSend(true);
472 } 509 }
473 } 510 }
474 511
475 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, 512 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel,
476 const char* data, size_t len) { 513 const char* data, size_t len) {
477 return (channel == rtcp_transport_channel_ || 514 return (channel == rtcp_transport_channel_ ||
478 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); 515 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len)));
479 } 516 }
480 517
481 bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet, 518 bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 return false; 620 return false;
584 } 621 }
585 622
586 // Bon voyage. 623 // Bon voyage.
587 int ret = 624 int ret =
588 channel->SendPacket(packet->data<char>(), packet->size(), options, 625 channel->SendPacket(packet->data<char>(), packet->size(), options,
589 (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0); 626 (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0);
590 if (ret != static_cast<int>(packet->size())) { 627 if (ret != static_cast<int>(packet->size())) {
591 if (channel->GetError() == EWOULDBLOCK) { 628 if (channel->GetError() == EWOULDBLOCK) {
592 LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; 629 LOG(LS_WARNING) << "Got EWOULDBLOCK from socket.";
593 SetReadyToSend(channel, false); 630 SetReadyToSend(rtcp, false);
594 } 631 }
595 return false; 632 return false;
596 } 633 }
597 return true; 634 return true;
598 } 635 }
599 636
600 bool BaseChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) { 637 bool BaseChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) {
601 // Protect ourselves against crazy data. 638 // Protect ourselves against crazy data.
602 if (!ValidPacket(rtcp, packet)) { 639 if (!ValidPacket(rtcp, packet)) {
603 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " 640 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " "
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 muted_streams_.erase(ssrc); 771 muted_streams_.erase(ssrc);
735 } 772 }
736 return ret; 773 return ret;
737 } 774 }
738 775
739 bool BaseChannel::IsStreamMuted_w(uint32 ssrc) { 776 bool BaseChannel::IsStreamMuted_w(uint32 ssrc) {
740 ASSERT(worker_thread_ == rtc::Thread::Current()); 777 ASSERT(worker_thread_ == rtc::Thread::Current());
741 return muted_streams_.find(ssrc) != muted_streams_.end(); 778 return muted_streams_.find(ssrc) != muted_streams_.end();
742 } 779 }
743 780
781 void BaseChannel::UpdateWritableState_w() {
782 if (transport_channel_ && transport_channel_->writable() &&
783 (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) {
784 ChannelWritable_w();
785 } else {
786 ChannelNotWritable_w();
787 }
788 }
789
744 void BaseChannel::ChannelWritable_w() { 790 void BaseChannel::ChannelWritable_w() {
745 ASSERT(worker_thread_ == rtc::Thread::Current()); 791 ASSERT(worker_thread_ == rtc::Thread::Current());
746 if (writable_) 792 if (writable_)
747 return; 793 return;
748 794
749 LOG(LS_INFO) << "Channel socket writable (" 795 LOG(LS_INFO) << "Channel writable (" << content_name_ << ")"
750 << transport_channel_->content_name() << ", "
751 << transport_channel_->component() << ")"
752 << (was_ever_writable_ ? "" : " for the first time"); 796 << (was_ever_writable_ ? "" : " for the first time");
753 797
754 std::vector<ConnectionInfo> infos; 798 std::vector<ConnectionInfo> infos;
755 transport_channel_->GetStats(&infos); 799 transport_channel_->GetStats(&infos);
756 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); 800 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin();
757 it != infos.end(); ++it) { 801 it != infos.end(); ++it) {
758 if (it->best_connection) { 802 if (it->best_connection) {
759 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() 803 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString()
760 << "->" << it->remote_candidate.ToSensitiveString(); 804 << "->" << it->remote_candidate.ToSensitiveString();
761 break; 805 break;
762 } 806 }
763 } 807 }
764 808
765 // If we're doing DTLS-SRTP, now is the time. 809 // If we're doing DTLS-SRTP, now is the time.
766 if (!was_ever_writable_ && ShouldSetupDtlsSrtp()) { 810 if (!was_ever_writable_ && ShouldSetupDtlsSrtp()) {
767 if (!SetupDtlsSrtp(false)) { 811 if (!SetupDtlsSrtp(false)) {
768 SignalDtlsSetupFailure(this, false); 812 SignalDtlsSetupFailure_w(false);
769 return; 813 return;
770 } 814 }
771 815
772 if (rtcp_transport_channel_) { 816 if (rtcp_transport_channel_) {
773 if (!SetupDtlsSrtp(true)) { 817 if (!SetupDtlsSrtp(true)) {
774 SignalDtlsSetupFailure(this, true); 818 SignalDtlsSetupFailure_w(true);
775 return; 819 return;
776 } 820 }
777 } 821 }
778 } 822 }
779 823
780 was_ever_writable_ = true; 824 was_ever_writable_ = true;
781 writable_ = true; 825 writable_ = true;
782 ChangeState(); 826 ChangeState();
783 } 827 }
784 828
(...skipping 22 matching lines...) Expand all
807 851
808 bool BaseChannel::ShouldSetupDtlsSrtp() const { 852 bool BaseChannel::ShouldSetupDtlsSrtp() const {
809 return true; 853 return true;
810 } 854 }
811 855
812 // This function returns true if either DTLS-SRTP is not in use 856 // This function returns true if either DTLS-SRTP is not in use
813 // *or* DTLS-SRTP is successfully set up. 857 // *or* DTLS-SRTP is successfully set up.
814 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { 858 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) {
815 bool ret = false; 859 bool ret = false;
816 860
817 TransportChannel *channel = rtcp_channel ? 861 TransportChannel* channel =
818 rtcp_transport_channel_ : transport_channel_; 862 rtcp_channel ? rtcp_transport_channel_ : transport_channel_;
819 863
820 // No DTLS 864 // No DTLS
821 if (!channel->IsDtlsActive()) 865 if (!channel->IsDtlsActive())
822 return true; 866 return true;
823 867
824 std::string selected_cipher; 868 std::string selected_cipher;
825 869
826 if (!channel->GetSrtpCipher(&selected_cipher)) { 870 if (!channel->GetSrtpCipher(&selected_cipher)) {
827 LOG(LS_ERROR) << "No DTLS-SRTP selected cipher"; 871 LOG(LS_ERROR) << "No DTLS-SRTP selected cipher";
828 return false; 872 return false;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 dtls_keyed_ = true; 947 dtls_keyed_ = true;
904 948
905 return ret; 949 return ret;
906 } 950 }
907 951
908 void BaseChannel::ChannelNotWritable_w() { 952 void BaseChannel::ChannelNotWritable_w() {
909 ASSERT(worker_thread_ == rtc::Thread::Current()); 953 ASSERT(worker_thread_ == rtc::Thread::Current());
910 if (!writable_) 954 if (!writable_)
911 return; 955 return;
912 956
913 LOG(LS_INFO) << "Channel socket not writable (" 957 LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")";
914 << transport_channel_->content_name() << ", "
915 << transport_channel_->component() << ")";
916 writable_ = false; 958 writable_ = false;
917 ChangeState(); 959 ChangeState();
918 } 960 }
919 961
920 bool BaseChannel::SetRtpTransportParameters_w( 962 bool BaseChannel::SetRtpTransportParameters_w(
921 const MediaContentDescription* content, 963 const MediaContentDescription* content,
922 ContentAction action, 964 ContentAction action,
923 ContentSource src, 965 ContentSource src,
924 std::string* error_desc) { 966 std::string* error_desc) {
925 if (action == CA_UPDATE) { 967 if (action == CA_UPDATE) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 } 1046 }
1005 1047
1006 void BaseChannel::ActivateRtcpMux() { 1048 void BaseChannel::ActivateRtcpMux() {
1007 worker_thread_->Invoke<void>(Bind( 1049 worker_thread_->Invoke<void>(Bind(
1008 &BaseChannel::ActivateRtcpMux_w, this)); 1050 &BaseChannel::ActivateRtcpMux_w, this));
1009 } 1051 }
1010 1052
1011 void BaseChannel::ActivateRtcpMux_w() { 1053 void BaseChannel::ActivateRtcpMux_w() {
1012 if (!rtcp_mux_filter_.IsActive()) { 1054 if (!rtcp_mux_filter_.IsActive()) {
1013 rtcp_mux_filter_.SetActive(); 1055 rtcp_mux_filter_.SetActive();
1014 set_rtcp_transport_channel(NULL); 1056 set_rtcp_transport_channel(nullptr);
1057 rtcp_transport_enabled_ = false;
1015 } 1058 }
1016 } 1059 }
1017 1060
1018 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action, 1061 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action,
1019 ContentSource src, 1062 ContentSource src,
1020 std::string* error_desc) { 1063 std::string* error_desc) {
1021 bool ret = false; 1064 bool ret = false;
1022 switch (action) { 1065 switch (action) {
1023 case CA_OFFER: 1066 case CA_OFFER:
1024 ret = rtcp_mux_filter_.SetOffer(enable, src); 1067 ret = rtcp_mux_filter_.SetOffer(enable, src);
1025 break; 1068 break;
1026 case CA_PRANSWER: 1069 case CA_PRANSWER:
1027 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); 1070 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src);
1028 break; 1071 break;
1029 case CA_ANSWER: 1072 case CA_ANSWER:
1030 ret = rtcp_mux_filter_.SetAnswer(enable, src); 1073 ret = rtcp_mux_filter_.SetAnswer(enable, src);
1031 if (ret && rtcp_mux_filter_.IsActive()) { 1074 if (ret && rtcp_mux_filter_.IsActive()) {
1032 // We activated RTCP mux, close down the RTCP transport. 1075 // We activated RTCP mux, close down the RTCP transport.
1033 set_rtcp_transport_channel(NULL); 1076 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name()
1077 << " by destroying RTCP transport channel for "
1078 << transport_name();
1079 set_rtcp_transport_channel(nullptr);
1080 rtcp_transport_enabled_ = false;
1034 } 1081 }
1035 break; 1082 break;
1036 case CA_UPDATE: 1083 case CA_UPDATE:
1037 // No RTCP mux info. 1084 // No RTCP mux info.
1038 ret = true; 1085 ret = true;
1039 break; 1086 break;
1040 default: 1087 default:
1041 break; 1088 break;
1042 } 1089 }
1043 if (!ret) { 1090 if (!ret) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages); 1297 worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages);
1251 for (rtc::MessageList::iterator it = rtcp_messages.begin(); 1298 for (rtc::MessageList::iterator it = rtcp_messages.begin();
1252 it != rtcp_messages.end(); ++it) { 1299 it != rtcp_messages.end(); ++it) {
1253 worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata); 1300 worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata);
1254 } 1301 }
1255 } 1302 }
1256 1303
1257 VoiceChannel::VoiceChannel(rtc::Thread* thread, 1304 VoiceChannel::VoiceChannel(rtc::Thread* thread,
1258 MediaEngineInterface* media_engine, 1305 MediaEngineInterface* media_engine,
1259 VoiceMediaChannel* media_channel, 1306 VoiceMediaChannel* media_channel,
1260 BaseSession* session, 1307 TransportController* transport_controller,
1261 const std::string& content_name, 1308 const std::string& content_name,
1262 bool rtcp) 1309 bool rtcp)
1263 : BaseChannel(thread, media_channel, session, content_name, 1310 : BaseChannel(thread,
1311 media_channel,
1312 transport_controller,
1313 content_name,
1264 rtcp), 1314 rtcp),
1265 media_engine_(media_engine), 1315 media_engine_(media_engine),
1266 received_media_(false) { 1316 received_media_(false) {
1267 } 1317 }
1268 1318
1269 VoiceChannel::~VoiceChannel() { 1319 VoiceChannel::~VoiceChannel() {
1270 StopAudioMonitor(); 1320 StopAudioMonitor();
1271 StopMediaMonitor(); 1321 StopMediaMonitor();
1272 // this can't be done in the base class, since it calls a virtual 1322 // this can't be done in the base class, since it calls a virtual
1273 DisableMedia_w(); 1323 DisableMedia_w();
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 break; 1699 break;
1650 } 1700 }
1651 } 1701 }
1652 1702
1653 void VoiceChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const { 1703 void VoiceChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const {
1654 GetSupportedAudioCryptoSuites(ciphers); 1704 GetSupportedAudioCryptoSuites(ciphers);
1655 } 1705 }
1656 1706
1657 VideoChannel::VideoChannel(rtc::Thread* thread, 1707 VideoChannel::VideoChannel(rtc::Thread* thread,
1658 VideoMediaChannel* media_channel, 1708 VideoMediaChannel* media_channel,
1659 BaseSession* session, 1709 TransportController* transport_controller,
1660 const std::string& content_name, 1710 const std::string& content_name,
1661 bool rtcp) 1711 bool rtcp)
1662 : BaseChannel(thread, media_channel, session, content_name, 1712 : BaseChannel(thread,
1713 media_channel,
1714 transport_controller,
1715 content_name,
1663 rtcp), 1716 rtcp),
1664 renderer_(NULL), 1717 renderer_(NULL),
1665 previous_we_(rtc::WE_CLOSE) { 1718 previous_we_(rtc::WE_CLOSE) {
1666 } 1719 }
1667 1720
1668 bool VideoChannel::Init() { 1721 bool VideoChannel::Init() {
1669 if (!BaseChannel::Init()) { 1722 if (!BaseChannel::Init()) {
1670 return false; 1723 return false;
1671 } 1724 }
1672 media_channel()->SignalMediaError.connect( 1725 media_channel()->SignalMediaError.connect(
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
2087 } 2140 }
2088 } 2141 }
2089 2142
2090 2143
2091 void VideoChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const { 2144 void VideoChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const {
2092 GetSupportedVideoCryptoSuites(ciphers); 2145 GetSupportedVideoCryptoSuites(ciphers);
2093 } 2146 }
2094 2147
2095 DataChannel::DataChannel(rtc::Thread* thread, 2148 DataChannel::DataChannel(rtc::Thread* thread,
2096 DataMediaChannel* media_channel, 2149 DataMediaChannel* media_channel,
2097 BaseSession* session, 2150 TransportController* transport_controller,
2098 const std::string& content_name, 2151 const std::string& content_name,
2099 bool rtcp) 2152 bool rtcp)
2100 : BaseChannel(thread, media_channel, session, content_name, rtcp), 2153 : BaseChannel(thread,
2154 media_channel,
2155 transport_controller,
2156 content_name,
2157 rtcp),
2101 data_channel_type_(cricket::DCT_NONE), 2158 data_channel_type_(cricket::DCT_NONE),
2102 ready_to_send_data_(false) { 2159 ready_to_send_data_(false) {
2103 } 2160 }
2104 2161
2105 DataChannel::~DataChannel() { 2162 DataChannel::~DataChannel() {
2106 StopMediaMonitor(); 2163 StopMediaMonitor();
2107 // this can't be done in the base class, since it calls a virtual 2164 // this can't be done in the base class, since it calls a virtual
2108 DisableMedia_w(); 2165 DisableMedia_w();
2109 2166
2110 Deinit(); 2167 Deinit();
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
2428 return (data_channel_type_ == DCT_RTP); 2485 return (data_channel_type_ == DCT_RTP);
2429 } 2486 }
2430 2487
2431 void DataChannel::OnStreamClosedRemotely(uint32 sid) { 2488 void DataChannel::OnStreamClosedRemotely(uint32 sid) {
2432 rtc::TypedMessageData<uint32>* message = 2489 rtc::TypedMessageData<uint32>* message =
2433 new rtc::TypedMessageData<uint32>(sid); 2490 new rtc::TypedMessageData<uint32>(sid);
2434 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); 2491 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message);
2435 } 2492 }
2436 2493
2437 } // namespace cricket 2494 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698