Bug 1289668 - Use 64 bits to store FrameStatistics values - r=kamidphish
Decoders uses 64-bit values to count frames, so we should use the same type in FrameStatistics. Because VideoPlaybackQuality can only use 32 bits (as defined in W3C specs), we need to ensure that imported FrameStatistics numbers can fit in 32 bits, while keeping their ratios the same. MozReview-Commit-ID: 3pUTGK0ekGv
This commit is contained in:
@@ -31,6 +31,9 @@
|
||||
#include "mozilla/dom/Performance.h"
|
||||
#include "mozilla/dom/VideoPlaybackQuality.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
NS_IMPL_NS_NEW_HTML_ELEMENT(Video)
|
||||
|
||||
namespace mozilla {
|
||||
@@ -244,10 +247,22 @@ HTMLVideoElement::GetVideoPlaybackQuality()
|
||||
if (mDecoder) {
|
||||
FrameStatisticsData stats =
|
||||
mDecoder->GetFrameStatistics().GetFrameStatisticsData();
|
||||
static_assert(sizeof(totalFrames) >= sizeof(stats.mParsedFrames),
|
||||
"possible truncation from FrameStatistics to VideoPlaybackQuality");
|
||||
totalFrames = stats.mParsedFrames;
|
||||
droppedFrames = stats.mDroppedFrames;
|
||||
if (sizeof(totalFrames) >= sizeof(stats.mParsedFrames)) {
|
||||
totalFrames = stats.mParsedFrames;
|
||||
droppedFrames = stats.mDroppedFrames;
|
||||
} else {
|
||||
auto maxStat = std::max(stats.mParsedFrames, 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);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
corruptedFrames = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user