| OLD | NEW | 
|     1 /* |     1 /* | 
|     2  *  Copyright 2004 The WebRTC project authors. All Rights Reserved. |     2  *  Copyright 2004 The WebRTC project authors. All Rights Reserved. | 
|     3  * |     3  * | 
|     4  *  Use of this source code is governed by a BSD-style license |     4  *  Use of this source code is governed by a BSD-style license | 
|     5  *  that can be found in the LICENSE file in the root of the source |     5  *  that can be found in the LICENSE file in the root of the source | 
|     6  *  tree. An additional intellectual property rights grant can be found |     6  *  tree. An additional intellectual property rights grant can be found | 
|     7  *  in the file PATENTS.  All contributing project authors may |     7  *  in the file PATENTS.  All contributing project authors may | 
|     8  *  be found in the AUTHORS file in the root of the source tree. |     8  *  be found in the AUTHORS file in the root of the source tree. | 
|     9  */ |     9  */ | 
|    10  |    10  | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|    30 using rtc::Bind; |    30 using rtc::Bind; | 
|    31  |    31  | 
|    32 namespace { |    32 namespace { | 
|    33 // See comment below for why we need to use a pointer to a unique_ptr. |    33 // See comment below for why we need to use a pointer to a unique_ptr. | 
|    34 bool SetRawAudioSink_w(VoiceMediaChannel* channel, |    34 bool SetRawAudioSink_w(VoiceMediaChannel* channel, | 
|    35                        uint32_t ssrc, |    35                        uint32_t ssrc, | 
|    36                        std::unique_ptr<webrtc::AudioSinkInterface>* sink) { |    36                        std::unique_ptr<webrtc::AudioSinkInterface>* sink) { | 
|    37   channel->SetRawAudioSink(ssrc, std::move(*sink)); |    37   channel->SetRawAudioSink(ssrc, std::move(*sink)); | 
|    38   return true; |    38   return true; | 
|    39 } |    39 } | 
 |    40  | 
 |    41 struct SendPacketMessageData : public rtc::MessageData { | 
 |    42   rtc::CopyOnWriteBuffer packet; | 
 |    43   rtc::PacketOptions options; | 
 |    44 }; | 
 |    45  | 
|    40 }  // namespace |    46 }  // namespace | 
|    41  |    47  | 
|    42 enum { |    48 enum { | 
|    43   MSG_EARLYMEDIATIMEOUT = 1, |    49   MSG_EARLYMEDIATIMEOUT = 1, | 
|    44   MSG_RTPPACKET, |    50   MSG_SEND_RTP_PACKET, | 
|    45   MSG_RTCPPACKET, |    51   MSG_SEND_RTCP_PACKET, | 
|    46   MSG_CHANNEL_ERROR, |    52   MSG_CHANNEL_ERROR, | 
|    47   MSG_READYTOSENDDATA, |    53   MSG_READYTOSENDDATA, | 
|    48   MSG_DATARECEIVED, |    54   MSG_DATARECEIVED, | 
|    49   MSG_FIRSTPACKETRECEIVED, |    55   MSG_FIRSTPACKETRECEIVED, | 
|    50   MSG_STREAMCLOSEDREMOTELY, |    56   MSG_STREAMCLOSEDREMOTELY, | 
|    51 }; |    57 }; | 
|    52  |    58  | 
|    53 // Value specified in RFC 5764. |    59 // Value specified in RFC 5764. | 
|    54 static const char kDtlsSrtpExporterLabel[] = "EXTRACTOR-dtls_srtp"; |    60 static const char kDtlsSrtpExporterLabel[] = "EXTRACTOR-dtls_srtp"; | 
|    55  |    61  | 
|    56 static const int kAgcMinus10db = -10; |    62 static const int kAgcMinus10db = -10; | 
|    57  |    63  | 
|    58 static void SafeSetError(const std::string& message, std::string* error_desc) { |    64 static void SafeSetError(const std::string& message, std::string* error_desc) { | 
|    59   if (error_desc) { |    65   if (error_desc) { | 
|    60     *error_desc = message; |    66     *error_desc = message; | 
|    61   } |    67   } | 
|    62 } |    68 } | 
|    63  |    69  | 
|    64 struct PacketMessageData : public rtc::MessageData { |  | 
|    65   rtc::CopyOnWriteBuffer packet; |  | 
|    66   rtc::PacketOptions options; |  | 
|    67 }; |  | 
|    68  |  | 
|    69 struct VoiceChannelErrorMessageData : public rtc::MessageData { |    70 struct VoiceChannelErrorMessageData : public rtc::MessageData { | 
|    70   VoiceChannelErrorMessageData(uint32_t in_ssrc, |    71   VoiceChannelErrorMessageData(uint32_t in_ssrc, | 
|    71                                VoiceMediaChannel::Error in_error) |    72                                VoiceMediaChannel::Error in_error) | 
|    72       : ssrc(in_ssrc), error(in_error) {} |    73       : ssrc(in_ssrc), error(in_error) {} | 
|    73   uint32_t ssrc; |    74   uint32_t ssrc; | 
|    74   VoiceMediaChannel::Error error; |    75   VoiceMediaChannel::Error error; | 
|    75 }; |    76 }; | 
|    76  |    77  | 
|    77 struct VideoChannelErrorMessageData : public rtc::MessageData { |    78 struct VideoChannelErrorMessageData : public rtc::MessageData { | 
|    78   VideoChannelErrorMessageData(uint32_t in_ssrc, |    79   VideoChannelErrorMessageData(uint32_t in_ssrc, | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   135 } |   136 } | 
|   136  |   137  | 
|   137 template <class Codec> |   138 template <class Codec> | 
|   138 void RtpSendParametersFromMediaDescription( |   139 void RtpSendParametersFromMediaDescription( | 
|   139     const MediaContentDescriptionImpl<Codec>* desc, |   140     const MediaContentDescriptionImpl<Codec>* desc, | 
|   140     RtpSendParameters<Codec>* send_params) { |   141     RtpSendParameters<Codec>* send_params) { | 
|   141   RtpParametersFromMediaDescription(desc, send_params); |   142   RtpParametersFromMediaDescription(desc, send_params); | 
|   142   send_params->max_bandwidth_bps = desc->bandwidth(); |   143   send_params->max_bandwidth_bps = desc->bandwidth(); | 
|   143 } |   144 } | 
|   144  |   145  | 
|   145 BaseChannel::BaseChannel(rtc::Thread* thread, |   146 BaseChannel::BaseChannel(rtc::Thread* worker_thread, | 
 |   147                          rtc::Thread* network_thread, | 
|   146                          MediaChannel* media_channel, |   148                          MediaChannel* media_channel, | 
|   147                          TransportController* transport_controller, |   149                          TransportController* transport_controller, | 
|   148                          const std::string& content_name, |   150                          const std::string& content_name, | 
|   149                          bool rtcp) |   151                          bool rtcp) | 
|   150     : worker_thread_(thread), |   152     : worker_thread_(worker_thread), | 
 |   153       network_thread_(network_thread), | 
 |   154  | 
 |   155       content_name_(content_name), | 
 |   156  | 
|   151       transport_controller_(transport_controller), |   157       transport_controller_(transport_controller), | 
|   152       media_channel_(media_channel), |  | 
|   153       content_name_(content_name), |  | 
|   154       rtcp_transport_enabled_(rtcp), |   158       rtcp_transport_enabled_(rtcp), | 
|   155       transport_channel_(nullptr), |   159       transport_channel_(nullptr), | 
|   156       rtcp_transport_channel_(nullptr), |   160       rtcp_transport_channel_(nullptr), | 
|   157       enabled_(false), |  | 
|   158       writable_(false), |  | 
|   159       rtp_ready_to_send_(false), |   161       rtp_ready_to_send_(false), | 
|   160       rtcp_ready_to_send_(false), |   162       rtcp_ready_to_send_(false), | 
 |   163       writable_(false), | 
|   161       was_ever_writable_(false), |   164       was_ever_writable_(false), | 
|   162       local_content_direction_(MD_INACTIVE), |  | 
|   163       remote_content_direction_(MD_INACTIVE), |  | 
|   164       has_received_packet_(false), |   165       has_received_packet_(false), | 
|   165       dtls_keyed_(false), |   166       dtls_keyed_(false), | 
|   166       secure_required_(false), |   167       secure_required_(false), | 
|   167       rtp_abs_sendtime_extn_id_(-1) { |   168       rtp_abs_sendtime_extn_id_(-1), | 
 |   169  | 
 |   170       media_channel_(media_channel), | 
 |   171       enabled_(false), | 
 |   172       local_content_direction_(MD_INACTIVE), | 
 |   173       remote_content_direction_(MD_INACTIVE) { | 
|   168   ASSERT(worker_thread_ == rtc::Thread::Current()); |   174   ASSERT(worker_thread_ == rtc::Thread::Current()); | 
 |   175   if (transport_controller) { | 
 |   176     RTC_DCHECK_EQ(network_thread, transport_controller->worker_thread()); | 
 |   177   } | 
|   169   LOG(LS_INFO) << "Created channel for " << content_name; |   178   LOG(LS_INFO) << "Created channel for " << content_name; | 
|   170 } |   179 } | 
|   171  |   180  | 
|   172 BaseChannel::~BaseChannel() { |   181 BaseChannel::~BaseChannel() { | 
|   173   TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); |   182   TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); | 
|   174   ASSERT(worker_thread_ == rtc::Thread::Current()); |   183   ASSERT(worker_thread_ == rtc::Thread::Current()); | 
|   175   Deinit(); |   184   Deinit(); | 
|   176   StopConnectionMonitor(); |   185   StopConnectionMonitor(); | 
|   177   FlushRtcpMessages();  // Send any outstanding RTCP packets. |   186   // Send any outstanding RTCP packets. | 
|   178   worker_thread_->Clear(this);  // eats any outstanding messages or packets |   187   network_thread_->Invoke<void>(Bind(&BaseChannel::FlushRtcpMessages_n, this)); | 
 |   188   // Eats any outstanding messages or packets. | 
 |   189   worker_thread_->Clear(&invoker_); | 
 |   190   worker_thread_->Clear(this); | 
|   179   // We must destroy the media channel before the transport channel, otherwise |   191   // We must destroy the media channel before the transport channel, otherwise | 
|   180   // the media channel may try to send on the dead transport channel. NULLing |   192   // the media channel may try to send on the dead transport channel. NULLing | 
|   181   // is not an effective strategy since the sends will come on another thread. |   193   // is not an effective strategy since the sends will come on another thread. | 
|   182   delete media_channel_; |   194   delete media_channel_; | 
|   183   // Note that we don't just call set_transport_channel(nullptr) because that |   195   // Note that we don't just call SetTransportChannel_n(nullptr) because that | 
|   184   // would call a pure virtual method which we can't do from a destructor. |   196   // would call a pure virtual method which we can't do from a destructor. | 
 |   197   network_thread_->Invoke<void>(Bind(&BaseChannel::DeinitNetwork_n, this)); | 
 |   198   LOG(LS_INFO) << "Destroyed channel"; | 
 |   199 } | 
 |   200  | 
 |   201 void BaseChannel::DeinitNetwork_n() { | 
|   185   if (transport_channel_) { |   202   if (transport_channel_) { | 
|   186     DisconnectFromTransportChannel(transport_channel_); |   203     DisconnectFromTransportChannel(transport_channel_); | 
|   187     transport_controller_->DestroyTransportChannel_w( |   204     transport_controller_->DestroyTransportChannel_w( | 
|   188         transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |   205         transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 
|   189   } |   206   } | 
|   190   if (rtcp_transport_channel_) { |   207   if (rtcp_transport_channel_) { | 
|   191     DisconnectFromTransportChannel(rtcp_transport_channel_); |   208     DisconnectFromTransportChannel(rtcp_transport_channel_); | 
|   192     transport_controller_->DestroyTransportChannel_w( |   209     transport_controller_->DestroyTransportChannel_w( | 
|   193         transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |   210         transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 
|   194   } |   211   } | 
|   195   LOG(LS_INFO) << "Destroyed channel"; |   212   network_thread_->Clear(this); | 
|   196 } |   213 } | 
|   197  |   214  | 
|   198 bool BaseChannel::Init() { |   215 bool BaseChannel::Init_w() { | 
|   199   if (!SetTransport(content_name())) { |   216   if (!network_thread_->Invoke<bool>(Bind(&BaseChannel::InitNetwork_n, this))) { | 
|   200     return false; |  | 
|   201   } |  | 
|   202  |  | 
|   203   if (!SetDtlsSrtpCryptoSuites(transport_channel(), false)) { |  | 
|   204     return false; |  | 
|   205   } |  | 
|   206   if (rtcp_transport_enabled() && |  | 
|   207       !SetDtlsSrtpCryptoSuites(rtcp_transport_channel(), true)) { |  | 
|   208     return false; |   217     return false; | 
|   209   } |   218   } | 
|   210  |   219  | 
|   211   // Both RTP and RTCP channels are set, we can call SetInterface on |   220   // Both RTP and RTCP channels are set, we can call SetInterface on | 
|   212   // media channel and it can set network options. |   221   // media channel and it can set network options. | 
 |   222   RTC_DCHECK(worker_thread_->IsCurrent()); | 
|   213   media_channel_->SetInterface(this); |   223   media_channel_->SetInterface(this); | 
|   214   return true; |   224   return true; | 
|   215 } |   225 } | 
|   216  |   226  | 
 |   227 bool BaseChannel::InitNetwork_n() { | 
 |   228   RTC_DCHECK(network_thread_->IsCurrent()); | 
 |   229   if (!SetTransport_n(content_name())) { | 
 |   230     return false; | 
 |   231   } | 
 |   232  | 
 |   233   if (!SetDtlsSrtpCryptoSuites_n(transport_channel_, false)) { | 
 |   234     return false; | 
 |   235   } | 
 |   236   if (rtcp_transport_enabled() && | 
 |   237       !SetDtlsSrtpCryptoSuites_n(rtcp_transport_channel_, true)) { | 
 |   238     return false; | 
 |   239   } | 
 |   240   return true; | 
 |   241 } | 
 |   242  | 
|   217 void BaseChannel::Deinit() { |   243 void BaseChannel::Deinit() { | 
 |   244   RTC_DCHECK(worker_thread_->IsCurrent()); | 
|   218   media_channel_->SetInterface(NULL); |   245   media_channel_->SetInterface(NULL); | 
|   219 } |   246 } | 
|   220  |   247  | 
|   221 bool BaseChannel::SetTransport(const std::string& transport_name) { |   248 bool BaseChannel::SetTransport(const std::string& transport_name) { | 
|   222   return worker_thread_->Invoke<bool>( |   249   return network_thread_->Invoke<bool>( | 
|   223       Bind(&BaseChannel::SetTransport_w, this, transport_name)); |   250       Bind(&BaseChannel::SetTransport_n, this, transport_name)); | 
|   224 } |   251 } | 
|   225  |   252  | 
|   226 bool BaseChannel::SetTransport_w(const std::string& transport_name) { |   253 bool BaseChannel::SetTransport_n(const std::string& transport_name) { | 
|   227   ASSERT(worker_thread_ == rtc::Thread::Current()); |   254   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   228  |   255  | 
|   229   if (transport_name == transport_name_) { |   256   if (transport_name == transport_name_) { | 
|   230     // Nothing to do if transport name isn't changing |   257     // Nothing to do if transport name isn't changing | 
|   231     return true; |   258     return true; | 
|   232   } |   259   } | 
|   233  |   260  | 
|   234   // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport |   261   // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport | 
|   235   // changes and wait until the DTLS handshake is complete to set the newly |   262   // changes and wait until the DTLS handshake is complete to set the newly | 
|   236   // negotiated parameters. |   263   // negotiated parameters. | 
|   237   if (ShouldSetupDtlsSrtp()) { |   264   if (ShouldSetupDtlsSrtp_n()) { | 
|   238     // Set |writable_| to false such that UpdateWritableState_w can set up |   265     // Set |writable_| to false such that UpdateWritableState_w can set up | 
|   239     // DTLS-SRTP when the writable_ becomes true again. |   266     // DTLS-SRTP when the writable_ becomes true again. | 
|   240     writable_ = false; |   267     writable_ = false; | 
|   241     srtp_filter_.ResetParams(); |   268     srtp_filter_.ResetParams(); | 
|   242   } |   269   } | 
|   243  |   270  | 
|   244   // TODO(guoweis): Remove this grossness when we remove non-muxed RTCP. |   271   // TODO(guoweis): Remove this grossness when we remove non-muxed RTCP. | 
|   245   if (rtcp_transport_enabled()) { |   272   if (rtcp_transport_enabled()) { | 
|   246     LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() |   273     LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() | 
|   247                  << " on " << transport_name << " transport "; |   274                  << " on " << transport_name << " transport "; | 
|   248     set_rtcp_transport_channel( |   275     SetRtcpTransportChannel_n( | 
|   249         transport_controller_->CreateTransportChannel_w( |   276         transport_controller_->CreateTransportChannel_w( | 
|   250             transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP), |   277             transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP), | 
|   251         false /* update_writablity */); |   278         false /* update_writablity */); | 
|   252     if (!rtcp_transport_channel()) { |   279     if (!rtcp_transport_channel_) { | 
|   253       return false; |   280       return false; | 
|   254     } |   281     } | 
|   255   } |   282   } | 
|   256  |   283  | 
|   257   // We're not updating the writablity during the transition state. |   284   // We're not updating the writablity during the transition state. | 
|   258   set_transport_channel(transport_controller_->CreateTransportChannel_w( |   285   SetTransportChannel_n(transport_controller_->CreateTransportChannel_w( | 
|   259       transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP)); |   286       transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 
|   260   if (!transport_channel()) { |   287   if (!transport_channel_) { | 
|   261     return false; |   288     return false; | 
|   262   } |   289   } | 
|   263  |   290  | 
|   264   // TODO(guoweis): Remove this grossness when we remove non-muxed RTCP. |   291   // TODO(guoweis): Remove this grossness when we remove non-muxed RTCP. | 
|   265   if (rtcp_transport_enabled()) { |   292   if (rtcp_transport_enabled()) { | 
|   266     // We can only update the RTCP ready to send after set_transport_channel has |   293     // We can only update the RTCP ready to send after set_transport_channel has | 
|   267     // handled channel writability. |   294     // handled channel writability. | 
|   268     SetReadyToSend( |   295     SetReadyToSend( | 
|   269         true, rtcp_transport_channel() && rtcp_transport_channel()->writable()); |   296         true, rtcp_transport_channel_ && rtcp_transport_channel_->writable()); | 
|   270   } |   297   } | 
|   271   transport_name_ = transport_name; |   298   transport_name_ = transport_name; | 
|   272   return true; |   299   return true; | 
|   273 } |   300 } | 
|   274  |   301  | 
|   275 void BaseChannel::set_transport_channel(TransportChannel* new_tc) { |   302 void BaseChannel::SetTransportChannel_n(TransportChannel* new_tc) { | 
|   276   ASSERT(worker_thread_ == rtc::Thread::Current()); |   303   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   277  |   304  | 
|   278   TransportChannel* old_tc = transport_channel_; |   305   TransportChannel* old_tc = transport_channel_; | 
|   279   if (!old_tc && !new_tc) { |   306   if (!old_tc && !new_tc) { | 
|   280     // Nothing to do |   307     // Nothing to do | 
|   281     return; |   308     return; | 
|   282   } |   309   } | 
|   283   ASSERT(old_tc != new_tc); |   310   ASSERT(old_tc != new_tc); | 
|   284  |   311  | 
|   285   if (old_tc) { |   312   if (old_tc) { | 
|   286     DisconnectFromTransportChannel(old_tc); |   313     DisconnectFromTransportChannel(old_tc); | 
|   287     transport_controller_->DestroyTransportChannel_w( |   314     transport_controller_->DestroyTransportChannel_w( | 
|   288         transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |   315         transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 
|   289   } |   316   } | 
|   290  |   317  | 
|   291   transport_channel_ = new_tc; |   318   transport_channel_ = new_tc; | 
|   292  |   319  | 
|   293   if (new_tc) { |   320   if (new_tc) { | 
|   294     ConnectToTransportChannel(new_tc); |   321     ConnectToTransportChannel(new_tc); | 
|   295     for (const auto& pair : socket_options_) { |   322     for (const auto& pair : socket_options_) { | 
|   296       new_tc->SetOption(pair.first, pair.second); |   323       new_tc->SetOption(pair.first, pair.second); | 
|   297     } |   324     } | 
|   298   } |   325   } | 
|   299  |   326  | 
|   300   // Update aggregate writable/ready-to-send state between RTP and RTCP upon |   327   // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 
|   301   // setting new channel |   328   // setting new channel | 
|   302   UpdateWritableState_w(); |   329   UpdateWritableState_n(); | 
|   303   SetReadyToSend(false, new_tc && new_tc->writable()); |   330   SetReadyToSend(false, new_tc && new_tc->writable()); | 
|   304 } |   331 } | 
|   305  |   332  | 
|   306 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc, |   333 void BaseChannel::SetRtcpTransportChannel_n(TransportChannel* new_tc, | 
|   307                                              bool update_writablity) { |   334                                             bool update_writablity) { | 
|   308   ASSERT(worker_thread_ == rtc::Thread::Current()); |   335   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   309  |   336  | 
|   310   TransportChannel* old_tc = rtcp_transport_channel_; |   337   TransportChannel* old_tc = rtcp_transport_channel_; | 
|   311   if (!old_tc && !new_tc) { |   338   if (!old_tc && !new_tc) { | 
|   312     // Nothing to do |   339     // Nothing to do | 
|   313     return; |   340     return; | 
|   314   } |   341   } | 
|   315   ASSERT(old_tc != new_tc); |   342   ASSERT(old_tc != new_tc); | 
|   316  |   343  | 
|   317   if (old_tc) { |   344   if (old_tc) { | 
|   318     DisconnectFromTransportChannel(old_tc); |   345     DisconnectFromTransportChannel(old_tc); | 
|   319     transport_controller_->DestroyTransportChannel_w( |   346     transport_controller_->DestroyTransportChannel_w( | 
|   320         transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |   347         transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 
|   321   } |   348   } | 
|   322  |   349  | 
|   323   rtcp_transport_channel_ = new_tc; |   350   rtcp_transport_channel_ = new_tc; | 
|   324  |   351  | 
|   325   if (new_tc) { |   352   if (new_tc) { | 
|   326     RTC_CHECK(!(ShouldSetupDtlsSrtp() && srtp_filter_.IsActive())) |   353     RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) | 
|   327         << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " |   354         << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " | 
|   328         << "should never happen."; |   355         << "should never happen."; | 
|   329     ConnectToTransportChannel(new_tc); |   356     ConnectToTransportChannel(new_tc); | 
|   330     for (const auto& pair : rtcp_socket_options_) { |   357     for (const auto& pair : rtcp_socket_options_) { | 
|   331       new_tc->SetOption(pair.first, pair.second); |   358       new_tc->SetOption(pair.first, pair.second); | 
|   332     } |   359     } | 
|   333   } |   360   } | 
|   334  |   361  | 
|   335   if (update_writablity) { |   362   if (update_writablity) { | 
|   336     // Update aggregate writable/ready-to-send state between RTP and RTCP upon |   363     // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 
|   337     // setting new channel |   364     // setting new channel | 
|   338     UpdateWritableState_w(); |   365     UpdateWritableState_n(); | 
|   339     SetReadyToSend(true, new_tc && new_tc->writable()); |   366     SetReadyToSend(true, new_tc && new_tc->writable()); | 
|   340   } |   367   } | 
|   341 } |   368 } | 
|   342  |   369  | 
|   343 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { |   370 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { | 
|   344   ASSERT(worker_thread_ == rtc::Thread::Current()); |   371   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   345  |   372  | 
|   346   tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |   373   tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 
|   347   tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); |   374   tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); | 
|   348   tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |   375   tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | 
|   349   tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); |   376   tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); | 
|   350   tc->SignalSelectedCandidatePairChanged.connect( |   377   tc->SignalSelectedCandidatePairChanged.connect( | 
|   351       this, &BaseChannel::OnSelectedCandidatePairChanged); |   378       this, &BaseChannel::OnSelectedCandidatePairChanged); | 
 |   379   tc->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); | 
|   352 } |   380 } | 
|   353  |   381  | 
|   354 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { |   382 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { | 
|   355   ASSERT(worker_thread_ == rtc::Thread::Current()); |   383   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   356  |   384  | 
|   357   tc->SignalWritableState.disconnect(this); |   385   tc->SignalWritableState.disconnect(this); | 
|   358   tc->SignalReadPacket.disconnect(this); |   386   tc->SignalReadPacket.disconnect(this); | 
|   359   tc->SignalReadyToSend.disconnect(this); |   387   tc->SignalReadyToSend.disconnect(this); | 
|   360   tc->SignalDtlsState.disconnect(this); |   388   tc->SignalDtlsState.disconnect(this); | 
 |   389   tc->SignalSelectedCandidatePairChanged.disconnect(this); | 
 |   390   tc->SignalSentPacket.disconnect(this); | 
|   361 } |   391 } | 
|   362  |   392  | 
|   363 bool BaseChannel::Enable(bool enable) { |   393 bool BaseChannel::Enable(bool enable) { | 
|   364   worker_thread_->Invoke<void>(Bind( |   394   worker_thread_->Invoke<void>(Bind( | 
|   365       enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, |   395       enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, | 
|   366       this)); |   396       this)); | 
|   367   return true; |   397   return true; | 
|   368 } |   398 } | 
|   369  |   399  | 
|   370 bool BaseChannel::AddRecvStream(const StreamParams& sp) { |   400 bool BaseChannel::AddRecvStream(const StreamParams& sp) { | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
|   398                                    std::string* error_desc) { |   428                                    std::string* error_desc) { | 
|   399   TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent"); |   429   TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent"); | 
|   400   return InvokeOnWorker(Bind(&BaseChannel::SetRemoteContent_w, |   430   return InvokeOnWorker(Bind(&BaseChannel::SetRemoteContent_w, | 
|   401                              this, content, action, error_desc)); |   431                              this, content, action, error_desc)); | 
|   402 } |   432 } | 
|   403  |   433  | 
|   404 void BaseChannel::StartConnectionMonitor(int cms) { |   434 void BaseChannel::StartConnectionMonitor(int cms) { | 
|   405   // We pass in the BaseChannel instead of the transport_channel_ |   435   // We pass in the BaseChannel instead of the transport_channel_ | 
|   406   // because if the transport_channel_ changes, the ConnectionMonitor |   436   // because if the transport_channel_ changes, the ConnectionMonitor | 
|   407   // would be pointing to the wrong TransportChannel. |   437   // would be pointing to the wrong TransportChannel. | 
|   408   connection_monitor_.reset(new ConnectionMonitor( |   438   // We pass in the network thread because on that thread connection monitor | 
|   409       this, worker_thread(), rtc::Thread::Current())); |   439   // will call BaseChannel::GetConnectionStats which must be called on the | 
 |   440   // network thread. | 
 |   441   connection_monitor_.reset( | 
 |   442       new ConnectionMonitor(this, network_thread(), rtc::Thread::Current())); | 
|   410   connection_monitor_->SignalUpdate.connect( |   443   connection_monitor_->SignalUpdate.connect( | 
|   411       this, &BaseChannel::OnConnectionMonitorUpdate); |   444       this, &BaseChannel::OnConnectionMonitorUpdate); | 
|   412   connection_monitor_->Start(cms); |   445   connection_monitor_->Start(cms); | 
|   413 } |   446 } | 
|   414  |   447  | 
|   415 void BaseChannel::StopConnectionMonitor() { |   448 void BaseChannel::StopConnectionMonitor() { | 
|   416   if (connection_monitor_) { |   449   if (connection_monitor_) { | 
|   417     connection_monitor_->Stop(); |   450     connection_monitor_->Stop(); | 
|   418     connection_monitor_.reset(); |   451     connection_monitor_.reset(); | 
|   419   } |   452   } | 
|   420 } |   453 } | 
|   421  |   454  | 
|   422 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { |   455 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { | 
|   423   ASSERT(worker_thread_ == rtc::Thread::Current()); |   456   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   424   return transport_channel_->GetStats(infos); |   457   return transport_channel_->GetStats(infos); | 
|   425 } |   458 } | 
|   426  |   459  | 
|   427 bool BaseChannel::IsReadyToReceive() const { |   460 bool BaseChannel::IsReadyToReceive_w() const { | 
|   428   // Receive data if we are enabled and have local content, |   461   // Receive data if we are enabled and have local content, | 
|   429   return enabled() && IsReceiveContentDirection(local_content_direction_); |   462   return enabled() && IsReceiveContentDirection(local_content_direction_); | 
|   430 } |   463 } | 
|   431  |   464  | 
|   432 bool BaseChannel::IsReadyToSend() const { |   465 bool BaseChannel::IsReadyToSend_w() const { | 
|   433   // Send outgoing data if we are enabled, have local and remote content, |   466   // Send outgoing data if we are enabled, have local and remote content, | 
|   434   // and we have had some form of connectivity. |   467   // and we have had some form of connectivity. | 
|   435   return enabled() && IsReceiveContentDirection(remote_content_direction_) && |   468   return enabled() && IsReceiveContentDirection(remote_content_direction_) && | 
|   436          IsSendContentDirection(local_content_direction_) && |   469          IsSendContentDirection(local_content_direction_) && | 
|   437          was_ever_writable() && |   470          network_thread_->Invoke<bool>( | 
|   438          (srtp_filter_.IsActive() || !ShouldSetupDtlsSrtp()); |   471              Bind(&BaseChannel::IsTransportReadyToSend_n, this)); | 
 |   472 } | 
 |   473  | 
 |   474 bool BaseChannel::IsTransportReadyToSend_n() const { | 
 |   475   return was_ever_writable() && | 
 |   476          (srtp_filter_.IsActive() || !ShouldSetupDtlsSrtp_n()); | 
|   439 } |   477 } | 
|   440  |   478  | 
|   441 bool BaseChannel::SendPacket(rtc::CopyOnWriteBuffer* packet, |   479 bool BaseChannel::SendPacket(rtc::CopyOnWriteBuffer* packet, | 
|   442                              const rtc::PacketOptions& options) { |   480                              const rtc::PacketOptions& options) { | 
|   443   return SendPacket(false, packet, options); |   481   return SendPacket(false, packet, options); | 
|   444 } |   482 } | 
|   445  |   483  | 
|   446 bool BaseChannel::SendRtcp(rtc::CopyOnWriteBuffer* packet, |   484 bool BaseChannel::SendRtcp(rtc::CopyOnWriteBuffer* packet, | 
|   447                            const rtc::PacketOptions& options) { |   485                            const rtc::PacketOptions& options) { | 
|   448   return SendPacket(true, packet, options); |   486   return SendPacket(true, packet, options); | 
|   449 } |   487 } | 
|   450  |   488  | 
|   451 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, |   489 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, | 
|   452                            int value) { |   490                            int value) { | 
|   453   TransportChannel* channel = NULL; |   491   return network_thread_->Invoke<int>( | 
 |   492       Bind(&BaseChannel::SetOption_n, this, type, opt, value)); | 
 |   493 } | 
 |   494  | 
 |   495 int BaseChannel::SetOption_n(SocketType type, | 
 |   496                              rtc::Socket::Option opt, | 
 |   497                              int value) { | 
 |   498   RTC_DCHECK(network_thread_->IsCurrent()); | 
 |   499   TransportChannel* channel = nullptr; | 
|   454   switch (type) { |   500   switch (type) { | 
|   455     case ST_RTP: |   501     case ST_RTP: | 
|   456       channel = transport_channel_; |   502       channel = transport_channel_; | 
|   457       socket_options_.push_back( |   503       socket_options_.push_back( | 
|   458           std::pair<rtc::Socket::Option, int>(opt, value)); |   504           std::pair<rtc::Socket::Option, int>(opt, value)); | 
|   459       break; |   505       break; | 
|   460     case ST_RTCP: |   506     case ST_RTCP: | 
|   461       channel = rtcp_transport_channel_; |   507       channel = rtcp_transport_channel_; | 
|   462       rtcp_socket_options_.push_back( |   508       rtcp_socket_options_.push_back( | 
|   463           std::pair<rtc::Socket::Option, int>(opt, value)); |   509           std::pair<rtc::Socket::Option, int>(opt, value)); | 
|   464       break; |   510       break; | 
|   465   } |   511   } | 
|   466   return channel ? channel->SetOption(opt, value) : -1; |   512   return channel ? channel->SetOption(opt, value) : -1; | 
|   467 } |   513 } | 
|   468  |   514  | 
|   469 void BaseChannel::OnWritableState(TransportChannel* channel) { |   515 void BaseChannel::OnWritableState(TransportChannel* channel) { | 
|   470   ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |   516   RTC_DCHECK(channel == transport_channel_ || | 
|   471   UpdateWritableState_w(); |   517              channel == rtcp_transport_channel_); | 
 |   518   RTC_DCHECK(network_thread_->IsCurrent()); | 
 |   519   UpdateWritableState_n(); | 
|   472 } |   520 } | 
|   473  |   521  | 
|   474 void BaseChannel::OnChannelRead(TransportChannel* channel, |   522 void BaseChannel::OnChannelRead(TransportChannel* channel, | 
|   475                                 const char* data, size_t len, |   523                                 const char* data, size_t len, | 
|   476                                 const rtc::PacketTime& packet_time, |   524                                 const rtc::PacketTime& packet_time, | 
|   477                                 int flags) { |   525                                 int flags) { | 
|   478   TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); |   526   TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); | 
|   479   // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine |   527   // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine | 
|   480   ASSERT(worker_thread_ == rtc::Thread::Current()); |   528   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   481  |   529  | 
|   482   // When using RTCP multiplexing we might get RTCP packets on the RTP |   530   // When using RTCP multiplexing we might get RTCP packets on the RTP | 
|   483   // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. |   531   // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. | 
|   484   bool rtcp = PacketIsRtcp(channel, data, len); |   532   bool rtcp = PacketIsRtcp(channel, data, len); | 
|   485   rtc::CopyOnWriteBuffer packet(data, len); |   533   rtc::CopyOnWriteBuffer packet(data, len); | 
|   486   HandlePacket(rtcp, &packet, packet_time); |   534   HandlePacket(rtcp, &packet, packet_time); | 
|   487 } |   535 } | 
|   488  |   536  | 
|   489 void BaseChannel::OnReadyToSend(TransportChannel* channel) { |   537 void BaseChannel::OnReadyToSend(TransportChannel* channel) { | 
|   490   ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |   538   ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 
|   491   SetReadyToSend(channel == rtcp_transport_channel_, true); |   539   SetReadyToSend(channel == rtcp_transport_channel_, true); | 
|   492 } |   540 } | 
|   493  |   541  | 
|   494 void BaseChannel::OnDtlsState(TransportChannel* channel, |   542 void BaseChannel::OnDtlsState(TransportChannel* channel, | 
|   495                               DtlsTransportState state) { |   543                               DtlsTransportState state) { | 
|   496   if (!ShouldSetupDtlsSrtp()) { |   544   if (!ShouldSetupDtlsSrtp_n()) { | 
|   497     return; |   545     return; | 
|   498   } |   546   } | 
|   499  |   547  | 
|   500   // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED |   548   // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED | 
|   501   // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to |   549   // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to | 
|   502   // cover other scenarios like the whole channel is writable (not just this |   550   // cover other scenarios like the whole channel is writable (not just this | 
|   503   // TransportChannel) or when TransportChannel is attached after DTLS is |   551   // TransportChannel) or when TransportChannel is attached after DTLS is | 
|   504   // negotiated. |   552   // negotiated. | 
|   505   if (state != DTLS_TRANSPORT_CONNECTED) { |   553   if (state != DTLS_TRANSPORT_CONNECTED) { | 
|   506     srtp_filter_.ResetParams(); |   554     srtp_filter_.ResetParams(); | 
|   507   } |   555   } | 
|   508 } |   556 } | 
|   509  |   557  | 
|   510 void BaseChannel::OnSelectedCandidatePairChanged( |   558 void BaseChannel::OnSelectedCandidatePairChanged( | 
|   511     TransportChannel* channel, |   559     TransportChannel* channel, | 
|   512     CandidatePairInterface* selected_candidate_pair, |   560     CandidatePairInterface* selected_candidate_pair, | 
|   513     int last_sent_packet_id) { |   561     int last_sent_packet_id) { | 
|   514   ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |   562   ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 
 |   563   RTC_DCHECK(network_thread_->IsCurrent()); | 
 |   564   std::string transport_name = channel->transport_name(); | 
|   515   rtc::NetworkRoute network_route; |   565   rtc::NetworkRoute network_route; | 
|   516   if (selected_candidate_pair) { |   566   if (selected_candidate_pair) { | 
|   517     network_route = rtc::NetworkRoute( |   567     network_route = rtc::NetworkRoute( | 
|   518         selected_candidate_pair->local_candidate().network_id(), |   568         selected_candidate_pair->local_candidate().network_id(), | 
|   519         selected_candidate_pair->remote_candidate().network_id(), |   569         selected_candidate_pair->remote_candidate().network_id(), | 
|   520         last_sent_packet_id); |   570         last_sent_packet_id); | 
|   521   } |   571   } | 
|   522   media_channel()->OnNetworkRouteChanged(channel->transport_name(), |   572   invoker_.AsyncInvoke<void>( | 
|   523                                          network_route); |   573       worker_thread_, Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, | 
 |   574                            transport_name, network_route)); | 
|   524 } |   575 } | 
|   525  |   576  | 
|   526 void BaseChannel::SetReadyToSend(bool rtcp, bool ready) { |   577 void BaseChannel::SetReadyToSend(bool rtcp, bool ready) { | 
 |   578   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   527   if (rtcp) { |   579   if (rtcp) { | 
|   528     rtcp_ready_to_send_ = ready; |   580     rtcp_ready_to_send_ = ready; | 
|   529   } else { |   581   } else { | 
|   530     rtp_ready_to_send_ = ready; |   582     rtp_ready_to_send_ = ready; | 
|   531   } |   583   } | 
|   532  |   584  | 
|   533   if (rtp_ready_to_send_ && |   585   bool ready_to_send = | 
|   534       // In the case of rtcp mux |rtcp_transport_channel_| will be null. |   586       (rtp_ready_to_send_ && | 
|   535       (rtcp_ready_to_send_ || !rtcp_transport_channel_)) { |   587        // In the case of rtcp mux |rtcp_transport_channel_| will be null. | 
|   536     // Notify the MediaChannel when both rtp and rtcp channel can send. |   588        (rtcp_ready_to_send_ || !rtcp_transport_channel_)); | 
|   537     media_channel_->OnReadyToSend(true); |   589  | 
|   538   } else { |   590   invoker_.AsyncInvoke<void>( | 
|   539     // Notify the MediaChannel when either rtp or rtcp channel can't send. |   591       worker_thread_, | 
|   540     media_channel_->OnReadyToSend(false); |   592       Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); | 
|   541   } |  | 
|   542 } |   593 } | 
|   543  |   594  | 
|   544 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, |   595 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, | 
|   545                                const char* data, size_t len) { |   596                                const char* data, size_t len) { | 
|   546   return (channel == rtcp_transport_channel_ || |   597   return (channel == rtcp_transport_channel_ || | 
|   547           rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); |   598           rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); | 
|   548 } |   599 } | 
|   549  |   600  | 
|   550 bool BaseChannel::SendPacket(bool rtcp, |   601 bool BaseChannel::SendPacket(bool rtcp, | 
|   551                              rtc::CopyOnWriteBuffer* packet, |   602                              rtc::CopyOnWriteBuffer* packet, | 
|   552                              const rtc::PacketOptions& options) { |   603                              const rtc::PacketOptions& options) { | 
|   553   // SendPacket gets called from MediaEngine, typically on an encoder thread. |   604   // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. | 
|   554   // If the thread is not our worker thread, we will post to our worker |   605   // If the thread is not our network thread, we will post to our network | 
|   555   // so that the real work happens on our worker. This avoids us having to |   606   // so that the real work happens on our network. This avoids us having to | 
|   556   // synchronize access to all the pieces of the send path, including |   607   // synchronize access to all the pieces of the send path, including | 
|   557   // SRTP and the inner workings of the transport channels. |   608   // SRTP and the inner workings of the transport channels. | 
|   558   // The only downside is that we can't return a proper failure code if |   609   // The only downside is that we can't return a proper failure code if | 
|   559   // needed. Since UDP is unreliable anyway, this should be a non-issue. |   610   // needed. Since UDP is unreliable anyway, this should be a non-issue. | 
|   560   if (rtc::Thread::Current() != worker_thread_) { |   611   if (!network_thread_->IsCurrent()) { | 
|   561     // Avoid a copy by transferring the ownership of the packet data. |   612     // Avoid a copy by transferring the ownership of the packet data. | 
|   562     int message_id = (!rtcp) ? MSG_RTPPACKET : MSG_RTCPPACKET; |   613     int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET; | 
|   563     PacketMessageData* data = new PacketMessageData; |   614     SendPacketMessageData* data = new SendPacketMessageData; | 
|   564     data->packet = std::move(*packet); |   615     data->packet = std::move(*packet); | 
|   565     data->options = options; |   616     data->options = options; | 
|   566     worker_thread_->Post(this, message_id, data); |   617     network_thread_->Post(this, message_id, data); | 
|   567     return true; |   618     return true; | 
|   568   } |   619   } | 
 |   620   TRACE_EVENT0("webrtc", "BaseChannel::SendPacket"); | 
|   569  |   621  | 
|   570   // Now that we are on the correct thread, ensure we have a place to send this |   622   // Now that we are on the correct thread, ensure we have a place to send this | 
|   571   // packet before doing anything. (We might get RTCP packets that we don't |   623   // packet before doing anything. (We might get RTCP packets that we don't | 
|   572   // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP |   624   // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP | 
|   573   // transport. |   625   // transport. | 
|   574   TransportChannel* channel = (!rtcp || rtcp_mux_filter_.IsActive()) ? |   626   TransportChannel* channel = (!rtcp || rtcp_mux_filter_.IsActive()) ? | 
|   575       transport_channel_ : rtcp_transport_channel_; |   627       transport_channel_ : rtcp_transport_channel_; | 
|   576   if (!channel || !channel->writable()) { |   628   if (!channel || !channel->writable()) { | 
|   577     return false; |   629     return false; | 
|   578   } |   630   } | 
|   579  |   631  | 
|   580   // Protect ourselves against crazy data. |   632   // Protect ourselves against crazy data. | 
|   581   if (!ValidPacket(rtcp, packet)) { |   633   if (!ValidPacket(rtcp, packet)) { | 
|   582     LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " |   634     LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " | 
|   583                   << PacketType(rtcp) |   635                   << PacketType(rtcp) | 
|   584                   << " packet: wrong size=" << packet->size(); |   636                   << " packet: wrong size=" << packet->size(); | 
|   585     return false; |   637     return false; | 
|   586   } |   638   } | 
|   587  |   639  | 
|   588   rtc::PacketOptions updated_options; |   640   rtc::PacketOptions updated_options; | 
|   589   updated_options = options; |   641   updated_options = options; | 
|   590   // Protect if needed. |   642   // Protect if needed. | 
|   591   if (srtp_filter_.IsActive()) { |   643   if (srtp_filter_.IsActive()) { | 
 |   644     TRACE_EVENT0("webrtc", "SRTP Encode"); | 
|   592     bool res; |   645     bool res; | 
|   593     uint8_t* data = packet->data(); |   646     uint8_t* data = packet->data(); | 
|   594     int len = static_cast<int>(packet->size()); |   647     int len = static_cast<int>(packet->size()); | 
|   595     if (!rtcp) { |   648     if (!rtcp) { | 
|   596     // If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done |   649     // If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done | 
|   597     // inside libsrtp for a RTP packet. A external HMAC module will be writing |   650     // inside libsrtp for a RTP packet. A external HMAC module will be writing | 
|   598     // a fake HMAC value. This is ONLY done for a RTP packet. |   651     // a fake HMAC value. This is ONLY done for a RTP packet. | 
|   599     // Socket layer will update rtp sendtime extension header if present in |   652     // Socket layer will update rtp sendtime extension header if present in | 
|   600     // packet with current time before updating the HMAC. |   653     // packet with current time before updating the HMAC. | 
|   601 #if !defined(ENABLE_EXTERNAL_AUTH) |   654 #if !defined(ENABLE_EXTERNAL_AUTH) | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   649   } else if (secure_required_) { |   702   } else if (secure_required_) { | 
|   650     // This is a double check for something that supposedly can't happen. |   703     // This is a double check for something that supposedly can't happen. | 
|   651     LOG(LS_ERROR) << "Can't send outgoing " << PacketType(rtcp) |   704     LOG(LS_ERROR) << "Can't send outgoing " << PacketType(rtcp) | 
|   652                   << " packet when SRTP is inactive and crypto is required"; |   705                   << " packet when SRTP is inactive and crypto is required"; | 
|   653  |   706  | 
|   654     ASSERT(false); |   707     ASSERT(false); | 
|   655     return false; |   708     return false; | 
|   656   } |   709   } | 
|   657  |   710  | 
|   658   // Bon voyage. |   711   // Bon voyage. | 
|   659   int ret = |   712   int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL; | 
|   660       channel->SendPacket(packet->data<char>(), packet->size(), updated_options, |   713   int ret = channel->SendPacket(packet->data<char>(), packet->size(), | 
|   661                           (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0); |   714                                 updated_options, flags); | 
|   662   if (ret != static_cast<int>(packet->size())) { |   715   if (ret != static_cast<int>(packet->size())) { | 
|   663     if (channel->GetError() == EWOULDBLOCK) { |   716     if (channel->GetError() == EWOULDBLOCK) { | 
|   664       LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; |   717       LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; | 
|   665       SetReadyToSend(rtcp, false); |   718       SetReadyToSend(rtcp, false); | 
|   666     } |   719     } | 
|   667     return false; |   720     return false; | 
|   668   } |   721   } | 
|   669   return true; |   722   return true; | 
|   670 } |   723 } | 
|   671  |   724  | 
|   672 bool BaseChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { |   725 bool BaseChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { | 
|   673   // Protect ourselves against crazy data. |   726   // Protect ourselves against crazy data. | 
|   674   if (!ValidPacket(rtcp, packet)) { |   727   if (!ValidPacket(rtcp, packet)) { | 
|   675     LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " |   728     LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " | 
|   676                   << PacketType(rtcp) |   729                   << PacketType(rtcp) | 
|   677                   << " packet: wrong size=" << packet->size(); |   730                   << " packet: wrong size=" << packet->size(); | 
|   678     return false; |   731     return false; | 
|   679   } |   732   } | 
|   680   if (rtcp) { |   733   if (rtcp) { | 
|   681     // Permit all (seemingly valid) RTCP packets. |   734     // Permit all (seemingly valid) RTCP packets. | 
|   682     return true; |   735     return true; | 
|   683   } |   736   } | 
|   684   // Check whether we handle this payload. |   737   // Check whether we handle this payload. | 
|   685   return bundle_filter_.DemuxPacket(packet->data(), packet->size()); |   738   return bundle_filter_.DemuxPacket(packet->data(), packet->size()); | 
|   686 } |   739 } | 
|   687  |   740  | 
|   688 void BaseChannel::HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet, |   741 void BaseChannel::HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet, | 
|   689                                const rtc::PacketTime& packet_time) { |   742                                const rtc::PacketTime& packet_time) { | 
 |   743   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   690   if (!WantsPacket(rtcp, packet)) { |   744   if (!WantsPacket(rtcp, packet)) { | 
|   691     return; |   745     return; | 
|   692   } |   746   } | 
|   693  |   747  | 
|   694   // We are only interested in the first rtp packet because that |   748   // We are only interested in the first rtp packet because that | 
|   695   // indicates the media has started flowing. |   749   // indicates the media has started flowing. | 
|   696   if (!has_received_packet_ && !rtcp) { |   750   if (!has_received_packet_ && !rtcp) { | 
|   697     has_received_packet_ = true; |   751     has_received_packet_ = true; | 
|   698     signaling_thread()->Post(this, MSG_FIRSTPACKETRECEIVED); |   752     signaling_thread()->Post(this, MSG_FIRSTPACKETRECEIVED); | 
|   699   } |   753   } | 
|   700  |   754  | 
|   701   // Unprotect the packet, if needed. |   755   // Unprotect the packet, if needed. | 
|   702   if (srtp_filter_.IsActive()) { |   756   if (srtp_filter_.IsActive()) { | 
 |   757     TRACE_EVENT0("webrtc", "SRTP Decode"); | 
|   703     char* data = packet->data<char>(); |   758     char* data = packet->data<char>(); | 
|   704     int len = static_cast<int>(packet->size()); |   759     int len = static_cast<int>(packet->size()); | 
|   705     bool res; |   760     bool res; | 
|   706     if (!rtcp) { |   761     if (!rtcp) { | 
|   707       res = srtp_filter_.UnprotectRtp(data, len, &len); |   762       res = srtp_filter_.UnprotectRtp(data, len, &len); | 
|   708       if (!res) { |   763       if (!res) { | 
|   709         int seq_num = -1; |   764         int seq_num = -1; | 
|   710         uint32_t ssrc = 0; |   765         uint32_t ssrc = 0; | 
|   711         GetRtpSeqNum(data, len, &seq_num); |   766         GetRtpSeqNum(data, len, &seq_num); | 
|   712         GetRtpSsrc(data, len, &ssrc); |   767         GetRtpSsrc(data, len, &ssrc); | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|   736     //    channels, so we haven't yet extracted keys, even if DTLS did complete |   791     //    channels, so we haven't yet extracted keys, even if DTLS did complete | 
|   737     //    on the channel that the packets are being sent on. It's really good |   792     //    on the channel that the packets are being sent on. It's really good | 
|   738     //    practice to wait for both RTP and RTCP to be good to go before sending |   793     //    practice to wait for both RTP and RTCP to be good to go before sending | 
|   739     //    media, to prevent weird failure modes, so it's fine for us to just eat |   794     //    media, to prevent weird failure modes, so it's fine for us to just eat | 
|   740     //    packets here. This is all sidestepped if RTCP mux is used anyway. |   795     //    packets here. This is all sidestepped if RTCP mux is used anyway. | 
|   741     LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp) |   796     LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp) | 
|   742                     << " packet when SRTP is inactive and crypto is required"; |   797                     << " packet when SRTP is inactive and crypto is required"; | 
|   743     return; |   798     return; | 
|   744   } |   799   } | 
|   745  |   800  | 
|   746   // Push it down to the media channel. |   801   invoker_.AsyncInvoke<void>( | 
|   747   if (!rtcp) { |   802       worker_thread_, | 
|   748     media_channel_->OnPacketReceived(packet, packet_time); |   803       Bind(&BaseChannel::OnPacketReceived, this, rtcp, *packet, packet_time)); | 
 |   804 } | 
 |   805  | 
 |   806 void BaseChannel::OnPacketReceived(bool rtcp, | 
 |   807                                    const rtc::CopyOnWriteBuffer& packet, | 
 |   808                                    const rtc::PacketTime& packet_time) { | 
 |   809   RTC_DCHECK(worker_thread_->IsCurrent()); | 
 |   810   // Need to copy variable because OnRtcpReceived/OnPacketReceived | 
 |   811   // requires non-const pointer to buffer. This doesn't memcpy the actual data. | 
 |   812   rtc::CopyOnWriteBuffer data(packet); | 
 |   813   if (rtcp) { | 
 |   814     media_channel_->OnRtcpReceived(&data, packet_time); | 
|   749   } else { |   815   } else { | 
|   750     media_channel_->OnRtcpReceived(packet, packet_time); |   816     media_channel_->OnPacketReceived(&data, packet_time); | 
|   751   } |   817   } | 
|   752 } |   818 } | 
|   753  |   819  | 
|   754 bool BaseChannel::PushdownLocalDescription( |   820 bool BaseChannel::PushdownLocalDescription( | 
|   755     const SessionDescription* local_desc, ContentAction action, |   821     const SessionDescription* local_desc, ContentAction action, | 
|   756     std::string* error_desc) { |   822     std::string* error_desc) { | 
|   757   const ContentInfo* content_info = GetFirstContent(local_desc); |   823   const ContentInfo* content_info = GetFirstContent(local_desc); | 
|   758   const MediaContentDescription* content_desc = |   824   const MediaContentDescription* content_desc = | 
|   759       GetContentDescription(content_info); |   825       GetContentDescription(content_info); | 
|   760   if (content_desc && content_info && !content_info->rejected && |   826   if (content_desc && content_info && !content_info->rejected && | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|   779   return true; |   845   return true; | 
|   780 } |   846 } | 
|   781  |   847  | 
|   782 void BaseChannel::EnableMedia_w() { |   848 void BaseChannel::EnableMedia_w() { | 
|   783   ASSERT(worker_thread_ == rtc::Thread::Current()); |   849   ASSERT(worker_thread_ == rtc::Thread::Current()); | 
|   784   if (enabled_) |   850   if (enabled_) | 
|   785     return; |   851     return; | 
|   786  |   852  | 
|   787   LOG(LS_INFO) << "Channel enabled"; |   853   LOG(LS_INFO) << "Channel enabled"; | 
|   788   enabled_ = true; |   854   enabled_ = true; | 
|   789   ChangeState(); |   855   ChangeState_w(); | 
|   790 } |   856 } | 
|   791  |   857  | 
|   792 void BaseChannel::DisableMedia_w() { |   858 void BaseChannel::DisableMedia_w() { | 
|   793   ASSERT(worker_thread_ == rtc::Thread::Current()); |   859   ASSERT(worker_thread_ == rtc::Thread::Current()); | 
|   794   if (!enabled_) |   860   if (!enabled_) | 
|   795     return; |   861     return; | 
|   796  |   862  | 
|   797   LOG(LS_INFO) << "Channel disabled"; |   863   LOG(LS_INFO) << "Channel disabled"; | 
|   798   enabled_ = false; |   864   enabled_ = false; | 
|   799   ChangeState(); |   865   ChangeState_w(); | 
|   800 } |   866 } | 
|   801  |   867  | 
|   802 void BaseChannel::UpdateWritableState_w() { |   868 void BaseChannel::UpdateWritableState_n() { | 
|   803   if (transport_channel_ && transport_channel_->writable() && |   869   if (transport_channel_ && transport_channel_->writable() && | 
|   804       (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { |   870       (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { | 
|   805     ChannelWritable_w(); |   871     ChannelWritable_n(); | 
|   806   } else { |   872   } else { | 
|   807     ChannelNotWritable_w(); |   873     ChannelNotWritable_n(); | 
|   808   } |   874   } | 
|   809 } |   875 } | 
|   810  |   876  | 
|   811 void BaseChannel::ChannelWritable_w() { |   877 void BaseChannel::ChannelWritable_n() { | 
|   812   ASSERT(worker_thread_ == rtc::Thread::Current()); |   878   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   813   if (writable_) { |   879   if (writable_) { | 
|   814     return; |   880     return; | 
|   815   } |   881   } | 
|   816  |   882  | 
|   817   LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" |   883   LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" | 
|   818                << (was_ever_writable_ ? "" : " for the first time"); |   884                << (was_ever_writable_ ? "" : " for the first time"); | 
|   819  |   885  | 
|   820   std::vector<ConnectionInfo> infos; |   886   std::vector<ConnectionInfo> infos; | 
|   821   transport_channel_->GetStats(&infos); |   887   transport_channel_->GetStats(&infos); | 
|   822   for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); |   888   for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); | 
|   823        it != infos.end(); ++it) { |   889        it != infos.end(); ++it) { | 
|   824     if (it->best_connection) { |   890     if (it->best_connection) { | 
|   825       LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() |   891       LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() | 
|   826                    << "->" << it->remote_candidate.ToSensitiveString(); |   892                    << "->" << it->remote_candidate.ToSensitiveString(); | 
|   827       break; |   893       break; | 
|   828     } |   894     } | 
|   829   } |   895   } | 
|   830  |   896  | 
|   831   was_ever_writable_ = true; |   897   was_ever_writable_ = true; | 
|   832   MaybeSetupDtlsSrtp_w(); |   898   MaybeSetupDtlsSrtp_n(); | 
|   833   writable_ = true; |   899   writable_ = true; | 
|   834   ChangeState(); |   900   ChangeState(); | 
|   835 } |   901 } | 
|   836  |   902  | 
|   837 void BaseChannel::SignalDtlsSetupFailure_w(bool rtcp) { |   903 void BaseChannel::SignalDtlsSetupFailure_n(bool rtcp) { | 
|   838   ASSERT(worker_thread() == rtc::Thread::Current()); |   904   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   839   signaling_thread()->Invoke<void>(Bind( |   905   invoker_.AsyncInvoke<void>( | 
|   840       &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); |   906       signaling_thread(), | 
 |   907       Bind(&BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); | 
|   841 } |   908 } | 
|   842  |   909  | 
|   843 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { |   910 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { | 
|   844   ASSERT(signaling_thread() == rtc::Thread::Current()); |   911   ASSERT(signaling_thread() == rtc::Thread::Current()); | 
|   845   SignalDtlsSetupFailure(this, rtcp); |   912   SignalDtlsSetupFailure(this, rtcp); | 
|   846 } |   913 } | 
|   847  |   914  | 
|   848 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { |   915 bool BaseChannel::SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp) { | 
|   849   std::vector<int> crypto_suites; |   916   std::vector<int> crypto_suites; | 
|   850   // We always use the default SRTP crypto suites for RTCP, but we may use |   917   // We always use the default SRTP crypto suites for RTCP, but we may use | 
|   851   // different crypto suites for RTP depending on the media type. |   918   // different crypto suites for RTP depending on the media type. | 
|   852   if (!rtcp) { |   919   if (!rtcp) { | 
|   853     GetSrtpCryptoSuites(&crypto_suites); |   920     GetSrtpCryptoSuites_n(&crypto_suites); | 
|   854   } else { |   921   } else { | 
|   855     GetDefaultSrtpCryptoSuites(&crypto_suites); |   922     GetDefaultSrtpCryptoSuites(&crypto_suites); | 
|   856   } |   923   } | 
|   857   return tc->SetSrtpCryptoSuites(crypto_suites); |   924   return tc->SetSrtpCryptoSuites(crypto_suites); | 
|   858 } |   925 } | 
|   859  |   926  | 
|   860 bool BaseChannel::ShouldSetupDtlsSrtp() const { |   927 bool BaseChannel::ShouldSetupDtlsSrtp_n() const { | 
|   861   // Since DTLS is applied to all channels, checking RTP should be enough. |   928   // Since DTLS is applied to all channels, checking RTP should be enough. | 
|   862   return transport_channel_ && transport_channel_->IsDtlsActive(); |   929   return transport_channel_ && transport_channel_->IsDtlsActive(); | 
|   863 } |   930 } | 
|   864  |   931  | 
|   865 // This function returns true if either DTLS-SRTP is not in use |   932 // This function returns true if either DTLS-SRTP is not in use | 
|   866 // *or* DTLS-SRTP is successfully set up. |   933 // *or* DTLS-SRTP is successfully set up. | 
|   867 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { |   934 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp_channel) { | 
 |   935   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   868   bool ret = false; |   936   bool ret = false; | 
|   869  |   937  | 
|   870   TransportChannel* channel = |   938   TransportChannel* channel = | 
|   871       rtcp_channel ? rtcp_transport_channel_ : transport_channel_; |   939       rtcp_channel ? rtcp_transport_channel_ : transport_channel_; | 
|   872  |   940  | 
|   873   RTC_DCHECK(channel->IsDtlsActive()); |   941   RTC_DCHECK(channel->IsDtlsActive()); | 
|   874  |   942  | 
|   875   int selected_crypto_suite; |   943   int selected_crypto_suite; | 
|   876  |   944  | 
|   877   if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { |   945   if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   943   } |  1011   } | 
|   944  |  1012  | 
|   945   if (!ret) |  1013   if (!ret) | 
|   946     LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; |  1014     LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; | 
|   947   else |  1015   else | 
|   948     dtls_keyed_ = true; |  1016     dtls_keyed_ = true; | 
|   949  |  1017  | 
|   950   return ret; |  1018   return ret; | 
|   951 } |  1019 } | 
|   952  |  1020  | 
|   953 void BaseChannel::MaybeSetupDtlsSrtp_w() { |  1021 void BaseChannel::MaybeSetupDtlsSrtp_n() { | 
|   954   if (srtp_filter_.IsActive()) { |  1022   if (srtp_filter_.IsActive()) { | 
|   955     return; |  1023     return; | 
|   956   } |  1024   } | 
|   957  |  1025  | 
|   958   if (!ShouldSetupDtlsSrtp()) { |  1026   if (!ShouldSetupDtlsSrtp_n()) { | 
|   959     return; |  1027     return; | 
|   960   } |  1028   } | 
|   961  |  1029  | 
|   962   if (!SetupDtlsSrtp(false)) { |  1030   if (!SetupDtlsSrtp_n(false)) { | 
|   963     SignalDtlsSetupFailure_w(false); |  1031     SignalDtlsSetupFailure_n(false); | 
|   964     return; |  1032     return; | 
|   965   } |  1033   } | 
|   966  |  1034  | 
|   967   if (rtcp_transport_channel_) { |  1035   if (rtcp_transport_channel_) { | 
|   968     if (!SetupDtlsSrtp(true)) { |  1036     if (!SetupDtlsSrtp_n(true)) { | 
|   969       SignalDtlsSetupFailure_w(true); |  1037       SignalDtlsSetupFailure_n(true); | 
|   970       return; |  1038       return; | 
|   971     } |  1039     } | 
|   972   } |  1040   } | 
|   973 } |  1041 } | 
|   974  |  1042  | 
|   975 void BaseChannel::ChannelNotWritable_w() { |  1043 void BaseChannel::ChannelNotWritable_n() { | 
|   976   ASSERT(worker_thread_ == rtc::Thread::Current()); |  1044   RTC_DCHECK(network_thread_->IsCurrent()); | 
|   977   if (!writable_) |  1045   if (!writable_) | 
|   978     return; |  1046     return; | 
|   979  |  1047  | 
|   980   LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; |  1048   LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; | 
|   981   writable_ = false; |  1049   writable_ = false; | 
|   982   ChangeState(); |  1050   ChangeState(); | 
|   983 } |  1051 } | 
|   984  |  1052  | 
|   985 bool BaseChannel::SetRtpTransportParameters_w( |  1053 bool BaseChannel::SetRtpTransportParameters( | 
|   986     const MediaContentDescription* content, |  1054     const MediaContentDescription* content, | 
|   987     ContentAction action, |  1055     ContentAction action, | 
|   988     ContentSource src, |  1056     ContentSource src, | 
|   989     std::string* error_desc) { |  1057     std::string* error_desc) { | 
|   990   if (action == CA_UPDATE) { |  1058   if (action == CA_UPDATE) { | 
|   991     // These parameters never get changed by a CA_UDPATE. |  1059     // These parameters never get changed by a CA_UDPATE. | 
|   992     return true; |  1060     return true; | 
|   993   } |  1061   } | 
|   994  |  1062  | 
|   995   // Cache secure_required_ for belt and suspenders check on SendPacket |  1063   // Cache secure_required_ for belt and suspenders check on SendPacket | 
 |  1064   return network_thread_->Invoke<bool>( | 
 |  1065       Bind(&BaseChannel::SetRtpTransportParameters_n, this, content, action, | 
 |  1066            src, error_desc)); | 
 |  1067 } | 
 |  1068  | 
 |  1069 bool BaseChannel::SetRtpTransportParameters_n( | 
 |  1070     const MediaContentDescription* content, | 
 |  1071     ContentAction action, | 
 |  1072     ContentSource src, | 
 |  1073     std::string* error_desc) { | 
 |  1074   RTC_DCHECK(network_thread_->IsCurrent()); | 
 |  1075  | 
|   996   if (src == CS_LOCAL) { |  1076   if (src == CS_LOCAL) { | 
|   997     set_secure_required(content->crypto_required() != CT_NONE); |  1077     set_secure_required(content->crypto_required() != CT_NONE); | 
|   998   } |  1078   } | 
|   999  |  1079  | 
|  1000   if (!SetSrtp_w(content->cryptos(), action, src, error_desc)) { |  1080   if (!SetSrtp_n(content->cryptos(), action, src, error_desc)) { | 
|  1001     return false; |  1081     return false; | 
|  1002   } |  1082   } | 
|  1003  |  1083  | 
|  1004   if (!SetRtcpMux_w(content->rtcp_mux(), action, src, error_desc)) { |  1084   if (!SetRtcpMux_n(content->rtcp_mux(), action, src, error_desc)) { | 
|  1005     return false; |  1085     return false; | 
|  1006   } |  1086   } | 
|  1007  |  1087  | 
|  1008   return true; |  1088   return true; | 
|  1009 } |  1089 } | 
|  1010  |  1090  | 
|  1011 // |dtls| will be set to true if DTLS is active for transport channel and |  1091 // |dtls| will be set to true if DTLS is active for transport channel and | 
|  1012 // crypto is empty. |  1092 // crypto is empty. | 
|  1013 bool BaseChannel::CheckSrtpConfig(const std::vector<CryptoParams>& cryptos, |  1093 bool BaseChannel::CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos, | 
|  1014                                   bool* dtls, |  1094                                     bool* dtls, | 
|  1015                                   std::string* error_desc) { |  1095                                     std::string* error_desc) { | 
|  1016   *dtls = transport_channel_->IsDtlsActive(); |  1096   *dtls = transport_channel_->IsDtlsActive(); | 
|  1017   if (*dtls && !cryptos.empty()) { |  1097   if (*dtls && !cryptos.empty()) { | 
|  1018     SafeSetError("Cryptos must be empty when DTLS is active.", |  1098     SafeSetError("Cryptos must be empty when DTLS is active.", error_desc); | 
|  1019                  error_desc); |  | 
|  1020     return false; |  1099     return false; | 
|  1021   } |  1100   } | 
|  1022   return true; |  1101   return true; | 
|  1023 } |  1102 } | 
|  1024  |  1103  | 
|  1025 bool BaseChannel::SetSrtp_w(const std::vector<CryptoParams>& cryptos, |  1104 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos, | 
|  1026                             ContentAction action, |  1105                             ContentAction action, | 
|  1027                             ContentSource src, |  1106                             ContentSource src, | 
|  1028                             std::string* error_desc) { |  1107                             std::string* error_desc) { | 
|  1029   TRACE_EVENT0("webrtc", "BaseChannel::SetSrtp_w"); |  1108   TRACE_EVENT0("webrtc", "BaseChannel::SetSrtp_w"); | 
|  1030   if (action == CA_UPDATE) { |  1109   if (action == CA_UPDATE) { | 
|  1031     // no crypto params. |  1110     // no crypto params. | 
|  1032     return true; |  1111     return true; | 
|  1033   } |  1112   } | 
|  1034   bool ret = false; |  1113   bool ret = false; | 
|  1035   bool dtls = false; |  1114   bool dtls = false; | 
|  1036   ret = CheckSrtpConfig(cryptos, &dtls, error_desc); |  1115   ret = CheckSrtpConfig_n(cryptos, &dtls, error_desc); | 
|  1037   if (!ret) { |  1116   if (!ret) { | 
|  1038     return false; |  1117     return false; | 
|  1039   } |  1118   } | 
|  1040   switch (action) { |  1119   switch (action) { | 
|  1041     case CA_OFFER: |  1120     case CA_OFFER: | 
|  1042       // If DTLS is already active on the channel, we could be renegotiating |  1121       // If DTLS is already active on the channel, we could be renegotiating | 
|  1043       // here. We don't update the srtp filter. |  1122       // here. We don't update the srtp filter. | 
|  1044       if (!dtls) { |  1123       if (!dtls) { | 
|  1045         ret = srtp_filter_.SetOffer(cryptos, src); |  1124         ret = srtp_filter_.SetOffer(cryptos, src); | 
|  1046       } |  1125       } | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|  1063       break; |  1142       break; | 
|  1064   } |  1143   } | 
|  1065   if (!ret) { |  1144   if (!ret) { | 
|  1066     SafeSetError("Failed to setup SRTP filter.", error_desc); |  1145     SafeSetError("Failed to setup SRTP filter.", error_desc); | 
|  1067     return false; |  1146     return false; | 
|  1068   } |  1147   } | 
|  1069   return true; |  1148   return true; | 
|  1070 } |  1149 } | 
|  1071  |  1150  | 
|  1072 void BaseChannel::ActivateRtcpMux() { |  1151 void BaseChannel::ActivateRtcpMux() { | 
|  1073   worker_thread_->Invoke<void>(Bind( |  1152   network_thread_->Invoke<void>(Bind(&BaseChannel::ActivateRtcpMux_n, this)); | 
|  1074       &BaseChannel::ActivateRtcpMux_w, this)); |  | 
|  1075 } |  1153 } | 
|  1076  |  1154  | 
|  1077 void BaseChannel::ActivateRtcpMux_w() { |  1155 void BaseChannel::ActivateRtcpMux_n() { | 
|  1078   if (!rtcp_mux_filter_.IsActive()) { |  1156   if (!rtcp_mux_filter_.IsActive()) { | 
|  1079     rtcp_mux_filter_.SetActive(); |  1157     rtcp_mux_filter_.SetActive(); | 
|  1080     set_rtcp_transport_channel(nullptr, true); |  1158     SetRtcpTransportChannel_n(nullptr, true); | 
|  1081     rtcp_transport_enabled_ = false; |  1159     rtcp_transport_enabled_ = false; | 
|  1082   } |  1160   } | 
|  1083 } |  1161 } | 
|  1084  |  1162  | 
|  1085 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action, |  1163 bool BaseChannel::SetRtcpMux_n(bool enable, | 
 |  1164                                ContentAction action, | 
|  1086                                ContentSource src, |  1165                                ContentSource src, | 
|  1087                                std::string* error_desc) { |  1166                                std::string* error_desc) { | 
|  1088   bool ret = false; |  1167   bool ret = false; | 
|  1089   switch (action) { |  1168   switch (action) { | 
|  1090     case CA_OFFER: |  1169     case CA_OFFER: | 
|  1091       ret = rtcp_mux_filter_.SetOffer(enable, src); |  1170       ret = rtcp_mux_filter_.SetOffer(enable, src); | 
|  1092       break; |  1171       break; | 
|  1093     case CA_PRANSWER: |  1172     case CA_PRANSWER: | 
|  1094       ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); |  1173       ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); | 
|  1095       break; |  1174       break; | 
|  1096     case CA_ANSWER: |  1175     case CA_ANSWER: | 
|  1097       ret = rtcp_mux_filter_.SetAnswer(enable, src); |  1176       ret = rtcp_mux_filter_.SetAnswer(enable, src); | 
|  1098       if (ret && rtcp_mux_filter_.IsActive()) { |  1177       if (ret && rtcp_mux_filter_.IsActive()) { | 
|  1099         // We activated RTCP mux, close down the RTCP transport. |  1178         // We activated RTCP mux, close down the RTCP transport. | 
|  1100         LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() |  1179         LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() | 
|  1101                      << " by destroying RTCP transport channel for " |  1180                      << " by destroying RTCP transport channel for " | 
|  1102                      << transport_name(); |  1181                      << transport_name(); | 
|  1103         set_rtcp_transport_channel(nullptr, true); |  1182         SetRtcpTransportChannel_n(nullptr, true); | 
|  1104         rtcp_transport_enabled_ = false; |  1183         rtcp_transport_enabled_ = false; | 
|  1105       } |  1184       } | 
|  1106       break; |  1185       break; | 
|  1107     case CA_UPDATE: |  1186     case CA_UPDATE: | 
|  1108       // No RTCP mux info. |  1187       // No RTCP mux info. | 
|  1109       ret = true; |  1188       ret = true; | 
|  1110       break; |  1189       break; | 
|  1111     default: |  1190     default: | 
|  1112       break; |  1191       break; | 
|  1113   } |  1192   } | 
|  1114   if (!ret) { |  1193   if (!ret) { | 
|  1115     SafeSetError("Failed to setup RTCP mux filter.", error_desc); |  1194     SafeSetError("Failed to setup RTCP mux filter.", error_desc); | 
|  1116     return false; |  1195     return false; | 
|  1117   } |  1196   } | 
|  1118   // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or |  1197   // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or | 
|  1119   // CA_ANSWER, but we only want to tear down the RTCP transport channel if we |  1198   // CA_ANSWER, but we only want to tear down the RTCP transport channel if we | 
|  1120   // received a final answer. |  1199   // received a final answer. | 
|  1121   if (rtcp_mux_filter_.IsActive()) { |  1200   if (rtcp_mux_filter_.IsActive()) { | 
|  1122     // If the RTP transport is already writable, then so are we. |  1201     // If the RTP transport is already writable, then so are we. | 
|  1123     if (transport_channel_->writable()) { |  1202     if (transport_channel_->writable()) { | 
|  1124       ChannelWritable_w(); |  1203       ChannelWritable_n(); | 
|  1125     } |  1204     } | 
|  1126   } |  1205   } | 
|  1127  |  1206  | 
|  1128   return true; |  1207   return true; | 
|  1129 } |  1208 } | 
|  1130  |  1209  | 
|  1131 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { |  1210 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { | 
|  1132   ASSERT(worker_thread() == rtc::Thread::Current()); |  1211   ASSERT(worker_thread() == rtc::Thread::Current()); | 
|  1133   return media_channel()->AddRecvStream(sp); |  1212   return media_channel()->AddRecvStream(sp); | 
|  1134 } |  1213 } | 
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1278         desc << "Failed to add remote stream ssrc: " << it->first_ssrc(); |  1357         desc << "Failed to add remote stream ssrc: " << it->first_ssrc(); | 
|  1279         SafeSetError(desc.str(), error_desc); |  1358         SafeSetError(desc.str(), error_desc); | 
|  1280         ret = false; |  1359         ret = false; | 
|  1281       } |  1360       } | 
|  1282     } |  1361     } | 
|  1283   } |  1362   } | 
|  1284   remote_streams_ = streams; |  1363   remote_streams_ = streams; | 
|  1285   return ret; |  1364   return ret; | 
|  1286 } |  1365 } | 
|  1287  |  1366  | 
|  1288 void BaseChannel::MaybeCacheRtpAbsSendTimeHeaderExtension( |  1367 void BaseChannel::MaybeCacheRtpAbsSendTimeHeaderExtension_w( | 
|  1289     const std::vector<RtpHeaderExtension>& extensions) { |  1368     const std::vector<RtpHeaderExtension>& extensions) { | 
 |  1369 // Absolute Send Time extension id is used only with external auth, | 
 |  1370 // so do not bother searching for it and making asyncronious call to set | 
 |  1371 // something that is not used. | 
 |  1372 #if defined(ENABLE_EXTERNAL_AUTH) | 
|  1290   const RtpHeaderExtension* send_time_extension = |  1373   const RtpHeaderExtension* send_time_extension = | 
|  1291       FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); |  1374       FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); | 
|  1292   rtp_abs_sendtime_extn_id_ = |  1375   int rtp_abs_sendtime_extn_id = | 
|  1293       send_time_extension ? send_time_extension->id : -1; |  1376       send_time_extension ? send_time_extension->id : -1; | 
 |  1377   invoker_.AsyncInvoke<void>( | 
 |  1378       network_thread_, Bind(&BaseChannel::CacheRtpAbsSendTimeHeaderExtension_n, | 
 |  1379                             this, rtp_abs_sendtime_extn_id)); | 
 |  1380 #endif | 
 |  1381 } | 
 |  1382  | 
 |  1383 void BaseChannel::CacheRtpAbsSendTimeHeaderExtension_n( | 
 |  1384     int rtp_abs_sendtime_extn_id) { | 
 |  1385   rtp_abs_sendtime_extn_id_ = rtp_abs_sendtime_extn_id; | 
|  1294 } |  1386 } | 
|  1295  |  1387  | 
|  1296 void BaseChannel::OnMessage(rtc::Message *pmsg) { |  1388 void BaseChannel::OnMessage(rtc::Message *pmsg) { | 
|  1297   TRACE_EVENT0("webrtc", "BaseChannel::OnMessage"); |  1389   TRACE_EVENT0("webrtc", "BaseChannel::OnMessage"); | 
|  1298   switch (pmsg->message_id) { |  1390   switch (pmsg->message_id) { | 
|  1299     case MSG_RTPPACKET: |  1391     case MSG_SEND_RTP_PACKET: | 
|  1300     case MSG_RTCPPACKET: { |  1392     case MSG_SEND_RTCP_PACKET: { | 
|  1301       PacketMessageData* data = static_cast<PacketMessageData*>(pmsg->pdata); |  1393       RTC_DCHECK(network_thread_->IsCurrent()); | 
|  1302       SendPacket(pmsg->message_id == MSG_RTCPPACKET, &data->packet, |  1394       SendPacketMessageData* data = | 
|  1303                  data->options); |  1395           static_cast<SendPacketMessageData*>(pmsg->pdata); | 
|  1304       delete data;  // because it is Posted |  1396       bool rtcp = pmsg->message_id == MSG_SEND_RTCP_PACKET; | 
 |  1397       SendPacket(rtcp, &data->packet, data->options); | 
 |  1398       delete data; | 
|  1305       break; |  1399       break; | 
|  1306     } |  1400     } | 
|  1307     case MSG_FIRSTPACKETRECEIVED: { |  1401     case MSG_FIRSTPACKETRECEIVED: { | 
|  1308       SignalFirstPacketReceived(this); |  1402       SignalFirstPacketReceived(this); | 
|  1309       break; |  1403       break; | 
|  1310     } |  1404     } | 
|  1311   } |  1405   } | 
|  1312 } |  1406 } | 
|  1313  |  1407  | 
|  1314 void BaseChannel::FlushRtcpMessages() { |  1408 void BaseChannel::FlushRtcpMessages_n() { | 
|  1315   // Flush all remaining RTCP messages. This should only be called in |  1409   // Flush all remaining RTCP messages. This should only be called in | 
|  1316   // destructor. |  1410   // destructor. | 
|  1317   ASSERT(rtc::Thread::Current() == worker_thread_); |  1411   RTC_DCHECK(network_thread_->IsCurrent()); | 
|  1318   rtc::MessageList rtcp_messages; |  1412   rtc::MessageList rtcp_messages; | 
|  1319   worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages); |  1413   network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages); | 
|  1320   for (rtc::MessageList::iterator it = rtcp_messages.begin(); |  1414   for (const auto& message : rtcp_messages) { | 
|  1321        it != rtcp_messages.end(); ++it) { |  1415     network_thread_->Send(this, MSG_SEND_RTCP_PACKET, message.pdata); | 
|  1322     worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata); |  | 
|  1323   } |  1416   } | 
|  1324 } |  1417 } | 
|  1325  |  1418  | 
|  1326 VoiceChannel::VoiceChannel(rtc::Thread* thread, |  1419 void BaseChannel::SignalSentPacket_n(TransportChannel* /* channel */, | 
 |  1420                                      const rtc::SentPacket& sent_packet) { | 
 |  1421   RTC_DCHECK(network_thread_->IsCurrent()); | 
 |  1422   invoker_.AsyncInvoke<void>( | 
 |  1423       worker_thread_, | 
 |  1424       rtc::Bind(&BaseChannel::SignalSentPacket_w, this, sent_packet)); | 
 |  1425 } | 
 |  1426  | 
 |  1427 void BaseChannel::SignalSentPacket_w(const rtc::SentPacket& sent_packet) { | 
 |  1428   RTC_DCHECK(worker_thread_->IsCurrent()); | 
 |  1429   SignalSentPacket(sent_packet); | 
 |  1430 } | 
 |  1431  | 
 |  1432 VoiceChannel::VoiceChannel(rtc::Thread* worker_thread, | 
 |  1433                            rtc::Thread* network_thread, | 
|  1327                            MediaEngineInterface* media_engine, |  1434                            MediaEngineInterface* media_engine, | 
|  1328                            VoiceMediaChannel* media_channel, |  1435                            VoiceMediaChannel* media_channel, | 
|  1329                            TransportController* transport_controller, |  1436                            TransportController* transport_controller, | 
|  1330                            const std::string& content_name, |  1437                            const std::string& content_name, | 
|  1331                            bool rtcp) |  1438                            bool rtcp) | 
|  1332     : BaseChannel(thread, |  1439     : BaseChannel(worker_thread, | 
 |  1440                   network_thread, | 
|  1333                   media_channel, |  1441                   media_channel, | 
|  1334                   transport_controller, |  1442                   transport_controller, | 
|  1335                   content_name, |  1443                   content_name, | 
|  1336                   rtcp), |  1444                   rtcp), | 
|  1337       media_engine_(media_engine), |  1445       media_engine_(media_engine), | 
|  1338       received_media_(false) {} |  1446       received_media_(false) {} | 
|  1339  |  1447  | 
|  1340 VoiceChannel::~VoiceChannel() { |  1448 VoiceChannel::~VoiceChannel() { | 
|  1341   TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); |  1449   TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); | 
|  1342   StopAudioMonitor(); |  1450   StopAudioMonitor(); | 
|  1343   StopMediaMonitor(); |  1451   StopMediaMonitor(); | 
|  1344   // this can't be done in the base class, since it calls a virtual |  1452   // this can't be done in the base class, since it calls a virtual | 
|  1345   DisableMedia_w(); |  1453   DisableMedia_w(); | 
|  1346   Deinit(); |  1454   Deinit(); | 
|  1347 } |  1455 } | 
|  1348  |  1456  | 
|  1349 bool VoiceChannel::Init() { |  1457 bool VoiceChannel::Init_w() { | 
|  1350   if (!BaseChannel::Init()) { |  1458   if (!BaseChannel::Init_w()) { | 
|  1351     return false; |  1459     return false; | 
|  1352   } |  1460   } | 
|  1353   return true; |  1461   return true; | 
|  1354 } |  1462 } | 
|  1355  |  1463  | 
|  1356 bool VoiceChannel::SetAudioSend(uint32_t ssrc, |  1464 bool VoiceChannel::SetAudioSend(uint32_t ssrc, | 
|  1357                                 bool enable, |  1465                                 bool enable, | 
|  1358                                 const AudioOptions* options, |  1466                                 const AudioOptions* options, | 
|  1359                                 AudioSource* source) { |  1467                                 AudioSource* source) { | 
|  1360   return InvokeOnWorker(Bind(&VoiceMediaChannel::SetAudioSend, media_channel(), |  1468   return InvokeOnWorker(Bind(&VoiceMediaChannel::SetAudioSend, media_channel(), | 
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1480                                 int flags) { |  1588                                 int flags) { | 
|  1481   BaseChannel::OnChannelRead(channel, data, len, packet_time, flags); |  1589   BaseChannel::OnChannelRead(channel, data, len, packet_time, flags); | 
|  1482  |  1590  | 
|  1483   // Set a flag when we've received an RTP packet. If we're waiting for early |  1591   // Set a flag when we've received an RTP packet. If we're waiting for early | 
|  1484   // media, this will disable the timeout. |  1592   // media, this will disable the timeout. | 
|  1485   if (!received_media_ && !PacketIsRtcp(channel, data, len)) { |  1593   if (!received_media_ && !PacketIsRtcp(channel, data, len)) { | 
|  1486     received_media_ = true; |  1594     received_media_ = true; | 
|  1487   } |  1595   } | 
|  1488 } |  1596 } | 
|  1489  |  1597  | 
|  1490 void VoiceChannel::ChangeState() { |  1598 void BaseChannel::ChangeState() { | 
 |  1599   RTC_DCHECK(network_thread_->IsCurrent()); | 
 |  1600   invoker_.AsyncInvoke<void>(worker_thread_, | 
 |  1601                              Bind(&BaseChannel::ChangeState_w, this)); | 
 |  1602 } | 
 |  1603  | 
 |  1604 void VoiceChannel::ChangeState_w() { | 
|  1491   // Render incoming data if we're the active call, and we have the local |  1605   // Render incoming data if we're the active call, and we have the local | 
|  1492   // content. We receive data on the default channel and multiplexed streams. |  1606   // content. We receive data on the default channel and multiplexed streams. | 
|  1493   bool recv = IsReadyToReceive(); |  1607   bool recv = IsReadyToReceive_w(); | 
|  1494   media_channel()->SetPlayout(recv); |  1608   media_channel()->SetPlayout(recv); | 
|  1495  |  1609  | 
|  1496   // Send outgoing data if we're the active call, we have the remote content, |  1610   // Send outgoing data if we're the active call, we have the remote content, | 
|  1497   // and we have had some form of connectivity. |  1611   // and we have had some form of connectivity. | 
|  1498   bool send = IsReadyToSend(); |  1612   bool send = IsReadyToSend_w(); | 
|  1499   media_channel()->SetSend(send); |  1613   media_channel()->SetSend(send); | 
|  1500  |  1614  | 
|  1501   LOG(LS_INFO) << "Changing voice state, recv=" << recv << " send=" << send; |  1615   LOG(LS_INFO) << "Changing voice state, recv=" << recv << " send=" << send; | 
|  1502 } |  1616 } | 
|  1503  |  1617  | 
|  1504 const ContentInfo* VoiceChannel::GetFirstContent( |  1618 const ContentInfo* VoiceChannel::GetFirstContent( | 
|  1505     const SessionDescription* sdesc) { |  1619     const SessionDescription* sdesc) { | 
|  1506   return GetFirstAudioContent(sdesc); |  1620   return GetFirstAudioContent(sdesc); | 
|  1507 } |  1621 } | 
|  1508  |  1622  | 
|  1509 bool VoiceChannel::SetLocalContent_w(const MediaContentDescription* content, |  1623 bool VoiceChannel::SetLocalContent_w(const MediaContentDescription* content, | 
|  1510                                      ContentAction action, |  1624                                      ContentAction action, | 
|  1511                                      std::string* error_desc) { |  1625                                      std::string* error_desc) { | 
|  1512   TRACE_EVENT0("webrtc", "VoiceChannel::SetLocalContent_w"); |  1626   TRACE_EVENT0("webrtc", "VoiceChannel::SetLocalContent_w"); | 
|  1513   ASSERT(worker_thread() == rtc::Thread::Current()); |  1627   ASSERT(worker_thread() == rtc::Thread::Current()); | 
|  1514   LOG(LS_INFO) << "Setting local voice description"; |  1628   LOG(LS_INFO) << "Setting local voice description"; | 
|  1515  |  1629  | 
|  1516   const AudioContentDescription* audio = |  1630   const AudioContentDescription* audio = | 
|  1517       static_cast<const AudioContentDescription*>(content); |  1631       static_cast<const AudioContentDescription*>(content); | 
|  1518   ASSERT(audio != NULL); |  1632   ASSERT(audio != NULL); | 
|  1519   if (!audio) { |  1633   if (!audio) { | 
|  1520     SafeSetError("Can't find audio content in local description.", error_desc); |  1634     SafeSetError("Can't find audio content in local description.", error_desc); | 
|  1521     return false; |  1635     return false; | 
|  1522   } |  1636   } | 
|  1523  |  1637  | 
|  1524   if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) { |  1638   if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) { | 
|  1525     return false; |  1639     return false; | 
|  1526   } |  1640   } | 
|  1527  |  1641  | 
|  1528   AudioRecvParameters recv_params = last_recv_params_; |  1642   AudioRecvParameters recv_params = last_recv_params_; | 
|  1529   RtpParametersFromMediaDescription(audio, &recv_params); |  1643   RtpParametersFromMediaDescription(audio, &recv_params); | 
|  1530   if (!media_channel()->SetRecvParameters(recv_params)) { |  1644   if (!media_channel()->SetRecvParameters(recv_params)) { | 
|  1531     SafeSetError("Failed to set local audio description recv parameters.", |  1645     SafeSetError("Failed to set local audio description recv parameters.", | 
|  1532                  error_desc); |  1646                  error_desc); | 
|  1533     return false; |  1647     return false; | 
|  1534   } |  1648   } | 
|  1535   for (const AudioCodec& codec : audio->codecs()) { |  1649   for (const AudioCodec& codec : audio->codecs()) { | 
|  1536     bundle_filter()->AddPayloadType(codec.id); |  1650     bundle_filter()->AddPayloadType(codec.id); | 
|  1537   } |  1651   } | 
|  1538   last_recv_params_ = recv_params; |  1652   last_recv_params_ = recv_params; | 
|  1539  |  1653  | 
|  1540   // TODO(pthatcher): Move local streams into AudioSendParameters, and |  1654   // TODO(pthatcher): Move local streams into AudioSendParameters, and | 
|  1541   // only give it to the media channel once we have a remote |  1655   // only give it to the media channel once we have a remote | 
|  1542   // description too (without a remote description, we won't be able |  1656   // description too (without a remote description, we won't be able | 
|  1543   // to send them anyway). |  1657   // to send them anyway). | 
|  1544   if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) { |  1658   if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) { | 
|  1545     SafeSetError("Failed to set local audio description streams.", error_desc); |  1659     SafeSetError("Failed to set local audio description streams.", error_desc); | 
|  1546     return false; |  1660     return false; | 
|  1547   } |  1661   } | 
|  1548  |  1662  | 
|  1549   set_local_content_direction(content->direction()); |  1663   set_local_content_direction(content->direction()); | 
|  1550   ChangeState(); |  1664   ChangeState_w(); | 
|  1551   return true; |  1665   return true; | 
|  1552 } |  1666 } | 
|  1553  |  1667  | 
|  1554 bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content, |  1668 bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content, | 
|  1555                                       ContentAction action, |  1669                                       ContentAction action, | 
|  1556                                       std::string* error_desc) { |  1670                                       std::string* error_desc) { | 
|  1557   TRACE_EVENT0("webrtc", "VoiceChannel::SetRemoteContent_w"); |  1671   TRACE_EVENT0("webrtc", "VoiceChannel::SetRemoteContent_w"); | 
|  1558   ASSERT(worker_thread() == rtc::Thread::Current()); |  1672   ASSERT(worker_thread() == rtc::Thread::Current()); | 
|  1559   LOG(LS_INFO) << "Setting remote voice description"; |  1673   LOG(LS_INFO) << "Setting remote voice description"; | 
|  1560  |  1674  | 
|  1561   const AudioContentDescription* audio = |  1675   const AudioContentDescription* audio = | 
|  1562       static_cast<const AudioContentDescription*>(content); |  1676       static_cast<const AudioContentDescription*>(content); | 
|  1563   ASSERT(audio != NULL); |  1677   ASSERT(audio != NULL); | 
|  1564   if (!audio) { |  1678   if (!audio) { | 
|  1565     SafeSetError("Can't find audio content in remote description.", error_desc); |  1679     SafeSetError("Can't find audio content in remote description.", error_desc); | 
|  1566     return false; |  1680     return false; | 
|  1567   } |  1681   } | 
|  1568  |  1682  | 
|  1569   if (!SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) { |  1683   if (!SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) { | 
|  1570     return false; |  1684     return false; | 
|  1571   } |  1685   } | 
|  1572  |  1686  | 
|  1573   AudioSendParameters send_params = last_send_params_; |  1687   AudioSendParameters send_params = last_send_params_; | 
|  1574   RtpSendParametersFromMediaDescription(audio, &send_params); |  1688   RtpSendParametersFromMediaDescription(audio, &send_params); | 
|  1575   if (audio->agc_minus_10db()) { |  1689   if (audio->agc_minus_10db()) { | 
|  1576     send_params.options.adjust_agc_delta = rtc::Optional<int>(kAgcMinus10db); |  1690     send_params.options.adjust_agc_delta = rtc::Optional<int>(kAgcMinus10db); | 
|  1577   } |  1691   } | 
|  1578  |  1692  | 
|  1579   bool parameters_applied = media_channel()->SetSendParameters(send_params); |  1693   bool parameters_applied = media_channel()->SetSendParameters(send_params); | 
|  1580   if (!parameters_applied) { |  1694   if (!parameters_applied) { | 
|  1581     SafeSetError("Failed to set remote audio description send parameters.", |  1695     SafeSetError("Failed to set remote audio description send parameters.", | 
|  1582                  error_desc); |  1696                  error_desc); | 
|  1583     return false; |  1697     return false; | 
|  1584   } |  1698   } | 
|  1585   last_send_params_ = send_params; |  1699   last_send_params_ = send_params; | 
|  1586  |  1700  | 
|  1587   // TODO(pthatcher): Move remote streams into AudioRecvParameters, |  1701   // TODO(pthatcher): Move remote streams into AudioRecvParameters, | 
|  1588   // and only give it to the media channel once we have a local |  1702   // and only give it to the media channel once we have a local | 
|  1589   // description too (without a local description, we won't be able to |  1703   // description too (without a local description, we won't be able to | 
|  1590   // recv them anyway). |  1704   // recv them anyway). | 
|  1591   if (!UpdateRemoteStreams_w(audio->streams(), action, error_desc)) { |  1705   if (!UpdateRemoteStreams_w(audio->streams(), action, error_desc)) { | 
|  1592     SafeSetError("Failed to set remote audio description streams.", error_desc); |  1706     SafeSetError("Failed to set remote audio description streams.", error_desc); | 
|  1593     return false; |  1707     return false; | 
|  1594   } |  1708   } | 
|  1595  |  1709  | 
|  1596   if (audio->rtp_header_extensions_set()) { |  1710   if (audio->rtp_header_extensions_set()) { | 
|  1597     MaybeCacheRtpAbsSendTimeHeaderExtension(audio->rtp_header_extensions()); |  1711     MaybeCacheRtpAbsSendTimeHeaderExtension_w(audio->rtp_header_extensions()); | 
|  1598   } |  1712   } | 
|  1599  |  1713  | 
|  1600   set_remote_content_direction(content->direction()); |  1714   set_remote_content_direction(content->direction()); | 
|  1601   ChangeState(); |  1715   ChangeState_w(); | 
|  1602   return true; |  1716   return true; | 
|  1603 } |  1717 } | 
|  1604  |  1718  | 
|  1605 void VoiceChannel::HandleEarlyMediaTimeout() { |  1719 void VoiceChannel::HandleEarlyMediaTimeout() { | 
|  1606   // This occurs on the main thread, not the worker thread. |  1720   // This occurs on the main thread, not the worker thread. | 
|  1607   if (!received_media_) { |  1721   if (!received_media_) { | 
|  1608     LOG(LS_INFO) << "No early media received before timeout"; |  1722     LOG(LS_INFO) << "No early media received before timeout"; | 
|  1609     SignalEarlyMediaTimeout(this); |  1723     SignalEarlyMediaTimeout(this); | 
|  1610   } |  1724   } | 
|  1611 } |  1725 } | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1645     VoiceMediaChannel* media_channel, const VoiceMediaInfo& info) { |  1759     VoiceMediaChannel* media_channel, const VoiceMediaInfo& info) { | 
|  1646   ASSERT(media_channel == this->media_channel()); |  1760   ASSERT(media_channel == this->media_channel()); | 
|  1647   SignalMediaMonitor(this, info); |  1761   SignalMediaMonitor(this, info); | 
|  1648 } |  1762 } | 
|  1649  |  1763  | 
|  1650 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, |  1764 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, | 
|  1651                                         const AudioInfo& info) { |  1765                                         const AudioInfo& info) { | 
|  1652   SignalAudioMonitor(this, info); |  1766   SignalAudioMonitor(this, info); | 
|  1653 } |  1767 } | 
|  1654  |  1768  | 
|  1655 void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |  1769 void VoiceChannel::GetSrtpCryptoSuites_n( | 
 |  1770     std::vector<int>* crypto_suites) const { | 
|  1656   GetSupportedAudioCryptoSuites(crypto_suites); |  1771   GetSupportedAudioCryptoSuites(crypto_suites); | 
|  1657 } |  1772 } | 
|  1658  |  1773  | 
|  1659 VideoChannel::VideoChannel(rtc::Thread* thread, |  1774 VideoChannel::VideoChannel(rtc::Thread* worker_thread, | 
 |  1775                            rtc::Thread* network_thread, | 
|  1660                            VideoMediaChannel* media_channel, |  1776                            VideoMediaChannel* media_channel, | 
|  1661                            TransportController* transport_controller, |  1777                            TransportController* transport_controller, | 
|  1662                            const std::string& content_name, |  1778                            const std::string& content_name, | 
|  1663                            bool rtcp) |  1779                            bool rtcp) | 
|  1664     : BaseChannel(thread, |  1780     : BaseChannel(worker_thread, | 
 |  1781                   network_thread, | 
|  1665                   media_channel, |  1782                   media_channel, | 
|  1666                   transport_controller, |  1783                   transport_controller, | 
|  1667                   content_name, |  1784                   content_name, | 
|  1668                   rtcp) {} |  1785                   rtcp) {} | 
|  1669  |  1786  | 
|  1670 bool VideoChannel::Init() { |  1787 bool VideoChannel::Init_w() { | 
|  1671   if (!BaseChannel::Init()) { |  1788   if (!BaseChannel::Init_w()) { | 
|  1672     return false; |  1789     return false; | 
|  1673   } |  1790   } | 
|  1674   return true; |  1791   return true; | 
|  1675 } |  1792 } | 
|  1676  |  1793  | 
|  1677 VideoChannel::~VideoChannel() { |  1794 VideoChannel::~VideoChannel() { | 
|  1678   TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel"); |  1795   TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel"); | 
|  1679   StopMediaMonitor(); |  1796   StopMediaMonitor(); | 
|  1680   // this can't be done in the base class, since it calls a virtual |  1797   // this can't be done in the base class, since it calls a virtual | 
|  1681   DisableMedia_w(); |  1798   DisableMedia_w(); | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1716 bool VideoChannel::SetRtpParameters(uint32_t ssrc, |  1833 bool VideoChannel::SetRtpParameters(uint32_t ssrc, | 
|  1717                                     const webrtc::RtpParameters& parameters) { |  1834                                     const webrtc::RtpParameters& parameters) { | 
|  1718   return InvokeOnWorker( |  1835   return InvokeOnWorker( | 
|  1719       Bind(&VideoChannel::SetRtpParameters_w, this, ssrc, parameters)); |  1836       Bind(&VideoChannel::SetRtpParameters_w, this, ssrc, parameters)); | 
|  1720 } |  1837 } | 
|  1721  |  1838  | 
|  1722 bool VideoChannel::SetRtpParameters_w(uint32_t ssrc, |  1839 bool VideoChannel::SetRtpParameters_w(uint32_t ssrc, | 
|  1723                                       webrtc::RtpParameters parameters) { |  1840                                       webrtc::RtpParameters parameters) { | 
|  1724   return media_channel()->SetRtpParameters(ssrc, parameters); |  1841   return media_channel()->SetRtpParameters(ssrc, parameters); | 
|  1725 } |  1842 } | 
|  1726 void VideoChannel::ChangeState() { |  1843  | 
 |  1844 void VideoChannel::ChangeState_w() { | 
|  1727   // Send outgoing data if we're the active call, we have the remote content, |  1845   // Send outgoing data if we're the active call, we have the remote content, | 
|  1728   // and we have had some form of connectivity. |  1846   // and we have had some form of connectivity. | 
|  1729   bool send = IsReadyToSend(); |  1847   bool send = IsReadyToSend_w(); | 
|  1730   if (!media_channel()->SetSend(send)) { |  1848   if (!media_channel()->SetSend(send)) { | 
|  1731     LOG(LS_ERROR) << "Failed to SetSend on video channel"; |  1849     LOG(LS_ERROR) << "Failed to SetSend on video channel"; | 
|  1732     // TODO(gangji): Report error back to server. |  1850     // TODO(gangji): Report error back to server. | 
|  1733   } |  1851   } | 
|  1734  |  1852  | 
|  1735   LOG(LS_INFO) << "Changing video state, send=" << send; |  1853   LOG(LS_INFO) << "Changing video state, send=" << send; | 
|  1736 } |  1854 } | 
|  1737  |  1855  | 
|  1738 bool VideoChannel::GetStats(VideoMediaInfo* stats) { |  1856 bool VideoChannel::GetStats(VideoMediaInfo* stats) { | 
|  1739   return InvokeOnWorker( |  1857   return InvokeOnWorker( | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
|  1768   LOG(LS_INFO) << "Setting local video description"; |  1886   LOG(LS_INFO) << "Setting local video description"; | 
|  1769  |  1887  | 
|  1770   const VideoContentDescription* video = |  1888   const VideoContentDescription* video = | 
|  1771       static_cast<const VideoContentDescription*>(content); |  1889       static_cast<const VideoContentDescription*>(content); | 
|  1772   ASSERT(video != NULL); |  1890   ASSERT(video != NULL); | 
|  1773   if (!video) { |  1891   if (!video) { | 
|  1774     SafeSetError("Can't find video content in local description.", error_desc); |  1892     SafeSetError("Can't find video content in local description.", error_desc); | 
|  1775     return false; |  1893     return false; | 
|  1776   } |  1894   } | 
|  1777  |  1895  | 
|  1778   if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) { |  1896   if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) { | 
|  1779     return false; |  1897     return false; | 
|  1780   } |  1898   } | 
|  1781  |  1899  | 
|  1782   VideoRecvParameters recv_params = last_recv_params_; |  1900   VideoRecvParameters recv_params = last_recv_params_; | 
|  1783   RtpParametersFromMediaDescription(video, &recv_params); |  1901   RtpParametersFromMediaDescription(video, &recv_params); | 
|  1784   if (!media_channel()->SetRecvParameters(recv_params)) { |  1902   if (!media_channel()->SetRecvParameters(recv_params)) { | 
|  1785     SafeSetError("Failed to set local video description recv parameters.", |  1903     SafeSetError("Failed to set local video description recv parameters.", | 
|  1786                  error_desc); |  1904                  error_desc); | 
|  1787     return false; |  1905     return false; | 
|  1788   } |  1906   } | 
|  1789   for (const VideoCodec& codec : video->codecs()) { |  1907   for (const VideoCodec& codec : video->codecs()) { | 
|  1790     bundle_filter()->AddPayloadType(codec.id); |  1908     bundle_filter()->AddPayloadType(codec.id); | 
|  1791   } |  1909   } | 
|  1792   last_recv_params_ = recv_params; |  1910   last_recv_params_ = recv_params; | 
|  1793  |  1911  | 
|  1794   // TODO(pthatcher): Move local streams into VideoSendParameters, and |  1912   // TODO(pthatcher): Move local streams into VideoSendParameters, and | 
|  1795   // only give it to the media channel once we have a remote |  1913   // only give it to the media channel once we have a remote | 
|  1796   // description too (without a remote description, we won't be able |  1914   // description too (without a remote description, we won't be able | 
|  1797   // to send them anyway). |  1915   // to send them anyway). | 
|  1798   if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) { |  1916   if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) { | 
|  1799     SafeSetError("Failed to set local video description streams.", error_desc); |  1917     SafeSetError("Failed to set local video description streams.", error_desc); | 
|  1800     return false; |  1918     return false; | 
|  1801   } |  1919   } | 
|  1802  |  1920  | 
|  1803   set_local_content_direction(content->direction()); |  1921   set_local_content_direction(content->direction()); | 
|  1804   ChangeState(); |  1922   ChangeState_w(); | 
|  1805   return true; |  1923   return true; | 
|  1806 } |  1924 } | 
|  1807  |  1925  | 
|  1808 bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, |  1926 bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, | 
|  1809                                       ContentAction action, |  1927                                       ContentAction action, | 
|  1810                                       std::string* error_desc) { |  1928                                       std::string* error_desc) { | 
|  1811   TRACE_EVENT0("webrtc", "VideoChannel::SetRemoteContent_w"); |  1929   TRACE_EVENT0("webrtc", "VideoChannel::SetRemoteContent_w"); | 
|  1812   ASSERT(worker_thread() == rtc::Thread::Current()); |  1930   ASSERT(worker_thread() == rtc::Thread::Current()); | 
|  1813   LOG(LS_INFO) << "Setting remote video description"; |  1931   LOG(LS_INFO) << "Setting remote video description"; | 
|  1814  |  1932  | 
|  1815   const VideoContentDescription* video = |  1933   const VideoContentDescription* video = | 
|  1816       static_cast<const VideoContentDescription*>(content); |  1934       static_cast<const VideoContentDescription*>(content); | 
|  1817   ASSERT(video != NULL); |  1935   ASSERT(video != NULL); | 
|  1818   if (!video) { |  1936   if (!video) { | 
|  1819     SafeSetError("Can't find video content in remote description.", error_desc); |  1937     SafeSetError("Can't find video content in remote description.", error_desc); | 
|  1820     return false; |  1938     return false; | 
|  1821   } |  1939   } | 
|  1822  |  1940  | 
|  1823  |  1941   if (!SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) { | 
|  1824   if (!SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) { |  | 
|  1825     return false; |  1942     return false; | 
|  1826   } |  1943   } | 
|  1827  |  1944  | 
|  1828   VideoSendParameters send_params = last_send_params_; |  1945   VideoSendParameters send_params = last_send_params_; | 
|  1829   RtpSendParametersFromMediaDescription(video, &send_params); |  1946   RtpSendParametersFromMediaDescription(video, &send_params); | 
|  1830   if (video->conference_mode()) { |  1947   if (video->conference_mode()) { | 
|  1831     send_params.conference_mode = true; |  1948     send_params.conference_mode = true; | 
|  1832   } |  1949   } | 
|  1833  |  1950  | 
|  1834   bool parameters_applied = media_channel()->SetSendParameters(send_params); |  1951   bool parameters_applied = media_channel()->SetSendParameters(send_params); | 
|  1835  |  1952  | 
|  1836   if (!parameters_applied) { |  1953   if (!parameters_applied) { | 
|  1837     SafeSetError("Failed to set remote video description send parameters.", |  1954     SafeSetError("Failed to set remote video description send parameters.", | 
|  1838                  error_desc); |  1955                  error_desc); | 
|  1839     return false; |  1956     return false; | 
|  1840   } |  1957   } | 
|  1841   last_send_params_ = send_params; |  1958   last_send_params_ = send_params; | 
|  1842  |  1959  | 
|  1843   // TODO(pthatcher): Move remote streams into VideoRecvParameters, |  1960   // TODO(pthatcher): Move remote streams into VideoRecvParameters, | 
|  1844   // and only give it to the media channel once we have a local |  1961   // and only give it to the media channel once we have a local | 
|  1845   // description too (without a local description, we won't be able to |  1962   // description too (without a local description, we won't be able to | 
|  1846   // recv them anyway). |  1963   // recv them anyway). | 
|  1847   if (!UpdateRemoteStreams_w(video->streams(), action, error_desc)) { |  1964   if (!UpdateRemoteStreams_w(video->streams(), action, error_desc)) { | 
|  1848     SafeSetError("Failed to set remote video description streams.", error_desc); |  1965     SafeSetError("Failed to set remote video description streams.", error_desc); | 
|  1849     return false; |  1966     return false; | 
|  1850   } |  1967   } | 
|  1851  |  1968  | 
|  1852   if (video->rtp_header_extensions_set()) { |  1969   if (video->rtp_header_extensions_set()) { | 
|  1853     MaybeCacheRtpAbsSendTimeHeaderExtension(video->rtp_header_extensions()); |  1970     MaybeCacheRtpAbsSendTimeHeaderExtension_w(video->rtp_header_extensions()); | 
|  1854   } |  1971   } | 
|  1855  |  1972  | 
|  1856   set_remote_content_direction(content->direction()); |  1973   set_remote_content_direction(content->direction()); | 
|  1857   ChangeState(); |  1974   ChangeState_w(); | 
|  1858   return true; |  1975   return true; | 
|  1859 } |  1976 } | 
|  1860  |  1977  | 
|  1861 void VideoChannel::OnMessage(rtc::Message *pmsg) { |  1978 void VideoChannel::OnMessage(rtc::Message *pmsg) { | 
|  1862   switch (pmsg->message_id) { |  1979   switch (pmsg->message_id) { | 
|  1863     case MSG_CHANNEL_ERROR: { |  1980     case MSG_CHANNEL_ERROR: { | 
|  1864       const VideoChannelErrorMessageData* data = |  1981       const VideoChannelErrorMessageData* data = | 
|  1865           static_cast<VideoChannelErrorMessageData*>(pmsg->pdata); |  1982           static_cast<VideoChannelErrorMessageData*>(pmsg->pdata); | 
|  1866       delete data; |  1983       delete data; | 
|  1867       break; |  1984       break; | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  1878 } |  1995 } | 
|  1879  |  1996  | 
|  1880 // TODO(pthatcher): Look into removing duplicate code between |  1997 // TODO(pthatcher): Look into removing duplicate code between | 
|  1881 // audio, video, and data, perhaps by using templates. |  1998 // audio, video, and data, perhaps by using templates. | 
|  1882 void VideoChannel::OnMediaMonitorUpdate( |  1999 void VideoChannel::OnMediaMonitorUpdate( | 
|  1883     VideoMediaChannel* media_channel, const VideoMediaInfo &info) { |  2000     VideoMediaChannel* media_channel, const VideoMediaInfo &info) { | 
|  1884   ASSERT(media_channel == this->media_channel()); |  2001   ASSERT(media_channel == this->media_channel()); | 
|  1885   SignalMediaMonitor(this, info); |  2002   SignalMediaMonitor(this, info); | 
|  1886 } |  2003 } | 
|  1887  |  2004  | 
|  1888 void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |  2005 void VideoChannel::GetSrtpCryptoSuites_n( | 
 |  2006     std::vector<int>* crypto_suites) const { | 
|  1889   GetSupportedVideoCryptoSuites(crypto_suites); |  2007   GetSupportedVideoCryptoSuites(crypto_suites); | 
|  1890 } |  2008 } | 
|  1891  |  2009  | 
|  1892 DataChannel::DataChannel(rtc::Thread* thread, |  2010 DataChannel::DataChannel(rtc::Thread* worker_thread, | 
 |  2011                          rtc::Thread* network_thread, | 
|  1893                          DataMediaChannel* media_channel, |  2012                          DataMediaChannel* media_channel, | 
|  1894                          TransportController* transport_controller, |  2013                          TransportController* transport_controller, | 
|  1895                          const std::string& content_name, |  2014                          const std::string& content_name, | 
|  1896                          bool rtcp) |  2015                          bool rtcp) | 
|  1897     : BaseChannel(thread, |  2016     : BaseChannel(worker_thread, | 
 |  2017                   network_thread, | 
|  1898                   media_channel, |  2018                   media_channel, | 
|  1899                   transport_controller, |  2019                   transport_controller, | 
|  1900                   content_name, |  2020                   content_name, | 
|  1901                   rtcp), |  2021                   rtcp), | 
|  1902       data_channel_type_(cricket::DCT_NONE), |  2022       data_channel_type_(cricket::DCT_NONE), | 
|  1903       ready_to_send_data_(false) {} |  2023       ready_to_send_data_(false) {} | 
|  1904  |  2024  | 
|  1905 DataChannel::~DataChannel() { |  2025 DataChannel::~DataChannel() { | 
|  1906   TRACE_EVENT0("webrtc", "DataChannel::~DataChannel"); |  2026   TRACE_EVENT0("webrtc", "DataChannel::~DataChannel"); | 
|  1907   StopMediaMonitor(); |  2027   StopMediaMonitor(); | 
|  1908   // this can't be done in the base class, since it calls a virtual |  2028   // this can't be done in the base class, since it calls a virtual | 
|  1909   DisableMedia_w(); |  2029   DisableMedia_w(); | 
|  1910  |  2030  | 
|  1911   Deinit(); |  2031   Deinit(); | 
|  1912 } |  2032 } | 
|  1913  |  2033  | 
|  1914 bool DataChannel::Init() { |  2034 bool DataChannel::Init_w() { | 
|  1915   if (!BaseChannel::Init()) { |  2035   if (!BaseChannel::Init_w()) { | 
|  1916     return false; |  2036     return false; | 
|  1917   } |  2037   } | 
|  1918   media_channel()->SignalDataReceived.connect( |  2038   media_channel()->SignalDataReceived.connect( | 
|  1919       this, &DataChannel::OnDataReceived); |  2039       this, &DataChannel::OnDataReceived); | 
|  1920   media_channel()->SignalReadyToSend.connect( |  2040   media_channel()->SignalReadyToSend.connect( | 
|  1921       this, &DataChannel::OnDataChannelReadyToSend); |  2041       this, &DataChannel::OnDataChannelReadyToSend); | 
|  1922   media_channel()->SignalStreamClosedRemotely.connect( |  2042   media_channel()->SignalStreamClosedRemotely.connect( | 
|  1923       this, &DataChannel::OnStreamClosedRemotely); |  2043       this, &DataChannel::OnStreamClosedRemotely); | 
|  1924   return true; |  2044   return true; | 
|  1925 } |  2045 } | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1991   if (!data) { |  2111   if (!data) { | 
|  1992     SafeSetError("Can't find data content in local description.", error_desc); |  2112     SafeSetError("Can't find data content in local description.", error_desc); | 
|  1993     return false; |  2113     return false; | 
|  1994   } |  2114   } | 
|  1995  |  2115  | 
|  1996   if (!SetDataChannelTypeFromContent(data, error_desc)) { |  2116   if (!SetDataChannelTypeFromContent(data, error_desc)) { | 
|  1997     return false; |  2117     return false; | 
|  1998   } |  2118   } | 
|  1999  |  2119  | 
|  2000   if (data_channel_type_ == DCT_RTP) { |  2120   if (data_channel_type_ == DCT_RTP) { | 
|  2001     if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) { |  2121     if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) { | 
|  2002       return false; |  2122       return false; | 
|  2003     } |  2123     } | 
|  2004   } |  2124   } | 
|  2005  |  2125  | 
|  2006   // FYI: We send the SCTP port number (not to be confused with the |  2126   // FYI: We send the SCTP port number (not to be confused with the | 
|  2007   // underlying UDP port number) as a codec parameter.  So even SCTP |  2127   // underlying UDP port number) as a codec parameter.  So even SCTP | 
|  2008   // data channels need codecs. |  2128   // data channels need codecs. | 
|  2009   DataRecvParameters recv_params = last_recv_params_; |  2129   DataRecvParameters recv_params = last_recv_params_; | 
|  2010   RtpParametersFromMediaDescription(data, &recv_params); |  2130   RtpParametersFromMediaDescription(data, &recv_params); | 
|  2011   if (!media_channel()->SetRecvParameters(recv_params)) { |  2131   if (!media_channel()->SetRecvParameters(recv_params)) { | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|  2023   // TODO(pthatcher): Move local streams into DataSendParameters, and |  2143   // TODO(pthatcher): Move local streams into DataSendParameters, and | 
|  2024   // only give it to the media channel once we have a remote |  2144   // only give it to the media channel once we have a remote | 
|  2025   // description too (without a remote description, we won't be able |  2145   // description too (without a remote description, we won't be able | 
|  2026   // to send them anyway). |  2146   // to send them anyway). | 
|  2027   if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { |  2147   if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { | 
|  2028     SafeSetError("Failed to set local data description streams.", error_desc); |  2148     SafeSetError("Failed to set local data description streams.", error_desc); | 
|  2029     return false; |  2149     return false; | 
|  2030   } |  2150   } | 
|  2031  |  2151  | 
|  2032   set_local_content_direction(content->direction()); |  2152   set_local_content_direction(content->direction()); | 
|  2033   ChangeState(); |  2153   ChangeState_w(); | 
|  2034   return true; |  2154   return true; | 
|  2035 } |  2155 } | 
|  2036  |  2156  | 
|  2037 bool DataChannel::SetRemoteContent_w(const MediaContentDescription* content, |  2157 bool DataChannel::SetRemoteContent_w(const MediaContentDescription* content, | 
|  2038                                      ContentAction action, |  2158                                      ContentAction action, | 
|  2039                                      std::string* error_desc) { |  2159                                      std::string* error_desc) { | 
|  2040   TRACE_EVENT0("webrtc", "DataChannel::SetRemoteContent_w"); |  2160   TRACE_EVENT0("webrtc", "DataChannel::SetRemoteContent_w"); | 
|  2041   ASSERT(worker_thread() == rtc::Thread::Current()); |  2161   ASSERT(worker_thread() == rtc::Thread::Current()); | 
|  2042  |  2162  | 
|  2043   const DataContentDescription* data = |  2163   const DataContentDescription* data = | 
|  2044       static_cast<const DataContentDescription*>(content); |  2164       static_cast<const DataContentDescription*>(content); | 
|  2045   ASSERT(data != NULL); |  2165   ASSERT(data != NULL); | 
|  2046   if (!data) { |  2166   if (!data) { | 
|  2047     SafeSetError("Can't find data content in remote description.", error_desc); |  2167     SafeSetError("Can't find data content in remote description.", error_desc); | 
|  2048     return false; |  2168     return false; | 
|  2049   } |  2169   } | 
|  2050  |  2170  | 
|  2051   // If the remote data doesn't have codecs and isn't an update, it |  2171   // If the remote data doesn't have codecs and isn't an update, it | 
|  2052   // must be empty, so ignore it. |  2172   // must be empty, so ignore it. | 
|  2053   if (!data->has_codecs() && action != CA_UPDATE) { |  2173   if (!data->has_codecs() && action != CA_UPDATE) { | 
|  2054     return true; |  2174     return true; | 
|  2055   } |  2175   } | 
|  2056  |  2176  | 
|  2057   if (!SetDataChannelTypeFromContent(data, error_desc)) { |  2177   if (!SetDataChannelTypeFromContent(data, error_desc)) { | 
|  2058     return false; |  2178     return false; | 
|  2059   } |  2179   } | 
|  2060  |  2180  | 
|  2061   LOG(LS_INFO) << "Setting remote data description"; |  2181   LOG(LS_INFO) << "Setting remote data description"; | 
|  2062   if (data_channel_type_ == DCT_RTP && |  2182   if (data_channel_type_ == DCT_RTP && | 
|  2063       !SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) { |  2183       !SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) { | 
|  2064     return false; |  2184     return false; | 
|  2065   } |  2185   } | 
|  2066  |  2186  | 
|  2067  |  2187  | 
|  2068   DataSendParameters send_params = last_send_params_; |  2188   DataSendParameters send_params = last_send_params_; | 
|  2069   RtpSendParametersFromMediaDescription<DataCodec>(data, &send_params); |  2189   RtpSendParametersFromMediaDescription<DataCodec>(data, &send_params); | 
|  2070   if (!media_channel()->SetSendParameters(send_params)) { |  2190   if (!media_channel()->SetSendParameters(send_params)) { | 
|  2071     SafeSetError("Failed to set remote data description send parameters.", |  2191     SafeSetError("Failed to set remote data description send parameters.", | 
|  2072                  error_desc); |  2192                  error_desc); | 
|  2073     return false; |  2193     return false; | 
|  2074   } |  2194   } | 
|  2075   last_send_params_ = send_params; |  2195   last_send_params_ = send_params; | 
|  2076  |  2196  | 
|  2077   // TODO(pthatcher): Move remote streams into DataRecvParameters, |  2197   // TODO(pthatcher): Move remote streams into DataRecvParameters, | 
|  2078   // and only give it to the media channel once we have a local |  2198   // and only give it to the media channel once we have a local | 
|  2079   // description too (without a local description, we won't be able to |  2199   // description too (without a local description, we won't be able to | 
|  2080   // recv them anyway). |  2200   // recv them anyway). | 
|  2081   if (!UpdateRemoteStreams_w(data->streams(), action, error_desc)) { |  2201   if (!UpdateRemoteStreams_w(data->streams(), action, error_desc)) { | 
|  2082     SafeSetError("Failed to set remote data description streams.", |  2202     SafeSetError("Failed to set remote data description streams.", | 
|  2083                  error_desc); |  2203                  error_desc); | 
|  2084     return false; |  2204     return false; | 
|  2085   } |  2205   } | 
|  2086  |  2206  | 
|  2087   set_remote_content_direction(content->direction()); |  2207   set_remote_content_direction(content->direction()); | 
|  2088   ChangeState(); |  2208   ChangeState_w(); | 
|  2089   return true; |  2209   return true; | 
|  2090 } |  2210 } | 
|  2091  |  2211  | 
|  2092 void DataChannel::ChangeState() { |  2212 void DataChannel::ChangeState_w() { | 
|  2093   // Render incoming data if we're the active call, and we have the local |  2213   // Render incoming data if we're the active call, and we have the local | 
|  2094   // content. We receive data on the default channel and multiplexed streams. |  2214   // content. We receive data on the default channel and multiplexed streams. | 
|  2095   bool recv = IsReadyToReceive(); |  2215   bool recv = IsReadyToReceive_w(); | 
|  2096   if (!media_channel()->SetReceive(recv)) { |  2216   if (!media_channel()->SetReceive(recv)) { | 
|  2097     LOG(LS_ERROR) << "Failed to SetReceive on data channel"; |  2217     LOG(LS_ERROR) << "Failed to SetReceive on data channel"; | 
|  2098   } |  2218   } | 
|  2099  |  2219  | 
|  2100   // Send outgoing data if we're the active call, we have the remote content, |  2220   // Send outgoing data if we're the active call, we have the remote content, | 
|  2101   // and we have had some form of connectivity. |  2221   // and we have had some form of connectivity. | 
|  2102   bool send = IsReadyToSend(); |  2222   bool send = IsReadyToSend_w(); | 
|  2103   if (!media_channel()->SetSend(send)) { |  2223   if (!media_channel()->SetSend(send)) { | 
|  2104     LOG(LS_ERROR) << "Failed to SetSend on data channel"; |  2224     LOG(LS_ERROR) << "Failed to SetSend on data channel"; | 
|  2105   } |  2225   } | 
|  2106  |  2226  | 
|  2107   // Trigger SignalReadyToSendData asynchronously. |  2227   // Trigger SignalReadyToSendData asynchronously. | 
|  2108   OnDataChannelReadyToSend(send); |  2228   OnDataChannelReadyToSend(send); | 
|  2109  |  2229  | 
|  2110   LOG(LS_INFO) << "Changing data state, recv=" << recv << " send=" << send; |  2230   LOG(LS_INFO) << "Changing data state, recv=" << recv << " send=" << send; | 
|  2111 } |  2231 } | 
|  2112  |  2232  | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2188 } |  2308 } | 
|  2189  |  2309  | 
|  2190 void DataChannel::OnDataChannelReadyToSend(bool writable) { |  2310 void DataChannel::OnDataChannelReadyToSend(bool writable) { | 
|  2191   // This is usded for congestion control to indicate that the stream is ready |  2311   // This is usded for congestion control to indicate that the stream is ready | 
|  2192   // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates |  2312   // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates | 
|  2193   // that the transport channel is ready. |  2313   // that the transport channel is ready. | 
|  2194   signaling_thread()->Post(this, MSG_READYTOSENDDATA, |  2314   signaling_thread()->Post(this, MSG_READYTOSENDDATA, | 
|  2195                            new DataChannelReadyToSendMessageData(writable)); |  2315                            new DataChannelReadyToSendMessageData(writable)); | 
|  2196 } |  2316 } | 
|  2197  |  2317  | 
|  2198 void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |  2318 void DataChannel::GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const { | 
|  2199   GetSupportedDataCryptoSuites(crypto_suites); |  2319   GetSupportedDataCryptoSuites(crypto_suites); | 
|  2200 } |  2320 } | 
|  2201  |  2321  | 
|  2202 bool DataChannel::ShouldSetupDtlsSrtp() const { |  2322 bool DataChannel::ShouldSetupDtlsSrtp_n() const { | 
|  2203   return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); |  2323   return data_channel_type_ == DCT_RTP && BaseChannel::ShouldSetupDtlsSrtp_n(); | 
|  2204 } |  2324 } | 
|  2205  |  2325  | 
|  2206 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |  2326 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 
|  2207   rtc::TypedMessageData<uint32_t>* message = |  2327   rtc::TypedMessageData<uint32_t>* message = | 
|  2208       new rtc::TypedMessageData<uint32_t>(sid); |  2328       new rtc::TypedMessageData<uint32_t>(sid); | 
|  2209   signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |  2329   signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 
|  2210 } |  2330 } | 
|  2211  |  2331  | 
|  2212 }  // namespace cricket |  2332 }  // namespace cricket | 
| OLD | NEW |