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 SendingPacketMessageData : public rtc::MessageData { | |
42 rtc::CopyOnWriteBuffer packet; | |
43 rtc::PacketOptions options; | |
44 }; | |
45 | |
46 struct ReceivedPacketMessageData : public rtc::MessageData { | |
47 rtc::CopyOnWriteBuffer packet; | |
48 rtc::PacketTime packet_time; | |
49 }; | |
50 | |
51 struct ChangeState : public rtc::MessageData { | |
52 bool send; | |
53 bool recv; | |
54 }; | |
55 | |
56 struct NetworkRouteChanged : public rtc::MessageData { | |
57 std::string transport_name; | |
58 rtc::NetworkRoute network_route; | |
59 }; | |
60 | |
40 } // namespace | 61 } // namespace |
41 | 62 |
42 enum { | 63 enum { |
43 MSG_EARLYMEDIATIMEOUT = 1, | 64 MSG_EARLYMEDIATIMEOUT = 1, |
44 MSG_RTPPACKET, | 65 MSG_SENDING_RTP_PACKET, |
45 MSG_RTCPPACKET, | 66 MSG_SENDING_RTCP_PACKET, |
46 MSG_CHANNEL_ERROR, | 67 MSG_CHANNEL_ERROR, |
47 MSG_READYTOSENDDATA, | 68 MSG_READYTOSENDDATA, |
48 MSG_DATARECEIVED, | 69 MSG_DATARECEIVED, |
49 MSG_FIRSTPACKETRECEIVED, | 70 MSG_FIRSTPACKETRECEIVED, |
50 MSG_STREAMCLOSEDREMOTELY, | 71 MSG_STREAMCLOSEDREMOTELY, |
72 MSG_RECEIVED_RTP_PACKET, | |
73 MSG_RECEIVED_RTCP_PACKET, | |
74 MSG_CHANGE_STATE, | |
75 MSG_NOT_READY_TO_SEND, | |
76 MSG_READY_TO_SEND, | |
77 MSG_NETWORK_ROUTE_CHANGED, | |
51 }; | 78 }; |
52 | 79 |
53 // Value specified in RFC 5764. | 80 // Value specified in RFC 5764. |
54 static const char kDtlsSrtpExporterLabel[] = "EXTRACTOR-dtls_srtp"; | 81 static const char kDtlsSrtpExporterLabel[] = "EXTRACTOR-dtls_srtp"; |
55 | 82 |
56 static const int kAgcMinus10db = -10; | 83 static const int kAgcMinus10db = -10; |
57 | 84 |
58 static void SafeSetError(const std::string& message, std::string* error_desc) { | 85 static void SafeSetError(const std::string& message, std::string* error_desc) { |
59 if (error_desc) { | 86 if (error_desc) { |
60 *error_desc = message; | 87 *error_desc = message; |
61 } | 88 } |
62 } | 89 } |
63 | 90 |
64 struct PacketMessageData : public rtc::MessageData { | |
65 rtc::CopyOnWriteBuffer packet; | |
66 rtc::PacketOptions options; | |
67 }; | |
68 | |
69 struct VoiceChannelErrorMessageData : public rtc::MessageData { | 91 struct VoiceChannelErrorMessageData : public rtc::MessageData { |
70 VoiceChannelErrorMessageData(uint32_t in_ssrc, | 92 VoiceChannelErrorMessageData(uint32_t in_ssrc, |
71 VoiceMediaChannel::Error in_error) | 93 VoiceMediaChannel::Error in_error) |
72 : ssrc(in_ssrc), error(in_error) {} | 94 : ssrc(in_ssrc), error(in_error) {} |
73 uint32_t ssrc; | 95 uint32_t ssrc; |
74 VoiceMediaChannel::Error error; | 96 VoiceMediaChannel::Error error; |
75 }; | 97 }; |
76 | 98 |
77 struct VideoChannelErrorMessageData : public rtc::MessageData { | 99 struct VideoChannelErrorMessageData : public rtc::MessageData { |
78 VideoChannelErrorMessageData(uint32_t in_ssrc, | 100 VideoChannelErrorMessageData(uint32_t in_ssrc, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 } | 157 } |
136 | 158 |
137 template <class Codec> | 159 template <class Codec> |
138 void RtpSendParametersFromMediaDescription( | 160 void RtpSendParametersFromMediaDescription( |
139 const MediaContentDescriptionImpl<Codec>* desc, | 161 const MediaContentDescriptionImpl<Codec>* desc, |
140 RtpSendParameters<Codec>* send_params) { | 162 RtpSendParameters<Codec>* send_params) { |
141 RtpParametersFromMediaDescription(desc, send_params); | 163 RtpParametersFromMediaDescription(desc, send_params); |
142 send_params->max_bandwidth_bps = desc->bandwidth(); | 164 send_params->max_bandwidth_bps = desc->bandwidth(); |
143 } | 165 } |
144 | 166 |
145 BaseChannel::BaseChannel(rtc::Thread* thread, | 167 BaseChannel::BaseChannel(rtc::Thread* worker_thread, |
168 rtc::Thread* network_thread, | |
146 MediaChannel* media_channel, | 169 MediaChannel* media_channel, |
147 TransportController* transport_controller, | 170 TransportController* transport_controller, |
148 const std::string& content_name, | 171 const std::string& content_name, |
149 bool rtcp) | 172 bool rtcp) |
150 : worker_thread_(thread), | 173 : worker_thread_(worker_thread), |
174 network_thread_(network_thread), | |
151 transport_controller_(transport_controller), | 175 transport_controller_(transport_controller), |
152 media_channel_(media_channel), | 176 media_channel_(media_channel), |
153 content_name_(content_name), | 177 content_name_(content_name), |
154 rtcp_transport_enabled_(rtcp), | 178 rtcp_transport_enabled_(rtcp), |
155 transport_channel_(nullptr), | 179 transport_channel_(nullptr), |
156 rtcp_transport_channel_(nullptr), | 180 rtcp_transport_channel_(nullptr), |
157 enabled_(false), | 181 enabled_(false), |
158 writable_(false), | 182 writable_(false), |
159 rtp_ready_to_send_(false), | 183 rtp_ready_to_send_(false), |
160 rtcp_ready_to_send_(false), | 184 rtcp_ready_to_send_(false), |
161 was_ever_writable_(false), | 185 was_ever_writable_(false), |
162 local_content_direction_(MD_INACTIVE), | 186 local_content_direction_(MD_INACTIVE), |
163 remote_content_direction_(MD_INACTIVE), | 187 remote_content_direction_(MD_INACTIVE), |
164 has_received_packet_(false), | 188 has_received_packet_(false), |
165 dtls_keyed_(false), | 189 dtls_keyed_(false), |
166 secure_required_(false), | 190 secure_required_(false), |
167 rtp_abs_sendtime_extn_id_(-1) { | 191 rtp_abs_sendtime_extn_id_(-1) { |
168 ASSERT(worker_thread_ == rtc::Thread::Current()); | 192 ASSERT(worker_thread_ == rtc::Thread::Current()); |
193 if (transport_controller) { | |
194 RTC_DCHECK_EQ(network_thread, transport_controller->worker_thread()); | |
195 } | |
169 LOG(LS_INFO) << "Created channel for " << content_name; | 196 LOG(LS_INFO) << "Created channel for " << content_name; |
170 } | 197 } |
171 | 198 |
172 BaseChannel::~BaseChannel() { | 199 BaseChannel::~BaseChannel() { |
173 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); | 200 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); |
174 ASSERT(worker_thread_ == rtc::Thread::Current()); | 201 ASSERT(worker_thread_ == rtc::Thread::Current()); |
175 Deinit(); | 202 Deinit(); |
176 StopConnectionMonitor(); | 203 StopConnectionMonitor(); |
177 FlushRtcpMessages(); // Send any outstanding RTCP packets. | 204 FlushRtcpMessages(); // Send any outstanding RTCP packets. |
178 worker_thread_->Clear(this); // eats any outstanding messages or packets | 205 worker_thread_->Clear(this); // eats any outstanding messages or packets |
179 // We must destroy the media channel before the transport channel, otherwise | 206 // 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 | 207 // 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. | 208 // is not an effective strategy since the sends will come on another thread. |
182 delete media_channel_; | 209 delete media_channel_; |
183 // Note that we don't just call set_transport_channel(nullptr) because that | 210 // Note that we don't just call set_transport_channel(nullptr) because that |
184 // would call a pure virtual method which we can't do from a destructor. | 211 // would call a pure virtual method which we can't do from a destructor. |
185 if (transport_channel_) { | 212 network_thread_->Invoke<void>([this] { |
186 DisconnectFromTransportChannel(transport_channel_); | 213 if (transport_channel_) { |
187 transport_controller_->DestroyTransportChannel_w( | 214 DisconnectFromTransportChannel(transport_channel_); |
188 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 215 transport_controller_->DestroyTransportChannel_w( |
189 } | 216 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
190 if (rtcp_transport_channel_) { | 217 } |
191 DisconnectFromTransportChannel(rtcp_transport_channel_); | 218 if (rtcp_transport_channel_) { |
192 transport_controller_->DestroyTransportChannel_w( | 219 DisconnectFromTransportChannel(rtcp_transport_channel_); |
193 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 220 transport_controller_->DestroyTransportChannel_w( |
194 } | 221 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
222 } | |
223 network_thread_->Clear(this); | |
224 }); | |
195 LOG(LS_INFO) << "Destroyed channel"; | 225 LOG(LS_INFO) << "Destroyed channel"; |
196 } | 226 } |
197 | 227 |
198 bool BaseChannel::Init() { | 228 bool BaseChannel::Init() { |
199 if (!SetTransport(content_name())) { | 229 bool setup_transport = network_thread_->Invoke<bool>([this] { |
200 return false; | 230 if (!SetTransport_n(content_name())) { |
201 } | 231 return false; |
232 } | |
202 | 233 |
203 if (!SetDtlsSrtpCryptoSuites(transport_channel(), false)) { | 234 if (!SetDtlsSrtpCryptoSuites(transport_channel(), false)) { |
204 return false; | 235 return false; |
205 } | 236 } |
206 if (rtcp_transport_enabled() && | 237 if (rtcp_transport_enabled() && |
207 !SetDtlsSrtpCryptoSuites(rtcp_transport_channel(), true)) { | 238 !SetDtlsSrtpCryptoSuites(rtcp_transport_channel(), true)) { |
239 return false; | |
240 } | |
241 return true; | |
242 }); | |
243 if (!setup_transport) { | |
208 return false; | 244 return false; |
209 } | 245 } |
210 | 246 |
211 // Both RTP and RTCP channels are set, we can call SetInterface on | 247 // Both RTP and RTCP channels are set, we can call SetInterface on |
212 // media channel and it can set network options. | 248 // media channel and it can set network options. |
249 RTC_DCHECK(worker_thread_->IsCurrent()); | |
213 media_channel_->SetInterface(this); | 250 media_channel_->SetInterface(this); |
214 return true; | 251 return true; |
215 } | 252 } |
216 | 253 |
217 void BaseChannel::Deinit() { | 254 void BaseChannel::Deinit() { |
255 RTC_DCHECK(worker_thread_->IsCurrent()); | |
218 media_channel_->SetInterface(NULL); | 256 media_channel_->SetInterface(NULL); |
219 } | 257 } |
220 | 258 |
221 bool BaseChannel::SetTransport(const std::string& transport_name) { | 259 bool BaseChannel::SetTransport(const std::string& transport_name) { |
222 return worker_thread_->Invoke<bool>( | 260 return network_thread_->Invoke<bool>( |
223 Bind(&BaseChannel::SetTransport_w, this, transport_name)); | 261 Bind(&BaseChannel::SetTransport_n, this, transport_name)); |
224 } | 262 } |
225 | 263 |
226 bool BaseChannel::SetTransport_w(const std::string& transport_name) { | 264 bool BaseChannel::SetTransport_n(const std::string& transport_name) { |
227 ASSERT(worker_thread_ == rtc::Thread::Current()); | 265 RTC_DCHECK(network_thread_->IsCurrent()); |
228 | 266 |
229 if (transport_name == transport_name_) { | 267 if (transport_name == transport_name_) { |
230 // Nothing to do if transport name isn't changing | 268 // Nothing to do if transport name isn't changing |
231 return true; | 269 return true; |
232 } | 270 } |
233 | 271 |
234 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport | 272 // 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 | 273 // changes and wait until the DTLS handshake is complete to set the newly |
236 // negotiated parameters. | 274 // negotiated parameters. |
237 if (ShouldSetupDtlsSrtp()) { | 275 if (ShouldSetupDtlsSrtp()) { |
(...skipping 28 matching lines...) Expand all Loading... | |
266 // We can only update the RTCP ready to send after set_transport_channel has | 304 // We can only update the RTCP ready to send after set_transport_channel has |
267 // handled channel writability. | 305 // handled channel writability. |
268 SetReadyToSend( | 306 SetReadyToSend( |
269 true, rtcp_transport_channel() && rtcp_transport_channel()->writable()); | 307 true, rtcp_transport_channel() && rtcp_transport_channel()->writable()); |
270 } | 308 } |
271 transport_name_ = transport_name; | 309 transport_name_ = transport_name; |
272 return true; | 310 return true; |
273 } | 311 } |
274 | 312 |
275 void BaseChannel::set_transport_channel(TransportChannel* new_tc) { | 313 void BaseChannel::set_transport_channel(TransportChannel* new_tc) { |
276 ASSERT(worker_thread_ == rtc::Thread::Current()); | 314 RTC_DCHECK(network_thread_->IsCurrent()); |
277 | 315 |
278 TransportChannel* old_tc = transport_channel_; | 316 TransportChannel* old_tc = transport_channel_; |
279 if (!old_tc && !new_tc) { | 317 if (!old_tc && !new_tc) { |
280 // Nothing to do | 318 // Nothing to do |
281 return; | 319 return; |
282 } | 320 } |
283 ASSERT(old_tc != new_tc); | 321 ASSERT(old_tc != new_tc); |
284 | 322 |
285 if (old_tc) { | 323 if (old_tc) { |
286 DisconnectFromTransportChannel(old_tc); | 324 DisconnectFromTransportChannel(old_tc); |
287 transport_controller_->DestroyTransportChannel_w( | 325 transport_controller_->DestroyTransportChannel_w( |
288 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 326 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
289 } | 327 } |
290 | 328 |
291 transport_channel_ = new_tc; | 329 transport_channel_ = new_tc; |
292 | 330 |
293 if (new_tc) { | 331 if (new_tc) { |
294 ConnectToTransportChannel(new_tc); | 332 ConnectToTransportChannel(new_tc); |
295 for (const auto& pair : socket_options_) { | 333 for (const auto& pair : socket_options_) { |
296 new_tc->SetOption(pair.first, pair.second); | 334 new_tc->SetOption(pair.first, pair.second); |
297 } | 335 } |
298 } | 336 } |
299 | 337 |
300 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 338 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
301 // setting new channel | 339 // setting new channel |
302 UpdateWritableState_w(); | 340 UpdateWritableState_n(); |
303 SetReadyToSend(false, new_tc && new_tc->writable()); | 341 SetReadyToSend(false, new_tc && new_tc->writable()); |
304 } | 342 } |
305 | 343 |
306 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc, | 344 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc, |
307 bool update_writablity) { | 345 bool update_writablity) { |
308 ASSERT(worker_thread_ == rtc::Thread::Current()); | 346 RTC_DCHECK(network_thread_->IsCurrent()); |
309 | 347 |
310 TransportChannel* old_tc = rtcp_transport_channel_; | 348 TransportChannel* old_tc = rtcp_transport_channel_; |
311 if (!old_tc && !new_tc) { | 349 if (!old_tc && !new_tc) { |
312 // Nothing to do | 350 // Nothing to do |
313 return; | 351 return; |
314 } | 352 } |
315 ASSERT(old_tc != new_tc); | 353 ASSERT(old_tc != new_tc); |
316 | 354 |
317 if (old_tc) { | 355 if (old_tc) { |
318 DisconnectFromTransportChannel(old_tc); | 356 DisconnectFromTransportChannel(old_tc); |
319 transport_controller_->DestroyTransportChannel_w( | 357 transport_controller_->DestroyTransportChannel_w( |
320 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 358 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
321 } | 359 } |
322 | 360 |
323 rtcp_transport_channel_ = new_tc; | 361 rtcp_transport_channel_ = new_tc; |
324 | 362 |
325 if (new_tc) { | 363 if (new_tc) { |
326 RTC_CHECK(!(ShouldSetupDtlsSrtp() && srtp_filter_.IsActive())) | 364 RTC_CHECK(!(ShouldSetupDtlsSrtp() && srtp_filter_.IsActive())) |
327 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " | 365 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " |
328 << "should never happen."; | 366 << "should never happen."; |
329 ConnectToTransportChannel(new_tc); | 367 ConnectToTransportChannel(new_tc); |
330 for (const auto& pair : rtcp_socket_options_) { | 368 for (const auto& pair : rtcp_socket_options_) { |
331 new_tc->SetOption(pair.first, pair.second); | 369 new_tc->SetOption(pair.first, pair.second); |
332 } | 370 } |
333 } | 371 } |
334 | 372 |
335 if (update_writablity) { | 373 if (update_writablity) { |
336 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 374 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
337 // setting new channel | 375 // setting new channel |
338 UpdateWritableState_w(); | 376 UpdateWritableState_n(); |
339 SetReadyToSend(true, new_tc && new_tc->writable()); | 377 SetReadyToSend(true, new_tc && new_tc->writable()); |
340 } | 378 } |
341 } | 379 } |
342 | 380 |
343 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { | 381 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { |
344 ASSERT(worker_thread_ == rtc::Thread::Current()); | 382 RTC_DCHECK(network_thread_->IsCurrent()); |
345 | 383 |
346 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 384 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
347 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); | 385 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); |
348 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | 386 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |
349 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); | 387 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); |
350 tc->SignalSelectedCandidatePairChanged.connect( | 388 tc->SignalSelectedCandidatePairChanged.connect( |
351 this, &BaseChannel::OnSelectedCandidatePairChanged); | 389 this, &BaseChannel::OnSelectedCandidatePairChanged); |
352 } | 390 } |
353 | 391 |
354 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { | 392 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { |
355 ASSERT(worker_thread_ == rtc::Thread::Current()); | 393 RTC_DCHECK(network_thread_->IsCurrent()); |
356 | 394 |
357 tc->SignalWritableState.disconnect(this); | 395 tc->SignalWritableState.disconnect(this); |
358 tc->SignalReadPacket.disconnect(this); | 396 tc->SignalReadPacket.disconnect(this); |
359 tc->SignalReadyToSend.disconnect(this); | 397 tc->SignalReadyToSend.disconnect(this); |
360 tc->SignalDtlsState.disconnect(this); | 398 tc->SignalDtlsState.disconnect(this); |
361 } | 399 } |
362 | 400 |
363 bool BaseChannel::Enable(bool enable) { | 401 bool BaseChannel::Enable(bool enable) { |
364 worker_thread_->Invoke<void>(Bind( | 402 worker_thread_->Invoke<void>(Bind( |
365 enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, | 403 enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 std::string* error_desc) { | 436 std::string* error_desc) { |
399 TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent"); | 437 TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent"); |
400 return InvokeOnWorker(Bind(&BaseChannel::SetRemoteContent_w, | 438 return InvokeOnWorker(Bind(&BaseChannel::SetRemoteContent_w, |
401 this, content, action, error_desc)); | 439 this, content, action, error_desc)); |
402 } | 440 } |
403 | 441 |
404 void BaseChannel::StartConnectionMonitor(int cms) { | 442 void BaseChannel::StartConnectionMonitor(int cms) { |
405 // We pass in the BaseChannel instead of the transport_channel_ | 443 // We pass in the BaseChannel instead of the transport_channel_ |
406 // because if the transport_channel_ changes, the ConnectionMonitor | 444 // because if the transport_channel_ changes, the ConnectionMonitor |
407 // would be pointing to the wrong TransportChannel. | 445 // would be pointing to the wrong TransportChannel. |
408 connection_monitor_.reset(new ConnectionMonitor( | 446 connection_monitor_.reset( |
409 this, worker_thread(), rtc::Thread::Current())); | 447 new ConnectionMonitor(this, network_thread(), rtc::Thread::Current())); |
410 connection_monitor_->SignalUpdate.connect( | 448 connection_monitor_->SignalUpdate.connect( |
411 this, &BaseChannel::OnConnectionMonitorUpdate); | 449 this, &BaseChannel::OnConnectionMonitorUpdate); |
412 connection_monitor_->Start(cms); | 450 connection_monitor_->Start(cms); |
413 } | 451 } |
414 | 452 |
415 void BaseChannel::StopConnectionMonitor() { | 453 void BaseChannel::StopConnectionMonitor() { |
416 if (connection_monitor_) { | 454 if (connection_monitor_) { |
417 connection_monitor_->Stop(); | 455 connection_monitor_->Stop(); |
418 connection_monitor_.reset(); | 456 connection_monitor_.reset(); |
419 } | 457 } |
420 } | 458 } |
421 | 459 |
422 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { | 460 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { |
423 ASSERT(worker_thread_ == rtc::Thread::Current()); | 461 RTC_DCHECK(network_thread_->IsCurrent()); |
424 return transport_channel_->GetStats(infos); | 462 return transport_channel_->GetStats(infos); |
425 } | 463 } |
426 | 464 |
427 bool BaseChannel::IsReadyToReceive() const { | 465 bool BaseChannel::IsReadyToReceive() const { |
428 // Receive data if we are enabled and have local content, | 466 // Receive data if we are enabled and have local content, |
429 return enabled() && IsReceiveContentDirection(local_content_direction_); | 467 return enabled() && IsReceiveContentDirection(local_content_direction_); |
430 } | 468 } |
431 | 469 |
432 bool BaseChannel::IsReadyToSend() const { | 470 bool BaseChannel::IsReadyToSend() const { |
433 // Send outgoing data if we are enabled, have local and remote content, | 471 // Send outgoing data if we are enabled, have local and remote content, |
434 // and we have had some form of connectivity. | 472 // and we have had some form of connectivity. |
435 return enabled() && IsReceiveContentDirection(remote_content_direction_) && | 473 return enabled() && IsReceiveContentDirection(remote_content_direction_) && |
436 IsSendContentDirection(local_content_direction_) && | 474 IsSendContentDirection(local_content_direction_) && |
437 was_ever_writable() && | 475 was_ever_writable() && |
438 (srtp_filter_.IsActive() || !ShouldSetupDtlsSrtp()); | 476 (srtp_filter_.IsActive() || !ShouldSetupDtlsSrtp()); |
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>([this, type, opt, value] { |
454 switch (type) { | 492 TransportChannel* channel = nullptr; |
455 case ST_RTP: | 493 switch (type) { |
456 channel = transport_channel_; | 494 case ST_RTP: |
457 socket_options_.push_back( | 495 channel = transport_channel_; |
458 std::pair<rtc::Socket::Option, int>(opt, value)); | 496 socket_options_.push_back( |
459 break; | 497 std::pair<rtc::Socket::Option, int>(opt, value)); |
460 case ST_RTCP: | 498 break; |
461 channel = rtcp_transport_channel_; | 499 case ST_RTCP: |
462 rtcp_socket_options_.push_back( | 500 channel = rtcp_transport_channel_; |
463 std::pair<rtc::Socket::Option, int>(opt, value)); | 501 rtcp_socket_options_.push_back( |
464 break; | 502 std::pair<rtc::Socket::Option, int>(opt, value)); |
465 } | 503 break; |
466 return channel ? channel->SetOption(opt, value) : -1; | 504 } |
505 return channel ? channel->SetOption(opt, value) : -1; | |
506 }); | |
467 } | 507 } |
468 | 508 |
469 void BaseChannel::OnWritableState(TransportChannel* channel) { | 509 void BaseChannel::OnWritableState(TransportChannel* channel) { |
470 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 510 RTC_DCHECK(channel == transport_channel_ || |
471 UpdateWritableState_w(); | 511 channel == rtcp_transport_channel_); |
512 RTC_DCHECK(network_thread_->IsCurrent()); | |
513 UpdateWritableState_n(); | |
472 } | 514 } |
473 | 515 |
474 void BaseChannel::OnChannelRead(TransportChannel* channel, | 516 void BaseChannel::OnChannelRead(TransportChannel* channel, |
475 const char* data, size_t len, | 517 const char* data, size_t len, |
476 const rtc::PacketTime& packet_time, | 518 const rtc::PacketTime& packet_time, |
477 int flags) { | 519 int flags) { |
478 TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); | 520 TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); |
479 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine | 521 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine |
480 ASSERT(worker_thread_ == rtc::Thread::Current()); | 522 RTC_DCHECK(network_thread_->IsCurrent()); |
481 | 523 |
482 // When using RTCP multiplexing we might get RTCP packets on the RTP | 524 // 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. | 525 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. |
484 bool rtcp = PacketIsRtcp(channel, data, len); | 526 bool rtcp = PacketIsRtcp(channel, data, len); |
485 rtc::CopyOnWriteBuffer packet(data, len); | 527 rtc::CopyOnWriteBuffer packet(data, len); |
486 HandlePacket(rtcp, &packet, packet_time); | 528 HandlePacket(rtcp, &packet, packet_time); |
487 } | 529 } |
488 | 530 |
489 void BaseChannel::OnReadyToSend(TransportChannel* channel) { | 531 void BaseChannel::OnReadyToSend(TransportChannel* channel) { |
490 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 532 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
(...skipping 14 matching lines...) Expand all Loading... | |
505 if (state != DTLS_TRANSPORT_CONNECTED) { | 547 if (state != DTLS_TRANSPORT_CONNECTED) { |
506 srtp_filter_.ResetParams(); | 548 srtp_filter_.ResetParams(); |
507 } | 549 } |
508 } | 550 } |
509 | 551 |
510 void BaseChannel::OnSelectedCandidatePairChanged( | 552 void BaseChannel::OnSelectedCandidatePairChanged( |
511 TransportChannel* channel, | 553 TransportChannel* channel, |
512 CandidatePairInterface* selected_candidate_pair, | 554 CandidatePairInterface* selected_candidate_pair, |
513 int last_sent_packet_id) { | 555 int last_sent_packet_id) { |
514 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 556 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
515 rtc::NetworkRoute network_route; | 557 RTC_DCHECK(network_thread_->IsCurrent()); |
558 NetworkRouteChanged* message = new NetworkRouteChanged; | |
516 if (selected_candidate_pair) { | 559 if (selected_candidate_pair) { |
517 network_route = rtc::NetworkRoute( | 560 message->network_route = rtc::NetworkRoute( |
518 selected_candidate_pair->local_candidate().network_id(), | 561 selected_candidate_pair->local_candidate().network_id(), |
519 selected_candidate_pair->remote_candidate().network_id(), | 562 selected_candidate_pair->remote_candidate().network_id(), |
520 last_sent_packet_id); | 563 last_sent_packet_id); |
521 } | 564 } |
522 media_channel()->OnNetworkRouteChanged(channel->transport_name(), | 565 message->transport_name = channel->transport_name(); |
523 network_route); | 566 if (worker_thread_->IsCurrent()) { |
567 media_channel()->OnNetworkRouteChanged(message->transport_name, | |
perkj_webrtc
2016/04/29 07:46:12
Why not always post this to the worker even if wor
danilchap
2016/04/29 08:47:00
The idea was to mimic current behavior as much as
| |
568 message->network_route); | |
569 delete message; | |
570 } else { | |
571 worker_thread_->Post(this, MSG_NETWORK_ROUTE_CHANGED, message); | |
572 } | |
524 } | 573 } |
525 | 574 |
526 void BaseChannel::SetReadyToSend(bool rtcp, bool ready) { | 575 void BaseChannel::SetReadyToSend(bool rtcp, bool ready) { |
527 if (rtcp) { | 576 if (rtcp) { |
perkj_webrtc
2016/04/29 07:46:12
DCHECK thread please.
danilchap
2016/04/29 08:47:00
Done.
| |
528 rtcp_ready_to_send_ = ready; | 577 rtcp_ready_to_send_ = ready; |
529 } else { | 578 } else { |
530 rtp_ready_to_send_ = ready; | 579 rtp_ready_to_send_ = ready; |
531 } | 580 } |
532 | 581 |
533 if (rtp_ready_to_send_ && | 582 bool ready_to_send = |
534 // In the case of rtcp mux |rtcp_transport_channel_| will be null. | 583 (rtp_ready_to_send_ && |
535 (rtcp_ready_to_send_ || !rtcp_transport_channel_)) { | 584 // In the case of rtcp mux |rtcp_transport_channel_| will be null. |
536 // Notify the MediaChannel when both rtp and rtcp channel can send. | 585 (rtcp_ready_to_send_ || !rtcp_transport_channel_)); |
537 media_channel_->OnReadyToSend(true); | 586 |
587 if (worker_thread_->IsCurrent()) { | |
perkj_webrtc
2016/04/29 07:46:12
dito- can we always post regardless if network_thr
danilchap
2016/04/29 08:47:00
Done.
| |
588 media_channel_->OnReadyToSend(ready_to_send); | |
538 } else { | 589 } else { |
539 // Notify the MediaChannel when either rtp or rtcp channel can't send. | 590 worker_thread_->Post( |
540 media_channel_->OnReadyToSend(false); | 591 this, ready_to_send ? MSG_READY_TO_SEND : MSG_NOT_READY_TO_SEND); |
541 } | 592 } |
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_SENDING_RTCP_PACKET : MSG_SENDING_RTP_PACKET; |
563 PacketMessageData* data = new PacketMessageData; | 614 SendingPacketMessageData* data = new SendingPacketMessageData; |
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 if (worker_thread_->IsCurrent()) { |
747 if (!rtcp) { | 802 // Push it down to the media channel. |
748 media_channel_->OnPacketReceived(packet, packet_time); | 803 if (!rtcp) { |
804 media_channel_->OnPacketReceived(packet, packet_time); | |
805 } else { | |
806 media_channel_->OnRtcpReceived(packet, packet_time); | |
807 } | |
749 } else { | 808 } else { |
750 media_channel_->OnRtcpReceived(packet, packet_time); | 809 ReceivedPacketMessageData* message_data = new ReceivedPacketMessageData; |
810 message_data->packet = std::move(*packet); | |
811 message_data->packet_time = packet_time; | |
812 int message_id = rtcp ? MSG_RECEIVED_RTCP_PACKET : MSG_RECEIVED_RTP_PACKET; | |
813 worker_thread_->Post(this, message_id, message_data); | |
751 } | 814 } |
752 } | 815 } |
753 | 816 |
754 bool BaseChannel::PushdownLocalDescription( | 817 bool BaseChannel::PushdownLocalDescription( |
755 const SessionDescription* local_desc, ContentAction action, | 818 const SessionDescription* local_desc, ContentAction action, |
756 std::string* error_desc) { | 819 std::string* error_desc) { |
757 const ContentInfo* content_info = GetFirstContent(local_desc); | 820 const ContentInfo* content_info = GetFirstContent(local_desc); |
758 const MediaContentDescription* content_desc = | 821 const MediaContentDescription* content_desc = |
759 GetContentDescription(content_info); | 822 GetContentDescription(content_info); |
760 if (content_desc && content_info && !content_info->rejected && | 823 if (content_desc && content_info && !content_info->rejected && |
(...skipping 18 matching lines...) Expand all Loading... | |
779 return true; | 842 return true; |
780 } | 843 } |
781 | 844 |
782 void BaseChannel::EnableMedia_w() { | 845 void BaseChannel::EnableMedia_w() { |
783 ASSERT(worker_thread_ == rtc::Thread::Current()); | 846 ASSERT(worker_thread_ == rtc::Thread::Current()); |
784 if (enabled_) | 847 if (enabled_) |
785 return; | 848 return; |
786 | 849 |
787 LOG(LS_INFO) << "Channel enabled"; | 850 LOG(LS_INFO) << "Channel enabled"; |
788 enabled_ = true; | 851 enabled_ = true; |
789 ChangeState(); | 852 ChangeState_w(); |
790 } | 853 } |
791 | 854 |
792 void BaseChannel::DisableMedia_w() { | 855 void BaseChannel::DisableMedia_w() { |
793 ASSERT(worker_thread_ == rtc::Thread::Current()); | 856 ASSERT(worker_thread_ == rtc::Thread::Current()); |
794 if (!enabled_) | 857 if (!enabled_) |
795 return; | 858 return; |
796 | 859 |
797 LOG(LS_INFO) << "Channel disabled"; | 860 LOG(LS_INFO) << "Channel disabled"; |
798 enabled_ = false; | 861 enabled_ = false; |
799 ChangeState(); | 862 ChangeState_w(); |
800 } | 863 } |
801 | 864 |
802 void BaseChannel::UpdateWritableState_w() { | 865 void BaseChannel::UpdateWritableState_n() { |
803 if (transport_channel_ && transport_channel_->writable() && | 866 if (transport_channel_ && transport_channel_->writable() && |
804 (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { | 867 (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { |
805 ChannelWritable_w(); | 868 ChannelWritable_n(); |
806 } else { | 869 } else { |
807 ChannelNotWritable_w(); | 870 ChannelNotWritable_n(); |
808 } | 871 } |
809 } | 872 } |
810 | 873 |
811 void BaseChannel::ChannelWritable_w() { | 874 void BaseChannel::ChannelWritable_n() { |
812 ASSERT(worker_thread_ == rtc::Thread::Current()); | 875 RTC_DCHECK(network_thread_->IsCurrent()); |
813 if (writable_) { | 876 if (writable_) { |
814 return; | 877 return; |
815 } | 878 } |
816 | 879 |
817 LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" | 880 LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" |
818 << (was_ever_writable_ ? "" : " for the first time"); | 881 << (was_ever_writable_ ? "" : " for the first time"); |
819 | 882 |
820 std::vector<ConnectionInfo> infos; | 883 std::vector<ConnectionInfo> infos; |
821 transport_channel_->GetStats(&infos); | 884 transport_channel_->GetStats(&infos); |
822 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); | 885 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); |
823 it != infos.end(); ++it) { | 886 it != infos.end(); ++it) { |
824 if (it->best_connection) { | 887 if (it->best_connection) { |
825 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() | 888 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() |
826 << "->" << it->remote_candidate.ToSensitiveString(); | 889 << "->" << it->remote_candidate.ToSensitiveString(); |
827 break; | 890 break; |
828 } | 891 } |
829 } | 892 } |
830 | 893 |
831 was_ever_writable_ = true; | 894 was_ever_writable_ = true; |
832 MaybeSetupDtlsSrtp_w(); | 895 MaybeSetupDtlsSrtp_n(); |
833 writable_ = true; | 896 writable_ = true; |
834 ChangeState(); | 897 ChangeState(); |
835 } | 898 } |
836 | 899 |
837 void BaseChannel::SignalDtlsSetupFailure_w(bool rtcp) { | 900 void BaseChannel::SignalDtlsSetupFailure_n(bool rtcp) { |
838 ASSERT(worker_thread() == rtc::Thread::Current()); | 901 RTC_DCHECK(network_thread_->IsCurrent()); |
902 RTC_NOTREACHED(); | |
903 // TODO(danilchap): Not allowed to invoke from network thread. Post instead. | |
839 signaling_thread()->Invoke<void>(Bind( | 904 signaling_thread()->Invoke<void>(Bind( |
840 &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); | 905 &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); |
841 } | 906 } |
842 | 907 |
843 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { | 908 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { |
844 ASSERT(signaling_thread() == rtc::Thread::Current()); | 909 ASSERT(signaling_thread() == rtc::Thread::Current()); |
845 SignalDtlsSetupFailure(this, rtcp); | 910 SignalDtlsSetupFailure(this, rtcp); |
846 } | 911 } |
847 | 912 |
848 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { | 913 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { |
849 std::vector<int> crypto_suites; | 914 std::vector<int> crypto_suites; |
850 // We always use the default SRTP crypto suites for RTCP, but we may use | 915 // 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. | 916 // different crypto suites for RTP depending on the media type. |
852 if (!rtcp) { | 917 if (!rtcp) { |
853 GetSrtpCryptoSuites(&crypto_suites); | 918 GetSrtpCryptoSuites(&crypto_suites); |
854 } else { | 919 } else { |
855 GetDefaultSrtpCryptoSuites(&crypto_suites); | 920 GetDefaultSrtpCryptoSuites(&crypto_suites); |
856 } | 921 } |
857 return tc->SetSrtpCryptoSuites(crypto_suites); | 922 return tc->SetSrtpCryptoSuites(crypto_suites); |
858 } | 923 } |
859 | 924 |
860 bool BaseChannel::ShouldSetupDtlsSrtp() const { | 925 bool BaseChannel::ShouldSetupDtlsSrtp() const { |
861 // Since DTLS is applied to all channels, checking RTP should be enough. | 926 // Since DTLS is applied to all channels, checking RTP should be enough. |
862 return transport_channel_ && transport_channel_->IsDtlsActive(); | 927 return transport_channel_ && transport_channel_->IsDtlsActive(); |
863 } | 928 } |
864 | 929 |
865 // This function returns true if either DTLS-SRTP is not in use | 930 // This function returns true if either DTLS-SRTP is not in use |
866 // *or* DTLS-SRTP is successfully set up. | 931 // *or* DTLS-SRTP is successfully set up. |
867 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { | 932 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp_channel) { |
933 RTC_DCHECK(network_thread_->IsCurrent()); | |
868 bool ret = false; | 934 bool ret = false; |
869 | 935 |
870 TransportChannel* channel = | 936 TransportChannel* channel = |
871 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; | 937 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; |
872 | 938 |
873 RTC_DCHECK(channel->IsDtlsActive()); | 939 RTC_DCHECK(channel->IsDtlsActive()); |
874 | 940 |
875 int selected_crypto_suite; | 941 int selected_crypto_suite; |
876 | 942 |
877 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { | 943 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 } | 1009 } |
944 | 1010 |
945 if (!ret) | 1011 if (!ret) |
946 LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; | 1012 LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; |
947 else | 1013 else |
948 dtls_keyed_ = true; | 1014 dtls_keyed_ = true; |
949 | 1015 |
950 return ret; | 1016 return ret; |
951 } | 1017 } |
952 | 1018 |
953 void BaseChannel::MaybeSetupDtlsSrtp_w() { | 1019 void BaseChannel::MaybeSetupDtlsSrtp_n() { |
954 if (srtp_filter_.IsActive()) { | 1020 if (srtp_filter_.IsActive()) { |
955 return; | 1021 return; |
956 } | 1022 } |
957 | 1023 |
958 if (!ShouldSetupDtlsSrtp()) { | 1024 if (!ShouldSetupDtlsSrtp()) { |
959 return; | 1025 return; |
960 } | 1026 } |
961 | 1027 |
962 if (!SetupDtlsSrtp(false)) { | 1028 if (!SetupDtlsSrtp_n(false)) { |
963 SignalDtlsSetupFailure_w(false); | 1029 SignalDtlsSetupFailure_n(false); |
964 return; | 1030 return; |
965 } | 1031 } |
966 | 1032 |
967 if (rtcp_transport_channel_) { | 1033 if (rtcp_transport_channel_) { |
968 if (!SetupDtlsSrtp(true)) { | 1034 if (!SetupDtlsSrtp_n(true)) { |
969 SignalDtlsSetupFailure_w(true); | 1035 SignalDtlsSetupFailure_n(true); |
970 return; | 1036 return; |
971 } | 1037 } |
972 } | 1038 } |
973 } | 1039 } |
974 | 1040 |
975 void BaseChannel::ChannelNotWritable_w() { | 1041 void BaseChannel::ChannelNotWritable_n() { |
976 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1042 RTC_DCHECK(network_thread_->IsCurrent()); |
977 if (!writable_) | 1043 if (!writable_) |
978 return; | 1044 return; |
979 | 1045 |
980 LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; | 1046 LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; |
981 writable_ = false; | 1047 writable_ = false; |
982 ChangeState(); | 1048 ChangeState(); |
983 } | 1049 } |
984 | 1050 |
985 bool BaseChannel::SetRtpTransportParameters_w( | 1051 bool BaseChannel::SetRtpTransportParameters( |
986 const MediaContentDescription* content, | 1052 const MediaContentDescription* content, |
987 ContentAction action, | 1053 ContentAction action, |
988 ContentSource src, | 1054 ContentSource src, |
989 std::string* error_desc) { | 1055 std::string* error_desc) { |
990 if (action == CA_UPDATE) { | 1056 if (action == CA_UPDATE) { |
991 // These parameters never get changed by a CA_UDPATE. | 1057 // These parameters never get changed by a CA_UDPATE. |
992 return true; | 1058 return true; |
993 } | 1059 } |
994 | 1060 |
995 // Cache secure_required_ for belt and suspenders check on SendPacket | 1061 // Cache secure_required_ for belt and suspenders check on SendPacket |
996 if (src == CS_LOCAL) { | 1062 return network_thread_->Invoke<bool>( |
997 set_secure_required(content->crypto_required() != CT_NONE); | 1063 [this, content, action, src, error_desc] { |
998 } | 1064 if (src == CS_LOCAL) { |
1065 set_secure_required(content->crypto_required() != CT_NONE); | |
1066 } | |
999 | 1067 |
1000 if (!SetSrtp_w(content->cryptos(), action, src, error_desc)) { | 1068 if (!SetSrtp_n(content->cryptos(), action, src, error_desc)) { |
1001 return false; | 1069 return false; |
1002 } | 1070 } |
1003 | 1071 |
1004 if (!SetRtcpMux_w(content->rtcp_mux(), action, src, error_desc)) { | 1072 if (!SetRtcpMux_n(content->rtcp_mux(), action, src, error_desc)) { |
1005 return false; | 1073 return false; |
1006 } | 1074 } |
1007 | 1075 |
1008 return true; | 1076 return true; |
1077 }); | |
1009 } | 1078 } |
1010 | 1079 |
1011 // |dtls| will be set to true if DTLS is active for transport channel and | 1080 // |dtls| will be set to true if DTLS is active for transport channel and |
1012 // crypto is empty. | 1081 // crypto is empty. |
1013 bool BaseChannel::CheckSrtpConfig(const std::vector<CryptoParams>& cryptos, | 1082 bool BaseChannel::CheckSrtpConfig(const std::vector<CryptoParams>& cryptos, |
1014 bool* dtls, | 1083 bool* dtls, |
1015 std::string* error_desc) { | 1084 std::string* error_desc) { |
1016 *dtls = transport_channel_->IsDtlsActive(); | 1085 *dtls = transport_channel_->IsDtlsActive(); |
1017 if (*dtls && !cryptos.empty()) { | 1086 if (*dtls && !cryptos.empty()) { |
1018 SafeSetError("Cryptos must be empty when DTLS is active.", | 1087 SafeSetError("Cryptos must be empty when DTLS is active.", |
1019 error_desc); | 1088 error_desc); |
1020 return false; | 1089 return false; |
1021 } | 1090 } |
1022 return true; | 1091 return true; |
1023 } | 1092 } |
1024 | 1093 |
1025 bool BaseChannel::SetSrtp_w(const std::vector<CryptoParams>& cryptos, | 1094 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos, |
1026 ContentAction action, | 1095 ContentAction action, |
1027 ContentSource src, | 1096 ContentSource src, |
1028 std::string* error_desc) { | 1097 std::string* error_desc) { |
1029 TRACE_EVENT0("webrtc", "BaseChannel::SetSrtp_w"); | 1098 TRACE_EVENT0("webrtc", "BaseChannel::SetSrtp_w"); |
1030 if (action == CA_UPDATE) { | 1099 if (action == CA_UPDATE) { |
1031 // no crypto params. | 1100 // no crypto params. |
1032 return true; | 1101 return true; |
1033 } | 1102 } |
1034 bool ret = false; | 1103 bool ret = false; |
1035 bool dtls = false; | 1104 bool dtls = false; |
(...skipping 27 matching lines...) Expand all Loading... | |
1063 break; | 1132 break; |
1064 } | 1133 } |
1065 if (!ret) { | 1134 if (!ret) { |
1066 SafeSetError("Failed to setup SRTP filter.", error_desc); | 1135 SafeSetError("Failed to setup SRTP filter.", error_desc); |
1067 return false; | 1136 return false; |
1068 } | 1137 } |
1069 return true; | 1138 return true; |
1070 } | 1139 } |
1071 | 1140 |
1072 void BaseChannel::ActivateRtcpMux() { | 1141 void BaseChannel::ActivateRtcpMux() { |
1073 worker_thread_->Invoke<void>(Bind( | 1142 network_thread_->Invoke<void>(Bind(&BaseChannel::ActivateRtcpMux_n, this)); |
1074 &BaseChannel::ActivateRtcpMux_w, this)); | |
1075 } | 1143 } |
1076 | 1144 |
1077 void BaseChannel::ActivateRtcpMux_w() { | 1145 void BaseChannel::ActivateRtcpMux_n() { |
1078 if (!rtcp_mux_filter_.IsActive()) { | 1146 if (!rtcp_mux_filter_.IsActive()) { |
1079 rtcp_mux_filter_.SetActive(); | 1147 rtcp_mux_filter_.SetActive(); |
1080 set_rtcp_transport_channel(nullptr, true); | 1148 set_rtcp_transport_channel(nullptr, true); |
1081 rtcp_transport_enabled_ = false; | 1149 rtcp_transport_enabled_ = false; |
1082 } | 1150 } |
1083 } | 1151 } |
1084 | 1152 |
1085 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action, | 1153 bool BaseChannel::SetRtcpMux_n(bool enable, |
1154 ContentAction action, | |
1086 ContentSource src, | 1155 ContentSource src, |
1087 std::string* error_desc) { | 1156 std::string* error_desc) { |
1088 bool ret = false; | 1157 bool ret = false; |
1089 switch (action) { | 1158 switch (action) { |
1090 case CA_OFFER: | 1159 case CA_OFFER: |
1091 ret = rtcp_mux_filter_.SetOffer(enable, src); | 1160 ret = rtcp_mux_filter_.SetOffer(enable, src); |
1092 break; | 1161 break; |
1093 case CA_PRANSWER: | 1162 case CA_PRANSWER: |
1094 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); | 1163 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); |
1095 break; | 1164 break; |
(...skipping 18 matching lines...) Expand all Loading... | |
1114 if (!ret) { | 1183 if (!ret) { |
1115 SafeSetError("Failed to setup RTCP mux filter.", error_desc); | 1184 SafeSetError("Failed to setup RTCP mux filter.", error_desc); |
1116 return false; | 1185 return false; |
1117 } | 1186 } |
1118 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or | 1187 // |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 | 1188 // CA_ANSWER, but we only want to tear down the RTCP transport channel if we |
1120 // received a final answer. | 1189 // received a final answer. |
1121 if (rtcp_mux_filter_.IsActive()) { | 1190 if (rtcp_mux_filter_.IsActive()) { |
1122 // If the RTP transport is already writable, then so are we. | 1191 // If the RTP transport is already writable, then so are we. |
1123 if (transport_channel_->writable()) { | 1192 if (transport_channel_->writable()) { |
1124 ChannelWritable_w(); | 1193 ChannelWritable_n(); |
1125 } | 1194 } |
1126 } | 1195 } |
1127 | 1196 |
1128 return true; | 1197 return true; |
1129 } | 1198 } |
1130 | 1199 |
1131 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { | 1200 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { |
1132 ASSERT(worker_thread() == rtc::Thread::Current()); | 1201 ASSERT(worker_thread() == rtc::Thread::Current()); |
1133 return media_channel()->AddRecvStream(sp); | 1202 return media_channel()->AddRecvStream(sp); |
1134 } | 1203 } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1289 const std::vector<RtpHeaderExtension>& extensions) { | 1358 const std::vector<RtpHeaderExtension>& extensions) { |
1290 const RtpHeaderExtension* send_time_extension = | 1359 const RtpHeaderExtension* send_time_extension = |
1291 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); | 1360 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); |
1292 rtp_abs_sendtime_extn_id_ = | 1361 rtp_abs_sendtime_extn_id_ = |
1293 send_time_extension ? send_time_extension->id : -1; | 1362 send_time_extension ? send_time_extension->id : -1; |
1294 } | 1363 } |
1295 | 1364 |
1296 void BaseChannel::OnMessage(rtc::Message *pmsg) { | 1365 void BaseChannel::OnMessage(rtc::Message *pmsg) { |
1297 TRACE_EVENT0("webrtc", "BaseChannel::OnMessage"); | 1366 TRACE_EVENT0("webrtc", "BaseChannel::OnMessage"); |
1298 switch (pmsg->message_id) { | 1367 switch (pmsg->message_id) { |
1299 case MSG_RTPPACKET: | 1368 case MSG_SENDING_RTP_PACKET: |
1300 case MSG_RTCPPACKET: { | 1369 case MSG_SENDING_RTCP_PACKET: { |
1301 PacketMessageData* data = static_cast<PacketMessageData*>(pmsg->pdata); | 1370 RTC_DCHECK(network_thread_->IsCurrent()); |
1302 SendPacket(pmsg->message_id == MSG_RTCPPACKET, &data->packet, | 1371 SendingPacketMessageData* data = |
1303 data->options); | 1372 static_cast<SendingPacketMessageData*>(pmsg->pdata); |
1304 delete data; // because it is Posted | 1373 bool rtcp = pmsg->message_id == MSG_SENDING_RTCP_PACKET; |
1374 SendPacket(rtcp, &data->packet, data->options); | |
1375 delete data; | |
1305 break; | 1376 break; |
1306 } | 1377 } |
1307 case MSG_FIRSTPACKETRECEIVED: { | 1378 case MSG_FIRSTPACKETRECEIVED: { |
1308 SignalFirstPacketReceived(this); | 1379 SignalFirstPacketReceived(this); |
1309 break; | 1380 break; |
1310 } | 1381 } |
1382 case MSG_RECEIVED_RTP_PACKET: { | |
1383 RTC_DCHECK(worker_thread_->IsCurrent()); | |
1384 ReceivedPacketMessageData* data = | |
1385 static_cast<ReceivedPacketMessageData*>(pmsg->pdata); | |
1386 media_channel_->OnPacketReceived(&data->packet, data->packet_time); | |
1387 delete data; | |
1388 break; | |
1389 } | |
1390 case MSG_RECEIVED_RTCP_PACKET: { | |
1391 RTC_DCHECK(worker_thread_->IsCurrent()); | |
1392 ReceivedPacketMessageData* data = | |
1393 static_cast<ReceivedPacketMessageData*>(pmsg->pdata); | |
1394 media_channel_->OnRtcpReceived(&data->packet, data->packet_time); | |
1395 delete data; | |
1396 break; | |
1397 } | |
1398 case MSG_CHANGE_STATE: { | |
1399 RTC_DCHECK(worker_thread_->IsCurrent()); | |
1400 ChangeState_w(); | |
1401 break; | |
1402 } | |
1403 case MSG_READY_TO_SEND: { | |
1404 RTC_DCHECK(worker_thread_->IsCurrent()); | |
1405 media_channel_->OnReadyToSend(true); | |
1406 break; | |
1407 } | |
1408 case MSG_NOT_READY_TO_SEND: { | |
1409 RTC_DCHECK(worker_thread_->IsCurrent()); | |
1410 media_channel_->OnReadyToSend(false); | |
1411 break; | |
1412 } | |
1413 case MSG_NETWORK_ROUTE_CHANGED: { | |
1414 RTC_DCHECK(worker_thread_->IsCurrent()); | |
1415 NetworkRouteChanged* data = | |
1416 static_cast<NetworkRouteChanged*>(pmsg->pdata); | |
1417 media_channel()->OnNetworkRouteChanged(data->transport_name, | |
1418 data->network_route); | |
1419 delete data; | |
1420 break; | |
1421 } | |
1311 } | 1422 } |
1312 } | 1423 } |
1313 | 1424 |
1314 void BaseChannel::FlushRtcpMessages() { | 1425 void BaseChannel::FlushRtcpMessages() { |
1315 // Flush all remaining RTCP messages. This should only be called in | 1426 // Flush all remaining RTCP messages. This should only be called in |
1316 // destructor. | 1427 // destructor. |
1317 ASSERT(rtc::Thread::Current() == worker_thread_); | 1428 network_thread_->Invoke<void>([this] { |
1318 rtc::MessageList rtcp_messages; | 1429 rtc::MessageList rtcp_messages; |
1319 worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages); | 1430 network_thread_->Clear(this, MSG_SENDING_RTCP_PACKET, &rtcp_messages); |
1320 for (rtc::MessageList::iterator it = rtcp_messages.begin(); | 1431 for (const auto& message : rtcp_messages) { |
1321 it != rtcp_messages.end(); ++it) { | 1432 network_thread_->Send(this, MSG_SENDING_RTCP_PACKET, message.pdata); |
1322 worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata); | 1433 } |
1323 } | 1434 }); |
1324 } | 1435 } |
1325 | 1436 |
1326 VoiceChannel::VoiceChannel(rtc::Thread* thread, | 1437 VoiceChannel::VoiceChannel(rtc::Thread* worker_thread, |
1438 rtc::Thread* network_thread, | |
1327 MediaEngineInterface* media_engine, | 1439 MediaEngineInterface* media_engine, |
1328 VoiceMediaChannel* media_channel, | 1440 VoiceMediaChannel* media_channel, |
1329 TransportController* transport_controller, | 1441 TransportController* transport_controller, |
1330 const std::string& content_name, | 1442 const std::string& content_name, |
1331 bool rtcp) | 1443 bool rtcp) |
1332 : BaseChannel(thread, | 1444 : BaseChannel(worker_thread, |
1445 network_thread, | |
1333 media_channel, | 1446 media_channel, |
1334 transport_controller, | 1447 transport_controller, |
1335 content_name, | 1448 content_name, |
1336 rtcp), | 1449 rtcp), |
1337 media_engine_(media_engine), | 1450 media_engine_(media_engine), |
1338 received_media_(false) {} | 1451 received_media_(false) {} |
1339 | 1452 |
1340 VoiceChannel::~VoiceChannel() { | 1453 VoiceChannel::~VoiceChannel() { |
1341 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); | 1454 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); |
1342 StopAudioMonitor(); | 1455 StopAudioMonitor(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1480 int flags) { | 1593 int flags) { |
1481 BaseChannel::OnChannelRead(channel, data, len, packet_time, flags); | 1594 BaseChannel::OnChannelRead(channel, data, len, packet_time, flags); |
1482 | 1595 |
1483 // Set a flag when we've received an RTP packet. If we're waiting for early | 1596 // Set a flag when we've received an RTP packet. If we're waiting for early |
1484 // media, this will disable the timeout. | 1597 // media, this will disable the timeout. |
1485 if (!received_media_ && !PacketIsRtcp(channel, data, len)) { | 1598 if (!received_media_ && !PacketIsRtcp(channel, data, len)) { |
1486 received_media_ = true; | 1599 received_media_ = true; |
1487 } | 1600 } |
1488 } | 1601 } |
1489 | 1602 |
1490 void VoiceChannel::ChangeState() { | 1603 void BaseChannel::ChangeState() { |
1604 if (worker_thread_->IsCurrent()) { | |
perkj_webrtc
2016/04/29 07:46:12
dcheck thread. Which thread is this?
danilchap
2016/04/29 08:47:00
Done.
| |
1605 ChangeState_w(); | |
1606 } else { | |
1607 worker_thread_->Post(this, MSG_CHANGE_STATE); | |
1608 } | |
1609 } | |
1610 | |
1611 void VoiceChannel::ChangeState_w() { | |
1491 // Render incoming data if we're the active call, and we have the local | 1612 // 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. | 1613 // content. We receive data on the default channel and multiplexed streams. |
1493 bool recv = IsReadyToReceive(); | 1614 bool recv = IsReadyToReceive(); |
1494 media_channel()->SetPlayout(recv); | 1615 media_channel()->SetPlayout(recv); |
1495 | 1616 |
1496 // Send outgoing data if we're the active call, we have the remote content, | 1617 // Send outgoing data if we're the active call, we have the remote content, |
1497 // and we have had some form of connectivity. | 1618 // and we have had some form of connectivity. |
1498 bool send = IsReadyToSend(); | 1619 bool send = IsReadyToSend(); |
1499 media_channel()->SetSend(send); | 1620 media_channel()->SetSend(send); |
1500 | 1621 |
(...skipping 13 matching lines...) Expand all Loading... | |
1514 LOG(LS_INFO) << "Setting local voice description"; | 1635 LOG(LS_INFO) << "Setting local voice description"; |
1515 | 1636 |
1516 const AudioContentDescription* audio = | 1637 const AudioContentDescription* audio = |
1517 static_cast<const AudioContentDescription*>(content); | 1638 static_cast<const AudioContentDescription*>(content); |
1518 ASSERT(audio != NULL); | 1639 ASSERT(audio != NULL); |
1519 if (!audio) { | 1640 if (!audio) { |
1520 SafeSetError("Can't find audio content in local description.", error_desc); | 1641 SafeSetError("Can't find audio content in local description.", error_desc); |
1521 return false; | 1642 return false; |
1522 } | 1643 } |
1523 | 1644 |
1524 if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) { | 1645 if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) { |
1525 return false; | 1646 return false; |
1526 } | 1647 } |
1527 | 1648 |
1528 AudioRecvParameters recv_params = last_recv_params_; | 1649 AudioRecvParameters recv_params = last_recv_params_; |
1529 RtpParametersFromMediaDescription(audio, &recv_params); | 1650 RtpParametersFromMediaDescription(audio, &recv_params); |
1530 if (!media_channel()->SetRecvParameters(recv_params)) { | 1651 if (!media_channel()->SetRecvParameters(recv_params)) { |
1531 SafeSetError("Failed to set local audio description recv parameters.", | 1652 SafeSetError("Failed to set local audio description recv parameters.", |
1532 error_desc); | 1653 error_desc); |
1533 return false; | 1654 return false; |
1534 } | 1655 } |
1535 for (const AudioCodec& codec : audio->codecs()) { | 1656 for (const AudioCodec& codec : audio->codecs()) { |
1536 bundle_filter()->AddPayloadType(codec.id); | 1657 bundle_filter()->AddPayloadType(codec.id); |
1537 } | 1658 } |
1538 last_recv_params_ = recv_params; | 1659 last_recv_params_ = recv_params; |
1539 | 1660 |
1540 // TODO(pthatcher): Move local streams into AudioSendParameters, and | 1661 // TODO(pthatcher): Move local streams into AudioSendParameters, and |
1541 // only give it to the media channel once we have a remote | 1662 // only give it to the media channel once we have a remote |
1542 // description too (without a remote description, we won't be able | 1663 // description too (without a remote description, we won't be able |
1543 // to send them anyway). | 1664 // to send them anyway). |
1544 if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) { | 1665 if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) { |
1545 SafeSetError("Failed to set local audio description streams.", error_desc); | 1666 SafeSetError("Failed to set local audio description streams.", error_desc); |
1546 return false; | 1667 return false; |
1547 } | 1668 } |
1548 | 1669 |
1549 set_local_content_direction(content->direction()); | 1670 set_local_content_direction(content->direction()); |
1550 ChangeState(); | 1671 ChangeState_w(); |
1551 return true; | 1672 return true; |
1552 } | 1673 } |
1553 | 1674 |
1554 bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content, | 1675 bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content, |
1555 ContentAction action, | 1676 ContentAction action, |
1556 std::string* error_desc) { | 1677 std::string* error_desc) { |
1557 TRACE_EVENT0("webrtc", "VoiceChannel::SetRemoteContent_w"); | 1678 TRACE_EVENT0("webrtc", "VoiceChannel::SetRemoteContent_w"); |
1558 ASSERT(worker_thread() == rtc::Thread::Current()); | 1679 ASSERT(worker_thread() == rtc::Thread::Current()); |
1559 LOG(LS_INFO) << "Setting remote voice description"; | 1680 LOG(LS_INFO) << "Setting remote voice description"; |
1560 | 1681 |
1561 const AudioContentDescription* audio = | 1682 const AudioContentDescription* audio = |
1562 static_cast<const AudioContentDescription*>(content); | 1683 static_cast<const AudioContentDescription*>(content); |
1563 ASSERT(audio != NULL); | 1684 ASSERT(audio != NULL); |
1564 if (!audio) { | 1685 if (!audio) { |
1565 SafeSetError("Can't find audio content in remote description.", error_desc); | 1686 SafeSetError("Can't find audio content in remote description.", error_desc); |
1566 return false; | 1687 return false; |
1567 } | 1688 } |
1568 | 1689 |
1569 if (!SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) { | 1690 if (!SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) { |
1570 return false; | 1691 return false; |
1571 } | 1692 } |
1572 | 1693 |
1573 AudioSendParameters send_params = last_send_params_; | 1694 AudioSendParameters send_params = last_send_params_; |
1574 RtpSendParametersFromMediaDescription(audio, &send_params); | 1695 RtpSendParametersFromMediaDescription(audio, &send_params); |
1575 if (audio->agc_minus_10db()) { | 1696 if (audio->agc_minus_10db()) { |
1576 send_params.options.adjust_agc_delta = rtc::Optional<int>(kAgcMinus10db); | 1697 send_params.options.adjust_agc_delta = rtc::Optional<int>(kAgcMinus10db); |
1577 } | 1698 } |
1578 | 1699 |
1579 bool parameters_applied = media_channel()->SetSendParameters(send_params); | 1700 bool parameters_applied = media_channel()->SetSendParameters(send_params); |
(...skipping 11 matching lines...) Expand all Loading... | |
1591 if (!UpdateRemoteStreams_w(audio->streams(), action, error_desc)) { | 1712 if (!UpdateRemoteStreams_w(audio->streams(), action, error_desc)) { |
1592 SafeSetError("Failed to set remote audio description streams.", error_desc); | 1713 SafeSetError("Failed to set remote audio description streams.", error_desc); |
1593 return false; | 1714 return false; |
1594 } | 1715 } |
1595 | 1716 |
1596 if (audio->rtp_header_extensions_set()) { | 1717 if (audio->rtp_header_extensions_set()) { |
1597 MaybeCacheRtpAbsSendTimeHeaderExtension(audio->rtp_header_extensions()); | 1718 MaybeCacheRtpAbsSendTimeHeaderExtension(audio->rtp_header_extensions()); |
1598 } | 1719 } |
1599 | 1720 |
1600 set_remote_content_direction(content->direction()); | 1721 set_remote_content_direction(content->direction()); |
1601 ChangeState(); | 1722 ChangeState_w(); |
1602 return true; | 1723 return true; |
1603 } | 1724 } |
1604 | 1725 |
1605 void VoiceChannel::HandleEarlyMediaTimeout() { | 1726 void VoiceChannel::HandleEarlyMediaTimeout() { |
1606 // This occurs on the main thread, not the worker thread. | 1727 // This occurs on the main thread, not the worker thread. |
1607 if (!received_media_) { | 1728 if (!received_media_) { |
1608 LOG(LS_INFO) << "No early media received before timeout"; | 1729 LOG(LS_INFO) << "No early media received before timeout"; |
1609 SignalEarlyMediaTimeout(this); | 1730 SignalEarlyMediaTimeout(this); |
1610 } | 1731 } |
1611 } | 1732 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1649 | 1770 |
1650 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, | 1771 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, |
1651 const AudioInfo& info) { | 1772 const AudioInfo& info) { |
1652 SignalAudioMonitor(this, info); | 1773 SignalAudioMonitor(this, info); |
1653 } | 1774 } |
1654 | 1775 |
1655 void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { | 1776 void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |
1656 GetSupportedAudioCryptoSuites(crypto_suites); | 1777 GetSupportedAudioCryptoSuites(crypto_suites); |
1657 } | 1778 } |
1658 | 1779 |
1659 VideoChannel::VideoChannel(rtc::Thread* thread, | 1780 VideoChannel::VideoChannel(rtc::Thread* worker_thread, |
1781 rtc::Thread* network_thread, | |
1660 VideoMediaChannel* media_channel, | 1782 VideoMediaChannel* media_channel, |
1661 TransportController* transport_controller, | 1783 TransportController* transport_controller, |
1662 const std::string& content_name, | 1784 const std::string& content_name, |
1663 bool rtcp) | 1785 bool rtcp) |
1664 : BaseChannel(thread, | 1786 : BaseChannel(worker_thread, |
1787 network_thread, | |
1665 media_channel, | 1788 media_channel, |
1666 transport_controller, | 1789 transport_controller, |
1667 content_name, | 1790 content_name, |
1668 rtcp) {} | 1791 rtcp) {} |
1669 | 1792 |
1670 bool VideoChannel::Init() { | 1793 bool VideoChannel::Init() { |
1671 if (!BaseChannel::Init()) { | 1794 if (!BaseChannel::Init()) { |
1672 return false; | 1795 return false; |
1673 } | 1796 } |
1674 return true; | 1797 return true; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1716 bool VideoChannel::SetRtpParameters(uint32_t ssrc, | 1839 bool VideoChannel::SetRtpParameters(uint32_t ssrc, |
1717 const webrtc::RtpParameters& parameters) { | 1840 const webrtc::RtpParameters& parameters) { |
1718 return InvokeOnWorker( | 1841 return InvokeOnWorker( |
1719 Bind(&VideoChannel::SetRtpParameters_w, this, ssrc, parameters)); | 1842 Bind(&VideoChannel::SetRtpParameters_w, this, ssrc, parameters)); |
1720 } | 1843 } |
1721 | 1844 |
1722 bool VideoChannel::SetRtpParameters_w(uint32_t ssrc, | 1845 bool VideoChannel::SetRtpParameters_w(uint32_t ssrc, |
1723 webrtc::RtpParameters parameters) { | 1846 webrtc::RtpParameters parameters) { |
1724 return media_channel()->SetRtpParameters(ssrc, parameters); | 1847 return media_channel()->SetRtpParameters(ssrc, parameters); |
1725 } | 1848 } |
1726 void VideoChannel::ChangeState() { | 1849 |
1850 void VideoChannel::ChangeState_w() { | |
1727 // Send outgoing data if we're the active call, we have the remote content, | 1851 // Send outgoing data if we're the active call, we have the remote content, |
1728 // and we have had some form of connectivity. | 1852 // and we have had some form of connectivity. |
1729 bool send = IsReadyToSend(); | 1853 bool send = IsReadyToSend(); |
1730 if (!media_channel()->SetSend(send)) { | 1854 if (!media_channel()->SetSend(send)) { |
1731 LOG(LS_ERROR) << "Failed to SetSend on video channel"; | 1855 LOG(LS_ERROR) << "Failed to SetSend on video channel"; |
1732 // TODO(gangji): Report error back to server. | 1856 // TODO(gangji): Report error back to server. |
1733 } | 1857 } |
1734 | 1858 |
1735 LOG(LS_INFO) << "Changing video state, send=" << send; | 1859 LOG(LS_INFO) << "Changing video state, send=" << send; |
1736 } | 1860 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1768 LOG(LS_INFO) << "Setting local video description"; | 1892 LOG(LS_INFO) << "Setting local video description"; |
1769 | 1893 |
1770 const VideoContentDescription* video = | 1894 const VideoContentDescription* video = |
1771 static_cast<const VideoContentDescription*>(content); | 1895 static_cast<const VideoContentDescription*>(content); |
1772 ASSERT(video != NULL); | 1896 ASSERT(video != NULL); |
1773 if (!video) { | 1897 if (!video) { |
1774 SafeSetError("Can't find video content in local description.", error_desc); | 1898 SafeSetError("Can't find video content in local description.", error_desc); |
1775 return false; | 1899 return false; |
1776 } | 1900 } |
1777 | 1901 |
1778 if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) { | 1902 if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) { |
1779 return false; | 1903 return false; |
1780 } | 1904 } |
1781 | 1905 |
1782 VideoRecvParameters recv_params = last_recv_params_; | 1906 VideoRecvParameters recv_params = last_recv_params_; |
1783 RtpParametersFromMediaDescription(video, &recv_params); | 1907 RtpParametersFromMediaDescription(video, &recv_params); |
1784 if (!media_channel()->SetRecvParameters(recv_params)) { | 1908 if (!media_channel()->SetRecvParameters(recv_params)) { |
1785 SafeSetError("Failed to set local video description recv parameters.", | 1909 SafeSetError("Failed to set local video description recv parameters.", |
1786 error_desc); | 1910 error_desc); |
1787 return false; | 1911 return false; |
1788 } | 1912 } |
1789 for (const VideoCodec& codec : video->codecs()) { | 1913 for (const VideoCodec& codec : video->codecs()) { |
1790 bundle_filter()->AddPayloadType(codec.id); | 1914 bundle_filter()->AddPayloadType(codec.id); |
1791 } | 1915 } |
1792 last_recv_params_ = recv_params; | 1916 last_recv_params_ = recv_params; |
1793 | 1917 |
1794 // TODO(pthatcher): Move local streams into VideoSendParameters, and | 1918 // TODO(pthatcher): Move local streams into VideoSendParameters, and |
1795 // only give it to the media channel once we have a remote | 1919 // only give it to the media channel once we have a remote |
1796 // description too (without a remote description, we won't be able | 1920 // description too (without a remote description, we won't be able |
1797 // to send them anyway). | 1921 // to send them anyway). |
1798 if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) { | 1922 if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) { |
1799 SafeSetError("Failed to set local video description streams.", error_desc); | 1923 SafeSetError("Failed to set local video description streams.", error_desc); |
1800 return false; | 1924 return false; |
1801 } | 1925 } |
1802 | 1926 |
1803 set_local_content_direction(content->direction()); | 1927 set_local_content_direction(content->direction()); |
1804 ChangeState(); | 1928 ChangeState_w(); |
1805 return true; | 1929 return true; |
1806 } | 1930 } |
1807 | 1931 |
1808 bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, | 1932 bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, |
1809 ContentAction action, | 1933 ContentAction action, |
1810 std::string* error_desc) { | 1934 std::string* error_desc) { |
1811 TRACE_EVENT0("webrtc", "VideoChannel::SetRemoteContent_w"); | 1935 TRACE_EVENT0("webrtc", "VideoChannel::SetRemoteContent_w"); |
1812 ASSERT(worker_thread() == rtc::Thread::Current()); | 1936 ASSERT(worker_thread() == rtc::Thread::Current()); |
1813 LOG(LS_INFO) << "Setting remote video description"; | 1937 LOG(LS_INFO) << "Setting remote video description"; |
1814 | 1938 |
1815 const VideoContentDescription* video = | 1939 const VideoContentDescription* video = |
1816 static_cast<const VideoContentDescription*>(content); | 1940 static_cast<const VideoContentDescription*>(content); |
1817 ASSERT(video != NULL); | 1941 ASSERT(video != NULL); |
1818 if (!video) { | 1942 if (!video) { |
1819 SafeSetError("Can't find video content in remote description.", error_desc); | 1943 SafeSetError("Can't find video content in remote description.", error_desc); |
1820 return false; | 1944 return false; |
1821 } | 1945 } |
1822 | 1946 |
1823 | 1947 if (!SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) { |
1824 if (!SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) { | |
1825 return false; | 1948 return false; |
1826 } | 1949 } |
1827 | 1950 |
1828 VideoSendParameters send_params = last_send_params_; | 1951 VideoSendParameters send_params = last_send_params_; |
1829 RtpSendParametersFromMediaDescription(video, &send_params); | 1952 RtpSendParametersFromMediaDescription(video, &send_params); |
1830 if (video->conference_mode()) { | 1953 if (video->conference_mode()) { |
1831 send_params.conference_mode = true; | 1954 send_params.conference_mode = true; |
1832 } | 1955 } |
1833 | 1956 |
1834 bool parameters_applied = media_channel()->SetSendParameters(send_params); | 1957 bool parameters_applied = media_channel()->SetSendParameters(send_params); |
(...skipping 12 matching lines...) Expand all Loading... | |
1847 if (!UpdateRemoteStreams_w(video->streams(), action, error_desc)) { | 1970 if (!UpdateRemoteStreams_w(video->streams(), action, error_desc)) { |
1848 SafeSetError("Failed to set remote video description streams.", error_desc); | 1971 SafeSetError("Failed to set remote video description streams.", error_desc); |
1849 return false; | 1972 return false; |
1850 } | 1973 } |
1851 | 1974 |
1852 if (video->rtp_header_extensions_set()) { | 1975 if (video->rtp_header_extensions_set()) { |
1853 MaybeCacheRtpAbsSendTimeHeaderExtension(video->rtp_header_extensions()); | 1976 MaybeCacheRtpAbsSendTimeHeaderExtension(video->rtp_header_extensions()); |
1854 } | 1977 } |
1855 | 1978 |
1856 set_remote_content_direction(content->direction()); | 1979 set_remote_content_direction(content->direction()); |
1857 ChangeState(); | 1980 ChangeState_w(); |
1858 return true; | 1981 return true; |
1859 } | 1982 } |
1860 | 1983 |
1861 void VideoChannel::OnMessage(rtc::Message *pmsg) { | 1984 void VideoChannel::OnMessage(rtc::Message *pmsg) { |
1862 switch (pmsg->message_id) { | 1985 switch (pmsg->message_id) { |
1863 case MSG_CHANNEL_ERROR: { | 1986 case MSG_CHANNEL_ERROR: { |
1864 const VideoChannelErrorMessageData* data = | 1987 const VideoChannelErrorMessageData* data = |
1865 static_cast<VideoChannelErrorMessageData*>(pmsg->pdata); | 1988 static_cast<VideoChannelErrorMessageData*>(pmsg->pdata); |
1866 delete data; | 1989 delete data; |
1867 break; | 1990 break; |
(...skipping 14 matching lines...) Expand all Loading... | |
1882 void VideoChannel::OnMediaMonitorUpdate( | 2005 void VideoChannel::OnMediaMonitorUpdate( |
1883 VideoMediaChannel* media_channel, const VideoMediaInfo &info) { | 2006 VideoMediaChannel* media_channel, const VideoMediaInfo &info) { |
1884 ASSERT(media_channel == this->media_channel()); | 2007 ASSERT(media_channel == this->media_channel()); |
1885 SignalMediaMonitor(this, info); | 2008 SignalMediaMonitor(this, info); |
1886 } | 2009 } |
1887 | 2010 |
1888 void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { | 2011 void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |
1889 GetSupportedVideoCryptoSuites(crypto_suites); | 2012 GetSupportedVideoCryptoSuites(crypto_suites); |
1890 } | 2013 } |
1891 | 2014 |
1892 DataChannel::DataChannel(rtc::Thread* thread, | 2015 DataChannel::DataChannel(rtc::Thread* worker_thread, |
2016 rtc::Thread* network_thread, | |
1893 DataMediaChannel* media_channel, | 2017 DataMediaChannel* media_channel, |
1894 TransportController* transport_controller, | 2018 TransportController* transport_controller, |
1895 const std::string& content_name, | 2019 const std::string& content_name, |
1896 bool rtcp) | 2020 bool rtcp) |
1897 : BaseChannel(thread, | 2021 : BaseChannel(worker_thread, |
2022 network_thread, | |
1898 media_channel, | 2023 media_channel, |
1899 transport_controller, | 2024 transport_controller, |
1900 content_name, | 2025 content_name, |
1901 rtcp), | 2026 rtcp), |
1902 data_channel_type_(cricket::DCT_NONE), | 2027 data_channel_type_(cricket::DCT_NONE), |
1903 ready_to_send_data_(false) {} | 2028 ready_to_send_data_(false) {} |
1904 | 2029 |
1905 DataChannel::~DataChannel() { | 2030 DataChannel::~DataChannel() { |
1906 TRACE_EVENT0("webrtc", "DataChannel::~DataChannel"); | 2031 TRACE_EVENT0("webrtc", "DataChannel::~DataChannel"); |
1907 StopMediaMonitor(); | 2032 StopMediaMonitor(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1991 if (!data) { | 2116 if (!data) { |
1992 SafeSetError("Can't find data content in local description.", error_desc); | 2117 SafeSetError("Can't find data content in local description.", error_desc); |
1993 return false; | 2118 return false; |
1994 } | 2119 } |
1995 | 2120 |
1996 if (!SetDataChannelTypeFromContent(data, error_desc)) { | 2121 if (!SetDataChannelTypeFromContent(data, error_desc)) { |
1997 return false; | 2122 return false; |
1998 } | 2123 } |
1999 | 2124 |
2000 if (data_channel_type_ == DCT_RTP) { | 2125 if (data_channel_type_ == DCT_RTP) { |
2001 if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) { | 2126 if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) { |
2002 return false; | 2127 return false; |
2003 } | 2128 } |
2004 } | 2129 } |
2005 | 2130 |
2006 // FYI: We send the SCTP port number (not to be confused with the | 2131 // 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 | 2132 // underlying UDP port number) as a codec parameter. So even SCTP |
2008 // data channels need codecs. | 2133 // data channels need codecs. |
2009 DataRecvParameters recv_params = last_recv_params_; | 2134 DataRecvParameters recv_params = last_recv_params_; |
2010 RtpParametersFromMediaDescription(data, &recv_params); | 2135 RtpParametersFromMediaDescription(data, &recv_params); |
2011 if (!media_channel()->SetRecvParameters(recv_params)) { | 2136 if (!media_channel()->SetRecvParameters(recv_params)) { |
(...skipping 11 matching lines...) Expand all Loading... | |
2023 // TODO(pthatcher): Move local streams into DataSendParameters, and | 2148 // TODO(pthatcher): Move local streams into DataSendParameters, and |
2024 // only give it to the media channel once we have a remote | 2149 // only give it to the media channel once we have a remote |
2025 // description too (without a remote description, we won't be able | 2150 // description too (without a remote description, we won't be able |
2026 // to send them anyway). | 2151 // to send them anyway). |
2027 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { | 2152 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { |
2028 SafeSetError("Failed to set local data description streams.", error_desc); | 2153 SafeSetError("Failed to set local data description streams.", error_desc); |
2029 return false; | 2154 return false; |
2030 } | 2155 } |
2031 | 2156 |
2032 set_local_content_direction(content->direction()); | 2157 set_local_content_direction(content->direction()); |
2033 ChangeState(); | 2158 ChangeState_w(); |
2034 return true; | 2159 return true; |
2035 } | 2160 } |
2036 | 2161 |
2037 bool DataChannel::SetRemoteContent_w(const MediaContentDescription* content, | 2162 bool DataChannel::SetRemoteContent_w(const MediaContentDescription* content, |
2038 ContentAction action, | 2163 ContentAction action, |
2039 std::string* error_desc) { | 2164 std::string* error_desc) { |
2040 TRACE_EVENT0("webrtc", "DataChannel::SetRemoteContent_w"); | 2165 TRACE_EVENT0("webrtc", "DataChannel::SetRemoteContent_w"); |
2041 ASSERT(worker_thread() == rtc::Thread::Current()); | 2166 ASSERT(worker_thread() == rtc::Thread::Current()); |
2042 | 2167 |
2043 const DataContentDescription* data = | 2168 const DataContentDescription* data = |
2044 static_cast<const DataContentDescription*>(content); | 2169 static_cast<const DataContentDescription*>(content); |
2045 ASSERT(data != NULL); | 2170 ASSERT(data != NULL); |
2046 if (!data) { | 2171 if (!data) { |
2047 SafeSetError("Can't find data content in remote description.", error_desc); | 2172 SafeSetError("Can't find data content in remote description.", error_desc); |
2048 return false; | 2173 return false; |
2049 } | 2174 } |
2050 | 2175 |
2051 // If the remote data doesn't have codecs and isn't an update, it | 2176 // If the remote data doesn't have codecs and isn't an update, it |
2052 // must be empty, so ignore it. | 2177 // must be empty, so ignore it. |
2053 if (!data->has_codecs() && action != CA_UPDATE) { | 2178 if (!data->has_codecs() && action != CA_UPDATE) { |
2054 return true; | 2179 return true; |
2055 } | 2180 } |
2056 | 2181 |
2057 if (!SetDataChannelTypeFromContent(data, error_desc)) { | 2182 if (!SetDataChannelTypeFromContent(data, error_desc)) { |
2058 return false; | 2183 return false; |
2059 } | 2184 } |
2060 | 2185 |
2061 LOG(LS_INFO) << "Setting remote data description"; | 2186 LOG(LS_INFO) << "Setting remote data description"; |
2062 if (data_channel_type_ == DCT_RTP && | 2187 if (data_channel_type_ == DCT_RTP && |
2063 !SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) { | 2188 !SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) { |
2064 return false; | 2189 return false; |
2065 } | 2190 } |
2066 | 2191 |
2067 | 2192 |
2068 DataSendParameters send_params = last_send_params_; | 2193 DataSendParameters send_params = last_send_params_; |
2069 RtpSendParametersFromMediaDescription<DataCodec>(data, &send_params); | 2194 RtpSendParametersFromMediaDescription<DataCodec>(data, &send_params); |
2070 if (!media_channel()->SetSendParameters(send_params)) { | 2195 if (!media_channel()->SetSendParameters(send_params)) { |
2071 SafeSetError("Failed to set remote data description send parameters.", | 2196 SafeSetError("Failed to set remote data description send parameters.", |
2072 error_desc); | 2197 error_desc); |
2073 return false; | 2198 return false; |
2074 } | 2199 } |
2075 last_send_params_ = send_params; | 2200 last_send_params_ = send_params; |
2076 | 2201 |
2077 // TODO(pthatcher): Move remote streams into DataRecvParameters, | 2202 // TODO(pthatcher): Move remote streams into DataRecvParameters, |
2078 // and only give it to the media channel once we have a local | 2203 // 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 | 2204 // description too (without a local description, we won't be able to |
2080 // recv them anyway). | 2205 // recv them anyway). |
2081 if (!UpdateRemoteStreams_w(data->streams(), action, error_desc)) { | 2206 if (!UpdateRemoteStreams_w(data->streams(), action, error_desc)) { |
2082 SafeSetError("Failed to set remote data description streams.", | 2207 SafeSetError("Failed to set remote data description streams.", |
2083 error_desc); | 2208 error_desc); |
2084 return false; | 2209 return false; |
2085 } | 2210 } |
2086 | 2211 |
2087 set_remote_content_direction(content->direction()); | 2212 set_remote_content_direction(content->direction()); |
2088 ChangeState(); | 2213 ChangeState_w(); |
2089 return true; | 2214 return true; |
2090 } | 2215 } |
2091 | 2216 |
2092 void DataChannel::ChangeState() { | 2217 void DataChannel::ChangeState_w() { |
2093 // Render incoming data if we're the active call, and we have the local | 2218 // 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. | 2219 // content. We receive data on the default channel and multiplexed streams. |
2095 bool recv = IsReadyToReceive(); | 2220 bool recv = IsReadyToReceive(); |
2096 if (!media_channel()->SetReceive(recv)) { | 2221 if (!media_channel()->SetReceive(recv)) { |
2097 LOG(LS_ERROR) << "Failed to SetReceive on data channel"; | 2222 LOG(LS_ERROR) << "Failed to SetReceive on data channel"; |
2098 } | 2223 } |
2099 | 2224 |
2100 // Send outgoing data if we're the active call, we have the remote content, | 2225 // Send outgoing data if we're the active call, we have the remote content, |
2101 // and we have had some form of connectivity. | 2226 // and we have had some form of connectivity. |
2102 bool send = IsReadyToSend(); | 2227 bool send = IsReadyToSend(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2203 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); | 2328 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); |
2204 } | 2329 } |
2205 | 2330 |
2206 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2331 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
2207 rtc::TypedMessageData<uint32_t>* message = | 2332 rtc::TypedMessageData<uint32_t>* message = |
2208 new rtc::TypedMessageData<uint32_t>(sid); | 2333 new rtc::TypedMessageData<uint32_t>(sid); |
2209 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2334 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
2210 } | 2335 } |
2211 | 2336 |
2212 } // namespace cricket | 2337 } // namespace cricket |
OLD | NEW |