| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/test/simple_test_tick_clock.h" | 6 #include "base/test/simple_test_tick_clock.h" |
| 7 #include "media/base/time_delta_interpolator.h" | 7 #include "media/base/time_delta_interpolator.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 EXPECT_EQ(kZero, interpolator_.StartInterpolating()); | 34 EXPECT_EQ(kZero, interpolator_.StartInterpolating()); |
| 35 AdvanceSystemTime(kTimeToAdvance); | 35 AdvanceSystemTime(kTimeToAdvance); |
| 36 EXPECT_EQ(kTimeToAdvance, interpolator_.GetInterpolatedTime()); | 36 EXPECT_EQ(kTimeToAdvance, interpolator_.GetInterpolatedTime()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 TEST_F(TimeDeltaInterpolatorTest, StartInterpolating_DoubleSpeed) { | 39 TEST_F(TimeDeltaInterpolatorTest, StartInterpolating_DoubleSpeed) { |
| 40 const base::TimeDelta kZero; | 40 const base::TimeDelta kZero; |
| 41 const base::TimeDelta kTimeToAdvance = base::TimeDelta::FromSeconds(5); | 41 const base::TimeDelta kTimeToAdvance = base::TimeDelta::FromSeconds(5); |
| 42 | 42 |
| 43 interpolator_.SetPlaybackRate(2.0f); | 43 interpolator_.SetPlaybackRate(2.0); |
| 44 EXPECT_EQ(kZero, interpolator_.StartInterpolating()); | 44 EXPECT_EQ(kZero, interpolator_.StartInterpolating()); |
| 45 AdvanceSystemTime(kTimeToAdvance); | 45 AdvanceSystemTime(kTimeToAdvance); |
| 46 EXPECT_EQ(2 * kTimeToAdvance, interpolator_.GetInterpolatedTime()); | 46 EXPECT_EQ(2 * kTimeToAdvance, interpolator_.GetInterpolatedTime()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 TEST_F(TimeDeltaInterpolatorTest, StartInterpolating_HalfSpeed) { | 49 TEST_F(TimeDeltaInterpolatorTest, StartInterpolating_HalfSpeed) { |
| 50 const base::TimeDelta kZero; | 50 const base::TimeDelta kZero; |
| 51 const base::TimeDelta kTimeToAdvance = base::TimeDelta::FromSeconds(4); | 51 const base::TimeDelta kTimeToAdvance = base::TimeDelta::FromSeconds(4); |
| 52 | 52 |
| 53 interpolator_.SetPlaybackRate(0.5f); | 53 interpolator_.SetPlaybackRate(0.5); |
| 54 EXPECT_EQ(kZero, interpolator_.StartInterpolating()); | 54 EXPECT_EQ(kZero, interpolator_.StartInterpolating()); |
| 55 AdvanceSystemTime(kTimeToAdvance); | 55 AdvanceSystemTime(kTimeToAdvance); |
| 56 EXPECT_EQ(kTimeToAdvance / 2, interpolator_.GetInterpolatedTime()); | 56 EXPECT_EQ(kTimeToAdvance / 2, interpolator_.GetInterpolatedTime()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 TEST_F(TimeDeltaInterpolatorTest, StartInterpolating_ZeroSpeed) { | 59 TEST_F(TimeDeltaInterpolatorTest, StartInterpolating_ZeroSpeed) { |
| 60 // We'll play for 2 seconds at normal speed, 4 seconds at zero speed, and 8 | 60 // We'll play for 2 seconds at normal speed, 4 seconds at zero speed, and 8 |
| 61 // seconds at normal speed. | 61 // seconds at normal speed. |
| 62 const base::TimeDelta kZero; | 62 const base::TimeDelta kZero; |
| 63 const base::TimeDelta kPlayDuration1 = base::TimeDelta::FromSeconds(2); | 63 const base::TimeDelta kPlayDuration1 = base::TimeDelta::FromSeconds(2); |
| 64 const base::TimeDelta kPlayDuration2 = base::TimeDelta::FromSeconds(4); | 64 const base::TimeDelta kPlayDuration2 = base::TimeDelta::FromSeconds(4); |
| 65 const base::TimeDelta kPlayDuration3 = base::TimeDelta::FromSeconds(8); | 65 const base::TimeDelta kPlayDuration3 = base::TimeDelta::FromSeconds(8); |
| 66 const base::TimeDelta kExpected = kPlayDuration1 + kPlayDuration3; | 66 const base::TimeDelta kExpected = kPlayDuration1 + kPlayDuration3; |
| 67 | 67 |
| 68 EXPECT_EQ(kZero, interpolator_.StartInterpolating()); | 68 EXPECT_EQ(kZero, interpolator_.StartInterpolating()); |
| 69 | 69 |
| 70 AdvanceSystemTime(kPlayDuration1); | 70 AdvanceSystemTime(kPlayDuration1); |
| 71 interpolator_.SetPlaybackRate(0.0f); | 71 interpolator_.SetPlaybackRate(0.0); |
| 72 AdvanceSystemTime(kPlayDuration2); | 72 AdvanceSystemTime(kPlayDuration2); |
| 73 interpolator_.SetPlaybackRate(1.0f); | 73 interpolator_.SetPlaybackRate(1.0); |
| 74 AdvanceSystemTime(kPlayDuration3); | 74 AdvanceSystemTime(kPlayDuration3); |
| 75 | 75 |
| 76 EXPECT_EQ(kExpected, interpolator_.GetInterpolatedTime()); | 76 EXPECT_EQ(kExpected, interpolator_.GetInterpolatedTime()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 TEST_F(TimeDeltaInterpolatorTest, StartInterpolating_MultiSpeed) { | 79 TEST_F(TimeDeltaInterpolatorTest, StartInterpolating_MultiSpeed) { |
| 80 // We'll play for 2 seconds at half speed, 4 seconds at normal speed, and 8 | 80 // We'll play for 2 seconds at half speed, 4 seconds at normal speed, and 8 |
| 81 // seconds at double speed. | 81 // seconds at double speed. |
| 82 const base::TimeDelta kZero; | 82 const base::TimeDelta kZero; |
| 83 const base::TimeDelta kPlayDuration1 = base::TimeDelta::FromSeconds(2); | 83 const base::TimeDelta kPlayDuration1 = base::TimeDelta::FromSeconds(2); |
| 84 const base::TimeDelta kPlayDuration2 = base::TimeDelta::FromSeconds(4); | 84 const base::TimeDelta kPlayDuration2 = base::TimeDelta::FromSeconds(4); |
| 85 const base::TimeDelta kPlayDuration3 = base::TimeDelta::FromSeconds(8); | 85 const base::TimeDelta kPlayDuration3 = base::TimeDelta::FromSeconds(8); |
| 86 const base::TimeDelta kExpected = | 86 const base::TimeDelta kExpected = |
| 87 kPlayDuration1 / 2 + kPlayDuration2 + 2 * kPlayDuration3; | 87 kPlayDuration1 / 2 + kPlayDuration2 + 2 * kPlayDuration3; |
| 88 | 88 |
| 89 interpolator_.SetPlaybackRate(0.5f); | 89 interpolator_.SetPlaybackRate(0.5); |
| 90 EXPECT_EQ(kZero, interpolator_.StartInterpolating()); | 90 EXPECT_EQ(kZero, interpolator_.StartInterpolating()); |
| 91 AdvanceSystemTime(kPlayDuration1); | 91 AdvanceSystemTime(kPlayDuration1); |
| 92 | 92 |
| 93 interpolator_.SetPlaybackRate(1.0f); | 93 interpolator_.SetPlaybackRate(1.0); |
| 94 AdvanceSystemTime(kPlayDuration2); | 94 AdvanceSystemTime(kPlayDuration2); |
| 95 | 95 |
| 96 interpolator_.SetPlaybackRate(2.0f); | 96 interpolator_.SetPlaybackRate(2.0); |
| 97 AdvanceSystemTime(kPlayDuration3); | 97 AdvanceSystemTime(kPlayDuration3); |
| 98 EXPECT_EQ(kExpected, interpolator_.GetInterpolatedTime()); | 98 EXPECT_EQ(kExpected, interpolator_.GetInterpolatedTime()); |
| 99 } | 99 } |
| 100 | 100 |
| 101 TEST_F(TimeDeltaInterpolatorTest, StopInterpolating) { | 101 TEST_F(TimeDeltaInterpolatorTest, StopInterpolating) { |
| 102 const base::TimeDelta kZero; | 102 const base::TimeDelta kZero; |
| 103 const base::TimeDelta kPlayDuration = base::TimeDelta::FromSeconds(4); | 103 const base::TimeDelta kPlayDuration = base::TimeDelta::FromSeconds(4); |
| 104 const base::TimeDelta kPauseDuration = base::TimeDelta::FromSeconds(20); | 104 const base::TimeDelta kPauseDuration = base::TimeDelta::FromSeconds(20); |
| 105 const base::TimeDelta kExpectedFirstPause = kPlayDuration; | 105 const base::TimeDelta kExpectedFirstPause = kPlayDuration; |
| 106 const base::TimeDelta kExpectedSecondPause = 2 * kPlayDuration; | 106 const base::TimeDelta kExpectedSecondPause = 2 * kPlayDuration; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 EXPECT_EQ(kMaxTime1, interpolator_.GetInterpolatedTime()); | 190 EXPECT_EQ(kMaxTime1, interpolator_.GetInterpolatedTime()); |
| 191 | 191 |
| 192 AdvanceSystemTime(kTimeInterval); | 192 AdvanceSystemTime(kTimeInterval); |
| 193 EXPECT_EQ(kMaxTime1 + kTimeInterval, interpolator_.GetInterpolatedTime()); | 193 EXPECT_EQ(kMaxTime1 + kTimeInterval, interpolator_.GetInterpolatedTime()); |
| 194 | 194 |
| 195 AdvanceSystemTime(kTimeInterval); | 195 AdvanceSystemTime(kTimeInterval); |
| 196 EXPECT_EQ(kMaxTime2, interpolator_.GetInterpolatedTime()); | 196 EXPECT_EQ(kMaxTime2, interpolator_.GetInterpolatedTime()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 } // namespace media | 199 } // namespace media |
| OLD | NEW |