Bug 1289668 - HTMLMediaElement uses video decoder's frame statistics - r=kamidphish
authorGerald Squelart <gsquelart@mozilla.com>
Tue, 26 Jul 2016 11:32:58 +1000
changeset 349168 fff6018d7bba1434d86fd42265569118e19387f7
parent 349167 12a97f1e4297f74a5a82e54dacefc05c3d58bed1
child 349169 a3bd0fb7c2691c1b22b7d359c230643221a2fb13
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish
bugs1289668
milestone50.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 1289668 - HTMLMediaElement uses video decoder's frame statistics - r=kamidphish HTMLVideoElement can expose its thread-safe FrameStatistics object, so that HTMLMediaElement can access more adequate data for its telemetry, without having to use an intermediary (and potentially less accurate) VideoPlaybackQuality object. This will also help with accessing other/new FrameStatistics members later on. MozReview-Commit-ID: AT7mEGy0zGr
dom/html/HTMLMediaElement.cpp
dom/html/HTMLVideoElement.cpp
dom/html/HTMLVideoElement.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3079,28 +3079,29 @@ HTMLMediaElement::ReportTelemetry()
       state = STALLED;
     }
   }
 
   Telemetry::Accumulate(Telemetry::VIDEO_UNLOAD_STATE, state);
   LOG(LogLevel::Debug, ("%p VIDEO_UNLOAD_STATE = %d", this, state));
 
   if (HTMLVideoElement* vid = HTMLVideoElement::FromContentOrNull(this)) {
-    RefPtr<VideoPlaybackQuality> quality = vid->GetVideoPlaybackQuality();
-    uint32_t totalFrames = quality->TotalVideoFrames();
-    if (totalFrames) {
-      uint32_t droppedFrames = quality->DroppedVideoFrames();
-      MOZ_ASSERT(droppedFrames <= totalFrames);
-      // Dropped frames <= total frames, so 'percentage' cannot be higher than
-      // 100 and therefore can fit in a uint32_t (that Telemetry takes).
-      uint32_t percentage = 100 * droppedFrames / totalFrames;
-      LOG(LogLevel::Debug,
-          ("Reporting telemetry DROPPED_FRAMES_IN_VIDEO_PLAYBACK"));
-      Telemetry::Accumulate(Telemetry::VIDEO_DROPPED_FRAMES_PROPORTION,
-                            percentage);
+    FrameStatistics* stats = vid->GetFrameStatistics();
+    if (stats) {
+      FrameStatisticsData data = stats->GetFrameStatisticsData();
+      if (data.mParsedFrames) {
+        MOZ_ASSERT(data.mDroppedFrames <= data.mParsedFrames);
+        // Dropped frames <= total frames, so 'percentage' cannot be higher than
+        // 100 and therefore can fit in a uint32_t (that Telemetry takes).
+        uint32_t percentage = 100 * data.mDroppedFrames / data.mParsedFrames;
+        LOG(LogLevel::Debug,
+            ("Reporting telemetry DROPPED_FRAMES_IN_VIDEO_PLAYBACK"));
+        Telemetry::Accumulate(Telemetry::VIDEO_DROPPED_FRAMES_PROPORTION,
+                              percentage);
+      }
     }
   }
 
   if (mMediaInfo.HasVideo() &&
       mMediaInfo.mVideo.mImage.height > 0) {
     // We have a valid video.
     double playTime = mPlayTime.Total();
     double hiddenPlayTime = mHiddenPlayTime.Total();
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -223,16 +223,22 @@ HTMLVideoElement::WrapNode(JSContext* aC
 bool
 HTMLVideoElement::NotifyOwnerDocumentActivityChangedInternal()
 {
   bool pauseElement = HTMLMediaElement::NotifyOwnerDocumentActivityChangedInternal();
   UpdateScreenWakeLock();
   return pauseElement;
 }
 
+FrameStatistics*
+HTMLVideoElement::GetFrameStatistics()
+{
+  return mDecoder ? &(mDecoder->GetFrameStatistics()) : nullptr;
+}
+
 already_AddRefed<VideoPlaybackQuality>
 HTMLVideoElement::GetVideoPlaybackQuality()
 {
   DOMHighResTimeStamp creationTime = 0;
   uint32_t totalFrames = 0;
   uint32_t droppedFrames = 0;
   uint32_t corruptedFrames = 0;
 
--- a/dom/html/HTMLVideoElement.h
+++ b/dom/html/HTMLVideoElement.h
@@ -125,16 +125,19 @@ public:
   bool MozHasAudio() const;
 
   bool MozUseScreenWakeLock() const;
 
   void SetMozUseScreenWakeLock(bool aValue);
 
   bool NotifyOwnerDocumentActivityChangedInternal() override;
 
+  // Gives access to the decoder's frame statistics, if present.
+  FrameStatistics* GetFrameStatistics();
+
   already_AddRefed<VideoPlaybackQuality> GetVideoPlaybackQuality();
 
 protected:
   virtual ~HTMLVideoElement();
 
   virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   virtual void WakeLockCreate() override;