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

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

Powered by Google App Engine
This is Rietveld 408576698