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.h" |
15 #include "webrtc/system_wrappers/include/metrics_default.h" | 16 #include "webrtc/system_wrappers/include/metrics_default.h" |
16 #include "webrtc/test/gtest.h" | 17 #include "webrtc/test/gtest.h" |
17 | 18 |
18 namespace webrtc { | 19 namespace webrtc { |
19 namespace { | 20 namespace { |
20 const int64_t kFreqOffsetProcessIntervalInMs = 40000; | 21 const int64_t kFreqOffsetProcessIntervalInMs = 40000; |
21 const uint32_t kLocalSsrc = 123; | 22 const uint32_t kLocalSsrc = 123; |
22 const uint32_t kRemoteSsrc = 456; | 23 const uint32_t kRemoteSsrc = 456; |
23 const int kMinRequiredSamples = 200; | 24 const int kMinRequiredSamples = 200; |
24 } // namespace | 25 } // namespace |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 const int64_t kTimeSec = 3; | 106 const int64_t kTimeSec = 3; |
106 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000); | 107 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000); |
107 // Histograms are updated when the statistics_proxy_ is deleted. | 108 // Histograms are updated when the statistics_proxy_ is deleted. |
108 statistics_proxy_.reset(); | 109 statistics_proxy_.reset(); |
109 EXPECT_EQ(1, | 110 EXPECT_EQ(1, |
110 metrics::NumSamples("WebRTC.Video.ReceiveStreamLifetimeInSeconds")); | 111 metrics::NumSamples("WebRTC.Video.ReceiveStreamLifetimeInSeconds")); |
111 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceiveStreamLifetimeInSeconds", | 112 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceiveStreamLifetimeInSeconds", |
112 kTimeSec)); | 113 kTimeSec)); |
113 } | 114 } |
114 | 115 |
| 116 TEST_F(ReceiveStatisticsProxyTest, PacketLossHistogramIsUpdated) { |
| 117 const uint32_t kCumLost1 = 1; |
| 118 const uint32_t kExtSeqNum1 = 10; |
| 119 const uint32_t kCumLost2 = 2; |
| 120 const uint32_t kExtSeqNum2 = 20; |
| 121 |
| 122 // One report block received. |
| 123 RtcpStatistics rtcp_stats1; |
| 124 rtcp_stats1.cumulative_lost = kCumLost1; |
| 125 rtcp_stats1.extended_max_sequence_number = kExtSeqNum1; |
| 126 statistics_proxy_->StatisticsUpdated(rtcp_stats1, kRemoteSsrc); |
| 127 |
| 128 // Two report blocks received. |
| 129 RtcpStatistics rtcp_stats2; |
| 130 rtcp_stats2.cumulative_lost = kCumLost2; |
| 131 rtcp_stats2.extended_max_sequence_number = kExtSeqNum2; |
| 132 statistics_proxy_->StatisticsUpdated(rtcp_stats2, kRemoteSsrc); |
| 133 |
| 134 // Two received report blocks but min run time has not passed. |
| 135 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000 - 1); |
| 136 SetUp(); // Reset stat proxy causes histograms to be updated. |
| 137 EXPECT_EQ(0, |
| 138 metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent")); |
| 139 |
| 140 // Two report blocks received. |
| 141 statistics_proxy_->StatisticsUpdated(rtcp_stats1, kRemoteSsrc); |
| 142 statistics_proxy_->StatisticsUpdated(rtcp_stats2, kRemoteSsrc); |
| 143 |
| 144 // Two received report blocks and min run time has passed. |
| 145 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
| 146 SetUp(); |
| 147 EXPECT_EQ(1, |
| 148 metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent")); |
| 149 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceivedPacketsLostInPercent", |
| 150 (kCumLost2 - kCumLost1) * 100 / |
| 151 (kExtSeqNum2 - kExtSeqNum1))); |
| 152 } |
| 153 |
| 154 TEST_F(ReceiveStatisticsProxyTest, |
| 155 PacketLossHistogramIsNotUpdatedIfLessThanTwoReportBlocksAreReceived) { |
| 156 RtcpStatistics rtcp_stats1; |
| 157 rtcp_stats1.cumulative_lost = 1; |
| 158 rtcp_stats1.extended_max_sequence_number = 10; |
| 159 |
| 160 // Min run time has passed but no received report block. |
| 161 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
| 162 SetUp(); // Reset stat proxy causes histograms to be updated. |
| 163 EXPECT_EQ(0, |
| 164 metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent")); |
| 165 |
| 166 // Min run time has passed but only one received report block. |
| 167 statistics_proxy_->StatisticsUpdated(rtcp_stats1, kRemoteSsrc); |
| 168 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
| 169 SetUp(); |
| 170 EXPECT_EQ(0, |
| 171 metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent")); |
| 172 } |
| 173 |
115 TEST_F(ReceiveStatisticsProxyTest, AvSyncOffsetHistogramIsUpdated) { | 174 TEST_F(ReceiveStatisticsProxyTest, AvSyncOffsetHistogramIsUpdated) { |
116 const int64_t kSyncOffsetMs = 22; | 175 const int64_t kSyncOffsetMs = 22; |
117 const double kFreqKhz = 90.0; | 176 const double kFreqKhz = 90.0; |
118 for (int i = 0; i < kMinRequiredSamples; ++i) | 177 for (int i = 0; i < kMinRequiredSamples; ++i) |
119 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); | 178 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
120 // Histograms are updated when the statistics_proxy_ is deleted. | 179 // Histograms are updated when the statistics_proxy_ is deleted. |
121 statistics_proxy_.reset(); | 180 statistics_proxy_.reset(); |
122 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AVSyncOffsetInMs")); | 181 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AVSyncOffsetInMs")); |
123 EXPECT_EQ(1, | 182 EXPECT_EQ(1, |
124 metrics::NumEvents("WebRTC.Video.AVSyncOffsetInMs", kSyncOffsetMs)); | 183 metrics::NumEvents("WebRTC.Video.AVSyncOffsetInMs", kSyncOffsetMs)); |
(...skipping 12 matching lines...) Expand all Loading... |
137 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); | 196 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); |
138 // Process interval passed, max diff: 4. | 197 // Process interval passed, max diff: 4. |
139 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); | 198 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
140 statistics_proxy_.reset(); | 199 statistics_proxy_.reset(); |
141 // Average reported: (2 + 4) / 2 = 3. | 200 // Average reported: (2 + 4) / 2 = 3. |
142 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtpToNtpFreqOffsetInKhz")); | 201 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtpToNtpFreqOffsetInKhz")); |
143 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtpToNtpFreqOffsetInKhz", 3)); | 202 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtpToNtpFreqOffsetInKhz", 3)); |
144 } | 203 } |
145 | 204 |
146 } // namespace webrtc | 205 } // namespace webrtc |
OLD | NEW |