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

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

Issue 1358413003: Revert of TransportController refactoring. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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
« no previous file with comments | « talk/session/media/channel.h ('k') | talk/session/media/channel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 template <class Codec, class Options> 164 template <class Codec, class Options>
165 void RtpSendParametersFromMediaDescription( 165 void RtpSendParametersFromMediaDescription(
166 const MediaContentDescriptionImpl<Codec>* desc, 166 const MediaContentDescriptionImpl<Codec>* desc,
167 RtpSendParameters<Codec, Options>* send_params) { 167 RtpSendParameters<Codec, Options>* send_params) {
168 RtpParametersFromMediaDescription(desc, send_params); 168 RtpParametersFromMediaDescription(desc, send_params);
169 send_params->max_bandwidth_bps = desc->bandwidth(); 169 send_params->max_bandwidth_bps = desc->bandwidth();
170 } 170 }
171 171
172 BaseChannel::BaseChannel(rtc::Thread* thread, 172 BaseChannel::BaseChannel(rtc::Thread* thread,
173 MediaChannel* media_channel, 173 MediaChannel* media_channel, BaseSession* session,
174 TransportController* transport_controller, 174 const std::string& content_name, bool rtcp)
175 const std::string& content_name,
176 bool rtcp)
177 : worker_thread_(thread), 175 : worker_thread_(thread),
178 transport_controller_(transport_controller), 176 session_(session),
179 media_channel_(media_channel), 177 media_channel_(media_channel),
180 content_name_(content_name), 178 content_name_(content_name),
181 rtcp_transport_enabled_(rtcp), 179 rtcp_(rtcp),
182 transport_channel_(nullptr), 180 transport_channel_(NULL),
183 rtcp_transport_channel_(nullptr), 181 rtcp_transport_channel_(NULL),
184 enabled_(false), 182 enabled_(false),
185 writable_(false), 183 writable_(false),
186 rtp_ready_to_send_(false), 184 rtp_ready_to_send_(false),
187 rtcp_ready_to_send_(false), 185 rtcp_ready_to_send_(false),
188 was_ever_writable_(false), 186 was_ever_writable_(false),
189 local_content_direction_(MD_INACTIVE), 187 local_content_direction_(MD_INACTIVE),
190 remote_content_direction_(MD_INACTIVE), 188 remote_content_direction_(MD_INACTIVE),
191 has_received_packet_(false), 189 has_received_packet_(false),
192 dtls_keyed_(false), 190 dtls_keyed_(false),
193 secure_required_(false), 191 secure_required_(false),
194 rtp_abs_sendtime_extn_id_(-1) { 192 rtp_abs_sendtime_extn_id_(-1) {
195 ASSERT(worker_thread_ == rtc::Thread::Current()); 193 ASSERT(worker_thread_ == rtc::Thread::Current());
196 LOG(LS_INFO) << "Created channel for " << content_name; 194 LOG(LS_INFO) << "Created channel for " << content_name;
197 } 195 }
198 196
199 BaseChannel::~BaseChannel() { 197 BaseChannel::~BaseChannel() {
200 ASSERT(worker_thread_ == rtc::Thread::Current()); 198 ASSERT(worker_thread_ == rtc::Thread::Current());
201 Deinit(); 199 Deinit();
202 StopConnectionMonitor(); 200 StopConnectionMonitor();
203 FlushRtcpMessages(); // Send any outstanding RTCP packets. 201 FlushRtcpMessages(); // Send any outstanding RTCP packets.
204 worker_thread_->Clear(this); // eats any outstanding messages or packets 202 worker_thread_->Clear(this); // eats any outstanding messages or packets
205 // We must destroy the media channel before the transport channel, otherwise 203 // We must destroy the media channel before the transport channel, otherwise
206 // the media channel may try to send on the dead transport channel. NULLing 204 // the media channel may try to send on the dead transport channel. NULLing
207 // is not an effective strategy since the sends will come on another thread. 205 // is not an effective strategy since the sends will come on another thread.
208 delete media_channel_; 206 delete media_channel_;
209 // Note that we don't just call set_transport_channel(nullptr) because that 207 set_transport_channel(nullptr);
210 // would call a pure virtual method which we can't do from a destructor. 208 set_rtcp_transport_channel(nullptr);
211 if (transport_channel_) {
212 DisconnectFromTransportChannel(transport_channel_);
213 transport_controller_->DestroyTransportChannel_w(
214 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP);
215 }
216 if (rtcp_transport_channel_) {
217 DisconnectFromTransportChannel(rtcp_transport_channel_);
218 transport_controller_->DestroyTransportChannel_w(
219 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
220 }
221 LOG(LS_INFO) << "Destroyed channel"; 209 LOG(LS_INFO) << "Destroyed channel";
222 } 210 }
223 211
224 bool BaseChannel::Init() { 212 bool BaseChannel::Init() {
225 if (!SetTransport(content_name())) { 213 if (!SetTransportChannels(session(), rtcp())) {
226 return false; 214 return false;
227 } 215 }
228 216
229 if (!SetDtlsSrtpCiphers(transport_channel(), false)) { 217 if (!SetDtlsSrtpCiphers(transport_channel(), false)) {
230 return false; 218 return false;
231 } 219 }
232 if (rtcp_transport_enabled() && 220 if (rtcp() && !SetDtlsSrtpCiphers(rtcp_transport_channel(), true)) {
233 !SetDtlsSrtpCiphers(rtcp_transport_channel(), true)) {
234 return false; 221 return false;
235 } 222 }
236 223
237 // Both RTP and RTCP channels are set, we can call SetInterface on 224 // Both RTP and RTCP channels are set, we can call SetInterface on
238 // media channel and it can set network options. 225 // media channel and it can set network options.
239 media_channel_->SetInterface(this); 226 media_channel_->SetInterface(this);
240 return true; 227 return true;
241 } 228 }
242 229
243 void BaseChannel::Deinit() { 230 void BaseChannel::Deinit() {
244 media_channel_->SetInterface(NULL); 231 media_channel_->SetInterface(NULL);
245 } 232 }
246 233
247 bool BaseChannel::SetTransport(const std::string& transport_name) { 234 bool BaseChannel::SetTransportChannels(BaseSession* session, bool rtcp) {
248 return worker_thread_->Invoke<bool>( 235 return worker_thread_->Invoke<bool>(Bind(
249 Bind(&BaseChannel::SetTransport_w, this, transport_name)); 236 &BaseChannel::SetTransportChannels_w, this, session, rtcp));
250 } 237 }
251 238
252 bool BaseChannel::SetTransport_w(const std::string& transport_name) { 239 bool BaseChannel::SetTransportChannels_w(BaseSession* session, bool rtcp) {
253 ASSERT(worker_thread_ == rtc::Thread::Current()); 240 ASSERT(worker_thread_ == rtc::Thread::Current());
254 241
255 if (transport_name == transport_name_) { 242 set_transport_channel(session->CreateChannel(
256 // Nothing to do if transport name isn't changing 243 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP));
257 return true;
258 }
259
260 set_transport_channel(transport_controller_->CreateTransportChannel_w(
261 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP));
262 if (!transport_channel()) { 244 if (!transport_channel()) {
263 return false; 245 return false;
264 } 246 }
265 if (rtcp_transport_enabled()) { 247 if (rtcp) {
266 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() 248 set_rtcp_transport_channel(session->CreateChannel(
267 << " on " << transport_name << " transport "; 249 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP));
268 set_rtcp_transport_channel(transport_controller_->CreateTransportChannel_w(
269 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP));
270 if (!rtcp_transport_channel()) { 250 if (!rtcp_transport_channel()) {
271 return false; 251 return false;
272 } 252 }
253 } else {
254 set_rtcp_transport_channel(nullptr);
273 } 255 }
274 256
275 transport_name_ = transport_name;
276 return true; 257 return true;
277 } 258 }
278 259
279 void BaseChannel::set_transport_channel(TransportChannel* new_tc) { 260 void BaseChannel::set_transport_channel(TransportChannel* new_tc) {
280 ASSERT(worker_thread_ == rtc::Thread::Current()); 261 ASSERT(worker_thread_ == rtc::Thread::Current());
281 262
282 TransportChannel* old_tc = transport_channel_; 263 TransportChannel* old_tc = transport_channel_;
283 if (!old_tc && !new_tc) { 264
284 // Nothing to do 265 if (old_tc == new_tc) {
285 return; 266 return;
286 } 267 }
287 ASSERT(old_tc != new_tc);
288
289 if (old_tc) { 268 if (old_tc) {
290 DisconnectFromTransportChannel(old_tc); 269 DisconnectFromTransportChannel(old_tc);
291 transport_controller_->DestroyTransportChannel_w( 270 session()->DestroyChannel(
292 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); 271 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
293 } 272 }
294 273
295 transport_channel_ = new_tc; 274 transport_channel_ = new_tc;
296 275
297 if (new_tc) { 276 if (new_tc) {
298 ConnectToTransportChannel(new_tc); 277 ConnectToTransportChannel(new_tc);
299 for (const auto& pair : socket_options_) {
300 new_tc->SetOption(pair.first, pair.second);
301 }
302 } 278 }
303
304 // Update aggregate writable/ready-to-send state between RTP and RTCP upon
305 // setting new channel
306 UpdateWritableState_w();
307 SetReadyToSend(false, new_tc && new_tc->writable());
308 } 279 }
309 280
310 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc) { 281 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc) {
311 ASSERT(worker_thread_ == rtc::Thread::Current()); 282 ASSERT(worker_thread_ == rtc::Thread::Current());
312 283
313 TransportChannel* old_tc = rtcp_transport_channel_; 284 TransportChannel* old_tc = rtcp_transport_channel_;
314 if (!old_tc && !new_tc) { 285
315 // Nothing to do 286 if (old_tc == new_tc) {
316 return; 287 return;
317 } 288 }
318 ASSERT(old_tc != new_tc);
319
320 if (old_tc) { 289 if (old_tc) {
321 DisconnectFromTransportChannel(old_tc); 290 DisconnectFromTransportChannel(old_tc);
322 transport_controller_->DestroyTransportChannel_w( 291 session()->DestroyChannel(
323 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); 292 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
324 } 293 }
325 294
326 rtcp_transport_channel_ = new_tc; 295 rtcp_transport_channel_ = new_tc;
327 296
328 if (new_tc) { 297 if (new_tc) {
329 ConnectToTransportChannel(new_tc); 298 ConnectToTransportChannel(new_tc);
330 for (const auto& pair : rtcp_socket_options_) {
331 new_tc->SetOption(pair.first, pair.second);
332 }
333 } 299 }
334
335 // Update aggregate writable/ready-to-send state between RTP and RTCP upon
336 // setting new channel
337 UpdateWritableState_w();
338 SetReadyToSend(true, new_tc && new_tc->writable());
339 } 300 }
340 301
341 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { 302 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) {
342 ASSERT(worker_thread_ == rtc::Thread::Current()); 303 ASSERT(worker_thread_ == rtc::Thread::Current());
343 304
344 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); 305 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState);
345 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); 306 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead);
346 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); 307 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend);
347 } 308 }
348 309
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 rtc::DiffServCodePoint dscp) { 400 rtc::DiffServCodePoint dscp) {
440 return SendPacket(true, packet, dscp); 401 return SendPacket(true, packet, dscp);
441 } 402 }
442 403
443 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, 404 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt,
444 int value) { 405 int value) {
445 TransportChannel* channel = NULL; 406 TransportChannel* channel = NULL;
446 switch (type) { 407 switch (type) {
447 case ST_RTP: 408 case ST_RTP:
448 channel = transport_channel_; 409 channel = transport_channel_;
449 socket_options_.push_back(
450 std::pair<rtc::Socket::Option, int>(opt, value));
451 break; 410 break;
452 case ST_RTCP: 411 case ST_RTCP:
453 channel = rtcp_transport_channel_; 412 channel = rtcp_transport_channel_;
454 rtcp_socket_options_.push_back(
455 std::pair<rtc::Socket::Option, int>(opt, value));
456 break; 413 break;
457 } 414 }
458 return channel ? channel->SetOption(opt, value) : -1; 415 return channel ? channel->SetOption(opt, value) : -1;
459 } 416 }
460 417
461 void BaseChannel::OnWritableState(TransportChannel* channel) { 418 void BaseChannel::OnWritableState(TransportChannel* channel) {
462 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); 419 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
463 UpdateWritableState_w(); 420 if (transport_channel_->writable()
421 && (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) {
422 ChannelWritable_w();
423 } else {
424 ChannelNotWritable_w();
425 }
464 } 426 }
465 427
466 void BaseChannel::OnChannelRead(TransportChannel* channel, 428 void BaseChannel::OnChannelRead(TransportChannel* channel,
467 const char* data, size_t len, 429 const char* data, size_t len,
468 const rtc::PacketTime& packet_time, 430 const rtc::PacketTime& packet_time,
469 int flags) { 431 int flags) {
470 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine 432 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine
471 ASSERT(worker_thread_ == rtc::Thread::Current()); 433 ASSERT(worker_thread_ == rtc::Thread::Current());
472 434
473 // When using RTCP multiplexing we might get RTCP packets on the RTP 435 // When using RTCP multiplexing we might get RTCP packets on the RTP
474 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. 436 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP.
475 bool rtcp = PacketIsRtcp(channel, data, len); 437 bool rtcp = PacketIsRtcp(channel, data, len);
476 rtc::Buffer packet(data, len); 438 rtc::Buffer packet(data, len);
477 HandlePacket(rtcp, &packet, packet_time); 439 HandlePacket(rtcp, &packet, packet_time);
478 } 440 }
479 441
480 void BaseChannel::OnReadyToSend(TransportChannel* channel) { 442 void BaseChannel::OnReadyToSend(TransportChannel* channel) {
481 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); 443 SetReadyToSend(channel, true);
482 SetReadyToSend(channel == rtcp_transport_channel_, true);
483 } 444 }
484 445
485 void BaseChannel::SetReadyToSend(bool rtcp, bool ready) { 446 void BaseChannel::SetReadyToSend(TransportChannel* channel, bool ready) {
486 if (rtcp) { 447 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
487 rtcp_ready_to_send_ = ready; 448 if (channel == transport_channel_) {
488 } else {
489 rtp_ready_to_send_ = ready; 449 rtp_ready_to_send_ = ready;
490 } 450 }
451 if (channel == rtcp_transport_channel_) {
452 rtcp_ready_to_send_ = ready;
453 }
491 454
492 if (rtp_ready_to_send_ && 455 if (!ready) {
493 // In the case of rtcp mux |rtcp_transport_channel_| will be null. 456 // Notify the MediaChannel when either rtp or rtcp channel can't send.
494 (rtcp_ready_to_send_ || !rtcp_transport_channel_)) { 457 media_channel_->OnReadyToSend(false);
458 } else if (rtp_ready_to_send_ &&
459 // In the case of rtcp mux |rtcp_transport_channel_| will be null.
460 (rtcp_ready_to_send_ || !rtcp_transport_channel_)) {
495 // Notify the MediaChannel when both rtp and rtcp channel can send. 461 // Notify the MediaChannel when both rtp and rtcp channel can send.
496 media_channel_->OnReadyToSend(true); 462 media_channel_->OnReadyToSend(true);
497 } else {
498 // Notify the MediaChannel when either rtp or rtcp channel can't send.
499 media_channel_->OnReadyToSend(false);
500 } 463 }
501 } 464 }
502 465
503 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, 466 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel,
504 const char* data, size_t len) { 467 const char* data, size_t len) {
505 return (channel == rtcp_transport_channel_ || 468 return (channel == rtcp_transport_channel_ ||
506 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); 469 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len)));
507 } 470 }
508 471
509 bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet, 472 bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 return false; 574 return false;
612 } 575 }
613 576
614 // Bon voyage. 577 // Bon voyage.
615 int ret = 578 int ret =
616 channel->SendPacket(packet->data<char>(), packet->size(), options, 579 channel->SendPacket(packet->data<char>(), packet->size(), options,
617 (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0); 580 (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0);
618 if (ret != static_cast<int>(packet->size())) { 581 if (ret != static_cast<int>(packet->size())) {
619 if (channel->GetError() == EWOULDBLOCK) { 582 if (channel->GetError() == EWOULDBLOCK) {
620 LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; 583 LOG(LS_WARNING) << "Got EWOULDBLOCK from socket.";
621 SetReadyToSend(rtcp, false); 584 SetReadyToSend(channel, false);
622 } 585 }
623 return false; 586 return false;
624 } 587 }
625 return true; 588 return true;
626 } 589 }
627 590
628 bool BaseChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) { 591 bool BaseChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) {
629 // Protect ourselves against crazy data. 592 // Protect ourselves against crazy data.
630 if (!ValidPacket(rtcp, packet)) { 593 if (!ValidPacket(rtcp, packet)) {
631 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " 594 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " "
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 void BaseChannel::DisableMedia_w() { 708 void BaseChannel::DisableMedia_w() {
746 ASSERT(worker_thread_ == rtc::Thread::Current()); 709 ASSERT(worker_thread_ == rtc::Thread::Current());
747 if (!enabled_) 710 if (!enabled_)
748 return; 711 return;
749 712
750 LOG(LS_INFO) << "Channel disabled"; 713 LOG(LS_INFO) << "Channel disabled";
751 enabled_ = false; 714 enabled_ = false;
752 ChangeState(); 715 ChangeState();
753 } 716 }
754 717
755 void BaseChannel::UpdateWritableState_w() {
756 if (transport_channel_ && transport_channel_->writable() &&
757 (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) {
758 ChannelWritable_w();
759 } else {
760 ChannelNotWritable_w();
761 }
762 }
763
764 void BaseChannel::ChannelWritable_w() { 718 void BaseChannel::ChannelWritable_w() {
765 ASSERT(worker_thread_ == rtc::Thread::Current()); 719 ASSERT(worker_thread_ == rtc::Thread::Current());
766 if (writable_) 720 if (writable_)
767 return; 721 return;
768 722
769 LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" 723 LOG(LS_INFO) << "Channel socket writable ("
724 << transport_channel_->content_name() << ", "
725 << transport_channel_->component() << ")"
770 << (was_ever_writable_ ? "" : " for the first time"); 726 << (was_ever_writable_ ? "" : " for the first time");
771 727
772 std::vector<ConnectionInfo> infos; 728 std::vector<ConnectionInfo> infos;
773 transport_channel_->GetStats(&infos); 729 transport_channel_->GetStats(&infos);
774 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); 730 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin();
775 it != infos.end(); ++it) { 731 it != infos.end(); ++it) {
776 if (it->best_connection) { 732 if (it->best_connection) {
777 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() 733 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString()
778 << "->" << it->remote_candidate.ToSensitiveString(); 734 << "->" << it->remote_candidate.ToSensitiveString();
779 break; 735 break;
780 } 736 }
781 } 737 }
782 738
783 // If we're doing DTLS-SRTP, now is the time. 739 // If we're doing DTLS-SRTP, now is the time.
784 if (!was_ever_writable_ && ShouldSetupDtlsSrtp()) { 740 if (!was_ever_writable_ && ShouldSetupDtlsSrtp()) {
785 if (!SetupDtlsSrtp(false)) { 741 if (!SetupDtlsSrtp(false)) {
786 SignalDtlsSetupFailure_w(false); 742 SignalDtlsSetupFailure(this, false);
787 return; 743 return;
788 } 744 }
789 745
790 if (rtcp_transport_channel_) { 746 if (rtcp_transport_channel_) {
791 if (!SetupDtlsSrtp(true)) { 747 if (!SetupDtlsSrtp(true)) {
792 SignalDtlsSetupFailure_w(true); 748 SignalDtlsSetupFailure(this, true);
793 return; 749 return;
794 } 750 }
795 } 751 }
796 } 752 }
797 753
798 was_ever_writable_ = true; 754 was_ever_writable_ = true;
799 writable_ = true; 755 writable_ = true;
800 ChangeState(); 756 ChangeState();
801 } 757 }
802 758
(...skipping 22 matching lines...) Expand all
825 781
826 bool BaseChannel::ShouldSetupDtlsSrtp() const { 782 bool BaseChannel::ShouldSetupDtlsSrtp() const {
827 return true; 783 return true;
828 } 784 }
829 785
830 // This function returns true if either DTLS-SRTP is not in use 786 // This function returns true if either DTLS-SRTP is not in use
831 // *or* DTLS-SRTP is successfully set up. 787 // *or* DTLS-SRTP is successfully set up.
832 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { 788 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) {
833 bool ret = false; 789 bool ret = false;
834 790
835 TransportChannel* channel = 791 TransportChannel *channel = rtcp_channel ?
836 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; 792 rtcp_transport_channel_ : transport_channel_;
837 793
838 // No DTLS 794 // No DTLS
839 if (!channel->IsDtlsActive()) 795 if (!channel->IsDtlsActive())
840 return true; 796 return true;
841 797
842 std::string selected_cipher; 798 std::string selected_cipher;
843 799
844 if (!channel->GetSrtpCipher(&selected_cipher)) { 800 if (!channel->GetSrtpCipher(&selected_cipher)) {
845 LOG(LS_ERROR) << "No DTLS-SRTP selected cipher"; 801 LOG(LS_ERROR) << "No DTLS-SRTP selected cipher";
846 return false; 802 return false;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 dtls_keyed_ = true; 877 dtls_keyed_ = true;
922 878
923 return ret; 879 return ret;
924 } 880 }
925 881
926 void BaseChannel::ChannelNotWritable_w() { 882 void BaseChannel::ChannelNotWritable_w() {
927 ASSERT(worker_thread_ == rtc::Thread::Current()); 883 ASSERT(worker_thread_ == rtc::Thread::Current());
928 if (!writable_) 884 if (!writable_)
929 return; 885 return;
930 886
931 LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; 887 LOG(LS_INFO) << "Channel socket not writable ("
888 << transport_channel_->content_name() << ", "
889 << transport_channel_->component() << ")";
932 writable_ = false; 890 writable_ = false;
933 ChangeState(); 891 ChangeState();
934 } 892 }
935 893
936 bool BaseChannel::SetRtpTransportParameters_w( 894 bool BaseChannel::SetRtpTransportParameters_w(
937 const MediaContentDescription* content, 895 const MediaContentDescription* content,
938 ContentAction action, 896 ContentAction action,
939 ContentSource src, 897 ContentSource src,
940 std::string* error_desc) { 898 std::string* error_desc) {
941 if (action == CA_UPDATE) { 899 if (action == CA_UPDATE) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 } 978 }
1021 979
1022 void BaseChannel::ActivateRtcpMux() { 980 void BaseChannel::ActivateRtcpMux() {
1023 worker_thread_->Invoke<void>(Bind( 981 worker_thread_->Invoke<void>(Bind(
1024 &BaseChannel::ActivateRtcpMux_w, this)); 982 &BaseChannel::ActivateRtcpMux_w, this));
1025 } 983 }
1026 984
1027 void BaseChannel::ActivateRtcpMux_w() { 985 void BaseChannel::ActivateRtcpMux_w() {
1028 if (!rtcp_mux_filter_.IsActive()) { 986 if (!rtcp_mux_filter_.IsActive()) {
1029 rtcp_mux_filter_.SetActive(); 987 rtcp_mux_filter_.SetActive();
1030 set_rtcp_transport_channel(nullptr); 988 set_rtcp_transport_channel(NULL);
1031 rtcp_transport_enabled_ = false;
1032 } 989 }
1033 } 990 }
1034 991
1035 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action, 992 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action,
1036 ContentSource src, 993 ContentSource src,
1037 std::string* error_desc) { 994 std::string* error_desc) {
1038 bool ret = false; 995 bool ret = false;
1039 switch (action) { 996 switch (action) {
1040 case CA_OFFER: 997 case CA_OFFER:
1041 ret = rtcp_mux_filter_.SetOffer(enable, src); 998 ret = rtcp_mux_filter_.SetOffer(enable, src);
1042 break; 999 break;
1043 case CA_PRANSWER: 1000 case CA_PRANSWER:
1044 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); 1001 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src);
1045 break; 1002 break;
1046 case CA_ANSWER: 1003 case CA_ANSWER:
1047 ret = rtcp_mux_filter_.SetAnswer(enable, src); 1004 ret = rtcp_mux_filter_.SetAnswer(enable, src);
1048 if (ret && rtcp_mux_filter_.IsActive()) { 1005 if (ret && rtcp_mux_filter_.IsActive()) {
1049 // We activated RTCP mux, close down the RTCP transport. 1006 // We activated RTCP mux, close down the RTCP transport.
1050 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() 1007 set_rtcp_transport_channel(NULL);
1051 << " by destroying RTCP transport channel for "
1052 << transport_name();
1053 set_rtcp_transport_channel(nullptr);
1054 rtcp_transport_enabled_ = false;
1055 } 1008 }
1056 break; 1009 break;
1057 case CA_UPDATE: 1010 case CA_UPDATE:
1058 // No RTCP mux info. 1011 // No RTCP mux info.
1059 ret = true; 1012 ret = true;
1060 break; 1013 break;
1061 default: 1014 default:
1062 break; 1015 break;
1063 } 1016 }
1064 if (!ret) { 1017 if (!ret) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages); 1224 worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages);
1272 for (rtc::MessageList::iterator it = rtcp_messages.begin(); 1225 for (rtc::MessageList::iterator it = rtcp_messages.begin();
1273 it != rtcp_messages.end(); ++it) { 1226 it != rtcp_messages.end(); ++it) {
1274 worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata); 1227 worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata);
1275 } 1228 }
1276 } 1229 }
1277 1230
1278 VoiceChannel::VoiceChannel(rtc::Thread* thread, 1231 VoiceChannel::VoiceChannel(rtc::Thread* thread,
1279 MediaEngineInterface* media_engine, 1232 MediaEngineInterface* media_engine,
1280 VoiceMediaChannel* media_channel, 1233 VoiceMediaChannel* media_channel,
1281 TransportController* transport_controller, 1234 BaseSession* session,
1282 const std::string& content_name, 1235 const std::string& content_name,
1283 bool rtcp) 1236 bool rtcp)
1284 : BaseChannel(thread, 1237 : BaseChannel(thread, media_channel, session, content_name,
1285 media_channel,
1286 transport_controller,
1287 content_name,
1288 rtcp), 1238 rtcp),
1289 media_engine_(media_engine), 1239 media_engine_(media_engine),
1290 received_media_(false) {} 1240 received_media_(false) {
1241 }
1291 1242
1292 VoiceChannel::~VoiceChannel() { 1243 VoiceChannel::~VoiceChannel() {
1293 StopAudioMonitor(); 1244 StopAudioMonitor();
1294 StopMediaMonitor(); 1245 StopMediaMonitor();
1295 // this can't be done in the base class, since it calls a virtual 1246 // this can't be done in the base class, since it calls a virtual
1296 DisableMedia_w(); 1247 DisableMedia_w();
1297 Deinit(); 1248 Deinit();
1298 } 1249 }
1299 1250
1300 bool VoiceChannel::Init() { 1251 bool VoiceChannel::Init() {
1301 if (!BaseChannel::Init()) { 1252 if (!BaseChannel::Init()) {
1302 return false; 1253 return false;
1303 } 1254 }
1304 media_channel()->SignalMediaError.connect( 1255 media_channel()->SignalMediaError.connect(
1305 this, &VoiceChannel::OnVoiceChannelError); 1256 this, &VoiceChannel::OnVoiceChannelError);
1306 srtp_filter()->SignalSrtpError.connect( 1257 srtp_filter()->SignalSrtpError.connect(
1307 this, &VoiceChannel::OnSrtpError); 1258 this, &VoiceChannel::OnSrtpError);
1308 return true; 1259 return true;
1309 } 1260 }
1310 1261
1311 bool VoiceChannel::SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) { 1262 bool VoiceChannel::SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) {
1312 return InvokeOnWorker(Bind(&VoiceMediaChannel::SetRemoteRenderer, 1263 return InvokeOnWorker(Bind(&VoiceMediaChannel::SetRemoteRenderer,
1313 media_channel(), ssrc, renderer)); 1264 media_channel(), ssrc, renderer));
1314 } 1265 }
1315 1266
1316 bool VoiceChannel::SetAudioSend(uint32 ssrc, 1267 bool VoiceChannel::SetAudioSend(uint32 ssrc, bool mute,
1317 bool mute,
1318 const AudioOptions* options, 1268 const AudioOptions* options,
1319 AudioRenderer* renderer) { 1269 AudioRenderer* renderer) {
1320 return InvokeOnWorker(Bind(&VoiceMediaChannel::SetAudioSend, media_channel(), 1270 return InvokeOnWorker(Bind(&VoiceMediaChannel::SetAudioSend,
1321 ssrc, mute, options, renderer)); 1271 media_channel(), ssrc, mute, options, renderer));
1322 } 1272 }
1323 1273
1324 bool VoiceChannel::SetRingbackTone(const void* buf, int len) { 1274 bool VoiceChannel::SetRingbackTone(const void* buf, int len) {
1325 return InvokeOnWorker(Bind(&VoiceChannel::SetRingbackTone_w, this, buf, len)); 1275 return InvokeOnWorker(Bind(&VoiceChannel::SetRingbackTone_w, this, buf, len));
1326 } 1276 }
1327 1277
1328 // TODO(juberti): Handle early media the right way. We should get an explicit 1278 // TODO(juberti): Handle early media the right way. We should get an explicit
1329 // ringing message telling us to start playing local ringback, which we cancel 1279 // ringing message telling us to start playing local ringback, which we cancel
1330 // if any early media actually arrives. For now, we do the opposite, which is 1280 // if any early media actually arrives. For now, we do the opposite, which is
1331 // to wait 1 second for early media, and start playing local ringback if none 1281 // to wait 1 second for early media, and start playing local ringback if none
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 break; 1600 break;
1651 } 1601 }
1652 } 1602 }
1653 1603
1654 void VoiceChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const { 1604 void VoiceChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const {
1655 GetSupportedAudioCryptoSuites(ciphers); 1605 GetSupportedAudioCryptoSuites(ciphers);
1656 } 1606 }
1657 1607
1658 VideoChannel::VideoChannel(rtc::Thread* thread, 1608 VideoChannel::VideoChannel(rtc::Thread* thread,
1659 VideoMediaChannel* media_channel, 1609 VideoMediaChannel* media_channel,
1660 TransportController* transport_controller, 1610 BaseSession* session,
1661 const std::string& content_name, 1611 const std::string& content_name,
1662 bool rtcp) 1612 bool rtcp)
1663 : BaseChannel(thread, 1613 : BaseChannel(thread, media_channel, session, content_name,
1664 media_channel,
1665 transport_controller,
1666 content_name,
1667 rtcp), 1614 rtcp),
1668 renderer_(NULL), 1615 renderer_(NULL),
1669 previous_we_(rtc::WE_CLOSE) {} 1616 previous_we_(rtc::WE_CLOSE) {
1617 }
1670 1618
1671 bool VideoChannel::Init() { 1619 bool VideoChannel::Init() {
1672 if (!BaseChannel::Init()) { 1620 if (!BaseChannel::Init()) {
1673 return false; 1621 return false;
1674 } 1622 }
1675 media_channel()->SignalMediaError.connect( 1623 media_channel()->SignalMediaError.connect(
1676 this, &VideoChannel::OnVideoChannelError); 1624 this, &VideoChannel::OnVideoChannelError);
1677 srtp_filter()->SignalSrtpError.connect( 1625 srtp_filter()->SignalSrtpError.connect(
1678 this, &VideoChannel::OnSrtpError); 1626 this, &VideoChannel::OnSrtpError);
1679 return true; 1627 return true;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 &VideoMediaChannel::SendIntraFrame, media_channel())); 1700 &VideoMediaChannel::SendIntraFrame, media_channel()));
1753 return true; 1701 return true;
1754 } 1702 }
1755 1703
1756 bool VideoChannel::RequestIntraFrame() { 1704 bool VideoChannel::RequestIntraFrame() {
1757 worker_thread()->Invoke<void>(Bind( 1705 worker_thread()->Invoke<void>(Bind(
1758 &VideoMediaChannel::RequestIntraFrame, media_channel())); 1706 &VideoMediaChannel::RequestIntraFrame, media_channel()));
1759 return true; 1707 return true;
1760 } 1708 }
1761 1709
1762 bool VideoChannel::SetVideoSend(uint32 ssrc, 1710 bool VideoChannel::SetVideoSend(uint32 ssrc, bool mute,
1763 bool mute,
1764 const VideoOptions* options) { 1711 const VideoOptions* options) {
1765 return InvokeOnWorker(Bind(&VideoMediaChannel::SetVideoSend, media_channel(), 1712 return InvokeOnWorker(Bind(&VideoMediaChannel::SetVideoSend,
1766 ssrc, mute, options)); 1713 media_channel(), ssrc, mute, options));
1767 } 1714 }
1768 1715
1769 void VideoChannel::ChangeState() { 1716 void VideoChannel::ChangeState() {
1770 // Render incoming data if we're the active call, and we have the local 1717 // Render incoming data if we're the active call, and we have the local
1771 // content. We receive data on the default channel and multiplexed streams. 1718 // content. We receive data on the default channel and multiplexed streams.
1772 bool recv = IsReadyToReceive(); 1719 bool recv = IsReadyToReceive();
1773 if (!media_channel()->SetRender(recv)) { 1720 if (!media_channel()->SetRender(recv)) {
1774 LOG(LS_ERROR) << "Failed to SetRender on video channel"; 1721 LOG(LS_ERROR) << "Failed to SetRender on video channel";
1775 // TODO(gangji): Report error back to server. 1722 // TODO(gangji): Report error back to server.
1776 } 1723 }
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 break; 2038 break;
2092 } 2039 }
2093 } 2040 }
2094 2041
2095 void VideoChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const { 2042 void VideoChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const {
2096 GetSupportedVideoCryptoSuites(ciphers); 2043 GetSupportedVideoCryptoSuites(ciphers);
2097 } 2044 }
2098 2045
2099 DataChannel::DataChannel(rtc::Thread* thread, 2046 DataChannel::DataChannel(rtc::Thread* thread,
2100 DataMediaChannel* media_channel, 2047 DataMediaChannel* media_channel,
2101 TransportController* transport_controller, 2048 BaseSession* session,
2102 const std::string& content_name, 2049 const std::string& content_name,
2103 bool rtcp) 2050 bool rtcp)
2104 : BaseChannel(thread, 2051 : BaseChannel(thread, media_channel, session, content_name, rtcp),
2105 media_channel,
2106 transport_controller,
2107 content_name,
2108 rtcp),
2109 data_channel_type_(cricket::DCT_NONE), 2052 data_channel_type_(cricket::DCT_NONE),
2110 ready_to_send_data_(false) {} 2053 ready_to_send_data_(false) {
2054 }
2111 2055
2112 DataChannel::~DataChannel() { 2056 DataChannel::~DataChannel() {
2113 StopMediaMonitor(); 2057 StopMediaMonitor();
2114 // this can't be done in the base class, since it calls a virtual 2058 // this can't be done in the base class, since it calls a virtual
2115 DisableMedia_w(); 2059 DisableMedia_w();
2116 2060
2117 Deinit(); 2061 Deinit();
2118 } 2062 }
2119 2063
2120 bool DataChannel::Init() { 2064 bool DataChannel::Init() {
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
2435 return (data_channel_type_ == DCT_RTP); 2379 return (data_channel_type_ == DCT_RTP);
2436 } 2380 }
2437 2381
2438 void DataChannel::OnStreamClosedRemotely(uint32 sid) { 2382 void DataChannel::OnStreamClosedRemotely(uint32 sid) {
2439 rtc::TypedMessageData<uint32>* message = 2383 rtc::TypedMessageData<uint32>* message =
2440 new rtc::TypedMessageData<uint32>(sid); 2384 new rtc::TypedMessageData<uint32>(sid);
2441 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); 2385 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message);
2442 } 2386 }
2443 2387
2444 } // namespace cricket 2388 } // namespace cricket
OLDNEW
« no previous file with comments | « talk/session/media/channel.h ('k') | talk/session/media/channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698