Update talk folder to revision=49713299.

TBR=mallinath@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/1848004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4380 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/talk/app/webrtc/jsepsessiondescription.cc b/talk/app/webrtc/jsepsessiondescription.cc
index bc65ca5..8ec1458 100644
--- a/talk/app/webrtc/jsepsessiondescription.cc
+++ b/talk/app/webrtc/jsepsessiondescription.cc
@@ -139,7 +139,7 @@
 
   candidate_collection_[mediasection_index].add(
        new JsepIceCandidate(candidate->sdp_mid(),
-                            mediasection_index,
+                            static_cast<int>(mediasection_index),
                             updated_candidate));
   return true;
 }
diff --git a/talk/app/webrtc/peerconnection_unittest.cc b/talk/app/webrtc/peerconnection_unittest.cc
index eed6936..250e60f 100644
--- a/talk/app/webrtc/peerconnection_unittest.cc
+++ b/talk/app/webrtc/peerconnection_unittest.cc
@@ -147,7 +147,8 @@
 
   void AddMediaStream(bool audio, bool video) {
     std::string label = kStreamLabelBase +
-        talk_base::ToString<int>(peer_connection_->local_streams()->count());
+        talk_base::ToString<int>(
+            static_cast<int>(peer_connection_->local_streams()->count()));
     talk_base::scoped_refptr<webrtc::MediaStreamInterface> stream =
         peer_connection_factory_->CreateLocalMediaStream(label);
 
@@ -306,11 +307,11 @@
           desc->GetTransportDescriptionByName(contents[index].name);
 
       std::map<int, IceUfragPwdPair>::const_iterator ufragpair_it =
-          ice_ufrag_pwd_.find(index);
+          ice_ufrag_pwd_.find(static_cast<int>(index));
       if (ufragpair_it == ice_ufrag_pwd_.end()) {
         ASSERT_FALSE(ExpectIceRestart());
-        ice_ufrag_pwd_[index] = IceUfragPwdPair(transport_desc->ice_ufrag,
-                                                transport_desc->ice_pwd);
+        ice_ufrag_pwd_[static_cast<int>(index)] =
+            IceUfragPwdPair(transport_desc->ice_ufrag, transport_desc->ice_pwd);
       } else if (ExpectIceRestart()) {
         const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second;
         EXPECT_NE(ufrag_pwd.first, transport_desc->ice_ufrag);
@@ -1007,13 +1008,13 @@
 
   ASSERT_LE(0, initializing_client()->rendered_height());
   double initiating_video_ratio =
-      static_cast<double> (initializing_client()->rendered_width()) /
+      static_cast<double>(initializing_client()->rendered_width()) /
       initializing_client()->rendered_height();
   EXPECT_LE(requested_ratio, initiating_video_ratio);
 
   ASSERT_LE(0, receiving_client()->rendered_height());
   double receiving_video_ratio =
-      static_cast<double> (receiving_client()->rendered_width()) /
+      static_cast<double>(receiving_client()->rendered_width()) /
       receiving_client()->rendered_height();
   EXPECT_LE(requested_ratio, receiving_video_ratio);
 }
diff --git a/talk/app/webrtc/peerconnectionfactory.cc b/talk/app/webrtc/peerconnectionfactory.cc
index 7ae5a3b..316b044 100644
--- a/talk/app/webrtc/peerconnectionfactory.cc
+++ b/talk/app/webrtc/peerconnectionfactory.cc
@@ -189,7 +189,7 @@
 void PeerConnectionFactory::OnMessage(talk_base::Message* msg) {
   switch (msg->message_id) {
     case MSG_INIT_FACTORY: {
-     InitMessageData* pdata = static_cast<InitMessageData*> (msg->pdata);
+     InitMessageData* pdata = static_cast<InitMessageData*>(msg->pdata);
      pdata->data() = Initialize_s();
      break;
     }
@@ -199,7 +199,7 @@
     }
     case MSG_CREATE_PEERCONNECTION: {
       CreatePeerConnectionParams* pdata =
-          static_cast<CreatePeerConnectionParams*> (msg->pdata);
+          static_cast<CreatePeerConnectionParams*>(msg->pdata);
       pdata->peerconnection = CreatePeerConnection_s(pdata->configuration,
                                                      pdata->constraints,
                                                      pdata->allocator_factory,
@@ -214,7 +214,7 @@
     }
     case MSG_CREATE_VIDEOSOURCE: {
       CreateVideoSourceParams* pdata =
-          static_cast<CreateVideoSourceParams*> (msg->pdata);
+          static_cast<CreateVideoSourceParams*>(msg->pdata);
       pdata->source = CreateVideoSource_s(pdata->capturer, pdata->constraints);
       break;
     }
diff --git a/talk/app/webrtc/peerconnectioninterface_unittest.cc b/talk/app/webrtc/peerconnectioninterface_unittest.cc
index 782bba1..698de3e 100644
--- a/talk/app/webrtc/peerconnectioninterface_unittest.cc
+++ b/talk/app/webrtc/peerconnectioninterface_unittest.cc
@@ -94,7 +94,7 @@
     return false;
   }
   const cricket::MediaContentDescription* media_desc =
-      static_cast<const cricket::MediaContentDescription*> (
+      static_cast<const cricket::MediaContentDescription*>(
           content_info->description);
   if (!media_desc || media_desc->streams().empty()) {
     return false;
diff --git a/talk/app/webrtc/webrtcsdp.cc b/talk/app/webrtc/webrtcsdp.cc
index f91db8d..8d9fba1 100644
--- a/talk/app/webrtc/webrtcsdp.cc
+++ b/talk/app/webrtc/webrtcsdp.cc
@@ -632,7 +632,7 @@
 void GetMediaStreamLabels(const ContentInfo* content,
                           std::set<std::string>* labels) {
   const MediaContentDescription* media_desc =
-      static_cast<const MediaContentDescription*> (
+      static_cast<const MediaContentDescription*>(
           content->description);
   const cricket::StreamParamsVec& streams =  media_desc->streams();
   for (cricket::StreamParamsVec::const_iterator it = streams.begin();
@@ -1123,7 +1123,7 @@
   // trunk/cppguide.xml?showone=Streams#Streams
   std::ostringstream os;
   const MediaContentDescription* media_desc =
-      static_cast<const MediaContentDescription*> (
+      static_cast<const MediaContentDescription*>(
           content_info->description);
   ASSERT(media_desc != NULL);
 
@@ -1928,7 +1928,7 @@
   if (!media_desc) {
     return;
   }
-  int preference = fmts.size();
+  int preference = static_cast<int>(fmts.size());
   std::vector<int>::const_iterator it = fmts.begin();
   bool add_new_codec = false;
   for (; it != fmts.end(); ++it) {
diff --git a/talk/app/webrtc/webrtcsdp_unittest.cc b/talk/app/webrtc/webrtcsdp_unittest.cc
index 9c3debd..4892f58 100644
--- a/talk/app/webrtc/webrtcsdp_unittest.cc
+++ b/talk/app/webrtc/webrtcsdp_unittest.cc
@@ -1240,7 +1240,7 @@
   int position = 0;
   for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) {
     if (string1.c_str()[i] != string2.c_str()[i]) {
-      position = i;
+      position = static_cast<int>(i);
       break;
     }
   }
diff --git a/talk/app/webrtc/webrtcsession.cc b/talk/app/webrtc/webrtcsession.cc
index fee8d42..840cb3d 100644
--- a/talk/app/webrtc/webrtcsession.cc
+++ b/talk/app/webrtc/webrtcsession.cc
@@ -629,25 +629,24 @@
 
 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc,
                                         std::string* err_desc) {
+  // Takes the ownership of |desc| regardless of the result.
+  talk_base::scoped_ptr<SessionDescriptionInterface> desc_temp(desc);
+
   if (error() != cricket::BaseSession::ERROR_NONE) {
-    delete desc;
     return BadLocalSdp(SessionErrorMsg(error()), err_desc);
   }
 
   if (!desc || !desc->description()) {
-    delete desc;
     return BadLocalSdp(kInvalidSdp, err_desc);
   }
   Action action = GetAction(desc->type());
   if (!ExpectSetLocalDescription(action)) {
     std::string type = desc->type();
-    delete desc;
     return BadLocalSdp(BadStateErrMsg(type, state()), err_desc);
   }
 
   if (session_desc_factory_.secure() == cricket::SEC_REQUIRED &&
       !VerifyCrypto(desc->description())) {
-    delete desc;
     return BadLocalSdp(kSdpWithoutCrypto, err_desc);
   }
 
@@ -665,10 +664,10 @@
   UpdateSessionDescriptionSecurePolicy(desc->description());
 
   set_local_description(desc->description()->Copy());
-  local_desc_.reset(desc);
+  local_desc_.reset(desc_temp.release());
 
   // Transport and Media channels will be created only when offer is set.
-  if (action == kOffer && !CreateChannels(desc->description())) {
+  if (action == kOffer && !CreateChannels(local_desc_->description())) {
     // TODO(mallinath) - Handle CreateChannel failure, as new local description
     // is applied. Restore back to old description.
     return BadLocalSdp(kCreateChannelFailed, err_desc);
@@ -676,10 +675,10 @@
 
   // Remove channel and transport proxies, if MediaContentDescription is
   // rejected.
-  RemoveUnusedChannelsAndTransports(desc->description());
+  RemoveUnusedChannelsAndTransports(local_desc_->description());
 
   if (!UpdateSessionState(action, cricket::CS_LOCAL,
-                          desc->description(), err_desc)) {
+                          local_desc_->description(), err_desc)) {
     return false;
   }
   // Kick starting the ice candidates allocation.
@@ -697,19 +696,19 @@
 
 bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc,
                                          std::string* err_desc) {
+  // Takes the ownership of |desc| regardless of the result.
+  talk_base::scoped_ptr<SessionDescriptionInterface> desc_temp(desc);
+
   if (error() != cricket::BaseSession::ERROR_NONE) {
-    delete desc;
     return BadRemoteSdp(SessionErrorMsg(error()), err_desc);
   }
 
   if (!desc || !desc->description()) {
-    delete desc;
     return BadRemoteSdp(kInvalidSdp, err_desc);
   }
   Action action = GetAction(desc->type());
   if (!ExpectSetRemoteDescription(action)) {
     std::string type = desc->type();
-    delete desc;
     return BadRemoteSdp(BadStateErrMsg(type, state()), err_desc);
   }
 
@@ -720,7 +719,6 @@
 
   if (session_desc_factory_.secure() == cricket::SEC_REQUIRED &&
       !VerifyCrypto(desc->description())) {
-    delete desc;
     return BadRemoteSdp(kSdpWithoutCrypto, err_desc);
   }
 
@@ -746,7 +744,6 @@
   // Update remote MediaStreams.
   mediastream_signaling_->OnRemoteDescriptionChanged(desc);
   if (local_description() && !UseCandidatesInSessionDescription(desc)) {
-    delete desc;
     return BadRemoteSdp(kInvalidCandidates, err_desc);
   }
 
@@ -758,7 +755,7 @@
   // that indicates the remote peer requests ice restart.
   ice_restart_latch_->CheckForRemoteIceRestart(remote_desc_.get(),
                                                desc);
-  remote_desc_.reset(desc);
+  remote_desc_.reset(desc_temp.release());
   if (error() != cricket::BaseSession::ERROR_NONE) {
     return BadRemoteSdp(SessionErrorMsg(error()), err_desc);
   }
@@ -1245,7 +1242,7 @@
   const ContentInfos& contents = BaseSession::local_description()->contents();
   for (size_t index = 0; index < contents.size(); ++index) {
     if (contents[index].name == content_name) {
-      *sdp_mline_index = index;
+      *sdp_mline_index = static_cast<int>(index);
       content_found = true;
       break;
     }
@@ -1428,7 +1425,7 @@
        iter != sdesc->contents().end(); ++iter) {
     if (cricket::IsMediaContent(&*iter)) {
       MediaContentDescription* mdesc =
-          static_cast<MediaContentDescription*> (iter->description);
+          static_cast<MediaContentDescription*>(iter->description);
       if (mdesc) {
         mdesc->set_crypto_required(
             session_desc_factory_.secure() == cricket::SEC_REQUIRED);
diff --git a/talk/app/webrtc/webrtcsession.h b/talk/app/webrtc/webrtcsession.h
index 045d347..f4fe202 100644
--- a/talk/app/webrtc/webrtcsession.h
+++ b/talk/app/webrtc/webrtcsession.h
@@ -140,8 +140,10 @@
   SessionDescriptionInterface* CreateAnswer(
       const MediaConstraintsInterface* constraints);
 
+  // The ownership of |desc| will be transferred after this call.
   bool SetLocalDescription(SessionDescriptionInterface* desc,
                            std::string* err_desc);
+  // The ownership of |desc| will be transferred after this call.
   bool SetRemoteDescription(SessionDescriptionInterface* desc,
                             std::string* err_desc);
   bool ProcessIceMessage(const IceCandidateInterface* ice_candidate);
diff --git a/talk/app/webrtc/webrtcsession_unittest.cc b/talk/app/webrtc/webrtcsession_unittest.cc
index 78619c6..48cccf4 100644
--- a/talk/app/webrtc/webrtcsession_unittest.cc
+++ b/talk/app/webrtc/webrtcsession_unittest.cc
@@ -496,12 +496,12 @@
     // Create a SDP without Crypto.
     cricket::MediaSessionOptions options;
     options.has_video = true;
-    scoped_ptr<JsepSessionDescription> offer(
+    JsepSessionDescription* offer(
         CreateRemoteOffer(options, cricket::SEC_DISABLED));
-    ASSERT_TRUE(offer.get() != NULL);
+    ASSERT_TRUE(offer != NULL);
     VerifyNoCryptoParams(offer->description(), false);
     SetRemoteDescriptionExpectError("Called with a SDP without crypto enabled",
-                                    offer.release());
+                                    offer);
     const webrtc::SessionDescriptionInterface* answer =
         session_->CreateAnswer(NULL);
     // Answer should be NULL as no crypto params in offer.
@@ -832,7 +832,7 @@
     const cricket::ContentDescription* description = content->description;
     ASSERT(description != NULL);
     const cricket::AudioContentDescription* audio_content_desc =
-        static_cast<const cricket::AudioContentDescription*> (description);
+        static_cast<const cricket::AudioContentDescription*>(description);
     ASSERT(audio_content_desc != NULL);
     for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
       if (audio_content_desc->codecs()[i].name == "CN")
@@ -2184,16 +2184,16 @@
   SetLocalDescriptionWithoutError(ice_only_offer);
   std::string original_offer_sdp;
   EXPECT_TRUE(offer->ToString(&original_offer_sdp));
-  talk_base::scoped_ptr<SessionDescriptionInterface> pranswer_with_gice(
+  SessionDescriptionInterface* pranswer_with_gice =
       CreateSessionDescription(JsepSessionDescription::kPrAnswer,
-                               original_offer_sdp, NULL));
+                               original_offer_sdp, NULL);
   SetRemoteDescriptionExpectError(kPushDownPranswerTDFailed,
-                                  pranswer_with_gice.get());
-  talk_base::scoped_ptr<SessionDescriptionInterface> answer_with_gice(
+                                  pranswer_with_gice);
+  SessionDescriptionInterface* answer_with_gice =
       CreateSessionDescription(JsepSessionDescription::kAnswer,
-                               original_offer_sdp, NULL));
+                               original_offer_sdp, NULL);
   SetRemoteDescriptionExpectError(kPushDownAnswerTDFailed,
-                                  answer_with_gice.get());
+                                  answer_with_gice);
 }
 
 // Verifing local offer and remote answer have matching m-lines as per RFC 3264.
@@ -2207,13 +2207,13 @@
 
   cricket::SessionDescription* answer_copy = answer->description()->Copy();
   answer_copy->RemoveContentByName("video");
-  talk_base::scoped_ptr<JsepSessionDescription> modified_answer(
-      new JsepSessionDescription(JsepSessionDescription::kAnswer));
+  JsepSessionDescription* modified_answer =
+      new JsepSessionDescription(JsepSessionDescription::kAnswer);
 
   EXPECT_TRUE(modified_answer->Initialize(answer_copy,
                                           answer->session_id(),
                                           answer->session_version()));
-  SetRemoteDescriptionExpectError(kMlineMismatch, modified_answer.get());
+  SetRemoteDescriptionExpectError(kMlineMismatch, modified_answer);
 
   // Modifying content names.
   std::string sdp;
@@ -2227,9 +2227,9 @@
                              kAudioMidReplaceStr.length(),
                              &sdp);
 
-  talk_base::scoped_ptr<SessionDescriptionInterface> modified_answer1(
-      CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL));
-  SetRemoteDescriptionExpectError(kMlineMismatch, modified_answer1.get());
+  SessionDescriptionInterface* modified_answer1 =
+      CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
+  SetRemoteDescriptionExpectError(kMlineMismatch, modified_answer1);
 
   SetRemoteDescriptionWithoutError(answer.release());
 }
@@ -2245,13 +2245,13 @@
 
   cricket::SessionDescription* answer_copy = answer->description()->Copy();
   answer_copy->RemoveContentByName("video");
-  talk_base::scoped_ptr<JsepSessionDescription> modified_answer(
-      new JsepSessionDescription(JsepSessionDescription::kAnswer));
+  JsepSessionDescription* modified_answer =
+      new JsepSessionDescription(JsepSessionDescription::kAnswer);
 
   EXPECT_TRUE(modified_answer->Initialize(answer_copy,
                                           answer->session_id(),
                                           answer->session_version()));
-  SetLocalDescriptionExpectError(kMlineMismatch, modified_answer.get());
+  SetLocalDescriptionExpectError(kMlineMismatch, modified_answer);
   SetLocalDescriptionWithoutError(answer);
 }
 
@@ -2388,9 +2388,9 @@
   video_channel_->set_fail_set_send_codecs(true);
 
   mediastream_signaling_.SendAudioVideoStream2();
-  talk_base::scoped_ptr<SessionDescriptionInterface> answer(
-      CreateRemoteAnswer(session_->local_description()));
-  SetRemoteDescriptionExpectError("ERROR_CONTENT", answer.get());
+  SessionDescriptionInterface* answer =
+      CreateRemoteAnswer(session_->local_description());
+  SetRemoteDescriptionExpectError("ERROR_CONTENT", answer);
 }
 
 // Runs the loopback call test with BUNDLE and STUN disabled.