blob: e219542768ecc630b361d2db6413710039ed5cbe [file] [log] [blame]
sakale5ba44e2016-10-26 07:09:24 -07001/*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/video/receive_statistics_proxy.h"
12
asapersson2077f2f2017-05-11 05:37:35 -070013#include <limits>
sakale5ba44e2016-10-26 07:09:24 -070014#include <memory>
15
nissef93752a2017-05-10 05:25:59 -070016#include "webrtc/api/video/i420_buffer.h"
hbos50cfe1f2017-01-23 07:21:55 -080017#include "webrtc/api/video/video_frame.h"
18#include "webrtc/api/video/video_rotation.h"
asapersson6966bd52017-01-03 00:44:06 -080019#include "webrtc/modules/video_coding/include/video_codec_interface.h"
asapersson0c43f772016-11-30 01:42:26 -080020#include "webrtc/system_wrappers/include/metrics.h"
asaperssonde9e5ff2016-11-02 07:14:03 -070021#include "webrtc/system_wrappers/include/metrics_default.h"
sakale5ba44e2016-10-26 07:09:24 -070022#include "webrtc/test/gtest.h"
23
24namespace webrtc {
asaperssonde9e5ff2016-11-02 07:14:03 -070025namespace {
26const int64_t kFreqOffsetProcessIntervalInMs = 40000;
asapersson46c4e3c2016-11-03 06:48:19 -070027const uint32_t kLocalSsrc = 123;
28const uint32_t kRemoteSsrc = 456;
29const int kMinRequiredSamples = 200;
asaperssonde9e5ff2016-11-02 07:14:03 -070030} // namespace
sakale5ba44e2016-10-26 07:09:24 -070031
32// TODO(sakal): ReceiveStatisticsProxy is lacking unittesting.
33class ReceiveStatisticsProxyTest : public ::testing::Test {
34 public:
35 ReceiveStatisticsProxyTest() : fake_clock_(1234), config_(GetTestConfig()) {}
36 virtual ~ReceiveStatisticsProxyTest() {}
37
38 protected:
39 virtual void SetUp() {
asaperssonde9e5ff2016-11-02 07:14:03 -070040 metrics::Reset();
sakale5ba44e2016-10-26 07:09:24 -070041 statistics_proxy_.reset(new ReceiveStatisticsProxy(&config_, &fake_clock_));
42 }
43
44 VideoReceiveStream::Config GetTestConfig() {
45 VideoReceiveStream::Config config(nullptr);
asapersson46c4e3c2016-11-03 06:48:19 -070046 config.rtp.local_ssrc = kLocalSsrc;
47 config.rtp.remote_ssrc = kRemoteSsrc;
sakale5ba44e2016-10-26 07:09:24 -070048 return config;
49 }
50
asapersson2077f2f2017-05-11 05:37:35 -070051 void InsertFirstRtpPacket(uint32_t ssrc) {
52 StreamDataCounters counters;
53 counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds();
54 statistics_proxy_->DataCountersUpdated(counters, ssrc);
55 }
56
57 VideoFrame CreateFrame(int width, int height) {
58 VideoFrame frame(I420Buffer::Create(width, height), 0, 0, kVideoRotation_0);
59 frame.set_ntp_time_ms(fake_clock_.CurrentNtpInMilliseconds());
60 return frame;
61 }
62
sakale5ba44e2016-10-26 07:09:24 -070063 SimulatedClock fake_clock_;
asaperssonde9e5ff2016-11-02 07:14:03 -070064 const VideoReceiveStream::Config config_;
sakale5ba44e2016-10-26 07:09:24 -070065 std::unique_ptr<ReceiveStatisticsProxy> statistics_proxy_;
sakale5ba44e2016-10-26 07:09:24 -070066};
67
68TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameIncreasesFramesDecoded) {
69 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_decoded);
70 for (uint32_t i = 1; i <= 3; ++i) {
ilnik00d802b2017-04-11 10:34:31 -070071 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(),
72 VideoContentType::UNSPECIFIED);
sakale5ba44e2016-10-26 07:09:24 -070073 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_decoded);
74 }
75}
76
sakalcc452e12017-02-09 04:53:45 -080077TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameWithQpResetsFramesDecoded) {
78 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_decoded);
79 for (uint32_t i = 1; i <= 3; ++i) {
ilnik00d802b2017-04-11 10:34:31 -070080 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(),
81 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -080082 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_decoded);
83 }
ilnik00d802b2017-04-11 10:34:31 -070084 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(1u),
85 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -080086 EXPECT_EQ(1u, statistics_proxy_->GetStats().frames_decoded);
87}
88
89TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameIncreasesQpSum) {
90 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
ilnik00d802b2017-04-11 10:34:31 -070091 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(3u),
92 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -080093 EXPECT_EQ(rtc::Optional<uint64_t>(3u), statistics_proxy_->GetStats().qp_sum);
ilnik00d802b2017-04-11 10:34:31 -070094 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(127u),
95 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -080096 EXPECT_EQ(rtc::Optional<uint64_t>(130u),
97 statistics_proxy_->GetStats().qp_sum);
98}
99
100TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameWithoutQpQpSumWontExist) {
101 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
ilnik00d802b2017-04-11 10:34:31 -0700102 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(),
103 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -0800104 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
105}
106
107TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameWithoutQpResetsQpSum) {
108 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
ilnik00d802b2017-04-11 10:34:31 -0700109 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(3u),
110 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -0800111 EXPECT_EQ(rtc::Optional<uint64_t>(3u), statistics_proxy_->GetStats().qp_sum);
ilnik00d802b2017-04-11 10:34:31 -0700112 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(),
113 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -0800114 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
115}
116
hbos50cfe1f2017-01-23 07:21:55 -0800117TEST_F(ReceiveStatisticsProxyTest, OnRenderedFrameIncreasesFramesRendered) {
118 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_rendered);
ilnik00d802b2017-04-11 10:34:31 -0700119 webrtc::VideoFrame frame(webrtc::I420Buffer::Create(1, 1), 0, 0,
120 webrtc::kVideoRotation_0);
hbos50cfe1f2017-01-23 07:21:55 -0800121 for (uint32_t i = 1; i <= 3; ++i) {
122 statistics_proxy_->OnRenderedFrame(frame);
123 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_rendered);
124 }
125}
126
asapersson46c4e3c2016-11-03 06:48:19 -0700127TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsSsrc) {
128 EXPECT_EQ(kRemoteSsrc, statistics_proxy_->GetStats().ssrc);
129}
130
131TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsIncomingPayloadType) {
132 const int kPayloadType = 111;
133 statistics_proxy_->OnIncomingPayloadType(kPayloadType);
134 EXPECT_EQ(kPayloadType, statistics_proxy_->GetStats().current_payload_type);
135}
136
asapersson6966bd52017-01-03 00:44:06 -0800137TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDecoderImplementationName) {
138 const char* kName = "decoderName";
139 statistics_proxy_->OnDecoderImplementationName(kName);
140 EXPECT_STREQ(
141 kName, statistics_proxy_->GetStats().decoder_implementation_name.c_str());
142}
143
philipela45102f2017-02-22 05:30:39 -0800144TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsOnCompleteFrame) {
145 const int kFrameSizeBytes = 1000;
146 statistics_proxy_->OnCompleteFrame(true, kFrameSizeBytes);
147 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
148 EXPECT_EQ(1, stats.network_frame_rate);
philipela45102f2017-02-22 05:30:39 -0800149 EXPECT_EQ(1, stats.frame_counts.key_frames);
150 EXPECT_EQ(0, stats.frame_counts.delta_frames);
asapersson46c4e3c2016-11-03 06:48:19 -0700151}
152
153TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDecodeTimingStats) {
154 const int kDecodeMs = 1;
155 const int kMaxDecodeMs = 2;
156 const int kCurrentDelayMs = 3;
157 const int kTargetDelayMs = 4;
158 const int kJitterBufferMs = 5;
159 const int kMinPlayoutDelayMs = 6;
160 const int kRenderDelayMs = 7;
161 const int64_t kRttMs = 8;
philipela45102f2017-02-22 05:30:39 -0800162 statistics_proxy_->OnRttUpdate(kRttMs, 0);
163 statistics_proxy_->OnFrameBufferTimingsUpdated(
asapersson46c4e3c2016-11-03 06:48:19 -0700164 kDecodeMs, kMaxDecodeMs, kCurrentDelayMs, kTargetDelayMs, kJitterBufferMs,
philipela45102f2017-02-22 05:30:39 -0800165 kMinPlayoutDelayMs, kRenderDelayMs);
asapersson46c4e3c2016-11-03 06:48:19 -0700166 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
167 EXPECT_EQ(kDecodeMs, stats.decode_ms);
168 EXPECT_EQ(kMaxDecodeMs, stats.max_decode_ms);
169 EXPECT_EQ(kCurrentDelayMs, stats.current_delay_ms);
170 EXPECT_EQ(kTargetDelayMs, stats.target_delay_ms);
171 EXPECT_EQ(kJitterBufferMs, stats.jitter_buffer_ms);
172 EXPECT_EQ(kMinPlayoutDelayMs, stats.min_playout_delay_ms);
173 EXPECT_EQ(kRenderDelayMs, stats.render_delay_ms);
174}
175
asapersson6966bd52017-01-03 00:44:06 -0800176TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsRtcpPacketTypeCounts) {
177 const uint32_t kFirPackets = 33;
178 const uint32_t kPliPackets = 44;
179 const uint32_t kNackPackets = 55;
180 RtcpPacketTypeCounter counter;
181 counter.fir_packets = kFirPackets;
182 counter.pli_packets = kPliPackets;
183 counter.nack_packets = kNackPackets;
184 statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc, counter);
185 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
186 EXPECT_EQ(kFirPackets, stats.rtcp_packet_type_counts.fir_packets);
187 EXPECT_EQ(kPliPackets, stats.rtcp_packet_type_counts.pli_packets);
188 EXPECT_EQ(kNackPackets, stats.rtcp_packet_type_counts.nack_packets);
189}
190
191TEST_F(ReceiveStatisticsProxyTest,
192 GetStatsReportsNoRtcpPacketTypeCountsForUnknownSsrc) {
193 RtcpPacketTypeCounter counter;
194 counter.fir_packets = 33;
195 statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc + 1, counter);
196 EXPECT_EQ(0u,
197 statistics_proxy_->GetStats().rtcp_packet_type_counts.fir_packets);
198}
199
200TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsFrameCounts) {
201 const int kKeyFrames = 3;
202 const int kDeltaFrames = 22;
203 FrameCounts frame_counts;
204 frame_counts.key_frames = kKeyFrames;
205 frame_counts.delta_frames = kDeltaFrames;
206 statistics_proxy_->OnFrameCountsUpdated(frame_counts);
207 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
208 EXPECT_EQ(kKeyFrames, stats.frame_counts.key_frames);
209 EXPECT_EQ(kDeltaFrames, stats.frame_counts.delta_frames);
210}
211
asapersson46c4e3c2016-11-03 06:48:19 -0700212TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDiscardedPackets) {
213 const int kDiscardedPackets = 12;
214 statistics_proxy_->OnDiscardedPacketsUpdated(kDiscardedPackets);
215 EXPECT_EQ(kDiscardedPackets, statistics_proxy_->GetStats().discarded_packets);
216}
217
asapersson6966bd52017-01-03 00:44:06 -0800218TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsRtcpStats) {
219 const uint8_t kFracLost = 0;
220 const uint32_t kCumLost = 1;
221 const uint32_t kExtSeqNum = 10;
222 const uint32_t kJitter = 4;
223
224 RtcpStatistics rtcp_stats;
225 rtcp_stats.fraction_lost = kFracLost;
226 rtcp_stats.cumulative_lost = kCumLost;
227 rtcp_stats.extended_max_sequence_number = kExtSeqNum;
228 rtcp_stats.jitter = kJitter;
229 statistics_proxy_->StatisticsUpdated(rtcp_stats, kRemoteSsrc);
230
231 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
232 EXPECT_EQ(kFracLost, stats.rtcp_stats.fraction_lost);
233 EXPECT_EQ(kCumLost, stats.rtcp_stats.cumulative_lost);
234 EXPECT_EQ(kExtSeqNum, stats.rtcp_stats.extended_max_sequence_number);
235 EXPECT_EQ(kJitter, stats.rtcp_stats.jitter);
236}
237
238TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsCName) {
239 const char* kName = "cName";
240 statistics_proxy_->CNameChanged(kName, kRemoteSsrc);
241 EXPECT_STREQ(kName, statistics_proxy_->GetStats().c_name.c_str());
242}
243
244TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsNoCNameForUnknownSsrc) {
245 const char* kName = "cName";
246 statistics_proxy_->CNameChanged(kName, kRemoteSsrc + 1);
247 EXPECT_STREQ("", statistics_proxy_->GetStats().c_name.c_str());
248}
249
asapersson46c4e3c2016-11-03 06:48:19 -0700250TEST_F(ReceiveStatisticsProxyTest, LifetimeHistogramIsUpdated) {
251 const int64_t kTimeSec = 3;
252 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000);
253 // Histograms are updated when the statistics_proxy_ is deleted.
254 statistics_proxy_.reset();
255 EXPECT_EQ(1,
256 metrics::NumSamples("WebRTC.Video.ReceiveStreamLifetimeInSeconds"));
257 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceiveStreamLifetimeInSeconds",
258 kTimeSec));
259}
260
palmkvista40672a2017-01-13 05:58:34 -0800261TEST_F(ReceiveStatisticsProxyTest, BadCallHistogramsAreUpdated) {
262 // Based on the tuning parameters this will produce 7 uncertain states,
263 // then 10 certainly bad states. There has to be 10 certain states before
264 // any histograms are recorded.
265 const int kNumBadSamples = 17;
266
267 StreamDataCounters counters;
268 counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds();
269 statistics_proxy_->DataCountersUpdated(counters, config_.rtp.remote_ssrc);
270
271 for (int i = 0; i < kNumBadSamples; ++i) {
272 // Since OnRenderedFrame is never called the fps in each sample will be 0,
273 // i.e. bad
274 fake_clock_.AdvanceTimeMilliseconds(1000);
275 statistics_proxy_->OnIncomingRate(0, 0);
276 }
277 // Histograms are updated when the statistics_proxy_ is deleted.
278 statistics_proxy_.reset();
279 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BadCall.Any"));
280 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.BadCall.Any", 100));
281
282 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BadCall.FrameRate"));
283 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.BadCall.FrameRate", 100));
284
285 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.BadCall.FrameRateVariance"));
286
287 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.BadCall.Qp"));
288}
289
asapersson0c43f772016-11-30 01:42:26 -0800290TEST_F(ReceiveStatisticsProxyTest, PacketLossHistogramIsUpdated) {
291 const uint32_t kCumLost1 = 1;
292 const uint32_t kExtSeqNum1 = 10;
293 const uint32_t kCumLost2 = 2;
294 const uint32_t kExtSeqNum2 = 20;
295
296 // One report block received.
297 RtcpStatistics rtcp_stats1;
298 rtcp_stats1.cumulative_lost = kCumLost1;
299 rtcp_stats1.extended_max_sequence_number = kExtSeqNum1;
300 statistics_proxy_->StatisticsUpdated(rtcp_stats1, kRemoteSsrc);
301
302 // Two report blocks received.
303 RtcpStatistics rtcp_stats2;
304 rtcp_stats2.cumulative_lost = kCumLost2;
305 rtcp_stats2.extended_max_sequence_number = kExtSeqNum2;
306 statistics_proxy_->StatisticsUpdated(rtcp_stats2, kRemoteSsrc);
307
308 // Two received report blocks but min run time has not passed.
309 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000 - 1);
310 SetUp(); // Reset stat proxy causes histograms to be updated.
311 EXPECT_EQ(0,
312 metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent"));
313
314 // Two report blocks received.
315 statistics_proxy_->StatisticsUpdated(rtcp_stats1, kRemoteSsrc);
316 statistics_proxy_->StatisticsUpdated(rtcp_stats2, kRemoteSsrc);
317
318 // Two received report blocks and min run time has passed.
319 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
320 SetUp();
321 EXPECT_EQ(1,
322 metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent"));
323 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceivedPacketsLostInPercent",
324 (kCumLost2 - kCumLost1) * 100 /
325 (kExtSeqNum2 - kExtSeqNum1)));
326}
327
328TEST_F(ReceiveStatisticsProxyTest,
329 PacketLossHistogramIsNotUpdatedIfLessThanTwoReportBlocksAreReceived) {
330 RtcpStatistics rtcp_stats1;
331 rtcp_stats1.cumulative_lost = 1;
332 rtcp_stats1.extended_max_sequence_number = 10;
333
334 // Min run time has passed but no received report block.
335 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
336 SetUp(); // Reset stat proxy causes histograms to be updated.
337 EXPECT_EQ(0,
338 metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent"));
339
340 // Min run time has passed but only one received report block.
341 statistics_proxy_->StatisticsUpdated(rtcp_stats1, kRemoteSsrc);
342 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
343 SetUp();
344 EXPECT_EQ(0,
345 metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent"));
346}
347
asapersson2077f2f2017-05-11 05:37:35 -0700348TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsAvSyncOffset) {
349 const int64_t kSyncOffsetMs = 22;
350 const double kFreqKhz = 90.0;
351 EXPECT_EQ(std::numeric_limits<int>::max(),
352 statistics_proxy_->GetStats().sync_offset_ms);
353 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz);
354 EXPECT_EQ(kSyncOffsetMs, statistics_proxy_->GetStats().sync_offset_ms);
355}
356
asapersson46c4e3c2016-11-03 06:48:19 -0700357TEST_F(ReceiveStatisticsProxyTest, AvSyncOffsetHistogramIsUpdated) {
358 const int64_t kSyncOffsetMs = 22;
359 const double kFreqKhz = 90.0;
360 for (int i = 0; i < kMinRequiredSamples; ++i)
361 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz);
362 // Histograms are updated when the statistics_proxy_ is deleted.
363 statistics_proxy_.reset();
364 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AVSyncOffsetInMs"));
365 EXPECT_EQ(1,
366 metrics::NumEvents("WebRTC.Video.AVSyncOffsetInMs", kSyncOffsetMs));
367}
368
asaperssonde9e5ff2016-11-02 07:14:03 -0700369TEST_F(ReceiveStatisticsProxyTest, RtpToNtpFrequencyOffsetHistogramIsUpdated) {
370 const int64_t kSyncOffsetMs = 22;
371 const double kFreqKhz = 90.0;
372 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz);
373 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 2.2);
374 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs);
375 // Process interval passed, max diff: 2.
376 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 1.1);
377 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 4.2);
378 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 0.9);
379 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs);
380 // Process interval passed, max diff: 4.
381 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz);
382 statistics_proxy_.reset();
383 // Average reported: (2 + 4) / 2 = 3.
384 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtpToNtpFreqOffsetInKhz"));
385 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtpToNtpFreqOffsetInKhz", 3));
386}
387
asapersson6966bd52017-01-03 00:44:06 -0800388TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsUpdated) {
389 const int kQp = 22;
390 EncodedImage encoded_image;
391 encoded_image.qp_ = kQp;
392 CodecSpecificInfo codec_info;
393 codec_info.codecType = kVideoCodecVP8;
394
395 for (int i = 0; i < kMinRequiredSamples; ++i)
396 statistics_proxy_->OnPreDecode(encoded_image, &codec_info);
397
398 statistics_proxy_.reset();
399 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp"));
400 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Decoded.Vp8.Qp", kQp));
401}
402
403TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsNotUpdatedForTooFewSamples) {
404 EncodedImage encoded_image;
405 encoded_image.qp_ = 22;
406 CodecSpecificInfo codec_info;
407 codec_info.codecType = kVideoCodecVP8;
408
409 for (int i = 0; i < kMinRequiredSamples - 1; ++i)
410 statistics_proxy_->OnPreDecode(encoded_image, &codec_info);
411
412 statistics_proxy_.reset();
413 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp"));
414}
415
416TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsNotUpdatedIfNoQpValue) {
417 EncodedImage encoded_image;
418 CodecSpecificInfo codec_info;
419 codec_info.codecType = kVideoCodecVP8;
420
421 for (int i = 0; i < kMinRequiredSamples; ++i)
422 statistics_proxy_->OnPreDecode(encoded_image, &codec_info);
423
424 statistics_proxy_.reset();
425 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp"));
426}
427
asaperssonb99baf82017-04-20 04:05:43 -0700428TEST_F(ReceiveStatisticsProxyTest,
429 KeyFrameHistogramNotUpdatedForTooFewSamples) {
430 const bool kIsKeyFrame = false;
431 const int kFrameSizeBytes = 1000;
432
433 for (int i = 0; i < kMinRequiredSamples - 1; ++i)
434 statistics_proxy_->OnCompleteFrame(kIsKeyFrame, kFrameSizeBytes);
435
436 EXPECT_EQ(0, statistics_proxy_->GetStats().frame_counts.key_frames);
437 EXPECT_EQ(kMinRequiredSamples - 1,
438 statistics_proxy_->GetStats().frame_counts.delta_frames);
439
440 statistics_proxy_.reset();
441 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.KeyFramesReceivedInPermille"));
442}
443
444TEST_F(ReceiveStatisticsProxyTest,
445 KeyFrameHistogramUpdatedForMinRequiredSamples) {
446 const bool kIsKeyFrame = false;
447 const int kFrameSizeBytes = 1000;
448
449 for (int i = 0; i < kMinRequiredSamples; ++i)
450 statistics_proxy_->OnCompleteFrame(kIsKeyFrame, kFrameSizeBytes);
451
452 EXPECT_EQ(0, statistics_proxy_->GetStats().frame_counts.key_frames);
453 EXPECT_EQ(kMinRequiredSamples,
454 statistics_proxy_->GetStats().frame_counts.delta_frames);
455
456 statistics_proxy_.reset();
457 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.KeyFramesReceivedInPermille"));
458 EXPECT_EQ(1,
459 metrics::NumEvents("WebRTC.Video.KeyFramesReceivedInPermille", 0));
460}
461
462TEST_F(ReceiveStatisticsProxyTest, KeyFrameHistogramIsUpdated) {
463 const int kFrameSizeBytes = 1000;
464
465 for (int i = 0; i < kMinRequiredSamples; ++i)
466 statistics_proxy_->OnCompleteFrame(true, kFrameSizeBytes);
467
468 for (int i = 0; i < kMinRequiredSamples; ++i)
469 statistics_proxy_->OnCompleteFrame(false, kFrameSizeBytes);
470
471 EXPECT_EQ(kMinRequiredSamples,
472 statistics_proxy_->GetStats().frame_counts.key_frames);
473 EXPECT_EQ(kMinRequiredSamples,
474 statistics_proxy_->GetStats().frame_counts.delta_frames);
475
476 statistics_proxy_.reset();
477 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.KeyFramesReceivedInPermille"));
478 EXPECT_EQ(
479 1, metrics::NumEvents("WebRTC.Video.KeyFramesReceivedInPermille", 500));
480}
481
482TEST_F(ReceiveStatisticsProxyTest, TimingHistogramsNotUpdatedForTooFewSamples) {
483 const int kDecodeMs = 1;
484 const int kMaxDecodeMs = 2;
485 const int kCurrentDelayMs = 3;
486 const int kTargetDelayMs = 4;
487 const int kJitterBufferMs = 5;
488 const int kMinPlayoutDelayMs = 6;
489 const int kRenderDelayMs = 7;
490
491 for (int i = 0; i < kMinRequiredSamples - 1; ++i) {
492 statistics_proxy_->OnFrameBufferTimingsUpdated(
493 kDecodeMs, kMaxDecodeMs, kCurrentDelayMs, kTargetDelayMs,
494 kJitterBufferMs, kMinPlayoutDelayMs, kRenderDelayMs);
495 }
496
497 statistics_proxy_.reset();
498 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.DecodeTimeInMs"));
499 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.JitterBufferDelayInMs"));
500 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.TargetDelayInMs"));
501 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.CurrentDelayInMs"));
502 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.OnewayDelayInMs"));
503}
504
505TEST_F(ReceiveStatisticsProxyTest, TimingHistogramsAreUpdated) {
506 const int kDecodeMs = 1;
507 const int kMaxDecodeMs = 2;
508 const int kCurrentDelayMs = 3;
509 const int kTargetDelayMs = 4;
510 const int kJitterBufferMs = 5;
511 const int kMinPlayoutDelayMs = 6;
512 const int kRenderDelayMs = 7;
513
514 for (int i = 0; i < kMinRequiredSamples; ++i) {
515 statistics_proxy_->OnFrameBufferTimingsUpdated(
516 kDecodeMs, kMaxDecodeMs, kCurrentDelayMs, kTargetDelayMs,
517 kJitterBufferMs, kMinPlayoutDelayMs, kRenderDelayMs);
518 }
519
520 statistics_proxy_.reset();
521 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.DecodeTimeInMs"));
522 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.JitterBufferDelayInMs"));
523 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.TargetDelayInMs"));
524 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.CurrentDelayInMs"));
525 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.OnewayDelayInMs"));
526
527 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.DecodeTimeInMs", kDecodeMs));
528 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.JitterBufferDelayInMs",
529 kJitterBufferMs));
530 EXPECT_EQ(1,
531 metrics::NumEvents("WebRTC.Video.TargetDelayInMs", kTargetDelayMs));
532 EXPECT_EQ(
533 1, metrics::NumEvents("WebRTC.Video.CurrentDelayInMs", kCurrentDelayMs));
534 EXPECT_EQ(1,
535 metrics::NumEvents("WebRTC.Video.OnewayDelayInMs", kTargetDelayMs));
536}
537
sprang948b2752017-05-04 02:47:13 -0700538TEST_F(ReceiveStatisticsProxyTest, DoesNotReportStaleFramerates) {
539 const int kDefaultFps = 30;
540 const int kWidth = 320;
541 const int kHeight = 240;
542
543 rtc::scoped_refptr<VideoFrameBuffer> video_frame_buffer(
544 I420Buffer::Create(kWidth, kHeight));
545 VideoFrame frame(video_frame_buffer, kVideoRotation_0, 0);
546
547 for (int i = 0; i < kDefaultFps; ++i) {
548 // Since OnRenderedFrame is never called the fps in each sample will be 0,
549 // i.e. bad
550 frame.set_ntp_time_ms(fake_clock_.CurrentNtpInMilliseconds());
551 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(),
552 VideoContentType::UNSPECIFIED);
553 statistics_proxy_->OnRenderedFrame(frame);
554 fake_clock_.AdvanceTimeMilliseconds(1000 / kDefaultFps);
555 }
556
557 EXPECT_EQ(kDefaultFps, statistics_proxy_->GetStats().decode_frame_rate);
558 EXPECT_EQ(kDefaultFps, statistics_proxy_->GetStats().render_frame_rate);
559
560 // FPS trackers in stats proxy have a 1000ms sliding window.
561 fake_clock_.AdvanceTimeMilliseconds(1000);
562 EXPECT_EQ(0, statistics_proxy_->GetStats().decode_frame_rate);
563 EXPECT_EQ(0, statistics_proxy_->GetStats().render_frame_rate);
564}
565
asapersson2077f2f2017-05-11 05:37:35 -0700566TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsReceivedFrameStats) {
567 const int kWidth = 160;
568 const int kHeight = 120;
569 EXPECT_EQ(0, statistics_proxy_->GetStats().width);
570 EXPECT_EQ(0, statistics_proxy_->GetStats().height);
571 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_rendered);
572
573 statistics_proxy_->OnRenderedFrame(CreateFrame(kWidth, kHeight));
574
575 EXPECT_EQ(kWidth, statistics_proxy_->GetStats().width);
576 EXPECT_EQ(kHeight, statistics_proxy_->GetStats().height);
577 EXPECT_EQ(1u, statistics_proxy_->GetStats().frames_rendered);
578}
579
580TEST_F(ReceiveStatisticsProxyTest,
581 ReceivedFrameHistogramsAreNotUpdatedForTooFewSamples) {
582 const int kWidth = 160;
583 const int kHeight = 120;
584
585 for (int i = 0; i < kMinRequiredSamples - 1; ++i)
586 statistics_proxy_->OnRenderedFrame(CreateFrame(kWidth, kHeight));
587
588 statistics_proxy_.reset();
589 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.ReceivedWidthInPixels"));
590 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.ReceivedHeightInPixels"));
591 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.RenderFramesPerSecond"));
592 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.RenderSqrtPixelsPerSecond"));
593}
594
595TEST_F(ReceiveStatisticsProxyTest, ReceivedFrameHistogramsAreUpdated) {
596 const int kWidth = 160;
597 const int kHeight = 120;
598
599 for (int i = 0; i < kMinRequiredSamples; ++i)
600 statistics_proxy_->OnRenderedFrame(CreateFrame(kWidth, kHeight));
601
602 statistics_proxy_.reset();
603 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.ReceivedWidthInPixels"));
604 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.ReceivedHeightInPixels"));
605 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RenderFramesPerSecond"));
606 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RenderSqrtPixelsPerSecond"));
607 EXPECT_EQ(1,
608 metrics::NumEvents("WebRTC.Video.ReceivedWidthInPixels", kWidth));
609 EXPECT_EQ(1,
610 metrics::NumEvents("WebRTC.Video.ReceivedHeightInPixels", kHeight));
611}
612
613TEST_F(ReceiveStatisticsProxyTest,
614 RtcpHistogramsNotUpdatedIfMinRuntimeHasNotPassed) {
615 InsertFirstRtpPacket(kRemoteSsrc);
616 fake_clock_.AdvanceTimeMilliseconds((metrics::kMinRunTimeInSeconds * 1000) -
617 1);
618
619 RtcpPacketTypeCounter counter;
620 statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc, counter);
621
622 statistics_proxy_.reset();
623 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.FirPacketsSentPerMinute"));
624 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.PliPacketsSentPerMinute"));
625 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.NackPacketsSentPerMinute"));
626}
627
628TEST_F(ReceiveStatisticsProxyTest, RtcpHistogramsAreUpdated) {
629 InsertFirstRtpPacket(kRemoteSsrc);
630 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
631
632 const uint32_t kFirPackets = 100;
633 const uint32_t kPliPackets = 200;
634 const uint32_t kNackPackets = 300;
635
636 RtcpPacketTypeCounter counter;
637 counter.fir_packets = kFirPackets;
638 counter.pli_packets = kPliPackets;
639 counter.nack_packets = kNackPackets;
640 statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc, counter);
641
642 statistics_proxy_.reset();
643 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FirPacketsSentPerMinute"));
644 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PliPacketsSentPerMinute"));
645 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NackPacketsSentPerMinute"));
646 EXPECT_EQ(
647 1, metrics::NumEvents("WebRTC.Video.FirPacketsSentPerMinute",
648 kFirPackets * 60 / metrics::kMinRunTimeInSeconds));
649 EXPECT_EQ(
650 1, metrics::NumEvents("WebRTC.Video.PliPacketsSentPerMinute",
651 kPliPackets * 60 / metrics::kMinRunTimeInSeconds));
652 EXPECT_EQ(
653 1, metrics::NumEvents("WebRTC.Video.NackPacketsSentPerMinute",
654 kNackPackets * 60 / metrics::kMinRunTimeInSeconds));
655}
656
sakale5ba44e2016-10-26 07:09:24 -0700657} // namespace webrtc