sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "video/receive_statistics_proxy.h" |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 12 | |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 13 | #include <limits> |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 14 | #include <memory> |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 15 | #include <utility> |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/video/i420_buffer.h" |
| 18 | #include "api/video/video_frame.h" |
| 19 | #include "api/video/video_rotation.h" |
| 20 | #include "modules/video_coding/include/video_codec_interface.h" |
| 21 | #include "system_wrappers/include/metrics.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "test/gtest.h" |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 25 | namespace { |
| 26 | const int64_t kFreqOffsetProcessIntervalInMs = 40000; |
asapersson | 46c4e3c | 2016-11-03 06:48:19 -0700 | [diff] [blame] | 27 | const uint32_t kLocalSsrc = 123; |
| 28 | const uint32_t kRemoteSsrc = 456; |
| 29 | const int kMinRequiredSamples = 200; |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 30 | const int kWidth = 1280; |
| 31 | const int kHeight = 720; |
| 32 | |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 33 | } // namespace |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 34 | |
| 35 | // TODO(sakal): ReceiveStatisticsProxy is lacking unittesting. |
sprang | 892dab5 | 2017-08-15 05:00:33 -0700 | [diff] [blame] | 36 | class ReceiveStatisticsProxyTest |
| 37 | : public ::testing::TestWithParam<webrtc::VideoContentType> { |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 38 | public: |
| 39 | ReceiveStatisticsProxyTest() : fake_clock_(1234), config_(GetTestConfig()) {} |
| 40 | virtual ~ReceiveStatisticsProxyTest() {} |
| 41 | |
| 42 | protected: |
| 43 | virtual void SetUp() { |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 44 | metrics::Reset(); |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 45 | statistics_proxy_.reset(new ReceiveStatisticsProxy(&config_, &fake_clock_)); |
| 46 | } |
| 47 | |
| 48 | VideoReceiveStream::Config GetTestConfig() { |
| 49 | VideoReceiveStream::Config config(nullptr); |
asapersson | 46c4e3c | 2016-11-03 06:48:19 -0700 | [diff] [blame] | 50 | config.rtp.local_ssrc = kLocalSsrc; |
| 51 | config.rtp.remote_ssrc = kRemoteSsrc; |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 52 | return config; |
| 53 | } |
| 54 | |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 55 | void InsertFirstRtpPacket(uint32_t ssrc) { |
| 56 | StreamDataCounters counters; |
| 57 | counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds(); |
| 58 | statistics_proxy_->DataCountersUpdated(counters, ssrc); |
| 59 | } |
| 60 | |
| 61 | VideoFrame CreateFrame(int width, int height) { |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 62 | return CreateVideoFrame(width, height, 0); |
| 63 | } |
| 64 | |
| 65 | VideoFrame CreateFrameWithRenderTimeMs(int64_t render_time_ms) { |
| 66 | return CreateVideoFrame(kWidth, kHeight, render_time_ms); |
| 67 | } |
| 68 | |
| 69 | VideoFrame CreateVideoFrame(int width, int height, int64_t render_time_ms) { |
| 70 | VideoFrame frame(I420Buffer::Create(width, height), 0, render_time_ms, |
| 71 | kVideoRotation_0); |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 72 | frame.set_ntp_time_ms(fake_clock_.CurrentNtpInMilliseconds()); |
| 73 | return frame; |
| 74 | } |
| 75 | |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 76 | SimulatedClock fake_clock_; |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 77 | const VideoReceiveStream::Config config_; |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 78 | std::unique_ptr<ReceiveStatisticsProxy> statistics_proxy_; |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameIncreasesFramesDecoded) { |
| 82 | EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_decoded); |
| 83 | for (uint32_t i = 1; i <= 3; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 84 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 85 | VideoContentType::UNSPECIFIED); |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 86 | EXPECT_EQ(i, statistics_proxy_->GetStats().frames_decoded); |
| 87 | } |
| 88 | } |
| 89 | |
Åsa Persson | b9b07ea | 2018-01-24 17:04:07 +0100 | [diff] [blame] | 90 | TEST_F(ReceiveStatisticsProxyTest, DecodedFpsIsReported) { |
| 91 | const int kFps = 20; |
| 92 | const int kRequiredSamples = metrics::kMinRunTimeInSeconds * kFps; |
| 93 | for (int i = 0; i < kRequiredSamples; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 94 | statistics_proxy_->OnDecodedFrame(absl::optional<uint8_t>(), kWidth, |
| 95 | kHeight, VideoContentType::UNSPECIFIED); |
Åsa Persson | b9b07ea | 2018-01-24 17:04:07 +0100 | [diff] [blame] | 96 | fake_clock_.AdvanceTimeMilliseconds(1000 / kFps); |
| 97 | } |
| 98 | statistics_proxy_.reset(); |
| 99 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.DecodedFramesPerSecond")); |
| 100 | EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.DecodedFramesPerSecond", kFps)); |
| 101 | } |
| 102 | |
| 103 | TEST_F(ReceiveStatisticsProxyTest, DecodedFpsIsNotReportedForTooFewSamples) { |
| 104 | const int kFps = 20; |
| 105 | const int kRequiredSamples = metrics::kMinRunTimeInSeconds * kFps; |
| 106 | for (int i = 0; i < kRequiredSamples - 1; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 107 | statistics_proxy_->OnDecodedFrame(absl::optional<uint8_t>(), kWidth, |
| 108 | kHeight, VideoContentType::UNSPECIFIED); |
Åsa Persson | b9b07ea | 2018-01-24 17:04:07 +0100 | [diff] [blame] | 109 | fake_clock_.AdvanceTimeMilliseconds(1000 / kFps); |
| 110 | } |
| 111 | statistics_proxy_.reset(); |
| 112 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.DecodedFramesPerSecond")); |
| 113 | } |
| 114 | |
| 115 | TEST_F(ReceiveStatisticsProxyTest, DecodedFpsIsReportedWithQpReset) { |
| 116 | const int kFps1 = 10; |
| 117 | for (int i = 0; i < metrics::kMinRunTimeInSeconds * kFps1; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 118 | statistics_proxy_->OnDecodedFrame(absl::optional<uint8_t>(), kWidth, |
| 119 | kHeight, VideoContentType::UNSPECIFIED); |
Åsa Persson | b9b07ea | 2018-01-24 17:04:07 +0100 | [diff] [blame] | 120 | fake_clock_.AdvanceTimeMilliseconds(1000 / kFps1); |
| 121 | } |
| 122 | // First QP value received, resets frames decoded. |
| 123 | const int kFps2 = 20; |
| 124 | for (int i = 0; i < metrics::kMinRunTimeInSeconds * kFps2; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 125 | statistics_proxy_->OnDecodedFrame(absl::optional<uint8_t>(1u), kWidth, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 126 | kHeight, VideoContentType::UNSPECIFIED); |
Åsa Persson | b9b07ea | 2018-01-24 17:04:07 +0100 | [diff] [blame] | 127 | fake_clock_.AdvanceTimeMilliseconds(1000 / kFps2); |
| 128 | } |
| 129 | statistics_proxy_.reset(); |
| 130 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.DecodedFramesPerSecond")); |
| 131 | EXPECT_EQ(1, |
| 132 | metrics::NumEvents("WebRTC.Video.DecodedFramesPerSecond", kFps2)); |
| 133 | } |
| 134 | |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 135 | TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameWithQpResetsFramesDecoded) { |
| 136 | EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_decoded); |
| 137 | for (uint32_t i = 1; i <= 3; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 138 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 139 | VideoContentType::UNSPECIFIED); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 140 | EXPECT_EQ(i, statistics_proxy_->GetStats().frames_decoded); |
| 141 | } |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 142 | statistics_proxy_->OnDecodedFrame(1u, kWidth, kHeight, |
| 143 | VideoContentType::UNSPECIFIED); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 144 | EXPECT_EQ(1u, statistics_proxy_->GetStats().frames_decoded); |
| 145 | } |
| 146 | |
| 147 | TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameIncreasesQpSum) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 148 | EXPECT_EQ(absl::nullopt, statistics_proxy_->GetStats().qp_sum); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 149 | statistics_proxy_->OnDecodedFrame(3u, kWidth, kHeight, |
| 150 | VideoContentType::UNSPECIFIED); |
Oskar Sundbom | 8e07c13 | 2018-01-08 16:45:42 +0100 | [diff] [blame] | 151 | EXPECT_EQ(3u, statistics_proxy_->GetStats().qp_sum); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 152 | statistics_proxy_->OnDecodedFrame(127u, kWidth, kHeight, |
| 153 | VideoContentType::UNSPECIFIED); |
Oskar Sundbom | 8e07c13 | 2018-01-08 16:45:42 +0100 | [diff] [blame] | 154 | EXPECT_EQ(130u, statistics_proxy_->GetStats().qp_sum); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 155 | } |
| 156 | |
ilnik | 2e1b40b | 2017-09-04 07:57:17 -0700 | [diff] [blame] | 157 | TEST_F(ReceiveStatisticsProxyTest, ReportsContentType) { |
| 158 | const std::string kRealtimeString("realtime"); |
| 159 | const std::string kScreenshareString("screen"); |
| 160 | EXPECT_EQ(kRealtimeString, videocontenttypehelpers::ToString( |
| 161 | statistics_proxy_->GetStats().content_type)); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 162 | statistics_proxy_->OnDecodedFrame(3u, kWidth, kHeight, |
| 163 | VideoContentType::SCREENSHARE); |
ilnik | 2e1b40b | 2017-09-04 07:57:17 -0700 | [diff] [blame] | 164 | EXPECT_EQ(kScreenshareString, videocontenttypehelpers::ToString( |
| 165 | statistics_proxy_->GetStats().content_type)); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 166 | statistics_proxy_->OnDecodedFrame(3u, kWidth, kHeight, |
| 167 | VideoContentType::UNSPECIFIED); |
ilnik | 2e1b40b | 2017-09-04 07:57:17 -0700 | [diff] [blame] | 168 | EXPECT_EQ(kRealtimeString, videocontenttypehelpers::ToString( |
| 169 | statistics_proxy_->GetStats().content_type)); |
| 170 | } |
| 171 | |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 172 | TEST_F(ReceiveStatisticsProxyTest, ReportsMaxInterframeDelay) { |
| 173 | const int64_t kInterframeDelayMs1 = 100; |
| 174 | const int64_t kInterframeDelayMs2 = 200; |
| 175 | const int64_t kInterframeDelayMs3 = 100; |
| 176 | EXPECT_EQ(-1, statistics_proxy_->GetStats().interframe_delay_max_ms); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 177 | statistics_proxy_->OnDecodedFrame(3u, kWidth, kHeight, |
| 178 | VideoContentType::UNSPECIFIED); |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 179 | EXPECT_EQ(-1, statistics_proxy_->GetStats().interframe_delay_max_ms); |
ilnik | f04afde | 2017-07-07 01:26:24 -0700 | [diff] [blame] | 180 | |
| 181 | fake_clock_.AdvanceTimeMilliseconds(kInterframeDelayMs1); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 182 | statistics_proxy_->OnDecodedFrame(127u, kWidth, kHeight, |
| 183 | VideoContentType::UNSPECIFIED); |
ilnik | f04afde | 2017-07-07 01:26:24 -0700 | [diff] [blame] | 184 | EXPECT_EQ(kInterframeDelayMs1, |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 185 | statistics_proxy_->GetStats().interframe_delay_max_ms); |
ilnik | f04afde | 2017-07-07 01:26:24 -0700 | [diff] [blame] | 186 | |
| 187 | fake_clock_.AdvanceTimeMilliseconds(kInterframeDelayMs2); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 188 | statistics_proxy_->OnDecodedFrame(127u, kWidth, kHeight, |
| 189 | VideoContentType::UNSPECIFIED); |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 190 | EXPECT_EQ(kInterframeDelayMs2, |
| 191 | statistics_proxy_->GetStats().interframe_delay_max_ms); |
| 192 | |
| 193 | fake_clock_.AdvanceTimeMilliseconds(kInterframeDelayMs3); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 194 | statistics_proxy_->OnDecodedFrame(127u, kWidth, kHeight, |
| 195 | VideoContentType::UNSPECIFIED); |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 196 | // kInterframeDelayMs3 is smaller than kInterframeDelayMs2. |
| 197 | EXPECT_EQ(kInterframeDelayMs2, |
| 198 | statistics_proxy_->GetStats().interframe_delay_max_ms); |
| 199 | } |
| 200 | |
| 201 | TEST_F(ReceiveStatisticsProxyTest, ReportInterframeDelayInWindow) { |
Ilya Nikolaevskiy | b06b358 | 2017-10-16 17:59:12 +0200 | [diff] [blame] | 202 | const int64_t kInterframeDelayMs1 = 900; |
| 203 | const int64_t kInterframeDelayMs2 = 750; |
| 204 | const int64_t kInterframeDelayMs3 = 700; |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 205 | EXPECT_EQ(-1, statistics_proxy_->GetStats().interframe_delay_max_ms); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 206 | statistics_proxy_->OnDecodedFrame(3u, kWidth, kHeight, |
| 207 | VideoContentType::UNSPECIFIED); |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 208 | EXPECT_EQ(-1, statistics_proxy_->GetStats().interframe_delay_max_ms); |
| 209 | |
| 210 | fake_clock_.AdvanceTimeMilliseconds(kInterframeDelayMs1); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 211 | statistics_proxy_->OnDecodedFrame(127u, kWidth, kHeight, |
| 212 | VideoContentType::UNSPECIFIED); |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 213 | EXPECT_EQ(kInterframeDelayMs1, |
| 214 | statistics_proxy_->GetStats().interframe_delay_max_ms); |
| 215 | |
| 216 | fake_clock_.AdvanceTimeMilliseconds(kInterframeDelayMs2); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 217 | statistics_proxy_->OnDecodedFrame(127u, kWidth, kHeight, |
| 218 | VideoContentType::UNSPECIFIED); |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 219 | // Still first delay is the maximum |
| 220 | EXPECT_EQ(kInterframeDelayMs1, |
| 221 | statistics_proxy_->GetStats().interframe_delay_max_ms); |
| 222 | |
| 223 | fake_clock_.AdvanceTimeMilliseconds(kInterframeDelayMs3); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 224 | statistics_proxy_->OnDecodedFrame(127u, kWidth, kHeight, |
| 225 | VideoContentType::UNSPECIFIED); |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 226 | // Now the first sample is out of the window, so the second is the maximum. |
| 227 | EXPECT_EQ(kInterframeDelayMs2, |
| 228 | statistics_proxy_->GetStats().interframe_delay_max_ms); |
ilnik | f04afde | 2017-07-07 01:26:24 -0700 | [diff] [blame] | 229 | } |
| 230 | |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 231 | TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameWithoutQpQpSumWontExist) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 232 | EXPECT_EQ(absl::nullopt, statistics_proxy_->GetStats().qp_sum); |
| 233 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 234 | VideoContentType::UNSPECIFIED); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 235 | EXPECT_EQ(absl::nullopt, statistics_proxy_->GetStats().qp_sum); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | TEST_F(ReceiveStatisticsProxyTest, OnDecodedFrameWithoutQpResetsQpSum) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 239 | EXPECT_EQ(absl::nullopt, statistics_proxy_->GetStats().qp_sum); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 240 | statistics_proxy_->OnDecodedFrame(3u, kWidth, kHeight, |
| 241 | VideoContentType::UNSPECIFIED); |
Oskar Sundbom | 8e07c13 | 2018-01-08 16:45:42 +0100 | [diff] [blame] | 242 | EXPECT_EQ(3u, statistics_proxy_->GetStats().qp_sum); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 243 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 244 | VideoContentType::UNSPECIFIED); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 245 | EXPECT_EQ(absl::nullopt, statistics_proxy_->GetStats().qp_sum); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 246 | } |
| 247 | |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 248 | TEST_F(ReceiveStatisticsProxyTest, OnRenderedFrameIncreasesFramesRendered) { |
| 249 | EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_rendered); |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 250 | webrtc::VideoFrame frame(webrtc::I420Buffer::Create(1, 1), 0, 0, |
| 251 | webrtc::kVideoRotation_0); |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 252 | for (uint32_t i = 1; i <= 3; ++i) { |
| 253 | statistics_proxy_->OnRenderedFrame(frame); |
| 254 | EXPECT_EQ(i, statistics_proxy_->GetStats().frames_rendered); |
| 255 | } |
| 256 | } |
| 257 | |
asapersson | 46c4e3c | 2016-11-03 06:48:19 -0700 | [diff] [blame] | 258 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsSsrc) { |
| 259 | EXPECT_EQ(kRemoteSsrc, statistics_proxy_->GetStats().ssrc); |
| 260 | } |
| 261 | |
| 262 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsIncomingPayloadType) { |
| 263 | const int kPayloadType = 111; |
| 264 | statistics_proxy_->OnIncomingPayloadType(kPayloadType); |
| 265 | EXPECT_EQ(kPayloadType, statistics_proxy_->GetStats().current_payload_type); |
| 266 | } |
| 267 | |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 268 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDecoderImplementationName) { |
| 269 | const char* kName = "decoderName"; |
| 270 | statistics_proxy_->OnDecoderImplementationName(kName); |
| 271 | EXPECT_STREQ( |
| 272 | kName, statistics_proxy_->GetStats().decoder_implementation_name.c_str()); |
| 273 | } |
| 274 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 275 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsOnCompleteFrame) { |
| 276 | const int kFrameSizeBytes = 1000; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 277 | statistics_proxy_->OnCompleteFrame(true, kFrameSizeBytes, |
| 278 | VideoContentType::UNSPECIFIED); |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 279 | VideoReceiveStream::Stats stats = statistics_proxy_->GetStats(); |
| 280 | EXPECT_EQ(1, stats.network_frame_rate); |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 281 | EXPECT_EQ(1, stats.frame_counts.key_frames); |
| 282 | EXPECT_EQ(0, stats.frame_counts.delta_frames); |
asapersson | 46c4e3c | 2016-11-03 06:48:19 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDecodeTimingStats) { |
| 286 | const int kDecodeMs = 1; |
| 287 | const int kMaxDecodeMs = 2; |
| 288 | const int kCurrentDelayMs = 3; |
| 289 | const int kTargetDelayMs = 4; |
| 290 | const int kJitterBufferMs = 5; |
| 291 | const int kMinPlayoutDelayMs = 6; |
| 292 | const int kRenderDelayMs = 7; |
| 293 | const int64_t kRttMs = 8; |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 294 | statistics_proxy_->OnRttUpdate(kRttMs, 0); |
| 295 | statistics_proxy_->OnFrameBufferTimingsUpdated( |
asapersson | 46c4e3c | 2016-11-03 06:48:19 -0700 | [diff] [blame] | 296 | kDecodeMs, kMaxDecodeMs, kCurrentDelayMs, kTargetDelayMs, kJitterBufferMs, |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 297 | kMinPlayoutDelayMs, kRenderDelayMs); |
asapersson | 46c4e3c | 2016-11-03 06:48:19 -0700 | [diff] [blame] | 298 | VideoReceiveStream::Stats stats = statistics_proxy_->GetStats(); |
| 299 | EXPECT_EQ(kDecodeMs, stats.decode_ms); |
| 300 | EXPECT_EQ(kMaxDecodeMs, stats.max_decode_ms); |
| 301 | EXPECT_EQ(kCurrentDelayMs, stats.current_delay_ms); |
| 302 | EXPECT_EQ(kTargetDelayMs, stats.target_delay_ms); |
| 303 | EXPECT_EQ(kJitterBufferMs, stats.jitter_buffer_ms); |
| 304 | EXPECT_EQ(kMinPlayoutDelayMs, stats.min_playout_delay_ms); |
| 305 | EXPECT_EQ(kRenderDelayMs, stats.render_delay_ms); |
| 306 | } |
| 307 | |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 308 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsRtcpPacketTypeCounts) { |
| 309 | const uint32_t kFirPackets = 33; |
| 310 | const uint32_t kPliPackets = 44; |
| 311 | const uint32_t kNackPackets = 55; |
| 312 | RtcpPacketTypeCounter counter; |
| 313 | counter.fir_packets = kFirPackets; |
| 314 | counter.pli_packets = kPliPackets; |
| 315 | counter.nack_packets = kNackPackets; |
| 316 | statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc, counter); |
| 317 | VideoReceiveStream::Stats stats = statistics_proxy_->GetStats(); |
| 318 | EXPECT_EQ(kFirPackets, stats.rtcp_packet_type_counts.fir_packets); |
| 319 | EXPECT_EQ(kPliPackets, stats.rtcp_packet_type_counts.pli_packets); |
| 320 | EXPECT_EQ(kNackPackets, stats.rtcp_packet_type_counts.nack_packets); |
| 321 | } |
| 322 | |
| 323 | TEST_F(ReceiveStatisticsProxyTest, |
| 324 | GetStatsReportsNoRtcpPacketTypeCountsForUnknownSsrc) { |
| 325 | RtcpPacketTypeCounter counter; |
| 326 | counter.fir_packets = 33; |
| 327 | statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc + 1, counter); |
| 328 | EXPECT_EQ(0u, |
| 329 | statistics_proxy_->GetStats().rtcp_packet_type_counts.fir_packets); |
| 330 | } |
| 331 | |
| 332 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsFrameCounts) { |
| 333 | const int kKeyFrames = 3; |
| 334 | const int kDeltaFrames = 22; |
| 335 | FrameCounts frame_counts; |
| 336 | frame_counts.key_frames = kKeyFrames; |
| 337 | frame_counts.delta_frames = kDeltaFrames; |
| 338 | statistics_proxy_->OnFrameCountsUpdated(frame_counts); |
| 339 | VideoReceiveStream::Stats stats = statistics_proxy_->GetStats(); |
| 340 | EXPECT_EQ(kKeyFrames, stats.frame_counts.key_frames); |
| 341 | EXPECT_EQ(kDeltaFrames, stats.frame_counts.delta_frames); |
| 342 | } |
| 343 | |
asapersson | 46c4e3c | 2016-11-03 06:48:19 -0700 | [diff] [blame] | 344 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsDiscardedPackets) { |
| 345 | const int kDiscardedPackets = 12; |
| 346 | statistics_proxy_->OnDiscardedPacketsUpdated(kDiscardedPackets); |
| 347 | EXPECT_EQ(kDiscardedPackets, statistics_proxy_->GetStats().discarded_packets); |
| 348 | } |
| 349 | |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 350 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsRtcpStats) { |
| 351 | const uint8_t kFracLost = 0; |
Harald Alvestrand | c7c4191 | 2017-12-08 09:59:34 +0100 | [diff] [blame] | 352 | const int32_t kCumLost = 1; |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 353 | const uint32_t kExtSeqNum = 10; |
| 354 | const uint32_t kJitter = 4; |
| 355 | |
| 356 | RtcpStatistics rtcp_stats; |
| 357 | rtcp_stats.fraction_lost = kFracLost; |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 358 | rtcp_stats.packets_lost = kCumLost; |
| 359 | rtcp_stats.extended_highest_sequence_number = kExtSeqNum; |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 360 | rtcp_stats.jitter = kJitter; |
| 361 | statistics_proxy_->StatisticsUpdated(rtcp_stats, kRemoteSsrc); |
| 362 | |
| 363 | VideoReceiveStream::Stats stats = statistics_proxy_->GetStats(); |
| 364 | EXPECT_EQ(kFracLost, stats.rtcp_stats.fraction_lost); |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 365 | EXPECT_EQ(kCumLost, stats.rtcp_stats.packets_lost); |
| 366 | EXPECT_EQ(kExtSeqNum, stats.rtcp_stats.extended_highest_sequence_number); |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 367 | EXPECT_EQ(kJitter, stats.rtcp_stats.jitter); |
| 368 | } |
| 369 | |
| 370 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsCName) { |
| 371 | const char* kName = "cName"; |
| 372 | statistics_proxy_->CNameChanged(kName, kRemoteSsrc); |
| 373 | EXPECT_STREQ(kName, statistics_proxy_->GetStats().c_name.c_str()); |
| 374 | } |
| 375 | |
| 376 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsNoCNameForUnknownSsrc) { |
| 377 | const char* kName = "cName"; |
| 378 | statistics_proxy_->CNameChanged(kName, kRemoteSsrc + 1); |
| 379 | EXPECT_STREQ("", statistics_proxy_->GetStats().c_name.c_str()); |
| 380 | } |
| 381 | |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 382 | TEST_F(ReceiveStatisticsProxyTest, |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 383 | ReportsLongestTimingFrameInfo) { |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 384 | const int64_t kShortEndToEndDelay = 10; |
| 385 | const int64_t kMedEndToEndDelay = 20; |
| 386 | const int64_t kLongEndToEndDelay = 100; |
| 387 | const uint32_t kExpectedRtpTimestamp = 2; |
| 388 | TimingFrameInfo info; |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 389 | absl::optional<TimingFrameInfo> result; |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 390 | info.rtp_timestamp = kExpectedRtpTimestamp - 1; |
| 391 | info.capture_time_ms = 0; |
| 392 | info.decode_finish_ms = kShortEndToEndDelay; |
| 393 | statistics_proxy_->OnTimingFrameInfoUpdated(info); |
| 394 | info.rtp_timestamp = |
| 395 | kExpectedRtpTimestamp; // this frame should be reported in the end. |
| 396 | info.capture_time_ms = 0; |
| 397 | info.decode_finish_ms = kLongEndToEndDelay; |
| 398 | statistics_proxy_->OnTimingFrameInfoUpdated(info); |
| 399 | info.rtp_timestamp = kExpectedRtpTimestamp + 1; |
| 400 | info.capture_time_ms = 0; |
| 401 | info.decode_finish_ms = kMedEndToEndDelay; |
| 402 | statistics_proxy_->OnTimingFrameInfoUpdated(info); |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 403 | result = statistics_proxy_->GetStats().timing_frame_info; |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 404 | EXPECT_TRUE(result); |
| 405 | EXPECT_EQ(kExpectedRtpTimestamp, result->rtp_timestamp); |
| 406 | } |
| 407 | |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 408 | TEST_F(ReceiveStatisticsProxyTest, RespectsReportingIntervalForTimingFrames) { |
| 409 | TimingFrameInfo info; |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 410 | const int64_t kShortEndToEndDelay = 10; |
| 411 | const uint32_t kExpectedRtpTimestamp = 2; |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 412 | const int64_t kShortDelayMs = 1000; |
| 413 | const int64_t kLongDelayMs = 10000; |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 414 | absl::optional<TimingFrameInfo> result; |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 415 | info.rtp_timestamp = kExpectedRtpTimestamp; |
| 416 | info.capture_time_ms = 0; |
| 417 | info.decode_finish_ms = kShortEndToEndDelay; |
| 418 | statistics_proxy_->OnTimingFrameInfoUpdated(info); |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 419 | fake_clock_.AdvanceTimeMilliseconds(kShortDelayMs); |
| 420 | result = statistics_proxy_->GetStats().timing_frame_info; |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 421 | EXPECT_TRUE(result); |
| 422 | EXPECT_EQ(kExpectedRtpTimestamp, result->rtp_timestamp); |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 423 | fake_clock_.AdvanceTimeMilliseconds(kLongDelayMs); |
| 424 | result = statistics_proxy_->GetStats().timing_frame_info; |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 425 | EXPECT_FALSE(result); |
| 426 | } |
| 427 | |
asapersson | 46c4e3c | 2016-11-03 06:48:19 -0700 | [diff] [blame] | 428 | TEST_F(ReceiveStatisticsProxyTest, LifetimeHistogramIsUpdated) { |
| 429 | const int64_t kTimeSec = 3; |
| 430 | fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 431 | // Need at least one frame to report stream lifetime. |
| 432 | statistics_proxy_->OnCompleteFrame(true, 1000, VideoContentType::UNSPECIFIED); |
asapersson | 46c4e3c | 2016-11-03 06:48:19 -0700 | [diff] [blame] | 433 | // Histograms are updated when the statistics_proxy_ is deleted. |
| 434 | statistics_proxy_.reset(); |
| 435 | EXPECT_EQ(1, |
| 436 | metrics::NumSamples("WebRTC.Video.ReceiveStreamLifetimeInSeconds")); |
| 437 | EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceiveStreamLifetimeInSeconds", |
| 438 | kTimeSec)); |
| 439 | } |
| 440 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 441 | TEST_F(ReceiveStatisticsProxyTest, |
| 442 | LifetimeHistogramNotReportedForEmptyStreams) { |
| 443 | const int64_t kTimeSec = 3; |
| 444 | fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000); |
| 445 | // No frames received. |
| 446 | // Histograms are updated when the statistics_proxy_ is deleted. |
| 447 | statistics_proxy_.reset(); |
| 448 | EXPECT_EQ(0, |
| 449 | metrics::NumSamples("WebRTC.Video.ReceiveStreamLifetimeInSeconds")); |
| 450 | } |
| 451 | |
palmkvist | a40672a | 2017-01-13 05:58:34 -0800 | [diff] [blame] | 452 | TEST_F(ReceiveStatisticsProxyTest, BadCallHistogramsAreUpdated) { |
| 453 | // Based on the tuning parameters this will produce 7 uncertain states, |
| 454 | // then 10 certainly bad states. There has to be 10 certain states before |
| 455 | // any histograms are recorded. |
| 456 | const int kNumBadSamples = 17; |
| 457 | |
| 458 | StreamDataCounters counters; |
| 459 | counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds(); |
| 460 | statistics_proxy_->DataCountersUpdated(counters, config_.rtp.remote_ssrc); |
| 461 | |
| 462 | for (int i = 0; i < kNumBadSamples; ++i) { |
| 463 | // Since OnRenderedFrame is never called the fps in each sample will be 0, |
| 464 | // i.e. bad |
| 465 | fake_clock_.AdvanceTimeMilliseconds(1000); |
| 466 | statistics_proxy_->OnIncomingRate(0, 0); |
| 467 | } |
| 468 | // Histograms are updated when the statistics_proxy_ is deleted. |
| 469 | statistics_proxy_.reset(); |
| 470 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BadCall.Any")); |
| 471 | EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.BadCall.Any", 100)); |
| 472 | |
| 473 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BadCall.FrameRate")); |
| 474 | EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.BadCall.FrameRate", 100)); |
| 475 | |
| 476 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.BadCall.FrameRateVariance")); |
| 477 | |
| 478 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.BadCall.Qp")); |
| 479 | } |
| 480 | |
asapersson | 0c43f77 | 2016-11-30 01:42:26 -0800 | [diff] [blame] | 481 | TEST_F(ReceiveStatisticsProxyTest, PacketLossHistogramIsUpdated) { |
| 482 | const uint32_t kCumLost1 = 1; |
| 483 | const uint32_t kExtSeqNum1 = 10; |
| 484 | const uint32_t kCumLost2 = 2; |
| 485 | const uint32_t kExtSeqNum2 = 20; |
| 486 | |
| 487 | // One report block received. |
| 488 | RtcpStatistics rtcp_stats1; |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 489 | rtcp_stats1.packets_lost = kCumLost1; |
| 490 | rtcp_stats1.extended_highest_sequence_number = kExtSeqNum1; |
asapersson | 0c43f77 | 2016-11-30 01:42:26 -0800 | [diff] [blame] | 491 | statistics_proxy_->StatisticsUpdated(rtcp_stats1, kRemoteSsrc); |
| 492 | |
| 493 | // Two report blocks received. |
| 494 | RtcpStatistics rtcp_stats2; |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 495 | rtcp_stats2.packets_lost = kCumLost2; |
| 496 | rtcp_stats2.extended_highest_sequence_number = kExtSeqNum2; |
asapersson | 0c43f77 | 2016-11-30 01:42:26 -0800 | [diff] [blame] | 497 | statistics_proxy_->StatisticsUpdated(rtcp_stats2, kRemoteSsrc); |
| 498 | |
| 499 | // Two received report blocks but min run time has not passed. |
| 500 | fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000 - 1); |
| 501 | SetUp(); // Reset stat proxy causes histograms to be updated. |
| 502 | EXPECT_EQ(0, |
| 503 | metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent")); |
| 504 | |
| 505 | // Two report blocks received. |
| 506 | statistics_proxy_->StatisticsUpdated(rtcp_stats1, kRemoteSsrc); |
| 507 | statistics_proxy_->StatisticsUpdated(rtcp_stats2, kRemoteSsrc); |
| 508 | |
| 509 | // Two received report blocks and min run time has passed. |
| 510 | fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
| 511 | SetUp(); |
| 512 | EXPECT_EQ(1, |
| 513 | metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent")); |
| 514 | EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.ReceivedPacketsLostInPercent", |
| 515 | (kCumLost2 - kCumLost1) * 100 / |
| 516 | (kExtSeqNum2 - kExtSeqNum1))); |
| 517 | } |
| 518 | |
| 519 | TEST_F(ReceiveStatisticsProxyTest, |
| 520 | PacketLossHistogramIsNotUpdatedIfLessThanTwoReportBlocksAreReceived) { |
| 521 | RtcpStatistics rtcp_stats1; |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 522 | rtcp_stats1.packets_lost = 1; |
| 523 | rtcp_stats1.extended_highest_sequence_number = 10; |
asapersson | 0c43f77 | 2016-11-30 01:42:26 -0800 | [diff] [blame] | 524 | |
| 525 | // Min run time has passed but no received report block. |
| 526 | fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
| 527 | SetUp(); // Reset stat proxy causes histograms to be updated. |
| 528 | EXPECT_EQ(0, |
| 529 | metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent")); |
| 530 | |
| 531 | // Min run time has passed but only one received report block. |
| 532 | statistics_proxy_->StatisticsUpdated(rtcp_stats1, kRemoteSsrc); |
| 533 | fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
| 534 | SetUp(); |
| 535 | EXPECT_EQ(0, |
| 536 | metrics::NumSamples("WebRTC.Video.ReceivedPacketsLostInPercent")); |
| 537 | } |
| 538 | |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 539 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsAvSyncOffset) { |
| 540 | const int64_t kSyncOffsetMs = 22; |
| 541 | const double kFreqKhz = 90.0; |
| 542 | EXPECT_EQ(std::numeric_limits<int>::max(), |
| 543 | statistics_proxy_->GetStats().sync_offset_ms); |
| 544 | statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
| 545 | EXPECT_EQ(kSyncOffsetMs, statistics_proxy_->GetStats().sync_offset_ms); |
| 546 | } |
| 547 | |
asapersson | 46c4e3c | 2016-11-03 06:48:19 -0700 | [diff] [blame] | 548 | TEST_F(ReceiveStatisticsProxyTest, AvSyncOffsetHistogramIsUpdated) { |
| 549 | const int64_t kSyncOffsetMs = 22; |
| 550 | const double kFreqKhz = 90.0; |
| 551 | for (int i = 0; i < kMinRequiredSamples; ++i) |
| 552 | statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
| 553 | // Histograms are updated when the statistics_proxy_ is deleted. |
| 554 | statistics_proxy_.reset(); |
| 555 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AVSyncOffsetInMs")); |
| 556 | EXPECT_EQ(1, |
| 557 | metrics::NumEvents("WebRTC.Video.AVSyncOffsetInMs", kSyncOffsetMs)); |
| 558 | } |
| 559 | |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 560 | TEST_F(ReceiveStatisticsProxyTest, RtpToNtpFrequencyOffsetHistogramIsUpdated) { |
| 561 | const int64_t kSyncOffsetMs = 22; |
| 562 | const double kFreqKhz = 90.0; |
| 563 | statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
| 564 | statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 2.2); |
| 565 | fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); |
| 566 | // Process interval passed, max diff: 2. |
| 567 | statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz + 1.1); |
| 568 | statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 4.2); |
| 569 | statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz - 0.9); |
| 570 | fake_clock_.AdvanceTimeMilliseconds(kFreqOffsetProcessIntervalInMs); |
| 571 | // Process interval passed, max diff: 4. |
| 572 | statistics_proxy_->OnSyncOffsetUpdated(kSyncOffsetMs, kFreqKhz); |
| 573 | statistics_proxy_.reset(); |
| 574 | // Average reported: (2 + 4) / 2 = 3. |
| 575 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtpToNtpFreqOffsetInKhz")); |
| 576 | EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtpToNtpFreqOffsetInKhz", 3)); |
| 577 | } |
| 578 | |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 579 | TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsUpdated) { |
| 580 | const int kQp = 22; |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 581 | |
| 582 | for (int i = 0; i < kMinRequiredSamples; ++i) |
Niels Möller | 147013a | 2018-10-01 15:56:33 +0200 | [diff] [blame] | 583 | statistics_proxy_->OnPreDecode(kVideoCodecVP8, kQp); |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 584 | |
| 585 | statistics_proxy_.reset(); |
| 586 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp")); |
| 587 | EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Decoded.Vp8.Qp", kQp)); |
| 588 | } |
| 589 | |
| 590 | TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsNotUpdatedForTooFewSamples) { |
Niels Möller | 147013a | 2018-10-01 15:56:33 +0200 | [diff] [blame] | 591 | const int kQp = 22; |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 592 | |
| 593 | for (int i = 0; i < kMinRequiredSamples - 1; ++i) |
Niels Möller | 147013a | 2018-10-01 15:56:33 +0200 | [diff] [blame] | 594 | statistics_proxy_->OnPreDecode(kVideoCodecVP8, kQp); |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 595 | |
| 596 | statistics_proxy_.reset(); |
| 597 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp")); |
| 598 | } |
| 599 | |
| 600 | TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsNotUpdatedIfNoQpValue) { |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 601 | for (int i = 0; i < kMinRequiredSamples; ++i) |
Niels Möller | 147013a | 2018-10-01 15:56:33 +0200 | [diff] [blame] | 602 | statistics_proxy_->OnPreDecode(kVideoCodecVP8, -1); |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 603 | |
| 604 | statistics_proxy_.reset(); |
| 605 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp")); |
| 606 | } |
| 607 | |
asapersson | b99baf8 | 2017-04-20 04:05:43 -0700 | [diff] [blame] | 608 | TEST_F(ReceiveStatisticsProxyTest, |
| 609 | KeyFrameHistogramNotUpdatedForTooFewSamples) { |
| 610 | const bool kIsKeyFrame = false; |
| 611 | const int kFrameSizeBytes = 1000; |
| 612 | |
| 613 | for (int i = 0; i < kMinRequiredSamples - 1; ++i) |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 614 | statistics_proxy_->OnCompleteFrame(kIsKeyFrame, kFrameSizeBytes, |
| 615 | VideoContentType::UNSPECIFIED); |
asapersson | b99baf8 | 2017-04-20 04:05:43 -0700 | [diff] [blame] | 616 | |
| 617 | EXPECT_EQ(0, statistics_proxy_->GetStats().frame_counts.key_frames); |
| 618 | EXPECT_EQ(kMinRequiredSamples - 1, |
| 619 | statistics_proxy_->GetStats().frame_counts.delta_frames); |
| 620 | |
| 621 | statistics_proxy_.reset(); |
| 622 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.KeyFramesReceivedInPermille")); |
| 623 | } |
| 624 | |
| 625 | TEST_F(ReceiveStatisticsProxyTest, |
| 626 | KeyFrameHistogramUpdatedForMinRequiredSamples) { |
| 627 | const bool kIsKeyFrame = false; |
| 628 | const int kFrameSizeBytes = 1000; |
| 629 | |
| 630 | for (int i = 0; i < kMinRequiredSamples; ++i) |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 631 | statistics_proxy_->OnCompleteFrame(kIsKeyFrame, kFrameSizeBytes, |
| 632 | VideoContentType::UNSPECIFIED); |
asapersson | b99baf8 | 2017-04-20 04:05:43 -0700 | [diff] [blame] | 633 | |
| 634 | EXPECT_EQ(0, statistics_proxy_->GetStats().frame_counts.key_frames); |
| 635 | EXPECT_EQ(kMinRequiredSamples, |
| 636 | statistics_proxy_->GetStats().frame_counts.delta_frames); |
| 637 | |
| 638 | statistics_proxy_.reset(); |
| 639 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.KeyFramesReceivedInPermille")); |
| 640 | EXPECT_EQ(1, |
| 641 | metrics::NumEvents("WebRTC.Video.KeyFramesReceivedInPermille", 0)); |
| 642 | } |
| 643 | |
| 644 | TEST_F(ReceiveStatisticsProxyTest, KeyFrameHistogramIsUpdated) { |
| 645 | const int kFrameSizeBytes = 1000; |
| 646 | |
| 647 | for (int i = 0; i < kMinRequiredSamples; ++i) |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 648 | statistics_proxy_->OnCompleteFrame(true, kFrameSizeBytes, |
| 649 | VideoContentType::UNSPECIFIED); |
asapersson | b99baf8 | 2017-04-20 04:05:43 -0700 | [diff] [blame] | 650 | |
| 651 | for (int i = 0; i < kMinRequiredSamples; ++i) |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 652 | statistics_proxy_->OnCompleteFrame(false, kFrameSizeBytes, |
| 653 | VideoContentType::UNSPECIFIED); |
asapersson | b99baf8 | 2017-04-20 04:05:43 -0700 | [diff] [blame] | 654 | |
| 655 | EXPECT_EQ(kMinRequiredSamples, |
| 656 | statistics_proxy_->GetStats().frame_counts.key_frames); |
| 657 | EXPECT_EQ(kMinRequiredSamples, |
| 658 | statistics_proxy_->GetStats().frame_counts.delta_frames); |
| 659 | |
| 660 | statistics_proxy_.reset(); |
| 661 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.KeyFramesReceivedInPermille")); |
| 662 | EXPECT_EQ( |
| 663 | 1, metrics::NumEvents("WebRTC.Video.KeyFramesReceivedInPermille", 500)); |
| 664 | } |
| 665 | |
| 666 | TEST_F(ReceiveStatisticsProxyTest, TimingHistogramsNotUpdatedForTooFewSamples) { |
| 667 | const int kDecodeMs = 1; |
| 668 | const int kMaxDecodeMs = 2; |
| 669 | const int kCurrentDelayMs = 3; |
| 670 | const int kTargetDelayMs = 4; |
| 671 | const int kJitterBufferMs = 5; |
| 672 | const int kMinPlayoutDelayMs = 6; |
| 673 | const int kRenderDelayMs = 7; |
| 674 | |
| 675 | for (int i = 0; i < kMinRequiredSamples - 1; ++i) { |
| 676 | statistics_proxy_->OnFrameBufferTimingsUpdated( |
| 677 | kDecodeMs, kMaxDecodeMs, kCurrentDelayMs, kTargetDelayMs, |
| 678 | kJitterBufferMs, kMinPlayoutDelayMs, kRenderDelayMs); |
| 679 | } |
| 680 | |
| 681 | statistics_proxy_.reset(); |
| 682 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.DecodeTimeInMs")); |
| 683 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.JitterBufferDelayInMs")); |
| 684 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.TargetDelayInMs")); |
| 685 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.CurrentDelayInMs")); |
| 686 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.OnewayDelayInMs")); |
| 687 | } |
| 688 | |
| 689 | TEST_F(ReceiveStatisticsProxyTest, TimingHistogramsAreUpdated) { |
| 690 | const int kDecodeMs = 1; |
| 691 | const int kMaxDecodeMs = 2; |
| 692 | const int kCurrentDelayMs = 3; |
| 693 | const int kTargetDelayMs = 4; |
| 694 | const int kJitterBufferMs = 5; |
| 695 | const int kMinPlayoutDelayMs = 6; |
| 696 | const int kRenderDelayMs = 7; |
| 697 | |
| 698 | for (int i = 0; i < kMinRequiredSamples; ++i) { |
| 699 | statistics_proxy_->OnFrameBufferTimingsUpdated( |
| 700 | kDecodeMs, kMaxDecodeMs, kCurrentDelayMs, kTargetDelayMs, |
| 701 | kJitterBufferMs, kMinPlayoutDelayMs, kRenderDelayMs); |
| 702 | } |
| 703 | |
| 704 | statistics_proxy_.reset(); |
| 705 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.DecodeTimeInMs")); |
| 706 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.JitterBufferDelayInMs")); |
| 707 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.TargetDelayInMs")); |
| 708 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.CurrentDelayInMs")); |
| 709 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.OnewayDelayInMs")); |
| 710 | |
| 711 | EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.DecodeTimeInMs", kDecodeMs)); |
| 712 | EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.JitterBufferDelayInMs", |
| 713 | kJitterBufferMs)); |
| 714 | EXPECT_EQ(1, |
| 715 | metrics::NumEvents("WebRTC.Video.TargetDelayInMs", kTargetDelayMs)); |
| 716 | EXPECT_EQ( |
| 717 | 1, metrics::NumEvents("WebRTC.Video.CurrentDelayInMs", kCurrentDelayMs)); |
| 718 | EXPECT_EQ(1, |
| 719 | metrics::NumEvents("WebRTC.Video.OnewayDelayInMs", kTargetDelayMs)); |
| 720 | } |
| 721 | |
sprang | 948b275 | 2017-05-04 02:47:13 -0700 | [diff] [blame] | 722 | TEST_F(ReceiveStatisticsProxyTest, DoesNotReportStaleFramerates) { |
| 723 | const int kDefaultFps = 30; |
sprang | 948b275 | 2017-05-04 02:47:13 -0700 | [diff] [blame] | 724 | rtc::scoped_refptr<VideoFrameBuffer> video_frame_buffer( |
| 725 | I420Buffer::Create(kWidth, kHeight)); |
| 726 | VideoFrame frame(video_frame_buffer, kVideoRotation_0, 0); |
| 727 | |
| 728 | for (int i = 0; i < kDefaultFps; ++i) { |
| 729 | // Since OnRenderedFrame is never called the fps in each sample will be 0, |
| 730 | // i.e. bad |
| 731 | frame.set_ntp_time_ms(fake_clock_.CurrentNtpInMilliseconds()); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 732 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
sprang | 948b275 | 2017-05-04 02:47:13 -0700 | [diff] [blame] | 733 | VideoContentType::UNSPECIFIED); |
| 734 | statistics_proxy_->OnRenderedFrame(frame); |
| 735 | fake_clock_.AdvanceTimeMilliseconds(1000 / kDefaultFps); |
| 736 | } |
| 737 | |
| 738 | EXPECT_EQ(kDefaultFps, statistics_proxy_->GetStats().decode_frame_rate); |
| 739 | EXPECT_EQ(kDefaultFps, statistics_proxy_->GetStats().render_frame_rate); |
| 740 | |
| 741 | // FPS trackers in stats proxy have a 1000ms sliding window. |
| 742 | fake_clock_.AdvanceTimeMilliseconds(1000); |
| 743 | EXPECT_EQ(0, statistics_proxy_->GetStats().decode_frame_rate); |
| 744 | EXPECT_EQ(0, statistics_proxy_->GetStats().render_frame_rate); |
| 745 | } |
| 746 | |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 747 | TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsReceivedFrameStats) { |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 748 | EXPECT_EQ(0, statistics_proxy_->GetStats().width); |
| 749 | EXPECT_EQ(0, statistics_proxy_->GetStats().height); |
| 750 | EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_rendered); |
| 751 | |
| 752 | statistics_proxy_->OnRenderedFrame(CreateFrame(kWidth, kHeight)); |
| 753 | |
| 754 | EXPECT_EQ(kWidth, statistics_proxy_->GetStats().width); |
| 755 | EXPECT_EQ(kHeight, statistics_proxy_->GetStats().height); |
| 756 | EXPECT_EQ(1u, statistics_proxy_->GetStats().frames_rendered); |
| 757 | } |
| 758 | |
| 759 | TEST_F(ReceiveStatisticsProxyTest, |
| 760 | ReceivedFrameHistogramsAreNotUpdatedForTooFewSamples) { |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 761 | for (int i = 0; i < kMinRequiredSamples - 1; ++i) |
| 762 | statistics_proxy_->OnRenderedFrame(CreateFrame(kWidth, kHeight)); |
| 763 | |
| 764 | statistics_proxy_.reset(); |
| 765 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.ReceivedWidthInPixels")); |
| 766 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.ReceivedHeightInPixels")); |
| 767 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.RenderFramesPerSecond")); |
| 768 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.RenderSqrtPixelsPerSecond")); |
| 769 | } |
| 770 | |
| 771 | TEST_F(ReceiveStatisticsProxyTest, ReceivedFrameHistogramsAreUpdated) { |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 772 | for (int i = 0; i < kMinRequiredSamples; ++i) |
| 773 | statistics_proxy_->OnRenderedFrame(CreateFrame(kWidth, kHeight)); |
| 774 | |
| 775 | statistics_proxy_.reset(); |
| 776 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.ReceivedWidthInPixels")); |
| 777 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.ReceivedHeightInPixels")); |
| 778 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RenderFramesPerSecond")); |
| 779 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RenderSqrtPixelsPerSecond")); |
| 780 | EXPECT_EQ(1, |
| 781 | metrics::NumEvents("WebRTC.Video.ReceivedWidthInPixels", kWidth)); |
| 782 | EXPECT_EQ(1, |
| 783 | metrics::NumEvents("WebRTC.Video.ReceivedHeightInPixels", kHeight)); |
| 784 | } |
| 785 | |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 786 | TEST_F(ReceiveStatisticsProxyTest, ZeroDelayReportedIfFrameNotDelayed) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 787 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 788 | VideoContentType::UNSPECIFIED); |
| 789 | |
| 790 | // Frame not delayed, delayed frames to render: 0%. |
| 791 | const int64_t kNowMs = fake_clock_.TimeInMilliseconds(); |
| 792 | statistics_proxy_->OnRenderedFrame(CreateFrameWithRenderTimeMs(kNowMs)); |
| 793 | |
| 794 | // Min run time has passed. |
| 795 | fake_clock_.AdvanceTimeMilliseconds((metrics::kMinRunTimeInSeconds * 1000)); |
| 796 | statistics_proxy_.reset(); |
| 797 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.DelayedFramesToRenderer")); |
| 798 | EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.DelayedFramesToRenderer", 0)); |
| 799 | EXPECT_EQ(0, metrics::NumSamples( |
| 800 | "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs")); |
| 801 | } |
| 802 | |
| 803 | TEST_F(ReceiveStatisticsProxyTest, |
| 804 | DelayedFrameHistogramsAreNotUpdatedIfMinRuntimeHasNotPassed) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 805 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 806 | VideoContentType::UNSPECIFIED); |
| 807 | |
| 808 | // Frame not delayed, delayed frames to render: 0%. |
| 809 | const int64_t kNowMs = fake_clock_.TimeInMilliseconds(); |
| 810 | statistics_proxy_->OnRenderedFrame(CreateFrameWithRenderTimeMs(kNowMs)); |
| 811 | |
| 812 | // Min run time has not passed. |
| 813 | fake_clock_.AdvanceTimeMilliseconds((metrics::kMinRunTimeInSeconds * 1000) - |
| 814 | 1); |
| 815 | statistics_proxy_.reset(); |
| 816 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.DelayedFramesToRenderer")); |
| 817 | EXPECT_EQ(0, metrics::NumSamples( |
| 818 | "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs")); |
| 819 | } |
| 820 | |
| 821 | TEST_F(ReceiveStatisticsProxyTest, |
| 822 | DelayedFramesHistogramsAreNotUpdatedIfNoRenderedFrames) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 823 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 824 | VideoContentType::UNSPECIFIED); |
| 825 | |
| 826 | // Min run time has passed. No rendered frames. |
| 827 | fake_clock_.AdvanceTimeMilliseconds((metrics::kMinRunTimeInSeconds * 1000)); |
| 828 | statistics_proxy_.reset(); |
| 829 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.DelayedFramesToRenderer")); |
| 830 | EXPECT_EQ(0, metrics::NumSamples( |
| 831 | "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs")); |
| 832 | } |
| 833 | |
| 834 | TEST_F(ReceiveStatisticsProxyTest, DelayReportedIfFrameIsDelayed) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 835 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 836 | VideoContentType::UNSPECIFIED); |
| 837 | |
| 838 | // Frame delayed 1 ms, delayed frames to render: 100%. |
| 839 | const int64_t kNowMs = fake_clock_.TimeInMilliseconds(); |
| 840 | statistics_proxy_->OnRenderedFrame(CreateFrameWithRenderTimeMs(kNowMs - 1)); |
| 841 | |
| 842 | // Min run time has passed. |
| 843 | fake_clock_.AdvanceTimeMilliseconds((metrics::kMinRunTimeInSeconds * 1000)); |
| 844 | statistics_proxy_.reset(); |
| 845 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.DelayedFramesToRenderer")); |
| 846 | EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.DelayedFramesToRenderer", 100)); |
| 847 | EXPECT_EQ(1, metrics::NumSamples( |
| 848 | "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs")); |
| 849 | EXPECT_EQ(1, metrics::NumEvents( |
| 850 | "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs", 1)); |
| 851 | } |
| 852 | |
| 853 | TEST_F(ReceiveStatisticsProxyTest, AverageDelayOfDelayedFramesIsReported) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 854 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 855 | VideoContentType::UNSPECIFIED); |
| 856 | |
| 857 | // Two frames delayed (6 ms, 10 ms), delayed frames to render: 50%. |
| 858 | const int64_t kNowMs = fake_clock_.TimeInMilliseconds(); |
| 859 | statistics_proxy_->OnRenderedFrame(CreateFrameWithRenderTimeMs(kNowMs - 10)); |
| 860 | statistics_proxy_->OnRenderedFrame(CreateFrameWithRenderTimeMs(kNowMs - 6)); |
| 861 | statistics_proxy_->OnRenderedFrame(CreateFrameWithRenderTimeMs(kNowMs)); |
| 862 | statistics_proxy_->OnRenderedFrame(CreateFrameWithRenderTimeMs(kNowMs + 1)); |
| 863 | |
| 864 | // Min run time has passed. |
| 865 | fake_clock_.AdvanceTimeMilliseconds((metrics::kMinRunTimeInSeconds * 1000)); |
| 866 | statistics_proxy_.reset(); |
| 867 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.DelayedFramesToRenderer")); |
| 868 | EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.DelayedFramesToRenderer", 50)); |
| 869 | EXPECT_EQ(1, metrics::NumSamples( |
| 870 | "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs")); |
| 871 | EXPECT_EQ(1, metrics::NumEvents( |
| 872 | "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs", 8)); |
| 873 | } |
| 874 | |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 875 | TEST_F(ReceiveStatisticsProxyTest, |
| 876 | RtcpHistogramsNotUpdatedIfMinRuntimeHasNotPassed) { |
| 877 | InsertFirstRtpPacket(kRemoteSsrc); |
| 878 | fake_clock_.AdvanceTimeMilliseconds((metrics::kMinRunTimeInSeconds * 1000) - |
| 879 | 1); |
| 880 | |
| 881 | RtcpPacketTypeCounter counter; |
| 882 | statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc, counter); |
| 883 | |
| 884 | statistics_proxy_.reset(); |
| 885 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.FirPacketsSentPerMinute")); |
| 886 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.PliPacketsSentPerMinute")); |
| 887 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.NackPacketsSentPerMinute")); |
| 888 | } |
| 889 | |
| 890 | TEST_F(ReceiveStatisticsProxyTest, RtcpHistogramsAreUpdated) { |
| 891 | InsertFirstRtpPacket(kRemoteSsrc); |
| 892 | fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
| 893 | |
| 894 | const uint32_t kFirPackets = 100; |
| 895 | const uint32_t kPliPackets = 200; |
| 896 | const uint32_t kNackPackets = 300; |
| 897 | |
| 898 | RtcpPacketTypeCounter counter; |
| 899 | counter.fir_packets = kFirPackets; |
| 900 | counter.pli_packets = kPliPackets; |
| 901 | counter.nack_packets = kNackPackets; |
| 902 | statistics_proxy_->RtcpPacketTypesCounterUpdated(kRemoteSsrc, counter); |
| 903 | |
| 904 | statistics_proxy_.reset(); |
| 905 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FirPacketsSentPerMinute")); |
| 906 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PliPacketsSentPerMinute")); |
| 907 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NackPacketsSentPerMinute")); |
| 908 | EXPECT_EQ( |
| 909 | 1, metrics::NumEvents("WebRTC.Video.FirPacketsSentPerMinute", |
| 910 | kFirPackets * 60 / metrics::kMinRunTimeInSeconds)); |
| 911 | EXPECT_EQ( |
| 912 | 1, metrics::NumEvents("WebRTC.Video.PliPacketsSentPerMinute", |
| 913 | kPliPackets * 60 / metrics::kMinRunTimeInSeconds)); |
| 914 | EXPECT_EQ( |
| 915 | 1, metrics::NumEvents("WebRTC.Video.NackPacketsSentPerMinute", |
| 916 | kNackPackets * 60 / metrics::kMinRunTimeInSeconds)); |
| 917 | } |
| 918 | |
sprang | 892dab5 | 2017-08-15 05:00:33 -0700 | [diff] [blame] | 919 | INSTANTIATE_TEST_CASE_P(ContentTypes, |
| 920 | ReceiveStatisticsProxyTest, |
| 921 | ::testing::Values(VideoContentType::UNSPECIFIED, |
| 922 | VideoContentType::SCREENSHARE)); |
| 923 | |
| 924 | TEST_P(ReceiveStatisticsProxyTest, InterFrameDelaysAreReported) { |
| 925 | const VideoContentType content_type = GetParam(); |
| 926 | const int kInterFrameDelayMs = 33; |
| 927 | for (int i = 0; i < kMinRequiredSamples; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 928 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 929 | content_type); |
sprang | 892dab5 | 2017-08-15 05:00:33 -0700 | [diff] [blame] | 930 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 931 | } |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 932 | // One extra with double the interval. |
sprang | 892dab5 | 2017-08-15 05:00:33 -0700 | [diff] [blame] | 933 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 934 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 935 | content_type); |
sprang | 892dab5 | 2017-08-15 05:00:33 -0700 | [diff] [blame] | 936 | |
| 937 | statistics_proxy_.reset(); |
| 938 | const int kExpectedInterFrame = |
| 939 | (kInterFrameDelayMs * (kMinRequiredSamples - 1) + |
| 940 | kInterFrameDelayMs * 2) / |
| 941 | kMinRequiredSamples; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 942 | if (videocontenttypehelpers::IsScreenshare(content_type)) { |
| 943 | EXPECT_EQ( |
| 944 | kExpectedInterFrame, |
| 945 | metrics::MinSample("WebRTC.Video.Screenshare.InterframeDelayInMs")); |
| 946 | EXPECT_EQ( |
| 947 | kInterFrameDelayMs * 2, |
| 948 | metrics::MinSample("WebRTC.Video.Screenshare.InterframeDelayMaxInMs")); |
| 949 | } else { |
| 950 | EXPECT_EQ(kExpectedInterFrame, |
| 951 | metrics::MinSample("WebRTC.Video.InterframeDelayInMs")); |
| 952 | EXPECT_EQ(kInterFrameDelayMs * 2, |
| 953 | metrics::MinSample("WebRTC.Video.InterframeDelayMaxInMs")); |
sprang | 892dab5 | 2017-08-15 05:00:33 -0700 | [diff] [blame] | 954 | } |
| 955 | } |
| 956 | |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 957 | TEST_P(ReceiveStatisticsProxyTest, InterFrameDelaysPercentilesAreReported) { |
| 958 | const VideoContentType content_type = GetParam(); |
| 959 | const int kInterFrameDelayMs = 33; |
| 960 | const int kLastFivePercentsSamples = kMinRequiredSamples * 5 / 100; |
| 961 | for (int i = 0; i <= kMinRequiredSamples - kLastFivePercentsSamples; ++i) { |
| 962 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 963 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 964 | content_type); |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 965 | } |
| 966 | // Last 5% of intervals are double in size. |
| 967 | for (int i = 0; i < kLastFivePercentsSamples; ++i) { |
| 968 | fake_clock_.AdvanceTimeMilliseconds(2 * kInterFrameDelayMs); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 969 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 970 | content_type); |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 971 | } |
| 972 | // Final sample is outlier and 10 times as big. |
| 973 | fake_clock_.AdvanceTimeMilliseconds(10 * kInterFrameDelayMs); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 974 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 975 | content_type); |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 976 | |
| 977 | statistics_proxy_.reset(); |
| 978 | const int kExpectedInterFrame = kInterFrameDelayMs * 2; |
| 979 | if (videocontenttypehelpers::IsScreenshare(content_type)) { |
| 980 | EXPECT_EQ(kExpectedInterFrame, |
| 981 | metrics::MinSample( |
| 982 | "WebRTC.Video.Screenshare.InterframeDelay95PercentileInMs")); |
| 983 | } else { |
| 984 | EXPECT_EQ( |
| 985 | kExpectedInterFrame, |
| 986 | metrics::MinSample("WebRTC.Video.InterframeDelay95PercentileInMs")); |
| 987 | } |
| 988 | } |
| 989 | |
sprang | 892dab5 | 2017-08-15 05:00:33 -0700 | [diff] [blame] | 990 | TEST_P(ReceiveStatisticsProxyTest, MaxInterFrameDelayOnlyWithValidAverage) { |
| 991 | const VideoContentType content_type = GetParam(); |
| 992 | const int kInterFrameDelayMs = 33; |
| 993 | for (int i = 0; i < kMinRequiredSamples; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 994 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 995 | content_type); |
sprang | 892dab5 | 2017-08-15 05:00:33 -0700 | [diff] [blame] | 996 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 997 | } |
| 998 | |
| 999 | // |kMinRequiredSamples| samples, and thereby intervals, is required. That |
| 1000 | // means we're one frame short of having a valid data set. |
| 1001 | statistics_proxy_.reset(); |
| 1002 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InterframeDelayInMs")); |
| 1003 | EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InterframeDelayMaxInMs")); |
| 1004 | EXPECT_EQ( |
| 1005 | 0, metrics::NumSamples("WebRTC.Video.Screenshare.InterframeDelayInMs")); |
| 1006 | EXPECT_EQ(0, metrics::NumSamples( |
| 1007 | "WebRTC.Video.Screenshare.InterframeDelayMaxInMs")); |
| 1008 | } |
| 1009 | |
sprang | 3e86e7e | 2017-08-22 09:23:28 -0700 | [diff] [blame] | 1010 | TEST_P(ReceiveStatisticsProxyTest, MaxInterFrameDelayOnlyWithPause) { |
| 1011 | const VideoContentType content_type = GetParam(); |
| 1012 | const int kInterFrameDelayMs = 33; |
| 1013 | for (int i = 0; i <= kMinRequiredSamples; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1014 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1015 | content_type); |
sprang | 3e86e7e | 2017-08-22 09:23:28 -0700 | [diff] [blame] | 1016 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1017 | } |
| 1018 | |
| 1019 | // At this state, we should have a valid inter-frame delay. |
| 1020 | // Indicate stream paused and make a large jump in time. |
| 1021 | statistics_proxy_->OnStreamInactive(); |
| 1022 | fake_clock_.AdvanceTimeMilliseconds(5000); |
| 1023 | |
| 1024 | // Insert two more frames. The interval during the pause should be disregarded |
| 1025 | // in the stats. |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1026 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1027 | content_type); |
sprang | 3e86e7e | 2017-08-22 09:23:28 -0700 | [diff] [blame] | 1028 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1029 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1030 | content_type); |
sprang | 3e86e7e | 2017-08-22 09:23:28 -0700 | [diff] [blame] | 1031 | |
| 1032 | statistics_proxy_.reset(); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 1033 | if (videocontenttypehelpers::IsScreenshare(content_type)) { |
sprang | 3e86e7e | 2017-08-22 09:23:28 -0700 | [diff] [blame] | 1034 | EXPECT_EQ( |
| 1035 | 1, metrics::NumSamples("WebRTC.Video.Screenshare.InterframeDelayInMs")); |
| 1036 | EXPECT_EQ(1, metrics::NumSamples( |
| 1037 | "WebRTC.Video.Screenshare.InterframeDelayMaxInMs")); |
| 1038 | EXPECT_EQ( |
| 1039 | kInterFrameDelayMs, |
| 1040 | metrics::MinSample("WebRTC.Video.Screenshare.InterframeDelayInMs")); |
| 1041 | EXPECT_EQ( |
| 1042 | kInterFrameDelayMs, |
| 1043 | metrics::MinSample("WebRTC.Video.Screenshare.InterframeDelayMaxInMs")); |
| 1044 | } else { |
| 1045 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InterframeDelayInMs")); |
| 1046 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InterframeDelayMaxInMs")); |
| 1047 | EXPECT_EQ(kInterFrameDelayMs, |
| 1048 | metrics::MinSample("WebRTC.Video.InterframeDelayInMs")); |
| 1049 | EXPECT_EQ(kInterFrameDelayMs, |
| 1050 | metrics::MinSample("WebRTC.Video.InterframeDelayMaxInMs")); |
| 1051 | } |
| 1052 | } |
| 1053 | |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1054 | TEST_P(ReceiveStatisticsProxyTest, FreezesAreReported) { |
| 1055 | const VideoContentType content_type = GetParam(); |
| 1056 | const int kInterFrameDelayMs = 33; |
| 1057 | const int kFreezeDelayMs = 200; |
Sergey Silkin | bea18ca | 2018-10-02 16:22:46 +0200 | [diff] [blame] | 1058 | const int kCallDurationMs = |
| 1059 | kMinRequiredSamples * kInterFrameDelayMs + kFreezeDelayMs; |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1060 | for (int i = 0; i < kMinRequiredSamples; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1061 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1062 | content_type); |
| 1063 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1064 | } |
| 1065 | // Add extra freeze. |
| 1066 | fake_clock_.AdvanceTimeMilliseconds(kFreezeDelayMs); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1067 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1068 | content_type); |
| 1069 | |
| 1070 | statistics_proxy_.reset(); |
| 1071 | const int kExpectedTimeBetweenFreezes = |
| 1072 | kInterFrameDelayMs * (kMinRequiredSamples - 1); |
Sergey Silkin | bea18ca | 2018-10-02 16:22:46 +0200 | [diff] [blame] | 1073 | const int kExpectedNumberFreezesPerMinute = 60 * 1000 / kCallDurationMs; |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1074 | if (videocontenttypehelpers::IsScreenshare(content_type)) { |
| 1075 | EXPECT_EQ( |
| 1076 | kFreezeDelayMs + kInterFrameDelayMs, |
| 1077 | metrics::MinSample("WebRTC.Video.Screenshare.MeanFreezeDurationMs")); |
| 1078 | EXPECT_EQ(kExpectedTimeBetweenFreezes, |
| 1079 | metrics::MinSample( |
| 1080 | "WebRTC.Video.Screenshare.MeanTimeBetweenFreezesMs")); |
Sergey Silkin | bea18ca | 2018-10-02 16:22:46 +0200 | [diff] [blame] | 1081 | EXPECT_EQ( |
| 1082 | kExpectedNumberFreezesPerMinute, |
| 1083 | metrics::MinSample("WebRTC.Video.Screenshare.NumberFreezesPerMinute")); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1084 | } else { |
| 1085 | EXPECT_EQ(kFreezeDelayMs + kInterFrameDelayMs, |
| 1086 | metrics::MinSample("WebRTC.Video.MeanFreezeDurationMs")); |
| 1087 | EXPECT_EQ(kExpectedTimeBetweenFreezes, |
| 1088 | metrics::MinSample("WebRTC.Video.MeanTimeBetweenFreezesMs")); |
Sergey Silkin | bea18ca | 2018-10-02 16:22:46 +0200 | [diff] [blame] | 1089 | EXPECT_EQ(kExpectedNumberFreezesPerMinute, |
| 1090 | metrics::MinSample("WebRTC.Video.NumberFreezesPerMinute")); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | TEST_P(ReceiveStatisticsProxyTest, PausesAreIgnored) { |
| 1095 | const VideoContentType content_type = GetParam(); |
| 1096 | const int kInterFrameDelayMs = 33; |
| 1097 | const int kPauseDurationMs = 10000; |
| 1098 | for (int i = 0; i <= kMinRequiredSamples; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1099 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1100 | content_type); |
| 1101 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1102 | } |
| 1103 | // Add a pause. |
| 1104 | fake_clock_.AdvanceTimeMilliseconds(kPauseDurationMs); |
| 1105 | statistics_proxy_->OnStreamInactive(); |
| 1106 | |
| 1107 | // Second playback interval with triple the length. |
| 1108 | for (int i = 0; i <= kMinRequiredSamples * 3; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1109 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1110 | content_type); |
| 1111 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1112 | } |
| 1113 | |
| 1114 | statistics_proxy_.reset(); |
| 1115 | // Average of two playback intervals. |
| 1116 | const int kExpectedTimeBetweenFreezes = |
| 1117 | kInterFrameDelayMs * kMinRequiredSamples * 2; |
| 1118 | if (videocontenttypehelpers::IsScreenshare(content_type)) { |
| 1119 | EXPECT_EQ(-1, metrics::MinSample( |
| 1120 | "WebRTC.Video.Screenshare.MeanFreezeDurationMs")); |
| 1121 | EXPECT_EQ(kExpectedTimeBetweenFreezes, |
| 1122 | metrics::MinSample( |
| 1123 | "WebRTC.Video.Screenshare.MeanTimeBetweenFreezesMs")); |
| 1124 | } else { |
| 1125 | EXPECT_EQ(-1, metrics::MinSample("WebRTC.Video.MeanFreezeDurationMs")); |
| 1126 | EXPECT_EQ(kExpectedTimeBetweenFreezes, |
| 1127 | metrics::MinSample("WebRTC.Video.MeanTimeBetweenFreezesMs")); |
| 1128 | } |
| 1129 | } |
| 1130 | |
Ilya Nikolaevskiy | 879f5a3 | 2018-05-31 09:47:17 +0200 | [diff] [blame] | 1131 | TEST_P(ReceiveStatisticsProxyTest, ManyPausesAtTheBeginning) { |
| 1132 | const VideoContentType content_type = GetParam(); |
| 1133 | const int kInterFrameDelayMs = 33; |
| 1134 | const int kPauseDurationMs = 10000; |
| 1135 | for (int i = 0; i <= kMinRequiredSamples; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1136 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 879f5a3 | 2018-05-31 09:47:17 +0200 | [diff] [blame] | 1137 | content_type); |
| 1138 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1139 | |
| 1140 | statistics_proxy_->OnStreamInactive(); |
| 1141 | fake_clock_.AdvanceTimeMilliseconds(kPauseDurationMs); |
| 1142 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1143 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
| 1144 | content_type); |
Ilya Nikolaevskiy | 879f5a3 | 2018-05-31 09:47:17 +0200 | [diff] [blame] | 1145 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1146 | } |
| 1147 | |
| 1148 | statistics_proxy_.reset(); |
| 1149 | // No freezes should be detected, as all long inter-frame delays were pauses. |
| 1150 | if (videocontenttypehelpers::IsScreenshare(content_type)) { |
| 1151 | EXPECT_EQ(-1, metrics::MinSample( |
| 1152 | "WebRTC.Video.Screenshare.MeanFreezeDurationMs")); |
| 1153 | } else { |
| 1154 | EXPECT_EQ(-1, metrics::MinSample("WebRTC.Video.MeanFreezeDurationMs")); |
| 1155 | } |
| 1156 | } |
| 1157 | |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1158 | TEST_P(ReceiveStatisticsProxyTest, TimeInHdReported) { |
| 1159 | const VideoContentType content_type = GetParam(); |
| 1160 | const int kInterFrameDelayMs = 20; |
| 1161 | // HD frames. |
| 1162 | for (int i = 0; i < kMinRequiredSamples; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1163 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1164 | content_type); |
| 1165 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1166 | } |
| 1167 | // SD frames. |
| 1168 | for (int i = 0; i < 2 * kMinRequiredSamples; ++i) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1169 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth / 2, kHeight / 2, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1170 | content_type); |
| 1171 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1172 | } |
| 1173 | // Extra last frame. |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1174 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth / 2, kHeight / 2, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1175 | content_type); |
| 1176 | statistics_proxy_.reset(); |
| 1177 | const int kExpectedTimeInHdPercents = 33; |
| 1178 | if (videocontenttypehelpers::IsScreenshare(content_type)) { |
| 1179 | EXPECT_EQ( |
| 1180 | kExpectedTimeInHdPercents, |
| 1181 | metrics::MinSample("WebRTC.Video.Screenshare.TimeInHdPercentage")); |
| 1182 | } else { |
| 1183 | EXPECT_EQ(kExpectedTimeInHdPercents, |
| 1184 | metrics::MinSample("WebRTC.Video.TimeInHdPercentage")); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | TEST_P(ReceiveStatisticsProxyTest, TimeInBlockyVideoReported) { |
| 1189 | const VideoContentType content_type = GetParam(); |
| 1190 | const int kInterFrameDelayMs = 20; |
| 1191 | const int kHighQp = 80; |
| 1192 | const int kLowQp = 30; |
| 1193 | // High quality frames. |
| 1194 | for (int i = 0; i < kMinRequiredSamples; ++i) { |
| 1195 | statistics_proxy_->OnDecodedFrame(kLowQp, kWidth, kHeight, content_type); |
| 1196 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1197 | } |
| 1198 | // Blocky frames. |
| 1199 | for (int i = 0; i < 2 * kMinRequiredSamples; ++i) { |
| 1200 | statistics_proxy_->OnDecodedFrame(kHighQp, kWidth, kHeight, content_type); |
| 1201 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1202 | } |
| 1203 | // Extra last frame. |
| 1204 | statistics_proxy_->OnDecodedFrame(kHighQp, kWidth, kHeight, content_type); |
| 1205 | statistics_proxy_.reset(); |
| 1206 | const int kExpectedTimeInHdPercents = 66; |
| 1207 | if (videocontenttypehelpers::IsScreenshare(content_type)) { |
| 1208 | EXPECT_EQ(kExpectedTimeInHdPercents, |
| 1209 | metrics::MinSample( |
| 1210 | "WebRTC.Video.Screenshare.TimeInBlockyVideoPercentage")); |
| 1211 | } else { |
| 1212 | EXPECT_EQ(kExpectedTimeInHdPercents, |
| 1213 | metrics::MinSample("WebRTC.Video.TimeInBlockyVideoPercentage")); |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | TEST_P(ReceiveStatisticsProxyTest, DownscalesReported) { |
| 1218 | const VideoContentType content_type = GetParam(); |
| 1219 | const int kInterFrameDelayMs = 1000; // To ensure long enough call duration. |
| 1220 | const int kLowQp = 30; |
| 1221 | |
| 1222 | statistics_proxy_->OnDecodedFrame(kLowQp, kWidth / 2, kHeight / 2, |
| 1223 | content_type); |
| 1224 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1225 | |
| 1226 | // Downscale. |
| 1227 | statistics_proxy_->OnDecodedFrame(kLowQp, kWidth, kHeight, content_type); |
| 1228 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1229 | |
| 1230 | statistics_proxy_->OnDecodedFrame(kLowQp, kWidth / 2, kHeight / 2, |
| 1231 | content_type); |
| 1232 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1233 | |
| 1234 | statistics_proxy_->OnDecodedFrame(kLowQp, kWidth / 2, kHeight / 2, |
| 1235 | content_type); |
| 1236 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1237 | |
| 1238 | // Downscale. |
| 1239 | statistics_proxy_->OnDecodedFrame(kLowQp, kWidth / 4, kHeight / 4, |
| 1240 | content_type); |
| 1241 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs); |
| 1242 | |
| 1243 | statistics_proxy_.reset(); |
| 1244 | const int kExpectedDownscales = 30; // 2 per 5 seconds = 30 per minute. |
| 1245 | if (videocontenttypehelpers::IsScreenshare(content_type)) { |
| 1246 | EXPECT_EQ( |
| 1247 | kExpectedDownscales, |
| 1248 | metrics::MinSample( |
| 1249 | "WebRTC.Video.Screenshare.NumberResolutionDownswitchesPerMinute")); |
| 1250 | } else { |
| 1251 | EXPECT_EQ(kExpectedDownscales, |
| 1252 | metrics::MinSample( |
| 1253 | "WebRTC.Video.NumberResolutionDownswitchesPerMinute")); |
| 1254 | } |
| 1255 | } |
| 1256 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 1257 | TEST_P(ReceiveStatisticsProxyTest, StatsAreSlicedOnSimulcastAndExperiment) { |
| 1258 | VideoContentType content_type = GetParam(); |
| 1259 | const uint8_t experiment_id = 1; |
| 1260 | videocontenttypehelpers::SetExperimentId(&content_type, experiment_id); |
| 1261 | const int kInterFrameDelayMs1 = 30; |
| 1262 | const int kInterFrameDelayMs2 = 50; |
| 1263 | |
| 1264 | videocontenttypehelpers::SetSimulcastId(&content_type, 1); |
| 1265 | for (int i = 0; i <= kMinRequiredSamples; ++i) { |
| 1266 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs1); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1267 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1268 | content_type); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | videocontenttypehelpers::SetSimulcastId(&content_type, 2); |
| 1272 | for (int i = 0; i <= kMinRequiredSamples; ++i) { |
| 1273 | fake_clock_.AdvanceTimeMilliseconds(kInterFrameDelayMs2); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1274 | statistics_proxy_->OnDecodedFrame(absl::nullopt, kWidth, kHeight, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 1275 | content_type); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 1276 | } |
| 1277 | statistics_proxy_.reset(); |
| 1278 | |
| 1279 | if (videocontenttypehelpers::IsScreenshare(content_type)) { |
| 1280 | EXPECT_EQ( |
| 1281 | 1, metrics::NumSamples("WebRTC.Video.Screenshare.InterframeDelayInMs")); |
| 1282 | EXPECT_EQ(1, metrics::NumSamples( |
| 1283 | "WebRTC.Video.Screenshare.InterframeDelayMaxInMs")); |
| 1284 | EXPECT_EQ(1, metrics::NumSamples( |
| 1285 | "WebRTC.Video.Screenshare.InterframeDelayInMs.S0")); |
| 1286 | EXPECT_EQ(1, metrics::NumSamples( |
| 1287 | "WebRTC.Video.Screenshare.InterframeDelayMaxInMs.S0")); |
| 1288 | EXPECT_EQ(1, metrics::NumSamples( |
| 1289 | "WebRTC.Video.Screenshare.InterframeDelayInMs.S1")); |
| 1290 | EXPECT_EQ(1, metrics::NumSamples( |
| 1291 | "WebRTC.Video.Screenshare.InterframeDelayMaxInMs.S1")); |
| 1292 | EXPECT_EQ(1, |
| 1293 | metrics::NumSamples("WebRTC.Video.Screenshare.InterframeDelayInMs" |
| 1294 | ".ExperimentGroup0")); |
| 1295 | EXPECT_EQ( |
| 1296 | 1, metrics::NumSamples("WebRTC.Video.Screenshare.InterframeDelayMaxInMs" |
| 1297 | ".ExperimentGroup0")); |
| 1298 | EXPECT_EQ( |
| 1299 | kInterFrameDelayMs1, |
| 1300 | metrics::MinSample("WebRTC.Video.Screenshare.InterframeDelayInMs.S0")); |
| 1301 | EXPECT_EQ( |
| 1302 | kInterFrameDelayMs2, |
| 1303 | metrics::MinSample("WebRTC.Video.Screenshare.InterframeDelayInMs.S1")); |
| 1304 | EXPECT_EQ( |
| 1305 | (kInterFrameDelayMs1 + kInterFrameDelayMs2) / 2, |
| 1306 | metrics::MinSample("WebRTC.Video.Screenshare.InterframeDelayInMs")); |
| 1307 | EXPECT_EQ( |
| 1308 | kInterFrameDelayMs2, |
| 1309 | metrics::MinSample("WebRTC.Video.Screenshare.InterframeDelayMaxInMs")); |
| 1310 | EXPECT_EQ( |
| 1311 | (kInterFrameDelayMs1 + kInterFrameDelayMs2) / 2, |
| 1312 | metrics::MinSample( |
| 1313 | "WebRTC.Video.Screenshare.InterframeDelayInMs.ExperimentGroup0")); |
| 1314 | } else { |
| 1315 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InterframeDelayInMs")); |
| 1316 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InterframeDelayMaxInMs")); |
| 1317 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InterframeDelayInMs.S0")); |
| 1318 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InterframeDelayMaxInMs.S0")); |
| 1319 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InterframeDelayInMs.S1")); |
| 1320 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InterframeDelayMaxInMs.S1")); |
| 1321 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InterframeDelayInMs" |
| 1322 | ".ExperimentGroup0")); |
| 1323 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InterframeDelayMaxInMs" |
| 1324 | ".ExperimentGroup0")); |
| 1325 | EXPECT_EQ(kInterFrameDelayMs1, |
| 1326 | metrics::MinSample("WebRTC.Video.InterframeDelayInMs.S0")); |
| 1327 | EXPECT_EQ(kInterFrameDelayMs2, |
| 1328 | metrics::MinSample("WebRTC.Video.InterframeDelayInMs.S1")); |
| 1329 | EXPECT_EQ((kInterFrameDelayMs1 + kInterFrameDelayMs2) / 2, |
| 1330 | metrics::MinSample("WebRTC.Video.InterframeDelayInMs")); |
| 1331 | EXPECT_EQ(kInterFrameDelayMs2, |
| 1332 | metrics::MinSample("WebRTC.Video.InterframeDelayMaxInMs")); |
| 1333 | EXPECT_EQ((kInterFrameDelayMs1 + kInterFrameDelayMs2) / 2, |
| 1334 | metrics::MinSample( |
| 1335 | "WebRTC.Video.InterframeDelayInMs.ExperimentGroup0")); |
| 1336 | } |
| 1337 | } |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 1338 | } // namespace webrtc |