Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Unified Diff: media/filters/video_cadence_estimator.cc

Issue 1459923003: Fix Bug: Video with Variable Frame Rate plays at incorrect speed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/video_cadence_estimator.h ('k') | media/filters/video_cadence_estimator_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/video_cadence_estimator.cc
diff --git a/media/filters/video_cadence_estimator.cc b/media/filters/video_cadence_estimator.cc
index 8804bf2d63a92edac0379b9ad6e6f697f2ea165c..ac2beb133ee3120790db99d753297f8a7d6b3bb6 100644
--- a/media/filters/video_cadence_estimator.cc
+++ b/media/filters/video_cadence_estimator.cc
@@ -18,6 +18,15 @@ namespace media {
// require some time to elapse before a cadence switch is accepted.
const int kMinimumCadenceDurationMs = 100;
+// The numbers are used to decide whether the current video is variable FPS or
+// constant FPS. If ratio of the sample deviation and the render length is
+// above |kVariableFPSFactor|, then it is recognized as a variable FPS, and if
+// the ratio is below |kConstantFPSFactor|, then it is recognized as a constant
+// FPS, and if the ratio is in between the two factors, then we do not change
+// previous recognition.
+const double kVariableFPSFactor = 0.55;
+const double kConstantFPSFactor = 0.45;
+
// Records the number of cadence changes to UMA.
static void HistogramCadenceChangeCount(int cadence_changes) {
const int kCadenceChangeMax = 10;
@@ -66,7 +75,8 @@ VideoCadenceEstimator::VideoCadenceEstimator(
base::TimeDelta minimum_time_until_max_drift)
: cadence_hysteresis_threshold_(
base::TimeDelta::FromMilliseconds(kMinimumCadenceDurationMs)),
- minimum_time_until_max_drift_(minimum_time_until_max_drift) {
+ minimum_time_until_max_drift_(minimum_time_until_max_drift),
+ is_variable_frame_rate_(false) {
Reset();
}
@@ -83,10 +93,27 @@ void VideoCadenceEstimator::Reset() {
bool VideoCadenceEstimator::UpdateCadenceEstimate(
base::TimeDelta render_interval,
base::TimeDelta frame_duration,
+ base::TimeDelta frame_duration_deviation,
base::TimeDelta max_acceptable_drift) {
DCHECK_GT(render_interval, base::TimeDelta());
DCHECK_GT(frame_duration, base::TimeDelta());
+ if (frame_duration_deviation > kVariableFPSFactor * render_interval) {
+ is_variable_frame_rate_ = true;
+ } else if (frame_duration_deviation < kConstantFPSFactor * render_interval) {
+ is_variable_frame_rate_ = false;
+ }
+
+ // Variable FPS detected, turn off Cadence by force.
+ if (is_variable_frame_rate_) {
+ render_intervals_cadence_held_ = 0;
+ if (!cadence_.empty()) {
+ cadence_.clear();
+ return true;
+ }
+ return false;
+ }
+
base::TimeDelta time_until_max_drift;
// See if we can find a cadence which fits the data.
« no previous file with comments | « media/filters/video_cadence_estimator.h ('k') | media/filters/video_cadence_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698