OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 old_transport_desc->ice_ufrag, old_transport_desc->ice_pwd, | 454 old_transport_desc->ice_ufrag, old_transport_desc->ice_pwd, |
455 new_transport_desc->ice_ufrag, new_transport_desc->ice_pwd)) { | 455 new_transport_desc->ice_ufrag, new_transport_desc->ice_pwd)) { |
456 LOG(LS_INFO) << "Remote peer requests ICE restart for " << content_name | 456 LOG(LS_INFO) << "Remote peer requests ICE restart for " << content_name |
457 << "."; | 457 << "."; |
458 return true; | 458 return true; |
459 } | 459 } |
460 return false; | 460 return false; |
461 } | 461 } |
462 | 462 |
463 WebRtcSession::WebRtcSession( | 463 WebRtcSession::WebRtcSession( |
464 webrtc::MediaControllerInterface* media_controller, | 464 cricket::ChannelManager* channel_manager, |
| 465 const cricket::MediaConfig& media_config, |
| 466 RtcEventLog* event_log, |
465 rtc::Thread* network_thread, | 467 rtc::Thread* network_thread, |
466 rtc::Thread* worker_thread, | 468 rtc::Thread* worker_thread, |
467 rtc::Thread* signaling_thread, | 469 rtc::Thread* signaling_thread, |
468 cricket::PortAllocator* port_allocator, | 470 cricket::PortAllocator* port_allocator, |
469 std::unique_ptr<cricket::TransportController> transport_controller, | 471 std::unique_ptr<cricket::TransportController> transport_controller, |
470 std::unique_ptr<cricket::SctpTransportInternalFactory> sctp_factory) | 472 std::unique_ptr<cricket::SctpTransportInternalFactory> sctp_factory) |
471 : network_thread_(network_thread), | 473 : network_thread_(network_thread), |
472 worker_thread_(worker_thread), | 474 worker_thread_(worker_thread), |
473 signaling_thread_(signaling_thread), | 475 signaling_thread_(signaling_thread), |
474 // RFC 3264: The numeric value of the session id and version in the | 476 // RFC 3264: The numeric value of the session id and version in the |
475 // o line MUST be representable with a "64 bit signed integer". | 477 // o line MUST be representable with a "64 bit signed integer". |
476 // Due to this constraint session id |sid_| is max limited to LLONG_MAX. | 478 // Due to this constraint session id |sid_| is max limited to LLONG_MAX. |
477 sid_(rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX)), | 479 sid_(rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX)), |
478 transport_controller_(std::move(transport_controller)), | 480 transport_controller_(std::move(transport_controller)), |
479 sctp_factory_(std::move(sctp_factory)), | 481 sctp_factory_(std::move(sctp_factory)), |
480 media_controller_(media_controller), | 482 media_config_(media_config), |
481 channel_manager_(media_controller_->channel_manager()), | 483 event_log_(event_log), |
| 484 channel_manager_(channel_manager), |
482 ice_observer_(NULL), | 485 ice_observer_(NULL), |
483 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), | 486 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
484 ice_connection_receiving_(true), | 487 ice_connection_receiving_(true), |
485 older_version_remote_peer_(false), | 488 older_version_remote_peer_(false), |
486 dtls_enabled_(false), | 489 dtls_enabled_(false), |
487 data_channel_type_(cricket::DCT_NONE), | 490 data_channel_type_(cricket::DCT_NONE), |
488 metrics_observer_(NULL) { | 491 metrics_observer_(NULL) { |
489 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLED); | 492 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLED); |
490 transport_controller_->SignalConnectionState.connect( | 493 transport_controller_->SignalConnectionState.connect( |
491 this, &WebRtcSession::OnTransportControllerConnectionState); | 494 this, &WebRtcSession::OnTransportControllerConnectionState); |
(...skipping 26 matching lines...) Expand all Loading... |
518 SignalDataChannelDestroyed(); | 521 SignalDataChannelDestroyed(); |
519 network_thread_->Invoke<void>( | 522 network_thread_->Invoke<void>( |
520 RTC_FROM_HERE, rtc::Bind(&WebRtcSession::DestroySctpTransport_n, this)); | 523 RTC_FROM_HERE, rtc::Bind(&WebRtcSession::DestroySctpTransport_n, this)); |
521 } | 524 } |
522 #ifdef HAVE_QUIC | 525 #ifdef HAVE_QUIC |
523 if (quic_data_transport_) { | 526 if (quic_data_transport_) { |
524 quic_data_transport_.reset(); | 527 quic_data_transport_.reset(); |
525 } | 528 } |
526 #endif | 529 #endif |
527 | 530 |
| 531 // Make sure Call is destructed on the worker thread. |
| 532 if (state() != STATE_CLOSED) { |
| 533 worker_thread_->Invoke<void>(RTC_FROM_HERE, |
| 534 rtc::Bind(&WebRtcSession::Close_w, this)); |
| 535 } |
528 LOG(LS_INFO) << "Session: " << id() << " is destroyed."; | 536 LOG(LS_INFO) << "Session: " << id() << " is destroyed."; |
529 } | 537 } |
530 | 538 |
531 bool WebRtcSession::Initialize( | 539 bool WebRtcSession::Initialize( |
532 const PeerConnectionFactoryInterface::Options& options, | 540 const PeerConnectionFactoryInterface::Options& options, |
533 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, | 541 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
534 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { | 542 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
535 bundle_policy_ = rtc_configuration.bundle_policy; | 543 bundle_policy_ = rtc_configuration.bundle_policy; |
536 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; | 544 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; |
537 transport_controller_->SetSslMaxProtocolVersion(options.ssl_max_version); | 545 transport_controller_->SetSslMaxProtocolVersion(options.ssl_max_version); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 } | 621 } |
614 } | 622 } |
615 | 623 |
616 webrtc_session_desc_factory_->SignalCertificateReady.connect( | 624 webrtc_session_desc_factory_->SignalCertificateReady.connect( |
617 this, &WebRtcSession::OnCertificateReady); | 625 this, &WebRtcSession::OnCertificateReady); |
618 | 626 |
619 if (options.disable_encryption) { | 627 if (options.disable_encryption) { |
620 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED); | 628 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED); |
621 } | 629 } |
622 | 630 |
| 631 worker_thread_->Invoke<void>(RTC_FROM_HERE, |
| 632 rtc::Bind(&WebRtcSession::Init_w, this)); |
| 633 |
623 return true; | 634 return true; |
624 } | 635 } |
625 | 636 |
| 637 void WebRtcSession::Init_w() { |
| 638 RTC_DCHECK(worker_thread_->IsCurrent()); |
| 639 RTC_DCHECK(!call_); |
| 640 |
| 641 const int kMinBandwidthBps = 30000; |
| 642 const int kStartBandwidthBps = 300000; |
| 643 const int kMaxBandwidthBps = 2000000; |
| 644 |
| 645 webrtc::Call::Config call_config(event_log_); |
| 646 call_config.audio_state = channel_manager_->media_engine()->GetAudioState(); |
| 647 call_config.bitrate_config.min_bitrate_bps = kMinBandwidthBps; |
| 648 call_config.bitrate_config.start_bitrate_bps = kStartBandwidthBps; |
| 649 call_config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps; |
| 650 |
| 651 call_.reset(webrtc::Call::Create(call_config)); |
| 652 } |
| 653 |
626 void WebRtcSession::Close() { | 654 void WebRtcSession::Close() { |
627 SetState(STATE_CLOSED); | 655 SetState(STATE_CLOSED); |
628 RemoveUnusedChannels(nullptr); | 656 RemoveUnusedChannels(nullptr); |
629 RTC_DCHECK(!voice_channel_); | 657 RTC_DCHECK(!voice_channel_); |
630 RTC_DCHECK(!video_channel_); | 658 RTC_DCHECK(!video_channel_); |
631 RTC_DCHECK(!rtp_data_channel_); | 659 RTC_DCHECK(!rtp_data_channel_); |
632 RTC_DCHECK(!sctp_transport_); | 660 RTC_DCHECK(!sctp_transport_); |
633 media_controller_->Close(); | 661 |
| 662 worker_thread_->Invoke<void>(RTC_FROM_HERE, |
| 663 rtc::Bind(&WebRtcSession::Close_w, this)); |
| 664 } |
| 665 |
| 666 void WebRtcSession::Close_w() { |
| 667 RTC_DCHECK(worker_thread_->IsCurrent()); |
| 668 call_.reset(); |
634 } | 669 } |
635 | 670 |
636 cricket::BaseChannel* WebRtcSession::GetChannel( | 671 cricket::BaseChannel* WebRtcSession::GetChannel( |
637 const std::string& content_name) { | 672 const std::string& content_name) { |
638 if (voice_channel() && voice_channel()->content_name() == content_name) { | 673 if (voice_channel() && voice_channel()->content_name() == content_name) { |
639 return voice_channel(); | 674 return voice_channel(); |
640 } | 675 } |
641 if (video_channel() && video_channel()->content_name() == content_name) { | 676 if (video_channel() && video_channel()->content_name() == content_name) { |
642 return video_channel(); | 677 return video_channel(); |
643 } | 678 } |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1750 cricket::DtlsTransportInternal* rtp_dtls_transport = | 1785 cricket::DtlsTransportInternal* rtp_dtls_transport = |
1751 transport_controller_->CreateDtlsTransport( | 1786 transport_controller_->CreateDtlsTransport( |
1752 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 1787 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
1753 cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr; | 1788 cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr; |
1754 if (!require_rtcp_mux) { | 1789 if (!require_rtcp_mux) { |
1755 rtcp_dtls_transport = transport_controller_->CreateDtlsTransport( | 1790 rtcp_dtls_transport = transport_controller_->CreateDtlsTransport( |
1756 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 1791 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
1757 } | 1792 } |
1758 | 1793 |
1759 voice_channel_.reset(channel_manager_->CreateVoiceChannel( | 1794 voice_channel_.reset(channel_manager_->CreateVoiceChannel( |
1760 media_controller_, rtp_dtls_transport, rtcp_dtls_transport, | 1795 call(), media_config_, rtp_dtls_transport, rtcp_dtls_transport, |
1761 transport_controller_->signaling_thread(), content->name, SrtpRequired(), | 1796 transport_controller_->signaling_thread(), content->name, SrtpRequired(), |
1762 audio_options_)); | 1797 audio_options_)); |
1763 if (!voice_channel_) { | 1798 if (!voice_channel_) { |
1764 transport_controller_->DestroyDtlsTransport( | 1799 transport_controller_->DestroyDtlsTransport( |
1765 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 1800 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
1766 if (rtcp_dtls_transport) { | 1801 if (rtcp_dtls_transport) { |
1767 transport_controller_->DestroyDtlsTransport( | 1802 transport_controller_->DestroyDtlsTransport( |
1768 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 1803 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
1769 } | 1804 } |
1770 return false; | 1805 return false; |
(...skipping 21 matching lines...) Expand all Loading... |
1792 cricket::DtlsTransportInternal* rtp_dtls_transport = | 1827 cricket::DtlsTransportInternal* rtp_dtls_transport = |
1793 transport_controller_->CreateDtlsTransport( | 1828 transport_controller_->CreateDtlsTransport( |
1794 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 1829 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
1795 cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr; | 1830 cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr; |
1796 if (!require_rtcp_mux) { | 1831 if (!require_rtcp_mux) { |
1797 rtcp_dtls_transport = transport_controller_->CreateDtlsTransport( | 1832 rtcp_dtls_transport = transport_controller_->CreateDtlsTransport( |
1798 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 1833 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
1799 } | 1834 } |
1800 | 1835 |
1801 video_channel_.reset(channel_manager_->CreateVideoChannel( | 1836 video_channel_.reset(channel_manager_->CreateVideoChannel( |
1802 media_controller_, rtp_dtls_transport, rtcp_dtls_transport, | 1837 call(), media_config_, rtp_dtls_transport, rtcp_dtls_transport, |
1803 transport_controller_->signaling_thread(), content->name, SrtpRequired(), | 1838 transport_controller_->signaling_thread(), content->name, SrtpRequired(), |
1804 video_options_)); | 1839 video_options_)); |
1805 | 1840 |
1806 if (!video_channel_) { | 1841 if (!video_channel_) { |
1807 transport_controller_->DestroyDtlsTransport( | 1842 transport_controller_->DestroyDtlsTransport( |
1808 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 1843 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
1809 if (rtcp_dtls_transport) { | 1844 if (rtcp_dtls_transport) { |
1810 transport_controller_->DestroyDtlsTransport( | 1845 transport_controller_->DestroyDtlsTransport( |
1811 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 1846 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
1812 } | 1847 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1857 cricket::DtlsTransportInternal* rtp_dtls_transport = | 1892 cricket::DtlsTransportInternal* rtp_dtls_transport = |
1858 transport_controller_->CreateDtlsTransport( | 1893 transport_controller_->CreateDtlsTransport( |
1859 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 1894 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
1860 cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr; | 1895 cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr; |
1861 if (!require_rtcp_mux) { | 1896 if (!require_rtcp_mux) { |
1862 rtcp_dtls_transport = transport_controller_->CreateDtlsTransport( | 1897 rtcp_dtls_transport = transport_controller_->CreateDtlsTransport( |
1863 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 1898 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
1864 } | 1899 } |
1865 | 1900 |
1866 rtp_data_channel_.reset(channel_manager_->CreateRtpDataChannel( | 1901 rtp_data_channel_.reset(channel_manager_->CreateRtpDataChannel( |
1867 media_controller_, rtp_dtls_transport, rtcp_dtls_transport, | 1902 media_config_, rtp_dtls_transport, rtcp_dtls_transport, |
1868 transport_controller_->signaling_thread(), content->name, | 1903 transport_controller_->signaling_thread(), content->name, |
1869 SrtpRequired())); | 1904 SrtpRequired())); |
1870 | 1905 |
1871 if (!rtp_data_channel_) { | 1906 if (!rtp_data_channel_) { |
1872 transport_controller_->DestroyDtlsTransport( | 1907 transport_controller_->DestroyDtlsTransport( |
1873 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 1908 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
1874 if (rtcp_dtls_transport) { | 1909 if (rtcp_dtls_transport) { |
1875 transport_controller_->DestroyDtlsTransport( | 1910 transport_controller_->DestroyDtlsTransport( |
1876 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 1911 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
1877 } | 1912 } |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2306 srtp_crypto_suite); | 2341 srtp_crypto_suite); |
2307 } | 2342 } |
2308 if (ssl_cipher_suite != rtc::TLS_NULL_WITH_NULL_NULL) { | 2343 if (ssl_cipher_suite != rtc::TLS_NULL_WITH_NULL_NULL) { |
2309 metrics_observer_->IncrementSparseEnumCounter(ssl_counter_type, | 2344 metrics_observer_->IncrementSparseEnumCounter(ssl_counter_type, |
2310 ssl_cipher_suite); | 2345 ssl_cipher_suite); |
2311 } | 2346 } |
2312 } | 2347 } |
2313 | 2348 |
2314 void WebRtcSession::OnSentPacket_w(const rtc::SentPacket& sent_packet) { | 2349 void WebRtcSession::OnSentPacket_w(const rtc::SentPacket& sent_packet) { |
2315 RTC_DCHECK(worker_thread()->IsCurrent()); | 2350 RTC_DCHECK(worker_thread()->IsCurrent()); |
2316 media_controller_->call_w()->OnSentPacket(sent_packet); | 2351 call()->OnSentPacket(sent_packet); |
2317 } | 2352 } |
2318 | 2353 |
2319 const std::string WebRtcSession::GetTransportName( | 2354 const std::string WebRtcSession::GetTransportName( |
2320 const std::string& content_name) { | 2355 const std::string& content_name) { |
2321 cricket::BaseChannel* channel = GetChannel(content_name); | 2356 cricket::BaseChannel* channel = GetChannel(content_name); |
2322 if (!channel) { | 2357 if (!channel) { |
2323 #ifdef HAVE_QUIC | 2358 #ifdef HAVE_QUIC |
2324 if (data_channel_type_ == cricket::DCT_QUIC && quic_data_transport_ && | 2359 if (data_channel_type_ == cricket::DCT_QUIC && quic_data_transport_ && |
2325 content_name == quic_data_transport_->transport_name()) { | 2360 content_name == quic_data_transport_->transport_name()) { |
2326 return quic_data_transport_->transport_name(); | 2361 return quic_data_transport_->transport_name(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2384 (rtp_data_channel_->rtcp_dtls_transport() != nullptr); | 2419 (rtp_data_channel_->rtcp_dtls_transport() != nullptr); |
2385 channel_manager_->DestroyRtpDataChannel(rtp_data_channel_.release()); | 2420 channel_manager_->DestroyRtpDataChannel(rtp_data_channel_.release()); |
2386 transport_controller_->DestroyDtlsTransport( | 2421 transport_controller_->DestroyDtlsTransport( |
2387 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 2422 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
2388 if (need_to_delete_rtcp) { | 2423 if (need_to_delete_rtcp) { |
2389 transport_controller_->DestroyDtlsTransport( | 2424 transport_controller_->DestroyDtlsTransport( |
2390 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 2425 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
2391 } | 2426 } |
2392 } | 2427 } |
2393 } // namespace webrtc | 2428 } // namespace webrtc |
OLD | NEW |