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

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

Issue 2606123002: Remove the dependency of TransportChannel and TransportChannelImpl. (Closed)
Patch Set: 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // BaseChannel could have resulted in an error), but even so, we'll just 336 // BaseChannel could have resulted in an error), but even so, we'll just
337 // encounter the error again and update "ready to send" accordingly. 337 // encounter the error again and update "ready to send" accordingly.
338 SetTransportChannelReadyToSend( 338 SetTransportChannelReadyToSend(
339 false, transport_channel_ && transport_channel_->writable()); 339 false, transport_channel_ && transport_channel_->writable());
340 SetTransportChannelReadyToSend( 340 SetTransportChannelReadyToSend(
341 true, rtcp_transport_channel_ && rtcp_transport_channel_->writable()); 341 true, rtcp_transport_channel_ && rtcp_transport_channel_->writable());
342 return true; 342 return true;
343 } 343 }
344 344
345 void BaseChannel::SetTransportChannel_n(bool rtcp, 345 void BaseChannel::SetTransportChannel_n(bool rtcp,
346 TransportChannel* new_channel) { 346 DtlsTransportInternal* new_channel) {
347 RTC_DCHECK(network_thread_->IsCurrent()); 347 RTC_DCHECK(network_thread_->IsCurrent());
348 TransportChannel*& old_channel = 348 DtlsTransportInternal*& old_channel =
349 rtcp ? rtcp_transport_channel_ : transport_channel_; 349 rtcp ? rtcp_transport_channel_ : transport_channel_;
350 350
351 if (!old_channel && !new_channel) { 351 if (!old_channel && !new_channel) {
352 // Nothing to do. 352 // Nothing to do.
353 return; 353 return;
354 } 354 }
355 RTC_DCHECK(old_channel != new_channel); 355 RTC_DCHECK(old_channel != new_channel);
356 356
357 if (old_channel) { 357 if (old_channel) {
358 DisconnectFromTransportChannel(old_channel); 358 DisconnectFromTransportChannel(old_channel);
(...skipping 11 matching lines...) Expand all
370 << "should never happen."; 370 << "should never happen.";
371 } 371 }
372 ConnectToTransportChannel(new_channel); 372 ConnectToTransportChannel(new_channel);
373 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_; 373 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_;
374 for (const auto& pair : socket_options) { 374 for (const auto& pair : socket_options) {
375 new_channel->SetOption(pair.first, pair.second); 375 new_channel->SetOption(pair.first, pair.second);
376 } 376 }
377 } 377 }
378 } 378 }
379 379
380 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { 380 void BaseChannel::ConnectToTransportChannel(DtlsTransportInternal* tc) {
381 RTC_DCHECK(network_thread_->IsCurrent()); 381 RTC_DCHECK(network_thread_->IsCurrent());
382 382
383 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); 383 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState);
384 tc->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); 384 tc->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead);
385 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); 385 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend);
386 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); 386 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState);
387 tc->SignalSelectedCandidatePairChanged.connect( 387 tc->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n);
388 tc->ice_transport()->SignalSelectedCandidatePairChanged.connect(
388 this, &BaseChannel::OnSelectedCandidatePairChanged); 389 this, &BaseChannel::OnSelectedCandidatePairChanged);
389 tc->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n);
390 } 390 }
391 391
392 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { 392 void BaseChannel::DisconnectFromTransportChannel(DtlsTransportInternal* tc) {
393 RTC_DCHECK(network_thread_->IsCurrent()); 393 RTC_DCHECK(network_thread_->IsCurrent());
394 OnSelectedCandidatePairChanged(tc, nullptr, -1, false); 394 OnSelectedCandidatePairChanged(tc->ice_transport(), nullptr, -1, false);
395 395
396 tc->SignalWritableState.disconnect(this); 396 tc->SignalWritableState.disconnect(this);
397 tc->SignalReadPacket.disconnect(this); 397 tc->SignalReadPacket.disconnect(this);
398 tc->SignalReadyToSend.disconnect(this); 398 tc->SignalReadyToSend.disconnect(this);
399 tc->SignalDtlsState.disconnect(this); 399 tc->SignalDtlsState.disconnect(this);
400 tc->SignalSelectedCandidatePairChanged.disconnect(this);
401 tc->SignalSentPacket.disconnect(this); 400 tc->SignalSentPacket.disconnect(this);
401 tc->ice_transport()->SignalSelectedCandidatePairChanged.disconnect(this);
402 } 402 }
403 403
404 bool BaseChannel::Enable(bool enable) { 404 bool BaseChannel::Enable(bool enable) {
405 worker_thread_->Invoke<void>( 405 worker_thread_->Invoke<void>(
406 RTC_FROM_HERE, 406 RTC_FROM_HERE,
407 Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, 407 Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w,
408 this)); 408 this));
409 return true; 409 return true;
410 } 410 }
411 411
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 461
462 void BaseChannel::StopConnectionMonitor() { 462 void BaseChannel::StopConnectionMonitor() {
463 if (connection_monitor_) { 463 if (connection_monitor_) {
464 connection_monitor_->Stop(); 464 connection_monitor_->Stop();
465 connection_monitor_.reset(); 465 connection_monitor_.reset();
466 } 466 }
467 } 467 }
468 468
469 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { 469 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) {
470 RTC_DCHECK(network_thread_->IsCurrent()); 470 RTC_DCHECK(network_thread_->IsCurrent());
471 return transport_channel_->GetStats(infos); 471 return transport_channel_->ice_transport()->GetStats(infos);
472 } 472 }
473 473
474 bool BaseChannel::IsReadyToReceiveMedia_w() const { 474 bool BaseChannel::IsReadyToReceiveMedia_w() const {
475 // Receive data if we are enabled and have local content, 475 // Receive data if we are enabled and have local content,
476 return enabled() && IsReceiveContentDirection(local_content_direction_); 476 return enabled() && IsReceiveContentDirection(local_content_direction_);
477 } 477 }
478 478
479 bool BaseChannel::IsReadyToSendMedia_w() const { 479 bool BaseChannel::IsReadyToSendMedia_w() const {
480 // Need to access some state updated on the network thread. 480 // Need to access some state updated on the network thread.
481 return network_thread_->Invoke<bool>( 481 return network_thread_->Invoke<bool>(
(...skipping 22 matching lines...) Expand all
504 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, 504 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt,
505 int value) { 505 int value) {
506 return network_thread_->Invoke<int>( 506 return network_thread_->Invoke<int>(
507 RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value)); 507 RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value));
508 } 508 }
509 509
510 int BaseChannel::SetOption_n(SocketType type, 510 int BaseChannel::SetOption_n(SocketType type,
511 rtc::Socket::Option opt, 511 rtc::Socket::Option opt,
512 int value) { 512 int value) {
513 RTC_DCHECK(network_thread_->IsCurrent()); 513 RTC_DCHECK(network_thread_->IsCurrent());
514 TransportChannel* channel = nullptr; 514 DtlsTransportInternal* channel = nullptr;
515 switch (type) { 515 switch (type) {
516 case ST_RTP: 516 case ST_RTP:
517 channel = transport_channel_; 517 channel = transport_channel_;
518 socket_options_.push_back( 518 socket_options_.push_back(
519 std::pair<rtc::Socket::Option, int>(opt, value)); 519 std::pair<rtc::Socket::Option, int>(opt, value));
520 break; 520 break;
521 case ST_RTCP: 521 case ST_RTCP:
522 channel = rtcp_transport_channel_; 522 channel = rtcp_transport_channel_;
523 rtcp_socket_options_.push_back( 523 rtcp_socket_options_.push_back(
524 std::pair<rtc::Socket::Option, int>(opt, value)); 524 std::pair<rtc::Socket::Option, int>(opt, value));
525 break; 525 break;
526 } 526 }
527 return channel ? channel->SetOption(opt, value) : -1; 527 return channel ? channel->ice_transport()->SetOption(opt, value) : -1;
528 } 528 }
529 529
530 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { 530 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) {
531 crypto_options_ = crypto_options; 531 crypto_options_ = crypto_options;
532 return true; 532 return true;
533 } 533 }
534 534
535 void BaseChannel::OnWritableState(rtc::PacketTransportInterface* transport) { 535 void BaseChannel::OnWritableState(rtc::PacketTransportInterface* transport) {
536 RTC_DCHECK(transport == transport_channel_ || 536 RTC_DCHECK(transport == transport_channel_ ||
537 transport == rtcp_transport_channel_); 537 transport == rtcp_transport_channel_);
(...skipping 16 matching lines...) Expand all
554 rtc::CopyOnWriteBuffer packet(data, len); 554 rtc::CopyOnWriteBuffer packet(data, len);
555 HandlePacket(rtcp, &packet, packet_time); 555 HandlePacket(rtcp, &packet, packet_time);
556 } 556 }
557 557
558 void BaseChannel::OnReadyToSend(rtc::PacketTransportInterface* transport) { 558 void BaseChannel::OnReadyToSend(rtc::PacketTransportInterface* transport) {
559 RTC_DCHECK(transport == transport_channel_ || 559 RTC_DCHECK(transport == transport_channel_ ||
560 transport == rtcp_transport_channel_); 560 transport == rtcp_transport_channel_);
561 SetTransportChannelReadyToSend(transport == rtcp_transport_channel_, true); 561 SetTransportChannelReadyToSend(transport == rtcp_transport_channel_, true);
562 } 562 }
563 563
564 void BaseChannel::OnDtlsState(TransportChannel* channel, 564 void BaseChannel::OnDtlsState(DtlsTransportInternal* channel,
565 DtlsTransportState state) { 565 DtlsTransportState state) {
566 if (!ShouldSetupDtlsSrtp_n()) { 566 if (!ShouldSetupDtlsSrtp_n()) {
567 return; 567 return;
568 } 568 }
569 569
570 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED 570 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED
571 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to 571 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to
572 // cover other scenarios like the whole channel is writable (not just this 572 // cover other scenarios like the whole channel is writable (not just this
573 // TransportChannel) or when TransportChannel is attached after DTLS is 573 // TransportChannel) or when TransportChannel is attached after DTLS is
574 // negotiated. 574 // negotiated.
575 if (state != DTLS_TRANSPORT_CONNECTED) { 575 if (state != DTLS_TRANSPORT_CONNECTED) {
576 srtp_filter_.ResetParams(); 576 srtp_filter_.ResetParams();
577 } 577 }
578 } 578 }
579 579
580 void BaseChannel::OnSelectedCandidatePairChanged( 580 void BaseChannel::OnSelectedCandidatePairChanged(
581 TransportChannel* channel, 581 TransportChannel* channel,
582 CandidatePairInterface* selected_candidate_pair, 582 CandidatePairInterface* selected_candidate_pair,
583 int last_sent_packet_id, 583 int last_sent_packet_id,
584 bool ready_to_send) { 584 bool ready_to_send) {
585 RTC_DCHECK(channel == transport_channel_ || 585 RTC_DCHECK(channel == transport_channel_->ice_transport() ||
586 channel == rtcp_transport_channel_); 586 channel == rtcp_transport_channel_->ice_transport());
587 RTC_DCHECK(network_thread_->IsCurrent()); 587 RTC_DCHECK(network_thread_->IsCurrent());
588 selected_candidate_pair_ = selected_candidate_pair; 588 selected_candidate_pair_ = selected_candidate_pair;
589 std::string transport_name = channel->transport_name(); 589 std::string transport_name = channel->transport_name();
590 rtc::NetworkRoute network_route; 590 rtc::NetworkRoute network_route;
591 if (selected_candidate_pair) { 591 if (selected_candidate_pair) {
592 network_route = rtc::NetworkRoute( 592 network_route = rtc::NetworkRoute(
593 ready_to_send, selected_candidate_pair->local_candidate().network_id(), 593 ready_to_send, selected_candidate_pair->local_candidate().network_id(),
594 selected_candidate_pair->remote_candidate().network_id(), 594 selected_candidate_pair->remote_candidate().network_id(),
595 last_sent_packet_id); 595 last_sent_packet_id);
596 596
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 data->options = options; 645 data->options = options;
646 network_thread_->Post(RTC_FROM_HERE, this, message_id, data); 646 network_thread_->Post(RTC_FROM_HERE, this, message_id, data);
647 return true; 647 return true;
648 } 648 }
649 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket"); 649 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket");
650 650
651 // Now that we are on the correct thread, ensure we have a place to send this 651 // Now that we are on the correct thread, ensure we have a place to send this
652 // packet before doing anything. (We might get RTCP packets that we don't 652 // packet before doing anything. (We might get RTCP packets that we don't
653 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP 653 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP
654 // transport. 654 // transport.
655 TransportChannel* channel = (!rtcp || rtcp_mux_filter_.IsActive()) ? 655 DtlsTransportInternal* channel = (!rtcp || rtcp_mux_filter_.IsActive())
656 transport_channel_ : rtcp_transport_channel_; 656 ? transport_channel_
657 : rtcp_transport_channel_;
657 if (!channel || !channel->writable()) { 658 if (!channel || !channel->writable()) {
658 return false; 659 return false;
659 } 660 }
660 661
661 // Protect ourselves against crazy data. 662 // Protect ourselves against crazy data.
662 if (!ValidPacket(rtcp, packet)) { 663 if (!ValidPacket(rtcp, packet)) {
663 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " 664 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " "
664 << PacketType(rtcp) 665 << PacketType(rtcp)
665 << " packet: wrong size=" << packet->size(); 666 << " packet: wrong size=" << packet->size();
666 return false; 667 return false;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 invoker_.AsyncInvoke<void>( 937 invoker_.AsyncInvoke<void>(
937 RTC_FROM_HERE, signaling_thread(), 938 RTC_FROM_HERE, signaling_thread(),
938 Bind(&BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); 939 Bind(&BaseChannel::SignalDtlsSetupFailure_s, this, rtcp));
939 } 940 }
940 941
941 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { 942 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) {
942 RTC_DCHECK(signaling_thread() == rtc::Thread::Current()); 943 RTC_DCHECK(signaling_thread() == rtc::Thread::Current());
943 SignalDtlsSetupFailure(this, rtcp); 944 SignalDtlsSetupFailure(this, rtcp);
944 } 945 }
945 946
946 bool BaseChannel::SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp) { 947 bool BaseChannel::SetDtlsSrtpCryptoSuites_n(DtlsTransportInternal* tc,
948 bool rtcp) {
947 std::vector<int> crypto_suites; 949 std::vector<int> crypto_suites;
948 // We always use the default SRTP crypto suites for RTCP, but we may use 950 // We always use the default SRTP crypto suites for RTCP, but we may use
949 // different crypto suites for RTP depending on the media type. 951 // different crypto suites for RTP depending on the media type.
950 if (!rtcp) { 952 if (!rtcp) {
951 GetSrtpCryptoSuites_n(&crypto_suites); 953 GetSrtpCryptoSuites_n(&crypto_suites);
952 } else { 954 } else {
953 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites); 955 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites);
954 } 956 }
955 return tc->SetSrtpCryptoSuites(crypto_suites); 957 return tc->SetSrtpCryptoSuites(crypto_suites);
956 } 958 }
957 959
958 bool BaseChannel::ShouldSetupDtlsSrtp_n() const { 960 bool BaseChannel::ShouldSetupDtlsSrtp_n() const {
959 // Since DTLS is applied to all channels, checking RTP should be enough. 961 // Since DTLS is applied to all channels, checking RTP should be enough.
960 return transport_channel_ && transport_channel_->IsDtlsActive(); 962 return transport_channel_ && transport_channel_->IsDtlsActive();
961 } 963 }
962 964
963 // This function returns true if either DTLS-SRTP is not in use 965 // This function returns true if either DTLS-SRTP is not in use
964 // *or* DTLS-SRTP is successfully set up. 966 // *or* DTLS-SRTP is successfully set up.
965 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp_channel) { 967 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp_channel) {
966 RTC_DCHECK(network_thread_->IsCurrent()); 968 RTC_DCHECK(network_thread_->IsCurrent());
967 bool ret = false; 969 bool ret = false;
968 970
969 TransportChannel* channel = 971 DtlsTransportInternal* channel =
970 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; 972 rtcp_channel ? rtcp_transport_channel_ : transport_channel_;
971 973
972 RTC_DCHECK(channel->IsDtlsActive()); 974 RTC_DCHECK(channel->IsDtlsActive());
973 975
974 int selected_crypto_suite; 976 int selected_crypto_suite;
975 977
976 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { 978 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) {
977 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; 979 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite";
978 return false; 980 return false;
979 } 981 }
(...skipping 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after
2467 } 2469 }
2468 2470
2469 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { 2471 void DataChannel::OnStreamClosedRemotely(uint32_t sid) {
2470 rtc::TypedMessageData<uint32_t>* message = 2472 rtc::TypedMessageData<uint32_t>* message =
2471 new rtc::TypedMessageData<uint32_t>(sid); 2473 new rtc::TypedMessageData<uint32_t>(sid);
2472 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, 2474 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY,
2473 message); 2475 message);
2474 } 2476 }
2475 2477
2476 } // namespace cricket 2478 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698