Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / app / webrtc / webrtcsession.cc
index 1f14ff7..13e2128 100644 (file)
@@ -224,30 +224,28 @@ static bool GetTrackIdBySsrc(const SessionDescription* session_description,
   cricket::StreamParams stream_out;
   const cricket::ContentInfo* audio_info =
       cricket::GetFirstAudioContent(session_description);
-  if (!audio_info) {
-    return false;
-  }
-  const cricket::MediaContentDescription* audio_content =
-      static_cast<const cricket::MediaContentDescription*>(
-          audio_info->description);
-
-  if (cricket::GetStreamBySsrc(audio_content->streams(), ssrc, &stream_out)) {
-    *track_id = stream_out.id;
-    return true;
+  if (audio_info) {
+    const cricket::MediaContentDescription* audio_content =
+        static_cast<const cricket::MediaContentDescription*>(
+            audio_info->description);
+
+    if (cricket::GetStreamBySsrc(audio_content->streams(), ssrc, &stream_out)) {
+      *track_id = stream_out.id;
+      return true;
+    }
   }
 
   const cricket::ContentInfo* video_info =
       cricket::GetFirstVideoContent(session_description);
-  if (!video_info) {
-    return false;
-  }
-  const cricket::MediaContentDescription* video_content =
-      static_cast<const cricket::MediaContentDescription*>(
-          video_info->description);
-
-  if (cricket::GetStreamBySsrc(video_content->streams(), ssrc, &stream_out)) {
-    *track_id = stream_out.id;
-    return true;
+  if (video_info) {
+    const cricket::MediaContentDescription* video_content =
+        static_cast<const cricket::MediaContentDescription*>(
+            video_info->description);
+
+    if (cricket::GetStreamBySsrc(video_content->streams(), ssrc, &stream_out)) {
+      *track_id = stream_out.id;
+      return true;
+    }
   }
   return false;
 }
@@ -389,6 +387,22 @@ static void SetOptionFromOptionalConstraint(
   }
 }
 
+uint32 ConvertIceTransportTypeToCandidateFilter(
+    PeerConnectionInterface::IceTransportsType type) {
+  switch (type) {
+    case PeerConnectionInterface::kNone:
+        return cricket::CF_NONE;
+    case PeerConnectionInterface::kRelay:
+        return cricket::CF_RELAY;
+    case PeerConnectionInterface::kNoHost:
+        return (cricket::CF_ALL & ~cricket::CF_HOST);
+    case PeerConnectionInterface::kAll:
+        return cricket::CF_ALL;
+    default: ASSERT(false);
+  }
+  return cricket::CF_NONE;
+}
+
 // Help class used to remember if a a remote peer has requested ice restart by
 // by sending a description with new ice ufrag and password.
 class IceRestartAnswerLatch {
@@ -471,14 +485,16 @@ WebRtcSession::WebRtcSession(
 }
 
 WebRtcSession::~WebRtcSession() {
-  if (voice_channel_.get()) {
-    SignalVoiceChannelDestroyed();
-    channel_manager_->DestroyVoiceChannel(voice_channel_.release());
-  }
+  // Destroy video_channel_ first since it may have a pointer to the
+  // voice_channel_.
   if (video_channel_.get()) {
     SignalVideoChannelDestroyed();
     channel_manager_->DestroyVideoChannel(video_channel_.release());
   }
+  if (voice_channel_.get()) {
+    SignalVoiceChannelDestroyed();
+    channel_manager_->DestroyVoiceChannel(voice_channel_.release());
+  }
   if (data_channel_.get()) {
     SignalDataChannelDestroyed();
     channel_manager_->DestroyDataChannel(data_channel_.release());
@@ -579,18 +595,6 @@ bool WebRtcSession::Initialize(
       MediaConstraintsInterface::kPayloadPadding,
       &video_options_.use_payload_padding);
 
-  // Find improved wifi bwe constraint.
-  if (FindConstraint(
-        constraints,
-        MediaConstraintsInterface::kImprovedWifiBwe,
-        &value,
-        NULL)) {
-    video_options_.use_improved_wifi_bandwidth_estimator.Set(value);
-  } else {
-    // Enable by default if the constraint is not set.
-    video_options_.use_improved_wifi_bandwidth_estimator.Set(true);
-  }
-
   SetOptionFromOptionalConstraint(constraints,
       MediaConstraintsInterface::kNumUnsignalledRecvStreams,
       &video_options_.unsignalled_recv_stream_limit);
@@ -623,8 +627,8 @@ bool WebRtcSession::Initialize(
   }
 
   SetOptionFromOptionalConstraint(constraints,
-      MediaConstraintsInterface::kOpusFec,
-      &audio_options_.opus_fec);
+      MediaConstraintsInterface::kCombinedAudioVideoBwe,
+      &audio_options_.combined_audio_video_bwe);
 
   const cricket::VideoCodec default_codec(
       JsepSessionDescription::kDefaultVideoCodecId,
@@ -652,7 +656,8 @@ bool WebRtcSession::Initialize(
   if (options.disable_encryption) {
     webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED);
   }
-
+  port_allocator()->set_candidate_filter(
+      ConvertIceTransportTypeToCandidateFilter(ice_transport));
   return true;
 }
 
@@ -758,6 +763,7 @@ bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc,
   if (!UpdateSessionState(action, cricket::CS_LOCAL, err_desc)) {
     return false;
   }
+
   // Kick starting the ice candidates allocation.
   StartCandidatesAllocation();
 
@@ -919,8 +925,10 @@ bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) {
   return UseCandidate(candidate);
 }
 
-bool WebRtcSession::UpdateIce(PeerConnectionInterface::IceTransportsType type) {
-  return false;
+bool WebRtcSession::SetIceTransports(
+    PeerConnectionInterface::IceTransportsType type) {
+  return port_allocator()->set_candidate_filter(
+        ConvertIceTransportTypeToCandidateFilter(type));
 }
 
 bool WebRtcSession::GetLocalTrackIdBySsrc(uint32 ssrc, std::string* track_id) {
@@ -1441,16 +1449,8 @@ bool WebRtcSession::UseCandidate(
 
 void WebRtcSession::RemoveUnusedChannelsAndTransports(
     const SessionDescription* desc) {
-  const cricket::ContentInfo* voice_info =
-      cricket::GetFirstAudioContent(desc);
-  if ((!voice_info || voice_info->rejected) && voice_channel_) {
-    mediastream_signaling_->OnAudioChannelClose();
-    SignalVoiceChannelDestroyed();
-    const std::string content_name = voice_channel_->content_name();
-    channel_manager_->DestroyVoiceChannel(voice_channel_.release());
-    DestroyTransportProxy(content_name);
-  }
-
+  // Destroy video_channel_ first since it may have a pointer to the
+  // voice_channel_.
   const cricket::ContentInfo* video_info =
       cricket::GetFirstVideoContent(desc);
   if ((!video_info || video_info->rejected) && video_channel_) {
@@ -1461,6 +1461,16 @@ void WebRtcSession::RemoveUnusedChannelsAndTransports(
     DestroyTransportProxy(content_name);
   }
 
+  const cricket::ContentInfo* voice_info =
+      cricket::GetFirstAudioContent(desc);
+  if ((!voice_info || voice_info->rejected) && voice_channel_) {
+    mediastream_signaling_->OnAudioChannelClose();
+    SignalVoiceChannelDestroyed();
+    const std::string content_name = voice_channel_->content_name();
+    channel_manager_->DestroyVoiceChannel(voice_channel_.release());
+    DestroyTransportProxy(content_name);
+  }
+
   const cricket::ContentInfo* data_info =
       cricket::GetFirstDataContent(desc);
   if ((!data_info || data_info->rejected) && data_channel_) {