Bug 1001959 - Give up references to NrIceMediaStream on STS instead of main. r=jib
authorByron Campen [:bwc] <docfaraday@gmail.com>
Mon, 28 Apr 2014 09:01:29 -0700
changeset 181076 7a1905545937b4bfe2a23b739a284599aba5e178
parent 181075 c1c7e0011be70e9650f34904311204f0c75b109c
child 181077 246b181357c29ace230e861eadd72e3c20246de5
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersjib
bugs1001959
milestone32.0a1
Bug 1001959 - Give up references to NrIceMediaStream on STS instead of main. r=jib
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -1891,30 +1891,32 @@ PeerConnectionImpl::IceGatheringStateCha
   nsRefPtr<PeerConnectionImpl> pc(this);
   RUN_ON_THREAD(mThread,
                 WrapRunnable(pc,
                              &PeerConnectionImpl::IceGatheringStateChange_m,
                              toDomIceGatheringState(state)),
                 NS_DISPATCH_NORMAL);
 }
 
+#ifdef MOZILLA_INTERNAL_API
 static bool isDone(PCImplIceConnectionState state) {
   return state != PCImplIceConnectionState::Checking &&
          state != PCImplIceConnectionState::New;
 }
 
 static bool isSucceeded(PCImplIceConnectionState state) {
   return state == PCImplIceConnectionState::Connected ||
          state == PCImplIceConnectionState::Completed;
 }
 
 static bool isFailed(PCImplIceConnectionState state) {
   return state == PCImplIceConnectionState::Failed ||
          state == PCImplIceConnectionState::Disconnected;
 }
+#endif
 
 nsresult
 PeerConnectionImpl::IceConnectionStateChange_m(PCImplIceConnectionState aState)
 {
   PC_AUTO_ENTER_API_CALL(false);
 
   CSFLogDebug(logTag, "%s", __FUNCTION__);
 
@@ -2180,21 +2182,16 @@ static void RecordIceStats_s(
   }
 }
 
 nsresult
 PeerConnectionImpl::ExecuteStatsQuery_s(RTCStatsQuery *query) {
 
   ASSERT_ON_THREAD(query->iceCtx->thread());
 
-  // NrIceCtx must be destroyed on STS, so it is not safe to dispatch it back
-  // to main.
-  RefPtr<NrIceCtx> iceCtxTmp(query->iceCtx);
-  query->iceCtx = nullptr;
-
   // Gather stats from pipelines provided (can't touch mMedia + stream on STS)
 
   for (size_t p = 0; p < query->pipelines.Length(); ++p) {
     const MediaPipeline& mp = *query->pipelines[p];
     bool isAudio = (mp.Conduit()->type() == MediaSessionConduit::AUDIO);
     nsString idstr = isAudio ?
         NS_LITERAL_STRING("audio_") : NS_LITERAL_STRING("video_");
     idstr.AppendInt(mp.trackid());
@@ -2328,16 +2325,21 @@ PeerConnectionImpl::ExecuteStatsQuery_s(
   // Gather stats from ICE
   for (size_t s = 0; s != query->streams.Length(); ++s) {
     RecordIceStats_s(*query->streams[s],
                      query->internalStats,
                      query->now,
                      &(query->report));
   }
 
+  // NrIceCtx and NrIceMediaStream must be destroyed on STS, so it is not safe
+  // to dispatch them back to main.
+  // We clear streams first to maintain destruction order
+  query->streams.Clear();
+  query->iceCtx = nullptr;
   return NS_OK;
 }
 
 void PeerConnectionImpl::GetStatsForPCObserver_s(
     const std::string& pcHandle, // The Runnable holds the memory
     nsAutoPtr<RTCStatsQuery> query) {
 
   MOZ_ASSERT(query);