| 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 |
| 11 #include "webrtc/api/webrtcsession.h" | 11 #include "webrtc/api/webrtcsession.h" |
| 12 | 12 |
| 13 #include <limits.h> | 13 #include <limits.h> |
| 14 | 14 |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 #include <set> | 16 #include <set> |
| 17 #include <utility> | 17 #include <utility> |
| 18 #include <vector> | 18 #include <vector> |
| 19 | 19 |
| 20 #include "webrtc/api/jsepicecandidate.h" | 20 #include "webrtc/api/jsepicecandidate.h" |
| 21 #include "webrtc/api/jsepsessiondescription.h" | 21 #include "webrtc/api/jsepsessiondescription.h" |
| 22 #include "webrtc/api/mediaconstraintsinterface.h" | |
| 23 #include "webrtc/api/peerconnectioninterface.h" | 22 #include "webrtc/api/peerconnectioninterface.h" |
| 24 #include "webrtc/api/sctputils.h" | 23 #include "webrtc/api/sctputils.h" |
| 25 #include "webrtc/api/webrtcsessiondescriptionfactory.h" | 24 #include "webrtc/api/webrtcsessiondescriptionfactory.h" |
| 26 #include "webrtc/audio/audio_sink.h" | 25 #include "webrtc/audio/audio_sink.h" |
| 27 #include "webrtc/base/basictypes.h" | 26 #include "webrtc/base/basictypes.h" |
| 28 #include "webrtc/base/checks.h" | 27 #include "webrtc/base/checks.h" |
| 29 #include "webrtc/base/helpers.h" | 28 #include "webrtc/base/helpers.h" |
| 30 #include "webrtc/base/logging.h" | 29 #include "webrtc/base/logging.h" |
| 31 #include "webrtc/base/stringencode.h" | 30 #include "webrtc/base/stringencode.h" |
| 32 #include "webrtc/base/stringutils.h" | 31 #include "webrtc/base/stringutils.h" |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 const std::string& desc) { | 414 const std::string& desc) { |
| 416 std::ostringstream ret; | 415 std::ostringstream ret; |
| 417 ret << error << " " << desc; | 416 ret << error << " " << desc; |
| 418 return ret.str(); | 417 return ret.str(); |
| 419 } | 418 } |
| 420 | 419 |
| 421 static std::string MakeTdErrorString(const std::string& desc) { | 420 static std::string MakeTdErrorString(const std::string& desc) { |
| 422 return MakeErrorString(kPushDownTDFailed, desc); | 421 return MakeErrorString(kPushDownTDFailed, desc); |
| 423 } | 422 } |
| 424 | 423 |
| 425 // Set |option| to the highest-priority value of |key| in the optional | |
| 426 // constraints if the key is found and has a valid value. | |
| 427 template <typename T> | |
| 428 static void SetOptionFromOptionalConstraint( | |
| 429 const MediaConstraintsInterface* constraints, | |
| 430 const std::string& key, | |
| 431 rtc::Optional<T>* option) { | |
| 432 if (!constraints) { | |
| 433 return; | |
| 434 } | |
| 435 std::string string_value; | |
| 436 T value; | |
| 437 if (constraints->GetOptional().FindFirst(key, &string_value)) { | |
| 438 if (rtc::FromString(string_value, &value)) { | |
| 439 *option = rtc::Optional<T>(value); | |
| 440 } | |
| 441 } | |
| 442 } | |
| 443 | |
| 444 uint32_t ConvertIceTransportTypeToCandidateFilter( | 424 uint32_t ConvertIceTransportTypeToCandidateFilter( |
| 445 PeerConnectionInterface::IceTransportsType type) { | 425 PeerConnectionInterface::IceTransportsType type) { |
| 446 switch (type) { | 426 switch (type) { |
| 447 case PeerConnectionInterface::kNone: | 427 case PeerConnectionInterface::kNone: |
| 448 return cricket::CF_NONE; | 428 return cricket::CF_NONE; |
| 449 case PeerConnectionInterface::kRelay: | 429 case PeerConnectionInterface::kRelay: |
| 450 return cricket::CF_RELAY; | 430 return cricket::CF_RELAY; |
| 451 case PeerConnectionInterface::kNoHost: | 431 case PeerConnectionInterface::kNoHost: |
| 452 return (cricket::CF_ALL & ~cricket::CF_HOST); | 432 return (cricket::CF_ALL & ~cricket::CF_HOST); |
| 453 case PeerConnectionInterface::kAll: | 433 case PeerConnectionInterface::kAll: |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 SignalDataChannelDestroyed(); | 552 SignalDataChannelDestroyed(); |
| 573 channel_manager_->DestroyDataChannel(data_channel_.release()); | 553 channel_manager_->DestroyDataChannel(data_channel_.release()); |
| 574 } | 554 } |
| 575 SignalDestroyed(); | 555 SignalDestroyed(); |
| 576 | 556 |
| 577 LOG(LS_INFO) << "Session: " << id() << " is destroyed."; | 557 LOG(LS_INFO) << "Session: " << id() << " is destroyed."; |
| 578 } | 558 } |
| 579 | 559 |
| 580 bool WebRtcSession::Initialize( | 560 bool WebRtcSession::Initialize( |
| 581 const PeerConnectionFactoryInterface::Options& options, | 561 const PeerConnectionFactoryInterface::Options& options, |
| 582 const MediaConstraintsInterface* constraints, | |
| 583 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 562 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 584 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { | 563 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
| 585 bundle_policy_ = rtc_configuration.bundle_policy; | 564 bundle_policy_ = rtc_configuration.bundle_policy; |
| 586 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; | 565 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; |
| 587 transport_controller_->SetSslMaxProtocolVersion(options.ssl_max_version); | 566 transport_controller_->SetSslMaxProtocolVersion(options.ssl_max_version); |
| 588 | 567 |
| 589 // Obtain a certificate from RTCConfiguration if any were provided (optional). | 568 // Obtain a certificate from RTCConfiguration if any were provided (optional). |
| 590 rtc::scoped_refptr<rtc::RTCCertificate> certificate; | 569 rtc::scoped_refptr<rtc::RTCCertificate> certificate; |
| 591 if (!rtc_configuration.certificates.empty()) { | 570 if (!rtc_configuration.certificates.empty()) { |
| 592 // TODO(hbos,torbjorng): Decide on certificate-selection strategy instead of | 571 // TODO(hbos,torbjorng): Decide on certificate-selection strategy instead of |
| 593 // just picking the first one. The decision should be made based on the DTLS | 572 // just picking the first one. The decision should be made based on the DTLS |
| 594 // handshake. The DTLS negotiations need to know about all certificates. | 573 // handshake. The DTLS negotiations need to know about all certificates. |
| 595 certificate = rtc_configuration.certificates[0]; | 574 certificate = rtc_configuration.certificates[0]; |
| 596 } | 575 } |
| 597 | 576 |
| 598 SetIceConfig(ParseIceConfig(rtc_configuration)); | 577 SetIceConfig(ParseIceConfig(rtc_configuration)); |
| 599 | 578 |
| 600 // TODO(perkj): Take |constraints| into consideration. Return false if not all | |
| 601 // mandatory constraints can be fulfilled. Note that |constraints| | |
| 602 // can be null. | |
| 603 bool value; | |
| 604 | |
| 605 if (options.disable_encryption) { | 579 if (options.disable_encryption) { |
| 606 dtls_enabled_ = false; | 580 dtls_enabled_ = false; |
| 607 } else { | 581 } else { |
| 608 // Enable DTLS by default if we have an identity store or a certificate. | 582 // Enable DTLS by default if we have an identity store or a certificate. |
| 609 dtls_enabled_ = (dtls_identity_store || certificate); | 583 dtls_enabled_ = (dtls_identity_store || certificate); |
| 610 // |constraints| can override the default |dtls_enabled_| value. | 584 // |rtc_configuration| can override the default |dtls_enabled_| value. |
| 611 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableDtlsSrtp, | 585 if (rtc_configuration.override_enable_dtls_srtp) { |
| 612 &value, nullptr)) { | 586 dtls_enabled_ = rtc_configuration.enable_dtls_srtp; |
| 613 dtls_enabled_ = value; | |
| 614 } | 587 } |
| 615 } | 588 } |
| 616 | 589 |
| 617 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. | 590 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. |
| 618 // It takes precendence over the disable_sctp_data_channels | 591 // It takes precendence over the disable_sctp_data_channels |
| 619 // PeerConnectionFactoryInterface::Options. | 592 // PeerConnectionFactoryInterface::Options. |
| 620 if (FindConstraint( | 593 if (rtc_configuration.enable_rtp_data_channel) { |
| 621 constraints, MediaConstraintsInterface::kEnableRtpDataChannels, | |
| 622 &value, NULL) && value) { | |
| 623 LOG(LS_INFO) << "Allowing RTP data engine."; | |
| 624 data_channel_type_ = cricket::DCT_RTP; | 594 data_channel_type_ = cricket::DCT_RTP; |
| 625 } else { | 595 } else { |
| 626 // DTLS has to be enabled to use SCTP. | 596 // DTLS has to be enabled to use SCTP. |
| 627 if (!options.disable_sctp_data_channels && dtls_enabled_) { | 597 if (!options.disable_sctp_data_channels && dtls_enabled_) { |
| 628 LOG(LS_INFO) << "Allowing SCTP data engine."; | |
| 629 data_channel_type_ = cricket::DCT_SCTP; | 598 data_channel_type_ = cricket::DCT_SCTP; |
| 630 } | 599 } |
| 631 } | 600 } |
| 632 | 601 |
| 633 // Find Suspend Below Min Bitrate constraint. | 602 // Find Suspend Below Min Bitrate constraint. |
| 634 if (FindConstraint( | 603 if (rtc_configuration.override_suspend_below_min_bitrate) { |
| 635 constraints, | 604 video_options_.suspend_below_min_bitrate = |
| 636 MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, | 605 rtc::Optional<bool>(rtc_configuration.suspend_below_min_bitrate); |
| 637 &value, | |
| 638 NULL)) { | |
| 639 video_options_.suspend_below_min_bitrate = rtc::Optional<bool>(value); | |
| 640 } | 606 } |
| 641 | 607 |
| 642 SetOptionFromOptionalConstraint(constraints, | 608 if (rtc_configuration.override_screencast_min_bitrate) { |
| 643 MediaConstraintsInterface::kScreencastMinBitrate, | 609 video_options_.screencast_min_bitrate_kbps = |
| 644 &video_options_.screencast_min_bitrate_kbps); | 610 rtc::Optional<int>(rtc_configuration.screencast_min_bitrate); |
| 645 | 611 } |
| 646 SetOptionFromOptionalConstraint(constraints, | 612 if (rtc_configuration.override_combined_audio_video_bwe) { |
| 647 MediaConstraintsInterface::kCombinedAudioVideoBwe, | 613 audio_options_.combined_audio_video_bwe = |
| 648 &audio_options_.combined_audio_video_bwe); | 614 rtc::Optional<bool>(rtc_configuration.combined_audio_video_bwe); |
| 615 } |
| 649 | 616 |
| 650 audio_options_.audio_jitter_buffer_max_packets = | 617 audio_options_.audio_jitter_buffer_max_packets = |
| 651 rtc::Optional<int>(rtc_configuration.audio_jitter_buffer_max_packets); | 618 rtc::Optional<int>(rtc_configuration.audio_jitter_buffer_max_packets); |
| 652 | 619 |
| 653 audio_options_.audio_jitter_buffer_fast_accelerate = rtc::Optional<bool>( | 620 audio_options_.audio_jitter_buffer_fast_accelerate = rtc::Optional<bool>( |
| 654 rtc_configuration.audio_jitter_buffer_fast_accelerate); | 621 rtc_configuration.audio_jitter_buffer_fast_accelerate); |
| 655 | 622 |
| 656 if (!dtls_enabled_) { | 623 if (!dtls_enabled_) { |
| 657 // Construct with DTLS disabled. | 624 // Construct with DTLS disabled. |
| 658 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( | 625 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 | 685 |
| 719 void WebRtcSession::CreateOffer( | 686 void WebRtcSession::CreateOffer( |
| 720 CreateSessionDescriptionObserver* observer, | 687 CreateSessionDescriptionObserver* observer, |
| 721 const PeerConnectionInterface::RTCOfferAnswerOptions& options, | 688 const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| 722 const cricket::MediaSessionOptions& session_options) { | 689 const cricket::MediaSessionOptions& session_options) { |
| 723 webrtc_session_desc_factory_->CreateOffer(observer, options, session_options); | 690 webrtc_session_desc_factory_->CreateOffer(observer, options, session_options); |
| 724 } | 691 } |
| 725 | 692 |
| 726 void WebRtcSession::CreateAnswer( | 693 void WebRtcSession::CreateAnswer( |
| 727 CreateSessionDescriptionObserver* observer, | 694 CreateSessionDescriptionObserver* observer, |
| 728 const MediaConstraintsInterface* constraints, | |
| 729 const cricket::MediaSessionOptions& session_options) { | 695 const cricket::MediaSessionOptions& session_options) { |
| 730 webrtc_session_desc_factory_->CreateAnswer(observer, constraints, | 696 webrtc_session_desc_factory_->CreateAnswer(observer, session_options); |
| 731 session_options); | |
| 732 } | 697 } |
| 733 | 698 |
| 734 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, | 699 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, |
| 735 std::string* err_desc) { | 700 std::string* err_desc) { |
| 736 ASSERT(signaling_thread()->IsCurrent()); | 701 ASSERT(signaling_thread()->IsCurrent()); |
| 737 | 702 |
| 738 // Takes the ownership of |desc| regardless of the result. | 703 // Takes the ownership of |desc| regardless of the result. |
| 739 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); | 704 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); |
| 740 | 705 |
| 741 // Validate SDP. | 706 // Validate SDP. |
| (...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2143 } | 2108 } |
| 2144 } | 2109 } |
| 2145 | 2110 |
| 2146 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, | 2111 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, |
| 2147 const rtc::SentPacket& sent_packet) { | 2112 const rtc::SentPacket& sent_packet) { |
| 2148 RTC_DCHECK(worker_thread()->IsCurrent()); | 2113 RTC_DCHECK(worker_thread()->IsCurrent()); |
| 2149 media_controller_->call_w()->OnSentPacket(sent_packet); | 2114 media_controller_->call_w()->OnSentPacket(sent_packet); |
| 2150 } | 2115 } |
| 2151 | 2116 |
| 2152 } // namespace webrtc | 2117 } // namespace webrtc |
| OLD | NEW |