Bug 1149298 - Part 3: Fire end of candidates signal when StartGathering has nothing to do, and only call StartGathering once per offer/answer. r=drno, a=lmandel
authorByron Campen [:bwc] <docfaraday@gmail.com>
Mon, 30 Mar 2015 16:32:51 -0700
changeset 265686 3e48f6649975ed92f5f052c412f37e9e61848254
parent 265685 021bc6e975d9f8d3fdf7ef83d6ec86c885a32e99
child 265687 d3af56f0df91619234f1ee19052bf38acd097202
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno, lmandel
bugs1149298
milestone39.0a2
Bug 1149298 - Part 3: Fire end of candidates signal when StartGathering has nothing to do, and only call StartGathering once per offer/answer. r=drno, a=lmandel
media/mtransport/nricectx.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.h
--- a/media/mtransport/nricectx.cpp
+++ b/media/mtransport/nricectx.cpp
@@ -672,29 +672,31 @@ abort:
     nr_socket_wrapper_factory_destroy(&wrapper);
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
 nsresult NrIceCtx::StartGathering() {
   ASSERT_ON_THREAD(sts_target_);
+  SetGatheringState(ICE_CTX_GATHER_STARTED);
   // This might start gathering for the first time, or again after
   // renegotiation, or might do nothing at all if gathering has already
   // finished.
   int r = nr_ice_gather(ctx_, &NrIceCtx::gather_cb, this);
 
-  if (r && (r != R_WOULDBLOCK)) {
+  if (!r) {
+    SetGatheringState(ICE_CTX_GATHER_COMPLETE);
+  } else if (r != R_WOULDBLOCK) {
     MOZ_MTLOG(ML_ERROR, "Couldn't gather ICE candidates for '"
                         << name_ << "', error=" << r);
     SetConnectionState(ICE_CTX_FAILED);
     return NS_ERROR_FAILURE;
   }
 
-  SetGatheringState(ICE_CTX_GATHER_STARTED);
   return NS_OK;
 }
 
 RefPtr<NrIceMediaStream> NrIceCtx::FindStream(
     nr_ice_media_stream *stream) {
   for (size_t i=0; i<streams_.size(); ++i) {
     if (streams_[i] && (streams_[i]->stream() == stream)) {
       return streams_[i];
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -2421,21 +2421,26 @@ void
 PeerConnectionImpl::SetSignalingState_m(PCImplSignalingState aSignalingState)
 {
   PC_AUTO_ENTER_API_CALL_NO_CHECK();
   if (mSignalingState == aSignalingState ||
       mSignalingState == PCImplSignalingState::SignalingClosed) {
     return;
   }
 
+  bool restartGathering =
+    aSignalingState == PCImplSignalingState::SignalingHaveLocalOffer ||
+    (aSignalingState == PCImplSignalingState::SignalingStable &&
+     mSignalingState == PCImplSignalingState::SignalingHaveRemoteOffer);
+
   mSignalingState = aSignalingState;
 
   if (mSignalingState == PCImplSignalingState::SignalingHaveLocalOffer ||
       mSignalingState == PCImplSignalingState::SignalingStable) {
-    mMedia->UpdateTransports(*mJsepSession);
+    mMedia->UpdateTransports(*mJsepSession, restartGathering);
   }
 
   bool fireNegotiationNeeded = false;
 
   if (mSignalingState == PCImplSignalingState::SignalingStable) {
     mMedia->UpdateMediaPipelines(*mJsepSession);
     InitializeDataChannel();
     mMedia->StartIceChecks(*mJsepSession);
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
@@ -323,17 +323,18 @@ nsresult PeerConnectionMedia::Init(const
   mIceCtx->SignalConnectionStateChange.connect(
       this,
       &PeerConnectionMedia::IceConnectionStateChange_s);
 
   return NS_OK;
 }
 
 void
-PeerConnectionMedia::UpdateTransports(const JsepSession& session) {
+PeerConnectionMedia::UpdateTransports(const JsepSession& session,
+                                      bool restartGathering) {
 
   auto transports = session.GetTransports();
   for (size_t i = 0; i < transports.size(); ++i) {
     RefPtr<JsepTransport> transport = transports[i];
 
     std::string ufrag;
     std::string pwd;
     std::vector<std::string> candidates;
@@ -356,18 +357,19 @@ PeerConnectionMedia::UpdateTransports(co
                                transport->mComponents,
                                hasAttrs,
                                ufrag,
                                pwd,
                                candidates),
                   NS_DISPATCH_NORMAL);
   }
 
-
-  GatherIfReady();
+  if (restartGathering) {
+    GatherIfReady();
+  }
 }
 
 nsresult PeerConnectionMedia::UpdateMediaPipelines(
     const JsepSession& session) {
   auto trackPairs = session.GetNegotiatedTrackPairs();
   MediaPipelineFactory factory(this);
   nsresult rv;
 
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.h
@@ -239,17 +239,17 @@ class PeerConnectionMedia : public sigsl
     return mIceCtx->GetStream(i);
   }
 
   size_t num_ice_media_streams() const {
     return mIceCtx->GetStreamCount();
   }
 
   // Create and modify transports in response to negotiation events.
-  void UpdateTransports(const JsepSession& session);
+  void UpdateTransports(const JsepSession& session, bool restartGathering);
 
   // Start ICE checks.
   void StartIceChecks(const JsepSession& session);
 
   // Process a trickle ICE candidate.
   void AddIceCandidate(const std::string& candidate, const std::string& mid,
                        uint32_t aMLine);