Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1280)

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

Issue 1903393004: Added network thread to rtc::BaseChannel (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: feedback Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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...) Expand all
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
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] {
pthatcher1 2016/04/29 23:36:23 It seems risky to have the BaseChannel destructor
pthatcher1 2016/04/29 23:36:23 I don't think we're allowed to invoke lambdas beca
danilchap 2016/05/02 14:50:34 Wasn't sure if storing in sendlist queue was count
danilchap 2016/05/02 14:50:34 Worker can be blocked on network thread, but netwo
pthatcher1 2016/05/11 04:50:01 That's a good point. It's probably worth bringing
pthatcher1 2016/05/11 04:50:01 That's probably the only thing that makes sense.
danilchap 2016/05/11 12:19:16 Expanded comment above BaseChannel definition
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)) {
pthatcher1 2016/04/29 23:36:23 I think SetDtlsSrtpCryptoSuites, rtcp_transport_en
danilchap 2016/05/02 14:50:34 Old code access them on worker, not signaling thre
pthatcher1 2016/05/11 04:50:01 Ah, true. I was thrown off by Init(). It should
danilchap 2016/05/11 12:19:16 Init renamed to Init_w, few more function got thre
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
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
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()));
pthatcher1 2016/04/29 23:36:23 We should comment that this is because GetConnecti
danilchap 2016/05/02 14:50:34 Done.
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;
pthatcher1 2016/04/29 23:36:23 Only this last part should be on the network threa
danilchap 2016/05/02 14:50:34 transport_channels created/destroyed/set on networ
pthatcher1 2016/05/11 04:50:01 Ah, that's a good point. transport_channel_ and r
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
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 worker_thread_->Post(this, MSG_NETWORK_ROUTE_CHANGED, message);
pthatcher1 2016/04/29 23:36:23 Can't we do an AsyncInvoke on the worker_thread_ w
danilchap 2016/05/02 14:50:34 Didn't know there was AsyncInvoke. Done.
524 } 567 }
525 568
526 void BaseChannel::SetReadyToSend(bool rtcp, bool ready) { 569 void BaseChannel::SetReadyToSend(bool rtcp, bool ready) {
570 RTC_DCHECK(network_thread_->IsCurrent());
527 if (rtcp) { 571 if (rtcp) {
528 rtcp_ready_to_send_ = ready; 572 rtcp_ready_to_send_ = ready;
529 } else { 573 } else {
530 rtp_ready_to_send_ = ready; 574 rtp_ready_to_send_ = ready;
531 } 575 }
532 576
533 if (rtp_ready_to_send_ && 577 bool ready_to_send =
534 // In the case of rtcp mux |rtcp_transport_channel_| will be null. 578 (rtp_ready_to_send_ &&
535 (rtcp_ready_to_send_ || !rtcp_transport_channel_)) { 579 // In the case of rtcp mux |rtcp_transport_channel_| will be null.
536 // Notify the MediaChannel when both rtp and rtcp channel can send. 580 (rtcp_ready_to_send_ || !rtcp_transport_channel_));
537 media_channel_->OnReadyToSend(true); 581
538 } else { 582 worker_thread_->Post(
539 // Notify the MediaChannel when either rtp or rtcp channel can't send. 583 this, ready_to_send ? MSG_READY_TO_SEND : MSG_NOT_READY_TO_SEND);
pthatcher1 2016/04/29 23:36:23 Same here.
danilchap 2016/05/02 14:50:34 Done.
540 media_channel_->OnReadyToSend(false);
541 }
542 } 584 }
543 585
544 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, 586 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel,
545 const char* data, size_t len) { 587 const char* data, size_t len) {
546 return (channel == rtcp_transport_channel_ || 588 return (channel == rtcp_transport_channel_ ||
547 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); 589 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len)));
548 } 590 }
549 591
550 bool BaseChannel::SendPacket(bool rtcp, 592 bool BaseChannel::SendPacket(bool rtcp,
551 rtc::CopyOnWriteBuffer* packet, 593 rtc::CopyOnWriteBuffer* packet,
552 const rtc::PacketOptions& options) { 594 const rtc::PacketOptions& options) {
553 // SendPacket gets called from MediaEngine, typically on an encoder thread. 595 // 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 596 // 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 597 // 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 598 // synchronize access to all the pieces of the send path, including
557 // SRTP and the inner workings of the transport channels. 599 // SRTP and the inner workings of the transport channels.
558 // The only downside is that we can't return a proper failure code if 600 // 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. 601 // needed. Since UDP is unreliable anyway, this should be a non-issue.
560 if (rtc::Thread::Current() != worker_thread_) { 602 if (!network_thread_->IsCurrent()) {
561 // Avoid a copy by transferring the ownership of the packet data. 603 // Avoid a copy by transferring the ownership of the packet data.
562 int message_id = (!rtcp) ? MSG_RTPPACKET : MSG_RTCPPACKET; 604 int message_id = rtcp ? MSG_SENDING_RTCP_PACKET : MSG_SENDING_RTP_PACKET;
563 PacketMessageData* data = new PacketMessageData; 605 SendingPacketMessageData* data = new SendingPacketMessageData;
pthatcher1 2016/04/29 23:36:23 Why is this "Sending" instead of "Send".
danilchap 2016/05/02 14:50:34 For no good reason. Changed.
564 data->packet = std::move(*packet); 606 data->packet = std::move(*packet);
565 data->options = options; 607 data->options = options;
566 worker_thread_->Post(this, message_id, data); 608 network_thread_->Post(this, message_id, data);
567 return true; 609 return true;
568 } 610 }
611 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket");
569 612
570 // Now that we are on the correct thread, ensure we have a place to send this 613 // 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 614 // 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 615 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP
573 // transport. 616 // transport.
574 TransportChannel* channel = (!rtcp || rtcp_mux_filter_.IsActive()) ? 617 TransportChannel* channel = (!rtcp || rtcp_mux_filter_.IsActive()) ?
575 transport_channel_ : rtcp_transport_channel_; 618 transport_channel_ : rtcp_transport_channel_;
576 if (!channel || !channel->writable()) { 619 if (!channel || !channel->writable()) {
577 return false; 620 return false;
578 } 621 }
579 622
580 // Protect ourselves against crazy data. 623 // Protect ourselves against crazy data.
581 if (!ValidPacket(rtcp, packet)) { 624 if (!ValidPacket(rtcp, packet)) {
582 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " 625 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " "
583 << PacketType(rtcp) 626 << PacketType(rtcp)
584 << " packet: wrong size=" << packet->size(); 627 << " packet: wrong size=" << packet->size();
585 return false; 628 return false;
586 } 629 }
587 630
588 rtc::PacketOptions updated_options; 631 rtc::PacketOptions updated_options;
589 updated_options = options; 632 updated_options = options;
590 // Protect if needed. 633 // Protect if needed.
591 if (srtp_filter_.IsActive()) { 634 if (srtp_filter_.IsActive()) {
635 TRACE_EVENT0("webrtc", "SRTP Encode");
592 bool res; 636 bool res;
593 uint8_t* data = packet->data(); 637 uint8_t* data = packet->data();
594 int len = static_cast<int>(packet->size()); 638 int len = static_cast<int>(packet->size());
595 if (!rtcp) { 639 if (!rtcp) {
596 // If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done 640 // 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 641 // 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. 642 // a fake HMAC value. This is ONLY done for a RTP packet.
599 // Socket layer will update rtp sendtime extension header if present in 643 // Socket layer will update rtp sendtime extension header if present in
600 // packet with current time before updating the HMAC. 644 // packet with current time before updating the HMAC.
601 #if !defined(ENABLE_EXTERNAL_AUTH) 645 #if !defined(ENABLE_EXTERNAL_AUTH)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 } else if (secure_required_) { 693 } else if (secure_required_) {
650 // This is a double check for something that supposedly can't happen. 694 // This is a double check for something that supposedly can't happen.
651 LOG(LS_ERROR) << "Can't send outgoing " << PacketType(rtcp) 695 LOG(LS_ERROR) << "Can't send outgoing " << PacketType(rtcp)
652 << " packet when SRTP is inactive and crypto is required"; 696 << " packet when SRTP is inactive and crypto is required";
653 697
654 ASSERT(false); 698 ASSERT(false);
655 return false; 699 return false;
656 } 700 }
657 701
658 // Bon voyage. 702 // Bon voyage.
659 int ret = 703 int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL;
660 channel->SendPacket(packet->data<char>(), packet->size(), updated_options, 704 int ret = channel->SendPacket(packet->data<char>(), packet->size(),
661 (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0); 705 updated_options, flags);
662 if (ret != static_cast<int>(packet->size())) { 706 if (ret != static_cast<int>(packet->size())) {
663 if (channel->GetError() == EWOULDBLOCK) { 707 if (channel->GetError() == EWOULDBLOCK) {
664 LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; 708 LOG(LS_WARNING) << "Got EWOULDBLOCK from socket.";
665 SetReadyToSend(rtcp, false); 709 SetReadyToSend(rtcp, false);
666 } 710 }
667 return false; 711 return false;
668 } 712 }
669 return true; 713 return true;
670 } 714 }
671 715
672 bool BaseChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { 716 bool BaseChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) {
673 // Protect ourselves against crazy data. 717 // Protect ourselves against crazy data.
674 if (!ValidPacket(rtcp, packet)) { 718 if (!ValidPacket(rtcp, packet)) {
675 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " 719 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " "
676 << PacketType(rtcp) 720 << PacketType(rtcp)
677 << " packet: wrong size=" << packet->size(); 721 << " packet: wrong size=" << packet->size();
678 return false; 722 return false;
679 } 723 }
680 if (rtcp) { 724 if (rtcp) {
681 // Permit all (seemingly valid) RTCP packets. 725 // Permit all (seemingly valid) RTCP packets.
682 return true; 726 return true;
683 } 727 }
684 // Check whether we handle this payload. 728 // Check whether we handle this payload.
685 return bundle_filter_.DemuxPacket(packet->data(), packet->size()); 729 return bundle_filter_.DemuxPacket(packet->data(), packet->size());
686 } 730 }
687 731
688 void BaseChannel::HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet, 732 void BaseChannel::HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet,
689 const rtc::PacketTime& packet_time) { 733 const rtc::PacketTime& packet_time) {
734 RTC_DCHECK(network_thread_->IsCurrent());
690 if (!WantsPacket(rtcp, packet)) { 735 if (!WantsPacket(rtcp, packet)) {
691 return; 736 return;
692 } 737 }
693 738
694 // We are only interested in the first rtp packet because that 739 // We are only interested in the first rtp packet because that
695 // indicates the media has started flowing. 740 // indicates the media has started flowing.
696 if (!has_received_packet_ && !rtcp) { 741 if (!has_received_packet_ && !rtcp) {
697 has_received_packet_ = true; 742 has_received_packet_ = true;
698 signaling_thread()->Post(this, MSG_FIRSTPACKETRECEIVED); 743 signaling_thread()->Post(this, MSG_FIRSTPACKETRECEIVED);
699 } 744 }
700 745
701 // Unprotect the packet, if needed. 746 // Unprotect the packet, if needed.
702 if (srtp_filter_.IsActive()) { 747 if (srtp_filter_.IsActive()) {
748 TRACE_EVENT0("webrtc", "SRTP Decode");
703 char* data = packet->data<char>(); 749 char* data = packet->data<char>();
704 int len = static_cast<int>(packet->size()); 750 int len = static_cast<int>(packet->size());
705 bool res; 751 bool res;
706 if (!rtcp) { 752 if (!rtcp) {
707 res = srtp_filter_.UnprotectRtp(data, len, &len); 753 res = srtp_filter_.UnprotectRtp(data, len, &len);
708 if (!res) { 754 if (!res) {
709 int seq_num = -1; 755 int seq_num = -1;
710 uint32_t ssrc = 0; 756 uint32_t ssrc = 0;
711 GetRtpSeqNum(data, len, &seq_num); 757 GetRtpSeqNum(data, len, &seq_num);
712 GetRtpSsrc(data, len, &ssrc); 758 GetRtpSsrc(data, len, &ssrc);
(...skipping 23 matching lines...) Expand all
736 // channels, so we haven't yet extracted keys, even if DTLS did complete 782 // 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 783 // 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 784 // 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 785 // 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. 786 // packets here. This is all sidestepped if RTCP mux is used anyway.
741 LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp) 787 LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp)
742 << " packet when SRTP is inactive and crypto is required"; 788 << " packet when SRTP is inactive and crypto is required";
743 return; 789 return;
744 } 790 }
745 791
746 // Push it down to the media channel. 792 ReceivedPacketMessageData* message_data = new ReceivedPacketMessageData;
747 if (!rtcp) { 793 message_data->packet = std::move(*packet);
748 media_channel_->OnPacketReceived(packet, packet_time); 794 message_data->packet_time = packet_time;
749 } else { 795 int message_id = rtcp ? MSG_RECEIVED_RTCP_PACKET : MSG_RECEIVED_RTP_PACKET;
750 media_channel_->OnRtcpReceived(packet, packet_time); 796 worker_thread_->Post(this, message_id, message_data);
pthatcher1 2016/04/29 23:36:23 Same here with AsyncInvoke
danilchap 2016/05/02 14:50:34 Done.
751 }
752 } 797 }
753 798
754 bool BaseChannel::PushdownLocalDescription( 799 bool BaseChannel::PushdownLocalDescription(
755 const SessionDescription* local_desc, ContentAction action, 800 const SessionDescription* local_desc, ContentAction action,
756 std::string* error_desc) { 801 std::string* error_desc) {
757 const ContentInfo* content_info = GetFirstContent(local_desc); 802 const ContentInfo* content_info = GetFirstContent(local_desc);
758 const MediaContentDescription* content_desc = 803 const MediaContentDescription* content_desc =
759 GetContentDescription(content_info); 804 GetContentDescription(content_info);
760 if (content_desc && content_info && !content_info->rejected && 805 if (content_desc && content_info && !content_info->rejected &&
761 !SetLocalContent(content_desc, action, error_desc)) { 806 !SetLocalContent(content_desc, action, error_desc)) {
(...skipping 17 matching lines...) Expand all
779 return true; 824 return true;
780 } 825 }
781 826
782 void BaseChannel::EnableMedia_w() { 827 void BaseChannel::EnableMedia_w() {
783 ASSERT(worker_thread_ == rtc::Thread::Current()); 828 ASSERT(worker_thread_ == rtc::Thread::Current());
784 if (enabled_) 829 if (enabled_)
785 return; 830 return;
786 831
787 LOG(LS_INFO) << "Channel enabled"; 832 LOG(LS_INFO) << "Channel enabled";
788 enabled_ = true; 833 enabled_ = true;
789 ChangeState(); 834 ChangeState_w();
790 } 835 }
791 836
792 void BaseChannel::DisableMedia_w() { 837 void BaseChannel::DisableMedia_w() {
793 ASSERT(worker_thread_ == rtc::Thread::Current()); 838 ASSERT(worker_thread_ == rtc::Thread::Current());
794 if (!enabled_) 839 if (!enabled_)
795 return; 840 return;
796 841
797 LOG(LS_INFO) << "Channel disabled"; 842 LOG(LS_INFO) << "Channel disabled";
798 enabled_ = false; 843 enabled_ = false;
799 ChangeState(); 844 ChangeState_w();
800 } 845 }
801 846
802 void BaseChannel::UpdateWritableState_w() { 847 void BaseChannel::UpdateWritableState_n() {
803 if (transport_channel_ && transport_channel_->writable() && 848 if (transport_channel_ && transport_channel_->writable() &&
804 (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { 849 (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) {
805 ChannelWritable_w(); 850 ChannelWritable_n();
806 } else { 851 } else {
807 ChannelNotWritable_w(); 852 ChannelNotWritable_n();
808 } 853 }
809 } 854 }
810 855
811 void BaseChannel::ChannelWritable_w() { 856 void BaseChannel::ChannelWritable_n() {
812 ASSERT(worker_thread_ == rtc::Thread::Current()); 857 RTC_DCHECK(network_thread_->IsCurrent());
813 if (writable_) { 858 if (writable_) {
814 return; 859 return;
815 } 860 }
816 861
817 LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" 862 LOG(LS_INFO) << "Channel writable (" << content_name_ << ")"
818 << (was_ever_writable_ ? "" : " for the first time"); 863 << (was_ever_writable_ ? "" : " for the first time");
819 864
820 std::vector<ConnectionInfo> infos; 865 std::vector<ConnectionInfo> infos;
821 transport_channel_->GetStats(&infos); 866 transport_channel_->GetStats(&infos);
822 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); 867 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin();
823 it != infos.end(); ++it) { 868 it != infos.end(); ++it) {
824 if (it->best_connection) { 869 if (it->best_connection) {
825 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() 870 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString()
826 << "->" << it->remote_candidate.ToSensitiveString(); 871 << "->" << it->remote_candidate.ToSensitiveString();
827 break; 872 break;
828 } 873 }
829 } 874 }
830 875
831 was_ever_writable_ = true; 876 was_ever_writable_ = true;
832 MaybeSetupDtlsSrtp_w(); 877 MaybeSetupDtlsSrtp_n();
833 writable_ = true; 878 writable_ = true;
834 ChangeState(); 879 ChangeState();
835 } 880 }
836 881
837 void BaseChannel::SignalDtlsSetupFailure_w(bool rtcp) { 882 void BaseChannel::SignalDtlsSetupFailure_n(bool rtcp) {
838 ASSERT(worker_thread() == rtc::Thread::Current()); 883 RTC_DCHECK(network_thread_->IsCurrent());
884 RTC_NOTREACHED();
pthatcher1 2016/04/29 23:36:23 This isn't reached?
danilchap 2016/05/02 14:50:34 In practice it isn't reached. In theory it can be
885 // TODO(danilchap): Not allowed to invoke from network thread. Post instead.
839 signaling_thread()->Invoke<void>(Bind( 886 signaling_thread()->Invoke<void>(Bind(
840 &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); 887 &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp));
841 } 888 }
842 889
843 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { 890 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) {
844 ASSERT(signaling_thread() == rtc::Thread::Current()); 891 ASSERT(signaling_thread() == rtc::Thread::Current());
845 SignalDtlsSetupFailure(this, rtcp); 892 SignalDtlsSetupFailure(this, rtcp);
846 } 893 }
847 894
848 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { 895 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) {
849 std::vector<int> crypto_suites; 896 std::vector<int> crypto_suites;
850 // We always use the default SRTP crypto suites for RTCP, but we may use 897 // 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. 898 // different crypto suites for RTP depending on the media type.
852 if (!rtcp) { 899 if (!rtcp) {
853 GetSrtpCryptoSuites(&crypto_suites); 900 GetSrtpCryptoSuites(&crypto_suites);
854 } else { 901 } else {
855 GetDefaultSrtpCryptoSuites(&crypto_suites); 902 GetDefaultSrtpCryptoSuites(&crypto_suites);
856 } 903 }
857 return tc->SetSrtpCryptoSuites(crypto_suites); 904 return tc->SetSrtpCryptoSuites(crypto_suites);
858 } 905 }
859 906
860 bool BaseChannel::ShouldSetupDtlsSrtp() const { 907 bool BaseChannel::ShouldSetupDtlsSrtp() const {
861 // Since DTLS is applied to all channels, checking RTP should be enough. 908 // Since DTLS is applied to all channels, checking RTP should be enough.
862 return transport_channel_ && transport_channel_->IsDtlsActive(); 909 return transport_channel_ && transport_channel_->IsDtlsActive();
863 } 910 }
864 911
865 // This function returns true if either DTLS-SRTP is not in use 912 // This function returns true if either DTLS-SRTP is not in use
866 // *or* DTLS-SRTP is successfully set up. 913 // *or* DTLS-SRTP is successfully set up.
867 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { 914 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp_channel) {
915 RTC_DCHECK(network_thread_->IsCurrent());
868 bool ret = false; 916 bool ret = false;
869 917
870 TransportChannel* channel = 918 TransportChannel* channel =
871 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; 919 rtcp_channel ? rtcp_transport_channel_ : transport_channel_;
872 920
873 RTC_DCHECK(channel->IsDtlsActive()); 921 RTC_DCHECK(channel->IsDtlsActive());
874 922
875 int selected_crypto_suite; 923 int selected_crypto_suite;
876 924
877 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { 925 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 } 991 }
944 992
945 if (!ret) 993 if (!ret)
946 LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; 994 LOG(LS_WARNING) << "DTLS-SRTP key installation failed";
947 else 995 else
948 dtls_keyed_ = true; 996 dtls_keyed_ = true;
949 997
950 return ret; 998 return ret;
951 } 999 }
952 1000
953 void BaseChannel::MaybeSetupDtlsSrtp_w() { 1001 void BaseChannel::MaybeSetupDtlsSrtp_n() {
954 if (srtp_filter_.IsActive()) { 1002 if (srtp_filter_.IsActive()) {
955 return; 1003 return;
956 } 1004 }
957 1005
958 if (!ShouldSetupDtlsSrtp()) { 1006 if (!ShouldSetupDtlsSrtp()) {
pthatcher1 2016/04/29 23:36:23 This should be renamed to ShouldSetupDtlsSrtp_n.
danilchap 2016/05/02 14:50:34 Done.
959 return; 1007 return;
960 } 1008 }
961 1009
962 if (!SetupDtlsSrtp(false)) { 1010 if (!SetupDtlsSrtp_n(false)) {
963 SignalDtlsSetupFailure_w(false); 1011 SignalDtlsSetupFailure_n(false);
964 return; 1012 return;
965 } 1013 }
966 1014
967 if (rtcp_transport_channel_) { 1015 if (rtcp_transport_channel_) {
968 if (!SetupDtlsSrtp(true)) { 1016 if (!SetupDtlsSrtp_n(true)) {
969 SignalDtlsSetupFailure_w(true); 1017 SignalDtlsSetupFailure_n(true);
970 return; 1018 return;
971 } 1019 }
972 } 1020 }
973 } 1021 }
974 1022
975 void BaseChannel::ChannelNotWritable_w() { 1023 void BaseChannel::ChannelNotWritable_n() {
976 ASSERT(worker_thread_ == rtc::Thread::Current()); 1024 RTC_DCHECK(network_thread_->IsCurrent());
977 if (!writable_) 1025 if (!writable_)
978 return; 1026 return;
979 1027
980 LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; 1028 LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")";
981 writable_ = false; 1029 writable_ = false;
982 ChangeState(); 1030 ChangeState();
983 } 1031 }
984 1032
985 bool BaseChannel::SetRtpTransportParameters_w( 1033 bool BaseChannel::SetRtpTransportParameters(
986 const MediaContentDescription* content, 1034 const MediaContentDescription* content,
987 ContentAction action, 1035 ContentAction action,
988 ContentSource src, 1036 ContentSource src,
989 std::string* error_desc) { 1037 std::string* error_desc) {
990 if (action == CA_UPDATE) { 1038 if (action == CA_UPDATE) {
991 // These parameters never get changed by a CA_UDPATE. 1039 // These parameters never get changed by a CA_UDPATE.
992 return true; 1040 return true;
993 } 1041 }
994 1042
995 // Cache secure_required_ for belt and suspenders check on SendPacket 1043 // Cache secure_required_ for belt and suspenders check on SendPacket
996 if (src == CS_LOCAL) { 1044 return network_thread_->Invoke<bool>(
997 set_secure_required(content->crypto_required() != CT_NONE); 1045 [this, content, action, src, error_desc] {
998 } 1046 if (src == CS_LOCAL) {
1047 set_secure_required(content->crypto_required() != CT_NONE);
1048 }
pthatcher1 2016/04/29 23:36:23 I think set_secure_required needs to be on the sig
danilchap 2016/05/02 14:50:34 Why? secure_required accessor is used in tests onl
999 1049
1000 if (!SetSrtp_w(content->cryptos(), action, src, error_desc)) { 1050 if (!SetSrtp_n(content->cryptos(), action, src, error_desc)) {
1001 return false; 1051 return false;
1002 } 1052 }
1003 1053
1004 if (!SetRtcpMux_w(content->rtcp_mux(), action, src, error_desc)) { 1054 if (!SetRtcpMux_n(content->rtcp_mux(), action, src, error_desc)) {
1005 return false; 1055 return false;
1006 } 1056 }
1007 1057
1008 return true; 1058 return true;
1059 });
1009 } 1060 }
1010 1061
1011 // |dtls| will be set to true if DTLS is active for transport channel and 1062 // |dtls| will be set to true if DTLS is active for transport channel and
1012 // crypto is empty. 1063 // crypto is empty.
1013 bool BaseChannel::CheckSrtpConfig(const std::vector<CryptoParams>& cryptos, 1064 bool BaseChannel::CheckSrtpConfig(const std::vector<CryptoParams>& cryptos,
1014 bool* dtls, 1065 bool* dtls,
1015 std::string* error_desc) { 1066 std::string* error_desc) {
1016 *dtls = transport_channel_->IsDtlsActive(); 1067 *dtls = transport_channel_->IsDtlsActive();
1017 if (*dtls && !cryptos.empty()) { 1068 if (*dtls && !cryptos.empty()) {
1018 SafeSetError("Cryptos must be empty when DTLS is active.", 1069 SafeSetError("Cryptos must be empty when DTLS is active.",
1019 error_desc); 1070 error_desc);
1020 return false; 1071 return false;
1021 } 1072 }
1022 return true; 1073 return true;
1023 } 1074 }
1024 1075
1025 bool BaseChannel::SetSrtp_w(const std::vector<CryptoParams>& cryptos, 1076 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos,
1026 ContentAction action, 1077 ContentAction action,
1027 ContentSource src, 1078 ContentSource src,
1028 std::string* error_desc) { 1079 std::string* error_desc) {
1029 TRACE_EVENT0("webrtc", "BaseChannel::SetSrtp_w"); 1080 TRACE_EVENT0("webrtc", "BaseChannel::SetSrtp_w");
1030 if (action == CA_UPDATE) { 1081 if (action == CA_UPDATE) {
1031 // no crypto params. 1082 // no crypto params.
1032 return true; 1083 return true;
1033 } 1084 }
1034 bool ret = false; 1085 bool ret = false;
1035 bool dtls = false; 1086 bool dtls = false;
(...skipping 27 matching lines...) Expand all
1063 break; 1114 break;
1064 } 1115 }
1065 if (!ret) { 1116 if (!ret) {
1066 SafeSetError("Failed to setup SRTP filter.", error_desc); 1117 SafeSetError("Failed to setup SRTP filter.", error_desc);
1067 return false; 1118 return false;
1068 } 1119 }
1069 return true; 1120 return true;
1070 } 1121 }
1071 1122
1072 void BaseChannel::ActivateRtcpMux() { 1123 void BaseChannel::ActivateRtcpMux() {
1073 worker_thread_->Invoke<void>(Bind( 1124 network_thread_->Invoke<void>(Bind(&BaseChannel::ActivateRtcpMux_n, this));
1074 &BaseChannel::ActivateRtcpMux_w, this));
1075 } 1125 }
1076 1126
1077 void BaseChannel::ActivateRtcpMux_w() { 1127 void BaseChannel::ActivateRtcpMux_n() {
1078 if (!rtcp_mux_filter_.IsActive()) { 1128 if (!rtcp_mux_filter_.IsActive()) {
1079 rtcp_mux_filter_.SetActive(); 1129 rtcp_mux_filter_.SetActive();
1080 set_rtcp_transport_channel(nullptr, true); 1130 set_rtcp_transport_channel(nullptr, true);
1081 rtcp_transport_enabled_ = false; 1131 rtcp_transport_enabled_ = false;
1082 } 1132 }
1083 } 1133 }
1084 1134
1085 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action, 1135 bool BaseChannel::SetRtcpMux_n(bool enable,
1136 ContentAction action,
1086 ContentSource src, 1137 ContentSource src,
1087 std::string* error_desc) { 1138 std::string* error_desc) {
1088 bool ret = false; 1139 bool ret = false;
1089 switch (action) { 1140 switch (action) {
1090 case CA_OFFER: 1141 case CA_OFFER:
1091 ret = rtcp_mux_filter_.SetOffer(enable, src); 1142 ret = rtcp_mux_filter_.SetOffer(enable, src);
1092 break; 1143 break;
1093 case CA_PRANSWER: 1144 case CA_PRANSWER:
1094 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); 1145 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src);
1095 break; 1146 break;
(...skipping 18 matching lines...) Expand all
1114 if (!ret) { 1165 if (!ret) {
1115 SafeSetError("Failed to setup RTCP mux filter.", error_desc); 1166 SafeSetError("Failed to setup RTCP mux filter.", error_desc);
1116 return false; 1167 return false;
1117 } 1168 }
1118 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or 1169 // |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 1170 // CA_ANSWER, but we only want to tear down the RTCP transport channel if we
1120 // received a final answer. 1171 // received a final answer.
1121 if (rtcp_mux_filter_.IsActive()) { 1172 if (rtcp_mux_filter_.IsActive()) {
1122 // If the RTP transport is already writable, then so are we. 1173 // If the RTP transport is already writable, then so are we.
1123 if (transport_channel_->writable()) { 1174 if (transport_channel_->writable()) {
1124 ChannelWritable_w(); 1175 ChannelWritable_n();
1125 } 1176 }
1126 } 1177 }
1127 1178
1128 return true; 1179 return true;
1129 } 1180 }
1130 1181
1131 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { 1182 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) {
1132 ASSERT(worker_thread() == rtc::Thread::Current()); 1183 ASSERT(worker_thread() == rtc::Thread::Current());
1133 return media_channel()->AddRecvStream(sp); 1184 return media_channel()->AddRecvStream(sp);
1134 } 1185 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 const std::vector<RtpHeaderExtension>& extensions) { 1340 const std::vector<RtpHeaderExtension>& extensions) {
1290 const RtpHeaderExtension* send_time_extension = 1341 const RtpHeaderExtension* send_time_extension =
1291 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); 1342 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension);
1292 rtp_abs_sendtime_extn_id_ = 1343 rtp_abs_sendtime_extn_id_ =
1293 send_time_extension ? send_time_extension->id : -1; 1344 send_time_extension ? send_time_extension->id : -1;
1294 } 1345 }
1295 1346
1296 void BaseChannel::OnMessage(rtc::Message *pmsg) { 1347 void BaseChannel::OnMessage(rtc::Message *pmsg) {
1297 TRACE_EVENT0("webrtc", "BaseChannel::OnMessage"); 1348 TRACE_EVENT0("webrtc", "BaseChannel::OnMessage");
1298 switch (pmsg->message_id) { 1349 switch (pmsg->message_id) {
1299 case MSG_RTPPACKET: 1350 case MSG_SENDING_RTP_PACKET:
1300 case MSG_RTCPPACKET: { 1351 case MSG_SENDING_RTCP_PACKET: {
1301 PacketMessageData* data = static_cast<PacketMessageData*>(pmsg->pdata); 1352 RTC_DCHECK(network_thread_->IsCurrent());
1302 SendPacket(pmsg->message_id == MSG_RTCPPACKET, &data->packet, 1353 SendingPacketMessageData* data =
1303 data->options); 1354 static_cast<SendingPacketMessageData*>(pmsg->pdata);
1304 delete data; // because it is Posted 1355 bool rtcp = pmsg->message_id == MSG_SENDING_RTCP_PACKET;
1356 SendPacket(rtcp, &data->packet, data->options);
1357 delete data;
1305 break; 1358 break;
1306 } 1359 }
1307 case MSG_FIRSTPACKETRECEIVED: { 1360 case MSG_FIRSTPACKETRECEIVED: {
1308 SignalFirstPacketReceived(this); 1361 SignalFirstPacketReceived(this);
1309 break; 1362 break;
1310 } 1363 }
1364 case MSG_RECEIVED_RTP_PACKET: {
1365 RTC_DCHECK(worker_thread_->IsCurrent());
1366 ReceivedPacketMessageData* data =
1367 static_cast<ReceivedPacketMessageData*>(pmsg->pdata);
1368 media_channel_->OnPacketReceived(&data->packet, data->packet_time);
1369 delete data;
1370 break;
1371 }
1372 case MSG_RECEIVED_RTCP_PACKET: {
1373 RTC_DCHECK(worker_thread_->IsCurrent());
1374 ReceivedPacketMessageData* data =
1375 static_cast<ReceivedPacketMessageData*>(pmsg->pdata);
1376 media_channel_->OnRtcpReceived(&data->packet, data->packet_time);
1377 delete data;
1378 break;
1379 }
1380 case MSG_CHANGE_STATE: {
1381 RTC_DCHECK(worker_thread_->IsCurrent());
1382 ChangeState_w();
1383 break;
1384 }
1385 case MSG_READY_TO_SEND: {
1386 RTC_DCHECK(worker_thread_->IsCurrent());
1387 media_channel_->OnReadyToSend(true);
1388 break;
1389 }
1390 case MSG_NOT_READY_TO_SEND: {
1391 RTC_DCHECK(worker_thread_->IsCurrent());
1392 media_channel_->OnReadyToSend(false);
1393 break;
1394 }
1395 case MSG_NETWORK_ROUTE_CHANGED: {
1396 RTC_DCHECK(worker_thread_->IsCurrent());
1397 NetworkRouteChanged* data =
1398 static_cast<NetworkRouteChanged*>(pmsg->pdata);
1399 media_channel()->OnNetworkRouteChanged(data->transport_name,
1400 data->network_route);
1401 delete data;
1402 break;
1403 }
1311 } 1404 }
1312 } 1405 }
1313 1406
1314 void BaseChannel::FlushRtcpMessages() { 1407 void BaseChannel::FlushRtcpMessages() {
1315 // Flush all remaining RTCP messages. This should only be called in 1408 // Flush all remaining RTCP messages. This should only be called in
1316 // destructor. 1409 // destructor.
1317 ASSERT(rtc::Thread::Current() == worker_thread_); 1410 network_thread_->Invoke<void>([this] {
1318 rtc::MessageList rtcp_messages; 1411 rtc::MessageList rtcp_messages;
1319 worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages); 1412 network_thread_->Clear(this, MSG_SENDING_RTCP_PACKET, &rtcp_messages);
1320 for (rtc::MessageList::iterator it = rtcp_messages.begin(); 1413 for (const auto& message : rtcp_messages) {
1321 it != rtcp_messages.end(); ++it) { 1414 network_thread_->Send(this, MSG_SENDING_RTCP_PACKET, message.pdata);
1322 worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata); 1415 }
1323 } 1416 });
1324 } 1417 }
1325 1418
1326 VoiceChannel::VoiceChannel(rtc::Thread* thread, 1419 VoiceChannel::VoiceChannel(rtc::Thread* worker_thread,
1420 rtc::Thread* network_thread,
1327 MediaEngineInterface* media_engine, 1421 MediaEngineInterface* media_engine,
1328 VoiceMediaChannel* media_channel, 1422 VoiceMediaChannel* media_channel,
1329 TransportController* transport_controller, 1423 TransportController* transport_controller,
1330 const std::string& content_name, 1424 const std::string& content_name,
1331 bool rtcp) 1425 bool rtcp)
1332 : BaseChannel(thread, 1426 : BaseChannel(worker_thread,
1427 network_thread,
1333 media_channel, 1428 media_channel,
1334 transport_controller, 1429 transport_controller,
1335 content_name, 1430 content_name,
1336 rtcp), 1431 rtcp),
1337 media_engine_(media_engine), 1432 media_engine_(media_engine),
1338 received_media_(false) {} 1433 received_media_(false) {}
1339 1434
1340 VoiceChannel::~VoiceChannel() { 1435 VoiceChannel::~VoiceChannel() {
1341 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); 1436 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel");
1342 StopAudioMonitor(); 1437 StopAudioMonitor();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 int flags) { 1575 int flags) {
1481 BaseChannel::OnChannelRead(channel, data, len, packet_time, flags); 1576 BaseChannel::OnChannelRead(channel, data, len, packet_time, flags);
1482 1577
1483 // Set a flag when we've received an RTP packet. If we're waiting for early 1578 // Set a flag when we've received an RTP packet. If we're waiting for early
1484 // media, this will disable the timeout. 1579 // media, this will disable the timeout.
1485 if (!received_media_ && !PacketIsRtcp(channel, data, len)) { 1580 if (!received_media_ && !PacketIsRtcp(channel, data, len)) {
1486 received_media_ = true; 1581 received_media_ = true;
1487 } 1582 }
1488 } 1583 }
1489 1584
1490 void VoiceChannel::ChangeState() { 1585 void BaseChannel::ChangeState() {
1586 RTC_DCHECK(network_thread_->IsCurrent());
1587 worker_thread_->Post(this, MSG_CHANGE_STATE);
1588 }
1589
1590 void VoiceChannel::ChangeState_w() {
1491 // Render incoming data if we're the active call, and we have the local 1591 // 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. 1592 // content. We receive data on the default channel and multiplexed streams.
1493 bool recv = IsReadyToReceive(); 1593 bool recv = IsReadyToReceive();
1494 media_channel()->SetPlayout(recv); 1594 media_channel()->SetPlayout(recv);
1495 1595
1496 // Send outgoing data if we're the active call, we have the remote content, 1596 // Send outgoing data if we're the active call, we have the remote content,
1497 // and we have had some form of connectivity. 1597 // and we have had some form of connectivity.
1498 bool send = IsReadyToSend(); 1598 bool send = IsReadyToSend();
1499 media_channel()->SetSend(send); 1599 media_channel()->SetSend(send);
1500 1600
(...skipping 13 matching lines...) Expand all
1514 LOG(LS_INFO) << "Setting local voice description"; 1614 LOG(LS_INFO) << "Setting local voice description";
1515 1615
1516 const AudioContentDescription* audio = 1616 const AudioContentDescription* audio =
1517 static_cast<const AudioContentDescription*>(content); 1617 static_cast<const AudioContentDescription*>(content);
1518 ASSERT(audio != NULL); 1618 ASSERT(audio != NULL);
1519 if (!audio) { 1619 if (!audio) {
1520 SafeSetError("Can't find audio content in local description.", error_desc); 1620 SafeSetError("Can't find audio content in local description.", error_desc);
1521 return false; 1621 return false;
1522 } 1622 }
1523 1623
1524 if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) { 1624 if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) {
1525 return false; 1625 return false;
1526 } 1626 }
1527 1627
1528 AudioRecvParameters recv_params = last_recv_params_; 1628 AudioRecvParameters recv_params = last_recv_params_;
1529 RtpParametersFromMediaDescription(audio, &recv_params); 1629 RtpParametersFromMediaDescription(audio, &recv_params);
1530 if (!media_channel()->SetRecvParameters(recv_params)) { 1630 if (!media_channel()->SetRecvParameters(recv_params)) {
1531 SafeSetError("Failed to set local audio description recv parameters.", 1631 SafeSetError("Failed to set local audio description recv parameters.",
1532 error_desc); 1632 error_desc);
1533 return false; 1633 return false;
1534 } 1634 }
1535 for (const AudioCodec& codec : audio->codecs()) { 1635 for (const AudioCodec& codec : audio->codecs()) {
1536 bundle_filter()->AddPayloadType(codec.id); 1636 bundle_filter()->AddPayloadType(codec.id);
1537 } 1637 }
1538 last_recv_params_ = recv_params; 1638 last_recv_params_ = recv_params;
1539 1639
1540 // TODO(pthatcher): Move local streams into AudioSendParameters, and 1640 // TODO(pthatcher): Move local streams into AudioSendParameters, and
1541 // only give it to the media channel once we have a remote 1641 // only give it to the media channel once we have a remote
1542 // description too (without a remote description, we won't be able 1642 // description too (without a remote description, we won't be able
1543 // to send them anyway). 1643 // to send them anyway).
1544 if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) { 1644 if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) {
1545 SafeSetError("Failed to set local audio description streams.", error_desc); 1645 SafeSetError("Failed to set local audio description streams.", error_desc);
1546 return false; 1646 return false;
1547 } 1647 }
1548 1648
1549 set_local_content_direction(content->direction()); 1649 set_local_content_direction(content->direction());
1550 ChangeState(); 1650 ChangeState_w();
1551 return true; 1651 return true;
1552 } 1652 }
1553 1653
1554 bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content, 1654 bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content,
1555 ContentAction action, 1655 ContentAction action,
1556 std::string* error_desc) { 1656 std::string* error_desc) {
1557 TRACE_EVENT0("webrtc", "VoiceChannel::SetRemoteContent_w"); 1657 TRACE_EVENT0("webrtc", "VoiceChannel::SetRemoteContent_w");
1558 ASSERT(worker_thread() == rtc::Thread::Current()); 1658 ASSERT(worker_thread() == rtc::Thread::Current());
1559 LOG(LS_INFO) << "Setting remote voice description"; 1659 LOG(LS_INFO) << "Setting remote voice description";
1560 1660
1561 const AudioContentDescription* audio = 1661 const AudioContentDescription* audio =
1562 static_cast<const AudioContentDescription*>(content); 1662 static_cast<const AudioContentDescription*>(content);
1563 ASSERT(audio != NULL); 1663 ASSERT(audio != NULL);
1564 if (!audio) { 1664 if (!audio) {
1565 SafeSetError("Can't find audio content in remote description.", error_desc); 1665 SafeSetError("Can't find audio content in remote description.", error_desc);
1566 return false; 1666 return false;
1567 } 1667 }
1568 1668
1569 if (!SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) { 1669 if (!SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) {
1570 return false; 1670 return false;
1571 } 1671 }
1572 1672
1573 AudioSendParameters send_params = last_send_params_; 1673 AudioSendParameters send_params = last_send_params_;
1574 RtpSendParametersFromMediaDescription(audio, &send_params); 1674 RtpSendParametersFromMediaDescription(audio, &send_params);
1575 if (audio->agc_minus_10db()) { 1675 if (audio->agc_minus_10db()) {
1576 send_params.options.adjust_agc_delta = rtc::Optional<int>(kAgcMinus10db); 1676 send_params.options.adjust_agc_delta = rtc::Optional<int>(kAgcMinus10db);
1577 } 1677 }
1578 1678
1579 bool parameters_applied = media_channel()->SetSendParameters(send_params); 1679 bool parameters_applied = media_channel()->SetSendParameters(send_params);
(...skipping 11 matching lines...) Expand all
1591 if (!UpdateRemoteStreams_w(audio->streams(), action, error_desc)) { 1691 if (!UpdateRemoteStreams_w(audio->streams(), action, error_desc)) {
1592 SafeSetError("Failed to set remote audio description streams.", error_desc); 1692 SafeSetError("Failed to set remote audio description streams.", error_desc);
1593 return false; 1693 return false;
1594 } 1694 }
1595 1695
1596 if (audio->rtp_header_extensions_set()) { 1696 if (audio->rtp_header_extensions_set()) {
1597 MaybeCacheRtpAbsSendTimeHeaderExtension(audio->rtp_header_extensions()); 1697 MaybeCacheRtpAbsSendTimeHeaderExtension(audio->rtp_header_extensions());
1598 } 1698 }
1599 1699
1600 set_remote_content_direction(content->direction()); 1700 set_remote_content_direction(content->direction());
1601 ChangeState(); 1701 ChangeState_w();
1602 return true; 1702 return true;
1603 } 1703 }
1604 1704
1605 void VoiceChannel::HandleEarlyMediaTimeout() { 1705 void VoiceChannel::HandleEarlyMediaTimeout() {
1606 // This occurs on the main thread, not the worker thread. 1706 // This occurs on the main thread, not the worker thread.
1607 if (!received_media_) { 1707 if (!received_media_) {
1608 LOG(LS_INFO) << "No early media received before timeout"; 1708 LOG(LS_INFO) << "No early media received before timeout";
1609 SignalEarlyMediaTimeout(this); 1709 SignalEarlyMediaTimeout(this);
1610 } 1710 }
1611 } 1711 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 1749
1650 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, 1750 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor,
1651 const AudioInfo& info) { 1751 const AudioInfo& info) {
1652 SignalAudioMonitor(this, info); 1752 SignalAudioMonitor(this, info);
1653 } 1753 }
1654 1754
1655 void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { 1755 void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const {
1656 GetSupportedAudioCryptoSuites(crypto_suites); 1756 GetSupportedAudioCryptoSuites(crypto_suites);
1657 } 1757 }
1658 1758
1659 VideoChannel::VideoChannel(rtc::Thread* thread, 1759 VideoChannel::VideoChannel(rtc::Thread* worker_thread,
1760 rtc::Thread* network_thread,
1660 VideoMediaChannel* media_channel, 1761 VideoMediaChannel* media_channel,
1661 TransportController* transport_controller, 1762 TransportController* transport_controller,
1662 const std::string& content_name, 1763 const std::string& content_name,
1663 bool rtcp) 1764 bool rtcp)
1664 : BaseChannel(thread, 1765 : BaseChannel(worker_thread,
1766 network_thread,
1665 media_channel, 1767 media_channel,
1666 transport_controller, 1768 transport_controller,
1667 content_name, 1769 content_name,
1668 rtcp) {} 1770 rtcp) {}
1669 1771
1670 bool VideoChannel::Init() { 1772 bool VideoChannel::Init() {
1671 if (!BaseChannel::Init()) { 1773 if (!BaseChannel::Init()) {
1672 return false; 1774 return false;
1673 } 1775 }
1674 return true; 1776 return true;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 bool VideoChannel::SetRtpParameters(uint32_t ssrc, 1818 bool VideoChannel::SetRtpParameters(uint32_t ssrc,
1717 const webrtc::RtpParameters& parameters) { 1819 const webrtc::RtpParameters& parameters) {
1718 return InvokeOnWorker( 1820 return InvokeOnWorker(
1719 Bind(&VideoChannel::SetRtpParameters_w, this, ssrc, parameters)); 1821 Bind(&VideoChannel::SetRtpParameters_w, this, ssrc, parameters));
1720 } 1822 }
1721 1823
1722 bool VideoChannel::SetRtpParameters_w(uint32_t ssrc, 1824 bool VideoChannel::SetRtpParameters_w(uint32_t ssrc,
1723 webrtc::RtpParameters parameters) { 1825 webrtc::RtpParameters parameters) {
1724 return media_channel()->SetRtpParameters(ssrc, parameters); 1826 return media_channel()->SetRtpParameters(ssrc, parameters);
1725 } 1827 }
1726 void VideoChannel::ChangeState() { 1828
1829 void VideoChannel::ChangeState_w() {
1727 // Send outgoing data if we're the active call, we have the remote content, 1830 // Send outgoing data if we're the active call, we have the remote content,
1728 // and we have had some form of connectivity. 1831 // and we have had some form of connectivity.
1729 bool send = IsReadyToSend(); 1832 bool send = IsReadyToSend();
1730 if (!media_channel()->SetSend(send)) { 1833 if (!media_channel()->SetSend(send)) {
1731 LOG(LS_ERROR) << "Failed to SetSend on video channel"; 1834 LOG(LS_ERROR) << "Failed to SetSend on video channel";
1732 // TODO(gangji): Report error back to server. 1835 // TODO(gangji): Report error back to server.
1733 } 1836 }
1734 1837
1735 LOG(LS_INFO) << "Changing video state, send=" << send; 1838 LOG(LS_INFO) << "Changing video state, send=" << send;
1736 } 1839 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 LOG(LS_INFO) << "Setting local video description"; 1871 LOG(LS_INFO) << "Setting local video description";
1769 1872
1770 const VideoContentDescription* video = 1873 const VideoContentDescription* video =
1771 static_cast<const VideoContentDescription*>(content); 1874 static_cast<const VideoContentDescription*>(content);
1772 ASSERT(video != NULL); 1875 ASSERT(video != NULL);
1773 if (!video) { 1876 if (!video) {
1774 SafeSetError("Can't find video content in local description.", error_desc); 1877 SafeSetError("Can't find video content in local description.", error_desc);
1775 return false; 1878 return false;
1776 } 1879 }
1777 1880
1778 if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) { 1881 if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) {
1779 return false; 1882 return false;
1780 } 1883 }
1781 1884
1782 VideoRecvParameters recv_params = last_recv_params_; 1885 VideoRecvParameters recv_params = last_recv_params_;
1783 RtpParametersFromMediaDescription(video, &recv_params); 1886 RtpParametersFromMediaDescription(video, &recv_params);
1784 if (!media_channel()->SetRecvParameters(recv_params)) { 1887 if (!media_channel()->SetRecvParameters(recv_params)) {
1785 SafeSetError("Failed to set local video description recv parameters.", 1888 SafeSetError("Failed to set local video description recv parameters.",
1786 error_desc); 1889 error_desc);
1787 return false; 1890 return false;
1788 } 1891 }
1789 for (const VideoCodec& codec : video->codecs()) { 1892 for (const VideoCodec& codec : video->codecs()) {
1790 bundle_filter()->AddPayloadType(codec.id); 1893 bundle_filter()->AddPayloadType(codec.id);
1791 } 1894 }
1792 last_recv_params_ = recv_params; 1895 last_recv_params_ = recv_params;
1793 1896
1794 // TODO(pthatcher): Move local streams into VideoSendParameters, and 1897 // TODO(pthatcher): Move local streams into VideoSendParameters, and
1795 // only give it to the media channel once we have a remote 1898 // only give it to the media channel once we have a remote
1796 // description too (without a remote description, we won't be able 1899 // description too (without a remote description, we won't be able
1797 // to send them anyway). 1900 // to send them anyway).
1798 if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) { 1901 if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) {
1799 SafeSetError("Failed to set local video description streams.", error_desc); 1902 SafeSetError("Failed to set local video description streams.", error_desc);
1800 return false; 1903 return false;
1801 } 1904 }
1802 1905
1803 set_local_content_direction(content->direction()); 1906 set_local_content_direction(content->direction());
1804 ChangeState(); 1907 ChangeState_w();
1805 return true; 1908 return true;
1806 } 1909 }
1807 1910
1808 bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, 1911 bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content,
1809 ContentAction action, 1912 ContentAction action,
1810 std::string* error_desc) { 1913 std::string* error_desc) {
1811 TRACE_EVENT0("webrtc", "VideoChannel::SetRemoteContent_w"); 1914 TRACE_EVENT0("webrtc", "VideoChannel::SetRemoteContent_w");
1812 ASSERT(worker_thread() == rtc::Thread::Current()); 1915 ASSERT(worker_thread() == rtc::Thread::Current());
1813 LOG(LS_INFO) << "Setting remote video description"; 1916 LOG(LS_INFO) << "Setting remote video description";
1814 1917
1815 const VideoContentDescription* video = 1918 const VideoContentDescription* video =
1816 static_cast<const VideoContentDescription*>(content); 1919 static_cast<const VideoContentDescription*>(content);
1817 ASSERT(video != NULL); 1920 ASSERT(video != NULL);
1818 if (!video) { 1921 if (!video) {
1819 SafeSetError("Can't find video content in remote description.", error_desc); 1922 SafeSetError("Can't find video content in remote description.", error_desc);
1820 return false; 1923 return false;
1821 } 1924 }
1822 1925
1823 1926 if (!SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) {
1824 if (!SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) {
1825 return false; 1927 return false;
1826 } 1928 }
1827 1929
1828 VideoSendParameters send_params = last_send_params_; 1930 VideoSendParameters send_params = last_send_params_;
1829 RtpSendParametersFromMediaDescription(video, &send_params); 1931 RtpSendParametersFromMediaDescription(video, &send_params);
1830 if (video->conference_mode()) { 1932 if (video->conference_mode()) {
1831 send_params.conference_mode = true; 1933 send_params.conference_mode = true;
1832 } 1934 }
1833 1935
1834 bool parameters_applied = media_channel()->SetSendParameters(send_params); 1936 bool parameters_applied = media_channel()->SetSendParameters(send_params);
(...skipping 12 matching lines...) Expand all
1847 if (!UpdateRemoteStreams_w(video->streams(), action, error_desc)) { 1949 if (!UpdateRemoteStreams_w(video->streams(), action, error_desc)) {
1848 SafeSetError("Failed to set remote video description streams.", error_desc); 1950 SafeSetError("Failed to set remote video description streams.", error_desc);
1849 return false; 1951 return false;
1850 } 1952 }
1851 1953
1852 if (video->rtp_header_extensions_set()) { 1954 if (video->rtp_header_extensions_set()) {
1853 MaybeCacheRtpAbsSendTimeHeaderExtension(video->rtp_header_extensions()); 1955 MaybeCacheRtpAbsSendTimeHeaderExtension(video->rtp_header_extensions());
1854 } 1956 }
1855 1957
1856 set_remote_content_direction(content->direction()); 1958 set_remote_content_direction(content->direction());
1857 ChangeState(); 1959 ChangeState_w();
1858 return true; 1960 return true;
1859 } 1961 }
1860 1962
1861 void VideoChannel::OnMessage(rtc::Message *pmsg) { 1963 void VideoChannel::OnMessage(rtc::Message *pmsg) {
1862 switch (pmsg->message_id) { 1964 switch (pmsg->message_id) {
1863 case MSG_CHANNEL_ERROR: { 1965 case MSG_CHANNEL_ERROR: {
1864 const VideoChannelErrorMessageData* data = 1966 const VideoChannelErrorMessageData* data =
1865 static_cast<VideoChannelErrorMessageData*>(pmsg->pdata); 1967 static_cast<VideoChannelErrorMessageData*>(pmsg->pdata);
1866 delete data; 1968 delete data;
1867 break; 1969 break;
(...skipping 14 matching lines...) Expand all
1882 void VideoChannel::OnMediaMonitorUpdate( 1984 void VideoChannel::OnMediaMonitorUpdate(
1883 VideoMediaChannel* media_channel, const VideoMediaInfo &info) { 1985 VideoMediaChannel* media_channel, const VideoMediaInfo &info) {
1884 ASSERT(media_channel == this->media_channel()); 1986 ASSERT(media_channel == this->media_channel());
1885 SignalMediaMonitor(this, info); 1987 SignalMediaMonitor(this, info);
1886 } 1988 }
1887 1989
1888 void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { 1990 void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const {
1889 GetSupportedVideoCryptoSuites(crypto_suites); 1991 GetSupportedVideoCryptoSuites(crypto_suites);
1890 } 1992 }
1891 1993
1892 DataChannel::DataChannel(rtc::Thread* thread, 1994 DataChannel::DataChannel(rtc::Thread* worker_thread,
1995 rtc::Thread* network_thread,
1893 DataMediaChannel* media_channel, 1996 DataMediaChannel* media_channel,
1894 TransportController* transport_controller, 1997 TransportController* transport_controller,
1895 const std::string& content_name, 1998 const std::string& content_name,
1896 bool rtcp) 1999 bool rtcp)
1897 : BaseChannel(thread, 2000 : BaseChannel(worker_thread,
2001 network_thread,
1898 media_channel, 2002 media_channel,
1899 transport_controller, 2003 transport_controller,
1900 content_name, 2004 content_name,
1901 rtcp), 2005 rtcp),
1902 data_channel_type_(cricket::DCT_NONE), 2006 data_channel_type_(cricket::DCT_NONE),
1903 ready_to_send_data_(false) {} 2007 ready_to_send_data_(false) {}
1904 2008
1905 DataChannel::~DataChannel() { 2009 DataChannel::~DataChannel() {
1906 TRACE_EVENT0("webrtc", "DataChannel::~DataChannel"); 2010 TRACE_EVENT0("webrtc", "DataChannel::~DataChannel");
1907 StopMediaMonitor(); 2011 StopMediaMonitor();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1991 if (!data) { 2095 if (!data) {
1992 SafeSetError("Can't find data content in local description.", error_desc); 2096 SafeSetError("Can't find data content in local description.", error_desc);
1993 return false; 2097 return false;
1994 } 2098 }
1995 2099
1996 if (!SetDataChannelTypeFromContent(data, error_desc)) { 2100 if (!SetDataChannelTypeFromContent(data, error_desc)) {
1997 return false; 2101 return false;
1998 } 2102 }
1999 2103
2000 if (data_channel_type_ == DCT_RTP) { 2104 if (data_channel_type_ == DCT_RTP) {
2001 if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) { 2105 if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) {
2002 return false; 2106 return false;
2003 } 2107 }
2004 } 2108 }
2005 2109
2006 // FYI: We send the SCTP port number (not to be confused with the 2110 // 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 2111 // underlying UDP port number) as a codec parameter. So even SCTP
2008 // data channels need codecs. 2112 // data channels need codecs.
2009 DataRecvParameters recv_params = last_recv_params_; 2113 DataRecvParameters recv_params = last_recv_params_;
2010 RtpParametersFromMediaDescription(data, &recv_params); 2114 RtpParametersFromMediaDescription(data, &recv_params);
2011 if (!media_channel()->SetRecvParameters(recv_params)) { 2115 if (!media_channel()->SetRecvParameters(recv_params)) {
(...skipping 11 matching lines...) Expand all
2023 // TODO(pthatcher): Move local streams into DataSendParameters, and 2127 // TODO(pthatcher): Move local streams into DataSendParameters, and
2024 // only give it to the media channel once we have a remote 2128 // only give it to the media channel once we have a remote
2025 // description too (without a remote description, we won't be able 2129 // description too (without a remote description, we won't be able
2026 // to send them anyway). 2130 // to send them anyway).
2027 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { 2131 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) {
2028 SafeSetError("Failed to set local data description streams.", error_desc); 2132 SafeSetError("Failed to set local data description streams.", error_desc);
2029 return false; 2133 return false;
2030 } 2134 }
2031 2135
2032 set_local_content_direction(content->direction()); 2136 set_local_content_direction(content->direction());
2033 ChangeState(); 2137 ChangeState_w();
2034 return true; 2138 return true;
2035 } 2139 }
2036 2140
2037 bool DataChannel::SetRemoteContent_w(const MediaContentDescription* content, 2141 bool DataChannel::SetRemoteContent_w(const MediaContentDescription* content,
2038 ContentAction action, 2142 ContentAction action,
2039 std::string* error_desc) { 2143 std::string* error_desc) {
2040 TRACE_EVENT0("webrtc", "DataChannel::SetRemoteContent_w"); 2144 TRACE_EVENT0("webrtc", "DataChannel::SetRemoteContent_w");
2041 ASSERT(worker_thread() == rtc::Thread::Current()); 2145 ASSERT(worker_thread() == rtc::Thread::Current());
2042 2146
2043 const DataContentDescription* data = 2147 const DataContentDescription* data =
2044 static_cast<const DataContentDescription*>(content); 2148 static_cast<const DataContentDescription*>(content);
2045 ASSERT(data != NULL); 2149 ASSERT(data != NULL);
2046 if (!data) { 2150 if (!data) {
2047 SafeSetError("Can't find data content in remote description.", error_desc); 2151 SafeSetError("Can't find data content in remote description.", error_desc);
2048 return false; 2152 return false;
2049 } 2153 }
2050 2154
2051 // If the remote data doesn't have codecs and isn't an update, it 2155 // If the remote data doesn't have codecs and isn't an update, it
2052 // must be empty, so ignore it. 2156 // must be empty, so ignore it.
2053 if (!data->has_codecs() && action != CA_UPDATE) { 2157 if (!data->has_codecs() && action != CA_UPDATE) {
2054 return true; 2158 return true;
2055 } 2159 }
2056 2160
2057 if (!SetDataChannelTypeFromContent(data, error_desc)) { 2161 if (!SetDataChannelTypeFromContent(data, error_desc)) {
2058 return false; 2162 return false;
2059 } 2163 }
2060 2164
2061 LOG(LS_INFO) << "Setting remote data description"; 2165 LOG(LS_INFO) << "Setting remote data description";
2062 if (data_channel_type_ == DCT_RTP && 2166 if (data_channel_type_ == DCT_RTP &&
2063 !SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) { 2167 !SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) {
2064 return false; 2168 return false;
2065 } 2169 }
2066 2170
2067 2171
2068 DataSendParameters send_params = last_send_params_; 2172 DataSendParameters send_params = last_send_params_;
2069 RtpSendParametersFromMediaDescription<DataCodec>(data, &send_params); 2173 RtpSendParametersFromMediaDescription<DataCodec>(data, &send_params);
2070 if (!media_channel()->SetSendParameters(send_params)) { 2174 if (!media_channel()->SetSendParameters(send_params)) {
2071 SafeSetError("Failed to set remote data description send parameters.", 2175 SafeSetError("Failed to set remote data description send parameters.",
2072 error_desc); 2176 error_desc);
2073 return false; 2177 return false;
2074 } 2178 }
2075 last_send_params_ = send_params; 2179 last_send_params_ = send_params;
2076 2180
2077 // TODO(pthatcher): Move remote streams into DataRecvParameters, 2181 // TODO(pthatcher): Move remote streams into DataRecvParameters,
2078 // and only give it to the media channel once we have a local 2182 // 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 2183 // description too (without a local description, we won't be able to
2080 // recv them anyway). 2184 // recv them anyway).
2081 if (!UpdateRemoteStreams_w(data->streams(), action, error_desc)) { 2185 if (!UpdateRemoteStreams_w(data->streams(), action, error_desc)) {
2082 SafeSetError("Failed to set remote data description streams.", 2186 SafeSetError("Failed to set remote data description streams.",
2083 error_desc); 2187 error_desc);
2084 return false; 2188 return false;
2085 } 2189 }
2086 2190
2087 set_remote_content_direction(content->direction()); 2191 set_remote_content_direction(content->direction());
2088 ChangeState(); 2192 ChangeState_w();
2089 return true; 2193 return true;
2090 } 2194 }
2091 2195
2092 void DataChannel::ChangeState() { 2196 void DataChannel::ChangeState_w() {
2093 // Render incoming data if we're the active call, and we have the local 2197 // 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. 2198 // content. We receive data on the default channel and multiplexed streams.
2095 bool recv = IsReadyToReceive(); 2199 bool recv = IsReadyToReceive();
2096 if (!media_channel()->SetReceive(recv)) { 2200 if (!media_channel()->SetReceive(recv)) {
2097 LOG(LS_ERROR) << "Failed to SetReceive on data channel"; 2201 LOG(LS_ERROR) << "Failed to SetReceive on data channel";
2098 } 2202 }
2099 2203
2100 // Send outgoing data if we're the active call, we have the remote content, 2204 // Send outgoing data if we're the active call, we have the remote content,
2101 // and we have had some form of connectivity. 2205 // and we have had some form of connectivity.
2102 bool send = IsReadyToSend(); 2206 bool send = IsReadyToSend();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); 2307 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp();
2204 } 2308 }
2205 2309
2206 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { 2310 void DataChannel::OnStreamClosedRemotely(uint32_t sid) {
2207 rtc::TypedMessageData<uint32_t>* message = 2311 rtc::TypedMessageData<uint32_t>* message =
2208 new rtc::TypedMessageData<uint32_t>(sid); 2312 new rtc::TypedMessageData<uint32_t>(sid);
2209 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); 2313 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message);
2210 } 2314 }
2211 2315
2212 } // namespace cricket 2316 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/pc/channel.h ('k') | webrtc/pc/channel_unittest.cc » ('j') | webrtc/pc/channelmanager.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698