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

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

Issue 2614263002: Remove BaseChannel's dependency on TransportController. (Closed)
Patch Set: Fix the tests Created 3 years, 11 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 template <class Codec> 153 template <class Codec>
154 void RtpSendParametersFromMediaDescription( 154 void RtpSendParametersFromMediaDescription(
155 const MediaContentDescriptionImpl<Codec>* desc, 155 const MediaContentDescriptionImpl<Codec>* desc,
156 RtpSendParameters<Codec>* send_params) { 156 RtpSendParameters<Codec>* send_params) {
157 RtpParametersFromMediaDescription(desc, send_params); 157 RtpParametersFromMediaDescription(desc, send_params);
158 send_params->max_bandwidth_bps = desc->bandwidth(); 158 send_params->max_bandwidth_bps = desc->bandwidth();
159 } 159 }
160 160
161 BaseChannel::BaseChannel(rtc::Thread* worker_thread, 161 BaseChannel::BaseChannel(rtc::Thread* worker_thread,
162 rtc::Thread* network_thread, 162 rtc::Thread* network_thread,
163 rtc::Thread* signaling_thread,
163 MediaChannel* media_channel, 164 MediaChannel* media_channel,
164 TransportController* transport_controller,
165 const std::string& content_name, 165 const std::string& content_name,
166 bool rtcp, 166 bool rtcp,
167 bool srtp_required) 167 bool srtp_required)
168 : worker_thread_(worker_thread), 168 : worker_thread_(worker_thread),
169 network_thread_(network_thread), 169 network_thread_(network_thread),
170 170 signaling_thread_(signaling_thread),
Taylor Brandstetter 2017/01/12 22:39:02 It doesn't look like this is used anywhere
Zhi Huang 2017/01/13 00:12:47 "signaling_thread()" used to return "transport_c
Taylor Brandstetter 2017/01/13 01:39:49 Oh, I didn't realize it was used in the header. My
171 content_name_(content_name), 171 content_name_(content_name),
172
173 transport_controller_(transport_controller),
174 rtcp_enabled_(rtcp), 172 rtcp_enabled_(rtcp),
175 srtp_required_(srtp_required), 173 srtp_required_(srtp_required),
176 media_channel_(media_channel), 174 media_channel_(media_channel),
177 selected_candidate_pair_(nullptr) { 175 selected_candidate_pair_(nullptr) {
178 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); 176 RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
179 if (transport_controller) {
180 RTC_DCHECK_EQ(network_thread, transport_controller->network_thread());
181 }
182 LOG(LS_INFO) << "Created channel for " << content_name; 177 LOG(LS_INFO) << "Created channel for " << content_name;
183 } 178 }
184 179
185 BaseChannel::~BaseChannel() { 180 BaseChannel::~BaseChannel() {
186 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); 181 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel");
187 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); 182 RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
188 Deinit(); 183 Deinit();
189 StopConnectionMonitor(); 184 StopConnectionMonitor();
190 // Eats any outstanding messages or packets. 185 // Eats any outstanding messages or packets.
191 worker_thread_->Clear(&invoker_); 186 worker_thread_->Clear(&invoker_);
192 worker_thread_->Clear(this); 187 worker_thread_->Clear(this);
193 // We must destroy the media channel before the transport channel, otherwise 188 // We must destroy the media channel before the transport channel, otherwise
194 // 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
195 // 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.
196 delete media_channel_; 191 delete media_channel_;
197 // Note that we don't just call SetTransportChannel_n(nullptr) because that 192 // Note that we don't just call SetTransportChannel_n(nullptr) because that
198 // 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.
199 network_thread_->Invoke<void>( 194 network_thread_->Invoke<void>(
200 RTC_FROM_HERE, Bind(&BaseChannel::DestroyTransportChannels_n, this)); 195 RTC_FROM_HERE, Bind(&BaseChannel::DestroyTransportChannels_n, this));
201 LOG(LS_INFO) << "Destroyed channel"; 196 LOG(LS_INFO) << "Destroyed channel:" << content_name_;
Taylor Brandstetter 2017/01/12 22:39:02 nit: space after colon
Zhi Huang 2017/01/13 00:12:47 Done.
202 } 197 }
203 198
204 void BaseChannel::DisconnectTransportChannels_n() { 199 void BaseChannel::DisconnectTransportChannels_n() {
205 // Send any outstanding RTCP packets. 200 // Send any outstanding RTCP packets.
206 FlushRtcpMessages_n(); 201 FlushRtcpMessages_n();
207 202
208 // Stop signals from transport channels, but keep them alive because 203 // Stop signals from transport channels, but keep them alive because
209 // media_channel may use them from a different thread. 204 // media_channel may use them from a different thread.
210 if (transport_channel_) { 205 if (rtp_transport_) {
211 DisconnectFromTransportChannel(transport_channel_); 206 DisconnectFromTransportChannel(rtp_transport_);
212 } 207 }
213 if (rtcp_transport_channel_) { 208 if (rtcp_transport_) {
214 DisconnectFromTransportChannel(rtcp_transport_channel_); 209 DisconnectFromTransportChannel(rtcp_transport_);
215 } 210 }
216 211
217 // Clear pending read packets/messages. 212 // Clear pending read packets/messages.
218 network_thread_->Clear(&invoker_); 213 network_thread_->Clear(&invoker_);
219 network_thread_->Clear(this); 214 network_thread_->Clear(this);
220 } 215 }
221 216
222 void BaseChannel::DestroyTransportChannels_n() { 217 void BaseChannel::DestroyTransportChannels_n() {
Taylor Brandstetter 2017/01/12 22:39:02 This can be removed now. Deinit already calls Disc
Zhi Huang 2017/01/13 00:12:47 You are right.
223 if (transport_channel_) {
224 transport_controller_->DestroyTransportChannel_n(
225 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP);
226 }
227 if (rtcp_transport_channel_) {
228 transport_controller_->DestroyTransportChannel_n(
229 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
230 }
231 // Clear pending send packets/messages. 218 // Clear pending send packets/messages.
232 network_thread_->Clear(&invoker_); 219 network_thread_->Clear(&invoker_);
233 network_thread_->Clear(this); 220 network_thread_->Clear(this);
234 } 221 }
235 222
236 bool BaseChannel::Init_w(const std::string* bundle_transport_name) { 223 bool BaseChannel::Init_w(TransportChannel* rtp_transport,
224 TransportChannel* rtcp_transport) {
237 if (!network_thread_->Invoke<bool>( 225 if (!network_thread_->Invoke<bool>(
238 RTC_FROM_HERE, 226 RTC_FROM_HERE, Bind(&BaseChannel::InitNetwork_n, this, rtp_transport,
239 Bind(&BaseChannel::InitNetwork_n, this, bundle_transport_name))) { 227 rtcp_transport))) {
240 return false; 228 return false;
241 } 229 }
242 230
243 // Both RTP and RTCP channels are set, we can call SetInterface on 231 // Both RTP and RTCP channels are set, we can call SetInterface on
244 // media channel and it can set network options. 232 // media channel and it can set network options.
245 RTC_DCHECK(worker_thread_->IsCurrent()); 233 RTC_DCHECK(worker_thread_->IsCurrent());
246 media_channel_->SetInterface(this); 234 media_channel_->SetInterface(this);
247 return true; 235 return true;
248 } 236 }
249 237
250 bool BaseChannel::InitNetwork_n(const std::string* bundle_transport_name) { 238 bool BaseChannel::InitNetwork_n(TransportChannel* rtp_transport,
239 TransportChannel* rtcp_transport) {
251 RTC_DCHECK(network_thread_->IsCurrent()); 240 RTC_DCHECK(network_thread_->IsCurrent());
252 const std::string& transport_name = 241 // const std::string& transport_name =
253 (bundle_transport_name ? *bundle_transport_name : content_name()); 242 // (bundle_transport_name ? *bundle_transport_name : content_name());
254 if (!SetTransport_n(transport_name)) { 243 if (!SetTransport_n(rtp_transport, rtcp_transport)) {
255 return false; 244 return false;
256 } 245 }
257 246
258 if (!SetDtlsSrtpCryptoSuites_n(transport_channel_, false)) { 247 if (!SetDtlsSrtpCryptoSuites_n(rtp_transport_, false)) {
259 return false; 248 return false;
260 } 249 }
261 if (rtcp_transport_channel_ && 250 if (rtcp_transport_ && !SetDtlsSrtpCryptoSuites_n(rtcp_transport_, true)) {
262 !SetDtlsSrtpCryptoSuites_n(rtcp_transport_channel_, true)) {
263 return false; 251 return false;
264 } 252 }
265 return true; 253 return true;
266 } 254 }
267 255
268 void BaseChannel::Deinit() { 256 void BaseChannel::Deinit() {
269 RTC_DCHECK(worker_thread_->IsCurrent()); 257 RTC_DCHECK(worker_thread_->IsCurrent());
270 media_channel_->SetInterface(NULL); 258 media_channel_->SetInterface(NULL);
271 // Packets arrive on the network thread, processing packets calls virtual 259 // Packets arrive on the network thread, processing packets calls virtual
272 // functions, so need to stop this process in Deinit that is called in 260 // functions, so need to stop this process in Deinit that is called in
273 // derived classes destructor. 261 // derived classes destructor.
274 network_thread_->Invoke<void>( 262 network_thread_->Invoke<void>(
275 RTC_FROM_HERE, Bind(&BaseChannel::DisconnectTransportChannels_n, this)); 263 RTC_FROM_HERE, Bind(&BaseChannel::DisconnectTransportChannels_n, this));
276 } 264 }
277 265
278 bool BaseChannel::SetTransport(const std::string& transport_name) { 266 bool BaseChannel::SetTransport(TransportChannel* rtp_transport,
267 TransportChannel* rtcp_transport) {
279 return network_thread_->Invoke<bool>( 268 return network_thread_->Invoke<bool>(
280 RTC_FROM_HERE, Bind(&BaseChannel::SetTransport_n, this, transport_name)); 269 RTC_FROM_HERE,
270 Bind(&BaseChannel::SetTransport_n, this, rtp_transport, rtcp_transport));
281 } 271 }
282 272
283 bool BaseChannel::SetTransport_n(const std::string& transport_name) { 273 bool BaseChannel::SetTransport_n(TransportChannel* rtp_transport,
274 TransportChannel* rtcp_transport) {
284 RTC_DCHECK(network_thread_->IsCurrent()); 275 RTC_DCHECK(network_thread_->IsCurrent());
276 if (!rtp_transport && !rtcp_transport) {
277 LOG(LS_ERROR) << "Setting nullptr to RTP Transport and RTCP Transport.";
278 return false;
279 }
285 280
286 if (transport_name == transport_name_) { 281 if (rtcp_transport) {
282 RTC_DCHECK(rtp_transport->transport_name() ==
283 rtcp_transport->transport_name());
284 RTC_DCHECK(NeedsRtcpTransport());
285 }
286
287 if (rtp_transport->transport_name() == transport_name_) {
287 // Nothing to do if transport name isn't changing. 288 // Nothing to do if transport name isn't changing.
288 return true; 289 return true;
289 } 290 }
290 291
292 transport_name_ = rtp_transport->transport_name();
293
291 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport 294 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport
292 // changes and wait until the DTLS handshake is complete to set the newly 295 // changes and wait until the DTLS handshake is complete to set the newly
293 // negotiated parameters. 296 // negotiated parameters.
294 if (ShouldSetupDtlsSrtp_n()) { 297 if (ShouldSetupDtlsSrtp_n()) {
295 // Set |writable_| to false such that UpdateWritableState_w can set up 298 // Set |writable_| to false such that UpdateWritableState_w can set up
296 // DTLS-SRTP when |writable_| becomes true again. 299 // DTLS-SRTP when |writable_| becomes true again.
297 writable_ = false; 300 writable_ = false;
298 srtp_filter_.ResetParams(); 301 srtp_filter_.ResetParams();
299 } 302 }
300 303
301 // If this BaseChannel uses RTCP and we haven't fully negotiated RTCP mux, 304 // If this BaseChannel uses RTCP and we haven't fully negotiated RTCP mux,
302 // we need an RTCP channel. 305 // we need an RTCP channel.
303 if (rtcp_enabled_ && !rtcp_mux_filter_.IsFullyActive()) { 306 if (NeedsRtcpTransport()) {
304 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() 307 LOG(LS_INFO) << "Setting RTCP Transport for " << content_name() << " on "
305 << " on " << transport_name << " transport "; 308 << transport_name() << " transport " << rtcp_transport;
306 SetTransportChannel_n( 309 SetTransportChannel_n(true, rtcp_transport);
307 true, transport_controller_->CreateTransportChannel_n( 310 if (!rtcp_transport_) {
308 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP));
309 if (!rtcp_transport_channel_) {
310 return false; 311 return false;
311 } 312 }
312 } 313 }
313 314
314 LOG(LS_INFO) << "Create non-RTCP TransportChannel for " << content_name() 315 LOG(LS_INFO) << "Setting non-RTCP Transport for " << content_name() << " on "
315 << " on " << transport_name << " transport "; 316 << transport_name() << " transport " << rtp_transport;
316 SetTransportChannel_n( 317 SetTransportChannel_n(false, rtp_transport);
317 false, transport_controller_->CreateTransportChannel_n( 318 if (!rtp_transport_) {
318 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP));
319 if (!transport_channel_) {
320 return false; 319 return false;
321 } 320 }
322 321
323 transport_name_ = transport_name;
324
325 // Update aggregate writable/ready-to-send state between RTP and RTCP upon 322 // Update aggregate writable/ready-to-send state between RTP and RTCP upon
326 // setting new transport channels. 323 // setting new transport channels.
327 UpdateWritableState_n(); 324 UpdateWritableState_n();
328 // We can only update ready-to-send after updating writability. 325 // We can only update ready-to-send after updating writability.
329 // 326 //
330 // On setting a new channel, assume it's ready to send if it's writable, 327 // On setting a new channel, assume it's ready to send if it's writable,
331 // because we have no way of knowing otherwise (the channel doesn't give us 328 // because we have no way of knowing otherwise (the channel doesn't give us
332 // "was last send successful?"). 329 // "was last send successful?").
333 // 330 //
334 // This won't always be accurate (the last SendPacket call from another 331 // This won't always be accurate (the last SendPacket call from another
335 // BaseChannel could have resulted in an error), but even so, we'll just 332 // BaseChannel could have resulted in an error), but even so, we'll just
336 // encounter the error again and update "ready to send" accordingly. 333 // encounter the error again and update "ready to send" accordingly.
334 SetTransportChannelReadyToSend(false,
335 rtp_transport_ && rtp_transport_->writable());
337 SetTransportChannelReadyToSend( 336 SetTransportChannelReadyToSend(
338 false, transport_channel_ && transport_channel_->writable()); 337 true, rtcp_transport_ && rtcp_transport_->writable());
339 SetTransportChannelReadyToSend(
340 true, rtcp_transport_channel_ && rtcp_transport_channel_->writable());
341 return true; 338 return true;
342 } 339 }
343 340
344 void BaseChannel::SetTransportChannel_n(bool rtcp, 341 void BaseChannel::SetTransportChannel_n(bool rtcp,
345 TransportChannel* new_channel) { 342 TransportChannel* new_transport) {
346 RTC_DCHECK(network_thread_->IsCurrent()); 343 RTC_DCHECK(network_thread_->IsCurrent());
347 TransportChannel*& old_channel = 344 TransportChannel*& old_transport = rtcp ? rtcp_transport_ : rtp_transport_;
348 rtcp ? rtcp_transport_channel_ : transport_channel_; 345 if (!old_transport && !new_transport) {
349
350 if (!old_channel && !new_channel) {
351 // Nothing to do. 346 // Nothing to do.
352 return; 347 return;
353 } 348 }
354 RTC_DCHECK(old_channel != new_channel); 349 RTC_DCHECK(old_transport != new_transport);
355 350 if (old_transport) {
356 if (old_channel) { 351 DisconnectFromTransportChannel(old_transport);
357 DisconnectFromTransportChannel(old_channel);
358 transport_controller_->DestroyTransportChannel_n(
359 transport_name_, rtcp ? cricket::ICE_CANDIDATE_COMPONENT_RTCP
360 : cricket::ICE_CANDIDATE_COMPONENT_RTP);
361 } 352 }
362 353
363 old_channel = new_channel; 354 old_transport = new_transport;
364 355
365 if (new_channel) { 356 if (new_transport) {
366 if (rtcp) { 357 if (rtcp) {
367 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) 358 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive()))
368 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " 359 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active "
369 << "should never happen."; 360 << "should never happen.";
370 } 361 }
371 ConnectToTransportChannel(new_channel); 362 ConnectToTransportChannel(new_transport);
372 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_; 363 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_;
373 for (const auto& pair : socket_options) { 364 for (const auto& pair : socket_options) {
374 new_channel->SetOption(pair.first, pair.second); 365 new_transport->SetOption(pair.first, pair.second);
375 } 366 }
376 } 367 }
377 } 368 }
378 369
379 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { 370 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) {
380 RTC_DCHECK(network_thread_->IsCurrent()); 371 RTC_DCHECK(network_thread_->IsCurrent());
381 372
382 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); 373 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState);
383 tc->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); 374 tc->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead);
384 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); 375 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 429
439 bool BaseChannel::SetRemoteContent(const MediaContentDescription* content, 430 bool BaseChannel::SetRemoteContent(const MediaContentDescription* content,
440 ContentAction action, 431 ContentAction action,
441 std::string* error_desc) { 432 std::string* error_desc) {
442 TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent"); 433 TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent");
443 return InvokeOnWorker(RTC_FROM_HERE, Bind(&BaseChannel::SetRemoteContent_w, 434 return InvokeOnWorker(RTC_FROM_HERE, Bind(&BaseChannel::SetRemoteContent_w,
444 this, content, action, error_desc)); 435 this, content, action, error_desc));
445 } 436 }
446 437
447 void BaseChannel::StartConnectionMonitor(int cms) { 438 void BaseChannel::StartConnectionMonitor(int cms) {
448 // We pass in the BaseChannel instead of the transport_channel_ 439 // We pass in the BaseChannel instead of the rtp_transport_
449 // because if the transport_channel_ changes, the ConnectionMonitor 440 // because if the rtp_transport_ changes, the ConnectionMonitor
450 // would be pointing to the wrong TransportChannel. 441 // would be pointing to the wrong TransportChannel.
451 // We pass in the network thread because on that thread connection monitor 442 // We pass in the network thread because on that thread connection monitor
452 // will call BaseChannel::GetConnectionStats which must be called on the 443 // will call BaseChannel::GetConnectionStats which must be called on the
453 // network thread. 444 // network thread.
454 connection_monitor_.reset( 445 connection_monitor_.reset(
455 new ConnectionMonitor(this, network_thread(), rtc::Thread::Current())); 446 new ConnectionMonitor(this, network_thread(), rtc::Thread::Current()));
456 connection_monitor_->SignalUpdate.connect( 447 connection_monitor_->SignalUpdate.connect(
457 this, &BaseChannel::OnConnectionMonitorUpdate); 448 this, &BaseChannel::OnConnectionMonitorUpdate);
458 connection_monitor_->Start(cms); 449 connection_monitor_->Start(cms);
459 } 450 }
460 451
461 void BaseChannel::StopConnectionMonitor() { 452 void BaseChannel::StopConnectionMonitor() {
462 if (connection_monitor_) { 453 if (connection_monitor_) {
463 connection_monitor_->Stop(); 454 connection_monitor_->Stop();
464 connection_monitor_.reset(); 455 connection_monitor_.reset();
465 } 456 }
466 } 457 }
467 458
468 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { 459 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) {
469 RTC_DCHECK(network_thread_->IsCurrent()); 460 RTC_DCHECK(network_thread_->IsCurrent());
470 return transport_channel_->GetStats(infos); 461 return rtp_transport_->GetStats(infos);
462 }
463
464 bool BaseChannel::NeedsRtcpTransport() {
465 return rtcp_enabled_ && !rtcp_mux_filter_.IsFullyActive();
471 } 466 }
472 467
473 bool BaseChannel::IsReadyToReceiveMedia_w() const { 468 bool BaseChannel::IsReadyToReceiveMedia_w() const {
474 // Receive data if we are enabled and have local content, 469 // Receive data if we are enabled and have local content,
475 return enabled() && IsReceiveContentDirection(local_content_direction_); 470 return enabled() && IsReceiveContentDirection(local_content_direction_);
476 } 471 }
477 472
478 bool BaseChannel::IsReadyToSendMedia_w() const { 473 bool BaseChannel::IsReadyToSendMedia_w() const {
479 // Need to access some state updated on the network thread. 474 // Need to access some state updated on the network thread.
480 return network_thread_->Invoke<bool>( 475 return network_thread_->Invoke<bool>(
(...skipping 25 matching lines...) Expand all
506 RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value)); 501 RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value));
507 } 502 }
508 503
509 int BaseChannel::SetOption_n(SocketType type, 504 int BaseChannel::SetOption_n(SocketType type,
510 rtc::Socket::Option opt, 505 rtc::Socket::Option opt,
511 int value) { 506 int value) {
512 RTC_DCHECK(network_thread_->IsCurrent()); 507 RTC_DCHECK(network_thread_->IsCurrent());
513 TransportChannel* channel = nullptr; 508 TransportChannel* channel = nullptr;
514 switch (type) { 509 switch (type) {
515 case ST_RTP: 510 case ST_RTP:
516 channel = transport_channel_; 511 channel = rtp_transport_;
517 socket_options_.push_back( 512 socket_options_.push_back(
518 std::pair<rtc::Socket::Option, int>(opt, value)); 513 std::pair<rtc::Socket::Option, int>(opt, value));
519 break; 514 break;
520 case ST_RTCP: 515 case ST_RTCP:
521 channel = rtcp_transport_channel_; 516 channel = rtcp_transport_;
522 rtcp_socket_options_.push_back( 517 rtcp_socket_options_.push_back(
523 std::pair<rtc::Socket::Option, int>(opt, value)); 518 std::pair<rtc::Socket::Option, int>(opt, value));
524 break; 519 break;
525 } 520 }
526 return channel ? channel->SetOption(opt, value) : -1; 521 return channel ? channel->SetOption(opt, value) : -1;
527 } 522 }
528 523
529 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { 524 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) {
530 crypto_options_ = crypto_options; 525 crypto_options_ = crypto_options;
531 return true; 526 return true;
532 } 527 }
533 528
534 void BaseChannel::OnWritableState(rtc::PacketTransportInterface* transport) { 529 void BaseChannel::OnWritableState(rtc::PacketTransportInterface* transport) {
535 RTC_DCHECK(transport == transport_channel_ || 530 RTC_DCHECK(transport == rtp_transport_ || transport == rtcp_transport_);
536 transport == rtcp_transport_channel_);
537 RTC_DCHECK(network_thread_->IsCurrent()); 531 RTC_DCHECK(network_thread_->IsCurrent());
538 UpdateWritableState_n(); 532 UpdateWritableState_n();
539 } 533 }
540 534
541 void BaseChannel::OnPacketRead(rtc::PacketTransportInterface* transport, 535 void BaseChannel::OnPacketRead(rtc::PacketTransportInterface* transport,
542 const char* data, 536 const char* data,
543 size_t len, 537 size_t len,
544 const rtc::PacketTime& packet_time, 538 const rtc::PacketTime& packet_time,
545 int flags) { 539 int flags) {
546 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead"); 540 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead");
547 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine 541 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine
548 RTC_DCHECK(network_thread_->IsCurrent()); 542 RTC_DCHECK(network_thread_->IsCurrent());
549 543
550 // When using RTCP multiplexing we might get RTCP packets on the RTP 544 // When using RTCP multiplexing we might get RTCP packets on the RTP
551 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. 545 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP.
552 bool rtcp = PacketIsRtcp(transport, data, len); 546 bool rtcp = PacketIsRtcp(transport, data, len);
553 rtc::CopyOnWriteBuffer packet(data, len); 547 rtc::CopyOnWriteBuffer packet(data, len);
554 HandlePacket(rtcp, &packet, packet_time); 548 HandlePacket(rtcp, &packet, packet_time);
555 } 549 }
556 550
557 void BaseChannel::OnReadyToSend(rtc::PacketTransportInterface* transport) { 551 void BaseChannel::OnReadyToSend(rtc::PacketTransportInterface* transport) {
558 RTC_DCHECK(transport == transport_channel_ || 552 RTC_DCHECK(transport == rtp_transport_ || transport == rtcp_transport_);
559 transport == rtcp_transport_channel_); 553 SetTransportChannelReadyToSend(transport == rtcp_transport_, true);
560 SetTransportChannelReadyToSend(transport == rtcp_transport_channel_, true);
561 } 554 }
562 555
563 void BaseChannel::OnDtlsState(TransportChannel* channel, 556 void BaseChannel::OnDtlsState(TransportChannel* channel,
564 DtlsTransportState state) { 557 DtlsTransportState state) {
565 if (!ShouldSetupDtlsSrtp_n()) { 558 if (!ShouldSetupDtlsSrtp_n()) {
566 return; 559 return;
567 } 560 }
568 561
569 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED 562 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED
570 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to 563 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to
571 // cover other scenarios like the whole channel is writable (not just this 564 // cover other scenarios like the whole channel is writable (not just this
572 // TransportChannel) or when TransportChannel is attached after DTLS is 565 // TransportChannel) or when TransportChannel is attached after DTLS is
573 // negotiated. 566 // negotiated.
574 if (state != DTLS_TRANSPORT_CONNECTED) { 567 if (state != DTLS_TRANSPORT_CONNECTED) {
575 srtp_filter_.ResetParams(); 568 srtp_filter_.ResetParams();
576 } 569 }
577 } 570 }
578 571
579 void BaseChannel::OnSelectedCandidatePairChanged( 572 void BaseChannel::OnSelectedCandidatePairChanged(
580 TransportChannel* channel, 573 TransportChannel* channel,
581 CandidatePairInterface* selected_candidate_pair, 574 CandidatePairInterface* selected_candidate_pair,
582 int last_sent_packet_id, 575 int last_sent_packet_id,
583 bool ready_to_send) { 576 bool ready_to_send) {
584 RTC_DCHECK(channel == transport_channel_ || 577 RTC_DCHECK(channel == rtp_transport_ || channel == rtcp_transport_);
585 channel == rtcp_transport_channel_);
586 RTC_DCHECK(network_thread_->IsCurrent()); 578 RTC_DCHECK(network_thread_->IsCurrent());
587 selected_candidate_pair_ = selected_candidate_pair; 579 selected_candidate_pair_ = selected_candidate_pair;
588 std::string transport_name = channel->transport_name(); 580 std::string transport_name = channel->transport_name();
589 rtc::NetworkRoute network_route; 581 rtc::NetworkRoute network_route;
590 if (selected_candidate_pair) { 582 if (selected_candidate_pair) {
591 network_route = rtc::NetworkRoute( 583 network_route = rtc::NetworkRoute(
592 ready_to_send, selected_candidate_pair->local_candidate().network_id(), 584 ready_to_send, selected_candidate_pair->local_candidate().network_id(),
593 selected_candidate_pair->remote_candidate().network_id(), 585 selected_candidate_pair->remote_candidate().network_id(),
594 last_sent_packet_id); 586 last_sent_packet_id);
595 587
596 UpdateTransportOverhead(); 588 UpdateTransportOverhead();
597 } 589 }
598 invoker_.AsyncInvoke<void>( 590 invoker_.AsyncInvoke<void>(
599 RTC_FROM_HERE, worker_thread_, 591 RTC_FROM_HERE, worker_thread_,
600 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, 592 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name,
601 network_route)); 593 network_route));
602 } 594 }
603 595
604 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) { 596 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) {
605 RTC_DCHECK(network_thread_->IsCurrent()); 597 RTC_DCHECK(network_thread_->IsCurrent());
606 if (rtcp) { 598 if (rtcp) {
607 rtcp_ready_to_send_ = ready; 599 rtcp_ready_to_send_ = ready;
608 } else { 600 } else {
609 rtp_ready_to_send_ = ready; 601 rtp_ready_to_send_ = ready;
610 } 602 }
611 603
612 bool ready_to_send = 604 bool ready_to_send =
613 (rtp_ready_to_send_ && 605 (rtp_ready_to_send_ &&
614 // In the case of rtcp mux |rtcp_transport_channel_| will be null. 606 // In the case of rtcp mux |rtcp_transport_| will be null.
615 (rtcp_ready_to_send_ || !rtcp_transport_channel_)); 607 (rtcp_ready_to_send_ || !rtcp_transport_));
616 608
617 invoker_.AsyncInvoke<void>( 609 invoker_.AsyncInvoke<void>(
618 RTC_FROM_HERE, worker_thread_, 610 RTC_FROM_HERE, worker_thread_,
619 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); 611 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send));
620 } 612 }
621 613
622 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInterface* transport, 614 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInterface* transport,
623 const char* data, 615 const char* data,
624 size_t len) { 616 size_t len) {
625 return (transport == rtcp_transport_channel_ || 617 return (transport == rtcp_transport_ ||
626 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); 618 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len)));
627 } 619 }
628 620
629 bool BaseChannel::SendPacket(bool rtcp, 621 bool BaseChannel::SendPacket(bool rtcp,
630 rtc::CopyOnWriteBuffer* packet, 622 rtc::CopyOnWriteBuffer* packet,
631 const rtc::PacketOptions& options) { 623 const rtc::PacketOptions& options) {
632 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. 624 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread.
633 // If the thread is not our network thread, we will post to our network 625 // If the thread is not our network thread, we will post to our network
634 // so that the real work happens on our network. This avoids us having to 626 // so that the real work happens on our network. This avoids us having to
635 // synchronize access to all the pieces of the send path, including 627 // synchronize access to all the pieces of the send path, including
636 // SRTP and the inner workings of the transport channels. 628 // SRTP and the inner workings of the transport channels.
637 // The only downside is that we can't return a proper failure code if 629 // The only downside is that we can't return a proper failure code if
638 // needed. Since UDP is unreliable anyway, this should be a non-issue. 630 // needed. Since UDP is unreliable anyway, this should be a non-issue.
639 if (!network_thread_->IsCurrent()) { 631 if (!network_thread_->IsCurrent()) {
640 // Avoid a copy by transferring the ownership of the packet data. 632 // Avoid a copy by transferring the ownership of the packet data.
641 int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET; 633 int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET;
642 SendPacketMessageData* data = new SendPacketMessageData; 634 SendPacketMessageData* data = new SendPacketMessageData;
643 data->packet = std::move(*packet); 635 data->packet = std::move(*packet);
644 data->options = options; 636 data->options = options;
645 network_thread_->Post(RTC_FROM_HERE, this, message_id, data); 637 network_thread_->Post(RTC_FROM_HERE, this, message_id, data);
646 return true; 638 return true;
647 } 639 }
648 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket"); 640 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket");
649 641
650 // Now that we are on the correct thread, ensure we have a place to send this 642 // Now that we are on the correct thread, ensure we have a place to send this
651 // packet before doing anything. (We might get RTCP packets that we don't 643 // packet before doing anything. (We might get RTCP packets that we don't
652 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP 644 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP
653 // transport. 645 // transport.
654 TransportChannel* channel = (!rtcp || rtcp_mux_filter_.IsActive()) ? 646 TransportChannel* channel =
655 transport_channel_ : rtcp_transport_channel_; 647 (!rtcp || rtcp_mux_filter_.IsActive()) ? rtp_transport_ : rtcp_transport_;
656 if (!channel || !channel->writable()) { 648 if (!channel || !channel->writable()) {
657 return false; 649 return false;
658 } 650 }
659 651
660 // Protect ourselves against crazy data. 652 // Protect ourselves against crazy data.
661 if (!ValidPacket(rtcp, packet)) { 653 if (!ValidPacket(rtcp, packet)) {
662 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " 654 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " "
663 << PacketType(rtcp) 655 << PacketType(rtcp)
664 << " packet: wrong size=" << packet->size(); 656 << " packet: wrong size=" << packet->size();
665 return false; 657 return false;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); 885 RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
894 if (!enabled_) 886 if (!enabled_)
895 return; 887 return;
896 888
897 LOG(LS_INFO) << "Channel disabled"; 889 LOG(LS_INFO) << "Channel disabled";
898 enabled_ = false; 890 enabled_ = false;
899 UpdateMediaSendRecvState_w(); 891 UpdateMediaSendRecvState_w();
900 } 892 }
901 893
902 void BaseChannel::UpdateWritableState_n() { 894 void BaseChannel::UpdateWritableState_n() {
903 if (transport_channel_ && transport_channel_->writable() && 895 if (rtp_transport_ && rtp_transport_->writable() &&
904 (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { 896 (!rtcp_transport_ || rtcp_transport_->writable())) {
905 ChannelWritable_n(); 897 ChannelWritable_n();
906 } else { 898 } else {
907 ChannelNotWritable_n(); 899 ChannelNotWritable_n();
908 } 900 }
909 } 901 }
910 902
911 void BaseChannel::ChannelWritable_n() { 903 void BaseChannel::ChannelWritable_n() {
912 RTC_DCHECK(network_thread_->IsCurrent()); 904 RTC_DCHECK(network_thread_->IsCurrent());
913 if (writable_) { 905 if (writable_) {
914 return; 906 return;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 if (!rtcp) { 941 if (!rtcp) {
950 GetSrtpCryptoSuites_n(&crypto_suites); 942 GetSrtpCryptoSuites_n(&crypto_suites);
951 } else { 943 } else {
952 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites); 944 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites);
953 } 945 }
954 return tc->SetSrtpCryptoSuites(crypto_suites); 946 return tc->SetSrtpCryptoSuites(crypto_suites);
955 } 947 }
956 948
957 bool BaseChannel::ShouldSetupDtlsSrtp_n() const { 949 bool BaseChannel::ShouldSetupDtlsSrtp_n() const {
958 // Since DTLS is applied to all channels, checking RTP should be enough. 950 // Since DTLS is applied to all channels, checking RTP should be enough.
959 return transport_channel_ && transport_channel_->IsDtlsActive(); 951 return rtp_transport_ && rtp_transport_->IsDtlsActive();
960 } 952 }
961 953
962 // This function returns true if either DTLS-SRTP is not in use 954 // This function returns true if either DTLS-SRTP is not in use
963 // *or* DTLS-SRTP is successfully set up. 955 // *or* DTLS-SRTP is successfully set up.
964 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp_channel) { 956 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp_channel) {
965 RTC_DCHECK(network_thread_->IsCurrent()); 957 RTC_DCHECK(network_thread_->IsCurrent());
966 bool ret = false; 958 bool ret = false;
967 959
968 TransportChannel* channel = 960 TransportChannel* channel = rtcp_channel ? rtcp_transport_ : rtp_transport_;
969 rtcp_channel ? rtcp_transport_channel_ : transport_channel_;
970 961
971 RTC_DCHECK(channel->IsDtlsActive()); 962 RTC_DCHECK(channel->IsDtlsActive());
972 963
973 int selected_crypto_suite; 964 int selected_crypto_suite;
974 965
975 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { 966 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) {
976 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; 967 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite";
977 return false; 968 return false;
978 } 969 }
979 970
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 1048
1058 if (!ShouldSetupDtlsSrtp_n()) { 1049 if (!ShouldSetupDtlsSrtp_n()) {
1059 return; 1050 return;
1060 } 1051 }
1061 1052
1062 if (!SetupDtlsSrtp_n(false)) { 1053 if (!SetupDtlsSrtp_n(false)) {
1063 SignalDtlsSrtpSetupFailure_n(false); 1054 SignalDtlsSrtpSetupFailure_n(false);
1064 return; 1055 return;
1065 } 1056 }
1066 1057
1067 if (rtcp_transport_channel_) { 1058 if (rtcp_transport_) {
1068 if (!SetupDtlsSrtp_n(true)) { 1059 if (!SetupDtlsSrtp_n(true)) {
1069 SignalDtlsSrtpSetupFailure_n(true); 1060 SignalDtlsSrtpSetupFailure_n(true);
1070 return; 1061 return;
1071 } 1062 }
1072 } 1063 }
1073 } 1064 }
1074 1065
1075 void BaseChannel::ChannelNotWritable_n() { 1066 void BaseChannel::ChannelNotWritable_n() {
1076 RTC_DCHECK(network_thread_->IsCurrent()); 1067 RTC_DCHECK(network_thread_->IsCurrent());
1077 if (!writable_) 1068 if (!writable_)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 } 1105 }
1115 1106
1116 return true; 1107 return true;
1117 } 1108 }
1118 1109
1119 // |dtls| will be set to true if DTLS is active for transport channel and 1110 // |dtls| will be set to true if DTLS is active for transport channel and
1120 // crypto is empty. 1111 // crypto is empty.
1121 bool BaseChannel::CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos, 1112 bool BaseChannel::CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos,
1122 bool* dtls, 1113 bool* dtls,
1123 std::string* error_desc) { 1114 std::string* error_desc) {
1124 *dtls = transport_channel_->IsDtlsActive(); 1115 *dtls = rtp_transport_->IsDtlsActive();
1125 if (*dtls && !cryptos.empty()) { 1116 if (*dtls && !cryptos.empty()) {
1126 SafeSetError("Cryptos must be empty when DTLS is active.", error_desc); 1117 SafeSetError("Cryptos must be empty when DTLS is active.", error_desc);
1127 return false; 1118 return false;
1128 } 1119 }
1129 return true; 1120 return true;
1130 } 1121 }
1131 1122
1132 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos, 1123 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos,
1133 ContentAction action, 1124 ContentAction action,
1134 ContentSource src, 1125 ContentSource src,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 } 1168 }
1178 1169
1179 void BaseChannel::ActivateRtcpMux() { 1170 void BaseChannel::ActivateRtcpMux() {
1180 network_thread_->Invoke<void>(RTC_FROM_HERE, 1171 network_thread_->Invoke<void>(RTC_FROM_HERE,
1181 Bind(&BaseChannel::ActivateRtcpMux_n, this)); 1172 Bind(&BaseChannel::ActivateRtcpMux_n, this));
1182 } 1173 }
1183 1174
1184 void BaseChannel::ActivateRtcpMux_n() { 1175 void BaseChannel::ActivateRtcpMux_n() {
1185 if (!rtcp_mux_filter_.IsActive()) { 1176 if (!rtcp_mux_filter_.IsActive()) {
1186 rtcp_mux_filter_.SetActive(); 1177 rtcp_mux_filter_.SetActive();
1178 bool need_to_delete_rtcp = (rtcp_transport() != nullptr);
1187 SetTransportChannel_n(true, nullptr); 1179 SetTransportChannel_n(true, nullptr);
1180 if (need_to_delete_rtcp) {
1181 SignalDestroyRtcpTransport(rtp_transport()->transport_name());
1182 }
1188 // Update aggregate writable/ready-to-send state between RTP and RTCP upon 1183 // Update aggregate writable/ready-to-send state between RTP and RTCP upon
1189 // removing channel. 1184 // removing channel.
1190 UpdateWritableState_n(); 1185 UpdateWritableState_n();
1191 SetTransportChannelReadyToSend(true, false); 1186 SetTransportChannelReadyToSend(true, false);
1192 } 1187 }
1193 } 1188 }
1194 1189
1195 bool BaseChannel::SetRtcpMux_n(bool enable, 1190 bool BaseChannel::SetRtcpMux_n(bool enable,
1196 ContentAction action, 1191 ContentAction action,
1197 ContentSource src, 1192 ContentSource src,
1198 std::string* error_desc) { 1193 std::string* error_desc) {
1199 bool ret = false; 1194 bool ret = false;
1200 switch (action) { 1195 switch (action) {
1201 case CA_OFFER: 1196 case CA_OFFER:
1202 ret = rtcp_mux_filter_.SetOffer(enable, src); 1197 ret = rtcp_mux_filter_.SetOffer(enable, src);
1203 break; 1198 break;
1204 case CA_PRANSWER: 1199 case CA_PRANSWER:
1205 // This may activate RTCP muxing, but we don't yet destroy the channel 1200 // This may activate RTCP muxing, but we don't yet destroy the channel
1206 // because the final answer may deactivate it. 1201 // because the final answer may deactivate it.
1207 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); 1202 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src);
1208 break; 1203 break;
1209 case CA_ANSWER: 1204 case CA_ANSWER:
1210 ret = rtcp_mux_filter_.SetAnswer(enable, src); 1205 ret = rtcp_mux_filter_.SetAnswer(enable, src);
1211 if (ret && rtcp_mux_filter_.IsActive()) { 1206 if (ret && rtcp_mux_filter_.IsActive()) {
1212 // We activated RTCP mux, close down the RTCP transport. 1207 // We activated RTCP mux, close down the RTCP transport.
1213 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() 1208 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name()
1214 << " by destroying RTCP transport channel for " 1209 << " by destroying RTCP transport channel for "
1215 << transport_name(); 1210 << transport_name();
1211 bool need_to_delete_rtcp = (rtcp_transport() != nullptr);
1216 SetTransportChannel_n(true, nullptr); 1212 SetTransportChannel_n(true, nullptr);
1213 if (need_to_delete_rtcp) {
1214 SignalDestroyRtcpTransport(rtp_transport()->transport_name());
1215 }
1217 UpdateWritableState_n(); 1216 UpdateWritableState_n();
1218 SetTransportChannelReadyToSend(true, false); 1217 SetTransportChannelReadyToSend(true, false);
1219 } 1218 }
1220 break; 1219 break;
1221 case CA_UPDATE: 1220 case CA_UPDATE:
1222 // No RTCP mux info. 1221 // No RTCP mux info.
1223 ret = true; 1222 ret = true;
1224 break; 1223 break;
1225 default: 1224 default:
1226 break; 1225 break;
1227 } 1226 }
1228 if (!ret) { 1227 if (!ret) {
1229 SafeSetError("Failed to setup RTCP mux filter.", error_desc); 1228 SafeSetError("Failed to setup RTCP mux filter.", error_desc);
1230 return false; 1229 return false;
1231 } 1230 }
1232 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or 1231 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or
1233 // CA_ANSWER, but we only want to tear down the RTCP transport channel if we 1232 // CA_ANSWER, but we only want to tear down the RTCP transport channel if we
1234 // received a final answer. 1233 // received a final answer.
1235 if (rtcp_mux_filter_.IsActive()) { 1234 if (rtcp_mux_filter_.IsActive()) {
1236 // If the RTP transport is already writable, then so are we. 1235 // If the RTP transport is already writable, then so are we.
1237 if (transport_channel_->writable()) { 1236 if (rtp_transport_->writable()) {
1238 ChannelWritable_n(); 1237 ChannelWritable_n();
1239 } 1238 }
1240 } 1239 }
1241 1240
1242 return true; 1241 return true;
1243 } 1242 }
1244 1243
1245 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { 1244 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) {
1246 RTC_DCHECK(worker_thread() == rtc::Thread::Current()); 1245 RTC_DCHECK(worker_thread() == rtc::Thread::Current());
1247 return media_channel()->AddRecvStream(sp); 1246 return media_channel()->AddRecvStream(sp);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 rtc::Bind(&BaseChannel::SignalSentPacket_w, this, sent_packet)); 1461 rtc::Bind(&BaseChannel::SignalSentPacket_w, this, sent_packet));
1463 } 1462 }
1464 1463
1465 void BaseChannel::SignalSentPacket_w(const rtc::SentPacket& sent_packet) { 1464 void BaseChannel::SignalSentPacket_w(const rtc::SentPacket& sent_packet) {
1466 RTC_DCHECK(worker_thread_->IsCurrent()); 1465 RTC_DCHECK(worker_thread_->IsCurrent());
1467 SignalSentPacket(sent_packet); 1466 SignalSentPacket(sent_packet);
1468 } 1467 }
1469 1468
1470 VoiceChannel::VoiceChannel(rtc::Thread* worker_thread, 1469 VoiceChannel::VoiceChannel(rtc::Thread* worker_thread,
1471 rtc::Thread* network_thread, 1470 rtc::Thread* network_thread,
1471 rtc::Thread* signaling_thread,
1472 MediaEngineInterface* media_engine, 1472 MediaEngineInterface* media_engine,
1473 VoiceMediaChannel* media_channel, 1473 VoiceMediaChannel* media_channel,
1474 TransportController* transport_controller,
1475 const std::string& content_name, 1474 const std::string& content_name,
1476 bool rtcp, 1475 bool rtcp,
1477 bool srtp_required) 1476 bool srtp_required)
1478 : BaseChannel(worker_thread, 1477 : BaseChannel(worker_thread,
1479 network_thread, 1478 network_thread,
1479 signaling_thread,
1480 media_channel, 1480 media_channel,
1481 transport_controller,
1482 content_name, 1481 content_name,
1483 rtcp, 1482 rtcp,
1484 srtp_required), 1483 srtp_required),
1485 media_engine_(media_engine), 1484 media_engine_(media_engine),
1486 received_media_(false) {} 1485 received_media_(false) {}
1487 1486
1488 VoiceChannel::~VoiceChannel() { 1487 VoiceChannel::~VoiceChannel() {
1489 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); 1488 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel");
1490 StopAudioMonitor(); 1489 StopAudioMonitor();
1491 StopMediaMonitor(); 1490 StopMediaMonitor();
1492 // this can't be done in the base class, since it calls a virtual 1491 // this can't be done in the base class, since it calls a virtual
1493 DisableMedia_w(); 1492 DisableMedia_w();
1494 Deinit(); 1493 Deinit();
1495 } 1494 }
1496 1495
1497 bool VoiceChannel::Init_w(const std::string* bundle_transport_name) { 1496 bool VoiceChannel::Init_w(TransportChannel* rtp_transport,
1498 if (!BaseChannel::Init_w(bundle_transport_name)) { 1497 TransportChannel* rtcp_transport) {
1499 return false; 1498 return BaseChannel::Init_w(rtp_transport, rtcp_transport);
1500 }
1501 return true;
1502 } 1499 }
1503 1500
1504 bool VoiceChannel::SetAudioSend(uint32_t ssrc, 1501 bool VoiceChannel::SetAudioSend(uint32_t ssrc,
1505 bool enable, 1502 bool enable,
1506 const AudioOptions* options, 1503 const AudioOptions* options,
1507 AudioSource* source) { 1504 AudioSource* source) {
1508 return InvokeOnWorker(RTC_FROM_HERE, 1505 return InvokeOnWorker(RTC_FROM_HERE,
1509 Bind(&VoiceMediaChannel::SetAudioSend, media_channel(), 1506 Bind(&VoiceMediaChannel::SetAudioSend, media_channel(),
1510 ssrc, enable, options, source)); 1507 ssrc, enable, options, source));
1511 } 1508 }
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1878 SignalAudioMonitor(this, info); 1875 SignalAudioMonitor(this, info);
1879 } 1876 }
1880 1877
1881 void VoiceChannel::GetSrtpCryptoSuites_n( 1878 void VoiceChannel::GetSrtpCryptoSuites_n(
1882 std::vector<int>* crypto_suites) const { 1879 std::vector<int>* crypto_suites) const {
1883 GetSupportedAudioCryptoSuites(crypto_options(), crypto_suites); 1880 GetSupportedAudioCryptoSuites(crypto_options(), crypto_suites);
1884 } 1881 }
1885 1882
1886 VideoChannel::VideoChannel(rtc::Thread* worker_thread, 1883 VideoChannel::VideoChannel(rtc::Thread* worker_thread,
1887 rtc::Thread* network_thread, 1884 rtc::Thread* network_thread,
1885 rtc::Thread* signaling_thread,
1888 VideoMediaChannel* media_channel, 1886 VideoMediaChannel* media_channel,
1889 TransportController* transport_controller,
1890 const std::string& content_name, 1887 const std::string& content_name,
1891 bool rtcp, 1888 bool rtcp,
1892 bool srtp_required) 1889 bool srtp_required)
1893 : BaseChannel(worker_thread, 1890 : BaseChannel(worker_thread,
1894 network_thread, 1891 network_thread,
1892 signaling_thread,
1895 media_channel, 1893 media_channel,
1896 transport_controller,
1897 content_name, 1894 content_name,
1898 rtcp, 1895 rtcp,
1899 srtp_required) {} 1896 srtp_required) {}
1900 1897
1901 bool VideoChannel::Init_w(const std::string* bundle_transport_name) { 1898 bool VideoChannel::Init_w(TransportChannel* rtp_transport,
1902 if (!BaseChannel::Init_w(bundle_transport_name)) { 1899 TransportChannel* rtcp_transport) {
1903 return false; 1900 return BaseChannel::Init_w(rtp_transport, rtcp_transport);
1904 }
1905 return true;
1906 } 1901 }
1907 1902
1908 VideoChannel::~VideoChannel() { 1903 VideoChannel::~VideoChannel() {
1909 TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel"); 1904 TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel");
1910 StopMediaMonitor(); 1905 StopMediaMonitor();
1911 // this can't be done in the base class, since it calls a virtual 1906 // this can't be done in the base class, since it calls a virtual
1912 DisableMedia_w(); 1907 DisableMedia_w();
1913 1908
1914 Deinit(); 1909 Deinit();
1915 } 1910 }
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 SignalMediaMonitor(this, info); 2136 SignalMediaMonitor(this, info);
2142 } 2137 }
2143 2138
2144 void VideoChannel::GetSrtpCryptoSuites_n( 2139 void VideoChannel::GetSrtpCryptoSuites_n(
2145 std::vector<int>* crypto_suites) const { 2140 std::vector<int>* crypto_suites) const {
2146 GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites); 2141 GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites);
2147 } 2142 }
2148 2143
2149 RtpDataChannel::RtpDataChannel(rtc::Thread* worker_thread, 2144 RtpDataChannel::RtpDataChannel(rtc::Thread* worker_thread,
2150 rtc::Thread* network_thread, 2145 rtc::Thread* network_thread,
2146 rtc::Thread* signaling_thread,
2151 DataMediaChannel* media_channel, 2147 DataMediaChannel* media_channel,
2152 TransportController* transport_controller,
2153 const std::string& content_name, 2148 const std::string& content_name,
2154 bool rtcp, 2149 bool rtcp,
2155 bool srtp_required) 2150 bool srtp_required)
2156 : BaseChannel(worker_thread, 2151 : BaseChannel(worker_thread,
2157 network_thread, 2152 network_thread,
2153 signaling_thread,
2158 media_channel, 2154 media_channel,
2159 transport_controller,
2160 content_name, 2155 content_name,
2161 rtcp, 2156 rtcp,
2162 srtp_required) {} 2157 srtp_required) {}
2163 2158
2164 RtpDataChannel::~RtpDataChannel() { 2159 RtpDataChannel::~RtpDataChannel() {
2165 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel"); 2160 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel");
2166 StopMediaMonitor(); 2161 StopMediaMonitor();
2167 // this can't be done in the base class, since it calls a virtual 2162 // this can't be done in the base class, since it calls a virtual
2168 DisableMedia_w(); 2163 DisableMedia_w();
2169 2164
2170 Deinit(); 2165 Deinit();
2171 } 2166 }
2172 2167
2173 bool RtpDataChannel::Init_w(const std::string* bundle_transport_name) { 2168 bool RtpDataChannel::Init_w(TransportChannel* rtp_transport,
2174 if (!BaseChannel::Init_w(bundle_transport_name)) { 2169 TransportChannel* rtcp_transport) {
2170 if (!BaseChannel::Init_w(rtp_transport, rtcp_transport)) {
2175 return false; 2171 return false;
2176 } 2172 }
2177 media_channel()->SignalDataReceived.connect(this, 2173 media_channel()->SignalDataReceived.connect(this,
2178 &RtpDataChannel::OnDataReceived); 2174 &RtpDataChannel::OnDataReceived);
2179 media_channel()->SignalReadyToSend.connect( 2175 media_channel()->SignalReadyToSend.connect(
2180 this, &RtpDataChannel::OnDataChannelReadyToSend); 2176 this, &RtpDataChannel::OnDataChannelReadyToSend);
2181 return true; 2177 return true;
2182 } 2178 }
2183 2179
2184 bool RtpDataChannel::SendData(const SendDataParams& params, 2180 bool RtpDataChannel::SendData(const SendDataParams& params,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, 2406 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA,
2411 new DataChannelReadyToSendMessageData(writable)); 2407 new DataChannelReadyToSendMessageData(writable));
2412 } 2408 }
2413 2409
2414 void RtpDataChannel::GetSrtpCryptoSuites_n( 2410 void RtpDataChannel::GetSrtpCryptoSuites_n(
2415 std::vector<int>* crypto_suites) const { 2411 std::vector<int>* crypto_suites) const {
2416 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); 2412 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites);
2417 } 2413 }
2418 2414
2419 } // namespace cricket 2415 } // 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