Bug 1311877 - VideoPlaybackQuality.totalVideoFrameCount is presented+dropped - r?jya draft
authorGerald Squelart <gsquelart@mozilla.com>
Fri, 21 Oct 2016 12:01:59 +1100
changeset 427870 ad81f06c0be9fd287657d28d30fc1f1d615814bd
parent 427779 f0f1aaf051d6798e1e73d1feee07ca847333167a
child 534580 0bb9107a2741c6820a3aad56d0e5d98436df16de
push id33147
push usergsquelart@mozilla.com
push dateFri, 21 Oct 2016 01:06:50 +0000
reviewersjya
bugs1311877
milestone52.0a1
Bug 1311877 - VideoPlaybackQuality.totalVideoFrameCount is presented+dropped - r?jya totalVideoFrameCount was previously incorrectly set to the number of demuxed frames. According to the current W3C specs [1], it should instead be the total number of frames that have been presented, plus frames that have been discarded. Also added a check that discarded<=total in mochitest. [1] https://wicg.github.io/media-playback-quality/#concepts MozReview-Commit-ID: Gnv1roM5n0A
dom/html/HTMLVideoElement.cpp
dom/media/test/test_VideoPlaybackQuality.html
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -249,29 +249,29 @@ HTMLVideoElement::GetVideoPlaybackQualit
         creationTime = perf->Now();
       }
     }
 
     if (mDecoder) {
       FrameStatisticsData stats =
         mDecoder->GetFrameStatistics().GetFrameStatisticsData();
       if (sizeof(totalFrames) >= sizeof(stats.mParsedFrames)) {
-        totalFrames = stats.mParsedFrames;
+        totalFrames = stats.mPresentedFrames + stats.mDroppedFrames;
         droppedFrames = stats.mDroppedFrames;
       } else {
-        auto maxStat = std::max(stats.mParsedFrames, stats.mDroppedFrames);
+        uint64_t total = stats.mPresentedFrames + stats.mDroppedFrames;
         const auto maxNumber = std::numeric_limits<uint32_t>::max();
-        if (maxStat <= maxNumber) {
-          totalFrames = static_cast<uint32_t>(stats.mParsedFrames);
-          droppedFrames = static_cast<uint32_t>(stats.mDroppedFrames);
+        if (total <= maxNumber) {
+          totalFrames = uint32_t(total);
+          droppedFrames = uint32_t(stats.mDroppedFrames);
         } else {
           // Too big number(s) -> Resize everything to fit in 32 bits.
-          double ratio = double(maxNumber) / double(maxStat);
-          totalFrames = double(stats.mParsedFrames) * ratio;
-          droppedFrames = double(stats.mDroppedFrames) * ratio;
+          double ratio = double(maxNumber) / double(total);
+          totalFrames = maxNumber; // === total * ratio
+          droppedFrames = uint32_t(double(stats.mDroppedFrames) * ratio);
         }
       }
       corruptedFrames = 0;
     }
   }
 
   RefPtr<VideoPlaybackQuality> playbackQuality =
     new VideoPlaybackQuality(this, creationTime, totalFrames, droppedFrames,
--- a/dom/media/test/test_VideoPlaybackQuality.html
+++ b/dom/media/test/test_VideoPlaybackQuality.html
@@ -31,16 +31,17 @@ function test() {
 
   video.src = "seek.webm";
   video.play();
   video.addEventListener("ended", function () {
     vpq = video.getVideoPlaybackQuality();
     ok(vpq.creationTime <= performance.now(), "creationTime should be in the past");
     ok(vpq.totalVideoFrames > 0, "totalVideoFrames should be > 0");
     ok(vpq.droppedVideoFrames >= 0, "droppedVideoFrames should be >= 0");
+    ok(vpq.droppedVideoFrames <= vpq.totalVideoFrames, "droppedVideoFrames should be <= totalVideoFrames");
     ok(vpq.corruptedVideoFrames >= 0, "corruptedVideoFrames should be >= 0");
 
     SpecialPowers.pushPrefEnv({"set": [["media.video_stats.enabled", false]]}, function () {
       vpq = video.getVideoPlaybackQuality();
       is(vpq.creationTime, 0, "creationTime should be 0");
       is(vpq.totalVideoFrames, 0, "totalVideoFrames should be 0");
       is(vpq.droppedVideoFrames, 0, "droppedVideoFrames should be 0");
       is(vpq.corruptedVideoFrames, 0, "corruptedVideoFrames should be 0");