Chromium Code Reviews| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 (!SetTransportChannels(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 if (!SetTransportChannels(transport_name)) { |
| 237 &BaseChannel::SetTransportChannels_w, this, session, rtcp)); | 250 return false; |
| 251 } | |
| 252 return true; | |
| 238 } | 253 } |
| 239 | 254 |
| 240 bool BaseChannel::SetTransportChannels_w(BaseSession* session, bool rtcp) { | 255 bool BaseChannel::SetTransportChannels(const std::string& transport_name) { |
| 256 return worker_thread_->Invoke<bool>( | |
| 257 Bind(&BaseChannel::SetTransportChannels_w, this, transport_name)); | |
| 258 } | |
| 259 | |
| 260 bool BaseChannel::SetTransportChannels_w(const std::string& transport_name) { | |
|
pthatcher1
2015/08/31 22:01:35
Maybe we should just call this SetTransport_w, and
Taylor Brandstetter
2015/09/01 23:53:30
Done.
| |
| 241 ASSERT(worker_thread_ == rtc::Thread::Current()); | 261 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 242 | 262 |
| 243 set_transport_channel(session->CreateChannel( | 263 if (transport_name == transport_name_) { |
| 244 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 264 // Nothing to do if transport name isn't changing |
| 265 return true; | |
| 266 } | |
| 267 | |
| 268 set_transport_channel(transport_controller_->CreateTransportChannel_w( | |
| 269 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP)); | |
| 245 if (!transport_channel()) { | 270 if (!transport_channel()) { |
| 246 return false; | 271 return false; |
| 247 } | 272 } |
| 248 if (rtcp) { | 273 if (rtcp_transport_enabled()) { |
| 249 set_rtcp_transport_channel(session->CreateChannel( | 274 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() |
| 250 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP)); | 275 << " on " << transport_name << " transport "; |
| 276 set_rtcp_transport_channel(transport_controller_->CreateTransportChannel_w( | |
| 277 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP)); | |
| 251 if (!rtcp_transport_channel()) { | 278 if (!rtcp_transport_channel()) { |
| 252 return false; | 279 return false; |
| 253 } | 280 } |
| 254 } else { | |
| 255 set_rtcp_transport_channel(nullptr); | |
| 256 } | 281 } |
| 257 | 282 |
| 283 transport_name_ = transport_name; | |
| 258 return true; | 284 return true; |
| 259 } | 285 } |
| 260 | 286 |
| 261 void BaseChannel::set_transport_channel(TransportChannel* new_tc) { | 287 void BaseChannel::set_transport_channel(TransportChannel* new_tc) { |
| 262 ASSERT(worker_thread_ == rtc::Thread::Current()); | 288 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 263 | 289 |
| 264 TransportChannel* old_tc = transport_channel_; | 290 TransportChannel* old_tc = transport_channel_; |
| 265 | |
| 266 if (old_tc == new_tc) { | |
| 267 return; | |
| 268 } | |
|
pthatcher1
2015/08/31 22:01:35
Sorry, can you remind me again why we don't return
Taylor Brandstetter
2015/09/01 23:53:30
It should now be impossible for "set_transport_cha
| |
| 269 if (old_tc) { | 291 if (old_tc) { |
| 270 DisconnectFromTransportChannel(old_tc); | 292 DisconnectFromTransportChannel(old_tc); |
| 271 session()->DestroyChannel( | 293 transport_controller_->DestroyTransportChannel_w( |
| 272 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP); | 294 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 273 } | 295 } |
| 274 | 296 |
| 275 transport_channel_ = new_tc; | 297 transport_channel_ = new_tc; |
| 276 | 298 |
| 277 if (new_tc) { | 299 if (new_tc) { |
| 278 ConnectToTransportChannel(new_tc); | 300 ConnectToTransportChannel(new_tc); |
| 301 for (const auto& pair : socket_options_) { | |
| 302 new_tc->SetOption(pair.first, pair.second); | |
| 303 } | |
| 279 } | 304 } |
| 305 | |
| 306 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | |
| 307 // setting new channel | |
| 308 UpdateWritableState_w(); | |
| 309 SetReadyToSend(false, new_tc && new_tc->writable()); | |
| 280 } | 310 } |
| 281 | 311 |
| 282 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc) { | 312 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc) { |
| 283 ASSERT(worker_thread_ == rtc::Thread::Current()); | 313 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 284 | 314 |
| 285 TransportChannel* old_tc = rtcp_transport_channel_; | 315 TransportChannel* old_tc = rtcp_transport_channel_; |
| 286 | |
| 287 if (old_tc == new_tc) { | |
| 288 return; | |
| 289 } | |
| 290 if (old_tc) { | 316 if (old_tc) { |
| 291 DisconnectFromTransportChannel(old_tc); | 317 DisconnectFromTransportChannel(old_tc); |
| 292 session()->DestroyChannel( | 318 transport_controller_->DestroyTransportChannel_w( |
| 293 content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 319 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
| 294 } | 320 } |
| 295 | 321 |
| 296 rtcp_transport_channel_ = new_tc; | 322 rtcp_transport_channel_ = new_tc; |
| 297 | 323 |
| 298 if (new_tc) { | 324 if (new_tc) { |
| 299 ConnectToTransportChannel(new_tc); | 325 ConnectToTransportChannel(new_tc); |
| 326 for (const auto& pair : rtcp_socket_options_) { | |
| 327 new_tc->SetOption(pair.first, pair.second); | |
| 328 } | |
| 300 } | 329 } |
| 330 | |
| 331 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | |
| 332 // setting new channel | |
| 333 UpdateWritableState_w(); | |
| 334 SetReadyToSend(true, new_tc && new_tc->writable()); | |
| 301 } | 335 } |
| 302 | 336 |
| 303 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { | 337 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { |
| 304 ASSERT(worker_thread_ == rtc::Thread::Current()); | 338 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 305 | 339 |
| 306 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 340 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
| 307 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); | 341 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); |
| 308 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | 342 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |
| 309 } | 343 } |
| 310 | 344 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 rtc::DiffServCodePoint dscp) { | 443 rtc::DiffServCodePoint dscp) { |
| 410 return SendPacket(true, packet, dscp); | 444 return SendPacket(true, packet, dscp); |
| 411 } | 445 } |
| 412 | 446 |
| 413 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, | 447 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, |
| 414 int value) { | 448 int value) { |
| 415 TransportChannel* channel = NULL; | 449 TransportChannel* channel = NULL; |
| 416 switch (type) { | 450 switch (type) { |
| 417 case ST_RTP: | 451 case ST_RTP: |
| 418 channel = transport_channel_; | 452 channel = transport_channel_; |
| 453 socket_options_.push_back( | |
| 454 std::pair<rtc::Socket::Option, int>(opt, value)); | |
| 419 break; | 455 break; |
| 420 case ST_RTCP: | 456 case ST_RTCP: |
| 421 channel = rtcp_transport_channel_; | 457 channel = rtcp_transport_channel_; |
| 458 rtcp_socket_options_.push_back( | |
| 459 std::pair<rtc::Socket::Option, int>(opt, value)); | |
| 422 break; | 460 break; |
| 423 } | 461 } |
| 424 return channel ? channel->SetOption(opt, value) : -1; | 462 return channel ? channel->SetOption(opt, value) : -1; |
| 425 } | 463 } |
| 426 | 464 |
| 427 void BaseChannel::OnWritableState(TransportChannel* channel) { | 465 void BaseChannel::OnWritableState(TransportChannel* channel) { |
| 428 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 466 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
| 429 if (transport_channel_->writable() | 467 UpdateWritableState_w(); |
| 430 && (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { | |
| 431 ChannelWritable_w(); | |
| 432 } else { | |
| 433 ChannelNotWritable_w(); | |
| 434 } | |
| 435 } | 468 } |
| 436 | 469 |
| 437 void BaseChannel::OnChannelRead(TransportChannel* channel, | 470 void BaseChannel::OnChannelRead(TransportChannel* channel, |
| 438 const char* data, size_t len, | 471 const char* data, size_t len, |
| 439 const rtc::PacketTime& packet_time, | 472 const rtc::PacketTime& packet_time, |
| 440 int flags) { | 473 int flags) { |
| 441 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine | 474 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine |
| 442 ASSERT(worker_thread_ == rtc::Thread::Current()); | 475 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 443 | 476 |
| 444 // When using RTCP multiplexing we might get RTCP packets on the RTP | 477 // 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. | 478 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. |
| 446 bool rtcp = PacketIsRtcp(channel, data, len); | 479 bool rtcp = PacketIsRtcp(channel, data, len); |
| 447 rtc::Buffer packet(data, len); | 480 rtc::Buffer packet(data, len); |
| 448 HandlePacket(rtcp, &packet, packet_time); | 481 HandlePacket(rtcp, &packet, packet_time); |
| 449 } | 482 } |
| 450 | 483 |
| 451 void BaseChannel::OnReadyToSend(TransportChannel* channel) { | 484 void BaseChannel::OnReadyToSend(TransportChannel* channel) { |
| 452 SetReadyToSend(channel, true); | 485 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
| 486 SetReadyToSend(channel == rtcp_transport_channel_, true); | |
| 453 } | 487 } |
| 454 | 488 |
| 455 void BaseChannel::SetReadyToSend(TransportChannel* channel, bool ready) { | 489 void BaseChannel::SetReadyToSend(bool rtcp, bool ready) { |
| 456 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 490 if (rtcp) { |
| 457 if (channel == transport_channel_) { | 491 rtcp_ready_to_send_ = ready; |
| 492 } else { | |
| 458 rtp_ready_to_send_ = ready; | 493 rtp_ready_to_send_ = ready; |
| 459 } | 494 } |
| 460 if (channel == rtcp_transport_channel_) { | |
| 461 rtcp_ready_to_send_ = ready; | |
| 462 } | |
| 463 | 495 |
| 464 if (!ready) { | 496 if (rtp_ready_to_send_ && |
| 497 // In the case of rtcp mux |rtcp_transport_channel_| will be null. | |
| 498 (rtcp_ready_to_send_ || !rtcp_transport_channel_)) { | |
| 499 // Notify the MediaChannel when both rtp and rtcp channel can send. | |
| 500 media_channel_->OnReadyToSend(true); | |
| 501 } else { | |
| 465 // Notify the MediaChannel when either rtp or rtcp channel can't send. | 502 // Notify the MediaChannel when either rtp or rtcp channel can't send. |
| 466 media_channel_->OnReadyToSend(false); | 503 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 } | 504 } |
| 473 } | 505 } |
| 474 | 506 |
| 475 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, | 507 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, |
| 476 const char* data, size_t len) { | 508 const char* data, size_t len) { |
| 477 return (channel == rtcp_transport_channel_ || | 509 return (channel == rtcp_transport_channel_ || |
| 478 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); | 510 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); |
| 479 } | 511 } |
| 480 | 512 |
| 481 bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet, | 513 bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 return false; | 615 return false; |
| 584 } | 616 } |
| 585 | 617 |
| 586 // Bon voyage. | 618 // Bon voyage. |
| 587 int ret = | 619 int ret = |
| 588 channel->SendPacket(packet->data<char>(), packet->size(), options, | 620 channel->SendPacket(packet->data<char>(), packet->size(), options, |
| 589 (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0); | 621 (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0); |
| 590 if (ret != static_cast<int>(packet->size())) { | 622 if (ret != static_cast<int>(packet->size())) { |
| 591 if (channel->GetError() == EWOULDBLOCK) { | 623 if (channel->GetError() == EWOULDBLOCK) { |
| 592 LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; | 624 LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; |
| 593 SetReadyToSend(channel, false); | 625 SetReadyToSend(rtcp, false); |
| 594 } | 626 } |
| 595 return false; | 627 return false; |
| 596 } | 628 } |
| 597 return true; | 629 return true; |
| 598 } | 630 } |
| 599 | 631 |
| 600 bool BaseChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) { | 632 bool BaseChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) { |
| 601 // Protect ourselves against crazy data. | 633 // Protect ourselves against crazy data. |
| 602 if (!ValidPacket(rtcp, packet)) { | 634 if (!ValidPacket(rtcp, packet)) { |
| 603 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " | 635 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 muted_streams_.erase(ssrc); | 766 muted_streams_.erase(ssrc); |
| 735 } | 767 } |
| 736 return ret; | 768 return ret; |
| 737 } | 769 } |
| 738 | 770 |
| 739 bool BaseChannel::IsStreamMuted_w(uint32 ssrc) { | 771 bool BaseChannel::IsStreamMuted_w(uint32 ssrc) { |
| 740 ASSERT(worker_thread_ == rtc::Thread::Current()); | 772 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 741 return muted_streams_.find(ssrc) != muted_streams_.end(); | 773 return muted_streams_.find(ssrc) != muted_streams_.end(); |
| 742 } | 774 } |
| 743 | 775 |
| 776 void BaseChannel::UpdateWritableState_w() { | |
| 777 if (transport_channel_ && transport_channel_->writable() && | |
| 778 (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { | |
| 779 ChannelWritable_w(); | |
| 780 } else { | |
| 781 ChannelNotWritable_w(); | |
| 782 } | |
| 783 } | |
| 784 | |
| 744 void BaseChannel::ChannelWritable_w() { | 785 void BaseChannel::ChannelWritable_w() { |
| 745 ASSERT(worker_thread_ == rtc::Thread::Current()); | 786 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 746 if (writable_) | 787 if (writable_) |
| 747 return; | 788 return; |
| 748 | 789 |
| 749 LOG(LS_INFO) << "Channel socket writable (" | 790 LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" |
| 750 << transport_channel_->content_name() << ", " | |
| 751 << transport_channel_->component() << ")" | |
| 752 << (was_ever_writable_ ? "" : " for the first time"); | 791 << (was_ever_writable_ ? "" : " for the first time"); |
| 753 | 792 |
| 754 std::vector<ConnectionInfo> infos; | 793 std::vector<ConnectionInfo> infos; |
| 755 transport_channel_->GetStats(&infos); | 794 transport_channel_->GetStats(&infos); |
| 756 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); | 795 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); |
| 757 it != infos.end(); ++it) { | 796 it != infos.end(); ++it) { |
| 758 if (it->best_connection) { | 797 if (it->best_connection) { |
| 759 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() | 798 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() |
| 760 << "->" << it->remote_candidate.ToSensitiveString(); | 799 << "->" << it->remote_candidate.ToSensitiveString(); |
| 761 break; | 800 break; |
| 762 } | 801 } |
| 763 } | 802 } |
| 764 | 803 |
| 765 // If we're doing DTLS-SRTP, now is the time. | 804 // If we're doing DTLS-SRTP, now is the time. |
| 766 if (!was_ever_writable_ && ShouldSetupDtlsSrtp()) { | 805 if (!was_ever_writable_ && ShouldSetupDtlsSrtp()) { |
| 767 if (!SetupDtlsSrtp(false)) { | 806 if (!SetupDtlsSrtp(false)) { |
| 768 SignalDtlsSetupFailure(this, false); | 807 SignalDtlsSetupFailure_w(false); |
| 769 return; | 808 return; |
| 770 } | 809 } |
| 771 | 810 |
| 772 if (rtcp_transport_channel_) { | 811 if (rtcp_transport_channel_) { |
| 773 if (!SetupDtlsSrtp(true)) { | 812 if (!SetupDtlsSrtp(true)) { |
| 774 SignalDtlsSetupFailure(this, true); | 813 SignalDtlsSetupFailure_w(true); |
| 775 return; | 814 return; |
| 776 } | 815 } |
| 777 } | 816 } |
| 778 } | 817 } |
| 779 | 818 |
| 780 was_ever_writable_ = true; | 819 was_ever_writable_ = true; |
| 781 writable_ = true; | 820 writable_ = true; |
| 782 ChangeState(); | 821 ChangeState(); |
| 783 } | 822 } |
| 784 | 823 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 807 | 846 |
| 808 bool BaseChannel::ShouldSetupDtlsSrtp() const { | 847 bool BaseChannel::ShouldSetupDtlsSrtp() const { |
| 809 return true; | 848 return true; |
| 810 } | 849 } |
| 811 | 850 |
| 812 // This function returns true if either DTLS-SRTP is not in use | 851 // This function returns true if either DTLS-SRTP is not in use |
| 813 // *or* DTLS-SRTP is successfully set up. | 852 // *or* DTLS-SRTP is successfully set up. |
| 814 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { | 853 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { |
| 815 bool ret = false; | 854 bool ret = false; |
| 816 | 855 |
| 817 TransportChannel *channel = rtcp_channel ? | 856 TransportChannel* channel = |
| 818 rtcp_transport_channel_ : transport_channel_; | 857 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; |
| 819 | 858 |
| 820 // No DTLS | 859 // No DTLS |
| 821 if (!channel->IsDtlsActive()) | 860 if (!channel->IsDtlsActive()) |
| 822 return true; | 861 return true; |
| 823 | 862 |
| 824 std::string selected_cipher; | 863 std::string selected_cipher; |
| 825 | 864 |
| 826 if (!channel->GetSrtpCipher(&selected_cipher)) { | 865 if (!channel->GetSrtpCipher(&selected_cipher)) { |
| 827 LOG(LS_ERROR) << "No DTLS-SRTP selected cipher"; | 866 LOG(LS_ERROR) << "No DTLS-SRTP selected cipher"; |
| 828 return false; | 867 return false; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 903 dtls_keyed_ = true; | 942 dtls_keyed_ = true; |
| 904 | 943 |
| 905 return ret; | 944 return ret; |
| 906 } | 945 } |
| 907 | 946 |
| 908 void BaseChannel::ChannelNotWritable_w() { | 947 void BaseChannel::ChannelNotWritable_w() { |
| 909 ASSERT(worker_thread_ == rtc::Thread::Current()); | 948 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 910 if (!writable_) | 949 if (!writable_) |
| 911 return; | 950 return; |
| 912 | 951 |
| 913 LOG(LS_INFO) << "Channel socket not writable (" | 952 LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; |
| 914 << transport_channel_->content_name() << ", " | |
| 915 << transport_channel_->component() << ")"; | |
| 916 writable_ = false; | 953 writable_ = false; |
| 917 ChangeState(); | 954 ChangeState(); |
| 918 } | 955 } |
| 919 | 956 |
| 920 bool BaseChannel::SetRtpTransportParameters_w( | 957 bool BaseChannel::SetRtpTransportParameters_w( |
| 921 const MediaContentDescription* content, | 958 const MediaContentDescription* content, |
| 922 ContentAction action, | 959 ContentAction action, |
| 923 ContentSource src, | 960 ContentSource src, |
| 924 std::string* error_desc) { | 961 std::string* error_desc) { |
| 925 if (action == CA_UPDATE) { | 962 if (action == CA_UPDATE) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1004 } | 1041 } |
| 1005 | 1042 |
| 1006 void BaseChannel::ActivateRtcpMux() { | 1043 void BaseChannel::ActivateRtcpMux() { |
| 1007 worker_thread_->Invoke<void>(Bind( | 1044 worker_thread_->Invoke<void>(Bind( |
| 1008 &BaseChannel::ActivateRtcpMux_w, this)); | 1045 &BaseChannel::ActivateRtcpMux_w, this)); |
| 1009 } | 1046 } |
| 1010 | 1047 |
| 1011 void BaseChannel::ActivateRtcpMux_w() { | 1048 void BaseChannel::ActivateRtcpMux_w() { |
| 1012 if (!rtcp_mux_filter_.IsActive()) { | 1049 if (!rtcp_mux_filter_.IsActive()) { |
| 1013 rtcp_mux_filter_.SetActive(); | 1050 rtcp_mux_filter_.SetActive(); |
| 1014 set_rtcp_transport_channel(NULL); | 1051 set_rtcp_transport_channel(nullptr); |
| 1052 rtcp_transport_enabled_ = false; | |
| 1015 } | 1053 } |
| 1016 } | 1054 } |
| 1017 | 1055 |
| 1018 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action, | 1056 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action, |
| 1019 ContentSource src, | 1057 ContentSource src, |
| 1020 std::string* error_desc) { | 1058 std::string* error_desc) { |
| 1021 bool ret = false; | 1059 bool ret = false; |
| 1022 switch (action) { | 1060 switch (action) { |
| 1023 case CA_OFFER: | 1061 case CA_OFFER: |
| 1024 ret = rtcp_mux_filter_.SetOffer(enable, src); | 1062 ret = rtcp_mux_filter_.SetOffer(enable, src); |
| 1025 break; | 1063 break; |
| 1026 case CA_PRANSWER: | 1064 case CA_PRANSWER: |
| 1027 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); | 1065 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); |
| 1028 break; | 1066 break; |
| 1029 case CA_ANSWER: | 1067 case CA_ANSWER: |
| 1030 ret = rtcp_mux_filter_.SetAnswer(enable, src); | 1068 ret = rtcp_mux_filter_.SetAnswer(enable, src); |
| 1031 if (ret && rtcp_mux_filter_.IsActive()) { | 1069 if (ret && rtcp_mux_filter_.IsActive()) { |
| 1032 // We activated RTCP mux, close down the RTCP transport. | 1070 // We activated RTCP mux, close down the RTCP transport. |
| 1033 set_rtcp_transport_channel(NULL); | 1071 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() |
| 1072 << " by destroying RTCP transport channel for " | |
| 1073 << transport_name(); | |
| 1074 set_rtcp_transport_channel(nullptr); | |
| 1075 rtcp_transport_enabled_ = false; | |
| 1034 } | 1076 } |
| 1035 break; | 1077 break; |
| 1036 case CA_UPDATE: | 1078 case CA_UPDATE: |
| 1037 // No RTCP mux info. | 1079 // No RTCP mux info. |
| 1038 ret = true; | 1080 ret = true; |
| 1039 break; | 1081 break; |
| 1040 default: | 1082 default: |
| 1041 break; | 1083 break; |
| 1042 } | 1084 } |
| 1043 if (!ret) { | 1085 if (!ret) { |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1250 worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages); | 1292 worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages); |
| 1251 for (rtc::MessageList::iterator it = rtcp_messages.begin(); | 1293 for (rtc::MessageList::iterator it = rtcp_messages.begin(); |
| 1252 it != rtcp_messages.end(); ++it) { | 1294 it != rtcp_messages.end(); ++it) { |
| 1253 worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata); | 1295 worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata); |
| 1254 } | 1296 } |
| 1255 } | 1297 } |
| 1256 | 1298 |
| 1257 VoiceChannel::VoiceChannel(rtc::Thread* thread, | 1299 VoiceChannel::VoiceChannel(rtc::Thread* thread, |
| 1258 MediaEngineInterface* media_engine, | 1300 MediaEngineInterface* media_engine, |
| 1259 VoiceMediaChannel* media_channel, | 1301 VoiceMediaChannel* media_channel, |
| 1260 BaseSession* session, | 1302 TransportController* transport_controller, |
| 1261 const std::string& content_name, | 1303 const std::string& content_name, |
| 1262 bool rtcp) | 1304 bool rtcp) |
| 1263 : BaseChannel(thread, media_channel, session, content_name, | 1305 : BaseChannel(thread, |
| 1306 media_channel, | |
| 1307 transport_controller, | |
| 1308 content_name, | |
| 1264 rtcp), | 1309 rtcp), |
| 1265 media_engine_(media_engine), | 1310 media_engine_(media_engine), |
| 1266 received_media_(false) { | 1311 received_media_(false) { |
| 1267 } | 1312 } |
| 1268 | 1313 |
| 1269 VoiceChannel::~VoiceChannel() { | 1314 VoiceChannel::~VoiceChannel() { |
| 1270 StopAudioMonitor(); | 1315 StopAudioMonitor(); |
| 1271 StopMediaMonitor(); | 1316 StopMediaMonitor(); |
| 1272 // this can't be done in the base class, since it calls a virtual | 1317 // this can't be done in the base class, since it calls a virtual |
| 1273 DisableMedia_w(); | 1318 DisableMedia_w(); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1649 break; | 1694 break; |
| 1650 } | 1695 } |
| 1651 } | 1696 } |
| 1652 | 1697 |
| 1653 void VoiceChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const { | 1698 void VoiceChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const { |
| 1654 GetSupportedAudioCryptoSuites(ciphers); | 1699 GetSupportedAudioCryptoSuites(ciphers); |
| 1655 } | 1700 } |
| 1656 | 1701 |
| 1657 VideoChannel::VideoChannel(rtc::Thread* thread, | 1702 VideoChannel::VideoChannel(rtc::Thread* thread, |
| 1658 VideoMediaChannel* media_channel, | 1703 VideoMediaChannel* media_channel, |
| 1659 BaseSession* session, | 1704 TransportController* transport_controller, |
| 1660 const std::string& content_name, | 1705 const std::string& content_name, |
| 1661 bool rtcp) | 1706 bool rtcp) |
| 1662 : BaseChannel(thread, media_channel, session, content_name, | 1707 : BaseChannel(thread, |
| 1708 media_channel, | |
| 1709 transport_controller, | |
| 1710 content_name, | |
| 1663 rtcp), | 1711 rtcp), |
| 1664 renderer_(NULL), | 1712 renderer_(NULL), |
| 1665 previous_we_(rtc::WE_CLOSE) { | 1713 previous_we_(rtc::WE_CLOSE) { |
| 1666 } | 1714 } |
| 1667 | 1715 |
| 1668 bool VideoChannel::Init() { | 1716 bool VideoChannel::Init() { |
| 1669 if (!BaseChannel::Init()) { | 1717 if (!BaseChannel::Init()) { |
| 1670 return false; | 1718 return false; |
| 1671 } | 1719 } |
| 1672 media_channel()->SignalMediaError.connect( | 1720 media_channel()->SignalMediaError.connect( |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2087 } | 2135 } |
| 2088 } | 2136 } |
| 2089 | 2137 |
| 2090 | 2138 |
| 2091 void VideoChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const { | 2139 void VideoChannel::GetSrtpCiphers(std::vector<std::string>* ciphers) const { |
| 2092 GetSupportedVideoCryptoSuites(ciphers); | 2140 GetSupportedVideoCryptoSuites(ciphers); |
| 2093 } | 2141 } |
| 2094 | 2142 |
| 2095 DataChannel::DataChannel(rtc::Thread* thread, | 2143 DataChannel::DataChannel(rtc::Thread* thread, |
| 2096 DataMediaChannel* media_channel, | 2144 DataMediaChannel* media_channel, |
| 2097 BaseSession* session, | 2145 TransportController* transport_controller, |
| 2098 const std::string& content_name, | 2146 const std::string& content_name, |
| 2099 bool rtcp) | 2147 bool rtcp) |
| 2100 : BaseChannel(thread, media_channel, session, content_name, rtcp), | 2148 : BaseChannel(thread, |
| 2149 media_channel, | |
| 2150 transport_controller, | |
| 2151 content_name, | |
| 2152 rtcp), | |
| 2101 data_channel_type_(cricket::DCT_NONE), | 2153 data_channel_type_(cricket::DCT_NONE), |
| 2102 ready_to_send_data_(false) { | 2154 ready_to_send_data_(false) { |
| 2103 } | 2155 } |
| 2104 | 2156 |
| 2105 DataChannel::~DataChannel() { | 2157 DataChannel::~DataChannel() { |
| 2106 StopMediaMonitor(); | 2158 StopMediaMonitor(); |
| 2107 // this can't be done in the base class, since it calls a virtual | 2159 // this can't be done in the base class, since it calls a virtual |
| 2108 DisableMedia_w(); | 2160 DisableMedia_w(); |
| 2109 | 2161 |
| 2110 Deinit(); | 2162 Deinit(); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2428 return (data_channel_type_ == DCT_RTP); | 2480 return (data_channel_type_ == DCT_RTP); |
| 2429 } | 2481 } |
| 2430 | 2482 |
| 2431 void DataChannel::OnStreamClosedRemotely(uint32 sid) { | 2483 void DataChannel::OnStreamClosedRemotely(uint32 sid) { |
| 2432 rtc::TypedMessageData<uint32>* message = | 2484 rtc::TypedMessageData<uint32>* message = |
| 2433 new rtc::TypedMessageData<uint32>(sid); | 2485 new rtc::TypedMessageData<uint32>(sid); |
| 2434 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2486 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
| 2435 } | 2487 } |
| 2436 | 2488 |
| 2437 } // namespace cricket | 2489 } // namespace cricket |
| OLD | NEW |