Bug 1289668 - Refactor FrameStatistics - r=kamidphish
authorGerald Squelart <gsquelart@mozilla.com>
Mon, 18 Jul 2016 09:51:25 +1000
changeset 332129 86cec74f5da677e7960ad18545242f4bec8a4368
parent 332128 442f122200745ef96d1f4a220a6fb422001a351f
child 332130 98c9b3317cbfc02821d096a7e44303da625e59be
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish
bugs1289668
milestone50.0a1
Bug 1289668 - Refactor FrameStatistics - r=kamidphish Move FrameStatistics' data into separate struct, so that it can more easily be changed and passed around, outside of the lock-controlled FrameStatistics object. MozReview-Commit-ID: TfsMRJhVfQ
dom/html/HTMLVideoElement.cpp
dom/media/FrameStatistics.h
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -237,21 +237,22 @@ HTMLVideoElement::GetVideoPlaybackQualit
     if (nsPIDOMWindowInner* window = OwnerDoc()->GetInnerWindow()) {
       Performance* perf = window->GetPerformance();
       if (perf) {
         creationTime = perf->Now();
       }
     }
 
     if (mDecoder) {
-      FrameStatistics& stats = mDecoder->GetFrameStatistics();
-      static_assert(sizeof(uint32_t) >= sizeof (stats.GetParsedFrames()),
+      FrameStatisticsData stats =
+        mDecoder->GetFrameStatistics().GetFrameStatisticsData();
+      static_assert(sizeof(totalFrames) >= sizeof(stats.mParsedFrames),
                     "possible truncation from FrameStatistics to VideoPlaybackQuality");
-      totalFrames = stats.GetParsedFrames();
-      droppedFrames = stats.GetDroppedFrames();
+      totalFrames = stats.mParsedFrames;
+      droppedFrames = stats.mDroppedFrames;
       corruptedFrames = 0;
     }
   }
 
   RefPtr<VideoPlaybackQuality> playbackQuality =
     new VideoPlaybackQuality(this, creationTime, totalFrames, droppedFrames,
                              corruptedFrames);
   return playbackQuality.forget();
--- a/dom/media/FrameStatistics.h
+++ b/dom/media/FrameStatistics.h
@@ -4,104 +4,113 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef FrameStatistics_h_
 #define FrameStatistics_h_
 
 namespace mozilla {
 
+struct FrameStatisticsData
+{
+  // Number of frames parsed and demuxed from media.
+  // Access protected by mReentrantMonitor.
+  uint32_t mParsedFrames = 0;
+
+  // Number of parsed frames which were actually decoded.
+  // Access protected by mReentrantMonitor.
+  uint32_t mDecodedFrames = 0;
+
+  // Number of decoded frames which were actually sent down the rendering
+  // pipeline to be painted ("presented"). Access protected by mReentrantMonitor.
+  uint32_t mPresentedFrames = 0;
+
+  // Number of frames that have been skipped because they have missed their
+  // composition deadline.
+  uint32_t mDroppedFrames = 0;
+};
+
 // Frame decoding/painting related performance counters.
 // Threadsafe.
 class FrameStatistics
 {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FrameStatistics);
 
   FrameStatistics()
     : mReentrantMonitor("FrameStats")
-    , mParsedFrames(0)
-    , mDecodedFrames(0)
-    , mPresentedFrames(0)
-    , mDroppedFrames(0)
   {}
 
+  // Returns a copy of all frame statistics data.
+  // Can be called on any thread.
+  FrameStatisticsData GetFrameStatisticsData() const
+  {
+    ReentrantMonitorAutoEnter mon(mReentrantMonitor);
+    return mFrameStatisticsData;
+  }
+
   // Returns number of frames which have been parsed from the media.
   // Can be called on any thread.
   uint32_t GetParsedFrames() const
   {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-    return mParsedFrames;
+    return mFrameStatisticsData.mParsedFrames;
   }
 
   // Returns the number of parsed frames which have been decoded.
   // Can be called on any thread.
   uint32_t GetDecodedFrames() const
   {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-    return mDecodedFrames;
+    return mFrameStatisticsData.mDecodedFrames;
   }
 
   // Returns the number of decoded frames which have been sent to the rendering
   // pipeline for painting ("presented").
   // Can be called on any thread.
   uint32_t GetPresentedFrames() const
   {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-    return mPresentedFrames;
+    return mFrameStatisticsData.mPresentedFrames;
   }
 
   // Returns the number of frames that have been skipped because they have
   // missed their composition deadline.
   uint32_t GetDroppedFrames() const
   {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-    return mDroppedFrames;
+    return mFrameStatisticsData.mDroppedFrames;
   }
 
   // Increments the parsed and decoded frame counters by the passed in counts.
   // Can be called on any thread.
   void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded,
                            uint32_t aDropped)
   {
     if (aParsed == 0 && aDecoded == 0 && aDropped == 0) {
       return;
     }
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-    mParsedFrames += aParsed;
-    mDecodedFrames += aDecoded;
-    mDroppedFrames += aDropped;
+    mFrameStatisticsData.mParsedFrames += aParsed;
+    mFrameStatisticsData.mDecodedFrames += aDecoded;
+    mFrameStatisticsData.mDroppedFrames += aDropped;
   }
 
   // Increments the presented frame counters.
   // Can be called on any thread.
   void NotifyPresentedFrame()
   {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-    ++mPresentedFrames;
+    ++mFrameStatisticsData.mPresentedFrames;
   }
 
 private:
   ~FrameStatistics() {}
 
   // ReentrantMonitor to protect access of playback statistics.
   mutable ReentrantMonitor mReentrantMonitor;
 
-  // Number of frames parsed and demuxed from media.
-  // Access protected by mReentrantMonitor.
-  uint32_t mParsedFrames;
-
-  // Number of parsed frames which were actually decoded.
-  // Access protected by mReentrantMonitor.
-  uint32_t mDecodedFrames;
-
-  // Number of decoded frames which were actually sent down the rendering
-  // pipeline to be painted ("presented"). Access protected by mReentrantMonitor.
-  uint32_t mPresentedFrames;
-
-  // Number of frames that have been skipped because they have missed their
-  // composition deadline.
-  uint32_t mDroppedFrames;
+  FrameStatisticsData mFrameStatisticsData;
 };
 
 } // namespace mozilla
 
 #endif // FrameStatistics_h_