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 |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "webrtc/pc/channel.h" | 13 #include "webrtc/pc/channel.h" |
14 | 14 |
15 #include "webrtc/audio_sink.h" | 15 #include "webrtc/audio_sink.h" |
16 #include "webrtc/base/bind.h" | 16 #include "webrtc/base/bind.h" |
17 #include "webrtc/base/byteorder.h" | 17 #include "webrtc/base/byteorder.h" |
18 #include "webrtc/base/common.h" | 18 #include "webrtc/base/common.h" |
19 #include "webrtc/base/copyonwritebuffer.h" | 19 #include "webrtc/base/copyonwritebuffer.h" |
20 #include "webrtc/base/dscp.h" | 20 #include "webrtc/base/dscp.h" |
21 #include "webrtc/base/logging.h" | 21 #include "webrtc/base/logging.h" |
22 #include "webrtc/base/networkroute.h" | 22 #include "webrtc/base/networkroute.h" |
| 23 #include "webrtc/base/thread_scope.h" |
23 #include "webrtc/base/trace_event.h" | 24 #include "webrtc/base/trace_event.h" |
24 #include "webrtc/media/base/mediaconstants.h" | 25 #include "webrtc/media/base/mediaconstants.h" |
25 #include "webrtc/media/base/rtputils.h" | 26 #include "webrtc/media/base/rtputils.h" |
26 #include "webrtc/p2p/base/transportchannel.h" | 27 #include "webrtc/p2p/base/transportchannel.h" |
27 #include "webrtc/pc/channelmanager.h" | 28 #include "webrtc/pc/channelmanager.h" |
28 | 29 |
29 namespace cricket { | 30 namespace cricket { |
30 using rtc::Bind; | 31 using rtc::Bind; |
31 | 32 |
32 namespace { | 33 namespace { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // the media channel may try to send on the dead transport channel. NULLing | 193 // the media channel may try to send on the dead transport channel. NULLing |
193 // is not an effective strategy since the sends will come on another thread. | 194 // is not an effective strategy since the sends will come on another thread. |
194 delete media_channel_; | 195 delete media_channel_; |
195 // Note that we don't just call SetTransportChannel_n(nullptr) because that | 196 // Note that we don't just call SetTransportChannel_n(nullptr) because that |
196 // would call a pure virtual method which we can't do from a destructor. | 197 // 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 network_thread_->Invoke<void>(Bind(&BaseChannel::DeinitNetwork_n, this)); |
198 LOG(LS_INFO) << "Destroyed channel"; | 199 LOG(LS_INFO) << "Destroyed channel"; |
199 } | 200 } |
200 | 201 |
201 void BaseChannel::DeinitNetwork_n() { | 202 void BaseChannel::DeinitNetwork_n() { |
| 203 RTC_DCHECK_RUN_ON(network_thread_); |
| 204 |
202 if (transport_channel_) { | 205 if (transport_channel_) { |
203 DisconnectFromTransportChannel(transport_channel_); | 206 DisconnectFromTransportChannel(transport_channel_); |
204 transport_controller_->DestroyTransportChannel_n( | 207 transport_controller_->DestroyTransportChannel_n( |
205 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 208 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
206 } | 209 } |
207 if (rtcp_transport_channel_) { | 210 if (rtcp_transport_channel_) { |
208 DisconnectFromTransportChannel(rtcp_transport_channel_); | 211 DisconnectFromTransportChannel(rtcp_transport_channel_); |
209 transport_controller_->DestroyTransportChannel_n( | 212 transport_controller_->DestroyTransportChannel_n( |
210 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 213 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
211 } | 214 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 RTC_DCHECK(worker_thread_->IsCurrent()); | 247 RTC_DCHECK(worker_thread_->IsCurrent()); |
245 media_channel_->SetInterface(NULL); | 248 media_channel_->SetInterface(NULL); |
246 } | 249 } |
247 | 250 |
248 bool BaseChannel::SetTransport(const std::string& transport_name) { | 251 bool BaseChannel::SetTransport(const std::string& transport_name) { |
249 return network_thread_->Invoke<bool>( | 252 return network_thread_->Invoke<bool>( |
250 Bind(&BaseChannel::SetTransport_n, this, transport_name)); | 253 Bind(&BaseChannel::SetTransport_n, this, transport_name)); |
251 } | 254 } |
252 | 255 |
253 bool BaseChannel::SetTransport_n(const std::string& transport_name) { | 256 bool BaseChannel::SetTransport_n(const std::string& transport_name) { |
254 RTC_DCHECK(network_thread_->IsCurrent()); | 257 RTC_DCHECK_RUN_ON(network_thread_); |
255 | 258 |
256 if (transport_name == transport_name_) { | 259 if (transport_name == transport_name_) { |
257 // Nothing to do if transport name isn't changing | 260 // Nothing to do if transport name isn't changing |
258 return true; | 261 return true; |
259 } | 262 } |
260 | 263 |
261 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport | 264 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport |
262 // changes and wait until the DTLS handshake is complete to set the newly | 265 // changes and wait until the DTLS handshake is complete to set the newly |
263 // negotiated parameters. | 266 // negotiated parameters. |
264 if (ShouldSetupDtlsSrtp_n()) { | 267 if (ShouldSetupDtlsSrtp_n()) { |
(...skipping 28 matching lines...) Expand all Loading... |
293 // We can only update the RTCP ready to send after set_transport_channel has | 296 // We can only update the RTCP ready to send after set_transport_channel has |
294 // handled channel writability. | 297 // handled channel writability. |
295 SetReadyToSend( | 298 SetReadyToSend( |
296 true, rtcp_transport_channel_ && rtcp_transport_channel_->writable()); | 299 true, rtcp_transport_channel_ && rtcp_transport_channel_->writable()); |
297 } | 300 } |
298 transport_name_ = transport_name; | 301 transport_name_ = transport_name; |
299 return true; | 302 return true; |
300 } | 303 } |
301 | 304 |
302 void BaseChannel::SetTransportChannel_n(TransportChannel* new_tc) { | 305 void BaseChannel::SetTransportChannel_n(TransportChannel* new_tc) { |
303 RTC_DCHECK(network_thread_->IsCurrent()); | |
304 | |
305 TransportChannel* old_tc = transport_channel_; | 306 TransportChannel* old_tc = transport_channel_; |
306 if (!old_tc && !new_tc) { | 307 if (!old_tc && !new_tc) { |
307 // Nothing to do | 308 // Nothing to do |
308 return; | 309 return; |
309 } | 310 } |
310 ASSERT(old_tc != new_tc); | 311 ASSERT(old_tc != new_tc); |
311 | 312 |
312 if (old_tc) { | 313 if (old_tc) { |
313 DisconnectFromTransportChannel(old_tc); | 314 DisconnectFromTransportChannel(old_tc); |
314 transport_controller_->DestroyTransportChannel_n( | 315 transport_controller_->DestroyTransportChannel_n( |
(...skipping 10 matching lines...) Expand all Loading... |
325 } | 326 } |
326 | 327 |
327 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 328 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
328 // setting new channel | 329 // setting new channel |
329 UpdateWritableState_n(); | 330 UpdateWritableState_n(); |
330 SetReadyToSend(false, new_tc && new_tc->writable()); | 331 SetReadyToSend(false, new_tc && new_tc->writable()); |
331 } | 332 } |
332 | 333 |
333 void BaseChannel::SetRtcpTransportChannel_n(TransportChannel* new_tc, | 334 void BaseChannel::SetRtcpTransportChannel_n(TransportChannel* new_tc, |
334 bool update_writablity) { | 335 bool update_writablity) { |
335 RTC_DCHECK(network_thread_->IsCurrent()); | 336 RTC_DCHECK_RUN_ON(network_thread_); |
336 | 337 |
337 TransportChannel* old_tc = rtcp_transport_channel_; | 338 TransportChannel* old_tc = rtcp_transport_channel_; |
338 if (!old_tc && !new_tc) { | 339 if (!old_tc && !new_tc) { |
339 // Nothing to do | 340 // Nothing to do |
340 return; | 341 return; |
341 } | 342 } |
342 ASSERT(old_tc != new_tc); | 343 ASSERT(old_tc != new_tc); |
343 | 344 |
344 if (old_tc) { | 345 if (old_tc) { |
345 DisconnectFromTransportChannel(old_tc); | 346 DisconnectFromTransportChannel(old_tc); |
(...skipping 1977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2323 return data_channel_type_ == DCT_RTP && BaseChannel::ShouldSetupDtlsSrtp_n(); | 2324 return data_channel_type_ == DCT_RTP && BaseChannel::ShouldSetupDtlsSrtp_n(); |
2324 } | 2325 } |
2325 | 2326 |
2326 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2327 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
2327 rtc::TypedMessageData<uint32_t>* message = | 2328 rtc::TypedMessageData<uint32_t>* message = |
2328 new rtc::TypedMessageData<uint32_t>(sid); | 2329 new rtc::TypedMessageData<uint32_t>(sid); |
2329 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2330 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
2330 } | 2331 } |
2331 | 2332 |
2332 } // namespace cricket | 2333 } // namespace cricket |
OLD | NEW |