OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/video/receive_statistics_proxy.h" | 11 #include "webrtc/video/receive_statistics_proxy.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
| 15 #include "webrtc/system_wrappers/include/metrics_default.h" |
15 #include "webrtc/test/gtest.h" | 16 #include "webrtc/test/gtest.h" |
16 | 17 |
17 namespace webrtc { | 18 namespace webrtc { |
| 19 namespace { |
| 20 const int64_t kFreqOffsetProcessIntervalInMs = 40000; |
| 21 } // namespace |
18 | 22 |
19 // TODO(sakal): ReceiveStatisticsProxy is lacking unittesting. | 23 // TODO(sakal): ReceiveStatisticsProxy is lacking unittesting. |
20 class ReceiveStatisticsProxyTest : public ::testing::Test { | 24 class ReceiveStatisticsProxyTest : public ::testing::Test { |
21 public: | 25 public: |
22 ReceiveStatisticsProxyTest() : fake_clock_(1234), config_(GetTestConfig()) {} | 26 ReceiveStatisticsProxyTest() : fake_clock_(1234), config_(GetTestConfig()) {} |
23 virtual ~ReceiveStatisticsProxyTest() {} | 27 virtual ~ReceiveStatisticsProxyTest() {} |
24 | 28 |
25 protected: | 29 protected: |
26 virtual void SetUp() { | 30 virtual void SetUp() { |
| 31 metrics::Reset(); |
27 statistics_proxy_.reset(new ReceiveStatisticsProxy(&config_, &fake_clock_)); | 32 statistics_proxy_.reset(new ReceiveStatisticsProxy(&config_, &fake_clock_)); |
28 } | 33 } |
29 | 34 |
30 VideoReceiveStream::Config GetTestConfig() { | 35 VideoReceiveStream::Config GetTestConfig() { |
31 VideoReceiveStream::Config config(nullptr); | 36 VideoReceiveStream::Config config(nullptr); |
32 return config; | 37 return config; |
33 } | 38 } |
34 | 39 |
35 SimulatedClock fake_clock_; | 40 SimulatedClock fake_clock_; |
| 41 const VideoReceiveStream::Config config_; |
36 std::unique_ptr<ReceiveStatisticsProxy> statistics_proxy_; | 42 std::unique_ptr<ReceiveStatisticsProxy> statistics_proxy_; |
37 VideoReceiveStream::Config config_; | |
38 }; | 43 }; |
39 | 44 |
40 TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameIncreasesFramesDecoded) { | 45 TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameIncreasesFramesDecoded) { |
41 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_decoded); | 46 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_decoded); |
42 for (uint32_t i = 1; i <= 3; ++i) { | 47 for (uint32_t i = 1; i <= 3; ++i) { |
43 statistics_proxy_->OnDecodedFrame(); | 48 statistics_proxy_->OnDecodedFrame(); |
44 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_decoded); | 49 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_decoded); |
45 } | 50 } |
46 } | 51 } |
47 | 52 |
| 53 TEST_F(ReceiveStatisticsProxyTest, RtpToNtpFrequencyOffsetHistogramIsUpdated) { |
| 54 const int64_t kSyncOffsetMs = 22; |
| 55 const double kFreqKhz = 90.0; |
| 56 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
| 57 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 2.2); |
| 58 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); |
| 59 // Process interval passed, max diff: 2. |
| 60 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 1.1); |
| 61 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 4.2); |
| 62 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 0.9); |
| 63 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); |
| 64 // Process interval passed, max diff: 4. |
| 65 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
| 66 statistics_proxy_.reset(); |
| 67 // Average reported: (2 + 4) / 2 = 3. |
| 68 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtpToNtpFreqOffsetInKhz")); |
| 69 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtpToNtpFreqOffsetInKhz", 3)); |
| 70 } |
| 71 |
48 } // namespace webrtc | 72 } // namespace webrtc |
OLD | NEW |