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

Unified Diff: media/filters/video_cadence_estimator_unittest.cc

Issue 1021943002: Introduce cadence based VideoRendererAlgorithm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix frame expiration when Render() never called. Created 5 years, 8 months 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
Index: media/filters/video_cadence_estimator_unittest.cc
diff --git a/media/filters/video_cadence_estimator_unittest.cc b/media/filters/video_cadence_estimator_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2dda9b27050acd09b5b5aeb2e506d5edde58f9b4
--- /dev/null
+++ b/media/filters/video_cadence_estimator_unittest.cc
@@ -0,0 +1,135 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/stringprintf.h"
+#include "media/filters/video_cadence_estimator.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media {
+
+// See VideoCadenceEstimator header for more details.
+static const int kMinimumAcceptableTimeBetweenGlitchesSecs = 8;
xhwang 2015/04/28 16:01:08 nit: "static" not needed.
DaleCurtis 2015/04/28 21:45:24 Done.
+
+// Slows down the given |fps| according to NTSC field reduction standards; see
+// http://en.wikipedia.org/wiki/Frame_rate#Digital_video_and_television
+static double NTSC(double fps) {
+ return fps / 1.001;
+}
+
+static base::TimeDelta Interval(double hertz) {
+ return base::TimeDelta::FromSecondsD(1.0 / hertz);
+}
+
+static void VerifyCadence(VideoCadenceEstimator* estimator,
+ double frame_hertz,
+ double render_hertz,
+ int expected_cadence) {
+ SCOPED_TRACE(base::StringPrintf("Checking %.03f fps into %0.03f", frame_hertz,
+ render_hertz));
+ estimator->Reset();
+ const base::TimeDelta acceptable_drift = Interval(frame_hertz) / 2;
+ const bool found_cadence = estimator->UpdateCadenceEstimate(
+ Interval(render_hertz), Interval(frame_hertz), acceptable_drift);
+ EXPECT_EQ(found_cadence, estimator->has_cadence());
+ EXPECT_EQ(!!expected_cadence, estimator->has_cadence());
+
+ // Nothing further to test.
+ if (!expected_cadence)
+ return;
+
+ // Spot check a few frame indices.
+ if (frame_hertz <= render_hertz) {
+ EXPECT_EQ(expected_cadence, estimator->GetCadenceForFrame(0));
+ EXPECT_EQ(expected_cadence, estimator->GetCadenceForFrame(1));
+ EXPECT_EQ(expected_cadence, estimator->GetCadenceForFrame(2));
+ } else {
+ EXPECT_EQ(1, estimator->GetCadenceForFrame(0));
+ EXPECT_EQ(0, estimator->GetCadenceForFrame(1));
+ EXPECT_EQ(1, estimator->GetCadenceForFrame(expected_cadence));
+ EXPECT_EQ(0, estimator->GetCadenceForFrame(expected_cadence + 1));
+ }
+}
+
+// Spot check common display and frame rate pairs for correctness.
+TEST(VideoCadenceEstimatorTest, CadenceCalculations) {
+ VideoCadenceEstimator estimator(
+ base::TimeDelta::FromSeconds(kMinimumAcceptableTimeBetweenGlitchesSecs));
+ estimator.disable_cadence_hysteresis_for_testing();
+
+ VerifyCadence(&estimator, 24, 60, 0);
+ VerifyCadence(&estimator, NTSC(24), 60, 0);
+ VerifyCadence(&estimator, 25, 60, 0);
+ VerifyCadence(&estimator, NTSC(30), 60, 2);
+ VerifyCadence(&estimator, 30, 60, 2);
+ VerifyCadence(&estimator, 50, 60, 0);
+ VerifyCadence(&estimator, NTSC(60), 60, 1);
+ VerifyCadence(&estimator, 120, 60, 2);
+
+ // 50Hz is common in the EU.
+ VerifyCadence(&estimator, NTSC(24), 50, 0);
+ VerifyCadence(&estimator, 24, 50, 0);
+ VerifyCadence(&estimator, NTSC(25), 50, 2);
+ VerifyCadence(&estimator, 25, 50, 2);
+ VerifyCadence(&estimator, NTSC(30), 50, 0);
+ VerifyCadence(&estimator, 30, 50, 0);
+ VerifyCadence(&estimator, NTSC(60), 50, 0);
+ VerifyCadence(&estimator, 60, 50, 0);
+
+ VerifyCadence(&estimator, 25, NTSC(60), 0);
+ VerifyCadence(&estimator, 120, NTSC(60), 0);
+ VerifyCadence(&estimator, 1, NTSC(60), 60);
+}
+
+TEST(VideoCadenceEstimatorTest, CadenceVariesWithAcceptableDrift) {
+ VideoCadenceEstimator estimator(
+ base::TimeDelta::FromSeconds(kMinimumAcceptableTimeBetweenGlitchesSecs));
+ estimator.disable_cadence_hysteresis_for_testing();
+
+ const base::TimeDelta render_interval = Interval(NTSC(60));
+ const base::TimeDelta frame_interval = Interval(120);
+
+ base::TimeDelta acceptable_drift = frame_interval / 2;
+ bool found_cadence = estimator.UpdateCadenceEstimate(
+ render_interval, frame_interval, acceptable_drift);
+ EXPECT_FALSE(found_cadence);
+ EXPECT_FALSE(estimator.has_cadence());
+
+ // Increasing the acceptable drift should be result in more permissive
+ // detection of cadence.
+ acceptable_drift = render_interval;
+ found_cadence = estimator.UpdateCadenceEstimate(
+ render_interval, frame_interval, acceptable_drift);
+ EXPECT_TRUE(found_cadence);
+ EXPECT_TRUE(estimator.has_cadence());
+ EXPECT_EQ(2, estimator.get_cadence_for_testing());
+}
+
+TEST(VideoCadenceEstimatorTest, CadenceVariesWithAcceptableGlitchTime) {
+ scoped_ptr<VideoCadenceEstimator> estimator(new VideoCadenceEstimator(
+ base::TimeDelta::FromSeconds(kMinimumAcceptableTimeBetweenGlitchesSecs)));
+ estimator->disable_cadence_hysteresis_for_testing();
+
+ const base::TimeDelta render_interval = Interval(NTSC(60));
+ const base::TimeDelta frame_interval = Interval(120);
+ const base::TimeDelta acceptable_drift = frame_interval / 2;
+
+ bool found_cadence = estimator->UpdateCadenceEstimate(
+ render_interval, frame_interval, acceptable_drift);
+ EXPECT_FALSE(found_cadence);
+ EXPECT_FALSE(estimator->has_cadence());
+
+ // Decreasing the acceptable glitch time should be result in more permissive
+ // detection of cadence.
+ estimator.reset(new VideoCadenceEstimator(base::TimeDelta::FromSeconds(
+ kMinimumAcceptableTimeBetweenGlitchesSecs / 2)));
+ estimator->disable_cadence_hysteresis_for_testing();
xhwang 2015/04/28 16:01:08 Can you also test with the hysteresis enabled?
DaleCurtis 2015/04/28 21:45:24 Whoops, forgot about that. Done.
+ found_cadence = estimator->UpdateCadenceEstimate(
+ render_interval, frame_interval, acceptable_drift);
+ EXPECT_TRUE(found_cadence);
+ EXPECT_TRUE(estimator->has_cadence());
+ EXPECT_EQ(2, estimator->get_cadence_for_testing());
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698