Bug 1204882 - Move MediaDecoder::FrameStatistics out of MediaDecoder for easier use in other classes. r=jwwang
authorKilik Kuo <kikuo@mozilla.com>
Tue, 15 Sep 2015 22:57:20 +0800
changeset 297358 bb6aaac878a4309dcacc9b1fdbf4eda08c764c5c
parent 297357 2637f47648c91034fdf6f2de6153288ff9572d83
child 297359 a02adf61c013e9d2bd0e11e664bc53374519695e
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1204882
milestone43.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 1204882 - Move MediaDecoder::FrameStatistics out of MediaDecoder for easier use in other classes. r=jwwang
dom/html/HTMLVideoElement.cpp
dom/media/FrameStatistics.h
dom/media/MediaDecoder.h
dom/media/MediaDecoderStateMachine.cpp
dom/media/moz.build
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -227,17 +227,17 @@ HTMLVideoElement::GetVideoPlaybackQualit
     if (window) {
       nsPerformance* perf = window->GetPerformance();
       if (perf) {
         creationTime = perf->Now();
       }
     }
 
     if (mDecoder) {
-      MediaDecoder::FrameStatistics& stats = mDecoder->GetFrameStatistics();
+      FrameStatistics& stats = mDecoder->GetFrameStatistics();
       totalFrames = stats.GetParsedFrames();
       droppedFrames = stats.GetDroppedFrames();
       corruptedFrames = 0;
     }
   }
 
   nsRefPtr<VideoPlaybackQuality> playbackQuality =
     new VideoPlaybackQuality(this, creationTime, totalFrames, droppedFrames,
new file mode 100644
--- /dev/null
+++ b/dom/media/FrameStatistics.h
@@ -0,0 +1,106 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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 {
+
+// Frame decoding/painting related performance counters.
+// Threadsafe.
+class FrameStatistics {
+public:
+  FrameStatistics() :
+      mReentrantMonitor("FrameStats"),
+      mParsedFrames(0),
+      mDecodedFrames(0),
+      mPresentedFrames(0),
+      mDroppedFrames(0),
+      mCorruptFrames(0) {}
+
+  // Returns number of frames which have been parsed from the media.
+  // Can be called on any thread.
+  uint32_t GetParsedFrames() {
+    ReentrantMonitorAutoEnter mon(mReentrantMonitor);
+    return mParsedFrames;
+  }
+
+  // Returns the number of parsed frames which have been decoded.
+  // Can be called on any thread.
+  uint32_t GetDecodedFrames() {
+    ReentrantMonitorAutoEnter mon(mReentrantMonitor);
+    return 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() {
+    ReentrantMonitorAutoEnter mon(mReentrantMonitor);
+    return mPresentedFrames;
+  }
+
+  // Number of frames that have been skipped because they have missed their
+  // compoisition deadline.
+  uint32_t GetDroppedFrames() {
+    ReentrantMonitorAutoEnter mon(mReentrantMonitor);
+    return mDroppedFrames + mCorruptFrames;
+  }
+
+  uint32_t GetCorruptedFrames() {
+    ReentrantMonitorAutoEnter mon(mReentrantMonitor);
+    return mCorruptFrames;
+  }
+
+  // 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;
+  }
+
+  // Increments the presented frame counters.
+  // Can be called on any thread.
+  void NotifyPresentedFrame() {
+    ReentrantMonitorAutoEnter mon(mReentrantMonitor);
+    ++mPresentedFrames;
+  }
+
+  void NotifyCorruptFrame() {
+    ReentrantMonitorAutoEnter mon(mReentrantMonitor);
+    ++mCorruptFrames;
+  }
+
+private:
+
+  // ReentrantMonitor to protect access of playback statistics.
+  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;
+
+  uint32_t mDroppedFrames;
+
+  uint32_t mCorruptFrames;
+};
+
+} // namespace mozilla
+
+#endif
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -198,16 +198,17 @@ destroying the MediaDecoder object.
 #include "necko-config.h"
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsIObserver.h"
 #include "nsISupports.h"
 #include "nsITimer.h"
 
 #include "AbstractMediaDecoder.h"
+#include "FrameStatistics.h"
 #include "MediaDecoderOwner.h"
 #include "MediaEventSource.h"
 #include "MediaMetadataManager.h"
 #include "MediaResource.h"
 #include "MediaStatistics.h"
 #include "MediaStreamGraph.h"
 #include "TimeUnits.h"
 
@@ -716,109 +717,16 @@ public:
 #endif
 
   // Return statistics. This is used for progress events and other things.
   // This can be called from any thread. It's only a snapshot of the
   // current state, since other threads might be changing the state
   // at any time.
   MediaStatistics GetStatistics();
 
-  // Frame decoding/painting related performance counters.
-  // Threadsafe.
-  class FrameStatistics {
-  public:
-
-    FrameStatistics() :
-        mReentrantMonitor("MediaDecoder::FrameStats"),
-        mParsedFrames(0),
-        mDecodedFrames(0),
-        mPresentedFrames(0),
-        mDroppedFrames(0),
-        mCorruptFrames(0) {}
-
-    // Returns number of frames which have been parsed from the media.
-    // Can be called on any thread.
-    uint32_t GetParsedFrames() {
-      ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-      return mParsedFrames;
-    }
-
-    // Returns the number of parsed frames which have been decoded.
-    // Can be called on any thread.
-    uint32_t GetDecodedFrames() {
-      ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-      return 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() {
-      ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-      return mPresentedFrames;
-    }
-
-    // Number of frames that have been skipped because they have missed their
-    // compoisition deadline.
-    uint32_t GetDroppedFrames() {
-      ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-      return mDroppedFrames + mCorruptFrames;
-    }
-
-    uint32_t GetCorruptedFrames() {
-      ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-      return mCorruptFrames;
-    }
-
-    // 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;
-    }
-
-    // Increments the presented frame counters.
-    // Can be called on any thread.
-    void NotifyPresentedFrame() {
-      ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-      ++mPresentedFrames;
-    }
-
-    void NotifyCorruptFrame() {
-      ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-      ++mCorruptFrames;
-    }
-
-  private:
-
-    // ReentrantMonitor to protect access of playback statistics.
-    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;
-
-    uint32_t mDroppedFrames;
-
-    uint32_t mCorruptFrames;
-  };
-
   // Return the frame decode/paint related statistics.
   FrameStatistics& GetFrameStatistics() { return mFrameStats; }
 
   // Increments the parsed and decoded frame counters by the passed in counts.
   // Can be called on any thread.
   virtual void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded,
                                    uint32_t aDropped) override
   {
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2493,17 +2493,17 @@ bool MediaDecoderStateMachine::CheckFram
   // If we've sent this frame before then only return the valid state,
   // don't update the statistics.
   if (aData->mSentToCompositor) {
     return !aData->mImage || aData->mImage->IsValid();
   }
 
   // Update corrupt-frames statistics
   if (aData->mImage && !aData->mImage->IsValid()) {
-    MediaDecoder::FrameStatistics& frameStats = mDecoder->GetFrameStatistics();
+    FrameStatistics& frameStats = mDecoder->GetFrameStatistics();
     frameStats.NotifyCorruptFrame();
     // If more than 10% of the last 30 frames have been corrupted, then try disabling
     // hardware acceleration. We use 10 as the corrupt value because RollingMean<>
     // only supports integer types.
     mCorruptFrames.insert(10);
     if (mReader->VideoIsHardwareAccelerated() &&
         frameStats.GetPresentedFrames() > 60 &&
         mCorruptFrames.mean() >= 2 /* 20% */) {
@@ -2630,17 +2630,17 @@ void MediaDecoderStateMachine::UpdateRen
                     currentFrame->mTime, clockTime);
       }
       currentFrame = VideoQueue().PopFront();
 
     }
     VideoQueue().PushFront(currentFrame);
     if (framesRemoved > 0) {
       mVideoFrameEndTime = currentFrame->GetEndTime();
-      MediaDecoder::FrameStatistics& frameStats = mDecoder->GetFrameStatistics();
+      FrameStatistics& frameStats = mDecoder->GetFrameStatistics();
       frameStats.NotifyPresentedFrame();
     }
   }
 
   RenderVideoFrames(sVideoQueueSendToCompositorSize, clockTime, nowTime);
 
   // Cap the current time to the larger of the audio and video end time.
   // This ensures that if we're running off the system clock, we don't
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -107,16 +107,17 @@ EXPORTS += [
     'AudioStream.h',
     'BufferMediaResource.h',
     'CubebUtils.h',
     'DecoderTraits.h',
     'DOMMediaStream.h',
     'EncodedBufferCache.h',
     'FileBlockCache.h',
     'FlushableTaskQueue.h',
+    'FrameStatistics.h',
     'Intervals.h',
     'Latency.h',
     'MediaCache.h',
     'MediaData.h',
     'MediaDataDemuxer.h',
     'MediaDecoder.h',
     'MediaDecoderOwner.h',
     'MediaDecoderReader.h',