Chromium Code Reviews

Side by Side Diff: webrtc/pc/channel.cc

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

Powered by Google App Engine