| 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 "media/cast/logging/receiver_time_offset_estimator_impl.h" | 5 #include "media/cast/logging/receiver_time_offset_estimator_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/test/simple_test_tick_clock.h" | 12 #include "base/test/simple_test_tick_clock.h" |
| 13 #include "base/time/tick_clock.h" | 13 #include "base/time/tick_clock.h" |
| 14 #include "media/base/fake_single_thread_task_runner.h" |
| 14 #include "media/cast/cast_environment.h" | 15 #include "media/cast/cast_environment.h" |
| 15 #include "media/cast/logging/logging_defines.h" | 16 #include "media/cast/logging/logging_defines.h" |
| 16 #include "media/cast/test/fake_single_thread_task_runner.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace media { | 19 namespace media { |
| 20 namespace cast { | 20 namespace cast { |
| 21 | 21 |
| 22 class ReceiverTimeOffsetEstimatorImplTest : public ::testing::Test { | 22 class ReceiverTimeOffsetEstimatorImplTest : public ::testing::Test { |
| 23 protected: | 23 protected: |
| 24 ReceiverTimeOffsetEstimatorImplTest() | 24 ReceiverTimeOffsetEstimatorImplTest() |
| 25 : sender_clock_(new base::SimpleTestTickClock()), | 25 : sender_clock_(new base::SimpleTestTickClock()), |
| 26 task_runner_(new test::FakeSingleThreadTaskRunner(sender_clock_)), | 26 task_runner_(new FakeSingleThreadTaskRunner(sender_clock_)), |
| 27 cast_environment_( | 27 cast_environment_( |
| 28 new CastEnvironment(scoped_ptr<base::TickClock>(sender_clock_), | 28 new CastEnvironment(scoped_ptr<base::TickClock>(sender_clock_), |
| 29 task_runner_, | 29 task_runner_, |
| 30 task_runner_, | 30 task_runner_, |
| 31 task_runner_)) { | 31 task_runner_)) { |
| 32 cast_environment_->logger()->Subscribe(&estimator_); | 32 cast_environment_->logger()->Subscribe(&estimator_); |
| 33 } | 33 } |
| 34 | 34 |
| 35 ~ReceiverTimeOffsetEstimatorImplTest() override { | 35 ~ReceiverTimeOffsetEstimatorImplTest() override { |
| 36 cast_environment_->logger()->Unsubscribe(&estimator_); | 36 cast_environment_->logger()->Unsubscribe(&estimator_); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void AdvanceClocks(base::TimeDelta time) { | 39 void AdvanceClocks(base::TimeDelta time) { |
| 40 task_runner_->Sleep(time); | 40 task_runner_->Sleep(time); |
| 41 receiver_clock_.Advance(time); | 41 receiver_clock_.Advance(time); |
| 42 } | 42 } |
| 43 | 43 |
| 44 base::SimpleTestTickClock* sender_clock_; // Owned by CastEnvironment. | 44 base::SimpleTestTickClock* sender_clock_; // Owned by CastEnvironment. |
| 45 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; | 45 scoped_refptr<FakeSingleThreadTaskRunner> task_runner_; |
| 46 scoped_refptr<CastEnvironment> cast_environment_; | 46 scoped_refptr<CastEnvironment> cast_environment_; |
| 47 base::SimpleTestTickClock receiver_clock_; | 47 base::SimpleTestTickClock receiver_clock_; |
| 48 ReceiverTimeOffsetEstimatorImpl estimator_; | 48 ReceiverTimeOffsetEstimatorImpl estimator_; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // Suppose the true offset is 100ms. | 51 // Suppose the true offset is 100ms. |
| 52 // Event A occurred at sender time 20ms. | 52 // Event A occurred at sender time 20ms. |
| 53 // Event B occurred at receiver time 130ms. (sender time 30ms) | 53 // Event B occurred at receiver time 130ms. (sender time 30ms) |
| 54 // Event C occurred at sender time 60ms. | 54 // Event C occurred at sender time 60ms. |
| 55 // Then the bound after all 3 events have arrived is [130-60=70, 130-20=110]. | 55 // Then the bound after all 3 events have arrived is [130-60=70, 130-20=110]. |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 int64_t lower_bound_ms = lower_bound.InMilliseconds(); | 396 int64_t lower_bound_ms = lower_bound.InMilliseconds(); |
| 397 int64_t upper_bound_ms = upper_bound.InMilliseconds(); | 397 int64_t upper_bound_ms = upper_bound.InMilliseconds(); |
| 398 EXPECT_GT(lower_bound_ms, 90); | 398 EXPECT_GT(lower_bound_ms, 90); |
| 399 EXPECT_LE(lower_bound_ms, true_offset_ms); | 399 EXPECT_LE(lower_bound_ms, true_offset_ms); |
| 400 EXPECT_LT(upper_bound_ms, 150); | 400 EXPECT_LT(upper_bound_ms, 150); |
| 401 EXPECT_GT(upper_bound_ms, true_offset_ms); | 401 EXPECT_GT(upper_bound_ms, true_offset_ms); |
| 402 } | 402 } |
| 403 | 403 |
| 404 } // namespace cast | 404 } // namespace cast |
| 405 } // namespace media | 405 } // namespace media |
| OLD | NEW |