| 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_sink.h" |    25 #include "webrtc/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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   539     SignalDataChannelDestroyed(); |   519     SignalDataChannelDestroyed(); | 
|   540     channel_manager_->DestroyDataChannel(data_channel_.release()); |   520     channel_manager_->DestroyDataChannel(data_channel_.release()); | 
|   541   } |   521   } | 
|   542   SignalDestroyed(); |   522   SignalDestroyed(); | 
|   543  |   523  | 
|   544   LOG(LS_INFO) << "Session: " << id() << " is destroyed."; |   524   LOG(LS_INFO) << "Session: " << id() << " is destroyed."; | 
|   545 } |   525 } | 
|   546  |   526  | 
|   547 bool WebRtcSession::Initialize( |   527 bool WebRtcSession::Initialize( | 
|   548     const PeerConnectionFactoryInterface::Options& options, |   528     const PeerConnectionFactoryInterface::Options& options, | 
|   549     const MediaConstraintsInterface* constraints, |  | 
|   550     rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |   529     rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 
|   551     const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |   530     const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { | 
|   552   bundle_policy_ = rtc_configuration.bundle_policy; |   531   bundle_policy_ = rtc_configuration.bundle_policy; | 
|   553   rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; |   532   rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; | 
|   554   transport_controller_->SetSslMaxProtocolVersion(options.ssl_max_version); |   533   transport_controller_->SetSslMaxProtocolVersion(options.ssl_max_version); | 
|   555  |   534  | 
|   556   // Obtain a certificate from RTCConfiguration if any were provided (optional). |   535   // Obtain a certificate from RTCConfiguration if any were provided (optional). | 
|   557   rtc::scoped_refptr<rtc::RTCCertificate> certificate; |   536   rtc::scoped_refptr<rtc::RTCCertificate> certificate; | 
|   558   if (!rtc_configuration.certificates.empty()) { |   537   if (!rtc_configuration.certificates.empty()) { | 
|   559     // TODO(hbos,torbjorng): Decide on certificate-selection strategy instead of |   538     // TODO(hbos,torbjorng): Decide on certificate-selection strategy instead of | 
|   560     // just picking the first one. The decision should be made based on the DTLS |   539     // just picking the first one. The decision should be made based on the DTLS | 
|   561     // handshake. The DTLS negotiations need to know about all certificates. |   540     // handshake. The DTLS negotiations need to know about all certificates. | 
|   562     certificate = rtc_configuration.certificates[0]; |   541     certificate = rtc_configuration.certificates[0]; | 
|   563   } |   542   } | 
|   564  |   543  | 
|   565   SetIceConfig(ParseIceConfig(rtc_configuration)); |   544   SetIceConfig(ParseIceConfig(rtc_configuration)); | 
|   566  |   545  | 
|   567   // TODO(perkj): Take |constraints| into consideration. Return false if not all |  | 
|   568   // mandatory constraints can be fulfilled. Note that |constraints| |  | 
|   569   // can be null. |  | 
|   570   bool value; |  | 
|   571  |  | 
|   572   if (options.disable_encryption) { |   546   if (options.disable_encryption) { | 
|   573     dtls_enabled_ = false; |   547     dtls_enabled_ = false; | 
|   574   } else { |   548   } else { | 
|   575     // Enable DTLS by default if we have an identity store or a certificate. |   549     // Enable DTLS by default if we have an identity store or a certificate. | 
|   576     dtls_enabled_ = (dtls_identity_store || certificate); |   550     dtls_enabled_ = (dtls_identity_store || certificate); | 
|   577     // |constraints| can override the default |dtls_enabled_| value. |   551     // |rtc_configuration| can override the default |dtls_enabled_| value. | 
|   578     if (FindConstraint(constraints, MediaConstraintsInterface::kEnableDtlsSrtp, |   552     if (rtc_configuration.enable_dtls_srtp) { | 
|   579                        &value, nullptr)) { |   553       dtls_enabled_ = *(rtc_configuration.enable_dtls_srtp); | 
|   580       dtls_enabled_ = value; |  | 
|   581     } |   554     } | 
|   582   } |   555   } | 
|   583  |   556  | 
|   584   // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. |   557   // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. | 
|   585   // It takes precendence over the disable_sctp_data_channels |   558   // It takes precendence over the disable_sctp_data_channels | 
|   586   // PeerConnectionFactoryInterface::Options. |   559   // PeerConnectionFactoryInterface::Options. | 
|   587   if (FindConstraint( |   560   if (rtc_configuration.enable_rtp_data_channel) { | 
|   588       constraints, MediaConstraintsInterface::kEnableRtpDataChannels, |  | 
|   589       &value, NULL) && value) { |  | 
|   590     LOG(LS_INFO) << "Allowing RTP data engine."; |  | 
|   591     data_channel_type_ = cricket::DCT_RTP; |   561     data_channel_type_ = cricket::DCT_RTP; | 
|   592   } else { |   562   } else { | 
|   593     // DTLS has to be enabled to use SCTP. |   563     // DTLS has to be enabled to use SCTP. | 
|   594     if (!options.disable_sctp_data_channels && dtls_enabled_) { |   564     if (!options.disable_sctp_data_channels && dtls_enabled_) { | 
|   595       LOG(LS_INFO) << "Allowing SCTP data engine."; |  | 
|   596       data_channel_type_ = cricket::DCT_SCTP; |   565       data_channel_type_ = cricket::DCT_SCTP; | 
|   597     } |   566     } | 
|   598   } |   567   } | 
|   599  |   568  | 
|   600   // Find Suspend Below Min Bitrate constraint. |   569   video_options_.suspend_below_min_bitrate = | 
|   601   if (FindConstraint( |   570       rtc_configuration.suspend_below_min_bitrate; | 
|   602           constraints, |   571   video_options_.screencast_min_bitrate_kbps = | 
|   603           MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, |   572       rtc_configuration.screencast_min_bitrate; | 
|   604           &value, |   573   audio_options_.combined_audio_video_bwe = | 
|   605           NULL)) { |   574       rtc_configuration.combined_audio_video_bwe; | 
|   606     video_options_.suspend_below_min_bitrate = rtc::Optional<bool>(value); |  | 
|   607   } |  | 
|   608  |  | 
|   609   SetOptionFromOptionalConstraint(constraints, |  | 
|   610       MediaConstraintsInterface::kScreencastMinBitrate, |  | 
|   611       &video_options_.screencast_min_bitrate_kbps); |  | 
|   612  |  | 
|   613   SetOptionFromOptionalConstraint(constraints, |  | 
|   614       MediaConstraintsInterface::kCombinedAudioVideoBwe, |  | 
|   615       &audio_options_.combined_audio_video_bwe); |  | 
|   616  |   575  | 
|   617   audio_options_.audio_jitter_buffer_max_packets = |   576   audio_options_.audio_jitter_buffer_max_packets = | 
|   618       rtc::Optional<int>(rtc_configuration.audio_jitter_buffer_max_packets); |   577       rtc::Optional<int>(rtc_configuration.audio_jitter_buffer_max_packets); | 
|   619  |   578  | 
|   620   audio_options_.audio_jitter_buffer_fast_accelerate = rtc::Optional<bool>( |   579   audio_options_.audio_jitter_buffer_fast_accelerate = rtc::Optional<bool>( | 
|   621       rtc_configuration.audio_jitter_buffer_fast_accelerate); |   580       rtc_configuration.audio_jitter_buffer_fast_accelerate); | 
|   622  |   581  | 
|   623   if (!dtls_enabled_) { |   582   if (!dtls_enabled_) { | 
|   624     // Construct with DTLS disabled. |   583     // Construct with DTLS disabled. | 
|   625     webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |   584     webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( | 
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   699  |   658  | 
|   700 void WebRtcSession::CreateOffer( |   659 void WebRtcSession::CreateOffer( | 
|   701     CreateSessionDescriptionObserver* observer, |   660     CreateSessionDescriptionObserver* observer, | 
|   702     const PeerConnectionInterface::RTCOfferAnswerOptions& options, |   661     const PeerConnectionInterface::RTCOfferAnswerOptions& options, | 
|   703     const cricket::MediaSessionOptions& session_options) { |   662     const cricket::MediaSessionOptions& session_options) { | 
|   704   webrtc_session_desc_factory_->CreateOffer(observer, options, session_options); |   663   webrtc_session_desc_factory_->CreateOffer(observer, options, session_options); | 
|   705 } |   664 } | 
|   706  |   665  | 
|   707 void WebRtcSession::CreateAnswer( |   666 void WebRtcSession::CreateAnswer( | 
|   708     CreateSessionDescriptionObserver* observer, |   667     CreateSessionDescriptionObserver* observer, | 
|   709     const MediaConstraintsInterface* constraints, |  | 
|   710     const cricket::MediaSessionOptions& session_options) { |   668     const cricket::MediaSessionOptions& session_options) { | 
|   711   webrtc_session_desc_factory_->CreateAnswer(observer, constraints, |   669   webrtc_session_desc_factory_->CreateAnswer(observer, session_options); | 
|   712                                              session_options); |  | 
|   713 } |   670 } | 
|   714  |   671  | 
|   715 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, |   672 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, | 
|   716                                         std::string* err_desc) { |   673                                         std::string* err_desc) { | 
|   717   ASSERT(signaling_thread()->IsCurrent()); |   674   ASSERT(signaling_thread()->IsCurrent()); | 
|   718  |   675  | 
|   719   // Takes the ownership of |desc| regardless of the result. |   676   // Takes the ownership of |desc| regardless of the result. | 
|   720   rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); |   677   rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); | 
|   721  |   678  | 
|   722   // Validate SDP. |   679   // Validate SDP. | 
| (...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2119   } |  2076   } | 
|  2120 } |  2077 } | 
|  2121  |  2078  | 
|  2122 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, |  2079 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, | 
|  2123                                    const rtc::SentPacket& sent_packet) { |  2080                                    const rtc::SentPacket& sent_packet) { | 
|  2124   RTC_DCHECK(worker_thread()->IsCurrent()); |  2081   RTC_DCHECK(worker_thread()->IsCurrent()); | 
|  2125   media_controller_->call_w()->OnSentPacket(sent_packet); |  2082   media_controller_->call_w()->OnSentPacket(sent_packet); | 
|  2126 } |  2083 } | 
|  2127  |  2084  | 
|  2128 }  // namespace webrtc |  2085 }  // namespace webrtc | 
| OLD | NEW |