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. |
202 if (transport_channel_) { | 206 if (transport_channel_) { |
203 DisconnectFromTransportChannel(transport_channel_); | 207 DisconnectFromTransportChannel(transport_channel_); |
| 208 } |
| 209 if (rtcp_transport_channel_) { |
| 210 DisconnectFromTransportChannel(rtcp_transport_channel_); |
| 211 } |
| 212 |
| 213 // Clear pending read packets/messages. |
| 214 network_thread_->Clear(&invoker_); |
| 215 network_thread_->Clear(this); |
| 216 } |
| 217 |
| 218 void BaseChannel::DestroyTransportChannels_n() { |
| 219 if (transport_channel_) { |
204 transport_controller_->DestroyTransportChannel_n( | 220 transport_controller_->DestroyTransportChannel_n( |
205 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 221 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
206 } | 222 } |
207 if (rtcp_transport_channel_) { | 223 if (rtcp_transport_channel_) { |
208 DisconnectFromTransportChannel(rtcp_transport_channel_); | |
209 transport_controller_->DestroyTransportChannel_n( | 224 transport_controller_->DestroyTransportChannel_n( |
210 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 225 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
211 } | 226 } |
| 227 // Clear pending send packets/messages. |
| 228 network_thread_->Clear(&invoker_); |
212 network_thread_->Clear(this); | 229 network_thread_->Clear(this); |
213 } | 230 } |
214 | 231 |
215 bool BaseChannel::Init_w() { | 232 bool BaseChannel::Init_w() { |
216 if (!network_thread_->Invoke<bool>(Bind(&BaseChannel::InitNetwork_n, this))) { | 233 if (!network_thread_->Invoke<bool>(Bind(&BaseChannel::InitNetwork_n, this))) { |
217 return false; | 234 return false; |
218 } | 235 } |
219 | 236 |
220 // Both RTP and RTCP channels are set, we can call SetInterface on | 237 // Both RTP and RTCP channels are set, we can call SetInterface on |
221 // media channel and it can set network options. | 238 // media channel and it can set network options. |
(...skipping 14 matching lines...) Expand all Loading... |
236 if (rtcp_transport_enabled() && | 253 if (rtcp_transport_enabled() && |
237 !SetDtlsSrtpCryptoSuites_n(rtcp_transport_channel_, true)) { | 254 !SetDtlsSrtpCryptoSuites_n(rtcp_transport_channel_, true)) { |
238 return false; | 255 return false; |
239 } | 256 } |
240 return true; | 257 return true; |
241 } | 258 } |
242 | 259 |
243 void BaseChannel::Deinit() { | 260 void BaseChannel::Deinit() { |
244 RTC_DCHECK(worker_thread_->IsCurrent()); | 261 RTC_DCHECK(worker_thread_->IsCurrent()); |
245 media_channel_->SetInterface(NULL); | 262 media_channel_->SetInterface(NULL); |
| 263 // Packets arrive on the network thread, processing packets calls virtual |
| 264 // functions, so need to stop this process in Deinit that is called in |
| 265 // derived classes destructor. |
| 266 network_thread_->Invoke<void>( |
| 267 Bind(&BaseChannel::DisconnectTransportChannels_n, this)); |
246 } | 268 } |
247 | 269 |
248 bool BaseChannel::SetTransport(const std::string& transport_name) { | 270 bool BaseChannel::SetTransport(const std::string& transport_name) { |
249 return network_thread_->Invoke<bool>( | 271 return network_thread_->Invoke<bool>( |
250 Bind(&BaseChannel::SetTransport_n, this, transport_name)); | 272 Bind(&BaseChannel::SetTransport_n, this, transport_name)); |
251 } | 273 } |
252 | 274 |
253 bool BaseChannel::SetTransport_n(const std::string& transport_name) { | 275 bool BaseChannel::SetTransport_n(const std::string& transport_name) { |
254 RTC_DCHECK(network_thread_->IsCurrent()); | 276 RTC_DCHECK(network_thread_->IsCurrent()); |
255 | 277 |
(...skipping 2067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2323 return data_channel_type_ == DCT_RTP && BaseChannel::ShouldSetupDtlsSrtp_n(); | 2345 return data_channel_type_ == DCT_RTP && BaseChannel::ShouldSetupDtlsSrtp_n(); |
2324 } | 2346 } |
2325 | 2347 |
2326 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2348 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
2327 rtc::TypedMessageData<uint32_t>* message = | 2349 rtc::TypedMessageData<uint32_t>* message = |
2328 new rtc::TypedMessageData<uint32_t>(sid); | 2350 new rtc::TypedMessageData<uint32_t>(sid); |
2329 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2351 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
2330 } | 2352 } |
2331 | 2353 |
2332 } // namespace cricket | 2354 } // namespace cricket |
OLD | NEW |