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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 RTC_DCHECK_EQ(network_thread, transport_controller->network_thread()); | 176 RTC_DCHECK_EQ(network_thread, transport_controller->network_thread()); |
177 } | 177 } |
178 LOG(LS_INFO) << "Created channel for " << content_name; | 178 LOG(LS_INFO) << "Created channel for " << content_name; |
179 } | 179 } |
180 | 180 |
181 BaseChannel::~BaseChannel() { | 181 BaseChannel::~BaseChannel() { |
182 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); | 182 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); |
183 ASSERT(worker_thread_ == rtc::Thread::Current()); | 183 ASSERT(worker_thread_ == rtc::Thread::Current()); |
184 Deinit(); | 184 Deinit(); |
185 StopConnectionMonitor(); | 185 StopConnectionMonitor(); |
186 // Send any outstanding RTCP packets. | |
187 network_thread_->Invoke<void>(Bind(&BaseChannel::FlushRtcpMessages_n, this)); | |
188 // Eats any outstanding messages or packets. | 186 // Eats any outstanding messages or packets. |
189 worker_thread_->Clear(&invoker_); | 187 worker_thread_->Clear(&invoker_); |
190 worker_thread_->Clear(this); | 188 worker_thread_->Clear(this); |
191 // We must destroy the media channel before the transport channel, otherwise | 189 // We must destroy the media channel before the transport channel, otherwise |
192 // the media channel may try to send on the dead transport channel. NULLing | 190 // 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. | 191 // is not an effective strategy since the sends will come on another thread. |
194 delete media_channel_; | 192 delete media_channel_; |
195 // Note that we don't just call SetTransportChannel_n(nullptr) because that | 193 // 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. | 194 // would call a pure virtual method which we can't do from a destructor. |
197 network_thread_->Invoke<void>(Bind(&BaseChannel::DeinitNetwork_n, this)); | 195 network_thread_->Invoke<void>( |
196 Bind(&BaseChannel::DestroyTransportChannels_n, this)); | |
198 LOG(LS_INFO) << "Destroyed channel"; | 197 LOG(LS_INFO) << "Destroyed channel"; |
199 } | 198 } |
200 | 199 |
201 void BaseChannel::DeinitNetwork_n() { | 200 void BaseChannel::DisconnectTransportChannels_n() { |
201 // Send any outstanding RTCP packets. | |
202 FlushRtcpMessages_n(); | |
203 | |
204 // Stop signals from transport channels, but keep them alive because | |
205 // media_channel may use them from a different thread. | |
206 if (transport_channel_) | |
207 DisconnectFromTransportChannel(transport_channel_); | |
208 if (rtcp_transport_channel_) | |
209 DisconnectFromTransportChannel(rtcp_transport_channel_); | |
210 | |
211 // Clear pending read packets/messages. | |
212 network_thread_->Clear(&invoker_); | |
213 network_thread_->Clear(this); | |
214 } | |
215 | |
216 void BaseChannel::DestroyTransportChannels_n() { | |
202 if (transport_channel_) { | 217 if (transport_channel_) { |
203 DisconnectFromTransportChannel(transport_channel_); | |
204 transport_controller_->DestroyTransportChannel_n( | 218 transport_controller_->DestroyTransportChannel_n( |
205 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 219 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
206 } | 220 } |
207 if (rtcp_transport_channel_) { | 221 if (rtcp_transport_channel_) { |
208 DisconnectFromTransportChannel(rtcp_transport_channel_); | |
209 transport_controller_->DestroyTransportChannel_n( | 222 transport_controller_->DestroyTransportChannel_n( |
210 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 223 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
211 } | 224 } |
225 // Clear pending send packets/messages. | |
226 network_thread_->Clear(&invoker_); | |
212 network_thread_->Clear(this); | 227 network_thread_->Clear(this); |
213 } | 228 } |
214 | 229 |
215 bool BaseChannel::Init_w() { | 230 bool BaseChannel::Init_w() { |
216 if (!network_thread_->Invoke<bool>(Bind(&BaseChannel::InitNetwork_n, this))) { | 231 if (!network_thread_->Invoke<bool>(Bind(&BaseChannel::InitNetwork_n, this))) { |
217 return false; | 232 return false; |
218 } | 233 } |
219 | 234 |
220 // Both RTP and RTCP channels are set, we can call SetInterface on | 235 // Both RTP and RTCP channels are set, we can call SetInterface on |
221 // media channel and it can set network options. | 236 // media channel and it can set network options. |
(...skipping 14 matching lines...) Expand all Loading... | |
236 if (rtcp_transport_enabled() && | 251 if (rtcp_transport_enabled() && |
237 !SetDtlsSrtpCryptoSuites_n(rtcp_transport_channel_, true)) { | 252 !SetDtlsSrtpCryptoSuites_n(rtcp_transport_channel_, true)) { |
238 return false; | 253 return false; |
239 } | 254 } |
240 return true; | 255 return true; |
241 } | 256 } |
242 | 257 |
243 void BaseChannel::Deinit() { | 258 void BaseChannel::Deinit() { |
244 RTC_DCHECK(worker_thread_->IsCurrent()); | 259 RTC_DCHECK(worker_thread_->IsCurrent()); |
245 media_channel_->SetInterface(NULL); | 260 media_channel_->SetInterface(NULL); |
261 // Packets arrive on network thread, processing packets calls virtual | |
pthatcher1
2016/05/13 18:33:27
on network thread => on the network thread
| |
262 // functions, so need to stop this process in Deinit that is called in | |
263 // derived classes destructor. | |
264 network_thread_->Invoke<void>( | |
265 Bind(&BaseChannel::DisconnectTransportChannels_n, this)); | |
246 } | 266 } |
247 | 267 |
248 bool BaseChannel::SetTransport(const std::string& transport_name) { | 268 bool BaseChannel::SetTransport(const std::string& transport_name) { |
249 return network_thread_->Invoke<bool>( | 269 return network_thread_->Invoke<bool>( |
250 Bind(&BaseChannel::SetTransport_n, this, transport_name)); | 270 Bind(&BaseChannel::SetTransport_n, this, transport_name)); |
251 } | 271 } |
252 | 272 |
253 bool BaseChannel::SetTransport_n(const std::string& transport_name) { | 273 bool BaseChannel::SetTransport_n(const std::string& transport_name) { |
254 RTC_DCHECK(network_thread_->IsCurrent()); | 274 RTC_DCHECK(network_thread_->IsCurrent()); |
255 | 275 |
(...skipping 2067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2323 return data_channel_type_ == DCT_RTP && BaseChannel::ShouldSetupDtlsSrtp_n(); | 2343 return data_channel_type_ == DCT_RTP && BaseChannel::ShouldSetupDtlsSrtp_n(); |
2324 } | 2344 } |
2325 | 2345 |
2326 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2346 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
2327 rtc::TypedMessageData<uint32_t>* message = | 2347 rtc::TypedMessageData<uint32_t>* message = |
2328 new rtc::TypedMessageData<uint32_t>(sid); | 2348 new rtc::TypedMessageData<uint32_t>(sid); |
2329 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2349 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
2330 } | 2350 } |
2331 | 2351 |
2332 } // namespace cricket | 2352 } // namespace cricket |
OLD | NEW |