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
--- 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");