OLD | NEW |
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 Loading... |
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, BaseSession* session, | 173 MediaChannel* media_channel, |
174 const std::string& content_name, bool rtcp) | 174 TransportController* transport_controller, |
| 175 const std::string& content_name, |
| 176 bool rtcp) |
175 : worker_thread_(thread), | 177 : worker_thread_(thread), |
176 session_(session), | 178 transport_controller_(transport_controller), |
177 media_channel_(media_channel), | 179 media_channel_(media_channel), |
178 content_name_(content_name), | 180 content_name_(content_name), |
179 rtcp_(rtcp), | 181 rtcp_transport_enabled_(rtcp), |
180 transport_channel_(NULL), | 182 transport_channel_(nullptr), |
181 rtcp_transport_channel_(NULL), | 183 rtcp_transport_channel_(nullptr), |
182 enabled_(false), | 184 enabled_(false), |
183 writable_(false), | 185 writable_(false), |
184 rtp_ready_to_send_(false), | 186 rtp_ready_to_send_(false), |
185 rtcp_ready_to_send_(false), | 187 rtcp_ready_to_send_(false), |
186 was_ever_writable_(false), | 188 was_ever_writable_(false), |
187 local_content_direction_(MD_INACTIVE), | 189 local_content_direction_(MD_INACTIVE), |
188 remote_content_direction_(MD_INACTIVE), | 190 remote_content_direction_(MD_INACTIVE), |
189 has_received_packet_(false), | 191 has_received_packet_(false), |
190 dtls_keyed_(false), | 192 dtls_keyed_(false), |
191 secure_required_(false), | 193 secure_required_(false), |
192 rtp_abs_sendtime_extn_id_(-1) { | 194 rtp_abs_sendtime_extn_id_(-1) { |
193 ASSERT(worker_thread_ == rtc::Thread::Current()); | 195 ASSERT(worker_thread_ == rtc::Thread::Current()); |
194 LOG(LS_INFO) << "Created channel for " << content_name; | 196 LOG(LS_INFO) << "Created channel for " << content_name; |
195 } | 197 } |
196 | 198 |
197 BaseChannel::~BaseChannel() { | 199 BaseChannel::~BaseChannel() { |
198 ASSERT(worker_thread_ == rtc::Thread::Current()); | 200 ASSERT(worker_thread_ == rtc::Thread::Current()); |
199 Deinit(); | 201 Deinit(); |
200 StopConnectionMonitor(); | 202 StopConnectionMonitor(); |
201 FlushRtcpMessages(); // Send any outstanding RTCP packets. | 203 FlushRtcpMessages(); // Send any outstanding RTCP packets. |
202 worker_thread_->Clear(this); // eats any outstanding messages or packets | 204 worker_thread_->Clear(this); // eats any outstanding messages or packets |
203 // We must destroy the media channel before the transport channel, otherwise | 205 // We must destroy the media channel before the transport channel, otherwise |
204 // the media channel may try to send on the dead transport channel. NULLing | 206 // the media channel may try to send on the dead transport channel. NULLing |
205 // is not an effective strategy since the sends will come on another thread. | 207 // is not an effective strategy since the sends will come on another thread. |
206 delete media_channel_; | 208 delete media_channel_; |
207 set_transport_channel(nullptr); | 209 // Note that we don't just call set_transport_channel(nullptr) because that |
208 set_rtcp_transport_channel(nullptr); | 210 // would call a pure virtual method which we can't do from a destructor. |
| 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 } |
209 LOG(LS_INFO) << "Destroyed channel"; | 221 LOG(LS_INFO) << "Destroyed channel"; |
210 } | 222 } |
211 | 223 |
212 bool BaseChannel::Init() { | 224 bool BaseChannel::Init() { |
213 if (!SetTransportChannels(session(), rtcp())) { | 225 if (!SetTransport(content_name())) { |
214 return false; | 226 return false; |
215 } | 227 } |
216 | 228 |
217 if (!SetDtlsSrtpCiphers(transport_channel(), false)) { | 229 if (!SetDtlsSrtpCiphers(transport_channel(), false)) { |
218 return false; | 230 return false; |
219 } | 231 } |
220 if (rtcp() && !SetDtlsSrtpCiphers(rtcp_transport_channel(), true)) { | 232 if (rtcp_transport_enabled() && |
| 233 !SetDtlsSrtpCiphers(rtcp_transport_channel(), true)) { |
221 return false; | 234 return false; |
222 } | 235 } |
223 | 236 |
224 // Both RTP and RTCP channels are set, we can call SetInterface on | 237 // Both RTP and RTCP channels are set, we can call SetInterface on |
225 // media channel and it can set network options. | 238 // media channel and it can set network options. |
226 media_channel_->SetInterface(this); | 239 media_channel_->SetInterface(this); |
227 return true; | 240 return true; |
228 } | 241 } |
229 | 242 |
230 void BaseChannel::Deinit() { | 243 void BaseChannel::Deinit() { |
231 media_channel_->SetInterface(NULL); | 244 media_channel_->SetInterface(NULL); |
232 } | 245 } |
233 | 246 |
234 bool BaseChannel::SetTransportChannels(BaseSession* session, bool rtcp) { | 247 bool BaseChannel::SetTransport(const std::string& transport_name) { |
235 return worker_thread_->Invoke<bool>(Bind( | 248 return worker_thread_->Invoke<bool>( |
236 &BaseChannel::SetTransportChannels_w, this, session, rtcp)); | 249 Bind(&BaseChannel::SetTransport_w, this, transport_name)); |
237 } | 250 } |
238 | 251 |
239 bool BaseChannel::SetTransportChannels_w(BaseSession* session, bool rtcp) { | 252 bool BaseChannel::SetTransport_w(const std::string& transport_name) { |
240 ASSERT(worker_thread_ == rtc::Thread::Current()); | 253 ASSERT(worker_thread_ == rtc::Thread::Current()); |
241 | 254 |
242 set_transport_channel(session->CreateChannel( | 255 if (transport_name == transport_name_) { |
243 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 256 // Nothing to do if transport name isn't changing |
| 257 return true; |
| 258 } |
| 259 |
| 260 set_transport_channel(transport_controller_->CreateTransportChannel_w( |
| 261 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
244 if (!transport_channel()) { | 262 if (!transport_channel()) { |
245 return false; | 263 return false; |
246 } | 264 } |
247 if (rtcp) { | 265 if (rtcp_transport_enabled()) { |
248 set_rtcp_transport_channel(session->CreateChannel( | 266 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() |
249 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP)); | 267 << " on " << transport_name << " transport "; |
| 268 set_rtcp_transport_channel(transport_controller_->CreateTransportChannel_w( |
| 269 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP)); |
250 if (!rtcp_transport_channel()) { | 270 if (!rtcp_transport_channel()) { |
251 return false; | 271 return false; |
252 } | 272 } |
253 } else { | |
254 set_rtcp_transport_channel(nullptr); | |
255 } | 273 } |
256 | 274 |
| 275 transport_name_ = transport_name; |
257 return true; | 276 return true; |
258 } | 277 } |
259 | 278 |
260 void BaseChannel::set_transport_channel(TransportChannel* new_tc) { | 279 void BaseChannel::set_transport_channel(TransportChannel* new_tc) { |
261 ASSERT(worker_thread_ == rtc::Thread::Current()); | 280 ASSERT(worker_thread_ == rtc::Thread::Current()); |
262 | 281 |
263 TransportChannel* old_tc = transport_channel_; | 282 TransportChannel* old_tc = transport_channel_; |
264 | 283 if (!old_tc && !new_tc) { |
265 if (old_tc == new_tc) { | 284 // Nothing to do |
266 return; | 285 return; |
267 } | 286 } |
| 287 ASSERT(old_tc != new_tc); |
| 288 |
268 if (old_tc) { | 289 if (old_tc) { |
269 DisconnectFromTransportChannel(old_tc); | 290 DisconnectFromTransportChannel(old_tc); |
270 session()->DestroyChannel( | 291 transport_controller_->DestroyTransportChannel_w( |
271 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP); | 292 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
272 } | 293 } |
273 | 294 |
274 transport_channel_ = new_tc; | 295 transport_channel_ = new_tc; |
275 | 296 |
276 if (new_tc) { | 297 if (new_tc) { |
277 ConnectToTransportChannel(new_tc); | 298 ConnectToTransportChannel(new_tc); |
| 299 for (const auto& pair : socket_options_) { |
| 300 new_tc->SetOption(pair.first, pair.second); |
| 301 } |
278 } | 302 } |
| 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()); |
279 } | 308 } |
280 | 309 |
281 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc) { | 310 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc) { |
282 ASSERT(worker_thread_ == rtc::Thread::Current()); | 311 ASSERT(worker_thread_ == rtc::Thread::Current()); |
283 | 312 |
284 TransportChannel* old_tc = rtcp_transport_channel_; | 313 TransportChannel* old_tc = rtcp_transport_channel_; |
285 | 314 if (!old_tc && !new_tc) { |
286 if (old_tc == new_tc) { | 315 // Nothing to do |
287 return; | 316 return; |
288 } | 317 } |
| 318 ASSERT(old_tc != new_tc); |
| 319 |
289 if (old_tc) { | 320 if (old_tc) { |
290 DisconnectFromTransportChannel(old_tc); | 321 DisconnectFromTransportChannel(old_tc); |
291 session()->DestroyChannel( | 322 transport_controller_->DestroyTransportChannel_w( |
292 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 323 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
293 } | 324 } |
294 | 325 |
295 rtcp_transport_channel_ = new_tc; | 326 rtcp_transport_channel_ = new_tc; |
296 | 327 |
297 if (new_tc) { | 328 if (new_tc) { |
298 ConnectToTransportChannel(new_tc); | 329 ConnectToTransportChannel(new_tc); |
| 330 for (const auto& pair : rtcp_socket_options_) { |
| 331 new_tc->SetOption(pair.first, pair.second); |
| 332 } |
299 } | 333 } |
| 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()); |
300 } | 339 } |
301 | 340 |
302 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { | 341 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { |
303 ASSERT(worker_thread_ == rtc::Thread::Current()); | 342 ASSERT(worker_thread_ == rtc::Thread::Current()); |
304 | 343 |
305 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 344 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
306 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); | 345 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); |
307 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | 346 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |
308 } | 347 } |
309 | 348 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 rtc::DiffServCodePoint dscp) { | 447 rtc::DiffServCodePoint dscp) { |
409 return SendPacket(true, packet, dscp); | 448 return SendPacket(true, packet, dscp); |
410 } | 449 } |
411 | 450 |
412 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, | 451 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, |
413 int value) { | 452 int value) { |
414 TransportChannel* channel = NULL; | 453 TransportChannel* channel = NULL; |
415 switch (type) { | 454 switch (type) { |
416 case ST_RTP: | 455 case ST_RTP: |
417 channel = transport_channel_; | 456 channel = transport_channel_; |
| 457 socket_options_.push_back( |
| 458 std::pair<rtc::Socket::Option, int>(opt, value)); |
418 break; | 459 break; |
419 case ST_RTCP: | 460 case ST_RTCP: |
420 channel = rtcp_transport_channel_; | 461 channel = rtcp_transport_channel_; |
| 462 rtcp_socket_options_.push_back( |
| 463 std::pair<rtc::Socket::Option, int>(opt, value)); |
421 break; | 464 break; |
422 } | 465 } |
423 return channel ? channel->SetOption(opt, value) : -1; | 466 return channel ? channel->SetOption(opt, value) : -1; |
424 } | 467 } |
425 | 468 |
426 void BaseChannel::OnWritableState(TransportChannel* channel) { | 469 void BaseChannel::OnWritableState(TransportChannel* channel) { |
427 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 470 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
428 if (transport_channel_->writable() | 471 UpdateWritableState_w(); |
429 && (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { | |
430 ChannelWritable_w(); | |
431 } else { | |
432 ChannelNotWritable_w(); | |
433 } | |
434 } | 472 } |
435 | 473 |
436 void BaseChannel::OnChannelRead(TransportChannel* channel, | 474 void BaseChannel::OnChannelRead(TransportChannel* channel, |
437 const char* data, size_t len, | 475 const char* data, size_t len, |
438 const rtc::PacketTime& packet_time, | 476 const rtc::PacketTime& packet_time, |
439 int flags) { | 477 int flags) { |
440 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine | 478 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine |
441 ASSERT(worker_thread_ == rtc::Thread::Current()); | 479 ASSERT(worker_thread_ == rtc::Thread::Current()); |
442 | 480 |
443 // When using RTCP multiplexing we might get RTCP packets on the RTP | 481 // When using RTCP multiplexing we might get RTCP packets on the RTP |
444 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. | 482 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. |
445 bool rtcp = PacketIsRtcp(channel, data, len); | 483 bool rtcp = PacketIsRtcp(channel, data, len); |
446 rtc::Buffer packet(data, len); | 484 rtc::Buffer packet(data, len); |
447 HandlePacket(rtcp, &packet, packet_time); | 485 HandlePacket(rtcp, &packet, packet_time); |
448 } | 486 } |
449 | 487 |
450 void BaseChannel::OnReadyToSend(TransportChannel* channel) { | 488 void BaseChannel::OnReadyToSend(TransportChannel* channel) { |
451 SetReadyToSend(channel, true); | 489 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
| 490 SetReadyToSend(channel == rtcp_transport_channel_, true); |
452 } | 491 } |
453 | 492 |
454 void BaseChannel::SetReadyToSend(TransportChannel* channel, bool ready) { | 493 void BaseChannel::SetReadyToSend(bool rtcp, bool ready) { |
455 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 494 if (rtcp) { |
456 if (channel == transport_channel_) { | 495 rtcp_ready_to_send_ = ready; |
| 496 } else { |
457 rtp_ready_to_send_ = ready; | 497 rtp_ready_to_send_ = ready; |
458 } | 498 } |
459 if (channel == rtcp_transport_channel_) { | |
460 rtcp_ready_to_send_ = ready; | |
461 } | |
462 | 499 |
463 if (!ready) { | 500 if (rtp_ready_to_send_ && |
| 501 // In the case of rtcp mux |rtcp_transport_channel_| will be null. |
| 502 (rtcp_ready_to_send_ || !rtcp_transport_channel_)) { |
| 503 // Notify the MediaChannel when both rtp and rtcp channel can send. |
| 504 media_channel_->OnReadyToSend(true); |
| 505 } else { |
464 // Notify the MediaChannel when either rtp or rtcp channel can't send. | 506 // Notify the MediaChannel when either rtp or rtcp channel can't send. |
465 media_channel_->OnReadyToSend(false); | 507 media_channel_->OnReadyToSend(false); |
466 } else if (rtp_ready_to_send_ && | |
467 // In the case of rtcp mux |rtcp_transport_channel_| will be null. | |
468 (rtcp_ready_to_send_ || !rtcp_transport_channel_)) { | |
469 // Notify the MediaChannel when both rtp and rtcp channel can send. | |
470 media_channel_->OnReadyToSend(true); | |
471 } | 508 } |
472 } | 509 } |
473 | 510 |
474 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, | 511 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, |
475 const char* data, size_t len) { | 512 const char* data, size_t len) { |
476 return (channel == rtcp_transport_channel_ || | 513 return (channel == rtcp_transport_channel_ || |
477 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); | 514 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); |
478 } | 515 } |
479 | 516 |
480 bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet, | 517 bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 return false; | 619 return false; |
583 } | 620 } |
584 | 621 |
585 // Bon voyage. | 622 // Bon voyage. |
586 int ret = | 623 int ret = |
587 channel->SendPacket(packet->data<char>(), packet->size(), options, | 624 channel->SendPacket(packet->data<char>(), packet->size(), options, |
588 (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0); | 625 (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0); |
589 if (ret != static_cast<int>(packet->size())) { | 626 if (ret != static_cast<int>(packet->size())) { |
590 if (channel->GetError() == EWOULDBLOCK) { | 627 if (channel->GetError() == EWOULDBLOCK) { |
591 LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; | 628 LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; |
592 SetReadyToSend(channel, false); | 629 SetReadyToSend(rtcp, false); |
593 } | 630 } |
594 return false; | 631 return false; |
595 } | 632 } |
596 return true; | 633 return true; |
597 } | 634 } |
598 | 635 |
599 bool BaseChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) { | 636 bool BaseChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) { |
600 // Protect ourselves against crazy data. | 637 // Protect ourselves against crazy data. |
601 if (!ValidPacket(rtcp, packet)) { | 638 if (!ValidPacket(rtcp, packet)) { |
602 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " | 639 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 muted_streams_.erase(ssrc); | 770 muted_streams_.erase(ssrc); |
734 } | 771 } |
735 return ret; | 772 return ret; |
736 } | 773 } |
737 | 774 |
738 bool BaseChannel::IsStreamMuted_w(uint32 ssrc) { | 775 bool BaseChannel::IsStreamMuted_w(uint32 ssrc) { |
739 ASSERT(worker_thread_ == rtc::Thread::Current()); | 776 ASSERT(worker_thread_ == rtc::Thread::Current()); |
740 return muted_streams_.find(ssrc) != muted_streams_.end(); | 777 return muted_streams_.find(ssrc) != muted_streams_.end(); |
741 } | 778 } |
742 | 779 |
| 780 void BaseChannel::UpdateWritableState_w() { |
| 781 if (transport_channel_ && transport_channel_->writable() && |
| 782 (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { |
| 783 ChannelWritable_w(); |
| 784 } else { |
| 785 ChannelNotWritable_w(); |
| 786 } |
| 787 } |
| 788 |
743 void BaseChannel::ChannelWritable_w() { | 789 void BaseChannel::ChannelWritable_w() { |
744 ASSERT(worker_thread_ == rtc::Thread::Current()); | 790 ASSERT(worker_thread_ == rtc::Thread::Current()); |
745 if (writable_) | 791 if (writable_) |
746 return; | 792 return; |
747 | 793 |
748 LOG(LS_INFO) << "Channel socket writable (" | 794 LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" |
749 << transport_channel_->content_name() << ", " | |
750 << transport_channel_->component() << ")" | |
751 << (was_ever_writable_ ? "" : " for the first time"); | 795 << (was_ever_writable_ ? "" : " for the first time"); |
752 | 796 |
753 std::vector<ConnectionInfo> infos; | 797 std::vector<ConnectionInfo> infos; |
754 transport_channel_->GetStats(&infos); | 798 transport_channel_->GetStats(&infos); |
755 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); | 799 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); |
756 it != infos.end(); ++it) { | 800 it != infos.end(); ++it) { |
757 if (it->best_connection) { | 801 if (it->best_connection) { |
758 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() | 802 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() |
759 << "->" << it->remote_candidate.ToSensitiveString(); | 803 << "->" << it->remote_candidate.ToSensitiveString(); |
760 break; | 804 break; |
761 } | 805 } |
762 } | 806 } |
763 | 807 |
764 // If we're doing DTLS-SRTP, now is the time. | 808 // If we're doing DTLS-SRTP, now is the time. |
765 if (!was_ever_writable_ && ShouldSetupDtlsSrtp()) { | 809 if (!was_ever_writable_ && ShouldSetupDtlsSrtp()) { |
766 if (!SetupDtlsSrtp(false)) { | 810 if (!SetupDtlsSrtp(false)) { |
767 SignalDtlsSetupFailure(this, false); | 811 SignalDtlsSetupFailure_w(false); |
768 return; | 812 return; |
769 } | 813 } |
770 | 814 |
771 if (rtcp_transport_channel_) { | 815 if (rtcp_transport_channel_) { |
772 if (!SetupDtlsSrtp(true)) { | 816 if (!SetupDtlsSrtp(true)) { |
773 SignalDtlsSetupFailure(this, true); | 817 SignalDtlsSetupFailure_w(true); |
774 return; | 818 return; |
775 } | 819 } |
776 } | 820 } |
777 } | 821 } |
778 | 822 |
779 was_ever_writable_ = true; | 823 was_ever_writable_ = true; |
780 writable_ = true; | 824 writable_ = true; |
781 ChangeState(); | 825 ChangeState(); |
782 } | 826 } |
783 | 827 |
(...skipping 22 matching lines...) Expand all Loading... |
806 | 850 |
807 bool BaseChannel::ShouldSetupDtlsSrtp() const { | 851 bool BaseChannel::ShouldSetupDtlsSrtp() const { |
808 return true; | 852 return true; |
809 } | 853 } |
810 | 854 |
811 // This function returns true if either DTLS-SRTP is not in use | 855 // This function returns true if either DTLS-SRTP is not in use |
812 // *or* DTLS-SRTP is successfully set up. | 856 // *or* DTLS-SRTP is successfully set up. |
813 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { | 857 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { |
814 bool ret = false; | 858 bool ret = false; |
815 | 859 |
816 TransportChannel *channel = rtcp_channel ? | 860 TransportChannel* channel = |
817 rtcp_transport_channel_ : transport_channel_; | 861 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; |
818 | 862 |
819 // No DTLS | 863 // No DTLS |
820 if (!channel->IsDtlsActive()) | 864 if (!channel->IsDtlsActive()) |
821 return true; | 865 return true; |
822 | 866 |
823 std::string selected_cipher; | 867 std::string selected_cipher; |
824 | 868 |
825 if (!channel->GetSrtpCipher(&selected_cipher)) { | 869 if (!channel->GetSrtpCipher(&selected_cipher)) { |
826 LOG(LS_ERROR) << "No DTLS-SRTP selected cipher"; | 870 LOG(LS_ERROR) << "No DTLS-SRTP selected cipher"; |
827 return false; | 871 return false; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 dtls_keyed_ = true; | 946 dtls_keyed_ = true; |
903 | 947 |
904 return ret; | 948 return ret; |
905 } | 949 } |
906 | 950 |
907 void BaseChannel::ChannelNotWritable_w() { | 951 void BaseChannel::ChannelNotWritable_w() { |
908 ASSERT(worker_thread_ == rtc::Thread::Current()); | 952 ASSERT(worker_thread_ == rtc::Thread::Current()); |
909 if (!writable_) | 953 if (!writable_) |
910 return; | 954 return; |
911 | 955 |
912 LOG(LS_INFO) << "Channel socket not writable (" | 956 LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; |
913 << transport_channel_->content_name() << ", " | |
914 << transport_channel_->component() << ")"; | |
915 writable_ = false; | 957 writable_ = false; |
916 ChangeState(); | 958 ChangeState(); |
917 } | 959 } |
918 | 960 |
919 bool BaseChannel::SetRtpTransportParameters_w( | 961 bool BaseChannel::SetRtpTransportParameters_w( |
920 const MediaContentDescription* content, | 962 const MediaContentDescription* content, |
921 ContentAction action, | 963 ContentAction action, |
922 ContentSource src, | 964 ContentSource src, |
923 std::string* error_desc) { | 965 std::string* error_desc) { |
924 if (action == CA_UPDATE) { | 966 if (action == CA_UPDATE) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 } | 1045 } |
1004 | 1046 |
1005 void BaseChannel::ActivateRtcpMux() { | 1047 void BaseChannel::ActivateRtcpMux() { |
1006 worker_thread_->Invoke<void>(Bind( | 1048 worker_thread_->Invoke<void>(Bind( |
1007 &BaseChannel::ActivateRtcpMux_w, this)); | 1049 &BaseChannel::ActivateRtcpMux_w, this)); |
1008 } | 1050 } |
1009 | 1051 |
1010 void BaseChannel::ActivateRtcpMux_w() { | 1052 void BaseChannel::ActivateRtcpMux_w() { |
1011 if (!rtcp_mux_filter_.IsActive()) { | 1053 if (!rtcp_mux_filter_.IsActive()) { |
1012 rtcp_mux_filter_.SetActive(); | 1054 rtcp_mux_filter_.SetActive(); |
1013 set_rtcp_transport_channel(NULL); | 1055 set_rtcp_transport_channel(nullptr); |
| 1056 rtcp_transport_enabled_ = false; |
1014 } | 1057 } |
1015 } | 1058 } |
1016 | 1059 |
1017 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action, | 1060 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action, |
1018 ContentSource src, | 1061 ContentSource src, |
1019 std::string* error_desc) { | 1062 std::string* error_desc) { |
1020 bool ret = false; | 1063 bool ret = false; |
1021 switch (action) { | 1064 switch (action) { |
1022 case CA_OFFER: | 1065 case CA_OFFER: |
1023 ret = rtcp_mux_filter_.SetOffer(enable, src); | 1066 ret = rtcp_mux_filter_.SetOffer(enable, src); |
1024 break; | 1067 break; |
1025 case CA_PRANSWER: | 1068 case CA_PRANSWER: |
1026 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); | 1069 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); |
1027 break; | 1070 break; |
1028 case CA_ANSWER: | 1071 case CA_ANSWER: |
1029 ret = rtcp_mux_filter_.SetAnswer(enable, src); | 1072 ret = rtcp_mux_filter_.SetAnswer(enable, src); |
1030 if (ret && rtcp_mux_filter_.IsActive()) { | 1073 if (ret && rtcp_mux_filter_.IsActive()) { |
1031 // We activated RTCP mux, close down the RTCP transport. | 1074 // We activated RTCP mux, close down the RTCP transport. |
1032 set_rtcp_transport_channel(NULL); | 1075 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() |
| 1076 << " by destroying RTCP transport channel for " |
| 1077 << transport_name(); |
| 1078 set_rtcp_transport_channel(nullptr); |
| 1079 rtcp_transport_enabled_ = false; |
1033 } | 1080 } |
1034 break; | 1081 break; |
1035 case CA_UPDATE: | 1082 case CA_UPDATE: |
1036 // No RTCP mux info. | 1083 // No RTCP mux info. |
1037 ret = true; | 1084 ret = true; |
1038 break; | 1085 break; |
1039 default: | 1086 default: |
1040 break; | 1087 break; |
1041 } | 1088 } |
1042 if (!ret) { | 1089 if (!ret) { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages); | 1296 worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages); |
1250 for (rtc::MessageList::iterator it = rtcp_messages.begin(); | 1297 for (rtc::MessageList::iterator it = rtcp_messages.begin(); |
1251 it != rtcp_messages.end(); ++it) { | 1298 it != rtcp_messages.end(); ++it) { |
1252 worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata); | 1299 worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata); |
1253 } | 1300 } |
1254 } | 1301 } |
1255 | 1302 |
1256 VoiceChannel::VoiceChannel(rtc::Thread* thread, | 1303 VoiceChannel::VoiceChannel(rtc::Thread* thread, |
1257 MediaEngineInterface* media_engine, | 1304 MediaEngineInterface* media_engine, |
1258 VoiceMediaChannel* media_channel, | 1305 VoiceMediaChannel* media_channel, |
1259 BaseSession* session, | 1306 TransportController* transport_controller, |
1260 const std::string& content_name, | 1307 const std::string& content_name, |
1261 bool rtcp) | 1308 bool rtcp) |
1262 : BaseChannel(thread, media_channel, session, content_name, | 1309 : BaseChannel(thread, |
| 1310 media_channel, |
| 1311 transport_controller, |
| 1312 content_name, |
1263 rtcp), | 1313 rtcp), |
1264 media_engine_(media_engine), | 1314 media_engine_(media_engine), |
1265 received_media_(false) { | 1315 received_media_(false) { |
1266 } | 1316 } |
1267 | 1317 |
1268 VoiceChannel::~VoiceChannel() { | 1318 VoiceChannel::~VoiceChannel() { |
1269 StopAudioMonitor(); | 1319 StopAudioMonitor(); |
1270 StopMediaMonitor(); | 1320 StopMediaMonitor(); |
1271 // this can't be done in the base class, since it calls a virtual | 1321 // this can't be done in the base class, since it calls a virtual |
1272 DisableMedia_w(); | 1322 DisableMedia_w(); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1628 break; | 1678 break; |
1629 } | 1679 } |
1630 } | 1680 } |
1631 | 1681 |
1632 void VoiceChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const { | 1682 void VoiceChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const { |
1633 GetSupportedAudioCryptoSuites(ciphers); | 1683 GetSupportedAudioCryptoSuites(ciphers); |
1634 } | 1684 } |
1635 | 1685 |
1636 VideoChannel::VideoChannel(rtc::Thread* thread, | 1686 VideoChannel::VideoChannel(rtc::Thread* thread, |
1637 VideoMediaChannel* media_channel, | 1687 VideoMediaChannel* media_channel, |
1638 BaseSession* session, | 1688 TransportController* transport_controller, |
1639 const std::string& content_name, | 1689 const std::string& content_name, |
1640 bool rtcp) | 1690 bool rtcp) |
1641 : BaseChannel(thread, media_channel, session, content_name, | 1691 : BaseChannel(thread, |
| 1692 media_channel, |
| 1693 transport_controller, |
| 1694 content_name, |
1642 rtcp), | 1695 rtcp), |
1643 renderer_(NULL), | 1696 renderer_(NULL), |
1644 previous_we_(rtc::WE_CLOSE) { | 1697 previous_we_(rtc::WE_CLOSE) { |
1645 } | 1698 } |
1646 | 1699 |
1647 bool VideoChannel::Init() { | 1700 bool VideoChannel::Init() { |
1648 if (!BaseChannel::Init()) { | 1701 if (!BaseChannel::Init()) { |
1649 return false; | 1702 return false; |
1650 } | 1703 } |
1651 media_channel()->SignalMediaError.connect( | 1704 media_channel()->SignalMediaError.connect( |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2066 } | 2119 } |
2067 } | 2120 } |
2068 | 2121 |
2069 | 2122 |
2070 void VideoChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const { | 2123 void VideoChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const { |
2071 GetSupportedVideoCryptoSuites(ciphers); | 2124 GetSupportedVideoCryptoSuites(ciphers); |
2072 } | 2125 } |
2073 | 2126 |
2074 DataChannel::DataChannel(rtc::Thread* thread, | 2127 DataChannel::DataChannel(rtc::Thread* thread, |
2075 DataMediaChannel* media_channel, | 2128 DataMediaChannel* media_channel, |
2076 BaseSession* session, | 2129 TransportController* transport_controller, |
2077 const std::string& content_name, | 2130 const std::string& content_name, |
2078 bool rtcp) | 2131 bool rtcp) |
2079 : BaseChannel(thread, media_channel, session, content_name, rtcp), | 2132 : BaseChannel(thread, |
| 2133 media_channel, |
| 2134 transport_controller, |
| 2135 content_name, |
| 2136 rtcp), |
2080 data_channel_type_(cricket::DCT_NONE), | 2137 data_channel_type_(cricket::DCT_NONE), |
2081 ready_to_send_data_(false) { | 2138 ready_to_send_data_(false) { |
2082 } | 2139 } |
2083 | 2140 |
2084 DataChannel::~DataChannel() { | 2141 DataChannel::~DataChannel() { |
2085 StopMediaMonitor(); | 2142 StopMediaMonitor(); |
2086 // this can't be done in the base class, since it calls a virtual | 2143 // this can't be done in the base class, since it calls a virtual |
2087 DisableMedia_w(); | 2144 DisableMedia_w(); |
2088 | 2145 |
2089 Deinit(); | 2146 Deinit(); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2407 return (data_channel_type_ == DCT_RTP); | 2464 return (data_channel_type_ == DCT_RTP); |
2408 } | 2465 } |
2409 | 2466 |
2410 void DataChannel::OnStreamClosedRemotely(uint32 sid) { | 2467 void DataChannel::OnStreamClosedRemotely(uint32 sid) { |
2411 rtc::TypedMessageData<uint32>* message = | 2468 rtc::TypedMessageData<uint32>* message = |
2412 new rtc::TypedMessageData<uint32>(sid); | 2469 new rtc::TypedMessageData<uint32>(sid); |
2413 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2470 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
2414 } | 2471 } |
2415 | 2472 |
2416 } // namespace cricket | 2473 } // namespace cricket |
OLD | NEW |