blob: d37d2035485334127083b21c5d572b70b1c588a2 [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.
sprang892dab52017-08-15 05:00:33 -070033class ReceiveStatisticsProxyTest
34 : public ::testing::TestWithParam<webrtc::VideoContentType> {
sakale5ba44e2016-10-26 07:09:24 -070035 public:
36 ReceiveStatisticsProxyTest() : fake_clock_(1234), config_(GetTestConfig()) {}
37 virtual ~ReceiveStatisticsProxyTest() {}
38
39 protected:
40 virtual void SetUp() {
asaperssonde9e5ff2016-11-02 07:14:03 -070041 metrics::Reset();
sakale5ba44e2016-10-26 07:09:24 -070042 statistics_proxy_.reset(new ReceiveStatisticsProxy(&config_, &fake_clock_));
43 }
44
45 VideoReceiveStream::Config GetTestConfig() {
46 VideoReceiveStream::Config config(nullptr);
asapersson46c4e3c2016-11-03 06:48:19 -070047 config.rtp.local_ssrc = kLocalSsrc;
48 config.rtp.remote_ssrc = kRemoteSsrc;
sakale5ba44e2016-10-26 07:09:24 -070049 return config;
50 }
51
asapersson2077f2f2017-05-11 05:37:35 -070052 void InsertFirstRtpPacket(uint32_t ssrc) {
53 StreamDataCounters counters;
54 counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds();
55 statistics_proxy_->DataCountersUpdated(counters, ssrc);
56 }
57
58 VideoFrame CreateFrame(int width, int height) {
59 VideoFrame frame(I420Buffer::Create(width, height), 0, 0, kVideoRotation_0);
60 frame.set_ntp_time_ms(fake_clock_.CurrentNtpInMilliseconds());
61 return frame;
62 }
63
sakale5ba44e2016-10-26 07:09:24 -070064 SimulatedClock fake_clock_;
asaperssonde9e5ff2016-11-02 07:14:03 -070065 const VideoReceiveStream::Config config_;
sakale5ba44e2016-10-26 07:09:24 -070066 std::unique_ptr<ReceiveStatisticsProxy> statistics_proxy_;
sakale5ba44e2016-10-26 07:09:24 -070067};
68
69TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameIncreasesFramesDecoded) {
70 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_decoded);
71 for (uint32_t i = 1; i <= 3; ++i) {
ilnik00d802b2017-04-11 10:34:31 -070072 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(),
73 VideoContentType::UNSPECIFIED);
sakale5ba44e2016-10-26 07:09:24 -070074 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_decoded);
75 }
76}
77
sakalcc452e12017-02-09 04:53:45 -080078TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameWithQpResetsFramesDecoded) {
79 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_decoded);
80 for (uint32_t i = 1; i <= 3; ++i) {
ilnik00d802b2017-04-11 10:34:31 -070081 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(),
82 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -080083 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_decoded);
84 }
ilnik00d802b2017-04-11 10:34:31 -070085 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(1u),
86 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -080087 EXPECT_EQ(1u, statistics_proxy_->GetStats().frames_decoded);
88}
89
90TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameIncreasesQpSum) {
91 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
ilnik00d802b2017-04-11 10:34:31 -070092 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(3u),
93 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -080094 EXPECT_EQ(rtc::Optional<uint64_t>(3u), statistics_proxy_->GetStats().qp_sum);
ilnik00d802b2017-04-11 10:34:31 -070095 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(127u),
96 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -080097 EXPECT_EQ(rtc::Optional<uint64_t>(130u),
98 statistics_proxy_->GetStats().qp_sum);
99}
100
ilnikf04afde2017-07-07 01:26:24 -0700101TEST_F(ReceiveStatisticsProxyTest,
102 OnDecodedFrameIncreasesInterframeDelayMsSum) {
103 const uint64_t kInterframeDelayMs1 = 100;
104 const uint64_t kInterframeDelayMs2 = 200;
105 EXPECT_EQ(0u, statistics_proxy_->GetStats().interframe_delay_sum_ms);
106 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(3u),
107 VideoContentType::UNSPECIFIED);
108 EXPECT_EQ(0u, statistics_proxy_->GetStats().interframe_delay_sum_ms);
109
110 fake_clock_.AdvanceTimeMilliseconds(kInterframeDelayMs1);
111 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(127u),
112 VideoContentType::UNSPECIFIED);
113 EXPECT_EQ(kInterframeDelayMs1,
114 statistics_proxy_->GetStats().interframe_delay_sum_ms);
115
116 fake_clock_.AdvanceTimeMilliseconds(kInterframeDelayMs2);
117 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(127u),
118 VideoContentType::UNSPECIFIED);
119 EXPECT_EQ(kInterframeDelayMs1 + kInterframeDelayMs2,
120 statistics_proxy_->GetStats().interframe_delay_sum_ms);
121}
122
sakalcc452e12017-02-09 04:53:45 -0800123TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameWithoutQpQpSumWontExist) {
124 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
ilnik00d802b2017-04-11 10:34:31 -0700125 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(),
126 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -0800127 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
128}
129
130TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameWithoutQpResetsQpSum) {
131 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
ilnik00d802b2017-04-11 10:34:31 -0700132 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(3u),
133 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -0800134 EXPECT_EQ(rtc::Optional<uint64_t>(3u), statistics_proxy_->GetStats().qp_sum);
ilnik00d802b2017-04-11 10:34:31 -0700135 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(),
136 VideoContentType::UNSPECIFIED);
sakalcc452e12017-02-09 04:53:45 -0800137 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
138}
139
hbos50cfe1f2017-01-23 07:21:55 -0800140TEST_F(ReceiveStatisticsProxyTest, OnRenderedFrameIncreasesFramesRendered) {
141 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_rendered);
ilnik00d802b2017-04-11 10:34:31 -0700142 webrtc::VideoFrame frame(webrtc::I420Buffer::Create(1, 1), 0, 0,
143 webrtc::kVideoRotation_0);
hbos50cfe1f2017-01-23 07:21:55 -0800144 for (uint32_t i = 1; i <= 3; ++i) {
145 statistics_proxy_->OnRenderedFrame(frame);
146 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_rendered);
147 }
148}
149
asapersson46c4e3c2016-11-03 06:48:19 -0700150TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsSsrc) {
151 EXPECT_EQ(kRemoteSsrc, statistics_proxy_->GetStats().ssrc);
152}
153
154TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsIncomingPayloadType) {
155 const int kPayloadType = 111;
156 statistics_proxy_->OnIncomingPayloadType(kPayloadType);
157 EXPECT_EQ(kPayloadType, statistics_proxy_->GetStats().current_payload_type);
158}
159
asapersson6966bd52017-01-03 00:44:06 -0800160TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDecoderImplementationName) {
161 const char* kName = "decoderName";
162 statistics_proxy_->OnDecoderImplementationName(kName);
163 EXPECT_STREQ(
164 kName, statistics_proxy_->GetStats().decoder_implementation_name.c_str());
165}
166
philipela45102f2017-02-22 05:30:39 -0800167TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsOnCompleteFrame) {
168 const int kFrameSizeBytes = 1000;
169 statistics_proxy_->OnCompleteFrame(true, kFrameSizeBytes);
170 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
171 EXPECT_EQ(1, stats.network_frame_rate);
philipela45102f2017-02-22 05:30:39 -0800172 EXPECT_EQ(1, stats.frame_counts.key_frames);
173 EXPECT_EQ(0, stats.frame_counts.delta_frames);
asapersson46c4e3c2016-11-03 06:48:19 -0700174}
175
176TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDecodeTimingStats) {
177 const int kDecodeMs = 1;
178 const int kMaxDecodeMs = 2;
179 const int kCurrentDelayMs = 3;
180 const int kTargetDelayMs = 4;
181 const int kJitterBufferMs = 5;
182 const int kMinPlayoutDelayMs = 6;
183 const int kRenderDelayMs = 7;
184 const int64_t kRttMs = 8;
philipela45102f2017-02-22 05:30:39 -0800185 statistics_proxy_->OnRttUpdate(kRttMs, 0);
186 statistics_proxy_->OnFrameBufferTimingsUpdated(
asapersson46c4e3c2016-11-03 06:48:19 -0700187 kDecodeMs, kMaxDecodeMs, kCurrentDelayMs, kTargetDelayMs, kJitterBufferMs,
philipela45102f2017-02-22 05:30:39 -0800188 kMinPlayoutDelayMs, kRenderDelayMs);
asapersson46c4e3c2016-11-03 06:48:19 -0700189 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
190 EXPECT_EQ(kDecodeMs, stats.decode_ms);
191 EXPECT_EQ(kMaxDecodeMs, stats.max_decode_ms);
192 EXPECT_EQ(kCurrentDelayMs, stats.current_delay_ms);
193 EXPECT_EQ(kTargetDelayMs, stats.target_delay_ms);
194 EXPECT_EQ(kJitterBufferMs, stats.jitter_buffer_ms);
195 EXPECT_EQ(kMinPlayoutDelayMs, stats.min_playout_delay_ms);
196 EXPECT_EQ(kRenderDelayMs, stats.render_delay_ms);
197}
198
asapersson6966bd52017-01-03 00:44:06 -0800199TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsRtcpPacketTypeCounts) {
200 const uint32_t kFirPackets = 33;
201 const uint32_t kPliPackets = 44;
202 const uint32_t kNackPackets = 55;
203 RtcpPacketTypeCounter counter;
204 counter.fir_packets = kFirPackets;
205 counter.pli_packets = kPliPackets;
206 counter.nack_packets = kNackPackets;
207 statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc, counter);
208 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
209 EXPECT_EQ(kFirPackets, stats.rtcp_packet_type_counts.fir_packets);
210 EXPECT_EQ(kPliPackets, stats.rtcp_packet_type_counts.pli_packets);
211 EXPECT_EQ(kNackPackets, stats.rtcp_packet_type_counts.nack_packets);
212}
213
214TEST_F(ReceiveStatisticsProxyTest,
215 GetStatsReportsNoRtcpPacketTypeCountsForUnknownSsrc) {
216 RtcpPacketTypeCounter counter;
217 counter.fir_packets = 33;
218 statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc + 1, counter);
219 EXPECT_EQ(0u,
220 statistics_proxy_->GetStats().rtcp_packet_type_counts.fir_packets);
221}
222
223TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsFrameCounts) {
224 const int kKeyFrames = 3;
225 const int kDeltaFrames = 22;
226 FrameCounts frame_counts;
227 frame_counts.key_frames = kKeyFrames;
228 frame_counts.delta_frames = kDeltaFrames;
229 statistics_proxy_->OnFrameCountsUpdated(frame_counts);
230 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
231 EXPECT_EQ(kKeyFrames, stats.frame_counts.key_frames);
232 EXPECT_EQ(kDeltaFrames, stats.frame_counts.delta_frames);
233}
234
asapersson46c4e3c2016-11-03 06:48:19 -0700235TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDiscardedPackets) {
236 const int kDiscardedPackets = 12;
237 statistics_proxy_->OnDiscardedPacketsUpdated(kDiscardedPackets);
238 EXPECT_EQ(kDiscardedPackets, statistics_proxy_->GetStats().discarded_packets);
239}
240
asapersson6966bd52017-01-03 00:44:06 -0800241TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsRtcpStats) {
242 const uint8_t kFracLost = 0;
243 const uint32_t kCumLost = 1;
244 const uint32_t kExtSeqNum = 10;
245 const uint32_t kJitter = 4;
246
247 RtcpStatistics rtcp_stats;
248 rtcp_stats.fraction_lost = kFracLost;
srte186d9c32017-08-04 05:03:53 -0700249 rtcp_stats.packets_lost = kCumLost;
250 rtcp_stats.extended_highest_sequence_number = kExtSeqNum;
asapersson6966bd52017-01-03 00:44:06 -0800251 rtcp_stats.jitter = kJitter;
252 statistics_proxy_->StatisticsUpdated(rtcp_stats, kRemoteSsrc);
253
254 VideoReceiveStream::Stats stats = statistics_proxy_->GetStats();
255 EXPECT_EQ(kFracLost, stats.rtcp_stats.fraction_lost);
srte186d9c32017-08-04 05:03:53 -0700256 EXPECT_EQ(kCumLost, stats.rtcp_stats.packets_lost);
257 EXPECT_EQ(kExtSeqNum, stats.rtcp_stats.extended_highest_sequence_number);
asapersson6966bd52017-01-03 00:44:06 -0800258 EXPECT_EQ(kJitter, stats.rtcp_stats.jitter);
259}
260
261TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsCName) {
262 const char* kName = "cName";
263 statistics_proxy_->CNameChanged(kName, kRemoteSsrc);
264 EXPECT_STREQ(kName, statistics_proxy_->GetStats().c_name.c_str());
265}
266
267TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsNoCNameForUnknownSsrc) {
268 const char* kName = "cName";
269 statistics_proxy_->CNameChanged(kName, kRemoteSsrc + 1);
270 EXPECT_STREQ("", statistics_proxy_->GetStats().c_name.c_str());
271}
272
ilnik2edc6842017-07-06 03:06:50 -0700273TEST_F(ReceiveStatisticsProxyTest,
274 GetTimingFrameInfoReportsLongestTimingFrame) {
275 const int64_t kShortEndToEndDelay = 10;
276 const int64_t kMedEndToEndDelay = 20;
277 const int64_t kLongEndToEndDelay = 100;
278 const uint32_t kExpectedRtpTimestamp = 2;
279 TimingFrameInfo info;
280 rtc::Optional<TimingFrameInfo> result;
281 info.rtp_timestamp = kExpectedRtpTimestamp - 1;
282 info.capture_time_ms = 0;
283 info.decode_finish_ms = kShortEndToEndDelay;
284 statistics_proxy_->OnTimingFrameInfoUpdated(info);
285 info.rtp_timestamp =
286 kExpectedRtpTimestamp; // this frame should be reported in the end.
287 info.capture_time_ms = 0;
288 info.decode_finish_ms = kLongEndToEndDelay;
289 statistics_proxy_->OnTimingFrameInfoUpdated(info);
290 info.rtp_timestamp = kExpectedRtpTimestamp + 1;
291 info.capture_time_ms = 0;
292 info.decode_finish_ms = kMedEndToEndDelay;
293 statistics_proxy_->OnTimingFrameInfoUpdated(info);
294 result = statistics_proxy_->GetAndResetTimingFrameInfo();
295 EXPECT_TRUE(result);
296 EXPECT_EQ(kExpectedRtpTimestamp, result->rtp_timestamp);
297}
298
299TEST_F(ReceiveStatisticsProxyTest, GetTimingFrameInfoTimingFramesReportedOnce) {
300 const int64_t kShortEndToEndDelay = 10;
301 const uint32_t kExpectedRtpTimestamp = 2;
302 TimingFrameInfo info;
303 rtc::Optional<TimingFrameInfo> result;
304 info.rtp_timestamp = kExpectedRtpTimestamp;
305 info.capture_time_ms = 0;
306 info.decode_finish_ms = kShortEndToEndDelay;
307 statistics_proxy_->OnTimingFrameInfoUpdated(info);
308 result = statistics_proxy_->GetAndResetTimingFrameInfo();
309 EXPECT_TRUE(result);
310 EXPECT_EQ(kExpectedRtpTimestamp, result->rtp_timestamp);
311 result = statistics_proxy_->GetAndResetTimingFrameInfo();
312 EXPECT_FALSE(result);
313}
314
asapersson46c4e3c2016-11-03 06:48:19 -0700315TEST_F(ReceiveStatisticsProxyTest, LifetimeHistogramIsUpdated) {
316 const int64_t kTimeSec = 3;
317 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000);
318 // Histograms are updated when the statistics_proxy_ is deleted.
319 statistics_proxy_.reset();
320 EXPECT_EQ(1,
321 metrics::NumSamples("WebRTC.Video.ReceiveStreamLifetimeInSeconds"));
322 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceiveStreamLifetimeInSeconds",
323 kTimeSec));
324}
325
palmkvista40672a2017-01-13 05:58:34 -0800326TEST_F(ReceiveStatisticsProxyTest, BadCallHistogramsAreUpdated) {
327 // Based on the tuning parameters this will produce 7 uncertain states,
328 // then 10 certainly bad states. There has to be 10 certain states before
329 // any histograms are recorded.
330 const int kNumBadSamples = 17;
331
332 StreamDataCounters counters;
333 counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds();
334 statistics_proxy_->DataCountersUpdated(counters, config_.rtp.remote_ssrc);
335
336 for (int i = 0; i < kNumBadSamples; ++i) {
337 // Since OnRenderedFrame is never called the fps in each sample will be 0,
338 // i.e. bad
339 fake_clock_.AdvanceTimeMilliseconds(1000);
340 statistics_proxy_->OnIncomingRate(0, 0);
341 }
342 // Histograms are updated when the statistics_proxy_ is deleted.
343 statistics_proxy_.reset();
344 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BadCall.Any"));
345 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.BadCall.Any", 100));
346
347 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BadCall.FrameRate"));
348 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.BadCall.FrameRate", 100));
349
350 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.BadCall.FrameRateVariance"));
351
352 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.BadCall.Qp"));
353}
354
asapersson0c43f772016-11-30 01:42:26 -0800355TEST_F(ReceiveStatisticsProxyTest, PacketLossHistogramIsUpdated) {
356 const uint32_t kCumLost1 = 1;
357 const uint32_t kExtSeqNum1 = 10;
358 const uint32_t kCumLost2 = 2;
359 const uint32_t kExtSeqNum2 = 20;
360
361 // One report block received.
362 RtcpStatistics rtcp_stats1;
srte186d9c32017-08-04 05:03:53 -0700363 rtcp_stats1.packets_lost = kCumLost1;
364 rtcp_stats1.extended_highest_sequence_number = kExtSeqNum1;
asapersson0c43f772016-11-30 01:42:26 -0800365 statistics_proxy_->StatisticsUpdated(rtcp_stats1, kRemoteSsrc);
366
367 // Two report blocks received.
368 RtcpStatistics rtcp_stats2;
srte186d9c32017-08-04 05:03:53 -0700369 rtcp_stats2.packets_lost = kCumLost2;
370 rtcp_stats2.extended_highest_sequence_number = kExtSeqNum2;
asapersson0c43f772016-11-30 01:42:26 -0800371 statistics_proxy_->StatisticsUpdated(rtcp_stats2, kRemoteSsrc);
372
373 // Two received report blocks but min run time has not passed.
374 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000 - 1);
375 SetUp(); // Reset stat proxy causes histograms to be updated.
376 EXPECT_EQ(0,
377 metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent"));
378
379 // Two report blocks received.
380 statistics_proxy_->StatisticsUpdated(rtcp_stats1, kRemoteSsrc);
381 statistics_proxy_->StatisticsUpdated(rtcp_stats2, kRemoteSsrc);
382
383 // Two received report blocks and min run time has passed.
384 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
385 SetUp();
386 EXPECT_EQ(1,
387 metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent"));
388 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceivedPacketsLostInPercent",
389 (kCumLost2 - kCumLost1) * 100 /
390 (kExtSeqNum2 - kExtSeqNum1)));
391}
392
393TEST_F(ReceiveStatisticsProxyTest,
394 PacketLossHistogramIsNotUpdatedIfLessThanTwoReportBlocksAreReceived) {
395 RtcpStatistics rtcp_stats1;
srte186d9c32017-08-04 05:03:53 -0700396 rtcp_stats1.packets_lost = 1;
397 rtcp_stats1.extended_highest_sequence_number = 10;
asapersson0c43f772016-11-30 01:42:26 -0800398
399 // Min run time has passed but no received report block.
400 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
401 SetUp(); // Reset stat proxy causes histograms to be updated.
402 EXPECT_EQ(0,
403 metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent"));
404
405 // Min run time has passed but only one received report block.
406 statistics_proxy_->StatisticsUpdated(rtcp_stats1, kRemoteSsrc);
407 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
408 SetUp();
409 EXPECT_EQ(0,
410 metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent"));
411}
412
asapersson2077f2f2017-05-11 05:37:35 -0700413TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsAvSyncOffset) {
414 const int64_t kSyncOffsetMs = 22;
415 const double kFreqKhz = 90.0;
416 EXPECT_EQ(std::numeric_limits<int>::max(),
417 statistics_proxy_->GetStats().sync_offset_ms);
418 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz);
419 EXPECT_EQ(kSyncOffsetMs, statistics_proxy_->GetStats().sync_offset_ms);
420}
421
asapersson46c4e3c2016-11-03 06:48:19 -0700422TEST_F(ReceiveStatisticsProxyTest, AvSyncOffsetHistogramIsUpdated) {
423 const int64_t kSyncOffsetMs = 22;
424 const double kFreqKhz = 90.0;
425 for (int i = 0; i < kMinRequiredSamples; ++i)
426 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz);
427 // Histograms are updated when the statistics_proxy_ is deleted.
428 statistics_proxy_.reset();
429 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AVSyncOffsetInMs"));
430 EXPECT_EQ(1,
431 metrics::NumEvents("WebRTC.Video.AVSyncOffsetInMs", kSyncOffsetMs));
432}
433
asaperssonde9e5ff2016-11-02 07:14:03 -0700434TEST_F(ReceiveStatisticsProxyTest, RtpToNtpFrequencyOffsetHistogramIsUpdated) {
435 const int64_t kSyncOffsetMs = 22;
436 const double kFreqKhz = 90.0;
437 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz);
438 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 2.2);
439 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs);
440 // Process interval passed, max diff: 2.
441 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 1.1);
442 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 4.2);
443 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 0.9);
444 fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs);
445 // Process interval passed, max diff: 4.
446 statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz);
447 statistics_proxy_.reset();
448 // Average reported: (2 + 4) / 2 = 3.
449 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtpToNtpFreqOffsetInKhz"));
450 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtpToNtpFreqOffsetInKhz", 3));
451}
452
asapersson6966bd52017-01-03 00:44:06 -0800453TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsUpdated) {
454 const int kQp = 22;
455 EncodedImage encoded_image;
456 encoded_image.qp_ = kQp;
457 CodecSpecificInfo codec_info;
458 codec_info.codecType = kVideoCodecVP8;
459
460 for (int i = 0; i < kMinRequiredSamples; ++i)
461 statistics_proxy_->OnPreDecode(encoded_image, &codec_info);
462
463 statistics_proxy_.reset();
464 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp"));
465 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Decoded.Vp8.Qp", kQp));
466}
467
468TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsNotUpdatedForTooFewSamples) {
469 EncodedImage encoded_image;
470 encoded_image.qp_ = 22;
471 CodecSpecificInfo codec_info;
472 codec_info.codecType = kVideoCodecVP8;
473
474 for (int i = 0; i < kMinRequiredSamples - 1; ++i)
475 statistics_proxy_->OnPreDecode(encoded_image, &codec_info);
476
477 statistics_proxy_.reset();
478 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp"));
479}
480
481TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsNotUpdatedIfNoQpValue) {
482 EncodedImage encoded_image;
483 CodecSpecificInfo codec_info;
484 codec_info.codecType = kVideoCodecVP8;
485
486 for (int i = 0; i < kMinRequiredSamples; ++i)
487 statistics_proxy_->OnPreDecode(encoded_image, &codec_info);
488
489 statistics_proxy_.reset();
490 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp"));
491}
492
asaperssonb99baf82017-04-20 04:05:43 -0700493TEST_F(ReceiveStatisticsProxyTest,
494 KeyFrameHistogramNotUpdatedForTooFewSamples) {
495 const bool kIsKeyFrame = false;
496 const int kFrameSizeBytes = 1000;
497
498 for (int i = 0; i < kMinRequiredSamples - 1; ++i)
499 statistics_proxy_->OnCompleteFrame(kIsKeyFrame, kFrameSizeBytes);
500
501 EXPECT_EQ(0, statistics_proxy_->GetStats().frame_counts.key_frames);
502 EXPECT_EQ(kMinRequiredSamples - 1,
503 statistics_proxy_->GetStats().frame_counts.delta_frames);
504
505 statistics_proxy_.reset();
506 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.KeyFramesReceivedInPermille"));
507}
508
509TEST_F(ReceiveStatisticsProxyTest,
510 KeyFrameHistogramUpdatedForMinRequiredSamples) {
511 const bool kIsKeyFrame = false;
512 const int kFrameSizeBytes = 1000;
513
514 for (int i = 0; i < kMinRequiredSamples; ++i)
515 statistics_proxy_->OnCompleteFrame(kIsKeyFrame, kFrameSizeBytes);
516
517 EXPECT_EQ(0, statistics_proxy_->GetStats().frame_counts.key_frames);
518 EXPECT_EQ(kMinRequiredSamples,
519 statistics_proxy_->GetStats().frame_counts.delta_frames);
520
521 statistics_proxy_.reset();
522 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.KeyFramesReceivedInPermille"));
523 EXPECT_EQ(1,
524 metrics::NumEvents("WebRTC.Video.KeyFramesReceivedInPermille", 0));
525}
526
527TEST_F(ReceiveStatisticsProxyTest, KeyFrameHistogramIsUpdated) {
528 const int kFrameSizeBytes = 1000;
529
530 for (int i = 0; i < kMinRequiredSamples; ++i)
531 statistics_proxy_->OnCompleteFrame(true, kFrameSizeBytes);
532
533 for (int i = 0; i < kMinRequiredSamples; ++i)
534 statistics_proxy_->OnCompleteFrame(false, kFrameSizeBytes);
535
536 EXPECT_EQ(kMinRequiredSamples,
537 statistics_proxy_->GetStats().frame_counts.key_frames);
538 EXPECT_EQ(kMinRequiredSamples,
539 statistics_proxy_->GetStats().frame_counts.delta_frames);
540
541 statistics_proxy_.reset();
542 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.KeyFramesReceivedInPermille"));
543 EXPECT_EQ(
544 1, metrics::NumEvents("WebRTC.Video.KeyFramesReceivedInPermille", 500));
545}
546
547TEST_F(ReceiveStatisticsProxyTest, TimingHistogramsNotUpdatedForTooFewSamples) {
548 const int kDecodeMs = 1;
549 const int kMaxDecodeMs = 2;
550 const int kCurrentDelayMs = 3;
551 const int kTargetDelayMs = 4;
552 const int kJitterBufferMs = 5;
553 const int kMinPlayoutDelayMs = 6;
554 const int kRenderDelayMs = 7;
555
556 for (int i = 0; i < kMinRequiredSamples - 1; ++i) {
557 statistics_proxy_->OnFrameBufferTimingsUpdated(
558 kDecodeMs, kMaxDecodeMs, kCurrentDelayMs, kTargetDelayMs,
559 kJitterBufferMs, kMinPlayoutDelayMs, kRenderDelayMs);
560 }
561
562 statistics_proxy_.reset();
563 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.DecodeTimeInMs"));
564 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.JitterBufferDelayInMs"));
565 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.TargetDelayInMs"));
566 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.CurrentDelayInMs"));
567 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.OnewayDelayInMs"));
568}
569
570TEST_F(ReceiveStatisticsProxyTest, TimingHistogramsAreUpdated) {
571 const int kDecodeMs = 1;
572 const int kMaxDecodeMs = 2;
573 const int kCurrentDelayMs = 3;
574 const int kTargetDelayMs = 4;
575 const int kJitterBufferMs = 5;
576 const int kMinPlayoutDelayMs = 6;
577 const int kRenderDelayMs = 7;
578
579 for (int i = 0; i < kMinRequiredSamples; ++i) {
580 statistics_proxy_->OnFrameBufferTimingsUpdated(
581 kDecodeMs, kMaxDecodeMs, kCurrentDelayMs, kTargetDelayMs,
582 kJitterBufferMs, kMinPlayoutDelayMs, kRenderDelayMs);
583 }
584
585 statistics_proxy_.reset();
586 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.DecodeTimeInMs"));
587 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.JitterBufferDelayInMs"));
588 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.TargetDelayInMs"));
589 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.CurrentDelayInMs"));
590 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.OnewayDelayInMs"));
591
592 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.DecodeTimeInMs", kDecodeMs));
593 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.JitterBufferDelayInMs",
594 kJitterBufferMs));
595 EXPECT_EQ(1,
596 metrics::NumEvents("WebRTC.Video.TargetDelayInMs", kTargetDelayMs));
597 EXPECT_EQ(
598 1, metrics::NumEvents("WebRTC.Video.CurrentDelayInMs", kCurrentDelayMs));
599 EXPECT_EQ(1,
600 metrics::NumEvents("WebRTC.Video.OnewayDelayInMs", kTargetDelayMs));
601}
602
sprang948b2752017-05-04 02:47:13 -0700603TEST_F(ReceiveStatisticsProxyTest, DoesNotReportStaleFramerates) {
604 const int kDefaultFps = 30;
605 const int kWidth = 320;
606 const int kHeight = 240;
607
608 rtc::scoped_refptr<VideoFrameBuffer> video_frame_buffer(
609 I420Buffer::Create(kWidth, kHeight));
610 VideoFrame frame(video_frame_buffer, kVideoRotation_0, 0);
611
612 for (int i = 0; i < kDefaultFps; ++i) {
613 // Since OnRenderedFrame is never called the fps in each sample will be 0,
614 // i.e. bad
615 frame.set_ntp_time_ms(fake_clock_.CurrentNtpInMilliseconds());
616 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(),
617 VideoContentType::UNSPECIFIED);
618 statistics_proxy_->OnRenderedFrame(frame);
619 fake_clock_.AdvanceTimeMilliseconds(1000 / kDefaultFps);
620 }
621
622 EXPECT_EQ(kDefaultFps, statistics_proxy_->GetStats().decode_frame_rate);
623 EXPECT_EQ(kDefaultFps, statistics_proxy_->GetStats().render_frame_rate);
624
625 // FPS trackers in stats proxy have a 1000ms sliding window.
626 fake_clock_.AdvanceTimeMilliseconds(1000);
627 EXPECT_EQ(0, statistics_proxy_->GetStats().decode_frame_rate);
628 EXPECT_EQ(0, statistics_proxy_->GetStats().render_frame_rate);
629}
630
asapersson2077f2f2017-05-11 05:37:35 -0700631TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsReceivedFrameStats) {
632 const int kWidth = 160;
633 const int kHeight = 120;
634 EXPECT_EQ(0, statistics_proxy_->GetStats().width);
635 EXPECT_EQ(0, statistics_proxy_->GetStats().height);
636 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_rendered);
637
638 statistics_proxy_->OnRenderedFrame(CreateFrame(kWidth, kHeight));
639
640 EXPECT_EQ(kWidth, statistics_proxy_->GetStats().width);
641 EXPECT_EQ(kHeight, statistics_proxy_->GetStats().height);
642 EXPECT_EQ(1u, statistics_proxy_->GetStats().frames_rendered);
643}
644
645TEST_F(ReceiveStatisticsProxyTest,
646 ReceivedFrameHistogramsAreNotUpdatedForTooFewSamples) {
647 const int kWidth = 160;
648 const int kHeight = 120;
649
650 for (int i = 0; i < kMinRequiredSamples - 1; ++i)
651 statistics_proxy_->OnRenderedFrame(CreateFrame(kWidth, kHeight));
652
653 statistics_proxy_.reset();
654 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.ReceivedWidthInPixels"));
655 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.ReceivedHeightInPixels"));
656 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.RenderFramesPerSecond"));
657 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.RenderSqrtPixelsPerSecond"));
658}
659
660TEST_F(ReceiveStatisticsProxyTest, ReceivedFrameHistogramsAreUpdated) {
661 const int kWidth = 160;
662 const int kHeight = 120;
663
664 for (int i = 0; i < kMinRequiredSamples; ++i)
665 statistics_proxy_->OnRenderedFrame(CreateFrame(kWidth, kHeight));
666
667 statistics_proxy_.reset();
668 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.ReceivedWidthInPixels"));
669 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.ReceivedHeightInPixels"));
670 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RenderFramesPerSecond"));
671 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RenderSqrtPixelsPerSecond"));
672 EXPECT_EQ(1,
673 metrics::NumEvents("WebRTC.Video.ReceivedWidthInPixels", kWidth));
674 EXPECT_EQ(1,
675 metrics::NumEvents("WebRTC.Video.ReceivedHeightInPixels", kHeight));
676}
677
678TEST_F(ReceiveStatisticsProxyTest,
679 RtcpHistogramsNotUpdatedIfMinRuntimeHasNotPassed) {
680 InsertFirstRtpPacket(kRemoteSsrc);
681 fake_clock_.AdvanceTimeMilliseconds((metrics::kMinRunTimeInSeconds * 1000) -
682 1);
683
684 RtcpPacketTypeCounter counter;
685 statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc, counter);
686
687 statistics_proxy_.reset();
688 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.FirPacketsSentPerMinute"));
689 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.PliPacketsSentPerMinute"));
690 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.NackPacketsSentPerMinute"));
691}
692
693TEST_F(ReceiveStatisticsProxyTest, RtcpHistogramsAreUpdated) {
694 InsertFirstRtpPacket(kRemoteSsrc);
695 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
696
697 const uint32_t kFirPackets = 100;
698 const uint32_t kPliPackets = 200;
699 const uint32_t kNackPackets = 300;
700
701 RtcpPacketTypeCounter counter;
702 counter.fir_packets = kFirPackets;
703 counter.pli_packets = kPliPackets;
704 counter.nack_packets = kNackPackets;
705 statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc, counter);
706
707 statistics_proxy_.reset();
708 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FirPacketsSentPerMinute"));
709 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PliPacketsSentPerMinute"));
710 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NackPacketsSentPerMinute"));
711 EXPECT_EQ(
712 1, metrics::NumEvents("WebRTC.Video.FirPacketsSentPerMinute",
713 kFirPackets * 60 / metrics::kMinRunTimeInSeconds));
714 EXPECT_EQ(
715 1, metrics::NumEvents("WebRTC.Video.PliPacketsSentPerMinute",
716 kPliPackets * 60 / metrics::kMinRunTimeInSeconds));
717 EXPECT_EQ(
718 1, metrics::NumEvents("WebRTC.Video.NackPacketsSentPerMinute",
719 kNackPackets * 60 / metrics::kMinRunTimeInSeconds));
720}
721
sprang892dab52017-08-15 05:00:33 -0700722INSTANTIATE_TEST_CASE_P(ContentTypes,
723 ReceiveStatisticsProxyTest,
724 ::testing::Values(VideoContentType::UNSPECIFIED,
725 VideoContentType::SCREENSHARE));
726
727TEST_P(ReceiveStatisticsProxyTest, InterFrameDelaysAreReported) {
728 const VideoContentType content_type = GetParam();
729 const int kInterFrameDelayMs = 33;
730 for (int i = 0; i < kMinRequiredSamples; ++i) {
731 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(), content_type);
732 fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs);
733 }
734 // One extra with with double the interval.
735 fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs);
736 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(), content_type);
737
738 statistics_proxy_.reset();
739 const int kExpectedInterFrame =
740 (kInterFrameDelayMs * (kMinRequiredSamples - 1) +
741 kInterFrameDelayMs * 2) /
742 kMinRequiredSamples;
743 switch (content_type) {
744 case VideoContentType::UNSPECIFIED:
745 EXPECT_EQ(kExpectedInterFrame,
746 metrics::MinSample("WebRTC.Video.InterframeDelayInMs"));
747 EXPECT_EQ(kInterFrameDelayMs * 2,
748 metrics::MinSample("WebRTC.Video.InterframeDelayMaxInMs"));
749 break;
750 case VideoContentType::SCREENSHARE:
751 EXPECT_EQ(
752 kExpectedInterFrame,
753 metrics::MinSample("WebRTC.Video.Screenshare.InterframeDelayInMs"));
754 EXPECT_EQ(kInterFrameDelayMs * 2,
755 metrics::MinSample(
756 "WebRTC.Video.Screenshare.InterframeDelayMaxInMs"));
757 break;
758 default:
759 RTC_NOTREACHED();
760 }
761}
762
763TEST_P(ReceiveStatisticsProxyTest, MaxInterFrameDelayOnlyWithValidAverage) {
764 const VideoContentType content_type = GetParam();
765 const int kInterFrameDelayMs = 33;
766 for (int i = 0; i < kMinRequiredSamples; ++i) {
767 statistics_proxy_->OnDecodedFrame(rtc::Optional<uint8_t>(), content_type);
768 fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs);
769 }
770
771 // |kMinRequiredSamples| samples, and thereby intervals, is required. That
772 // means we're one frame short of having a valid data set.
773 statistics_proxy_.reset();
774 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InterframeDelayInMs"));
775 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InterframeDelayMaxInMs"));
776 EXPECT_EQ(
777 0, metrics::NumSamples("WebRTC.Video.Screenshare.InterframeDelayInMs"));
778 EXPECT_EQ(0, metrics::NumSamples(
779 "WebRTC.Video.Screenshare.InterframeDelayMaxInMs"));
780}
781
sakale5ba44e2016-10-26 07:09:24 -0700782} // namespace webrtc