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

Side by Side Diff: media/filters/video_renderer_algorithm_unittest.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 unified diff | Download patch
« no previous file with comments | « media/filters/video_renderer_algorithm.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <cmath> 5 #include <cmath>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/test/simple_test_tick_clock.h" 10 #include "base/test/simple_test_tick_clock.h"
(...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 RunFramePumpTest( 1173 RunFramePumpTest(
1174 true, &frame_tg, &display_tg, 1174 true, &frame_tg, &display_tg,
1175 [](const scoped_refptr<VideoFrame>& frame, size_t frames_dropped) {}); 1175 [](const scoped_refptr<VideoFrame>& frame, size_t frames_dropped) {});
1176 if (HasFatalFailure()) 1176 if (HasFatalFailure())
1177 return; 1177 return;
1178 } 1178 }
1179 } 1179 }
1180 } 1180 }
1181 1181
1182 // Rotate through various playback rates and ensure algorithm adapts correctly. 1182 // Rotate through various playback rates and ensure algorithm adapts correctly.
1183 TEST_F(VideoRendererAlgorithmTest, VariableFrameRateCadence) { 1183 TEST_F(VideoRendererAlgorithmTest, VariablePlaybackRateCadence) {
1184 TickGenerator frame_tg(base::TimeTicks(), NTSC(30)); 1184 TickGenerator frame_tg(base::TimeTicks(), NTSC(30));
1185 TickGenerator display_tg(tick_clock_->NowTicks(), 60); 1185 TickGenerator display_tg(tick_clock_->NowTicks(), 60);
1186 1186
1187 const double kTestRates[] = {1.0, 2, 0.215, 0.5, 1.0, 3.15}; 1187 const double kTestRates[] = {1.0, 2, 0.215, 0.5, 1.0, 3.15};
1188 const bool kTestRateHasCadence[arraysize(kTestRates)] = {true, true, true, 1188 const bool kTestRateHasCadence[arraysize(kTestRates)] = {true, true, true,
1189 true, true, false}; 1189 true, true, false};
1190 1190
1191 for (size_t i = 0; i < arraysize(kTestRates); ++i) { 1191 for (size_t i = 0; i < arraysize(kTestRates); ++i) {
1192 const double playback_rate = kTestRates[i]; 1192 const double playback_rate = kTestRates[i];
1193 SCOPED_TRACE(base::StringPrintf("Playback Rate: %.03f", playback_rate)); 1193 SCOPED_TRACE(base::StringPrintf("Playback Rate: %.03f", playback_rate));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 // enough frames are encountered; after which it should not drop out of 1234 // enough frames are encountered; after which it should not drop out of
1235 // cadence. 1235 // cadence.
1236 if (is_using_cadence()) 1236 if (is_using_cadence())
1237 cadence_detected = true; 1237 cadence_detected = true;
1238 1238
1239 if (cadence_detected) 1239 if (cadence_detected)
1240 ASSERT_TRUE(is_using_cadence()); 1240 ASSERT_TRUE(is_using_cadence());
1241 } 1241 }
1242 } 1242 }
1243 1243
1244 // Ensures media with variable frame rate should not be applied with Cadence.
1245 TEST_F(VideoRendererAlgorithmTest, VariableFrameRateNoCadence) {
1246 TickGenerator display_tg(tick_clock_->NowTicks(), 60);
1247 time_source_.StartTicking();
1248
1249 const int kBadTimestampsMs[] = {200, 200, 200, 200, 200, 1000,
1250 1000, 1000, 1000, 200, 200, 200,
1251 200, 200, 1000, 1000, 1000, 1000};
1252
1253 // Run throught ~10 seconds worth of frames.
1254 bool cadence_detected = false;
1255 bool cadence_turned_off = false;
1256 base::TimeDelta timestamp;
1257 for (size_t i = 0; i < arraysize(kBadTimestampsMs);) {
1258 while (algorithm_.EffectiveFramesQueued() < 3) {
1259 algorithm_.EnqueueFrame(CreateFrame(timestamp));
1260 timestamp += base::TimeDelta::FromMilliseconds(
1261 kBadTimestampsMs[i % arraysize(kBadTimestampsMs)]);
1262 ++i;
1263 }
1264
1265 size_t frames_dropped = 0;
1266 RenderAndStep(&display_tg, &frames_dropped);
1267 ASSERT_EQ(0u, frames_dropped);
1268
1269 // Cadence would be detected during the first second, and then
1270 // it should be off due to variable FPS detection, and then for this
1271 // sample, it should never be on.
1272 if (is_using_cadence())
1273 cadence_detected = true;
1274
1275 if (cadence_detected) {
1276 if (!is_using_cadence())
1277 cadence_turned_off = true;
1278 }
1279
1280 if (cadence_turned_off) {
1281 ASSERT_FALSE(is_using_cadence());
1282 }
1283 }
1284
1285 // Make sure Cadence is turned off somewhen, not always on.
1286 ASSERT_TRUE(cadence_turned_off);
1287 }
1288
1244 TEST_F(VideoRendererAlgorithmTest, EnqueueFrames) { 1289 TEST_F(VideoRendererAlgorithmTest, EnqueueFrames) {
1245 TickGenerator tg(base::TimeTicks(), 50); 1290 TickGenerator tg(base::TimeTicks(), 50);
1246 time_source_.StartTicking(); 1291 time_source_.StartTicking();
1247 1292
1248 EXPECT_EQ(0u, frames_queued()); 1293 EXPECT_EQ(0u, frames_queued());
1249 scoped_refptr<VideoFrame> frame_1 = CreateFrame(tg.interval(0)); 1294 scoped_refptr<VideoFrame> frame_1 = CreateFrame(tg.interval(0));
1250 algorithm_.EnqueueFrame(frame_1); 1295 algorithm_.EnqueueFrame(frame_1);
1251 EXPECT_EQ(1u, frames_queued()); 1296 EXPECT_EQ(1u, frames_queued());
1252 1297
1253 // Enqueuing a frame with the same timestamp should always be dropped. 1298 // Enqueuing a frame with the same timestamp should always be dropped.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 ASSERT_TRUE(is_using_cadence()); 1383 ASSERT_TRUE(is_using_cadence());
1339 1384
1340 // Finally the last frame. 1385 // Finally the last frame.
1341 rendered_frame = RenderAndStep(&tg, &frames_dropped); 1386 rendered_frame = RenderAndStep(&tg, &frames_dropped);
1342 EXPECT_EQ(1u, frames_queued()); 1387 EXPECT_EQ(1u, frames_queued());
1343 EXPECT_EQ(tg.interval(12), rendered_frame->timestamp()); 1388 EXPECT_EQ(tg.interval(12), rendered_frame->timestamp());
1344 ASSERT_TRUE(is_using_cadence()); 1389 ASSERT_TRUE(is_using_cadence());
1345 } 1390 }
1346 1391
1347 } // namespace media 1392 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/video_renderer_algorithm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698