Bug 958221 - Part 1: Move (but not alter) some code as step one in refactoring the GetStats functionality so it can be used by other classes. r=jib
authorByron Campen [:bwc] <docfaraday@gmail.com>
Fri, 24 Jan 2014 14:48:15 -0800
changeset 189289 23bebfef70a2ca7ec9db6e60df7152b280670865
parent 189288 b8e76bcb90879cd2ed69c8bab74afeda24f0829d
child 189290 95e8301cb71e00e271cb9461fd79736df70e2d12
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs958221
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 958221 - Part 1: Move (but not alter) some code as step one in refactoring the GetStats functionality so it can be used by other classes. r=jib
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -1298,61 +1298,41 @@ PeerConnectionImpl::GetStats(MediaStream
   PC_AUTO_ENTER_API_CALL(true);
 
 #ifdef MOZILLA_INTERNAL_API
   if (!mMedia) {
     // Since we zero this out before the d'tor, we should check.
     return NS_ERROR_UNEXPECTED;
   }
 
-  // Gather up pipelines from mMedia and dispatch them to STS for inspection
-
   std::vector<RefPtr<MediaPipeline>> pipelines;
-  TrackID trackId = aSelector ? aSelector->GetTrackID() : 0;
-
-  for (int i = 0, len = mMedia->LocalStreamsLength(); i < len; i++) {
-    PushBackSelect(pipelines, mMedia->GetLocalStream(i)->GetPipelines(), trackId);
-  }
-  for (int i = 0, len = mMedia->RemoteStreamsLength(); i < len; i++) {
-    PushBackSelect(pipelines, mMedia->GetRemoteStream(i)->GetPipelines(), trackId);
-  }
-
-  // From the list of MediaPipelines, determine the set of NrIceMediaStreams
-  // we are interested in.
   std::vector<RefPtr<NrIceMediaStream> > streams;
-  RefPtr<NrIceCtx> iceCtx(mMedia->ice_ctx());
-  for (auto p = pipelines.begin(); p != pipelines.end(); ++p) {
-    size_t level = p->get()->level();
-    // TODO(bcampen@mozilla.com): I may need to revisit this for bundle.
-    // (Bug 786234)
-    RefPtr<NrIceMediaStream> temp(mMedia->ice_media_stream(level-1));
-    if (temp.get()) {
-      streams.push_back(temp);
-    } else {
-       CSFLogError(logTag, "Failed to get NrIceMediaStream for level %u "
-                           "in %s:  %s",
-                           uint32_t(level), __FUNCTION__, mHandle.c_str());
-       MOZ_CRASH();
-    }
-  }
+  RefPtr<NrIceCtx> iceCtx;
+  DOMHighResTimeStamp now;
+  nsAutoPtr<RTCStatsReportInternal> report;
 
-  DOMHighResTimeStamp now;
-  nsresult rv = GetTimeSinceEpoch(&now);
+  nsresult rv = BuildStatsQuery_m(aSelector,
+                                  pipelines,
+                                  iceCtx,
+                                  streams,
+                                  now,
+                                  report);
   NS_ENSURE_SUCCESS(rv, rv);
 
   RUN_ON_THREAD(mSTSThread,
                 WrapRunnableNM(&PeerConnectionImpl::GetStats_s,
                                mHandle,
                                mName,
                                mThread,
                                internalStats,
                                pipelines,
                                iceCtx,
                                streams,
-                               now),
+                               now,
+                               report),
                 NS_DISPATCH_NORMAL);
 #endif
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PeerConnectionImpl::GetLogging(const nsAString& aPattern) {
   PC_AUTO_ENTER_API_CALL_NO_CHECK();
@@ -1961,16 +1941,64 @@ PeerConnectionImpl::IceGatheringStateCha
                              PCObserverStateType::IceGatheringState,
                              rv, static_cast<JSCompartment*>(nullptr)),
                 NS_DISPATCH_NORMAL);
   return NS_OK;
 }
 
 #ifdef MOZILLA_INTERNAL_API
 nsresult
+PeerConnectionImpl::BuildStatsQuery_m(
+    mozilla::dom::MediaStreamTrack *aSelector,
+    std::vector<mozilla::RefPtr<mozilla::MediaPipeline>> &pipelines,
+    mozilla::RefPtr<NrIceCtx> &iceCtx,
+    std::vector<mozilla::RefPtr<NrIceMediaStream>> &streams,
+    DOMHighResTimeStamp &now,
+    nsAutoPtr<mozilla::dom::RTCStatsReportInternal> &report) {
+
+  // We do not use the pcHandle here, since that's risky to expose to content.
+  report = new RTCStatsReportInternalConstruct(
+      NS_ConvertASCIItoUTF16(mName.c_str()),
+      now);
+
+  // Gather up pipelines from mMedia and dispatch them to STS for inspection
+  TrackID trackId = aSelector ? aSelector->GetTrackID() : 0;
+
+  for (int i = 0, len = mMedia->LocalStreamsLength(); i < len; i++) {
+    PushBackSelect(pipelines, mMedia->GetLocalStream(i)->GetPipelines(), trackId);
+  }
+  for (int i = 0, len = mMedia->RemoteStreamsLength(); i < len; i++) {
+    PushBackSelect(pipelines, mMedia->GetRemoteStream(i)->GetPipelines(), trackId);
+  }
+
+  iceCtx = mMedia->ice_ctx();
+
+  // From the list of MediaPipelines, determine the set of NrIceMediaStreams
+  // we are interested in.
+  for (auto p = pipelines.begin(); p != pipelines.end(); ++p) {
+    size_t level = p->get()->level();
+    // TODO(bcampen@mozilla.com): I may need to revisit this for bundle.
+    // (Bug 786234)
+    RefPtr<NrIceMediaStream> temp(mMedia->ice_media_stream(level-1));
+    if (temp.get()) {
+      streams.push_back(temp);
+    } else {
+       CSFLogError(logTag, "Failed to get NrIceMediaStream for level %u "
+                           "in %s:  %s",
+                           uint32_t(level), __FUNCTION__, mHandle.c_str());
+       MOZ_CRASH();
+    }
+  }
+
+  nsresult rv = GetTimeSinceEpoch(&now);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return NS_OK;
+}
+
+nsresult
 PeerConnectionImpl::GetStatsImpl_s(
     bool internalStats,
     const std::vector<RefPtr<MediaPipeline>>& pipelines,
     const RefPtr<NrIceCtx>& iceCtx,
     const std::vector<RefPtr<NrIceMediaStream>>& streams,
     DOMHighResTimeStamp now,
     RTCStatsReportInternal* report) {
 
@@ -2186,26 +2214,21 @@ void PeerConnectionImpl::FillStatsReport
 void PeerConnectionImpl::GetStats_s(
     const std::string& pcHandle, // The Runnable holds the memory
     const std::string& pcName, // The Runnable holds the memory
     nsCOMPtr<nsIThread> callbackThread,
     bool internalStats,
     const std::vector<RefPtr<MediaPipeline>>& pipelines,
     const RefPtr<NrIceCtx>& iceCtx,
     const std::vector<RefPtr<NrIceMediaStream>>& streams,
-    DOMHighResTimeStamp now) {
+    DOMHighResTimeStamp now,
+    nsAutoPtr<RTCStatsReportInternal> report) {
 
   ASSERT_ON_THREAD(iceCtx->thread());
 
-  // We do not use the pcHandle here, since that's risky to expose to content.
-  nsAutoPtr<RTCStatsReportInternal> report(
-      new RTCStatsReportInternalConstruct(
-          NS_ConvertASCIItoUTF16(pcName.c_str()),
-          now));
-
   nsresult rv = GetStatsImpl_s(internalStats,
                                pipelines,
                                iceCtx,
                                streams,
                                now,
                                report);
 
   RUN_ON_THREAD(callbackThread,
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
@@ -488,16 +488,34 @@ public:
   const std::vector<std::string> &GetSdpParseErrors();
 
   // Sets the RTC Signaling State
   void SetSignalingState_m(mozilla::dom::PCImplSignalingState aSignalingState);
 
 #ifdef MOZILLA_INTERNAL_API
   // initialize telemetry for when calls start
   void startCallTelem();
+
+  // This is an intermediate form, to make this refactoring easier to review.
+  // Please forgive the use of & for out-params.
+  nsresult BuildStatsQuery_m(
+      mozilla::dom::MediaStreamTrack *aSelector,
+      std::vector<mozilla::RefPtr<mozilla::MediaPipeline>> &pipelines,
+      mozilla::RefPtr<NrIceCtx> &iceCtx,
+      std::vector<mozilla::RefPtr<NrIceMediaStream>> &streams,
+      DOMHighResTimeStamp &now,
+      nsAutoPtr<mozilla::dom::RTCStatsReportInternal> &report);
+
+  static nsresult GetStatsImpl_s(
+      bool internalStats,
+      const std::vector<mozilla::RefPtr<mozilla::MediaPipeline>> &pipelines,
+      const mozilla::RefPtr<NrIceCtx> &iceCtx,
+      const std::vector<mozilla::RefPtr<NrIceMediaStream>> &streams,
+      DOMHighResTimeStamp now,
+      mozilla::dom::RTCStatsReportInternal *report);
 #endif
 
 private:
   PeerConnectionImpl(const PeerConnectionImpl&rhs);
   PeerConnectionImpl& operator=(PeerConnectionImpl);
   NS_IMETHODIMP Initialize(PeerConnectionObserver& aObserver,
                            nsGlobalWindow* aWindow,
                            const IceConfiguration* aConfiguration,
@@ -552,25 +570,18 @@ private:
   static void GetStats_s(
       const std::string& pcHandle,
       const std::string& pcName,
       nsCOMPtr<nsIThread> callbackThread,
       bool internalStats,
       const std::vector<mozilla::RefPtr<mozilla::MediaPipeline>> &pipelines,
       const mozilla::RefPtr<NrIceCtx> &iceCtx,
       const std::vector<mozilla::RefPtr<NrIceMediaStream>> &streams,
-      DOMHighResTimeStamp now);
-
-  static nsresult GetStatsImpl_s(
-      bool internalStats,
-      const std::vector<mozilla::RefPtr<mozilla::MediaPipeline>> &pipelines,
-      const mozilla::RefPtr<NrIceCtx> &iceCtx,
-      const std::vector<mozilla::RefPtr<NrIceMediaStream>> &streams,
       DOMHighResTimeStamp now,
-      mozilla::dom::RTCStatsReportInternal *report);
+      nsAutoPtr<mozilla::dom::RTCStatsReportInternal> report);
 
   static void FillStatsReport_s(
       NrIceMediaStream& stream,
       bool internalStats,
       DOMHighResTimeStamp now,
       mozilla::dom::RTCStatsReportInternal* stats);
 
   // Sends an RTCStatsReport to JS. Must run on main thread.