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/system_wrappers/include/metrics_default.h" |
16 #include "webrtc/test/gtest.h" | 16 #include "webrtc/test/gtest.h" |
17 | 17 |
18 namespace webrtc { | 18 namespace webrtc { |
19 namespace { | 19 namespace { |
20 const int64_t kFreqOffsetProcessIntervalInMs = 40000; | 20 const int64_t kFreqOffsetProcessIntervalInMs = 40000; |
| 21 const uint32_t kLocalSsrc = 123; |
| 22 const uint32_t kRemoteSsrc = 456; |
| 23 const int kMinRequiredSamples = 200; |
21 } // namespace | 24 } // namespace |
22 | 25 |
23 // TODO(sakal): ReceiveStatisticsProxy is lacking unittesting. | 26 // TODO(sakal): ReceiveStatisticsProxy is lacking unittesting. |
24 class ReceiveStatisticsProxyTest : public ::testing::Test { | 27 class ReceiveStatisticsProxyTest : public ::testing::Test { |
25 public: | 28 public: |
26 ReceiveStatisticsProxyTest() : fake_clock_(1234), config_(GetTestConfig()) {} | 29 ReceiveStatisticsProxyTest() : fake_clock_(1234), config_(GetTestConfig()) {} |
27 virtual ~ReceiveStatisticsProxyTest() {} | 30 virtual ~ReceiveStatisticsProxyTest() {} |
28 | 31 |
29 protected: | 32 protected: |
30 virtual void SetUp() { | 33 virtual void SetUp() { |
31 metrics::Reset(); | 34 metrics::Reset(); |
32 statistics_proxy_.reset(new ReceiveStatisticsProxy(&config_, &fake_clock_)); | 35 statistics_proxy_.reset(new ReceiveStatisticsProxy(&config_, &fake_clock_)); |
33 } | 36 } |
34 | 37 |
35 VideoReceiveStream::Config GetTestConfig() { | 38 VideoReceiveStream::Config GetTestConfig() { |
36 VideoReceiveStream::Config config(nullptr); | 39 VideoReceiveStream::Config config(nullptr); |
| 40 config.rtp.local_ssrc = kLocalSsrc; |
| 41 config.rtp.remote_ssrc = kRemoteSsrc; |
37 return config; | 42 return config; |
38 } | 43 } |
39 | 44 |
40 SimulatedClock fake_clock_; | 45 SimulatedClock fake_clock_; |
41 const VideoReceiveStream::Config config_; | 46 const VideoReceiveStream::Config config_; |
42 std::unique_ptr<ReceiveStatisticsProxy> statistics_proxy_; | 47 std::unique_ptr<ReceiveStatisticsProxy> statistics_proxy_; |
43 }; | 48 }; |
44 | 49 |
45 TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameIncreasesFramesDecoded) { | 50 TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameIncreasesFramesDecoded) { |
46 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_decoded); | 51 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_decoded); |
47 for (uint32_t i = 1; i <= 3; ++i) { | 52 for (uint32_t i = 1; i <= 3; ++i) { |
48 statistics_proxy_->OnDecodedFrame(); | 53 statistics_proxy_->OnDecodedFrame(); |
49 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_decoded); | 54 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_decoded); |
50 } | 55 } |
51 } | 56 } |
52 | 57 |
| 58 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsSsrc) { |
| 59 EXPECT_EQ(kRemoteSsrc, statistics_proxy_->GetStats().ssrc); |
| 60 } |
| 61 |
| 62 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsIncomingPayloadType) { |
| 63 const int kPayloadType = 111; |
| 64 statistics_proxy_->OnIncomingPayloadType(kPayloadType); |
| 65 EXPECT_EQ(kPayloadType, statistics_proxy_->GetStats().current_payload_type); |
| 66 } |
| 67 |
| 68 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsIncomingRate) { |
| 69 const int kFramerate = 28; |
| 70 const int kBitrateBps = 311000; |
| 71 statistics_proxy_->OnIncomingRate(kFramerate, kBitrateBps); |
| 72 EXPECT_EQ(kFramerate, statistics_proxy_->GetStats().network_frame_rate); |
| 73 EXPECT_EQ(kBitrateBps, statistics_proxy_->GetStats().total_bitrate_bps); |
| 74 } |
| 75 |
| 76 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDecodeTimingStats) { |
| 77 const int kDecodeMs = 1; |
| 78 const int kMaxDecodeMs = 2; |
| 79 const int kCurrentDelayMs = 3; |
| 80 const int kTargetDelayMs = 4; |
| 81 const int kJitterBufferMs = 5; |
| 82 const int kMinPlayoutDelayMs = 6; |
| 83 const int kRenderDelayMs = 7; |
| 84 const int64_t kRttMs = 8; |
| 85 statistics_proxy_->OnDecoderTiming( |
| 86 kDecodeMs, kMaxDecodeMs, kCurrentDelayMs, kTargetDelayMs, kJitterBufferMs, |
| 87 kMinPlayoutDelayMs, kRenderDelayMs, kRttMs); |
| 88 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats(); |
| 89 EXPECT_EQ(kDecodeMs, stats.decode_ms); |
| 90 EXPECT_EQ(kMaxDecodeMs, stats.max_decode_ms); |
| 91 EXPECT_EQ(kCurrentDelayMs, stats.current_delay_ms); |
| 92 EXPECT_EQ(kTargetDelayMs, stats.target_delay_ms); |
| 93 EXPECT_EQ(kJitterBufferMs, stats.jitter_buffer_ms); |
| 94 EXPECT_EQ(kMinPlayoutDelayMs, stats.min_playout_delay_ms); |
| 95 EXPECT_EQ(kRenderDelayMs, stats.render_delay_ms); |
| 96 } |
| 97 |
| 98 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDiscardedPackets) { |
| 99 const int kDiscardedPackets = 12; |
| 100 statistics_proxy_->OnDiscardedPacketsUpdated(kDiscardedPackets); |
| 101 EXPECT_EQ(kDiscardedPackets, statistics_proxy_->GetStats().discarded_packets); |
| 102 } |
| 103 |
| 104 TEST_F(ReceiveStatisticsProxyTest, LifetimeHistogramIsUpdated) { |
| 105 const int64_t kTimeSec = 3; |
| 106 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000); |
| 107 // Histograms are updated when the statistics_proxy_ is deleted. |
| 108 statistics_proxy_.reset(); |
| 109 EXPECT_EQ(1, |
| 110 metrics::NumSamples("WebRTC.Video.ReceiveStreamLifetimeInSeconds")); |
| 111 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceiveStreamLifetimeInSeconds", |
| 112 kTimeSec)); |
| 113 } |
| 114 |
| 115 TEST_F(ReceiveStatisticsProxyTest, AvSyncOffsetHistogramIsUpdated) { |
| 116 const int64_t kSyncOffsetMs = 22; |
| 117 const double kFreqKhz = 90.0; |
| 118 for (int i = 0; i < kMinRequiredSamples; ++i) |
| 119 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
| 120 // Histograms are updated when the statistics_proxy_ is deleted. |
| 121 statistics_proxy_.reset(); |
| 122 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AVSyncOffsetInMs")); |
| 123 EXPECT_EQ(1, |
| 124 metrics::NumEvents("WebRTC.Video.AVSyncOffsetInMs", kSyncOffsetMs)); |
| 125 } |
| 126 |
53 TEST_F(ReceiveStatisticsProxyTest, RtpToNtpFrequencyOffsetHistogramIsUpdated) { | 127 TEST_F(ReceiveStatisticsProxyTest, RtpToNtpFrequencyOffsetHistogramIsUpdated) { |
54 const int64_t kSyncOffsetMs = 22; | 128 const int64_t kSyncOffsetMs = 22; |
55 const double kFreqKhz = 90.0; | 129 const double kFreqKhz = 90.0; |
56 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); | 130 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
57 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 2.2); | 131 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 2.2); |
58 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); | 132 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); |
59 // Process interval passed, max diff: 2. | 133 // Process interval passed, max diff: 2. |
60 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 1.1); | 134 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 1.1); |
61 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 4.2); | 135 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 4.2); |
62 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 0.9); | 136 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 0.9); |
63 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); | 137 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); |
64 // Process interval passed, max diff: 4. | 138 // Process interval passed, max diff: 4. |
65 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); | 139 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
66 statistics_proxy_.reset(); | 140 statistics_proxy_.reset(); |
67 // Average reported: (2 + 4) / 2 = 3. | 141 // Average reported: (2 + 4) / 2 = 3. |
68 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtpToNtpFreqOffsetInKhz")); | 142 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtpToNtpFreqOffsetInKhz")); |
69 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtpToNtpFreqOffsetInKhz", 3)); | 143 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtpToNtpFreqOffsetInKhz", 3)); |
70 } | 144 } |
71 | 145 |
72 } // namespace webrtc | 146 } // namespace webrtc |
OLD | NEW |