Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: webrtc/video/receive_statistics_proxy_unittest.cc

Issue 2577073002: ReceiveStatisticsProxy: add some unit tests, change members from int to int64_t. (Closed)
Patch Set: add unit tests Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/receive_statistics_proxy.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/modules/video_coding/include/video_codec_interface.h"
15 #include "webrtc/system_wrappers/include/metrics.h" 16 #include "webrtc/system_wrappers/include/metrics.h"
16 #include "webrtc/system_wrappers/include/metrics_default.h" 17 #include "webrtc/system_wrappers/include/metrics_default.h"
17 #include "webrtc/test/gtest.h" 18 #include "webrtc/test/gtest.h"
18 19
19 namespace webrtc { 20 namespace webrtc {
20 namespace { 21 namespace {
21 const int64_t kFreqOffsetProcessIntervalInMs = 40000; 22 const int64_t kFreqOffsetProcessIntervalInMs = 40000;
22 const uint32_t kLocalSsrc = 123; 23 const uint32_t kLocalSsrc = 123;
23 const uint32_t kRemoteSsrc = 456; 24 const uint32_t kRemoteSsrc = 456;
24 const int kMinRequiredSamples = 200; 25 const int kMinRequiredSamples = 200;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsSsrc) { 60 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsSsrc) {
60 EXPECT_EQ(kRemoteSsrc, statistics_proxy_->GetStats().ssrc); 61 EXPECT_EQ(kRemoteSsrc, statistics_proxy_->GetStats().ssrc);
61 } 62 }
62 63
63 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsIncomingPayloadType) { 64 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsIncomingPayloadType) {
64 const int kPayloadType = 111; 65 const int kPayloadType = 111;
65 statistics_proxy_->OnIncomingPayloadType(kPayloadType); 66 statistics_proxy_->OnIncomingPayloadType(kPayloadType);
66 EXPECT_EQ(kPayloadType, statistics_proxy_->GetStats().current_payload_type); 67 EXPECT_EQ(kPayloadType, statistics_proxy_->GetStats().current_payload_type);
67 } 68 }
68 69
70 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDecoderImplementationName) {
71 const char* kName = "decoderName";
72 statistics_proxy_->OnDecoderImplementationName(kName);
73 EXPECT_STREQ(
74 kName, statistics_proxy_->GetStats().decoder_implementation_name.c_str());
75 }
76
69 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsIncomingRate) { 77 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsIncomingRate) {
70 const int kFramerate = 28; 78 const int kFramerate = 28;
71 const int kBitrateBps = 311000; 79 const int kBitrateBps = 311000;
72 statistics_proxy_->OnIncomingRate(kFramerate, kBitrateBps); 80 statistics_proxy_->OnIncomingRate(kFramerate, kBitrateBps);
73 EXPECT_EQ(kFramerate, statistics_proxy_->GetStats().network_frame_rate); 81 EXPECT_EQ(kFramerate, statistics_proxy_->GetStats().network_frame_rate);
74 EXPECT_EQ(kBitrateBps, statistics_proxy_->GetStats().total_bitrate_bps); 82 EXPECT_EQ(kBitrateBps, statistics_proxy_->GetStats().total_bitrate_bps);
75 } 83 }
76 84
77 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDecodeTimingStats) { 85 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDecodeTimingStats) {
78 const int kDecodeMs = 1; 86 const int kDecodeMs = 1;
(...skipping 10 matching lines...) Expand all
89 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats(); 97 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
90 EXPECT_EQ(kDecodeMs, stats.decode_ms); 98 EXPECT_EQ(kDecodeMs, stats.decode_ms);
91 EXPECT_EQ(kMaxDecodeMs, stats.max_decode_ms); 99 EXPECT_EQ(kMaxDecodeMs, stats.max_decode_ms);
92 EXPECT_EQ(kCurrentDelayMs, stats.current_delay_ms); 100 EXPECT_EQ(kCurrentDelayMs, stats.current_delay_ms);
93 EXPECT_EQ(kTargetDelayMs, stats.target_delay_ms); 101 EXPECT_EQ(kTargetDelayMs, stats.target_delay_ms);
94 EXPECT_EQ(kJitterBufferMs, stats.jitter_buffer_ms); 102 EXPECT_EQ(kJitterBufferMs, stats.jitter_buffer_ms);
95 EXPECT_EQ(kMinPlayoutDelayMs, stats.min_playout_delay_ms); 103 EXPECT_EQ(kMinPlayoutDelayMs, stats.min_playout_delay_ms);
96 EXPECT_EQ(kRenderDelayMs, stats.render_delay_ms); 104 EXPECT_EQ(kRenderDelayMs, stats.render_delay_ms);
97 } 105 }
98 106
107 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsRtcpPacketTypeCounts) {
108 const uint32_t kFirPackets = 33;
109 const uint32_t kPliPackets = 44;
110 const uint32_t kNackPackets = 55;
111 RtcpPacketTypeCounter counter;
112 counter.fir_packets = kFirPackets;
113 counter.pli_packets = kPliPackets;
114 counter.nack_packets = kNackPackets;
115 statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc, counter);
116 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
117 EXPECT_EQ(kFirPackets, stats.rtcp_packet_type_counts.fir_packets);
118 EXPECT_EQ(kPliPackets, stats.rtcp_packet_type_counts.pli_packets);
119 EXPECT_EQ(kNackPackets, stats.rtcp_packet_type_counts.nack_packets);
120 }
121
122 TEST_F(ReceiveStatisticsProxyTest,
123 GetStatsReportsNoRtcpPacketTypeCountsForUnknownSsrc) {
124 RtcpPacketTypeCounter counter;
125 counter.fir_packets = 33;
126 statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc + 1, counter);
127 EXPECT_EQ(0u,
128 statistics_proxy_->GetStats().rtcp_packet_type_counts.fir_packets);
129 }
130
131 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsFrameCounts) {
132 const int kKeyFrames = 3;
133 const int kDeltaFrames = 22;
134 FrameCounts frame_counts;
135 frame_counts.key_frames = kKeyFrames;
136 frame_counts.delta_frames = kDeltaFrames;
137 statistics_proxy_->OnFrameCountsUpdated(frame_counts);
138 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
139 EXPECT_EQ(kKeyFrames, stats.frame_counts.key_frames);
140 EXPECT_EQ(kDeltaFrames, stats.frame_counts.delta_frames);
141 }
142
99 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDiscardedPackets) { 143 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDiscardedPackets) {
100 const int kDiscardedPackets = 12; 144 const int kDiscardedPackets = 12;
101 statistics_proxy_->OnDiscardedPacketsUpdated(kDiscardedPackets); 145 statistics_proxy_->OnDiscardedPacketsUpdated(kDiscardedPackets);
102 EXPECT_EQ(kDiscardedPackets, statistics_proxy_->GetStats().discarded_packets); 146 EXPECT_EQ(kDiscardedPackets, statistics_proxy_->GetStats().discarded_packets);
103 } 147 }
104 148
149 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsRtcpStats) {
150 const uint8_t kFracLost = 0;
151 const uint32_t kCumLost = 1;
152 const uint32_t kExtSeqNum = 10;
153 const uint32_t kJitter = 4;
154
155 RtcpStatistics rtcp_stats;
156 rtcp_stats.fraction_lost = kFracLost;
157 rtcp_stats.cumulative_lost = kCumLost;
158 rtcp_stats.extended_max_sequence_number = kExtSeqNum;
159 rtcp_stats.jitter = kJitter;
160 statistics_proxy_->StatisticsUpdated(rtcp_stats, kRemoteSsrc);
161
162 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
163 EXPECT_EQ(kFracLost, stats.rtcp_stats.fraction_lost);
164 EXPECT_EQ(kCumLost, stats.rtcp_stats.cumulative_lost);
165 EXPECT_EQ(kExtSeqNum, stats.rtcp_stats.extended_max_sequence_number);
166 EXPECT_EQ(kJitter, stats.rtcp_stats.jitter);
167 }
168
169 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsCName) {
170 const char* kName = "cName";
171 statistics_proxy_->CNameChanged(kName, kRemoteSsrc);
172 EXPECT_STREQ(kName, statistics_proxy_->GetStats().c_name.c_str());
173 }
174
175 TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsNoCNameForUnknownSsrc) {
176 const char* kName = "cName";
177 statistics_proxy_->CNameChanged(kName, kRemoteSsrc + 1);
178 EXPECT_STREQ("", statistics_proxy_->GetStats().c_name.c_str());
179 }
180
105 TEST_F(ReceiveStatisticsProxyTest, LifetimeHistogramIsUpdated) { 181 TEST_F(ReceiveStatisticsProxyTest, LifetimeHistogramIsUpdated) {
106 const int64_t kTimeSec = 3; 182 const int64_t kTimeSec = 3;
107 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000); 183 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000);
108 // Histograms are updated when the statistics_proxy_ is deleted. 184 // Histograms are updated when the statistics_proxy_ is deleted.
109 statistics_proxy_.reset(); 185 statistics_proxy_.reset();
110 EXPECT_EQ(1, 186 EXPECT_EQ(1,
111 metrics::NumSamples("WebRTC.Video.ReceiveStreamLifetimeInSeconds")); 187 metrics::NumSamples("WebRTC.Video.ReceiveStreamLifetimeInSeconds"));
112 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceiveStreamLifetimeInSeconds", 188 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceiveStreamLifetimeInSeconds",
113 kTimeSec)); 189 kTimeSec));
114 } 190 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 0.9); 271 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 0.9);
196 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); 272 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs);
197 // Process interval passed, max diff: 4. 273 // Process interval passed, max diff: 4.
198 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); 274 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz);
199 statistics_proxy_.reset(); 275 statistics_proxy_.reset();
200 // Average reported: (2 + 4) / 2 = 3. 276 // Average reported: (2 + 4) / 2 = 3.
201 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtpToNtpFreqOffsetInKhz")); 277 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtpToNtpFreqOffsetInKhz"));
202 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtpToNtpFreqOffsetInKhz", 3)); 278 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtpToNtpFreqOffsetInKhz", 3));
203 } 279 }
204 280
281 TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsUpdated) {
282 const int kQp = 22;
283 EncodedImage encoded_image;
284 encoded_image.qp_ = kQp;
285 CodecSpecificInfo codec_info;
286 codec_info.codecType = kVideoCodecVP8;
287
288 for (int i = 0; i < kMinRequiredSamples; ++i)
289 statistics_proxy_->OnPreDecode(encoded_image, &codec_info);
290
291 statistics_proxy_.reset();
292 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp"));
293 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Decoded.Vp8.Qp", kQp));
294 }
295
296 TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsNotUpdatedForTooFewSamples) {
297 EncodedImage encoded_image;
298 encoded_image.qp_ = 22;
299 CodecSpecificInfo codec_info;
300 codec_info.codecType = kVideoCodecVP8;
301
302 for (int i = 0; i < kMinRequiredSamples - 1; ++i)
303 statistics_proxy_->OnPreDecode(encoded_image, &codec_info);
304
305 statistics_proxy_.reset();
306 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp"));
307 }
308
309 TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsNotUpdatedIfNoQpValue) {
310 EncodedImage encoded_image;
311 CodecSpecificInfo codec_info;
312 codec_info.codecType = kVideoCodecVP8;
313
314 for (int i = 0; i < kMinRequiredSamples; ++i)
315 statistics_proxy_->OnPreDecode(encoded_image, &codec_info);
316
317 statistics_proxy_.reset();
318 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp"));
319 }
320
205 } // namespace webrtc 321 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/receive_statistics_proxy.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698